xref: /illumos-gate/usr/src/boot/i386/libi386/vbe.h (revision 22028508fd28d36ff74dc02c5774a8ba1f0db045)
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 #ifndef _VBE_H
37 #define	_VBE_H
38 
39 #define	VBE_DEFAULT_MODE	"800x600"
40 
41 struct vbeinfoblock {
42 	char VbeSignature[4];
43 	uint16_t VbeVersion;
44 	uint32_t OemStringPtr;
45 	uint32_t Capabilities;
46 #define	VBE_CAP_DAC8	(1 << 0)	/* Can switch DAC */
47 #define	VBE_CAP_NONVGA	(1 << 1)	/* Controller is not VGA comp. */
48 #define	VBE_CAP_SNOW	(1 << 2)	/* Set data during Vertical Reterace */
49 	uint32_t VideoModePtr;
50 	uint16_t TotalMemory;
51 	uint16_t OemSoftwareRev;
52 	uint32_t OemVendorNamePtr, OemProductNamePtr, OemProductRevPtr;
53 	/* data area, in total max 512 bytes for VBE 2.0 */
54 	uint8_t Reserved[222];
55 	uint8_t OemData[256];
56 } __packed;
57 
58 struct modeinfoblock {
59 	/* Mandatory information for all VBE revisions */
60 	uint16_t ModeAttributes;
61 	uint8_t WinAAttributes, WinBAttributes;
62 	uint16_t WinGranularity, WinSize, WinASegment, WinBSegment;
63 	uint32_t WinFuncPtr;
64 	uint16_t BytesPerScanLine;
65 	/* Mandatory information for VBE 1.2 and above */
66 	uint16_t XResolution, YResolution;
67 	uint8_t XCharSize, YCharSize, NumberOfPlanes, BitsPerPixel;
68 	uint8_t NumberOfBanks, MemoryModel, BankSize, NumberOfImagePages;
69 	uint8_t Reserved1;
70 	/*
71 	 * Direct Color fields
72 	 * (required for direct/6 and YUV/7 memory models)
73 	 */
74 	uint8_t RedMaskSize, RedFieldPosition;
75 	uint8_t GreenMaskSize, GreenFieldPosition;
76 	uint8_t BlueMaskSize, BlueFieldPosition;
77 	uint8_t RsvdMaskSize, RsvdFieldPosition;
78 	uint8_t DirectColorModeInfo;
79 	/* Mandatory information for VBE 2.0 and above */
80 	uint32_t PhysBasePtr;
81 	uint32_t OffScreenMemOffset;	/* reserved in VBE 3.0 and above */
82 	uint16_t OffScreenMemSize;	/* reserved in VBE 3.0 and above */
83 
84 	/* Mandatory information for VBE 3.0 and above */
85 	uint16_t LinBytesPerScanLine;
86 	uint8_t BnkNumberOfImagePages;
87 	uint8_t LinNumberOfImagePages;
88 	uint8_t LinRedMaskSize, LinRedFieldPosition;
89 	uint8_t LinGreenMaskSize, LinGreenFieldPosition;
90 	uint8_t LinBlueMaskSize, LinBlueFieldPosition;
91 	uint8_t LinRsvdMaskSize, LinRsvdFieldPosition;
92 	uint32_t MaxPixelClock;
93 	/* + 1 will fix the size to 256 bytes */
94 	uint8_t Reserved4[189 + 1];
95 } __packed;
96 
97 struct crtciinfoblock {
98 	uint16_t HorizontalTotal;
99 	uint16_t HorizontalSyncStart;
100 	uint16_t HorizontalSyncEnd;
101 	uint16_t VerticalTotal;
102 	uint16_t VerticalSyncStart;
103 	uint16_t VerticalSyncEnd;
104 	uint8_t Flags;
105 	uint32_t PixelClock;
106 	uint16_t RefreshRate;
107 	uint8_t Reserved[40];
108 } __packed;
109 
110 struct paletteentry {
111 	uint8_t Blue;
112 	uint8_t Green;
113 	uint8_t Red;
114 	uint8_t Reserved;
115 } __packed;
116 
117 struct flatpanelinfo
118 {
119 	uint16_t HorizontalSize;	/* Horizontal Size in Pixels */
120 	uint16_t VerticalSize;		/* Vertical Size in Lines */
121 	uint16_t PanelType;		/* Flat Panel Type */
122 	uint8_t RedBPP;			/* Red Bits Per Primary */
123 	uint8_t GreenBPP;		/* Green Bits Per Primary */
124 	uint8_t BlueBPP;		/* Blue Bits Per Primary */
125 	uint8_t ReservedBPP;		/* Reserved Bits Per Primary */
126 	uint32_t RsvdOffScreenMemSize;	/* Size in KB of Offscreen Memory */
127 	uint32_t RsvdOffScreenMemPtr; /* Pointer to reserved offscreen memory */
128 	uint8_t Reserved[14];		/* remainder of FPInfo */
129 } __packed;
130 
131 #define	VBE_BASE_MODE		(0x100)		/* VBE 3.0 page 18 */
132 #define	VBE_VALID_MODE(a)	((a) >= VBE_BASE_MODE)
133 #define	VBE_ERROR(a)		(((a) & 0xFF) != 0x4F || ((a) & 0xFF00) != 0)
134 #define	VBE_SUCCESS		(0x004F)
135 #define	VBE_FAILED		(0x014F)
136 #define	VBE_NOTSUP		(0x024F)
137 #define	VBE_INVALID		(0x034F)
138 
139 #define	VGA_TEXT_MODE		(3)		/* 80x25 text mode */
140 #define	TEXT_ROWS		(25)		/* VGATEXT rows */
141 #define	TEXT_COLS		(80)		/* VGATEXT columns */
142 
143 #define	CMAP_SIZE		256	/* Number of colors in palette */
144 
145 extern struct paletteentry pe8[CMAP_SIZE];
146 extern int palette_format;
147 
148 /* high-level VBE helpers, from vbe.c */
149 void bios_set_text_mode(int);
150 int biosvbe_palette_format(int *);
151 void vbe_init(void);
152 int vbe_available(void);
153 int vbe_default_mode(void);
154 int vbe_set_mode(int);
155 int vbe_get_mode(void);
156 int vbe_set_palette(const struct paletteentry *, size_t);
157 void vbe_modelist(int);
158 
159 #endif /* _VBE_H */
160