blob: c700147d6ffb24b72fbbf43ff954d4cfd268f137 [file] [log] [blame]
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
H. Peter Anvincf06de72009-04-01 18:20:11 -07005 * Copyright 2009 Intel Corporation; author H. Peter Anvin
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07006 *
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 Anvin5e8ddcbe2007-07-11 12:18:52 -070013 * VESA text modes
14 */
15
16#include "boot.h"
17#include "video.h"
18#include "vesa.h"
19
20/* VESA information */
21static struct vesa_general_info vginfo;
22static struct vesa_mode_info vminfo;
23
roel kluin8bcad302008-10-21 19:49:09 -040024static __videocard video_vesa;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070025
Pavel Macheke44b7b72008-04-10 23:28:10 +020026#ifndef _WAKEUP
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070027static void vesa_store_mode_params_graphics(void);
Pavel Macheke44b7b72008-04-10 23:28:10 +020028#else /* _WAKEUP */
29static inline void vesa_store_mode_params_graphics(void) {}
30#endif /* _WAKEUP */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070031
32static int vesa_probe(void)
33{
34#if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
H. Peter Anvincf06de72009-04-01 18:20:11 -070035 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070036 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 Anvincf06de72009-04-01 18:20:11 -070043 initregs(&ireg);
44 ireg.ax = 0x4f00;
45 ireg.di = (size_t)&vginfo;
46 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070047
H. Peter Anvincf06de72009-04-01 18:20:11 -070048 if (ireg.ax != 0x004f ||
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070049 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 Anvine6e1ace2007-10-25 16:09:38 -070060 if (!heap_free(sizeof(struct mode_info)))
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070061 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
H. Peter Anvincf06de72009-04-01 18:20:11 -070068 ireg.ax = 0x4f01;
69 ireg.cx = mode;
70 ireg.di = (size_t)&vminfo;
71 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070072
H. Peter Anvincf06de72009-04-01 18:20:11 -070073 if (ireg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070074 continue;
75
76 if ((vminfo.mode_attr & 0x15) == 0x05) {
77 /* Text Mode, TTY BIOS supported,
78 supported by hardware */
79 mi = GET_HEAP(struct mode_info, 1);
H. Peter Anvin1cac5002008-01-30 13:33:02 +010080 mi->mode = mode + VIDEO_FIRST_VESA;
81 mi->depth = 0; /* text */
82 mi->x = vminfo.h_res;
83 mi->y = vminfo.v_res;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070084 nmodes++;
H. Peter Anvin1cac5002008-01-30 13:33:02 +010085 } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
86 (vminfo.memory_layout == 4 ||
87 vminfo.memory_layout == 6) &&
88 vminfo.memory_planes == 1) {
Michal Januszewski4d31a2b2008-10-15 22:03:51 -070089#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070090 /* Graphics mode, color, linear frame buffer
H. Peter Anvin1cac5002008-01-30 13:33:02 +010091 supported. Only register the mode if
92 if framebuffer is configured, however,
Michal Januszewski4d31a2b2008-10-15 22:03:51 -070093 otherwise the user will be left without a screen. */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070094 mi = GET_HEAP(struct mode_info, 1);
95 mi->mode = mode + VIDEO_FIRST_VESA;
H. Peter Anvin1cac5002008-01-30 13:33:02 +010096 mi->depth = vminfo.bpp;
97 mi->x = vminfo.h_res;
98 mi->y = vminfo.v_res;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070099 nmodes++;
100#endif
101 }
102 }
103
104 return nmodes;
105#else
106 return 0;
107#endif /* CONFIG_VIDEO_VESA */
108}
109
110static int vesa_set_mode(struct mode_info *mode)
111{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700112 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700113 int is_graphic;
114 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
115
116 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
117
H. Peter Anvincf06de72009-04-01 18:20:11 -0700118 initregs(&ireg);
119 ireg.ax = 0x4f01;
120 ireg.cx = vesa_mode;
121 ireg.di = (size_t)&vminfo;
122 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700123
H. Peter Anvincf06de72009-04-01 18:20:11 -0700124 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700125 return -1;
126
127 if ((vminfo.mode_attr & 0x15) == 0x05) {
128 /* It's a supported text mode */
129 is_graphic = 0;
Michal Januszewski4d31a2b2008-10-15 22:03:51 -0700130#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700131 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
132 /* It's a graphics mode with linear frame buffer */
133 is_graphic = 1;
134 vesa_mode |= 0x4000; /* Request linear frame buffer */
Michal Januszewski4d31a2b2008-10-15 22:03:51 -0700135#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700136 } else {
137 return -1; /* Invalid mode */
138 }
139
140
H. Peter Anvincf06de72009-04-01 18:20:11 -0700141 initregs(&ireg);
142 ireg.ax = 0x4f02;
143 ireg.bx = vesa_mode;
144 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700145
H. Peter Anvincf06de72009-04-01 18:20:11 -0700146 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700147 return -1;
148
149 graphic_mode = is_graphic;
150 if (!is_graphic) {
151 /* Text mode */
152 force_x = mode->x;
153 force_y = mode->y;
154 do_restore = 1;
155 } else {
156 /* Graphics mode */
157 vesa_store_mode_params_graphics();
158 }
159
160 return 0;
161}
162
163
Pavel Macheke44b7b72008-04-10 23:28:10 +0200164#ifndef _WAKEUP
165
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700166/* Switch DAC to 8-bit mode */
167static void vesa_dac_set_8bits(void)
168{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700169 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700170 u8 dac_size = 6;
171
172 /* If possible, switch the DAC to 8-bit mode */
173 if (vginfo.capabilities & 1) {
H. Peter Anvincf06de72009-04-01 18:20:11 -0700174 initregs(&ireg);
175 ireg.ax = 0x4f08;
176 ireg.bh = 0x08;
177 intcall(0x10, &ireg, &oreg);
178 if (oreg.ax == 0x004f)
179 dac_size = oreg.bh;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700180 }
181
182 /* Set the color sizes to the DAC size, and offsets to 0 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700183 boot_params.screen_info.red_size = dac_size;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700184 boot_params.screen_info.green_size = dac_size;
H. Peter Anvincf06de72009-04-01 18:20:11 -0700185 boot_params.screen_info.blue_size = dac_size;
186 boot_params.screen_info.rsvd_size = dac_size;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700187
H. Peter Anvincf06de72009-04-01 18:20:11 -0700188 boot_params.screen_info.red_pos = 0;
189 boot_params.screen_info.green_pos = 0;
190 boot_params.screen_info.blue_pos = 0;
191 boot_params.screen_info.rsvd_pos = 0;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700192}
193
194/* Save the VESA protected mode info */
195static void vesa_store_pm_info(void)
196{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700197 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700198
H. Peter Anvincf06de72009-04-01 18:20:11 -0700199 initregs(&ireg);
200 ireg.ax = 0x4f0a;
201 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700202
H. Peter Anvincf06de72009-04-01 18:20:11 -0700203 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700204 return;
205
H. Peter Anvincf06de72009-04-01 18:20:11 -0700206 boot_params.screen_info.vesapm_seg = oreg.es;
207 boot_params.screen_info.vesapm_off = oreg.di;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700208}
209
210/*
211 * Save video mode parameters for graphics mode
212 */
213static void vesa_store_mode_params_graphics(void)
214{
215 /* Tell the kernel we're in VESA graphics mode */
Michal Januszewski24073902008-10-05 12:16:04 +0200216 boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700217
218 /* Mode parameters */
219 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
220 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
221 boot_params.screen_info.lfb_width = vminfo.h_res;
222 boot_params.screen_info.lfb_height = vminfo.v_res;
223 boot_params.screen_info.lfb_depth = vminfo.bpp;
224 boot_params.screen_info.pages = vminfo.image_planes;
225 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
226 memcpy(&boot_params.screen_info.red_size,
227 &vminfo.rmask, 8);
228
229 /* General parameters */
230 boot_params.screen_info.lfb_size = vginfo.total_memory;
231
232 if (vminfo.bpp <= 8)
233 vesa_dac_set_8bits();
234
235 vesa_store_pm_info();
236}
237
238/*
239 * Save EDID information for the kernel; this is invoked, separately,
240 * after mode-setting.
241 */
242void vesa_store_edid(void)
243{
244#ifdef CONFIG_FIRMWARE_EDID
H. Peter Anvincf06de72009-04-01 18:20:11 -0700245 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700246
247 /* Apparently used as a nonsense token... */
248 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
249
250 if (vginfo.version < 0x0200)
251 return; /* EDID requires VBE 2.0+ */
252
H. Peter Anvincf06de72009-04-01 18:20:11 -0700253 initregs(&ireg);
254 ireg.ax = 0x4f15; /* VBE DDC */
255 /* ireg.bx = 0x0000; */ /* Report DDC capabilities */
256 /* ireg.cx = 0; */ /* Controller 0 */
257 ireg.es = 0; /* ES:DI must be 0 by spec */
258 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700259
H. Peter Anvincf06de72009-04-01 18:20:11 -0700260 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700261 return; /* No EDID */
262
263 /* BH = time in seconds to transfer EDD information */
264 /* BL = DDC level supported */
265
H. Peter Anvincf06de72009-04-01 18:20:11 -0700266 ireg.ax = 0x4f15; /* VBE DDC */
267 ireg.bx = 0x0001; /* Read EDID */
268 /* ireg.cx = 0; */ /* Controller 0 */
269 /* ireg.dx = 0; */ /* EDID block number */
270 ireg.es = ds();
271 ireg.di =(size_t)&boot_params.edid_info; /* (ES:)Pointer to block */
272 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700273#endif /* CONFIG_FIRMWARE_EDID */
274}
275
Pavel Macheke44b7b72008-04-10 23:28:10 +0200276#endif /* not _WAKEUP */
277
roel kluin8bcad302008-10-21 19:49:09 -0400278static __videocard video_vesa =
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700279{
280 .card_name = "VESA",
281 .probe = vesa_probe,
282 .set_mode = vesa_set_mode,
283 .xmode_first = VIDEO_FIRST_VESA,
284 .xmode_n = 0x200,
285};