1 // SPDX-License-Identifier: GPL-2.0-only
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * Copyright 2009 Intel Corporation; author H. Peter Anvin
8 * ----------------------------------------------------------------------- */
19 /* VESA information */
20 static struct vesa_general_info vginfo
;
21 static struct vesa_mode_info vminfo
;
23 static __videocard video_vesa
;
26 static void vesa_store_mode_params_graphics(void);
28 static inline void vesa_store_mode_params_graphics(void) {}
31 static int vesa_probe(void)
33 struct biosregs ireg
, oreg
;
39 video_vesa
.modes
= GET_HEAP(struct mode_info
, 0);
43 ireg
.di
= (size_t)&vginfo
;
44 intcall(0x10, &ireg
, &oreg
);
46 if (oreg
.ax
!= 0x004f ||
47 vginfo
.signature
!= VESA_MAGIC
||
48 vginfo
.version
< 0x0102)
49 return 0; /* Not present */
51 set_fs(vginfo
.video_mode_ptr
.seg
);
52 mode_ptr
= vginfo
.video_mode_ptr
.off
;
54 while ((mode
= rdfs16(mode_ptr
)) != 0xffff) {
57 if (!heap_free(sizeof(struct mode_info
)))
58 break; /* Heap full, can't save mode info */
63 memset(&vminfo
, 0, sizeof(vminfo
)); /* Just in case... */
67 ireg
.di
= (size_t)&vminfo
;
68 intcall(0x10, &ireg
, &oreg
);
70 if (oreg
.ax
!= 0x004f)
73 if ((vminfo
.mode_attr
& 0x15) == 0x05) {
74 /* Text Mode, TTY BIOS supported,
75 supported by hardware */
76 mi
= GET_HEAP(struct mode_info
, 1);
77 mi
->mode
= mode
+ VIDEO_FIRST_VESA
;
78 mi
->depth
= 0; /* text */
82 } else if ((vminfo
.mode_attr
& 0x99) == 0x99 &&
83 (vminfo
.memory_layout
== 4 ||
84 vminfo
.memory_layout
== 6) &&
85 vminfo
.memory_planes
== 1) {
86 #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
87 /* Graphics mode, color, linear frame buffer
88 supported. Only register the mode if
89 if framebuffer is configured, however,
90 otherwise the user will be left without a screen. */
91 mi
= GET_HEAP(struct mode_info
, 1);
92 mi
->mode
= mode
+ VIDEO_FIRST_VESA
;
93 mi
->depth
= vminfo
.bpp
;
104 static int vesa_set_mode(struct mode_info
*mode
)
106 struct biosregs ireg
, oreg
;
108 u16 vesa_mode
= mode
->mode
- VIDEO_FIRST_VESA
;
110 memset(&vminfo
, 0, sizeof(vminfo
)); /* Just in case... */
115 ireg
.di
= (size_t)&vminfo
;
116 intcall(0x10, &ireg
, &oreg
);
118 if (oreg
.ax
!= 0x004f)
121 if ((vminfo
.mode_attr
& 0x15) == 0x05) {
122 /* It's a supported text mode */
124 #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
125 } else if ((vminfo
.mode_attr
& 0x99) == 0x99) {
126 /* It's a graphics mode with linear frame buffer */
128 vesa_mode
|= 0x4000; /* Request linear frame buffer */
131 return -1; /* Invalid mode */
138 intcall(0x10, &ireg
, &oreg
);
140 if (oreg
.ax
!= 0x004f)
143 graphic_mode
= is_graphic
;
151 vesa_store_mode_params_graphics();
160 /* Switch DAC to 8-bit mode */
161 static void vesa_dac_set_8bits(void)
163 struct biosregs ireg
, oreg
;
166 /* If possible, switch the DAC to 8-bit mode */
167 if (vginfo
.capabilities
& 1) {
171 intcall(0x10, &ireg
, &oreg
);
172 if (oreg
.ax
== 0x004f)
176 /* Set the color sizes to the DAC size, and offsets to 0 */
177 boot_params
.screen_info
.red_size
= dac_size
;
178 boot_params
.screen_info
.green_size
= dac_size
;
179 boot_params
.screen_info
.blue_size
= dac_size
;
180 boot_params
.screen_info
.rsvd_size
= dac_size
;
182 boot_params
.screen_info
.red_pos
= 0;
183 boot_params
.screen_info
.green_pos
= 0;
184 boot_params
.screen_info
.blue_pos
= 0;
185 boot_params
.screen_info
.rsvd_pos
= 0;
188 /* Save the VESA protected mode info */
189 static void vesa_store_pm_info(void)
191 struct biosregs ireg
, oreg
;
195 intcall(0x10, &ireg
, &oreg
);
197 if (oreg
.ax
!= 0x004f)
200 boot_params
.screen_info
.vesapm_seg
= oreg
.es
;
201 boot_params
.screen_info
.vesapm_off
= oreg
.di
;
205 * Save video mode parameters for graphics mode
207 static void vesa_store_mode_params_graphics(void)
209 /* Tell the kernel we're in VESA graphics mode */
210 boot_params
.screen_info
.orig_video_isVGA
= VIDEO_TYPE_VLFB
;
212 /* Mode parameters */
213 boot_params
.screen_info
.vesa_attributes
= vminfo
.mode_attr
;
214 boot_params
.screen_info
.lfb_linelength
= vminfo
.logical_scan
;
215 boot_params
.screen_info
.lfb_width
= vminfo
.h_res
;
216 boot_params
.screen_info
.lfb_height
= vminfo
.v_res
;
217 boot_params
.screen_info
.lfb_depth
= vminfo
.bpp
;
218 boot_params
.screen_info
.pages
= vminfo
.image_planes
;
219 boot_params
.screen_info
.lfb_base
= vminfo
.lfb_ptr
;
220 memcpy(&boot_params
.screen_info
.red_size
,
223 /* General parameters */
224 boot_params
.screen_info
.lfb_size
= vginfo
.total_memory
;
227 vesa_dac_set_8bits();
229 vesa_store_pm_info();
233 * Save EDID information for the kernel; this is invoked, separately,
234 * after mode-setting.
236 void vesa_store_edid(void)
238 #ifdef CONFIG_FIRMWARE_EDID
239 struct biosregs ireg
, oreg
;
241 /* Apparently used as a nonsense token... */
242 memset(&boot_params
.edid_info
, 0x13, sizeof(boot_params
.edid_info
));
244 if (vginfo
.version
< 0x0200)
245 return; /* EDID requires VBE 2.0+ */
248 ireg
.ax
= 0x4f15; /* VBE DDC */
249 /* ireg.bx = 0x0000; */ /* Report DDC capabilities */
250 /* ireg.cx = 0; */ /* Controller 0 */
251 ireg
.es
= 0; /* ES:DI must be 0 by spec */
252 intcall(0x10, &ireg
, &oreg
);
254 if (oreg
.ax
!= 0x004f)
255 return; /* No EDID */
257 /* BH = time in seconds to transfer EDD information */
258 /* BL = DDC level supported */
260 ireg
.ax
= 0x4f15; /* VBE DDC */
261 ireg
.bx
= 0x0001; /* Read EDID */
262 /* ireg.cx = 0; */ /* Controller 0 */
263 /* ireg.dx = 0; */ /* EDID block number */
265 ireg
.di
=(size_t)&boot_params
.edid_info
; /* (ES:)Pointer to block */
266 intcall(0x10, &ireg
, &oreg
);
267 #endif /* CONFIG_FIRMWARE_EDID */
270 #endif /* not _WAKEUP */
272 static __videocard video_vesa
=
276 .set_mode
= vesa_set_mode
,
277 .xmode_first
= VIDEO_FIRST_VESA
,