1 // SPDX-License-Identifier: GPL-2.0-only
3 * A framebuffer driver for VBE 2.0+ compliant video cards
5 * (c) 2007 Michal Januszewski <spock@gentoo.org>
6 * Loosely based upon the vesafb driver.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/skbuff.h>
16 #include <linux/timer.h>
17 #include <linux/completion.h>
18 #include <linux/connector.h>
19 #include <linux/random.h>
20 #include <linux/platform_device.h>
21 #include <linux/limits.h>
24 #include <linux/mutex.h>
25 #include <linux/slab.h>
26 #include <video/edid.h>
27 #include <video/uvesafb.h>
29 #include <video/vga.h>
33 static struct cb_id uvesafb_cn_id
= {
35 .val
= CN_VAL_V86D_UVESAFB
37 static char v86d_path
[PATH_MAX
] = "/sbin/v86d";
38 static char v86d_started
; /* has v86d been started by uvesafb? */
40 static const struct fb_fix_screeninfo uvesafb_fix
= {
42 .type
= FB_TYPE_PACKED_PIXELS
,
43 .accel
= FB_ACCEL_NONE
,
44 .visual
= FB_VISUAL_TRUECOLOR
,
47 static int mtrr
= 3; /* enable mtrr by default */
48 static bool blank
= true; /* enable blanking by default */
49 static int ypan
= 1; /* 0: scroll, 1: ypan, 2: ywrap */
50 static bool pmi_setpal
= true; /* use PMI for palette changes */
51 static bool nocrtc
; /* ignore CRTC settings */
52 static bool noedid
; /* don't try DDC transfers */
53 static int vram_remap
; /* set amt. of memory to be used */
54 static int vram_total
; /* set total amount of memory */
55 static u16 maxclk
; /* maximum pixel clock */
56 static u16 maxvf
; /* maximum vertical frequency */
57 static u16 maxhf
; /* maximum horizontal frequency */
58 static u16 vbemode
; /* force use of a specific VBE mode */
59 static char *mode_option
;
60 static u8 dac_width
= 6;
62 static struct uvesafb_ktask
*uvfb_tasks
[UVESAFB_TASKS_MAX
];
63 static DEFINE_MUTEX(uvfb_lock
);
66 * A handler for replies from userspace.
68 * Make sure each message passes consistency checks and if it does,
69 * find the kernel part of the task struct, copy the registers and
70 * the buffer contents and then complete the task.
72 static void uvesafb_cn_callback(struct cn_msg
*msg
, struct netlink_skb_parms
*nsp
)
74 struct uvesafb_task
*utask
;
75 struct uvesafb_ktask
*task
;
77 if (!capable(CAP_SYS_ADMIN
))
80 if (msg
->seq
>= UVESAFB_TASKS_MAX
)
83 mutex_lock(&uvfb_lock
);
84 task
= uvfb_tasks
[msg
->seq
];
86 if (!task
|| msg
->ack
!= task
->ack
) {
87 mutex_unlock(&uvfb_lock
);
91 utask
= (struct uvesafb_task
*)msg
->data
;
93 /* Sanity checks for the buffer length. */
94 if (task
->t
.buf_len
< utask
->buf_len
||
95 utask
->buf_len
> msg
->len
- sizeof(*utask
)) {
96 mutex_unlock(&uvfb_lock
);
100 uvfb_tasks
[msg
->seq
] = NULL
;
101 mutex_unlock(&uvfb_lock
);
103 memcpy(&task
->t
, utask
, sizeof(*utask
));
105 if (task
->t
.buf_len
&& task
->buf
)
106 memcpy(task
->buf
, utask
+ 1, task
->t
.buf_len
);
108 complete(task
->done
);
112 static int uvesafb_helper_start(void)
125 return call_usermodehelper(v86d_path
, argv
, envp
, UMH_WAIT_PROC
);
129 * Execute a uvesafb task.
131 * Returns 0 if the task is executed successfully.
133 * A message sent to the userspace consists of the uvesafb_task
134 * struct and (optionally) a buffer. The uvesafb_task struct is
135 * a simplified version of uvesafb_ktask (its kernel counterpart)
136 * containing only the register values, flags and the length of
139 * Each message is assigned a sequence number (increased linearly)
140 * and a random ack number. The sequence number is used as a key
141 * for the uvfb_tasks array which holds pointers to uvesafb_ktask
142 * structs for all requests.
144 static int uvesafb_exec(struct uvesafb_ktask
*task
)
149 int len
= sizeof(task
->t
) + task
->t
.buf_len
;
152 * Check whether the message isn't longer than the maximum
153 * allowed by connector.
155 if (sizeof(*m
) + len
> CONNECTOR_MAX_MSG_SIZE
) {
156 pr_warn("message too long (%d), can't execute task\n",
157 (int)(sizeof(*m
) + len
));
161 m
= kzalloc(sizeof(*m
) + len
, GFP_KERNEL
);
165 init_completion(task
->done
);
167 memcpy(&m
->id
, &uvesafb_cn_id
, sizeof(m
->id
));
170 m
->ack
= get_random_u32();
172 /* uvesafb_task structure */
173 memcpy(m
+ 1, &task
->t
, sizeof(task
->t
));
176 memcpy((u8
*)(m
+ 1) + sizeof(task
->t
), task
->buf
, task
->t
.buf_len
);
179 * Save the message ack number so that we can find the kernel
180 * part of this task when a reply is received from userspace.
184 mutex_lock(&uvfb_lock
);
186 /* If all slots are taken -- bail out. */
187 if (uvfb_tasks
[seq
]) {
188 mutex_unlock(&uvfb_lock
);
193 /* Save a pointer to the kernel part of the task struct. */
194 uvfb_tasks
[seq
] = task
;
195 mutex_unlock(&uvfb_lock
);
197 err
= cn_netlink_send(m
, 0, 0, GFP_KERNEL
);
200 * Try to start the userspace helper if sending
201 * the request failed the first time.
203 err
= uvesafb_helper_start();
205 pr_err("failed to execute %s\n", v86d_path
);
206 pr_err("make sure that the v86d helper is installed and executable\n");
209 err
= cn_netlink_send(m
, 0, 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
)
244 * Prepare a uvesafb_ktask struct to be used again.
246 static void uvesafb_reset(struct uvesafb_ktask
*task
)
248 struct completion
*cpl
= task
->done
;
250 memset(task
, 0, sizeof(*task
));
255 * Allocate and prepare a uvesafb_ktask struct.
257 static struct uvesafb_ktask
*uvesafb_prep(void)
259 struct uvesafb_ktask
*task
;
261 task
= kzalloc(sizeof(*task
), GFP_KERNEL
);
263 task
->done
= kzalloc(sizeof(*task
->done
), GFP_KERNEL
);
272 static void uvesafb_setup_var(struct fb_var_screeninfo
*var
,
273 struct fb_info
*info
, struct vbe_mode_ib
*mode
)
275 struct uvesafb_par
*par
= info
->par
;
277 var
->vmode
= FB_VMODE_NONINTERLACED
;
278 var
->sync
= FB_SYNC_VERT_HIGH_ACT
;
280 var
->xres
= mode
->x_res
;
281 var
->yres
= mode
->y_res
;
282 var
->xres_virtual
= mode
->x_res
;
283 var
->yres_virtual
= (par
->ypan
) ?
284 info
->fix
.smem_len
/ mode
->bytes_per_scan_line
:
288 var
->bits_per_pixel
= mode
->bits_per_pixel
;
290 if (var
->bits_per_pixel
== 15)
291 var
->bits_per_pixel
= 16;
293 if (var
->bits_per_pixel
> 8) {
294 var
->red
.offset
= mode
->red_off
;
295 var
->red
.length
= mode
->red_len
;
296 var
->green
.offset
= mode
->green_off
;
297 var
->green
.length
= mode
->green_len
;
298 var
->blue
.offset
= mode
->blue_off
;
299 var
->blue
.length
= mode
->blue_len
;
300 var
->transp
.offset
= mode
->rsvd_off
;
301 var
->transp
.length
= mode
->rsvd_len
;
304 var
->green
.offset
= 0;
305 var
->blue
.offset
= 0;
306 var
->transp
.offset
= 0;
309 var
->green
.length
= 8;
310 var
->blue
.length
= 8;
311 var
->transp
.length
= 0;
315 static int uvesafb_vbe_find_mode(struct uvesafb_par
*par
,
316 int xres
, int yres
, int depth
, unsigned char flags
)
318 int i
, match
= -1, h
= 0, d
= 0x7fffffff;
320 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
321 h
= abs(par
->vbe_modes
[i
].x_res
- xres
) +
322 abs(par
->vbe_modes
[i
].y_res
- yres
) +
323 abs(depth
- par
->vbe_modes
[i
].depth
);
326 * We have an exact match in terms of resolution
332 if (h
< d
|| (h
== d
&& par
->vbe_modes
[i
].depth
> depth
)) {
339 if (flags
& UVESAFB_EXACT_DEPTH
&&
340 par
->vbe_modes
[match
].depth
!= depth
)
343 if (flags
& UVESAFB_EXACT_RES
&& d
> 24)
352 static u8
*uvesafb_vbe_state_save(struct uvesafb_par
*par
)
354 struct uvesafb_ktask
*task
;
358 if (!par
->vbe_state_size
)
361 state
= kmalloc(par
->vbe_state_size
, GFP_KERNEL
);
363 return ERR_PTR(-ENOMEM
);
365 task
= uvesafb_prep();
371 task
->t
.regs
.eax
= 0x4f04;
372 task
->t
.regs
.ecx
= 0x000f;
373 task
->t
.regs
.edx
= 0x0001;
374 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESBX
;
375 task
->t
.buf_len
= par
->vbe_state_size
;
377 err
= uvesafb_exec(task
);
379 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
380 pr_warn("VBE get state call failed (eax=0x%x, err=%d)\n",
381 task
->t
.regs
.eax
, err
);
390 static void uvesafb_vbe_state_restore(struct uvesafb_par
*par
, u8
*state_buf
)
392 struct uvesafb_ktask
*task
;
398 task
= uvesafb_prep();
402 task
->t
.regs
.eax
= 0x4f04;
403 task
->t
.regs
.ecx
= 0x000f;
404 task
->t
.regs
.edx
= 0x0002;
405 task
->t
.buf_len
= par
->vbe_state_size
;
406 task
->t
.flags
= TF_BUF_ESBX
;
407 task
->buf
= state_buf
;
409 err
= uvesafb_exec(task
);
410 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f)
411 pr_warn("VBE state restore call failed (eax=0x%x, err=%d)\n",
412 task
->t
.regs
.eax
, err
);
417 static int uvesafb_vbe_getinfo(struct uvesafb_ktask
*task
,
418 struct uvesafb_par
*par
)
422 task
->t
.regs
.eax
= 0x4f00;
423 task
->t
.flags
= TF_VBEIB
;
424 task
->t
.buf_len
= sizeof(struct vbe_ib
);
425 task
->buf
= &par
->vbe_ib
;
426 memcpy(par
->vbe_ib
.vbe_signature
, "VBE2", 4);
428 err
= uvesafb_exec(task
);
429 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
430 pr_err("Getting VBE info block failed (eax=0x%x, err=%d)\n",
431 (u32
)task
->t
.regs
.eax
, err
);
435 if (par
->vbe_ib
.vbe_version
< 0x0200) {
436 pr_err("Sorry, pre-VBE 2.0 cards are not supported\n");
440 if (!par
->vbe_ib
.mode_list_ptr
) {
441 pr_err("Missing mode list!\n");
448 * Convert string pointers and the mode list pointer into
449 * usable addresses. Print informational messages about the
450 * video adapter and its vendor.
452 if (par
->vbe_ib
.oem_vendor_name_ptr
)
454 ((char *)task
->buf
) + par
->vbe_ib
.oem_vendor_name_ptr
);
456 if (par
->vbe_ib
.oem_product_name_ptr
)
458 ((char *)task
->buf
) + par
->vbe_ib
.oem_product_name_ptr
);
460 if (par
->vbe_ib
.oem_product_rev_ptr
)
462 ((char *)task
->buf
) + par
->vbe_ib
.oem_product_rev_ptr
);
464 if (par
->vbe_ib
.oem_string_ptr
)
466 ((char *)task
->buf
) + par
->vbe_ib
.oem_string_ptr
);
468 pr_cont("VBE v%d.%d\n",
469 (par
->vbe_ib
.vbe_version
& 0xff00) >> 8,
470 par
->vbe_ib
.vbe_version
& 0xff);
475 static int uvesafb_vbe_getmodes(struct uvesafb_ktask
*task
,
476 struct uvesafb_par
*par
)
481 par
->vbe_modes_cnt
= 0;
483 /* Count available modes. */
484 mode
= (u16
*) (((u8
*)&par
->vbe_ib
) + par
->vbe_ib
.mode_list_ptr
);
485 while (*mode
!= 0xffff) {
486 par
->vbe_modes_cnt
++;
490 par
->vbe_modes
= kcalloc(par
->vbe_modes_cnt
,
491 sizeof(struct vbe_mode_ib
),
496 /* Get info about all available modes. */
497 mode
= (u16
*) (((u8
*)&par
->vbe_ib
) + par
->vbe_ib
.mode_list_ptr
);
498 while (*mode
!= 0xffff) {
499 struct vbe_mode_ib
*mib
;
502 task
->t
.regs
.eax
= 0x4f01;
503 task
->t
.regs
.ecx
= (u32
) *mode
;
504 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESDI
;
505 task
->t
.buf_len
= sizeof(struct vbe_mode_ib
);
506 task
->buf
= par
->vbe_modes
+ off
;
508 err
= uvesafb_exec(task
);
509 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
510 pr_warn("Getting mode info block for mode 0x%x failed (eax=0x%x, err=%d)\n",
511 *mode
, (u32
)task
->t
.regs
.eax
, err
);
513 par
->vbe_modes_cnt
--;
518 mib
->mode_id
= *mode
;
521 * We only want modes that are supported with the current
522 * hardware configuration, color, graphics and that have
523 * support for the LFB.
525 if ((mib
->mode_attr
& VBE_MODE_MASK
) == VBE_MODE_MASK
&&
526 mib
->bits_per_pixel
>= 8)
529 par
->vbe_modes_cnt
--;
532 mib
->depth
= mib
->red_len
+ mib
->green_len
+ mib
->blue_len
;
535 * Handle 8bpp modes and modes with broken color component
538 if (mib
->depth
== 0 || (mib
->depth
== 24 &&
539 mib
->bits_per_pixel
== 32))
540 mib
->depth
= mib
->bits_per_pixel
;
543 if (par
->vbe_modes_cnt
> 0)
550 * The Protected Mode Interface is 32-bit x86 code, so we only run it on
551 * x86 and not x86_64.
554 static int uvesafb_vbe_getpmi(struct uvesafb_ktask
*task
,
555 struct uvesafb_par
*par
)
560 task
->t
.regs
.eax
= 0x4f0a;
561 task
->t
.regs
.ebx
= 0x0;
562 err
= uvesafb_exec(task
);
566 if ((task
->t
.regs
.eax
& 0xffff) != 0x4f || task
->t
.regs
.es
< 0xc000) {
567 par
->pmi_setpal
= par
->ypan
= 0;
569 par
->pmi_base
= (u16
*)phys_to_virt(((u32
)task
->t
.regs
.es
<< 4)
571 par
->pmi_start
= (u8
*)par
->pmi_base
+ par
->pmi_base
[1];
572 par
->pmi_pal
= (u8
*)par
->pmi_base
+ par
->pmi_base
[2];
573 pr_info("protected mode interface info at %04x:%04x\n",
574 (u16
)task
->t
.regs
.es
, (u16
)task
->t
.regs
.edi
);
575 pr_info("pmi: set display start = %p, set palette = %p\n",
576 par
->pmi_start
, par
->pmi_pal
);
578 if (par
->pmi_base
[3]) {
579 pr_info("pmi: ports =");
580 for (i
= par
->pmi_base
[3]/2;
581 par
->pmi_base
[i
] != 0xffff; i
++)
582 pr_cont(" %x", par
->pmi_base
[i
]);
585 if (par
->pmi_base
[i
] != 0xffff) {
586 pr_info("can't handle memory requests, pmi disabled\n");
587 par
->ypan
= par
->pmi_setpal
= 0;
593 #endif /* CONFIG_X86_32 */
596 * Check whether a video mode is supported by the Video BIOS and is
597 * compatible with the monitor limits.
599 static int uvesafb_is_valid_mode(struct fb_videomode
*mode
,
600 struct fb_info
*info
)
602 if (info
->monspecs
.gtf
) {
603 fb_videomode_to_var(&info
->var
, mode
);
604 if (fb_validate_mode(&info
->var
, info
))
608 if (uvesafb_vbe_find_mode(info
->par
, mode
->xres
, mode
->yres
, 8,
609 UVESAFB_EXACT_RES
) == -1)
615 static int uvesafb_vbe_getedid(struct uvesafb_ktask
*task
, struct fb_info
*info
)
617 struct uvesafb_par
*par
= info
->par
;
620 if (noedid
|| par
->vbe_ib
.vbe_version
< 0x0300)
623 task
->t
.regs
.eax
= 0x4f15;
624 task
->t
.regs
.ebx
= 0;
625 task
->t
.regs
.ecx
= 0;
629 err
= uvesafb_exec(task
);
631 if ((task
->t
.regs
.eax
& 0xffff) != 0x004f || err
)
634 if ((task
->t
.regs
.ebx
& 0x3) == 3) {
635 pr_info("VBIOS/hardware supports both DDC1 and DDC2 transfers\n");
636 } else if ((task
->t
.regs
.ebx
& 0x3) == 2) {
637 pr_info("VBIOS/hardware supports DDC2 transfers\n");
638 } else if ((task
->t
.regs
.ebx
& 0x3) == 1) {
639 pr_info("VBIOS/hardware supports DDC1 transfers\n");
641 pr_info("VBIOS/hardware doesn't support DDC transfers\n");
645 task
->t
.regs
.eax
= 0x4f15;
646 task
->t
.regs
.ebx
= 1;
647 task
->t
.regs
.ecx
= task
->t
.regs
.edx
= 0;
648 task
->t
.flags
= TF_BUF_RET
| TF_BUF_ESDI
;
649 task
->t
.buf_len
= EDID_LENGTH
;
650 task
->buf
= kzalloc(EDID_LENGTH
, GFP_KERNEL
);
654 err
= uvesafb_exec(task
);
656 if ((task
->t
.regs
.eax
& 0xffff) == 0x004f && !err
) {
657 fb_edid_to_monspecs(task
->buf
, &info
->monspecs
);
659 if (info
->monspecs
.vfmax
&& info
->monspecs
.hfmax
) {
661 * If the maximum pixel clock wasn't specified in
662 * the EDID block, set it to 300 MHz.
664 if (info
->monspecs
.dclkmax
== 0)
665 info
->monspecs
.dclkmax
= 300 * 1000000;
666 info
->monspecs
.gtf
= 1;
676 static void uvesafb_vbe_getmonspecs(struct uvesafb_ktask
*task
,
677 struct fb_info
*info
)
679 struct uvesafb_par
*par
= info
->par
;
682 memset(&info
->monspecs
, 0, sizeof(info
->monspecs
));
685 * If we don't get all necessary data from the EDID block,
686 * mark it as incompatible with the GTF and set nocrtc so
687 * that we always use the default BIOS refresh rate.
689 if (uvesafb_vbe_getedid(task
, info
)) {
690 info
->monspecs
.gtf
= 0;
694 /* Kernel command line overrides. */
696 info
->monspecs
.dclkmax
= maxclk
* 1000000;
698 info
->monspecs
.vfmax
= maxvf
;
700 info
->monspecs
.hfmax
= maxhf
* 1000;
703 * In case DDC transfers are not supported, the user can provide
704 * monitor limits manually. Lower limits are set to "safe" values.
706 if (info
->monspecs
.gtf
== 0 && maxclk
&& maxvf
&& maxhf
) {
707 info
->monspecs
.dclkmin
= 0;
708 info
->monspecs
.vfmin
= 60;
709 info
->monspecs
.hfmin
= 29000;
710 info
->monspecs
.gtf
= 1;
714 if (info
->monspecs
.gtf
)
715 pr_info("monitor limits: vf = %d Hz, hf = %d kHz, clk = %d MHz\n",
716 info
->monspecs
.vfmax
,
717 (int)(info
->monspecs
.hfmax
/ 1000),
718 (int)(info
->monspecs
.dclkmax
/ 1000000));
720 pr_info("no monitor limits have been set, default refresh rate will be used\n");
722 /* Add VBE modes to the modelist. */
723 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
724 struct fb_var_screeninfo var
;
725 struct vbe_mode_ib
*mode
;
726 struct fb_videomode vmode
;
728 mode
= &par
->vbe_modes
[i
];
729 memset(&var
, 0, sizeof(var
));
731 var
.xres
= mode
->x_res
;
732 var
.yres
= mode
->y_res
;
734 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60, &var
, info
);
735 fb_var_to_videomode(&vmode
, &var
);
736 fb_add_videomode(&vmode
, &info
->modelist
);
739 /* Add valid VESA modes to our modelist. */
740 for (i
= 0; i
< VESA_MODEDB_SIZE
; i
++) {
741 if (uvesafb_is_valid_mode((struct fb_videomode
*)
742 &vesa_modes
[i
], info
))
743 fb_add_videomode(&vesa_modes
[i
], &info
->modelist
);
746 for (i
= 0; i
< info
->monspecs
.modedb_len
; i
++) {
747 if (uvesafb_is_valid_mode(&info
->monspecs
.modedb
[i
], info
))
748 fb_add_videomode(&info
->monspecs
.modedb
[i
],
755 static void uvesafb_vbe_getstatesize(struct uvesafb_ktask
*task
,
756 struct uvesafb_par
*par
)
763 * Get the VBE state buffer size. We want all available
764 * hardware state data (CL = 0x0f).
766 task
->t
.regs
.eax
= 0x4f04;
767 task
->t
.regs
.ecx
= 0x000f;
768 task
->t
.regs
.edx
= 0x0000;
771 err
= uvesafb_exec(task
);
773 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
774 pr_warn("VBE state buffer size cannot be determined (eax=0x%x, err=%d)\n",
775 task
->t
.regs
.eax
, err
);
776 par
->vbe_state_size
= 0;
780 par
->vbe_state_size
= 64 * (task
->t
.regs
.ebx
& 0xffff);
783 static int uvesafb_vbe_init(struct fb_info
*info
)
785 struct uvesafb_ktask
*task
= NULL
;
786 struct uvesafb_par
*par
= info
->par
;
789 task
= uvesafb_prep();
793 err
= uvesafb_vbe_getinfo(task
, par
);
797 err
= uvesafb_vbe_getmodes(task
, par
);
801 par
->nocrtc
= nocrtc
;
803 par
->pmi_setpal
= pmi_setpal
;
806 if (par
->pmi_setpal
|| par
->ypan
) {
807 if (__supported_pte_mask
& _PAGE_NX
) {
808 par
->pmi_setpal
= par
->ypan
= 0;
809 pr_warn("NX protection is active, better not use the PMI\n");
811 uvesafb_vbe_getpmi(task
, par
);
815 /* The protected mode interface is not available on non-x86. */
816 par
->pmi_setpal
= par
->ypan
= 0;
819 INIT_LIST_HEAD(&info
->modelist
);
820 uvesafb_vbe_getmonspecs(task
, info
);
821 uvesafb_vbe_getstatesize(task
, par
);
823 out
: uvesafb_free(task
);
827 static int uvesafb_vbe_init_mode(struct fb_info
*info
)
829 struct list_head
*pos
;
830 struct fb_modelist
*modelist
;
831 struct fb_videomode
*mode
;
832 struct uvesafb_par
*par
= info
->par
;
835 /* Has the user requested a specific VESA mode? */
837 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
838 if (par
->vbe_modes
[i
].mode_id
== vbemode
) {
840 uvesafb_setup_var(&info
->var
, info
,
841 &par
->vbe_modes
[modeid
]);
842 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
845 * With pixclock set to 0, the default BIOS
846 * timings will be used in set_par().
848 info
->var
.pixclock
= 0;
852 pr_info("requested VBE mode 0x%x is unavailable\n", vbemode
);
856 /* Count the modes in the modelist */
858 list_for_each(pos
, &info
->modelist
)
862 * Convert the modelist into a modedb so that we can use it with
865 mode
= kcalloc(i
, sizeof(*mode
), GFP_KERNEL
);
868 list_for_each(pos
, &info
->modelist
) {
869 modelist
= list_entry(pos
, struct fb_modelist
, list
);
870 mode
[i
] = modelist
->mode
;
875 mode_option
= UVESAFB_DEFAULT_MODE
;
877 i
= fb_find_mode(&info
->var
, info
, mode_option
, mode
, i
,
883 /* fb_find_mode() failed */
885 info
->var
.xres
= 640;
886 info
->var
.yres
= 480;
887 mode
= (struct fb_videomode
*)
888 fb_find_best_mode(&info
->var
, &info
->modelist
);
891 fb_videomode_to_var(&info
->var
, mode
);
893 modeid
= par
->vbe_modes
[0].mode_id
;
894 uvesafb_setup_var(&info
->var
, info
,
895 &par
->vbe_modes
[modeid
]);
896 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
903 /* Look for a matching VBE mode. */
904 modeid
= uvesafb_vbe_find_mode(par
, info
->var
.xres
, info
->var
.yres
,
905 info
->var
.bits_per_pixel
, UVESAFB_EXACT_RES
);
910 uvesafb_setup_var(&info
->var
, info
, &par
->vbe_modes
[modeid
]);
914 * If we are not VBE3.0+ compliant, we're done -- the BIOS will
915 * ignore our timings anyway.
917 if (par
->vbe_ib
.vbe_version
< 0x0300 || par
->nocrtc
)
918 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60,
924 static int uvesafb_setpalette(struct uvesafb_pal_entry
*entries
, int count
,
925 int start
, struct fb_info
*info
)
927 struct uvesafb_ktask
*task
;
929 struct uvesafb_par
*par
= info
->par
;
930 int i
= par
->mode_idx
;
935 * We support palette modifications for 8 bpp modes only, so
936 * there can never be more than 256 entries.
938 if (start
+ count
> 256)
942 /* Use VGA registers if mode is VGA-compatible. */
943 if (i
>= 0 && i
< par
->vbe_modes_cnt
&&
944 par
->vbe_modes
[i
].mode_attr
& VBE_MODE_VGACOMPAT
) {
945 for (i
= 0; i
< count
; i
++) {
946 outb_p(start
+ i
, dac_reg
);
947 outb_p(entries
[i
].red
, dac_val
);
948 outb_p(entries
[i
].green
, dac_val
);
949 outb_p(entries
[i
].blue
, dac_val
);
953 else if (par
->pmi_setpal
) {
954 __asm__
__volatile__(
956 : /* no return value */
957 : "a" (0x4f09), /* EAX */
959 "c" (count
), /* ECX */
960 "d" (start
), /* EDX */
961 "D" (entries
), /* EDI */
962 "S" (&par
->pmi_pal
)); /* ESI */
964 #endif /* CONFIG_X86_32 */
966 #endif /* CONFIG_X86 */
968 task
= uvesafb_prep();
972 task
->t
.regs
.eax
= 0x4f09;
973 task
->t
.regs
.ebx
= 0x0;
974 task
->t
.regs
.ecx
= count
;
975 task
->t
.regs
.edx
= start
;
976 task
->t
.flags
= TF_BUF_ESDI
;
977 task
->t
.buf_len
= sizeof(struct uvesafb_pal_entry
) * count
;
980 err
= uvesafb_exec(task
);
981 if ((task
->t
.regs
.eax
& 0xffff) != 0x004f)
989 static int uvesafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
990 unsigned blue
, unsigned transp
,
991 struct fb_info
*info
)
993 struct uvesafb_pal_entry entry
;
994 int shift
= 16 - dac_width
;
997 if (regno
>= info
->cmap
.len
)
1000 if (info
->var
.bits_per_pixel
== 8) {
1001 entry
.red
= red
>> shift
;
1002 entry
.green
= green
>> shift
;
1003 entry
.blue
= blue
>> shift
;
1006 err
= uvesafb_setpalette(&entry
, 1, regno
, info
);
1007 } else if (regno
< 16) {
1008 switch (info
->var
.bits_per_pixel
) {
1010 if (info
->var
.red
.offset
== 10) {
1012 ((u32
*) (info
->pseudo_palette
))[regno
] =
1013 ((red
& 0xf800) >> 1) |
1014 ((green
& 0xf800) >> 6) |
1015 ((blue
& 0xf800) >> 11);
1018 ((u32
*) (info
->pseudo_palette
))[regno
] =
1020 ((green
& 0xfc00) >> 5) |
1021 ((blue
& 0xf800) >> 11);
1030 ((u32
*)(info
->pseudo_palette
))[regno
] =
1031 (red
<< info
->var
.red
.offset
) |
1032 (green
<< info
->var
.green
.offset
) |
1033 (blue
<< info
->var
.blue
.offset
);
1040 static int uvesafb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1042 struct uvesafb_pal_entry
*entries
;
1043 int shift
= 16 - dac_width
;
1046 if (info
->var
.bits_per_pixel
== 8) {
1047 if (cmap
->start
+ cmap
->len
> info
->cmap
.start
+
1048 info
->cmap
.len
|| cmap
->start
< info
->cmap
.start
)
1051 entries
= kmalloc_array(cmap
->len
, sizeof(*entries
),
1056 for (i
= 0; i
< cmap
->len
; i
++) {
1057 entries
[i
].red
= cmap
->red
[i
] >> shift
;
1058 entries
[i
].green
= cmap
->green
[i
] >> shift
;
1059 entries
[i
].blue
= cmap
->blue
[i
] >> shift
;
1062 err
= uvesafb_setpalette(entries
, cmap
->len
, cmap
->start
, info
);
1066 * For modes with bpp > 8, we only set the pseudo palette in
1067 * the fb_info struct. We rely on uvesafb_setcolreg to do all
1070 for (i
= 0; i
< cmap
->len
; i
++) {
1071 err
|= uvesafb_setcolreg(cmap
->start
+ i
, cmap
->red
[i
],
1072 cmap
->green
[i
], cmap
->blue
[i
],
1079 static int uvesafb_pan_display(struct fb_var_screeninfo
*var
,
1080 struct fb_info
*info
)
1082 #ifdef CONFIG_X86_32
1084 struct uvesafb_par
*par
= info
->par
;
1086 offset
= (var
->yoffset
* info
->fix
.line_length
+ var
->xoffset
) / 4;
1089 * It turns out it's not the best idea to do panning via vm86,
1090 * so we only allow it if we have a PMI.
1092 if (par
->pmi_start
) {
1093 __asm__
__volatile__(
1095 : /* no return value */
1096 : "a" (0x4f07), /* EAX */
1098 "c" (offset
), /* ECX */
1099 "d" (offset
>> 16), /* EDX */
1100 "D" (&par
->pmi_start
)); /* EDI */
1106 static int uvesafb_blank(int blank
, struct fb_info
*info
)
1108 struct uvesafb_ktask
*task
;
1111 struct uvesafb_par
*par
= info
->par
;
1113 if (par
->vbe_ib
.capabilities
& VBE_CAP_VGACOMPAT
) {
1115 u8 seq
= 0, crtc17
= 0;
1117 if (blank
== FB_BLANK_POWERDOWN
) {
1124 err
= (blank
== FB_BLANK_UNBLANK
) ? 0 : -EINVAL
;
1127 vga_wseq(NULL
, 0x00, 0x01);
1128 seq
|= vga_rseq(NULL
, 0x01) & ~0x20;
1129 vga_wseq(NULL
, 0x00, seq
);
1131 crtc17
|= vga_rcrt(NULL
, 0x17) & ~0x80;
1133 vga_wcrt(NULL
, 0x17, crtc17
);
1134 vga_wseq(NULL
, 0x00, 0x03);
1136 #endif /* CONFIG_X86 */
1138 task
= uvesafb_prep();
1142 task
->t
.regs
.eax
= 0x4f10;
1144 case FB_BLANK_UNBLANK
:
1145 task
->t
.regs
.ebx
= 0x0001;
1147 case FB_BLANK_NORMAL
:
1148 task
->t
.regs
.ebx
= 0x0101; /* standby */
1150 case FB_BLANK_POWERDOWN
:
1151 task
->t
.regs
.ebx
= 0x0401; /* powerdown */
1157 err
= uvesafb_exec(task
);
1158 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f)
1160 out
: uvesafb_free(task
);
1165 static int uvesafb_open(struct fb_info
*info
, int user
)
1167 struct uvesafb_par
*par
= info
->par
;
1168 int cnt
= atomic_read(&par
->ref_count
);
1171 if (!cnt
&& par
->vbe_state_size
) {
1172 buf
= uvesafb_vbe_state_save(par
);
1174 pr_warn("save hardware state failed, error code is %ld!\n",
1177 par
->vbe_state_orig
= buf
;
1181 atomic_inc(&par
->ref_count
);
1185 static int uvesafb_release(struct fb_info
*info
, int user
)
1187 struct uvesafb_ktask
*task
= NULL
;
1188 struct uvesafb_par
*par
= info
->par
;
1189 int cnt
= atomic_read(&par
->ref_count
);
1197 task
= uvesafb_prep();
1201 /* First, try to set the standard 80x25 text mode. */
1202 task
->t
.regs
.eax
= 0x0003;
1206 * Now try to restore whatever hardware state we might have
1207 * saved when the fb device was first opened.
1209 uvesafb_vbe_state_restore(par
, par
->vbe_state_orig
);
1211 atomic_dec(&par
->ref_count
);
1216 static int uvesafb_set_par(struct fb_info
*info
)
1218 struct uvesafb_par
*par
= info
->par
;
1219 struct uvesafb_ktask
*task
= NULL
;
1220 struct vbe_crtc_ib
*crtc
= NULL
;
1221 struct vbe_mode_ib
*mode
= NULL
;
1222 int i
, err
= 0, depth
= info
->var
.bits_per_pixel
;
1224 if (depth
> 8 && depth
!= 32)
1225 depth
= info
->var
.red
.length
+ info
->var
.green
.length
+
1226 info
->var
.blue
.length
;
1228 i
= uvesafb_vbe_find_mode(par
, info
->var
.xres
, info
->var
.yres
, depth
,
1229 UVESAFB_EXACT_RES
| UVESAFB_EXACT_DEPTH
);
1231 mode
= &par
->vbe_modes
[i
];
1235 task
= uvesafb_prep();
1239 task
->t
.regs
.eax
= 0x4f02;
1240 task
->t
.regs
.ebx
= mode
->mode_id
| 0x4000; /* use LFB */
1242 if (par
->vbe_ib
.vbe_version
>= 0x0300 && !par
->nocrtc
&&
1243 info
->var
.pixclock
!= 0) {
1244 task
->t
.regs
.ebx
|= 0x0800; /* use CRTC data */
1245 task
->t
.flags
= TF_BUF_ESDI
;
1246 crtc
= kzalloc(sizeof(struct vbe_crtc_ib
), GFP_KERNEL
);
1251 crtc
->horiz_start
= info
->var
.xres
+ info
->var
.right_margin
;
1252 crtc
->horiz_end
= crtc
->horiz_start
+ info
->var
.hsync_len
;
1253 crtc
->horiz_total
= crtc
->horiz_end
+ info
->var
.left_margin
;
1255 crtc
->vert_start
= info
->var
.yres
+ info
->var
.lower_margin
;
1256 crtc
->vert_end
= crtc
->vert_start
+ info
->var
.vsync_len
;
1257 crtc
->vert_total
= crtc
->vert_end
+ info
->var
.upper_margin
;
1259 crtc
->pixel_clock
= PICOS2KHZ(info
->var
.pixclock
) * 1000;
1260 crtc
->refresh_rate
= (u16
)(100 * (crtc
->pixel_clock
/
1261 (crtc
->vert_total
* crtc
->horiz_total
)));
1263 if (info
->var
.vmode
& FB_VMODE_DOUBLE
)
1265 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
1267 if (!(info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
))
1269 if (!(info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
))
1271 memcpy(&par
->crtc
, crtc
, sizeof(*crtc
));
1273 memset(&par
->crtc
, 0, sizeof(*crtc
));
1276 task
->t
.buf_len
= sizeof(struct vbe_crtc_ib
);
1277 task
->buf
= &par
->crtc
;
1279 err
= uvesafb_exec(task
);
1280 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f) {
1282 * The mode switch might have failed because we tried to
1283 * use our own timings. Try again with the default timings.
1286 pr_warn("mode switch failed (eax=0x%x, err=%d) - trying again with default timings\n",
1287 task
->t
.regs
.eax
, err
);
1288 uvesafb_reset(task
);
1291 info
->var
.pixclock
= 0;
1294 pr_err("mode switch failed (eax=0x%x, err=%d)\n",
1295 task
->t
.regs
.eax
, err
);
1302 /* For 8bpp modes, always try to set the DAC to 8 bits. */
1303 if (par
->vbe_ib
.capabilities
& VBE_CAP_CAN_SWITCH_DAC
&&
1304 mode
->bits_per_pixel
<= 8) {
1305 uvesafb_reset(task
);
1306 task
->t
.regs
.eax
= 0x4f08;
1307 task
->t
.regs
.ebx
= 0x0800;
1309 err
= uvesafb_exec(task
);
1310 if (err
|| (task
->t
.regs
.eax
& 0xffff) != 0x004f ||
1311 ((task
->t
.regs
.ebx
& 0xff00) >> 8) != 8) {
1318 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8) ?
1319 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
1320 info
->fix
.line_length
= mode
->bytes_per_scan_line
;
1329 static void uvesafb_check_limits(struct fb_var_screeninfo
*var
,
1330 struct fb_info
*info
)
1332 const struct fb_videomode
*mode
;
1333 struct uvesafb_par
*par
= info
->par
;
1336 * If pixclock is set to 0, then we're using default BIOS timings
1337 * and thus don't have to perform any checks here.
1342 if (par
->vbe_ib
.vbe_version
< 0x0300) {
1343 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
, 60, var
, info
);
1347 if (!fb_validate_mode(var
, info
))
1350 mode
= fb_find_best_mode(var
, &info
->modelist
);
1352 if (mode
->xres
== var
->xres
&& mode
->yres
== var
->yres
&&
1353 !(mode
->vmode
& (FB_VMODE_INTERLACED
| FB_VMODE_DOUBLE
))) {
1354 fb_videomode_to_var(var
, mode
);
1359 if (info
->monspecs
.gtf
&& !fb_get_mode(FB_MAXTIMINGS
, 0, var
, info
))
1361 /* Use default refresh rate */
1365 static int uvesafb_check_var(struct fb_var_screeninfo
*var
,
1366 struct fb_info
*info
)
1368 struct uvesafb_par
*par
= info
->par
;
1369 struct vbe_mode_ib
*mode
= NULL
;
1371 int depth
= var
->red
.length
+ var
->green
.length
+ var
->blue
.length
;
1374 * Various apps will use bits_per_pixel to set the color depth,
1375 * which is theoretically incorrect, but which we'll try to handle
1378 if (depth
== 0 || abs(depth
- var
->bits_per_pixel
) >= 8)
1379 depth
= var
->bits_per_pixel
;
1381 match
= uvesafb_vbe_find_mode(par
, var
->xres
, var
->yres
, depth
,
1386 mode
= &par
->vbe_modes
[match
];
1387 uvesafb_setup_var(var
, info
, mode
);
1390 * Check whether we have remapped enough memory for this mode.
1391 * We might be called at an early stage, when we haven't remapped
1392 * any memory yet, in which case we simply skip the check.
1394 if (var
->yres
* mode
->bytes_per_scan_line
> info
->fix
.smem_len
1395 && info
->fix
.smem_len
)
1398 if ((var
->vmode
& FB_VMODE_DOUBLE
) &&
1399 !(par
->vbe_modes
[match
].mode_attr
& 0x100))
1400 var
->vmode
&= ~FB_VMODE_DOUBLE
;
1402 if ((var
->vmode
& FB_VMODE_INTERLACED
) &&
1403 !(par
->vbe_modes
[match
].mode_attr
& 0x200))
1404 var
->vmode
&= ~FB_VMODE_INTERLACED
;
1406 uvesafb_check_limits(var
, info
);
1408 var
->xres_virtual
= var
->xres
;
1409 var
->yres_virtual
= (par
->ypan
) ?
1410 info
->fix
.smem_len
/ mode
->bytes_per_scan_line
:
1415 static struct fb_ops uvesafb_ops
= {
1416 .owner
= THIS_MODULE
,
1417 .fb_open
= uvesafb_open
,
1418 .fb_release
= uvesafb_release
,
1419 FB_DEFAULT_IOMEM_OPS
,
1420 .fb_setcolreg
= uvesafb_setcolreg
,
1421 .fb_setcmap
= uvesafb_setcmap
,
1422 .fb_pan_display
= uvesafb_pan_display
,
1423 .fb_blank
= uvesafb_blank
,
1424 .fb_check_var
= uvesafb_check_var
,
1425 .fb_set_par
= uvesafb_set_par
,
1428 static void uvesafb_init_info(struct fb_info
*info
, struct vbe_mode_ib
*mode
)
1430 unsigned int size_vmode
;
1431 unsigned int size_remap
;
1432 unsigned int size_total
;
1433 struct uvesafb_par
*par
= info
->par
;
1436 info
->pseudo_palette
= ((u8
*)info
->par
+ sizeof(struct uvesafb_par
));
1437 info
->fix
= uvesafb_fix
;
1438 info
->fix
.ypanstep
= par
->ypan
? 1 : 0;
1439 info
->fix
.ywrapstep
= (par
->ypan
> 1) ? 1 : 0;
1441 /* Disable blanking if the user requested so. */
1443 uvesafb_ops
.fb_blank
= NULL
;
1446 * Find out how much IO memory is required for the mode with
1447 * the highest resolution.
1450 for (i
= 0; i
< par
->vbe_modes_cnt
; i
++) {
1451 h
= par
->vbe_modes
[i
].bytes_per_scan_line
*
1452 par
->vbe_modes
[i
].y_res
;
1459 * size_vmode -- that is the amount of memory needed for the
1460 * used video mode, i.e. the minimum amount of
1463 size_vmode
= info
->var
.yres
* mode
->bytes_per_scan_line
;
1466 * size_total -- all video memory we have. Used for mtrr
1467 * entries, resource allocation and bounds
1470 size_total
= par
->vbe_ib
.total_memory
* 65536;
1472 size_total
= vram_total
* 1024 * 1024;
1473 if (size_total
< size_vmode
)
1474 size_total
= size_vmode
;
1477 * size_remap -- the amount of video memory we are going to
1478 * use for vesafb. With modern cards it is no
1479 * option to simply use size_total as th
1480 * wastes plenty of kernel address space.
1483 size_remap
= vram_remap
* 1024 * 1024;
1484 if (size_remap
< size_vmode
)
1485 size_remap
= size_vmode
;
1486 if (size_remap
> size_total
)
1487 size_remap
= size_total
;
1489 info
->fix
.smem_len
= size_remap
;
1490 info
->fix
.smem_start
= mode
->phys_base_ptr
;
1493 * We have to set yres_virtual here because when setup_var() was
1494 * called, smem_len wasn't defined yet.
1496 info
->var
.yres_virtual
= info
->fix
.smem_len
/
1497 mode
->bytes_per_scan_line
;
1499 if (par
->ypan
&& info
->var
.yres_virtual
> info
->var
.yres
) {
1500 pr_info("scrolling: %s using protected mode interface, yres_virtual=%d\n",
1501 (par
->ypan
> 1) ? "ywrap" : "ypan",
1502 info
->var
.yres_virtual
);
1504 pr_info("scrolling: redraw\n");
1505 info
->var
.yres_virtual
= info
->var
.yres
;
1509 info
->flags
= (par
->ypan
? FBINFO_HWACCEL_YPAN
: 0);
1512 uvesafb_ops
.fb_pan_display
= NULL
;
1515 static void uvesafb_init_mtrr(struct fb_info
*info
)
1517 struct uvesafb_par
*par
= info
->par
;
1519 if (mtrr
&& !(info
->fix
.smem_start
& (PAGE_SIZE
- 1))) {
1520 int temp_size
= info
->fix
.smem_len
;
1524 /* Find the largest power-of-two */
1525 temp_size
= roundup_pow_of_two(temp_size
);
1527 /* Try and find a power of two to add */
1529 rc
= arch_phys_wc_add(info
->fix
.smem_start
, temp_size
);
1531 } while (temp_size
>= PAGE_SIZE
&& rc
== -EINVAL
);
1534 par
->mtrr_handle
= rc
;
1538 static void uvesafb_ioremap(struct fb_info
*info
)
1540 info
->screen_base
= ioremap_wc(info
->fix
.smem_start
, info
->fix
.smem_len
);
1543 static ssize_t
uvesafb_show_vbe_ver(struct device
*dev
,
1544 struct device_attribute
*attr
, char *buf
)
1546 struct fb_info
*info
= dev_get_drvdata(dev
);
1547 struct uvesafb_par
*par
= info
->par
;
1549 return sysfs_emit(buf
, "%.4x\n", par
->vbe_ib
.vbe_version
);
1552 static DEVICE_ATTR(vbe_version
, S_IRUGO
, uvesafb_show_vbe_ver
, NULL
);
1554 static ssize_t
uvesafb_show_vbe_modes(struct device
*dev
,
1555 struct device_attribute
*attr
, char *buf
)
1557 struct fb_info
*info
= dev_get_drvdata(dev
);
1558 struct uvesafb_par
*par
= info
->par
;
1561 for (i
= 0; i
< par
->vbe_modes_cnt
&& ret
< PAGE_SIZE
; i
++) {
1562 ret
+= scnprintf(buf
+ ret
, PAGE_SIZE
- ret
,
1563 "%dx%d-%d, 0x%.4x\n",
1564 par
->vbe_modes
[i
].x_res
, par
->vbe_modes
[i
].y_res
,
1565 par
->vbe_modes
[i
].depth
, par
->vbe_modes
[i
].mode_id
);
1571 static DEVICE_ATTR(vbe_modes
, S_IRUGO
, uvesafb_show_vbe_modes
, NULL
);
1573 static ssize_t
uvesafb_show_vendor(struct device
*dev
,
1574 struct device_attribute
*attr
, char *buf
)
1576 struct fb_info
*info
= dev_get_drvdata(dev
);
1577 struct uvesafb_par
*par
= info
->par
;
1579 if (par
->vbe_ib
.oem_vendor_name_ptr
)
1580 return sysfs_emit(buf
, "%s\n", (char *)
1581 (&par
->vbe_ib
) + par
->vbe_ib
.oem_vendor_name_ptr
);
1586 static DEVICE_ATTR(oem_vendor
, S_IRUGO
, uvesafb_show_vendor
, NULL
);
1588 static ssize_t
uvesafb_show_product_name(struct device
*dev
,
1589 struct device_attribute
*attr
, char *buf
)
1591 struct fb_info
*info
= dev_get_drvdata(dev
);
1592 struct uvesafb_par
*par
= info
->par
;
1594 if (par
->vbe_ib
.oem_product_name_ptr
)
1595 return sysfs_emit(buf
, "%s\n", (char *)
1596 (&par
->vbe_ib
) + par
->vbe_ib
.oem_product_name_ptr
);
1601 static DEVICE_ATTR(oem_product_name
, S_IRUGO
, uvesafb_show_product_name
, NULL
);
1603 static ssize_t
uvesafb_show_product_rev(struct device
*dev
,
1604 struct device_attribute
*attr
, char *buf
)
1606 struct fb_info
*info
= dev_get_drvdata(dev
);
1607 struct uvesafb_par
*par
= info
->par
;
1609 if (par
->vbe_ib
.oem_product_rev_ptr
)
1610 return sysfs_emit(buf
, "%s\n", (char *)
1611 (&par
->vbe_ib
) + par
->vbe_ib
.oem_product_rev_ptr
);
1616 static DEVICE_ATTR(oem_product_rev
, S_IRUGO
, uvesafb_show_product_rev
, NULL
);
1618 static ssize_t
uvesafb_show_oem_string(struct device
*dev
,
1619 struct device_attribute
*attr
, char *buf
)
1621 struct fb_info
*info
= dev_get_drvdata(dev
);
1622 struct uvesafb_par
*par
= info
->par
;
1624 if (par
->vbe_ib
.oem_string_ptr
)
1625 return sysfs_emit(buf
, "%s\n",
1626 (char *)(&par
->vbe_ib
) + par
->vbe_ib
.oem_string_ptr
);
1631 static DEVICE_ATTR(oem_string
, S_IRUGO
, uvesafb_show_oem_string
, NULL
);
1633 static ssize_t
uvesafb_show_nocrtc(struct device
*dev
,
1634 struct device_attribute
*attr
, char *buf
)
1636 struct fb_info
*info
= dev_get_drvdata(dev
);
1637 struct uvesafb_par
*par
= info
->par
;
1639 return sysfs_emit(buf
, "%d\n", par
->nocrtc
);
1642 static ssize_t
uvesafb_store_nocrtc(struct device
*dev
,
1643 struct device_attribute
*attr
, const char *buf
, size_t count
)
1645 struct fb_info
*info
= dev_get_drvdata(dev
);
1646 struct uvesafb_par
*par
= info
->par
;
1657 static DEVICE_ATTR(nocrtc
, S_IRUGO
| S_IWUSR
, uvesafb_show_nocrtc
,
1658 uvesafb_store_nocrtc
);
1660 static struct attribute
*uvesafb_dev_attrs
[] = {
1661 &dev_attr_vbe_version
.attr
,
1662 &dev_attr_vbe_modes
.attr
,
1663 &dev_attr_oem_vendor
.attr
,
1664 &dev_attr_oem_product_name
.attr
,
1665 &dev_attr_oem_product_rev
.attr
,
1666 &dev_attr_oem_string
.attr
,
1667 &dev_attr_nocrtc
.attr
,
1671 static const struct attribute_group uvesafb_dev_attgrp
= {
1673 .attrs
= uvesafb_dev_attrs
,
1676 static int uvesafb_probe(struct platform_device
*dev
)
1678 struct fb_info
*info
;
1679 struct vbe_mode_ib
*mode
= NULL
;
1680 struct uvesafb_par
*par
;
1683 info
= framebuffer_alloc(sizeof(*par
) + sizeof(u32
) * 256, &dev
->dev
);
1689 err
= uvesafb_vbe_init(info
);
1691 pr_err("vbe_init() failed with %d\n", err
);
1695 info
->fbops
= &uvesafb_ops
;
1697 i
= uvesafb_vbe_init_mode(info
);
1702 mode
= &par
->vbe_modes
[i
];
1705 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
1710 uvesafb_init_info(info
, mode
);
1712 if (!request_region(0x3c0, 32, "uvesafb")) {
1713 pr_err("request region 0x3c0-0x3e0 failed\n");
1718 if (!request_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
,
1720 pr_err("cannot reserve video memory at 0x%lx\n",
1721 info
->fix
.smem_start
);
1726 uvesafb_init_mtrr(info
);
1727 uvesafb_ioremap(info
);
1729 if (!info
->screen_base
) {
1730 pr_err("abort, cannot ioremap 0x%x bytes of video memory at 0x%lx\n",
1731 info
->fix
.smem_len
, info
->fix
.smem_start
);
1736 platform_set_drvdata(dev
, info
);
1738 if (register_framebuffer(info
) < 0) {
1739 pr_err("failed to register framebuffer device\n");
1744 pr_info("framebuffer at 0x%lx, mapped to 0x%p, using %dk, total %dk\n",
1745 info
->fix
.smem_start
, info
->screen_base
,
1746 info
->fix
.smem_len
/ 1024, par
->vbe_ib
.total_memory
* 64);
1747 fb_info(info
, "%s frame buffer device\n", info
->fix
.id
);
1749 err
= sysfs_create_group(&dev
->dev
.kobj
, &uvesafb_dev_attgrp
);
1751 fb_warn(info
, "failed to register attributes\n");
1756 iounmap(info
->screen_base
);
1758 arch_phys_wc_del(par
->mtrr_handle
);
1759 release_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
);
1761 release_region(0x3c0, 32);
1763 if (!list_empty(&info
->modelist
))
1764 fb_destroy_modelist(&info
->modelist
);
1765 fb_destroy_modedb(info
->monspecs
.modedb
);
1766 fb_dealloc_cmap(&info
->cmap
);
1768 kfree(par
->vbe_modes
);
1770 framebuffer_release(info
);
1774 static void uvesafb_remove(struct platform_device
*dev
)
1776 struct fb_info
*info
= platform_get_drvdata(dev
);
1777 struct uvesafb_par
*par
= info
->par
;
1779 sysfs_remove_group(&dev
->dev
.kobj
, &uvesafb_dev_attgrp
);
1780 unregister_framebuffer(info
);
1781 release_region(0x3c0, 32);
1782 iounmap(info
->screen_base
);
1783 arch_phys_wc_del(par
->mtrr_handle
);
1784 release_mem_region(info
->fix
.smem_start
, info
->fix
.smem_len
);
1785 fb_destroy_modedb(info
->monspecs
.modedb
);
1786 fb_dealloc_cmap(&info
->cmap
);
1788 kfree(par
->vbe_modes
);
1789 kfree(par
->vbe_state_orig
);
1790 kfree(par
->vbe_state_saved
);
1792 framebuffer_release(info
);
1795 static struct platform_driver uvesafb_driver
= {
1796 .probe
= uvesafb_probe
,
1797 .remove
= uvesafb_remove
,
1803 static struct platform_device
*uvesafb_device
;
1806 static int uvesafb_setup(char *options
)
1810 if (!options
|| !*options
)
1813 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1814 if (!*this_opt
) continue;
1816 if (!strcmp(this_opt
, "redraw"))
1818 else if (!strcmp(this_opt
, "ypan"))
1820 else if (!strcmp(this_opt
, "ywrap"))
1822 else if (!strcmp(this_opt
, "vgapal"))
1824 else if (!strcmp(this_opt
, "pmipal"))
1826 else if (!strncmp(this_opt
, "mtrr:", 5))
1827 mtrr
= simple_strtoul(this_opt
+5, NULL
, 0);
1828 else if (!strcmp(this_opt
, "nomtrr"))
1830 else if (!strcmp(this_opt
, "nocrtc"))
1832 else if (!strcmp(this_opt
, "noedid"))
1834 else if (!strcmp(this_opt
, "noblank"))
1836 else if (!strncmp(this_opt
, "vtotal:", 7))
1837 vram_total
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1838 else if (!strncmp(this_opt
, "vremap:", 7))
1839 vram_remap
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1840 else if (!strncmp(this_opt
, "maxhf:", 6))
1841 maxhf
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1842 else if (!strncmp(this_opt
, "maxvf:", 6))
1843 maxvf
= simple_strtoul(this_opt
+ 6, NULL
, 0);
1844 else if (!strncmp(this_opt
, "maxclk:", 7))
1845 maxclk
= simple_strtoul(this_opt
+ 7, NULL
, 0);
1846 else if (!strncmp(this_opt
, "vbemode:", 8))
1847 vbemode
= simple_strtoul(this_opt
+ 8, NULL
, 0);
1848 else if (this_opt
[0] >= '0' && this_opt
[0] <= '9') {
1849 mode_option
= this_opt
;
1851 pr_warn("unrecognized option %s\n", this_opt
);
1855 if (mtrr
!= 3 && mtrr
!= 0)
1856 pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr
);
1860 #endif /* !MODULE */
1862 static ssize_t
v86d_show(struct device_driver
*dev
, char *buf
)
1864 return snprintf(buf
, PAGE_SIZE
, "%s\n", v86d_path
);
1867 static ssize_t
v86d_store(struct device_driver
*dev
, const char *buf
,
1870 strscpy_pad(v86d_path
, buf
);
1873 static DRIVER_ATTR_RW(v86d
);
1875 static int uvesafb_init(void)
1880 char *option
= NULL
;
1882 if (fb_get_options("uvesafb", &option
))
1884 uvesafb_setup(option
);
1886 err
= cn_add_callback(&uvesafb_cn_id
, "uvesafb", uvesafb_cn_callback
);
1890 err
= platform_driver_register(&uvesafb_driver
);
1893 uvesafb_device
= platform_device_alloc("uvesafb", 0);
1895 err
= platform_device_add(uvesafb_device
);
1900 platform_device_put(uvesafb_device
);
1901 platform_driver_unregister(&uvesafb_driver
);
1902 cn_del_callback(&uvesafb_cn_id
);
1906 err
= driver_create_file(&uvesafb_driver
.driver
,
1909 pr_warn("failed to register attributes\n");
1916 module_init(uvesafb_init
);
1918 static void uvesafb_exit(void)
1920 struct uvesafb_ktask
*task
;
1923 task
= uvesafb_prep();
1925 task
->t
.flags
= TF_EXIT
;
1931 driver_remove_file(&uvesafb_driver
.driver
, &driver_attr_v86d
);
1932 platform_device_unregister(uvesafb_device
);
1933 platform_driver_unregister(&uvesafb_driver
);
1934 cn_del_callback(&uvesafb_cn_id
);
1937 module_exit(uvesafb_exit
);
1939 static int param_set_scroll(const char *val
, const struct kernel_param
*kp
)
1943 if (!strcmp(val
, "redraw"))
1945 else if (!strcmp(val
, "ypan"))
1947 else if (!strcmp(val
, "ywrap"))
1954 static const struct kernel_param_ops param_ops_scroll
= {
1955 .set
= param_set_scroll
,
1957 #define param_check_scroll(name, p) __param_check(name, p, void)
1959 module_param_named(scroll
, ypan
, scroll
, 0);
1960 MODULE_PARM_DESC(scroll
,
1961 "Scrolling mode, set to 'redraw', 'ypan', or 'ywrap'");
1962 module_param_named(vgapal
, pmi_setpal
, invbool
, 0);
1963 MODULE_PARM_DESC(vgapal
, "Set palette using VGA registers");
1964 module_param_named(pmipal
, pmi_setpal
, bool, 0);
1965 MODULE_PARM_DESC(pmipal
, "Set palette using PMI calls");
1966 module_param(mtrr
, uint
, 0);
1967 MODULE_PARM_DESC(mtrr
,
1968 "Memory Type Range Registers setting. Use 0 to disable.");
1969 module_param(blank
, bool, 0);
1970 MODULE_PARM_DESC(blank
, "Enable hardware blanking");
1971 module_param(nocrtc
, bool, 0);
1972 MODULE_PARM_DESC(nocrtc
, "Ignore CRTC timings when setting modes");
1973 module_param(noedid
, bool, 0);
1974 MODULE_PARM_DESC(noedid
,
1975 "Ignore EDID-provided monitor limits when setting modes");
1976 module_param(vram_remap
, uint
, 0);
1977 MODULE_PARM_DESC(vram_remap
, "Set amount of video memory to be used [MiB]");
1978 module_param(vram_total
, uint
, 0);
1979 MODULE_PARM_DESC(vram_total
, "Set total amount of video memory [MiB]");
1980 module_param(maxclk
, ushort
, 0);
1981 MODULE_PARM_DESC(maxclk
, "Maximum pixelclock [MHz], overrides EDID data");
1982 module_param(maxhf
, ushort
, 0);
1983 MODULE_PARM_DESC(maxhf
,
1984 "Maximum horizontal frequency [kHz], overrides EDID data");
1985 module_param(maxvf
, ushort
, 0);
1986 MODULE_PARM_DESC(maxvf
,
1987 "Maximum vertical frequency [Hz], overrides EDID data");
1988 module_param(mode_option
, charp
, 0);
1989 MODULE_PARM_DESC(mode_option
,
1990 "Specify initial video mode as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
1991 module_param(vbemode
, ushort
, 0);
1992 MODULE_PARM_DESC(vbemode
,
1993 "VBE mode number to set, overrides the 'mode' option");
1994 module_param_string(v86d
, v86d_path
, PATH_MAX
, 0660);
1995 MODULE_PARM_DESC(v86d
, "Path to the v86d userspace helper.");
1997 MODULE_LICENSE("GPL");
1998 MODULE_AUTHOR("Michal Januszewski <spock@gentoo.org>");
1999 MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");