Subversion Repositories shark

Rev

Rev 190 | Rev 192 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 pj 1
/* SVGA Lib - Linker module to use the low level driver
2
 * without the vga.c support
3
 *
4
*/
5
 
6
/* variables used to shift between monchrome and color emulation */
7
#include <stdint.h>
8
#include <unistd.h>
9
 
10
#include <ll/i386/hw-data.h>
11
#include <ll/i386/mem.h>
12
#include <ll/i386/cons.h>
13
#include <ll/sys/ll/ll-func.h>
14
 
15
#include "libvga.h"
16
#include "vgaversion.h"
17
#include "vgaio.h"
18
#include "driver.h"
184 giacomo 19
#include "lrmi.h"
54 pj 20
 
21
int __svgalib_CRT_I;                    /* current CRT index register address */
22
int __svgalib_CRT_D;                    /* current CRT data register address */
23
int __svgalib_IS1_R;                    /* current input status register address */
24
static int color_text;                  /* true if color text emulation */
25
 
26
uint8_t *BANKED_POINTER=NULL, *LINEAR_POINTER;
27
uint8_t *MMIO_POINTER;
28
uint8_t *SPARSE_MMIO;
29
static int mmio_mapped=0, mem_mapped=0;
30
static uint8_t *B8000_POINTER=NULL;
31
unsigned long __svgalib_banked_mem_base, __svgalib_banked_mem_size;
32
unsigned long __svgalib_mmio_base, __svgalib_mmio_size=0;
33
unsigned long __svgalib_linear_mem_base=0, __svgalib_linear_mem_size=0;
34
 
35
extern int init_vgapci(void);
36
extern int nv3_test(void);
37
extern int savage_test(void);
74 giacomo 38
extern int r128_test(void);
132 giacomo 39
extern int neo_test(void);
40
extern int vesa_test(void);
169 giacomo 41
extern int s3_test(void);
54 pj 42
 
43
/* If == 0 then nothing is defined by the user... */
44
int __svgalib_default_mode = 10;
45
 
