xref: /netbsd-src/sys/arch/x86/include/bootinfo.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: bootinfo.h,v 1.30 2019/06/21 02:08:55 nonaka Exp $	*/
2 
3 /*
4  * Copyright (c) 1997
5  *	Matthias Drochner.  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 BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #define BTINFO_BOOTPATH		0
30 #define BTINFO_ROOTDEVICE	1
31 #define BTINFO_BOOTDISK		3
32 #define BTINFO_NETIF		4
33 #define BTINFO_CONSOLE		6
34 #define BTINFO_BIOSGEOM		7
35 #define BTINFO_SYMTAB		8
36 #define BTINFO_MEMMAP		9
37 #define	BTINFO_BOOTWEDGE	10
38 #define BTINFO_MODULELIST	11
39 #define BTINFO_FRAMEBUFFER	12
40 #define BTINFO_USERCONFCOMMANDS	13
41 #define BTINFO_EFI		14
42 #define BTINFO_EFIMEMMAP	15
43 #define BTINFO_PREKERN		16
44 
45 #define BTINFO_STR "bootpath", "rootdevice", "bootdisk", "netif", \
46     "console", "biosgeom", "symtab", "memmap", "bootwedge", "modulelist", \
47     "framebuffer", "userconfcommands", "efi", "efimemmap", "prekern",
48 
49 #ifndef _LOCORE
50 
51 struct btinfo_common {
52 	int len;
53 	int type;
54 };
55 
56 struct btinfo_bootpath {
57 	struct btinfo_common common;
58 	char bootpath[80];
59 };
60 
61 struct btinfo_rootdevice {
62 	struct btinfo_common common;
63 	char devname[16];
64 };
65 
66 struct btinfo_bootdisk {
67 	struct btinfo_common common;
68 	int labelsector; /* label valid if != -1 */
69 	struct {
70 		uint16_t type, checksum;
71 		char packname[16];
72 	} label;
73 	int biosdev;
74 	int partition;
75 };
76 
77 struct btinfo_bootwedge {
78 	struct btinfo_common common;
79 	int biosdev;
80 	daddr_t startblk;
81 	uint64_t nblks;
82 	daddr_t matchblk;
83 	uint64_t matchnblks;
84 	uint8_t matchhash[16];	/* MD5 hash */
85 } __packed;
86 
87 struct btinfo_netif {
88 	struct btinfo_common common;
89 	char ifname[16];
90 	int bus;
91 #define BI_BUS_ISA 0
92 #define BI_BUS_PCI 1
93 	union {
94 		unsigned int iobase; /* ISA */
95 		unsigned int tag; /* PCI, BIOS format */
96 	} addr;
97 };
98 
99 struct btinfo_console {
100 	struct btinfo_common common;
101 	char devname[16];
102 	int addr;
103 	int speed;
104 };
105 
106 struct btinfo_symtab {
107 	struct btinfo_common common;
108 	int nsym;
109 	int ssym;
110 	int esym;
111 };
112 
113 struct bi_memmap_entry {
114 	uint64_t addr;		/* beginning of block */	/* 8 */
115 	uint64_t size;		/* size of block */		/* 8 */
116 	uint32_t type;		/* type of block */		/* 4 */
117 } __packed;				/*	== 20 */
118 
119 #define	BIM_Memory	1	/* available RAM usable by OS */
120 #define	BIM_Reserved	2	/* in use or reserved by the system */
121 #define	BIM_ACPI	3	/* ACPI Reclaim memory */
122 #define	BIM_NVS		4	/* ACPI NVS memory */
123 #define	BIM_Unusable	5	/* errors have been detected */
124 #define	BIM_Disabled	6	/* not enabled */
125 #define	BIM_PMEM	7	/* Persistent memory */
126 #define	BIM_PRAM	12	/* legacy NVDIMM (OEM defined) */
127 
128 struct btinfo_memmap {
129 	struct btinfo_common common;
130 	int num;
131 	struct bi_memmap_entry entry[1]; /* var len */
132 };
133 
134 #if HAVE_NBTOOL_CONFIG_H
135 #include <nbinclude/sys/bootblock.h>
136 #else
137 #include <sys/bootblock.h>
138 #endif /* HAVE_NBTOOL_CONFIG_H */
139 
140 /*
141  * Structure describing disk info as seen by the BIOS.
142  */
143 struct bi_biosgeom_entry {
144 	int		sec, head, cyl;		/* geometry */
145 	uint64_t	totsec;			/* LBA sectors from ext int13 */
146 	int		flags, dev;		/* flags, BIOS device # */
147 #define BI_GEOM_INVALID		0x000001
148 #define BI_GEOM_EXTINT13	0x000002
149 #ifdef BIOSDISK_EXTINFO_V3
150 #define BI_GEOM_BADCKSUM	0x000004	/* v3.x checksum invalid */
151 #define BI_GEOM_BUS_MASK	0x00ff00	/* connecting bus type */
152 #define BI_GEOM_BUS_ISA		0x000100
153 #define BI_GEOM_BUS_PCI		0x000200
154 #define BI_GEOM_BUS_OTHER	0x00ff00
155 #define BI_GEOM_IFACE_MASK	0xff0000	/* interface type */
156 #define BI_GEOM_IFACE_ATA	0x010000
157 #define BI_GEOM_IFACE_ATAPI	0x020000
158 #define BI_GEOM_IFACE_SCSI	0x030000
159 #define BI_GEOM_IFACE_USB	0x040000
160 #define BI_GEOM_IFACE_1394	0x050000	/* Firewire */
161 #define BI_GEOM_IFACE_FIBRE	0x060000	/* Fibre channel */
162 #define BI_GEOM_IFACE_OTHER	0xff0000
163 	unsigned int	cksum;			/* MBR checksum */
164 	unsigned int	interface_path;		/* ISA iobase PCI bus/dev/fun */
165 	uint64_t	device_path;
166 	int		res0;			/* future expansion; 0 now */
167 #else
168 	unsigned int	cksum;			/* MBR checksum */
169 	int		res0, res1, res2, res3;	/* future expansion; 0 now */
170 #endif
171 	struct mbr_partition mbrparts[MBR_PART_COUNT]; /* MBR itself */
172 } __packed;
173 
174 struct btinfo_biosgeom {
175 	struct btinfo_common common;
176 	int num;
177 	struct bi_biosgeom_entry disk[1]; /* var len */
178 };
179 
180 struct bi_modulelist_entry {
181 	char path[80];
182 	int type;
183 	int len;
184 	uint32_t base;
185 };
186 #define	BI_MODULE_NONE		0x00
187 #define	BI_MODULE_ELF		0x01
188 #define	BI_MODULE_IMAGE		0x02
189 #define BI_MODULE_RND		0x03
190 #define BI_MODULE_FS		0x04
191 
192 struct btinfo_modulelist {
193 	struct btinfo_common common;
194 	int num;
195 	uint32_t endpa;
196 	/* bi_modulelist_entry list follows */
197 };
198 
199 struct btinfo_framebuffer {
200 	struct btinfo_common common;
201 	uint64_t physaddr;
202 	uint32_t flags;
203 	uint32_t width;
204 	uint32_t height;
205 	uint16_t stride;
206 	uint8_t depth;
207 	uint8_t rnum;
208 	uint8_t gnum;
209 	uint8_t bnum;
210 	uint8_t rpos;
211 	uint8_t gpos;
212 	uint8_t bpos;
213 	uint16_t vbemode;
214 	uint8_t reserved[14];
215 };
216 
217 struct bi_userconfcommand {
218 	char text[80];
219 };
220 
221 struct btinfo_userconfcommands {
222 	struct btinfo_common common;
223 	int num;
224 	/* bi_userconfcommand list follows */
225 };
226 
227 /* EFI Information */
228 struct btinfo_efi {
229 	struct btinfo_common common;
230 	uint64_t systblpa;	/* Physical address of the EFI System Table */
231 	uint32_t flags;
232 #define BI_EFI_32BIT	__BIT(0)	/* 32bit UEFI */
233 	uint8_t reserved[12];
234 };
235 
236 struct btinfo_prekern {
237 	struct btinfo_common common;
238 	uint32_t kernpa_start;
239 	uint32_t kernpa_end;
240 };
241 
242 struct btinfo_efimemmap {
243 	struct btinfo_common common;
244 	uint32_t num;		/* number of memory descriptor */
245 	uint32_t version;	/* version of memory descriptor */
246 	uint32_t size;		/* size of memory descriptor */
247 	uint8_t memmap[1];	/* whole memory descriptors */
248 };
249 
250 #endif /* _LOCORE */
251 
252 #ifdef _KERNEL
253 
254 #define BOOTINFO_MAXSIZE 16384
255 
256 #ifndef _LOCORE
257 /*
258  * Structure that holds the information passed by the boot loader.
259  */
260 struct bootinfo {
261 	/* Number of bootinfo_* entries in bi_data. */
262 	uint32_t	bi_nentries;
263 
264 	/* Raw data of bootinfo entries.  The first one (if any) is
265 	 * found at bi_data[0] and can be casted to (bootinfo_common *).
266 	 * Once this is done, the following entry is found at 'len'
267 	 * offset as specified by the previous entry. */
268 	uint8_t		bi_data[BOOTINFO_MAXSIZE - sizeof(uint32_t)];
269 };
270 
271 extern struct bootinfo bootinfo;
272 
273 void *lookup_bootinfo(int);
274 void  aprint_bootinfo(void);
275 #endif /* _LOCORE */
276 
277 #endif /* _KERNEL */
278