/[linux-patches]/genpatches-2.6/trunk/2.6.19/4205_vesafb-tng-1.0-rc2.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.19/4205_vesafb-tng-1.0-rc2.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20