xref: /freebsd/stand/i386/libi386/vbe.h (revision a18b956b73cee784e5c422d20fd0e4dabebd7eee)
1 /*-
2  * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
15  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
18  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 /*
28  * Default mode for VESA frame buffer.
29  * This mode is selected when there is no EDID inormation and
30  * mode is not provided by user.
31  * To provide consistent look with UEFI GOP, we use 800x600 here,
32  * and if this mode is not available, we fall back to text mode and
33  * VESA disabled.
34  */
35 
36 #define VBE_DEFAULT_MODE	"800x600"
37 
38 struct vbeinfoblock {
39 	char VbeSignature[4];
40 	uint16_t VbeVersion;
41 	uint32_t OemStringPtr;
42 	uint32_t Capabilities;
43 #define	VBE_CAP_DAC8	(1 << 0)	/* Can switch DAC */
44 #define	VBE_CAP_NONVGA	(1 << 1)	/* Controller is not VGA comp. */
45 #define	VBE_CAP_SNOW	(1 << 2)	/* Set data during Vertical Reterace */
46 	uint32_t VideoModePtr;
47 	uint16_t TotalMemory;
48 	uint16_t OemSoftwareRev;
49 	uint32_t OemVendorNamePtr, OemProductNamePtr, OemProductRevPtr;
50 	/* data area, in total max 512 bytes for VBE 2.0 */
51 	uint8_t Reserved[222];
52 	uint8_t OemData[256];
53 } __packed;
54 
55 struct modeinfoblock {
56 	/* Mandatory information for all VBE revisions */
57 	uint16_t ModeAttributes;
58 	uint8_t WinAAttributes, WinBAttributes;
59 	uint16_t WinGranularity, WinSize, WinASegment, WinBSegment;
60 	uint32_t WinFuncPtr;
61 	uint16_t BytesPerScanLine;
62 	/* Mandatory information for VBE 1.2 and above */
63 	uint16_t XResolution, YResolution;
64 	uint8_t XCharSize, YCharSize, NumberOfPlanes, BitsPerPixel;
65 	uint8_t NumberOfBanks, MemoryModel, BankSize, NumberOfImagePages;
66 	uint8_t Reserved1;
67 	/* Direct Color fields
68 	   (required for direct/6 and YUV/7 memory models) */
69 	uint8_t RedMaskSize, RedFieldPosition;
70 	uint8_t GreenMaskSize, GreenFieldPosition;
71 	uint8_t BlueMaskSize, BlueFieldPosition;
72 	uint8_t RsvdMaskSize, RsvdFieldPosition;
73 	uint8_t DirectColorModeInfo;
74 	/* Mandatory information for VBE 2.0 and above */
75 	uint32_t PhysBasePtr;
76 	uint32_t OffScreenMemOffset;	/* reserved in VBE 3.0 and above */
77 	uint16_t OffScreenMemSize;	/* reserved in VBE 3.0 and above */
78 
79 	/* Mandatory information for VBE 3.0 and above */
80 	uint16_t LinBytesPerScanLine;
81 	uint8_t BnkNumberOfImagePages;
82 	uint8_t LinNumberOfImagePages;
83 	uint8_t LinRedMaskSize, LinRedFieldPosition;
84 	uint8_t LinGreenMaskSize, LinGreenFieldPosition;
85 	uint8_t LinBlueMaskSize, LinBlueFieldPosition;
86 	uint8_t LinRsvdMaskSize, LinRsvdFieldPosition;
87 	uint32_t MaxPixelClock;
88 	/* + 1 will fix the size to 256 bytes */
89 	uint8_t Reserved4[189 + 1];
90 } __packed;
91 
92 struct crtciinfoblock {
93 	uint16_t HorizontalTotal;
94 	uint16_t HorizontalSyncStart;
95 	uint16_t HorizontalSyncEnd;
96 	uint16_t VerticalTotal;
97 	uint16_t VerticalSyncStart;
98 	uint16_t VerticalSyncEnd;
99 	uint8_t Flags;
100 	uint32_t PixelClock;
101 	uint16_t RefreshRate;
102 	uint8_t Reserved[40];
103 } __packed;
104 
105 struct paletteentry {
106 	uint8_t Blue;
107 	uint8_t Green;
108 	uint8_t Red;
109 	uint8_t Reserved;
110 } __packed;
111 
112 struct flatpanelinfo
113 {
114 	uint16_t HorizontalSize;
115 	uint16_t VerticalSize;
116 	uint16_t PanelType;
117 	uint8_t RedBPP;
118 	uint8_t GreenBPP;
119 	uint8_t BlueBPP;
120 	uint8_t ReservedBPP;
121 	uint32_t ReservedOffScreenMemSize;
122 	uint32_t ReservedOffScreenMemPtr;
123 
124 	uint8_t Reserved[14];
125 } __packed;
126 
127 #define	VBE_BASE_MODE		(0x100)		/* VBE 3.0 page 18 */
128 #define	VBE_VALID_MODE(a)	((a) >= VBE_BASE_MODE)
129 #define	VBE_ERROR(a)		(((a) & 0xFF) != 0x4F || ((a) & 0xFF00) != 0)
130 #define	VBE_SUCCESS		(0x004F)
131 #define	VBE_FAILED		(0x014F)
132 #define	VBE_NOTSUP		(0x024F)
133 #define	VBE_INVALID		(0x034F)
134 
135 #define	VGA_TEXT_MODE		(3)		/* 80x25 text mode */
136 #define	TEXT_ROWS		(25)		/* VGATEXT rows */
137 #define	TEXT_COLS		(80)		/* VGATEXT columns */
138 
139 extern struct paletteentry *pe8;
140 extern int palette_format;
141 
142 int vga_get_reg(int, int);
143 int vga_get_atr(int, int);
144 void vga_set_atr(int, int, int);
145 void vga_set_indexed(int, int, int, uint8_t, uint8_t);
146 int vga_get_indexed(int, int, int, uint8_t);
147 int vga_get_crtc(int, int);
148 void vga_set_crtc(int, int, int);
149 int vga_get_seq(int, int);
150 void vga_set_seq(int, int, int);
151 int vga_get_grc(int, int);
152 void vga_set_grc(int, int, int);
153 
154 /* high-level VBE helpers, from vbe.c */
155 bool vbe_is_vga(void);
156 void bios_set_text_mode(int);
157 int biosvbe_palette_format(int *);
158 void vbe_init(void);
159 bool vbe_available(void);
160 int vbe_default_mode(void);
161 int vbe_set_mode(int);
162 int vbe_get_mode(void);
163 int vbe_set_palette(const struct paletteentry *, size_t);
164 void vbe_modelist(int);
165