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