46
struct info infotable[] =
47
{
48
    {80, 25, 16, 160, 0},       /* VGAlib VGA modes */
49
    {320, 200, 16, 40, 0},
50
    {640, 200, 16, 80, 0},
51
    {640, 350, 16, 80, 0},
52
    {640, 480, 16, 80, 0},
53
    {320, 200, 256, 320, 1},
54
    {320, 240, 256, 80, 0},
55
    {320, 400, 256, 80, 0},
56
    {360, 480, 256, 90, 0},
57
    {640, 480, 2, 80, 0},
58
 
59
    {640, 480, 256, 640, 1},    /* VGAlib SVGA modes */
60
    {800, 600, 256, 800, 1},
61
    {1024, 768, 256, 1024, 1},
62
    {1280, 1024, 256, 1280, 1},
63
 
64
    {320, 200, 1 << 15, 640, 2},        /* Hicolor/truecolor modes */
65
    {320, 200, 1 << 16, 640, 2},
66
    {320, 200, 1 << 24, 320 * 3, 3},
67
    {640, 480, 1 << 15, 640 * 2, 2},
68
    {640, 480, 1 << 16, 640 * 2, 2},
69
    {640, 480, 1 << 24, 640 * 3, 3},
70
    {800, 600, 1 << 15, 800 * 2, 2},
71
    {800, 600, 1 << 16, 800 * 2, 2},
72
    {800, 600, 1 << 24, 800 * 3, 3},
73
    {1024, 768, 1 << 15, 1024 * 2, 2},
74
    {1024, 768, 1 << 16, 1024 * 2, 2},
75
    {1024, 768, 1 << 24, 1024 * 3, 3},
76
    {1280, 1024, 1 << 15, 1280 * 2, 2},
77
    {1280, 1024, 1 << 16, 1280 * 2, 2},
78
    {1280, 1024, 1 << 24, 1280 * 3, 3},
79
 
80
    {800, 600, 16, 100, 0},     /* SVGA 16-color modes */
81
    {1024, 768, 16, 128, 0},
82
    {1280, 1024, 16, 160, 0},
83
 
84
    {720, 348, 2, 90, 0},       /* Hercules emulation mode */
85
 
86
    {320, 200, 1 << 24, 320 * 4, 4},
87
    {640, 480, 1 << 24, 640 * 4, 4},
88
    {800, 600, 1 << 24, 800 * 4, 4},
89
    {1024, 768, 1 << 24, 1024 * 4, 4},
90
    {1280, 1024, 1 << 24, 1280 * 4, 4},
91
 
92
    {1152, 864, 16, 144, 0},
93
    {1152, 864, 256, 1152, 1},
94
    {1152, 864, 1 << 15, 1152 * 2, 2},
95
    {1152, 864, 1 << 16, 1152 * 2, 2},
96
    {1152, 864, 1 << 24, 1152 * 3, 3},
97
    {1152, 864, 1 << 24, 1152 * 4, 4},
98
 
99
    {1600, 1200, 16, 200, 0},
100
    {1600, 1200, 256, 1600, 1},
101
    {1600, 1200, 1 << 15, 1600 * 2, 2},
102
    {1600, 1200, 1 << 16, 1600 * 2, 2},
103
    {1600, 1200, 1 << 24, 1600 * 3, 3},
104
    {1600, 1200, 1 << 24, 1600 * 4, 4},
105
 
106
    {320, 240, 256, 320, 1},   
107
    {320, 240, 1<<15, 320*2, 2},
108
    {320, 240, 1<<16, 320*2, 2},
109
    {320, 240, 1<<24, 320*3, 3},
110
    {320, 240, 1<<24, 320*4, 4},
111
 
112
    {400, 300, 256, 400, 1},
113
    {400, 300, 1<<15, 400*2, 2},
114
    {400, 300, 1<<16, 400*2, 2},
115
    {400, 300, 1<<24, 400*3, 3},
116
    {400, 300, 1<<24, 400*4, 4},
117
 
118
    {512, 384, 256, 512, 1},           
119
    {512, 384, 1<<15, 512*2, 2},
120
    {512, 384, 1<<16, 512*2, 2},
121
    {512, 384, 1<<24, 512*3, 3},
122
    {512, 384, 1<<24, 512*4, 4},
123
 
124
    {960, 720, 256, 960, 1},           
125
    {960, 720, 1<<15, 960*2, 2},
126
    {960, 720, 1<<16, 960*2, 2},
127
    {960, 720, 1<<24, 960*3, 3},
128
    {960, 720, 1<<24, 960*4, 4},
129
 
130
    {1920, 1440, 256, 1920, 1},        
131
    {1920, 1440, 1<<15, 1920*2, 2},
132
    {1920, 1440, 1<<16, 1920*2, 2},
133
    {1920, 1440, 1<<24, 1920*3, 3},
134
    {1920, 1440, 1<<24, 1920*4, 4},
135
 
136
    {320, 400, 1<<8,  320,   1},
137
    {320, 400, 1<<15, 320*2, 2},
138
    {320, 400, 1<<16, 320*2, 2},
139
    {320, 400, 1<<24, 320*3, 3},
140
    {320, 400, 1<<24, 320*4, 4},
141
 
142
    {640, 400, 256, 640, 1},
143
    {640, 400, 1<<15, 640*2, 2},
144
    {640, 400, 1<<16, 640*2, 2},
145
    {640, 400, 1<<24, 640*3, 3},
146
    {640, 400, 1<<24, 640*4, 4},
147
 
148
    {320, 480, 256, 320, 1},
149
    {320, 480, 1<<15, 320*2, 2},
150
    {320, 480, 1<<16, 320*2, 2},
151
    {320, 480, 1<<24, 320*3, 3},
152
    {320, 480, 1<<24, 320*4, 4},
153
 
154
    {720, 540, 256, 720, 1},
155
    {720, 540, 1<<15, 720*2, 2},
156
    {720, 540, 1<<16, 720*2, 2},
157
    {720, 540, 1<<24, 720*3, 3},
158
    {720, 540, 1<<24, 720*4, 4},
159
 
160
    {848, 480, 256, 848, 1},
161
    {848, 480, 1<<15, 848*2, 2},
162
    {848, 480, 1<<16, 848*2, 2},
163
    {848, 480, 1<<24, 848*3, 3},
164
    {848, 480, 1<<24, 848*4, 4},
165
 
166
    {1072, 600, 256, 1072, 1},
167
    {1072, 600, 1<<15, 1072*2, 2},
168
    {1072, 600, 1<<16, 1072*2, 2},
169
    {1072, 600, 1<<24, 1072*3, 3},
170
    {1072, 600, 1<<24, 1072*4, 4},
171
 
172
    {1280, 720, 256, 1280, 1},
173
    {1280, 720, 1<<15, 1280*2, 2},
174
    {1280, 720, 1<<16, 1280*2, 2},
175
    {1280, 720, 1<<24, 1280*3, 3},
176
    {1280, 720, 1<<24, 1280*4, 4},
177
 
178
    {1360, 768, 256, 1360, 1},
179
    {1360, 768, 1<<15, 1360*2, 2},
180
    {1360, 768, 1<<16, 1360*2, 2},
181
    {1360, 768, 1<<24, 1360*3, 3},
182
    {1360, 768, 1<<24, 1360*4, 4},
183
 
184
    {1800, 1012, 256, 1800, 1},
185
    {1800, 1012, 1<<15, 1800*2, 2},
186
    {1800, 1012, 1<<16, 1800*2, 2},
187
    {1800, 1012, 1<<24, 1800*3, 3},
188
    {1800, 1012, 1<<24, 1800*4, 4},
189
 
190
    {1920, 1080, 256, 1920, 1},
191
    {1920, 1080, 1<<15, 1920*2, 2},
192
    {1920, 1080, 1<<16, 1920*2, 2},
193
    {1920, 1080, 1<<24, 1920*3, 3},
194
    {1920, 1080, 1<<24, 1920*4, 4},
195
 
196
    {2048, 1152, 256, 2048, 1},
197
    {2048, 1152, 1<<15, 2048*2, 2},
198
    {2048, 1152, 1<<16, 2048*2, 2},
199
    {2048, 1152, 1<<24, 2048*3, 3},
200
    {2048, 1152, 1<<24, 2048*4, 4},
201
 
202
    {2048, 1536, 256, 2048, 1},
203
    {2048, 1536, 1<<15, 2048*2, 2},
204
    {2048, 1536, 1<<16, 2048*2, 2},
205
    {2048, 1536, 1<<24, 2048*3, 3},
206
    {2048, 1536, 1<<24, 2048*4, 4},
207
 
208
    {512, 480, 256, 512, 1},           
209
    {512, 480, 1<<15, 512*2, 2},
210
    {512, 480, 1<<16, 512*2, 2},
211
    {512, 480, 1<<24, 512*3, 3},
212
    {512, 480, 1<<24, 512*4, 4},
213
 
214
    {400, 600, 256, 400, 1},
215
    {400, 600, 1<<15, 400*2, 2},
216
    {400, 600, 1<<16, 400*2, 2},
217
    {400, 600, 1<<24, 400*3, 3},
218
    {400, 600, 1<<24, 400*4, 4},
219
 
220
    {400, 300, 256, 100, 0},
221
    {320, 200, 256, 320, 1},
222
    {0, 0, 0, 0, 0},
223
    {0, 0, 0, 0, 0},
224
    {0, 0, 0, 0, 0},
225
    {0, 0, 0, 0, 0},
226
    {0, 0, 0, 0, 0},
227
    {0, 0, 0, 0, 0},
228
    {0, 0, 0, 0, 0},
229
    {0, 0, 0, 0, 0},
230
    {0, 0, 0, 0, 0},
231
    {0, 0, 0, 0, 0},
232
    {0, 0, 0, 0, 0},
233
    {0, 0, 0, 0, 0},
234
    {0, 0, 0, 0, 0},
235
    {0, 0, 0, 0, 0},
236
    {0, 0, 0, 0, 0}
237
};
238
 
239
#define MAX_MODES (sizeof(infotable) / sizeof(struct info))
240
 
241
void (*__svgalib_go_to_background) (void) = 0;
242
void (*__svgalib_come_from_background) (void) = 0;
243
static int release_acquire=0;
244
 
245
unsigned long __svgalib_graph_base = GRAPH_BASE;
246
 
247
unsigned char __svgalib_novga = 0;     /* Does not have VGA circuitry on board */
248
unsigned char __svgalib_vesatext = 0;
249
unsigned char __svgalib_textprog = 0;  /* run a program when returning to text mode */
250
unsigned char __svgalib_secondary = 0; /* this is not the main card with VC'S ) */
251
unsigned char __svgalib_emulatepage = 0; /* don't use 0xa0000 memory */
252
unsigned char __svgalib_novccontrol = 0; /* this is not the main card with VC'S  */
253
unsigned char __svgalib_ragedoubleclock = 0;
254
unsigned char __svgalib_simple = 0;
255
 
256
/* default palette values */
257
static const unsigned char default_red[256]
258
=
259
{0, 0, 0, 0, 42, 42, 42, 42, 21, 21, 21, 21, 63, 63, 63, 63,
260
 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
261
 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16,
262
 0, 0, 0, 0, 0, 0, 0, 0, 31, 39, 47, 55, 63, 63, 63, 63,
263
 63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31,
264
 45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49,
265
 45, 45, 45, 45, 45, 45, 45, 45, 0, 7, 14, 21, 28, 28, 28, 28,
266
 28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0,
267
 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17,
268
 14, 14, 14, 14, 14, 14, 14, 14, 20, 22, 24, 26, 28, 28, 28, 28,
269
 28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20,
270
 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4,
271
 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 16, 16, 16,
272
 16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8,
273
 11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12,
274
 11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0};
