Rev 466 | Rev 478 | 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 | |||
183 | static struct fb_ops vesafb_ops = { |
||
184 | .owner = THIS_MODULE, |
||
185 | .fb_setcolreg = vesafb_setcolreg, |
||
186 | .fb_pan_display = vesafb_pan_display, |
||
187 | .fb_fillrect = cfb_fillrect, |
||
188 | .fb_copyarea = cfb_copyarea, |
||
189 | .fb_imageblit = cfb_imageblit, |
||
190 | .fb_cursor = soft_cursor, |
||
191 | }; |
||
192 | |||
193 | int __init vesafb_setup(char *options) |
||
194 | { |
||
195 | char *this_opt; |
||
196 | |||
197 | if (!options || !*options) |
||
198 | return 0; |
||
199 | |||
200 | while ((this_opt = strsep(&options, ",")) != NULL) { |
||
201 | if (!*this_opt) continue; |
||
202 | |||
203 | if (! strcmp(this_opt, "inverse")) |
||
204 | inverse=1; |
||
205 | else if (! strcmp(this_opt, "redraw")) |
||
206 | ypan=0; |
||
207 | else if (! strcmp(this_opt, "ypan")) |
||
208 | ypan=1; |
||
209 | else if (! strcmp(this_opt, "ywrap")) |
||
210 | ypan=2; |
||
211 | else if (! strcmp(this_opt, "vgapal")) |
||
212 | pmi_setpal=0; |
||
213 | else if (! strcmp(this_opt, "pmipal")) |
||
214 | pmi_setpal=1; |
||
215 | else if (! strcmp(this_opt, "mtrr")) |
||
216 | mtrr=1; |
||
217 | else if (! strcmp(this_opt, "nomtrr")) |
||
218 | mtrr=0; |
||
219 | } |
||
220 | return 0; |
||
221 | } |
||
222 | |||
477 | giacomo | 223 | extern VbeInfoBlock VbeInfo; |
224 | extern int vbe_getifo(void); |
||
225 | extern void vm86_init(void); |
||
226 | |||
466 | giacomo | 227 | int __init vesafb_init(void) |
228 | { |
||
477 | giacomo | 229 | ModeInfoBlock ModeInfo; |
466 | giacomo | 230 | int video_cmap_len; |
231 | int i; |
||
232 | |||
477 | giacomo | 233 | vm86_init(); |
234 | |||
235 | if (vbe_getinfo()) |
||
236 | return -EIO; |
||
237 | |||
238 | printk(KERN_INFO "VBE Extension Found.\n"); |
||
239 | |||
240 | screen_info.lfb_base = vbe_getmodeinfo(&ModeInfo,INIT_MODE); |
||
241 | |||
242 | screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB; |
||
243 | |||
466 | giacomo | 244 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) |
245 | return -ENXIO; |
||
246 | |||
477 | giacomo | 247 | screen_info.lfb_depth = ModeInfo.BitsPerPixel; |
248 | screen_info.lfb_width = ModeInfo.XResolution; |
||
249 | screen_info.lfb_height = ModeInfo.YResolution; |
||
250 | screen_info.lfb_linelength = ModeInfo.BytesPerScanLine; |
||
251 | screen_info.lfb_size = VbeInfo.TotalMemory; |
||
252 | screen_info.pages = ModeInfo.NumberOfImagePages; |
||
253 | |||
254 | screen_info.vesapm_seg = 0; |
||
255 | screen_info.vesapm_off = 0; |
||
256 | |||
257 | screen_info.red_pos = ModeInfo.RedFieldPosition; |
||
258 | screen_info.red_size = ModeInfo.RedMaskSize; |
||
259 | screen_info.green_pos = ModeInfo.GreenFieldPosition; |
||
260 | screen_info.green_size = ModeInfo.GreenMaskSize; |
||
261 | screen_info.blue_pos = ModeInfo.BlueFieldPosition; |
||
262 | screen_info.blue_size = ModeInfo.BlueMaskSize; |
||
263 | screen_info.rsvd_pos = ModeInfo.RsvdFieldPosition; |
||
264 | screen_info.rsvd_size = ModeInfo.RsvdMaskSize; |
||
265 | |||
266 | vbe_setmode(INIT_MODE); |
||
267 | |||
466 | giacomo | 268 | vesafb_fix.smem_start = screen_info.lfb_base; |
269 | vesafb_defined.bits_per_pixel = screen_info.lfb_depth; |
||
270 | if (15 == vesafb_defined.bits_per_pixel) |
||
271 | vesafb_defined.bits_per_pixel = 16; |
||
272 | vesafb_defined.xres = screen_info.lfb_width; |
||
273 | vesafb_defined.yres = screen_info.lfb_height; |
||
274 | vesafb_fix.line_length = screen_info.lfb_linelength; |
||
477 | giacomo | 275 | vesafb_fix.smem_len = screen_info.lfb_size; |
466 | giacomo | 276 | vesafb_fix.visual = (vesafb_defined.bits_per_pixel == 8) ? |
277 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
||
278 | |||
279 | /* limit framebuffer size to 16 MB. Otherwise we'll eat tons of |
||
280 | * kernel address space for nothing if the gfx card has alot of |
||
281 | * memory (>= 128 MB isn't uncommon these days ...) */ |
||
282 | if (vesafb_fix.smem_len > 16 * 1024 * 1024) |
||
283 | vesafb_fix.smem_len = 16 * 1024 * 1024; |
||
284 | |||
285 | #ifndef __i386__ |
||
286 | screen_info.vesapm_seg = 0; |
||
287 | #endif |
||
288 | |||
289 | if (!request_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len, "vesafb")) { |
||
290 | printk(KERN_WARNING |
||
291 | "vesafb: abort, cannot reserve video memory at 0x%lx\n", |
||
292 | vesafb_fix.smem_start); |
||
293 | /* We cannot make this fatal. Sometimes this comes from magic |
||
294 | spaces our resource handlers simply don't know about */ |
||
295 | } |
||
296 | |||
297 | fb_info.screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len); |
||
298 | if (!fb_info.screen_base) { |
||
299 | release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len); |
||
300 | printk(KERN_ERR |
||
301 | "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", |
||
302 | vesafb_fix.smem_len, vesafb_fix.smem_start); |
||
303 | return -EIO; |
||
304 | } |
||
305 | |||
306 | printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n", |
||
307 | vesafb_fix.smem_start, fb_info.screen_base, vesafb_fix.smem_len/1024); |
||
308 | printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n", |
||
309 | vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages); |
||
310 | |||
311 | if (screen_info.vesapm_seg) { |
||
312 | printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n", |
||
313 | screen_info.vesapm_seg,screen_info.vesapm_off); |
||
314 | } |
||
315 | |||
316 | if (screen_info.vesapm_seg < 0xc000) |
||
317 | ypan = pmi_setpal = 0; /* not available or some DOS TSR ... */ |
||
318 | |||
319 | if (ypan || pmi_setpal) { |
||
320 | pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); |
||
321 | pmi_start = (void*)((char*)pmi_base + pmi_base[1]); |
||
322 | pmi_pal = (void*)((char*)pmi_base + pmi_base[2]); |
||
323 | printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal); |
||
324 | if (pmi_base[3]) { |
||
325 | printk(KERN_INFO "vesafb: pmi: ports = "); |
||
326 | for (i = pmi_base[3]/2; pmi_base[i] != 0xffff; i++) |
||
327 | printk("%x ",pmi_base[i]); |
||
328 | printk("\n"); |
||
477 | giacomo | 329 | |
466 | giacomo | 330 | if (pmi_base[i] != 0xffff) { |
331 | /* |
||
332 | * memory areas not supported (yet?) |
||
333 | * |
||
334 | * Rules are: we have to set up a descriptor for the requested |
||
335 | * memory area and pass it in the ES register to the BIOS function. |
||
336 | */ |
||
337 | printk(KERN_INFO "vesafb: can't handle memory requests, pmi disabled\n"); |
||
338 | ypan = pmi_setpal = 0; |
||
339 | } |
||
340 | } |
||
341 | } |
||
342 | |||
343 | vesafb_defined.xres_virtual = vesafb_defined.xres; |
||
344 | vesafb_defined.yres_virtual = vesafb_fix.smem_len / vesafb_fix.line_length; |
||
345 | if (ypan && vesafb_defined.yres_virtual > vesafb_defined.yres) { |
||
346 | printk(KERN_INFO "vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n", |
||
347 | (ypan > 1) ? "ywrap" : "ypan",vesafb_defined.yres_virtual); |
||
348 | } else { |
||
349 | printk(KERN_INFO "vesafb: scrolling: redraw\n"); |
||
350 | vesafb_defined.yres_virtual = vesafb_defined.yres; |
||
351 | ypan = 0; |
||
352 | } |
||
353 | |||
354 | /* some dummy values for timing to make fbset happy */ |
||
355 | vesafb_defined.pixclock = 10000000 / vesafb_defined.xres * 1000 / vesafb_defined.yres; |
||
356 | vesafb_defined.left_margin = (vesafb_defined.xres / 8) & 0xf8; |
||
357 | vesafb_defined.hsync_len = (vesafb_defined.xres / 8) & 0xf8; |
||
358 | |||
359 | if (vesafb_defined.bits_per_pixel > 8) { |
||
360 | vesafb_defined.red.offset = screen_info.red_pos; |
||
361 | vesafb_defined.red.length = screen_info.red_size; |
||
362 | vesafb_defined.green.offset = screen_info.green_pos; |
||
363 | vesafb_defined.green.length = screen_info.green_size; |
||
364 | vesafb_defined.blue.offset = screen_info.blue_pos; |
||
365 | vesafb_defined.blue.length = screen_info.blue_size; |
||
366 | vesafb_defined.transp.offset = screen_info.rsvd_pos; |
||
367 | vesafb_defined.transp.length = screen_info.rsvd_size; |
||
368 | printk(KERN_INFO "vesafb: directcolor: " |
||
369 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", |
||
370 | screen_info.rsvd_size, |
||
371 | screen_info.red_size, |
||
372 | screen_info.green_size, |
||
373 | screen_info.blue_size, |
||
374 | screen_info.rsvd_pos, |
||
375 | screen_info.red_pos, |
||
376 | screen_info.green_pos, |
||
377 | screen_info.blue_pos); |
||
378 | video_cmap_len = 16; |
||
379 | } else { |
||
380 | vesafb_defined.red.length = 6; |
||
381 | vesafb_defined.green.length = 6; |
||
382 | vesafb_defined.blue.length = 6; |
||
383 | video_cmap_len = 256; |
||
384 | } |
||
385 | |||
386 | vesafb_fix.ypanstep = ypan ? 1 : 0; |
||
387 | vesafb_fix.ywrapstep = (ypan>1) ? 1 : 0; |
||
388 | |||
389 | /* request failure does not faze us, as vgacon probably has this |
||
390 | * region already (FIXME) */ |
||
391 | request_region(0x3c0, 32, "vesafb"); |
||
392 | |||
393 | if (mtrr) { |
||
394 | int temp_size = vesafb_fix.smem_len; |
||
395 | /* Find the largest power-of-two */ |
||
396 | while (temp_size & (temp_size - 1)) |
||
397 | temp_size &= (temp_size - 1); |
||
398 | |||
399 | /* Try and find a power of two to add */ |
||
400 | while (temp_size && mtrr_add(vesafb_fix.smem_start, temp_size, MTRR_TYPE_WRCOMB, 1)==-EINVAL) { |
||
401 | temp_size >>= 1; |
||
402 | } |
||
403 | } |
||
404 | |||
405 | fb_info.fbops = &vesafb_ops; |
||
406 | fb_info.var = vesafb_defined; |
||
407 | fb_info.fix = vesafb_fix; |
||
408 | fb_info.pseudo_palette = pseudo_palette; |
||
409 | fb_info.flags = FBINFO_FLAG_DEFAULT; |
||
410 | |||
411 | fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0); |
||
412 | |||
413 | if (register_framebuffer(&fb_info)<0) |
||
414 | return -EINVAL; |
||
415 | |||
416 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
||
417 | fb_info.node, fb_info.fix.id); |
||
418 | return 0; |
||
419 | } |
||
420 | |||
421 | /* |
||
422 | * Overrides for Emacs so that we follow Linus's tabbing style. |
||
423 | * --------------------------------------------------------------------------- |
||
424 | * Local variables: |
||
425 | * c-basic-offset: 8 |
||
426 | * End: |
||
427 | */ |
||
428 | |||
429 | MODULE_LICENSE("GPL"); |