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