Magellan Linux

Contents of /trunk/kernel26-magellan/patches-2.6.21-r4/0151-2.6.21-vesafb-tng-1.0-rc2-2.6.20-rc2.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (show annotations) (download)
Tue Jun 12 08:03:28 2007 UTC (16 years, 10 months ago) by niro
File size: 90982 byte(s)
files for 2.6.21-magellan-r4

1 diff --git a/Documentation/fb/vesafb.txt b/Documentation/fb/vesafb.txt
2 index ee277dd..93d6e6e 100644
3 --- a/Documentation/fb/vesafb.txt
4 +++ b/Documentation/fb/vesafb.txt
5 @@ -2,16 +2,18 @@
6 What is vesafb?
7 ===============
8
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.
11
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.
15 +VESA BIOS Extensions Version 2.0 are required, because we need access to
16 +a linear frame buffer. VBE 3.0 is required if you want to use modes with a
17 +higher (than the standard 60 Hz) refresh rate.
18
19 -This means we decide at boot time whenever we want to run in text or
20 -graphics mode. Switching mode later on (in protected mode) is
21 -impossible; BIOS calls work in real mode only. VESA BIOS Extensions
22 -Version 2.0 are required, because we need a linear frame buffer.
23 +The VESA framebuffer driver comes in two flavors - the standard 'vesafb'
24 +and 'vesafb-tng'. Vesafb-tng is available only on 32-bit x86 due to the
25 +technology it uses (vm86). Vesafb-tng has more features than vesafb
26 +(adjusting the refresh rate on VBE 3.0 compliant boards, switching the
27 +video mode without rebooting, selecting a mode by providing its
28 +modedb name, and more).
29
30 Advantages:
31
32 @@ -29,26 +31,35 @@ Disadvantages:
33 How to use it?
34 ==============
35
36 -Switching modes is done using the vga=... boot parameter. Read
37 -Documentation/svga.txt for details.
38 +If you are running a 32-bit x86 system and you decide to use vesafb-tng,
39 +you can either compile the driver into the kernel or use it as a module.
40 +The graphics mode you want to use is in both cases specified using the
41 +standard modedb format.
42
43 -You should compile in both vgacon (for text mode) and vesafb (for
44 -graphics mode). Which of them takes over the console depends on
45 -whenever the specified mode is text or graphics.
46 +If your system doesn't support vm86 calls, things get a little more tricky.
47 +Since on such systems you can't do BIOS calls from protected mode in which
48 +kernel runs, you have to decide at boot time whenever you want to run in text
49 +or in graphics mode. Switching mode later on is impossible. Switching modes
50 +is done using the vga=... boot parameter. Read Documentation/svga.txt for
51 +details. Below is a more detailed description of what to do on systems using
52 +the standard vesafb driver.
53
54 -The graphic modes are NOT in the list which you get if you boot with
55 -vga=ask and hit return. The mode you wish to use is derived from the
56 -VESA mode number. Here are those VESA mode numbers:
57 +You should compile in both vgacon (for text mode) and vesafb (for graphics
58 +mode). Which of them takes over the console depends on whenever the
59 +specified mode is text or graphics.
60 +
61 +The graphic modes are NOT in the list which you get if you boot with vga=ask
62 +and hit return. The mode you wish to use is derived from the VESA mode number.
63 +Here are those VESA mode numbers:
64
65 | 640x480 800x600 1024x768 1280x1024
66 ----+-------------------------------------
67 -256 | 0x101 0x103 0x105 0x107
68 -32k | 0x110 0x113 0x116 0x119
69 -64k | 0x111 0x114 0x117 0x11A
70 -16M | 0x112 0x115 0x118 0x11B
71 +256 | 0x101 0x103 0x105 0x107
72 +32k | 0x110 0x113 0x116 0x119
73 +64k | 0x111 0x114 0x117 0x11A
74 +16M | 0x112 0x115 0x118 0x11B
75
76 -The video mode number of the Linux kernel is the VESA mode number plus
77 -0x200.
78 +The video mode number of the Linux kernel is the VESA mode number plus 0x200.
79
80 Linux_kernel_mode_number = VESA_mode_number + 0x200
81
82 @@ -56,15 +67,15 @@ So the table for the Kernel mode numbers are:
83
84 | 640x480 800x600 1024x768 1280x1024
85 ----+-------------------------------------
86 -256 | 0x301 0x303 0x305 0x307
87 -32k | 0x310 0x313 0x316 0x319
88 -64k | 0x311 0x314 0x317 0x31A
89 -16M | 0x312 0x315 0x318 0x31B
90 +256 | 0x301 0x303 0x305 0x307
91 +32k | 0x310 0x313 0x316 0x319
92 +64k | 0x311 0x314 0x317 0x31A
93 +16M | 0x312 0x315 0x318 0x31B
94
95 -To enable one of those modes you have to specify "vga=ask" in the
96 -lilo.conf file and rerun LILO. Then you can type in the desired
97 -mode at the "vga=ask" prompt. For example if you like to use
98 -1024x768x256 colors you have to say "305" at this prompt.
99 +To enable one of those modes you have to specify "vga=ask" in the lilo.conf
100 +file and rerun LILO. Then you can type in the desired mode at the "vga=ask"
101 +prompt. For example if you like to use 1024x768x256 colors you have to say
102 +"305" at this prompt.
103
104 If this does not work, this might be because your BIOS does not support
105 linear framebuffers or because it does not support this mode at all.
106 @@ -72,11 +83,12 @@ Even if your board does, it might be the BIOS which does not. VESA BIOS
107 Extensions v2.0 are required, 1.2 is NOT sufficient. You will get a
108 "bad mode number" message if something goes wrong.
109
110 -1. Note: LILO cannot handle hex, for booting directly with
111 +1. Note: LILO cannot handle hex, for booting directly with
112 "vga=mode-number" you have to transform the numbers to decimal.
113 2. Note: Some newer versions of LILO appear to work with those hex values,
114 if you set the 0x in front of the numbers.
115
116 +
117 X11
118 ===
119
120 @@ -84,98 +96,164 @@ XF68_FBDev should work just fine, but it is non-accelerated. Running
121 another (accelerated) X-Server like XF86_SVGA might or might not work.
122 It depends on X-Server and graphics board.
123
124 -The X-Server must restore the video mode correctly, else you end up
125 +The X-Server must restore the video mode correctly, or else you end up
126 with a broken console (and vesafb cannot do anything about this).
127 +With vesafb-tng chances are that the console will be restored properly
128 +even if the X server messes up the video mode.
129
130
131 Refresh rates
132 =============
133
134 -There is no way to change the vesafb video mode and/or timings after
135 -booting linux. If you are not happy with the 60 Hz refresh rate, you
136 -have these options:
137 +With VBE 3.0 compatible BIOSes and vesafb-tng it is possible to change
138 +the refresh rate either at boot time (by specifying the @<rr> part of
139 +the mode name) or later, using the fbset utility.
140 +
141 +If you want to use the default BIOS refresh rate while switching modes
142 +on a running system, set pixclock to 0.
143
144 - * configure and load the DOS-Tools for your the graphics board (if
145 - available) and boot linux with loadlin.
146 - * use a native driver (matroxfb/atyfb) instead if vesafb. If none
147 +With VBE 2.0 there is no way to change the mode timings after booting
148 +Linux. If you are not happy with the 60 Hz refresh rate, you have
149 +the following options:
150 +
151 + * Configure and load the DOS tools for your the graphics board (if
152 + available) and boot Linux with loadlin.
153 + * Use a native driver (matroxfb/atyfb) instead of vesafb. If none
154 is available, write a new one!
155 - * VBE 3.0 might work too. I have neither a gfx board with VBE 3.0
156 - support nor the specs, so I have not checked this yet.
157 + * Use a BIOS editor to change the default refresh rate (such an
158 + editor does exist at least for ATI Radeon BIOSes).
159 + * If you're running a non-vm86 and VBE 3.0 compatible system, you can
160 + use a kernel patch (vesafb-rrc) to hard-code some mode timings in
161 + the kernel and use these while setting the video mode at boot time.
162 +
163 +Note that there are some boards (nVidia 59**, 57** and newer models)
164 +claiming that their Video BIOS is VBE 3.0 compliant, while ignoring the
165 +CRTC values provided by software such as vesafb-tng. You'll not be able
166 +to adjust the refresh rate if you're using one of these boards.
167
168
169 Configuration
170 =============
171
172 -The VESA BIOS provides protected mode interface for changing
173 -some parameters. vesafb can use it for palette changes and
174 -to pan the display. It is turned off by default because it
175 -seems not to work with some BIOS versions, but there are options
176 -to turn it on.
177 -
178 -You can pass options to vesafb using "video=vesafb:option" on
179 -the kernel command line. Multiple options should be separated
180 -by comma, like this: "video=vesafb:ypan,invers"
181 -
182 -Accepted options:
183 -
184 -invers no comment...
185 -
186 -ypan enable display panning using the VESA protected mode
187 - interface. The visible screen is just a window of the
188 - video memory, console scrolling is done by changing the
189 - start of the window.
190 - pro: * scrolling (fullscreen) is fast, because there is
191 - no need to copy around data.
192 - * You'll get scrollback (the Shift-PgUp thing),
193 - the video memory can be used as scrollback buffer
194 - kontra: * scrolling only parts of the screen causes some
195 - ugly flicker effects (boot logo flickers for
196 - example).
197 -
198 -ywrap Same as ypan, but assumes your gfx board can wrap-around
199 - the video memory (i.e. starts reading from top if it
200 - reaches the end of video memory). Faster than ypan.
201 -
202 -redraw scroll by redrawing the affected part of the screen, this
203 - is the safe (and slow) default.
204 -
205 -
206 -vgapal Use the standard vga registers for palette changes.
207 - This is the default.
208 -pmipal Use the protected mode interface for palette changes.
209 -
210 -mtrr:n setup memory type range registers for the vesafb framebuffer
211 - where n:
212 - 0 - disabled (equivalent to nomtrr) (default)
213 - 1 - uncachable
214 - 2 - write-back
215 - 3 - write-combining
216 - 4 - write-through
217 -
218 - If you see the following in dmesg, choose the type that matches the
219 - old one. In this example, use "mtrr:2".
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.
224 +
225 +You can pass options to vesafb using "video=vesafb:option" on the kernel
226 +command line. Multiple options should be separated by a comma, like this:
227 +"video=vesafb:ypan,1024x768-32@85"
228 +
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.
231 +
232 +Accepted options (both vesafb and vesafb-tng):
233 +
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
243 + example).
244 +
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.
248 +
249 +redraw Scroll by redrawing the affected part of the screen, this is the
250 + safe (and slow) default.
251 +
252 +vgapal Use the standard VGA registers for palette changes.
253 +
254 +pmipal Use the protected mode interface for palette changes.
255 + This is the default is the protected mode interface is available.
256 +
257 +mtrr:n Setup memory type range registers for the vesafb framebuffer
258 + where n:
259 + 0 - disabled (equivalent to nomtrr) (default)
260 + 1 - uncachable
261 + 2 - write-back
262 + 3 - write-combining
263 + 4 - write-through
264 +
265 + If you see the following in dmesg, choose the type that matches
266 + the old one. In this example, use "mtrr:2".
267 ...
268 mtrr: type mismatch for e0000000,8000000 old: write-back new: write-combining
269 ...
270
271 -nomtrr disable mtrr
272 +nomtrr Do not use memory type range registers for vesafb.
273
274 vremap:n
275 remap 'n' MiB of video RAM. If 0 or not specified, remap memory
276 - according to video mode. (2.5.66 patch/idea by Antonino Daplas
277 - reversed to give override possibility (allocate more fb memory
278 - than the kernel would) to 2.4 by tmb@iki.fi)
279 + according to video mode. (2.5.66 patch/idea by Antonino Daplas
280 + reversed to give override possibility (allocate more fb memory
281 + than the kernel would) to 2.4 by tmb@iki.fi)
282
283 vtotal:n
284 if the video BIOS of your card incorrectly determines the total
285 amount of video RAM, use this option to override the BIOS (in MiB).
286
287 -Have fun!
288 +Options accepted only by vesafb-tng:
289 +
290 +<mode> The mode you want to set, in the standard modedb format. Refer to
291 + modedb.txt for a detailed description. If you specify a mode that is
292 + not supported by your board's BIOS, vesafb-tng will attempt to set a
293 + similar mode. The list of supported modes can be found in
294 + /proc/fbx/modes, where x is the framebuffer number (usually 0).
295 + When vesafb-tng is compiled as a module, the mode string should be
296 + provided as a value of the parameter 'mode'.
297 +
298 +vbemode:x
299 + Force the use of VBE mode x. The mode will only be set if it's
300 + found in the VBE-provided list of supported modes.
301 + NOTE: The mode number 'x' should be specified in VESA mode number
302 + notation, not the Linux kernel one (eg. 257 instead of 769).
303 + HINT: If you use this option because normal <mode> parameter does
304 + not work for you and you use a X server, you'll probably want to
305 + set the 'nocrtc' option to ensure that the video mode is properly
306 + restored after console <-> X switches.
307 +
308 +nocrtc Do not use CRTC timings while setting the video mode. This option
309 + makes sence only with VBE 3.0 compliant systems. Use it if you have
310 + problems with modes set in the standard way. Note that using this
311 + option means that any refresh rate adjustments will be ignored
312 + and the refresh rate will stay at your BIOS default (60 Hz).
313 +
314 +noedid Do not try to fetch and use EDID-provided modes.
315 +
316 +noblank Disable hardware blanking.
317 +
318 +gtf Force the use of VESA's GTF (Generalized Timing Formula). Specifying
319 + this will cause vesafb to skip its internal modedb and EDID-modedb
320 + and jump straight to the GTF part of the code (normally used only if
321 + everything else failed). This can be useful if you want to get as
322 + much as possible from your graphics board but your BIOS doesn't
323 + support modes with the refresh rates you require. Note that you may
324 + need to specify the maxhf, maxvf and maxclk parameters if they are not
325 + provided by the EDID block.
326 +
327 +Additionally, the following parameters may be provided. They all override the
328 +EDID-provided values and BIOS defaults. Refer to your monitor's specs to get
329 +the correct values for maxhf, maxvf and maxclk for your hardware.
330 +
331 +maxhf:n Maximum horizontal frequency (in kHz).
332 +maxvf:n Maximum vertical frequency (in Hz).
333 +maxclk:n Maximum pixel clock (in MHz).
334
335 - Gerd
336 +Have fun!
337
338 --
339 +Original document for the vesafb driver by
340 Gerd Knorr <kraxel@goldbach.in-berlin.de>
341
342 -Minor (mostly typo) changes
343 -by Nico Schmoigl <schmoigl@rumms.uni-mannheim.de>
344 +Minor (mostly typo) changes by
345 +Nico Schmoigl <schmoigl@rumms.uni-mannheim.de>
346 +
347 +Extended documentation for vm86, VBE 3.0 and vesafb-tng by
348 +Michal Januszewski <spock@gentoo.org>
349 +
350 diff --git a/arch/i386/boot/video.S b/arch/i386/boot/video.S
351 index 2c5b5cc..2c2d4b5 100644
352 --- a/arch/i386/boot/video.S
353 +++ b/arch/i386/boot/video.S
354 @@ -163,10 +163,12 @@ basret: ret
355 # parameters in the default 80x25 mode -- these are set directly,
356 # because some very obscure BIOSes supply insane values.
357 mode_params:
358 +#ifdef CONFIG_FB_VESA_STD
359 #ifdef CONFIG_VIDEO_SELECT
360 cmpb $0, graphic_mode
361 jnz mopar_gr
362 #endif
363 +#endif
364 movb $0x03, %ah # Read cursor position
365 xorb %bh, %bh
366 int $0x10
367 @@ -199,6 +201,7 @@ mopar2: movb %al, %fs:(PARAM_VIDEO_LINES)
368 ret
369
370 #ifdef CONFIG_VIDEO_SELECT
371 +#ifdef CONFIG_FB_VESA_STD
372 # Fetching of VESA frame buffer parameters
373 mopar_gr:
374 leaw modelist+1024, %di
375 @@ -281,6 +284,7 @@ dac_done:
376 movw %es, %fs:(PARAM_VESAPM_SEG)
377 movw %di, %fs:(PARAM_VESAPM_OFF)
378 no_pm: ret
379 +#endif
380
381 # The video mode menu
382 mode_menu:
383 @@ -495,10 +499,12 @@ mode_set:
384
385 cmpb $VIDEO_FIRST_V7>>8, %ah
386 jz setv7
387 -
388 +
389 +#ifdef CONFIG_FB_VESA_STD
390 cmpb $VIDEO_FIRST_VESA>>8, %ah
391 jnc check_vesa
392 -
393 +#endif
394 +
395 orb %ah, %ah
396 jz setmenu
397
398 @@ -570,6 +576,7 @@ setr1: lodsw
399 movw -4(%si), %ax # Fetch mode ID
400 jmp _m_s
401
402 +#ifdef CONFIG_FB_VESA_STD
403 check_vesa:
404 leaw modelist+1024, %di
405 subb $VIDEO_FIRST_VESA>>8, %bh
406 @@ -603,6 +610,7 @@ check_vesa:
407 ret
408
409 _setbad: jmp setbad # Ugly...
410 +#endif
411
412 # Recalculate vertical display end registers -- this fixes various
413 # inconsistencies of extended modes on many adapters. Called when
414 diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
415 index 1393523..8a05f95 100644
416 --- a/drivers/char/sysrq.c
417 +++ b/drivers/char/sysrq.c
418 @@ -240,7 +240,7 @@ static void send_sig_all(int sig)
419 struct task_struct *p;
420
421 for_each_process(p) {
422 - if (p->mm && !is_init(p))
423 + if (p->mm && !is_init(p) && !(p->flags & PF_BORROWED_MM))
424 /* Not swapper, init nor kernel thread */
425 force_sig(sig, p);
426 }
427 diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
428 index 4e83f01..ae122fd 100644
429 --- a/drivers/video/Kconfig
430 +++ b/drivers/video/Kconfig
431 @@ -547,8 +547,22 @@ config FB_TGA
432 cards. Say Y if you have one of those.
433
434 config FB_VESA
435 - bool "VESA VGA graphics support"
436 - depends on (FB = y) && X86
437 + tristate "VESA VGA graphics support"
438 + depends on (FB = y) && (X86 || X86_64)
439 + help
440 + This is the frame buffer device driver for generic VESA 2.0
441 + compliant graphic cards. The older VESA 1.2 cards are not supported.
442 + You will get a boot time penguin logo at no additional cost. Please
443 + read <file:Documentation/fb/vesafb.txt>. If unsure, say Y.
444 +
445 +choice
446 + prompt "VESA driver type"
447 + depends on FB_VESA
448 + default FB_VESA_STD if X86_64
449 + default FB_VESA_TNG if X86
450 +
451 +config FB_VESA_STD
452 + bool "vesafb"
453 select FB_CFB_FILLRECT
454 select FB_CFB_COPYAREA
455 select FB_CFB_IMAGEBLIT
456 @@ -557,7 +571,43 @@ config FB_VESA
457 This is the frame buffer device driver for generic VESA 2.0
458 compliant graphic cards. The older VESA 1.2 cards are not supported.
459 You will get a boot time penguin logo at no additional cost. Please
460 - read <file:Documentation/fb/vesafb.txt>. If unsure, say Y.
461 + read <file:Documentation/fb/vesafb.txt>. Choose this driver if you
462 + are experiencing problems with vesafb-tng or if you own a 64-bit system.
463 +
464 + Note that this driver cannot be compiled as a module.
465 +
466 +config FB_VESA_TNG
467 + bool "vesafb-tng"
468 + depends on !X86_64
469 + select FB_MODE_HELPERS
470 + select FB_CFB_FILLRECT
471 + select FB_CFB_COPYAREA
472 + select FB_CFB_IMAGEBLIT
473 + help
474 + This is an enhanced generic frame buffer device driver for
475 + VBE 2.0 compliant graphic cards. It can take advantage of VBE 3.0
476 + features (refresh rate adjustment) when these are available.
477 + The driver also makes it possible to change the video mode
478 + on the fly and to switch back to text mode when it's unloaded.
479 +
480 + If the driver is compiled as a module, the module will be called
481 + vesafb-tng.
482 +
483 +endchoice
484 +
485 +config FB_VESA_DEFAULT_MODE
486 + string "VESA default mode"
487 + depends on FB_VESA_TNG
488 + default "640x480@60"
489 + help
490 + This option is used to determine the default mode vesafb is
491 + supposed to switch to in case no mode is provided as a kernel
492 + command line parameter.
493 +
494 +config VIDEO_SELECT
495 + bool
496 + depends on FB_VESA
497 + default y
498
499 config FB_IMAC
500 bool "Intel-based Macintosh Framebuffer Support"
501 diff --git a/drivers/video/Makefile b/drivers/video/Makefile
502 index 309a26d..e57b0e7 100644
503 --- a/drivers/video/Makefile
504 +++ b/drivers/video/Makefile
505 @@ -102,7 +102,11 @@ obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
506 obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
507
508 # Platform or fallback drivers go here
509 -obj-$(CONFIG_FB_VESA) += vesafb.o
510 +ifeq ($(CONFIG_FB_VESA_STD),y)
511 + obj-y += vesafb.o
512 +else
513 + obj-$(CONFIG_FB_VESA) += vesafb-thread.o vesafb-tng.o
514 +endif
515 obj-$(CONFIG_FB_IMAC) += imacfb.o
516 obj-$(CONFIG_FB_VGA16) += vga16fb.o vgastate.o
517 obj-$(CONFIG_FB_OF) += offb.o
518 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
519 index 3cfea31..bfb39cc 100644
520 --- a/drivers/video/fbmem.c
521 +++ b/drivers/video/fbmem.c
522 @@ -1408,6 +1408,7 @@ fbmem_init(void)
523 printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
524 fb_class = NULL;
525 }
526 +
527 return 0;
528 }
529
530 diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
531 index 5df41f6..f838a53 100644
532 --- a/drivers/video/modedb.c
533 +++ b/drivers/video/modedb.c
534 @@ -674,6 +674,7 @@ void fb_var_to_videomode(struct fb_videomode *mode,
535 {
536 u32 pixclock, hfreq, htotal, vtotal;
537
538 + mode->refresh = 0;
539 mode->name = NULL;
540 mode->xres = var->xres;
541 mode->yres = var->yres;
542 @@ -1025,3 +1026,4 @@ EXPORT_SYMBOL(fb_find_best_mode);
543 EXPORT_SYMBOL(fb_find_nearest_mode);
544 EXPORT_SYMBOL(fb_videomode_to_modelist);
545 EXPORT_SYMBOL(fb_find_mode);
546 +EXPORT_SYMBOL(fb_destroy_modelist);
547 diff --git a/drivers/video/vesafb-thread.c b/drivers/video/vesafb-thread.c
548 new file mode 100644
549 index 0000000..543e202
550 --- /dev/null
551 +++ b/drivers/video/vesafb-thread.c
552 @@ -0,0 +1,751 @@
553 +/*
554 + * Framebuffer driver for VBE 2.0+ compliant graphic boards.
555 + * Kernel thread and vm86 routines.
556 + *
557 + * (c) 2004-2006 Michal Januszewski <spock@gentoo.org>
558 + *
559 + */
560 +
561 +#include <linux/workqueue.h>
562 +#include <linux/completion.h>
563 +#include <linux/module.h>
564 +#include <linux/kernel.h>
565 +#include <linux/errno.h>
566 +#include <linux/mm.h>
567 +#include <linux/delay.h>
568 +#include <linux/signal.h>
569 +#include <linux/freezer.h>
570 +#include <linux/suspend.h>
571 +#include <linux/unistd.h>
572 +#include <video/vesa.h>
573 +#include <video/edid.h>
574 +#include <asm/mman.h>
575 +#include <asm/page.h>
576 +#include <asm/vm86.h>
577 +#include <asm/thread_info.h>
578 +#include <asm/uaccess.h>
579 +#include <asm/mmu_context.h>
580 +#include "edid.h"
581 +
582 +static int errno;
583 +
584 +static DECLARE_COMPLETION(vesafb_th_completion);
585 +static DECLARE_MUTEX(vesafb_task_list_sem);
586 +static LIST_HEAD(vesafb_task_list);
587 +static DECLARE_WAIT_QUEUE_HEAD(vesafb_wait);
588 +
589 +static struct vm86_struct vm86;
590 +static int vesafb_pid = 0;
591 +
592 +#define DEFAULT_VM86_FLAGS (IF_MASK | IOPL_MASK)
593 +#define VM86_PUSHW(x) \
594 +do { \
595 + vm86.regs.esp -= 2; \
596 + *(u16*)(STACK_ADDR + vm86.regs.esp) = x; \
597 +} while(0);
598 +
599 +/* Stack, the return code and buffers will be put into
600 + * one contiguous memory chunk:
601 + *
602 + * [ STACK | RET_CODE | BUFFER ]
603 + *
604 + * Some video BIOSes (sis6326) try to store data somewhere
605 + * in 0x7000-0x7fff, so we zeromap more memory to be safe.
606 + */
607 +#define IVTBDA_SIZE PAGE_SIZE
608 +#define RET_CODE_SIZE 0x0010
609 +#define STACK_SIZE 0x0500
610 +#define BUFFER_SIZE 0x10000
611 +
612 +/* The amount of memory that will be allocated should be a multiple
613 + * of PAGE_SIZE. */
614 +#define __MEM_SIZE (RET_CODE_SIZE + STACK_SIZE + BUFFER_SIZE)
615 +#define REAL_MEM_SIZE (((__MEM_SIZE / PAGE_SIZE) + 1) * PAGE_SIZE)
616 +
617 +#define IVTBDA_ADDR 0x00000
618 +#define STACK_ADDR (IVTBDA_ADDR + IVTBDA_SIZE)
619 +#define RET_CODE_ADDR (STACK_ADDR + STACK_SIZE)
620 +#define BUF_ADDR (RET_CODE_ADDR + RET_CODE_SIZE)
621 +
622 +#define FLAG_D (1 << 10)
623 +
624 +/* Syscalls used by the vesafb thread */
625 +static int vm86old(struct vm86_struct __user* v86)
626 +{
627 + long res;
628 + __asm__ volatile ("push %%ebx; movl %2, %%ebx ; int $0x80 ; pop %%ebx"
629 + : "=a" (res)
630 + : "0" (__NR_vm86old), "ri" ((long)(v86)) : "memory");
631 +
632 + if ((unsigned long)(res) >= (unsigned long)(-MAX_ERRNO)) {
633 + errno = -res;
634 + res = -1;
635 + }
636 + return (int)res;
637 +}
638 +
639 +static int ioperm(unsigned long a, unsigned long b, unsigned long c)
640 +{
641 + long res;
642 + __asm__ volatile ("push %%ebx; movl %2, %%ebx ; int $0x80 ; pop %%ebx"
643 + : "=a" (res)
644 + : "0" (__NR_ioperm), "ri" ((long)(a)), "c" ((long)(b)),
645 + "d" ((long)(c)) : "memory");
646 +
647 + if ((unsigned long)(res) >= (unsigned long)(-MAX_ERRNO)) {
648 + errno = -res;
649 + res = -1;
650 + }
651 + return (int)res;
652 +}
653 +
654 +/* Segment prefix opcodes */
655 +enum {
656 + P_CS = 0x2e,
657 + P_SS = 0x36,
658 + P_DS = 0x3e,
659 + P_ES = 0x26,
660 + P_FS = 0x64,
661 + P_GS = 0x65
662 +};
663 +
664 +/* Emulated vm86 ins instruction */
665 +static void vm86_ins(int size)
666 +{
667 + u32 edx, edi;
668 + edx = vm86.regs.edx & 0xffff;
669 + edi = (vm86.regs.edi & 0xffff) + (u32)(vm86.regs.es << 4);
670 +
671 + if (vm86.regs.eflags & FLAG_D)
672 + asm volatile ("std\n");
673 + else
674 + asm volatile ("cld\n");
675 +
676 + switch (size) {
677 + case 4:
678 + asm volatile ("insl\n" : "=D" (edi) : "d" (edx), "0" (edi));
679 + break;
680 + case 2:
681 + asm volatile ("insw\n" : "=D" (edi) : "d" (edx), "0" (edi));
682 + break;
683 + case 1:
684 + asm volatile ("insb\n" : "=D" (edi) : "d" (edx), "0" (edi));
685 + break;
686 + }
687 +
688 + if (vm86.regs.eflags & FLAG_D)
689 + asm volatile ("cld\n");
690 +
691 + edi -= (u32)(vm86.regs.es << 4);
692 +
693 + vm86.regs.edi &= 0xffff0000;
694 + vm86.regs.edi |= edi & 0xffff;
695 +}
696 +
697 +static void vm86_rep_ins(int size)
698 +{
699 + u16 cx = vm86.regs.ecx;
700 + while (cx--)
701 + vm86_ins(size);
702 +
703 + vm86.regs.ecx &= 0xffff0000;
704 +}
705 +
706 +/* Emulated vm86 outs instruction */
707 +static void vm86_outs(int size, int segment)
708 +{
709 + u32 edx, esi, base;
710 +
711 + edx = vm86.regs.edx & 0xffff;
712 + esi = vm86.regs.esi & 0xffff;
713 +
714 + switch (segment) {
715 + case P_CS: base = vm86.regs.cs; break;
716 + case P_SS: base = vm86.regs.ss; break;
717 + case P_ES: base = vm86.regs.es; break;
718 + case P_FS: base = vm86.regs.fs; break;
719 + case P_GS: base = vm86.regs.gs; break;
720 + default: base = vm86.regs.ds; break;
721 + }
722 +
723 + esi += base << 4;
724 +
725 + if (vm86.regs.eflags & FLAG_D)
726 + asm volatile ("std\n");
727 + else
728 + asm volatile ("cld\n");
729 +
730 + switch (size) {
731 + case 4:
732 + asm volatile ("outsl\n" : "=S" (esi) : "d" (edx), "0" (esi));
733 + break;
734 + case 2:
735 + asm volatile ("outsw\n" : "=S" (esi) : "d" (edx), "0" (esi));
736 + break;
737 + case 1:
738 + asm volatile ("outsb\n" : "=S" (esi) : "d" (edx), "0" (esi));
739 + break;
740 + }
741 +
742 + if (vm86.regs.eflags & FLAG_D)
743 + asm volatile ("cld");
744 +
745 + esi -= base << 4;
746 + vm86.regs.esi &= 0xffff0000;
747 + vm86.regs.esi |= (esi & 0xffff);
748 +}
749 +
750 +static void vm86_rep_outs(int size, int segment)
751 +{
752 + u16 cx = vm86.regs.ecx;
753 + while (cx--)
754 + vm86_outs(size, segment);
755 +
756 + vm86.regs.ecx &= 0xffff0000;
757 +}
758 +
759 +static int vm86_do_unknown(void)
760 +{
761 + u8 data32 = 0, segment = P_DS, rep = 0;
762 + u8 *instr;
763 + int ret = 0, i = 0;
764 +
765 + instr = (u8*)((vm86.regs.cs << 4) + vm86.regs.eip);
766 +
767 + while (1) {
768 + switch(instr[i]) {
769 + case 0x66: /* operand size prefix */
770 + data32 = 1 - data32;
771 + i++;
772 + break;
773 + case 0xf2: /* repnz */
774 + case 0xf3: /* rep */
775 + rep = 1;
776 + i++;
777 + break;
778 + case P_CS: /* segment prefix */
779 + case P_SS:
780 + case P_DS:
781 + case P_ES:
782 + case P_FS:
783 + case P_GS:
784 + segment = instr[i];
785 + i++;
786 + break;
787 + case 0xf0: /* LOCK - ignored */
788 + case 0x67: /* address size prefix - ignored */
789 + i++;
790 + break;
791 + case 0x6c: /* insb */
792 + if (rep)
793 + vm86_rep_ins(1);
794 + else
795 + vm86_ins(1);
796 + i++;
797 + goto out;
798 + case 0x6d: /* insw / insd */
799 + if (rep) {
800 + if (data32)
801 + vm86_rep_ins(4);
802 + else
803 + vm86_rep_ins(2);
804 + } else {
805 + if (data32)
806 + vm86_ins(4);
807 + else
808 + vm86_ins(2);
809 + }
810 + i++;
811 + goto out;
812 + case 0x6e: /* outsb */
813 + if (rep)
814 + vm86_rep_outs(1, segment);
815 + else
816 + vm86_outs(1, segment);
817 + i++;
818 + goto out;
819 + case 0x6f: /* outsw / outsd */
820 + if (rep) {
821 + if (data32)
822 + vm86_rep_outs(4, segment);
823 + else
824 + vm86_rep_outs(2, segment);
825 + } else {
826 + if (data32)
827 + vm86_outs(4, segment);
828 + else
829 + vm86_outs(2, segment);
830 + }
831 + i++;
832 + goto out;
833 + case 0xe4: /* inb xx */
834 + asm volatile (
835 + "inb %w1, %b0"
836 + : "=a" (vm86.regs.eax)
837 + : "d" (instr[i+1]), "0" (vm86.regs.eax));
838 + i += 2;
839 + goto out;
840 + case 0xe5: /* inw xx / ind xx */
841 + if (data32) {
842 + asm volatile (
843 + "inl %w1, %0"
844 + : "=a" (vm86.regs.eax)
845 + : "d" (instr[i+1]),
846 + "0" (vm86.regs.eax));
847 + } else {
848 + asm volatile (
849 + "inw %w1, %w0"
850 + : "=a" (vm86.regs.eax)
851 + : "d" (instr[i+1]),
852 + "0" (vm86.regs.eax));
853 + }
854 + i += 2;
855 + goto out;
856 +
857 + case 0xec: /* inb dx */
858 + asm volatile (
859 + "inb %w1, %b0"
860 + : "=a" (vm86.regs.eax)
861 + : "d" (vm86.regs.edx), "0" (vm86.regs.eax));
862 + i++;
863 + goto out;
864 + case 0xed: /* inw dx / ind dx */
865 + if (data32) {
866 + asm volatile (
867 + "inl %w1, %0"
868 + : "=a" (vm86.regs.eax)
869 + : "d" (vm86.regs.edx));
870 + } else {
871 + asm volatile (
872 + "inw %w1, %w0"
873 + : "=a" (vm86.regs.eax)
874 + : "d" (vm86.regs.edx));
875 + }
876 + i++;
877 + goto out;
878 + case 0xe6: /* outb xx */
879 + asm volatile (
880 + "outb %b0, %w1"
881 + : /* no return value */
882 + : "a" (vm86.regs.eax), "d" (instr[i+1]));
883 + i += 2;
884 + goto out;
885 + case 0xe7: /* outw xx / outd xx */
886 + if (data32) {
887 + asm volatile (
888 + "outl %0, %w1"
889 + : /* no return value */
890 + : "a" (vm86.regs.eax),
891 + "d" (instr[i+1]));
892 + } else {
893 + asm volatile (
894 + "outw %w0, %w1"
895 + : /* no return value */
896 + : "a" (vm86.regs.eax),
897 + "d" (instr[i+1]));
898 + }
899 + i += 2;
900 + goto out;
901 + case 0xee: /* outb dx */
902 + asm volatile (
903 + "outb %b0, %w1"
904 + : /* no return value */
905 + : "a" (vm86.regs.eax), "d" (vm86.regs.edx));
906 + i++;
907 + goto out;
908 + case 0xef: /* outw dx / outd dx */
909 + if (data32) {
910 + asm volatile (
911 + "outl %0, %w1"
912 + : /* no return value */
913 + : "a" (vm86.regs.eax),
914 + "d" (vm86.regs.edx));
915 + } else {
916 + asm volatile (
917 + "outw %w0, %w1"
918 + : /* no return value */
919 + : "a" (vm86.regs.eax),
920 + "d" (vm86.regs.edx));
921 + }
922 + i++;
923 + goto out;
924 + default:
925 + printk(KERN_ERR "vesafb: BUG, opcode 0x%x emulation "
926 + "not supported (EIP: 0x%lx)\n",
927 + instr[i], (u32)(vm86.regs.cs << 4) +
928 + vm86.regs.eip);
929 + ret = 1;
930 + goto out;
931 + }
932 + }
933 +out: vm86.regs.eip += i;
934 + return ret;
935 +}
936 +
937 +void vesafb_do_vm86(struct vm86_regs *regs)
938 +{
939 + unsigned int ret;
940 + u8 *retcode = (void*)RET_CODE_ADDR;
941 +
942 + memset(&vm86,0,sizeof(vm86));
943 + memcpy(&vm86.regs, regs, sizeof(struct vm86_regs));
944 +
945 + /* The return code */
946 + retcode[0] = 0xcd; /* int opcode */
947 + retcode[1] = 0xff; /* int number (255) */
948 +
949 + /* We use int 0xff to get back to protected mode */
950 + memset(&vm86.int_revectored, 0, sizeof(vm86.int_revectored));
951 + ((unsigned char *)&vm86.int_revectored)[0xff / 8] |= (1 << (0xff % 8));
952 +
953 + /*
954 + * We want to call int 0x10, so we set:
955 + * CS = 0x42 = 0x10 * 4 + 2
956 + * IP = 0x40 = 0x10 * 4
957 + * and SS:ESP. It's up to the caller to set the rest of the registers.
958 + */
959 + vm86.regs.eflags = DEFAULT_VM86_FLAGS;
960 + vm86.regs.cs = *(unsigned short *)0x42;
961 + vm86.regs.eip = *(unsigned short *)0x40;
962 + vm86.regs.ss = (STACK_ADDR >> 4);
963 + vm86.regs.esp = ((STACK_ADDR & 0x0000f) + STACK_SIZE);
964 +
965 + /* These will be fetched off the stack when we come to an iret in the
966 + * int's 0x10 code. */
967 + VM86_PUSHW(DEFAULT_VM86_FLAGS);
968 + VM86_PUSHW((RET_CODE_ADDR >> 4)); /* return code segment */
969 + VM86_PUSHW((RET_CODE_ADDR & 0x0000f)); /* return code offset */
970 +
971 + while(1) {
972 + ret = vm86old(&vm86);
973 +
974 + if (VM86_TYPE(ret) == VM86_INTx) {
975 + int vint = VM86_ARG(ret);
976 +
977 + /* If exit from vm86 was caused by int 0xff, then
978 + * we're done.. */
979 + if (vint == 0xff)
980 + goto out;
981 +
982 + /* .. otherwise, we have to call the int handler
983 + * manually */
984 + VM86_PUSHW(vm86.regs.eflags);
985 + VM86_PUSHW(vm86.regs.cs);
986 + VM86_PUSHW(vm86.regs.eip);
987 +
988 + vm86.regs.cs = *(u16 *)((vint << 2) + 2);
989 + vm86.regs.eip = *(u16 *)(vint << 2);
990 + vm86.regs.eflags &= ~(VIF_MASK | TF_MASK);
991 + } else if (VM86_TYPE(ret) == VM86_UNKNOWN) {
992 + if (vm86_do_unknown())
993 + goto out;
994 + } else {
995 + printk(KERN_ERR "vesafb: BUG, returned from "
996 + "vm86 with %x (EIP: 0x%lx)\n",
997 + ret, (u32)(vm86.regs.cs << 4) +
998 + vm86.regs.eip);
999 + goto out;
1000 + }
1001 + }
1002 +
1003 +out: /* copy the registers' state back to the caller's struct */
1004 + memcpy(regs, &vm86.regs, sizeof(struct vm86_regs));
1005 +}
1006 +
1007 +static int vesafb_remap_pfn_range(unsigned long start, unsigned long end,
1008 + unsigned long pgoff, unsigned long prot,
1009 + int type)
1010 +{
1011 + struct vm_area_struct *vma;
1012 + struct mm_struct *mm = current->mm;
1013 + int ret = 0;
1014 +
1015 + vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
1016 + if (!vma)
1017 + return -ENOMEM;
1018 + memset(vma, 0, sizeof(*vma));
1019 + down_write(&mm->mmap_sem);
1020 + vma->vm_mm = mm;
1021 + vma->vm_start = start;
1022 + vma->vm_end = end;
1023 + vma->vm_flags = VM_READ | VM_WRITE | VM_EXEC;
1024 + vma->vm_flags |= mm->def_flags;
1025 + vma->vm_page_prot.pgprot = prot;
1026 + vma->vm_pgoff = pgoff;
1027 +
1028 + if ((ret = insert_vm_struct(mm, vma))) {
1029 + up_write(&mm->mmap_sem);
1030 + kmem_cache_free(vm_area_cachep, vma);
1031 + return ret;
1032 + }
1033 +
1034 + if (type) {
1035 + ret = zeromap_page_range(vma,
1036 + vma->vm_start,
1037 + vma->vm_end - vma->vm_start,
1038 + vma->vm_page_prot);
1039 + } else {
1040 + vma->vm_flags |= VM_SHARED;
1041 + ret = remap_pfn_range(vma,
1042 + vma->vm_start,
1043 + vma->vm_pgoff,
1044 + vma->vm_end - vma->vm_start,
1045 + vma->vm_page_prot);
1046 + }
1047 + up_write(&mm->mmap_sem);
1048 + return ret;
1049 +}
1050 +
1051 +static inline int vesafb_init_mem(void)
1052 +{
1053 + int ret = 0;
1054 +
1055 + /* The memory chunks we're remapping here should be multiples
1056 + * of PAGE_SIZE. */
1057 + ret += vesafb_remap_pfn_range(0x00000, IVTBDA_SIZE, 0,
1058 + PROT_READ | PROT_EXEC | PROT_WRITE, 0);
1059 + ret += vesafb_remap_pfn_range(IVTBDA_SIZE, REAL_MEM_SIZE, 0,
1060 + PROT_READ | PROT_EXEC | PROT_WRITE, 1);
1061 + ret += vesafb_remap_pfn_range(0x9f000, 0x100000,
1062 + 0x9f000 >> PAGE_SHIFT,
1063 + PROT_READ | PROT_EXEC | PROT_WRITE, 0);
1064 + if (ret)
1065 + printk(KERN_ERR "vesafb thread: memory remapping failed\n");
1066 +
1067 + return ret;
1068 +}
1069 +
1070 +#define vesafb_get_string(str) \
1071 +{ \
1072 + /* The address is in the form ssssoooo, where oooo = offset, \
1073 + * ssss = segment */ \
1074 + addr = ((p_vbe(tsk->buf)->str & 0xffff0000) >> 12) + \
1075 + (p_vbe(tsk->buf)->str & 0x0000ffff); \
1076 + \
1077 + /* The data is in ROM which is shared between processes, so we \
1078 + * just translate the real mode address into one visible from \
1079 + * kernel space */ \
1080 + if (addr >= 0xa0000) { \
1081 + p_vbe(tsk->buf)->str = (u32) __va(addr); \
1082 + \
1083 + /* The data is in the buffer, we just have to convert the \
1084 + * address so that it points into the buffer user provided. */ \
1085 + } else if (addr > BUF_ADDR && addr < BUF_ADDR + \
1086 + sizeof(struct vesafb_vbe_ib)) { \
1087 + addr -= BUF_ADDR; \
1088 + p_vbe(tsk->buf)->str = (u32) (tsk->buf + addr); \
1089 + \
1090 + /* This should never happen: someone was insane enough to put \
1091 + * the data somewhere in RAM.. */ \
1092 + } else { \
1093 + p_vbe(tsk->buf)->str = (u32) ""; \
1094 + } \
1095 +}
1096 +
1097 +void vesafb_handle_getvbeib(struct vesafb_task *tsk)
1098 +{
1099 + int addr, res;
1100 +
1101 + tsk->regs.es = (BUF_ADDR >> 4);
1102 + tsk->regs.edi = (BUF_ADDR & 0x000f);
1103 + strncpy(p_vbe(BUF_ADDR)->vbe_signature, "VBE2", 4);
1104 +
1105 + vesafb_do_vm86(&tsk->regs);
1106 + memcpy(tsk->buf, (void*)(BUF_ADDR), sizeof(struct vesafb_vbe_ib));
1107 +
1108 + /* The OEM fields were not defined prior to VBE 2.0 */
1109 + if (p_vbe(tsk->buf)->vbe_version >= 0x200) {
1110 + vesafb_get_string(oem_string_ptr);
1111 + vesafb_get_string(oem_vendor_name_ptr);
1112 + vesafb_get_string(oem_product_name_ptr);
1113 + vesafb_get_string(oem_product_rev_ptr);
1114 + }
1115 +
1116 + /* This is basically the same as vesafb_get_string() */
1117 + addr = ((p_vbe(tsk->buf)->mode_list_ptr & 0xffff0000) >> 12) +
1118 + (p_vbe(tsk->buf)->mode_list_ptr & 0x0000ffff);
1119 +
1120 + if (addr >= 0xa0000) {
1121 + p_vbe(tsk->buf)->mode_list_ptr = (u32) __va(addr);
1122 + } else if (addr > BUF_ADDR && addr < BUF_ADDR +
1123 + sizeof(struct vesafb_vbe_ib)) {
1124 + addr -= BUF_ADDR;
1125 + p_vbe(tsk->buf)->mode_list_ptr = (u32) (tsk->buf + addr);
1126 + } else {
1127 + res = 0;
1128 + printk(KERN_WARNING "vesafb: warning, copying modelist "
1129 + "from somewhere in RAM!\n");
1130 + while (*(u16*)(addr+res) != 0xffff &&
1131 + res < (sizeof(p_vbe(tsk->buf)->reserved) - 2)) {
1132 + *(u16*) ((u32)&(p_vbe(tsk->buf)->reserved) + res) =
1133 + *(u16*)(addr+res);
1134 + res += 2;
1135 + }
1136 + *(u16*) ((u32)&(p_vbe(tsk->buf)->reserved) + res) = 0xffff;
1137 + }
1138 +}
1139 +
1140 +int vesafb_handle_tasks(void)
1141 +{
1142 + struct vesafb_task *tsk;
1143 + struct list_head *curr, *next;
1144 + int ret = 0;
1145 +
1146 + down(&vesafb_task_list_sem);
1147 + list_for_each_safe(curr, next, &vesafb_task_list) {
1148 + tsk = list_entry(curr, struct vesafb_task, node);
1149 +
1150 + if (tsk->flags & TF_EXIT) {
1151 + ret = 1;
1152 + goto task_done;
1153 + }
1154 + if (tsk->flags & TF_GETVBEIB) {
1155 + vesafb_handle_getvbeib(tsk);
1156 + goto task_done;
1157 + }
1158 + /* Do we need to store a pointer to the buffer in ES:EDI? */
1159 + if (tsk->flags & TF_BUF_DI) {
1160 + tsk->regs.es = (BUF_ADDR >> 4);
1161 + tsk->regs.edi = (BUF_ADDR & 0x000f);
1162 + }
1163 + /* Sometimes the pointer has to be in ES:EBX. */
1164 + if (tsk->flags & TF_BUF_BX) {
1165 + tsk->regs.es = (BUF_ADDR >> 4);
1166 + tsk->regs.ebx = (BUF_ADDR & 0x000f);
1167 + }
1168 + if (tsk->flags & (TF_BUF_DI | TF_BUF_BX))
1169 + memcpy((void*)BUF_ADDR, tsk->buf, tsk->buf_len);
1170 +
1171 + vesafb_do_vm86(&tsk->regs);
1172 +
1173 + if (tsk->flags & TF_RETURN_BUF)
1174 + memcpy(tsk->buf, (void*)BUF_ADDR, tsk->buf_len);
1175 +
1176 +task_done: list_del(curr);
1177 + complete(&tsk->done);
1178 + }
1179 +
1180 + /* If we're going to kill this thread, don't allow any elements
1181 + * to be added to the task list. */
1182 + if (!ret)
1183 + up(&vesafb_task_list_sem);
1184 +
1185 + return ret;
1186 +}
1187 +
1188 +/*
1189 + * This 'hybrid' thread serves as a backend for vesafb-tng, handling all vm86
1190 + * calls. It is started as a kernel thread. It then creates its own mm struct,
1191 + * thus separating itself from any userspace processes. At this moment, it
1192 + * stops being a kernel thread (kernel threads have mm = NULL) and becomes
1193 + * a 'hybrid' thread -- one that has full access to kernel space, yet runs
1194 + * with its own address space.
1195 + *
1196 + * This is necessary because in order to make vm86 calls some parts of the
1197 + * first 1MB of RAM have to be setup to mimic the real mode. These are:
1198 + * - interrupt vector table [0x00000-0x003ff]
1199 + * - BIOS data area [0x00400-0x004ff]
1200 + * - Extended BIOS data area [0x9fc00-0x9ffff]
1201 + * - the video RAM [0xa0000-0xbffff]
1202 + * - video BIOS [0xc0000-0xcffff]
1203 + * - motherboard BIOS [0xf0000-0xfffff]
1204 + */
1205 +int vesafb_thread(void *unused)
1206 +{
1207 + int err = 0;
1208 +
1209 + set_fs(KERNEL_DS);
1210 + daemonize("vesafb");
1211 +
1212 + if (set_new_mm()) {
1213 + err = -ENOMEM;
1214 + goto thr_end;
1215 + }
1216 + if (vesafb_init_mem()) {
1217 + err = -ENOMEM;
1218 + goto thr_end;
1219 + }
1220 +
1221 + DPRINTK("started vesafb thread\n");
1222 +
1223 + /* Having an IO bitmap makes things faster as we avoid GPFs
1224 + * when running vm86 code. We can live if it fails, though,
1225 + * so don't bother checking for errors. */
1226 + ioperm(0,1024,1);
1227 + set_user_nice(current, -10);
1228 +
1229 + complete(&vesafb_th_completion);
1230 +
1231 + while (1) {
1232 + if (vesafb_handle_tasks())
1233 + break;
1234 + wait_event_interruptible(vesafb_wait,
1235 + !list_empty(&vesafb_task_list));
1236 + try_to_freeze();
1237 + }
1238 +
1239 +out: DPRINTK("exiting the vesafb thread\n");
1240 + vesafb_pid = -1;
1241 +
1242 + /* Now that all callers know this thread is no longer running
1243 + * (pid < 0), allow them to continue. */
1244 + up(&vesafb_task_list_sem);
1245 + return err;
1246 +thr_end:
1247 + down(&vesafb_task_list_sem);
1248 + complete(&vesafb_th_completion);
1249 + goto out;
1250 +}
1251 +
1252 +int vesafb_queue_task(struct vesafb_task *tsk)
1253 +{
1254 + down(&vesafb_task_list_sem);
1255 + if (vesafb_pid < 0)
1256 + return -1;
1257 + list_add_tail(&tsk->node, &vesafb_task_list);
1258 + up(&vesafb_task_list_sem);
1259 + wake_up(&vesafb_wait);
1260 + return 0;
1261 +}
1262 +
1263 +int vesafb_wait_for_thread(void)
1264 +{
1265 + /* PID 0 means that the thread is still initializing. */
1266 + if (vesafb_pid < 0)
1267 + return -1;
1268 + wait_for_completion(&vesafb_th_completion);
1269 + return 0;
1270 +}
1271 +
1272 +int __init vesafb_init_thread(void)
1273 +{
1274 + vesafb_pid = kernel_thread(vesafb_thread,NULL,0);
1275 + return 0;
1276 +}
1277 +
1278 +#ifdef MODULE
1279 +void __exit vesafb_kill_thread(void)
1280 +{
1281 + struct vesafb_task *tsk;
1282 + if (vesafb_pid <= 0)
1283 + return;
1284 +
1285 + vesafb_create_task(tsk);
1286 + if (!tsk)
1287 + return;
1288 + tsk->flags |= TF_EXIT;
1289 + vesafb_queue_task(tsk);
1290 + vesafb_wait_for_task(tsk);
1291 + kfree(tsk);
1292 + return;
1293 +}
1294 +module_exit(vesafb_kill_thread);
1295 +#endif
1296 +module_init(vesafb_init_thread);
1297 +
1298 +EXPORT_SYMBOL_GPL(vesafb_queue_task);
1299 +EXPORT_SYMBOL_GPL(vesafb_wait_for_thread);
1300 +
1301 +MODULE_LICENSE("GPL");
1302 +MODULE_AUTHOR("Michal Januszewski");
1303 +
1304 diff --git a/drivers/video/vesafb-tng.c b/drivers/video/vesafb-tng.c
1305 new file mode 100644
1306 index 0000000..b4d4394
1307 --- /dev/null
1308 +++ b/drivers/video/vesafb-tng.c
1309 @@ -0,0 +1,1586 @@
1310 +/*
1311 + * Framebuffer driver for VBE 2.0+ compliant graphic boards
1312 + *
1313 + * (c) 2004-2006 Michal Januszewski <spock@gentoo.org>
1314 + * Based upon vesafb code by Gerd Knorr <kraxel@goldbach.in-berlin.de>
1315 + *
1316 + */
1317 +
1318 +#include <linux/module.h>
1319 +#include <linux/kernel.h>
1320 +#include <linux/errno.h>
1321 +#include <linux/string.h>
1322 +#include <linux/mm.h>
1323 +#include <linux/tty.h>
1324 +#include <linux/delay.h>
1325 +#include <linux/fb.h>
1326 +#include <linux/ioport.h>
1327 +#include <linux/init.h>
1328 +#include <linux/proc_fs.h>
1329 +#include <linux/completion.h>
1330 +#include <linux/platform_device.h>
1331 +#include <video/edid.h>
1332 +#include <video/vesa.h>
1333 +#include <video/vga.h>
1334 +#include <asm/io.h>
1335 +#include <asm/mtrr.h>
1336 +#include <asm/page.h>
1337 +#include <asm/pgtable.h>
1338 +#include "edid.h"
1339 +
1340 +#define dac_reg (0x3c8)
1341 +#define dac_val (0x3c9)
1342 +
1343 +#define VESAFB_NEED_EXACT_RES 1
1344 +#define VESAFB_NEED_EXACT_DEPTH 2
1345 +
1346 +/* --------------------------------------------------------------------- */
1347 +
1348 +static struct fb_var_screeninfo vesafb_defined __initdata = {
1349 + .activate = FB_ACTIVATE_NOW,
1350 + .height = 0,
1351 + .width = 0,
1352 + .right_margin = 32,
1353 + .upper_margin = 16,
1354 + .lower_margin = 4,
1355 + .vsync_len = 4,
1356 + .vmode = FB_VMODE_NONINTERLACED,
1357 +};
1358 +
1359 +static struct fb_fix_screeninfo vesafb_fix __initdata = {
1360 + .id = "VESA VGA",
1361 + .type = FB_TYPE_PACKED_PIXELS,
1362 + .accel = FB_ACCEL_NONE,
1363 +};
1364 +
1365 +static int mtrr = 0; /* disable mtrr by default */
1366 +static int blank = 1; /* enable blanking by default */
1367 +static int ypan = 0; /* 0 - nothing, 1 - ypan, 2 - ywrap */
1368 +static int pmi_setpal = 1; /* pmi for palette changes */
1369 +static u16 *pmi_base = NULL; /* protected mode interface location */
1370 +static void (*pmi_start)(void) = NULL;
1371 +static void (*pmi_pal)(void) = NULL;
1372 +static struct vesafb_vbe_ib vbe_ib;
1373 +static struct vesafb_mode_ib *vbe_modes;
1374 +static int vbe_modes_cnt = 0;
1375 +static struct fb_info *vesafb_info = NULL;
1376 +static int nocrtc = 0; /* ignore CRTC settings */
1377 +static int noedid __initdata = 0; /* don't try DDC transfers */
1378 +static int vram_remap __initdata = 0; /* set amount of memory to be used */
1379 +static int vram_total __initdata = 0; /* set total amount of memory */
1380 +static u16 maxclk __initdata = 0; /* maximum pixel clock */
1381 +static u16 maxvf __initdata = 0; /* maximum vertical frequency */
1382 +static u16 maxhf __initdata = 0; /* maximum horizontal frequency */
1383 +static int gtf __initdata = 0; /* forces use of the GTF */
1384 +static char *mode_option __initdata = NULL;
1385 +static u16 vbemode __initdata = 0;
1386 +
1387 +/* --------------------------------------------------------------------- */
1388 +
1389 +static int vesafb_find_vbe_mode(int xres, int yres, int depth,
1390 + unsigned char flags)
1391 +{
1392 + int i, match = -1, h = 0, d = 0x7fffffff;
1393 +
1394 + for (i = 0; i < vbe_modes_cnt; i++) {
1395 + h = abs(vbe_modes[i].x_res - xres) +
1396 + abs(vbe_modes[i].y_res - yres) +
1397 + abs(depth - vbe_modes[i].depth);
1398 + if (h == 0)
1399 + return i;
1400 + if (h < d || (h == d && vbe_modes[i].depth > depth)) {
1401 + d = h;
1402 + match = i;
1403 + }
1404 + }
1405 + i = 1;
1406 +
1407 + if (flags & VESAFB_NEED_EXACT_DEPTH && vbe_modes[match].depth != depth)
1408 + i = 0;
1409 + if (flags & VESAFB_NEED_EXACT_RES && d > 24)
1410 + i = 0;
1411 + if (i != 0)
1412 + return match;
1413 + else
1414 + return -1;
1415 +}
1416 +
1417 +static int vesafb_pan_display(struct fb_var_screeninfo *var,
1418 + struct fb_info *info)
1419 +{
1420 + int offset;
1421 +
1422 + offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4;
1423 +
1424 + /* It turns out it's not the best idea to do panning via vm86,
1425 + * so we only allow it if we have a PMI. */
1426 + if (pmi_start) {
1427 + __asm__ __volatile__(
1428 + "call *(%%edi)"
1429 + : /* no return value */
1430 + : "a" (0x4f07), /* EAX */
1431 + "b" (0), /* EBX */
1432 + "c" (offset), /* ECX */
1433 + "d" (offset >> 16), /* EDX */
1434 + "D" (&pmi_start)); /* EDI */
1435 + }
1436 + return 0;
1437 +}
1438 +
1439 +static int vesafb_blank(int blank, struct fb_info *info)
1440 +{
1441 + struct vesafb_task *tsk;
1442 + int err = 1;
1443 +
1444 + if (vbe_ib.capabilities & VBE_CAP_VGACOMPAT) {
1445 + int loop = 10000;
1446 + u8 seq = 0, crtc17 = 0;
1447 +
1448 + if (blank == FB_BLANK_POWERDOWN) {
1449 + seq = 0x20;
1450 + crtc17 = 0x00;
1451 + err = 0;
1452 + } else {
1453 + seq = 0x00;
1454 + crtc17 = 0x80;
1455 + err = (blank == FB_BLANK_UNBLANK) ? 0 : -EINVAL;
1456 + }
1457 +
1458 + vga_wseq(NULL, 0x00, 0x01);
1459 + seq |= vga_rseq(NULL, 0x01) & ~0x20;
1460 + vga_wseq(NULL, 0x00, seq);
1461 +
1462 + crtc17 |= vga_rcrt(NULL, 0x17) & ~0x80;
1463 + while (loop--);
1464 + vga_wcrt(NULL, 0x17, crtc17);
1465 + vga_wseq(NULL, 0x00, 0x03);
1466 + } else {
1467 + vesafb_create_task (tsk);
1468 + if (!tsk)
1469 + return -ENOMEM;
1470 + tsk->regs.eax = 0x4f10;
1471 + switch (blank) {
1472 + case FB_BLANK_UNBLANK:
1473 + tsk->regs.ebx = 0x0001;
1474 + break;
1475 + case FB_BLANK_NORMAL:
1476 + tsk->regs.ebx = 0x0101; /* standby */
1477 + break;
1478 + case FB_BLANK_POWERDOWN:
1479 + tsk->regs.ebx = 0x0401; /* powerdown */
1480 + break;
1481 + default:
1482 + goto out;
1483 + }
1484 + tsk->flags = TF_CALL;
1485 + if (!vesafb_queue_task (tsk))
1486 + vesafb_wait_for_task(tsk);
1487 +
1488 + if ((tsk->regs.eax & 0xffff) == 0x004f)
1489 + err = 0;
1490 +out: kfree(tsk);
1491 + }
1492 + return err;
1493 +}
1494 +
1495 +static int vesafb_setpalette(struct vesafb_pal_entry *entries, int count,
1496 + int start, struct fb_info *info)
1497 +{
1498 + struct vesafb_task *tsk;
1499 + int i = ((struct vesafb_par*)info->par)->mode_idx;
1500 + int ret = 0;
1501 +
1502 + /* We support palette modifications for 8 bpp modes only, so
1503 + * there can never be more than 256 entries. */
1504 + if (start + count > 256)
1505 + return -EINVAL;
1506 +
1507 + /* Use VGA registers if mode is VGA-compatible. */
1508 + if (i >= 0 && i < vbe_modes_cnt &&
1509 + vbe_modes[i].mode_attr & VBE_MODE_VGACOMPAT) {
1510 + for (i = 0; i < count; i++) {
1511 + outb_p(start + i, dac_reg);
1512 + outb_p(entries[i].red, dac_val);
1513 + outb_p(entries[i].green, dac_val);
1514 + outb_p(entries[i].blue, dac_val);
1515 + }
1516 + } else if (pmi_setpal) {
1517 + __asm__ __volatile__(
1518 + "call *(%%esi)"
1519 + : /* no return value */
1520 + : "a" (0x4f09), /* EAX */
1521 + "b" (0), /* EBX */
1522 + "c" (count), /* ECX */
1523 + "d" (start), /* EDX */
1524 + "D" (entries), /* EDI */
1525 + "S" (&pmi_pal)); /* ESI */
1526 + } else {
1527 + vesafb_create_task (tsk);
1528 + if (!tsk)
1529 + return -ENOMEM;
1530 + tsk->regs.eax = 0x4f09;
1531 + tsk->regs.ebx = 0x0;
1532 + tsk->regs.ecx = count;
1533 + tsk->regs.edx = start;
1534 + tsk->buf = entries;
1535 + tsk->buf_len = sizeof(struct vesafb_pal_entry) * count;
1536 + tsk->flags = TF_CALL | TF_BUF_DI;
1537 +
1538 + if (!vesafb_queue_task (tsk))
1539 + vesafb_wait_for_task(tsk);
1540 + if ((tsk->regs.eax & 0xffff) != 0x004f)
1541 + ret = 1;
1542 + kfree(tsk);
1543 + }
1544 + return ret;
1545 +}
1546 +
1547 +static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
1548 + unsigned blue, unsigned transp,
1549 + struct fb_info *info)
1550 +{
1551 + struct vesafb_pal_entry entry;
1552 + int shift = 16 - info->var.green.length;
1553 + int ret = 0;
1554 +
1555 + if (regno >= info->cmap.len)
1556 + return -EINVAL;
1557 +
1558 + if (info->var.bits_per_pixel == 8) {
1559 + entry.red = red >> shift;
1560 + entry.green = green >> shift;
1561 + entry.blue = blue >> shift;
1562 + entry.pad = 0;
1563 +
1564 + ret = vesafb_setpalette(&entry, 1, regno, info);
1565 + } else if (regno < 16) {
1566 + switch (info->var.bits_per_pixel) {
1567 + case 16:
1568 + if (info->var.red.offset == 10) {
1569 + /* 1:5:5:5 */
1570 + ((u32*) (info->pseudo_palette))[regno] =
1571 + ((red & 0xf800) >> 1) |
1572 + ((green & 0xf800) >> 6) |
1573 + ((blue & 0xf800) >> 11);
1574 + } else {
1575 + /* 0:5:6:5 */
1576 + ((u32*) (info->pseudo_palette))[regno] =
1577 + ((red & 0xf800) ) |
1578 + ((green & 0xfc00) >> 5) |
1579 + ((blue & 0xf800) >> 11);
1580 + }
1581 + break;
1582 +
1583 + case 24:
1584 + case 32:
1585 + red >>= 8;
1586 + green >>= 8;
1587 + blue >>= 8;
1588 + ((u32 *)(info->pseudo_palette))[regno] =
1589 + (red << info->var.red.offset) |
1590 + (green << info->var.green.offset) |
1591 + (blue << info->var.blue.offset);
1592 + break;
1593 + }
1594 + }
1595 + return ret;
1596 +}
1597 +
1598 +static int vesafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1599 +{
1600 + struct vesafb_pal_entry *entries;
1601 + int shift = 16 - info->var.green.length;
1602 + int i, ret = 0;
1603 +
1604 + if (info->var.bits_per_pixel == 8) {
1605 + if (cmap->start + cmap->len > info->cmap.start +
1606 + info->cmap.len || cmap->start < info->cmap.start)
1607 + return -EINVAL;
1608 +
1609 + entries = vmalloc(sizeof(struct vesafb_pal_entry) * cmap->len);
1610 + if (!entries)
1611 + return -ENOMEM;
1612 + for (i = 0; i < cmap->len; i++) {
1613 + entries[i].red = cmap->red[i] >> shift;
1614 + entries[i].green = cmap->green[i] >> shift;
1615 + entries[i].blue = cmap->blue[i] >> shift;
1616 + entries[i].pad = 0;
1617 + }
1618 + ret = vesafb_setpalette(entries, cmap->len, cmap->start, info);
1619 + vfree(entries);
1620 + } else {
1621 + /* For modes with bpp > 8, we only set the pseudo palette in
1622 + * the fb_info struct. We rely on vesafb_setcolreg to do all
1623 + * sanity checking. */
1624 + for (i = 0; i < cmap->len; i++) {
1625 + ret += vesafb_setcolreg(cmap->start + i, cmap->red[i],
1626 + cmap->green[i], cmap->blue[i],
1627 + 0, info);
1628 + }
1629 + }
1630 + return ret;
1631 +}
1632 +
1633 +static int vesafb_set_par(struct fb_info *info)
1634 +{
1635 + struct vesafb_par *par = (struct vesafb_par *) info->par;
1636 + struct vesafb_task *tsk;
1637 + struct vesafb_crtc_ib *crtc = NULL;
1638 + struct vesafb_mode_ib *mode = NULL;
1639 + int i, err = 0, depth = info->var.bits_per_pixel;
1640 +
1641 + if (depth > 8 && depth != 32)
1642 + depth = info->var.red.length + info->var.green.length +
1643 + info->var.blue.length;
1644 +
1645 + i = vesafb_find_vbe_mode(info->var.xres, info->var.yres, depth,
1646 + VESAFB_NEED_EXACT_RES |
1647 + VESAFB_NEED_EXACT_DEPTH);
1648 + if (i >= 0)
1649 + mode = &vbe_modes[i];
1650 + else
1651 + return -EINVAL;
1652 +
1653 + vesafb_create_task (tsk);
1654 + if (!tsk)
1655 + return -ENOMEM;
1656 + tsk->regs.eax = 0x4f02;
1657 + tsk->regs.ebx = mode->mode_id | 0x4000; /* use LFB */
1658 + tsk->flags = TF_CALL;
1659 +
1660 + if (vbe_ib.vbe_version >= 0x0300 && !nocrtc &&
1661 + info->var.pixclock != 0) {
1662 + tsk->regs.ebx |= 0x0800; /* use CRTC data */
1663 + tsk->flags |= TF_BUF_DI;
1664 + crtc = kmalloc(sizeof(struct vesafb_crtc_ib), GFP_KERNEL);
1665 + if (!crtc) {
1666 + err = -ENOMEM;
1667 + goto out;
1668 + }
1669 + crtc->horiz_start = info->var.xres + info->var.right_margin;
1670 + crtc->horiz_end = crtc->horiz_start + info->var.hsync_len;
1671 + crtc->horiz_total = crtc->horiz_end + info->var.left_margin;
1672 +
1673 + crtc->vert_start = info->var.yres + info->var.lower_margin;
1674 + crtc->vert_end = crtc->vert_start + info->var.vsync_len;
1675 + crtc->vert_total = crtc->vert_end + info->var.upper_margin;
1676 +
1677 + crtc->pixel_clock = PICOS2KHZ(info->var.pixclock) * 1000;
1678 + crtc->refresh_rate = (u16)(100 * (crtc->pixel_clock /
1679 + (crtc->vert_total * crtc->horiz_total)));
1680 + crtc->flags = 0;
1681 +
1682 + if (info->var.vmode & FB_VMODE_DOUBLE)
1683 + crtc->flags |= 0x1;
1684 + if (info->var.vmode & FB_VMODE_INTERLACED)
1685 + crtc->flags |= 0x2;
1686 + if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
1687 + crtc->flags |= 0x4;
1688 + if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
1689 + crtc->flags |= 0x8;
1690 + memcpy(&par->crtc, crtc, sizeof(struct vesafb_crtc_ib));
1691 + } else
1692 + memset(&par->crtc, 0, sizeof(struct vesafb_crtc_ib));
1693 +
1694 + tsk->buf = (void*)crtc;
1695 + tsk->buf_len = sizeof(struct vesafb_crtc_ib);
1696 +
1697 + if (vesafb_queue_task (tsk)) {
1698 + err = -EINVAL;
1699 + goto out;
1700 + }
1701 + vesafb_wait_for_task(tsk);
1702 +
1703 + if ((tsk->regs.eax & 0xffff) != 0x004f) {
1704 + printk(KERN_ERR "vesafb: mode switch failed (eax: 0x%lx)\n",
1705 + tsk->regs.eax);
1706 + err = -EINVAL;
1707 + goto out;
1708 + }
1709 + par->mode_idx = i;
1710 +
1711 + /* For 8bpp modes, always try to set the DAC to 8 bits. */
1712 + if (vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC &&
1713 + mode->bits_per_pixel <= 8) {
1714 + vesafb_reset_task(tsk);
1715 + tsk->flags = TF_CALL;
1716 + tsk->regs.eax = 0x4f08;
1717 + tsk->regs.ebx = 0x0800;
1718 +
1719 + if (!vesafb_queue_task (tsk))
1720 + vesafb_wait_for_task(tsk);
1721 +
1722 + if ((tsk->regs.eax & 0xffff) != 0x004f ||
1723 + ((tsk->regs.ebx & 0xff00) >> 8) != 8) {
1724 + /* We've failed to set the DAC palette format -
1725 + * time to correct var. */
1726 + info->var.red.length = 6;
1727 + info->var.green.length = 6;
1728 + info->var.blue.length = 6;
1729 + }
1730 + }
1731 +
1732 + info->fix.visual = (info->var.bits_per_pixel == 8) ?
1733 + FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1734 + info->fix.line_length = mode->bytes_per_scan_line;
1735 +
1736 + DPRINTK("set new mode %dx%d-%d (0x%x)\n",
1737 + info->var.xres, info->var.yres, info->var.bits_per_pixel,
1738 + mode->mode_id);
1739 +
1740 +out: if (crtc != NULL)
1741 + kfree(crtc);
1742 + kfree(tsk);
1743 +
1744 + return err;
1745 +}
1746 +
1747 +static void vesafb_setup_var(struct fb_var_screeninfo *var, struct fb_info *info,
1748 + struct vesafb_mode_ib *mode)
1749 +{
1750 + var->xres = mode->x_res;
1751 + var->yres = mode->y_res;
1752 + var->xres_virtual = mode->x_res;
1753 + var->yres_virtual = (ypan) ?
1754 + info->fix.smem_len / mode->bytes_per_scan_line :
1755 + mode->y_res;
1756 + var->xoffset = 0;
1757 + var->yoffset = 0;
1758 + var->bits_per_pixel = mode->bits_per_pixel;
1759 +
1760 + if (var->bits_per_pixel == 15)
1761 + var->bits_per_pixel = 16;
1762 +
1763 + if (var->bits_per_pixel > 8) {
1764 + var->red.offset = mode->red_off;
1765 + var->red.length = mode->red_len;
1766 + var->green.offset = mode->green_off;
1767 + var->green.length = mode->green_len;
1768 + var->blue.offset = mode->blue_off;
1769 + var->blue.length = mode->blue_len;
1770 + var->transp.offset = mode->rsvd_off;
1771 + var->transp.length = mode->rsvd_len;
1772 +
1773 + DPRINTK("directcolor: size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
1774 + mode->rsvd_len,
1775 + mode->red_len,
1776 + mode->green_len,
1777 + mode->blue_len,
1778 + mode->rsvd_off,
1779 + mode->red_off,
1780 + mode->green_off,
1781 + mode->blue_off);
1782 + } else {
1783 + var->red.offset = 0;
1784 + var->green.offset = 0;
1785 + var->blue.offset = 0;
1786 + var->transp.offset = 0;
1787 +
1788 + /* We're assuming that we can switch the DAC to 8 bits. If
1789 + * this proves to be incorrect, we'll update the fields
1790 + * later in set_par(). */
1791 + if (vbe_ib.capabilities & VBE_CAP_CAN_SWITCH_DAC) {
1792 + var->red.length = 8;
1793 + var->green.length = 8;
1794 + var->blue.length = 8;
1795 + var->transp.length = 0;
1796 + } else {
1797 + var->red.length = 6;
1798 + var->green.length = 6;
1799 + var->blue.length = 6;
1800 + var->transp.length = 0;
1801 + }
1802 + }
1803 +}
1804 +
1805 +static void inline vesafb_check_limits(struct fb_var_screeninfo *var,
1806 + struct fb_info *info)
1807 +{
1808 + struct fb_videomode *mode;
1809 +
1810 + if (!var->pixclock)
1811 + return;
1812 + if (vbe_ib.vbe_version < 0x0300) {
1813 + fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60, var, info);
1814 + return;
1815 + }
1816 + if (!fb_validate_mode(var, info))
1817 + return;
1818 + mode = fb_find_best_mode(var, &info->modelist);
1819 + if (mode) {
1820 + DPRINTK("find_best_mode: %d %d @ %d (vmode: %d)\n",
1821 + mode->xres, mode->yres, mode->refresh, mode->vmode);
1822 + if (mode->xres == var->xres && mode->yres == var->yres &&
1823 + !(mode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))) {
1824 + fb_videomode_to_var(var, mode);
1825 + return;
1826 + }
1827 + }
1828 + if (info->monspecs.gtf && !fb_get_mode(FB_MAXTIMINGS, 0, var, info))
1829 + return;
1830 + /* Use default refresh rate */
1831 + var->pixclock = 0;
1832 +}
1833 +
1834 +static int vesafb_check_var(struct fb_var_screeninfo *var,
1835 + struct fb_info *info)
1836 +{
1837 + int match = -1;
1838 + int depth = var->red.length + var->green.length + var->blue.length;
1839 +
1840 + /* Various apps will use bits_per_pixel to set the color depth,
1841 + * which is theoretically incorrect, but which we'll try to handle
1842 + * here. */
1843 + if (depth == 0 || abs(depth - var->bits_per_pixel) >= 8)
1844 + depth = var->bits_per_pixel;
1845 + match = vesafb_find_vbe_mode(var->xres, var->yres, depth,
1846 + VESAFB_NEED_EXACT_RES);
1847 +
1848 + if (match == -1) {
1849 + DPRINTK("vesafb: mode %dx%d-%d not found\n", var->xres,
1850 + var->yres, depth);
1851 + return -EINVAL;
1852 + }
1853 +
1854 + vesafb_setup_var(var, info, &vbe_modes[match]);
1855 + DPRINTK("found mode 0x%x (%dx%d-%dbpp)\n",
1856 + vbe_modes[match].mode_id, vbe_modes[match].x_res,
1857 + vbe_modes[match].y_res, vbe_modes[match].depth);
1858 +
1859 + /* Check whether we have remapped enough memory for this mode. */
1860 + if (var->yres * vbe_modes[match].bytes_per_scan_line >
1861 + info->fix.smem_len) {
1862 + return -EINVAL;
1863 + }
1864 +
1865 + if ((var->vmode & FB_VMODE_DOUBLE) &&
1866 + !(vbe_modes[match].mode_attr & 0x100))
1867 + var->vmode &= ~FB_VMODE_DOUBLE;
1868 + if ((var->vmode & FB_VMODE_INTERLACED) &&
1869 + !(vbe_modes[match].mode_attr & 0x200))
1870 + var->vmode &= ~FB_VMODE_INTERLACED;
1871 + vesafb_check_limits(var, info);
1872 + return 0;
1873 +}
1874 +
1875 +static int vesafb_open(struct fb_info *info, int user)
1876 +{
1877 + struct vesafb_task *tsk = NULL;
1878 + struct vesafb_par *par = info->par;
1879 + int cnt = atomic_read(&par->ref_count);
1880 +
1881 + if (!cnt) {
1882 + vesafb_create_task(tsk);
1883 + if (!tsk)
1884 + goto out;
1885 +
1886 + /* Get the VBE state buffer size. We want all available
1887 + * hardware state data (CL = 0x0f). */
1888 + tsk->regs.eax = 0x4f04;
1889 + tsk->regs.ecx = 0x000f;
1890 + tsk->regs.edx = 0x0000;
1891 + tsk->flags = TF_CALL;
1892 +
1893 + if (vesafb_queue_task(tsk))
1894 + goto out;
1895 +
1896 + vesafb_wait_for_task(tsk);
1897 +
1898 + if ((tsk->regs.eax & 0xffff) != 0x004f) {
1899 + printk(KERN_WARNING "vesafb: VBE state buffer size "
1900 + "cannot be determined (eax: 0x%lx)\n",
1901 + tsk->regs.eax);
1902 + goto out;
1903 + }
1904 +
1905 + par->vbe_state_size = 64 * (tsk->regs.ebx & 0xffff);
1906 + par->vbe_state = kzalloc(par->vbe_state_size, GFP_KERNEL);
1907 + if (!par->vbe_state)
1908 + goto out;
1909 +
1910 + vesafb_reset_task(tsk);
1911 + tsk->regs.eax = 0x4f04;
1912 + tsk->regs.ecx = 0x000f;
1913 + tsk->regs.edx = 0x0001;
1914 + tsk->flags = TF_CALL | TF_BUF_BX | TF_RETURN_BUF;
1915 + tsk->buf = (void*)(par->vbe_state);
1916 + tsk->buf_len = par->vbe_state_size;
1917 +
1918 + if (vesafb_queue_task(tsk))
1919 + goto getstate_failed;
1920 + vesafb_wait_for_task(tsk);
1921 +
1922 + if ((tsk->regs.eax & 0xffff) != 0x004f) {
1923 + printk(KERN_WARNING "vesafb: VBE get state call "
1924 + "failed (eax: 0x%lx)\n", tsk->regs.eax);
1925 + goto getstate_failed;
1926 + }
1927 + }
1928 +out:
1929 + atomic_inc(&par->ref_count);
1930 + if (tsk)
1931 + kfree(tsk);
1932 + return 0;
1933 +
1934 +getstate_failed:
1935 + kfree(par->vbe_state);
1936 + par->vbe_state = NULL;
1937 + par->vbe_state_size = 0;
1938 + goto out;
1939 +}
1940 +
1941 +static int vesafb_release(struct fb_info *info, int user)
1942 +{
1943 + struct vesafb_task *tsk = NULL;
1944 + struct vesafb_par *par = info->par;
1945 + int cnt = atomic_read(&par->ref_count);
1946 +
1947 + if (!cnt)
1948 + return -EINVAL;
1949 +
1950 + if (cnt == 1 && par->vbe_state && par->vbe_state_size) {
1951 + vesafb_create_task(tsk);
1952 + if (!tsk)
1953 + goto out;
1954 +
1955 + tsk->regs.eax = 0x0003;
1956 + tsk->regs.ebx = 0x0000;
1957 + tsk->flags = TF_CALL;
1958 +
1959 + if (vesafb_queue_task(tsk))
1960 + goto out;
1961 +
1962 + vesafb_wait_for_task(tsk);
1963 +
1964 + vesafb_reset_task(tsk);
1965 + tsk->regs.eax = 0x4f04;
1966 + tsk->regs.ecx = 0x000f;
1967 + tsk->regs.edx = 0x0002;
1968 + tsk->buf = (void*)(par->vbe_state);
1969 + tsk->buf_len = par->vbe_state_size;
1970 + tsk->flags = TF_CALL | TF_BUF_BX;
1971 +
1972 + if (vesafb_queue_task(tsk))
1973 + goto out;
1974 +
1975 + vesafb_wait_for_task(tsk);
1976 +
1977 + if ((tsk->regs.eax & 0xffff) != 0x004f)
1978 + printk(KERN_WARNING "vesafb: VBE state restore call "
1979 + "failed (eax: 0x%lx)\n",
1980 + tsk->regs.eax);
1981 + }
1982 +out:
1983 + atomic_dec(&par->ref_count);
1984 + if (tsk)
1985 + kfree(tsk);
1986 + return 0;
1987 +}
1988 +
1989 +static int __init vesafb_probe(struct platform_device *device);
1990 +
1991 +static struct fb_ops vesafb_ops = {
1992 + .owner = THIS_MODULE,
1993 + .fb_open = vesafb_open,
1994 + .fb_release = vesafb_release,
1995 + .fb_setcolreg = vesafb_setcolreg,
1996 + .fb_setcmap = vesafb_setcmap,
1997 + .fb_pan_display = vesafb_pan_display,
1998 + .fb_blank = vesafb_blank,
1999 + .fb_fillrect = cfb_fillrect,
2000 + .fb_copyarea = cfb_copyarea,
2001 + .fb_imageblit = cfb_imageblit,
2002 + .fb_check_var = vesafb_check_var,
2003 + .fb_set_par = vesafb_set_par
2004 +};
2005 +
2006 +static struct platform_driver vesafb_driver = {
2007 + .probe = vesafb_probe,
2008 + .driver = {
2009 + .name = "vesafb",
2010 + },
2011 +};
2012 +
2013 +static struct platform_device *vesafb_device;
2014 +
2015 +#ifndef MODULE
2016 +int __init vesafb_setup(char *options)
2017 +{
2018 + char *this_opt;
2019 +
2020 + if (!options || !*options)
2021 + return 0;
2022 +
2023 + DPRINTK("options %s\n",options);
2024 +
2025 + while ((this_opt = strsep(&options, ",")) != NULL) {
2026 + if (!*this_opt) continue;
2027 +
2028 + DPRINTK("this_opt: %s\n",this_opt);
2029 +
2030 + if (! strcmp(this_opt, "redraw"))
2031 + ypan=0;
2032 + else if (! strcmp(this_opt, "ypan"))
2033 + ypan=1;
2034 + else if (! strcmp(this_opt, "ywrap"))
2035 + ypan=2;
2036 + else if (! strcmp(this_opt, "vgapal"))
2037 + pmi_setpal=0;
2038 + else if (! strcmp(this_opt, "pmipal"))
2039 + pmi_setpal=1;
2040 + else if (! strncmp(this_opt, "mtrr:", 5))
2041 + mtrr = simple_strtoul(this_opt+5, NULL, 0);
2042 + else if (! strcmp(this_opt, "nomtrr"))
2043 + mtrr=0;
2044 + else if (! strcmp(this_opt, "nocrtc"))
2045 + nocrtc=1;
2046 + else if (! strcmp(this_opt, "noedid"))
2047 + noedid=1;
2048 + else if (! strcmp(this_opt, "noblank"))
2049 + blank=0;
2050 + else if (! strcmp(this_opt, "gtf"))
2051 + gtf=1;
2052 + else if (! strncmp(this_opt, "vtotal:", 7))
2053 + vram_total = simple_strtoul(this_opt + 7, NULL, 0);
2054 + else if (! strncmp(this_opt, "vremap:", 7))
2055 + vram_remap = simple_strtoul(this_opt + 7, NULL, 0);
2056 + else if (! strncmp(this_opt, "maxhf:", 6))
2057 + maxhf = simple_strtoul(this_opt + 6, NULL, 0);
2058 + else if (! strncmp(this_opt, "maxvf:", 6))
2059 + maxvf = simple_strtoul(this_opt + 6, NULL, 0);
2060 + else if (! strncmp(this_opt, "maxclk:", 7))
2061 + maxclk = simple_strtoul(this_opt + 7, NULL, 0);
2062 + else if (! strncmp(this_opt, "vbemode:", 8))
2063 + vbemode = simple_strtoul(this_opt + 8, NULL,0);
2064 + else if (this_opt[0] >= '0' && this_opt[0] <= '9') {
2065 + DPRINTK("mode_option: %s\n",this_opt);
2066 + mode_option = this_opt;
2067 + } else {
2068 + printk(KERN_WARNING
2069 + "vesafb: unrecognized option %s\n", this_opt);
2070 + }
2071 + }
2072 +
2073 + return 0;
2074 +}
2075 +#endif /* !MODULE */
2076 +
2077 +static int vesafb_read_proc_modes(char *buf, char **start, off_t offset,
2078 + int len, int *eof, void *private)
2079 +{
2080 + int clen = 0, i;
2081 +
2082 + for (i = 0; i < vbe_modes_cnt; i++) {
2083 + clen += min(snprintf(buf + clen, len - clen, "%dx%d-%d\n", vbe_modes[i].x_res,
2084 + vbe_modes[i].y_res, vbe_modes[i].depth), len - clen);
2085 + }
2086 + *eof = 1;
2087 + return clen;
2088 +}
2089 +
2090 +static int vesafb_read_proc_vbe_info(char *buf, char **start, off_t offset,
2091 + int len, int *eof, void *private)
2092 +{
2093 + int clen = 0;
2094 +
2095 + clen += min(snprintf(buf + clen, len, "Version: %d.%d\n",
2096 + ((vbe_ib.vbe_version & 0xff00) >> 8),
2097 + vbe_ib.vbe_version & 0xff), len);
2098 + clen += min(snprintf(buf + clen, len - clen, "Vendor: %s\n",
2099 + (char*)vbe_ib.oem_vendor_name_ptr), len - clen);
2100 + clen += min(snprintf(buf + clen, len - clen, "Product: %s\n",
2101 + (char*)vbe_ib.oem_product_name_ptr), len - clen);
2102 + clen += min(snprintf(buf + clen, len - clen, "OEM rev: %s\n",
2103 + (char*)vbe_ib.oem_product_rev_ptr), len - clen);
2104 + clen += min(snprintf(buf + clen, len - clen, "OEM string: %s\n",
2105 + (char*)vbe_ib.oem_string_ptr), len - clen);
2106 +
2107 + *eof = 1;
2108 + return clen;
2109 +}
2110 +
2111 +static int __init inline vesafb_vbe_getinfo(struct vesafb_task *tsk)
2112 +{
2113 + tsk->regs.eax = 0x4f00;
2114 + tsk->flags = TF_CALL | TF_GETVBEIB;
2115 + tsk->buf = &vbe_ib;
2116 + tsk->buf_len = sizeof(vbe_ib);
2117 + if (vesafb_queue_task (tsk))
2118 + return -EINVAL;
2119 + vesafb_wait_for_task(tsk);
2120 +
2121 + if (vbe_ib.vbe_version < 0x0200) {
2122 + printk(KERN_ERR "vesafb: Sorry, pre-VBE 2.0 cards are "
2123 + "not supported.\n");
2124 + return -EINVAL;
2125 + }
2126 +
2127 + if ((tsk->regs.eax & 0xffff) != 0x004f) {
2128 + printk(KERN_ERR "vesafb: Getting mode info block failed "
2129 + "(eax=0x%x)\n", (u32)tsk->regs.eax);
2130 + return -EINVAL;
2131 + }
2132 +
2133 + printk(KERN_INFO "vesafb: %s, %s, %s (OEM: %s)\n",
2134 + (char*)vbe_ib.oem_vendor_name_ptr,
2135 + (char*)vbe_ib.oem_product_name_ptr,
2136 + (char*)vbe_ib.oem_product_rev_ptr,
2137 + (char*)vbe_ib.oem_string_ptr);
2138 +
2139 + printk(KERN_INFO "vesafb: VBE version: %d.%d\n",
2140 + ((vbe_ib.vbe_version & 0xff00) >> 8),
2141 + vbe_ib.vbe_version & 0xff);
2142 + return 0;
2143 +}
2144 +
2145 +static int __init inline vesafb_vbe_getmodes(struct vesafb_task *tsk)
2146 +{
2147 + u16 *mode = 0;
2148 + int off = 0;
2149 +
2150 + /* Count available modes. */
2151 + mode = (u16*)vbe_ib.mode_list_ptr;
2152 + while (*mode != 0xffff) {
2153 + vbe_modes_cnt++;
2154 + mode++;
2155 + }
2156 +
2157 + vbe_modes = kmalloc(sizeof(struct vesafb_mode_ib)*
2158 + vbe_modes_cnt, GFP_KERNEL);
2159 + if (!vbe_modes)
2160 + return -ENOMEM;
2161 +
2162 + /* Get mode info for all available modes. */
2163 + mode = (u16*)vbe_ib.mode_list_ptr;
2164 +
2165 + while (*mode != 0xffff) {
2166 + struct vesafb_mode_ib *mib;
2167 +
2168 + vesafb_reset_task(tsk);
2169 + tsk->regs.eax = 0x4f01;
2170 + tsk->regs.ecx = (u32) *mode;
2171 + tsk->flags = TF_CALL | TF_RETURN_BUF | TF_BUF_DI;
2172 + tsk->buf = vbe_modes+off;
2173 + tsk->buf_len = sizeof(struct vesafb_mode_ib);
2174 + if (vesafb_queue_task(tsk))
2175 + return -EINVAL;
2176 + vesafb_wait_for_task(tsk);
2177 + mib = p_mode(tsk->buf);
2178 + mib->mode_id = *mode;
2179 +
2180 + /* We only want modes that are supported with the currennt
2181 + * hardware configuration (D0), color (D3), graphics (D4)
2182 + * and that have support for the LFB (D7). */
2183 + if ((mib->mode_attr & 0x99) == 0x99 &&
2184 + mib->bits_per_pixel >= 8) {
2185 + off++;
2186 + } else {
2187 + vbe_modes_cnt--;
2188 + }
2189 + mode++;
2190 + mib->depth = mib->red_len + mib->green_len + mib->blue_len;
2191 + /* Handle 8bpp modes and modes with broken color component
2192 + * lengths. */
2193 + if (mib->depth == 0 ||
2194 + (mib->depth == 24 && mib->bits_per_pixel == 32))
2195 + mib->depth = mib->bits_per_pixel;
2196 + }
2197 +
2198 + return 0;
2199 +}
2200 +
2201 +static int __init inline vesafb_vbe_getpmi(struct vesafb_task *tsk)
2202 +{
2203 + int i;
2204 +
2205 + vesafb_reset_task(tsk);
2206 + tsk->regs.eax = 0x4f0a;
2207 + tsk->regs.ebx = 0x0;
2208 + tsk->flags = TF_CALL;
2209 + if (vesafb_queue_task(tsk))
2210 + return -EINVAL;
2211 + vesafb_wait_for_task(tsk);
2212 +
2213 + if ((tsk->regs.eax & 0xffff) != 0x004f || tsk->regs.es < 0xc000) {
2214 + pmi_setpal = ypan = 0;
2215 + } else {
2216 + pmi_base = (u16*)phys_to_virt(((u32)tsk->regs.es << 4) +
2217 + tsk->regs.edi);
2218 + pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
2219 + pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
2220 + printk(KERN_INFO "vesafb: protected mode interface info at "
2221 + "%04x:%04x\n",
2222 + (u16)tsk->regs.es, (u16)tsk->regs.edi);
2223 + printk(KERN_INFO "vesafb: pmi: set display start = %p, "
2224 + "set palette = %p\n", pmi_start, pmi_pal);
2225 +
2226 + if (pmi_base[3]) {
2227 + printk(KERN_INFO "vesafb: pmi: ports = ");
2228 + for (i = pmi_base[3]/2; pmi_base[i] != 0xffff; i++)
2229 + printk("%x ",pmi_base[i]);
2230 + printk("\n");
2231 +
2232 + /*
2233 + * memory areas not supported (yet?)
2234 + *
2235 + * Rules are: we have to set up a descriptor for the
2236 + * requested memory area and pass it in the ES register
2237 + * to the BIOS function.
2238 + */
2239 + if (pmi_base[i] != 0xffff) {
2240 + printk(KERN_INFO "vesafb: can't handle memory "
2241 + "requests, pmi disabled\n");
2242 + ypan = pmi_setpal = 0;
2243 + }
2244 + }
2245 + }
2246 + return 0;
2247 +}
2248 +
2249 +static int __init inline vesafb_vbe_getedid(struct vesafb_task *tsk,
2250 + struct fb_info *info)
2251 +{
2252 + int res = 0;
2253 +
2254 + if (noedid || vbe_ib.vbe_version < 0x0300)
2255 + return -EINVAL;
2256 +
2257 + vesafb_reset_task(tsk);
2258 + tsk->regs.eax = 0x4f15;
2259 + tsk->regs.ebx = 0;
2260 + tsk->regs.ecx = 0;
2261 + if (vesafb_queue_task(tsk))
2262 + return -EINVAL;
2263 + vesafb_wait_for_task(tsk);
2264 +
2265 + if ((tsk->regs.eax & 0xffff) != 0x004f)
2266 + return -EINVAL;
2267 +
2268 + if ((tsk->regs.ebx & 0x3) == 3) {
2269 + printk(KERN_INFO "vesafb: VBIOS/hardware supports both "
2270 + "DDC1 and DDC2 transfers\n");
2271 + } else if ((tsk->regs.ebx & 0x3) == 2) {
2272 + printk(KERN_INFO "vesafb: VBIOS/hardware supports DDC2 "
2273 + "transfers\n");
2274 + } else if ((tsk->regs.ebx & 0x3) == 1) {
2275 + printk(KERN_INFO "vesafb: VBIOS/hardware supports DDC1 "
2276 + "transfers\n");
2277 + } else {
2278 + printk(KERN_INFO "vesafb: VBIOS/hardware doesn't support "
2279 + "DDC transfers\n");
2280 + return -EINVAL;
2281 + }
2282 +
2283 + vesafb_reset_task(tsk);
2284 + tsk->regs.eax = 0x4f15;
2285 + tsk->regs.ebx = 1;
2286 + tsk->regs.ecx = tsk->regs.edx = 0;
2287 + tsk->flags = TF_CALL | TF_RETURN_BUF | TF_BUF_DI;
2288 + tsk->buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
2289 + tsk->buf_len = EDID_LENGTH;
2290 +
2291 + if (vesafb_queue_task(tsk)) {
2292 + res = -EINVAL;
2293 + goto out;
2294 + }
2295 + vesafb_wait_for_task(tsk);
2296 +
2297 + if ((tsk->regs.eax & 0xffff) == 0x004f) {
2298 + fb_edid_to_monspecs(tsk->buf, &info->monspecs);
2299 + fb_videomode_to_modelist(info->monspecs.modedb,
2300 + info->monspecs.modedb_len, &info->modelist);
2301 + if (info->monspecs.vfmax && info->monspecs.hfmax) {
2302 + /* If the maximum pixel clock wasn't specified in
2303 + * the EDID block, set it to 300 MHz. */
2304 + if (info->monspecs.dclkmax == 0)
2305 + info->monspecs.dclkmax = 300 * 1000000;
2306 + info->monspecs.gtf = 1;
2307 + } else {
2308 + res = -EINVAL;
2309 + }
2310 + }
2311 +
2312 +out: kfree(tsk->buf);
2313 + return res;
2314 +}
2315 +
2316 +static void __init inline vesafb_vbe_getmonspecs(struct vesafb_task *tsk,
2317 + struct fb_info *info)
2318 +{
2319 + struct fb_var_screeninfo var;
2320 + int i;
2321 + memset(&info->monspecs, 0, sizeof(struct fb_monspecs));
2322 +
2323 + /* If we didn't get all necessary data from the EDID block,
2324 + * mark it as incompatible with the GTF. */
2325 + if (vesafb_vbe_getedid(tsk, info))
2326 + info->monspecs.gtf = 0;
2327 +
2328 + /* Kernel command line overrides. */
2329 + if (maxclk)
2330 + info->monspecs.dclkmax = maxclk * 1000000;
2331 + if (maxvf)
2332 + info->monspecs.vfmax = maxvf;
2333 + if (maxhf)
2334 + info->monspecs.hfmax = maxhf * 1000;
2335 +
2336 + /* In case DDC transfers are not supported the user can provide
2337 + * monitor limits manually. Lower limits are set to "safe" values. */
2338 + if (info->monspecs.gtf == 0 && maxclk && maxvf && maxhf) {
2339 + info->monspecs.dclkmin = 0;
2340 + info->monspecs.vfmin = 60;
2341 + info->monspecs.hfmin = 29000;
2342 + info->monspecs.gtf = 1;
2343 + }
2344 +
2345 + if (info->monspecs.gtf) {
2346 + printk(KERN_INFO
2347 + "vesafb: monitor limits: vf = %d Hz, hf = %d kHz, "
2348 + "clk = %d MHz\n", info->monspecs.vfmax,
2349 + (int)(info->monspecs.hfmax / 1000),
2350 + (int)(info->monspecs.dclkmax / 1000000));
2351 + /* Add valid VESA video modes to our modelist. */
2352 + for (i = 0; i < VESA_MODEDB_SIZE; i++) {
2353 + fb_videomode_to_var(&var, (struct fb_videomode *)
2354 + &vesa_modes[i]);
2355 + if (!fb_validate_mode(&var, info))
2356 + fb_add_videomode((struct fb_videomode *)
2357 + &vesa_modes[i],
2358 + &info->modelist);
2359 + }
2360 + } else {
2361 + /* Add all VESA video modes to our modelist. */
2362 + fb_videomode_to_modelist((struct fb_videomode *)vesa_modes,
2363 + VESA_MODEDB_SIZE, &info->modelist);
2364 + printk(KERN_INFO "vesafb: no monitor limits have been set\n");
2365 + }
2366 + return;
2367 +}
2368 +
2369 +static int __init inline vesafb_vbe_init(struct fb_info *info)
2370 +{
2371 + struct vesafb_task *tsk;
2372 + int res = 0;
2373 +
2374 + vesafb_create_task(tsk);
2375 + if (!tsk)
2376 + return -EINVAL;
2377 + if ((res = vesafb_vbe_getinfo(tsk)) != 0)
2378 + goto out;
2379 + if ((res = vesafb_vbe_getmodes(tsk)) != 0)
2380 + goto out;
2381 + if (pmi_setpal || ypan)
2382 + vesafb_vbe_getpmi(tsk);
2383 +
2384 + INIT_LIST_HEAD(&info->modelist);
2385 + vesafb_vbe_getmonspecs(tsk, info);
2386 +
2387 +out: kfree(tsk);
2388 + return res;
2389 +}
2390 +
2391 +static int __init decode_mode(u32 *xres, u32 *yres, u32 *bpp, u32 *refresh)
2392 +{
2393 + int len = strlen(mode_option), i, err = 0;
2394 + u8 res_specified = 0, bpp_specified = 0, refresh_specified = 0,
2395 + yres_specified = 0;
2396 +
2397 + for (i = len-1; i >= 0; i--) {
2398 + switch (mode_option[i]) {
2399 + case '@':
2400 + len = i;
2401 + if (!refresh_specified && !bpp_specified &&
2402 + !yres_specified) {
2403 + *refresh = simple_strtoul(&mode_option[i+1],
2404 + NULL, 0);
2405 + refresh_specified = 1;
2406 + } else
2407 + goto out;
2408 + break;
2409 + case '-':
2410 + len = i;
2411 + if (!bpp_specified && !yres_specified) {
2412 + *bpp = simple_strtoul(&mode_option[i+1],
2413 + NULL, 0);
2414 + bpp_specified = 1;
2415 + } else
2416 + goto out;
2417 + break;
2418 + case 'x':
2419 + if (!yres_specified) {
2420 + *yres = simple_strtoul(&mode_option[i+1],
2421 + NULL, 0);
2422 + yres_specified = 1;
2423 + } else
2424 + goto out;
2425 + break;
2426 + case '0'...'9':
2427 + break;
2428 + default:
2429 + goto out;
2430 + }
2431 + }
2432 +
2433 + if (i < 0 && yres_specified) {
2434 + *xres = simple_strtoul(mode_option, NULL, 0);
2435 + res_specified = 1;
2436 + }
2437 +
2438 +out: if (!res_specified || !yres_specified) {
2439 + printk(KERN_ERR "vesafb: invalid resolution, "
2440 + "%s not specified\n",
2441 + (!res_specified) ? "width" : "height");
2442 + err = -EINVAL;
2443 + }
2444 +
2445 + return err;
2446 +}
2447 +
2448 +static int __init vesafb_init_set_mode(struct fb_info *info)
2449 +{
2450 + struct fb_videomode *fbmode;
2451 + struct fb_videomode mode;
2452 + int i, modeid, refresh = 0;
2453 + u8 refresh_specified = 0;
2454 +
2455 + if (!mode_option)
2456 + mode_option = CONFIG_FB_VESA_DEFAULT_MODE;
2457 +
2458 + if (vbemode > 0) {
2459 + for (i = 0; i < vbe_modes_cnt; i++) {
2460 + if (vbe_modes[i].mode_id == vbemode) {
2461 + info->var.vmode = FB_VMODE_NONINTERLACED;
2462 + info->var.sync = FB_SYNC_VERT_HIGH_ACT;
2463 + vesafb_setup_var(&info->var, info,
2464 + &vbe_modes[i]);
2465 + fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON,
2466 + 60, &info->var, info);
2467 + /* With pixclock set to 0, the default BIOS
2468 + * timings will be used in set_par(). */
2469 + info->var.pixclock = 0;
2470 + modeid = i;
2471 + goto out;
2472 + }
2473 + }
2474 + printk(KERN_INFO "specified VBE mode %d not found\n",
2475 + vbemode);
2476 + vbemode = 0;
2477 + }
2478 +
2479 + /* Decode the mode specified on the kernel command line. We save
2480 + * the depth into bits_per_pixel, which is wrong, but will work
2481 + * anyway. */
2482 + if (decode_mode(&info->var.xres, &info->var.yres,
2483 + &info->var.bits_per_pixel, &refresh))
2484 + return -EINVAL;
2485 + if (refresh)
2486 + refresh_specified = 1;
2487 + else
2488 + refresh = 60;
2489 +
2490 + /* Look for a matching VBE mode. We can live if an exact match
2491 + * cannot be found. */
2492 + modeid = vesafb_find_vbe_mode(info->var.xres, info->var.yres,
2493 + info->var.bits_per_pixel, 0);
2494 +
2495 + if (modeid == -1) {
2496 + return -EINVAL;
2497 + } else {
2498 + info->var.vmode = FB_VMODE_NONINTERLACED;
2499 + info->var.sync = FB_SYNC_VERT_HIGH_ACT;
2500 + vesafb_setup_var(&info->var, info, &vbe_modes[modeid]);
2501 + }
2502 + if (vbe_ib.vbe_version < 0x0300) {
2503 + fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 60,
2504 + &info->var, info);
2505 + goto out;
2506 + }
2507 + if (!gtf) {
2508 + struct fb_videomode tmode;
2509 +
2510 + if (refresh_specified) {
2511 + fb_var_to_videomode(&tmode, &info->var);
2512 + tmode.refresh = refresh;
2513 + fbmode = fb_find_nearest_mode(&tmode,
2514 + &info->modelist);
2515 + } else
2516 + fbmode = fb_find_best_mode(&info->var,
2517 + &info->modelist);
2518 +
2519 + if (fbmode->xres == info->var.xres &&
2520 + fbmode->yres == info->var.yres &&
2521 + !(fbmode->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE))
2522 + && (!refresh_specified ||
2523 + abs(refresh - fbmode->refresh) <= 5)) {
2524 + fb_videomode_to_var(&info->var, fbmode);
2525 + return modeid;
2526 + }
2527 + }
2528 + i = FB_MAXTIMINGS;
2529 + if (!info->monspecs.gtf)
2530 + i = FB_IGNOREMON | FB_VSYNCTIMINGS;
2531 + else if (refresh_specified)
2532 + i = FB_VSYNCTIMINGS;
2533 + if (!fb_get_mode(i, refresh, &info->var, info))
2534 + goto out;
2535 + if (info->monspecs.gtf &&
2536 + !fb_get_mode(FB_MAXTIMINGS, 0, &info->var, info))
2537 + goto out;
2538 + /* Use default refresh rate */
2539 + printk(KERN_WARNING "vesafb: using default BIOS refresh rate\n");
2540 + info->var.pixclock = 0;
2541 +
2542 +out:
2543 + fb_var_to_videomode(&mode, &info->var);
2544 + fb_add_videomode(&mode, &info->modelist);
2545 + return modeid;
2546 +}
2547 +
2548 +static int __init vesafb_probe(struct platform_device *dev)
2549 +{
2550 + char entry[16];
2551 + struct fb_info *info;
2552 + struct vesafb_mode_ib *mode = NULL;
2553 + int err = 0, i, h;
2554 + unsigned int size_vmode;
2555 + unsigned int size_remap;
2556 + unsigned int size_total;
2557 +
2558 + vesafb_info = info = framebuffer_alloc(sizeof(struct vesafb_par) +
2559 + sizeof(u32) * 256, &dev->dev);
2560 + if (!info)
2561 + return -ENOMEM;
2562 +
2563 + if (vesafb_wait_for_thread()) {
2564 + printk(KERN_ERR "vesafb: vesafb thread not running\n");
2565 + framebuffer_release(info);
2566 + return -EINVAL;
2567 + }
2568 +
2569 + if (vesafb_vbe_init(info)) {
2570 + printk(KERN_ERR "vesafb: vbe_init failed\n");
2571 + err = -EINVAL;
2572 + goto out;
2573 + }
2574 +
2575 + vesafb_fix.ypanstep = ypan ? 1 : 0;
2576 + vesafb_fix.ywrapstep = (ypan>1) ? 1 : 0;
2577 +
2578 + info->pseudo_palette = ((u8*)info->par + sizeof(struct vesafb_par));
2579 + info->fbops = &vesafb_ops;
2580 + info->var = vesafb_defined;
2581 + info->fix = vesafb_fix;
2582 +
2583 + if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
2584 + err = -ENXIO;
2585 + goto out;
2586 + }
2587 +
2588 + i = vesafb_init_set_mode(info);
2589 + if (i < 0) {
2590 + err = -EINVAL;
2591 + goto out_cmap;
2592 + } else
2593 + mode = &vbe_modes[i];
2594 +
2595 + /* Disable blanking if the user requested so. */
2596 + if (!blank) {
2597 + info->fbops->fb_blank = NULL;
2598 + }
2599 +
2600 + /* Find out how much IO memory is required for the mode with
2601 + * the highest resolution. */
2602 + size_remap = 0;
2603 + for (i = 0; i < vbe_modes_cnt; i++) {
2604 + h = vbe_modes[i].bytes_per_scan_line * vbe_modes[i].y_res;
2605 + if (h > size_remap)
2606 + size_remap = h;
2607 + }
2608 + size_remap *= 2;
2609 +
2610 + /* size_vmode -- that is the amount of memory needed for the
2611 + * used video mode, i.e. the minimum amount of
2612 + * memory we need. */
2613 + if (mode != NULL) {
2614 + size_vmode = info->var.yres * mode->bytes_per_scan_line;
2615 + } else {
2616 + size_vmode = info->var.yres * info->var.xres *
2617 + ((info->var.bits_per_pixel + 7) >> 3);
2618 + }
2619 +
2620 + /* size_total -- all video memory we have. Used for mtrr
2621 + * entries, ressource allocation and bounds
2622 + * checking. */
2623 + size_total = vbe_ib.total_memory * 65536;
2624 + if (vram_total)
2625 + size_total = vram_total * 1024 * 1024;
2626 + if (size_total < size_vmode)
2627 + size_total = size_vmode;
2628 + ((struct vesafb_par*)(info->par))->mem_total = size_total;
2629 +
2630 + /* size_remap -- the amount of video memory we are going to
2631 + * use for vesafb. With modern cards it is no
2632 + * option to simply use size_total as th
2633 + * wastes plenty of kernel address space. */
2634 + if (vram_remap)
2635 + size_remap = vram_remap * 1024 * 1024;
2636 + if (size_remap < size_vmode)
2637 + size_remap = size_vmode;
2638 + if (size_remap > size_total)
2639 + size_remap = size_total;
2640 +
2641 + info->fix.smem_len = size_remap;
2642 + info->fix.smem_start = mode->phys_base_ptr;
2643 +
2644 + /* We have to set it here, because when setup_var() was called,
2645 + * smem_len wasn't defined yet. */
2646 + info->var.yres_virtual = info->fix.smem_len /
2647 + mode->bytes_per_scan_line;
2648 +
2649 + if (ypan && info->var.yres_virtual > info->var.yres) {
2650 + printk(KERN_INFO "vesafb: scrolling: %s "
2651 + "using protected mode interface, "
2652 + "yres_virtual=%d\n",
2653 + (ypan > 1) ? "ywrap" : "ypan",info->var.yres_virtual);
2654 + } else {
2655 + printk(KERN_INFO "vesafb: scrolling: redraw\n");
2656 + info->var.yres_virtual = info->var.yres;
2657 + ypan = 0;
2658 + }
2659 +
2660 + info->flags = FBINFO_FLAG_DEFAULT |
2661 + (ypan) ? FBINFO_HWACCEL_YPAN : 0;
2662 +
2663 + if (!ypan)
2664 + info->fbops->fb_pan_display = NULL;
2665 +
2666 + if (!request_mem_region(info->fix.smem_start, size_total, "vesafb")) {
2667 + printk(KERN_WARNING "vesafb: cannot reserve video memory at "
2668 + "0x%lx\n", info->fix.smem_start);
2669 + /* We cannot make this fatal. Sometimes this comes from magic
2670 + spaces our resource handlers simply don't know about. */
2671 + }
2672 +
2673 + info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
2674 +
2675 + if (!info->screen_base) {
2676 + printk(KERN_ERR
2677 + "vesafb: abort, cannot ioremap video memory "
2678 + "0x%x @ 0x%lx\n",
2679 + info->fix.smem_len, info->fix.smem_start);
2680 + err = -EIO;
2681 + goto out_mem;
2682 + }
2683 +
2684 + /* Request failure does not faze us, as vgacon probably has this
2685 + region already (FIXME) */
2686 + request_region(0x3c0, 32, "vesafb");
2687 +
2688 +#ifdef CONFIG_MTRR
2689 + if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
2690 + int temp_size = size_total;
2691 + unsigned int type = 0;
2692 +
2693 + switch (mtrr) {
2694 + case 1:
2695 + type = MTRR_TYPE_UNCACHABLE;
2696 + break;
2697 + case 2:
2698 + type = MTRR_TYPE_WRBACK;
2699 + break;
2700 + case 3:
2701 + type = MTRR_TYPE_WRCOMB;
2702 + break;
2703 + case 4:
2704 + type = MTRR_TYPE_WRTHROUGH;
2705 + break;
2706 + default:
2707 + type = 0;
2708 + break;
2709 + }
2710 +
2711 + if (type) {
2712 + int rc;
2713 +
2714 + /* Find the largest power-of-two */
2715 + while (temp_size & (temp_size - 1))
2716 + temp_size &= (temp_size - 1);
2717 +
2718 + /* Try and find a power of two to add */
2719 + do {
2720 + rc = mtrr_add(info->fix.smem_start,
2721 + temp_size, type, 1);
2722 + temp_size >>= 1;
2723 + } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
2724 + }
2725 + }
2726 +#endif /* CONFIG_MTRR */
2727 +
2728 + if (register_framebuffer(info) < 0) {
2729 + printk(KERN_ERR
2730 + "vesafb: failed to register framebuffer device\n");
2731 + err = -EINVAL;
2732 + goto out_mem;
2733 + }
2734 +
2735 + printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
2736 + "using %dk, total %dk\n", info->fix.smem_start,
2737 + info->screen_base, size_remap/1024, size_total/1024);
2738 + printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
2739 + info->fix.id);
2740 +
2741 + sprintf(entry, "fb%d", info->node);
2742 + proc_mkdir(entry, 0);
2743 +
2744 + sprintf(entry, "fb%d/modes", info->node);
2745 + create_proc_read_entry(entry, 0, 0, vesafb_read_proc_modes, NULL);
2746 +
2747 + sprintf(entry, "fb%d/vbe_info", info->node);
2748 + create_proc_read_entry(entry, 0, 0, vesafb_read_proc_vbe_info, NULL);
2749 + return 0;
2750 +
2751 +out_mem:
2752 + release_mem_region(info->fix.smem_start, size_total);
2753 + if (!list_empty(&info->modelist))
2754 + fb_destroy_modelist(&info->modelist);
2755 + fb_destroy_modedb(info->monspecs.modedb);
2756 +out_cmap:
2757 + fb_dealloc_cmap(&info->cmap);
2758 +out:
2759 + framebuffer_release(info);
2760 + vesafb_info = NULL;
2761 + kfree(vbe_modes);
2762 + vbe_modes = NULL;
2763 + return err;
2764 +}
2765 +
2766 +int __init vesafb_init(void)
2767 +{
2768 + int ret;
2769 +#ifndef MODULE
2770 + char *option = NULL;
2771 +
2772 + if (fb_get_options("vesafb", &option))
2773 + return -ENODEV;
2774 + vesafb_setup(option);
2775 +#endif
2776 + ret = platform_driver_register(&vesafb_driver);
2777 +
2778 + if (!ret) {
2779 + vesafb_device = platform_device_alloc("vesafb", 0);
2780 +
2781 + if (vesafb_device)
2782 + ret = platform_device_add(vesafb_device);
2783 + else
2784 + ret = -ENOMEM;
2785 +
2786 + if (ret) {
2787 + platform_device_put(vesafb_device);
2788 + platform_driver_unregister(&vesafb_driver);
2789 + }
2790 + }
2791 + return ret;
2792 +}
2793 +
2794 +module_init(vesafb_init);
2795 +
2796 +#ifdef MODULE
2797 +void __exit vesafb_exit(void)
2798 +{
2799 + char entry[16];
2800 +
2801 + if (vesafb_info)
2802 + unregister_framebuffer(vesafb_info);
2803 +
2804 + platform_device_unregister(vesafb_device);
2805 + platform_driver_unregister(&vesafb_driver);
2806 +
2807 + if (vesafb_info) {
2808 + struct vesafb_par *par = (struct vesafb_par*)vesafb_info->par;
2809 +
2810 + sprintf(entry, "fb%d/modes", vesafb_info->node);
2811 + remove_proc_entry(entry, NULL);
2812 +
2813 + sprintf(entry, "fb%d/vbe_info", vesafb_info->node);
2814 + remove_proc_entry(entry, NULL);
2815 +
2816 + sprintf(entry, "fb%d", vesafb_info->node);
2817 + remove_proc_entry(entry, NULL);
2818 +
2819 + iounmap(vesafb_info->screen_base);
2820 + release_mem_region(vesafb_info->fix.smem_start,
2821 + par->mem_total);
2822 + fb_dealloc_cmap(&vesafb_info->cmap);
2823 + if (!list_empty(&vesafb_info->modelist))
2824 + fb_destroy_modelist(&vesafb_info->modelist);
2825 + fb_destroy_modedb(vesafb_info->monspecs.modedb);
2826 + framebuffer_release(vesafb_info);
2827 + }
2828 +
2829 + if (vbe_modes != NULL)
2830 + kfree(vbe_modes);
2831 +}
2832 +
2833 +module_exit(vesafb_exit);
2834 +
2835 +static inline int param_get_scroll(char *buffer, struct kernel_param *kp)
2836 +{
2837 + return 0;
2838 +}
2839 +static inline int param_set_scroll(const char *val, struct kernel_param *kp)
2840 +{
2841 + ypan = 0;
2842 +
2843 + if (! strcmp(val, "redraw"))
2844 + ypan = 0;
2845 + else if (! strcmp(val, "ypan"))
2846 + ypan = 1;
2847 + else if (! strcmp(val, "ywrap"))
2848 + ypan = 2;
2849 +
2850 + return 0;
2851 +}
2852 +
2853 +#define param_check_scroll(name, p) __param_check(name, p, void);
2854 +
2855 +module_param_named(scroll, ypan, scroll, 0);
2856 +MODULE_PARM_DESC(scroll,"Scrolling mode, set to 'redraw', 'ypan' or 'ywrap'");
2857 +module_param_named(vgapal, pmi_setpal, invbool, 0);
2858 +MODULE_PARM_DESC(vgapal,"bool: set palette using VGA registers");
2859 +module_param_named(pmipal, pmi_setpal, bool, 0);
2860 +MODULE_PARM_DESC(pmipal,"bool: set palette using PMI calls");
2861 +module_param(mtrr, uint, 0);
2862 +MODULE_PARM_DESC(mtrr,"Memory Type Range Registers setting. Use 0 to disable.");
2863 +module_param(blank, bool, 1);
2864 +MODULE_PARM_DESC(blank,"bool: enable hardware blanking");
2865 +module_param(nocrtc, bool, 0);
2866 +MODULE_PARM_DESC(nocrtc,"bool: ignore CRTC timings when setting modes");
2867 +module_param(noedid, bool, 0);
2868 +MODULE_PARM_DESC(noedid,"bool: ignore EDID-provided monitor limits "
2869 + "when setting modes");
2870 +module_param(gtf, bool, 0);
2871 +MODULE_PARM_DESC(gtf,"bool: force use of VESA GTF to calculate mode timings");
2872 +module_param(vram_remap, uint, 0);
2873 +MODULE_PARM_DESC(vram_remap,"Set amount of video memory to be used [MiB]");
2874 +module_param(vram_total, uint, 0);
2875 +MODULE_PARM_DESC(vram_total,"Set total amount of video memoery [MiB]");
2876 +module_param(maxclk, ushort, 0);
2877 +MODULE_PARM_DESC(maxclk,"Maximum pixelclock [MHz], overrides EDID data");
2878 +module_param(maxhf, ushort, 0);
2879 +MODULE_PARM_DESC(maxhf,"Maximum horizontal frequency [kHz], "
2880 + "overrides EDID data");
2881 +module_param(maxvf, ushort, 0);
2882 +MODULE_PARM_DESC(maxvf,"Maximum vertical frequency [Hz], "
2883 + "overrides EDID data");
2884 +module_param_named(mode, mode_option, charp, 0);
2885 +MODULE_PARM_DESC(mode, "Specify resolution as "
2886 + "\"<xres>x<yres>[-<bpp>][@<refresh>]\"");
2887 +module_param(vbemode, ushort, 0);
2888 +MODULE_PARM_DESC(vbemode,"VBE mode number to set, overrides 'mode' setting");
2889 +
2890 +#endif /* MODULE */
2891 +
2892 +MODULE_LICENSE("GPL");
2893 +MODULE_AUTHOR("Michal Januszewski");
2894 +MODULE_DESCRIPTION("Framebuffer driver for VBE2.0+ compliant graphics boards");
2895 +
2896 diff --git a/include/linux/sched.h b/include/linux/sched.h
2897 index 4463735..7283e48 100644
2898 --- a/include/linux/sched.h
2899 +++ b/include/linux/sched.h
2900 @@ -1390,6 +1390,8 @@ extern void mmput(struct mm_struct *);
2901 extern struct mm_struct *get_task_mm(struct task_struct *task);
2902 /* Remove the current tasks stale references to the old mm_struct */
2903 extern void mm_release(struct task_struct *, struct mm_struct *);
2904 +/* Create a new mm for a kernel thread */
2905 +extern int set_new_mm(void);
2906
2907 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
2908 extern void flush_thread(void);
2909 diff --git a/include/video/vesa.h b/include/video/vesa.h
2910 new file mode 100644
2911 index 0000000..bb5abcf
2912 --- /dev/null
2913 +++ b/include/video/vesa.h
2914 @@ -0,0 +1,150 @@
2915 +#if 0
2916 +#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , \
2917 + ## args)
2918 +#else
2919 +#define DPRINTK(fmt, args...)
2920 +#endif
2921 +
2922 +#define p_crtc(arg) ((struct vesafb_crtc_ib*)(arg))
2923 +#define p_vbe(arg) ((struct vesafb_vbe_ib*)(arg))
2924 +#define p_mode(arg) ((struct vesafb_mode_ib*)(arg))
2925 +
2926 +struct vesafb_task {
2927 + u8 flags;
2928 + void *buf;
2929 + int buf_len;
2930 + struct vm86_regs regs;
2931 + struct list_head node;
2932 + struct completion done;
2933 +};
2934 +
2935 +/* Vesafb task flags and masks */
2936 +#define TF_CALL 0x00
2937 +#define TF_EXIT 0x01
2938 +#define TF_GETVBEIB 0x02
2939 +#define TF_BUF_DI 0x04
2940 +#define TF_BUF_BX 0x08
2941 +#define TF_RETURN_BUF 0x10
2942 +
2943 +/* Macros and functions for manipulating vesafb tasks */
2944 +#define vesafb_create_task(task) \
2945 +do { \
2946 + task = kmalloc(sizeof(struct vesafb_task), GFP_ATOMIC); \
2947 + if (task) \
2948 + memset(task, 0, sizeof(struct vesafb_task)); \
2949 + init_completion(&task->done); \
2950 +} while (0)
2951 +
2952 +#define vesafb_wait_for_task(task) wait_for_completion(&task->done);
2953 +#define vesafb_reset_task(task) init_completion(&task->done);
2954 +int vesafb_queue_task(struct vesafb_task *task);
2955 +
2956 +/* Functions for controlling the vesafb thread */
2957 +int vesafb_wait_for_thread(void);
2958 +
2959 +#define VBE_CAP_CAN_SWITCH_DAC 0x01
2960 +#define VBE_CAP_VGACOMPAT 0x02
2961 +
2962 +/* This struct is 512 bytes long */
2963 +struct vesafb_vbe_ib {
2964 + char vbe_signature[4];
2965 + u16 vbe_version;
2966 + u32 oem_string_ptr;
2967 + u32 capabilities;
2968 + u32 mode_list_ptr;
2969 + u16 total_memory;
2970 + u16 oem_software_rev;
2971 + u32 oem_vendor_name_ptr;
2972 + u32 oem_product_name_ptr;
2973 + u32 oem_product_rev_ptr;
2974 + u8 reserved[222];
2975 + char oem_data[256];
2976 +} __attribute__ ((packed));
2977 +
2978 +struct vesafb_crtc_ib {
2979 + u16 horiz_total;
2980 + u16 horiz_start;
2981 + u16 horiz_end;
2982 + u16 vert_total;
2983 + u16 vert_start;
2984 + u16 vert_end;
2985 + u8 flags;
2986 + u32 pixel_clock;
2987 + u16 refresh_rate;
2988 + u8 reserved[40];
2989 +} __attribute__ ((packed));
2990 +
2991 +#define VBE_MODE_VGACOMPAT 0x20
2992 +
2993 +struct vesafb_mode_ib {
2994 + /* for all VBE revisions */
2995 + u16 mode_attr;
2996 + u8 winA_attr;
2997 + u8 winB_attr;
2998 + u16 win_granularity;
2999 + u16 win_size;
3000 + u16 winA_seg;
3001 + u16 winB_seg;
3002 + u32 win_func_ptr;
3003 + u16 bytes_per_scan_line;
3004 +
3005 + /* for VBE 1.2+ */
3006 + u16 x_res;
3007 + u16 y_res;
3008 + u8 x_char_size;
3009 + u8 y_char_size;
3010 + u8 planes;
3011 + u8 bits_per_pixel;
3012 + u8 banks;
3013 + u8 memory_model;
3014 + u8 bank_size;
3015 + u8 image_pages;
3016 + u8 reserved1;
3017 +
3018 + /* Direct color fields for direct/6 and YUV/7 memory models. */
3019 + /* Offsets are bit positions of lsb in the mask. */
3020 + u8 red_len;
3021 + u8 red_off;
3022 + u8 green_len;
3023 + u8 green_off;
3024 + u8 blue_len;
3025 + u8 blue_off;
3026 + u8 rsvd_len;
3027 + u8 rsvd_off;
3028 + u8 direct_color_info; /* direct color mode attributes */
3029 +
3030 + /* for VBE 2.0+ */
3031 + u32 phys_base_ptr;
3032 + u8 reserved2[6];
3033 +
3034 + /* for VBE 3.0+ */
3035 + u16 lin_bytes_per_scan_line;
3036 + u8 bnk_image_pages;
3037 + u8 lin_image_pages;
3038 + u8 lin_red_len;
3039 + u8 lin_red_off;
3040 + u8 lin_green_len;
3041 + u8 lin_green_off;
3042 + u8 lin_blue_len;
3043 + u8 lin_blue_off;
3044 + u8 lin_rsvd_len;
3045 + u8 lin_rsvd_off;
3046 + u32 max_pixel_clock;
3047 + u16 mode_id;
3048 + u8 depth;
3049 +} __attribute__ ((packed));
3050 +
3051 +struct vesafb_pal_entry {
3052 + u_char blue, green, red, pad;
3053 +} __attribute__ ((packed));
3054 +
3055 +struct vesafb_par {
3056 + u8 *vbe_state;
3057 + int vbe_state_size;
3058 + atomic_t ref_count;
3059 +
3060 + u32 mem_total;
3061 + int mode_idx;
3062 + struct vesafb_crtc_ib crtc;
3063 +};
3064 +
3065 diff --git a/kernel/fork.c b/kernel/fork.c
3066 index fc723e5..dc8f93b 100644
3067 --- a/kernel/fork.c
3068 +++ b/kernel/fork.c
3069 @@ -100,6 +100,7 @@ struct kmem_cache *fs_cachep;
3070
3071 /* SLAB cache for vm_area_struct structures */
3072 struct kmem_cache *vm_area_cachep;
3073 +EXPORT_SYMBOL_GPL(vm_area_cachep);
3074
3075 /* SLAB cache for mm_struct structures (tsk->mm) */
3076 static struct kmem_cache *mm_cachep;
3077 @@ -399,6 +400,40 @@ void mmput(struct mm_struct *mm)
3078 EXPORT_SYMBOL_GPL(mmput);
3079
3080 /**
3081 + * set_new_mm - allocate, init and activate a new mm for a kernel thread
3082 + */
3083 +int set_new_mm(void)
3084 +{
3085 + struct mm_struct *mm;
3086 + struct task_struct *tsk = current;
3087 + struct mm_struct *active_mm;
3088 +
3089 + mm = mm_alloc();
3090 + if (!mm)
3091 + goto fail_nomem;
3092 + if (init_new_context(current,mm))
3093 + goto fail_nocontext;
3094 +
3095 + task_lock(tsk);
3096 + tsk->flags |= PF_BORROWED_MM;
3097 + active_mm = tsk->active_mm;
3098 + current->mm = mm;
3099 + current->active_mm = mm;
3100 + activate_mm(active_mm, mm);
3101 + task_unlock(current);
3102 +
3103 + /* Drop the previous active_mm */
3104 + mmdrop(active_mm);
3105 + return 0;
3106 +
3107 +fail_nocontext:
3108 + mmdrop(mm);
3109 +fail_nomem:
3110 + return -EINVAL;
3111 +}
3112 +EXPORT_SYMBOL_GPL(set_new_mm);
3113 +
3114 +/**
3115 * get_task_mm - acquire a reference to the task's mm
3116 *
3117 * Returns %NULL if the task has no mm. Checks PF_BORROWED_MM (meaning
3118 diff --git a/mm/memory.c b/mm/memory.c
3119 index 563792f..a9519ea 100644
3120 --- a/mm/memory.c
3121 +++ b/mm/memory.c
3122 @@ -1193,6 +1193,7 @@ int zeromap_page_range(struct vm_area_struct *vma,
3123 } while (pgd++, addr = next, addr != end);
3124 return err;
3125 }
3126 +EXPORT_SYMBOL_GPL(zeromap_page_range);
3127
3128 pte_t * fastcall get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl)
3129 {
3130 diff --git a/mm/mmap.c b/mm/mmap.c
3131 index 9717337..6fa5b1c 100644
3132 --- a/mm/mmap.c
3133 +++ b/mm/mmap.c
3134 @@ -2024,6 +2024,7 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
3135 vma_link(mm, vma, prev, rb_link, rb_parent);
3136 return 0;
3137 }
3138 +EXPORT_SYMBOL_GPL(insert_vm_struct);
3139
3140 /*
3141 * Copy the vma structure to a new location in the same mm,