275
static const unsigned char default_green[256]
276
=
277
{0, 0, 42, 42, 0, 0, 21, 42, 21, 21, 63, 63, 21, 21, 63, 63,
278
 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
279
 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63,
280
 63, 63, 63, 63, 63, 47, 31, 16, 31, 31, 31, 31, 31, 31, 31, 31,
281
 31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
282
 45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63,
283
 63, 63, 63, 63, 63, 58, 54, 49, 0, 0, 0, 0, 0, 0, 0, 0,
284
 0, 7, 14, 21, 29, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7,
285
 14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28,
286
 28, 28, 28, 28, 28, 24, 21, 17, 20, 20, 20, 20, 20, 20, 20, 20,
287
 20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
288
 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16,
289
 16, 16, 16, 16, 16, 12, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8,
290
 8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
291
 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16,
292
 16, 16, 16, 16, 16, 15, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0};
293
static const unsigned char default_blue[256]
294
=
295
{0, 42, 0, 42, 0, 42, 0, 42, 21, 63, 21, 63, 21, 63, 21, 63,
296
 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
297
 63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0,
298
 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
299
 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63,
300
 63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45,
301
 45, 49, 54, 58, 63, 63, 63, 63, 28, 28, 28, 28, 28, 21, 14, 7,
302
 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 28, 28, 28, 28,
303
 28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14,
304
 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
305
 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28,
306
 16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0,
307
 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
308
 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16,
309
 16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11,
310
 11, 12, 13, 15, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0};
311
 
312
static unsigned char text_regs[MAX_REGS];       /* VGA registers for saved text mode */
313
 
314
char *__svgalib_TextProg_argv[16]; /* should be enough */
315
char *__svgalib_TextProg;
316
 
317
/* saved text mode palette values */
318
static unsigned char text_red[256];
319
static unsigned char text_green[256];
320
static unsigned char text_blue[256];
321
 
322
/* saved graphics mode palette values */
323
static unsigned char graph_red[256];
324
static unsigned char graph_green[256];
325
static unsigned char graph_blue[256];
326
 
327
static int prv_mode = TEXT;     /* previous video mode      */
328
static int flip_mode = TEXT;    /* flipped video mode       */
329
 
330
int CM = TEXT;                  /* current video mode       */
331
struct info CI;                 /* current video parameters */
332
int COL;                        /* current color            */
333
 
334
static int initialized = 0;     /* flag: initialize() called ?  */
335
static int flip = 0;            /* flag: executing vga_flip() ? */
336
static int background_fd = -1;
337
 
338
/* svgalib additions: */
339
int __svgalib_chipset = UNDEFINED;
340
int __svgalib_driver_report = 1;
341
        /* report driver used after chipset detection */
342
int __svgalib_videomemoryused = -1;
343
int __svgalib_modeX = 0;        /* true after vga_setmodeX() */
344
int __svgalib_modeflags = 0;    /* copy of flags for current mode */
345
int __svgalib_critical = 0;     /* indicates blitter is busy */
346
int __svgalib_screenon = 1;     /* screen visible if != 0 */
347
int __svgalib_vgacolormode = 1; /* assume color for now. needs to be
348
                                   config file option */
349
 
350
static int __svgalib_savemem=0;
351
 
352
RefreshRange __svgalib_horizsync =
353
{31500U, 60000U};                       /* horz. refresh (Hz) min, max */
354
RefreshRange __svgalib_vertrefresh =
355
{50U, 70U};                     /* vert. refresh (Hz) min, max */
356
int __svgalib_bandwidth=50000;  /* monitor maximum bandwidth (kHz) */
357
int __svgalib_grayscale = 0;    /* grayscale vs. color mode */
358
int __svgalib_modeinfo_linearset = 0;   /* IS_LINEAR handled via extended vga_modeinfo */
359
const int __svgalib_max_modes = MAX_MODES;      /* Needed for dynamical allocated tables in mach32.c */
360
 
361
static unsigned __svgalib_maxhsync[] =
362
{
363
    31500, 35100, 35500, 37900, 48300, 56000, 60000
364
};
365
 
366
static int lastmodenumber = __GLASTMODE;        /* Last defined mode */
367
static int my_pid = 0;          /* process PID, used with atexit() */
368
static int __svgalib_currentpage;
369
static int vga_page_offset;     /* offset to add to all vga_set*page() calls */
370
static int currentlogicalwidth;
371
static int currentdisplaystart;
372
static int mouse_support = 0;
373
int mouse_open = 0;
374
static int mouse_mode = 0;
375
static int mouse_type = -1;
376
static int mouse_modem_ctl = 0;
377
char *__svgalib_mouse_device = "/dev/mouse";
378
int __svgalib_mouse_flag;
379
static char *mem_device = "/dev/svga";
380
static int __svgalib_oktowrite = 1;
381
static int modeinfo_mask = ~0;
382
 
383
int __svgalib_mem_fd = -1;      /* /dev/svga file descriptor  */
384
int __svgalib_tty_fd = -1;      /* /dev/tty file descriptor */
385
int __svgalib_nosigint = 0;     /* Don't generate SIGINT in graphics mode */
386
int __svgalib_runinbackground = 0;
387
int __svgalib_startup_vc = -1;
388
static int __svgalib_security_revokeallprivs = 1;
389
static unsigned fontbufsize = 8192; /* compatibility */
390
 
391
/* Dummy buffer for mmapping grahics memory; points to 64K VGA framebuffer. */
392
unsigned char *GM;
393
/* Exported variable (read-only) is shadowed from internal variable, for */
394
/* better shared library performance. */
395
unsigned char *graph_mem;
396
 
397
void *__svgalib_physaddr;
398
int __svgalib_linear_memory_size;
399
 
400
static unsigned long graph_buf_size = 0;
401
static unsigned char *graph_buf = NULL;         /* saves graphics data during flip */
402
static int inbackground=0;
403
 
404
static unsigned char *font_buf1;        /* saved font data - plane 2 */
405
static unsigned char *font_buf2;        /* saved font data - plane 3 */
406
static unsigned char *text_buf1=NULL;   /* saved text data - plane 0 */
407
static unsigned char *text_buf2;        /* saved text data - plane 1 */
408
 
409
int __svgalib_flipchar = '\x1b';                /* flip character - initially  ESCAPE */
410
 
411
/* Chipset specific functions */
412
 
413
DriverSpecs *__svgalib_driverspecs = &__svgalib_vga_driverspecs;
414
 
415
static void (*__svgalib_setpage) (int); /* gives little faster vga_setpage() */
416
static void (*__svgalib_setrdpage) (int);
417
static void (*__svgalib_setwrpage) (int);
418
 
