Subversion Repositories shark

Rev

Rev 161 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
132 giacomo 1
/*
2
*/
3
 
4
#include <stdlib.h>
5
#include <stdio.h>              /* for printf */
6
#include <string.h>             /* for memset */
7
#include <unistd.h>
8
//#include <sys/mman.h>         /* for mmap */
9
#include "vga.h"
10
#include "libvga.h"
11
#include "driver.h"
12
 
13
/* New style driver interface. */
14
#include "timing.h"
15
#include "vgaregs.h"
16
#include "interface.h"
17
#include "lrmi.h"
18
#include "vbe.h"
19
#define VESAREG_SAVE(i) (VGA_TOTAL_REGS+i)
20
#define VESA_TOTAL_REGS (VGA_TOTAL_REGS + 4024)
21
 
22
/* #define VESA_savebitmap 0x0e */
23
int __svgalib_VESA_savebitmap=0x0e;
24
int __svgalib_VESA_textmode=3;
25
 
26
static int vesa_init(int, int, int);
27
static void vesa_unlock(void);
28
 
29
static int vesa_memory,vesa_chiptype;
30
static int vesa_is_linear, vesa_logical_width, vesa_bpp, vesa_granularity;
31
static int vesa_regs_size, vesa_linear_base, vesa_last_mode_set;
32
static struct LRMI_regs vesa_r;
33
static int vesa_read_write, vesa_read_window, vesa_write_window;
34
static void * LRMI_mem1, * LRMI_mem2;
35
 
36
static CardSpecs *cardspecs;
37
static struct
38
        {
39
        struct vbe_info_block *info;
40
        struct vbe_mode_info_block *mode;
41
        } vesa_data;
42
 
43
static int SVGALIB_VESA[__GLASTMODE+1];
44
 
45
char VideoModeNames [96][40] = {
46
   "100 - 640x400      256 colors", "101 - 640x480      256 colors",  "102 - 800x600       16 colors",
47
   "103 - 800x600      256 colors", "104 - 1024x768      16 colors",  "105 - 1024x768     256 colors",
48
   "106 - 1280x1024     16 colors", "107 - 1280x1024    256 colors",  "108 - 80x60         Text Mode",
49
   "109 - 132x25        Text Mode", "10A - 132x43        Text Mode",  "10B - 132x50        Text Mode",
50
   "10C - 132x60        Text Mode", "10D - 320x200   32,768 colors",  "10E - 320x200   65,536 colors",
51
   "10F - 320x200      16m colors", "110 - 640x480   32,768 colors",  "111 - 640x480   65,536 colors",
52
   "112 - 640x480      16m colors", "113 - 800x600   32,768 colors",  "114 - 800x600   65,536 colors",
53
   "115 - 800x600      16m colors", "116 - 1024x768  32,768 colors",  "117 - 1024x768  65,536 colors",
54
   "118 - 1024x768     16m colors", "119 - 1280x1024 32,768 colors",  "11A - 1280x1024 65,536 colors",
55
   "11B - 1280x1024    16m colors", "11C - 640x350      256 colors",  "11D - 640x350   32,768 colors",
56
   "11E - 640x400   32,768 colors", "11F - 640x350   65,536 colors",  "120 - 640x400   65,536 colors",
57
   "121 - 640x350      16m colors", "122 - 640x400      16m colors",  "123 - 1600x1200     16 colors",
58
   "124 - 1600x1200    256 colors", "125 - 1600x1200 32,768 colors",  "126 - 1600x1200 65,536 colors",
59
   "127 - 1600x1200    16m colors", "128 - 640x480   16m colors(*)",  "129 - 800x600   16m colors(*)",
60
   "12A - 1024x768  16m colors(*)", "12B - 1280x1024 16m colors(*)",  "12C - 1600x1200 16m colors(*)",
61
   "12D - 320x240   32,768 colors", "12E - 320x400   32,768 colors",  "12F - 360x200   32,768 colors",
62
   "130 - 360x240   32,768 colors", "131 - 360x400   32,768 colors",  "132 - 320x240   65,536 colors",
63
   "133 - 320x400   65,536 colors", "134 - 360x200   65,536 colors",  "135 - 360x240   65,536 colors",
64
   "136 - 360x400   65,536 colors", "137 - 320x240      16m colors",  "138 - 320x400      16m colors",
65
   "139 - name n/a",                "13A - name n/a",                 "13B - name n/a",
66
   "13C - name n/a",                "13D - name n/a",                 "13E - name n/a",
67
   "13F - name n/a",                "140 - name n/a",                 "141 - name n/a",
68
   "142 - 640x350   16m colors(*)", "143 - 640x400   16m colors(*)",  "144 - name n/a",
69
   "145 - name n/a",                "146 - name n/a",                 "147 - name n/a",
70
   "148 - name n/a",                "149 - name n/a",                 "14A - name n/a",
71
   "14B - name n/a",                "14C - name n/a",                 "14D - name n/a",
72
   "14E - name n/a",                "14F - name n/a",                 "150 - 640x350       16 colors",
73
   "151 - 640x400       16 colors", "152 - 640x480       16 colors",  "153 - 320x200      256 colors",
74
   "154 - 320x240      256 colors", "155 - 320x400      256 colors",  "156 - 360x200      256 colors",
75
   "157 - 360x240      256 colors", "158 - 360x400      256 colors",  "159 - name n/a",
76
   "15A - name n/a",                "15B - name n/a",                 "15C - name n/a",
77
   "15D - name n/a",                "15E - name n/a",                 "15F - name n/a"
78
};
79
 
