Magellan Linux

Contents of /trunk/kernel26-alx/patches-2.6.17-r6/0151-2.6.17-vesafb-tng-1.0-rc1-r3-2.6.16.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 199 - (show annotations) (download)
Fri May 18 11:04:36 2007 UTC (16 years, 11 months ago) by niro
File size: 86172 byte(s)
-import

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