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 |
| 5 | * |
| 6 | * This file is part of the Linux kernel, and is made available under |
| 7 | * the terms of the GNU General Public License version 2. |
| 8 | * |
| 9 | * ----------------------------------------------------------------------- */ |
| 10 | |
| 11 | /* |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 12 | * VESA text modes |
| 13 | */ |
| 14 | |
| 15 | #include "boot.h" |
| 16 | #include "video.h" |
| 17 | #include "vesa.h" |
| 18 | |
| 19 | /* VESA information */ |
| 20 | static struct vesa_general_info vginfo; |
| 21 | static struct vesa_mode_info vminfo; |
| 22 | |
roel kluin | 8bcad30 | 2008-10-21 19:49:09 -0400 | [diff] [blame^] | 23 | static __videocard video_vesa; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 24 | |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 25 | #ifndef _WAKEUP |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 26 | static void vesa_store_mode_params_graphics(void); |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 27 | #else /* _WAKEUP */ |
| 28 | static inline void vesa_store_mode_params_graphics(void) {} |
| 29 | #endif /* _WAKEUP */ |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 30 | |
| 31 | static int vesa_probe(void) |
| 32 | { |
| 33 | #if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID) |
H. Peter Anvin | 4221d01 | 2007-08-31 11:30:31 -0700 | [diff] [blame] | 34 | u16 ax, cx, di; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 35 | u16 mode; |
| 36 | addr_t mode_ptr; |
| 37 | struct mode_info *mi; |
| 38 | int nmodes = 0; |
| 39 | |
| 40 | video_vesa.modes = GET_HEAP(struct mode_info, 0); |
| 41 | |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 42 | ax = 0x4f00; |
H. Peter Anvin | 4221d01 | 2007-08-31 11:30:31 -0700 | [diff] [blame] | 43 | di = (size_t)&vginfo; |
| 44 | asm(INT10 |
| 45 | : "+a" (ax), "+D" (di), "=m" (vginfo) |
| 46 | : : "ebx", "ecx", "edx", "esi"); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 47 | |
| 48 | if (ax != 0x004f || |
| 49 | vginfo.signature != VESA_MAGIC || |
| 50 | vginfo.version < 0x0102) |
| 51 | return 0; /* Not present */ |
| 52 | #endif /* CONFIG_VIDEO_VESA || CONFIG_FIRMWARE_EDID */ |
| 53 | #ifdef CONFIG_VIDEO_VESA |
| 54 | set_fs(vginfo.video_mode_ptr.seg); |
| 55 | mode_ptr = vginfo.video_mode_ptr.off; |
| 56 | |
| 57 | while ((mode = rdfs16(mode_ptr)) != 0xffff) { |
| 58 | mode_ptr += 2; |
| 59 | |
H. Peter Anvin | e6e1ace | 2007-10-25 16:09:38 -0700 | [diff] [blame] | 60 | if (!heap_free(sizeof(struct mode_info))) |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 61 | break; /* Heap full, can't save mode info */ |
| 62 | |
| 63 | if (mode & ~0x1ff) |
| 64 | continue; |
| 65 | |
| 66 | memset(&vminfo, 0, sizeof vminfo); /* Just in case... */ |
| 67 | |
| 68 | ax = 0x4f01; |
H. Peter Anvin | 4221d01 | 2007-08-31 11:30:31 -0700 | [diff] [blame] | 69 | cx = mode; |
| 70 | di = (size_t)&vminfo; |
| 71 | asm(INT10 |
| 72 | : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo) |
| 73 | : : "ebx", "edx", "esi"); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 74 | |
| 75 | if (ax != 0x004f) |
| 76 | continue; |
| 77 | |
| 78 | if ((vminfo.mode_attr & 0x15) == 0x05) { |
| 79 | /* Text Mode, TTY BIOS supported, |
| 80 | supported by hardware */ |
| 81 | mi = GET_HEAP(struct mode_info, 1); |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 82 | mi->mode = mode + VIDEO_FIRST_VESA; |
| 83 | mi->depth = 0; /* text */ |
| 84 | mi->x = vminfo.h_res; |
| 85 | mi->y = vminfo.v_res; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 86 | nmodes++; |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 87 | } else if ((vminfo.mode_attr & 0x99) == 0x99 && |
| 88 | (vminfo.memory_layout == 4 || |
| 89 | vminfo.memory_layout == 6) && |
| 90 | vminfo.memory_planes == 1) { |
Michal Januszewski | 4d31a2b | 2008-10-15 22:03:51 -0700 | [diff] [blame] | 91 | #ifdef CONFIG_FB_BOOT_VESA_SUPPORT |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 92 | /* Graphics mode, color, linear frame buffer |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 93 | supported. Only register the mode if |
| 94 | if framebuffer is configured, however, |
Michal Januszewski | 4d31a2b | 2008-10-15 22:03:51 -0700 | [diff] [blame] | 95 | otherwise the user will be left without a screen. */ |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 96 | mi = GET_HEAP(struct mode_info, 1); |
| 97 | mi->mode = mode + VIDEO_FIRST_VESA; |
H. Peter Anvin | 1cac500 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 98 | mi->depth = vminfo.bpp; |
| 99 | mi->x = vminfo.h_res; |
| 100 | mi->y = vminfo.v_res; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 101 | nmodes++; |
| 102 | #endif |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return nmodes; |
| 107 | #else |
| 108 | return 0; |
| 109 | #endif /* CONFIG_VIDEO_VESA */ |
| 110 | } |
| 111 | |
| 112 | static int vesa_set_mode(struct mode_info *mode) |
| 113 | { |
H. Peter Anvin | 4221d01 | 2007-08-31 11:30:31 -0700 | [diff] [blame] | 114 | u16 ax, bx, cx, di; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 115 | int is_graphic; |
| 116 | u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA; |
| 117 | |
| 118 | memset(&vminfo, 0, sizeof vminfo); /* Just in case... */ |
| 119 | |
| 120 | ax = 0x4f01; |
H. Peter Anvin | 4221d01 | 2007-08-31 11:30:31 -0700 | [diff] [blame] | 121 | cx = vesa_mode; |
| 122 | di = (size_t)&vminfo; |
| 123 | asm(INT10 |
| 124 | : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo) |
| 125 | : : "ebx", "edx", "esi"); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 126 | |
| 127 | if (ax != 0x004f) |
| 128 | return -1; |
| 129 | |
| 130 | if ((vminfo.mode_attr & 0x15) == 0x05) { |
| 131 | /* It's a supported text mode */ |
| 132 | is_graphic = 0; |
Michal Januszewski | 4d31a2b | 2008-10-15 22:03:51 -0700 | [diff] [blame] | 133 | #ifdef CONFIG_FB_BOOT_VESA_SUPPORT |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 134 | } else if ((vminfo.mode_attr & 0x99) == 0x99) { |
| 135 | /* It's a graphics mode with linear frame buffer */ |
| 136 | is_graphic = 1; |
| 137 | vesa_mode |= 0x4000; /* Request linear frame buffer */ |
Michal Januszewski | 4d31a2b | 2008-10-15 22:03:51 -0700 | [diff] [blame] | 138 | #endif |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 139 | } else { |
| 140 | return -1; /* Invalid mode */ |
| 141 | } |
| 142 | |
| 143 | |
| 144 | ax = 0x4f02; |
H. Peter Anvin | 4221d01 | 2007-08-31 11:30:31 -0700 | [diff] [blame] | 145 | bx = vesa_mode; |
| 146 | di = 0; |
| 147 | asm volatile(INT10 |
| 148 | : "+a" (ax), "+b" (bx), "+D" (di) |
| 149 | : : "ecx", "edx", "esi"); |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 150 | |
| 151 | if (ax != 0x004f) |
| 152 | return -1; |
| 153 | |
| 154 | graphic_mode = is_graphic; |
| 155 | if (!is_graphic) { |
| 156 | /* Text mode */ |
| 157 | force_x = mode->x; |
| 158 | force_y = mode->y; |
| 159 | do_restore = 1; |
| 160 | } else { |
| 161 | /* Graphics mode */ |
| 162 | vesa_store_mode_params_graphics(); |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 169 | #ifndef _WAKEUP |
| 170 | |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 171 | /* Switch DAC to 8-bit mode */ |
| 172 | static void vesa_dac_set_8bits(void) |
| 173 | { |
| 174 | u8 dac_size = 6; |
| 175 | |
| 176 | /* If possible, switch the DAC to 8-bit mode */ |
| 177 | if (vginfo.capabilities & 1) { |
| 178 | u16 ax, bx; |
| 179 | |
| 180 | ax = 0x4f08; |
| 181 | bx = 0x0800; |
| 182 | asm volatile(INT10 |
| 183 | : "+a" (ax), "+b" (bx) |
| 184 | : : "ecx", "edx", "esi", "edi"); |
| 185 | |
| 186 | if (ax == 0x004f) |
| 187 | dac_size = bx >> 8; |
| 188 | } |
| 189 | |
| 190 | /* Set the color sizes to the DAC size, and offsets to 0 */ |
| 191 | boot_params.screen_info.red_size = dac_size; |
| 192 | boot_params.screen_info.green_size = dac_size; |
| 193 | boot_params.screen_info.blue_size = dac_size; |
| 194 | boot_params.screen_info.rsvd_size = dac_size; |
| 195 | |
| 196 | boot_params.screen_info.red_pos = 0; |
| 197 | boot_params.screen_info.green_pos = 0; |
| 198 | boot_params.screen_info.blue_pos = 0; |
| 199 | boot_params.screen_info.rsvd_pos = 0; |
| 200 | } |
| 201 | |
| 202 | /* Save the VESA protected mode info */ |
| 203 | static void vesa_store_pm_info(void) |
| 204 | { |
| 205 | u16 ax, bx, di, es; |
| 206 | |
| 207 | ax = 0x4f0a; |
| 208 | bx = di = 0; |
| 209 | asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es" |
| 210 | : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di) |
| 211 | : : "ecx", "esi"); |
| 212 | |
| 213 | if (ax != 0x004f) |
| 214 | return; |
| 215 | |
| 216 | boot_params.screen_info.vesapm_seg = es; |
| 217 | boot_params.screen_info.vesapm_off = di; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Save video mode parameters for graphics mode |
| 222 | */ |
| 223 | static void vesa_store_mode_params_graphics(void) |
| 224 | { |
| 225 | /* Tell the kernel we're in VESA graphics mode */ |
Michal Januszewski | 2407390 | 2008-10-05 12:16:04 +0200 | [diff] [blame] | 226 | boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB; |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 227 | |
| 228 | /* Mode parameters */ |
| 229 | boot_params.screen_info.vesa_attributes = vminfo.mode_attr; |
| 230 | boot_params.screen_info.lfb_linelength = vminfo.logical_scan; |
| 231 | boot_params.screen_info.lfb_width = vminfo.h_res; |
| 232 | boot_params.screen_info.lfb_height = vminfo.v_res; |
| 233 | boot_params.screen_info.lfb_depth = vminfo.bpp; |
| 234 | boot_params.screen_info.pages = vminfo.image_planes; |
| 235 | boot_params.screen_info.lfb_base = vminfo.lfb_ptr; |
| 236 | memcpy(&boot_params.screen_info.red_size, |
| 237 | &vminfo.rmask, 8); |
| 238 | |
| 239 | /* General parameters */ |
| 240 | boot_params.screen_info.lfb_size = vginfo.total_memory; |
| 241 | |
| 242 | if (vminfo.bpp <= 8) |
| 243 | vesa_dac_set_8bits(); |
| 244 | |
| 245 | vesa_store_pm_info(); |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Save EDID information for the kernel; this is invoked, separately, |
| 250 | * after mode-setting. |
| 251 | */ |
| 252 | void vesa_store_edid(void) |
| 253 | { |
| 254 | #ifdef CONFIG_FIRMWARE_EDID |
| 255 | u16 ax, bx, cx, dx, di; |
| 256 | |
| 257 | /* Apparently used as a nonsense token... */ |
| 258 | memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info); |
| 259 | |
| 260 | if (vginfo.version < 0x0200) |
| 261 | return; /* EDID requires VBE 2.0+ */ |
| 262 | |
| 263 | ax = 0x4f15; /* VBE DDC */ |
| 264 | bx = 0x0000; /* Report DDC capabilities */ |
| 265 | cx = 0; /* Controller 0 */ |
| 266 | di = 0; /* ES:DI must be 0 by spec */ |
| 267 | |
| 268 | /* Note: The VBE DDC spec is different from the main VESA spec; |
| 269 | we genuinely have to assume all registers are destroyed here. */ |
| 270 | |
| 271 | asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es" |
| 272 | : "+a" (ax), "+b" (bx) |
| 273 | : "c" (cx), "D" (di) |
| 274 | : "esi"); |
| 275 | |
| 276 | if (ax != 0x004f) |
| 277 | return; /* No EDID */ |
| 278 | |
| 279 | /* BH = time in seconds to transfer EDD information */ |
| 280 | /* BL = DDC level supported */ |
| 281 | |
| 282 | ax = 0x4f15; /* VBE DDC */ |
| 283 | bx = 0x0001; /* Read EDID */ |
| 284 | cx = 0; /* Controller 0 */ |
| 285 | dx = 0; /* EDID block number */ |
| 286 | di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */ |
| 287 | asm(INT10 |
Antonino A. Daplas | 59acc08 | 2007-08-02 18:16:46 +0800 | [diff] [blame] | 288 | : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info) |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 289 | : "c" (cx), "D" (di) |
| 290 | : "esi"); |
| 291 | #endif /* CONFIG_FIRMWARE_EDID */ |
| 292 | } |
| 293 | |
Pavel Machek | e44b7b7 | 2008-04-10 23:28:10 +0200 | [diff] [blame] | 294 | #endif /* not _WAKEUP */ |
| 295 | |
roel kluin | 8bcad30 | 2008-10-21 19:49:09 -0400 | [diff] [blame^] | 296 | static __videocard video_vesa = |
H. Peter Anvin | 5e8ddcbe | 2007-07-11 12:18:52 -0700 | [diff] [blame] | 297 | { |
| 298 | .card_name = "VESA", |
| 299 | .probe = vesa_probe, |
| 300 | .set_mode = vesa_set_mode, |
| 301 | .xmode_first = VIDEO_FIRST_VESA, |
| 302 | .xmode_n = 0x200, |
| 303 | }; |