419
int  (*__svgalib_inmisc)(void);
420
void (*__svgalib_outmisc)(int);
421
int  (*__svgalib_incrtc)(int);
422
void (*__svgalib_outcrtc)(int,int);
423
int  (*__svgalib_inseq)(int);
424
void (*__svgalib_outseq)(int,int);
425
int  (*__svgalib_ingra)(int);
426
void (*__svgalib_outgra)(int,int);
427
int  (*__svgalib_inatt)(int);
428
void (*__svgalib_outatt)(int,int);
429
void (*__svgalib_attscreen)(int);
430
void (*__svgalib_inpal)(int,int*,int*,int*);
431
void (*__svgalib_outpal)(int,int,int,int);
432
int  (*__svgalib_inis1)(void);
433
 
434
void map_banked(void);
435
void map_banked_fix(void);
436
inline void vga_setpage(int p);
437
 
438
DriverSpecs *__svgalib_driverspecslist[] =
439
{
440
    NULL,                       /* chipset undefined */
441
    &__svgalib_vga_driverspecs,
442
#ifdef INCLUDE_ET4000_DRIVER
443
    &__svgalib_et4000_driverspecs,
444
#else
445
    NULL,
446
#endif
447
#ifdef INCLUDE_CIRRUS_DRIVER
448
    &__svgalib_cirrus_driverspecs,
449
#else
450
    NULL,
451
#endif
452
#ifdef INCLUDE_TVGA_DRIVER
453
    &__svgalib_tvga8900_driverspecs,
454
#else
455
    NULL,
456
#endif
457
#ifdef INCLUDE_OAK_DRIVER
458
    &__svgalib_oak_driverspecs,
459
#else
460
    NULL,
461
#endif
462
#ifdef INCLUDE_EGA_DRIVER
463
    &__svgalib_ega_driverspecs,
464
#else
465
    NULL,
466
#endif
467
#ifdef INCLUDE_S3_DRIVER
468
    &__svgalib_s3_driverspecs,
469
#else
470
    NULL,
471
#endif
472
#ifdef INCLUDE_ET3000_DRIVER
473
    &__svgalib_et3000_driverspecs,
474
#else
475
    NULL,
476
#endif
477
#ifdef INCLUDE_MACH32_DRIVER
478
    &__svgalib_mach32_driverspecs,
479
#else
480
    NULL,
481
#endif
482
#ifdef INCLUDE_GVGA6400_DRIVER
483
    &__svgalib_gvga6400_driverspecs,
484
#else
485
    NULL,
486
#endif
487
#ifdef INCLUDE_ARK_DRIVER
488
    &__svgalib_ark_driverspecs,
489
#else
490
    NULL,
491
#endif
492
#ifdef INCLUDE_ATI_DRIVER
493
    &__svgalib_ati_driverspecs,
494
#else
495
    NULL,
496
#endif
497
#ifdef INCLUDE_ALI_DRIVER
498
    &__svgalib_ali_driverspecs,
499
#else
500
    NULL,
501
#endif
502
#ifdef INCLUDE_MACH64_DRIVER
503
    &__svgalib_mach64_driverspecs,
504
#else
505
    NULL,
506
#endif
507
#ifdef INCLUDE_CHIPS_DRIVER
508
    &__svgalib_chips_driverspecs,
509
#else
510
    NULL,
511
#endif
512
#ifdef INCLUDE_APM_DRIVER
513
    &__svgalib_apm_driverspecs,
514
#else
515
    NULL,
516
#endif
517
#ifdef INCLUDE_NV3_DRIVER
518
    &__svgalib_nv3_driverspecs,
519
#else
520
    NULL,
521
#endif
522
#ifdef INCLUDE_ET6000_DRIVER
523
    &__svgalib_et6000_driverspecs,
524
#else
525
    NULL,
526
#endif
527
#ifdef INCLUDE_VESA_DRIVER
528
    &__svgalib_vesa_driverspecs,
529
#else
530
    NULL,
531
#endif
532
#ifdef INCLUDE_MX_DRIVER
533
    &__svgalib_mx_driverspecs,
534
#else
535
    NULL,
536
#endif
537
#ifdef INCLUDE_PARADISE_DRIVER
538
    &__svgalib_paradise_driverspecs,
539
#else
540
    NULL,
541
#endif
542
#ifdef INCLUDE_RAGE_DRIVER
543
    &__svgalib_rage_driverspecs,
544
#else
545
    NULL,
546
#endif
547
#ifdef INCLUDE_BANSHEE_DRIVER
548
    &__svgalib_banshee_driverspecs,
549
#else
550
    NULL,
551
#endif
552
#ifdef INCLUDE_SIS_DRIVER
553
    &__svgalib_sis_driverspecs,
554
#else
555
    NULL,
556
#endif
557
#ifdef INCLUDE_I740_DRIVER
558
    &__svgalib_i740_driverspecs,
559
#else
560
    NULL,
561
#endif
562
#ifdef INCLUDE_NEO_DRIVER
563
    &__svgalib_neo_driverspecs,
564
#else
565
    NULL,
566
#endif
567
#ifdef INCLUDE_LAGUNA_DRIVER
568
    &__svgalib_laguna_driverspecs,
569
#else
570
    NULL,
571
#endif
572
#ifdef INCLUDE_FBDEV_DRIVER
573
     &__svgalib_fbdev_driverspecs,
574
#else
575
     NULL,
576
#endif
577
#ifdef INCLUDE_G400_DRIVER
578
    &__svgalib_g400_driverspecs,
579
#else
580
    NULL,
581
#endif
582
#ifdef INCLUDE_R128_DRIVER
583
    &__svgalib_r128_driverspecs,
584
#else
585
    NULL,
586
#endif
587
#ifdef INCLUDE_SAVAGE_DRIVER
588
    &__svgalib_savage_driverspecs,
589
#else
590
    NULL,
591
#endif
592
#ifdef INCLUDE_MILLENNIUM_DRIVER
593
    &__svgalib_mil_driverspecs,
594
#else
595
    NULL,
596
#endif
597
#ifdef INCLUDE_I810_DRIVER
598
    &__svgalib_i810_driverspecs,
599
#else
600
    NULL,
601
#endif
602
#ifdef INCLUDE_TRIDENT_DRIVER
603
    &__svgalib_trident_driverspecs,
604
#else
605
    NULL,
606
#endif
607
#ifdef INCLUDE_RENDITION_DRIVER
608
    &__svgalib_rendition_driverspecs,
609
#else
610
    NULL,
611
#endif
612
#ifdef INCLUDE_G450C2_DRIVER
613
    &__svgalib_g450c2_driverspecs,
614
#else
615
    NULL,
616
#endif
617
#ifdef INCLUDE_PM2_DRIVER
618
    &__svgalib_pm2_driverspecs,
619
#else
620
    NULL,
621
#endif
622
};
623
 
