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