Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * A framebuffer driver for VBE 2.0+ compliant video cards
0004  *
0005  * (c) 2007 Michal Januszewski <spock@gentoo.org>
0006  *     Loosely based upon the vesafb driver.
0007  *
0008  */
0009 
0010 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0011 
0012 #include <linux/init.h>
0013 #include <linux/module.h>
0014 #include <linux/moduleparam.h>
0015 #include <linux/skbuff.h>
0016 #include <linux/timer.h>
0017 #include <linux/completion.h>
0018 #include <linux/connector.h>
0019 #include <linux/random.h>
0020 #include <linux/platform_device.h>
0021 #include <linux/limits.h>
0022 #include <linux/fb.h>
0023 #include <linux/io.h>
0024 #include <linux/mutex.h>
0025 #include <linux/slab.h>
0026 #include <video/edid.h>
0027 #include <video/uvesafb.h>
0028 #ifdef CONFIG_X86
0029 #include <video/vga.h>
0030 #endif
0031 #include "edid.h"
0032 
0033 static struct cb_id uvesafb_cn_id = {
0034     .idx = CN_IDX_V86D,
0035     .val = CN_VAL_V86D_UVESAFB
0036 };
0037 static char v86d_path[PATH_MAX] = "/sbin/v86d";
0038 static char v86d_started;   /* has v86d been started by uvesafb? */
0039 
0040 static const struct fb_fix_screeninfo uvesafb_fix = {
0041     .id = "VESA VGA",
0042     .type   = FB_TYPE_PACKED_PIXELS,
0043     .accel  = FB_ACCEL_NONE,
0044     .visual = FB_VISUAL_TRUECOLOR,
0045 };
0046 
0047 static int mtrr     = 3;    /* enable mtrr by default */
0048 static bool blank   = true; /* enable blanking by default */
0049 static int ypan     = 1;    /* 0: scroll, 1: ypan, 2: ywrap */
0050 static bool pmi_setpal  = true; /* use PMI for palette changes */
0051 static bool nocrtc;     /* ignore CRTC settings */
0052 static bool noedid;     /* don't try DDC transfers */
0053 static int vram_remap;      /* set amt. of memory to be used */
0054 static int vram_total;      /* set total amount of memory */
0055 static u16 maxclk;      /* maximum pixel clock */
0056 static u16 maxvf;       /* maximum vertical frequency */
0057 static u16 maxhf;       /* maximum horizontal frequency */
0058 static u16 vbemode;     /* force use of a specific VBE mode */
0059 static char *mode_option;
0060 static u8  dac_width    = 6;
0061 
0062 static struct uvesafb_ktask *uvfb_tasks[UVESAFB_TASKS_MAX];
0063 static DEFINE_MUTEX(uvfb_lock);
0064 
0065 /*
0066  * A handler for replies from userspace.
0067  *
0068  * Make sure each message passes consistency checks and if it does,
0069  * find the kernel part of the task struct, copy the registers and
0070  * the buffer contents and then complete the task.
0071  */
0072 static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
0073 {
0074     struct uvesafb_task *utask;
0075     struct uvesafb_ktask *task;
0076 
0077     if (!capable(CAP_SYS_ADMIN))
0078         return;
0079 
0080     if (msg->seq >= UVESAFB_TASKS_MAX)
0081         return;
0082 
0083     mutex_lock(&uvfb_lock);
0084     task = uvfb_tasks[msg->seq];
0085 
0086     if (!task || msg->ack != task->ack) {
0087         mutex_unlock(&uvfb_lock);
0088         return;
0089     }
0090 
0091     utask = (struct uvesafb_task *)msg->data;
0092 
0093     /* Sanity checks for the buffer length. */
0094     if (task->t.buf_len < utask->buf_len ||
0095         utask->buf_len > msg->len - sizeof(*utask)) {
0096         mutex_unlock(&uvfb_lock);
0097         return;
0098     }
0099 
0100     uvfb_tasks[msg->seq] = NULL;
0101     mutex_unlock(&uvfb_lock);
0102 
0103     memcpy(&task->t, utask, sizeof(*utask));
0104 
0105     if (task->t.buf_len && task->buf)
0106         memcpy(task->buf, utask + 1, task->t.buf_len);
0107 
0108     complete(task->done);
0109     return;
0110 }
0111 
0112 static int uvesafb_helper_start(void)
0113 {
0114     char *envp[] = {
0115         "HOME=/",
0116         "PATH=/sbin:/bin",
0117         NULL,
0118     };
0119 
0120     char *argv[] = {
0121         v86d_path,
0122         NULL,
0123     };
0124 
0125     return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
0126 }
0127 
0128 /*
0129  * Execute a uvesafb task.
0130  *
0131  * Returns 0 if the task is executed successfully.
0132  *
0133  * A message sent to the userspace consists of the uvesafb_task
0134  * struct and (optionally) a buffer. The uvesafb_task struct is
0135  * a simplified version of uvesafb_ktask (its kernel counterpart)
0136  * containing only the register values, flags and the length of
0137  * the buffer.
0138  *
0139  * Each message is assigned a sequence number (increased linearly)
0140  * and a random ack number. The sequence number is used as a key
0141  * for the uvfb_tasks array which holds pointers to uvesafb_ktask
0142  * structs for all requests.
0143  */
0144 static int uvesafb_exec(struct uvesafb_ktask *task)
0145 {
0146     static int seq;
0147     struct cn_msg *m;
0148     int err;
0149     int len = sizeof(task->t) + task->t.buf_len;
0150 
0151     /*
0152      * Check whether the message isn't longer than the maximum
0153      * allowed by connector.
0154      */
0155     if (sizeof(*m) + len > CONNECTOR_MAX_MSG_SIZE) {
0156         pr_warn("message too long (%d), can't execute task\n",
0157             (int)(sizeof(*m) + len));
0158         return -E2BIG;
0159     }
0160 
0161     m = kzalloc(sizeof(*m) + len, GFP_KERNEL);
0162     if (!m)
0163         return -ENOMEM;
0164 
0165     init_completion(task->done);
0166 
0167     memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id));
0168     m->seq = seq;
0169     m->len = len;
0170     m->ack = prandom_u32();
0171 
0172     /* uvesafb_task structure */
0173     memcpy(m + 1, &task->t, sizeof(task->t));
0174 
0175     /* Buffer */
0176     memcpy((u8 *)(m + 1) + sizeof(task->t), task->buf, task->t.buf_len);
0177 
0178     /*
0179      * Save the message ack number so that we can find the kernel
0180      * part of this task when a reply is received from userspace.
0181      */
0182     task->ack = m->ack;
0183 
0184     mutex_lock(&uvfb_lock);
0185 
0186     /* If all slots are taken -- bail out. */
0187     if (uvfb_tasks[seq]) {
0188         mutex_unlock(&uvfb_lock);
0189         err = -EBUSY;
0190         goto out;
0191     }
0192 
0193     /* Save a pointer to the kernel part of the task struct. */
0194     uvfb_tasks[seq] = task;
0195     mutex_unlock(&uvfb_lock);
0196 
0197     err = cn_netlink_send(m, 0, 0, GFP_KERNEL);
0198     if (err == -ESRCH) {
0199         /*
0200          * Try to start the userspace helper if sending
0201          * the request failed the first time.
0202          */
0203         err = uvesafb_helper_start();
0204         if (err) {
0205             pr_err("failed to execute %s\n", v86d_path);
0206             pr_err("make sure that the v86d helper is installed and executable\n");
0207         } else {
0208             v86d_started = 1;
0209             err = cn_netlink_send(m, 0, 0, gfp_any());
0210             if (err == -ENOBUFS)
0211                 err = 0;
0212         }
0213     } else if (err == -ENOBUFS)
0214         err = 0;
0215 
0216     if (!err && !(task->t.flags & TF_EXIT))
0217         err = !wait_for_completion_timeout(task->done,
0218                 msecs_to_jiffies(UVESAFB_TIMEOUT));
0219 
0220     mutex_lock(&uvfb_lock);
0221     uvfb_tasks[seq] = NULL;
0222     mutex_unlock(&uvfb_lock);
0223 
0224     seq++;
0225     if (seq >= UVESAFB_TASKS_MAX)
0226         seq = 0;
0227 out:
0228     kfree(m);
0229     return err;
0230 }
0231 
0232 /*
0233  * Free a uvesafb_ktask struct.
0234  */
0235 static void uvesafb_free(struct uvesafb_ktask *task)
0236 {
0237     if (task) {
0238         kfree(task->done);
0239         kfree(task);
0240     }
0241 }
0242 
0243 /*
0244  * Prepare a uvesafb_ktask struct to be used again.
0245  */
0246 static void uvesafb_reset(struct uvesafb_ktask *task)
0247 {
0248     struct completion *cpl = task->done;
0249 
0250     memset(task, 0, sizeof(*task));
0251     task->done = cpl;
0252 }
0253 
0254 /*
0255  * Allocate and prepare a uvesafb_ktask struct.
0256  */
0257 static struct uvesafb_ktask *uvesafb_prep(void)
0258 {
0259     struct uvesafb_ktask *task;
0260 
0261     task = kzalloc(sizeof(*task), GFP_KERNEL);
0262     if (task) {
0263         task->done = kzalloc(sizeof(*task->done), GFP_KERNEL);
0264         if (!task->done) {
0265             kfree(task);
0266             task = NULL;
0267         }
0268     }
0269     return task;
0270 }
0271 
0272 static void uvesafb_setup_var(struct fb_var_screeninfo *var,
0273         struct fb_info *info, struct vbe_mode_ib *mode)
0274 {
0275     struct uvesafb_par *par = info->par;
0276 
0277     var->vmode = FB_VMODE_NONINTERLACED;
0278     var->sync = FB_SYNC_VERT_HIGH_ACT;
0279 
0280     var->xres = mode->x_res;
0281     var->yres = mode->y_res;
0282     var->xres_virtual = mode->x_res;
0283     var->yres_virtual = (par->ypan) ?
0284             info->fix.smem_len / mode->bytes_per_scan_line :
0285             mode->y_res;
0286     var->xoffset = 0;
0287     var->yoffset = 0;
0288     var->bits_per_pixel = mode->bits_per_pixel;
0289 
0290     if (var->bits_per_pixel == 15)
0291         var->bits_per_pixel = 16;
0292 
0293     if (var->bits_per_pixel > 8) {
0294         var->red.offset    = mode->red_off;
0295         var->red.length    = mode->red_len;
0296         var->green.offset  = mode->green_off;
0297         var->green.length  = mode->green_len;
0298         var->blue.offset   = mode->blue_off;
0299         var->blue.length   = mode->blue_len;
0300         var->transp.offset = mode->rsvd_off;
0301         var->transp.length = mode->rsvd_len;
0302     } else {
0303         var->red.offset    = 0;
0304         var->green.offset  = 0;
0305         var->blue.offset   = 0;
0306         var->transp.offset = 0;
0307 
0308         var->red.length    = 8;
0309         var->green.length  = 8;
0310         var->blue.length   = 8;
0311         var->transp.length = 0;
0312     }
0313 }
0314 
0315 static int uvesafb_vbe_find_mode(struct uvesafb_par *par,
0316         int xres, int yres, int depth, unsigned char flags)
0317 {
0318     int i, match = -1, h = 0, d = 0x7fffffff;
0319 
0320     for (i = 0; i < par->vbe_modes_cnt; i++) {
0321         h = abs(par->vbe_modes[i].x_res - xres) +
0322             abs(par->vbe_modes[i].y_res - yres) +
0323             abs(depth - par->vbe_modes[i].depth);
0324 
0325         /*
0326          * We have an exact match in terms of resolution
0327          * and depth.
0328          */
0329         if (h == 0)
0330             return i;
0331 
0332         if (h < d || (h == d && par->vbe_modes[i].depth > depth)) {
0333             d = h;
0334             match = i;
0335         }
0336     }
0337     i = 1;
0338 
0339     if (flags & UVESAFB_EXACT_DEPTH &&
0340             par->vbe_modes[match].depth != depth)
0341         i = 0;
0342 
0343     if (flags & UVESAFB_EXACT_RES && d > 24)
0344         i = 0;
0345 
0346     if (i != 0)
0347         return match;
0348     else
0349         return -1;
0350 }
0351 
0352 static u8 *uvesafb_vbe_state_save(struct uvesafb_par *par)
0353 {
0354     struct uvesafb_ktask *task;
0355     u8 *state;
0356     int err;
0357 
0358     if (!par->vbe_state_size)
0359         return NULL;
0360 
0361     state = kmalloc(par->vbe_state_size, GFP_KERNEL);
0362     if (!state)
0363         return ERR_PTR(-ENOMEM);
0364 
0365     task = uvesafb_prep();
0366     if (!task) {
0367         kfree(state);
0368         return NULL;
0369     }
0370 
0371     task->t.regs.eax = 0x4f04;
0372     task->t.regs.ecx = 0x000f;
0373     task->t.regs.edx = 0x0001;
0374     task->t.flags = TF_BUF_RET | TF_BUF_ESBX;
0375     task->t.buf_len = par->vbe_state_size;
0376     task->buf = state;
0377     err = uvesafb_exec(task);
0378 
0379     if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
0380         pr_warn("VBE get state call failed (eax=0x%x, err=%d)\n",
0381             task->t.regs.eax, err);
0382         kfree(state);
0383         state = NULL;
0384     }
0385 
0386     uvesafb_free(task);
0387     return state;
0388 }
0389 
0390 static void uvesafb_vbe_state_restore(struct uvesafb_par *par, u8 *state_buf)
0391 {
0392     struct uvesafb_ktask *task;
0393     int err;
0394 
0395     if (!state_buf)
0396         return;
0397 
0398     task = uvesafb_prep();
0399     if (!task)
0400         return;
0401 
0402     task->t.regs.eax = 0x4f04;
0403     task->t.regs.ecx = 0x000f;
0404     task->t.regs.edx = 0x0002;
0405     task->t.buf_len = par->vbe_state_size;
0406     task->t.flags = TF_BUF_ESBX;
0407     task->buf = state_buf;
0408 
0409     err = uvesafb_exec(task);
0410     if (err || (task->t.regs.eax & 0xffff) != 0x004f)
0411         pr_warn("VBE state restore call failed (eax=0x%x, err=%d)\n",
0412             task->t.regs.eax, err);
0413 
0414     uvesafb_free(task);
0415 }
0416 
0417 static int uvesafb_vbe_getinfo(struct uvesafb_ktask *task,
0418                    struct uvesafb_par *par)
0419 {
0420     int err;
0421 
0422     task->t.regs.eax = 0x4f00;
0423     task->t.flags = TF_VBEIB;
0424     task->t.buf_len = sizeof(struct vbe_ib);
0425     task->buf = &par->vbe_ib;
0426     memcpy(par->vbe_ib.vbe_signature, "VBE2", 4);
0427 
0428     err = uvesafb_exec(task);
0429     if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
0430         pr_err("Getting VBE info block failed (eax=0x%x, err=%d)\n",
0431                (u32)task->t.regs.eax, err);
0432         return -EINVAL;
0433     }
0434 
0435     if (par->vbe_ib.vbe_version < 0x0200) {
0436         pr_err("Sorry, pre-VBE 2.0 cards are not supported\n");
0437         return -EINVAL;
0438     }
0439 
0440     if (!par->vbe_ib.mode_list_ptr) {
0441         pr_err("Missing mode list!\n");
0442         return -EINVAL;
0443     }
0444 
0445     pr_info("");
0446 
0447     /*
0448      * Convert string pointers and the mode list pointer into
0449      * usable addresses. Print informational messages about the
0450      * video adapter and its vendor.
0451      */
0452     if (par->vbe_ib.oem_vendor_name_ptr)
0453         pr_cont("%s, ",
0454             ((char *)task->buf) + par->vbe_ib.oem_vendor_name_ptr);
0455 
0456     if (par->vbe_ib.oem_product_name_ptr)
0457         pr_cont("%s, ",
0458             ((char *)task->buf) + par->vbe_ib.oem_product_name_ptr);
0459 
0460     if (par->vbe_ib.oem_product_rev_ptr)
0461         pr_cont("%s, ",
0462             ((char *)task->buf) + par->vbe_ib.oem_product_rev_ptr);
0463 
0464     if (par->vbe_ib.oem_string_ptr)
0465         pr_cont("OEM: %s, ",
0466             ((char *)task->buf) + par->vbe_ib.oem_string_ptr);
0467 
0468     pr_cont("VBE v%d.%d\n",
0469         (par->vbe_ib.vbe_version & 0xff00) >> 8,
0470         par->vbe_ib.vbe_version & 0xff);
0471 
0472     return 0;
0473 }
0474 
0475 static int uvesafb_vbe_getmodes(struct uvesafb_ktask *task,
0476                 struct uvesafb_par *par)
0477 {
0478     int off = 0, err;
0479     u16 *mode;
0480 
0481     par->vbe_modes_cnt = 0;
0482 
0483     /* Count available modes. */
0484     mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
0485     while (*mode != 0xffff) {
0486         par->vbe_modes_cnt++;
0487         mode++;
0488     }
0489 
0490     par->vbe_modes = kcalloc(par->vbe_modes_cnt,
0491                  sizeof(struct vbe_mode_ib),
0492                  GFP_KERNEL);
0493     if (!par->vbe_modes)
0494         return -ENOMEM;
0495 
0496     /* Get info about all available modes. */
0497     mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
0498     while (*mode != 0xffff) {
0499         struct vbe_mode_ib *mib;
0500 
0501         uvesafb_reset(task);
0502         task->t.regs.eax = 0x4f01;
0503         task->t.regs.ecx = (u32) *mode;
0504         task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
0505         task->t.buf_len = sizeof(struct vbe_mode_ib);
0506         task->buf = par->vbe_modes + off;
0507 
0508         err = uvesafb_exec(task);
0509         if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
0510             pr_warn("Getting mode info block for mode 0x%x failed (eax=0x%x, err=%d)\n",
0511                 *mode, (u32)task->t.regs.eax, err);
0512             mode++;
0513             par->vbe_modes_cnt--;
0514             continue;
0515         }
0516 
0517         mib = task->buf;
0518         mib->mode_id = *mode;
0519 
0520         /*
0521          * We only want modes that are supported with the current
0522          * hardware configuration, color, graphics and that have
0523          * support for the LFB.
0524          */
0525         if ((mib->mode_attr & VBE_MODE_MASK) == VBE_MODE_MASK &&
0526                  mib->bits_per_pixel >= 8)
0527             off++;
0528         else
0529             par->vbe_modes_cnt--;
0530 
0531         mode++;
0532         mib->depth = mib->red_len + mib->green_len + mib->blue_len;
0533 
0534         /*
0535          * Handle 8bpp modes and modes with broken color component
0536          * lengths.
0537          */
0538         if (mib->depth == 0 || (mib->depth == 24 &&
0539                     mib->bits_per_pixel == 32))
0540             mib->depth = mib->bits_per_pixel;
0541     }
0542 
0543     if (par->vbe_modes_cnt > 0)
0544         return 0;
0545     else
0546         return -EINVAL;
0547 }
0548 
0549 /*
0550  * The Protected Mode Interface is 32-bit x86 code, so we only run it on
0551  * x86 and not x86_64.
0552  */
0553 #ifdef CONFIG_X86_32
0554 static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
0555                   struct uvesafb_par *par)
0556 {
0557     int i, err;
0558 
0559     uvesafb_reset(task);
0560     task->t.regs.eax = 0x4f0a;
0561     task->t.regs.ebx = 0x0;
0562     err = uvesafb_exec(task);
0563     if (err)
0564         return err;
0565 
0566     if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
0567         par->pmi_setpal = par->ypan = 0;
0568     } else {
0569         par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
0570                         + task->t.regs.edi);
0571         par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
0572         par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
0573         pr_info("protected mode interface info at %04x:%04x\n",
0574             (u16)task->t.regs.es, (u16)task->t.regs.edi);
0575         pr_info("pmi: set display start = %p, set palette = %p\n",
0576             par->pmi_start, par->pmi_pal);
0577 
0578         if (par->pmi_base[3]) {
0579             pr_info("pmi: ports =");
0580             for (i = par->pmi_base[3]/2;
0581                     par->pmi_base[i] != 0xffff; i++)
0582                 pr_cont(" %x", par->pmi_base[i]);
0583             pr_cont("\n");
0584 
0585             if (par->pmi_base[i] != 0xffff) {
0586                 pr_info("can't handle memory requests, pmi disabled\n");
0587                 par->ypan = par->pmi_setpal = 0;
0588             }
0589         }
0590     }
0591     return 0;
0592 }
0593 #endif /* CONFIG_X86_32 */
0594 
0595 /*
0596  * Check whether a video mode is supported by the Video BIOS and is
0597  * compatible with the monitor limits.
0598  */
0599 static int uvesafb_is_valid_mode(struct fb_videomode *mode,
0600                  struct fb_info *info)
0601 {
0602     if (info->monspecs.gtf) {
0603         fb_videomode_to_var(&info->var, mode);
0604         if (fb_validate_mode(&info->var, info))
0605             return 0;
0606     }
0607 
0608     if (uvesafb_vbe_find_mode(info->par, mode->xres, mode->yres, 8,
0609                 UVESAFB_EXACT_RES) == -1)
0610         return 0;
0611 
0612     return 1;
0613 }
0614 
0615 static int uvesafb_vbe_getedid(struct uvesafb_ktask *task, struct fb_info *info)
0616 {
0617     struct uvesafb_par *par = info->par;
0618     int err = 0;
0619 
0620     if (noedid || par->vbe_ib.vbe_version < 0x0300)
0621         return -EINVAL;
0622 
0623     task->t.regs.eax = 0x4f15;
0624     task->t.regs.ebx = 0;
0625     task->t.regs.ecx = 0;
0626     task->t.buf_len = 0;
0627     task->t.flags = 0;
0628 
0629     err = uvesafb_exec(task);
0630 
0631     if ((task->t.regs.eax & 0xffff) != 0x004f || err)
0632         return -EINVAL;
0633 
0634     if ((task->t.regs.ebx & 0x3) == 3) {
0635         pr_info("VBIOS/hardware supports both DDC1 and DDC2 transfers\n");
0636     } else if ((task->t.regs.ebx & 0x3) == 2) {
0637         pr_info("VBIOS/hardware supports DDC2 transfers\n");
0638     } else if ((task->t.regs.ebx & 0x3) == 1) {
0639         pr_info("VBIOS/hardware supports DDC1 transfers\n");
0640     } else {
0641         pr_info("VBIOS/hardware doesn't support DDC transfers\n");
0642         return -EINVAL;
0643     }
0644 
0645     task->t.regs.eax = 0x4f15;
0646     task->t.regs.ebx = 1;
0647     task->t.regs.ecx = task->t.regs.edx = 0;
0648     task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
0649     task->t.buf_len = EDID_LENGTH;
0650     task->buf = kzalloc(EDID_LENGTH, GFP_KERNEL);
0651     if (!task->buf)
0652         return -ENOMEM;
0653 
0654     err = uvesafb_exec(task);
0655 
0656     if ((task->t.regs.eax & 0xffff) == 0x004f && !err) {
0657         fb_edid_to_monspecs(task->buf, &info->monspecs);
0658 
0659         if (info->monspecs.vfmax && info->monspecs.hfmax) {
0660             /*
0661              * If the maximum pixel clock wasn't specified in
0662              * the EDID block, set it to 300 MHz.
0663              */
0664             if (info->monspecs.dclkmax == 0)
0665                 info->monspecs.dclkmax = 300 * 1000000;
0666             info->monspecs.gtf = 1;
0667         }
0668     } else {
0669         err = -EINVAL;
0670     }
0671 
0672     kfree(task->buf);
0673     return err;
0674 }
0675 
0676 static void uvesafb_vbe_getmonspecs(struct uvesafb_ktask *task,
0677                     struct fb_info *info)
0678 {
0679     struct uvesafb_par *par = info->par;
0680     int i;
0681 
0682     memset(&info->monspecs, 0, sizeof(info->monspecs));
0683 
0684     /*
0685      * If we don't get all necessary data from the EDID block,
0686      * mark it as incompatible with the GTF and set nocrtc so
0687      * that we always use the default BIOS refresh rate.
0688      */
0689     if (uvesafb_vbe_getedid(task, info)) {
0690         info->monspecs.gtf = 0;
0691         par->nocrtc = 1;
0692     }
0693 
0694     /* Kernel command line overrides. */
0695     if (maxclk)
0696         info->monspecs.dclkmax = maxclk * 1000000;
0697     if (maxvf)
0698         info->monspecs.vfmax = maxvf;
0699     if (maxhf)
0700         info->monspecs.hfmax = maxhf * 1000;
0701 
0702     /*
0703      * In case DDC transfers are not supported, the user can provide
0704      * monitor limits manually. Lower limits are set to "safe" values.
0705      */
0706     if (info->monspecs.gtf == 0 && maxclk && maxvf && maxhf) {
0707         info->monspecs.dclkmin = 0;
0708         info->monspecs.vfmin = 60;
0709         info->monspecs.hfmin = 29000;
0710         info->monspecs.gtf = 1;
0711         par->nocrtc = 0;
0712     }
0713 
0714     if (info->monspecs.gtf)
0715         pr_info("monitor limits: vf = %d Hz, hf = %d kHz, clk = %d MHz\n",
0716             info->monspecs.vfmax,
0717             (int)(info->monspecs.hfmax / 1000),
0718             (int)(info->monspecs.dclkmax / 1000000));
0719     else
0720         pr_info("no monitor limits have been set, default refresh rate will be used\n");
0721 
0722     /* Add VBE modes to the modelist. */
0723     for (i = 0; i < par->vbe_modes_cnt; i++) {
0724         struct fb_var_screeninfo var;
0725         struct vbe_mode_ib *mode;
0726         struct fb_videomode vmode;
0727 
0728         mode = &par->vbe_modes[i];
0729         memset(&var, 0, sizeof(var));
0730 
0731         var.xres = mode->x_res;
0732         var.yres = mode->y_res;
0733 
0734         fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, &var, info);
0735         fb_var_to_videomode(&vmode, &var);
0736         fb_add_videomode(&vmode, &info->modelist);
0737     }
0738 
0739     /* Add valid VESA modes to our modelist. */
0740     for (i = 0; i < VESA_MODEDB_SIZE; i++) {
0741         if (uvesafb_is_valid_mode((struct fb_videomode *)
0742                         &vesa_modes[i], info))
0743             fb_add_videomode(&vesa_modes[i], &info->modelist);
0744     }
0745 
0746     for (i = 0; i < info->monspecs.modedb_len; i++) {
0747         if (uvesafb_is_valid_mode(&info->monspecs.modedb[i], info))
0748             fb_add_videomode(&info->monspecs.modedb[i],
0749                     &info->modelist);
0750     }
0751 
0752     return;
0753 }
0754 
0755 static void uvesafb_vbe_getstatesize(struct uvesafb_ktask *task,
0756                      struct uvesafb_par *par)
0757 {
0758     int err;
0759 
0760     uvesafb_reset(task);
0761 
0762     /*
0763      * Get the VBE state buffer size. We want all available
0764      * hardware state data (CL = 0x0f).
0765      */
0766     task->t.regs.eax = 0x4f04;
0767     task->t.regs.ecx = 0x000f;
0768     task->t.regs.edx = 0x0000;
0769     task->t.flags = 0;
0770 
0771     err = uvesafb_exec(task);
0772 
0773     if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
0774         pr_warn("VBE state buffer size cannot be determined (eax=0x%x, err=%d)\n",
0775             task->t.regs.eax, err);
0776         par->vbe_state_size = 0;
0777         return;
0778     }
0779 
0780     par->vbe_state_size = 64 * (task->t.regs.ebx & 0xffff);
0781 }
0782 
0783 static int uvesafb_vbe_init(struct fb_info *info)
0784 {
0785     struct uvesafb_ktask *task = NULL;
0786     struct uvesafb_par *par = info->par;
0787     int err;
0788 
0789     task = uvesafb_prep();
0790     if (!task)
0791         return -ENOMEM;
0792 
0793     err = uvesafb_vbe_getinfo(task, par);
0794     if (err)
0795         goto out;
0796 
0797     err = uvesafb_vbe_getmodes(task, par);
0798     if (err)
0799         goto out;
0800 
0801     par->nocrtc = nocrtc;
0802 #ifdef CONFIG_X86_32
0803     par->pmi_setpal = pmi_setpal;
0804     par->ypan = ypan;
0805 
0806     if (par->pmi_setpal || par->ypan) {
0807         if (__supported_pte_mask & _PAGE_NX) {
0808             par->pmi_setpal = par->ypan = 0;
0809             pr_warn("NX protection is active, better not use the PMI\n");
0810         } else {
0811             uvesafb_vbe_getpmi(task, par);
0812         }
0813     }
0814 #else
0815     /* The protected mode interface is not available on non-x86. */
0816     par->pmi_setpal = par->ypan = 0;
0817 #endif
0818 
0819     INIT_LIST_HEAD(&info->modelist);
0820     uvesafb_vbe_getmonspecs(task, info);
0821     uvesafb_vbe_getstatesize(task, par);
0822 
0823 out:    uvesafb_free(task);
0824     return err;
0825 }
0826 
0827 static int uvesafb_vbe_init_mode(struct fb_info *info)
0828 {
0829     struct list_head *pos;
0830     struct fb_modelist *modelist;
0831     struct fb_videomode *mode;
0832     struct uvesafb_par *par = info->par;
0833     int i, modeid;
0834 
0835     /* Has the user requested a specific VESA mode? */
0836     if (vbemode) {
0837         for (i = 0; i < par->vbe_modes_cnt; i++) {
0838             if (par->vbe_modes[i].mode_id == vbemode) {
0839                 modeid = i;
0840                 uvesafb_setup_var(&info->var, info,
0841                         &par->vbe_modes[modeid]);
0842                 fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
0843                         &info->var, info);
0844                 /*
0845                  * With pixclock set to 0, the default BIOS
0846                  * timings will be used in set_par().
0847                  */
0848                 info->var.pixclock = 0;
0849                 goto gotmode;
0850             }
0851         }
0852         pr_info("requested VBE mode 0x%x is unavailable\n", vbemode);
0853         vbemode = 0;
0854     }
0855 
0856     /* Count the modes in the modelist */
0857     i = 0;
0858     list_for_each(pos, &info->modelist)
0859         i++;
0860 
0861     /*
0862      * Convert the modelist into a modedb so that we can use it with
0863      * fb_find_mode().
0864      */
0865     mode = kcalloc(i, sizeof(*mode), GFP_KERNEL);
0866     if (mode) {
0867         i = 0;
0868         list_for_each(pos, &info->modelist) {
0869             modelist = list_entry(pos, struct fb_modelist, list);
0870             mode[i] = modelist->mode;
0871             i++;
0872         }
0873 
0874         if (!mode_option)
0875             mode_option = UVESAFB_DEFAULT_MODE;
0876 
0877         i = fb_find_mode(&info->var, info, mode_option, mode, i,
0878             NULL, 8);
0879 
0880         kfree(mode);
0881     }
0882 
0883     /* fb_find_mode() failed */
0884     if (i == 0) {
0885         info->var.xres = 640;
0886         info->var.yres = 480;
0887         mode = (struct fb_videomode *)
0888                 fb_find_best_mode(&info->var, &info->modelist);
0889 
0890         if (mode) {
0891             fb_videomode_to_var(&info->var, mode);
0892         } else {
0893             modeid = par->vbe_modes[0].mode_id;
0894             uvesafb_setup_var(&info->var, info,
0895                     &par->vbe_modes[modeid]);
0896             fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
0897                     &info->var, info);
0898 
0899             goto gotmode;
0900         }
0901     }
0902 
0903     /* Look for a matching VBE mode. */
0904     modeid = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres,
0905             info->var.bits_per_pixel, UVESAFB_EXACT_RES);
0906 
0907     if (modeid == -1)
0908         return -EINVAL;
0909 
0910     uvesafb_setup_var(&info->var, info, &par->vbe_modes[modeid]);
0911 
0912 gotmode:
0913     /*
0914      * If we are not VBE3.0+ compliant, we're done -- the BIOS will
0915      * ignore our timings anyway.
0916      */
0917     if (par->vbe_ib.vbe_version < 0x0300 || par->nocrtc)
0918         fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
0919                     &info->var, info);
0920 
0921     return modeid;
0922 }
0923 
0924 static int uvesafb_setpalette(struct uvesafb_pal_entry *entries, int count,
0925         int start, struct fb_info *info)
0926 {
0927     struct uvesafb_ktask *task;
0928 #ifdef CONFIG_X86
0929     struct uvesafb_par *par = info->par;
0930     int i = par->mode_idx;
0931 #endif
0932     int err = 0;
0933 
0934     /*
0935      * We support palette modifications for 8 bpp modes only, so
0936      * there can never be more than 256 entries.
0937      */
0938     if (start + count > 256)
0939         return -EINVAL;
0940 
0941 #ifdef CONFIG_X86
0942     /* Use VGA registers if mode is VGA-compatible. */
0943     if (i >= 0 && i < par->vbe_modes_cnt &&
0944         par->vbe_modes[i].mode_attr & VBE_MODE_VGACOMPAT) {
0945         for (i = 0; i < count; i++) {
0946             outb_p(start + i,        dac_reg);
0947             outb_p(entries[i].red,   dac_val);
0948             outb_p(entries[i].green, dac_val);
0949             outb_p(entries[i].blue,  dac_val);
0950         }
0951     }
0952 #ifdef CONFIG_X86_32
0953     else if (par->pmi_setpal) {
0954         __asm__ __volatile__(
0955         "call *(%%esi)"
0956         : /* no return value */
0957         : "a" (0x4f09),         /* EAX */
0958           "b" (0),              /* EBX */
0959           "c" (count),          /* ECX */
0960           "d" (start),          /* EDX */
0961           "D" (entries),        /* EDI */
0962           "S" (&par->pmi_pal)); /* ESI */
0963     }
0964 #endif /* CONFIG_X86_32 */
0965     else
0966 #endif /* CONFIG_X86 */
0967     {
0968         task = uvesafb_prep();
0969         if (!task)
0970             return -ENOMEM;
0971 
0972         task->t.regs.eax = 0x4f09;
0973         task->t.regs.ebx = 0x0;
0974         task->t.regs.ecx = count;
0975         task->t.regs.edx = start;
0976         task->t.flags = TF_BUF_ESDI;
0977         task->t.buf_len = sizeof(struct uvesafb_pal_entry) * count;
0978         task->buf = entries;
0979 
0980         err = uvesafb_exec(task);
0981         if ((task->t.regs.eax & 0xffff) != 0x004f)
0982             err = 1;
0983 
0984         uvesafb_free(task);
0985     }
0986     return err;
0987 }
0988 
0989 static int uvesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
0990         unsigned blue, unsigned transp,
0991         struct fb_info *info)
0992 {
0993     struct uvesafb_pal_entry entry;
0994     int shift = 16 - dac_width;
0995     int err = 0;
0996 
0997     if (regno >= info->cmap.len)
0998         return -EINVAL;
0999 
1000     if (info->var.bits_per_pixel == 8) {
1001         entry.red   = red   >> shift;
1002         entry.green = green >> shift;
1003         entry.blue  = blue  >> shift;
1004         entry.pad   = 0;
1005 
1006         err = uvesafb_setpalette(&entry, 1, regno, info);
1007     } else if (regno < 16) {
1008         switch (info->var.bits_per_pixel) {
1009         case 16:
1010             if (info->var.red.offset == 10) {
1011                 /* 1:5:5:5 */
1012                 ((u32 *) (info->pseudo_palette))[regno] =
1013                         ((red   & 0xf800) >>  1) |
1014                         ((green & 0xf800) >>  6) |
1015                         ((blue  & 0xf800) >> 11);
1016             } else {
1017                 /* 0:5:6:5 */
1018                 ((u32 *) (info->pseudo_palette))[regno] =
1019                         ((red   & 0xf800)      ) |
1020                         ((green & 0xfc00) >>  5) |
1021                         ((blue  & 0xf800) >> 11);
1022             }
1023             break;
1024 
1025         case 24:
1026         case 32:
1027             red   >>= 8;
1028             green >>= 8;
1029             blue  >>= 8;
1030             ((u32 *)(info->pseudo_palette))[regno] =
1031                 (red   << info->var.red.offset)   |
1032                 (green << info->var.green.offset) |
1033                 (blue  << info->var.blue.offset);
1034             break;
1035         }
1036     }
1037     return err;
1038 }
1039 
1040 static int uvesafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1041 {
1042     struct uvesafb_pal_entry *entries;
1043     int shift = 16 - dac_width;
1044     int i, err = 0;
1045 
1046     if (info->var.bits_per_pixel == 8) {
1047         if (cmap->start + cmap->len > info->cmap.start +
1048             info->cmap.len || cmap->start < info->cmap.start)
1049             return -EINVAL;
1050 
1051         entries = kmalloc_array(cmap->len, sizeof(*entries),
1052                     GFP_KERNEL);
1053         if (!entries)
1054             return -ENOMEM;
1055 
1056         for (i = 0; i < cmap->len; i++) {
1057             entries[i].red   = cmap->red[i]   >> shift;
1058             entries[i].green = cmap->green[i] >> shift;
1059             entries[i].blue  = cmap->blue[i]  >> shift;
1060             entries[i].pad   = 0;
1061         }
1062         err = uvesafb_setpalette(entries, cmap->len, cmap->start, info);
1063         kfree(entries);
1064     } else {
1065         /*
1066          * For modes with bpp > 8, we only set the pseudo palette in
1067          * the fb_info struct. We rely on uvesafb_setcolreg to do all
1068          * sanity checking.
1069          */
1070         for (i = 0; i < cmap->len; i++) {
1071             err |= uvesafb_setcolreg(cmap->start + i, cmap->red[i],
1072                         cmap->green[i], cmap->blue[i],
1073                         0, info);
1074         }
1075     }
1076     return err;
1077 }
1078 
1079 static int uvesafb_pan_display(struct fb_var_screeninfo *var,
1080         struct fb_info *info)
1081 {
1082 #ifdef CONFIG_X86_32
1083     int offset;
1084     struct uvesafb_par *par = info->par;
1085 
1086     offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
1087 
1088     /*
1089      * It turns out it's not the best idea to do panning via vm86,
1090      * so we only allow it if we have a PMI.
1091      */
1092     if (par->pmi_start) {
1093         __asm__ __volatile__(
1094             "call *(%%edi)"
1095             : /* no return value */
1096             : "a" (0x4f07),         /* EAX */
1097               "b" (0),              /* EBX */
1098               "c" (offset),         /* ECX */
1099               "d" (offset >> 16),   /* EDX */
1100               "D" (&par->pmi_start));    /* EDI */
1101     }
1102 #endif
1103     return 0;
1104 }
1105 
1106 static int uvesafb_blank(int blank, struct fb_info *info)
1107 {
1108     struct uvesafb_ktask *task;
1109     int err = 1;
1110 #ifdef CONFIG_X86
1111     struct uvesafb_par *par = info->par;
1112 
1113     if (par->vbe_ib.capabilities & VBE_CAP_VGACOMPAT) {
1114         int loop = 10000;
1115         u8 seq = 0, crtc17 = 0;
1116 
1117         if (blank == FB_BLANK_POWERDOWN) {
1118             seq = 0x20;
1119             crtc17 = 0x00;
1120             err = 0;
1121         } else {
1122             seq = 0x00;
1123             crtc17 = 0x80;
1124             err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;
1125         }
1126 
1127         vga_wseq(NULL, 0x00, 0x01);
1128         seq |= vga_rseq(NULL, 0x01) & ~0x20;
1129         vga_wseq(NULL, 0x00, seq);
1130 
1131         crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
1132         while (loop--);
1133         vga_wcrt(NULL, 0x17, crtc17);
1134         vga_wseq(NULL, 0x00, 0x03);
1135     } else
1136 #endif /* CONFIG_X86 */
1137     {
1138         task = uvesafb_prep();
1139         if (!task)
1140             return -ENOMEM;
1141 
1142         task->t.regs.eax = 0x4f10;
1143         switch (blank) {
1144         case FB_BLANK_UNBLANK:
1145             task->t.regs.ebx = 0x0001;
1146             break;
1147         case FB_BLANK_NORMAL:
1148             task->t.regs.ebx = 0x0101;  /* standby */
1149             break;
1150         case FB_BLANK_POWERDOWN:
1151             task->t.regs.ebx = 0x0401;  /* powerdown */
1152             break;
1153         default:
1154             goto out;
1155         }
1156 
1157         err = uvesafb_exec(task);
1158         if (err || (task->t.regs.eax & 0xffff) != 0x004f)
1159             err = 1;
1160 out:        uvesafb_free(task);
1161     }
1162     return err;
1163 }
1164 
1165 static int uvesafb_open(struct fb_info *info, int user)
1166 {
1167     struct uvesafb_par *par = info->par;
1168     int cnt = atomic_read(&par->ref_count);
1169     u8 *buf = NULL;
1170 
1171     if (!cnt && par->vbe_state_size) {
1172         buf =  uvesafb_vbe_state_save(par);
1173         if (IS_ERR(buf)) {
1174             pr_warn("save hardware state failed, error code is %ld!\n",
1175                 PTR_ERR(buf));
1176         } else {
1177             par->vbe_state_orig = buf;
1178         }
1179     }
1180 
1181     atomic_inc(&par->ref_count);
1182     return 0;
1183 }
1184 
1185 static int uvesafb_release(struct fb_info *info, int user)
1186 {
1187     struct uvesafb_ktask *task = NULL;
1188     struct uvesafb_par *par = info->par;
1189     int cnt = atomic_read(&par->ref_count);
1190 
1191     if (!cnt)
1192         return -EINVAL;
1193 
1194     if (cnt != 1)
1195         goto out;
1196 
1197     task = uvesafb_prep();
1198     if (!task)
1199         goto out;
1200 
1201     /* First, try to set the standard 80x25 text mode. */
1202     task->t.regs.eax = 0x0003;
1203     uvesafb_exec(task);
1204 
1205     /*
1206      * Now try to restore whatever hardware state we might have
1207      * saved when the fb device was first opened.
1208      */
1209     uvesafb_vbe_state_restore(par, par->vbe_state_orig);
1210 out:
1211     atomic_dec(&par->ref_count);
1212     uvesafb_free(task);
1213     return 0;
1214 }
1215 
1216 static int uvesafb_set_par(struct fb_info *info)
1217 {
1218     struct uvesafb_par *par = info->par;
1219     struct uvesafb_ktask *task = NULL;
1220     struct vbe_crtc_ib *crtc = NULL;
1221     struct vbe_mode_ib *mode = NULL;
1222     int i, err = 0, depth = info->var.bits_per_pixel;
1223 
1224     if (depth > 8 && depth != 32)
1225         depth = info->var.red.length + info->var.green.length +
1226             info->var.blue.length;
1227 
1228     i = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres, depth,
1229                  UVESAFB_EXACT_RES | UVESAFB_EXACT_DEPTH);
1230     if (i >= 0)
1231         mode = &par->vbe_modes[i];
1232     else
1233         return -EINVAL;
1234 
1235     task = uvesafb_prep();
1236     if (!task)
1237         return -ENOMEM;
1238 setmode:
1239     task->t.regs.eax = 0x4f02;
1240     task->t.regs.ebx = mode->mode_id | 0x4000;  /* use LFB */
1241 
1242     if (par->vbe_ib.vbe_version >= 0x0300 && !par->nocrtc &&
1243         info->var.pixclock != 0) {
1244         task->t.regs.ebx |= 0x0800;     /* use CRTC data */
1245         task->t.flags = TF_BUF_ESDI;
1246         crtc = kzalloc(sizeof(struct vbe_crtc_ib), GFP_KERNEL);
1247         if (!crtc) {
1248             err = -ENOMEM;
1249             goto out;
1250         }
1251         crtc->horiz_start = info->var.xres + info->var.right_margin;
1252         crtc->horiz_end   = crtc->horiz_start + info->var.hsync_len;
1253         crtc->horiz_total = crtc->horiz_end + info->var.left_margin;
1254 
1255         crtc->vert_start  = info->var.yres + info->var.lower_margin;
1256         crtc->vert_end    = crtc->vert_start + info->var.vsync_len;
1257         crtc->vert_total  = crtc->vert_end + info->var.upper_margin;
1258 
1259         crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;
1260         crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /
1261                 (crtc->vert_total * crtc->horiz_total)));
1262 
1263         if (info->var.vmode & FB_VMODE_DOUBLE)
1264             crtc->flags |= 0x1;
1265         if (info->var.vmode & FB_VMODE_INTERLACED)
1266             crtc->flags |= 0x2;
1267         if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
1268             crtc->flags |= 0x4;
1269         if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
1270             crtc->flags |= 0x8;
1271         memcpy(&par->crtc, crtc, sizeof(*crtc));
1272     } else {
1273         memset(&par->crtc, 0, sizeof(*crtc));
1274     }
1275 
1276     task->t.buf_len = sizeof(struct vbe_crtc_ib);
1277     task->buf = &par->crtc;
1278 
1279     err = uvesafb_exec(task);
1280     if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
1281         /*
1282          * The mode switch might have failed because we tried to
1283          * use our own timings.  Try again with the default timings.
1284          */
1285         if (crtc != NULL) {
1286             pr_warn("mode switch failed (eax=0x%x, err=%d) - trying again with default timings\n",
1287                 task->t.regs.eax, err);
1288             uvesafb_reset(task);
1289             kfree(crtc);
1290             crtc = NULL;
1291             info->var.pixclock = 0;
1292             goto setmode;
1293         } else {
1294             pr_err("mode switch failed (eax=0x%x, err=%d)\n",
1295                    task->t.regs.eax, err);
1296             err = -EINVAL;
1297             goto out;
1298         }
1299     }
1300     par->mode_idx = i;
1301 
1302     /* For 8bpp modes, always try to set the DAC to 8 bits. */
1303     if (par->vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&
1304         mode->bits_per_pixel <= 8) {
1305         uvesafb_reset(task);
1306         task->t.regs.eax = 0x4f08;
1307         task->t.regs.ebx = 0x0800;
1308 
1309         err = uvesafb_exec(task);
1310         if (err || (task->t.regs.eax & 0xffff) != 0x004f ||
1311             ((task->t.regs.ebx & 0xff00) >> 8) != 8) {
1312             dac_width = 6;
1313         } else {
1314             dac_width = 8;
1315         }
1316     }
1317 
1318     info->fix.visual = (info->var.bits_per_pixel == 8) ?
1319                 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1320     info->fix.line_length = mode->bytes_per_scan_line;
1321 
1322 out:
1323     kfree(crtc);
1324     uvesafb_free(task);
1325 
1326     return err;
1327 }
1328 
1329 static void uvesafb_check_limits(struct fb_var_screeninfo *var,
1330         struct fb_info *info)
1331 {
1332     const struct fb_videomode *mode;
1333     struct uvesafb_par *par = info->par;
1334 
1335     /*
1336      * If pixclock is set to 0, then we're using default BIOS timings
1337      * and thus don't have to perform any checks here.
1338      */
1339     if (!var->pixclock)
1340         return;
1341 
1342     if (par->vbe_ib.vbe_version < 0x0300) {
1343         fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);
1344         return;
1345     }
1346 
1347     if (!fb_validate_mode(var, info))
1348         return;
1349 
1350     mode = fb_find_best_mode(var, &info->modelist);
1351     if (mode) {
1352         if (mode->xres == var->xres && mode->yres == var->yres &&
1353             !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {
1354             fb_videomode_to_var(var, mode);
1355             return;
1356         }
1357     }
1358 
1359     if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1360         return;
1361     /* Use default refresh rate */
1362     var->pixclock = 0;
1363 }
1364 
1365 static int uvesafb_check_var(struct fb_var_screeninfo *var,
1366         struct fb_info *info)
1367 {
1368     struct uvesafb_par *par = info->par;
1369     struct vbe_mode_ib *mode = NULL;
1370     int match = -1;
1371     int depth = var->red.length + var->green.length + var->blue.length;
1372 
1373     /*
1374      * Various apps will use bits_per_pixel to set the color depth,
1375      * which is theoretically incorrect, but which we'll try to handle
1376      * here.
1377      */
1378     if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)
1379         depth = var->bits_per_pixel;
1380 
1381     match = uvesafb_vbe_find_mode(par, var->xres, var->yres, depth,
1382                         UVESAFB_EXACT_RES);
1383     if (match == -1)
1384         return -EINVAL;
1385 
1386     mode = &par->vbe_modes[match];
1387     uvesafb_setup_var(var, info, mode);
1388 
1389     /*
1390      * Check whether we have remapped enough memory for this mode.
1391      * We might be called at an early stage, when we haven't remapped
1392      * any memory yet, in which case we simply skip the check.
1393      */
1394     if (var->yres * mode->bytes_per_scan_line > info->fix.smem_len
1395                         && info->fix.smem_len)
1396         return -EINVAL;
1397 
1398     if ((var->vmode & FB_VMODE_DOUBLE) &&
1399                 !(par->vbe_modes[match].mode_attr & 0x100))
1400         var->vmode &= ~FB_VMODE_DOUBLE;
1401 
1402     if ((var->vmode & FB_VMODE_INTERLACED) &&
1403                 !(par->vbe_modes[match].mode_attr & 0x200))
1404         var->vmode &= ~FB_VMODE_INTERLACED;
1405 
1406     uvesafb_check_limits(var, info);
1407 
1408     var->xres_virtual = var->xres;
1409     var->yres_virtual = (par->ypan) ?
1410                 info->fix.smem_len / mode->bytes_per_scan_line :
1411                 var->yres;
1412     return 0;
1413 }
1414 
1415 static struct fb_ops uvesafb_ops = {
1416     .owner      = THIS_MODULE,
1417     .fb_open    = uvesafb_open,
1418     .fb_release = uvesafb_release,
1419     .fb_setcolreg   = uvesafb_setcolreg,
1420     .fb_setcmap = uvesafb_setcmap,
1421     .fb_pan_display = uvesafb_pan_display,
1422     .fb_blank   = uvesafb_blank,
1423     .fb_fillrect    = cfb_fillrect,
1424     .fb_copyarea    = cfb_copyarea,
1425     .fb_imageblit   = cfb_imageblit,
1426     .fb_check_var   = uvesafb_check_var,
1427     .fb_set_par = uvesafb_set_par,
1428 };
1429 
1430 static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
1431 {
1432     unsigned int size_vmode;
1433     unsigned int size_remap;
1434     unsigned int size_total;
1435     struct uvesafb_par *par = info->par;
1436     int i, h;
1437 
1438     info->pseudo_palette = ((u8 *)info->par + sizeof(struct uvesafb_par));
1439     info->fix = uvesafb_fix;
1440     info->fix.ypanstep = par->ypan ? 1 : 0;
1441     info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
1442 
1443     /* Disable blanking if the user requested so. */
1444     if (!blank)
1445         uvesafb_ops.fb_blank = NULL;
1446 
1447     /*
1448      * Find out how much IO memory is required for the mode with
1449      * the highest resolution.
1450      */
1451     size_remap = 0;
1452     for (i = 0; i < par->vbe_modes_cnt; i++) {
1453         h = par->vbe_modes[i].bytes_per_scan_line *
1454                     par->vbe_modes[i].y_res;
1455         if (h > size_remap)
1456             size_remap = h;
1457     }
1458     size_remap *= 2;
1459 
1460     /*
1461      *   size_vmode -- that is the amount of memory needed for the
1462      *                 used video mode, i.e. the minimum amount of
1463      *                 memory we need.
1464      */
1465     size_vmode = info->var.yres * mode->bytes_per_scan_line;
1466 
1467     /*
1468      *   size_total -- all video memory we have. Used for mtrr
1469      *                 entries, resource allocation and bounds
1470      *                 checking.
1471      */
1472     size_total = par->vbe_ib.total_memory * 65536;
1473     if (vram_total)
1474         size_total = vram_total * 1024 * 1024;
1475     if (size_total < size_vmode)
1476         size_total = size_vmode;
1477 
1478     /*
1479      *   size_remap -- the amount of video memory we are going to
1480      *                 use for vesafb.  With modern cards it is no
1481      *                 option to simply use size_total as th
1482      *                 wastes plenty of kernel address space.
1483      */
1484     if (vram_remap)
1485         size_remap = vram_remap * 1024 * 1024;
1486     if (size_remap < size_vmode)
1487         size_remap = size_vmode;
1488     if (size_remap > size_total)
1489         size_remap = size_total;
1490 
1491     info->fix.smem_len = size_remap;
1492     info->fix.smem_start = mode->phys_base_ptr;
1493 
1494     /*
1495      * We have to set yres_virtual here because when setup_var() was
1496      * called, smem_len wasn't defined yet.
1497      */
1498     info->var.yres_virtual = info->fix.smem_len /
1499                  mode->bytes_per_scan_line;
1500 
1501     if (par->ypan && info->var.yres_virtual > info->var.yres) {
1502         pr_info("scrolling: %s using protected mode interface, yres_virtual=%d\n",
1503             (par->ypan > 1) ? "ywrap" : "ypan",
1504             info->var.yres_virtual);
1505     } else {
1506         pr_info("scrolling: redraw\n");
1507         info->var.yres_virtual = info->var.yres;
1508         par->ypan = 0;
1509     }
1510 
1511     info->flags = FBINFO_FLAG_DEFAULT |
1512             (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
1513 
1514     if (!par->ypan)
1515         uvesafb_ops.fb_pan_display = NULL;
1516 }
1517 
1518 static void uvesafb_init_mtrr(struct fb_info *info)
1519 {
1520     struct uvesafb_par *par = info->par;
1521 
1522     if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
1523         int temp_size = info->fix.smem_len;
1524 
1525         int rc;
1526 
1527         /* Find the largest power-of-two */
1528         temp_size = roundup_pow_of_two(temp_size);
1529 
1530         /* Try and find a power of two to add */
1531         do {
1532             rc = arch_phys_wc_add(info->fix.smem_start, temp_size);
1533             temp_size >>= 1;
1534         } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
1535 
1536         if (rc >= 0)
1537             par->mtrr_handle = rc;
1538     }
1539 }
1540 
1541 static void uvesafb_ioremap(struct fb_info *info)
1542 {
1543     info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
1544 }
1545 
1546 static ssize_t uvesafb_show_vbe_ver(struct device *dev,
1547         struct device_attribute *attr, char *buf)
1548 {
1549     struct fb_info *info = dev_get_drvdata(dev);
1550     struct uvesafb_par *par = info->par;
1551 
1552     return snprintf(buf, PAGE_SIZE, "%.4x\n", par->vbe_ib.vbe_version);
1553 }
1554 
1555 static DEVICE_ATTR(vbe_version, S_IRUGO, uvesafb_show_vbe_ver, NULL);
1556 
1557 static ssize_t uvesafb_show_vbe_modes(struct device *dev,
1558         struct device_attribute *attr, char *buf)
1559 {
1560     struct fb_info *info = dev_get_drvdata(dev);
1561     struct uvesafb_par *par = info->par;
1562     int ret = 0, i;
1563 
1564     for (i = 0; i < par->vbe_modes_cnt && ret < PAGE_SIZE; i++) {
1565         ret += scnprintf(buf + ret, PAGE_SIZE - ret,
1566             "%dx%d-%d, 0x%.4x\n",
1567             par->vbe_modes[i].x_res, par->vbe_modes[i].y_res,
1568             par->vbe_modes[i].depth, par->vbe_modes[i].mode_id);
1569     }
1570 
1571     return ret;
1572 }
1573 
1574 static DEVICE_ATTR(vbe_modes, S_IRUGO, uvesafb_show_vbe_modes, NULL);
1575 
1576 static ssize_t uvesafb_show_vendor(struct device *dev,
1577         struct device_attribute *attr, char *buf)
1578 {
1579     struct fb_info *info = dev_get_drvdata(dev);
1580     struct uvesafb_par *par = info->par;
1581 
1582     if (par->vbe_ib.oem_vendor_name_ptr)
1583         return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
1584             (&par->vbe_ib) + par->vbe_ib.oem_vendor_name_ptr);
1585     else
1586         return 0;
1587 }
1588 
1589 static DEVICE_ATTR(oem_vendor, S_IRUGO, uvesafb_show_vendor, NULL);
1590 
1591 static ssize_t uvesafb_show_product_name(struct device *dev,
1592         struct device_attribute *attr, char *buf)
1593 {
1594     struct fb_info *info = dev_get_drvdata(dev);
1595     struct uvesafb_par *par = info->par;
1596 
1597     if (par->vbe_ib.oem_product_name_ptr)
1598         return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
1599             (&par->vbe_ib) + par->vbe_ib.oem_product_name_ptr);
1600     else
1601         return 0;
1602 }
1603 
1604 static DEVICE_ATTR(oem_product_name, S_IRUGO, uvesafb_show_product_name, NULL);
1605 
1606 static ssize_t uvesafb_show_product_rev(struct device *dev,
1607         struct device_attribute *attr, char *buf)
1608 {
1609     struct fb_info *info = dev_get_drvdata(dev);
1610     struct uvesafb_par *par = info->par;
1611 
1612     if (par->vbe_ib.oem_product_rev_ptr)
1613         return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
1614             (&par->vbe_ib) + par->vbe_ib.oem_product_rev_ptr);
1615     else
1616         return 0;
1617 }
1618 
1619 static DEVICE_ATTR(oem_product_rev, S_IRUGO, uvesafb_show_product_rev, NULL);
1620 
1621 static ssize_t uvesafb_show_oem_string(struct device *dev,
1622         struct device_attribute *attr, char *buf)
1623 {
1624     struct fb_info *info = dev_get_drvdata(dev);
1625     struct uvesafb_par *par = info->par;
1626 
1627     if (par->vbe_ib.oem_string_ptr)
1628         return snprintf(buf, PAGE_SIZE, "%s\n",
1629             (char *)(&par->vbe_ib) + par->vbe_ib.oem_string_ptr);
1630     else
1631         return 0;
1632 }
1633 
1634 static DEVICE_ATTR(oem_string, S_IRUGO, uvesafb_show_oem_string, NULL);
1635 
1636 static ssize_t uvesafb_show_nocrtc(struct device *dev,
1637         struct device_attribute *attr, char *buf)
1638 {
1639     struct fb_info *info = dev_get_drvdata(dev);
1640     struct uvesafb_par *par = info->par;
1641 
1642     return snprintf(buf, PAGE_SIZE, "%d\n", par->nocrtc);
1643 }
1644 
1645 static ssize_t uvesafb_store_nocrtc(struct device *dev,
1646         struct device_attribute *attr, const char *buf, size_t count)
1647 {
1648     struct fb_info *info = dev_get_drvdata(dev);
1649     struct uvesafb_par *par = info->par;
1650 
1651     if (count > 0) {
1652         if (buf[0] == '0')
1653             par->nocrtc = 0;
1654         else
1655             par->nocrtc = 1;
1656     }
1657     return count;
1658 }
1659 
1660 static DEVICE_ATTR(nocrtc, S_IRUGO | S_IWUSR, uvesafb_show_nocrtc,
1661             uvesafb_store_nocrtc);
1662 
1663 static struct attribute *uvesafb_dev_attrs[] = {
1664     &dev_attr_vbe_version.attr,
1665     &dev_attr_vbe_modes.attr,
1666     &dev_attr_oem_vendor.attr,
1667     &dev_attr_oem_product_name.attr,
1668     &dev_attr_oem_product_rev.attr,
1669     &dev_attr_oem_string.attr,
1670     &dev_attr_nocrtc.attr,
1671     NULL,
1672 };
1673 
1674 static const struct attribute_group uvesafb_dev_attgrp = {
1675     .name = NULL,
1676     .attrs = uvesafb_dev_attrs,
1677 };
1678 
1679 static int uvesafb_probe(struct platform_device *dev)
1680 {
1681     struct fb_info *info;
1682     struct vbe_mode_ib *mode = NULL;
1683     struct uvesafb_par *par;
1684     int err = 0, i;
1685 
1686     info = framebuffer_alloc(sizeof(*par) + sizeof(u32) * 256, &dev->dev);
1687     if (!info)
1688         return -ENOMEM;
1689 
1690     par = info->par;
1691 
1692     err = uvesafb_vbe_init(info);
1693     if (err) {
1694         pr_err("vbe_init() failed with %d\n", err);
1695         goto out;
1696     }
1697 
1698     info->fbops = &uvesafb_ops;
1699 
1700     i = uvesafb_vbe_init_mode(info);
1701     if (i < 0) {
1702         err = -EINVAL;
1703         goto out;
1704     } else {
1705         mode = &par->vbe_modes[i];
1706     }
1707 
1708     if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
1709         err = -ENXIO;
1710         goto out;
1711     }
1712 
1713     uvesafb_init_info(info, mode);
1714 
1715     if (!request_region(0x3c0, 32, "uvesafb")) {
1716         pr_err("request region 0x3c0-0x3e0 failed\n");
1717         err = -EIO;
1718         goto out_mode;
1719     }
1720 
1721     if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
1722                 "uvesafb")) {
1723         pr_err("cannot reserve video memory at 0x%lx\n",
1724                info->fix.smem_start);
1725         err = -EIO;
1726         goto out_reg;
1727     }
1728 
1729     uvesafb_init_mtrr(info);
1730     uvesafb_ioremap(info);
1731 
1732     if (!info->screen_base) {
1733         pr_err("abort, cannot ioremap 0x%x bytes of video memory at 0x%lx\n",
1734                info->fix.smem_len, info->fix.smem_start);
1735         err = -EIO;
1736         goto out_mem;
1737     }
1738 
1739     platform_set_drvdata(dev, info);
1740 
1741     if (register_framebuffer(info) < 0) {
1742         pr_err("failed to register framebuffer device\n");
1743         err = -EINVAL;
1744         goto out_unmap;
1745     }
1746 
1747     pr_info("framebuffer at 0x%lx, mapped to 0x%p, using %dk, total %dk\n",
1748         info->fix.smem_start, info->screen_base,
1749         info->fix.smem_len / 1024, par->vbe_ib.total_memory * 64);
1750     fb_info(info, "%s frame buffer device\n", info->fix.id);
1751 
1752     err = sysfs_create_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
1753     if (err != 0)
1754         fb_warn(info, "failed to register attributes\n");
1755 
1756     return 0;
1757 
1758 out_unmap:
1759     iounmap(info->screen_base);
1760 out_mem:
1761     release_mem_region(info->fix.smem_start, info->fix.smem_len);
1762 out_reg:
1763     release_region(0x3c0, 32);
1764 out_mode:
1765     if (!list_empty(&info->modelist))
1766         fb_destroy_modelist(&info->modelist);
1767     fb_destroy_modedb(info->monspecs.modedb);
1768     fb_dealloc_cmap(&info->cmap);
1769 out:
1770     kfree(par->vbe_modes);
1771 
1772     framebuffer_release(info);
1773     return err;
1774 }
1775 
1776 static int uvesafb_remove(struct platform_device *dev)
1777 {
1778     struct fb_info *info = platform_get_drvdata(dev);
1779 
1780     if (info) {
1781         struct uvesafb_par *par = info->par;
1782 
1783         sysfs_remove_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
1784         unregister_framebuffer(info);
1785         release_region(0x3c0, 32);
1786         iounmap(info->screen_base);
1787         arch_phys_wc_del(par->mtrr_handle);
1788         release_mem_region(info->fix.smem_start, info->fix.smem_len);
1789         fb_destroy_modedb(info->monspecs.modedb);
1790         fb_dealloc_cmap(&info->cmap);
1791 
1792         kfree(par->vbe_modes);
1793         kfree(par->vbe_state_orig);
1794         kfree(par->vbe_state_saved);
1795 
1796         framebuffer_release(info);
1797     }
1798     return 0;
1799 }
1800 
1801 static struct platform_driver uvesafb_driver = {
1802     .probe  = uvesafb_probe,
1803     .remove = uvesafb_remove,
1804     .driver = {
1805         .name = "uvesafb",
1806     },
1807 };
1808 
1809 static struct platform_device *uvesafb_device;
1810 
1811 #ifndef MODULE
1812 static int uvesafb_setup(char *options)
1813 {
1814     char *this_opt;
1815 
1816     if (!options || !*options)
1817         return 0;
1818 
1819     while ((this_opt = strsep(&options, ",")) != NULL) {
1820         if (!*this_opt) continue;
1821 
1822         if (!strcmp(this_opt, "redraw"))
1823             ypan = 0;
1824         else if (!strcmp(this_opt, "ypan"))
1825             ypan = 1;
1826         else if (!strcmp(this_opt, "ywrap"))
1827             ypan = 2;
1828         else if (!strcmp(this_opt, "vgapal"))
1829             pmi_setpal = false;
1830         else if (!strcmp(this_opt, "pmipal"))
1831             pmi_setpal = true;
1832         else if (!strncmp(this_opt, "mtrr:", 5))
1833             mtrr = simple_strtoul(this_opt+5, NULL, 0);
1834         else if (!strcmp(this_opt, "nomtrr"))
1835             mtrr = 0;
1836         else if (!strcmp(this_opt, "nocrtc"))
1837             nocrtc = true;
1838         else if (!strcmp(this_opt, "noedid"))
1839             noedid = true;
1840         else if (!strcmp(this_opt, "noblank"))
1841             blank = false;
1842         else if (!strncmp(this_opt, "vtotal:", 7))
1843             vram_total = simple_strtoul(this_opt + 7, NULL, 0);
1844         else if (!strncmp(this_opt, "vremap:", 7))
1845             vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
1846         else if (!strncmp(this_opt, "maxhf:", 6))
1847             maxhf = simple_strtoul(this_opt + 6, NULL, 0);
1848         else if (!strncmp(this_opt, "maxvf:", 6))
1849             maxvf = simple_strtoul(this_opt + 6, NULL, 0);
1850         else if (!strncmp(this_opt, "maxclk:", 7))
1851             maxclk = simple_strtoul(this_opt + 7, NULL, 0);
1852         else if (!strncmp(this_opt, "vbemode:", 8))
1853             vbemode = simple_strtoul(this_opt + 8, NULL, 0);
1854         else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
1855             mode_option = this_opt;
1856         } else {
1857             pr_warn("unrecognized option %s\n", this_opt);
1858         }
1859     }
1860 
1861     if (mtrr != 3 && mtrr != 0)
1862         pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr);
1863 
1864     return 0;
1865 }
1866 #endif /* !MODULE */
1867 
1868 static ssize_t v86d_show(struct device_driver *dev, char *buf)
1869 {
1870     return snprintf(buf, PAGE_SIZE, "%s\n", v86d_path);
1871 }
1872 
1873 static ssize_t v86d_store(struct device_driver *dev, const char *buf,
1874         size_t count)
1875 {
1876     strncpy(v86d_path, buf, PATH_MAX - 1);
1877     return count;
1878 }
1879 static DRIVER_ATTR_RW(v86d);
1880 
1881 static int uvesafb_init(void)
1882 {
1883     int err;
1884 
1885 #ifndef MODULE
1886     char *option = NULL;
1887 
1888     if (fb_get_options("uvesafb", &option))
1889         return -ENODEV;
1890     uvesafb_setup(option);
1891 #endif
1892     err = cn_add_callback(&uvesafb_cn_id, "uvesafb", uvesafb_cn_callback);
1893     if (err)
1894         return err;
1895 
1896     err = platform_driver_register(&uvesafb_driver);
1897 
1898     if (!err) {
1899         uvesafb_device = platform_device_alloc("uvesafb", 0);
1900         if (uvesafb_device)
1901             err = platform_device_add(uvesafb_device);
1902         else
1903             err = -ENOMEM;
1904 
1905         if (err) {
1906             platform_device_put(uvesafb_device);
1907             platform_driver_unregister(&uvesafb_driver);
1908             cn_del_callback(&uvesafb_cn_id);
1909             return err;
1910         }
1911 
1912         err = driver_create_file(&uvesafb_driver.driver,
1913                 &driver_attr_v86d);
1914         if (err) {
1915             pr_warn("failed to register attributes\n");
1916             err = 0;
1917         }
1918     }
1919     return err;
1920 }
1921 
1922 module_init(uvesafb_init);
1923 
1924 static void uvesafb_exit(void)
1925 {
1926     struct uvesafb_ktask *task;
1927 
1928     if (v86d_started) {
1929         task = uvesafb_prep();
1930         if (task) {
1931             task->t.flags = TF_EXIT;
1932             uvesafb_exec(task);
1933             uvesafb_free(task);
1934         }
1935     }
1936 
1937     cn_del_callback(&uvesafb_cn_id);
1938     driver_remove_file(&uvesafb_driver.driver, &driver_attr_v86d);
1939     platform_device_unregister(uvesafb_device);
1940     platform_driver_unregister(&uvesafb_driver);
1941 }
1942 
1943 module_exit(uvesafb_exit);
1944 
1945 static int param_set_scroll(const char *val, const struct kernel_param *kp)
1946 {
1947     ypan = 0;
1948 
1949     if (!strcmp(val, "redraw"))
1950         ypan = 0;
1951     else if (!strcmp(val, "ypan"))
1952         ypan = 1;
1953     else if (!strcmp(val, "ywrap"))
1954         ypan = 2;
1955     else
1956         return -EINVAL;
1957 
1958     return 0;
1959 }
1960 static const struct kernel_param_ops param_ops_scroll = {
1961     .set = param_set_scroll,
1962 };
1963 #define param_check_scroll(name, p) __param_check(name, p, void)
1964 
1965 module_param_named(scroll, ypan, scroll, 0);
1966 MODULE_PARM_DESC(scroll,
1967     "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
1968 module_param_named(vgapal, pmi_setpal, invbool, 0);
1969 MODULE_PARM_DESC(vgapal, "Set palette using VGA registers");
1970 module_param_named(pmipal, pmi_setpal, bool, 0);
1971 MODULE_PARM_DESC(pmipal, "Set palette using PMI calls");
1972 module_param(mtrr, uint, 0);
1973 MODULE_PARM_DESC(mtrr,
1974     "Memory Type Range Registers setting. Use 0 to disable.");
1975 module_param(blank, bool, 0);
1976 MODULE_PARM_DESC(blank, "Enable hardware blanking");
1977 module_param(nocrtc, bool, 0);
1978 MODULE_PARM_DESC(nocrtc, "Ignore CRTC timings when setting modes");
1979 module_param(noedid, bool, 0);
1980 MODULE_PARM_DESC(noedid,
1981     "Ignore EDID-provided monitor limits when setting modes");
1982 module_param(vram_remap, uint, 0);
1983 MODULE_PARM_DESC(vram_remap, "Set amount of video memory to be used [MiB]");
1984 module_param(vram_total, uint, 0);
1985 MODULE_PARM_DESC(vram_total, "Set total amount of video memory [MiB]");
1986 module_param(maxclk, ushort, 0);
1987 MODULE_PARM_DESC(maxclk, "Maximum pixelclock [MHz], overrides EDID data");
1988 module_param(maxhf, ushort, 0);
1989 MODULE_PARM_DESC(maxhf,
1990     "Maximum horizontal frequency [kHz], overrides EDID data");
1991 module_param(maxvf, ushort, 0);
1992 MODULE_PARM_DESC(maxvf,
1993     "Maximum vertical frequency [Hz], overrides EDID data");
1994 module_param(mode_option, charp, 0);
1995 MODULE_PARM_DESC(mode_option,
1996     "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
1997 module_param(vbemode, ushort, 0);
1998 MODULE_PARM_DESC(vbemode,
1999     "VBE mode number to set, overrides the 'mode' option");
2000 module_param_string(v86d, v86d_path, PATH_MAX, 0660);
2001 MODULE_PARM_DESC(v86d, "Path to the v86d userspace helper.");
2002 
2003 MODULE_LICENSE("GPL");
2004 MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
2005 MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");
2006