624
static char *driver_names[] =
625
{
626
"",
627
"VGA",
628
"ET4000",
629
"Cirrus",
630
"TVGA",
631
"Oak",
632
"EGA",
633
"S3",
634
"ET3000",
635
"Mach32",
636
"GVGA6400",
637
"ARK",
638
"ATI",
639
"ALI",
640
"Mach64",
641
"C&T",
642
"APM",
643
"NV3",
644
"ET6000",
645
"VESA",
646
"MX",
647
"PARADISE",
648
"RAGE",
649
"BANSHEE",
650
"SIS",
651
"I740",
652
"NEOMAGIC",
653
"LAGUNA",
654
"FBDev",
655
"G400",
656
"R128",
657
"SAVAGE",
658
"MILLENNIUM",
659
"I810",
660
"TRIDENT",
661
"RENDITION",
662
"G450C2",
663
"PM2",
664
 NULL};
665
 
666
/* Chipset drivers */
667
 
668
/* vgadrv       Standard VGA (also used by drivers below) */
669
/* et4000       Tseng ET4000 (from original vgalib) */
670
/* cirrus       Cirrus Logic GD542x */
671
/* tvga8900     Trident TVGA 8900/9000 (derived from tvgalib) */
672
/* oak          Oak Technologies 037/067/077 */
673
/* egadrv       IBM EGA (subset of VGA) */
674
/* s3           S3 911 */
675
/* mach32       ATI MACH32 */
676
/* ark          ARK Logic */
677
/* gvga6400     Genoa 6400 (old SVGA) */
678
/* ati          ATI */
679
/* ali          ALI2301 */
680
/* mach64       ATI MACH64 */
681
/* chips        chips & technologies*/
682
/* et6000       Tseng ET6000 */         /* DS */
683
 
684
inline void vga_setpage(int p)
685
{
686
    p += vga_page_offset;
687
    if (p == __svgalib_currentpage)
688
        return;
689
 
690
    __svgalib_currentpage = p;
691
}
692
 
693
int __svgalib_setregs(const unsigned char *regs)
694
{
695
    int i;
696
 
697
    if(__svgalib_novga) return 1;
698
 
699
    if (__svgalib_chipset == EGA) {
700
        /* Enable graphics register modification */
701
        port_out(0x00, GRA_E0);
702
        port_out(0x01, GRA_E1);
703
    }
704
    /* update misc output register */
705
    __svgalib_outmisc(regs[MIS]);
706
 
707
    /* synchronous reset on */
708
    __svgalib_outseq(0x00,0x01);
709
 
710
    /* write sequencer registers */
711
    __svgalib_outseq(0x01,regs[SEQ + 1] | 0x20);
712
    for (i = 2; i < SEQ_C; i++) {
713
       __svgalib_outseq(i,regs[SEQ + i]);
714
    }
715
 
716
    /* synchronous reset off */
717
    __svgalib_outseq(0x00,0x03);
718
 
719
    if (__svgalib_chipset != EGA) {
720
        /* deprotect CRT registers 0-7 */
721
        __svgalib_outcrtc(0x11,__svgalib_incrtc(0x11)&0x7f);
722
    }
723
    /* write CRT registers */
724
    for (i = 0; i < CRT_C; i++) {
725
        __svgalib_outcrtc(i,regs[CRT + i]);
726
    }
727
 
728
    /* write graphics controller registers */
729
    for (i = 0; i < GRA_C; i++) {
730
        __svgalib_outgra(i,regs[GRA+i]);
731
    }
732
 
733
    /* write attribute controller registers */
734
    for (i = 0; i < ATT_C; i++) {
735
        __svgalib_outatt(i,regs[ATT+i]);
736
    }
737
 
738
    return 0;
739
}
740
 
741
int vga_screenon(void)
742
{
743
    int tmp = 0;
744
 
745
    SCREENON = 1;
746
    if(__svgalib_novga) return 0;
747
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->screenon) {
748
        tmp = __svgalib_driverspecs->emul->screenon();
749
    } else {
750
        /* turn screen back on */
751
        if ((CHIPSET != EGA) && !__svgalib_novga) {
752
            __svgalib_outseq(0x01,__svgalib_inseq(0x01) & 0xdf);
753
        }
754
/* #ifdef DISABLE_VIDEO_OUTPUT */
755
        /* enable video output */
756
        __svgalib_attscreen(0x20);
757
/* #endif */
758
    }
759
 
760
    return 0;
761
}
762
 
763
int vga_claimvideomemory(int m)
764
{
765
    vga_modeinfo *modeinfo;
766
    int cardmemory;
767
 
768
    modeinfo = vga_getmodeinfo(CM);
769
    if (m < VMEM)
770
        return 0;
771
    if (modeinfo->colors == 16)
772
        cardmemory = modeinfo->maxpixels / 2;
773
    else
774
        cardmemory = (modeinfo->maxpixels * modeinfo->bytesperpixel
775
                      + 2) & 0xffff0000;
776
    /* maxpixels * bytesperpixel can be 2 less than video memory in */
777
    /* 3 byte-per-pixel modes; assume memory is multiple of 64K */
778
    if (m > cardmemory)
779
        return -1;
780
    VMEM = m;
781
    return 0;
782
}
783
 
784
void map_banked() {
785
 
786
    if(__svgalib_emulatepage){
787
              BANKED_POINTER=(void *)__svgalib_linear_mem_base;
788
    } else {
789
              BANKED_POINTER=(void *)__svgalib_banked_mem_base;
790
    }
791
 
792
}
793
 
794
void map_mmio() {
795
 
796
    if(mmio_mapped) return;
797
 
798
    if(__svgalib_mmio_size) {
799
        mmio_mapped=1;
800
        MMIO_POINTER=(void *)__svgalib_mmio_base;
801
    } else {
802
        MMIO_POINTER=NULL;
803
        SPARSE_MMIO=NULL;
804
    }
805
}
806
 
807
void map_mem() {
808
 
809
    if(mem_mapped) return;
810
 
811
    if(__svgalib_banked_mem_size==0) __svgalib_banked_mem_size = 0x10000;
812
 
813
    map_banked();
814
 
815
    if(__svgalib_linear_mem_size) {
816
        map_linear(__svgalib_linear_mem_base, __svgalib_linear_mem_size);
817
    };
818
 
819
    B8000_POINTER = (void *)0xb8000;
820
 
821
    mem_mapped = 1;
822
 
823
}
824
 
825
static void __vga_map(void)
826
{
827
    GM = (unsigned char *) BANKED_POINTER;
828
    graph_mem = GM;     /* Exported variable. */
829
}
830
 
74 giacomo 831
void __svgalib_emul_setpage(int page)
832
{
833
        static int oldpage = -2;
834
 
835
        if (page != oldpage)
836
        {
837
                oldpage = page;
838
        }
839
}
840
 
