2 * A framebuffer driver for VBE 2.0+ compliant video cards
4 * (c) 2007 Michal Januszewski <spock@gentoo.org>
5 * Loosely based upon the vesafb driver.
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>
20 #include <linux/mutex.h>
21 #include <video/edid.h>
22 #include <video/uvesafb.h>
24 #include <video/vga.h>
31 static struct cb_id uvesafb_cn_id
= {
33 .val
= CN_VAL_V86D_UVESAFB
35 static char v86d_path
[PATH_MAX
] = "/sbin/v86d";
36 static char v86d_started
; /* has v86d been started by uvesafb? */
38 static struct fb_fix_screeninfo uvesafb_fix __devinitdata
= {
40 .type
= FB_TYPE_PACKED_PIXELS
,
41 .accel
= FB_ACCEL_NONE
,
42 .visual
= FB_VISUAL_TRUECOLOR
,
45 static int mtrr __devinitdata
= 3; /* enable mtrr by default */
46 static int blank
= 1; /* enable blanking by default */
47 static int ypan
= 1; /* 0: scroll, 1: ypan, 2: ywrap */
48 static bool pmi_setpal __devinitdata
= true; /* use PMI for palette changes */
49 static int nocrtc __devinitdata
; /* ignore CRTC settings */
50 static int noedid __devinitdata
; /* don't try DDC transfers */
51 static int vram_remap __devinitdata
; /* set amt. of memory to be used */
52 static int vram_total __devinitdata
; /* set total amount of memory */
53 static u16 maxclk __devinitdata
; /* maximum pixel clock */
54 static u16 maxvf __devinitdata
; /* maximum vertical frequency */
55 static u16 maxhf __devinitdata
; /* maximum horizontal frequency */
56 static u16 vbemode __devinitdata
; /* force use of a specific VBE mode */
57 static char *mode_option __devinitdata
;
58 static u8 dac_width
= 6;
60 static struct uvesafb_ktask
*uvfb_tasks
[UVESAFB_TASKS_MAX
];
61 static DEFINE_MUTEX(uvfb_lock
);
64 * A handler for replies from userspace.
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.
70 static void uvesafb_cn_callback(struct cn_msg
*msg
, struct netlink_skb_parms
*nsp
)
72 struct uvesafb_task
*utask
;
73 struct uvesafb_ktask
*task
;
75 if (!cap_raised(nsp
->eff_cap
, CAP_SYS_ADMIN
))
78 if (msg
->seq
>= UVESAFB_TASKS_MAX
)
81 mutex_lock(&uvfb_lock
);
82 task
= uvfb_tasks
[msg
->seq
];
84 if (!task
|| msg
->ack
!= task
->ack
) {
85 mutex_unlock(&uvfb_lock
);
89 utask
= (struct uvesafb_task
*)msg
->data
;
91 /* Sanity checks for the buffer length. */
92 if (task
->t
.buf_len
< utask
->buf_len
||
93 utask
->buf_len
> msg
->len
- sizeof(*utask
)) {
94 mutex_unlock(&uvfb_lock
);
98 uvfb_tasks
[msg
->seq
] = NULL
;
99 mutex_unlock(&uvfb_lock
);
101 memcpy(&task
->t
, utask
, sizeof(*utask
));
103 if (task
->t
.buf_len
&& task
->buf
)
104 memcpy(task
->buf
, utask
+ 1, task
->t
.buf_len
);
106 complete(task
->done
);
110 static int uvesafb_helper_start(void)
123 return call_usermodehelper(v86d_path
, argv
, envp
, 1);
127 * Execute a uvesafb task.
129 * Returns 0 if the task is executed successfully.
131 * A message sent to the userspace consists of the uvesafb_task
132 * struct and (optionally) a buffer. The uvesafb_task struct is
133 * a simplified version of uvesafb_ktask (its kernel counterpart)
134 * containing only the register values, flags and the length of
137 * Each message is assigned a sequence number (increased linearly)
138 * and a random ack number. The sequence number is used as a key
139 * for the uvfb_tasks array which holds pointers to uvesafb_ktask
140 * structs for all requests.
142 static int uvesafb_exec(struct uvesafb_ktask
*task
)
147 int len
= sizeof(task
->t
) + task
->t
.buf_len
;
150 * Check whether the message isn't longer than the maximum
151 * allowed by connector.
153 if (sizeof(*m
) + len
> CONNECTOR_MAX_MSG_SIZE
) {
154 printk(KERN_WARNING
"uvesafb: message too long (%d), "
155 "can't execute task\n", (int)(sizeof(*m
) + len
));
159 m
= kzalloc(sizeof(*m
) + len
, GFP_KERNEL
);
163 init_completion(task
->done
);
165 memcpy(&m
->id
, &uvesafb_cn_id
, sizeof(m
->id
));
170 /* uvesafb_task structure */
171 memcpy(m
+ 1, &task
->t
, sizeof(task
->t
));
174 memcpy((u8
*)(m
+ 1) + sizeof(task
->t
), task
->buf
, task
->t
.buf_len
);
177 * Save the message ack number so that we can find the kernel
178 * part of this task when a reply is received from userspace.
182 mutex_lock(&uvfb_lock
);
184 /* If all slots are taken -- bail out. */
185 if (uvfb_tasks
[seq
]) {
186 mutex_unlock(&uvfb_lock
);
191 /* Save a pointer to the kernel part of the task struct. */
192 uvfb_tasks
[seq
] = task
;
193 mutex_unlock(&uvfb_lock
);
195 err
= cn_netlink_send(m
, 0, GFP_KERNEL
);
198 * Try to start the userspace helper if sending
199 * the request failed the first time.
201 err
= uvesafb_helper_start();
203 printk(KERN_ERR
"uvesafb: failed to execute %s\n",
205 printk(KERN_ERR
"uvesafb: make sure that the v86d "
206 "helper is installed and executable\n");
209 err
= cn_netlink_send(m
, 0, gfp_any());
213 } else if (err
== -ENOBUFS
)
216 if (!err
&& !(task
->t
.flags
& TF_EXIT
))
217 err
= !wait_for_completion_timeout(task
->done
,
218 msecs_to_jiffies(UVESAFB_TIMEOUT
));
220 mutex_lock(&uvfb_lock
);
221 uvfb_tasks
[seq
] = NULL
;
222 mutex_unlock(&uvfb_lock
);
225 if (seq
>= UVESAFB_TASKS_MAX
)
233 * Free a uvesafb_ktask struct.
235 static void uvesafb_free(struct uvesafb_ktask
*task
)
245 * Prepare a uvesafb_ktask struct to be used again.
247 static void uvesafb_reset(struct uvesafb_ktask
*task
)
249 struct completion
*cpl
= task
->done
;
251 memset(task
, 0, sizeof(*task
));
256 * Allocate and prepare a uvesafb_ktask struct.
258 static struct uvesafb_ktask
*uvesafb_prep(void)
260 struct uvesafb_ktask
*task
;
262 task
= kzalloc(sizeof(*task
), GFP_KERNEL
);
264 task
->done
= kzalloc(sizeof(*task
->done
), GFP_KERNEL
);
273 static void uvesafb_setup_var(struct fb_var_screeninfo
*var
,
274 struct fb_info
*info
, struct vbe_mode_ib
*mode
)
276 struct uvesafb_par
*par
= info
->par
;
278 var
->vmode
= FB_VMODE_NONINTERLACED
;
279 var
->sync
= FB_SYNC_VERT_HIGH_ACT
;
281 var
->xres
= mode
->x_res
;
282 var
->yres
= mode
->y_res
;
283 var
->xres_virtual
= mode
->x_res
;
284 var
->yres_virtual
= (par
->ypan
) ?
285 info
->fix
.smem_len
/ mode
->bytes_per_scan_line
:
289 var
->bits_per_pixel
= mode
->bits_per_pixel
;
291 if (var
->bits_per_pixel
== 15)
292 var
->bits_per_pixel
= 16;
294 if (var
->bits_per_pixel
> 8) {
295 var
->red
.offset
= mode
->red_off
;
296 var
->red
.length
= mode
->red_len
;
297 var
->green
.offset
= mode
->green_off
;
298 var
->green
.length
= mode
->green_len
;
299 var
->blue
.offset
= mode
->blue_off
;
300 var
->blue
.length
= mode
->blue_len
;
301 var
->transp
.offset
= mode
->rsvd_off
;
302 var
->transp
.length
= mode
->rsvd_len
;
305 var
->green
.offset
= 0;
306 var
->blue
.offset
= 0;
307 var
->transp
.offset
= 0;
310 var
->green
.length
= 8;
311 var
->blue
.length
= 8;
312 var
->transp
.length
= 0;
316 static int uvesafb_vbe_find_mode(struct uvesafb_par
*par
,
317 int xres
, int yres
, int depth
, unsigned char flags
)
319 int i
, match
= -1, h
= 0, d
= 0x7fffffff;
321 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
322 h
= abs(par
->vbe_modes
[i
].x_res
- xres
) +
323 abs(par
->vbe_modes
[i
].y_res
- yres
) +
324 abs(depth
- par
->vbe_modes
[i
].depth
);
327 * We have an exact match in terms of resolution
333 if (h
< d
|| (h
== d
&& par
->vbe_modes
[i
].depth
> depth
)) {
340 if (flags
& UVESAFB_EXACT_DEPTH
&&
341 par
->vbe_modes
[match
].depth
!= depth
)
344 if (flags
& UVESAFB_EXACT_RES
&& d
> 24)
353 static u8
*uvesafb_vbe_state_save(struct uvesafb_par
*par
)
355 struct uvesafb_ktask
*task
;
359 if (!par
->vbe_state_size
)
362 state
= kmalloc(par
->vbe_state_size
, GFP_KERNEL
);
366 task
= uvesafb_prep();
372 task
->t
.regs
.eax
= 0x4f04;
373 task
->t
.regs
.ecx
= 0x000f;
374 task
->t
.regs
.edx
= 0x0001;
375 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESBX
;
376 task
->t
.buf_len
= par
->vbe_state_size
;
378 err
= uvesafb_exec(task
);
380 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
381 printk(KERN_WARNING
"uvesafb: VBE get state call "
382 "failed (eax=0x%x, err=%d)\n",
383 task
->t
.regs
.eax
, err
);
392 static void uvesafb_vbe_state_restore(struct uvesafb_par
*par
, u8
*state_buf
)
394 struct uvesafb_ktask
*task
;
400 task
= uvesafb_prep();
404 task
->t
.regs
.eax
= 0x4f04;
405 task
->t
.regs
.ecx
= 0x000f;
406 task
->t
.regs
.edx
= 0x0002;
407 task
->t
.buf_len
= par
->vbe_state_size
;
408 task
->t
.flags
= TF_BUF_ESBX
;
409 task
->buf
= state_buf
;
411 err
= uvesafb_exec(task
);
412 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f)
413 printk(KERN_WARNING
"uvesafb: VBE state restore call "
414 "failed (eax=0x%x, err=%d)\n",
415 task
->t
.regs
.eax
, err
);
420 static int __devinit
uvesafb_vbe_getinfo(struct uvesafb_ktask
*task
,
421 struct uvesafb_par
*par
)
425 task
->t
.regs
.eax
= 0x4f00;
426 task
->t
.flags
= TF_VBEIB
;
427 task
->t
.buf_len
= sizeof(struct vbe_ib
);
428 task
->buf
= &par
->vbe_ib
;
429 strncpy(par
->vbe_ib
.vbe_signature
, "VBE2", 4);
431 err
= uvesafb_exec(task
);
432 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
433 printk(KERN_ERR
"uvesafb: Getting VBE info block failed "
434 "(eax=0x%x, err=%d)\n", (u32
)task
->t
.regs
.eax
,
439 if (par
->vbe_ib
.vbe_version
< 0x0200) {
440 printk(KERN_ERR
"uvesafb: Sorry, pre-VBE 2.0 cards are "
445 if (!par
->vbe_ib
.mode_list_ptr
) {
446 printk(KERN_ERR
"uvesafb: Missing mode list!\n");
450 printk(KERN_INFO
"uvesafb: ");
453 * Convert string pointers and the mode list pointer into
454 * usable addresses. Print informational messages about the
455 * video adapter and its vendor.
457 if (par
->vbe_ib
.oem_vendor_name_ptr
)
459 ((char *)task
->buf
) + par
->vbe_ib
.oem_vendor_name_ptr
);
461 if (par
->vbe_ib
.oem_product_name_ptr
)
463 ((char *)task
->buf
) + par
->vbe_ib
.oem_product_name_ptr
);
465 if (par
->vbe_ib
.oem_product_rev_ptr
)
467 ((char *)task
->buf
) + par
->vbe_ib
.oem_product_rev_ptr
);
469 if (par
->vbe_ib
.oem_string_ptr
)
471 ((char *)task
->buf
) + par
->vbe_ib
.oem_string_ptr
);
473 printk("VBE v%d.%d\n", ((par
->vbe_ib
.vbe_version
& 0xff00) >> 8),
474 par
->vbe_ib
.vbe_version
& 0xff);
479 static int __devinit
uvesafb_vbe_getmodes(struct uvesafb_ktask
*task
,
480 struct uvesafb_par
*par
)
485 par
->vbe_modes_cnt
= 0;
487 /* Count available modes. */
488 mode
= (u16
*) (((u8
*)&par
->vbe_ib
) + par
->vbe_ib
.mode_list_ptr
);
489 while (*mode
!= 0xffff) {
490 par
->vbe_modes_cnt
++;
494 par
->vbe_modes
= kzalloc(sizeof(struct vbe_mode_ib
) *
495 par
->vbe_modes_cnt
, GFP_KERNEL
);
499 /* Get info about all available modes. */
500 mode
= (u16
*) (((u8
*)&par
->vbe_ib
) + par
->vbe_ib
.mode_list_ptr
);
501 while (*mode
!= 0xffff) {
502 struct vbe_mode_ib
*mib
;
505 task
->t
.regs
.eax
= 0x4f01;
506 task
->t
.regs
.ecx
= (u32
) *mode
;
507 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESDI
;
508 task
->t
.buf_len
= sizeof(struct vbe_mode_ib
);
509 task
->buf
= par
->vbe_modes
+ off
;
511 err
= uvesafb_exec(task
);
512 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
513 printk(KERN_WARNING
"uvesafb: Getting mode info block "
514 "for mode 0x%x failed (eax=0x%x, err=%d)\n",
515 *mode
, (u32
)task
->t
.regs
.eax
, err
);
517 par
->vbe_modes_cnt
--;
522 mib
->mode_id
= *mode
;
525 * We only want modes that are supported with the current
526 * hardware configuration, color, graphics and that have
527 * support for the LFB.
529 if ((mib
->mode_attr
& VBE_MODE_MASK
) == VBE_MODE_MASK
&&
530 mib
->bits_per_pixel
>= 8)
533 par
->vbe_modes_cnt
--;
536 mib
->depth
= mib
->red_len
+ mib
->green_len
+ mib
->blue_len
;
539 * Handle 8bpp modes and modes with broken color component
542 if (mib
->depth
== 0 || (mib
->depth
== 24 &&
543 mib
->bits_per_pixel
== 32))
544 mib
->depth
= mib
->bits_per_pixel
;
547 if (par
->vbe_modes_cnt
> 0)
554 * The Protected Mode Interface is 32-bit x86 code, so we only run it on
555 * x86 and not x86_64.
558 static int __devinit
uvesafb_vbe_getpmi(struct uvesafb_ktask
*task
,
559 struct uvesafb_par
*par
)
564 task
->t
.regs
.eax
= 0x4f0a;
565 task
->t
.regs
.ebx
= 0x0;
566 err
= uvesafb_exec(task
);
568 if ((task
->t
.regs
.eax
& 0xffff) != 0x4f || task
->t
.regs
.es
< 0xc000) {
569 par
->pmi_setpal
= par
->ypan
= 0;
571 par
->pmi_base
= (u16
*)phys_to_virt(((u32
)task
->t
.regs
.es
<< 4)
573 par
->pmi_start
= (u8
*)par
->pmi_base
+ par
->pmi_base
[1];
574 par
->pmi_pal
= (u8
*)par
->pmi_base
+ par
->pmi_base
[2];
575 printk(KERN_INFO
"uvesafb: protected mode interface info at "
577 (u16
)task
->t
.regs
.es
, (u16
)task
->t
.regs
.edi
);
578 printk(KERN_INFO
"uvesafb: pmi: set display start = %p, "
579 "set palette = %p\n", par
->pmi_start
,
582 if (par
->pmi_base
[3]) {
583 printk(KERN_INFO
"uvesafb: pmi: ports = ");
584 for (i
= par
->pmi_base
[3]/2;
585 par
->pmi_base
[i
] != 0xffff; i
++)
586 printk("%x ", par
->pmi_base
[i
]);
589 if (par
->pmi_base
[i
] != 0xffff) {
590 printk(KERN_INFO
"uvesafb: can't handle memory"
591 " requests, pmi disabled\n");
592 par
->ypan
= par
->pmi_setpal
= 0;
598 #endif /* CONFIG_X86_32 */
601 * Check whether a video mode is supported by the Video BIOS and is
602 * compatible with the monitor limits.
604 static int __devinit
uvesafb_is_valid_mode(struct fb_videomode
*mode
,
605 struct fb_info
*info
)
607 if (info
->monspecs
.gtf
) {
608 fb_videomode_to_var(&info
->var
, mode
);
609 if (fb_validate_mode(&info
->var
, info
))
613 if (uvesafb_vbe_find_mode(info
->par
, mode
->xres
, mode
->yres
, 8,
614 UVESAFB_EXACT_RES
) == -1)
620 static int __devinit
uvesafb_vbe_getedid(struct uvesafb_ktask
*task
,
621 struct fb_info
*info
)
623 struct uvesafb_par
*par
= info
->par
;
626 if (noedid
|| par
->vbe_ib
.vbe_version
< 0x0300)
629 task
->t
.regs
.eax
= 0x4f15;
630 task
->t
.regs
.ebx
= 0;
631 task
->t
.regs
.ecx
= 0;
635 err
= uvesafb_exec(task
);
637 if ((task
->t
.regs
.eax
& 0xffff) != 0x004f || err
)
640 if ((task
->t
.regs
.ebx
& 0x3) == 3) {
641 printk(KERN_INFO
"uvesafb: VBIOS/hardware supports both "
642 "DDC1 and DDC2 transfers\n");
643 } else if ((task
->t
.regs
.ebx
& 0x3) == 2) {
644 printk(KERN_INFO
"uvesafb: VBIOS/hardware supports DDC2 "
646 } else if ((task
->t
.regs
.ebx
& 0x3) == 1) {
647 printk(KERN_INFO
"uvesafb: VBIOS/hardware supports DDC1 "
650 printk(KERN_INFO
"uvesafb: VBIOS/hardware doesn't support "
655 task
->t
.regs
.eax
= 0x4f15;
656 task
->t
.regs
.ebx
= 1;
657 task
->t
.regs
.ecx
= task
->t
.regs
.edx
= 0;
658 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESDI
;
659 task
->t
.buf_len
= EDID_LENGTH
;
660 task
->buf
= kzalloc(EDID_LENGTH
, GFP_KERNEL
);
662 err
= uvesafb_exec(task
);
664 if ((task
->t
.regs
.eax
& 0xffff) == 0x004f && !err
) {
665 fb_edid_to_monspecs(task
->buf
, &info
->monspecs
);
667 if (info
->monspecs
.vfmax
&& info
->monspecs
.hfmax
) {
669 * If the maximum pixel clock wasn't specified in
670 * the EDID block, set it to 300 MHz.
672 if (info
->monspecs
.dclkmax
== 0)
673 info
->monspecs
.dclkmax
= 300 * 1000000;
674 info
->monspecs
.gtf
= 1;
684 static void __devinit
uvesafb_vbe_getmonspecs(struct uvesafb_ktask
*task
,
685 struct fb_info
*info
)
687 struct uvesafb_par
*par
= info
->par
;
690 memset(&info
->monspecs
, 0, sizeof(info
->monspecs
));
693 * If we don't get all necessary data from the EDID block,
694 * mark it as incompatible with the GTF and set nocrtc so
695 * that we always use the default BIOS refresh rate.
697 if (uvesafb_vbe_getedid(task
, info
)) {
698 info
->monspecs
.gtf
= 0;
702 /* Kernel command line overrides. */
704 info
->monspecs
.dclkmax
= maxclk
* 1000000;
706 info
->monspecs
.vfmax
= maxvf
;
708 info
->monspecs
.hfmax
= maxhf
* 1000;
711 * In case DDC transfers are not supported, the user can provide
712 * monitor limits manually. Lower limits are set to "safe" values.
714 if (info
->monspecs
.gtf
== 0 && maxclk
&& maxvf
&& maxhf
) {
715 info
->monspecs
.dclkmin
= 0;
716 info
->monspecs
.vfmin
= 60;
717 info
->monspecs
.hfmin
= 29000;
718 info
->monspecs
.gtf
= 1;
722 if (info
->monspecs
.gtf
)
724 "uvesafb: monitor limits: vf = %d Hz, hf = %d kHz, "
725 "clk = %d MHz\n", info
->monspecs
.vfmax
,
726 (int)(info
->monspecs
.hfmax
/ 1000),
727 (int)(info
->monspecs
.dclkmax
/ 1000000));
729 printk(KERN_INFO
"uvesafb: no monitor limits have been set, "
730 "default refresh rate will be used\n");
732 /* Add VBE modes to the modelist. */
733 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
734 struct fb_var_screeninfo var
;
735 struct vbe_mode_ib
*mode
;
736 struct fb_videomode vmode
;
738 mode
= &par
->vbe_modes
[i
];
739 memset(&var
, 0, sizeof(var
));
741 var
.xres
= mode
->x_res
;
742 var
.yres
= mode
->y_res
;
744 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60, &var
, info
);
745 fb_var_to_videomode(&vmode
, &var
);
746 fb_add_videomode(&vmode
, &info
->modelist
);
749 /* Add valid VESA modes to our modelist. */
750 for (i
= 0; i
< VESA_MODEDB_SIZE
; i
++) {
751 if (uvesafb_is_valid_mode((struct fb_videomode
*)
752 &vesa_modes
[i
], info
))
753 fb_add_videomode(&vesa_modes
[i
], &info
->modelist
);
756 for (i
= 0; i
< info
->monspecs
.modedb_len
; i
++) {
757 if (uvesafb_is_valid_mode(&info
->monspecs
.modedb
[i
], info
))
758 fb_add_videomode(&info
->monspecs
.modedb
[i
],
765 static void __devinit
uvesafb_vbe_getstatesize(struct uvesafb_ktask
*task
,
766 struct uvesafb_par
*par
)
773 * Get the VBE state buffer size. We want all available
774 * hardware state data (CL = 0x0f).
776 task
->t
.regs
.eax
= 0x4f04;
777 task
->t
.regs
.ecx
= 0x000f;
778 task
->t
.regs
.edx
= 0x0000;
781 err
= uvesafb_exec(task
);
783 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
784 printk(KERN_WARNING
"uvesafb: VBE state buffer size "
785 "cannot be determined (eax=0x%x, err=%d)\n",
786 task
->t
.regs
.eax
, err
);
787 par
->vbe_state_size
= 0;
791 par
->vbe_state_size
= 64 * (task
->t
.regs
.ebx
& 0xffff);
794 static int __devinit
uvesafb_vbe_init(struct fb_info
*info
)
796 struct uvesafb_ktask
*task
= NULL
;
797 struct uvesafb_par
*par
= info
->par
;
800 task
= uvesafb_prep();
804 err
= uvesafb_vbe_getinfo(task
, par
);
808 err
= uvesafb_vbe_getmodes(task
, par
);
812 par
->nocrtc
= nocrtc
;
814 par
->pmi_setpal
= pmi_setpal
;
817 if (par
->pmi_setpal
|| par
->ypan
) {
818 if (__supported_pte_mask
& _PAGE_NX
) {
819 par
->pmi_setpal
= par
->ypan
= 0;
820 printk(KERN_WARNING
"uvesafb: NX protection is actively."
821 "We have better not to use the PMI.\n");
823 uvesafb_vbe_getpmi(task
, par
);
827 /* The protected mode interface is not available on non-x86. */
828 par
->pmi_setpal
= par
->ypan
= 0;
831 INIT_LIST_HEAD(&info
->modelist
);
832 uvesafb_vbe_getmonspecs(task
, info
);
833 uvesafb_vbe_getstatesize(task
, par
);
835 out
: uvesafb_free(task
);
839 static int __devinit
uvesafb_vbe_init_mode(struct fb_info
*info
)
841 struct list_head
*pos
;
842 struct fb_modelist
*modelist
;
843 struct fb_videomode
*mode
;
844 struct uvesafb_par
*par
= info
->par
;
847 /* Has the user requested a specific VESA mode? */
849 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
850 if (par
->vbe_modes
[i
].mode_id
== vbemode
) {
852 uvesafb_setup_var(&info
->var
, info
,
853 &par
->vbe_modes
[modeid
]);
854 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
857 * With pixclock set to 0, the default BIOS
858 * timings will be used in set_par().
860 info
->var
.pixclock
= 0;
864 printk(KERN_INFO
"uvesafb: requested VBE mode 0x%x is "
865 "unavailable\n", vbemode
);
869 /* Count the modes in the modelist */
871 list_for_each(pos
, &info
->modelist
)
875 * Convert the modelist into a modedb so that we can use it with
878 mode
= kzalloc(i
* sizeof(*mode
), GFP_KERNEL
);
881 list_for_each(pos
, &info
->modelist
) {
882 modelist
= list_entry(pos
, struct fb_modelist
, list
);
883 mode
[i
] = modelist
->mode
;
888 mode_option
= UVESAFB_DEFAULT_MODE
;
890 i
= fb_find_mode(&info
->var
, info
, mode_option
, mode
, i
,
896 /* fb_find_mode() failed */
898 info
->var
.xres
= 640;
899 info
->var
.yres
= 480;
900 mode
= (struct fb_videomode
*)
901 fb_find_best_mode(&info
->var
, &info
->modelist
);
904 fb_videomode_to_var(&info
->var
, mode
);
906 modeid
= par
->vbe_modes
[0].mode_id
;
907 uvesafb_setup_var(&info
->var
, info
,
908 &par
->vbe_modes
[modeid
]);
909 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
916 /* Look for a matching VBE mode. */
917 modeid
= uvesafb_vbe_find_mode(par
, info
->var
.xres
, info
->var
.yres
,
918 info
->var
.bits_per_pixel
, UVESAFB_EXACT_RES
);
923 uvesafb_setup_var(&info
->var
, info
, &par
->vbe_modes
[modeid
]);
927 * If we are not VBE3.0+ compliant, we're done -- the BIOS will
928 * ignore our timings anyway.
930 if (par
->vbe_ib
.vbe_version
< 0x0300 || par
->nocrtc
)
931 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
937 static int uvesafb_setpalette(struct uvesafb_pal_entry
*entries
, int count
,
938 int start
, struct fb_info
*info
)
940 struct uvesafb_ktask
*task
;
942 struct uvesafb_par
*par
= info
->par
;
943 int i
= par
->mode_idx
;
948 * We support palette modifications for 8 bpp modes only, so
949 * there can never be more than 256 entries.
951 if (start
+ count
> 256)
955 /* Use VGA registers if mode is VGA-compatible. */
956 if (i
>= 0 && i
< par
->vbe_modes_cnt
&&
957 par
->vbe_modes
[i
].mode_attr
& VBE_MODE_VGACOMPAT
) {
958 for (i
= 0; i
< count
; i
++) {
959 outb_p(start
+ i
, dac_reg
);
960 outb_p(entries
[i
].red
, dac_val
);
961 outb_p(entries
[i
].green
, dac_val
);
962 outb_p(entries
[i
].blue
, dac_val
);
966 else if (par
->pmi_setpal
) {
967 __asm__
__volatile__(
969 : /* no return value */
970 : "a" (0x4f09), /* EAX */
972 "c" (count
), /* ECX */
973 "d" (start
), /* EDX */
974 "D" (entries
), /* EDI */
975 "S" (&par
->pmi_pal
)); /* ESI */
977 #endif /* CONFIG_X86_32 */
979 #endif /* CONFIG_X86 */
981 task
= uvesafb_prep();
985 task
->t
.regs
.eax
= 0x4f09;
986 task
->t
.regs
.ebx
= 0x0;
987 task
->t
.regs
.ecx
= count
;
988 task
->t
.regs
.edx
= start
;
989 task
->t
.flags
= TF_BUF_ESDI
;
990 task
->t
.buf_len
= sizeof(struct uvesafb_pal_entry
) * count
;
993 err
= uvesafb_exec(task
);
994 if ((task
->t
.regs
.eax
& 0xffff) != 0x004f)
1002 static int uvesafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1003 unsigned blue
, unsigned transp
,
1004 struct fb_info
*info
)
1006 struct uvesafb_pal_entry entry
;
1007 int shift
= 16 - dac_width
;
1010 if (regno
>= info
->cmap
.len
)
1013 if (info
->var
.bits_per_pixel
== 8) {
1014 entry
.red
= red
>> shift
;
1015 entry
.green
= green
>> shift
;
1016 entry
.blue
= blue
>> shift
;
1019 err
= uvesafb_setpalette(&entry
, 1, regno
, info
);
1020 } else if (regno
< 16) {
1021 switch (info
->var
.bits_per_pixel
) {
1023 if (info
->var
.red
.offset
== 10) {
1025 ((u32
*) (info
->pseudo_palette
))[regno
] =
1026 ((red
& 0xf800) >> 1) |
1027 ((green
& 0xf800) >> 6) |
1028 ((blue
& 0xf800) >> 11);
1031 ((u32
*) (info
->pseudo_palette
))[regno
] =
1033 ((green
& 0xfc00) >> 5) |
1034 ((blue
& 0xf800) >> 11);
1043 ((u32
*)(info
->pseudo_palette
))[regno
] =
1044 (red
<< info
->var
.red
.offset
) |
1045 (green
<< info
->var
.green
.offset
) |
1046 (blue
<< info
->var
.blue
.offset
);
1053 static int uvesafb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1055 struct uvesafb_pal_entry
*entries
;
1056 int shift
= 16 - dac_width
;
1059 if (info
->var
.bits_per_pixel
== 8) {
1060 if (cmap
->start
+ cmap
->len
> info
->cmap
.start
+
1061 info
->cmap
.len
|| cmap
->start
< info
->cmap
.start
)
1064 entries
= kmalloc(sizeof(*entries
) * cmap
->len
, GFP_KERNEL
);
1068 for (i
= 0; i
< cmap
->len
; i
++) {
1069 entries
[i
].red
= cmap
->red
[i
] >> shift
;
1070 entries
[i
].green
= cmap
->green
[i
] >> shift
;
1071 entries
[i
].blue
= cmap
->blue
[i
] >> shift
;
1074 err
= uvesafb_setpalette(entries
, cmap
->len
, cmap
->start
, info
);
1078 * For modes with bpp > 8, we only set the pseudo palette in
1079 * the fb_info struct. We rely on uvesafb_setcolreg to do all
1082 for (i
= 0; i
< cmap
->len
; i
++) {
1083 err
|= uvesafb_setcolreg(cmap
->start
+ i
, cmap
->red
[i
],
1084 cmap
->green
[i
], cmap
->blue
[i
],
1091 static int uvesafb_pan_display(struct fb_var_screeninfo
*var
,
1092 struct fb_info
*info
)
1094 #ifdef CONFIG_X86_32
1096 struct uvesafb_par
*par
= info
->par
;
1098 offset
= (var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
) / 4;
1101 * It turns out it's not the best idea to do panning via vm86,
1102 * so we only allow it if we have a PMI.
1104 if (par
->pmi_start
) {
1105 __asm__
__volatile__(
1107 : /* no return value */
1108 : "a" (0x4f07), /* EAX */
1110 "c" (offset
), /* ECX */
1111 "d" (offset
>> 16), /* EDX */
1112 "D" (&par
->pmi_start
)); /* EDI */
1118 static int uvesafb_blank(int blank
, struct fb_info
*info
)
1120 struct uvesafb_ktask
*task
;
1123 struct uvesafb_par
*par
= info
->par
;
1125 if (par
->vbe_ib
.capabilities
& VBE_CAP_VGACOMPAT
) {
1127 u8 seq
= 0, crtc17
= 0;
1129 if (blank
== FB_BLANK_POWERDOWN
) {
1136 err
= (blank
== FB_BLANK_UNBLANK
) ? 0 : -EINVAL
;
1139 vga_wseq(NULL
, 0x00, 0x01);
1140 seq
|= vga_rseq(NULL
, 0x01) & ~0x20;
1141 vga_wseq(NULL
, 0x00, seq
);
1143 crtc17
|= vga_rcrt(NULL
, 0x17) & ~0x80;
1145 vga_wcrt(NULL
, 0x17, crtc17
);
1146 vga_wseq(NULL
, 0x00, 0x03);
1148 #endif /* CONFIG_X86 */
1150 task
= uvesafb_prep();
1154 task
->t
.regs
.eax
= 0x4f10;
1156 case FB_BLANK_UNBLANK
:
1157 task
->t
.regs
.ebx
= 0x0001;
1159 case FB_BLANK_NORMAL
:
1160 task
->t
.regs
.ebx
= 0x0101; /* standby */
1162 case FB_BLANK_POWERDOWN
:
1163 task
->t
.regs
.ebx
= 0x0401; /* powerdown */
1169 err
= uvesafb_exec(task
);
1170 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f)
1172 out
: uvesafb_free(task
);
1177 static int uvesafb_open(struct fb_info
*info
, int user
)
1179 struct uvesafb_par
*par
= info
->par
;
1180 int cnt
= atomic_read(&par
->ref_count
);
1182 if (!cnt
&& par
->vbe_state_size
)
1183 par
->vbe_state_orig
= uvesafb_vbe_state_save(par
);
1185 atomic_inc(&par
->ref_count
);
1189 static int uvesafb_release(struct fb_info
*info
, int user
)
1191 struct uvesafb_ktask
*task
= NULL
;
1192 struct uvesafb_par
*par
= info
->par
;
1193 int cnt
= atomic_read(&par
->ref_count
);
1201 task
= uvesafb_prep();
1205 /* First, try to set the standard 80x25 text mode. */
1206 task
->t
.regs
.eax
= 0x0003;
1210 * Now try to restore whatever hardware state we might have
1211 * saved when the fb device was first opened.
1213 uvesafb_vbe_state_restore(par
, par
->vbe_state_orig
);
1215 atomic_dec(&par
->ref_count
);
1221 static int uvesafb_set_par(struct fb_info
*info
)
1223 struct uvesafb_par
*par
= info
->par
;
1224 struct uvesafb_ktask
*task
= NULL
;
1225 struct vbe_crtc_ib
*crtc
= NULL
;
1226 struct vbe_mode_ib
*mode
= NULL
;
1227 int i
, err
= 0, depth
= info
->var
.bits_per_pixel
;
1229 if (depth
> 8 && depth
!= 32)
1230 depth
= info
->var
.red
.length
+ info
->var
.green
.length
+
1231 info
->var
.blue
.length
;
1233 i
= uvesafb_vbe_find_mode(par
, info
->var
.xres
, info
->var
.yres
, depth
,
1234 UVESAFB_EXACT_RES
| UVESAFB_EXACT_DEPTH
);
1236 mode
= &par
->vbe_modes
[i
];
1240 task
= uvesafb_prep();
1244 task
->t
.regs
.eax
= 0x4f02;
1245 task
->t
.regs
.ebx
= mode
->mode_id
| 0x4000; /* use LFB */
1247 if (par
->vbe_ib
.vbe_version
>= 0x0300 && !par
->nocrtc
&&
1248 info
->var
.pixclock
!= 0) {
1249 task
->t
.regs
.ebx
|= 0x0800; /* use CRTC data */
1250 task
->t
.flags
= TF_BUF_ESDI
;
1251 crtc
= kzalloc(sizeof(struct vbe_crtc_ib
), GFP_KERNEL
);
1256 crtc
->horiz_start
= info
->var
.xres
+ info
->var
.right_margin
;
1257 crtc
->horiz_end
= crtc
->horiz_start
+ info
->var
.hsync_len
;
1258 crtc
->horiz_total
= crtc
->horiz_end
+ info
->var
.left_margin
;
1260 crtc
->vert_start
= info
->var
.yres
+ info
->var
.lower_margin
;
1261 crtc
->vert_end
= crtc
->vert_start
+ info
->var
.vsync_len
;
1262 crtc
->vert_total
= crtc
->vert_end
+ info
->var
.upper_margin
;
1264 crtc
->pixel_clock
= PICOS2KHZ(info
->var
.pixclock
) * 1000;
1265 crtc
->refresh_rate
= (u16
)(100 * (crtc
->pixel_clock
/
1266 (crtc
->vert_total
* crtc
->horiz_total
)));
1268 if (info
->var
.vmode
& FB_VMODE_DOUBLE
)
1270 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
1272 if (!(info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
))
1274 if (!(info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
))
1276 memcpy(&par
->crtc
, crtc
, sizeof(*crtc
));
1278 memset(&par
->crtc
, 0, sizeof(*crtc
));
1281 task
->t
.buf_len
= sizeof(struct vbe_crtc_ib
);
1282 task
->buf
= &par
->crtc
;
1284 err
= uvesafb_exec(task
);
1285 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
1287 * The mode switch might have failed because we tried to
1288 * use our own timings. Try again with the default timings.
1291 printk(KERN_WARNING
"uvesafb: mode switch failed "
1292 "(eax=0x%x, err=%d). Trying again with "
1293 "default timings.\n", task
->t
.regs
.eax
, err
);
1294 uvesafb_reset(task
);
1297 info
->var
.pixclock
= 0;
1300 printk(KERN_ERR
"uvesafb: mode switch failed (eax="
1301 "0x%x, err=%d)\n", task
->t
.regs
.eax
, err
);
1308 /* For 8bpp modes, always try to set the DAC to 8 bits. */
1309 if (par
->vbe_ib
.capabilities
& VBE_CAP_CAN_SWITCH_DAC
&&
1310 mode
->bits_per_pixel
<= 8) {
1311 uvesafb_reset(task
);
1312 task
->t
.regs
.eax
= 0x4f08;
1313 task
->t
.regs
.ebx
= 0x0800;
1315 err
= uvesafb_exec(task
);
1316 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f ||
1317 ((task
->t
.regs
.ebx
& 0xff00) >> 8) != 8) {
1324 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1325 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
1326 info
->fix
.line_length
= mode
->bytes_per_scan_line
;
1328 out
: if (crtc
!= NULL
)
1335 static void uvesafb_check_limits(struct fb_var_screeninfo
*var
,
1336 struct fb_info
*info
)
1338 const struct fb_videomode
*mode
;
1339 struct uvesafb_par
*par
= info
->par
;
1342 * If pixclock is set to 0, then we're using default BIOS timings
1343 * and thus don't have to perform any checks here.
1348 if (par
->vbe_ib
.vbe_version
< 0x0300) {
1349 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60, var
, info
);
1353 if (!fb_validate_mode(var
, info
))
1356 mode
= fb_find_best_mode(var
, &info
->modelist
);
1358 if (mode
->xres
== var
->xres
&& mode
->yres
== var
->yres
&&
1359 !(mode
->vmode
& (FB_VMODE_INTERLACED
| FB_VMODE_DOUBLE
))) {
1360 fb_videomode_to_var(var
, mode
);
1365 if (info
->monspecs
.gtf
&& !fb_get_mode(FB_MAXTIMINGS
, 0, var
, info
))
1367 /* Use default refresh rate */
1371 static int uvesafb_check_var(struct fb_var_screeninfo
*var
,
1372 struct fb_info
*info
)
1374 struct uvesafb_par
*par
= info
->par
;
1375 struct vbe_mode_ib
*mode
= NULL
;
1377 int depth
= var
->red
.length
+ var
->green
.length
+ var
->blue
.length
;
1380 * Various apps will use bits_per_pixel to set the color depth,
1381 * which is theoretically incorrect, but which we'll try to handle
1384 if (depth
== 0 || abs(depth
- var
->bits_per_pixel
) >= 8)
1385 depth
= var
->bits_per_pixel
;
1387 match
= uvesafb_vbe_find_mode(par
, var
->xres
, var
->yres
, depth
,
1392 mode
= &par
->vbe_modes
[match
];
1393 uvesafb_setup_var(var
, info
, mode
);
1396 * Check whether we have remapped enough memory for this mode.
1397 * We might be called at an early stage, when we haven't remapped
1398 * any memory yet, in which case we simply skip the check.
1400 if (var
->yres
* mode
->bytes_per_scan_line
> info
->fix
.smem_len
1401 && info
->fix
.smem_len
)
1404 if ((var
->vmode
& FB_VMODE_DOUBLE
) &&
1405 !(par
->vbe_modes
[match
].mode_attr
& 0x100))
1406 var
->vmode
&= ~FB_VMODE_DOUBLE
;
1408 if ((var
->vmode
& FB_VMODE_INTERLACED
) &&
1409 !(par
->vbe_modes
[match
].mode_attr
& 0x200))
1410 var
->vmode
&= ~FB_VMODE_INTERLACED
;
1412 uvesafb_check_limits(var
, info
);
1414 var
->xres_virtual
= var
->xres
;
1415 var
->yres_virtual
= (par
->ypan
) ?
1416 info
->fix
.smem_len
/ mode
->bytes_per_scan_line
:
1421 static struct fb_ops uvesafb_ops
= {
1422 .owner
= THIS_MODULE
,
1423 .fb_open
= uvesafb_open
,
1424 .fb_release
= uvesafb_release
,
1425 .fb_setcolreg
= uvesafb_setcolreg
,
1426 .fb_setcmap
= uvesafb_setcmap
,
1427 .fb_pan_display
= uvesafb_pan_display
,
1428 .fb_blank
= uvesafb_blank
,
1429 .fb_fillrect
= cfb_fillrect
,
1430 .fb_copyarea
= cfb_copyarea
,
1431 .fb_imageblit
= cfb_imageblit
,
1432 .fb_check_var
= uvesafb_check_var
,
1433 .fb_set_par
= uvesafb_set_par
,
1436 static void __devinit
uvesafb_init_info(struct fb_info
*info
,
1437 struct vbe_mode_ib
*mode
)
1439 unsigned int size_vmode
;
1440 unsigned int size_remap
;
1441 unsigned int size_total
;
1442 struct uvesafb_par
*par
= info
->par
;
1445 info
->pseudo_palette
= ((u8
*)info
->par
+ sizeof(struct uvesafb_par
));
1446 info
->fix
= uvesafb_fix
;
1447 info
->fix
.ypanstep
= par
->ypan
? 1 : 0;
1448 info
->fix
.ywrapstep
= (par
->ypan
> 1) ? 1 : 0;
1450 /* Disable blanking if the user requested so. */
1452 info
->fbops
->fb_blank
= NULL
;
1455 * Find out how much IO memory is required for the mode with
1456 * the highest resolution.
1459 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
1460 h
= par
->vbe_modes
[i
].bytes_per_scan_line
*
1461 par
->vbe_modes
[i
].y_res
;
1468 * size_vmode -- that is the amount of memory needed for the
1469 * used video mode, i.e. the minimum amount of
1473 size_vmode
= info
->var
.yres
* mode
->bytes_per_scan_line
;
1475 size_vmode
= info
->var
.yres
* info
->var
.xres
*
1476 ((info
->var
.bits_per_pixel
+ 7) >> 3);
1480 * size_total -- all video memory we have. Used for mtrr
1481 * entries, resource allocation and bounds
1484 size_total
= par
->vbe_ib
.total_memory
* 65536;
1486 size_total
= vram_total
* 1024 * 1024;
1487 if (size_total
< size_vmode
)
1488 size_total
= size_vmode
;
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.
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
;
1503 info
->fix
.smem_len
= size_remap
;
1504 info
->fix
.smem_start
= mode
->phys_base_ptr
;
1507 * We have to set yres_virtual here because when setup_var() was
1508 * called, smem_len wasn't defined yet.
1510 info
->var
.yres_virtual
= info
->fix
.smem_len
/
1511 mode
->bytes_per_scan_line
;
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
);
1520 printk(KERN_INFO
"uvesafb: scrolling: redraw\n");
1521 info
->var
.yres_virtual
= info
->var
.yres
;
1525 info
->flags
= FBINFO_FLAG_DEFAULT
|
1526 (par
->ypan
? FBINFO_HWACCEL_YPAN
: 0);
1529 info
->fbops
->fb_pan_display
= NULL
;
1532 static void __devinit
uvesafb_init_mtrr(struct fb_info
*info
)
1535 if (mtrr
&& !(info
->fix
.smem_start
& (PAGE_SIZE
- 1))) {
1536 int temp_size
= info
->fix
.smem_len
;
1537 unsigned int type
= 0;
1541 type
= MTRR_TYPE_UNCACHABLE
;
1544 type
= MTRR_TYPE_WRBACK
;
1547 type
= MTRR_TYPE_WRCOMB
;
1550 type
= MTRR_TYPE_WRTHROUGH
;
1560 /* Find the largest power-of-two */
1561 while (temp_size
& (temp_size
- 1))
1562 temp_size
&= (temp_size
- 1);
1564 /* Try and find a power of two to add */
1566 rc
= mtrr_add(info
->fix
.smem_start
,
1567 temp_size
, type
, 1);
1569 } while (temp_size
>= PAGE_SIZE
&& rc
== -EINVAL
);
1572 #endif /* CONFIG_MTRR */
1576 static ssize_t
uvesafb_show_vbe_ver(struct device
*dev
,
1577 struct device_attribute
*attr
, char *buf
)
1579 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1580 struct uvesafb_par
*par
= info
->par
;
1582 return snprintf(buf
, PAGE_SIZE
, "%.4x\n", par
->vbe_ib
.vbe_version
);
1585 static DEVICE_ATTR(vbe_version
, S_IRUGO
, uvesafb_show_vbe_ver
, NULL
);
1587 static ssize_t
uvesafb_show_vbe_modes(struct device
*dev
,
1588 struct device_attribute
*attr
, char *buf
)
1590 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1591 struct uvesafb_par
*par
= info
->par
;
1594 for (i
= 0; i
< par
->vbe_modes_cnt
&& ret
< PAGE_SIZE
; i
++) {
1595 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1596 "%dx%d-%d, 0x%.4x\n",
1597 par
->vbe_modes
[i
].x_res
, par
->vbe_modes
[i
].y_res
,
1598 par
->vbe_modes
[i
].depth
, par
->vbe_modes
[i
].mode_id
);
1604 static DEVICE_ATTR(vbe_modes
, S_IRUGO
, uvesafb_show_vbe_modes
, NULL
);
1606 static ssize_t
uvesafb_show_vendor(struct device
*dev
,
1607 struct device_attribute
*attr
, char *buf
)
1609 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1610 struct uvesafb_par
*par
= info
->par
;
1612 if (par
->vbe_ib
.oem_vendor_name_ptr
)
1613 return snprintf(buf
, PAGE_SIZE
, "%s\n", (char *)
1614 (&par
->vbe_ib
) + par
->vbe_ib
.oem_vendor_name_ptr
);
1619 static DEVICE_ATTR(oem_vendor
, S_IRUGO
, uvesafb_show_vendor
, NULL
);
1621 static ssize_t
uvesafb_show_product_name(struct device
*dev
,
1622 struct device_attribute
*attr
, char *buf
)
1624 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1625 struct uvesafb_par
*par
= info
->par
;
1627 if (par
->vbe_ib
.oem_product_name_ptr
)
1628 return snprintf(buf
, PAGE_SIZE
, "%s\n", (char *)
1629 (&par
->vbe_ib
) + par
->vbe_ib
.oem_product_name_ptr
);
1634 static DEVICE_ATTR(oem_product_name
, S_IRUGO
, uvesafb_show_product_name
, NULL
);
1636 static ssize_t
uvesafb_show_product_rev(struct device
*dev
,
1637 struct device_attribute
*attr
, char *buf
)
1639 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1640 struct uvesafb_par
*par
= info
->par
;
1642 if (par
->vbe_ib
.oem_product_rev_ptr
)
1643 return snprintf(buf
, PAGE_SIZE
, "%s\n", (char *)
1644 (&par
->vbe_ib
) + par
->vbe_ib
.oem_product_rev_ptr
);
1649 static DEVICE_ATTR(oem_product_rev
, S_IRUGO
, uvesafb_show_product_rev
, NULL
);
1651 static ssize_t
uvesafb_show_oem_string(struct device
*dev
,
1652 struct device_attribute
*attr
, char *buf
)
1654 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1655 struct uvesafb_par
*par
= info
->par
;
1657 if (par
->vbe_ib
.oem_string_ptr
)
1658 return snprintf(buf
, PAGE_SIZE
, "%s\n",
1659 (char *)(&par
->vbe_ib
) + par
->vbe_ib
.oem_string_ptr
);
1664 static DEVICE_ATTR(oem_string
, S_IRUGO
, uvesafb_show_oem_string
, NULL
);
1666 static ssize_t
uvesafb_show_nocrtc(struct device
*dev
,
1667 struct device_attribute
*attr
, char *buf
)
1669 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1670 struct uvesafb_par
*par
= info
->par
;
1672 return snprintf(buf
, PAGE_SIZE
, "%d\n", par
->nocrtc
);
1675 static ssize_t
uvesafb_store_nocrtc(struct device
*dev
,
1676 struct device_attribute
*attr
, const char *buf
, size_t count
)
1678 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1679 struct uvesafb_par
*par
= info
->par
;
1690 static DEVICE_ATTR(nocrtc
, S_IRUGO
| S_IWUSR
, uvesafb_show_nocrtc
,
1691 uvesafb_store_nocrtc
);
1693 static struct attribute
*uvesafb_dev_attrs
[] = {
1694 &dev_attr_vbe_version
.attr
,
1695 &dev_attr_vbe_modes
.attr
,
1696 &dev_attr_oem_vendor
.attr
,
1697 &dev_attr_oem_product_name
.attr
,
1698 &dev_attr_oem_product_rev
.attr
,
1699 &dev_attr_oem_string
.attr
,
1700 &dev_attr_nocrtc
.attr
,
1704 static struct attribute_group uvesafb_dev_attgrp
= {
1706 .attrs
= uvesafb_dev_attrs
,
1709 static int __devinit
uvesafb_probe(struct platform_device
*dev
)
1711 struct fb_info
*info
;
1712 struct vbe_mode_ib
*mode
= NULL
;
1713 struct uvesafb_par
*par
;
1716 info
= framebuffer_alloc(sizeof(*par
) + sizeof(u32
) * 256, &dev
->dev
);
1722 err
= uvesafb_vbe_init(info
);
1724 printk(KERN_ERR
"uvesafb: vbe_init() failed with %d\n", err
);
1728 info
->fbops
= &uvesafb_ops
;
1730 i
= uvesafb_vbe_init_mode(info
);
1735 mode
= &par
->vbe_modes
[i
];
1738 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
1743 uvesafb_init_info(info
, mode
);
1745 if (!request_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
,
1747 printk(KERN_ERR
"uvesafb: cannot reserve video memory at "
1748 "0x%lx\n", info
->fix
.smem_start
);
1753 info
->screen_base
= ioremap(info
->fix
.smem_start
, info
->fix
.smem_len
);
1755 if (!info
->screen_base
) {
1757 "uvesafb: abort, cannot ioremap 0x%x bytes of video "
1758 "memory at 0x%lx\n",
1759 info
->fix
.smem_len
, info
->fix
.smem_start
);
1764 if (!request_region(0x3c0, 32, "uvesafb")) {
1765 printk(KERN_ERR
"uvesafb: request region 0x3c0-0x3e0 failed\n");
1770 uvesafb_init_mtrr(info
);
1771 platform_set_drvdata(dev
, info
);
1773 if (register_framebuffer(info
) < 0) {
1775 "uvesafb: failed to register framebuffer device\n");
1780 printk(KERN_INFO
"uvesafb: framebuffer at 0x%lx, mapped to 0x%p, "
1781 "using %dk, total %dk\n", info
->fix
.smem_start
,
1782 info
->screen_base
, info
->fix
.smem_len
/1024,
1783 par
->vbe_ib
.total_memory
* 64);
1784 printk(KERN_INFO
"fb%d: %s frame buffer device\n", info
->node
,
1787 err
= sysfs_create_group(&dev
->dev
.kobj
, &uvesafb_dev_attgrp
);
1789 printk(KERN_WARNING
"fb%d: failed to register attributes\n",
1795 release_region(0x3c0, 32);
1797 iounmap(info
->screen_base
);
1799 release_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
);
1801 if (!list_empty(&info
->modelist
))
1802 fb_destroy_modelist(&info
->modelist
);
1803 fb_destroy_modedb(info
->monspecs
.modedb
);
1804 fb_dealloc_cmap(&info
->cmap
);
1807 kfree(par
->vbe_modes
);
1809 framebuffer_release(info
);
1813 static int uvesafb_remove(struct platform_device
*dev
)
1815 struct fb_info
*info
= platform_get_drvdata(dev
);
1818 struct uvesafb_par
*par
= info
->par
;
1820 sysfs_remove_group(&dev
->dev
.kobj
, &uvesafb_dev_attgrp
);
1821 unregister_framebuffer(info
);
1822 release_region(0x3c0, 32);
1823 iounmap(info
->screen_base
);
1824 release_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
);
1825 fb_destroy_modedb(info
->monspecs
.modedb
);
1826 fb_dealloc_cmap(&info
->cmap
);
1830 kfree(par
->vbe_modes
);
1831 if (par
->vbe_state_orig
)
1832 kfree(par
->vbe_state_orig
);
1833 if (par
->vbe_state_saved
)
1834 kfree(par
->vbe_state_saved
);
1837 framebuffer_release(info
);
1842 static struct platform_driver uvesafb_driver
= {
1843 .probe
= uvesafb_probe
,
1844 .remove
= uvesafb_remove
,
1850 static struct platform_device
*uvesafb_device
;
1853 static int __devinit
uvesafb_setup(char *options
)
1857 if (!options
|| !*options
)
1860 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1861 if (!*this_opt
) continue;
1863 if (!strcmp(this_opt
, "redraw"))
1865 else if (!strcmp(this_opt
, "ypan"))
1867 else if (!strcmp(this_opt
, "ywrap"))
1869 else if (!strcmp(this_opt
, "vgapal"))
1871 else if (!strcmp(this_opt
, "pmipal"))
1873 else if (!strncmp(this_opt
, "mtrr:", 5))
1874 mtrr
= simple_strtoul(this_opt
+5, NULL
, 0);
1875 else if (!strcmp(this_opt
, "nomtrr"))
1877 else if (!strcmp(this_opt
, "nocrtc"))
1879 else if (!strcmp(this_opt
, "noedid"))
1881 else if (!strcmp(this_opt
, "noblank"))
1883 else if (!strncmp(this_opt
, "vtotal:", 7))
1884 vram_total
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1885 else if (!strncmp(this_opt
, "vremap:", 7))
1886 vram_remap
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1887 else if (!strncmp(this_opt
, "maxhf:", 6))
1888 maxhf
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1889 else if (!strncmp(this_opt
, "maxvf:", 6))
1890 maxvf
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1891 else if (!strncmp(this_opt
, "maxclk:", 7))
1892 maxclk
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1893 else if (!strncmp(this_opt
, "vbemode:", 8))
1894 vbemode
= simple_strtoul(this_opt
+ 8, NULL
, 0);
1895 else if (this_opt
[0] >= '0' && this_opt
[0] <= '9') {
1896 mode_option
= this_opt
;
1899 "uvesafb: unrecognized option %s\n", this_opt
);
1905 #endif /* !MODULE */
1907 static ssize_t
show_v86d(struct device_driver
*dev
, char *buf
)
1909 return snprintf(buf
, PAGE_SIZE
, "%s\n", v86d_path
);
1912 static ssize_t
store_v86d(struct device_driver
*dev
, const char *buf
,
1915 strncpy(v86d_path
, buf
, PATH_MAX
);
1919 static DRIVER_ATTR(v86d
, S_IRUGO
| S_IWUSR
, show_v86d
, store_v86d
);
1921 static int __devinit
uvesafb_init(void)
1926 char *option
= NULL
;
1928 if (fb_get_options("uvesafb", &option
))
1930 uvesafb_setup(option
);
1932 err
= cn_add_callback(&uvesafb_cn_id
, "uvesafb", uvesafb_cn_callback
);
1936 err
= platform_driver_register(&uvesafb_driver
);
1939 uvesafb_device
= platform_device_alloc("uvesafb", 0);
1941 err
= platform_device_add(uvesafb_device
);
1946 platform_device_put(uvesafb_device
);
1947 platform_driver_unregister(&uvesafb_driver
);
1948 cn_del_callback(&uvesafb_cn_id
);
1952 err
= driver_create_file(&uvesafb_driver
.driver
,
1955 printk(KERN_WARNING
"uvesafb: failed to register "
1963 module_init(uvesafb_init
);
1965 static void __devexit
uvesafb_exit(void)
1967 struct uvesafb_ktask
*task
;
1970 task
= uvesafb_prep();
1972 task
->t
.flags
= TF_EXIT
;
1978 cn_del_callback(&uvesafb_cn_id
);
1979 driver_remove_file(&uvesafb_driver
.driver
, &driver_attr_v86d
);
1980 platform_device_unregister(uvesafb_device
);
1981 platform_driver_unregister(&uvesafb_driver
);
1984 module_exit(uvesafb_exit
);
1986 #define param_get_scroll NULL
1987 static int param_set_scroll(const char *val
, struct kernel_param
*kp
)
1991 if (!strcmp(val
, "redraw"))
1993 else if (!strcmp(val
, "ypan"))
1995 else if (!strcmp(val
, "ywrap"))
2003 #define param_check_scroll(name, p) __param_check(name, p, void)
2005 module_param_named(scroll
, ypan
, scroll
, 0);
2006 MODULE_PARM_DESC(scroll
,
2007 "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
2008 module_param_named(vgapal
, pmi_setpal
, invbool
, 0);
2009 MODULE_PARM_DESC(vgapal
, "Set palette using VGA registers");
2010 module_param_named(pmipal
, pmi_setpal
, bool, 0);
2011 MODULE_PARM_DESC(pmipal
, "Set palette using PMI calls");
2012 module_param(mtrr
, uint
, 0);
2013 MODULE_PARM_DESC(mtrr
,
2014 "Memory Type Range Registers setting. Use 0 to disable.");
2015 module_param(blank
, bool, 0);
2016 MODULE_PARM_DESC(blank
, "Enable hardware blanking");
2017 module_param(nocrtc
, bool, 0);
2018 MODULE_PARM_DESC(nocrtc
, "Ignore CRTC timings when setting modes");
2019 module_param(noedid
, bool, 0);
2020 MODULE_PARM_DESC(noedid
,
2021 "Ignore EDID-provided monitor limits when setting modes");
2022 module_param(vram_remap
, uint
, 0);
2023 MODULE_PARM_DESC(vram_remap
, "Set amount of video memory to be used [MiB]");
2024 module_param(vram_total
, uint
, 0);
2025 MODULE_PARM_DESC(vram_total
, "Set total amount of video memoery [MiB]");
2026 module_param(maxclk
, ushort
, 0);
2027 MODULE_PARM_DESC(maxclk
, "Maximum pixelclock [MHz], overrides EDID data");
2028 module_param(maxhf
, ushort
, 0);
2029 MODULE_PARM_DESC(maxhf
,
2030 "Maximum horizontal frequency [kHz], overrides EDID data");
2031 module_param(maxvf
, ushort
, 0);
2032 MODULE_PARM_DESC(maxvf
,
2033 "Maximum vertical frequency [Hz], overrides EDID data");
2034 module_param(mode_option
, charp
, 0);
2035 MODULE_PARM_DESC(mode_option
,
2036 "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
2037 module_param(vbemode
, ushort
, 0);
2038 MODULE_PARM_DESC(vbemode
,
2039 "VBE mode number to set, overrides the 'mode' option");
2040 module_param_string(v86d
, v86d_path
, PATH_MAX
, 0660);
2041 MODULE_PARM_DESC(v86d
, "Path to the v86d userspace helper.");
2043 MODULE_LICENSE("GPL");
2044 MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
2045 MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");