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