H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 1 | /* -*- linux-c -*- ------------------------------------------------------- * |
| 2 | * |
| 3 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 4 | * Copyright 2007 rPath, Inc. - All Rights Reserved |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 5 | * Copyright 2009 Intel Corporation; author H. Peter Anvin |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 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 | /* |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 13 | * Common all-VGA modes |
| 14 | */ |
| 15 | |
| 16 | #include "boot.h" |
| 17 | #include "video.h" |
| 18 | |
| 19 | static struct mode_info vga_modes[] = { |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 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 }, |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static struct mode_info ega_modes[] = { |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 30 | { VIDEO_80x25, 80, 25, 0 }, |
| 31 | { VIDEO_8POINT, 80, 43, 0 }, |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | static struct mode_info cga_modes[] = { |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 35 | { VIDEO_80x25, 80, 25, 0 }, |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Hannes Eder | a1a00b5 | 2008-11-23 19:37:09 +0100 | [diff] [blame] | 38 | static __videocard video_vga; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 39 | |
| 40 | /* Set basic 80x25 mode */ |
| 41 | static u8 vga_set_basic_mode(void) |
| 42 | { |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 43 | struct biosregs ireg, oreg; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 44 | u16 ax; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 45 | u8 mode; |
| 46 | |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 47 | initregs(&ireg); |
| 48 | |
H. Peter Anvin | 8e92dc7 | 2010-02-19 13:21:38 -0800 | [diff] [blame^] | 49 | /* Query current mode */ |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 50 | ax = 0x0f00; |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 51 | intcall(0x10, &ireg, &oreg); |
| 52 | mode = oreg.al; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 53 | |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 54 | if (mode != 3 && mode != 7) |
| 55 | mode = 3; |
| 56 | |
| 57 | /* Set the mode */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 58 | ireg.ax = mode; /* AH=0: set mode */ |
| 59 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 60 | do_restore = 1; |
| 61 | return mode; |
| 62 | } |
| 63 | |
| 64 | static void vga_set_8font(void) |
| 65 | { |
| 66 | /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 67 | struct biosregs ireg; |
| 68 | |
| 69 | initregs(&ireg); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 70 | |
| 71 | /* Set 8x8 font */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 72 | ireg.ax = 0x1112; |
| 73 | /* ireg.bl = 0; */ |
| 74 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 75 | |
| 76 | /* Use alternate print screen */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 77 | ireg.ax = 0x1200; |
| 78 | ireg.bl = 0x20; |
| 79 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 80 | |
| 81 | /* Turn off cursor emulation */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 82 | ireg.ax = 0x1201; |
| 83 | ireg.bl = 0x34; |
| 84 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 85 | |
| 86 | /* Cursor is scan lines 6-7 */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 87 | ireg.ax = 0x0100; |
| 88 | ireg.cx = 0x0607; |
| 89 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static void vga_set_14font(void) |
| 93 | { |
| 94 | /* Set 9x14 font - 80x28 on VGA */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 95 | struct biosregs ireg; |
| 96 | |
| 97 | initregs(&ireg); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 98 | |
| 99 | /* Set 9x14 font */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 100 | ireg.ax = 0x1111; |
| 101 | /* ireg.bl = 0; */ |
| 102 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 103 | |
| 104 | /* Turn off cursor emulation */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 105 | ireg.ax = 0x1201; |
| 106 | ireg.bl = 0x34; |
| 107 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 108 | |
| 109 | /* Cursor is scan lines 11-12 */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 110 | ireg.ax = 0x0100; |
| 111 | ireg.cx = 0x0b0c; |
| 112 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void vga_set_80x43(void) |
| 116 | { |
| 117 | /* Set 80x43 mode on VGA (not EGA) */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 118 | struct biosregs ireg; |
| 119 | |
| 120 | initregs(&ireg); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 121 | |
| 122 | /* Set 350 scans */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 123 | ireg.ax = 0x1201; |
| 124 | ireg.bl = 0x30; |
| 125 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 126 | |
| 127 | /* Reset video mode */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 128 | ireg.ax = 0x0003; |
| 129 | intcall(0x10, &ireg, NULL); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 130 | |
| 131 | vga_set_8font(); |
| 132 | } |
| 133 | |
| 134 | /* I/O address of the VGA CRTC */ |
| 135 | u16 vga_crtc(void) |
| 136 | { |
| 137 | return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4; |
| 138 | } |
| 139 | |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 140 | static void vga_set_480_scanlines(void) |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 141 | { |
H. Peter Anvin | 5f64135 | 2009-03-18 16:54:05 -0700 | [diff] [blame] | 142 | u16 crtc; /* CRTC base address */ |
| 143 | u8 csel; /* CRTC miscellaneous output register */ |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 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 */ |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 149 | out_idx(0x3e, crtc, 0x07); /* Vertical overflow */ |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 150 | out_idx(0xea, crtc, 0x10); /* Vertical sync start */ |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 151 | out_idx(0xdf, crtc, 0x12); /* Vertical display end */ |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 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; |
H. Peter Anvin | 5f64135 | 2009-03-18 16:54:05 -0700 | [diff] [blame] | 157 | outb(csel, 0x3c2); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 158 | } |
| 159 | |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 160 | static 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 | |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 174 | static void vga_set_80x30(void) |
| 175 | { |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 176 | vga_set_480_scanlines(); |
| 177 | vga_set_vertical_end(30*16); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void vga_set_80x34(void) |
| 181 | { |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 182 | vga_set_480_scanlines(); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 183 | vga_set_14font(); |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 184 | vga_set_vertical_end(34*14); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static void vga_set_80x60(void) |
| 188 | { |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 189 | vga_set_480_scanlines(); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 190 | vga_set_8font(); |
H. Peter Anvin | 1e274a5 | 2009-04-07 10:59:25 -0700 | [diff] [blame] | 191 | vga_set_vertical_end(60*8); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static 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 | */ |
| 234 | static 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 | }; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 249 | |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 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); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 257 | |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 258 | #ifndef _WAKEUP |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 259 | boot_params.screen_info.orig_video_ega_bx = oreg.bx; |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 260 | #endif |
| 261 | |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 262 | /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 263 | if (oreg.bl != 0x10) { |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 264 | /* EGA/VGA */ |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 265 | ireg.ax = 0x1a00; |
| 266 | intcall(0x10, &ireg, &oreg); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 267 | |
H. Peter Anvin | cf06de7 | 2009-04-01 18:20:11 -0700 | [diff] [blame] | 268 | if (oreg.al == 0x1a) { |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 269 | adapter = ADAPTER_VGA; |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 270 | #ifndef _WAKEUP |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 271 | boot_params.screen_info.orig_video_isVGA = 1; |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 272 | #endif |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 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 | |
Hannes Eder | a1a00b5 | 2008-11-23 19:37:09 +0100 | [diff] [blame] | 285 | static __videocard video_vga = { |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 286 | .card_name = "VGA", |
| 287 | .probe = vga_probe, |
| 288 | .set_mode = vga_set_mode, |
| 289 | }; |