1 /* $OpenBSD: biosvar.h,v 1.64 2015/09/03 15:52:16 deraadt 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 (PAGE_SIZE * 2) 34 #define BOOTARG_LEN (PAGE_SIZE * 1) 35 #define BOOTBIOS_ADDR (0x7c00) 36 #define BOOTBIOS_MAXSEC ((1 << 28) - 1) 37 38 /* BIOS configure flags */ 39 #define BIOSF_BIOS32 0x0001 40 #define BIOSF_PCIBIOS 0x0002 41 #define BIOSF_PROMSCAN 0x0004 42 #define BIOSF_SMBIOS 0x0008 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 } __packed *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 } __packed *bios32_header_t; 89 90 typedef 91 struct bios32_entry_info { 92 u_int32_t bei_base; 93 u_int32_t bei_size; 94 u_int32_t bei_entry; 95 } __packed *bios32_entry_info_t; 96 97 typedef 98 struct bios32_entry { 99 u_int32_t offset; 100 u_int16_t segment; 101 } __packed *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 #define SMBIOS_SIGNATURE BIOS32_MAKESIG('_', 'S', 'M', '_') 112 113 /* 114 * CTL_BIOS definitions. 115 */ 116 #define BIOS_DEV 1 /* int: BIOS boot device */ 117 #define BIOS_DISKINFO 2 /* struct: BIOS boot device info */ 118 #define BIOS_CKSUMLEN 3 /* int: disk cksum block count */ 119 #define BIOS_MAXID 4 /* number of valid machdep ids */ 120 121 #define CTL_BIOS_NAMES { \ 122 { 0, 0 }, \ 123 { "biosdev", CTLTYPE_INT }, \ 124 { "diskinfo", CTLTYPE_STRUCT }, \ 125 { "cksumlen", CTLTYPE_INT }, \ 126 } 127 128 #define BOOTARG_MEMMAP 0 129 typedef struct _bios_memmap { 130 u_int64_t addr; /* Beginning of block */ 131 u_int64_t size; /* Size of block */ 132 u_int32_t type; /* Type of block */ 133 } __packed bios_memmap_t; 134 135 /* Info about disk from the bios, plus the mapping from 136 * BIOS numbers to BSD major (driver?) number. 137 * 138 * Also, do not bother with BIOSN*() macros, just parcel 139 * the info out, and use it like this. This makes for less 140 * of a dependance on BIOSN*() macros having to be the same 141 * across /boot, /bsd, and userland. 142 */ 143 #define BOOTARG_DISKINFO 1 144 typedef struct _bios_diskinfo { 145 /* BIOS section */ 146 int bios_number; /* BIOS number of drive (or -1) */ 147 u_int bios_cylinders; /* BIOS cylinders */ 148 u_int bios_heads; /* BIOS heads */ 149 u_int bios_sectors; /* BIOS sectors */ 150 int bios_edd; /* EDD support */ 151 152 /* BSD section */ 153 dev_t bsd_dev; /* BSD device */ 154 155 /* Checksum section */ 156 u_int32_t checksum; /* Checksum for drive */ 157 158 /* Misc. flags */ 159 u_int32_t flags; 160 #define BDI_INVALID 0x00000001 /* I/O error during checksumming */ 161 #define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */ 162 #define BDI_BADLABEL 0x00000004 /* Had another disklabel */ 163 #define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */ 164 #define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */ 165 166 } __packed bios_diskinfo_t; 167 168 #define BOOTARG_APMINFO 2 169 typedef struct _bios_apminfo { 170 /* APM_CONNECT returned values */ 171 u_int apm_detail; 172 u_int apm_code32_base; 173 u_int apm_code16_base; 174 u_int apm_code_len; 175 u_int apm_data_base; 176 u_int apm_data_len; 177 u_int apm_entry; 178 u_int apm_code16_len; 179 } __packed bios_apminfo_t; 180 181 #define BOOTARG_CKSUMLEN 3 /* u_int32_t */ 182 183 #define BOOTARG_PCIINFO 4 184 typedef struct _bios_pciinfo { 185 /* PCI BIOS v2.0+ - Installation check values */ 186 u_int32_t pci_chars; /* Characteristics (%eax) */ 187 u_int32_t pci_rev; /* BCD Revision (%ebx) */ 188 u_int32_t pci_entry32; /* PM entry point for PCI BIOS */ 189 u_int32_t pci_lastbus; /* Number of last PCI bus */ 190 } __packed bios_pciinfo_t; 191 192 #define BOOTARG_CONSDEV 5 193 typedef struct _bios_consdev { 194 dev_t consdev; 195 int conspeed; 196 int consaddr; 197 int consfreq; 198 } __packed bios_consdev_t; 199 200 #define BOOTARG_SMPINFO 6 /* struct mp_float[] */ 201 202 #define BOOTARG_BOOTMAC 7 203 typedef struct _bios_bootmac { 204 char mac[6]; 205 } __packed bios_bootmac_t; 206 207 #define BOOTARG_DDB 8 208 typedef struct _bios_ddb { 209 int db_console; 210 } __packed bios_ddb_t; 211 212 #define BOOTARG_BOOTDUID 9 213 typedef struct _bios_bootduid { 214 u_char duid[8]; 215 } __packed bios_bootduid_t; 216 217 #define BOOTARG_BOOTSR 10 218 #define BOOTSR_UUID_MAX 16 219 #define BOOTSR_CRYPTO_MAXKEYBYTES 32 220 typedef struct _bios_bootsr { 221 u_int8_t uuid[BOOTSR_UUID_MAX]; 222 u_int8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; 223 } __packed bios_bootsr_t; 224 225 #define BOOTARG_EFIINFO 11 226 typedef struct _bios_efiinfo { 227 uint64_t config_acpi; 228 uint64_t config_smbios; 229 uint64_t fb_addr; 230 uint64_t fb_size; 231 uint32_t fb_height; 232 uint32_t fb_width; 233 uint32_t fb_pixpsl; /* pixels per scan line */ 234 uint32_t fb_red_mask; 235 uint32_t fb_green_mask; 236 uint32_t fb_blue_mask; 237 uint32_t fb_reserved_mask; 238 } __packed bios_efiinfo_t; 239 240 #if defined(_KERNEL) || defined (_STANDALONE) 241 242 #ifdef _LOCORE 243 #define DOINT(n) int $0x20+(n) 244 #else 245 #define DOINT(n) "int $0x20+(" #n ")" 246 247 extern volatile struct BIOS_regs { 248 u_int32_t biosr_ax; 249 u_int32_t biosr_cx; 250 u_int32_t biosr_dx; 251 u_int32_t biosr_bx; 252 u_int32_t biosr_bp; 253 u_int32_t biosr_si; 254 u_int32_t biosr_di; 255 u_int32_t biosr_ds; 256 u_int32_t biosr_es; 257 } __packed BIOS_regs; 258 259 #ifdef _KERNEL 260 #include <machine/bus.h> 261 262 struct bios_attach_args { 263 char *ba_name; 264 u_int ba_func; 265 bus_space_tag_t ba_iot; 266 bus_space_tag_t ba_memt; 267 union { 268 void *_p; 269 bios_apminfo_t *_ba_apmp; 270 paddr_t _ba_acpipbase; 271 } _; 272 }; 273 274 #define ba_apmp _._ba_apmp 275 #define ba_acpipbase _._ba_acpipbase 276 277 struct consdev; 278 struct proc; 279 280 int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); 281 282 void bios_getopt(void); 283 284 /* bios32.c */ 285 int bios32_service(u_int32_t, bios32_entry_t, bios32_entry_info_t); 286 void bios32_cleanup(void); 287 288 extern u_int bootapiver; 289 extern bios_memmap_t *bios_memmap; 290 extern bios_efiinfo_t *bios_efiinfo; 291 extern void *bios_smpinfo; 292 extern bios_pciinfo_t *bios_pciinfo; 293 294 #endif /* _KERNEL */ 295 #endif /* _LOCORE */ 296 #endif /* _KERNEL || _STANDALONE */ 297 298 #endif /* _MACHINE_BIOSVAR_H_ */ 299