1 // QEMU Cirrus CLGD 54xx VGABIOS Extension.
3 // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (c) 2004 Makoto Suzuki (suzu)
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "vgatables.h" // cirrus_init
9 #include "biosvar.h" // GET_GLOBAL
10 #include "util.h" // dprintf
13 /****************************************************************
15 ****************************************************************/
17 struct cirrus_mode_s {
24 u16 hidden_dac; /* 0x3c6 */
26 u16 *graph; /* 0x3ce */
27 u16 *crtc; /* 0x3d4 */
43 static u16 cseq_vga[] VAR16 = {0x0007,0xffff};
44 static u16 cgraph_vga[] VAR16 = {0x0009,0x000a,0x000b,0xffff};
45 static u16 ccrtc_vga[] VAR16 = {0x001a,0x001b,0x001d,0xffff};
48 static u16 cgraph_svgacolor[] VAR16 = {
49 0x0000,0x0001,0x0002,0x0003,0x0004,0x4005,0x0506,0x0f07,0xff08,
54 static u16 cseq_640x480x8[] VAR16 = {
55 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1107,
56 0x580b,0x580c,0x580d,0x580e,
58 0x331b,0x331c,0x331d,0x331e,
61 static u16 ccrtc_640x480x8[] VAR16 = {
63 0x5f00,0x4f01,0x4f02,0x8003,0x5204,0x1e05,0x0b06,0x3e07,
65 0xea10,0xdf12,0x5013,0x4014,0xdf15,0x0b16,0xc317,0xff18,
70 static u16 cseq_640x480x16[] VAR16 = {
71 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1707,
72 0x580b,0x580c,0x580d,0x580e,
74 0x331b,0x331c,0x331d,0x331e,
77 static u16 ccrtc_640x480x16[] VAR16 = {
79 0x5f00,0x4f01,0x4f02,0x8003,0x5204,0x1e05,0x0b06,0x3e07,
81 0xea10,0xdf12,0xa013,0x4014,0xdf15,0x0b16,0xc317,0xff18,
86 static u16 cseq_640x480x24[] VAR16 = {
87 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1507,
88 0x580b,0x580c,0x580d,0x580e,
90 0x331b,0x331c,0x331d,0x331e,
93 static u16 ccrtc_640x480x24[] VAR16 = {
95 0x5f00,0x4f01,0x4f02,0x8003,0x5204,0x1e05,0x0b06,0x3e07,
97 0xea10,0xdf12,0x0013,0x4014,0xdf15,0x0b16,0xc317,0xff18,
102 static u16 cseq_800x600x8[] VAR16 = {
103 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1107,
104 0x230b,0x230c,0x230d,0x230e,
105 0x0412,0x0013,0x2017,
106 0x141b,0x141c,0x141d,0x141e,
109 static u16 ccrtc_800x600x8[] VAR16 = {
110 0x2311,0x7d00,0x6301,0x6302,0x8003,0x6b04,0x1a05,0x9806,0xf007,
111 0x6009,0x000c,0x000d,
112 0x7d10,0x5712,0x6413,0x4014,0x5715,0x9816,0xc317,0xff18,
113 0x001a,0x221b,0x001d,
117 static u16 cseq_800x600x16[] VAR16 = {
118 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1707,
119 0x230b,0x230c,0x230d,0x230e,
120 0x0412,0x0013,0x2017,
121 0x141b,0x141c,0x141d,0x141e,
124 static u16 ccrtc_800x600x16[] VAR16 = {
125 0x2311,0x7d00,0x6301,0x6302,0x8003,0x6b04,0x1a05,0x9806,0xf007,
126 0x6009,0x000c,0x000d,
127 0x7d10,0x5712,0xc813,0x4014,0x5715,0x9816,0xc317,0xff18,
128 0x001a,0x221b,0x001d,
132 static u16 cseq_800x600x24[] VAR16 = {
133 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1507,
134 0x230b,0x230c,0x230d,0x230e,
135 0x0412,0x0013,0x2017,
136 0x141b,0x141c,0x141d,0x141e,
139 static u16 ccrtc_800x600x24[] VAR16 = {
140 0x2311,0x7d00,0x6301,0x6302,0x8003,0x6b04,0x1a05,0x9806,0xf007,
141 0x6009,0x000c,0x000d,
142 0x7d10,0x5712,0x2c13,0x4014,0x5715,0x9816,0xc317,0xff18,
143 0x001a,0x321b,0x001d,
147 static u16 cseq_1024x768x8[] VAR16 = {
148 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1107,
149 0x760b,0x760c,0x760d,0x760e,
150 0x0412,0x0013,0x2017,
151 0x341b,0x341c,0x341d,0x341e,
154 static u16 ccrtc_1024x768x8[] VAR16 = {
155 0x2911,0xa300,0x7f01,0x7f02,0x8603,0x8304,0x9405,0x2406,0xf507,
156 0x6009,0x000c,0x000d,
157 0x0310,0xff12,0x8013,0x4014,0xff15,0x2416,0xc317,0xff18,
158 0x001a,0x221b,0x001d,
162 static u16 cseq_1024x768x16[] VAR16 = {
163 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1707,
164 0x760b,0x760c,0x760d,0x760e,
165 0x0412,0x0013,0x2017,
166 0x341b,0x341c,0x341d,0x341e,
169 static u16 ccrtc_1024x768x16[] VAR16 = {
170 0x2911,0xa300,0x7f01,0x7f02,0x8603,0x8304,0x9405,0x2406,0xf507,
171 0x6009,0x000c,0x000d,
172 0x0310,0xff12,0x0013,0x4014,0xff15,0x2416,0xc317,0xff18,
173 0x001a,0x321b,0x001d,
177 static u16 cseq_1024x768x24[] VAR16 = {
178 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1507,
179 0x760b,0x760c,0x760d,0x760e,
180 0x0412,0x0013,0x2017,
181 0x341b,0x341c,0x341d,0x341e,
184 static u16 ccrtc_1024x768x24[] VAR16 = {
185 0x2911,0xa300,0x7f01,0x7f02,0x8603,0x8304,0x9405,0x2406,0xf507,
186 0x6009,0x000c,0x000d,
187 0x0310,0xff12,0x8013,0x4014,0xff15,0x2416,0xc317,0xff18,
188 0x001a,0x321b,0x001d,
192 static u16 cseq_1280x1024x8[] VAR16 = {
193 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1107,
194 0x760b,0x760c,0x760d,0x760e,
195 0x0412,0x0013,0x2017,
196 0x341b,0x341c,0x341d,0x341e,
199 static u16 ccrtc_1280x1024x8[] VAR16 = {
200 0x2911,0xc300,0x9f01,0x9f02,0x8603,0x8304,0x9405,0x2406,0xf707,
201 0x6009,0x000c,0x000d,
202 0x0310,0xff12,0xa013,0x4014,0xff15,0x2416,0xc317,0xff18,
203 0x001a,0x221b,0x001d,
207 static u16 cseq_1280x1024x16[] VAR16 = {
208 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1707,
209 0x760b,0x760c,0x760d,0x760e,
210 0x0412,0x0013,0x2017,
211 0x341b,0x341c,0x341d,0x341e,
214 static u16 ccrtc_1280x1024x16[] VAR16 = {
215 0x2911,0xc300,0x9f01,0x9f02,0x8603,0x8304,0x9405,0x2406,0xf707,
216 0x6009,0x000c,0x000d,
217 0x0310,0xff12,0x4013,0x4014,0xff15,0x2416,0xc317,0xff18,
218 0x001a,0x321b,0x001d,
223 static u16 cseq_1600x1200x8[] VAR16 = {
224 0x0300,0x2101,0x0f02,0x0003,0x0e04,0x1107,
225 0x760b,0x760c,0x760d,0x760e,
226 0x0412,0x0013,0x2017,
227 0x341b,0x341c,0x341d,0x341e,
230 static u16 ccrtc_1600x1200x8[] VAR16 = {
231 0x2911,0xc300,0x9f01,0x9f02,0x8603,0x8304,0x9405,0x2406,0xf707,
232 0x6009,0x000c,0x000d,
233 0x0310,0xff12,0xa013,0x4014,0xff15,0x2416,0xc317,0xff18,
234 0x001a,0x221b,0x001d,
238 static struct cirrus_mode_s cirrus_modes[] VAR16 = {
239 {0x5f,640,480,8,0x00,
240 cseq_640x480x8,cgraph_svgacolor,ccrtc_640x480x8,8,
242 {0x64,640,480,16,0xe1,
243 cseq_640x480x16,cgraph_svgacolor,ccrtc_640x480x16,16,
245 {0x66,640,480,15,0xf0,
246 cseq_640x480x16,cgraph_svgacolor,ccrtc_640x480x16,16,
247 6,5,10,5,5,5,0,1,15},
248 {0x71,640,480,24,0xe5,
249 cseq_640x480x24,cgraph_svgacolor,ccrtc_640x480x24,24,
252 {0x5c,800,600,8,0x00,
253 cseq_800x600x8,cgraph_svgacolor,ccrtc_800x600x8,8,
255 {0x65,800,600,16,0xe1,
256 cseq_800x600x16,cgraph_svgacolor,ccrtc_800x600x16,16,
258 {0x67,800,600,15,0xf0,
259 cseq_800x600x16,cgraph_svgacolor,ccrtc_800x600x16,16,
260 6,5,10,5,5,5,0,1,15},
262 {0x60,1024,768,8,0x00,
263 cseq_1024x768x8,cgraph_svgacolor,ccrtc_1024x768x8,8,
265 {0x74,1024,768,16,0xe1,
266 cseq_1024x768x16,cgraph_svgacolor,ccrtc_1024x768x16,16,
268 {0x68,1024,768,15,0xf0,
269 cseq_1024x768x16,cgraph_svgacolor,ccrtc_1024x768x16,16,
270 6,5,10,5,5,5,0,1,15},
272 {0x78,800,600,24,0xe5,
273 cseq_800x600x24,cgraph_svgacolor,ccrtc_800x600x24,24,
275 {0x79,1024,768,24,0xe5,
276 cseq_1024x768x24,cgraph_svgacolor,ccrtc_1024x768x24,24,
279 {0x6d,1280,1024,8,0x00,
280 cseq_1280x1024x8,cgraph_svgacolor,ccrtc_1280x1024x8,8,
282 {0x69,1280,1024,15,0xf0,
283 cseq_1280x1024x16,cgraph_svgacolor,ccrtc_1280x1024x16,16,
284 6,5,10,5,5,5,0,1,15},
285 {0x75,1280,1024,16,0xe1,
286 cseq_1280x1024x16,cgraph_svgacolor,ccrtc_1280x1024x16,16,
289 {0x7b,1600,1200,8,0x00,
290 cseq_1600x1200x8,cgraph_svgacolor,ccrtc_1600x1200x8,8,
293 {0xfe,0,0,0,0,cseq_vga,cgraph_vga,ccrtc_vga,0,
294 0xff,0,0,0,0,0,0,0,0},
298 /****************************************************************
300 ****************************************************************/
302 static struct cirrus_mode_s *
303 cirrus_get_modeentry(u8 mode)
305 struct cirrus_mode_s *table_g = cirrus_modes;
306 while (table_g < &cirrus_modes[ARRAY_SIZE(cirrus_modes)]) {
307 u16 tmode = GET_GLOBAL(table_g->mode);
316 cirrus_switch_mode_setregs(u16 *data, u16 port)
319 u16 val = GET_GLOBAL(*data);
328 cirrus_get_crtc(void)
330 if (inb(VGAREG_READ_MISC_OUTPUT) & 1)
331 return VGAREG_VGA_CRTC_ADDRESS;
332 return VGAREG_MDA_CRTC_ADDRESS;
336 cirrus_switch_mode(struct cirrus_mode_s *table)
338 // Unlock cirrus special
339 outw(0x1206, VGAREG_SEQU_ADDRESS);
340 cirrus_switch_mode_setregs(GET_GLOBAL(table->seq), VGAREG_SEQU_ADDRESS);
341 cirrus_switch_mode_setregs(GET_GLOBAL(table->graph), VGAREG_GRDC_ADDRESS);
342 cirrus_switch_mode_setregs(GET_GLOBAL(table->crtc), cirrus_get_crtc());
344 outb(0x00, VGAREG_PEL_MASK);
345 inb(VGAREG_PEL_MASK);
346 inb(VGAREG_PEL_MASK);
347 inb(VGAREG_PEL_MASK);
348 inb(VGAREG_PEL_MASK);
349 outb(GET_GLOBAL(table->hidden_dac), VGAREG_PEL_MASK);
350 outb(0xff, VGAREG_PEL_MASK);
352 u8 vesacolortype = GET_GLOBAL(table->vesacolortype);
353 u8 v = vgahw_get_single_palette_reg(0x10) & 0xfe;
354 if (vesacolortype == 3)
356 else if (vesacolortype)
358 vgahw_set_single_palette_reg(0x10, v);
362 cirrus_get_memsize(void)
364 // get DRAM band width
365 outb(0x0f, VGAREG_SEQU_ADDRESS);
366 u8 v = inb(VGAREG_SEQU_DATA);
367 u8 x = (v >> 3) & 0x03;
379 cirrus_enable_16k_granularity(void)
381 outb(0x0b, VGAREG_GRDC_ADDRESS);
382 u8 v = inb(VGAREG_GRDC_DATA);
383 outb(v | 0x20, VGAREG_GRDC_DATA);
387 cirrus_clear_vram(u16 param)
389 cirrus_enable_16k_granularity();
390 u8 count = cirrus_get_memsize() * 4;
392 for (i=0; i<count; i++) {
393 outw((i<<8) | 0x09, VGAREG_GRDC_ADDRESS);
394 memset16_far(SEG_GRAPH, 0, param, 16 * 1024);
396 outw(0x0009, VGAREG_GRDC_ADDRESS);
400 cirrus_set_video_mode(u8 mode, u8 noclearmem)
402 dprintf(1, "cirrus mode %d\n", mode);
403 SET_BDA(vbe_mode, 0);
404 struct cirrus_mode_s *table_g = cirrus_get_modeentry(mode);
406 cirrus_switch_mode(table_g);
408 cirrus_clear_vram(0xffff);
409 SET_BDA(video_mode, mode);
412 table_g = cirrus_get_modeentry(0xfe);
413 cirrus_switch_mode(table_g);
414 dprintf(1, "cirrus mode switch regular\n");
421 outw(0x9206, VGAREG_SEQU_ADDRESS);
422 return inb(VGAREG_SEQU_DATA) == 0x12;
426 /****************************************************************
428 ****************************************************************/
431 cirrus_extbios_80h(struct bregs *regs)
433 u16 crtc_addr = cirrus_get_crtc();
434 outb(0x27, crtc_addr);
435 u8 v = inb(crtc_addr + 1);
449 cirrus_extbios_81h(struct bregs *regs)
456 cirrus_extbios_82h(struct bregs *regs)
458 u16 crtc_addr = cirrus_get_crtc();
459 outb(0x27, crtc_addr);
460 regs->al = inb(crtc_addr + 1) & 0x03;
465 cirrus_extbios_85h(struct bregs *regs)
467 regs->al = cirrus_get_memsize();
471 cirrus_extbios_9Ah(struct bregs *regs)
477 extern void a0h_callback(void);
479 // fatal: not implemented yet
486 cirrus_extbios_A0h(struct bregs *regs)
488 struct cirrus_mode_s *table_g = cirrus_get_modeentry(regs->al & 0x7f);
489 regs->ah = (table_g ? 1 : 0);
491 regs->di = regs->ds = regs->es = regs->bx = (u32)a0h_callback;
495 cirrus_extbios_A1h(struct bregs *regs)
497 regs->bx = 0x0e00; // IBM 8512/8513, color
501 cirrus_extbios_A2h(struct bregs *regs)
503 regs->al = 0x07; // HSync 31.5 - 64.0 kHz
507 cirrus_extbios_AEh(struct bregs *regs)
509 regs->al = 0x01; // High Refresh 75Hz
513 cirrus_extbios(struct bregs *regs)
515 // XXX - regs->bl < 0x80 or > 0xaf call regular handlers.
517 case 0x80: cirrus_extbios_80h(regs); break;
518 case 0x81: cirrus_extbios_81h(regs); break;
519 case 0x82: cirrus_extbios_82h(regs); break;
520 case 0x85: cirrus_extbios_85h(regs); break;
521 case 0x9a: cirrus_extbios_9Ah(regs); break;
522 case 0xa0: cirrus_extbios_A0h(regs); break;
523 case 0xa1: cirrus_extbios_A1h(regs); break;
524 case 0xa2: cirrus_extbios_A2h(regs); break;
525 case 0xae: cirrus_extbios_AEh(regs); break;
531 /****************************************************************
533 ****************************************************************/
537 cirrus_vesamode_to_mode(u16 vesamode)
539 // XXX - convert assembler
544 cirrus_get_bpp_bytes(void)
546 // XXX - convert assembler
551 cirrus_set_line_offset(u16 new_line_offset)
553 // XXX - convert assembler
557 cirrus_get_line_offset(void)
559 // XXX - convert assembler
564 cirrus_get_line_offset_entry(void *table)
566 // XXX - convert assembler
571 cirrus_set_start_addr(void *addr)
573 // XXX - convert assembler
577 cirrus_get_start_addr(void)
579 // XXX - convert assembler
585 cirrus_vesa_00h(struct bregs *regs)
587 // XXX - convert assembler
591 cirrus_vesa_01h(struct bregs *regs)
593 // XXX - convert assembler
597 cirrus_vesa_02h(struct bregs *regs)
599 // XXX - convert assembler
603 cirrus_vesa_03h(struct bregs *regs)
605 // XXX - convert assembler
608 // XXX - add cirrus_vesa_05h_farentry to vgaentry.S
611 cirrus_vesa_05h(struct bregs *regs)
613 // XXX - convert assembler
617 cirrus_vesa_06h(struct bregs *regs)
619 // XXX - convert assembler
623 cirrus_vesa_07h(struct bregs *regs)
625 // XXX - convert assembler
629 cirrus_vesa_10h(struct bregs *regs)
631 // XXX - convert assembler
635 cirrus_vesa_not_handled(struct bregs *regs)
642 cirrus_vesa(struct bregs *regs)
645 case 0x00: cirrus_vesa_00h(regs); break;
646 case 0x01: cirrus_vesa_01h(regs); break;
647 case 0x02: cirrus_vesa_02h(regs); break;
648 case 0x03: cirrus_vesa_03h(regs); break;
649 case 0x05: cirrus_vesa_05h(regs); break;
650 case 0x06: cirrus_vesa_06h(regs); break;
651 case 0x07: cirrus_vesa_07h(regs); break;
652 case 0x10: cirrus_vesa_10h(regs); break;
653 default: cirrus_vesa_not_handled(regs); break;
658 /****************************************************************
660 ****************************************************************/
665 dprintf(1, "cirrus init\n");
666 if (! cirrus_check())
668 dprintf(1, "cirrus init 2\n");
671 outb(0x0f, VGAREG_SEQU_ADDRESS);
672 u8 v = inb(VGAREG_SEQU_DATA);
673 outb(((v & 0x18) << 8) | 0x0a, VGAREG_SEQU_ADDRESS);
675 outw(0x0007, VGAREG_SEQU_ADDRESS);
677 outw(0x0431, VGAREG_GRDC_ADDRESS);
678 outw(0x0031, VGAREG_GRDC_ADDRESS);