xref: /freebsd/sys/i386/include/pc/bios.h (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1 /*-
2  * Copyright (c) 1997 Michael Smith
3  * Copyright (c) 1998 Jonathan Lemon
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef _MACHINE_PC_BIOS_H_
31 #define _MACHINE_PC_BIOS_H_
32 
33 /*
34  * Signature structure for the BIOS32 Service Directory header
35  */
36 struct bios32_SDheader
37 {
38     u_int8_t	sig[4];
39     u_int32_t	entry;
40     u_int8_t	revision;
41     u_int8_t	len;
42     u_int8_t	cksum;
43     u_int8_t	pad[5];
44 };
45 
46 /*
47  * PnP BIOS presence structure
48  */
49 struct PnPBIOS_table
50 {
51     u_int8_t	sig[4];			/* "$PnP */
52     u_int8_t	version;		/* should be 0x10 */
53     u_int8_t	len;    		/* total structure length */
54     u_int16_t	control;		/* BIOS feature flags */
55     u_int8_t	cksum;			/* checksum */
56     u_int32_t	evflagaddr;		/* address of event notificaton flag */
57     u_int16_t	rmentryoffset;		/* real-mode entry offset */
58     u_int16_t	rmentryseg;		/*                 segment */
59     u_int16_t	pmentryoffset;		/* protected-mode entry offset */
60     u_int32_t	pmentrybase;		/*                segment base */
61     u_int32_t	oemdevid;		/* motherboard EISA ID */
62     u_int16_t	rmbiosseg;		/* real-mode BIOS segment */
63     u_int32_t	pmdataseg;		/* protected-mode data segment */
64 } __packed;
65 
66 /*
67  * PnP BIOS return codes
68  */
69 #define PNP_SUCCESS				0x00
70 #define PNP_NOT_SET_STATICALLY			0x7f
71 #define PNP_UNKNOWN_FUNCTION			0x81
72 #define PNP_FUNCTION_NOT_SUPPORTED		0x82
73 #define PNP_INVALID_HANDLE			0x83
74 #define PNP_BAD_PARAMETER			0x84
75 #define PNP_SET_FAILED				0x85
76 #define PNP_EVENTS_NOT_PENDING			0x86
77 #define PNP_SYSTEM_NOT_DOCKED			0x87
78 #define PNP_NO_ISA_PNP_CARDS			0x88
79 #define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
80 #define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY	0x8a
81 #define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
82 #define PNP_BUFFER_TOO_SMALL			0x8c
83 #define PNP_USE_ESCD_SUPPORT			0x8d
84 #define PNP_MESSAGE_NOT_SUPPORTED		0x8e
85 #define PNP_HARDWARE_ERROR			0x8f
86 
87 /*
88  * DMI return codes
89  */
90 #define DMI_SUCCESS				0x00
91 #define DMI_UNKNOWN_FUNCTION			0x81
92 #define DMI_FUNCTION_NOT_SUPPORTED		0x82
93 #define DMI_INVALID_HANDLE			0x83
94 #define DMI_BAD_PARAMETER			0x84
95 #define DMI_INVALID_SUBFUNCTION			0x85
96 #define DMI_NO_CHANGE				0x86
97 #define DMI_ADD_STRUCTURE_FAILED		0x87
98 #define DMI_READ_ONLY				0x8d
99 #define DMI_LOCK_NOT_SUPPORTED			0x90
100 #define DMI_CURRENTLY_LOCKED			0x91
101 #define DMI_INVALID_LOCK			0x92
102 
103 /*
104  * format specifiers and defines for bios16()
105  *     s	= short (16 bits)
106  *     i	= int (32 bits)
107  *     p	= pointer (converted to seg:offset)
108  *     C,D,U 	= selector (corresponding to code/data/utility segment)
109  */
110 #define PNP_COUNT_DEVNODES	"sppD",		0x00
111 #define PNP_GET_DEVNODE		"sppsD",	0x01
112 #define PNP_SET_DEVNODE		"sspsD",	0x02
113 #define PNP_GET_EVENT		"spD",		0x03
114 #define PNP_SEND_MSG		"ssD",		0x04
115 #define PNP_GET_DOCK_INFO	"spD",		0x05
116 
117 #define PNP_SEL_PRIBOOT		"ssiiisspD",	0x07
118 #define PNP_GET_PRIBOOT		"sspppppD",	0x08
119 #define PNP_SET_RESINFO		"spD",		0x09
120 #define PNP_GET_RESINFO		"spD",		0x0A
121 #define PNP_GET_APM_ID		"sppD",		0x0B
122 
123 #define PNP_GET_ISA_INFO	"spD",		0x40
124 #define PNP_GET_ECSD_INFO	"spppD",	0x41
125 #define PNP_READ_ESCD		"spUD",		0x42
126 #define PNP_WRITE_ESCD		"spUD",		0x43
127 
128 #define PNP_GET_DMI_INFO	"spppppD",	0x50
129 #define PNP_GET_DMI_STRUCTURE	"sppUD",	0x51
130 #define PNP_SET_DMI_STRUCTURE	"sppsUD"	0x52
131 #define PNP_GET_DMI_CHANGE	"spUD"		0x53
132 #define PNP_DMI_CONTROL		"sspsUD"	0x54
133 #define PNP_GET_GPNV_INFO	"sppppD"	0x55
134 #define PNP_READ_GPNV_DATA	"ssppUD"	0x56
135 #define PNP_WRITE_GPNV_DATA	"sspsUD"	0x57
136 
137 #define PNP_BOOT_CHECK		"sp",		0x60
138 #define PNP_COUNT_IPL		"sppp",		0x61
139 #define PNP_GET_BOOTPRI		"spp",		0x62
140 #define PNP_SET_BOOTPRI		"sp",		0x63
141 #define PNP_GET_LASTBOOT	"sp",		0x64
142 #define PNP_GET_BOOTFIRST	"sp",		0x65
143 #define PNP_SET_BOOTFIRST	"sp",		0x66
144 
145 /*
146  * PCI BIOS functions
147  */
148 #define PCIBIOS_BIOS_PRESENT		0xb101
149 #define PCIBIOS_READ_CONFIG_BYTE	0xb108
150 #define PCIBIOS_READ_CONFIG_WORD	0xb109
151 #define PCIBIOS_READ_CONFIG_DWORD	0xb10a
152 #define PCIBIOS_WRITE_CONFIG_BYTE	0xb10b
153 #define PCIBIOS_WRITE_CONFIG_WORD	0xb10c
154 #define PCIBIOS_WRITE_CONFIG_DWORD	0xb10d
155 #define PCIBIOS_GET_IRQ_ROUTING		0xb10e
156 #define PCIBIOS_ROUTE_INTERRUPT		0xb10f
157 
158 /*
159  * PCI interrupt routing table.
160  *
161  * $PIR in the BIOS segment contains a PIR_table
162  * int 1a:b106 returns PIR_table in buffer at es:(e)di
163  * int 1a:b18e returns PIR_table in buffer at es:(e)di
164  * int 1a:b406 returns es:di pointing to the BIOS PIR_table
165  */
166 struct PIR_header
167 {
168     int8_t	ph_signature[4];
169     u_int16_t	ph_version;
170     u_int16_t	ph_length;
171     u_int8_t	ph_router_bus;
172     u_int8_t	ph_router_dev_fn;
173     u_int16_t	ph_pci_irqs;
174     u_int16_t	ph_router_vendor;
175     u_int16_t	ph_router_device;
176     u_int32_t	ph_miniport;
177     u_int8_t	ph_res[11];
178     u_int8_t	ph_checksum;
179 } __packed;
180 
181 struct PIR_intpin
182 {
183     u_int8_t	link;
184     u_int16_t	irqs;
185 } __packed;
186 
187 struct PIR_entry
188 {
189     u_int8_t		pe_bus;
190     u_int8_t		pe_res1:3;
191     u_int8_t		pe_device:5;
192     struct PIR_intpin	pe_intpin[4];
193     u_int8_t	pe_slot;
194     u_int8_t	pe_res3;
195 } __packed;
196 
197 struct PIR_table
198 {
199     struct PIR_header	pt_header;
200     struct PIR_entry	pt_entry[0];
201 } __packed;
202 
203 /*
204  * Int 15:E820 'SMAP' structure
205  */
206 #define SMAP_SIG	0x534D4150			/* 'SMAP' */
207 
208 #define	SMAP_TYPE_MEMORY	1
209 #define	SMAP_TYPE_RESERVED	2
210 #define	SMAP_TYPE_ACPI_RECLAIM	3
211 #define	SMAP_TYPE_ACPI_NVS	4
212 #define	SMAP_TYPE_ACPI_ERROR	5
213 #define	SMAP_TYPE_DISABLED	6
214 #define	SMAP_TYPE_PMEM		7
215 #define	SMAP_TYPE_PRAM		12
216 
217 #define	SMAP_XATTR_ENABLED	0x00000001
218 #define	SMAP_XATTR_NON_VOLATILE	0x00000002
219 #define	SMAP_XATTR_MASK		(SMAP_XATTR_ENABLED | SMAP_XATTR_NON_VOLATILE)
220 
221 struct bios_smap {
222     u_int64_t	base;
223     u_int64_t	length;
224     u_int32_t	type;
225 } __packed;
226 
227 /* Structure extended to include extended attribute field in ACPI 3.0. */
228 struct bios_smap_xattr {
229     u_int64_t	base;
230     u_int64_t	length;
231     u_int32_t	type;
232     u_int32_t	xattr;
233 } __packed;
234 
235 /*
236  * System Management BIOS
237  */
238 #define	SMBIOS_START	0xf0000
239 #define	SMBIOS_STEP	0x10
240 #define	SMBIOS_OFF	0
241 #define	SMBIOS_LEN	4
242 #define	SMBIOS_SIG	"_SM_"
243 
244 struct smbios_eps {
245 	uint8_t		anchor_string[4];		/* '_SM_' */
246 	uint8_t		checksum;
247 	uint8_t		length;
248 	uint8_t		major_version;
249 	uint8_t		minor_version;
250 	uint16_t	maximum_structure_size;
251 	uint8_t		entry_point_revision;
252 	uint8_t		formatted_area[5];
253 	uint8_t		intermediate_anchor_string[5];	/* '_DMI_' */
254 	uint8_t		intermediate_checksum;
255 	uint16_t	structure_table_length;
256 	uint32_t	structure_table_address;
257 	uint16_t	number_structures;
258 	uint8_t		BCD_revision;
259 };
260 
261 struct smbios_structure_header {
262 	uint8_t		type;
263 	uint8_t		length;
264 	uint16_t	handle;
265 };
266 
267 #ifdef _KERNEL
268 #define BIOS_PADDRTOVADDR(x)	((x) + KERNBASE)
269 #define BIOS_VADDRTOPADDR(x)	((x) - KERNBASE)
270 
271 struct bios_oem_signature {
272 	char * anchor;		/* search anchor string in BIOS memory */
273 	size_t offset;		/* offset from anchor (may be negative) */
274 	size_t totlen;		/* total length of BIOS string to copy */
275 } __packed;
276 
277 struct bios_oem_range {
278 	u_int from;		/* shouldn't be below 0xe0000 */
279 	u_int to;		/* shouldn't be above 0xfffff */
280 } __packed;
281 
282 struct bios_oem {
283 	struct bios_oem_range range;
284 	struct bios_oem_signature signature[];
285 } __packed;
286 
287 struct segment_info {
288 	u_int	base;
289 	u_int	limit;
290 };
291 
292 #define BIOSCODE_FLAG	0x01
293 #define BIOSDATA_FLAG	0x02
294 #define BIOSUTIL_FLAG	0x04
295 #define BIOSARGS_FLAG	0x08
296 
297 struct bios_segments {
298 	struct	segment_info code32;		/* 32-bit code (mandatory) */
299 	struct	segment_info code16;		/* 16-bit code */
300 	struct	segment_info data;		/* 16-bit data */
301 	struct	segment_info util;		/* 16-bit utility */
302 	struct	segment_info args;		/* 16-bit args */
303 };
304 
305 struct bios_regs {
306 	u_int	eax;
307 	u_int	ebx;
308 	u_int	ecx;
309 	u_int	edx;
310 	u_int	esi;
311 	u_int	edi;
312 };
313 
314 struct bios_args {
315 	u_int	entry;				/* entry point of routine */
316 	struct	bios_regs r;
317 	struct	bios_segments seg;
318 };
319 
320 /*
321  * BIOS32 Service Directory entry.  Caller supplies name, bios32_SDlookup
322  * fills in the rest of the details.
323  */
324 struct bios32_SDentry
325 {
326     union
327     {
328 	u_int8_t	name[4];	/* service identifier */
329 	u_int32_t	id;		/* as a 32-bit value */
330     } ident;
331     u_int32_t	base;			/* base of service */
332     u_int32_t	len;			/* service length */
333     u_int32_t	entry;			/* entrypoint offset from base */
334     vm_offset_t	ventry;			/* entrypoint in kernel virtual segment */
335 };
336 
337 /*
338  * Exported lookup results
339  */
340 extern struct bios32_SDentry	PCIbios;
341 
342 int	bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen);
343 uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen,
344 	    int sigofs);
345 int	bios16(struct bios_args *, char *, ...);
346 int	bios16_call(struct bios_regs *, char *);
347 int	bios32(struct bios_regs *, u_int, u_short);
348 int	bios32_SDlookup(struct bios32_SDentry *ent);
349 void	set_bios_selectors(struct bios_segments *, int);
350 
351 #endif
352 
353 #endif /* _MACHINE_PC_BIOS_H_ */
354