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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20