Rev 477 | Rev 479 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
466 | giacomo | 1 | /* |
2 | * framebuffer driver for VBE 2.0 compliant graphic boards |
||
3 | * |
||
4 | * switching to graphics mode happens at boot time (while |
||
5 | * running in real mode, see arch/i386/boot/video.S). |
||
6 | * |
||
7 | * (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de> |
||
8 | * |
||
9 | */ |
||
10 | |||
11 | #include <linuxcomp.h> |
||
12 | |||
13 | #include <linux/module.h> |
||
14 | #include <linux/kernel.h> |
||
15 | #include <linux/errno.h> |
||
16 | #include <linux/string.h> |
||
17 | #include <linux/mm.h> |
||
18 | #include <linux/tty.h> |
||
19 | #include <linux/slab.h> |
||
20 | #include <linux/delay.h> |
||
21 | #include <linux/fb.h> |
||
22 | #include <linux/ioport.h> |
||
23 | #include <linux/init.h> |
||
24 | #ifdef __i386__ |
||
25 | #include <video/edid.h> |
||
26 | #endif |
||
27 | #include <asm/io.h> |
||
28 | #include <asm/mtrr.h> |
||
29 | |||
30 | #define dac_reg (0x3c8) |
||
31 | #define dac_val (0x3c9) |
||
32 | |||
477 | giacomo | 33 | #include <vesa.h> |
34 | |||
35 | #define INIT_MODE 0x4101 |
||
36 | |||
466 | giacomo | 37 | /* --------------------------------------------------------------------- */ |
38 | |||
39 | static struct fb_var_screeninfo vesafb_defined __initdata = { |
||
40 | .activate = FB_ACTIVATE_NOW, |
||
41 | .height = -1, |
||
42 | .width = -1, |
||
43 | .right_margin = 32, |
||
44 | .upper_margin = 16, |
||
45 | .lower_margin = 4, |
||
46 | .vsync_len = 4, |
||
47 | .vmode = FB_VMODE_NONINTERLACED, |
||
48 | }; |
||
49 | |||
50 | static struct fb_fix_screeninfo vesafb_fix __initdata = { |
||
51 | .id = "VESA VGA", |
||
52 | .type = FB_TYPE_PACKED_PIXELS, |
||
53 | .accel = FB_ACCEL_NONE, |
||
54 | }; |
||
55 | |||
56 | static struct fb_info fb_info; |
||
57 | static u32 pseudo_palette[17]; |
||
58 | |||
59 | static int inverse = 0; |
||
60 | static int mtrr = 1; |
||
61 | |||
62 | static int pmi_setpal = 0; /* pmi for palette changes ??? */ |
||
63 | static int ypan = 0; /* 0..nothing, 1..ypan, 2..ywrap */ |
||
64 | static unsigned short *pmi_base = 0; |
||
65 | static void (*pmi_start)(void); |
||
66 | static void (*pmi_pal)(void); |
||
67 | |||
68 | /* --------------------------------------------------------------------- */ |
||
69 | |||
70 | static int vesafb_pan_display(struct fb_var_screeninfo *var, |
||
71 | struct fb_info *info) |
||
72 | { |
||
73 | #ifdef __i386__ |
||
74 | int offset; |
||
75 | |||
76 | if (!ypan) |
||
77 | return -EINVAL; |
||
78 | if (var->xoffset) |
||
79 | return -EINVAL; |
||
80 | if (var->yoffset > var->yres_virtual) |
||
81 | return -EINVAL; |
||
82 | if ((ypan==1) && var->yoffset+var->yres > var->yres_virtual) |
||
83 | return -EINVAL; |
||
84 | |||
85 | offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4; |
||
86 | |||
87 | __asm__ __volatile__( |
||
88 | "call *(%%edi)" |
||
89 | : /* no return value */ |
||
90 | : "a" (0x4f07), /* EAX */ |
||
91 | "b" (0), /* EBX */ |
||
92 | "c" (offset), /* ECX */ |
||
93 | "d" (offset >> 16), /* EDX */ |
||
94 | "D" (&pmi_start)); /* EDI */ |
||
95 | #endif |
||
96 | return 0; |
||
97 | } |
||
98 | |||
99 | static void vesa_setpalette(int regno, unsigned red, unsigned green, unsigned blue) |
||
100 | { |
||
101 | #ifdef __i386__ |
||
102 | struct { u_char blue, green, red, pad; } entry; |
||
103 | |||
104 | if (pmi_setpal) { |
||
105 | entry.red = red >> 10; |
||
106 | entry.green = green >> 10; |
||
107 | entry.blue = blue >> 10; |
||
108 | entry.pad = 0; |
||
109 | __asm__ __volatile__( |
||
110 | "call *(%%esi)" |
||
111 | : /* no return value */ |
||
112 | : "a" (0x4f09), /* EAX */ |
||
113 | "b" (0), /* EBX */ |
||
114 | "c" (1), /* ECX */ |
||
115 | "d" (regno), /* EDX */ |
||
116 | "D" (&entry), /* EDI */ |
||
117 | "S" (&pmi_pal)); /* ESI */ |
||
118 | } else { |
||
119 | /* without protected mode interface, try VGA registers... */ |
||
120 | outb_p(regno, dac_reg); |
||
121 | outb_p(red >> 10, dac_val); |
||
122 | outb_p(green >> 10, dac_val); |
||
123 | outb_p(blue >> 10, dac_val); |
||
124 | } |
||
125 | #endif |
||
126 | } |
||
127 | |||
128 | static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green, |
||
129 | unsigned blue, unsigned transp, |
||
130 | struct fb_info *info) |
||
131 | { |
||
132 | /* |
||
133 | * Set a single color register. The values supplied are |
||
134 | * already rounded down to the hardware's capabilities |
||
135 | * (according to the entries in the `var' structure). Return |
||
136 | * != 0 for invalid regno. |
||
137 | */ |
||
138 | |||
139 | if (regno >= info->cmap.len) |
||
140 | return 1; |
||
141 | |||
142 | switch (info->var.bits_per_pixel) { |
||
143 | case 8: |
||
144 | vesa_setpalette(regno,red,green,blue); |
||
145 | break; |
||
146 | case 16: |
||
147 | if (info->var.red.offset == 10) { |
||
148 | /* 1:5:5:5 */ |
||
149 | ((u32*) (info->pseudo_palette))[regno] = |
||
150 | ((red & 0xf800) >> 1) | |
||
151 | ((green & 0xf800) >> 6) | |
||
152 | ((blue & 0xf800) >> 11); |
||
153 | } else { |
||
154 | /* 0:5:6:5 */ |
||
155 | ((u32*) (info->pseudo_palette))[regno] = |
||
156 | ((red & 0xf800) ) | |
||
157 | ((green & 0xfc00) >> 5) | |
||
158 | ((blue & 0xf800) >> 11); |
||
159 | } |
||
160 | break; |
||
161 | case 24: |
||
162 | red >>= 8; |
||
163 | green >>= 8; |
||
164 | blue >>= 8; |
||
165 | ((u32 *)(info->pseudo_palette))[regno] = |
||
166 | (red << info->var.red.offset) | |
||
167 | (green << info->var.green.offset) | |
||
168 | (blue << info->var.blue.offset); |
||
169 | break; |
||
170 | case 32: |
||
171 | red >>= 8; |
||
172 | green >>= 8; |
||
173 | blue >>= 8; |
||
174 | ((u32 *)(info->pseudo_palette))[regno] = |
||
175 | (red << info->var.red.offset) | |
||
176 | (green << info->var.green.offset) | |
||
177 | (blue << info->var.blue.offset); |
||
178 | break; |
||
179 | } |
||
180 | return 0; |
||
181 | } |
||
182 | |||
478 | giacomo | 183 | static int vesafb_release(struct fb_info *info, int user) |
184 | { |
||
185 | |||
186 | vbe_restore_vga(); |
||
187 | return 0; |
||
188 | |||
189 | } |
||
190 | |||
466 | giacomo | 191 | static struct fb_ops vesafb_ops = { |
192 | .owner = THIS_MODULE, |
||
193 | .fb_setcolreg = vesafb_setcolreg, |
||
194 | .fb_pan_display = vesafb_pan_display, |
||
195 | .fb_fillrect = cfb_fillrect, |
||
196 | .fb_copyarea = cfb_copyarea, |
||
197 | .fb_imageblit = cfb_imageblit, |
||
198 | .fb_cursor = soft_cursor, |
||
478 | giacomo | 199 | .fb_release = vesafb_release, |
466 | giacomo | 200 | }; |
201 | |||
202 | int __init vesafb_setup(char *options) |
||
203 | { |
||
204 | char *this_opt; |
||
205 | |||
206 | if (!options || !*options) |
||
207 | return 0; |
||
208 | |||
209 | while ((this_opt = strsep(&options, ",")) != NULL) { |
||
210 | if (!*this_opt) continue; |
||
211 | |||
212 | if (! strcmp(this_opt, "inverse")) |
||
213 | inverse=1; |
||
214 | else if (! strcmp(this_opt, "redraw")) |
||
215 | ypan=0; |
||
216 | else if (! strcmp(this_opt, "ypan")) |
||
217 | ypan=1; |
||
218 | else if (! strcmp(this_opt, "ywrap")) |
||
219 | ypan=2; |
||
220 | else if (! strcmp(this_opt, "vgapal")) |
||
221 | pmi_setpal=0; |
||
222 | else if (! strcmp(this_opt, "pmipal")) |
||
223 | pmi_setpal=1; |
||
224 | else if (! strcmp(this_opt, "mtrr")) |
||
225 | mtrr=1; |
||
226 | else if (! strcmp(this_opt, "nomtrr")) |
||
227 | mtrr=0; |
||
228 | } |
||
229 | return 0; |
||
230 | } |
||
231 | |||
477 | giacomo | 232 | extern VbeInfoBlock VbeInfo; |
233 | extern int vbe_getifo(void); |
||
234 | extern void vm86_init(void); |
||
235 | |||
466 | giacomo | 236 | int __init vesafb_init(void) |
237 | { |
||
477 | giacomo | 238 | ModeInfoBlock ModeInfo; |
466 | giacomo | 239 | int video_cmap_len; |
240 | int i; |
||
241 | |||
477 | giacomo | 242 | vm86_init(); |
243 | |||
244 | if (vbe_getinfo()) |
||
245 | return -EIO; |
||
246 | |||
247 | printk(KERN_INFO "VBE Extension Found.\n"); |
||
248 | |||
249 | screen_info.lfb_base = vbe_getmodeinfo(&ModeInfo,INIT_MODE); |
||
250 | |||
251 | screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB; |
||
252 | |||
466 | giacomo | 253 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) |
254 | return -ENXIO; |
||
255 | |||
477 | giacomo | 256 | screen_info.lfb_depth = ModeInfo.BitsPerPixel; |
257 | screen_info.lfb_width = ModeInfo.XResolution; |
||
258 | screen_info.lfb_height = ModeInfo.YResolution; |
||
259 | screen_info.lfb_linelength = ModeInfo.BytesPerScanLine; |
||
260 | screen_info.lfb_size = VbeInfo.TotalMemory; |
||
261 | screen_info.pages = ModeInfo.NumberOfImagePages; |
||
262 | |||
263 | screen_info.vesapm_seg = 0; |
||
264 | screen_info.vesapm_off = 0; |
||
265 | |||
266 | screen_info.red_pos = ModeInfo.RedFieldPosition; |
||
267 | screen_info.red_size = ModeInfo.RedMaskSize; |
||
268 | screen_info.green_pos = ModeInfo.GreenFieldPosition; |
||
269 | screen_info.green_size = ModeInfo.GreenMaskSize; |
||
270 | screen_info.blue_pos = ModeInfo.BlueFieldPosition; |
||
271 | screen_info.blue_size = ModeInfo.BlueMaskSize; |
||
272 | screen_info.rsvd_pos = ModeInfo.RsvdFieldPosition; |
||
273 | screen_info.rsvd_size = ModeInfo.RsvdMaskSize; |
||
274 | |||
275 | vbe_setmode(INIT_MODE); |
||
276 | |||
466 | giacomo | 277 | vesafb_fix.smem_start = screen_info.lfb_base; |
278 | vesafb_defined.bits_per_pixel = screen_info.lfb_depth; |
||
279 | if (15 == vesafb_defined.bits_per_pixel) |
||
280 | vesafb_defined.bits_per_pixel = 16; |
||
281 | vesafb_defined.xres = screen_info.lfb_width; |
||
282 | vesafb_defined.yres = screen_info.lfb_height; |
||
283 | vesafb_fix.line_length = screen_info.lfb_linelength; |
||
477 | giacomo | 284 | vesafb_fix.smem_len = screen_info.lfb_size; |
466 | giacomo | 285 | vesafb_fix.visual = (vesafb_defined.bits_per_pixel == 8) ? |
286 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
||
287 | |||
288 | /* limit framebuffer size to 16 MB. Otherwise we'll eat tons of |
||
289 | * kernel address space for nothing if the gfx card has alot of |
||
290 | * memory (>= 128 MB isn't uncommon these days ...) */ |
||
291 | if (vesafb_fix.smem_len > 16 * 1024 * 1024) |
||
292 | vesafb_fix.smem_len = 16 * 1024 * 1024; |
||
293 | |||
294 | #ifndef __i386__ |
||
295 | screen_info.vesapm_seg = 0; |
||
296 | #endif |
||
297 | |||
298 | if (!request_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len, "vesafb")) { |
||
299 | printk(KERN_WARNING |
||
300 | "vesafb: abort, cannot reserve video memory at 0x%lx\n", |
||
301 | vesafb_fix.smem_start); |
||
302 | /* We cannot make this fatal. Sometimes this comes from magic |
||
303 | spaces our resource handlers simply don't know about */ |
||
304 | } |
||
305 | |||
306 | fb_info.screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len); |
||
307 | if (!fb_info.screen_base) { |
||
308 | release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len); |
||
309 | printk(KERN_ERR |
||
310 | "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", |
||
311 | vesafb_fix.smem_len, vesafb_fix.smem_start); |
||
312 | return -EIO; |
||
313 | } |
||
314 | |||
315 | printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n", |
||
316 | vesafb_fix.smem_start, fb_info.screen_base, vesafb_fix.smem_len/1024); |
||
317 | printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n", |
||
318 | vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages); |
||
319 | |||
320 | if (screen_info.vesapm_seg) { |
||
321 | printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n", |
||
322 | screen_info.vesapm_seg,screen_info.vesapm_off); |
||
323 | } |
||
324 | |||
325 | if (screen_info.vesapm_seg < 0xc000) |
||
326 | ypan = pmi_setpal = 0; /* not available or some DOS TSR ... */ |
||
327 | |||
328 | if (ypan || pmi_setpal) { |
||
329 | pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); |
||
330 | pmi_start = (void*)((char*)pmi_base + pmi_base[1]); |
||
331 | pmi_pal = (void*)((char*)pmi_base + pmi_base[2]); |
||
332 | printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal); |
||
333 | if (pmi_base[3]) { |
||
334 | printk(KERN_INFO "vesafb: pmi: ports = "); |
||
335 | for (i = pmi_base[3]/2; pmi_base[i] != 0xffff; i++) |
||
336 | printk("%x ",pmi_base[i]); |
||
337 | printk("\n"); |
||
477 | giacomo | 338 | |
466 | giacomo | 339 | if (pmi_base[i] != 0xffff) { |
340 | /* |
||
341 | * memory areas not supported (yet?) |
||
342 | * |
||
343 | * Rules are: we have to set up a descriptor for the requested |
||
344 | * memory area and pass it in the ES register to the BIOS function. |
||
345 | */ |
||
346 | printk(KERN_INFO "vesafb: can't handle memory requests, pmi disabled\n"); |
||
347 | ypan = pmi_setpal = 0; |
||
348 | } |
||
349 | } |
||
350 | } |
||
351 | |||
352 | vesafb_defined.xres_virtual = vesafb_defined.xres; |
||
353 | vesafb_defined.yres_virtual = vesafb_fix.smem_len / vesafb_fix.line_length; |
||
354 | if (ypan && vesafb_defined.yres_virtual > vesafb_defined.yres) { |
||
355 | printk(KERN_INFO "vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n", |
||
356 | (ypan > 1) ? "ywrap" : "ypan",vesafb_defined.yres_virtual); |
||
357 | } else { |
||
358 | printk(KERN_INFO "vesafb: scrolling: redraw\n"); |
||
359 | vesafb_defined.yres_virtual = vesafb_defined.yres; |
||
360 | ypan = 0; |
||
361 | } |
||
362 | |||
363 | /* some dummy values for timing to make fbset happy */ |
||
364 | vesafb_defined.pixclock = 10000000 / vesafb_defined.xres * 1000 / vesafb_defined.yres; |
||
365 | vesafb_defined.left_margin = (vesafb_defined.xres / 8) & 0xf8; |
||
366 | vesafb_defined.hsync_len = (vesafb_defined.xres / 8) & 0xf8; |
||
367 | |||
368 | if (vesafb_defined.bits_per_pixel > 8) { |
||
369 | vesafb_defined.red.offset = screen_info.red_pos; |
||
370 | vesafb_defined.red.length = screen_info.red_size; |
||
371 | vesafb_defined.green.offset = screen_info.green_pos; |
||
372 | vesafb_defined.green.length = screen_info.green_size; |
||
373 | vesafb_defined.blue.offset = screen_info.blue_pos; |
||
374 | vesafb_defined.blue.length = screen_info.blue_size; |
||
375 | vesafb_defined.transp.offset = screen_info.rsvd_pos; |
||
376 | vesafb_defined.transp.length = screen_info.rsvd_size; |
||
377 | printk(KERN_INFO "vesafb: directcolor: " |
||
378 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", |
||
379 | screen_info.rsvd_size, |
||
380 | screen_info.red_size, |
||
381 | screen_info.green_size, |
||
382 | screen_info.blue_size, |
||
383 | screen_info.rsvd_pos, |
||
384 | screen_info.red_pos, |
||
385 | screen_info.green_pos, |
||
386 | screen_info.blue_pos); |
||
387 | video_cmap_len = 16; |
||
388 | } else { |
||
389 | vesafb_defined.red.length = 6; |
||
390 | vesafb_defined.green.length = 6; |
||
391 | vesafb_defined.blue.length = 6; |
||
392 | video_cmap_len = 256; |
||
393 | } |
||
394 | |||
395 | vesafb_fix.ypanstep = ypan ? 1 : 0; |
||
396 | vesafb_fix.ywrapstep = (ypan>1) ? 1 : 0; |
||
397 | |||
398 | /* request failure does not faze us, as vgacon probably has this |
||
399 | * region already (FIXME) */ |
||
400 | request_region(0x3c0, 32, "vesafb"); |
||
401 | |||
402 | if (mtrr) { |
||
403 | int temp_size = vesafb_fix.smem_len; |
||
404 | /* Find the largest power-of-two */ |
||
405 | while (temp_size & (temp_size - 1)) |
||
406 | temp_size &= (temp_size - 1); |
||
407 | |||
408 | /* Try and find a power of two to add */ |
||
409 | while (temp_size && mtrr_add(vesafb_fix.smem_start, temp_size, MTRR_TYPE_WRCOMB, 1)==-EINVAL) { |
||
410 | temp_size >>= 1; |
||
411 | } |
||
412 | } |
||
413 | |||
414 | fb_info.fbops = &vesafb_ops; |
||
415 | fb_info.var = vesafb_defined; |
||
416 | fb_info.fix = vesafb_fix; |
||
417 | fb_info.pseudo_palette = pseudo_palette; |
||
418 | fb_info.flags = FBINFO_FLAG_DEFAULT; |
||
419 | |||
420 | fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0); |
||
421 | |||
422 | if (register_framebuffer(&fb_info)<0) |
||
423 | return -EINVAL; |
||
424 | |||
425 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
||
426 | fb_info.node, fb_info.fix.id); |
||
427 | return 0; |
||
428 | } |
||
429 | |||
430 | /* |
||
431 | * Overrides for Emacs so that we follow Linus's tabbing style. |
||
432 | * --------------------------------------------------------------------------- |
||
433 | * Local variables: |
||
434 | * c-basic-offset: 8 |
||
435 | * End: |
||
436 | */ |
||
437 | |||
438 | MODULE_LICENSE("GPL"); |