54 pj 841
static void map_vgaio(void)
842
{
843
    __svgalib_inmisc=__svgalib_vga_inmisc;
844
    __svgalib_outmisc=__svgalib_vga_outmisc;
845
    __svgalib_incrtc=__svgalib_vga_incrtc;
846
    __svgalib_outcrtc=__svgalib_vga_outcrtc;
847
    __svgalib_inseq=__svgalib_vga_inseq;
848
    __svgalib_outseq=__svgalib_vga_outseq;
849
    __svgalib_ingra=__svgalib_vga_ingra;
850
    __svgalib_outgra=__svgalib_vga_outgra;
851
    __svgalib_inatt=__svgalib_vga_inatt;
852
    __svgalib_outatt=__svgalib_vga_outatt;
853
    __svgalib_attscreen=__svgalib_vga_attscreen;
854
    __svgalib_inpal=__svgalib_vga_inpal;
855
    __svgalib_outpal=__svgalib_vga_outpal;
856
    __svgalib_inis1=__svgalib_vga_inis1;
857
}
858
 
859
int __svgalib_saveregs(unsigned char *regs)
860
{
861
    int i;
862
 
863
    if (__svgalib_chipset == EGA || __svgalib_novga) {
864
        /* Special case: Don't save standard VGA registers. */
865
        return chipset_saveregs(regs);
866
    }
867
    /* save VGA registers */
868
    for (i = 0; i < CRT_C; i++) {
869
        regs[CRT + i] = __svgalib_incrtc(i);
870
    }
871
    for (i = 0; i < ATT_C; i++) {
872
        regs[ATT + i] = __svgalib_inatt(i);
873
    }
874
    for (i = 0; i < GRA_C; i++) {
875
        regs[GRA + i] = __svgalib_ingra(i);
876
    }
877
    for (i = 0; i < SEQ_C; i++) {
878
        regs[SEQ + i] = __svgalib_inseq(i);
879
    }
880
    regs[MIS] = __svgalib_inmisc();
881
 
882
    i = chipset_saveregs(regs); /* save chipset-specific registers */
883
    /* i : additional registers */
884
    if (!SCREENON) {            /* We turned off the screen */
885
        __svgalib_attscreen(0x20);
886
    }
887
    return CRT_C + ATT_C + GRA_C + SEQ_C + 1 + i;
888
}
889
 
890
int vga_setcolor(int color)
891
{
892
    switch (CI.colors) {
893
    case 2:
894
        if (color != 0)
895
            color = 15;
896
    case 16:                    /* update set/reset register */
897
        __svgalib_outgra(0x00,color&0x0f);
898
        break;
899
    default:
900
        COL = color;
901
        break;
902
    }
903
    return 0;
904
}
905
 
906
vga_modeinfo *vga_getmodeinfo(int mode)
907
{
908
    static vga_modeinfo modeinfo;
909
    int is_modeX = (CM == mode) && MODEX;
910
 
911
    printk(KERN_INFO "getmodeinfo %i\n",mode);
912
 
913
    modeinfo.linewidth = infotable[mode].xbytes;
914
    __svgalib_getchipset(CHIPSET);
915
    if (mode > vga_lastmodenumber())
916
        return NULL;
917
    modeinfo.width = infotable[mode].xdim;
918
    modeinfo.height = infotable[mode].ydim;
919
    modeinfo.bytesperpixel = infotable[mode].bytesperpixel;
920
    modeinfo.colors = infotable[mode].colors;
921
    if (is_modeX) {
922
        modeinfo.linewidth = modeinfo.width / 4;
923
        modeinfo.bytesperpixel = 0;
924
    }
925
    if (mode == TEXT) {
926
        modeinfo.flags = HAVE_EXT_SET;
927
        return &modeinfo;
928
    }
929
    modeinfo.flags = 0;
930
    if ((STDVGAMODE(mode) && mode != G320x200x256) || is_modeX)
931
        __svgalib_vga_driverspecs.getmodeinfo(mode, &modeinfo);
932
    else
933
        /* Get chipset specific info for SVGA modes and */
934
        /* 320x200x256 (chipsets may support more pages) */
935
        chipset_getmodeinfo(mode, &modeinfo);
936
 
937
    if (modeinfo.colors == 256 && modeinfo.bytesperpixel == 0)
938
        modeinfo.flags |= IS_MODEX;
939
    if (mode > __GLASTMODE)
940
        modeinfo.flags |= IS_DYNAMICMODE;
941
 
942
    /* Maskout CAPABLE_LINEAR if requested by config file */
943
    modeinfo.flags &= modeinfo_mask;
944
 
945
    /* Many cards have problems with linear 320x200x256 mode */
946
    if(mode==G320x200x256)modeinfo.flags &= (~CAPABLE_LINEAR) & (~IS_LINEAR) ;
947
 
948
    /* If all needed info is here, signal if linear support has been enabled */
949
    if ((modeinfo.flags & (CAPABLE_LINEAR | EXT_INFO_AVAILABLE)) ==
950
        (CAPABLE_LINEAR | EXT_INFO_AVAILABLE)) {
951
        modeinfo.flags |= __svgalib_modeinfo_linearset;
952
    }
953
 
954
    return &modeinfo;
955
}
956
 
957
char *__svgalib_token(char **ptr)
958
{
959
    char *p;
960
    p=*ptr;
961
    while(*p==' ')p++;
962
 
963
    if(*p != '\0' ) {
964
        char *t;
965
        t=p;
966
        while((*t != '\0') && (*t != ' '))t++;
967
        if(*t==' ') {
968
            *t='\0';
969
            t++;
970
        }
971
        *ptr=t;
972
        return p;
973
    } else {
974
        *ptr=NULL;
975
        return NULL;
976
    }
977
}
978
 
979
int vga_lastmodenumber(void)
980
{
981
    __svgalib_getchipset(CHIPSET);
982
    return lastmodenumber;
983
}
984
 
985
int __svgalib_getchipset(int set_chipset)
986
{
987
 
988
    /* SHARK: Supported Graphics Drivers
989
     *
74 giacomo 990
     * NV3 (NVIDIA: GEFORCE/TNT/TNT2)
991
     * SAVAGE (S3: VIRGE/SAVAGE
992
     * R128 (ATI: RAGE 128/RADEON)
132 giacomo 993
     * NEOMAGIC (NEOMAGIC CARD)
994
     *  
54 pj 995
     */
996
 
997
    CHIPSET = set_chipset;
998
 
999
    if(!initialized) {
1000
 
1001
        map_vgaio();
1002
        init_vgapci();
1003
 
1004
        switch(CHIPSET) {
1005
                case NV3:
1006
                  nv3_test();
1007
                  break;
1008
                case SAVAGE:
1009
                  savage_test();
1010
                  break;
74 giacomo 1011
                case R128:
1012
                  r128_test();
1013
                  break;
132 giacomo 1014
                case NEOMAGIC:
1015
                  neo_test();
1016
                  break;
1017
                case VESA:
1018
                  vesa_test();
1019
                  break;
169 giacomo 1020
                case S3:
1021
                  s3_test();
1022
                  break;
54 pj 1023
        }
1024
 
1025
    }
1026
 
1027
    return CHIPSET;
1028
 
1029
}
1030
 