80
static void vesa_setpage(int page)
81
{
82
vesa_r.eax=0x4f05;
83
vesa_r.ebx=0;
84
vesa_r.edx=page*64/vesa_granularity;
85
__svgalib_LRMI_int(0x10,&vesa_r);
86
 
87
if(vesa_read_write){
88
   vesa_r.eax=0x4f05;
89
   vesa_r.ebx=1;
90
   vesa_r.edx=page*64/vesa_granularity;
91
   __svgalib_LRMI_int(0x10,&vesa_r);
92
};
93
}
94
 
95
 
96
static int __svgalib_vesa_inlinearmode(void)
97
{
98
return vesa_is_linear;
99
}
100
 
101
 
102
/* Fill in chipset specific mode information */
103
 
104
static void vesa_getmodeinfo(int mode, vga_modeinfo *modeinfo)
105
{
106
    if (IS_IN_STANDARD_VGA_DRIVER(mode))
107
        return __svgalib_vga_driverspecs.getmodeinfo(mode, modeinfo);
108
 
109
    if(modeinfo->colors==16)return;
110
 
111
    modeinfo->maxpixels = vesa_memory*1024/modeinfo->bytesperpixel;
112
    modeinfo->maxlogicalwidth = 4088; /* just a guess, */
113
    modeinfo->startaddressrange = vesa_memory * 1024 - 1;
114
    modeinfo->haveblit = 0;
115
    modeinfo->flags &= ~HAVE_RWPAGE;
116
    modeinfo->flags |= vesa_read_write;  /* sets HAVE_RWPAGE bit */
117
 
118
    /* for linear need VBE2 */
119
    if(vesa_chiptype>=1)
120
      if (modeinfo->bytesperpixel >= 1) {
121
        modeinfo->flags |= CAPABLE_LINEAR;
122
        if (__svgalib_vesa_inlinearmode())
123
            modeinfo->flags |= IS_LINEAR | LINEAR_MODE;
124
      }
125
 
126
    /* to get the logical scanline width */
127
    memset(&vesa_r, 0, sizeof(vesa_r));
128
 
129
    vesa_r.eax = 0x4f01;
130
    vesa_r.ecx = SVGALIB_VESA[mode];
131
    vesa_r.es = (unsigned int)vesa_data.mode >> 4;
132
    vesa_r.edi = (unsigned int)vesa_data.mode & 0xf;
133
 
134
    if (!__svgalib_LRMI_int(0x10, &vesa_r)) {
135
       printk(KERN_ERR "Can't get mode info (vm86 failure)\n");
136
       return;
137
    }
138
    modeinfo->linewidth = vesa_data.mode->bytes_per_scanline;
139
}
140
 
