blob: ba3e100654db0239622a3f23f5d9d64855ebffd0 [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"
Vivek Goyalc041b5a2014-03-18 15:26:37 -040019#include "string.h"
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070020
21/* VESA information */
22static struct vesa_general_info vginfo;
23static struct vesa_mode_info vminfo;
24
roel kluin8bcad302008-10-21 19:49:09 -040025static __videocard video_vesa;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070026
Pavel Macheke44b7b72008-04-10 23:28:10 +020027#ifndef _WAKEUP
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070028static void vesa_store_mode_params_graphics(void);
Pavel Macheke44b7b72008-04-10 23:28:10 +020029#else /* _WAKEUP */
30static inline void vesa_store_mode_params_graphics(void) {}
31#endif /* _WAKEUP */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070032
33static int vesa_probe(void)
34{
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
Akinobu Mitafebe04d2009-07-01 11:13:07 +090048 if (oreg.ax != 0x004f ||
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070049 vginfo.signature != VESA_MAGIC ||
50 vginfo.version < 0x0102)
51 return 0; /* Not present */
H. Peter Anvin2495fbf2009-06-26 10:53:57 -070052
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070053 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 Anvine6e1ace2007-10-25 16:09:38 -070059 if (!heap_free(sizeof(struct mode_info)))
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070060 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 Anvincf06de72009-04-01 18:20:11 -070067 ireg.ax = 0x4f01;
68 ireg.cx = mode;
69 ireg.di = (size_t)&vminfo;
70 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070071
Akinobu Mitafebe04d2009-07-01 11:13:07 +090072 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070073 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 Anvin1cac5002008-01-30 13:33:02 +010079 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 Anvin5e8ddcbe2007-07-11 12:18:52 -070083 nmodes++;
H. Peter Anvin1cac5002008-01-30 13:33:02 +010084 } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
85 (vminfo.memory_layout == 4 ||
86 vminfo.memory_layout == 6) &&
87 vminfo.memory_planes == 1) {
Michal Januszewski4d31a2b2008-10-15 22:03:51 -070088#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070089 /* Graphics mode, color, linear frame buffer
H. Peter Anvin1cac5002008-01-30 13:33:02 +010090 supported. Only register the mode if
91 if framebuffer is configured, however,
Michal Januszewski4d31a2b2008-10-15 22:03:51 -070092 otherwise the user will be left without a screen. */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070093 mi = GET_HEAP(struct mode_info, 1);
94 mi->mode = mode + VIDEO_FIRST_VESA;
H. Peter Anvin1cac5002008-01-30 13:33:02 +010095 mi->depth = vminfo.bpp;
96 mi->x = vminfo.h_res;
97 mi->y = vminfo.v_res;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070098 nmodes++;
99#endif
100 }
101 }
102
103 return nmodes;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700104}
105
106static int vesa_set_mode(struct mode_info *mode)
107{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700108 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700109 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 Anvincf06de72009-04-01 18:20:11 -0700114 initregs(&ireg);
115 ireg.ax = 0x4f01;
116 ireg.cx = vesa_mode;
117 ireg.di = (size_t)&vminfo;
118 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700119
H. Peter Anvincf06de72009-04-01 18:20:11 -0700120 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700121 return -1;
122
123 if ((vminfo.mode_attr & 0x15) == 0x05) {
124 /* It's a supported text mode */
125 is_graphic = 0;
Michal Januszewski4d31a2b2008-10-15 22:03:51 -0700126#ifdef CONFIG_FB_BOOT_VESA_SUPPORT
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700127 } 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 Januszewski4d31a2b2008-10-15 22:03:51 -0700131#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700132 } else {
133 return -1; /* Invalid mode */
134 }
135
136
H. Peter Anvincf06de72009-04-01 18:20:11 -0700137 initregs(&ireg);
138 ireg.ax = 0x4f02;
139 ireg.bx = vesa_mode;
140 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700141
H. Peter Anvincf06de72009-04-01 18:20:11 -0700142 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700143 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 Macheke44b7b72008-04-10 23:28:10 +0200160#ifndef _WAKEUP
161
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700162/* Switch DAC to 8-bit mode */
163static void vesa_dac_set_8bits(void)
164{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700165 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700166 u8 dac_size = 6;
167
168 /* If possible, switch the DAC to 8-bit mode */
169 if (vginfo.capabilities & 1) {
H. Peter Anvincf06de72009-04-01 18:20:11 -0700170 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 Anvin5e8ddcbe2007-07-11 12:18:52 -0700176 }
177
178 /* Set the color sizes to the DAC size, and offsets to 0 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700179 boot_params.screen_info.red_size = dac_size;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700180 boot_params.screen_info.green_size = dac_size;
H. Peter Anvincf06de72009-04-01 18:20:11 -0700181 boot_params.screen_info.blue_size = dac_size;
182 boot_params.screen_info.rsvd_size = dac_size;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700183
H. Peter Anvincf06de72009-04-01 18:20:11 -0700184 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 Anvin5e8ddcbe2007-07-11 12:18:52 -0700188}
189
190/* Save the VESA protected mode info */
191static void vesa_store_pm_info(void)
192{
H. Peter Anvincf06de72009-04-01 18:20:11 -0700193 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700194
H. Peter Anvincf06de72009-04-01 18:20:11 -0700195 initregs(&ireg);
196 ireg.ax = 0x4f0a;
197 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700198
H. Peter Anvincf06de72009-04-01 18:20:11 -0700199 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700200 return;
201
H. Peter Anvincf06de72009-04-01 18:20:11 -0700202 boot_params.screen_info.vesapm_seg = oreg.es;
203 boot_params.screen_info.vesapm_off = oreg.di;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700204}
205
206/*
207 * Save video mode parameters for graphics mode
208 */
209static void vesa_store_mode_params_graphics(void)
210{
211 /* Tell the kernel we're in VESA graphics mode */
Michal Januszewski24073902008-10-05 12:16:04 +0200212 boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700213
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 */
238void vesa_store_edid(void)
239{
240#ifdef CONFIG_FIRMWARE_EDID
H. Peter Anvincf06de72009-04-01 18:20:11 -0700241 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700242
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 Anvincf06de72009-04-01 18:20:11 -0700249 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 Anvin5e8ddcbe2007-07-11 12:18:52 -0700255
H. Peter Anvincf06de72009-04-01 18:20:11 -0700256 if (oreg.ax != 0x004f)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700257 return; /* No EDID */
258
259 /* BH = time in seconds to transfer EDD information */
260 /* BL = DDC level supported */
261
H. Peter Anvincf06de72009-04-01 18:20:11 -0700262 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 Anvin5e8ddcbe2007-07-11 12:18:52 -0700269#endif /* CONFIG_FIRMWARE_EDID */
270}
271
Pavel Macheke44b7b72008-04-10 23:28:10 +0200272#endif /* not _WAKEUP */
273
roel kluin8bcad302008-10-21 19:49:09 -0400274static __videocard video_vesa =
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700275{
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};