blob: 11e8c6eb80a1014b4f0df92d15ccca32d29c6625 [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{
H. Peter Anvincf06de72009-04-01 18:20:11 -070034 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070035 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 Anvincf06de72009-04-01 18:20:11 -070042 initregs(&ireg);
43 ireg.ax = 0x4f00;
44 ireg.di = (size_t)&vginfo;
45 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070046
Akinobu Mitafebe04d2009-07-01 11:13:07 +090047 if (oreg.ax != 0x004f ||
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070048 vginfo.signature != VESA_MAGIC ||
49 vginfo.version < 0x0102)
50 return 0; /* Not present */
H. Peter Anvin2495fbf2009-06-26 10:53:57 -070051
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070052 set_fs(vginfo.video_mode_ptr.seg);
53 mode_ptr = vginfo.video_mode_ptr.off;
54
55 while ((mode = rdfs16(mode_ptr)) != 0xffff) {
56 mode_ptr += 2;
57
H. Peter Anvine6e1ace2007-10-25 16:09:38 -070058 if (!heap_free(sizeof(struct mode_info)))
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070059 break; /* Heap full, can't save mode info */
60
61 if (mode & ~0x1ff)
62 continue;
63
64 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
65
H. Peter Anvincf06de72009-04-01 18:20:11 -070066 ireg.ax = 0x4f01;
67 ireg.cx = mode;
68 ireg.di = (size_t)&vminfo;
69 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070070
Akinobu Mitafebe04d2009-07-01 11:13:07 +090071 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070072 continue;
73
74 if ((vminfo.mode_attr & 0x15) == 0x05) {
75 /* Text Mode, TTY BIOS supported,
76 supported by hardware */
77 mi = GET_HEAP(struct mode_info, 1);
H. Peter Anvin1cac5002008-01-30 13:33:02 +010078 mi->mode = mode + VIDEO_FIRST_VESA;
79 mi->depth = 0; /* text */
80 mi->x = vminfo.h_res;
81 mi->y = vminfo.v_res;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070082 nmodes++;
H. Peter Anvin1cac5002008-01-30 13:33:02 +010083 } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
84 (vminfo.memory_layout == 4 ||
85 vminfo.memory_layout == 6) &&
86 vminfo.memory_planes == 1) {
Michal Januszewski4d31a2b2008-10-15 22:03:51 -070087#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070088 /* Graphics mode, color, linear frame buffer
H. Peter Anvin1cac5002008-01-30 13:33:02 +010089 supported. Only register the mode if
90 if framebuffer is configured, however,
Michal Januszewski4d31a2b2008-10-15 22:03:51 -070091 otherwise the user will be left without a screen. */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070092 mi = GET_HEAP(struct mode_info, 1);
93 mi->mode = mode + VIDEO_FIRST_VESA;
H. Peter Anvin1cac5002008-01-30 13:33:02 +010094 mi->depth = vminfo.bpp;
95 mi->x = vminfo.h_res;
96 mi->y = vminfo.v_res;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070097 nmodes++;
98#endif
99 }
100 }
101
102 return nmodes;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700103}
104
105static int vesa_set_mode(struct mode_info *mode)
106{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700107 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700108 int is_graphic;
109 u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
110
111 memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
112
H. Peter Anvincf06de72009-04-01 18:20:11 -0700113 initregs(&ireg);
114 ireg.ax = 0x4f01;
115 ireg.cx = vesa_mode;
116 ireg.di = (size_t)&vminfo;
117 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700118
H. Peter Anvincf06de72009-04-01 18:20:11 -0700119 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700120 return -1;
121
122 if ((vminfo.mode_attr & 0x15) == 0x05) {
123 /* It's a supported text mode */
124 is_graphic = 0;
Michal Januszewski4d31a2b2008-10-15 22:03:51 -0700125#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700126 } else if ((vminfo.mode_attr & 0x99) == 0x99) {
127 /* It's a graphics mode with linear frame buffer */
128 is_graphic = 1;
129 vesa_mode |= 0x4000; /* Request linear frame buffer */
Michal Januszewski4d31a2b2008-10-15 22:03:51 -0700130#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700131 } else {
132 return -1; /* Invalid mode */
133 }
134
135
H. Peter Anvincf06de72009-04-01 18:20:11 -0700136 initregs(&ireg);
137 ireg.ax = 0x4f02;
138 ireg.bx = vesa_mode;
139 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700140
H. Peter Anvincf06de72009-04-01 18:20:11 -0700141 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700142 return -1;
143
144 graphic_mode = is_graphic;
145 if (!is_graphic) {
146 /* Text mode */
147 force_x = mode->x;
148 force_y = mode->y;
149 do_restore = 1;
150 } else {
151 /* Graphics mode */
152 vesa_store_mode_params_graphics();
153 }
154
155 return 0;
156}
157
158
Pavel Macheke44b7b72008-04-10 23:28:10 +0200159#ifndef _WAKEUP
160
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700161/* Switch DAC to 8-bit mode */
162static void vesa_dac_set_8bits(void)
163{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700164 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700165 u8 dac_size = 6;
166
167 /* If possible, switch the DAC to 8-bit mode */
168 if (vginfo.capabilities & 1) {
H. Peter Anvincf06de72009-04-01 18:20:11 -0700169 initregs(&ireg);
170 ireg.ax = 0x4f08;
171 ireg.bh = 0x08;
172 intcall(0x10, &ireg, &oreg);
173 if (oreg.ax == 0x004f)
174 dac_size = oreg.bh;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700175 }
176
177 /* Set the color sizes to the DAC size, and offsets to 0 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700178 boot_params.screen_info.red_size = dac_size;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700179 boot_params.screen_info.green_size = dac_size;
H. Peter Anvincf06de72009-04-01 18:20:11 -0700180 boot_params.screen_info.blue_size = dac_size;
181 boot_params.screen_info.rsvd_size = dac_size;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700182
H. Peter Anvincf06de72009-04-01 18:20:11 -0700183 boot_params.screen_info.red_pos = 0;
184 boot_params.screen_info.green_pos = 0;
185 boot_params.screen_info.blue_pos = 0;
186 boot_params.screen_info.rsvd_pos = 0;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700187}
188
189/* Save the VESA protected mode info */
190static void vesa_store_pm_info(void)
191{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700192 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700193
H. Peter Anvincf06de72009-04-01 18:20:11 -0700194 initregs(&ireg);
195 ireg.ax = 0x4f0a;
196 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700197
H. Peter Anvincf06de72009-04-01 18:20:11 -0700198 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700199 return;
200
H. Peter Anvincf06de72009-04-01 18:20:11 -0700201 boot_params.screen_info.vesapm_seg = oreg.es;
202 boot_params.screen_info.vesapm_off = oreg.di;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700203}
204
205/*
206 * Save video mode parameters for graphics mode
207 */
208static void vesa_store_mode_params_graphics(void)
209{
210 /* Tell the kernel we're in VESA graphics mode */
Michal Januszewski24073902008-10-05 12:16:04 +0200211 boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700212
213 /* Mode parameters */
214 boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
215 boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
216 boot_params.screen_info.lfb_width = vminfo.h_res;
217 boot_params.screen_info.lfb_height = vminfo.v_res;
218 boot_params.screen_info.lfb_depth = vminfo.bpp;
219 boot_params.screen_info.pages = vminfo.image_planes;
220 boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
221 memcpy(&boot_params.screen_info.red_size,
222 &vminfo.rmask, 8);
223
224 /* General parameters */
225 boot_params.screen_info.lfb_size = vginfo.total_memory;
226
227 if (vminfo.bpp <= 8)
228 vesa_dac_set_8bits();
229
230 vesa_store_pm_info();
231}
232
233/*
234 * Save EDID information for the kernel; this is invoked, separately,
235 * after mode-setting.
236 */
237void vesa_store_edid(void)
238{
239#ifdef CONFIG_FIRMWARE_EDID
H. Peter Anvincf06de72009-04-01 18:20:11 -0700240 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700241
242 /* Apparently used as a nonsense token... */
243 memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
244
245 if (vginfo.version < 0x0200)
246 return; /* EDID requires VBE 2.0+ */
247
H. Peter Anvincf06de72009-04-01 18:20:11 -0700248 initregs(&ireg);
249 ireg.ax = 0x4f15; /* VBE DDC */
250 /* ireg.bx = 0x0000; */ /* Report DDC capabilities */
251 /* ireg.cx = 0; */ /* Controller 0 */
252 ireg.es = 0; /* ES:DI must be 0 by spec */
253 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700254
H. Peter Anvincf06de72009-04-01 18:20:11 -0700255 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700256 return; /* No EDID */
257
258 /* BH = time in seconds to transfer EDD information */
259 /* BL = DDC level supported */
260
H. Peter Anvincf06de72009-04-01 18:20:11 -0700261 ireg.ax = 0x4f15; /* VBE DDC */
262 ireg.bx = 0x0001; /* Read EDID */
263 /* ireg.cx = 0; */ /* Controller 0 */
264 /* ireg.dx = 0; */ /* EDID block number */
265 ireg.es = ds();
266 ireg.di =(size_t)&boot_params.edid_info; /* (ES:)Pointer to block */
267 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700268#endif /* CONFIG_FIRMWARE_EDID */
269}
270
Pavel Macheke44b7b72008-04-10 23:28:10 +0200271#endif /* not _WAKEUP */
272
roel kluin8bcad302008-10-21 19:49:09 -0400273static __videocard video_vesa =
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700274{
275 .card_name = "VESA",
276 .probe = vesa_probe,
277 .set_mode = vesa_set_mode,
278 .xmode_first = VIDEO_FIRST_VESA,
279 .xmode_n = 0x200,
280};