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.
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/skbuff.h>
15 #include <linux/timer.h>
16 #include <linux/completion.h>
17 #include <linux/connector.h>
18 #include <linux/random.h>
19 #include <linux/platform_device.h>
20 #include <linux/limits.h>
23 #include <linux/mutex.h>
24 #include <linux/slab.h>
25 #include <video/edid.h>
26 #include <video/uvesafb.h>
28 #include <video/vga.h>
32 static struct cb_id uvesafb_cn_id
= {
34 .val
= CN_VAL_V86D_UVESAFB
36 static char v86d_path
[PATH_MAX
] = "/sbin/v86d";
37 static char v86d_started
; /* has v86d been started by uvesafb? */
39 static const struct fb_fix_screeninfo uvesafb_fix
= {
41 .type
= FB_TYPE_PACKED_PIXELS
,
42 .accel
= FB_ACCEL_NONE
,
43 .visual
= FB_VISUAL_TRUECOLOR
,
46 static int mtrr
= 3; /* enable mtrr by default */
47 static bool blank
= 1; /* enable blanking by default */
48 static int ypan
= 1; /* 0: scroll, 1: ypan, 2: ywrap */
49 static bool pmi_setpal
= true; /* use PMI for palette changes */
50 static bool nocrtc
; /* ignore CRTC settings */
51 static bool noedid
; /* don't try DDC transfers */
52 static int vram_remap
; /* set amt. of memory to be used */
53 static int vram_total
; /* set total amount of memory */
54 static u16 maxclk
; /* maximum pixel clock */
55 static u16 maxvf
; /* maximum vertical frequency */
56 static u16 maxhf
; /* maximum horizontal frequency */
57 static u16 vbemode
; /* force use of a specific VBE mode */
58 static char *mode_option
;
59 static u8 dac_width
= 6;
61 static struct uvesafb_ktask
*uvfb_tasks
[UVESAFB_TASKS_MAX
];
62 static DEFINE_MUTEX(uvfb_lock
);
65 * A handler for replies from userspace.
67 * Make sure each message passes consistency checks and if it does,
68 * find the kernel part of the task struct, copy the registers and
69 * the buffer contents and then complete the task.
71 static void uvesafb_cn_callback(struct cn_msg
*msg
, struct netlink_skb_parms
*nsp
)
73 struct uvesafb_task
*utask
;
74 struct uvesafb_ktask
*task
;
76 if (!capable(CAP_SYS_ADMIN
))
79 if (msg
->seq
>= UVESAFB_TASKS_MAX
)
82 mutex_lock(&uvfb_lock
);
83 task
= uvfb_tasks
[msg
->seq
];
85 if (!task
|| msg
->ack
!= task
->ack
) {
86 mutex_unlock(&uvfb_lock
);
90 utask
= (struct uvesafb_task
*)msg
->data
;
92 /* Sanity checks for the buffer length. */
93 if (task
->t
.buf_len
< utask
->buf_len
||
94 utask
->buf_len
> msg
->len
- sizeof(*utask
)) {
95 mutex_unlock(&uvfb_lock
);
99 uvfb_tasks
[msg
->seq
] = NULL
;
100 mutex_unlock(&uvfb_lock
);
102 memcpy(&task
->t
, utask
, sizeof(*utask
));
104 if (task
->t
.buf_len
&& task
->buf
)
105 memcpy(task
->buf
, utask
+ 1, task
->t
.buf_len
);
107 complete(task
->done
);
111 static int uvesafb_helper_start(void)
124 return call_usermodehelper(v86d_path
, argv
, envp
, UMH_WAIT_PROC
);
128 * Execute a uvesafb task.
130 * Returns 0 if the task is executed successfully.
132 * A message sent to the userspace consists of the uvesafb_task
133 * struct and (optionally) a buffer. The uvesafb_task struct is
134 * a simplified version of uvesafb_ktask (its kernel counterpart)
135 * containing only the register values, flags and the length of
138 * Each message is assigned a sequence number (increased linearly)
139 * and a random ack number. The sequence number is used as a key
140 * for the uvfb_tasks array which holds pointers to uvesafb_ktask
141 * structs for all requests.
143 static int uvesafb_exec(struct uvesafb_ktask
*task
)
148 int len
= sizeof(task
->t
) + task
->t
.buf_len
;
151 * Check whether the message isn't longer than the maximum
152 * allowed by connector.
154 if (sizeof(*m
) + len
> CONNECTOR_MAX_MSG_SIZE
) {
155 pr_warn("message too long (%d), can't execute task\n",
156 (int)(sizeof(*m
) + len
));
160 m
= kzalloc(sizeof(*m
) + len
, GFP_KERNEL
);
164 init_completion(task
->done
);
166 memcpy(&m
->id
, &uvesafb_cn_id
, sizeof(m
->id
));
169 m
->ack
= prandom_u32();
171 /* uvesafb_task structure */
172 memcpy(m
+ 1, &task
->t
, sizeof(task
->t
));
175 memcpy((u8
*)(m
+ 1) + sizeof(task
->t
), task
->buf
, task
->t
.buf_len
);
178 * Save the message ack number so that we can find the kernel
179 * part of this task when a reply is received from userspace.
183 mutex_lock(&uvfb_lock
);
185 /* If all slots are taken -- bail out. */
186 if (uvfb_tasks
[seq
]) {
187 mutex_unlock(&uvfb_lock
);
192 /* Save a pointer to the kernel part of the task struct. */
193 uvfb_tasks
[seq
] = task
;
194 mutex_unlock(&uvfb_lock
);
196 err
= cn_netlink_send(m
, 0, 0, GFP_KERNEL
);
199 * Try to start the userspace helper if sending
200 * the request failed the first time.
202 err
= uvesafb_helper_start();
204 pr_err("failed to execute %s\n", v86d_path
);
205 pr_err("make sure that the v86d helper is installed and executable\n");
208 err
= cn_netlink_send(m
, 0, 0, gfp_any());
212 } else if (err
== -ENOBUFS
)
215 if (!err
&& !(task
->t
.flags
& TF_EXIT
))
216 err
= !wait_for_completion_timeout(task
->done
,
217 msecs_to_jiffies(UVESAFB_TIMEOUT
));
219 mutex_lock(&uvfb_lock
);
220 uvfb_tasks
[seq
] = NULL
;
221 mutex_unlock(&uvfb_lock
);
224 if (seq
>= UVESAFB_TASKS_MAX
)
232 * Free a uvesafb_ktask struct.
234 static void uvesafb_free(struct uvesafb_ktask
*task
)
243 * Prepare a uvesafb_ktask struct to be used again.
245 static void uvesafb_reset(struct uvesafb_ktask
*task
)
247 struct completion
*cpl
= task
->done
;
249 memset(task
, 0, sizeof(*task
));
254 * Allocate and prepare a uvesafb_ktask struct.
256 static struct uvesafb_ktask
*uvesafb_prep(void)
258 struct uvesafb_ktask
*task
;
260 task
= kzalloc(sizeof(*task
), GFP_KERNEL
);
262 task
->done
= kzalloc(sizeof(*task
->done
), GFP_KERNEL
);
271 static void uvesafb_setup_var(struct fb_var_screeninfo
*var
,
272 struct fb_info
*info
, struct vbe_mode_ib
*mode
)
274 struct uvesafb_par
*par
= info
->par
;
276 var
->vmode
= FB_VMODE_NONINTERLACED
;
277 var
->sync
= FB_SYNC_VERT_HIGH_ACT
;
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
:
287 var
->bits_per_pixel
= mode
->bits_per_pixel
;
289 if (var
->bits_per_pixel
== 15)
290 var
->bits_per_pixel
= 16;
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
;
303 var
->green
.offset
= 0;
304 var
->blue
.offset
= 0;
305 var
->transp
.offset
= 0;
308 var
->green
.length
= 8;
309 var
->blue
.length
= 8;
310 var
->transp
.length
= 0;
314 static int uvesafb_vbe_find_mode(struct uvesafb_par
*par
,
315 int xres
, int yres
, int depth
, unsigned char flags
)
317 int i
, match
= -1, h
= 0, d
= 0x7fffffff;
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
);
325 * We have an exact match in terms of resolution
331 if (h
< d
|| (h
== d
&& par
->vbe_modes
[i
].depth
> depth
)) {
338 if (flags
& UVESAFB_EXACT_DEPTH
&&
339 par
->vbe_modes
[match
].depth
!= depth
)
342 if (flags
& UVESAFB_EXACT_RES
&& d
> 24)
351 static u8
*uvesafb_vbe_state_save(struct uvesafb_par
*par
)
353 struct uvesafb_ktask
*task
;
357 if (!par
->vbe_state_size
)
360 state
= kmalloc(par
->vbe_state_size
, GFP_KERNEL
);
362 return ERR_PTR(-ENOMEM
);
364 task
= uvesafb_prep();
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
;
376 err
= uvesafb_exec(task
);
378 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
379 pr_warn("VBE get state call failed (eax=0x%x, err=%d)\n",
380 task
->t
.regs
.eax
, err
);
389 static void uvesafb_vbe_state_restore(struct uvesafb_par
*par
, u8
*state_buf
)
391 struct uvesafb_ktask
*task
;
397 task
= uvesafb_prep();
401 task
->t
.regs
.eax
= 0x4f04;
402 task
->t
.regs
.ecx
= 0x000f;
403 task
->t
.regs
.edx
= 0x0002;
404 task
->t
.buf_len
= par
->vbe_state_size
;
405 task
->t
.flags
= TF_BUF_ESBX
;
406 task
->buf
= state_buf
;
408 err
= uvesafb_exec(task
);
409 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f)
410 pr_warn("VBE state restore call failed (eax=0x%x, err=%d)\n",
411 task
->t
.regs
.eax
, err
);
416 static int uvesafb_vbe_getinfo(struct uvesafb_ktask
*task
,
417 struct uvesafb_par
*par
)
421 task
->t
.regs
.eax
= 0x4f00;
422 task
->t
.flags
= TF_VBEIB
;
423 task
->t
.buf_len
= sizeof(struct vbe_ib
);
424 task
->buf
= &par
->vbe_ib
;
425 strncpy(par
->vbe_ib
.vbe_signature
, "VBE2", 4);
427 err
= uvesafb_exec(task
);
428 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
429 pr_err("Getting VBE info block failed (eax=0x%x, err=%d)\n",
430 (u32
)task
->t
.regs
.eax
, err
);
434 if (par
->vbe_ib
.vbe_version
< 0x0200) {
435 pr_err("Sorry, pre-VBE 2.0 cards are not supported\n");
439 if (!par
->vbe_ib
.mode_list_ptr
) {
440 pr_err("Missing mode list!\n");
447 * Convert string pointers and the mode list pointer into
448 * usable addresses. Print informational messages about the
449 * video adapter and its vendor.
451 if (par
->vbe_ib
.oem_vendor_name_ptr
)
453 ((char *)task
->buf
) + par
->vbe_ib
.oem_vendor_name_ptr
);
455 if (par
->vbe_ib
.oem_product_name_ptr
)
457 ((char *)task
->buf
) + par
->vbe_ib
.oem_product_name_ptr
);
459 if (par
->vbe_ib
.oem_product_rev_ptr
)
461 ((char *)task
->buf
) + par
->vbe_ib
.oem_product_rev_ptr
);
463 if (par
->vbe_ib
.oem_string_ptr
)
465 ((char *)task
->buf
) + par
->vbe_ib
.oem_string_ptr
);
467 pr_cont("VBE v%d.%d\n",
468 (par
->vbe_ib
.vbe_version
& 0xff00) >> 8,
469 par
->vbe_ib
.vbe_version
& 0xff);
474 static int uvesafb_vbe_getmodes(struct uvesafb_ktask
*task
,
475 struct uvesafb_par
*par
)
480 par
->vbe_modes_cnt
= 0;
482 /* Count available modes. */
483 mode
= (u16
*) (((u8
*)&par
->vbe_ib
) + par
->vbe_ib
.mode_list_ptr
);
484 while (*mode
!= 0xffff) {
485 par
->vbe_modes_cnt
++;
489 par
->vbe_modes
= kzalloc(sizeof(struct vbe_mode_ib
) *
490 par
->vbe_modes_cnt
, GFP_KERNEL
);
494 /* Get info about all available modes. */
495 mode
= (u16
*) (((u8
*)&par
->vbe_ib
) + par
->vbe_ib
.mode_list_ptr
);
496 while (*mode
!= 0xffff) {
497 struct vbe_mode_ib
*mib
;
500 task
->t
.regs
.eax
= 0x4f01;
501 task
->t
.regs
.ecx
= (u32
) *mode
;
502 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESDI
;
503 task
->t
.buf_len
= sizeof(struct vbe_mode_ib
);
504 task
->buf
= par
->vbe_modes
+ off
;
506 err
= uvesafb_exec(task
);
507 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
508 pr_warn("Getting mode info block for mode 0x%x failed (eax=0x%x, err=%d)\n",
509 *mode
, (u32
)task
->t
.regs
.eax
, err
);
511 par
->vbe_modes_cnt
--;
516 mib
->mode_id
= *mode
;
519 * We only want modes that are supported with the current
520 * hardware configuration, color, graphics and that have
521 * support for the LFB.
523 if ((mib
->mode_attr
& VBE_MODE_MASK
) == VBE_MODE_MASK
&&
524 mib
->bits_per_pixel
>= 8)
527 par
->vbe_modes_cnt
--;
530 mib
->depth
= mib
->red_len
+ mib
->green_len
+ mib
->blue_len
;
533 * Handle 8bpp modes and modes with broken color component
536 if (mib
->depth
== 0 || (mib
->depth
== 24 &&
537 mib
->bits_per_pixel
== 32))
538 mib
->depth
= mib
->bits_per_pixel
;
541 if (par
->vbe_modes_cnt
> 0)
548 * The Protected Mode Interface is 32-bit x86 code, so we only run it on
549 * x86 and not x86_64.
552 static int uvesafb_vbe_getpmi(struct uvesafb_ktask
*task
,
553 struct uvesafb_par
*par
)
558 task
->t
.regs
.eax
= 0x4f0a;
559 task
->t
.regs
.ebx
= 0x0;
560 err
= uvesafb_exec(task
);
562 if ((task
->t
.regs
.eax
& 0xffff) != 0x4f || task
->t
.regs
.es
< 0xc000) {
563 par
->pmi_setpal
= par
->ypan
= 0;
565 par
->pmi_base
= (u16
*)phys_to_virt(((u32
)task
->t
.regs
.es
<< 4)
567 par
->pmi_start
= (u8
*)par
->pmi_base
+ par
->pmi_base
[1];
568 par
->pmi_pal
= (u8
*)par
->pmi_base
+ par
->pmi_base
[2];
569 pr_info("protected mode interface info at %04x:%04x\n",
570 (u16
)task
->t
.regs
.es
, (u16
)task
->t
.regs
.edi
);
571 pr_info("pmi: set display start = %p, set palette = %p\n",
572 par
->pmi_start
, par
->pmi_pal
);
574 if (par
->pmi_base
[3]) {
575 pr_info("pmi: ports =");
576 for (i
= par
->pmi_base
[3]/2;
577 par
->pmi_base
[i
] != 0xffff; i
++)
578 pr_cont(" %x", par
->pmi_base
[i
]);
581 if (par
->pmi_base
[i
] != 0xffff) {
582 pr_info("can't handle memory requests, pmi disabled\n");
583 par
->ypan
= par
->pmi_setpal
= 0;
589 #endif /* CONFIG_X86_32 */
592 * Check whether a video mode is supported by the Video BIOS and is
593 * compatible with the monitor limits.
595 static int uvesafb_is_valid_mode(struct fb_videomode
*mode
,
596 struct fb_info
*info
)
598 if (info
->monspecs
.gtf
) {
599 fb_videomode_to_var(&info
->var
, mode
);
600 if (fb_validate_mode(&info
->var
, info
))
604 if (uvesafb_vbe_find_mode(info
->par
, mode
->xres
, mode
->yres
, 8,
605 UVESAFB_EXACT_RES
) == -1)
611 static int uvesafb_vbe_getedid(struct uvesafb_ktask
*task
, struct fb_info
*info
)
613 struct uvesafb_par
*par
= info
->par
;
616 if (noedid
|| par
->vbe_ib
.vbe_version
< 0x0300)
619 task
->t
.regs
.eax
= 0x4f15;
620 task
->t
.regs
.ebx
= 0;
621 task
->t
.regs
.ecx
= 0;
625 err
= uvesafb_exec(task
);
627 if ((task
->t
.regs
.eax
& 0xffff) != 0x004f || err
)
630 if ((task
->t
.regs
.ebx
& 0x3) == 3) {
631 pr_info("VBIOS/hardware supports both DDC1 and DDC2 transfers\n");
632 } else if ((task
->t
.regs
.ebx
& 0x3) == 2) {
633 pr_info("VBIOS/hardware supports DDC2 transfers\n");
634 } else if ((task
->t
.regs
.ebx
& 0x3) == 1) {
635 pr_info("VBIOS/hardware supports DDC1 transfers\n");
637 pr_info("VBIOS/hardware doesn't support DDC transfers\n");
641 task
->t
.regs
.eax
= 0x4f15;
642 task
->t
.regs
.ebx
= 1;
643 task
->t
.regs
.ecx
= task
->t
.regs
.edx
= 0;
644 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESDI
;
645 task
->t
.buf_len
= EDID_LENGTH
;
646 task
->buf
= kzalloc(EDID_LENGTH
, GFP_KERNEL
);
650 err
= uvesafb_exec(task
);
652 if ((task
->t
.regs
.eax
& 0xffff) == 0x004f && !err
) {
653 fb_edid_to_monspecs(task
->buf
, &info
->monspecs
);
655 if (info
->monspecs
.vfmax
&& info
->monspecs
.hfmax
) {
657 * If the maximum pixel clock wasn't specified in
658 * the EDID block, set it to 300 MHz.
660 if (info
->monspecs
.dclkmax
== 0)
661 info
->monspecs
.dclkmax
= 300 * 1000000;
662 info
->monspecs
.gtf
= 1;
672 static void uvesafb_vbe_getmonspecs(struct uvesafb_ktask
*task
,
673 struct fb_info
*info
)
675 struct uvesafb_par
*par
= info
->par
;
678 memset(&info
->monspecs
, 0, sizeof(info
->monspecs
));
681 * If we don't get all necessary data from the EDID block,
682 * mark it as incompatible with the GTF and set nocrtc so
683 * that we always use the default BIOS refresh rate.
685 if (uvesafb_vbe_getedid(task
, info
)) {
686 info
->monspecs
.gtf
= 0;
690 /* Kernel command line overrides. */
692 info
->monspecs
.dclkmax
= maxclk
* 1000000;
694 info
->monspecs
.vfmax
= maxvf
;
696 info
->monspecs
.hfmax
= maxhf
* 1000;
699 * In case DDC transfers are not supported, the user can provide
700 * monitor limits manually. Lower limits are set to "safe" values.
702 if (info
->monspecs
.gtf
== 0 && maxclk
&& maxvf
&& maxhf
) {
703 info
->monspecs
.dclkmin
= 0;
704 info
->monspecs
.vfmin
= 60;
705 info
->monspecs
.hfmin
= 29000;
706 info
->monspecs
.gtf
= 1;
710 if (info
->monspecs
.gtf
)
711 pr_info("monitor limits: vf = %d Hz, hf = %d kHz, clk = %d MHz\n",
712 info
->monspecs
.vfmax
,
713 (int)(info
->monspecs
.hfmax
/ 1000),
714 (int)(info
->monspecs
.dclkmax
/ 1000000));
716 pr_info("no monitor limits have been set, default refresh rate will be used\n");
718 /* Add VBE modes to the modelist. */
719 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
720 struct fb_var_screeninfo var
;
721 struct vbe_mode_ib
*mode
;
722 struct fb_videomode vmode
;
724 mode
= &par
->vbe_modes
[i
];
725 memset(&var
, 0, sizeof(var
));
727 var
.xres
= mode
->x_res
;
728 var
.yres
= mode
->y_res
;
730 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60, &var
, info
);
731 fb_var_to_videomode(&vmode
, &var
);
732 fb_add_videomode(&vmode
, &info
->modelist
);
735 /* Add valid VESA modes to our modelist. */
736 for (i
= 0; i
< VESA_MODEDB_SIZE
; i
++) {
737 if (uvesafb_is_valid_mode((struct fb_videomode
*)
738 &vesa_modes
[i
], info
))
739 fb_add_videomode(&vesa_modes
[i
], &info
->modelist
);
742 for (i
= 0; i
< info
->monspecs
.modedb_len
; i
++) {
743 if (uvesafb_is_valid_mode(&info
->monspecs
.modedb
[i
], info
))
744 fb_add_videomode(&info
->monspecs
.modedb
[i
],
751 static void uvesafb_vbe_getstatesize(struct uvesafb_ktask
*task
,
752 struct uvesafb_par
*par
)
759 * Get the VBE state buffer size. We want all available
760 * hardware state data (CL = 0x0f).
762 task
->t
.regs
.eax
= 0x4f04;
763 task
->t
.regs
.ecx
= 0x000f;
764 task
->t
.regs
.edx
= 0x0000;
767 err
= uvesafb_exec(task
);
769 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
770 pr_warn("VBE state buffer size cannot be determined (eax=0x%x, err=%d)\n",
771 task
->t
.regs
.eax
, err
);
772 par
->vbe_state_size
= 0;
776 par
->vbe_state_size
= 64 * (task
->t
.regs
.ebx
& 0xffff);
779 static int uvesafb_vbe_init(struct fb_info
*info
)
781 struct uvesafb_ktask
*task
= NULL
;
782 struct uvesafb_par
*par
= info
->par
;
785 task
= uvesafb_prep();
789 err
= uvesafb_vbe_getinfo(task
, par
);
793 err
= uvesafb_vbe_getmodes(task
, par
);
797 par
->nocrtc
= nocrtc
;
799 par
->pmi_setpal
= pmi_setpal
;
802 if (par
->pmi_setpal
|| par
->ypan
) {
803 if (__supported_pte_mask
& _PAGE_NX
) {
804 par
->pmi_setpal
= par
->ypan
= 0;
805 pr_warn("NX protection is active, better not use the PMI\n");
807 uvesafb_vbe_getpmi(task
, par
);
811 /* The protected mode interface is not available on non-x86. */
812 par
->pmi_setpal
= par
->ypan
= 0;
815 INIT_LIST_HEAD(&info
->modelist
);
816 uvesafb_vbe_getmonspecs(task
, info
);
817 uvesafb_vbe_getstatesize(task
, par
);
819 out
: uvesafb_free(task
);
823 static int uvesafb_vbe_init_mode(struct fb_info
*info
)
825 struct list_head
*pos
;
826 struct fb_modelist
*modelist
;
827 struct fb_videomode
*mode
;
828 struct uvesafb_par
*par
= info
->par
;
831 /* Has the user requested a specific VESA mode? */
833 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
834 if (par
->vbe_modes
[i
].mode_id
== vbemode
) {
836 uvesafb_setup_var(&info
->var
, info
,
837 &par
->vbe_modes
[modeid
]);
838 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
841 * With pixclock set to 0, the default BIOS
842 * timings will be used in set_par().
844 info
->var
.pixclock
= 0;
848 pr_info("requested VBE mode 0x%x is unavailable\n", vbemode
);
852 /* Count the modes in the modelist */
854 list_for_each(pos
, &info
->modelist
)
858 * Convert the modelist into a modedb so that we can use it with
861 mode
= kzalloc(i
* sizeof(*mode
), GFP_KERNEL
);
864 list_for_each(pos
, &info
->modelist
) {
865 modelist
= list_entry(pos
, struct fb_modelist
, list
);
866 mode
[i
] = modelist
->mode
;
871 mode_option
= UVESAFB_DEFAULT_MODE
;
873 i
= fb_find_mode(&info
->var
, info
, mode_option
, mode
, i
,
879 /* fb_find_mode() failed */
881 info
->var
.xres
= 640;
882 info
->var
.yres
= 480;
883 mode
= (struct fb_videomode
*)
884 fb_find_best_mode(&info
->var
, &info
->modelist
);
887 fb_videomode_to_var(&info
->var
, mode
);
889 modeid
= par
->vbe_modes
[0].mode_id
;
890 uvesafb_setup_var(&info
->var
, info
,
891 &par
->vbe_modes
[modeid
]);
892 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
899 /* Look for a matching VBE mode. */
900 modeid
= uvesafb_vbe_find_mode(par
, info
->var
.xres
, info
->var
.yres
,
901 info
->var
.bits_per_pixel
, UVESAFB_EXACT_RES
);
906 uvesafb_setup_var(&info
->var
, info
, &par
->vbe_modes
[modeid
]);
910 * If we are not VBE3.0+ compliant, we're done -- the BIOS will
911 * ignore our timings anyway.
913 if (par
->vbe_ib
.vbe_version
< 0x0300 || par
->nocrtc
)
914 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
920 static int uvesafb_setpalette(struct uvesafb_pal_entry
*entries
, int count
,
921 int start
, struct fb_info
*info
)
923 struct uvesafb_ktask
*task
;
925 struct uvesafb_par
*par
= info
->par
;
926 int i
= par
->mode_idx
;
931 * We support palette modifications for 8 bpp modes only, so
932 * there can never be more than 256 entries.
934 if (start
+ count
> 256)
938 /* Use VGA registers if mode is VGA-compatible. */
939 if (i
>= 0 && i
< par
->vbe_modes_cnt
&&
940 par
->vbe_modes
[i
].mode_attr
& VBE_MODE_VGACOMPAT
) {
941 for (i
= 0; i
< count
; i
++) {
942 outb_p(start
+ i
, dac_reg
);
943 outb_p(entries
[i
].red
, dac_val
);
944 outb_p(entries
[i
].green
, dac_val
);
945 outb_p(entries
[i
].blue
, dac_val
);
949 else if (par
->pmi_setpal
) {
950 __asm__
__volatile__(
952 : /* no return value */
953 : "a" (0x4f09), /* EAX */
955 "c" (count
), /* ECX */
956 "d" (start
), /* EDX */
957 "D" (entries
), /* EDI */
958 "S" (&par
->pmi_pal
)); /* ESI */
960 #endif /* CONFIG_X86_32 */
962 #endif /* CONFIG_X86 */
964 task
= uvesafb_prep();
968 task
->t
.regs
.eax
= 0x4f09;
969 task
->t
.regs
.ebx
= 0x0;
970 task
->t
.regs
.ecx
= count
;
971 task
->t
.regs
.edx
= start
;
972 task
->t
.flags
= TF_BUF_ESDI
;
973 task
->t
.buf_len
= sizeof(struct uvesafb_pal_entry
) * count
;
976 err
= uvesafb_exec(task
);
977 if ((task
->t
.regs
.eax
& 0xffff) != 0x004f)
985 static int uvesafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
986 unsigned blue
, unsigned transp
,
987 struct fb_info
*info
)
989 struct uvesafb_pal_entry entry
;
990 int shift
= 16 - dac_width
;
993 if (regno
>= info
->cmap
.len
)
996 if (info
->var
.bits_per_pixel
== 8) {
997 entry
.red
= red
>> shift
;
998 entry
.green
= green
>> shift
;
999 entry
.blue
= blue
>> shift
;
1002 err
= uvesafb_setpalette(&entry
, 1, regno
, info
);
1003 } else if (regno
< 16) {
1004 switch (info
->var
.bits_per_pixel
) {
1006 if (info
->var
.red
.offset
== 10) {
1008 ((u32
*) (info
->pseudo_palette
))[regno
] =
1009 ((red
& 0xf800) >> 1) |
1010 ((green
& 0xf800) >> 6) |
1011 ((blue
& 0xf800) >> 11);
1014 ((u32
*) (info
->pseudo_palette
))[regno
] =
1016 ((green
& 0xfc00) >> 5) |
1017 ((blue
& 0xf800) >> 11);
1026 ((u32
*)(info
->pseudo_palette
))[regno
] =
1027 (red
<< info
->var
.red
.offset
) |
1028 (green
<< info
->var
.green
.offset
) |
1029 (blue
<< info
->var
.blue
.offset
);
1036 static int uvesafb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1038 struct uvesafb_pal_entry
*entries
;
1039 int shift
= 16 - dac_width
;
1042 if (info
->var
.bits_per_pixel
== 8) {
1043 if (cmap
->start
+ cmap
->len
> info
->cmap
.start
+
1044 info
->cmap
.len
|| cmap
->start
< info
->cmap
.start
)
1047 entries
= kmalloc(sizeof(*entries
) * cmap
->len
, GFP_KERNEL
);
1051 for (i
= 0; i
< cmap
->len
; i
++) {
1052 entries
[i
].red
= cmap
->red
[i
] >> shift
;
1053 entries
[i
].green
= cmap
->green
[i
] >> shift
;
1054 entries
[i
].blue
= cmap
->blue
[i
] >> shift
;
1057 err
= uvesafb_setpalette(entries
, cmap
->len
, cmap
->start
, info
);
1061 * For modes with bpp > 8, we only set the pseudo palette in
1062 * the fb_info struct. We rely on uvesafb_setcolreg to do all
1065 for (i
= 0; i
< cmap
->len
; i
++) {
1066 err
|= uvesafb_setcolreg(cmap
->start
+ i
, cmap
->red
[i
],
1067 cmap
->green
[i
], cmap
->blue
[i
],
1074 static int uvesafb_pan_display(struct fb_var_screeninfo
*var
,
1075 struct fb_info
*info
)
1077 #ifdef CONFIG_X86_32
1079 struct uvesafb_par
*par
= info
->par
;
1081 offset
= (var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
) / 4;
1084 * It turns out it's not the best idea to do panning via vm86,
1085 * so we only allow it if we have a PMI.
1087 if (par
->pmi_start
) {
1088 __asm__
__volatile__(
1090 : /* no return value */
1091 : "a" (0x4f07), /* EAX */
1093 "c" (offset
), /* ECX */
1094 "d" (offset
>> 16), /* EDX */
1095 "D" (&par
->pmi_start
)); /* EDI */
1101 static int uvesafb_blank(int blank
, struct fb_info
*info
)
1103 struct uvesafb_ktask
*task
;
1106 struct uvesafb_par
*par
= info
->par
;
1108 if (par
->vbe_ib
.capabilities
& VBE_CAP_VGACOMPAT
) {
1110 u8 seq
= 0, crtc17
= 0;
1112 if (blank
== FB_BLANK_POWERDOWN
) {
1119 err
= (blank
== FB_BLANK_UNBLANK
) ? 0 : -EINVAL
;
1122 vga_wseq(NULL
, 0x00, 0x01);
1123 seq
|= vga_rseq(NULL
, 0x01) & ~0x20;
1124 vga_wseq(NULL
, 0x00, seq
);
1126 crtc17
|= vga_rcrt(NULL
, 0x17) & ~0x80;
1128 vga_wcrt(NULL
, 0x17, crtc17
);
1129 vga_wseq(NULL
, 0x00, 0x03);
1131 #endif /* CONFIG_X86 */
1133 task
= uvesafb_prep();
1137 task
->t
.regs
.eax
= 0x4f10;
1139 case FB_BLANK_UNBLANK
:
1140 task
->t
.regs
.ebx
= 0x0001;
1142 case FB_BLANK_NORMAL
:
1143 task
->t
.regs
.ebx
= 0x0101; /* standby */
1145 case FB_BLANK_POWERDOWN
:
1146 task
->t
.regs
.ebx
= 0x0401; /* powerdown */
1152 err
= uvesafb_exec(task
);
1153 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f)
1155 out
: uvesafb_free(task
);
1160 static int uvesafb_open(struct fb_info
*info
, int user
)
1162 struct uvesafb_par
*par
= info
->par
;
1163 int cnt
= atomic_read(&par
->ref_count
);
1166 if (!cnt
&& par
->vbe_state_size
) {
1167 buf
= uvesafb_vbe_state_save(par
);
1169 pr_warn("save hardware state failed, error code is %ld!\n",
1172 par
->vbe_state_orig
= buf
;
1176 atomic_inc(&par
->ref_count
);
1180 static int uvesafb_release(struct fb_info
*info
, int user
)
1182 struct uvesafb_ktask
*task
= NULL
;
1183 struct uvesafb_par
*par
= info
->par
;
1184 int cnt
= atomic_read(&par
->ref_count
);
1192 task
= uvesafb_prep();
1196 /* First, try to set the standard 80x25 text mode. */
1197 task
->t
.regs
.eax
= 0x0003;
1201 * Now try to restore whatever hardware state we might have
1202 * saved when the fb device was first opened.
1204 uvesafb_vbe_state_restore(par
, par
->vbe_state_orig
);
1206 atomic_dec(&par
->ref_count
);
1211 static int uvesafb_set_par(struct fb_info
*info
)
1213 struct uvesafb_par
*par
= info
->par
;
1214 struct uvesafb_ktask
*task
= NULL
;
1215 struct vbe_crtc_ib
*crtc
= NULL
;
1216 struct vbe_mode_ib
*mode
= NULL
;
1217 int i
, err
= 0, depth
= info
->var
.bits_per_pixel
;
1219 if (depth
> 8 && depth
!= 32)
1220 depth
= info
->var
.red
.length
+ info
->var
.green
.length
+
1221 info
->var
.blue
.length
;
1223 i
= uvesafb_vbe_find_mode(par
, info
->var
.xres
, info
->var
.yres
, depth
,
1224 UVESAFB_EXACT_RES
| UVESAFB_EXACT_DEPTH
);
1226 mode
= &par
->vbe_modes
[i
];
1230 task
= uvesafb_prep();
1234 task
->t
.regs
.eax
= 0x4f02;
1235 task
->t
.regs
.ebx
= mode
->mode_id
| 0x4000; /* use LFB */
1237 if (par
->vbe_ib
.vbe_version
>= 0x0300 && !par
->nocrtc
&&
1238 info
->var
.pixclock
!= 0) {
1239 task
->t
.regs
.ebx
|= 0x0800; /* use CRTC data */
1240 task
->t
.flags
= TF_BUF_ESDI
;
1241 crtc
= kzalloc(sizeof(struct vbe_crtc_ib
), GFP_KERNEL
);
1246 crtc
->horiz_start
= info
->var
.xres
+ info
->var
.right_margin
;
1247 crtc
->horiz_end
= crtc
->horiz_start
+ info
->var
.hsync_len
;
1248 crtc
->horiz_total
= crtc
->horiz_end
+ info
->var
.left_margin
;
1250 crtc
->vert_start
= info
->var
.yres
+ info
->var
.lower_margin
;
1251 crtc
->vert_end
= crtc
->vert_start
+ info
->var
.vsync_len
;
1252 crtc
->vert_total
= crtc
->vert_end
+ info
->var
.upper_margin
;
1254 crtc
->pixel_clock
= PICOS2KHZ(info
->var
.pixclock
) * 1000;
1255 crtc
->refresh_rate
= (u16
)(100 * (crtc
->pixel_clock
/
1256 (crtc
->vert_total
* crtc
->horiz_total
)));
1258 if (info
->var
.vmode
& FB_VMODE_DOUBLE
)
1260 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
1262 if (!(info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
))
1264 if (!(info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
))
1266 memcpy(&par
->crtc
, crtc
, sizeof(*crtc
));
1268 memset(&par
->crtc
, 0, sizeof(*crtc
));
1271 task
->t
.buf_len
= sizeof(struct vbe_crtc_ib
);
1272 task
->buf
= &par
->crtc
;
1274 err
= uvesafb_exec(task
);
1275 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
1277 * The mode switch might have failed because we tried to
1278 * use our own timings. Try again with the default timings.
1281 pr_warn("mode switch failed (eax=0x%x, err=%d) - trying again with default timings\n",
1282 task
->t
.regs
.eax
, err
);
1283 uvesafb_reset(task
);
1286 info
->var
.pixclock
= 0;
1289 pr_err("mode switch failed (eax=0x%x, err=%d)\n",
1290 task
->t
.regs
.eax
, err
);
1297 /* For 8bpp modes, always try to set the DAC to 8 bits. */
1298 if (par
->vbe_ib
.capabilities
& VBE_CAP_CAN_SWITCH_DAC
&&
1299 mode
->bits_per_pixel
<= 8) {
1300 uvesafb_reset(task
);
1301 task
->t
.regs
.eax
= 0x4f08;
1302 task
->t
.regs
.ebx
= 0x0800;
1304 err
= uvesafb_exec(task
);
1305 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f ||
1306 ((task
->t
.regs
.ebx
& 0xff00) >> 8) != 8) {
1313 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1314 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
1315 info
->fix
.line_length
= mode
->bytes_per_scan_line
;
1324 static void uvesafb_check_limits(struct fb_var_screeninfo
*var
,
1325 struct fb_info
*info
)
1327 const struct fb_videomode
*mode
;
1328 struct uvesafb_par
*par
= info
->par
;
1331 * If pixclock is set to 0, then we're using default BIOS timings
1332 * and thus don't have to perform any checks here.
1337 if (par
->vbe_ib
.vbe_version
< 0x0300) {
1338 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60, var
, info
);
1342 if (!fb_validate_mode(var
, info
))
1345 mode
= fb_find_best_mode(var
, &info
->modelist
);
1347 if (mode
->xres
== var
->xres
&& mode
->yres
== var
->yres
&&
1348 !(mode
->vmode
& (FB_VMODE_INTERLACED
| FB_VMODE_DOUBLE
))) {
1349 fb_videomode_to_var(var
, mode
);
1354 if (info
->monspecs
.gtf
&& !fb_get_mode(FB_MAXTIMINGS
, 0, var
, info
))
1356 /* Use default refresh rate */
1360 static int uvesafb_check_var(struct fb_var_screeninfo
*var
,
1361 struct fb_info
*info
)
1363 struct uvesafb_par
*par
= info
->par
;
1364 struct vbe_mode_ib
*mode
= NULL
;
1366 int depth
= var
->red
.length
+ var
->green
.length
+ var
->blue
.length
;
1369 * Various apps will use bits_per_pixel to set the color depth,
1370 * which is theoretically incorrect, but which we'll try to handle
1373 if (depth
== 0 || abs(depth
- var
->bits_per_pixel
) >= 8)
1374 depth
= var
->bits_per_pixel
;
1376 match
= uvesafb_vbe_find_mode(par
, var
->xres
, var
->yres
, depth
,
1381 mode
= &par
->vbe_modes
[match
];
1382 uvesafb_setup_var(var
, info
, mode
);
1385 * Check whether we have remapped enough memory for this mode.
1386 * We might be called at an early stage, when we haven't remapped
1387 * any memory yet, in which case we simply skip the check.
1389 if (var
->yres
* mode
->bytes_per_scan_line
> info
->fix
.smem_len
1390 && info
->fix
.smem_len
)
1393 if ((var
->vmode
& FB_VMODE_DOUBLE
) &&
1394 !(par
->vbe_modes
[match
].mode_attr
& 0x100))
1395 var
->vmode
&= ~FB_VMODE_DOUBLE
;
1397 if ((var
->vmode
& FB_VMODE_INTERLACED
) &&
1398 !(par
->vbe_modes
[match
].mode_attr
& 0x200))
1399 var
->vmode
&= ~FB_VMODE_INTERLACED
;
1401 uvesafb_check_limits(var
, info
);
1403 var
->xres_virtual
= var
->xres
;
1404 var
->yres_virtual
= (par
->ypan
) ?
1405 info
->fix
.smem_len
/ mode
->bytes_per_scan_line
:
1410 static struct fb_ops uvesafb_ops
= {
1411 .owner
= THIS_MODULE
,
1412 .fb_open
= uvesafb_open
,
1413 .fb_release
= uvesafb_release
,
1414 .fb_setcolreg
= uvesafb_setcolreg
,
1415 .fb_setcmap
= uvesafb_setcmap
,
1416 .fb_pan_display
= uvesafb_pan_display
,
1417 .fb_blank
= uvesafb_blank
,
1418 .fb_fillrect
= cfb_fillrect
,
1419 .fb_copyarea
= cfb_copyarea
,
1420 .fb_imageblit
= cfb_imageblit
,
1421 .fb_check_var
= uvesafb_check_var
,
1422 .fb_set_par
= uvesafb_set_par
,
1425 static void uvesafb_init_info(struct fb_info
*info
, struct vbe_mode_ib
*mode
)
1427 unsigned int size_vmode
;
1428 unsigned int size_remap
;
1429 unsigned int size_total
;
1430 struct uvesafb_par
*par
= info
->par
;
1433 info
->pseudo_palette
= ((u8
*)info
->par
+ sizeof(struct uvesafb_par
));
1434 info
->fix
= uvesafb_fix
;
1435 info
->fix
.ypanstep
= par
->ypan
? 1 : 0;
1436 info
->fix
.ywrapstep
= (par
->ypan
> 1) ? 1 : 0;
1438 /* Disable blanking if the user requested so. */
1440 info
->fbops
->fb_blank
= NULL
;
1443 * Find out how much IO memory is required for the mode with
1444 * the highest resolution.
1447 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
1448 h
= par
->vbe_modes
[i
].bytes_per_scan_line
*
1449 par
->vbe_modes
[i
].y_res
;
1456 * size_vmode -- that is the amount of memory needed for the
1457 * used video mode, i.e. the minimum amount of
1460 size_vmode
= info
->var
.yres
* mode
->bytes_per_scan_line
;
1463 * size_total -- all video memory we have. Used for mtrr
1464 * entries, resource allocation and bounds
1467 size_total
= par
->vbe_ib
.total_memory
* 65536;
1469 size_total
= vram_total
* 1024 * 1024;
1470 if (size_total
< size_vmode
)
1471 size_total
= size_vmode
;
1474 * size_remap -- the amount of video memory we are going to
1475 * use for vesafb. With modern cards it is no
1476 * option to simply use size_total as th
1477 * wastes plenty of kernel address space.
1480 size_remap
= vram_remap
* 1024 * 1024;
1481 if (size_remap
< size_vmode
)
1482 size_remap
= size_vmode
;
1483 if (size_remap
> size_total
)
1484 size_remap
= size_total
;
1486 info
->fix
.smem_len
= size_remap
;
1487 info
->fix
.smem_start
= mode
->phys_base_ptr
;
1490 * We have to set yres_virtual here because when setup_var() was
1491 * called, smem_len wasn't defined yet.
1493 info
->var
.yres_virtual
= info
->fix
.smem_len
/
1494 mode
->bytes_per_scan_line
;
1496 if (par
->ypan
&& info
->var
.yres_virtual
> info
->var
.yres
) {
1497 pr_info("scrolling: %s using protected mode interface, yres_virtual=%d\n",
1498 (par
->ypan
> 1) ? "ywrap" : "ypan",
1499 info
->var
.yres_virtual
);
1501 pr_info("scrolling: redraw\n");
1502 info
->var
.yres_virtual
= info
->var
.yres
;
1506 info
->flags
= FBINFO_FLAG_DEFAULT
|
1507 (par
->ypan
? FBINFO_HWACCEL_YPAN
: 0);
1510 info
->fbops
->fb_pan_display
= NULL
;
1513 static void uvesafb_init_mtrr(struct fb_info
*info
)
1515 struct uvesafb_par
*par
= info
->par
;
1517 if (mtrr
&& !(info
->fix
.smem_start
& (PAGE_SIZE
- 1))) {
1518 int temp_size
= info
->fix
.smem_len
;
1522 /* Find the largest power-of-two */
1523 temp_size
= roundup_pow_of_two(temp_size
);
1525 /* Try and find a power of two to add */
1527 rc
= arch_phys_wc_add(info
->fix
.smem_start
, temp_size
);
1529 } while (temp_size
>= PAGE_SIZE
&& rc
== -EINVAL
);
1532 par
->mtrr_handle
= rc
;
1536 static void uvesafb_ioremap(struct fb_info
*info
)
1538 info
->screen_base
= ioremap_wc(info
->fix
.smem_start
, info
->fix
.smem_len
);
1541 static ssize_t
uvesafb_show_vbe_ver(struct device
*dev
,
1542 struct device_attribute
*attr
, char *buf
)
1544 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1545 struct uvesafb_par
*par
= info
->par
;
1547 return snprintf(buf
, PAGE_SIZE
, "%.4x\n", par
->vbe_ib
.vbe_version
);
1550 static DEVICE_ATTR(vbe_version
, S_IRUGO
, uvesafb_show_vbe_ver
, NULL
);
1552 static ssize_t
uvesafb_show_vbe_modes(struct device
*dev
,
1553 struct device_attribute
*attr
, char *buf
)
1555 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1556 struct uvesafb_par
*par
= info
->par
;
1559 for (i
= 0; i
< par
->vbe_modes_cnt
&& ret
< PAGE_SIZE
; i
++) {
1560 ret
+= snprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1561 "%dx%d-%d, 0x%.4x\n",
1562 par
->vbe_modes
[i
].x_res
, par
->vbe_modes
[i
].y_res
,
1563 par
->vbe_modes
[i
].depth
, par
->vbe_modes
[i
].mode_id
);
1569 static DEVICE_ATTR(vbe_modes
, S_IRUGO
, uvesafb_show_vbe_modes
, NULL
);
1571 static ssize_t
uvesafb_show_vendor(struct device
*dev
,
1572 struct device_attribute
*attr
, char *buf
)
1574 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1575 struct uvesafb_par
*par
= info
->par
;
1577 if (par
->vbe_ib
.oem_vendor_name_ptr
)
1578 return snprintf(buf
, PAGE_SIZE
, "%s\n", (char *)
1579 (&par
->vbe_ib
) + par
->vbe_ib
.oem_vendor_name_ptr
);
1584 static DEVICE_ATTR(oem_vendor
, S_IRUGO
, uvesafb_show_vendor
, NULL
);
1586 static ssize_t
uvesafb_show_product_name(struct device
*dev
,
1587 struct device_attribute
*attr
, char *buf
)
1589 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1590 struct uvesafb_par
*par
= info
->par
;
1592 if (par
->vbe_ib
.oem_product_name_ptr
)
1593 return snprintf(buf
, PAGE_SIZE
, "%s\n", (char *)
1594 (&par
->vbe_ib
) + par
->vbe_ib
.oem_product_name_ptr
);
1599 static DEVICE_ATTR(oem_product_name
, S_IRUGO
, uvesafb_show_product_name
, NULL
);
1601 static ssize_t
uvesafb_show_product_rev(struct device
*dev
,
1602 struct device_attribute
*attr
, char *buf
)
1604 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1605 struct uvesafb_par
*par
= info
->par
;
1607 if (par
->vbe_ib
.oem_product_rev_ptr
)
1608 return snprintf(buf
, PAGE_SIZE
, "%s\n", (char *)
1609 (&par
->vbe_ib
) + par
->vbe_ib
.oem_product_rev_ptr
);
1614 static DEVICE_ATTR(oem_product_rev
, S_IRUGO
, uvesafb_show_product_rev
, NULL
);
1616 static ssize_t
uvesafb_show_oem_string(struct device
*dev
,
1617 struct device_attribute
*attr
, char *buf
)
1619 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1620 struct uvesafb_par
*par
= info
->par
;
1622 if (par
->vbe_ib
.oem_string_ptr
)
1623 return snprintf(buf
, PAGE_SIZE
, "%s\n",
1624 (char *)(&par
->vbe_ib
) + par
->vbe_ib
.oem_string_ptr
);
1629 static DEVICE_ATTR(oem_string
, S_IRUGO
, uvesafb_show_oem_string
, NULL
);
1631 static ssize_t
uvesafb_show_nocrtc(struct device
*dev
,
1632 struct device_attribute
*attr
, char *buf
)
1634 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1635 struct uvesafb_par
*par
= info
->par
;
1637 return snprintf(buf
, PAGE_SIZE
, "%d\n", par
->nocrtc
);
1640 static ssize_t
uvesafb_store_nocrtc(struct device
*dev
,
1641 struct device_attribute
*attr
, const char *buf
, size_t count
)
1643 struct fb_info
*info
= platform_get_drvdata(to_platform_device(dev
));
1644 struct uvesafb_par
*par
= info
->par
;
1655 static DEVICE_ATTR(nocrtc
, S_IRUGO
| S_IWUSR
, uvesafb_show_nocrtc
,
1656 uvesafb_store_nocrtc
);
1658 static struct attribute
*uvesafb_dev_attrs
[] = {
1659 &dev_attr_vbe_version
.attr
,
1660 &dev_attr_vbe_modes
.attr
,
1661 &dev_attr_oem_vendor
.attr
,
1662 &dev_attr_oem_product_name
.attr
,
1663 &dev_attr_oem_product_rev
.attr
,
1664 &dev_attr_oem_string
.attr
,
1665 &dev_attr_nocrtc
.attr
,
1669 static const struct attribute_group uvesafb_dev_attgrp
= {
1671 .attrs
= uvesafb_dev_attrs
,
1674 static int uvesafb_probe(struct platform_device
*dev
)
1676 struct fb_info
*info
;
1677 struct vbe_mode_ib
*mode
= NULL
;
1678 struct uvesafb_par
*par
;
1681 info
= framebuffer_alloc(sizeof(*par
) + sizeof(u32
) * 256, &dev
->dev
);
1687 err
= uvesafb_vbe_init(info
);
1689 pr_err("vbe_init() failed with %d\n", err
);
1693 info
->fbops
= &uvesafb_ops
;
1695 i
= uvesafb_vbe_init_mode(info
);
1700 mode
= &par
->vbe_modes
[i
];
1703 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
1708 uvesafb_init_info(info
, mode
);
1710 if (!request_region(0x3c0, 32, "uvesafb")) {
1711 pr_err("request region 0x3c0-0x3e0 failed\n");
1716 if (!request_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
,
1718 pr_err("cannot reserve video memory at 0x%lx\n",
1719 info
->fix
.smem_start
);
1724 uvesafb_init_mtrr(info
);
1725 uvesafb_ioremap(info
);
1727 if (!info
->screen_base
) {
1728 pr_err("abort, cannot ioremap 0x%x bytes of video memory at 0x%lx\n",
1729 info
->fix
.smem_len
, info
->fix
.smem_start
);
1734 platform_set_drvdata(dev
, info
);
1736 if (register_framebuffer(info
) < 0) {
1737 pr_err("failed to register framebuffer device\n");
1742 pr_info("framebuffer at 0x%lx, mapped to 0x%p, using %dk, total %dk\n",
1743 info
->fix
.smem_start
, info
->screen_base
,
1744 info
->fix
.smem_len
/ 1024, par
->vbe_ib
.total_memory
* 64);
1745 fb_info(info
, "%s frame buffer device\n", info
->fix
.id
);
1747 err
= sysfs_create_group(&dev
->dev
.kobj
, &uvesafb_dev_attgrp
);
1749 fb_warn(info
, "failed to register attributes\n");
1754 iounmap(info
->screen_base
);
1756 release_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
);
1758 release_region(0x3c0, 32);
1760 if (!list_empty(&info
->modelist
))
1761 fb_destroy_modelist(&info
->modelist
);
1762 fb_destroy_modedb(info
->monspecs
.modedb
);
1763 fb_dealloc_cmap(&info
->cmap
);
1765 kfree(par
->vbe_modes
);
1767 framebuffer_release(info
);
1771 static int uvesafb_remove(struct platform_device
*dev
)
1773 struct fb_info
*info
= platform_get_drvdata(dev
);
1776 struct uvesafb_par
*par
= info
->par
;
1778 sysfs_remove_group(&dev
->dev
.kobj
, &uvesafb_dev_attgrp
);
1779 unregister_framebuffer(info
);
1780 release_region(0x3c0, 32);
1781 iounmap(info
->screen_base
);
1782 arch_phys_wc_del(par
->mtrr_handle
);
1783 release_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
);
1784 fb_destroy_modedb(info
->monspecs
.modedb
);
1785 fb_dealloc_cmap(&info
->cmap
);
1787 kfree(par
->vbe_modes
);
1788 kfree(par
->vbe_state_orig
);
1789 kfree(par
->vbe_state_saved
);
1791 framebuffer_release(info
);
1796 static struct platform_driver uvesafb_driver
= {
1797 .probe
= uvesafb_probe
,
1798 .remove
= uvesafb_remove
,
1804 static struct platform_device
*uvesafb_device
;
1807 static int uvesafb_setup(char *options
)
1811 if (!options
|| !*options
)
1814 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1815 if (!*this_opt
) continue;
1817 if (!strcmp(this_opt
, "redraw"))
1819 else if (!strcmp(this_opt
, "ypan"))
1821 else if (!strcmp(this_opt
, "ywrap"))
1823 else if (!strcmp(this_opt
, "vgapal"))
1825 else if (!strcmp(this_opt
, "pmipal"))
1827 else if (!strncmp(this_opt
, "mtrr:", 5))
1828 mtrr
= simple_strtoul(this_opt
+5, NULL
, 0);
1829 else if (!strcmp(this_opt
, "nomtrr"))
1831 else if (!strcmp(this_opt
, "nocrtc"))
1833 else if (!strcmp(this_opt
, "noedid"))
1835 else if (!strcmp(this_opt
, "noblank"))
1837 else if (!strncmp(this_opt
, "vtotal:", 7))
1838 vram_total
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1839 else if (!strncmp(this_opt
, "vremap:", 7))
1840 vram_remap
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1841 else if (!strncmp(this_opt
, "maxhf:", 6))
1842 maxhf
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1843 else if (!strncmp(this_opt
, "maxvf:", 6))
1844 maxvf
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1845 else if (!strncmp(this_opt
, "maxclk:", 7))
1846 maxclk
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1847 else if (!strncmp(this_opt
, "vbemode:", 8))
1848 vbemode
= simple_strtoul(this_opt
+ 8, NULL
, 0);
1849 else if (this_opt
[0] >= '0' && this_opt
[0] <= '9') {
1850 mode_option
= this_opt
;
1852 pr_warn("unrecognized option %s\n", this_opt
);
1856 if (mtrr
!= 3 && mtrr
!= 0)
1857 pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr
);
1861 #endif /* !MODULE */
1863 static ssize_t
v86d_show(struct device_driver
*dev
, char *buf
)
1865 return snprintf(buf
, PAGE_SIZE
, "%s\n", v86d_path
);
1868 static ssize_t
v86d_store(struct device_driver
*dev
, const char *buf
,
1871 strncpy(v86d_path
, buf
, PATH_MAX
);
1874 static DRIVER_ATTR_RW(v86d
);
1876 static int uvesafb_init(void)
1881 char *option
= NULL
;
1883 if (fb_get_options("uvesafb", &option
))
1885 uvesafb_setup(option
);
1887 err
= cn_add_callback(&uvesafb_cn_id
, "uvesafb", uvesafb_cn_callback
);
1891 err
= platform_driver_register(&uvesafb_driver
);
1894 uvesafb_device
= platform_device_alloc("uvesafb", 0);
1896 err
= platform_device_add(uvesafb_device
);
1901 platform_device_put(uvesafb_device
);
1902 platform_driver_unregister(&uvesafb_driver
);
1903 cn_del_callback(&uvesafb_cn_id
);
1907 err
= driver_create_file(&uvesafb_driver
.driver
,
1910 pr_warn("failed to register attributes\n");
1917 module_init(uvesafb_init
);
1919 static void uvesafb_exit(void)
1921 struct uvesafb_ktask
*task
;
1924 task
= uvesafb_prep();
1926 task
->t
.flags
= TF_EXIT
;
1932 cn_del_callback(&uvesafb_cn_id
);
1933 driver_remove_file(&uvesafb_driver
.driver
, &driver_attr_v86d
);
1934 platform_device_unregister(uvesafb_device
);
1935 platform_driver_unregister(&uvesafb_driver
);
1938 module_exit(uvesafb_exit
);
1940 static int param_set_scroll(const char *val
, const struct kernel_param
*kp
)
1944 if (!strcmp(val
, "redraw"))
1946 else if (!strcmp(val
, "ypan"))
1948 else if (!strcmp(val
, "ywrap"))
1955 static const struct kernel_param_ops param_ops_scroll
= {
1956 .set
= param_set_scroll
,
1958 #define param_check_scroll(name, p) __param_check(name, p, void)
1960 module_param_named(scroll
, ypan
, scroll
, 0);
1961 MODULE_PARM_DESC(scroll
,
1962 "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
1963 module_param_named(vgapal
, pmi_setpal
, invbool
, 0);
1964 MODULE_PARM_DESC(vgapal
, "Set palette using VGA registers");
1965 module_param_named(pmipal
, pmi_setpal
, bool, 0);
1966 MODULE_PARM_DESC(pmipal
, "Set palette using PMI calls");
1967 module_param(mtrr
, uint
, 0);
1968 MODULE_PARM_DESC(mtrr
,
1969 "Memory Type Range Registers setting. Use 0 to disable.");
1970 module_param(blank
, bool, 0);
1971 MODULE_PARM_DESC(blank
, "Enable hardware blanking");
1972 module_param(nocrtc
, bool, 0);
1973 MODULE_PARM_DESC(nocrtc
, "Ignore CRTC timings when setting modes");
1974 module_param(noedid
, bool, 0);
1975 MODULE_PARM_DESC(noedid
,
1976 "Ignore EDID-provided monitor limits when setting modes");
1977 module_param(vram_remap
, uint
, 0);
1978 MODULE_PARM_DESC(vram_remap
, "Set amount of video memory to be used [MiB]");
1979 module_param(vram_total
, uint
, 0);
1980 MODULE_PARM_DESC(vram_total
, "Set total amount of video memoery [MiB]");
1981 module_param(maxclk
, ushort
, 0);
1982 MODULE_PARM_DESC(maxclk
, "Maximum pixelclock [MHz], overrides EDID data");
1983 module_param(maxhf
, ushort
, 0);
1984 MODULE_PARM_DESC(maxhf
,
1985 "Maximum horizontal frequency [kHz], overrides EDID data");
1986 module_param(maxvf
, ushort
, 0);
1987 MODULE_PARM_DESC(maxvf
,
1988 "Maximum vertical frequency [Hz], overrides EDID data");
1989 module_param(mode_option
, charp
, 0);
1990 MODULE_PARM_DESC(mode_option
,
1991 "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
1992 module_param(vbemode
, ushort
, 0);
1993 MODULE_PARM_DESC(vbemode
,
1994 "VBE mode number to set, overrides the 'mode' option");
1995 module_param_string(v86d
, v86d_path
, PATH_MAX
, 0660);
1996 MODULE_PARM_DESC(v86d
, "Path to the v86d userspace helper.");
1998 MODULE_LICENSE("GPL");
1999 MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
2000 MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");