141
/* Read and save chipset-specific registers */
142
static int vesa_saveregs(uint8_t regs[])
143
{
144
  void * buf;
145
  buf=LRMI_mem1;
146
  vesa_r.eax=0x4f04;
147
  vesa_r.ebx=0;
148
  vesa_r.es=((long)buf)>>4;
149
  vesa_r.edx=1;
150
  vesa_r.ecx=__svgalib_VESA_savebitmap;
151
  __svgalib_LRMI_int(0x10,&vesa_r);
152
  memcpy(&regs[VGA_TOTAL_REGS],buf,vesa_regs_size);  
153
    return vesa_regs_size;
154
}
155
 
156
/* Set chipset-specific registers */
157
 
158
static void vesa_setregs(const uint8_t regs[], int mode)
159
{  
160
 
161
  void * buf;
162
  buf=LRMI_mem1;
163
  memcpy(buf,&regs[VGA_TOTAL_REGS],vesa_regs_size);  
164
  vesa_r.eax=0x4f04;
165
  vesa_r.ebx=0;
166
  vesa_r.es=((long)buf)>>4;
167
  vesa_r.edx=2;
168
  vesa_r.ecx=__svgalib_VESA_savebitmap;
169
  __svgalib_LRMI_int(0x10,&vesa_r);
170
}
171
 
172
 
173
/* Return nonzero if mode is available */
174
 
175
static int vesa_modeavailable(int mode)
176
{
177
    struct info *info;
178
    ModeTiming *modetiming;
179
    ModeInfo *modeinfo;
180
 
181
 
182
    if (IS_IN_STANDARD_VGA_DRIVER(mode))
183
        return __svgalib_vga_driverspecs.modeavailable(mode);
184
 
185
    info = &__svgalib_infotable[mode];
186
 
187
    modeinfo = __svgalib_createModeInfoStructureForSvgalibMode(mode);
188
 
189
    modetiming = malloc(sizeof(ModeTiming));
190
    if (__svgalib_getmodetiming(modetiming, modeinfo, cardspecs)) {
191
        free(modetiming);
192
        free(modeinfo);
193
        return 0;
194
    }
195
    free(modetiming);
196
    free(modeinfo);
197
 
198
return SVGALIB_VESA[mode];
199
}
200
 
201
 
202
static int vesa_setmode(int mode, int prv_mode)
203
{
204
    vesa_bpp=1;
205
    vesa_granularity=1;
206
    if (IS_IN_STANDARD_VGA_DRIVER(mode)) {
207
 
208
        if(__svgalib_vesatext){
209
            vesa_r.eax=0x4f02; /* make sure we are in a regular VGA mode before we start */
210
            vesa_r.ebx=__svgalib_VESA_textmode;    /* without this, if we start in SVGA mode the result might */
211
            __svgalib_LRMI_int(0x10,&vesa_r); /* be something weird */
212
        };
213
        return __svgalib_vga_driverspecs.setmode(mode, prv_mode);
214
    }
215
    if (!vesa_modeavailable(mode)) return 1;
216
    vesa_r.eax=0x4f02;
217
    vesa_r.ebx=SVGALIB_VESA[mode]|0x8000|(vesa_is_linear*0x4000);
218
    vesa_last_mode_set=vesa_r.ebx;
219
    __svgalib_LRMI_int(0x10,&vesa_r);
220
 
221
    vesa_data.info = LRMI_mem2 ;
222
    vesa_data.mode = (struct vbe_mode_info_block *)(vesa_data.info + 1);
223
    vesa_r.eax = 0x4f01;
224
    vesa_r.ecx=SVGALIB_VESA[mode];
225
    vesa_r.es = (unsigned int)vesa_data.mode >> 4;
226
    vesa_r.edi = (unsigned int)vesa_data.mode&0xf;    
227
    __svgalib_LRMI_int(0x10, &vesa_r);
228
    vesa_logical_width=vesa_data.mode->bytes_per_scanline;
229
    vesa_bpp=(vesa_data.mode->bits_per_pixel+7)/8;
230
    if(vesa_logical_width==0) vesa_logical_width=vesa_bpp*vesa_data.mode->x_resolution;
231
                                                /* if not reported then guess */
232
    vesa_granularity=vesa_data.mode->win_granularity;
233
    if(vesa_granularity==0)vesa_granularity=64; /* if not reported then guess */
234
    if(vesa_chiptype>=1)vesa_linear_base=vesa_data.mode->phys_base_ptr;
235
    vesa_read_write=0;
236
    vesa_read_window=0;
237
    vesa_write_window=0;
238
    if((vesa_data.mode->win_a_attributes&6)!=6){
239
        vesa_read_write=1;
240
        if ((vesa_data.mode->win_b_attributes&2) == 2) vesa_read_window=1;
241
        if ((vesa_data.mode->win_b_attributes&4) == 4) vesa_write_window=1;
242
    }
243
    return 0;
244
}
245
 
