Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
6 *
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
9 *
10 * ----------------------------------------------------------------------- */
11
12/*
13 * Common all-VGA modes
14 */
15
16#include "boot.h"
17#include "video.h"
18
19static struct mode_info vga_modes[] = {
20 { VIDEO_80x25, 80, 25, 0 },
21 { VIDEO_8POINT, 80, 50, 0 },
22 { VIDEO_80x43, 80, 43, 0 },
23 { VIDEO_80x28, 80, 28, 0 },
24 { VIDEO_80x30, 80, 30, 0 },
25 { VIDEO_80x34, 80, 34, 0 },
26 { VIDEO_80x60, 80, 60, 0 },
27};
28
29static struct mode_info ega_modes[] = {
30 { VIDEO_80x25, 80, 25, 0 },
31 { VIDEO_8POINT, 80, 43, 0 },
32};
33
34static struct mode_info cga_modes[] = {
35 { VIDEO_80x25, 80, 25, 0 },
36};
37
38static __videocard video_vga;
39
40/* Set basic 80x25 mode */
41static u8 vga_set_basic_mode(void)
42{
43 struct biosregs ireg, oreg;
44 u16 ax;
45 u8 mode;
46
47 initregs(&ireg);
48
49 /* Query current mode */
50 ax = 0x0f00;
51 intcall(0x10, &ireg, &oreg);
52 mode = oreg.al;
53
54 if (mode != 3 && mode != 7)
55 mode = 3;
56
57 /* Set the mode */
58 ireg.ax = mode; /* AH=0: set mode */
59 intcall(0x10, &ireg, NULL);
60 do_restore = 1;
61 return mode;
62}
63
64static void vga_set_8font(void)
65{
66 /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
67 struct biosregs ireg;
68
69 initregs(&ireg);
70
71 /* Set 8x8 font */
72 ireg.ax = 0x1112;
73 /* ireg.bl = 0; */
74 intcall(0x10, &ireg, NULL);
75
76 /* Use alternate print screen */
77 ireg.ax = 0x1200;
78 ireg.bl = 0x20;
79 intcall(0x10, &ireg, NULL);
80
81 /* Turn off cursor emulation */
82 ireg.ax = 0x1201;
83 ireg.bl = 0x34;
84 intcall(0x10, &ireg, NULL);
85
86 /* Cursor is scan lines 6-7 */
87 ireg.ax = 0x0100;
88 ireg.cx = 0x0607;
89 intcall(0x10, &ireg, NULL);
90}
91
92static void vga_set_14font(void)
93{
94 /* Set 9x14 font - 80x28 on VGA */
95 struct biosregs ireg;
96
97 initregs(&ireg);
98
99 /* Set 9x14 font */
100 ireg.ax = 0x1111;
101 /* ireg.bl = 0; */
102 intcall(0x10, &ireg, NULL);
103
104 /* Turn off cursor emulation */
105 ireg.ax = 0x1201;
106 ireg.bl = 0x34;
107 intcall(0x10, &ireg, NULL);
108
109 /* Cursor is scan lines 11-12 */
110 ireg.ax = 0x0100;
111 ireg.cx = 0x0b0c;
112 intcall(0x10, &ireg, NULL);
113}
114
115static void vga_set_80x43(void)
116{
117 /* Set 80x43 mode on VGA (not EGA) */
118 struct biosregs ireg;
119
120 initregs(&ireg);
121
122 /* Set 350 scans */
123 ireg.ax = 0x1201;
124 ireg.bl = 0x30;
125 intcall(0x10, &ireg, NULL);
126
127 /* Reset video mode */
128 ireg.ax = 0x0003;
129 intcall(0x10, &ireg, NULL);
130
131 vga_set_8font();
132}
133
134/* I/O address of the VGA CRTC */
135u16 vga_crtc(void)
136{
137 return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
138}
139
140static void vga_set_480_scanlines(void)
141{
142 u16 crtc; /* CRTC base address */
143 u8 csel; /* CRTC miscellaneous output register */
144
145 crtc = vga_crtc();
146
147 out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
148 out_idx(0x0b, crtc, 0x06); /* Vertical total */
149 out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
150 out_idx(0xea, crtc, 0x10); /* Vertical sync start */
151 out_idx(0xdf, crtc, 0x12); /* Vertical display end */
152 out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
153 out_idx(0x04, crtc, 0x16); /* Vertical blank end */
154 csel = inb(0x3cc);
155 csel &= 0x0d;
156 csel |= 0xe2;
157 outb(csel, 0x3c2);
158}
159
160static void vga_set_vertical_end(int lines)
161{
162 u16 crtc; /* CRTC base address */
163 u8 ovfw; /* CRTC overflow register */
164 int end = lines-1;
165
166 crtc = vga_crtc();
167
168 ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
169
170 out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
171 out_idx(end, crtc, 0x12); /* Vertical display end */
172}
173
174static void vga_set_80x30(void)
175{
176 vga_set_480_scanlines();
177 vga_set_vertical_end(30*16);
178}
179
180static void vga_set_80x34(void)
181{
182 vga_set_480_scanlines();
183 vga_set_14font();
184 vga_set_vertical_end(34*14);
185}
186
187static void vga_set_80x60(void)
188{
189 vga_set_480_scanlines();
190 vga_set_8font();
191 vga_set_vertical_end(60*8);
192}
193
194static int vga_set_mode(struct mode_info *mode)
195{
196 /* Set the basic mode */
197 vga_set_basic_mode();
198
199 /* Override a possibly broken BIOS */
200 force_x = mode->x;
201 force_y = mode->y;
202
203 switch (mode->mode) {
204 case VIDEO_80x25:
205 break;
206 case VIDEO_8POINT:
207 vga_set_8font();
208 break;
209 case VIDEO_80x43:
210 vga_set_80x43();
211 break;
212 case VIDEO_80x28:
213 vga_set_14font();
214 break;
215 case VIDEO_80x30:
216 vga_set_80x30();
217 break;
218 case VIDEO_80x34:
219 vga_set_80x34();
220 break;
221 case VIDEO_80x60:
222 vga_set_80x60();
223 break;
224 }
225
226 return 0;
227}
228
229/*
230 * Note: this probe includes basic information required by all
231 * systems. It should be executed first, by making sure
232 * video-vga.c is listed first in the Makefile.
233 */
234static int vga_probe(void)
235{
236 static const char *card_name[] = {
237 "CGA/MDA/HGC", "EGA", "VGA"
238 };
239 static struct mode_info *mode_lists[] = {
240 cga_modes,
241 ega_modes,
242 vga_modes,
243 };
244 static int mode_count[] = {
245 sizeof(cga_modes)/sizeof(struct mode_info),
246 sizeof(ega_modes)/sizeof(struct mode_info),
247 sizeof(vga_modes)/sizeof(struct mode_info),
248 };
249
250 struct biosregs ireg, oreg;
251
252 initregs(&ireg);
253
254 ireg.ax = 0x1200;
255 ireg.bl = 0x10; /* Check EGA/VGA */
256 intcall(0x10, &ireg, &oreg);
257
258#ifndef _WAKEUP
259 boot_params.screen_info.orig_video_ega_bx = oreg.bx;
260#endif
261
262 /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
263 if (oreg.bl != 0x10) {
264 /* EGA/VGA */
265 ireg.ax = 0x1a00;
266 intcall(0x10, &ireg, &oreg);
267
268 if (oreg.al == 0x1a) {
269 adapter = ADAPTER_VGA;
270#ifndef _WAKEUP
271 boot_params.screen_info.orig_video_isVGA = 1;
272#endif
273 } else {
274 adapter = ADAPTER_EGA;
275 }
276 } else {
277 adapter = ADAPTER_CGA;
278 }
279
280 video_vga.modes = mode_lists[adapter];
281 video_vga.card_name = card_name[adapter];
282 return mode_count[adapter];
283}
284
285static __videocard video_vga = {
286 .card_name = "VGA",
287 .probe = vga_probe,
288 .set_mode = vga_set_mode,
289};