linux/drivers/video/fbdev/uvesafb.c
<<
>>
Prefs
   1/*
   2 * A framebuffer driver for VBE 2.0+ compliant video cards
   3 *
   4 * (c) 2007 Michal Januszewski <spock@gentoo.org>
   5 *     Loosely based upon the vesafb driver.
   6 *
   7 */
   8
   9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10
  11#include <linux/init.h>
  12#include <linux/module.h>
  13#include <linux/moduleparam.h>
  14#include <linux/skbuff.h>
  15#include <linux/timer.h>
  16#include <linux/completion.h>
  17#include <linux/connector.h>
  18#include <linux/random.h>
  19#include <linux/platform_device.h>
  20#include <linux/limits.h>
  21#include <linux/fb.h>
  22#include <linux/io.h>
  23#include <linux/mutex.h>
  24#include <linux/slab.h>
  25#include <video/edid.h>
  26#include <video/uvesafb.h>
  27#ifdef CONFIG_X86
  28#include <video/vga.h>
  29#endif
  30#include "edid.h"
  31
  32static struct cb_id uvesafb_cn_id = {
  33        .idx = CN_IDX_V86D,
  34        .val = CN_VAL_V86D_UVESAFB
  35};
  36static char v86d_path[PATH_MAX] = "/sbin/v86d";
  37static char v86d_started;       /* has v86d been started by uvesafb? */
  38
  39static const struct fb_fix_screeninfo uvesafb_fix = {
  40        .id     = "VESA VGA",
  41        .type   = FB_TYPE_PACKED_PIXELS,
  42        .accel  = FB_ACCEL_NONE,
  43        .visual = FB_VISUAL_TRUECOLOR,
  44};
  45
  46static int mtrr         = 3;    /* enable mtrr by default */
  47static bool blank       = 1;    /* enable blanking by default */
  48static int ypan         = 1;    /* 0: scroll, 1: ypan, 2: ywrap */
  49static bool pmi_setpal  = true; /* use PMI for palette changes */
  50static bool nocrtc;             /* ignore CRTC settings */
  51static bool noedid;             /* don't try DDC transfers */
  52static int vram_remap;          /* set amt. of memory to be used */
  53static int vram_total;          /* set total amount of memory */
  54static u16 maxclk;              /* maximum pixel clock */
  55static u16 maxvf;               /* maximum vertical frequency */
  56static u16 maxhf;               /* maximum horizontal frequency */
  57static u16 vbemode;             /* force use of a specific VBE mode */
  58static char *mode_option;
  59static u8  dac_width    = 6;
  60
  61static struct uvesafb_ktask *uvfb_tasks[UVESAFB_TASKS_MAX];
  62static DEFINE_MUTEX(uvfb_lock);
  63
  64/*
  65 * A handler for replies from userspace.
  66 *
  67 * Make sure each message passes consistency checks and if it does,
  68 * find the kernel part of the task struct, copy the registers and
  69 * the buffer contents and then complete the task.
  70 */
  71static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
  72{
  73        struct uvesafb_task *utask;
  74        struct uvesafb_ktask *task;
  75
  76        if (!capable(CAP_SYS_ADMIN))
  77                return;
  78
  79        if (msg->seq >= UVESAFB_TASKS_MAX)
  80                return;
  81
  82        mutex_lock(&uvfb_lock);
  83        task = uvfb_tasks[msg->seq];
  84
  85        if (!task || msg->ack != task->ack) {
  86                mutex_unlock(&uvfb_lock);
  87                return;
  88        }
  89
  90        utask = (struct uvesafb_task *)msg->data;
  91
  92        /* Sanity checks for the buffer length. */
  93        if (task->t.buf_len < utask->buf_len ||
  94            utask->buf_len > msg->len - sizeof(*utask)) {
  95                mutex_unlock(&uvfb_lock);
  96                return;
  97        }
  98
  99        uvfb_tasks[msg->seq] = NULL;
 100        mutex_unlock(&uvfb_lock);
 101
 102        memcpy(&task->t, utask, sizeof(*utask));
 103
 104        if (task->t.buf_len && task->buf)
 105                memcpy(task->buf, utask + 1, task->t.buf_len);
 106
 107        complete(task->done);
 108        return;
 109}
 110
 111static int uvesafb_helper_start(void)
 112{
 113        char *envp[] = {
 114                "HOME=/",
 115                "PATH=/sbin:/bin",
 116                NULL,
 117        };
 118
 119        char *argv[] = {
 120                v86d_path,
 121                NULL,
 122        };
 123
 124        return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
 125}
 126
 127/*
 128 * Execute a uvesafb task.
 129 *
 130 * Returns 0 if the task is executed successfully.
 131 *
 132 * A message sent to the userspace consists of the uvesafb_task
 133 * struct and (optionally) a buffer. The uvesafb_task struct is
 134 * a simplified version of uvesafb_ktask (its kernel counterpart)
 135 * containing only the register values, flags and the length of
 136 * the buffer.
 137 *
 138 * Each message is assigned a sequence number (increased linearly)
 139 * and a random ack number. The sequence number is used as a key
 140 * for the uvfb_tasks array which holds pointers to uvesafb_ktask
 141 * structs for all requests.
 142 */
 143static int uvesafb_exec(struct uvesafb_ktask *task)
 144{
 145        static int seq;
 146        struct cn_msg *m;
 147        int err;
 148        int len = sizeof(task->t) + task->t.buf_len;
 149
 150        /*
 151         * Check whether the message isn't longer than the maximum
 152         * allowed by connector.
 153         */
 154        if (sizeof(*m) + len > CONNECTOR_MAX_MSG_SIZE) {
 155                pr_warn("message too long (%d), can't execute task\n",
 156                        (int)(sizeof(*m) + len));
 157                return -E2BIG;
 158        }
 159
 160        m = kzalloc(sizeof(*m) + len, GFP_KERNEL);
 161        if (!m)
 162                return -ENOMEM;
 163
 164        init_completion(task->done);
 165
 166        memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id));
 167        m->seq = seq;
 168        m->len = len;
 169        m->ack = prandom_u32();
 170
 171        /* uvesafb_task structure */
 172        memcpy(m + 1, &task->t, sizeof(task->t));
 173
 174        /* Buffer */
 175        memcpy((u8 *)(m + 1) + sizeof(task->t), task->buf, task->t.buf_len);
 176
 177        /*
 178         * Save the message ack number so that we can find the kernel
 179         * part of this task when a reply is received from userspace.
 180         */
 181        task->ack = m->ack;
 182
 183        mutex_lock(&uvfb_lock);
 184
 185        /* If all slots are taken -- bail out. */
 186        if (uvfb_tasks[seq]) {
 187                mutex_unlock(&uvfb_lock);
 188                err = -EBUSY;
 189                goto out;
 190        }
 191
 192        /* Save a pointer to the kernel part of the task struct. */
 193        uvfb_tasks[seq] = task;
 194        mutex_unlock(&uvfb_lock);
 195
 196        err = cn_netlink_send(m, 0, 0, GFP_KERNEL);
 197        if (err == -ESRCH) {
 198                /*
 199                 * Try to start the userspace helper if sending
 200                 * the request failed the first time.
 201                 */
 202                err = uvesafb_helper_start();
 203                if (err) {
 204                        pr_err("failed to execute %s\n", v86d_path);
 205                        pr_err("make sure that the v86d helper is installed and executable\n");
 206                } else {
 207                        v86d_started = 1;
 208                        err = cn_netlink_send(m, 0, 0, gfp_any());
 209                        if (err == -ENOBUFS)
 210                                err = 0;
 211                }
 212        } else if (err == -ENOBUFS)
 213                err = 0;
 214
 215        if (!err && !(task->t.flags & TF_EXIT))
 216                err = !wait_for_completion_timeout(task->done,
 217                                msecs_to_jiffies(UVESAFB_TIMEOUT));
 218
 219        mutex_lock(&uvfb_lock);
 220        uvfb_tasks[seq] = NULL;
 221        mutex_unlock(&uvfb_lock);
 222
 223        seq++;
 224        if (seq >= UVESAFB_TASKS_MAX)
 225                seq = 0;
 226out:
 227        kfree(m);
 228        return err;
 229}
 230
 231/*
 232 * Free a uvesafb_ktask struct.
 233 */
 234static void uvesafb_free(struct uvesafb_ktask *task)
 235{
 236        if (task) {
 237                kfree(task->done);
 238                kfree(task);
 239        }
 240}
 241
 242/*
 243 * Prepare a uvesafb_ktask struct to be used again.
 244 */
 245static void uvesafb_reset(struct uvesafb_ktask *task)
 246{
 247        struct completion *cpl = task->done;
 248
 249        memset(task, 0, sizeof(*task));
 250        task->done = cpl;
 251}
 252
 253/*
 254 * Allocate and prepare a uvesafb_ktask struct.
 255 */
 256static struct uvesafb_ktask *uvesafb_prep(void)
 257{
 258        struct uvesafb_ktask *task;
 259
 260        task = kzalloc(sizeof(*task), GFP_KERNEL);
 261        if (task) {
 262                task->done = kzalloc(sizeof(*task->done), GFP_KERNEL);
 263                if (!task->done) {
 264                        kfree(task);
 265                        task = NULL;
 266                }
 267        }
 268        return task;
 269}
 270
 271static void uvesafb_setup_var(struct fb_var_screeninfo *var,
 272                struct fb_info *info, struct vbe_mode_ib *mode)
 273{
 274        struct uvesafb_par *par = info->par;
 275
 276        var->vmode = FB_VMODE_NONINTERLACED;
 277        var->sync = FB_SYNC_VERT_HIGH_ACT;
 278
 279        var->xres = mode->x_res;
 280        var->yres = mode->y_res;
 281        var->xres_virtual = mode->x_res;
 282        var->yres_virtual = (par->ypan) ?
 283                        info->fix.smem_len / mode->bytes_per_scan_line :
 284                        mode->y_res;
 285        var->xoffset = 0;
 286        var->yoffset = 0;
 287        var->bits_per_pixel = mode->bits_per_pixel;
 288
 289        if (var->bits_per_pixel == 15)
 290                var->bits_per_pixel = 16;
 291
 292        if (var->bits_per_pixel > 8) {
 293                var->red.offset    = mode->red_off;
 294                var->red.length    = mode->red_len;
 295                var->green.offset  = mode->green_off;
 296                var->green.length  = mode->green_len;
 297                var->blue.offset   = mode->blue_off;
 298                var->blue.length   = mode->blue_len;
 299                var->transp.offset = mode->rsvd_off;
 300                var->transp.length = mode->rsvd_len;
 301        } else {
 302                var->red.offset    = 0;
 303                var->green.offset  = 0;
 304                var->blue.offset   = 0;
 305                var->transp.offset = 0;
 306
 307                var->red.length    = 8;
 308                var->green.length  = 8;
 309                var->blue.length   = 8;
 310                var->transp.length = 0;
 311        }
 312}
 313
 314static int uvesafb_vbe_find_mode(struct uvesafb_par *par,
 315                int xres, int yres, int depth, unsigned char flags)
 316{
 317        int i, match = -1, h = 0, d = 0x7fffffff;
 318
 319        for (i = 0; i < par->vbe_modes_cnt; i++) {
 320                h = abs(par->vbe_modes[i].x_res - xres) +
 321                    abs(par->vbe_modes[i].y_res - yres) +
 322                    abs(depth - par->vbe_modes[i].depth);
 323
 324                /*
 325                 * We have an exact match in terms of resolution
 326                 * and depth.
 327                 */
 328                if (h == 0)
 329                        return i;
 330
 331                if (h < d || (h == d && par->vbe_modes[i].depth > depth)) {
 332                        d = h;
 333                        match = i;
 334                }
 335        }
 336        i = 1;
 337
 338        if (flags & UVESAFB_EXACT_DEPTH &&
 339                        par->vbe_modes[match].depth != depth)
 340                i = 0;
 341
 342        if (flags & UVESAFB_EXACT_RES && d > 24)
 343                i = 0;
 344
 345        if (i != 0)
 346                return match;
 347        else
 348                return -1;
 349}
 350
 351static u8 *uvesafb_vbe_state_save(struct uvesafb_par *par)
 352{
 353        struct uvesafb_ktask *task;
 354        u8 *state;
 355        int err;
 356
 357        if (!par->vbe_state_size)
 358                return NULL;
 359
 360        state = kmalloc(par->vbe_state_size, GFP_KERNEL);
 361        if (!state)
 362                return ERR_PTR(-ENOMEM);
 363
 364        task = uvesafb_prep();
 365        if (!task) {
 366                kfree(state);
 367                return NULL;
 368        }
 369
 370        task->t.regs.eax = 0x4f04;
 371        task->t.regs.ecx = 0x000f;
 372        task->t.regs.edx = 0x0001;
 373        task->t.flags = TF_BUF_RET | TF_BUF_ESBX;
 374        task->t.buf_len = par->vbe_state_size;
 375        task->buf = state;
 376        err = uvesafb_exec(task);
 377
 378        if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
 379                pr_warn("VBE get state call failed (eax=0x%x, err=%d)\n",
 380                        task->t.regs.eax, err);
 381                kfree(state);
 382                state = NULL;
 383        }
 384
 385        uvesafb_free(task);
 386        return state;
 387}
 388
 389static void uvesafb_vbe_state_restore(struct uvesafb_par *par, u8 *state_buf)
 390{
 391        struct uvesafb_ktask *task;
 392        int err;
 393
 394        if (!state_buf)
 395                return;
 396
 397        task = uvesafb_prep();
 398        if (!task)
 399                return;
 400
 401        task->t.regs.eax = 0x4f04;
 402        task->t.regs.ecx = 0x000f;
 403        task->t.regs.edx = 0x0002;
 404        task->t.buf_len = par->vbe_state_size;
 405        task->t.flags = TF_BUF_ESBX;
 406        task->buf = state_buf;
 407
 408        err = uvesafb_exec(task);
 409        if (err || (task->t.regs.eax & 0xffff) != 0x004f)
 410                pr_warn("VBE state restore call failed (eax=0x%x, err=%d)\n",
 411                        task->t.regs.eax, err);
 412
 413        uvesafb_free(task);
 414}
 415
 416static int uvesafb_vbe_getinfo(struct uvesafb_ktask *task,
 417                               struct uvesafb_par *par)
 418{
 419        int err;
 420
 421        task->t.regs.eax = 0x4f00;
 422        task->t.flags = TF_VBEIB;
 423        task->t.buf_len = sizeof(struct vbe_ib);
 424        task->buf = &par->vbe_ib;
 425        strncpy(par->vbe_ib.vbe_signature, "VBE2", 4);
 426
 427        err = uvesafb_exec(task);
 428        if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
 429                pr_err("Getting VBE info block failed (eax=0x%x, err=%d)\n",
 430                       (u32)task->t.regs.eax, err);
 431                return -EINVAL;
 432        }
 433
 434        if (par->vbe_ib.vbe_version < 0x0200) {
 435                pr_err("Sorry, pre-VBE 2.0 cards are not supported\n");
 436                return -EINVAL;
 437        }
 438
 439        if (!par->vbe_ib.mode_list_ptr) {
 440                pr_err("Missing mode list!\n");
 441                return -EINVAL;
 442        }
 443
 444        pr_info("");
 445
 446        /*
 447         * Convert string pointers and the mode list pointer into
 448         * usable addresses. Print informational messages about the
 449         * video adapter and its vendor.
 450         */
 451        if (par->vbe_ib.oem_vendor_name_ptr)
 452                pr_cont("%s, ",
 453                        ((char *)task->buf) + par->vbe_ib.oem_vendor_name_ptr);
 454
 455        if (par->vbe_ib.oem_product_name_ptr)
 456                pr_cont("%s, ",
 457                        ((char *)task->buf) + par->vbe_ib.oem_product_name_ptr);
 458
 459        if (par->vbe_ib.oem_product_rev_ptr)
 460                pr_cont("%s, ",
 461                        ((char *)task->buf) + par->vbe_ib.oem_product_rev_ptr);
 462
 463        if (par->vbe_ib.oem_string_ptr)
 464                pr_cont("OEM: %s, ",
 465                        ((char *)task->buf) + par->vbe_ib.oem_string_ptr);
 466
 467        pr_cont("VBE v%d.%d\n",
 468                (par->vbe_ib.vbe_version & 0xff00) >> 8,
 469                par->vbe_ib.vbe_version & 0xff);
 470
 471        return 0;
 472}
 473
 474static int uvesafb_vbe_getmodes(struct uvesafb_ktask *task,
 475                                struct uvesafb_par *par)
 476{
 477        int off = 0, err;
 478        u16 *mode;
 479
 480        par->vbe_modes_cnt = 0;
 481
 482        /* Count available modes. */
 483        mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
 484        while (*mode != 0xffff) {
 485                par->vbe_modes_cnt++;
 486                mode++;
 487        }
 488
 489        par->vbe_modes = kcalloc(par->vbe_modes_cnt,
 490                                 sizeof(struct vbe_mode_ib),
 491                                 GFP_KERNEL);
 492        if (!par->vbe_modes)
 493                return -ENOMEM;
 494
 495        /* Get info about all available modes. */
 496        mode = (u16 *) (((u8 *)&par->vbe_ib) + par->vbe_ib.mode_list_ptr);
 497        while (*mode != 0xffff) {
 498                struct vbe_mode_ib *mib;
 499
 500                uvesafb_reset(task);
 501                task->t.regs.eax = 0x4f01;
 502                task->t.regs.ecx = (u32) *mode;
 503                task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
 504                task->t.buf_len = sizeof(struct vbe_mode_ib);
 505                task->buf = par->vbe_modes + off;
 506
 507                err = uvesafb_exec(task);
 508                if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
 509                        pr_warn("Getting mode info block for mode 0x%x failed (eax=0x%x, err=%d)\n",
 510                                *mode, (u32)task->t.regs.eax, err);
 511                        mode++;
 512                        par->vbe_modes_cnt--;
 513                        continue;
 514                }
 515
 516                mib = task->buf;
 517                mib->mode_id = *mode;
 518
 519                /*
 520                 * We only want modes that are supported with the current
 521                 * hardware configuration, color, graphics and that have
 522                 * support for the LFB.
 523                 */
 524                if ((mib->mode_attr & VBE_MODE_MASK) == VBE_MODE_MASK &&
 525                                 mib->bits_per_pixel >= 8)
 526                        off++;
 527                else
 528                        par->vbe_modes_cnt--;
 529
 530                mode++;
 531                mib->depth = mib->red_len + mib->green_len + mib->blue_len;
 532
 533                /*
 534                 * Handle 8bpp modes and modes with broken color component
 535                 * lengths.
 536                 */
 537                if (mib->depth == 0 || (mib->depth == 24 &&
 538                                        mib->bits_per_pixel == 32))
 539                        mib->depth = mib->bits_per_pixel;
 540        }
 541
 542        if (par->vbe_modes_cnt > 0)
 543                return 0;
 544        else
 545                return -EINVAL;
 546}
 547
 548/*
 549 * The Protected Mode Interface is 32-bit x86 code, so we only run it on
 550 * x86 and not x86_64.
 551 */
 552#ifdef CONFIG_X86_32
 553static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
 554                              struct uvesafb_par *par)
 555{
 556        int i, err;
 557
 558        uvesafb_reset(task);
 559        task->t.regs.eax = 0x4f0a;
 560        task->t.regs.ebx = 0x0;
 561        err = uvesafb_exec(task);
 562
 563        if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
 564                par->pmi_setpal = par->ypan = 0;
 565        } else {
 566                par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
 567                                                + task->t.regs.edi);
 568                par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
 569                par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
 570                pr_info("protected mode interface info at %04x:%04x\n",
 571                        (u16)task->t.regs.es, (u16)task->t.regs.edi);
 572                pr_info("pmi: set display start = %p, set palette = %p\n",
 573                        par->pmi_start, par->pmi_pal);
 574
 575                if (par->pmi_base[3]) {
 576                        pr_info("pmi: ports =");
 577                        for (i = par->pmi_base[3]/2;
 578                                        par->pmi_base[i] != 0xffff; i++)
 579                                pr_cont(" %x", par->pmi_base[i]);
 580                        pr_cont("\n");
 581
 582                        if (par->pmi_base[i] != 0xffff) {
 583                                pr_info("can't handle memory requests, pmi disabled\n");
 584                                par->ypan = par->pmi_setpal = 0;
 585                        }
 586                }
 587        }
 588        return 0;
 589}
 590#endif /* CONFIG_X86_32 */
 591
 592/*
 593 * Check whether a video mode is supported by the Video BIOS and is
 594 * compatible with the monitor limits.
 595 */
 596static int uvesafb_is_valid_mode(struct fb_videomode *mode,
 597                                 struct fb_info *info)
 598{
 599        if (info->monspecs.gtf) {
 600                fb_videomode_to_var(&info->var, mode);
 601                if (fb_validate_mode(&info->var, info))
 602                        return 0;
 603        }
 604
 605        if (uvesafb_vbe_find_mode(info->par, mode->xres, mode->yres, 8,
 606                                UVESAFB_EXACT_RES) == -1)
 607                return 0;
 608
 609        return 1;
 610}
 611
 612static int uvesafb_vbe_getedid(struct uvesafb_ktask *task, struct fb_info *info)
 613{
 614        struct uvesafb_par *par = info->par;
 615        int err = 0;
 616
 617        if (noedid || par->vbe_ib.vbe_version < 0x0300)
 618                return -EINVAL;
 619
 620        task->t.regs.eax = 0x4f15;
 621        task->t.regs.ebx = 0;
 622        task->t.regs.ecx = 0;
 623        task->t.buf_len = 0;
 624        task->t.flags = 0;
 625
 626        err = uvesafb_exec(task);
 627
 628        if ((task->t.regs.eax & 0xffff) != 0x004f || err)
 629                return -EINVAL;
 630
 631        if ((task->t.regs.ebx & 0x3) == 3) {
 632                pr_info("VBIOS/hardware supports both DDC1 and DDC2 transfers\n");
 633        } else if ((task->t.regs.ebx & 0x3) == 2) {
 634                pr_info("VBIOS/hardware supports DDC2 transfers\n");
 635        } else if ((task->t.regs.ebx & 0x3) == 1) {
 636                pr_info("VBIOS/hardware supports DDC1 transfers\n");
 637        } else {
 638                pr_info("VBIOS/hardware doesn't support DDC transfers\n");
 639                return -EINVAL;
 640        }
 641
 642        task->t.regs.eax = 0x4f15;
 643        task->t.regs.ebx = 1;
 644        task->t.regs.ecx = task->t.regs.edx = 0;
 645        task->t.flags = TF_BUF_RET | TF_BUF_ESDI;
 646        task->t.buf_len = EDID_LENGTH;
 647        task->buf = kzalloc(EDID_LENGTH, GFP_KERNEL);
 648        if (!task->buf)
 649                return -ENOMEM;
 650
 651        err = uvesafb_exec(task);
 652
 653        if ((task->t.regs.eax & 0xffff) == 0x004f && !err) {
 654                fb_edid_to_monspecs(task->buf, &info->monspecs);
 655
 656                if (info->monspecs.vfmax && info->monspecs.hfmax) {
 657                        /*
 658                         * If the maximum pixel clock wasn't specified in
 659                         * the EDID block, set it to 300 MHz.
 660                         */
 661                        if (info->monspecs.dclkmax == 0)
 662                                info->monspecs.dclkmax = 300 * 1000000;
 663                        info->monspecs.gtf = 1;
 664                }
 665        } else {
 666                err = -EINVAL;
 667        }
 668
 669        kfree(task->buf);
 670        return err;
 671}
 672
 673static void uvesafb_vbe_getmonspecs(struct uvesafb_ktask *task,
 674                                    struct fb_info *info)
 675{
 676        struct uvesafb_par *par = info->par;
 677        int i;
 678
 679        memset(&info->monspecs, 0, sizeof(info->monspecs));
 680
 681        /*
 682         * If we don't get all necessary data from the EDID block,
 683         * mark it as incompatible with the GTF and set nocrtc so
 684         * that we always use the default BIOS refresh rate.
 685         */
 686        if (uvesafb_vbe_getedid(task, info)) {
 687                info->monspecs.gtf = 0;
 688                par->nocrtc = 1;
 689        }
 690
 691        /* Kernel command line overrides. */
 692        if (maxclk)
 693                info->monspecs.dclkmax = maxclk * 1000000;
 694        if (maxvf)
 695                info->monspecs.vfmax = maxvf;
 696        if (maxhf)
 697                info->monspecs.hfmax = maxhf * 1000;
 698
 699        /*
 700         * In case DDC transfers are not supported, the user can provide
 701         * monitor limits manually. Lower limits are set to "safe" values.
 702         */
 703        if (info->monspecs.gtf == 0 && maxclk && maxvf && maxhf) {
 704                info->monspecs.dclkmin = 0;
 705                info->monspecs.vfmin = 60;
 706                info->monspecs.hfmin = 29000;
 707                info->monspecs.gtf = 1;
 708                par->nocrtc = 0;
 709        }
 710
 711        if (info->monspecs.gtf)
 712                pr_info("monitor limits: vf = %d Hz, hf = %d kHz, clk = %d MHz\n",
 713                        info->monspecs.vfmax,
 714                        (int)(info->monspecs.hfmax / 1000),
 715                        (int)(info->monspecs.dclkmax / 1000000));
 716        else
 717                pr_info("no monitor limits have been set, default refresh rate will be used\n");
 718
 719        /* Add VBE modes to the modelist. */
 720        for (i = 0; i < par->vbe_modes_cnt; i++) {
 721                struct fb_var_screeninfo var;
 722                struct vbe_mode_ib *mode;
 723                struct fb_videomode vmode;
 724
 725                mode = &par->vbe_modes[i];
 726                memset(&var, 0, sizeof(var));
 727
 728                var.xres = mode->x_res;
 729                var.yres = mode->y_res;
 730
 731                fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, &var, info);
 732                fb_var_to_videomode(&vmode, &var);
 733                fb_add_videomode(&vmode, &info->modelist);
 734        }
 735
 736        /* Add valid VESA modes to our modelist. */
 737        for (i = 0; i < VESA_MODEDB_SIZE; i++) {
 738                if (uvesafb_is_valid_mode((struct fb_videomode *)
 739                                                &vesa_modes[i], info))
 740                        fb_add_videomode(&vesa_modes[i], &info->modelist);
 741        }
 742
 743        for (i = 0; i < info->monspecs.modedb_len; i++) {
 744                if (uvesafb_is_valid_mode(&info->monspecs.modedb[i], info))
 745                        fb_add_videomode(&info->monspecs.modedb[i],
 746                                        &info->modelist);
 747        }
 748
 749        return;
 750}
 751
 752static void uvesafb_vbe_getstatesize(struct uvesafb_ktask *task,
 753                                     struct uvesafb_par *par)
 754{
 755        int err;
 756
 757        uvesafb_reset(task);
 758
 759        /*
 760         * Get the VBE state buffer size. We want all available
 761         * hardware state data (CL = 0x0f).
 762         */
 763        task->t.regs.eax = 0x4f04;
 764        task->t.regs.ecx = 0x000f;
 765        task->t.regs.edx = 0x0000;
 766        task->t.flags = 0;
 767
 768        err = uvesafb_exec(task);
 769
 770        if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
 771                pr_warn("VBE state buffer size cannot be determined (eax=0x%x, err=%d)\n",
 772                        task->t.regs.eax, err);
 773                par->vbe_state_size = 0;
 774                return;
 775        }
 776
 777        par->vbe_state_size = 64 * (task->t.regs.ebx & 0xffff);
 778}
 779
 780static int uvesafb_vbe_init(struct fb_info *info)
 781{
 782        struct uvesafb_ktask *task = NULL;
 783        struct uvesafb_par *par = info->par;
 784        int err;
 785
 786        task = uvesafb_prep();
 787        if (!task)
 788                return -ENOMEM;
 789
 790        err = uvesafb_vbe_getinfo(task, par);
 791        if (err)
 792                goto out;
 793
 794        err = uvesafb_vbe_getmodes(task, par);
 795        if (err)
 796                goto out;
 797
 798        par->nocrtc = nocrtc;
 799#ifdef CONFIG_X86_32
 800        par->pmi_setpal = pmi_setpal;
 801        par->ypan = ypan;
 802
 803        if (par->pmi_setpal || par->ypan) {
 804                if (__supported_pte_mask & _PAGE_NX) {
 805                        par->pmi_setpal = par->ypan = 0;
 806                        pr_warn("NX protection is active, better not use the PMI\n");
 807                } else {
 808                        uvesafb_vbe_getpmi(task, par);
 809                }
 810        }
 811#else
 812        /* The protected mode interface is not available on non-x86. */
 813        par->pmi_setpal = par->ypan = 0;
 814#endif
 815
 816        INIT_LIST_HEAD(&info->modelist);
 817        uvesafb_vbe_getmonspecs(task, info);
 818        uvesafb_vbe_getstatesize(task, par);
 819
 820out:    uvesafb_free(task);
 821        return err;
 822}
 823
 824static int uvesafb_vbe_init_mode(struct fb_info *info)
 825{
 826        struct list_head *pos;
 827        struct fb_modelist *modelist;
 828        struct fb_videomode *mode;
 829        struct uvesafb_par *par = info->par;
 830        int i, modeid;
 831
 832        /* Has the user requested a specific VESA mode? */
 833        if (vbemode) {
 834                for (i = 0; i < par->vbe_modes_cnt; i++) {
 835                        if (par->vbe_modes[i].mode_id == vbemode) {
 836                                modeid = i;
 837                                uvesafb_setup_var(&info->var, info,
 838                                                &par->vbe_modes[modeid]);
 839                                fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
 840                                                &info->var, info);
 841                                /*
 842                                 * With pixclock set to 0, the default BIOS
 843                                 * timings will be used in set_par().
 844                                 */
 845                                info->var.pixclock = 0;
 846                                goto gotmode;
 847                        }
 848                }
 849                pr_info("requested VBE mode 0x%x is unavailable\n", vbemode);
 850                vbemode = 0;
 851        }
 852
 853        /* Count the modes in the modelist */
 854        i = 0;
 855        list_for_each(pos, &info->modelist)
 856                i++;
 857
 858        /*
 859         * Convert the modelist into a modedb so that we can use it with
 860         * fb_find_mode().
 861         */
 862        mode = kcalloc(i, sizeof(*mode), GFP_KERNEL);
 863        if (mode) {
 864                i = 0;
 865                list_for_each(pos, &info->modelist) {
 866                        modelist = list_entry(pos, struct fb_modelist, list);
 867                        mode[i] = modelist->mode;
 868                        i++;
 869                }
 870
 871                if (!mode_option)
 872                        mode_option = UVESAFB_DEFAULT_MODE;
 873
 874                i = fb_find_mode(&info->var, info, mode_option, mode, i,
 875                        NULL, 8);
 876
 877                kfree(mode);
 878        }
 879
 880        /* fb_find_mode() failed */
 881        if (i == 0) {
 882                info->var.xres = 640;
 883                info->var.yres = 480;
 884                mode = (struct fb_videomode *)
 885                                fb_find_best_mode(&info->var, &info->modelist);
 886
 887                if (mode) {
 888                        fb_videomode_to_var(&info->var, mode);
 889                } else {
 890                        modeid = par->vbe_modes[0].mode_id;
 891                        uvesafb_setup_var(&info->var, info,
 892                                        &par->vbe_modes[modeid]);
 893                        fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
 894                                        &info->var, info);
 895
 896                        goto gotmode;
 897                }
 898        }
 899
 900        /* Look for a matching VBE mode. */
 901        modeid = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres,
 902                        info->var.bits_per_pixel, UVESAFB_EXACT_RES);
 903
 904        if (modeid == -1)
 905                return -EINVAL;
 906
 907        uvesafb_setup_var(&info->var, info, &par->vbe_modes[modeid]);
 908
 909gotmode:
 910        /*
 911         * If we are not VBE3.0+ compliant, we're done -- the BIOS will
 912         * ignore our timings anyway.
 913         */
 914        if (par->vbe_ib.vbe_version < 0x0300 || par->nocrtc)
 915                fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
 916                                        &info->var, info);
 917
 918        return modeid;
 919}
 920
 921static int uvesafb_setpalette(struct uvesafb_pal_entry *entries, int count,
 922                int start, struct fb_info *info)
 923{
 924        struct uvesafb_ktask *task;
 925#ifdef CONFIG_X86
 926        struct uvesafb_par *par = info->par;
 927        int i = par->mode_idx;
 928#endif
 929        int err = 0;
 930
 931        /*
 932         * We support palette modifications for 8 bpp modes only, so
 933         * there can never be more than 256 entries.
 934         */
 935        if (start + count > 256)
 936                return -EINVAL;
 937
 938#ifdef CONFIG_X86
 939        /* Use VGA registers if mode is VGA-compatible. */
 940        if (i >= 0 && i < par->vbe_modes_cnt &&
 941            par->vbe_modes[i].mode_attr & VBE_MODE_VGACOMPAT) {
 942                for (i = 0; i < count; i++) {
 943                        outb_p(start + i,        dac_reg);
 944                        outb_p(entries[i].red,   dac_val);
 945                        outb_p(entries[i].green, dac_val);
 946                        outb_p(entries[i].blue,  dac_val);
 947                }
 948        }
 949#ifdef CONFIG_X86_32
 950        else if (par->pmi_setpal) {
 951                __asm__ __volatile__(
 952                "call *(%%esi)"
 953                : /* no return value */
 954                : "a" (0x4f09),         /* EAX */
 955                  "b" (0),              /* EBX */
 956                  "c" (count),          /* ECX */
 957                  "d" (start),          /* EDX */
 958                  "D" (entries),        /* EDI */
 959                  "S" (&par->pmi_pal)); /* ESI */
 960        }
 961#endif /* CONFIG_X86_32 */
 962        else
 963#endif /* CONFIG_X86 */
 964        {
 965                task = uvesafb_prep();
 966                if (!task)
 967                        return -ENOMEM;
 968
 969                task->t.regs.eax = 0x4f09;
 970                task->t.regs.ebx = 0x0;
 971                task->t.regs.ecx = count;
 972                task->t.regs.edx = start;
 973                task->t.flags = TF_BUF_ESDI;
 974                task->t.buf_len = sizeof(struct uvesafb_pal_entry) * count;
 975                task->buf = entries;
 976
 977                err = uvesafb_exec(task);
 978                if ((task->t.regs.eax & 0xffff) != 0x004f)
 979                        err = 1;
 980
 981                uvesafb_free(task);
 982        }
 983        return err;
 984}
 985
 986static int uvesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
 987                unsigned blue, unsigned transp,
 988                struct fb_info *info)
 989{
 990        struct uvesafb_pal_entry entry;
 991        int shift = 16 - dac_width;
 992        int err = 0;
 993
 994        if (regno >= info->cmap.len)
 995                return -EINVAL;
 996
 997        if (info->var.bits_per_pixel == 8) {
 998                entry.red   = red   >> shift;
 999                entry.green = green >> shift;
1000                entry.blue  = blue  >> shift;
1001                entry.pad   = 0;
1002
1003                err = uvesafb_setpalette(&entry, 1, regno, info);
1004        } else if (regno < 16) {
1005                switch (info->var.bits_per_pixel) {
1006                case 16:
1007                        if (info->var.red.offset == 10) {
1008                                /* 1:5:5:5 */
1009                                ((u32 *) (info->pseudo_palette))[regno] =
1010                                                ((red   & 0xf800) >>  1) |
1011                                                ((green & 0xf800) >>  6) |
1012                                                ((blue  & 0xf800) >> 11);
1013                        } else {
1014                                /* 0:5:6:5 */
1015                                ((u32 *) (info->pseudo_palette))[regno] =
1016                                                ((red   & 0xf800)      ) |
1017                                                ((green & 0xfc00) >>  5) |
1018                                                ((blue  & 0xf800) >> 11);
1019                        }
1020                        break;
1021
1022                case 24:
1023                case 32:
1024                        red   >>= 8;
1025                        green >>= 8;
1026                        blue  >>= 8;
1027                        ((u32 *)(info->pseudo_palette))[regno] =
1028                                (red   << info->var.red.offset)   |
1029                                (green << info->var.green.offset) |
1030                                (blue  << info->var.blue.offset);
1031                        break;
1032                }
1033        }
1034        return err;
1035}
1036
1037static int uvesafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1038{
1039        struct uvesafb_pal_entry *entries;
1040        int shift = 16 - dac_width;
1041        int i, err = 0;
1042
1043        if (info->var.bits_per_pixel == 8) {
1044                if (cmap->start + cmap->len > info->cmap.start +
1045                    info->cmap.len || cmap->start < info->cmap.start)
1046                        return -EINVAL;
1047
1048                entries = kmalloc_array(cmap->len, sizeof(*entries),
1049                                        GFP_KERNEL);
1050                if (!entries)
1051                        return -ENOMEM;
1052
1053                for (i = 0; i < cmap->len; i++) {
1054                        entries[i].red   = cmap->red[i]   >> shift;
1055                        entries[i].green = cmap->green[i] >> shift;
1056                        entries[i].blue  = cmap->blue[i]  >> shift;
1057                        entries[i].pad   = 0;
1058                }
1059                err = uvesafb_setpalette(entries, cmap->len, cmap->start, info);
1060                kfree(entries);
1061        } else {
1062                /*
1063                 * For modes with bpp > 8, we only set the pseudo palette in
1064                 * the fb_info struct. We rely on uvesafb_setcolreg to do all
1065                 * sanity checking.
1066                 */
1067                for (i = 0; i < cmap->len; i++) {
1068                        err |= uvesafb_setcolreg(cmap->start + i, cmap->red[i],
1069                                                cmap->green[i], cmap->blue[i],
1070                                                0, info);
1071                }
1072        }
1073        return err;
1074}
1075
1076static int uvesafb_pan_display(struct fb_var_screeninfo *var,
1077                struct fb_info *info)
1078{
1079#ifdef CONFIG_X86_32
1080        int offset;
1081        struct uvesafb_par *par = info->par;
1082
1083        offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
1084
1085        /*
1086         * It turns out it's not the best idea to do panning via vm86,
1087         * so we only allow it if we have a PMI.
1088         */
1089        if (par->pmi_start) {
1090                __asm__ __volatile__(
1091                        "call *(%%edi)"
1092                        : /* no return value */
1093                        : "a" (0x4f07),         /* EAX */
1094                          "b" (0),              /* EBX */
1095                          "c" (offset),         /* ECX */
1096                          "d" (offset >> 16),   /* EDX */
1097                          "D" (&par->pmi_start));    /* EDI */
1098        }
1099#endif
1100        return 0;
1101}
1102
1103static int uvesafb_blank(int blank, struct fb_info *info)
1104{
1105        struct uvesafb_ktask *task;
1106        int err = 1;
1107#ifdef CONFIG_X86
1108        struct uvesafb_par *par = info->par;
1109
1110        if (par->vbe_ib.capabilities & VBE_CAP_VGACOMPAT) {
1111                int loop = 10000;
1112                u8 seq = 0, crtc17 = 0;
1113
1114                if (blank == FB_BLANK_POWERDOWN) {
1115                        seq = 0x20;
1116                        crtc17 = 0x00;
1117                        err = 0;
1118                } else {
1119                        seq = 0x00;
1120                        crtc17 = 0x80;
1121                        err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;
1122                }
1123
1124                vga_wseq(NULL, 0x00, 0x01);
1125                seq |= vga_rseq(NULL, 0x01) & ~0x20;
1126                vga_wseq(NULL, 0x00, seq);
1127
1128                crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
1129                while (loop--);
1130                vga_wcrt(NULL, 0x17, crtc17);
1131                vga_wseq(NULL, 0x00, 0x03);
1132        } else
1133#endif /* CONFIG_X86 */
1134        {
1135                task = uvesafb_prep();
1136                if (!task)
1137                        return -ENOMEM;
1138
1139                task->t.regs.eax = 0x4f10;
1140                switch (blank) {
1141                case FB_BLANK_UNBLANK:
1142                        task->t.regs.ebx = 0x0001;
1143                        break;
1144                case FB_BLANK_NORMAL:
1145                        task->t.regs.ebx = 0x0101;      /* standby */
1146                        break;
1147                case FB_BLANK_POWERDOWN:
1148                        task->t.regs.ebx = 0x0401;      /* powerdown */
1149                        break;
1150                default:
1151                        goto out;
1152                }
1153
1154                err = uvesafb_exec(task);
1155                if (err || (task->t.regs.eax & 0xffff) != 0x004f)
1156                        err = 1;
1157out:            uvesafb_free(task);
1158        }
1159        return err;
1160}
1161
1162static int uvesafb_open(struct fb_info *info, int user)
1163{
1164        struct uvesafb_par *par = info->par;
1165        int cnt = atomic_read(&par->ref_count);
1166        u8 *buf = NULL;
1167
1168        if (!cnt && par->vbe_state_size) {
1169                buf =  uvesafb_vbe_state_save(par);
1170                if (IS_ERR(buf)) {
1171                        pr_warn("save hardware state failed, error code is %ld!\n",
1172                                PTR_ERR(buf));
1173                } else {
1174                        par->vbe_state_orig = buf;
1175                }
1176        }
1177
1178        atomic_inc(&par->ref_count);
1179        return 0;
1180}
1181
1182static int uvesafb_release(struct fb_info *info, int user)
1183{
1184        struct uvesafb_ktask *task = NULL;
1185        struct uvesafb_par *par = info->par;
1186        int cnt = atomic_read(&par->ref_count);
1187
1188        if (!cnt)
1189                return -EINVAL;
1190
1191        if (cnt != 1)
1192                goto out;
1193
1194        task = uvesafb_prep();
1195        if (!task)
1196                goto out;
1197
1198        /* First, try to set the standard 80x25 text mode. */
1199        task->t.regs.eax = 0x0003;
1200        uvesafb_exec(task);
1201
1202        /*
1203         * Now try to restore whatever hardware state we might have
1204         * saved when the fb device was first opened.
1205         */
1206        uvesafb_vbe_state_restore(par, par->vbe_state_orig);
1207out:
1208        atomic_dec(&par->ref_count);
1209        uvesafb_free(task);
1210        return 0;
1211}
1212
1213static int uvesafb_set_par(struct fb_info *info)
1214{
1215        struct uvesafb_par *par = info->par;
1216        struct uvesafb_ktask *task = NULL;
1217        struct vbe_crtc_ib *crtc = NULL;
1218        struct vbe_mode_ib *mode = NULL;
1219        int i, err = 0, depth = info->var.bits_per_pixel;
1220
1221        if (depth > 8 && depth != 32)
1222                depth = info->var.red.length + info->var.green.length +
1223                        info->var.blue.length;
1224
1225        i = uvesafb_vbe_find_mode(par, info->var.xres, info->var.yres, depth,
1226                                 UVESAFB_EXACT_RES | UVESAFB_EXACT_DEPTH);
1227        if (i >= 0)
1228                mode = &par->vbe_modes[i];
1229        else
1230                return -EINVAL;
1231
1232        task = uvesafb_prep();
1233        if (!task)
1234                return -ENOMEM;
1235setmode:
1236        task->t.regs.eax = 0x4f02;
1237        task->t.regs.ebx = mode->mode_id | 0x4000;      /* use LFB */
1238
1239        if (par->vbe_ib.vbe_version >= 0x0300 && !par->nocrtc &&
1240            info->var.pixclock != 0) {
1241                task->t.regs.ebx |= 0x0800;             /* use CRTC data */
1242                task->t.flags = TF_BUF_ESDI;
1243                crtc = kzalloc(sizeof(struct vbe_crtc_ib), GFP_KERNEL);
1244                if (!crtc) {
1245                        err = -ENOMEM;
1246                        goto out;
1247                }
1248                crtc->horiz_start = info->var.xres + info->var.right_margin;
1249                crtc->horiz_end   = crtc->horiz_start + info->var.hsync_len;
1250                crtc->horiz_total = crtc->horiz_end + info->var.left_margin;
1251
1252                crtc->vert_start  = info->var.yres + info->var.lower_margin;
1253                crtc->vert_end    = crtc->vert_start + info->var.vsync_len;
1254                crtc->vert_total  = crtc->vert_end + info->var.upper_margin;
1255
1256                crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;
1257                crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /
1258                                (crtc->vert_total * crtc->horiz_total)));
1259
1260                if (info->var.vmode & FB_VMODE_DOUBLE)
1261                        crtc->flags |= 0x1;
1262                if (info->var.vmode & FB_VMODE_INTERLACED)
1263                        crtc->flags |= 0x2;
1264                if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
1265                        crtc->flags |= 0x4;
1266                if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
1267                        crtc->flags |= 0x8;
1268                memcpy(&par->crtc, crtc, sizeof(*crtc));
1269        } else {
1270                memset(&par->crtc, 0, sizeof(*crtc));
1271        }
1272
1273        task->t.buf_len = sizeof(struct vbe_crtc_ib);
1274        task->buf = &par->crtc;
1275
1276        err = uvesafb_exec(task);
1277        if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
1278                /*
1279                 * The mode switch might have failed because we tried to
1280                 * use our own timings.  Try again with the default timings.
1281                 */
1282                if (crtc != NULL) {
1283                        pr_warn("mode switch failed (eax=0x%x, err=%d) - trying again with default timings\n",
1284                                task->t.regs.eax, err);
1285                        uvesafb_reset(task);
1286                        kfree(crtc);
1287                        crtc = NULL;
1288                        info->var.pixclock = 0;
1289                        goto setmode;
1290                } else {
1291                        pr_err("mode switch failed (eax=0x%x, err=%d)\n",
1292                               task->t.regs.eax, err);
1293                        err = -EINVAL;
1294                        goto out;
1295                }
1296        }
1297        par->mode_idx = i;
1298
1299        /* For 8bpp modes, always try to set the DAC to 8 bits. */
1300        if (par->vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&
1301            mode->bits_per_pixel <= 8) {
1302                uvesafb_reset(task);
1303                task->t.regs.eax = 0x4f08;
1304                task->t.regs.ebx = 0x0800;
1305
1306                err = uvesafb_exec(task);
1307                if (err || (task->t.regs.eax & 0xffff) != 0x004f ||
1308                    ((task->t.regs.ebx & 0xff00) >> 8) != 8) {
1309                        dac_width = 6;
1310                } else {
1311                        dac_width = 8;
1312                }
1313        }
1314
1315        info->fix.visual = (info->var.bits_per_pixel == 8) ?
1316                                FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1317        info->fix.line_length = mode->bytes_per_scan_line;
1318
1319out:
1320        kfree(crtc);
1321        uvesafb_free(task);
1322
1323        return err;
1324}
1325
1326static void uvesafb_check_limits(struct fb_var_screeninfo *var,
1327                struct fb_info *info)
1328{
1329        const struct fb_videomode *mode;
1330        struct uvesafb_par *par = info->par;
1331
1332        /*
1333         * If pixclock is set to 0, then we're using default BIOS timings
1334         * and thus don't have to perform any checks here.
1335         */
1336        if (!var->pixclock)
1337                return;
1338
1339        if (par->vbe_ib.vbe_version < 0x0300) {
1340                fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);
1341                return;
1342        }
1343
1344        if (!fb_validate_mode(var, info))
1345                return;
1346
1347        mode = fb_find_best_mode(var, &info->modelist);
1348        if (mode) {
1349                if (mode->xres == var->xres && mode->yres == var->yres &&
1350                    !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {
1351                        fb_videomode_to_var(var, mode);
1352                        return;
1353                }
1354        }
1355
1356        if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1357                return;
1358        /* Use default refresh rate */
1359        var->pixclock = 0;
1360}
1361
1362static int uvesafb_check_var(struct fb_var_screeninfo *var,
1363                struct fb_info *info)
1364{
1365        struct uvesafb_par *par = info->par;
1366        struct vbe_mode_ib *mode = NULL;
1367        int match = -1;
1368        int depth = var->red.length + var->green.length + var->blue.length;
1369
1370        /*
1371         * Various apps will use bits_per_pixel to set the color depth,
1372         * which is theoretically incorrect, but which we'll try to handle
1373         * here.
1374         */
1375        if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)
1376                depth = var->bits_per_pixel;
1377
1378        match = uvesafb_vbe_find_mode(par, var->xres, var->yres, depth,
1379                                                UVESAFB_EXACT_RES);
1380        if (match == -1)
1381                return -EINVAL;
1382
1383        mode = &par->vbe_modes[match];
1384        uvesafb_setup_var(var, info, mode);
1385
1386        /*
1387         * Check whether we have remapped enough memory for this mode.
1388         * We might be called at an early stage, when we haven't remapped
1389         * any memory yet, in which case we simply skip the check.
1390         */
1391        if (var->yres * mode->bytes_per_scan_line > info->fix.smem_len
1392                                                && info->fix.smem_len)
1393                return -EINVAL;
1394
1395        if ((var->vmode & FB_VMODE_DOUBLE) &&
1396                                !(par->vbe_modes[match].mode_attr & 0x100))
1397                var->vmode &= ~FB_VMODE_DOUBLE;
1398
1399        if ((var->vmode & FB_VMODE_INTERLACED) &&
1400                                !(par->vbe_modes[match].mode_attr & 0x200))
1401                var->vmode &= ~FB_VMODE_INTERLACED;
1402
1403        uvesafb_check_limits(var, info);
1404
1405        var->xres_virtual = var->xres;
1406        var->yres_virtual = (par->ypan) ?
1407                                info->fix.smem_len / mode->bytes_per_scan_line :
1408                                var->yres;
1409        return 0;
1410}
1411
1412static struct fb_ops uvesafb_ops = {
1413        .owner          = THIS_MODULE,
1414        .fb_open        = uvesafb_open,
1415        .fb_release     = uvesafb_release,
1416        .fb_setcolreg   = uvesafb_setcolreg,
1417        .fb_setcmap     = uvesafb_setcmap,
1418        .fb_pan_display = uvesafb_pan_display,
1419        .fb_blank       = uvesafb_blank,
1420        .fb_fillrect    = cfb_fillrect,
1421        .fb_copyarea    = cfb_copyarea,
1422        .fb_imageblit   = cfb_imageblit,
1423        .fb_check_var   = uvesafb_check_var,
1424        .fb_set_par     = uvesafb_set_par,
1425};
1426
1427static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
1428{
1429        unsigned int size_vmode;
1430        unsigned int size_remap;
1431        unsigned int size_total;
1432        struct uvesafb_par *par = info->par;
1433        int i, h;
1434
1435        info->pseudo_palette = ((u8 *)info->par + sizeof(struct uvesafb_par));
1436        info->fix = uvesafb_fix;
1437        info->fix.ypanstep = par->ypan ? 1 : 0;
1438        info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
1439
1440        /* Disable blanking if the user requested so. */
1441        if (!blank)
1442                info->fbops->fb_blank = NULL;
1443
1444        /*
1445         * Find out how much IO memory is required for the mode with
1446         * the highest resolution.
1447         */
1448        size_remap = 0;
1449        for (i = 0; i < par->vbe_modes_cnt; i++) {
1450                h = par->vbe_modes[i].bytes_per_scan_line *
1451                                        par->vbe_modes[i].y_res;
1452                if (h > size_remap)
1453                        size_remap = h;
1454        }
1455        size_remap *= 2;
1456
1457        /*
1458         *   size_vmode -- that is the amount of memory needed for the
1459         *                 used video mode, i.e. the minimum amount of
1460         *                 memory we need.
1461         */
1462        size_vmode = info->var.yres * mode->bytes_per_scan_line;
1463
1464        /*
1465         *   size_total -- all video memory we have. Used for mtrr
1466         *                 entries, resource allocation and bounds
1467         *                 checking.
1468         */
1469        size_total = par->vbe_ib.total_memory * 65536;
1470        if (vram_total)
1471                size_total = vram_total * 1024 * 1024;
1472        if (size_total < size_vmode)
1473                size_total = size_vmode;
1474
1475        /*
1476         *   size_remap -- the amount of video memory we are going to
1477         *                 use for vesafb.  With modern cards it is no
1478         *                 option to simply use size_total as th
1479         *                 wastes plenty of kernel address space.
1480         */
1481        if (vram_remap)
1482                size_remap = vram_remap * 1024 * 1024;
1483        if (size_remap < size_vmode)
1484                size_remap = size_vmode;
1485        if (size_remap > size_total)
1486                size_remap = size_total;
1487
1488        info->fix.smem_len = size_remap;
1489        info->fix.smem_start = mode->phys_base_ptr;
1490
1491        /*
1492         * We have to set yres_virtual here because when setup_var() was
1493         * called, smem_len wasn't defined yet.
1494         */
1495        info->var.yres_virtual = info->fix.smem_len /
1496                                 mode->bytes_per_scan_line;
1497
1498        if (par->ypan && info->var.yres_virtual > info->var.yres) {
1499                pr_info("scrolling: %s using protected mode interface, yres_virtual=%d\n",
1500                        (par->ypan > 1) ? "ywrap" : "ypan",
1501                        info->var.yres_virtual);
1502        } else {
1503                pr_info("scrolling: redraw\n");
1504                info->var.yres_virtual = info->var.yres;
1505                par->ypan = 0;
1506        }
1507
1508        info->flags = FBINFO_FLAG_DEFAULT |
1509                        (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
1510
1511        if (!par->ypan)
1512                info->fbops->fb_pan_display = NULL;
1513}
1514
1515static void uvesafb_init_mtrr(struct fb_info *info)
1516{
1517        struct uvesafb_par *par = info->par;
1518
1519        if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
1520                int temp_size = info->fix.smem_len;
1521
1522                int rc;
1523
1524                /* Find the largest power-of-two */
1525                temp_size = roundup_pow_of_two(temp_size);
1526
1527                /* Try and find a power of two to add */
1528                do {
1529                        rc = arch_phys_wc_add(info->fix.smem_start, temp_size);
1530                        temp_size >>= 1;
1531                } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
1532
1533                if (rc >= 0)
1534                        par->mtrr_handle = rc;
1535        }
1536}
1537
1538static void uvesafb_ioremap(struct fb_info *info)
1539{
1540        info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
1541}
1542
1543static ssize_t uvesafb_show_vbe_ver(struct device *dev,
1544                struct device_attribute *attr, char *buf)
1545{
1546        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1547        struct uvesafb_par *par = info->par;
1548
1549        return snprintf(buf, PAGE_SIZE, "%.4x\n", par->vbe_ib.vbe_version);
1550}
1551
1552static DEVICE_ATTR(vbe_version, S_IRUGO, uvesafb_show_vbe_ver, NULL);
1553
1554static ssize_t uvesafb_show_vbe_modes(struct device *dev,
1555                struct device_attribute *attr, char *buf)
1556{
1557        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1558        struct uvesafb_par *par = info->par;
1559        int ret = 0, i;
1560
1561        for (i = 0; i < par->vbe_modes_cnt && ret < PAGE_SIZE; i++) {
1562                ret += snprintf(buf + ret, PAGE_SIZE - ret,
1563                        "%dx%d-%d, 0x%.4x\n",
1564                        par->vbe_modes[i].x_res, par->vbe_modes[i].y_res,
1565                        par->vbe_modes[i].depth, par->vbe_modes[i].mode_id);
1566        }
1567
1568        return ret;
1569}
1570
1571static DEVICE_ATTR(vbe_modes, S_IRUGO, uvesafb_show_vbe_modes, NULL);
1572
1573static ssize_t uvesafb_show_vendor(struct device *dev,
1574                struct device_attribute *attr, char *buf)
1575{
1576        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1577        struct uvesafb_par *par = info->par;
1578
1579        if (par->vbe_ib.oem_vendor_name_ptr)
1580                return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
1581                        (&par->vbe_ib) + par->vbe_ib.oem_vendor_name_ptr);
1582        else
1583                return 0;
1584}
1585
1586static DEVICE_ATTR(oem_vendor, S_IRUGO, uvesafb_show_vendor, NULL);
1587
1588static ssize_t uvesafb_show_product_name(struct device *dev,
1589                struct device_attribute *attr, char *buf)
1590{
1591        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1592        struct uvesafb_par *par = info->par;
1593
1594        if (par->vbe_ib.oem_product_name_ptr)
1595                return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
1596                        (&par->vbe_ib) + par->vbe_ib.oem_product_name_ptr);
1597        else
1598                return 0;
1599}
1600
1601static DEVICE_ATTR(oem_product_name, S_IRUGO, uvesafb_show_product_name, NULL);
1602
1603static ssize_t uvesafb_show_product_rev(struct device *dev,
1604                struct device_attribute *attr, char *buf)
1605{
1606        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1607        struct uvesafb_par *par = info->par;
1608
1609        if (par->vbe_ib.oem_product_rev_ptr)
1610                return snprintf(buf, PAGE_SIZE, "%s\n", (char *)
1611                        (&par->vbe_ib) + par->vbe_ib.oem_product_rev_ptr);
1612        else
1613                return 0;
1614}
1615
1616static DEVICE_ATTR(oem_product_rev, S_IRUGO, uvesafb_show_product_rev, NULL);
1617
1618static ssize_t uvesafb_show_oem_string(struct device *dev,
1619                struct device_attribute *attr, char *buf)
1620{
1621        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1622        struct uvesafb_par *par = info->par;
1623
1624        if (par->vbe_ib.oem_string_ptr)
1625                return snprintf(buf, PAGE_SIZE, "%s\n",
1626                        (char *)(&par->vbe_ib) + par->vbe_ib.oem_string_ptr);
1627        else
1628                return 0;
1629}
1630
1631static DEVICE_ATTR(oem_string, S_IRUGO, uvesafb_show_oem_string, NULL);
1632
1633static ssize_t uvesafb_show_nocrtc(struct device *dev,
1634                struct device_attribute *attr, char *buf)
1635{
1636        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1637        struct uvesafb_par *par = info->par;
1638
1639        return snprintf(buf, PAGE_SIZE, "%d\n", par->nocrtc);
1640}
1641
1642static ssize_t uvesafb_store_nocrtc(struct device *dev,
1643                struct device_attribute *attr, const char *buf, size_t count)
1644{
1645        struct fb_info *info = platform_get_drvdata(to_platform_device(dev));
1646        struct uvesafb_par *par = info->par;
1647
1648        if (count > 0) {
1649                if (buf[0] == '0')
1650                        par->nocrtc = 0;
1651                else
1652                        par->nocrtc = 1;
1653        }
1654        return count;
1655}
1656
1657static DEVICE_ATTR(nocrtc, S_IRUGO | S_IWUSR, uvesafb_show_nocrtc,
1658                        uvesafb_store_nocrtc);
1659
1660static struct attribute *uvesafb_dev_attrs[] = {
1661        &dev_attr_vbe_version.attr,
1662        &dev_attr_vbe_modes.attr,
1663        &dev_attr_oem_vendor.attr,
1664        &dev_attr_oem_product_name.attr,
1665        &dev_attr_oem_product_rev.attr,
1666        &dev_attr_oem_string.attr,
1667        &dev_attr_nocrtc.attr,
1668        NULL,
1669};
1670
1671static const struct attribute_group uvesafb_dev_attgrp = {
1672        .name = NULL,
1673        .attrs = uvesafb_dev_attrs,
1674};
1675
1676static int uvesafb_probe(struct platform_device *dev)
1677{
1678        struct fb_info *info;
1679        struct vbe_mode_ib *mode = NULL;
1680        struct uvesafb_par *par;
1681        int err = 0, i;
1682
1683        info = framebuffer_alloc(sizeof(*par) + sizeof(u32) * 256, &dev->dev);
1684        if (!info)
1685                return -ENOMEM;
1686
1687        par = info->par;
1688
1689        err = uvesafb_vbe_init(info);
1690        if (err) {
1691                pr_err("vbe_init() failed with %d\n", err);
1692                goto out;
1693        }
1694
1695        info->fbops = &uvesafb_ops;
1696
1697        i = uvesafb_vbe_init_mode(info);
1698        if (i < 0) {
1699                err = -EINVAL;
1700                goto out;
1701        } else {
1702                mode = &par->vbe_modes[i];
1703        }
1704
1705        if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
1706                err = -ENXIO;
1707                goto out;
1708        }
1709
1710        uvesafb_init_info(info, mode);
1711
1712        if (!request_region(0x3c0, 32, "uvesafb")) {
1713                pr_err("request region 0x3c0-0x3e0 failed\n");
1714                err = -EIO;
1715                goto out_mode;
1716        }
1717
1718        if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
1719                                "uvesafb")) {
1720                pr_err("cannot reserve video memory at 0x%lx\n",
1721                       info->fix.smem_start);
1722                err = -EIO;
1723                goto out_reg;
1724        }
1725
1726        uvesafb_init_mtrr(info);
1727        uvesafb_ioremap(info);
1728
1729        if (!info->screen_base) {
1730                pr_err("abort, cannot ioremap 0x%x bytes of video memory at 0x%lx\n",
1731                       info->fix.smem_len, info->fix.smem_start);
1732                err = -EIO;
1733                goto out_mem;
1734        }
1735
1736        platform_set_drvdata(dev, info);
1737
1738        if (register_framebuffer(info) < 0) {
1739                pr_err("failed to register framebuffer device\n");
1740                err = -EINVAL;
1741                goto out_unmap;
1742        }
1743
1744        pr_info("framebuffer at 0x%lx, mapped to 0x%p, using %dk, total %dk\n",
1745                info->fix.smem_start, info->screen_base,
1746                info->fix.smem_len / 1024, par->vbe_ib.total_memory * 64);
1747        fb_info(info, "%s frame buffer device\n", info->fix.id);
1748
1749        err = sysfs_create_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
1750        if (err != 0)
1751                fb_warn(info, "failed to register attributes\n");
1752
1753        return 0;
1754
1755out_unmap:
1756        iounmap(info->screen_base);
1757out_mem:
1758        release_mem_region(info->fix.smem_start, info->fix.smem_len);
1759out_reg:
1760        release_region(0x3c0, 32);
1761out_mode:
1762        if (!list_empty(&info->modelist))
1763                fb_destroy_modelist(&info->modelist);
1764        fb_destroy_modedb(info->monspecs.modedb);
1765        fb_dealloc_cmap(&info->cmap);
1766out:
1767        kfree(par->vbe_modes);
1768
1769        framebuffer_release(info);
1770        return err;
1771}
1772
1773static int uvesafb_remove(struct platform_device *dev)
1774{
1775        struct fb_info *info = platform_get_drvdata(dev);
1776
1777        if (info) {
1778                struct uvesafb_par *par = info->par;
1779
1780                sysfs_remove_group(&dev->dev.kobj, &uvesafb_dev_attgrp);
1781                unregister_framebuffer(info);
1782                release_region(0x3c0, 32);
1783                iounmap(info->screen_base);
1784                arch_phys_wc_del(par->mtrr_handle);
1785                release_mem_region(info->fix.smem_start, info->fix.smem_len);
1786                fb_destroy_modedb(info->monspecs.modedb);
1787                fb_dealloc_cmap(&info->cmap);
1788
1789                kfree(par->vbe_modes);
1790                kfree(par->vbe_state_orig);
1791                kfree(par->vbe_state_saved);
1792
1793                framebuffer_release(info);
1794        }
1795        return 0;
1796}
1797
1798static struct platform_driver uvesafb_driver = {
1799        .probe  = uvesafb_probe,
1800        .remove = uvesafb_remove,
1801        .driver = {
1802                .name = "uvesafb",
1803        },
1804};
1805
1806static struct platform_device *uvesafb_device;
1807
1808#ifndef MODULE
1809static int uvesafb_setup(char *options)
1810{
1811        char *this_opt;
1812
1813        if (!options || !*options)
1814                return 0;
1815
1816        while ((this_opt = strsep(&options, ",")) != NULL) {
1817                if (!*this_opt) continue;
1818
1819                if (!strcmp(this_opt, "redraw"))
1820                        ypan = 0;
1821                else if (!strcmp(this_opt, "ypan"))
1822                        ypan = 1;
1823                else if (!strcmp(this_opt, "ywrap"))
1824                        ypan = 2;
1825                else if (!strcmp(this_opt, "vgapal"))
1826                        pmi_setpal = 0;
1827                else if (!strcmp(this_opt, "pmipal"))
1828                        pmi_setpal = 1;
1829                else if (!strncmp(this_opt, "mtrr:", 5))
1830                        mtrr = simple_strtoul(this_opt+5, NULL, 0);
1831                else if (!strcmp(this_opt, "nomtrr"))
1832                        mtrr = 0;
1833                else if (!strcmp(this_opt, "nocrtc"))
1834                        nocrtc = 1;
1835                else if (!strcmp(this_opt, "noedid"))
1836                        noedid = 1;
1837                else if (!strcmp(this_opt, "noblank"))
1838                        blank = 0;
1839                else if (!strncmp(this_opt, "vtotal:", 7))
1840                        vram_total = simple_strtoul(this_opt + 7, NULL, 0);
1841                else if (!strncmp(this_opt, "vremap:", 7))
1842                        vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
1843                else if (!strncmp(this_opt, "maxhf:", 6))
1844                        maxhf = simple_strtoul(this_opt + 6, NULL, 0);
1845                else if (!strncmp(this_opt, "maxvf:", 6))
1846                        maxvf = simple_strtoul(this_opt + 6, NULL, 0);
1847                else if (!strncmp(this_opt, "maxclk:", 7))
1848                        maxclk = simple_strtoul(this_opt + 7, NULL, 0);
1849                else if (!strncmp(this_opt, "vbemode:", 8))
1850                        vbemode = simple_strtoul(this_opt + 8, NULL, 0);
1851                else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
1852                        mode_option = this_opt;
1853                } else {
1854                        pr_warn("unrecognized option %s\n", this_opt);
1855                }
1856        }
1857
1858        if (mtrr != 3 && mtrr != 0)
1859                pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr);
1860
1861        return 0;
1862}
1863#endif /* !MODULE */
1864
1865static ssize_t v86d_show(struct device_driver *dev, char *buf)
1866{
1867        return snprintf(buf, PAGE_SIZE, "%s\n", v86d_path);
1868}
1869
1870static ssize_t v86d_store(struct device_driver *dev, const char *buf,
1871                size_t count)
1872{
1873        strncpy(v86d_path, buf, PATH_MAX);
1874        return count;
1875}
1876static DRIVER_ATTR_RW(v86d);
1877
1878static int uvesafb_init(void)
1879{
1880        int err;
1881
1882#ifndef MODULE
1883        char *option = NULL;
1884
1885        if (fb_get_options("uvesafb", &option))
1886                return -ENODEV;
1887        uvesafb_setup(option);
1888#endif
1889        err = cn_add_callback(&uvesafb_cn_id, "uvesafb", uvesafb_cn_callback);
1890        if (err)
1891                return err;
1892
1893        err = platform_driver_register(&uvesafb_driver);
1894
1895        if (!err) {
1896                uvesafb_device = platform_device_alloc("uvesafb", 0);
1897                if (uvesafb_device)
1898                        err = platform_device_add(uvesafb_device);
1899                else
1900                        err = -ENOMEM;
1901
1902                if (err) {
1903                        platform_device_put(uvesafb_device);
1904                        platform_driver_unregister(&uvesafb_driver);
1905                        cn_del_callback(&uvesafb_cn_id);
1906                        return err;
1907                }
1908
1909                err = driver_create_file(&uvesafb_driver.driver,
1910                                &driver_attr_v86d);
1911                if (err) {
1912                        pr_warn("failed to register attributes\n");
1913                        err = 0;
1914                }
1915        }
1916        return err;
1917}
1918
1919module_init(uvesafb_init);
1920
1921static void uvesafb_exit(void)
1922{
1923        struct uvesafb_ktask *task;
1924
1925        if (v86d_started) {
1926                task = uvesafb_prep();
1927                if (task) {
1928                        task->t.flags = TF_EXIT;
1929                        uvesafb_exec(task);
1930                        uvesafb_free(task);
1931                }
1932        }
1933
1934        cn_del_callback(&uvesafb_cn_id);
1935        driver_remove_file(&uvesafb_driver.driver, &driver_attr_v86d);
1936        platform_device_unregister(uvesafb_device);
1937        platform_driver_unregister(&uvesafb_driver);
1938}
1939
1940module_exit(uvesafb_exit);
1941
1942static int param_set_scroll(const char *val, const struct kernel_param *kp)
1943{
1944        ypan = 0;
1945
1946        if (!strcmp(val, "redraw"))
1947                ypan = 0;
1948        else if (!strcmp(val, "ypan"))
1949                ypan = 1;
1950        else if (!strcmp(val, "ywrap"))
1951                ypan = 2;
1952        else
1953                return -EINVAL;
1954
1955        return 0;
1956}
1957static const struct kernel_param_ops param_ops_scroll = {
1958        .set = param_set_scroll,
1959};
1960#define param_check_scroll(name, p) __param_check(name, p, void)
1961
1962module_param_named(scroll, ypan, scroll, 0);
1963MODULE_PARM_DESC(scroll,
1964        "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
1965module_param_named(vgapal, pmi_setpal, invbool, 0);
1966MODULE_PARM_DESC(vgapal, "Set palette using VGA registers");
1967module_param_named(pmipal, pmi_setpal, bool, 0);
1968MODULE_PARM_DESC(pmipal, "Set palette using PMI calls");
1969module_param(mtrr, uint, 0);
1970MODULE_PARM_DESC(mtrr,
1971        "Memory Type Range Registers setting. Use 0 to disable.");
1972module_param(blank, bool, 0);
1973MODULE_PARM_DESC(blank, "Enable hardware blanking");
1974module_param(nocrtc, bool, 0);
1975MODULE_PARM_DESC(nocrtc, "Ignore CRTC timings when setting modes");
1976module_param(noedid, bool, 0);
1977MODULE_PARM_DESC(noedid,
1978        "Ignore EDID-provided monitor limits when setting modes");
1979module_param(vram_remap, uint, 0);
1980MODULE_PARM_DESC(vram_remap, "Set amount of video memory to be used [MiB]");
1981module_param(vram_total, uint, 0);
1982MODULE_PARM_DESC(vram_total, "Set total amount of video memoery [MiB]");
1983module_param(maxclk, ushort, 0);
1984MODULE_PARM_DESC(maxclk, "Maximum pixelclock [MHz], overrides EDID data");
1985module_param(maxhf, ushort, 0);
1986MODULE_PARM_DESC(maxhf,
1987        "Maximum horizontal frequency [kHz], overrides EDID data");
1988module_param(maxvf, ushort, 0);
1989MODULE_PARM_DESC(maxvf,
1990        "Maximum vertical frequency [Hz], overrides EDID data");
1991module_param(mode_option, charp, 0);
1992MODULE_PARM_DESC(mode_option,
1993        "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
1994module_param(vbemode, ushort, 0);
1995MODULE_PARM_DESC(vbemode,
1996        "VBE mode number to set, overrides the 'mode' option");
1997module_param_string(v86d, v86d_path, PATH_MAX, 0660);
1998MODULE_PARM_DESC(v86d, "Path to the v86d userspace helper.");
1999
2000MODULE_LICENSE("GPL");
2001MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
2002MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");
2003
2004