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