74 giacomo 1031
int vga_getxdim(void)
1032
{
1033
    return CI.xdim;
1034
}
1035
 
1036
 
1037
int vga_getydim(void)
1038
{
1039
    return CI.ydim;
1040
}
1041
 
1042
 
1043
int vga_getcolors(void)
1044
{
1045
    return CI.colors;
1046
}
1047
 
1048
int vga_white(void)
1049
{
1050
    switch (CI.colors) {
1051
    case 2:
1052
    case 16:
1053
    case 256:
1054
        return 15;
1055
    case 1 << 15:
1056
        return 32767;
1057
    case 1 << 16:
1058
        return 65535;
1059
    case 1 << 24:
1060
        return (1 << 24) - 1;
1061
    }
1062
    return CI.colors - 1;
1063
}
1064
 
54 pj 1065
void __svgalib_delay(void)
1066
{
1067
    int i;
1068
    for (i = 0; i < 10; i++);
1069
}
1070
 
1071
int vga_screenoff(void)
1072
{
1073
    int tmp = 0;
1074
 
1075
    SCREENON = 0;
1076
 
1077
    if(__svgalib_novga) return 0;
1078
 
1079
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->screenoff) {
1080
        tmp = __svgalib_driverspecs->emul->screenoff();
1081
    } else {
1082
        /* turn off screen for faster VGA memory acces */
1083
        if ((CHIPSET != EGA) && !__svgalib_novga) {
1084
            __svgalib_outseq(0x01,__svgalib_inseq(0x01) | 0x20);
1085
        }
1086
        /* Disable video output */
1087
#ifdef DISABLE_VIDEO_OUTPUT
1088
        __svgalib_attscreen(0);
1089
#endif
1090
    }
1091
 
1092
    return tmp;
1093
}
1094
 
1095
static void setcoloremulation(void)
1096
{
1097
    /* shift to color emulation */
1098
    __svgalib_CRT_I = CRT_IC;
1099
    __svgalib_CRT_D = CRT_DC;
1100
    __svgalib_IS1_R = IS1_RC;
1101
    __svgalib_vgacolormode=1;
1102
    if (CHIPSET != EGA && !__svgalib_novga)  
1103
        __svgalib_outmisc(__svgalib_inmisc()|0x01);
1104
}
1105
 
1106
void map_linear(unsigned long base, unsigned long size) {
1107
 
1108
    LINEAR_POINTER= (void *)base;
1109
 
1110
}
1111
 
1112
static void savepalette(unsigned char *red, unsigned char *green,
1113
                        unsigned char *blue)
1114
{
1115
    int i;
1116
 
1117
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->savepalette)
1118
        return (__svgalib_driverspecs->emul->savepalette(red, green, blue));
1119
 
1120
    if (CHIPSET == EGA || __svgalib_novga)
1121
        return;
1122
 
1123
    /* save graphics mode palette */
1124
 
1125
    for (i = 0; i < 256; i++) {
1126
        int r,g,b;
1127
        __svgalib_inpal(i,&r,&g,&b);
1128
        *(red++) = r;
1129
        *(green++) = g;
1130
        *(blue++) = b;
1131
    }
1132
}
1133
 
1134
static void restorepalette(const unsigned char *red,
1135
                   const unsigned char *green, const unsigned char *blue)
1136
{
1137
    int i;
1138
 
1139
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->restorepalette)
1140
        return (__svgalib_driverspecs->emul->restorepalette(red, green, blue));
1141
 
1142
    if (CHIPSET == EGA || __svgalib_novga)
1143
        return;
1144
 
1145
    /* restore saved palette */
1146
    /* read RGB components - index is autoincremented */
1147
    for (i = 0; i < 256; i++) {
1148
        __svgalib_outpal(i,*(red++),*(green++),*(blue++));
1149
    }
1150
}
1151
 
1152
int vga_getcurrentmode(void)
1153
{
1154
    return CM;
1155
}
1156
 
1157
 
1158
static void initialize(int set_chipset)
1159
{
1160
    int i;
1161
 
1162
    printk(KERN_INFO "Initialize\n");
1163
 
1164
//    __svgalib_disable_interrupt();    /* Is reenabled later by set_texttermio */
1165
 
1166
    __svgalib_getchipset(set_chipset);
1167
    chipset_unlock();
1168
 
1169
    /* mmap graphics memory */
1170
    map_mem();
1171
    map_mmio();
1172
 
1173
    __vga_map();
1174
 
1175
    /* disable video */
1176
    vga_screenoff();
1177
 
1178
    /* Sanity check: (from painful experience) */
1179
    i = __svgalib_saveregs(text_regs);
1180
    if (i > MAX_REGS) {
1181
        printk(KERN_INFO "svgalib: FATAL internal error:\n");
1182
        printk(KERN_INFO "Set MAX_REGS at least to %d in src/driver.h and recompile everything.\n",
1183
               i);
1184
    }
1185
 
1186
    /* save text mode palette */
1187
    savepalette(text_red, text_green, text_blue);
1188
 
1189
    /* shift to color emulation */
1190
    setcoloremulation();
1191
 
1192
    initialized = 1;
1193
 
1194
    /* vga_unlockvc(); */
1195
 
1196
}
1197
 
1198
void vga_gettextfont(void *font)
1199
{
1200
    unsigned int getsize;
1201
 
1202
    getsize = fontbufsize;
1203
    if (getsize > FONT_SIZE)
1204
        getsize = FONT_SIZE;
1205
    memcpy(font, font_buf1, getsize);
1206
    if (fontbufsize > getsize)
1207
        memset(((char *)font) + getsize, 0, (size_t)(fontbufsize - getsize));
1208
}
1209
 
1210
void vga_puttextfont(void *font)
1211
{
1212
    unsigned int putsize;
1213
 
1214
    putsize = fontbufsize;
1215
    if (putsize > FONT_SIZE)
1216
        putsize = FONT_SIZE;
1217
    memcpy(font_buf1, font, putsize);
1218
    memcpy(font_buf2, font, putsize);
1219
    if (putsize < FONT_SIZE) {
1220
        memset(font_buf1 + putsize, 0, (size_t)(FONT_SIZE - putsize));
1221
        memset(font_buf2 + putsize, 0, (size_t)(FONT_SIZE - putsize));
1222
    }
1223
 
1224
}
1225
 
