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