1 /* $OpenBSD: biosvar.h,v 1.22 2015/08/30 10:05:09 yasuoka 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 0x0006 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 u_int16_t signature; /* 0xaa55 */ 73 u_int8_t len; /* length in pages (512 bytes) */ 74 u_int32_t entry; /* initialization entry point */ 75 u_int8_t reserved[19]; 76 u_int16_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 u_int64_t addr; /* Beginning of block */ 101 u_int64_t size; /* Size of block */ 102 u_int32_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 dependance 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 u_int32_t checksum; /* Checksum for drive */ 127 128 /* Misc. flags */ 129 u_int32_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_PICKED 0x80000000 /* kernel-only: cksum matched */ 135 136 } __packed bios_diskinfo_t; 137 138 #define BOOTARG_APMINFO 2 139 typedef struct _bios_apminfo { 140 /* APM_CONNECT returned values */ 141 u_int apm_detail; 142 u_int apm_code32_base; 143 u_int apm_code16_base; 144 u_int apm_code_len; 145 u_int apm_data_base; 146 u_int apm_data_len; 147 u_int apm_entry; 148 u_int apm_code16_len; 149 } __packed bios_apminfo_t; 150 151 #define BOOTARG_CKSUMLEN 3 /* u_int32_t */ 152 153 #define BOOTARG_PCIINFO 4 154 typedef struct _bios_pciinfo { 155 /* PCI BIOS v2.0+ - Installation check values */ 156 u_int32_t pci_chars; /* Characteristics (%eax) */ 157 u_int32_t pci_rev; /* BCD Revision (%ebx) */ 158 u_int32_t pci_entry32; /* PM entry point for PCI BIOS */ 159 u_int32_t pci_lastbus; /* Number of last PCI bus */ 160 } __packed bios_pciinfo_t; 161 162 #define BOOTARG_CONSDEV 5 163 typedef struct _bios_consdev { 164 dev_t consdev; 165 int conspeed; 166 int consaddr; 167 int consfreq; 168 } __packed bios_consdev_t; 169 170 #define BOOTARG_BOOTMAC 7 171 typedef struct _bios_bootmac { 172 char mac[6]; 173 } __packed bios_bootmac_t; 174 175 #define BOOTARG_DDB 8 176 typedef struct _bios_ddb { 177 int db_console; 178 } __packed bios_ddb_t; 179 180 #define BOOTARG_BOOTDUID 9 181 typedef struct _bios_bootduid { 182 u_char duid[8]; 183 } __packed bios_bootduid_t; 184 185 #define BOOTARG_BOOTSR 10 186 #define BOOTSR_UUID_MAX 16 187 #define BOOTSR_CRYPTO_MAXKEYBYTES 32 188 typedef struct _bios_bootsr { 189 u_int8_t uuid[BOOTSR_UUID_MAX]; 190 u_int8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; 191 } __packed bios_bootsr_t; 192 193 #define BOOTARG_EFIINFO 11 194 typedef struct _bios_efiinfo { 195 uint64_t config_acpi; 196 uint64_t config_smbios; 197 uint64_t fb_addr; 198 uint64_t fb_size; 199 uint32_t fb_height; 200 uint32_t fb_width; 201 uint32_t fb_pixpsl; /* pixels per scan line */ 202 uint32_t fb_red_mask; 203 uint32_t fb_green_mask; 204 uint32_t fb_blue_mask; 205 uint32_t fb_reserved_mask; 206 } __packed bios_efiinfo_t; 207 208 #if defined(_KERNEL) || defined (_STANDALONE) 209 210 #ifdef _LOCORE 211 #define DOINT(n) int $0x20+(n) 212 #else 213 #define DOINT(n) "int $0x20+(" #n ")" 214 215 extern volatile struct BIOS_regs { 216 u_int32_t biosr_ax; 217 u_int32_t biosr_cx; 218 u_int32_t biosr_dx; 219 u_int32_t biosr_bx; 220 u_int32_t biosr_bp; 221 u_int32_t biosr_si; 222 u_int32_t biosr_di; 223 u_int32_t biosr_ds; 224 u_int32_t biosr_es; 225 } __packed BIOS_regs; 226 227 #ifdef _KERNEL 228 #include <machine/bus.h> 229 230 struct bios_attach_args { 231 char *ba_name; 232 u_int ba_biosfunc; 233 bus_space_tag_t ba_iot; 234 bus_space_tag_t ba_memt; 235 union { 236 void *_p; 237 bios_apminfo_t *_ba_apmp; 238 paddr_t _ba_acpipbase; 239 } _; 240 }; 241 242 #define ba_apmp _._ba_apmp 243 #define ba_acpipbase _._ba_acpipbase 244 245 struct consdev; 246 struct proc; 247 248 int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); 249 250 void bios_getopt(void); 251 bios_diskinfo_t *bios_getdiskinfo(dev_t); 252 253 extern u_int bootapiver; 254 extern bios_memmap_t *bios_memmap; 255 extern bios_efiinfo_t *bios_efiinfo; 256 257 #endif /* _KERNEL */ 258 #endif /* _LOCORE */ 259 #endif /* _KERNEL || _STANDALONE */ 260 261 #endif /* _MACHINE_BIOSVAR_H_ */ 262