xref: /openbsd-src/sys/arch/i386/include/biosvar.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: biosvar.h,v 1.56 2011/04/26 17:33:17 jsing Exp $	*/
2 
3 /*
4  * Copyright (c) 1997-1999 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _MACHINE_BIOSVAR_H_
30 #define _MACHINE_BIOSVAR_H_
31 
32 	/* some boxes put apm data seg in the 2nd page */
33 #define	BOOTARG_OFF	(NBPG*2)
34 #define	BOOTARG_LEN	(NBPG*1)
35 #define	BOOTBIOS_ADDR	(0x7c00)
36 #define	BOOTBIOS_MAXSEC	((1 << 28) - 1)
37 
38 	/* physical page for ptp 0 need for various tramps */
39 #define PTP0_PA		(NBPG*3)
40 
41 	/* BIOS configure flags */
42 #define	BIOSF_BIOS32	0x0001
43 #define	BIOSF_PCIBIOS	0x0002
44 #define	BIOSF_PROMSCAN	0x0004
45 #define	BIOSF_SMBIOS	0x0008
46 
47 /* BIOS media ID */
48 #define BIOSM_F320K	0xff	/* floppy ds/sd  8 spt */
49 #define	BIOSM_F160K	0xfe	/* floppy ss/sd  8 spt */
50 #define	BIOSM_F360K	0xfd	/* floppy ds/sd  9 spt */
51 #define	BIOSM_F180K	0xfc	/* floppy ss/sd  9 spt */
52 #define	BIOSM_ROMD	0xfa	/* ROM disk */
53 #define	BIOSM_F120M	0xf9	/* floppy ds/hd 15 spt 5.25" */
54 #define	BIOSM_F720K	0xf9	/* floppy ds/dd  9 spt 3.50" */
55 #define	BIOSM_HD	0xf8	/* hard drive */
56 #define	BIOSM_F144K	0xf0	/* floppy ds/hd 18 spt 3.50" */
57 #define	BIOSM_OTHER	0xf0	/* any other */
58 
59 /*
60  * BIOS memory maps
61  */
62 #define	BIOS_MAP_END	0x00	/* End of array XXX - special */
63 #define	BIOS_MAP_FREE	0x01	/* Usable memory */
64 #define	BIOS_MAP_RES	0x02	/* Reserved memory */
65 #define	BIOS_MAP_ACPI	0x03	/* ACPI Reclaim memory */
66 #define	BIOS_MAP_NVS	0x04	/* ACPI NVS memory */
67 
68 /*
69  * Optional ROM header
70  */
71 typedef
72 struct bios_romheader {
73 	u_int16_t	signature;	/* 0xaa55 */
74 	u_int8_t	len;		/* length in pages (512 bytes) */
75 	u_int32_t	entry;		/* initialization entry point */
76 	u_int8_t	reserved[19];
77 	u_int16_t	pnpheader;	/* offset to PnP expansion header */
78 } __packed *bios_romheader_t;
79 
80 /*
81  * BIOS32
82  */
83 typedef
84 struct bios32_header {
85 	u_int32_t	signature;	/* 00: signature "_32_" */
86 	u_int32_t	entry;		/* 04: entry point */
87 	u_int8_t	rev;		/* 08: revision */
88 	u_int8_t	length;		/* 09: header length */
89 	u_int8_t	cksum;		/* 0a: modulo 256 checksum */
90 	u_int8_t	reserved[5];
91 } __packed *bios32_header_t;
92 
93 typedef
94 struct bios32_entry_info {
95 	u_int32_t	bei_base;
96 	u_int32_t	bei_size;
97 	u_int32_t	bei_entry;
98 } __packed *bios32_entry_info_t;
99 
100 typedef
101 struct bios32_entry {
102 	u_int32_t	offset;
103 	u_int16_t	segment;
104 } __packed *bios32_entry_t;
105 
106 #define	BIOS32_START	0xe0000
107 #define	BIOS32_SIZE	0x20000
108 #define	BIOS32_END	(BIOS32_START + BIOS32_SIZE - 0x10)
109 
110 #define	BIOS32_MAKESIG(a, b, c, d) \
111 	((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
112 #define	BIOS32_SIGNATURE	BIOS32_MAKESIG('_', '3', '2', '_')
113 #define	PCIBIOS_SIGNATURE	BIOS32_MAKESIG('$', 'P', 'C', 'I')
114 #define	SMBIOS_SIGNATURE	BIOS32_MAKESIG('_', 'S', 'M', '_')
115 
116 /*
117  * CTL_BIOS definitions.
118  */
119 #define	BIOS_DEV		1	/* int: BIOS boot device */
120 #define	BIOS_DISKINFO		2	/* struct: BIOS boot device info */
121 #define BIOS_CKSUMLEN		3	/* int: disk cksum block count */
122 #define	BIOS_MAXID		4	/* number of valid machdep ids */
123 
124 #define	CTL_BIOS_NAMES { \
125 	{ 0, 0 }, \
126 	{ "biosdev", CTLTYPE_INT }, \
127 	{ "diskinfo", CTLTYPE_STRUCT }, \
128 	{ "cksumlen", CTLTYPE_INT }, \
129 }
130 
131 #define	BOOTARG_MEMMAP 0
132 typedef struct _bios_memmap {
133 	u_int64_t addr;		/* Beginning of block */
134 	u_int64_t size;		/* Size of block */
135 	u_int32_t type;		/* Type of block */
136 } __packed bios_memmap_t;
137 
138 /* Info about disk from the bios, plus the mapping from
139  * BIOS numbers to BSD major (driver?) number.
140  *
141  * Also, do not bother with BIOSN*() macros, just parcel
142  * the info out, and use it like this.  This makes for less
143  * of a dependance on BIOSN*() macros having to be the same
144  * across /boot, /bsd, and userland.
145  */
146 #define	BOOTARG_DISKINFO 1
147 typedef struct _bios_diskinfo {
148 	/* BIOS section */
149 	int bios_number;	/* BIOS number of drive (or -1) */
150 	u_int bios_cylinders;	/* BIOS cylinders */
151 	u_int bios_heads;	/* BIOS heads */
152 	u_int bios_sectors;	/* BIOS sectors */
153 	int bios_edd;		/* EDD support */
154 
155 	/* BSD section */
156 	dev_t bsd_dev;		/* BSD device */
157 
158 	/* Checksum section */
159 	u_int32_t checksum;	/* Checksum for drive */
160 
161 	/* Misc. flags */
162 	u_int32_t flags;
163 #define BDI_INVALID	0x00000001	/* I/O error during checksumming */
164 #define BDI_GOODLABEL	0x00000002	/* Had SCSI or ST506/ESDI disklabel */
165 #define BDI_BADLABEL	0x00000004	/* Had another disklabel */
166 #define BDI_EL_TORITO	0x00000008	/* 2,048-byte sectors */
167 #define BDI_PICKED	0x80000000	/* kernel-only: cksum matched */
168 
169 } __packed bios_diskinfo_t;
170 
171 #define	BOOTARG_APMINFO 2
172 typedef struct _bios_apminfo {
173 	/* APM_CONNECT returned values */
174 	u_int	apm_detail;
175 	u_int	apm_code32_base;
176 	u_int	apm_code16_base;
177 	u_int	apm_code_len;
178 	u_int	apm_data_base;
179 	u_int	apm_data_len;
180 	u_int	apm_entry;
181 	u_int	apm_code16_len;
182 } __packed bios_apminfo_t;
183 
184 #define	BOOTARG_CKSUMLEN 3		/* u_int32_t */
185 
186 #define	BOOTARG_PCIINFO 4
187 typedef struct _bios_pciinfo {
188 	/* PCI BIOS v2.0+ - Installation check values */
189 	u_int32_t	pci_chars;	/* Characteristics (%eax) */
190 	u_int32_t	pci_rev;	/* BCD Revision (%ebx) */
191 	u_int32_t	pci_entry32;	/* PM entry point for PCI BIOS */
192 	u_int32_t	pci_lastbus;	/* Number of last PCI bus */
193 } __packed bios_pciinfo_t;
194 
195 #define	BOOTARG_CONSDEV	5
196 typedef struct _bios_consdev {
197 	dev_t	consdev;
198 	int	conspeed;
199 } __packed bios_consdev_t;
200 
201 #define BOOTARG_SMPINFO 6		/* struct mp_float[] */
202 
203 #define BOOTARG_BOOTMAC	7
204 typedef struct _bios_bootmac {
205 	char	mac[6];
206 } __packed bios_bootmac_t;
207 
208 #define BOOTARG_DDB 8
209 typedef struct _bios_ddb {
210 	int	db_console;
211 } __packed bios_ddb_t;
212 
213 #define BOOTARG_ROOTDUID 9
214 typedef struct _bios_rootduid {
215 	u_char	duid[8];
216 } __packed bios_rootduid_t;
217 
218 #if defined(_KERNEL) || defined (_STANDALONE)
219 
220 #ifdef _LOCORE
221 #define	DOINT(n)	int	$0x20+(n)
222 #else
223 #define	DOINT(n)	"int $0x20+(" #n ")"
224 
225 extern volatile struct BIOS_regs {
226 	u_int32_t	biosr_ax;
227 	u_int32_t	biosr_cx;
228 	u_int32_t	biosr_dx;
229 	u_int32_t	biosr_bx;
230 	u_int32_t	biosr_bp;
231 	u_int32_t	biosr_si;
232 	u_int32_t	biosr_di;
233 	u_int32_t	biosr_ds;
234 	u_int32_t	biosr_es;
235 } __packed BIOS_regs;
236 
237 #ifdef _KERNEL
238 #include <machine/bus.h>
239 
240 struct bios_attach_args {
241 	char		*ba_name;
242 	u_int		ba_func;
243 	bus_space_tag_t	ba_iot;
244 	bus_space_tag_t	ba_memt;
245 	union {
246 		void		*_p;
247 		bios_apminfo_t	*_ba_apmp;
248 		paddr_t		_ba_acpipbase;
249 	} _;
250 };
251 
252 #define	ba_apmp		_._ba_apmp
253 #define ba_acpipbase	_._ba_acpipbase
254 
255 struct consdev;
256 struct proc;
257 
258 int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
259 
260 void bios_getopt(void);
261 
262 /* bios32.c */
263 int  bios32_service(u_int32_t, bios32_entry_t, bios32_entry_info_t);
264 
265 extern u_int bootapiver;
266 extern bios_memmap_t *bios_memmap;
267 extern void *bios_smpinfo;
268 extern bios_pciinfo_t *bios_pciinfo;
269 
270 #endif /* _KERNEL */
271 #endif /* _LOCORE */
272 #endif /* _KERNEL || _STANDALONE */
273 
274 #endif /* _MACHINE_BIOSVAR_H_ */
275