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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20