/[linux-patches]/genpatches-2.6/trunk/2.6.14/4505_vesafb-tng-1.0-rc1-r1.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.14/4505_vesafb-tng-1.0-rc1-r1.patch

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20