1226
int vga_setmode(int mode,int set_chipset)
1227
{
1228
    int modeflags=mode&0xfffff000;
184 giacomo 1229
    struct LRMI_regs vesa_r;
1230
 
54 pj 1231
    printk(KERN_INFO "Setmode %i from %i\n", mode, CM);
1232
 
1233
    if(mode==-1)return vga_version;
1234
 
1235
    mode&=0xfff;
1236
 
1237
    if (!initialized) {
1238
        if (mode == TEXT) return 0;
1239
        initialize(set_chipset);
1240
    }
1241
 
1242
    if (mode != TEXT && !chipset_modeavailable(mode)) {
1243
        return -1;
1244
    }
1245
 
1246
//    __svgalib_disable_interrupt();
1247
 
1248
    prv_mode = CM;
1249
    CM = mode;
1250
 
1251
    /* disable video */
1252
    vga_screenoff();
1253
 
1254
    if (mode == TEXT) {
1255
        /* Returning to textmode. */
191 giacomo 1256
 
1257
        cli();
1258
 
184 giacomo 1259
        vesa_r.eax = 0x03;
1260
        __svgalib_LRMI_int(0x10,&vesa_r);
54 pj 1261
 
191 giacomo 1262
        sti();
1263
 
54 pj 1264
    } else {
1265
        /* Setting a graphics mode. */
1266
 
1267
        if (SVGAMODE(prv_mode)) {
1268
            /* The current mode is an SVGA mode, and we now want to */
1269
            /* set a standard VGA mode. Make sure the extended regs */
1270
            /* are restored. */
1271
            /* Also used when setting another SVGA mode to hopefully */
1272
            /* eliminate lock-ups. */
1273
            vga_setpage(0);
1274
            chipset_setregs(text_regs, mode);
1275
            /* restore old extended regs */
1276
        }
1277
        /* shift to color emulation */
1278
        setcoloremulation();
1279
 
1280
        CI.xdim = infotable[mode].xdim;
1281
        CI.ydim = infotable[mode].ydim;
1282
        CI.colors = infotable[mode].colors;
1283
        CI.xbytes = infotable[mode].xbytes;
1284
        CI.bytesperpixel = infotable[mode].bytesperpixel;
1285
 
1286
        chipset_setmode(mode, prv_mode);
1287
        MODEX = 0;
1288
 
1289
        /* Set default claimed memory (moved here from initialize - Michael.) */
1290
        if (mode == G320x200x256)
1291
            VMEM = 65536;
1292
        else if (STDVGAMODE(mode))
1293
            VMEM = 256 * 1024;  /* Why always 256K ??? - Michael */
1294
        else {
1295
            vga_modeinfo *modeinfo;
1296
 
1297
            modeinfo = vga_getmodeinfo(mode);
1298
            VMEM = modeinfo->linewidth * modeinfo->height;
1299
            CI.xbytes = modeinfo->linewidth;
1300
        }
1301
 
1302
        if (!flip) {
1303
            /* set default palette */
1304
            if (CI.colors <= 256)
1305
                restorepalette(default_red, default_green, default_blue);
1306
 
1307
            /* clear screen (sets current color to 15) */
1308
            __svgalib_currentpage = -1;
1309
            if(!(modeflags&0x8000))vga_clear();
1310
 
1311
            if (SVGAMODE(CM))
1312
                vga_setpage(0);
1313
        }
1314
        __svgalib_currentpage = -1;
1315
        currentlogicalwidth = CI.xbytes;
1316
        currentdisplaystart = 0;
1317
 
1318
        /* enable video */
1319
        if (!flip)
1320
            vga_screenon();
1321
 
1322
        {
1323
            vga_modeinfo *modeinfo;
1324
            modeinfo = vga_getmodeinfo(mode);
1325
            MODEX = ((MODEFLAGS = modeinfo->flags) & IS_MODEX);
1326
        }
1327
 
1328
    }
1329
 
1330
    return 0;
1331
 
1332
}
1333
 
1334
inline void copy_videomem_32to16(void *src, void *dst, unsigned long int memdiv2)
1335
{
1336
          __asm__ __volatile__("push %%esi
1337
                                push %%edi
1338
                                movl %1, %%esi
1339
                                movl %2, %%edi
1340
                                1:
1341
                                movl (%%esi), %%edx
1342
                                xorl %%ebx, %%ebx
1343
                                xorw %%ax, %%ax
1344
                                movb %%dl, %%al
1345
                                shrl $0x8, %%edx
1346
                                shrw $0x3, %%ax
1347
                                orw  %%ax, %%bx
1348
                                shll $0x6, %%ebx
1349
                                xorw %%ax, %%ax
1350
                                movb %%dl, %%al
1351
                                shrl $0x8, %%edx
1352
                                shrw $0x2, %%ax
1353
                                orw  %%ax, %%bx
1354
                                shll $0x5, %%ebx
1355
                                xorw %%ax, %%ax
1356
                                movb %%dl, %%al
1357
                                shrw $0x3, %%ax
1358
                                orw  %%ax, %%bx
1359
                                shll $0x5, %%ebx
1360
                                incl %%esi
1361
                                incl %%esi
1362
                                incl %%esi
1363
                                incl %%esi
1364
                                movl (%%esi), %%edx
1365
                                xorw %%ax, %%ax
1366
                                movb %%dl, %%al
1367
                                shrl $0x8,%%edx
1368
                                shrw $0x3, %%ax
1369
                                orw  %%ax, %%bx
1370
                                shll $0x6, %%ebx
1371
                                xorw %%ax, %%ax
1372
                                movb %%dl, %%al
1373
                                shrl $0x8, %%edx
1374
                                shrw $0x2, %%ax
1375
                                orw  %%ax, %%bx
1376
                                shll $0x5, %%ebx
1377
                                xorw %%ax, %%ax
1378
                                movb %%dl, %%al
1379
                                shrw $0x3, %%ax
1380
                                orw  %%ax, %%bx
1381
                                rorl $0x10, %%ebx
1382
                                movl %%ebx, (%%edi)
1383
                                incl %%esi
1384
                                incl %%esi
1385
                                incl %%esi
1386
                                incl %%esi
1387
                                incl %%edi
1388
                                incl %%edi
1389
                                incl %%edi
1390
                                incl %%edi
1391
                                loop 1b
1392
                                pop %%edi
1393
                                pop %%esi"
1394
                                :
1395
                                : "c" (memdiv2), "a" (src), "b" (dst));
1396
 
1397
}
74 giacomo 1398
 
1399
inline void copy_videomem_16to16(void *src, void *dst, unsigned long int memdiv4)
1400
{
1401
          __asm__ __volatile__("push %%esi
1402
                                push %%edi
1403
                                movl %1, %%esi
1404
                                movl %2, %%edi
1405
                                cld
1406
                                rep
1407
                                movsl
1408
 
1409
                                pop %%edi
1410
                                pop %%esi"
1411
                                :
1412
                                : "c" (memdiv4), "a" (src), "b" (dst));
1413
 
1414
}