xref: /freebsd/sys/i386/include/pc/bios.h (revision 4cf49a43559ed9fdad601bdcccd2c55963008675)
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 /*
31  * Signature structure for the BIOS32 Service Directory header
32  */
33 struct 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  */
47 struct 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 
59 extern int		bios32_SDlookup(struct bios32_SDentry *ent);
60 extern 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  * PnP BIOS presence structure
69  */
70 struct PnPBIOS_table
71 {
72     u_int8_t	sig[4];			/* "$PnP */
73     u_int8_t	version;		/* should be 0x10 */
74     u_int8_t	len;    		/* total structure length */
75     u_int16_t	control;		/* BIOS feature flags */
76     u_int8_t	cksum;			/* checksum */
77     u_int32_t	evflagaddr;		/* address of event notificaton flag */
78     u_int16_t	rmentryoffset;		/* real-mode entry offset */
79     u_int16_t	rmentryseg;		/*                 segment */
80     u_int16_t	pmentryoffset;		/* protected-mode entry offset */
81     u_int32_t	pmentrybase;		/*                segment base */
82     u_int32_t	oemdevid;		/* motherboard EISA ID */
83     u_int16_t	rmbiosseg;		/* real-mode BIOS segment */
84     u_int32_t	pmdataseg;		/* protected-mode data segment */
85 } __attribute__ ((packed));
86 
87 
88 /*
89  * Exported lookup results
90  */
91 extern struct bios32_SDentry	PCIbios;
92 extern struct PnPBIOS_table	*PnPBIOStable;
93 
94 struct segment_info {
95 	u_int	base;
96 	u_int	limit;
97 };
98 
99 #define BIOSCODE_FLAG	0x01
100 #define BIOSDATA_FLAG	0x02
101 #define BIOSUTIL_FLAG	0x04
102 #define BIOSARGS_FLAG	0x08
103 
104 struct bios_segments {
105 	struct	segment_info code32;		/* 32-bit code (mandatory) */
106 	struct	segment_info code16;		/* 16-bit code */
107 	struct	segment_info data;		/* 16-bit data */
108 	struct	segment_info util;		/* 16-bit utility */
109 	struct	segment_info args;		/* 16-bit args */
110 };
111 
112 struct bios_regs {
113 	u_int	eax;
114 	u_int	ebx;
115 	u_int	ecx;
116 	u_int	edx;
117 	u_int	esi;
118 	u_int	edi;
119 };
120 
121 struct bios_args {
122 	u_int	entry;				/* entry point of routine */
123 	struct	bios_regs r;
124 	struct	bios_segments seg;
125 };
126 
127 /*
128  * PnP BIOS return codes
129  */
130 #define PNP_SUCCESS				0x00
131 #define PNP_NOT_SET_STATICALLY			0x7f
132 #define PNP_UNKNOWN_FUNCTION			0x81
133 #define PNP_FUNTION_NOT_SUPPORTED		0x82
134 #define PNP_INVALID_HANDLE			0x83
135 #define PNP_BAD_PARAMETER			0x84
136 #define PNP_SET_FAILED				0x85
137 #define PNP_EVENTS_NOT_PENDING			0x86
138 #define PNP_SYSTEM_NOT_DOCKED			0x87
139 #define PNP_NO_ISA_PNP_CARDS			0x88
140 #define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
141 #define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY	0x8a
142 #define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
143 #define PNP_BUFFER_TOO_SMALL			0x8c
144 #define PNP_USE_ESCD_SUPPORT			0x8d
145 #define PNP_MESSAGE_NOT_SUPPORTED		0x8e
146 #define PNP_HARDWARE_ERROR			0x8f
147 
148 /*
149  * DMI return codes
150  */
151 #define DMI_SUCCESS				0x00
152 #define DMI_UNKNOWN_FUNCTION			0x81
153 #define DMI_FUNCTION_NOT_SUPPORTED		0x82
154 #define DMI_INVALID_HANDLE			0x83
155 #define DMI_BAD_PARAMETER			0x84
156 #define DMI_INVALID_SUBFUNCTION			0x85
157 #define DMI_NO_CHANGE				0x86
158 #define DMI_ADD_STRUCTURE_FAILED		0x87
159 #define DMI_READ_ONLY				0x8d
160 #define DMI_LOCK_NOT_SUPPORTED			0x90
161 #define DMI_CURRENTLY_LOCKED			0x91
162 #define DMI_INVALID_LOCK			0x92
163 
164 /*
165  * format specifiers and defines for bios16()
166  *     s	= short (16 bits)
167  *     i	= int (32 bits)
168  *     p	= pointer (converted to seg:offset)
169  *     C,D,U 	= selector (corresponding to code/data/utility segment)
170  */
171 #define PNP_COUNT_DEVNODES	"sppD",		0x00
172 #define PNP_GET_DEVNODE		"sppsD",	0x01
173 #define PNP_SET_DEVNODE		"sppsD",	0x02
174 #define PNP_GET_EVENT		"spD",		0x03
175 #define PNP_SEND_MSG		"ssD",		0x04
176 #define PNP_GET_DOCK_INFO	"spD",		0x05
177 
178 #define PNP_SEL_PRIBOOT		"ssiiisspD",	0x07
179 #define PNP_GET_PRIBOOT		"sspppppD",	0x08
180 #define PNP_SET_RESINFO		"spD",		0x09
181 #define PNP_GET_RESINFO		"spD",		0x0A
182 #define PNP_GET_APM_ID		"sppD",		0x0B
183 
184 #define PNP_GET_ISA_INFO	"spD",		0x40
185 #define PNP_GET_ECSD_INFO	"spppD",	0x41
186 #define PNP_READ_ESCD		"spUD",		0x42
187 #define PNP_WRITE_ESCD		"spUD",		0x43
188 
189 #define PNP_GET_DMI_INFO	"spppppD",	0x50
190 #define PNP_GET_DMI_STRUCTURE	"sppUD",	0x51
191 #define PNP_SET_DMI_STRUCTURE	"sppsUD"	0x52
192 #define PNP_GET_DMI_CHANGE	"spUD"		0x53
193 #define PNP_DMI_CONTROL		"sspsUD"	0x54
194 #define PNP_GET_GPNV_INFO	"sppppD"	0x55
195 #define PNP_READ_GPNV_DATA	"ssppUD"	0x56
196 #define PNP_WRITE_GPNV_DATA	"sspsUD"	0x57
197 
198 #define PNP_BOOT_CHECK		"sp",		0x60
199 #define PNP_COUNT_IPL		"sppp",		0x61
200 #define PNP_GET_BOOTPRI		"spp",		0x62
201 #define PNP_SET_BOOTPRI		"sp",		0x63
202 #define PNP_GET_LASTBOOT	"sp",		0x64
203 #define PNP_GET_BOOTFIRST	"sp",		0x65
204 #define PNP_SET_BOOTFIRST	"sp",		0x66
205 
206 extern int bios16(struct bios_args *, char *, ...);
207 extern int bios16_call(struct bios_regs *, char *);
208 extern int bios32(struct bios_regs *, u_int, u_short);
209 extern void set_bios_selectors(struct bios_segments *, int);
210