bios.h revision 130040
1160814Ssimon/*-
2160814Ssimon * Copyright (c) 1997 Michael Smith
3160814Ssimon * Copyright (c) 1998 Jonathan Lemon
4160814Ssimon * All rights reserved.
5160814Ssimon *
6160814Ssimon * Redistribution and use in source and binary forms, with or without
7160814Ssimon * modification, are permitted provided that the following conditions
8160814Ssimon * are met:
9160814Ssimon * 1. Redistributions of source code must retain the above copyright
10160814Ssimon *    notice, this list of conditions and the following disclaimer.
11160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright
12160814Ssimon *    notice, this list of conditions and the following disclaimer in the
13160814Ssimon *    documentation and/or other materials provided with the distribution.
14160814Ssimon *
15160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16160814Ssimon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18160814Ssimon * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19160814Ssimon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20160814Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21160814Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23160814Ssimon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24160814Ssimon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25160814Ssimon * SUCH DAMAGE.
26160814Ssimon *
27160814Ssimon * $FreeBSD: head/sys/i386/include/pc/bios.h 130040 2004-06-03 22:36:24Z phk $
28160814Ssimon */
29160814Ssimon
30160814Ssimon#ifndef _MACHINE_PC_BIOS_H_
31160814Ssimon#define _MACHINE_PC_BIOS_H_
32160814Ssimon
33160814Ssimon/*
34160814Ssimon * Signature structure for the BIOS32 Service Directory header
35160814Ssimon */
36160814Ssimonstruct bios32_SDheader
37160814Ssimon{
38160814Ssimon    u_int8_t	sig[4];
39160814Ssimon    u_int32_t	entry;
40160814Ssimon    u_int8_t	revision;
41160814Ssimon    u_int8_t	len;
42160814Ssimon    u_int8_t	cksum;
43160814Ssimon    u_int8_t	pad[5];
44160814Ssimon};
45160814Ssimon
46160814Ssimon/*
47160814Ssimon * BIOS32 Service Directory entry.  Caller supplies name, bios32_SDlookup
48160814Ssimon * fills in the rest of the details.
49160814Ssimon */
50160814Ssimonstruct bios32_SDentry
51160814Ssimon{
52160814Ssimon    union
53160814Ssimon    {
54160814Ssimon	u_int8_t	name[4];	/* service identifier */
55160814Ssimon	u_int32_t	id;		/* as a 32-bit value */
56160814Ssimon    } ident;
57160814Ssimon    u_int32_t	base;			/* base of service */
58160814Ssimon    u_int32_t	len;			/* service length */
59160814Ssimon    u_int32_t	entry;			/* entrypoint offset from base */
60160814Ssimon    vm_offset_t	ventry;			/* entrypoint in kernel virtual segment */
61160814Ssimon};
62160814Ssimon
63160814Ssimonextern int		bios32_SDlookup(struct bios32_SDentry *ent);
64160814Ssimonextern u_int32_t	bios_sigsearch(u_int32_t start, u_char *sig, int siglen,
65160814Ssimon					 int paralen, int sigofs);
66160814Ssimon
67160814Ssimon#define BIOS_PADDRTOVADDR(x)	(((x) - ISA_HOLE_START) + atdevbase)
68160814Ssimon#define BIOS_VADDRTOPADDR(x)	(((x) - atdevbase) + ISA_HOLE_START)
69160814Ssimon
70160814Ssimon
71160814Ssimon/*
72160814Ssimon * PnP BIOS presence structure
73160814Ssimon */
74160814Ssimonstruct PnPBIOS_table
75160814Ssimon{
76160814Ssimon    u_int8_t	sig[4];			/* "$PnP */
77160814Ssimon    u_int8_t	version;		/* should be 0x10 */
78160814Ssimon    u_int8_t	len;    		/* total structure length */
79160814Ssimon    u_int16_t	control;		/* BIOS feature flags */
80160814Ssimon    u_int8_t	cksum;			/* checksum */
81160814Ssimon    u_int32_t	evflagaddr;		/* address of event notificaton flag */
82160814Ssimon    u_int16_t	rmentryoffset;		/* real-mode entry offset */
83160814Ssimon    u_int16_t	rmentryseg;		/*                 segment */
84160814Ssimon    u_int16_t	pmentryoffset;		/* protected-mode entry offset */
85160814Ssimon    u_int32_t	pmentrybase;		/*                segment base */
86160814Ssimon    u_int32_t	oemdevid;		/* motherboard EISA ID */
87160814Ssimon    u_int16_t	rmbiosseg;		/* real-mode BIOS segment */
88160814Ssimon    u_int32_t	pmdataseg;		/* protected-mode data segment */
89160814Ssimon} __packed;
90160814Ssimon
91160814Ssimon
92160814Ssimon/*
93160814Ssimon * Exported lookup results
94160814Ssimon */
95160814Ssimonextern struct bios32_SDentry	PCIbios;
96160814Ssimonextern struct PnPBIOS_table	*PnPBIOStable;
97160814Ssimon
98160814Ssimonstruct segment_info {
99160814Ssimon	u_int	base;
100160814Ssimon	u_int	limit;
101160814Ssimon};
102160814Ssimon
103160814Ssimon#define BIOSCODE_FLAG	0x01
104160814Ssimon#define BIOSDATA_FLAG	0x02
105160814Ssimon#define BIOSUTIL_FLAG	0x04
106160814Ssimon#define BIOSARGS_FLAG	0x08
107160814Ssimon
108160814Ssimonstruct bios_segments {
109160814Ssimon	struct	segment_info code32;		/* 32-bit code (mandatory) */
110160814Ssimon	struct	segment_info code16;		/* 16-bit code */
111160814Ssimon	struct	segment_info data;		/* 16-bit data */
112160814Ssimon	struct	segment_info util;		/* 16-bit utility */
113160814Ssimon	struct	segment_info args;		/* 16-bit args */
114160814Ssimon};
115160814Ssimon
116160814Ssimonstruct bios_regs {
117160814Ssimon	u_int	eax;
118160814Ssimon	u_int	ebx;
119160814Ssimon	u_int	ecx;
120160814Ssimon	u_int	edx;
121160814Ssimon	u_int	esi;
122160814Ssimon	u_int	edi;
123160814Ssimon};
124160814Ssimon
125160814Ssimonstruct bios_args {
126160814Ssimon	u_int	entry;				/* entry point of routine */
127160814Ssimon	struct	bios_regs r;
128160814Ssimon	struct	bios_segments seg;
129160814Ssimon};
130160814Ssimon
131160814Ssimon/*
132160814Ssimon * PnP BIOS return codes
133160814Ssimon */
134160814Ssimon#define PNP_SUCCESS				0x00
135160814Ssimon#define PNP_NOT_SET_STATICALLY			0x7f
136160814Ssimon#define PNP_UNKNOWN_FUNCTION			0x81
137160814Ssimon#define PNP_FUNTION_NOT_SUPPORTED		0x82
138160814Ssimon#define PNP_INVALID_HANDLE			0x83
139160814Ssimon#define PNP_BAD_PARAMETER			0x84
140160814Ssimon#define PNP_SET_FAILED				0x85
141160814Ssimon#define PNP_EVENTS_NOT_PENDING			0x86
142160814Ssimon#define PNP_SYSTEM_NOT_DOCKED			0x87
143160814Ssimon#define PNP_NO_ISA_PNP_CARDS			0x88
144160814Ssimon#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
145160814Ssimon#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY	0x8a
146160814Ssimon#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
147#define PNP_BUFFER_TOO_SMALL			0x8c
148#define PNP_USE_ESCD_SUPPORT			0x8d
149#define PNP_MESSAGE_NOT_SUPPORTED		0x8e
150#define PNP_HARDWARE_ERROR			0x8f
151
152/*
153 * DMI return codes
154 */
155#define DMI_SUCCESS				0x00
156#define DMI_UNKNOWN_FUNCTION			0x81
157#define DMI_FUNCTION_NOT_SUPPORTED		0x82
158#define DMI_INVALID_HANDLE			0x83
159#define DMI_BAD_PARAMETER			0x84
160#define DMI_INVALID_SUBFUNCTION			0x85
161#define DMI_NO_CHANGE				0x86
162#define DMI_ADD_STRUCTURE_FAILED		0x87
163#define DMI_READ_ONLY				0x8d
164#define DMI_LOCK_NOT_SUPPORTED			0x90
165#define DMI_CURRENTLY_LOCKED			0x91
166#define DMI_INVALID_LOCK			0x92
167
168/*
169 * format specifiers and defines for bios16()
170 *     s	= short (16 bits)
171 *     i	= int (32 bits)
172 *     p	= pointer (converted to seg:offset)
173 *     C,D,U 	= selector (corresponding to code/data/utility segment)
174 */
175#define PNP_COUNT_DEVNODES	"sppD",		0x00
176#define PNP_GET_DEVNODE		"sppsD",	0x01
177#define PNP_SET_DEVNODE		"sspsD",	0x02
178#define PNP_GET_EVENT		"spD",		0x03
179#define PNP_SEND_MSG		"ssD",		0x04
180#define PNP_GET_DOCK_INFO	"spD",		0x05
181
182#define PNP_SEL_PRIBOOT		"ssiiisspD",	0x07
183#define PNP_GET_PRIBOOT		"sspppppD",	0x08
184#define PNP_SET_RESINFO		"spD",		0x09
185#define PNP_GET_RESINFO		"spD",		0x0A
186#define PNP_GET_APM_ID		"sppD",		0x0B
187
188#define PNP_GET_ISA_INFO	"spD",		0x40
189#define PNP_GET_ECSD_INFO	"spppD",	0x41
190#define PNP_READ_ESCD		"spUD",		0x42
191#define PNP_WRITE_ESCD		"spUD",		0x43
192
193#define PNP_GET_DMI_INFO	"spppppD",	0x50
194#define PNP_GET_DMI_STRUCTURE	"sppUD",	0x51
195#define PNP_SET_DMI_STRUCTURE	"sppsUD"	0x52
196#define PNP_GET_DMI_CHANGE	"spUD"		0x53
197#define PNP_DMI_CONTROL		"sspsUD"	0x54
198#define PNP_GET_GPNV_INFO	"sppppD"	0x55
199#define PNP_READ_GPNV_DATA	"ssppUD"	0x56
200#define PNP_WRITE_GPNV_DATA	"sspsUD"	0x57
201
202#define PNP_BOOT_CHECK		"sp",		0x60
203#define PNP_COUNT_IPL		"sppp",		0x61
204#define PNP_GET_BOOTPRI		"spp",		0x62
205#define PNP_SET_BOOTPRI		"sp",		0x63
206#define PNP_GET_LASTBOOT	"sp",		0x64
207#define PNP_GET_BOOTFIRST	"sp",		0x65
208#define PNP_SET_BOOTFIRST	"sp",		0x66
209
210/*
211 * PCI BIOS functions
212 */
213#define PCIBIOS_BIOS_PRESENT		0xb101
214#define PCIBIOS_READ_CONFIG_BYTE	0xb108
215#define PCIBIOS_READ_CONFIG_WORD	0xb109
216#define PCIBIOS_READ_CONFIG_DWORD	0xb10a
217#define PCIBIOS_WRITE_CONFIG_BYTE	0xb10b
218#define PCIBIOS_WRITE_CONFIG_WORD	0xb10c
219#define PCIBIOS_WRITE_CONFIG_DWORD	0xb10d
220#define PCIBIOS_GET_IRQ_ROUTING		0xb10e
221#define PCIBIOS_ROUTE_INTERRUPT		0xb10f
222
223extern int bios16(struct bios_args *, char *, ...);
224extern int bios16_call(struct bios_regs *, char *);
225extern int bios32(struct bios_regs *, u_int, u_short);
226extern void set_bios_selectors(struct bios_segments *, int);
227
228/*
229 * PCI interrupt routing table.
230 *
231 * $PIR in the BIOS segment contains a PIR_table
232 * int 1a:b106 returns PIR_table in buffer at es:(e)di
233 * int 1a:b18e returns PIR_table in buffer at es:(e)di
234 * int 1a:b406 returns es:di pointing to the BIOS PIR_table
235 */
236struct PIR_header
237{
238    int8_t	ph_signature[4];
239    u_int16_t	ph_version;
240    u_int16_t	ph_length;
241    u_int8_t	ph_router_bus;
242    u_int8_t	ph_router_dev_fn;
243    u_int16_t	ph_pci_irqs;
244    u_int16_t	ph_router_vendor;
245    u_int16_t	ph_router_device;
246    u_int32_t	ph_miniport;
247    u_int8_t	ph_res[11];
248    u_int8_t	ph_checksum;
249} __packed;
250
251struct PIR_intpin
252{
253    u_int8_t	link;
254    u_int16_t	irqs;
255} __packed;
256
257struct PIR_entry
258{
259    u_int8_t		pe_bus;
260    u_int8_t		pe_res1:3;
261    u_int8_t		pe_device:5;
262    struct PIR_intpin	pe_intpin[4];
263    u_int8_t	pe_slot;
264    u_int8_t	pe_res3;
265} __packed;
266
267struct PIR_table
268{
269    struct PIR_header	pt_header;
270    struct PIR_entry	pt_entry[0];
271} __packed;
272
273/*
274 * Int 15:E820 'SMAP' structure
275 *
276 * XXX add constants for type
277 */
278#define SMAP_SIG	0x534D4150			/* 'SMAP' */
279struct bios_smap {
280    u_int64_t	base;
281    u_int64_t	length;
282    u_int32_t	type;
283} __packed;
284
285const u_char *bios_string(u_int from, u_int to, const u_char *string, int len);
286
287
288#endif /* _MACHINE_PC_BIOS_H_ */
289