1 diff --git a/Documentation/fb/vesafb.txt b/Documentation/fb/vesafb.txt
2 index ee277dd..f768129 100644
3 --- a/Documentation/fb/vesafb.txt
4 +++ b/Documentation/fb/vesafb.txt
9 -This is a generic driver for a graphic framebuffer on intel boxes.
10 +Vesafb is a generic framebuffer driver for x86 and x86_64 boxes.
12 -The idea is simple: Turn on graphics mode at boot time with the help
13 -of the BIOS, and use this as framebuffer device /dev/fb0, like the m68k
14 -(and other) ports do.
16 -This means we decide at boot time whenever we want to run in text or
17 -graphics mode. Switching mode later on (in protected mode) is
18 -impossible; BIOS calls work in real mode only. VESA BIOS Extensions
19 -Version 2.0 are required, because we need a linear frame buffer.
20 +VESA BIOS Extensions Version 2.0 are required, because we need access to
21 +a linear frame buffer. VBE 3.0 is required if you want to use modes with a
22 +higher (than the standard 60Hz) refresh rate.
24 +The VESA framebuffer driver comes in two flavors - the standard 'vesafb'
25 +and 'vesafb-tng'. Vesafb-tng is available only on 32-bit x86 due to the
26 +technology it uses (vm86). Vesafb-tng has more features than vesafb
27 +(adjusting the refresh rate on VBE3.0-compliant boards, switching the
28 +video mode without rebooting, selecting a mode by providing its
29 +modedb name, and more).
33 @@ -29,26 +31,35 @@ Disadvantages:
37 -Switching modes is done using the vga=... boot parameter. Read
38 -Documentation/svga.txt for details.
40 -You should compile in both vgacon (for text mode) and vesafb (for
41 -graphics mode). Which of them takes over the console depends on
42 -whenever the specified mode is text or graphics.
44 -The graphic modes are NOT in the list which you get if you boot with
45 -vga=ask and hit return. The mode you wish to use is derived from the
46 -VESA mode number. Here are those VESA mode numbers:
47 +If you are running a 32-bit x86 system and you decide to use vesafb-tng,
48 +you can either compile the driver into the kernel or use it as a module.
49 +The graphics mode you want to use is in both cases specified using the
50 +standard modedb format.
52 +If your system doesn't support vm86 calls, things get a little more tricky.
53 +Since on such systems you can't do BIOS calls from protected mode in which
54 +kernel runs, you have to decide at boot time whenever you want to run in text
55 +or in graphics mode. Switching mode later on is impossible. Switching modes
56 +is done using the vga=... boot parameter. Read Documentation/svga.txt for
57 +details. Below is a more detailed description of what to do on systems using
58 +the standard vesafb driver.
60 +You should compile in both vgacon (for text mode) and vesafb (for graphics
61 +mode). Which of them takes over the console depends on whenever the
62 +specified mode is text or graphics.
64 +The graphic modes are NOT in the list which you get if you boot with vga=ask
65 +and hit return. The mode you wish to use is derived from the VESA mode number.
66 +Here are those VESA mode numbers:
68 | 640x480 800x600 1024x768 1280x1024
69 ----+-------------------------------------
70 -256 | 0x101 0x103 0x105 0x107
71 -32k | 0x110 0x113 0x116 0x119
72 -64k | 0x111 0x114 0x117 0x11A
73 -16M | 0x112 0x115 0x118 0x11B
74 +256 | 0x101 0x103 0x105 0x107
75 +32k | 0x110 0x113 0x116 0x119
76 +64k | 0x111 0x114 0x117 0x11A
77 +16M | 0x112 0x115 0x118 0x11B
79 -The video mode number of the Linux kernel is the VESA mode number plus
81 +The video mode number of the Linux kernel is the VESA mode number plus 0x200.
83 Linux_kernel_mode_number = VESA_mode_number + 0x200
85 @@ -56,15 +67,15 @@ So the table for the Kernel mode numbers
87 | 640x480 800x600 1024x768 1280x1024
88 ----+-------------------------------------
89 -256 | 0x301 0x303 0x305 0x307
90 -32k | 0x310 0x313 0x316 0x319
91 -64k | 0x311 0x314 0x317 0x31A
92 -16M | 0x312 0x315 0x318 0x31B
94 -To enable one of those modes you have to specify "vga=ask" in the
95 -lilo.conf file and rerun LILO. Then you can type in the desired
96 -mode at the "vga=ask" prompt. For example if you like to use
97 -1024x768x256 colors you have to say "305" at this prompt.
98 +256 | 0x301 0x303 0x305 0x307
99 +32k | 0x310 0x313 0x316 0x319
100 +64k | 0x311 0x314 0x317 0x31A
101 +16M | 0x312 0x315 0x318 0x31B
103 +To enable one of those modes you have to specify "vga=ask" in the lilo.conf
104 +file and rerun LILO. Then you can type in the desired mode at the "vga=ask"
105 +prompt. For example if you like to use 1024x768x256 colors you have to say
106 +"305" at this prompt.
108 If this does not work, this might be because your BIOS does not support
109 linear framebuffers or because it does not support this mode at all.
110 @@ -72,11 +83,12 @@ Even if your board does, it might be the
111 Extensions v2.0 are required, 1.2 is NOT sufficient. You will get a
112 "bad mode number" message if something goes wrong.
114 -1. Note: LILO cannot handle hex, for booting directly with
115 +1. Note: LILO cannot handle hex, for booting directly with
116 "vga=mode-number" you have to transform the numbers to decimal.
117 2. Note: Some newer versions of LILO appear to work with those hex values,
118 if you set the 0x in front of the numbers.
124 @@ -84,98 +96,164 @@ XF68_FBDev should work just fine, but it
125 another (accelerated) X-Server like XF86_SVGA might or might not work.
126 It depends on X-Server and graphics board.
128 -The X-Server must restore the video mode correctly, else you end up
129 +The X-Server must restore the video mode correctly, or else you end up
130 with a broken console (and vesafb cannot do anything about this).
131 +With vesafb-tng chances are that the console will be restored properly
132 +even if the X server messes up the video mode.
138 -There is no way to change the vesafb video mode and/or timings after
139 -booting linux. If you are not happy with the 60 Hz refresh rate, you
141 +With VBE3.0 compatible BIOSes and vesafb-tng it is possible to change
142 +the refresh rate either at boot time (by specifying the @<rr> part of
143 +the mode name) or later, using the fbset utility.
145 +If you want to use the default BIOS refresh rate while switching modes
146 +on a running system, set pixclock to 0.
148 +With VBE2.0 there is no way to change the mode timings after booting
149 +Linux. If you are not happy with the 60 Hz refresh rate, you have
152 - * configure and load the DOS-Tools for your the graphics board (if
153 - available) and boot linux with loadlin.
154 + * configure and load the DOS tools for your the graphics board (if
155 + available) and boot Linux with loadlin.
156 * use a native driver (matroxfb/atyfb) instead if vesafb. If none
157 is available, write a new one!
158 - * VBE 3.0 might work too. I have neither a gfx board with VBE 3.0
159 - support nor the specs, so I have not checked this yet.
160 + * use a BIOS editor to change the default refresh rate (such an
161 + editor does exist at least for ATI Radeon BIOSes).
162 + * if you're running a non-vm86 and VBE3.0-compatible system, you can
163 + use a kernel patch (vesafb-rrc) to hard-code some mode timings in
164 + the kernel and use these while setting the graphic mode at boot time.
166 +Note that there are some boards (nVidia 59**, 57** and newer models)
167 +claiming that their Video BIOS is VBE3.0 compliant, while ignoring the
168 +CRTC values provided by software such as vesafb-tng. You'll not be able
169 +to change the refresh rate if you're using one of these boards.
175 -The VESA BIOS provides protected mode interface for changing
176 -some parameters. vesafb can use it for palette changes and
177 -to pan the display. It is turned off by default because it
178 -seems not to work with some BIOS versions, but there are options
181 -You can pass options to vesafb using "video=vesafb:option" on
182 -the kernel command line. Multiple options should be separated
183 -by comma, like this: "video=vesafb:ypan,invers"
187 -invers no comment...
189 -ypan enable display panning using the VESA protected mode
190 - interface. The visible screen is just a window of the
191 - video memory, console scrolling is done by changing the
192 - start of the window.
193 - pro: * scrolling (fullscreen) is fast, because there is
194 - no need to copy around data.
195 - * You'll get scrollback (the Shift-PgUp thing),
196 - the video memory can be used as scrollback buffer
197 - kontra: * scrolling only parts of the screen causes some
198 - ugly flicker effects (boot logo flickers for
201 -ywrap Same as ypan, but assumes your gfx board can wrap-around
202 - the video memory (i.e. starts reading from top if it
203 - reaches the end of video memory). Faster than ypan.
205 -redraw scroll by redrawing the affected part of the screen, this
206 - is the safe (and slow) default.
209 -vgapal Use the standard vga registers for palette changes.
210 - This is the default.
211 -pmipal Use the protected mode interface for palette changes.
213 -mtrr:n setup memory type range registers for the vesafb framebuffer
215 - 0 - disabled (equivalent to nomtrr) (default)
218 - 3 - write-combining
220 +The VESA BIOS provides protected mode interface for changing some parameters.
221 +vesafb can use it for palette changes and to pan the display. It is turned
222 +off by default because it seems not to work with some BIOS versions, but
223 +there are options to turn it on.
225 +You can pass options to vesafb using "video=vesafb:option" on the kernel
226 +command line. Multiple options should be separated by comma, like this:
227 +"video=vesafb:ypan,1024x768-32@85"
229 +Note that vesafb-tng still uses the "video=vesafb:option" format of the
230 +kernel command line video parameter. "video=vesafb-tng:xxx" is incorrect.
232 +Accepted options (both vesafb and vesafb-tng):
234 +ypan Enable display panning using the VESA protected mode interface
235 + The visible screen is just a window of the video memory,
236 + console scrolling is done by changing the start of the window.
237 + pro: * scrolling (fullscreen) is fast, because there is
238 + no need to copy around data.
239 + * you'll get scrollback (the Shift-PgUp thing),
240 + the video memory can be used as scrollback buffer
241 + con: * scrolling only parts of the screen causes some
242 + ugly flicker effects (boot logo flickers for
245 +ywrap Same as ypan, but assumes your gfx board can wrap-around the video
246 + memory (i.e. starts reading from top if it reaches the end of
247 + video memory). Faster than ypan.
249 +redraw Scroll by redrawing the affected part of the screen, this is the
250 + safe (and slow) default.
252 +vgapal Use the standard VGA registers for palette changes.
253 + This is the default.
255 +pmipal Use the protected mode interface for palette changes.
257 +mtrr:n Setup memory type range registers for the vesafb framebuffer
259 + 0 - disabled (equivalent to nomtrr) (default)
262 + 3 - write-combining
265 - If you see the following in dmesg, choose the type that matches the
266 - old one. In this example, use "mtrr:2".
267 + If you see the following in dmesg, choose the type that matches
268 + the old one. In this example, use "mtrr:2".
270 mtrr: type mismatch for e0000000,8000000 old: write-back new: write-combining
274 +nomtrr Do not use memory type range registers for vesafb.
277 remap 'n' MiB of video RAM. If 0 or not specified, remap memory
278 - according to video mode. (2.5.66 patch/idea by Antonino Daplas
279 - reversed to give override possibility (allocate more fb memory
280 - than the kernel would) to 2.4 by tmb@iki.fi)
281 + according to video mode. (2.5.66 patch/idea by Antonino Daplas
282 + reversed to give override possibility (allocate more fb memory
283 + than the kernel would) to 2.4 by tmb@iki.fi)
286 if the video BIOS of your card incorrectly determines the total
287 amount of video RAM, use this option to override the BIOS (in MiB).
290 +Options accepted only by vesafb-tng:
293 +<mode> The mode you want to set, in the standard modedb format. Refer to
294 + modedb.txt for detailed description. If you specify a mode that is
295 + not supported by your board's BIOS, vesafb will attempt to set a
296 + similar mode. The list of supported modes can be found in
297 + /proc/fbx/modes, where x is the framebuffer number (usually 0).
298 + When vesafb is compiled as a module, the mode string should be
299 + provided as a value of the parameter 'mode'.
302 + Force the use of VBE mode x. The mode will only be set if it's
303 + found in VBE-provided list of supported modes.
304 + NOTE: The mode number 'x' should be specified in VESA mode number
305 + notation, not the Linux kernel one (ie. 257 instead of 769).
306 + HINT: If you use this option because normal <mode> parameter does
307 + not work for you and you use a X server, you'll probably want to
308 + set the 'nocrtc' option to ensure that the video mode is properly
309 + restored after console <-> X switches.
311 +nocrtc Do not use CRTC timings while setting the graphic mode. This option
312 + makes sence only with VBE3.0 compliant systems. Use it if you have
313 + problems with the modes set in the standard way. Note that specifying
314 + this option means the refresh rate will be ignored and will stay at
315 + your BIOS default (60 Hz).
317 +noedid Do not try to fetch and use EDID-provided modes.
319 +noblank Disable hardware blanking.
321 +gtf Force the use of VESA's GTF (Generalized Timing Formula). Specifying
322 + this will cause vesafb to skip it's internal modedb and EDID-modedb
323 + and jump straight to the GTF part of the code (normally used only if
324 + everything else failed). This can be useful if you want to get as
325 + much as possible from you graphics board but your BIOS doesn't
326 + support modes with refresh rates you require. Note that you may need
327 + to specify the maxhf, maxvf and maxclk parameters if they are not
330 +Additionally, the following parameters may be provided. They all override the
331 +EDID-provided values and BIOS defaults. Refer to your monitor's specs to get
332 +the correct values for maxhf, maxvf and maxclk for your hardware.
334 +maxhf:n Maximum horizontal frequency (in kHz).
335 +maxvf:n Maximum vertical frequency (in Hz).
336 +maxclk:n Maximum pixel clock (in MHz).
341 +Original document for the vesafb driver by
342 Gerd Knorr <kraxel@goldbach.in-berlin.de>
344 -Minor (mostly typo) changes
345 -by Nico Schmoigl <schmoigl@rumms.uni-mannheim.de>
346 +Minor (mostly typo) changes by
347 +Nico Schmoigl <schmoigl@rumms.uni-mannheim.de>
349 +Extended documentation for vm86, VBE3.0 and vesafb-tng by
350 +Michal Januszewski <spock@gentoo.org>
352 diff --git a/arch/i386/boot/video.S b/arch/i386/boot/video.S
353 index 2ac40c8..335d401 100644
354 --- a/arch/i386/boot/video.S
355 +++ b/arch/i386/boot/video.S
356 @@ -164,10 +164,12 @@ basret: ret
357 # parameters in the default 80x25 mode -- these are set directly,
358 # because some very obscure BIOSes supply insane values.
360 +#ifdef CONFIG_FB_VESA_STD
361 #ifdef CONFIG_VIDEO_SELECT
362 cmpb $0, graphic_mode
366 movb $0x03, %ah # Read cursor position
369 @@ -200,6 +202,7 @@ mopar2: movb %al, %fs:(PARAM_VIDEO_LINES
372 #ifdef CONFIG_VIDEO_SELECT
373 +#ifdef CONFIG_FB_VESA_STD
374 # Fetching of VESA frame buffer parameters
376 leaw modelist+1024, %di
377 @@ -278,6 +281,7 @@ dac_done:
378 movw %es, %fs:(PARAM_VESAPM_SEG)
379 movw %di, %fs:(PARAM_VESAPM_OFF)
383 # The video mode menu
385 @@ -492,10 +496,12 @@ mode_set:
387 cmpb $VIDEO_FIRST_V7>>8, %ah
391 +#ifdef CONFIG_FB_VESA_STD
392 cmpb $VIDEO_FIRST_VESA>>8, %ah
400 @@ -567,6 +573,7 @@ setr1: lodsw
401 movw -4(%si), %ax # Fetch mode ID
404 +#ifdef CONFIG_FB_VESA_STD
406 leaw modelist+1024, %di
407 subb $VIDEO_FIRST_VESA>>8, %bh
408 @@ -600,6 +607,7 @@ check_vesa:
411 _setbad: jmp setbad # Ugly...
414 # Recalculate vertical display end registers -- this fixes various
415 # inconsistencies of extended modes on many adapters. Called when
416 diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
417 index fdebd60..a1d6253 100644
418 --- a/drivers/video/Kconfig
419 +++ b/drivers/video/Kconfig
420 @@ -454,8 +454,8 @@ config FB_TGA
421 cards. Say Y if you have one of those.
424 - bool "VESA VGA graphics support"
425 - depends on (FB = y) && X86
426 + tristate "VESA VGA graphics support"
427 + depends on (FB = y) && (X86 || X86_64)
428 select FB_CFB_FILLRECT
429 select FB_CFB_COPYAREA
430 select FB_CFB_IMAGEBLIT
431 @@ -465,6 +465,48 @@ config FB_VESA
432 You will get a boot time penguin logo at no additional cost. Please
433 read <file:Documentation/fb/vesafb.txt>. If unsure, say Y.
436 + prompt "VESA driver type"
438 + default FB_VESA_STD if X86_64
439 + default FB_VESA_TNG if X86
444 + This is the frame buffer device driver for generic VESA 2.0
445 + compliant graphic cards. The older VESA 1.2 cards are not supported.
446 + You will get a boot time penguin logo at no additional cost. Please
447 + read <file:Documentation/fb/vesafb.txt>. Choose this driver if you
448 + are experiencing problems with vesafb-tng or if you own a 64-bit system.
450 + Note that this driver cannot be compiled as a module.
455 + select FB_MODE_HELPERS
457 + This is the frame buffer device driver for generic VESA 2.0
458 + compliant graphic cards. It is capable of taking advantage of
459 + VBE 3.0 features. With this driver you will be able to adjust
460 + the refresh rate (VBE 3.0 compliant boards only) and change
461 + the graphic mode on-the-fly.
463 + You will also get a boot time penguin logo at no additional cost. Please
464 + read <file:Documentation/fb/vesafb.txt>.
468 +config FB_VESA_DEFAULT_MODE
469 + string "VESA default mode"
470 + depends on FB_VESA_TNG
471 + default "640x480@60"
473 + This option is used to determine the default mode vesafb is
474 + supposed to switch to in case no mode is provided as a kernel
475 + command line parameter.
480 diff --git a/drivers/video/Makefile b/drivers/video/Makefile
481 index aa434e7..247cfb3 100644
482 --- a/drivers/video/Makefile
483 +++ b/drivers/video/Makefile
484 @@ -96,7 +96,11 @@ obj-$(CONFIG_FB_IMX) += imx
485 obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
487 # Platform or fallback drivers go here
488 -obj-$(CONFIG_FB_VESA) += vesafb.o
489 +ifeq ($(CONFIG_FB_VESA_STD),y)
492 + obj-$(CONFIG_FB_VESA) += vesafb-thread.o vesafb-tng.o
494 obj-$(CONFIG_FB_VGA16) += vga16fb.o vgastate.o
495 obj-$(CONFIG_FB_OF) += offb.o
497 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
498 index 996c7b5..f48eee0 100644
499 --- a/drivers/video/fbmem.c
500 +++ b/drivers/video/fbmem.c
501 @@ -1430,6 +1430,7 @@ fbmem_init(void)
502 printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
509 diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
510 index 1da2f84..6755cb2 100644
511 --- a/drivers/video/modedb.c
512 +++ b/drivers/video/modedb.c
513 @@ -667,6 +667,7 @@ void fb_var_to_videomode(struct fb_video
515 u32 pixclock, hfreq, htotal, vtotal;
519 mode->xres = var->xres;
520 mode->yres = var->yres;
521 diff --git a/drivers/video/vesafb-thread.c b/drivers/video/vesafb-thread.c
523 index 0000000..249d794
525 +++ b/drivers/video/vesafb-thread.c
528 + * Framebuffer driver for VBE 2.0+ compliant graphic boards.
529 + * Kernel thread and vm86 routines.
531 + * (c) 2004-2005 Michal Januszewski <spock@gentoo.org>
535 +#include <linux/config.h>
536 +#include <linux/slab.h>
537 +#include <linux/workqueue.h>
538 +#include <linux/completion.h>
539 +#include <linux/module.h>
540 +#include <linux/kernel.h>
541 +#include <linux/errno.h>
542 +#include <linux/mm.h>
543 +#include <linux/delay.h>
544 +#include <linux/signal.h>
545 +#include <linux/suspend.h>
546 +#include <linux/unistd.h>
547 +#include <video/vesa.h>
548 +#include <video/edid.h>
549 +#include <asm/mman.h>
550 +#include <asm/page.h>
551 +#include <asm/vm86.h>
552 +#include <asm/thread_info.h>
553 +#include <asm/uaccess.h>
554 +#include <asm/mmu_context.h>
561 +static DECLARE_COMPLETION(vesafb_th_completion);
562 +static DECLARE_MUTEX(vesafb_task_list_sem);
563 +static LIST_HEAD(vesafb_task_list);
564 +static DECLARE_WAIT_QUEUE_HEAD(vesafb_wait);
566 +static struct vm86_struct vm86;
567 +static int vesafb_pid = 0;
569 +_syscall3(int,ioperm,unsigned long, a, unsigned long, b, unsigned long, c);
570 +_syscall1(int,vm86old,struct vm86_struct __user*, v86);
572 +#define DEFAULT_VM86_FLAGS (IF_MASK | IOPL_MASK)
573 +#define VM86_PUSHW(x) \
575 + vm86.regs.esp -= 2; \
576 + *(u16*)(STACK_ADDR + vm86.regs.esp) = x; \
579 +/* Stack, the return code and buffers will be put into
580 + * one contiguous memory chunk:
582 + * [ STACK | RET_CODE | BUFFER ]
584 + * We only need a buffer that is ca. 0x2000 bytes in size.
585 + * Some video BIOSes (sis6326) try to store data somewhere
586 + * in 0x7000-0x7fff, so we zeromap more memory to be safe.
588 +#define IVTBDA_SIZE PAGE_SIZE
589 +#define RET_CODE_SIZE 0x0010
590 +#define STACK_SIZE 0x0500
591 +#define BUFFER_SIZE 0x10000
593 +/* The amount of memory that will be allocated should be a multiple
595 +#define __MEM_SIZE (RET_CODE_SIZE + STACK_SIZE + BUFFER_SIZE)
596 +#define REAL_MEM_SIZE (((__MEM_SIZE / PAGE_SIZE) + 1) * PAGE_SIZE)
598 +#define IVTBDA_ADDR 0x00000
599 +#define STACK_ADDR (IVTBDA_ADDR + IVTBDA_SIZE)
600 +#define RET_CODE_ADDR (STACK_ADDR + STACK_SIZE)
601 +#define BUF_ADDR (RET_CODE_ADDR + RET_CODE_SIZE)
603 +#define FLAG_D (1 << 10)
605 +/* Segment prefix opcodes */
615 +/* Emulated vm86 ins instruction */
616 +static void vm86_ins(int size)
619 + edx = vm86.regs.edx & 0xffff;
620 + edi = (vm86.regs.edi & 0xffff) + (u32)(vm86.regs.es << 4);
622 + if (vm86.regs.eflags & FLAG_D)
623 + asm volatile ("std\n");
625 + asm volatile ("cld\n");
629 + asm volatile ("insl\n" : "=D" (edi) : "d" (edx), "0" (edi));
632 + asm volatile ("insw\n" : "=D" (edi) : "d" (edx), "0" (edi));
635 + asm volatile ("insb\n" : "=D" (edi) : "d" (edx), "0" (edi));
639 + if (vm86.regs.eflags & FLAG_D)
640 + asm volatile ("cld\n");
642 + edi -= (u32)(vm86.regs.es << 4);
644 + vm86.regs.edi &= 0xffff0000;
645 + vm86.regs.edi |= edi & 0xffff;
648 +static void vm86_rep_ins(int size)
650 + u16 cx = vm86.regs.ecx;
654 + vm86.regs.ecx &= 0xffff0000;
657 +/* Emulated vm86 outs instruction */
658 +static void vm86_outs(int size, int segment)
660 + u32 edx, esi, base;
662 + edx = vm86.regs.edx & 0xffff;
663 + esi = vm86.regs.esi & 0xffff;
666 + case P_CS: base = vm86.regs.cs; break;
667 + case P_SS: base = vm86.regs.ss; break;
668 + case P_ES: base = vm86.regs.es; break;
669 + case P_FS: base = vm86.regs.fs; break;
670 + case P_GS: base = vm86.regs.gs; break;
671 + default: base = vm86.regs.ds; break;
676 + if (vm86.regs.eflags & FLAG_D)
677 + asm volatile ("std\n");
679 + asm volatile ("cld\n");
683 + asm volatile ("outsl\n" : "=S" (esi) : "d" (edx), "0" (esi));
686 + asm volatile ("outsw\n" : "=S" (esi) : "d" (edx), "0" (esi));
689 + asm volatile ("outsb\n" : "=S" (esi) : "d" (edx), "0" (esi));
693 + if (vm86.regs.eflags & FLAG_D)
694 + asm volatile ("cld");
697 + vm86.regs.esi &= 0xffff0000;
698 + vm86.regs.esi |= (esi & 0xffff);
701 +static void vm86_rep_outs(int size, int segment)
703 + u16 cx = vm86.regs.ecx;
705 + vm86_outs(size, segment);
707 + vm86.regs.ecx &= 0xffff0000;
710 +static int vm86_do_unknown(void)
712 + u8 data32 = 0, segment = P_DS, rep = 0;
714 + int ret = 0, i = 0;
716 + instr = (u8*)((vm86.regs.cs << 4) + vm86.regs.eip);
720 + case 0x66: /* operand size prefix */
721 + data32 = 1 - data32;
724 + case 0xf2: /* repnz */
725 + case 0xf3: /* rep */
729 + case P_CS: /* segment prefix */
735 + segment = instr[i];
738 + case 0xf0: /* LOCK - ignored */
739 + case 0x67: /* address size prefix - ignored */
742 + case 0x6c: /* insb */
749 + case 0x6d: /* insw / insd */
763 + case 0x6e: /* outsb */
765 + vm86_rep_outs(1, segment);
767 + vm86_outs(1, segment);
770 + case 0x6f: /* outsw / outsd */
773 + vm86_rep_outs(4, segment);
775 + vm86_rep_outs(2, segment);
778 + vm86_outs(4, segment);
780 + vm86_outs(2, segment);
784 + case 0xe4: /* inb xx */
787 + : "=a" (vm86.regs.eax)
788 + : "d" (instr[i+1]), "0" (vm86.regs.eax));
791 + case 0xe5: /* inw xx / ind xx */
795 + : "=a" (vm86.regs.eax)
796 + : "d" (instr[i+1]),
797 + "0" (vm86.regs.eax));
801 + : "=a" (vm86.regs.eax)
802 + : "d" (instr[i+1]),
803 + "0" (vm86.regs.eax));
808 + case 0xec: /* inb dx */
811 + : "=a" (vm86.regs.eax)
812 + : "d" (vm86.regs.edx), "0" (vm86.regs.eax));
815 + case 0xed: /* inw dx / ind dx */
819 + : "=a" (vm86.regs.eax)
820 + : "d" (vm86.regs.edx));
824 + : "=a" (vm86.regs.eax)
825 + : "d" (vm86.regs.edx));
829 + case 0xe6: /* outb xx */
832 + : /* no return value */
833 + : "a" (vm86.regs.eax), "d" (instr[i+1]));
836 + case 0xe7: /* outw xx / outd xx */
840 + : /* no return value */
841 + : "a" (vm86.regs.eax),
846 + : /* no return value */
847 + : "a" (vm86.regs.eax),
852 + case 0xee: /* outb dx */
855 + : /* no return value */
856 + : "a" (vm86.regs.eax), "d" (vm86.regs.edx));
859 + case 0xef: /* outw dx / outd dx */
863 + : /* no return value */
864 + : "a" (vm86.regs.eax),
865 + "d" (vm86.regs.edx));
869 + : /* no return value */
870 + : "a" (vm86.regs.eax),
871 + "d" (vm86.regs.edx));
876 + printk(KERN_ERR "vesafb: BUG, opcode 0x%x emulation "
877 + "not supported (EIP: 0x%lx)\n",
878 + instr[i], (u32)(vm86.regs.cs << 4) +
884 +out: vm86.regs.eip += i;
888 +void vesafb_do_vm86(struct vm86_regs *regs)
891 + u8 *retcode = (void*)RET_CODE_ADDR;
893 + memset(&vm86,0,sizeof(vm86));
894 + memcpy(&vm86.regs, regs, sizeof(struct vm86_regs));
896 + /* The return code */
897 + retcode[0] = 0xcd; /* int opcode */
898 + retcode[1] = 0xff; /* int number (255) */
900 + /* We use int 0xff to get back to protected mode */
901 + memset(&vm86.int_revectored, 0, sizeof(vm86.int_revectored));
902 + ((unsigned char *)&vm86.int_revectored)[0xff / 8] |= (1 << (0xff % 8));
905 + * We want to call int 0x10, so we set:
906 + * CS = 0x42 = 0x10 * 4 + 2
907 + * IP = 0x40 = 0x10 * 4
908 + * and SS:ESP. It's up to the caller to set the rest of the registers.
910 + vm86.regs.eflags = DEFAULT_VM86_FLAGS;
911 + vm86.regs.cs = *(unsigned short *)0x42;
912 + vm86.regs.eip = *(unsigned short *)0x40;
913 + vm86.regs.ss = (STACK_ADDR >> 4);
914 + vm86.regs.esp = ((STACK_ADDR & 0x0000f) + STACK_SIZE);
916 + /* These will be fetched off the stack when we come to an iret in the
917 + * int's 0x10 code. */
918 + VM86_PUSHW(DEFAULT_VM86_FLAGS);
919 + VM86_PUSHW((RET_CODE_ADDR >> 4)); /* return code segment */
920 + VM86_PUSHW((RET_CODE_ADDR & 0x0000f)); /* return code offset */
923 + ret = vm86old(&vm86);
925 + if (VM86_TYPE(ret) == VM86_INTx) {
926 + int vint = VM86_ARG(ret);
928 + /* If exit from vm86 was caused by int 0xff, then
933 + /* .. otherwise, we have to call the int handler
935 + VM86_PUSHW(vm86.regs.eflags);
936 + VM86_PUSHW(vm86.regs.cs);
937 + VM86_PUSHW(vm86.regs.eip);
939 + vm86.regs.cs = *(u16 *)((vint << 2) + 2);
940 + vm86.regs.eip = *(u16 *)(vint << 2);
941 + vm86.regs.eflags &= ~(VIF_MASK | TF_MASK);
942 + } else if (VM86_TYPE(ret) == VM86_UNKNOWN) {
943 + if (vm86_do_unknown())
946 + printk(KERN_ERR "vesafb: BUG, returned from "
947 + "vm86 with %x (EIP: 0x%lx)\n",
948 + ret, (u32)(vm86.regs.cs << 4) +
954 +out: /* copy the registers' state back to the caller's struct */
955 + memcpy(regs, &vm86.regs, sizeof(struct vm86_regs));
958 +static int vesafb_remap_pfn_range(unsigned long start, unsigned long end,
959 + unsigned long pgoff, unsigned long prot,
962 + struct vm_area_struct *vma;
963 + struct mm_struct *mm = current->mm;
966 + vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
969 + memset(vma, 0, sizeof(*vma));
970 + down_write(&mm->mmap_sem);
972 + vma->vm_start = start;
974 + vma->vm_flags = VM_READ | VM_WRITE | VM_EXEC;
975 + vma->vm_flags |= mm->def_flags;
976 + vma->vm_page_prot.pgprot = prot;
977 + vma->vm_pgoff = pgoff;
979 + if ((ret = insert_vm_struct(mm, vma))) {
980 + up_write(&mm->mmap_sem);
981 + kmem_cache_free(vm_area_cachep, vma);
986 + vma->vm_flags |= VM_SHARED;
987 + ret = zeromap_page_range(vma,
989 + vma->vm_end - vma->vm_start,
990 + vma->vm_page_prot);
992 + ret = remap_pfn_range(vma,
995 + vma->vm_end - vma->vm_start,
996 + vma->vm_page_prot);
998 + up_write(&mm->mmap_sem);
1002 +static inline int vesafb_init_mem(void)
1006 + /* The memory chunks we're remapping here should be multiples
1007 + * of PAGE_SIZE. */
1008 + ret += vesafb_remap_pfn_range(0x00000, IVTBDA_SIZE, 0,
1009 + PROT_READ | PROT_EXEC | PROT_WRITE, 0);
1010 + ret += vesafb_remap_pfn_range(IVTBDA_SIZE, REAL_MEM_SIZE, 0,
1011 + PROT_READ | PROT_EXEC | PROT_WRITE, 1);
1012 + ret += vesafb_remap_pfn_range(0x9f000, 0x100000,
1013 + 0x9f000 >> PAGE_SHIFT,
1014 + PROT_READ | PROT_EXEC | PROT_WRITE, 0);
1016 + printk(KERN_ERR "vesafb thread: memory remapping failed\n");
1021 +#define vesafb_get_string(str) \
1023 + /* The address is in the form ssssoooo, where oooo = offset, \
1024 + * ssss = segment */ \
1025 + addr = ((p_vbe(tsk->buf)->str & 0xffff0000) >> 12) + \
1026 + (p_vbe(tsk->buf)->str & 0x0000ffff); \
1028 + /* The data is in ROM which is shared between processes, so we \
1029 + * just translate the real mode address into one visible from \
1030 + * kernel space */ \
1031 + if (addr >= 0xa0000) { \
1032 + p_vbe(tsk->buf)->str = (u32) __va(addr); \
1034 + /* The data is in the buffer, we just have to convert the \
1035 + * address so that it points into the buffer user provided. */ \
1036 + } else if (addr > BUF_ADDR && addr < BUF_ADDR + \
1037 + sizeof(struct vesafb_vbe_ib)) { \
1038 + addr -= BUF_ADDR; \
1039 + p_vbe(tsk->buf)->str = (u32) (tsk->buf + addr); \
1041 + /* This should never happen: someone was insane enough to put \
1042 + * the data somewhere in RAM.. */ \
1044 + p_vbe(tsk->buf)->str = (u32) ""; \
1048 +void vesafb_handle_getvbeib(struct vesafb_task *tsk)
1052 + tsk->regs.es = (BUF_ADDR >> 4);
1053 + tsk->regs.edi = (BUF_ADDR & 0x000f);
1054 + strncpy(p_vbe(BUF_ADDR)->vbe_signature, "VBE2", 4);
1056 + vesafb_do_vm86(&tsk->regs);
1057 + memcpy(tsk->buf, (void*)(BUF_ADDR), sizeof(struct vesafb_vbe_ib));
1059 + /* The OEM fields were not defined prior to VBE 2.0 */
1060 + if (p_vbe(tsk->buf)->vbe_version >= 0x200) {
1061 + vesafb_get_string(oem_string_ptr);
1062 + vesafb_get_string(oem_vendor_name_ptr);
1063 + vesafb_get_string(oem_product_name_ptr);
1064 + vesafb_get_string(oem_product_rev_ptr);
1067 + /* This is basically the same as vesafb_get_string() */
1068 + addr = ((p_vbe(tsk->buf)->mode_list_ptr & 0xffff0000) >> 12) +
1069 + (p_vbe(tsk->buf)->mode_list_ptr & 0x0000ffff);
1071 + if (addr >= 0xa0000) {
1072 + p_vbe(tsk->buf)->mode_list_ptr = (u32) __va(addr);
1073 + } else if (addr > BUF_ADDR && addr < BUF_ADDR +
1074 + sizeof(struct vesafb_vbe_ib)) {
1076 + p_vbe(tsk->buf)->mode_list_ptr = (u32) (tsk->buf + addr);
1079 + printk(KERN_WARNING "vesafb: warning, copying modelist "
1080 + "from somewhere in RAM!\n");
1081 + while (*(u16*)(addr+res) != 0xffff &&
1082 + res < (sizeof(p_vbe(tsk->buf)->reserved) - 2)) {
1083 + *(u16*) ((u32)&(p_vbe(tsk->buf)->reserved) + res) =
1084 + *(u16*)(addr+res);
1087 + *(u16*) ((u32)&(p_vbe(tsk->buf)->reserved) + res) = 0xffff;
1091 +int vesafb_handle_tasks(void)
1093 + struct vesafb_task *tsk;
1094 + struct list_head *curr, *next;
1097 + down(&vesafb_task_list_sem);
1098 + list_for_each_safe(curr, next, &vesafb_task_list) {
1099 + tsk = list_entry(curr, struct vesafb_task, node);
1101 + if (tsk->flags & TF_EXIT) {
1105 + if (tsk->flags & TF_GETVBEIB) {
1106 + vesafb_handle_getvbeib(tsk);
1109 + if (tsk->flags & TF_MASK_BUF) {
1110 + tsk->regs.es = (BUF_ADDR >> 4);
1111 + tsk->regs.edi = (BUF_ADDR & 0x000f);
1113 + if (tsk->flags & TF_USE_BUF)
1114 + memcpy((void*)BUF_ADDR, tsk->buf, tsk->buf_len);
1116 + vesafb_do_vm86(&tsk->regs);
1118 + if (tsk->flags & TF_RETURN_BUF)
1119 + memcpy(tsk->buf, (void*)BUF_ADDR, tsk->buf_len);
1121 +task_done: list_del(curr);
1122 + complete(&tsk->done);
1125 + /* If we're going to kill this thread, don't allow any elements
1126 + * to be added to the task list. */
1128 + up(&vesafb_task_list_sem);
1134 + * This 'hybrid' thread serves as a backend for vesafb-tng, handling all vm86
1135 + * calls. It is started as a kernel thread. It then creates its own mm struct,
1136 + * thus separating itself from any userspace processes. At this moment, it
1137 + * stops being a kernel thread (kernel threads have mm = NULL) and becomes
1138 + * a 'hybrid' thread -- one that has full access to kernel space, yet runs
1139 + * with its own address space.
1141 + * This is necessary because in order to make vm86 calls some parts of the
1142 + * first 1MB of RAM have to be setup to mimic the real mode. These are:
1143 + * - interrupt vector table [0x00000-0x003ff]
1144 + * - BIOS data area [0x00400-0x004ff]
1145 + * - Extended BIOS data area [0x9fc00-0x9ffff]
1146 + * - the video RAM [0xa0000-0xbffff]
1147 + * - video BIOS [0xc0000-0xcffff]
1148 + * - motherboard BIOS [0xf0000-0xfffff]
1150 +int vesafb_thread(void *unused)
1154 + set_fs(KERNEL_DS);
1155 + daemonize("vesafb");
1157 + if (set_new_mm()) {
1161 + if (vesafb_init_mem()) {
1166 + DPRINTK("started vesafb thread\n");
1168 + /* Having an IO bitmap makes things faster as we avoid GPFs
1169 + * when running vm86 code. We can live if it fails, though,
1170 + * so don't bother checking for errors. */
1172 + set_user_nice(current, -10);
1174 + complete(&vesafb_th_completion);
1177 + if (vesafb_handle_tasks())
1179 + wait_event_interruptible(vesafb_wait,
1180 + !list_empty(&vesafb_task_list));
1184 +out: DPRINTK("exiting the vesafb thread\n");
1187 + /* Now that all callers know this thread is no longer running
1188 + * (pid < 0), allow them to continue. */
1189 + up(&vesafb_task_list_sem);
1192 + down(&vesafb_task_list_sem);
1193 + complete(&vesafb_th_completion);
1197 +int vesafb_queue_task(struct vesafb_task *tsk)
1199 + down(&vesafb_task_list_sem);
1200 + if (vesafb_pid < 0)
1202 + list_add_tail(&tsk->node, &vesafb_task_list);
1203 + up(&vesafb_task_list_sem);
1204 + wake_up(&vesafb_wait);
1208 +int vesafb_wait_for_thread(void)
1210 + /* PID 0 means that the thread is still initializing. */
1211 + if (vesafb_pid < 0)
1213 + wait_for_completion(&vesafb_th_completion);
1217 +int __init vesafb_init_thread(void)
1219 + vesafb_pid = kernel_thread(vesafb_thread,NULL,0);
1224 +void __exit vesafb_kill_thread(void)
1226 + struct vesafb_task *tsk;
1227 + if (vesafb_pid <= 0)
1230 + vesafb_create_task(tsk);
1233 + tsk->flags |= TF_EXIT;
1234 + vesafb_queue_task(tsk);
1235 + vesafb_wait_for_task(tsk);
1239 +module_exit(vesafb_kill_thread);
1241 +module_init(vesafb_init_thread);
1243 +EXPORT_SYMBOL_GPL(vesafb_queue_task);
1244 +EXPORT_SYMBOL_GPL(vesafb_wait_for_thread);
1246 +MODULE_LICENSE("GPL");
1247 +MODULE_AUTHOR("Michal Januszewski");
1249 diff --git a/drivers/video/vesafb-tng.c b/drivers/video/vesafb-tng.c
1250 new file mode 100644
1251 index 0000000..e8cf57d
1253 +++ b/drivers/video/vesafb-tng.c
1256 + * Framebuffer driver for VBE 2.0+ compliant graphic boards
1258 + * (c) 2004-2005 Michal Januszewski <spock@gentoo.org
1259 + * Based upon vesafb code by Gerd Knorr <kraxel@goldbach.in-berlin.de
1263 +#include <linux/module.h>
1264 +#include <linux/kernel.h>
1265 +#include <linux/errno.h>
1266 +#include <linux/string.h>
1267 +#include <linux/mm.h>
1268 +#include <linux/tty.h>
1269 +#include <linux/delay.h>
1270 +#include <linux/fb.h>
1271 +#include <linux/ioport.h>
1272 +#include <linux/init.h>
1273 +#include <linux/proc_fs.h>
1274 +#include <linux/completion.h>
1275 +#include <linux/platform_device.h>
1276 +#include <video/edid.h>
1277 +#include <video/vesa.h>
1278 +#include <video/vga.h>
1279 +#include <asm/io.h>
1280 +#include <asm/mtrr.h>
1281 +#include <asm/page.h>
1282 +#include <asm/pgtable.h>
1285 +#define dac_reg (0x3c8)
1286 +#define dac_val (0x3c9)
1288 +#define VESAFB_NEED_EXACT_RES 1
1289 +#define VESAFB_NEED_EXACT_DEPTH 2
1291 +/* --------------------------------------------------------------------- */
1293 +static struct fb_var_screeninfo vesafb_defined __initdata = {
1294 + .activate = FB_ACTIVATE_NOW,
1297 + .right_margin = 32,
1298 + .upper_margin = 16,
1299 + .lower_margin = 4,
1301 + .vmode = FB_VMODE_NONINTERLACED,
1304 +static struct fb_fix_screeninfo vesafb_fix __initdata = {
1306 + .type = FB_TYPE_PACKED_PIXELS,
1307 + .accel = FB_ACCEL_NONE,
1310 +static int mtrr = 0; /* disable mtrr by default */
1311 +static int blank = 1; /* enable blanking by default */
1312 +static int ypan = 0; /* 0 - nothing, 1 - ypan, 2 - ywrap */
1313 +static int pmi_setpal = 0; /* pmi for palette changes */
1314 +static u16 *pmi_base = NULL; /* protected mode interface location */
1315 +static void (*pmi_start)(void) = NULL;
1316 +static void (*pmi_pal)(void) = NULL;
1317 +static struct vesafb_vbe_ib vbe_ib;
1318 +static struct vesafb_mode_ib *vbe_modes;
1319 +static int vbe_modes_cnt = 0;
1320 +static struct fb_info *vesafb_info = NULL;
1321 +static int nocrtc = 0; /* ignore CRTC settings */
1322 +static int noedid __initdata = 0; /* don't try DDC transfers */
1323 +static int vram_remap __initdata = 0; /* set amount of memory to be used */
1324 +static int vram_total __initdata = 0; /* set total amount of memory */
1325 +static u16 maxclk __initdata = 0; /* maximum pixel clock */
1326 +static u16 maxvf __initdata = 0; /* maximum vertical frequency */
1327 +static u16 maxhf __initdata = 0; /* maximum horizontal frequency */
1328 +static int gtf __initdata = 0; /* forces use of the GTF */
1329 +static char *mode_option __initdata = NULL;
1330 +static u16 vbemode __initdata = 0;
1332 +/* --------------------------------------------------------------------- */
1334 +static int vesafb_find_vbe_mode(int xres, int yres, int depth,
1335 + unsigned char flags)
1337 + int i, match = -1, h = 0, d = 0x7fffffff;
1339 + for (i = 0; i < vbe_modes_cnt; i++) {
1340 + h = abs(vbe_modes[i].x_res - xres) +
1341 + abs(vbe_modes[i].y_res - yres) +
1342 + abs(depth - vbe_modes[i].depth);
1345 + if (h < d || (h == d && vbe_modes[i].depth > depth)) {
1352 + if (flags & VESAFB_NEED_EXACT_DEPTH && vbe_modes[match].depth != depth)
1354 + if (flags & VESAFB_NEED_EXACT_RES && d > 24)
1362 +static int vesafb_pan_display(struct fb_var_screeninfo *var,
1363 + struct fb_info *info)
1367 + offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
1369 + /* It turns out it's not the best idea to do panning via vm86,
1370 + * so we only allow it if we have a PMI. */
1372 + __asm__ __volatile__(
1374 + : /* no return value */
1375 + : "a" (0x4f07), /* EAX */
1376 + "b" (0), /* EBX */
1377 + "c" (offset), /* ECX */
1378 + "d" (offset >> 16), /* EDX */
1379 + "D" (&pmi_start)); /* EDI */
1384 +static int vesafb_blank(int blank, struct fb_info *info)
1386 + struct vesafb_task *tsk;
1389 + if (vbe_ib.capabilities & VBE_CAP_VGACOMPAT) {
1391 + u8 seq = 0, crtc17 = 0;
1393 + if (blank == FB_BLANK_POWERDOWN) {
1400 + err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;
1403 + vga_wseq(NULL, 0x00, 0x01);
1404 + seq |= vga_rseq(NULL, 0x01) & ~0x20;
1405 + vga_wseq(NULL, 0x00, seq);
1407 + crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
1409 + vga_wcrt(NULL, 0x17, crtc17);
1410 + vga_wseq(NULL, 0x00, 0x03);
1412 + vesafb_create_task (tsk);
1415 + tsk->regs.eax = 0x4f10;
1417 + case FB_BLANK_UNBLANK:
1418 + tsk->regs.ebx = 0x0001;
1420 + case FB_BLANK_NORMAL:
1421 + tsk->regs.ebx = 0x0101; /* standby */
1423 + case FB_BLANK_POWERDOWN:
1424 + tsk->regs.ebx = 0x0401; /* powerdown */
1429 + tsk->flags = TF_CALL;
1430 + if (!vesafb_queue_task (tsk))
1431 + vesafb_wait_for_task(tsk);
1433 + if ((tsk->regs.eax & 0xffff) == 0x004f)
1440 +static int vesafb_setpalette(struct vesafb_pal_entry *entries, int count,
1441 + int start, struct fb_info *info)
1443 + struct vesafb_task *tsk;
1444 + int i = ((struct vesafb_par*)info->par)->mode_idx;
1447 + /* We support palette modifications for 8 bpp modes only, so
1448 + * there can never be more than 256 entries. */
1449 + if (start + count > 256)
1453 + __asm__ __volatile__(
1455 + : /* no return value */
1456 + : "a" (0x4f09), /* EAX */
1457 + "b" (0), /* EBX */
1458 + "c" (count), /* ECX */
1459 + "d" (start), /* EDX */
1460 + "D" (entries), /* EDI */
1461 + "S" (&pmi_pal)); /* ESI */
1465 + /* Use VGA registers if mode is VGA-compatible. */
1466 + if (i >= 0 && i < vbe_modes_cnt &&
1467 + vbe_modes[i].mode_attr & VBE_MODE_VGACOMPAT) {
1468 + for (i = 0; i < count; i++) {
1469 + outb_p(start + i, dac_reg);
1470 + outb_p(entries[i].red, dac_val);
1471 + outb_p(entries[i].green, dac_val);
1472 + outb_p(entries[i].blue, dac_val);
1475 + vesafb_create_task (tsk);
1478 + tsk->regs.eax = 0x4f09;
1479 + tsk->regs.ebx = 0x0;
1480 + tsk->regs.ecx = count;
1481 + tsk->regs.edx = start;
1482 + tsk->buf = entries;
1483 + tsk->buf_len = sizeof(struct vesafb_pal_entry) * count;
1484 + tsk->flags = TF_CALL | TF_USE_BUF;
1486 + if (!vesafb_queue_task (tsk))
1487 + vesafb_wait_for_task(tsk);
1488 + if ((tsk->regs.eax & 0xffff) != 0x004f)
1495 +static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
1496 + unsigned blue, unsigned transp,
1497 + struct fb_info *info)
1499 + struct vesafb_pal_entry entry;
1500 + int shift = 16 - info->var.green.length;
1503 + if (regno >= info->cmap.len)
1506 + if (info->var.bits_per_pixel == 8) {
1507 + entry.red = red >> shift;
1508 + entry.green = green >> shift;
1509 + entry.blue = blue >> shift;
1512 + ret = vesafb_setpalette(&entry, 1, regno, info);
1513 + } else if (regno < 16) {
1514 + switch (info->var.bits_per_pixel) {
1516 + if (info->var.red.offset == 10) {
1518 + ((u32*) (info->pseudo_palette))[regno] =
1519 + ((red & 0xf800) >> 1) |
1520 + ((green & 0xf800) >> 6) |
1521 + ((blue & 0xf800) >> 11);
1524 + ((u32*) (info->pseudo_palette))[regno] =
1525 + ((red & 0xf800) ) |
1526 + ((green & 0xfc00) >> 5) |
1527 + ((blue & 0xf800) >> 11);
1536 + ((u32 *)(info->pseudo_palette))[regno] =
1537 + (red << info->var.red.offset) |
1538 + (green << info->var.green.offset) |
1539 + (blue << info->var.blue.offset);
1546 +static int vesafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1548 + struct vesafb_pal_entry *entries;
1549 + int shift = 16 - info->var.green.length;
1552 + if (info->var.bits_per_pixel == 8) {
1553 + if (cmap->start + cmap->len > info->cmap.start +
1554 + info->cmap.len || cmap->start < info->cmap.start)
1557 + entries = vmalloc(sizeof(struct vesafb_pal_entry) * cmap->len);
1560 + for (i = 0; i < cmap->len; i++) {
1561 + entries[i].red = cmap->red[i] >> shift;
1562 + entries[i].green = cmap->green[i] >> shift;
1563 + entries[i].blue = cmap->blue[i] >> shift;
1564 + entries[i].pad = 0;
1566 + ret = vesafb_setpalette(entries, cmap->len, cmap->start, info);
1569 + /* For modes with bpp > 8, we only set the pseudo palette in
1570 + * the fb_info struct. We rely on vesafb_setcolreg to do all
1571 + * sanity checking. */
1572 + for (i = 0; i < cmap->len; i++) {
1573 + ret += vesafb_setcolreg(cmap->start + i, cmap->red[i],
1574 + cmap->green[i], cmap->blue[i],
1581 +static int vesafb_set_par(struct fb_info *info)
1583 + struct vesafb_par *par = (struct vesafb_par *) info->par;
1584 + struct vesafb_task *tsk;
1585 + struct vesafb_crtc_ib *crtc = NULL;
1586 + struct vesafb_mode_ib *mode = NULL;
1587 + int i, err = 0, depth = info->var.bits_per_pixel;
1589 + if (depth > 8 && depth != 32)
1590 + depth = info->var.red.length + info->var.green.length +
1591 + info->var.blue.length;
1593 + i = vesafb_find_vbe_mode(info->var.xres, info->var.yres, depth,
1594 + VESAFB_NEED_EXACT_RES |
1595 + VESAFB_NEED_EXACT_DEPTH);
1597 + mode = &vbe_modes[i];
1601 + vesafb_create_task (tsk);
1604 + tsk->regs.eax = 0x4f02;
1605 + tsk->regs.ebx = mode->mode_id | 0x4000; /* use LFB */
1606 + tsk->flags = TF_CALL;
1608 + if (vbe_ib.vbe_version >= 0x0300 && !nocrtc &&
1609 + info->var.pixclock != 0) {
1610 + tsk->regs.ebx |= 0x0800; /* use CRTC data */
1611 + tsk->flags |= TF_USE_BUF;
1612 + crtc = kmalloc(sizeof(struct vesafb_crtc_ib), GFP_KERNEL);
1617 + crtc->horiz_start = info->var.xres + info->var.right_margin;
1618 + crtc->horiz_end = crtc->horiz_start + info->var.hsync_len;
1619 + crtc->horiz_total = crtc->horiz_end + info->var.left_margin;
1621 + crtc->vert_start = info->var.yres + info->var.lower_margin;
1622 + crtc->vert_end = crtc->vert_start + info->var.vsync_len;
1623 + crtc->vert_total = crtc->vert_end + info->var.upper_margin;
1625 + crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;
1626 + crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /
1627 + (crtc->vert_total * crtc->horiz_total)));
1630 + if (info->var.vmode & FB_VMODE_DOUBLE)
1631 + crtc->flags |= 0x1;
1632 + if (info->var.vmode & FB_VMODE_INTERLACED)
1633 + crtc->flags |= 0x2;
1634 + if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
1635 + crtc->flags |= 0x4;
1636 + if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
1637 + crtc->flags |= 0x8;
1638 + memcpy(&par->crtc, crtc, sizeof(struct vesafb_crtc_ib));
1640 + memset(&par->crtc, 0, sizeof(struct vesafb_crtc_ib));
1642 + tsk->buf = (void*)crtc;
1643 + tsk->buf_len = sizeof(struct vesafb_crtc_ib);
1645 + if (vesafb_queue_task (tsk)) {
1649 + vesafb_wait_for_task(tsk);
1651 + if ((tsk->regs.eax & 0xffff) != 0x004f) {
1652 + printk(KERN_ERR "vesafb: mode switch failed (eax: 0x%lx)\n",
1657 + par->mode_idx = i;
1659 + /* For 8bpp modes, always try to set the DAC to 8 bits. */
1660 + if (vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&
1661 + mode->bits_per_pixel <= 8) {
1662 + vesafb_reset_task(tsk);
1663 + tsk->flags = TF_CALL;
1664 + tsk->regs.eax = 0x4f08;
1665 + tsk->regs.ebx = 0x0800;
1667 + if (!vesafb_queue_task (tsk))
1668 + vesafb_wait_for_task(tsk);
1670 + if ((tsk->regs.eax & 0xffff) != 0x004f ||
1671 + ((tsk->regs.ebx & 0xff00) >> 8) != 8) {
1672 + /* We've failed to set the DAC palette format -
1673 + * time to correct var. */
1674 + info->var.red.length = 6;
1675 + info->var.green.length = 6;
1676 + info->var.blue.length = 6;
1680 + info->fix.visual = (info->var.bits_per_pixel == 8) ?
1681 + FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1682 + info->fix.line_length = mode->bytes_per_scan_line;
1684 + DPRINTK("set new mode %dx%d-%d (0x%x)\n",
1685 + info->var.xres, info->var.yres, info->var.bits_per_pixel,
1688 +out: if (crtc != NULL)
1695 +static void vesafb_setup_var(struct fb_var_screeninfo *var, struct fb_info *info,
1696 + struct vesafb_mode_ib *mode)
1698 + var->xres = mode->x_res;
1699 + var->yres = mode->y_res;
1700 + var->xres_virtual = mode->x_res;
1701 + var->yres_virtual = (ypan) ?
1702 + info->fix.smem_len / mode->bytes_per_scan_line :
1706 + var->bits_per_pixel = mode->bits_per_pixel;
1708 + if (var->bits_per_pixel == 15)
1709 + var->bits_per_pixel = 16;
1711 + if (var->bits_per_pixel > 8) {
1712 + var->red.offset = mode->red_off;
1713 + var->red.length = mode->red_len;
1714 + var->green.offset = mode->green_off;
1715 + var->green.length = mode->green_len;
1716 + var->blue.offset = mode->blue_off;
1717 + var->blue.length = mode->blue_len;
1718 + var->transp.offset = mode->rsvd_off;
1719 + var->transp.length = mode->rsvd_len;
1721 + DPRINTK("directcolor: size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
1731 + var->red.offset = 0;
1732 + var->green.offset = 0;
1733 + var->blue.offset = 0;
1734 + var->transp.offset = 0;
1736 + /* We're assuming that we can switch the DAC to 8 bits. If
1737 + * this proves to be incorrect, we'll update the fields
1738 + * later in set_par(). */
1739 + if (vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC) {
1740 + var->red.length = 8;
1741 + var->green.length = 8;
1742 + var->blue.length = 8;
1743 + var->transp.length = 0;
1745 + var->red.length = 6;
1746 + var->green.length = 6;
1747 + var->blue.length = 6;
1748 + var->transp.length = 0;
1753 +static void inline vesafb_check_limits(struct fb_var_screeninfo *var,
1754 + struct fb_info *info)
1756 + struct fb_videomode *mode;
1758 + if (!var->pixclock)
1760 + if (vbe_ib.vbe_version < 0x0300) {
1761 + fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);
1764 + if (!fb_validate_mode(var, info))
1766 + mode = fb_find_best_mode(var, &info->modelist);
1768 + DPRINTK("find_best_mode: %d %d @ %d (vmode: %d)\n",
1769 + mode->xres, mode->yres, mode->refresh, mode->vmode);
1770 + if (mode->xres == var->xres && mode->yres == var->yres &&
1771 + !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {
1772 + fb_videomode_to_var(var, mode);
1776 + if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1778 + /* Use default refresh rate */
1779 + var->pixclock = 0;
1782 +static int vesafb_check_var(struct fb_var_screeninfo *var,
1783 + struct fb_info *info)
1786 + int depth = var->red.length + var->green.length + var->blue.length;
1788 + /* Various apps will use bits_per_pixel to set the color depth,
1789 + * which is theoretically incorrect, but which we'll try to handle
1791 + if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)
1792 + depth = var->bits_per_pixel;
1793 + match = vesafb_find_vbe_mode(var->xres, var->yres, depth,
1794 + VESAFB_NEED_EXACT_RES);
1796 + if (match == -1) {
1797 + DPRINTK("vesafb: mode %dx%d-%d not found\n", var->xres,
1798 + var->yres, depth);
1802 + vesafb_setup_var(var, info, &vbe_modes[match]);
1803 + DPRINTK("found mode 0x%x (%dx%d-%dbpp)\n",
1804 + vbe_modes[match].mode_id, vbe_modes[match].x_res,
1805 + vbe_modes[match].y_res, vbe_modes[match].depth);
1807 + /* Check whether we have remapped enough memory for this mode. */
1808 + if (var->yres * vbe_modes[match].bytes_per_scan_line >
1809 + info->fix.smem_len) {
1813 + if ((var->vmode & FB_VMODE_DOUBLE) &&
1814 + !(vbe_modes[match].mode_attr & 0x100))
1815 + var->vmode &= ~FB_VMODE_DOUBLE;
1816 + if ((var->vmode & FB_VMODE_INTERLACED) &&
1817 + !(vbe_modes[match].mode_attr & 0x200))
1818 + var->vmode &= ~FB_VMODE_INTERLACED;
1819 + vesafb_check_limits(var, info);
1823 +static void vesafb_platform_release(struct device *device)
1828 +static int __init vesafb_probe(struct platform_device *device);
1830 +static struct fb_ops vesafb_ops = {
1831 + .owner = THIS_MODULE,
1832 + .fb_setcolreg = vesafb_setcolreg,
1833 + .fb_setcmap = vesafb_setcmap,
1834 + .fb_pan_display = vesafb_pan_display,
1835 + .fb_blank = vesafb_blank,
1836 + .fb_fillrect = cfb_fillrect,
1837 + .fb_copyarea = cfb_copyarea,
1838 + .fb_imageblit = cfb_imageblit,
1839 + .fb_check_var = vesafb_check_var,
1840 + .fb_set_par = vesafb_set_par
1843 +static struct platform_driver vesafb_driver = {
1844 + .probe = vesafb_probe,
1850 +static struct platform_device vesafb_device = {
1853 + .release = vesafb_platform_release,
1858 +int __init vesafb_setup(char *options)
1862 + if (!options || !*options)
1865 + DPRINTK("options %s\n",options);
1867 + while ((this_opt = strsep(&options, ",")) != NULL) {
1868 + if (!*this_opt) continue;
1870 + DPRINTK("this_opt: %s\n",this_opt);
1872 + if (! strcmp(this_opt, "redraw"))
1874 + else if (! strcmp(this_opt, "ypan"))
1876 + else if (! strcmp(this_opt, "ywrap"))
1878 + else if (! strcmp(this_opt, "vgapal"))
1880 + else if (! strcmp(this_opt, "pmipal"))
1882 + else if (! strncmp(this_opt, "mtrr:", 5))
1883 + mtrr = simple_strtoul(this_opt+5, NULL, 0);
1884 + else if (! strcmp(this_opt, "nomtrr"))
1886 + else if (! strcmp(this_opt, "nocrtc"))
1888 + else if (! strcmp(this_opt, "noedid"))
1890 + else if (! strcmp(this_opt, "noblank"))
1892 + else if (! strcmp(this_opt, "gtf"))
1894 + else if (! strncmp(this_opt, "vtotal:", 7))
1895 + vram_total = simple_strtoul(this_opt + 7, NULL, 0);
1896 + else if (! strncmp(this_opt, "vremap:", 7))
1897 + vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
1898 + else if (! strncmp(this_opt, "maxhf:", 6))
1899 + maxhf = simple_strtoul(this_opt + 6, NULL, 0);
1900 + else if (! strncmp(this_opt, "maxvf:", 6))
1901 + maxvf = simple_strtoul(this_opt + 6, NULL, 0);
1902 + else if (! strncmp(this_opt, "maxclk:", 7))
1903 + maxclk = simple_strtoul(this_opt + 7, NULL, 0);
1904 + else if (! strncmp(this_opt, "vbemode:", 8))
1905 + vbemode = simple_strtoul(this_opt + 8, NULL,0);
1906 + else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
1907 + DPRINTK("mode_option: %s\n",this_opt);
1908 + mode_option = this_opt;
1910 + printk(KERN_WARNING
1911 + "vesafb: unrecognized option %s\n", this_opt);
1917 +#endif /* !MODULE */
1919 +static int vesafb_read_proc_modes(char *buf, char **start, off_t offset,
1920 + int len, int *eof, void *private)
1924 + for (i = 0; i < vbe_modes_cnt; i++) {
1925 + clen += sprintf(buf + clen, "%dx%d-%d\n", vbe_modes[i].x_res,
1926 + vbe_modes[i].y_res, vbe_modes[i].depth);
1928 + *start = buf + offset;
1930 + if (clen > offset) {
1938 +static int vesafb_read_proc_vbe_info(char *buf, char **start, off_t offset,
1939 + int len, int *eof, void *private)
1943 + clen += sprintf(buf + clen, "Version: %d.%d\n",
1944 + ((vbe_ib.vbe_version & 0xff00) >> 8),
1945 + vbe_ib.vbe_version & 0xff);
1946 + clen += sprintf(buf + clen, "Vendor: %s\n",
1947 + (char*)vbe_ib.oem_vendor_name_ptr);
1948 + clen += sprintf(buf + clen, "Product: %s\n",
1949 + (char*)vbe_ib.oem_product_name_ptr);
1950 + clen += sprintf(buf + clen, "OEM rev: %s\n",
1951 + (char*)vbe_ib.oem_product_rev_ptr);
1952 + clen += sprintf(buf + clen, "OEM string: %s\n",
1953 + (char*)vbe_ib.oem_string_ptr);
1955 + *start = buf + offset;
1957 + if (clen > offset) {
1965 +static int __init inline vesafb_vbe_getinfo(struct vesafb_task *tsk)
1967 + tsk->regs.eax = 0x4f00;
1968 + tsk->flags = TF_CALL | TF_GETVBEIB;
1969 + tsk->buf = &vbe_ib;
1970 + tsk->buf_len = sizeof(vbe_ib);
1971 + if (vesafb_queue_task (tsk))
1973 + vesafb_wait_for_task(tsk);
1975 + if (vbe_ib.vbe_version < 0x0200) {
1976 + printk(KERN_ERR "vesafb: Sorry, pre-VBE 2.0 cards are "
1977 + "not supported.\n");
1981 + if ((tsk->regs.eax & 0xffff) != 0x004f) {
1982 + printk(KERN_ERR "vesafb: Getting mode info block failed "
1983 + "(eax=0x%x)\n", (u32)tsk->regs.eax);
1987 + printk(KERN_INFO "vesafb: %s, %s, %s (OEM: %s)\n",
1988 + (char*)vbe_ib.oem_vendor_name_ptr,
1989 + (char*)vbe_ib.oem_product_name_ptr,
1990 + (char*)vbe_ib.oem_product_rev_ptr,
1991 + (char*)vbe_ib.oem_string_ptr);
1993 + printk(KERN_INFO "vesafb: VBE version: %d.%d\n",
1994 + ((vbe_ib.vbe_version & 0xff00) >> 8),
1995 + vbe_ib.vbe_version & 0xff);
1999 +static int __init inline vesafb_vbe_getmodes(struct vesafb_task *tsk)
2004 + /* Count available modes. */
2005 + mode = (u16*)vbe_ib.mode_list_ptr;
2006 + while (*mode != 0xffff) {
2011 + vbe_modes = kmalloc(sizeof(struct vesafb_mode_ib)*
2012 + vbe_modes_cnt, GFP_KERNEL);
2016 + /* Get mode info for all available modes. */
2017 + mode = (u16*)vbe_ib.mode_list_ptr;
2019 + while (*mode != 0xffff) {
2020 + struct vesafb_mode_ib *mib;
2022 + vesafb_reset_task(tsk);
2023 + tsk->regs.eax = 0x4f01;
2024 + tsk->regs.ecx = (u32) *mode;
2025 + tsk->flags = TF_CALL | TF_RETURN_BUF;
2026 + tsk->buf = vbe_modes+off;
2027 + tsk->buf_len = sizeof(struct vesafb_mode_ib);
2028 + if (vesafb_queue_task(tsk))
2030 + vesafb_wait_for_task(tsk);
2031 + mib = p_mode(tsk->buf);
2032 + mib->mode_id = *mode;
2034 + /* We only want modes that are supported with the currennt
2035 + * hardware configuration (D0), color (D3), graphics (D4)
2036 + * and that have support for the LFB (D7). */
2037 + if ((mib->mode_attr & 0x99) == 0x99 &&
2038 + mib->bits_per_pixel >= 8) {
2044 + mib->depth = mib->red_len + mib->green_len + mib->blue_len;
2045 + /* Handle 8bpp modes and modes with broken color component
2047 + if (mib->depth == 0 ||
2048 + (mib->depth == 24 && mib->bits_per_pixel == 32))
2049 + mib->depth = mib->bits_per_pixel;
2055 +static int __init inline vesafb_vbe_getpmi(struct vesafb_task *tsk)
2059 + vesafb_reset_task(tsk);
2060 + tsk->regs.eax = 0x4f0a;
2061 + tsk->regs.ebx = 0x0;
2062 + tsk->flags = TF_CALL;
2063 + if (vesafb_queue_task(tsk))
2065 + vesafb_wait_for_task(tsk);
2067 + if ((tsk->regs.eax & 0xffff) != 0x004f || tsk->regs.es < 0xc000) {
2068 + pmi_setpal = ypan = 0;
2070 + pmi_base = (u16*)phys_to_virt(((u32)tsk->regs.es << 4) +
2072 + pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
2073 + pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
2074 + printk(KERN_INFO "vesafb: protected mode interface info at "
2076 + (u16)tsk->regs.es, (u16)tsk->regs.edi);
2077 + printk(KERN_INFO "vesafb: pmi: set display start = %p, "
2078 + "set palette = %p\n", pmi_start, pmi_pal);
2080 + if (pmi_base[3]) {
2081 + printk(KERN_INFO "vesafb: pmi: ports = ");
2082 + for (i = pmi_base[3]/2; pmi_base[i] != 0xffff; i++)
2083 + printk("%x ",pmi_base[i]);
2087 + * memory areas not supported (yet?)
2089 + * Rules are: we have to set up a descriptor for the
2090 + * requested memory area and pass it in the ES register
2091 + * to the BIOS function.
2093 + if (pmi_base[i] != 0xffff) {
2094 + printk(KERN_INFO "vesafb: can't handle memory "
2095 + "requests, pmi disabled\n");
2096 + ypan = pmi_setpal = 0;
2103 +static int __init inline vesafb_vbe_getedid(struct vesafb_task *tsk,
2104 + struct fb_info *info)
2108 + if (noedid || vbe_ib.vbe_version < 0x0300)
2111 + vesafb_reset_task(tsk);
2112 + tsk->regs.eax = 0x4f15;
2113 + tsk->regs.ebx = 0;
2114 + tsk->regs.ecx = 0;
2115 + if (vesafb_queue_task(tsk))
2117 + vesafb_wait_for_task(tsk);
2119 + if ((tsk->regs.eax & 0xffff) != 0x004f)
2122 + if ((tsk->regs.ebx & 0x3) == 3) {
2123 + printk(KERN_INFO "vesafb: VBIOS/hardware supports both "
2124 + "DDC1 and DDC2 transfers\n");
2125 + } else if ((tsk->regs.ebx & 0x3) == 2) {
2126 + printk(KERN_INFO "vesafb: VBIOS/hardware supports DDC2 "
2128 + } else if ((tsk->regs.ebx & 0x3) == 1) {
2129 + printk(KERN_INFO "vesafb: VBIOS/hardware supports DDC1 "
2132 + printk(KERN_INFO "vesafb: VBIOS/hardware doesn't support "
2133 + "DDC transfers\n");
2137 + vesafb_reset_task(tsk);
2138 + tsk->regs.eax = 0x4f15;
2139 + tsk->regs.ebx = 1;
2140 + tsk->regs.ecx = tsk->regs.edx = 0;
2141 + tsk->flags = TF_CALL | TF_RETURN_BUF;
2142 + tsk->buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
2143 + tsk->buf_len = EDID_LENGTH;
2145 + if (vesafb_queue_task(tsk)) {
2149 + vesafb_wait_for_task(tsk);
2151 + if ((tsk->regs.eax & 0xffff) == 0x004f) {
2152 + fb_edid_to_monspecs(tsk->buf, &info->monspecs);
2153 + fb_videomode_to_modelist(info->monspecs.modedb,
2154 + info->monspecs.modedb_len, &info->modelist);
2155 + if (info->monspecs.vfmax && info->monspecs.hfmax) {
2156 + /* If the maximum pixel clock wasn't specified in
2157 + * the EDID block, set it to 300 MHz. */
2158 + if (info->monspecs.dclkmax == 0)
2159 + info->monspecs.dclkmax = 300 * 1000000;
2160 + info->monspecs.gtf = 1;
2166 +out: kfree(tsk->buf);
2170 +static void __init inline vesafb_vbe_getmonspecs(struct vesafb_task *tsk,
2171 + struct fb_info *info)
2173 + struct fb_var_screeninfo var;
2175 + memset(&info->monspecs, 0, sizeof(struct fb_monspecs));
2177 + /* If we didn't get all necessary data from the EDID block,
2178 + * mark it as incompatible with the GTF. */
2179 + if (vesafb_vbe_getedid(tsk, info))
2180 + info->monspecs.gtf = 0;
2182 + /* Kernel command line overrides. */
2184 + info->monspecs.dclkmax = maxclk * 1000000;
2186 + info->monspecs.vfmax = maxvf;
2188 + info->monspecs.hfmax = maxhf * 1000;
2190 + /* In case DDC transfers are not supported the user can provide
2191 + * monitor limits manually. Lower limits are set to "safe" values. */
2192 + if (info->monspecs.gtf == 0 && maxclk && maxvf && maxhf) {
2193 + info->monspecs.dclkmin = 0;
2194 + info->monspecs.vfmin = 60;
2195 + info->monspecs.hfmin = 29000;
2196 + info->monspecs.gtf = 1;
2199 + if (info->monspecs.gtf) {
2201 + "vesafb: monitor limits: vf = %d Hz, hf = %d kHz, "
2202 + "clk = %d MHz\n", info->monspecs.vfmax,
2203 + (int)(info->monspecs.hfmax / 1000),
2204 + (int)(info->monspecs.dclkmax / 1000000));
2205 + /* Add valid VESA video modes to our modelist. */
2206 + for (i = 0; i < VESA_MODEDB_SIZE; i++) {
2207 + fb_videomode_to_var(&var, (struct fb_videomode *)
2209 + if (!fb_validate_mode(&var, info))
2210 + fb_add_videomode((struct fb_videomode *)
2215 + /* Add all VESA video modes to our modelist. */
2216 + fb_videomode_to_modelist((struct fb_videomode *)vesa_modes,
2217 + VESA_MODEDB_SIZE, &info->modelist);
2218 + printk(KERN_INFO "vesafb: no monitor limits have been set\n");
2223 +static int __init inline vesafb_vbe_init(struct fb_info *info)
2225 + struct vesafb_task *tsk;
2228 + vesafb_create_task(tsk);
2231 + if ((res = vesafb_vbe_getinfo(tsk)) != 0)
2233 + if ((res = vesafb_vbe_getmodes(tsk)) != 0)
2235 + if (pmi_setpal || ypan)
2236 + vesafb_vbe_getpmi(tsk);
2237 + vesafb_vbe_getmonspecs(tsk, info);
2242 +static int __init decode_mode(u32 *xres, u32 *yres, u32 *bpp, u32 *refresh)
2244 + int len = strlen(mode_option), i, err = 0;
2245 + u8 res_specified = 0, bpp_specified = 0, refresh_specified = 0,
2246 + yres_specified = 0;
2248 + for (i = len-1; i >= 0; i--) {
2249 + switch (mode_option[i]) {
2252 + if (!refresh_specified && !bpp_specified &&
2253 + !yres_specified) {
2254 + *refresh = simple_strtoul(&mode_option[i+1],
2256 + refresh_specified = 1;
2262 + if (!bpp_specified && !yres_specified) {
2263 + *bpp = simple_strtoul(&mode_option[i+1],
2265 + bpp_specified = 1;
2270 + if (!yres_specified) {
2271 + *yres = simple_strtoul(&mode_option[i+1],
2273 + yres_specified = 1;
2284 + if (i < 0 && yres_specified) {
2285 + *xres = simple_strtoul(mode_option, NULL, 0);
2286 + res_specified = 1;
2289 +out: if (!res_specified || !yres_specified) {
2290 + printk(KERN_ERR "vesafb: invalid resolution, "
2291 + "%s not specified\n",
2292 + (!res_specified) ? "width" : "height");
2299 +static int __init vesafb_init_set_mode(struct fb_info *info)
2301 + struct fb_videomode *fbmode;
2302 + struct fb_videomode mode;
2303 + int i, modeid, refresh = 0;
2304 + u8 refresh_specified = 0;
2307 + mode_option = CONFIG_FB_VESA_DEFAULT_MODE;
2309 + if (vbemode > 0) {
2310 + for (i = 0; i < vbe_modes_cnt; i++) {
2311 + if (vbe_modes[i].mode_id == vbemode) {
2312 + info->var.vmode = FB_VMODE_NONINTERLACED;
2313 + info->var.sync = FB_SYNC_VERT_HIGH_ACT;
2314 + vesafb_setup_var(&info->var, info,
2316 + fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON,
2317 + 60, &info->var, info);
2318 + /* With pixclock set to 0, the default BIOS
2319 + * timings will be used in set_par(). */
2320 + info->var.pixclock = 0;
2325 + printk(KERN_INFO "specified VBE mode %d not found\n",
2330 + /* Decode the mode specified on the kernel command line. We save
2331 + * the depth into bits_per_pixel, which is wrong, but will work
2333 + if (decode_mode(&info->var.xres, &info->var.yres,
2334 + &info->var.bits_per_pixel, &refresh))
2337 + refresh_specified = 1;
2341 + /* Look for a matching VBE mode. We can live if an exact match
2342 + * cannot be found. */
2343 + modeid = vesafb_find_vbe_mode(info->var.xres, info->var.yres,
2344 + info->var.bits_per_pixel, 0);
2346 + if (modeid == -1) {
2349 + info->var.vmode = FB_VMODE_NONINTERLACED;
2350 + info->var.sync = FB_SYNC_VERT_HIGH_ACT;
2351 + vesafb_setup_var(&info->var, info, &vbe_modes[modeid]);
2353 + if (vbe_ib.vbe_version < 0x0300) {
2354 + fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
2355 + &info->var, info);
2359 + struct fb_videomode tmode;
2361 + if (refresh_specified) {
2362 + fb_var_to_videomode(&tmode, &info->var);
2363 + tmode.refresh = refresh;
2364 + fbmode = fb_find_nearest_mode(&tmode,
2367 + fbmode = fb_find_best_mode(&info->var,
2370 + if (fbmode->xres == info->var.xres &&
2371 + fbmode->yres == info->var.yres &&
2372 + !(fbmode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))
2373 + && (!refresh_specified ||
2374 + abs(refresh - fbmode->refresh) <= 5)) {
2375 + fb_videomode_to_var(&info->var, fbmode);
2379 + i = FB_MAXTIMINGS;
2380 + if (!info->monspecs.gtf)
2381 + i = FB_IGNOREMON | FB_VSYNCTIMINGS;
2382 + else if (refresh_specified)
2383 + i = FB_VSYNCTIMINGS;
2384 + if (!fb_get_mode(i, refresh, &info->var, info))
2386 + if (info->monspecs.gtf &&
2387 + !fb_get_mode(FB_MAXTIMINGS, 0, &info->var, info))
2389 + /* Use default refresh rate */
2390 + printk(KERN_WARNING "vesafb: using default BIOS refresh rate\n");
2391 + info->var.pixclock = 0;
2394 + fb_var_to_videomode(&mode, &info->var);
2395 + fb_add_videomode(&mode, &info->modelist);
2399 +static int __init vesafb_probe(struct platform_device *dev)
2402 + struct fb_info *info;
2403 + struct vesafb_mode_ib *mode = NULL;
2404 + int err = 0, i, h;
2405 + unsigned int size_vmode;
2406 + unsigned int size_remap;
2407 + unsigned int size_total;
2409 + vesafb_info = info = framebuffer_alloc(sizeof(struct vesafb_par) +
2410 + sizeof(u32) * 256, &dev->dev);
2414 + if (vesafb_wait_for_thread()) {
2415 + printk(KERN_ERR "vesafb: vesafb thread not running\n");
2416 + framebuffer_release(info);
2420 + if (vesafb_vbe_init(info)) {
2421 + printk(KERN_ERR "vesafb: vbe_init failed\n");
2426 + vesafb_fix.ypanstep = ypan ? 1 : 0;
2427 + vesafb_fix.ywrapstep = (ypan>1) ? 1 : 0;
2429 + info->pseudo_palette = ((u8*)info->par + sizeof(struct vesafb_par));
2430 + info->fbops = &vesafb_ops;
2431 + info->var = vesafb_defined;
2432 + info->fix = vesafb_fix;
2434 + if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
2439 + i = vesafb_init_set_mode(info);
2444 + mode = &vbe_modes[i];
2446 + /* Disable blanking if the user requested so. */
2448 + info->fbops->fb_blank = NULL;
2451 + /* Find out how much IO memory is required for the mode with
2452 + * the highest resolution. */
2454 + for (i = 0; i < vbe_modes_cnt; i++) {
2455 + h = vbe_modes[i].bytes_per_scan_line * vbe_modes[i].y_res;
2456 + if (h > size_remap)
2461 + /* size_vmode -- that is the amount of memory needed for the
2462 + * used video mode, i.e. the minimum amount of
2463 + * memory we need. */
2464 + if (mode != NULL) {
2465 + size_vmode = info->var.yres * mode->bytes_per_scan_line;
2467 + size_vmode = info->var.yres * info->var.xres *
2468 + ((info->var.bits_per_pixel + 7) >> 3);
2471 + /* size_total -- all video memory we have. Used for mtrr
2472 + * entries, ressource allocation and bounds
2474 + size_total = vbe_ib.total_memory * 65536;
2476 + size_total = vram_total * 1024 * 1024;
2477 + if (size_total < size_vmode)
2478 + size_total = size_vmode;
2479 + ((struct vesafb_par*)(info->par))->mem_total = size_total;
2481 + /* size_remap -- the amount of video memory we are going to
2482 + * use for vesafb. With modern cards it is no
2483 + * option to simply use size_total as th
2484 + * wastes plenty of kernel address space. */
2486 + size_remap = vram_remap * 1024 * 1024;
2487 + if (size_remap < size_vmode)
2488 + size_remap = size_vmode;
2489 + if (size_remap > size_total)
2490 + size_remap = size_total;
2492 + info->fix.smem_len = size_remap;
2493 + info->fix.smem_start = mode->phys_base_ptr;
2495 + /* We have to set it here, because when setup_var() was called,
2496 + * smem_len wasn't defined yet. */
2497 + info->var.yres_virtual = info->fix.smem_len /
2498 + mode->bytes_per_scan_line;
2500 + if (ypan && info->var.yres_virtual > info->var.yres) {
2501 + printk(KERN_INFO "vesafb: scrolling: %s "
2502 + "using protected mode interface, "
2503 + "yres_virtual=%d\n",
2504 + (ypan > 1) ? "ywrap" : "ypan",info->var.yres_virtual);
2506 + printk(KERN_INFO "vesafb: scrolling: redraw\n");
2507 + info->var.yres_virtual = info->var.yres;
2511 + info->flags = FBINFO_FLAG_DEFAULT |
2512 + (ypan) ? FBINFO_HWACCEL_YPAN : 0;
2515 + info->fbops->fb_pan_display = NULL;
2517 + if (!request_mem_region(info->fix.smem_start, size_total, "vesafb")) {
2518 + printk(KERN_WARNING "vesafb: cannot reserve video memory at "
2519 + "0x%lx\n", info->fix.smem_start);
2520 + /* We cannot make this fatal. Sometimes this comes from magic
2521 + spaces our resource handlers simply don't know about. */
2524 + info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
2526 + if (!info->screen_base) {
2528 + "vesafb: abort, cannot ioremap video memory "
2530 + info->fix.smem_len, info->fix.smem_start);
2535 + /* Request failure does not faze us, as vgacon probably has this
2536 + region already (FIXME) */
2537 + request_region(0x3c0, 32, "vesafb");
2540 + if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
2541 + int temp_size = size_total;
2542 + unsigned int type = 0;
2546 + type = MTRR_TYPE_UNCACHABLE;
2549 + type = MTRR_TYPE_WRBACK;
2552 + type = MTRR_TYPE_WRCOMB;
2555 + type = MTRR_TYPE_WRTHROUGH;
2565 + /* Find the largest power-of-two */
2566 + while (temp_size & (temp_size - 1))
2567 + temp_size &= (temp_size - 1);
2569 + /* Try and find a power of two to add */
2571 + rc = mtrr_add(info->fix.smem_start,
2572 + temp_size, type, 1);
2574 + } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
2577 +#endif /* CONFIG_MTRR */
2579 + if (register_framebuffer(info) < 0) {
2581 + "vesafb: failed to register framebuffer device\n");
2586 + printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
2587 + "using %dk, total %dk\n", info->fix.smem_start,
2588 + info->screen_base, size_remap/1024, size_total/1024);
2589 + printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
2592 + sprintf(entry, "fb%d", info->node);
2593 + proc_mkdir(entry, 0);
2595 + sprintf(entry, "fb%d/modes", info->node);
2596 + create_proc_read_entry(entry, 0, 0, vesafb_read_proc_modes, NULL);
2598 + sprintf(entry, "fb%d/vbe_info", info->node);
2599 + create_proc_read_entry(entry, 0, 0, vesafb_read_proc_vbe_info, NULL);
2603 + release_mem_region(info->fix.smem_start, size_total);
2604 + if (!list_empty(&info->modelist))
2605 + fb_destroy_modelist(&info->modelist);
2606 + fb_destroy_modedb(info->monspecs.modedb);
2608 + fb_dealloc_cmap(&info->cmap);
2610 + framebuffer_release(info);
2611 + vesafb_info = NULL;
2617 +int __init vesafb_init(void)
2621 + char *option = NULL;
2623 + if (fb_get_options("vesafb", &option))
2625 + vesafb_setup(option);
2627 + ret = platform_driver_register(&vesafb_driver);
2630 + ret = platform_device_register(&vesafb_device);
2632 + platform_driver_unregister(&vesafb_driver);
2637 +module_init(vesafb_init);
2640 +void __exit vesafb_exit(void)
2645 + unregister_framebuffer(vesafb_info);
2647 + platform_device_unregister(&vesafb_device);
2648 + platform_driver_unregister(&vesafb_driver);
2650 + if (vesafb_info) {
2651 + struct vesafb_par *par = (struct vesafb_par*)vesafb_info->par;
2653 + sprintf(entry, "fb%d/modes", vesafb_info->node);
2654 + remove_proc_entry(entry, NULL);
2656 + sprintf(entry, "fb%d/vbe_info", vesafb_info->node);
2657 + remove_proc_entry(entry, NULL);
2659 + sprintf(entry, "fb%d", vesafb_info->node);
2660 + remove_proc_entry(entry, NULL);
2662 + iounmap(vesafb_info->screen_base);
2663 + release_mem_region(vesafb_info->fix.smem_start,
2665 + fb_dealloc_cmap(&vesafb_info->cmap);
2666 + if (!list_empty(&vesafb_info->modelist))
2667 + fb_destroy_modelist(&vesafb_info->modelist);
2668 + fb_destroy_modedb(vesafb_info->monspecs.modedb);
2669 + framebuffer_release(vesafb_info);
2672 + if (vbe_modes != NULL)
2676 +module_exit(vesafb_exit);
2678 +static inline int param_get_scroll(char *buffer, struct kernel_param *kp)
2682 +static inline int param_set_scroll(const char *val, struct kernel_param *kp)
2686 + if (! strcmp(val, "redraw"))
2688 + else if (! strcmp(val, "ypan"))
2690 + else if (! strcmp(val, "ywrap"))
2696 +#define param_check_scroll(name, p) __param_check(name, p, void);
2698 +module_param_named(scroll, ypan, scroll, 0);
2699 +MODULE_PARM_DESC(scroll,"Scrolling mode, set to 'redraw', 'ypan' or 'ywrap'");
2700 +module_param_named(vgapal, pmi_setpal, invbool, 0);
2701 +MODULE_PARM_DESC(vgapal,"bool: set palette using VGA registers");
2702 +module_param_named(pmipal, pmi_setpal, bool, 0);
2703 +MODULE_PARM_DESC(pmipal,"bool: set palette using PMI calls");
2704 +module_param_named(nomtrr, mtrr, invbool, 0);
2705 +MODULE_PARM_DESC(nomtrr,"bool: disable use of MTRR registers");
2706 +module_param(blank, bool, 1);
2707 +MODULE_PARM_DESC(blank,"bool: enable hardware blanking");
2708 +module_param(nocrtc, bool, 0);
2709 +MODULE_PARM_DESC(nocrtc,"bool: ignore CRTC timings when setting modes");
2710 +module_param(noedid, bool, 0);
2711 +MODULE_PARM_DESC(noedid,"bool: ignore EDID-provided monitor limits "
2712 + "when setting modes");
2713 +module_param(gtf, bool, 0);
2714 +MODULE_PARM_DESC(gtf,"bool: force use of VESA GTF to calculate mode timings");
2715 +module_param(vram_remap, uint, 0);
2716 +MODULE_PARM_DESC(vram_remap,"Set amount of video memory to be used [MiB]");
2717 +module_param(vram_total, uint, 0);
2718 +MODULE_PARM_DESC(vram_total,"Set total amount of video memoery [MiB]");
2719 +module_param(maxclk, ushort, 0);
2720 +MODULE_PARM_DESC(maxclk,"Maximum pixelclock [MHz], overrides EDID data");
2721 +module_param(maxhf, ushort, 0);
2722 +MODULE_PARM_DESC(maxhf,"Maximum horizontal frequency [kHz], "
2723 + "overrides EDID data");
2724 +module_param(maxvf, ushort, 0);
2725 +MODULE_PARM_DESC(maxvf,"Maximum vertical frequency [Hz], "
2726 + "overrides EDID data");
2727 +module_param_named(mode, mode_option, charp, 0);
2728 +MODULE_PARM_DESC(mode, "Specify resolution as "
2729 + "\"<xres>x<yres>[-<bpp>][@<refresh>]\"");
2730 +module_param(vbemode, ushort, 0);
2731 +MODULE_PARM_DESC(vbemode,"VBE mode number to set, overrides 'mode' setting");
2733 +#endif /* MODULE */
2735 +MODULE_LICENSE("GPL");
2736 +MODULE_AUTHOR("Michal Januszewski");
2737 +MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");
2739 diff --git a/include/linux/sched.h b/include/linux/sched.h
2740 index 62e6314..91920b6 100644
2741 --- a/include/linux/sched.h
2742 +++ b/include/linux/sched.h
2743 @@ -1140,6 +1140,8 @@ extern void mmput(struct mm_struct *);
2744 extern struct mm_struct *get_task_mm(struct task_struct *task);
2745 /* Remove the current tasks stale references to the old mm_struct */
2746 extern void mm_release(struct task_struct *, struct mm_struct *);
2747 +/* Create a new mm for a kernel thread */
2748 +extern int set_new_mm(void);
2750 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
2751 extern void flush_thread(void);
2752 diff --git a/include/video/vesa.h b/include/video/vesa.h
2753 new file mode 100644
2754 index 0000000..c274604
2756 +++ b/include/video/vesa.h
2759 +#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , \
2762 +#define DPRINTK(fmt, args...)
2765 +#define p_crtc(arg) ((struct vesafb_crtc_ib*)(arg))
2766 +#define p_vbe(arg) ((struct vesafb_vbe_ib*)(arg))
2767 +#define p_mode(arg) ((struct vesafb_mode_ib*)(arg))
2769 +struct vesafb_task {
2773 + struct vm86_regs regs;
2774 + struct list_head node;
2775 + struct completion done;
2778 +/* Vesafb task flags and masks */
2779 +#define TF_CALL 0x00
2780 +#define TF_EXIT 0x01
2781 +#define TF_GETVBEIB 0x02
2782 +#define TF_USE_BUF 0x04
2783 +#define TF_RETURN_BUF 0x08
2784 +#define TF_MASK_BUF (TF_USE_BUF | TF_RETURN_BUF)
2786 +/* Macros and functions for manipulating vesafb tasks */
2787 +#define vesafb_create_task(task) \
2789 + task = kmalloc(sizeof(struct vesafb_task), GFP_ATOMIC); \
2791 + memset(task, 0, sizeof(struct vesafb_task)); \
2792 + init_completion(&task->done); \
2795 +#define vesafb_wait_for_task(task) wait_for_completion(&task->done);
2796 +#define vesafb_reset_task(task) init_completion(&task->done);
2797 +int vesafb_queue_task(struct vesafb_task *task);
2799 +/* Functions for controlling the vesafb thread */
2800 +int vesafb_wait_for_thread(void);
2802 +#define VBE_CAP_CAN_SWITCH_DAC 0x01
2803 +#define VBE_CAP_VGACOMPAT 0x02
2805 +/* This struct is 512 bytes long */
2806 +struct vesafb_vbe_ib {
2807 + char vbe_signature[4];
2809 + u32 oem_string_ptr;
2811 + u32 mode_list_ptr;
2813 + u16 oem_software_rev;
2814 + u32 oem_vendor_name_ptr;
2815 + u32 oem_product_name_ptr;
2816 + u32 oem_product_rev_ptr;
2818 + char oem_data[256];
2819 +} __attribute__ ((packed));
2821 +struct vesafb_crtc_ib {
2832 +} __attribute__ ((packed));
2834 +#define VBE_MODE_VGACOMPAT 0x20
2836 +struct vesafb_mode_ib {
2837 + /* for all VBE revisions */
2841 + u16 win_granularity;
2846 + u16 bytes_per_scan_line;
2848 + /* for VBE 1.2+ */
2854 + u8 bits_per_pixel;
2861 + /* Direct color fields for direct/6 and YUV/7 memory models. */
2862 + /* Offsets are bit positions of lsb in the mask. */
2871 + u8 direct_color_info; /* direct color mode attributes */
2873 + /* for VBE 2.0+ */
2874 + u32 phys_base_ptr;
2877 + /* for VBE 3.0+ */
2878 + u16 lin_bytes_per_scan_line;
2879 + u8 bnk_image_pages;
2880 + u8 lin_image_pages;
2889 + u32 max_pixel_clock;
2892 +} __attribute__ ((packed));
2894 +struct vesafb_pal_entry {
2895 + u_char blue, green, red, pad;
2896 +} __attribute__ ((packed));
2898 +struct vesafb_par {
2901 + struct vesafb_crtc_ib crtc;
2904 diff --git a/kernel/fork.c b/kernel/fork.c
2905 index b373322..49d16cf 100644
2908 @@ -97,6 +97,7 @@ kmem_cache_t *fs_cachep;
2910 /* SLAB cache for vm_area_struct structures */
2911 kmem_cache_t *vm_area_cachep;
2912 +EXPORT_SYMBOL_GPL(vm_area_cachep);
2914 /* SLAB cache for mm_struct structures (tsk->mm) */
2915 static kmem_cache_t *mm_cachep;
2916 @@ -385,6 +386,40 @@ void mmput(struct mm_struct *mm)
2917 EXPORT_SYMBOL_GPL(mmput);
2920 + * set_new_mm - allocate, init and activate a new mm for a kernel thread
2922 +int set_new_mm(void)
2924 + struct mm_struct *mm;
2925 + struct task_struct *tsk = current;
2926 + struct mm_struct *active_mm;
2931 + if (init_new_context(current,mm))
2932 + goto fail_nocontext;
2935 + tsk->flags |= PF_BORROWED_MM;
2936 + active_mm = tsk->active_mm;
2938 + current->active_mm = mm;
2939 + activate_mm(active_mm, mm);
2940 + task_unlock(current);
2942 + /* Drop the previous active_mm */
2943 + mmdrop(active_mm);
2951 +EXPORT_SYMBOL_GPL(set_new_mm);
2954 * get_task_mm - acquire a reference to the task's mm
2956 * Returns %NULL if the task has no mm. Checks PF_BORROWED_MM (meaning
2957 diff --git a/mm/memory.c b/mm/memory.c
2958 index 85e80a5..5a7871a 100644
2961 @@ -1163,6 +1163,7 @@ int zeromap_page_range(struct vm_area_st
2962 } while (pgd++, addr = next, addr != end);
2965 +EXPORT_SYMBOL_GPL(zeromap_page_range);
2967 pte_t * fastcall get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl)
2969 diff --git a/mm/mmap.c b/mm/mmap.c
2970 index 47556d2..c94ec36 100644
2973 @@ -1991,6 +1991,7 @@ int insert_vm_struct(struct mm_struct *
2974 vma_link(mm, vma, prev, rb_link, rb_parent);
2977 +EXPORT_SYMBOL_GPL(insert_vm_struct);
2980 * Copy the vma structure to a new location in the same mm,