bios.h revision 49953
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 *      $Id: bios.h,v 1.3 1999/07/29 01:49:19 msmith Exp $
28 */
29
30/*
31 * Signature structure for the BIOS32 Service Directory header
32 */
33struct bios32_SDheader
34{
35    u_int8_t	sig[4];
36    u_int32_t	entry;
37    u_int8_t	revision;
38    u_int8_t	len;
39    u_int8_t	cksum;
40    u_int8_t	pad[5];
41};
42
43/*
44 * BIOS32 Service Directory entry.  Caller supplies name, bios32_SDlookup
45 * fills in the rest of the details.
46 */
47struct bios32_SDentry
48{
49    union
50    {
51	u_int8_t	name[4];	/* service identifier */
52	u_int32_t	id;		/* as a 32-bit value */
53    } ident;
54    u_int32_t	base;			/* base of service */
55    u_int32_t	len;			/* service length */
56    u_int32_t	entry;			/* entrypoint offset from base */
57};
58
59extern int		bios32_SDlookup(struct bios32_SDentry *ent);
60extern u_int32_t	bios_sigsearch(u_int32_t start, u_char *sig, int siglen,
61					 int paralen, int sigofs);
62
63#define BIOS_PADDRTOVADDR(x)	(((x) - ISA_HOLE_START) + atdevbase)
64#define BIOS_VADDRTOPADDR(x)	(((x) - atdevbase) + ISA_HOLE_START)
65
66
67/*
68 * System Management BIOS / Desktop Management Interface tables
69 */
70
71struct DMI_table
72{
73    u_int8_t	sig[5];			/* "_DMI_" */
74    u_int8_t	cksum;			/* checksum */
75    u_int16_t	st_size;		/* total length of SMBIOS table (bytes)*/
76    u_int32_t	st_base;		/* base address of the SMBIOS table (physical) */
77    u_int16_t	st_entries;		/* total number of structures present in the table */
78    u_int8_t	bcd_revision;		/* interface revision number */
79};
80
81struct SMBIOS_table
82{
83    u_int8_t	sig[4];			/* "_SM_" */
84    u_int8_t	cksum;			/* checksum */
85    u_int8_t	len;			/* structure length */
86    u_int8_t	major, minor;		/* major/minor revision numbers */
87    u_int16_t	st_maxsize;		/* largest structure size (bytes) */
88    u_int8_t	revision;		/* entrypoint revision */
89    u_int8_t	pad[5];
90    struct DMI_table dmi;		/* follows immediately */
91};
92
93
94/*
95 * PnP BIOS presence structure
96 */
97struct PnPBIOS_table
98{
99    u_int8_t	sig[4];			/* "$PnP */
100    u_int8_t	version;		/* should be 0x10 */
101    u_int8_t	len;    		/* total structure length */
102    u_int16_t	control;		/* BIOS feature flags */
103    u_int8_t	cksum;			/* checksum */
104    u_int32_t	evflagaddr;		/* address of event notificaton flag */
105    u_int16_t	rmentryoffset;		/* real-mode entry offset */
106    u_int16_t	rmentryseg;		/*                 segment */
107    u_int16_t	pmentryoffset;		/* protected-mode entry offset */
108    u_int32_t	pmentrybase;		/*                segment base */
109    u_int32_t	oemdevid;		/* motherboard EISA ID */
110    u_int16_t	rmbiosseg;		/* real-mode BIOS segment */
111    u_int32_t	pmdataseg;		/* protected-mode data segment */
112} __attribute__ ((packed));
113
114
115/*
116 * Exported lookup results
117 */
118extern struct bios32_SDentry	PCIbios;
119extern struct SMBIOS_table	*SMBIOStable;
120extern struct PnPBIOS_table	*PnPBIOStable;
121
122struct segment_info {
123	u_int	base;
124	u_int	limit;
125};
126
127#define BIOSCODE_FLAG	0x01
128#define BIOSDATA_FLAG	0x02
129#define BIOSUTIL_FLAG	0x04
130#define BIOSARGS_FLAG	0x08
131
132struct bios_segments {
133	u_int 	generation;
134	struct	segment_info code32;		/* 32-bit code (mandatory) */
135	struct	segment_info code16;		/* 16-bit code */
136	struct	segment_info data;		/* 16-bit data */
137	struct	segment_info util;		/* 16-bit utility */
138	struct	segment_info args;		/* 16-bit args */
139};
140
141struct bios_regs {
142	u_int	eax;
143	u_int	ebx;
144	u_int	ecx;
145	u_int	edx;
146	u_int	esi;
147	u_int	edi;
148};
149
150struct bios_args {
151	u_int	entry;				/* entry point of routine */
152	struct	bios_regs r;
153	struct	bios_segments seg;
154};
155
156/*
157 * PnP BIOS return codes
158 */
159#define PNP_SUCCESS				0x00
160#define PNP_NOT_SET_STATICALLY			0x7f
161#define PNP_UNKNOWN_FUNCTION			0x81
162#define PNP_FUNTION_NOT_SUPPORTED		0x82
163#define PNP_INVALID_HANDLE			0x83
164#define PNP_BAD_PARAMETER			0x84
165#define PNP_SET_FAILED				0x85
166#define PNP_EVENTS_NOT_PENDING			0x86
167#define PNP_SYSTEM_NOT_DOCKED			0x87
168#define PNP_NO_ISA_PNP_CARDS			0x88
169#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
170#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY	0x8a
171#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
172#define PNP_BUFFER_TOO_SMALL			0x8c
173#define PNP_USE_ESCD_SUPPORT			0x8d
174#define PNP_MESSAGE_NOT_SUPPORTED		0x8e
175#define PNP_HARDWARE_ERROR			0x8f
176
177/*
178 * DMI return codes
179 */
180#define DMI_SUCCESS				0x00
181#define DMI_UNKNOWN_FUNCTION			0x81
182#define DMI_FUNCTION_NOT_SUPPORTED		0x82
183#define DMI_INVALID_HANDLE			0x83
184#define DMI_BAD_PARAMETER			0x84
185#define DMI_INVALID_SUBFUNCTION			0x85
186#define DMI_NO_CHANGE				0x86
187#define DMI_ADD_STRUCTURE_FAILED		0x87
188#define DMI_READ_ONLY				0x8d
189#define DMI_LOCK_NOT_SUPPORTED			0x90
190#define DMI_CURRENTLY_LOCKED			0x91
191#define DMI_INVALID_LOCK			0x92
192
193/*
194 * format specifiers and defines for bios16()
195 *     s	= short (16 bits)
196 *     i	= int (32 bits)
197 *     p	= pointer (converted to seg:offset)
198 *     C,D,U 	= selector (corresponding to code/data/utility segment)
199 */
200#define PNP_COUNT_DEVNODES	"sppD",		0x00
201#define PNP_GET_DEVNODE		"sppsD",	0x01
202#define PNP_SET_DEVNODE		"sppsD",	0x02
203#define PNP_GET_EVENT		"spD",		0x03
204#define PNP_SEND_MSG		"ssD",		0x04
205#define PNP_GET_DOCK_INFO	"spD",		0x05
206
207#define PNP_SEL_PRIBOOT		"ssiiisspD",	0x07
208#define PNP_GET_PRIBOOT		"sspppppD",	0x08
209#define PNP_SET_RESINFO		"spD",		0x09
210#define PNP_GET_RESINFO		"spD",		0x0A
211#define PNP_GET_APM_ID		"sppD",		0x0B
212
213#define PNP_GET_ISA_INFO	"spD",		0x40
214#define PNP_GET_ECSD_INFO	"spppD",	0x41
215#define PNP_READ_ESCD		"spUD",		0x42
216#define PNP_WRITE_ESCD		"spUD",		0x43
217
218#define PNP_GET_DMI_INFO	"spppppD",	0x50
219#define PNP_GET_DMI_STRUCTURE	"sppUD",	0x51
220#define PNP_SET_DMI_STRUCTURE	"sppsUD"	0x52
221#define PNP_GET_DMI_CHANGE	"spUD"		0x53
222#define PNP_DMI_CONTROL		"sspsUD"	0x54
223#define PNP_GET_GPNV_INFO	"sppppD"	0x55
224#define PNP_READ_GPNV_DATA	"ssppUD"	0x56
225#define PNP_WRITE_GPNV_DATA	"sspsUD"	0x57
226
227#define PNP_BOOT_CHECK		"sp",		0x60
228#define PNP_COUNT_IPL		"sppp",		0x61
229#define PNP_GET_BOOTPRI		"spp",		0x62
230#define PNP_SET_BOOTPRI		"sp",		0x63
231#define PNP_GET_LASTBOOT	"sp",		0x64
232#define PNP_GET_BOOTFIRST	"sp",		0x65
233#define PNP_SET_BOOTFIRST	"sp",		0x66
234
235extern int bios16(struct bios_args *, char *, ...);
236extern int bios16_call(struct bios_regs *, char *);
237extern int bios32(struct bios_regs *, u_int, u_short);
238extern void set_bios_selectors(struct bios_segments *, int);
239