| 1 | /*	$OpenBSD: biosvar.h,v 1.32 2023/09/08 20:47:22 kn 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 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, |
| 22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 27 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 28 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef _MACHINE_BIOSVAR_H_ |
| 32 | #define _MACHINE_BIOSVAR_H_ |
| 33 | |
| 34 | 	/* some boxes put apm data seg in the 2nd page */ |
| 35 | #define	BOOTARG_OFF	(PAGE_SIZE * 2) |
| 36 | #define	BOOTARG_LEN	(PAGE_SIZE * 1) |
| 37 | #define	BOOTBIOS_ADDR	(0x7c00) |
| 38 | #define	BOOTBIOS_MAXSEC	((1 << 28) - 1) |
| 39 | |
| 40 | 	/* BIOS configure flags */ |
| 41 | #define	BIOSF_BIOS32	0x0001 |
| 42 | #define	BIOSF_PCIBIOS	0x0002 |
| 43 | #define	BIOSF_PROMSCAN	0x0004 |
| 44 | #define	BIOSF_SMBIOS	0x0008 |
| 45 | |
| 46 | /* BIOS media ID */ |
| 47 | #define BIOSM_F320K	0xff	/* floppy ds/sd 8 spt */ |
| 48 | #define	BIOSM_F160K	0xfe	/* floppy ss/sd 8 spt */ |
| 49 | #define	BIOSM_F360K	0xfd	/* floppy ds/sd 9 spt */ |
| 50 | #define	BIOSM_F180K	0xfc	/* floppy ss/sd 9 spt */ |
| 51 | #define	BIOSM_ROMD	0xfa	/* ROM disk */ |
| 52 | #define	BIOSM_F120M	0xf9	/* floppy ds/hd 15 spt 5.25" */ |
| 53 | #define	BIOSM_F720K	0xf9	/* floppy ds/dd 9 spt 3.50" */ |
| 54 | #define	BIOSM_HD	0xf8	/* hard drive */ |
| 55 | #define	BIOSM_F144K	0xf0	/* floppy ds/hd 18 spt 3.50" */ |
| 56 | #define	BIOSM_OTHER	0xf0	/* any other */ |
| 57 | |
| 58 | /* |
| 59 | * BIOS memory maps |
| 60 | */ |
| 61 | #define	BIOS_MAP_END	0x00	/* End of array XXX - special */ |
| 62 | #define	BIOS_MAP_FREE	0x01	/* Usable memory */ |
| 63 | #define	BIOS_MAP_RES	0x02	/* Reserved memory */ |
| 64 | #define	BIOS_MAP_ACPI	0x03	/* ACPI Reclaim memory */ |
| 65 | #define	BIOS_MAP_NVS	0x04	/* ACPI NVS memory */ |
| 66 | |
| 67 | /* |
| 68 | * Optional ROM header |
| 69 | */ |
| 70 | typedef |
| 71 | struct bios_romheader { |
| 72 | 	uint16_t	signature;	/* 0xaa55 */ |
| 73 | 	uint8_t		len;		/* length in pages (512 bytes) */ |
| 74 | 	uint32_t	entry;		/* initialization entry point */ |
| 75 | 	uint8_t		reserved[19]; |
| 76 | 	uint16_t	pnpheader;	/* offset to PnP expansion header */ |
| 77 | } __packed *bios_romheader_t; |
| 78 | |
| 79 | #define	BIOS32_MAKESIG(a, b, c, d) \ |
| 80 | 	((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) |
| 81 | #define	SMBIOS_SIGNATURE	BIOS32_MAKESIG('_', 'S', 'M', '_') |
| 82 | |
| 83 | /* |
| 84 | * CTL_BIOS definitions. |
| 85 | */ |
| 86 | #define	BIOS_DEV		1	/* int: BIOS boot device */ |
| 87 | #define	BIOS_DISKINFO		2	/* struct: BIOS boot device info */ |
| 88 | #define BIOS_CKSUMLEN		3	/* int: disk cksum block count */ |
| 89 | #define	BIOS_MAXID		4	/* number of valid machdep ids */ |
| 90 | |
| 91 | #define	CTL_BIOS_NAMES { \ |
| 92 | 	{ 0, 0 }, \ |
| 93 | 	{ "biosdev", CTLTYPE_INT }, \ |
| 94 | 	{ "diskinfo", CTLTYPE_STRUCT }, \ |
| 95 | 	{ "cksumlen", CTLTYPE_INT }, \ |
| 96 | } |
| 97 | |
| 98 | #define	BOOTARG_MEMMAP 0 |
| 99 | typedef struct _bios_memmap { |
| 100 | 	uint64_t addr;		/* Beginning of block */ |
| 101 | 	uint64_t size;		/* Size of block */ |
| 102 | 	uint32_t type;		/* Type of block */ |
| 103 | } __packed bios_memmap_t; |
| 104 | |
| 105 | /* Info about disk from the bios, plus the mapping from |
| 106 | * BIOS numbers to BSD major (driver?) number. |
| 107 | * |
| 108 | * Also, do not bother with BIOSN*() macros, just parcel |
| 109 | * the info out, and use it like this. This makes for less |
| 110 | * of a dependence on BIOSN*() macros having to be the same |
| 111 | * across /boot, /bsd, and userland. |
| 112 | */ |
| 113 | #define	BOOTARG_DISKINFO 1 |
| 114 | typedef struct _bios_diskinfo { |
| 115 | 	/* BIOS section */ |
| 116 | 	int bios_number;	/* BIOS number of drive (or -1) */ |
| 117 | 	u_int bios_cylinders;	/* BIOS cylinders */ |
| 118 | 	u_int bios_heads;	/* BIOS heads */ |
| 119 | 	u_int bios_sectors;	/* BIOS sectors */ |
| 120 | 	int bios_edd;		/* EDD support */ |
| 121 | |
| 122 | 	/* BSD section */ |
| 123 | 	dev_t bsd_dev;		/* BSD device */ |
| 124 | |
| 125 | 	/* Checksum section */ |
| 126 | 	uint32_t checksum;	/* Checksum for drive */ |
| 127 | |
| 128 | 	/* Misc. flags */ |
| 129 | 	uint32_t flags; |
| 130 | #define BDI_INVALID	0x00000001	/* I/O error during checksumming */ |
| 131 | #define BDI_GOODLABEL	0x00000002	/* Had SCSI or ST506/ESDI disklabel */ |
| 132 | #define BDI_BADLABEL	0x00000004	/* Had another disklabel */ |
| 133 | #define BDI_EL_TORITO	0x00000008	/* 2,048-byte sectors */ |
| 134 | #define BDI_HIBVALID	0x00000010	/* hibernate signature valid */ |
| 135 | #define BDI_PICKED	0x80000000	/* kernel-only: cksum matched */ |
| 136 | |
| 137 | } __packed bios_diskinfo_t; |
| 138 | |
| 139 | #define	BOOTARG_APMINFO 2 |
| 140 | typedef struct _bios_apminfo { |
| 141 | 	/* APM_CONNECT returned values */ |
| 142 | 	u_int	apm_detail; |
| 143 | 	u_int	apm_code32_base; |
| 144 | 	u_int	apm_code16_base; |
| 145 | 	u_int	apm_code_len; |
| 146 | 	u_int	apm_data_base; |
| 147 | 	u_int	apm_data_len; |
| 148 | 	u_int	apm_entry; |
| 149 | 	u_int	apm_code16_len; |
| 150 | } __packed bios_apminfo_t; |
| 151 | |
| 152 | #define	BOOTARG_CKSUMLEN 3		/* uint32_t */ |
| 153 | |
| 154 | #define	BOOTARG_PCIINFO 4 |
| 155 | typedef struct _bios_pciinfo { |
| 156 | 	/* PCI BIOS v2.0+ - Installation check values */ |
| 157 | 	uint32_t	pci_chars;	/* Characteristics (%eax) */ |
| 158 | 	uint32_t	pci_rev;	/* BCD Revision (%ebx) */ |
| 159 | 	uint32_t	pci_entry32;	/* PM entry point for PCI BIOS */ |
| 160 | 	uint32_t	pci_lastbus;	/* Number of last PCI bus */ |
| 161 | } __packed bios_pciinfo_t; |
| 162 | |
| 163 | #define	BOOTARG_CONSDEV	5 |
| 164 | typedef struct _bios_consdev { |
| 165 | 	dev_t		consdev; |
| 166 | 	int		conspeed; |
| 167 | 	uint64_t	consaddr; |
| 168 | 	int		consfreq; |
| 169 | 	uint32_t	flags; |
| 170 | #define BCD_MMIO	0x00000001	/* Memory Mapped IO */ |
| 171 | 	int		reg_width; |
| 172 | 	int		reg_shift; |
| 173 | } __packed bios_consdev_t; |
| 174 | |
| 175 | #define BOOTARG_BOOTMAC	7 |
| 176 | typedef struct _bios_bootmac { |
| 177 | 	char	mac[6]; |
| 178 | } __packed bios_bootmac_t; |
| 179 | |
| 180 | #define BOOTARG_DDB 8 |
| 181 | typedef struct _bios_ddb { |
| 182 | 	int	db_console; |
| 183 | } __packed bios_ddb_t; |
| 184 | |
| 185 | #define BOOTARG_BOOTDUID 9 |
| 186 | typedef struct _bios_bootduid { |
| 187 | 	u_char	duid[8]; |
| 188 | } __packed bios_bootduid_t; |
| 189 | |
| 190 | #define BOOTARG_BOOTSR 10 |
| 191 | #define BOOTSR_UUID_MAX 16 |
| 192 | #define BOOTSR_CRYPTO_MAXKEYBYTES 32 |
| 193 | typedef struct _bios_bootsr { |
| 194 | 	uint8_t		uuid[BOOTSR_UUID_MAX]; |
| 195 | 	uint8_t		maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; |
| 196 | } __packed bios_bootsr_t; |
| 197 | |
| 198 | #define	BOOTARG_EFIINFO 11 |
| 199 | typedef struct _bios_efiinfo { |
| 200 | 	uint64_t	config_acpi; |
| 201 | 	uint64_t	config_smbios; |
| 202 | 	uint64_t	fb_addr; |
| 203 | 	uint64_t	fb_size; |
| 204 | 	uint32_t	fb_height; |
| 205 | 	uint32_t	fb_width; |
| 206 | 	uint32_t	fb_pixpsl;	/* pixels per scan line */ |
| 207 | 	uint32_t	fb_red_mask; |
| 208 | 	uint32_t	fb_green_mask; |
| 209 | 	uint32_t	fb_blue_mask; |
| 210 | 	uint32_t	fb_reserved_mask; |
| 211 | 	uint32_t	flags; |
| 212 | #define BEI_64BIT	0x00000001	/* 64-bit EFI implementation */ |
| 213 | #define BEI_ESRT	0x00000002	/* ESRT table */ |
| 214 | 	uint32_t	mmap_desc_ver; |
| 215 | 	uint32_t	mmap_desc_size; |
| 216 | 	uint32_t	mmap_size; |
| 217 | 	uint64_t	mmap_start; |
| 218 | 	uint64_t	system_table; |
| 219 | 	uint64_t	config_esrt; |
| 220 | } __packed bios_efiinfo_t; |
| 221 | |
| 222 | #define	BOOTARG_UCODE 12 |
| 223 | typedef struct _bios_ucode { |
| 224 | 	uint64_t	uc_addr; |
| 225 | 	uint64_t	uc_size; |
| 226 | } __packed bios_ucode_t; |
| 227 | |
| 228 | #if defined(_KERNEL) || defined (_STANDALONE) |
| 229 | |
| 230 | #ifdef _LOCORE |
| 231 | #define	DOINT(n)	int	$0x20+(n) |
| 232 | #else |
| 233 | #define	DOINT(n)	"int $0x20+(" #n ")" |
| 234 | |
| 235 | extern volatile struct BIOS_regs { |
| 236 | 	uint32_t	biosr_ax; |
| 237 | 	uint32_t	biosr_cx; |
| 238 | 	uint32_t	biosr_dx; |
| 239 | 	uint32_t	biosr_bx; |
| 240 | 	uint32_t	biosr_bp; |
| 241 | 	uint32_t	biosr_si; |
| 242 | 	uint32_t	biosr_di; |
| 243 | 	uint32_t	biosr_ds; |
| 244 | 	uint32_t	biosr_es; |
| 245 | } __packed BIOS_regs; |
| 246 | |
| 247 | #ifdef _KERNEL |
| 248 | #include <machine/bus.h> |
| 249 | |
| 250 | struct bios_attach_args { |
| 251 | 	char		*ba_name; |
| 252 | 	u_int		ba_func; |
| 253 | 	bus_space_tag_t	ba_iot; |
| 254 | 	bus_space_tag_t	ba_memt; |
| 255 | 	union { |
| 256 | 		void		*_p; |
| 257 | 		bios_apminfo_t	*_ba_apmp; |
| 258 | 		paddr_t		_ba_acpipbase; |
| 259 | 	} _; |
| 260 | }; |
| 261 | |
| 262 | #define	ba_apmp		_._ba_apmp |
| 263 | #define ba_acpipbase	_._ba_acpipbase |
| 264 | |
| 265 | struct consdev; |
| 266 | struct proc; |
| 267 | |
| 268 | int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); |
| 269 | |
| 270 | void bios_getopt(void); |
| 271 | bios_diskinfo_t *bios_getdiskinfo(dev_t); |
| 272 | |
| 273 | extern int biosbasemem; |
| 274 | extern u_int bootapiver; |
| 275 | extern bios_memmap_t *bios_memmap; |
| 276 | extern bios_efiinfo_t *bios_efiinfo; |
| 277 | extern bios_ucode_t *bios_ucode; |
| 278 | |
| 279 | #endif /* _KERNEL */ |
| 280 | #endif /* _LOCORE */ |
| 281 | #endif /* _KERNEL || _STANDALONE */ |
| 282 | |
| 283 | #endif /* _MACHINE_BIOSVAR_H_ */ |