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