Subversion Repositories shark

Rev

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