246
 
247
/* Unlock chipset-specific registers */
248
 
249
static void vesa_unlock(void)
250
{
251
}
252
 
253
 
254
/* Relock chipset-specific registers */
255
/* (currently not used) */
256
 
257
static void vesa_lock(void)
258
{
259
}
260
 
261
 
262
/* Indentify chipset, initialize and return non-zero if detected */
263
 
264
int vesa_test(void)
265
{
266
        __svgalib_LRMI_init();
267
        LRMI_mem2 = __svgalib_LRMI_alloc_real(sizeof(struct vbe_info_block)
268
                                        + sizeof(struct vbe_mode_info_block));
269
        vesa_data.info = LRMI_mem2;
270
        vesa_data.mode = (struct vbe_mode_info_block *)(vesa_data.info + 1);
271
        vesa_r.eax = 0x4f00;
272
        vesa_r.es = (unsigned int)vesa_data.info >> 4;
273
        vesa_r.ds = (unsigned int)vesa_data.info >> 4;
274
        vesa_r.edi = 0;
275
 
276
        __svgalib_LRMI_free_real(LRMI_mem2,sizeof(struct vbe_info_block) + sizeof(struct vbe_mode_info_block));
277
 
278
        __svgalib_LRMI_int(0x10, &vesa_r);
279
 
280
        printk(KERN_INFO "Int 0x10 result ax=%2x\n",vesa_r.eax);
281
 
282
        if (vesa_r.eax!=0x4f) return 0;
283
        return !vesa_init(0,0,0);
284
}
285
 
286
 
287
/* No r/w paging */
288
static void vesa_setrdpage(int page)
289
{
290
vesa_r.eax=0x4f05;
291
vesa_r.ebx=vesa_read_window;
292
vesa_r.edx=page*64/vesa_granularity;
293
__svgalib_LRMI_int(0x10,&vesa_r);
294
}
295
static void vesa_setwrpage(int page)
296
{
297
vesa_r.eax=0x4f05;
298
vesa_r.ebx=vesa_write_window;
299
vesa_r.edx=page*64/vesa_granularity;
300
__svgalib_LRMI_int(0x10,&vesa_r);
301
}
302
 
303
 
304
/* Set display start address (not for 16 color modes) */
305
 
306
static void vesa_setdisplaystart(int address)
307
{
308
  vesa_r.eax=0x4f07;
309
  vesa_r.ebx=0;
310
  vesa_r.ecx=address % vesa_logical_width;
311
  vesa_r.edx=address / vesa_logical_width;
312
 
313
  __svgalib_LRMI_int(0x10,&vesa_r);
314
 
315
}
316
 
317
/* Set logical scanline length (usually multiple of 8) */
318
 
319
static void vesa_setlogicalwidth(int width)
320
{
321
  vesa_r.eax=0x4f06;
322
  vesa_r.ebx=0;
323
  vesa_r.ecx=width / vesa_bpp ;
324
  __svgalib_LRMI_int(0x10,&vesa_r);
325
  vesa_logical_width=vesa_r.ebx;
326
 
327
}
328
 
329
static int vesa_linear(int op, int param)
330
{
331
if (op==LINEAR_ENABLE) {  
332
  vesa_r.eax=0x4f02;
333
  vesa_r.ebx=vesa_last_mode_set|0x4000;
334
  __svgalib_LRMI_int(0x10,&vesa_r);
335
  vesa_is_linear=1;
336
};
337
 
338
if (op==LINEAR_DISABLE){
339
  vesa_r.eax=0x4f02;
340
  vesa_r.ebx=vesa_last_mode_set;
341
  __svgalib_LRMI_int(0x10,&vesa_r);
342
  vesa_is_linear=0;
343
};
344
if (op==LINEAR_QUERY_BASE) {return vesa_linear_base ;}
345
if (op == LINEAR_QUERY_RANGE || op == LINEAR_QUERY_GRANULARITY) return 0;               /* No granularity or range. */
346
    else return -1;             /* Unknown function. */
347
}
348
 
