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