349
static int vesa_match_programmable_clock(int clock)
350
{
351
return clock ;
352
}
353
static int vesa_map_clock(int bpp, int clock)
354
{
355
return clock ;
356
}
357
static int vesa_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
358
{
359
return htiming;
360
}
361
/* Function table (exported) */
362
 
363
DriverSpecs __svgalib_vesa_driverspecs =
364
{
365
    vesa_saveregs,
366
    vesa_setregs,
367
    vesa_unlock,
368
    vesa_lock,
369
    vesa_test,
370
    vesa_init,
371
    vesa_setpage,
372
    vesa_setrdpage,
373
    vesa_setwrpage,
374
    vesa_setmode,
375
    vesa_modeavailable,
376
    vesa_setdisplaystart,
377
    vesa_setlogicalwidth,
378
    vesa_getmodeinfo,
379
    0,                          /* old blit funcs */
380
    0,
381
    0,
382
    0,
383
    0,
384
    0,                          /* ext_set */
385
    0,                          /* accel */
386
    vesa_linear,
387
    0,                          /* accelspecs, filled in during init. */
388
    NULL,                       /* Emulation */
389
};
390
 
391
/* Initialize chipset (called after detection) */
392
 
393
static int vesa_init(int force, int par1, int par2)
394
{  
395
    short int *mode_list;
396
    int i;
397
 
398
    __svgalib_textprog|=1;
399
 
400
    /* Get I/O priviledge */
401
 
402
    if (force) {
403
        vesa_memory = par1;
404
        vesa_chiptype = par2;
405
    } else {
406
        vesa_memory=4096;
407
    };
408
 
409
    vesa_data.info = __svgalib_LRMI_alloc_real(sizeof(struct vbe_info_block)
410
         + sizeof(struct vbe_mode_info_block));
411
    vesa_data.mode = (struct vbe_mode_info_block *)(vesa_data.info + 1);
412
    vesa_r.eax = 0x4f00;
413
    vesa_r.es = (unsigned int)vesa_data.info >> 4;
414
    vesa_r.ds = (unsigned int)vesa_data.info >> 4;
415
    vesa_r.edi = 0;
416
 
417
    memcpy(vesa_data.info->vbe_signature, "VBE2", 4);
418
 
419
    __svgalib_LRMI_int(0x10, &vesa_r);
420
 
421
    if ((vesa_r.eax & 0xffff) != 0x4f || strncmp(vesa_data.info->vbe_signature, "VESA", 4) != 0) {
422
        printk(KERN_ERR "No VESA bios detected!\n");
423
        printk(KERN_ERR "Try running vga_reset.\n");
424
        return 1;
425
    }
426
 
427
    if(vesa_data.info->vbe_version>=0x0200)vesa_chiptype=1 ; else vesa_chiptype=0;
428
    if(vesa_data.info->vbe_version>=0x0300)vesa_chiptype=2 ;
429
 
430
    vesa_memory = vesa_data.info->total_memory*64;
431
 
432
    for(i=0;i<__GLASTMODE;i++)SVGALIB_VESA[i]=IS_IN_STANDARD_VGA_DRIVER(i);
433
 
434
    mode_list = (short int *)(vesa_data.info->video_mode_list_seg * 16 + vesa_data.info->video_mode_list_off);
435
 
436
    while (*mode_list != -1) {
437
       memset(&vesa_r, 0, sizeof(vesa_r));
438
 
439
       vesa_r.eax = 0x4f01;
440
       vesa_r.ecx = *mode_list;
441
       vesa_r.es = (unsigned int)vesa_data.mode >> 4;
442
       vesa_r.ds = (unsigned int)vesa_data.mode >> 4;
443
       vesa_r.edi = (unsigned int)vesa_data.mode & 0xf;
444
 
445
       if((vesa_chiptype>=1)&&(vesa_data.mode->mode_attributes&0x80))
446
          vesa_linear_base=vesa_data.mode->phys_base_ptr;
447
       if (!__svgalib_LRMI_int(0x10, &vesa_r)) {
448
          printk(KERN_ERR "Can't get mode info (vm86 failure)\n");
449
          return 1;
450
       }
451
 
452
       for(i=0;i<=__GLASTMODE;i++)
453
          if((infotable[i].xdim==vesa_data.mode->x_resolution)&&
454
             (infotable[i].ydim==vesa_data.mode->y_resolution)&&
455
             (((vesa_data.mode->rsvd_mask_size==8)&&(infotable[i].bytesperpixel==4))||
456
              ((vesa_data.mode->bits_per_pixel==32)&&(infotable[i].bytesperpixel==4))||
457
              ((vesa_data.mode->bits_per_pixel==24)&&(infotable[i].bytesperpixel==3))||
458
              ((vesa_data.mode->green_mask_size==5)&&(infotable[i].colors==32768))||
459
              ((vesa_data.mode->green_mask_size==6)&&(infotable[i].colors==65536))||
460
              ((vesa_data.mode->memory_model==VBE_MODEL_PLANAR)&&(infotable[i].colors==16))||
461
              ((vesa_data.mode->memory_model==VBE_MODEL_256)&&(infotable[i].colors==256))||
462
              ((vesa_data.mode->memory_model==VBE_MODEL_PACKED)&&
463
               (infotable[i].colors==256)&&(vesa_data.mode->bits_per_pixel==8)))){
464
                        SVGALIB_VESA[i]=*mode_list;
465
                        i=__GLASTMODE+1;
466
          };
467
 
468
        mode_list++;
469
 
470
    };
471
 
472
    vesa_r.eax=0x4f04;
473
    vesa_r.edx=0;
474
    vesa_r.ecx=__svgalib_VESA_savebitmap;
475
    vesa_r.ebx=0;
476
    __svgalib_LRMI_int(0x10,&vesa_r);
477
    vesa_regs_size=vesa_r.ebx*64;
478
    __svgalib_LRMI_free_real(vesa_data.info,sizeof(vesa_data.info));
479
 
480
    SVGALIB_VESA[TEXT]=3;
481
 
482
    cardspecs = malloc(sizeof(CardSpecs));
483
    cardspecs->videoMemory = vesa_memory;
484
    cardspecs->maxPixelClock4bpp = 300000;     
485
    cardspecs->maxPixelClock8bpp = 300000;     
486
    cardspecs->maxPixelClock16bpp = 300000;    
487
    cardspecs->maxPixelClock24bpp = 300000;
488
    cardspecs->maxPixelClock32bpp = 300000;
489
    cardspecs->flags = CLOCK_PROGRAMMABLE;
490
    cardspecs->maxHorizontalCrtc = 4088;
491
    cardspecs->nClocks =1;
492
    cardspecs->clocks = NULL;
493
    cardspecs->mapClock = vesa_map_clock;
494
    cardspecs->mapHorizontalCrtc = vesa_map_horizontal_crtc;
495
    cardspecs->matchProgrammableClock=vesa_match_programmable_clock;
496
    __svgalib_driverspecs = &__svgalib_vesa_driverspecs;
497
 
498
    LRMI_mem1 = __svgalib_LRMI_alloc_real(vesa_regs_size);
499
    LRMI_mem2 = __svgalib_LRMI_alloc_real(sizeof(struct vbe_info_block)
500
                                    + sizeof(struct vbe_mode_info_block));
501
 
502
    __svgalib_banked_mem_base=0xa0000;
503
    __svgalib_banked_mem_size=0x10000;
504
    if(vesa_chiptype>=1) {
505
      __svgalib_linear_mem_base=vesa_linear_base;
506
      __svgalib_linear_mem_size=vesa_memory*0x400;
507
    };
508
 
509
    if (__svgalib_driver_report) {
510
        printk(KERN_INFO "Using VESA driver, %iKB. %s\n",vesa_memory,
511
                (vesa_chiptype==2)?"VBE3":(vesa_chiptype?"VBE2.0":"VBE1.2"));
512
    }
513
 
514
    sleep(4);
515
 
516
    return 0;
517
 
518
}