1*f721f560Skettenis /* $OpenBSD: biosvar.h,v 1.68 2019/08/04 14:28:58 kettenis Exp $ */ 212f60ca1Smickey 312f60ca1Smickey /* 4857b0937Smickey * Copyright (c) 1997-1999 Michael Shalayeff 512f60ca1Smickey * All rights reserved. 612f60ca1Smickey * 712f60ca1Smickey * Redistribution and use in source and binary forms, with or without 812f60ca1Smickey * modification, are permitted provided that the following conditions 912f60ca1Smickey * are met: 1012f60ca1Smickey * 1. Redistributions of source code must retain the above copyright 1112f60ca1Smickey * notice, this list of conditions and the following disclaimer. 1212f60ca1Smickey * 2. Redistributions in binary form must reproduce the above copyright 1312f60ca1Smickey * notice, this list of conditions and the following disclaimer in the 1412f60ca1Smickey * documentation and/or other materials provided with the distribution. 1512f60ca1Smickey * 1612f60ca1Smickey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17857b0937Smickey * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18857b0937Smickey * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19857b0937Smickey * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20857b0937Smickey * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21857b0937Smickey * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22857b0937Smickey * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23857b0937Smickey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24857b0937Smickey * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25857b0937Smickey * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26857b0937Smickey * THE POSSIBILITY OF SUCH DAMAGE. 2712f60ca1Smickey */ 2812f60ca1Smickey 292fa72412Spirofti #ifndef _MACHINE_BIOSVAR_H_ 302fa72412Spirofti #define _MACHINE_BIOSVAR_H_ 3112f60ca1Smickey 32857b0937Smickey /* some boxes put apm data seg in the 2nd page */ 33184e2458Sderaadt #define BOOTARG_OFF (PAGE_SIZE * 2) 34184e2458Sderaadt #define BOOTARG_LEN (PAGE_SIZE * 1) 35857b0937Smickey #define BOOTBIOS_ADDR (0x7c00) 369730fd37Skrw #define BOOTBIOS_MAXSEC ((1 << 28) - 1) 3712f60ca1Smickey 38d9b09113Smickey /* BIOS configure flags */ 39d9b09113Smickey #define BIOSF_BIOS32 0x0001 40d9b09113Smickey #define BIOSF_PCIBIOS 0x0002 41a91c80dcSmickey #define BIOSF_PROMSCAN 0x0004 42cf7bb6c7Stom #define BIOSF_SMBIOS 0x0008 43d9b09113Smickey 4497b39c71Smickey /* BIOS media ID */ 4597b39c71Smickey #define BIOSM_F320K 0xff /* floppy ds/sd 8 spt */ 4697b39c71Smickey #define BIOSM_F160K 0xfe /* floppy ss/sd 8 spt */ 4797b39c71Smickey #define BIOSM_F360K 0xfd /* floppy ds/sd 9 spt */ 4897b39c71Smickey #define BIOSM_F180K 0xfc /* floppy ss/sd 9 spt */ 4997b39c71Smickey #define BIOSM_ROMD 0xfa /* ROM disk */ 5097b39c71Smickey #define BIOSM_F120M 0xf9 /* floppy ds/hd 15 spt 5.25" */ 5197b39c71Smickey #define BIOSM_F720K 0xf9 /* floppy ds/dd 9 spt 3.50" */ 5297b39c71Smickey #define BIOSM_HD 0xf8 /* hard drive */ 5397b39c71Smickey #define BIOSM_F144K 0xf0 /* floppy ds/hd 18 spt 3.50" */ 5497b39c71Smickey #define BIOSM_OTHER 0xf0 /* any other */ 5597b39c71Smickey 5612f60ca1Smickey /* 579bd88327Sweingart * BIOS memory maps 589bd88327Sweingart */ 599bd88327Sweingart #define BIOS_MAP_END 0x00 /* End of array XXX - special */ 609bd88327Sweingart #define BIOS_MAP_FREE 0x01 /* Usable memory */ 619251768bSmickey #define BIOS_MAP_RES 0x02 /* Reserved memory */ 629bd88327Sweingart #define BIOS_MAP_ACPI 0x03 /* ACPI Reclaim memory */ 639bd88327Sweingart #define BIOS_MAP_NVS 0x04 /* ACPI NVS memory */ 649bd88327Sweingart 659bd88327Sweingart /* 66a91c80dcSmickey * Optional ROM header 67a91c80dcSmickey */ 68a91c80dcSmickey typedef 69a91c80dcSmickey struct bios_romheader { 70*f721f560Skettenis uint16_t signature; /* 0xaa55 */ 71*f721f560Skettenis uint8_t len; /* length in pages (512 bytes) */ 72*f721f560Skettenis uint32_t entry; /* initialization entry point */ 73*f721f560Skettenis uint8_t reserved[19]; 74*f721f560Skettenis uint16_t pnpheader; /* offset to PnP expansion header */ 75e7940adfSderaadt } __packed *bios_romheader_t; 76a91c80dcSmickey 77a91c80dcSmickey /* 786661564bSmickey * BIOS32 796661564bSmickey */ 806661564bSmickey typedef 81d9b09113Smickey struct bios32_header { 82*f721f560Skettenis uint32_t signature; /* 00: signature "_32_" */ 83*f721f560Skettenis uint32_t entry; /* 04: entry point */ 84*f721f560Skettenis uint8_t rev; /* 08: revision */ 85*f721f560Skettenis uint8_t length; /* 09: header length */ 86*f721f560Skettenis uint8_t cksum; /* 0a: modulo 256 checksum */ 87*f721f560Skettenis uint8_t reserved[5]; 88e7940adfSderaadt } __packed *bios32_header_t; 89d9b09113Smickey 90d9b09113Smickey typedef 916661564bSmickey struct bios32_entry_info { 92*f721f560Skettenis uint32_t bei_base; 93*f721f560Skettenis uint32_t bei_size; 94*f721f560Skettenis uint32_t bei_entry; 95e7940adfSderaadt } __packed *bios32_entry_info_t; 966661564bSmickey 976661564bSmickey typedef 986661564bSmickey struct bios32_entry { 99*f721f560Skettenis uint32_t offset; 100*f721f560Skettenis uint16_t segment; 101e7940adfSderaadt } __packed *bios32_entry_t; 1026661564bSmickey 103d9b09113Smickey #define BIOS32_START 0xe0000 104d9b09113Smickey #define BIOS32_SIZE 0x20000 105d9b09113Smickey #define BIOS32_END (BIOS32_START + BIOS32_SIZE - 0x10) 106d9b09113Smickey 1076661564bSmickey #define BIOS32_MAKESIG(a, b, c, d) \ 1086661564bSmickey ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) 109d9b09113Smickey #define BIOS32_SIGNATURE BIOS32_MAKESIG('_', '3', '2', '_') 110d9b09113Smickey #define PCIBIOS_SIGNATURE BIOS32_MAKESIG('$', 'P', 'C', 'I') 111de8bfd7dSgwk #define SMBIOS_SIGNATURE BIOS32_MAKESIG('_', 'S', 'M', '_') 1126661564bSmickey 1136661564bSmickey /* 114bbada368Smickey * CTL_BIOS definitions. 115bbada368Smickey */ 116bbada368Smickey #define BIOS_DEV 1 /* int: BIOS boot device */ 1179251768bSmickey #define BIOS_DISKINFO 2 /* struct: BIOS boot device info */ 1180194024dSmickey #define BIOS_CKSUMLEN 3 /* int: disk cksum block count */ 1190194024dSmickey #define BIOS_MAXID 4 /* number of valid machdep ids */ 120bbada368Smickey 121bbada368Smickey #define CTL_BIOS_NAMES { \ 122bbada368Smickey { 0, 0 }, \ 123bbada368Smickey { "biosdev", CTLTYPE_INT }, \ 1249251768bSmickey { "diskinfo", CTLTYPE_STRUCT }, \ 125fd794b39Smickey { "cksumlen", CTLTYPE_INT }, \ 126bbada368Smickey } 127bbada368Smickey 1289251768bSmickey #define BOOTARG_MEMMAP 0 1291fd86601Sweingart typedef struct _bios_memmap { 130*f721f560Skettenis uint64_t addr; /* Beginning of block */ 131*f721f560Skettenis uint64_t size; /* Size of block */ 132*f721f560Skettenis uint32_t type; /* Type of block */ 133e7940adfSderaadt } __packed bios_memmap_t; 1349bd88327Sweingart 13556427238Sweingart /* Info about disk from the bios, plus the mapping from 13656427238Sweingart * BIOS numbers to BSD major (driver?) number. 13756427238Sweingart * 13856427238Sweingart * Also, do not bother with BIOSN*() macros, just parcel 13956427238Sweingart * the info out, and use it like this. This makes for less 140897c442bStom * of a dependence on BIOSN*() macros having to be the same 14156427238Sweingart * across /boot, /bsd, and userland. 14256427238Sweingart */ 1439251768bSmickey #define BOOTARG_DISKINFO 1 14456427238Sweingart typedef struct _bios_diskinfo { 14556427238Sweingart /* BIOS section */ 1469251768bSmickey int bios_number; /* BIOS number of drive (or -1) */ 1479251768bSmickey u_int bios_cylinders; /* BIOS cylinders */ 1489251768bSmickey u_int bios_heads; /* BIOS heads */ 1499251768bSmickey u_int bios_sectors; /* BIOS sectors */ 1509251768bSmickey int bios_edd; /* EDD support */ 15156427238Sweingart 15256427238Sweingart /* BSD section */ 15305cdd021Sweingart dev_t bsd_dev; /* BSD device */ 1541fd86601Sweingart 1551fd86601Sweingart /* Checksum section */ 156*f721f560Skettenis uint32_t checksum; /* Checksum for drive */ 157fd794b39Smickey 158fd794b39Smickey /* Misc. flags */ 159*f721f560Skettenis uint32_t flags; 160fd794b39Smickey #define BDI_INVALID 0x00000001 /* I/O error during checksumming */ 161fd794b39Smickey #define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */ 162fd794b39Smickey #define BDI_BADLABEL 0x00000004 /* Had another disklabel */ 163285601acStom #define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */ 164897c442bStom #define BDI_HIBVALID 0x00000010 /* hibernate signature valid */ 165edd967eaSniklas #define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */ 1669251768bSmickey 167e7940adfSderaadt } __packed bios_diskinfo_t; 16856427238Sweingart 1699251768bSmickey #define BOOTARG_APMINFO 2 1709251768bSmickey typedef struct _bios_apminfo { 1719251768bSmickey /* APM_CONNECT returned values */ 1729251768bSmickey u_int apm_detail; 1739251768bSmickey u_int apm_code32_base; 1749251768bSmickey u_int apm_code16_base; 1759251768bSmickey u_int apm_code_len; 1769251768bSmickey u_int apm_data_base; 1779251768bSmickey u_int apm_data_len; 1789251768bSmickey u_int apm_entry; 179857b0937Smickey u_int apm_code16_len; 180e7940adfSderaadt } __packed bios_apminfo_t; 1819251768bSmickey 182*f721f560Skettenis #define BOOTARG_CKSUMLEN 3 /* uint32_t */ 183fd794b39Smickey 1845cc22009Sweingart #define BOOTARG_PCIINFO 4 1855cc22009Sweingart typedef struct _bios_pciinfo { 1865cc22009Sweingart /* PCI BIOS v2.0+ - Installation check values */ 187*f721f560Skettenis uint32_t pci_chars; /* Characteristics (%eax) */ 188*f721f560Skettenis uint32_t pci_rev; /* BCD Revision (%ebx) */ 189*f721f560Skettenis uint32_t pci_entry32; /* PM entry point for PCI BIOS */ 190*f721f560Skettenis uint32_t pci_lastbus; /* Number of last PCI bus */ 191e7940adfSderaadt } __packed bios_pciinfo_t; 1925cc22009Sweingart 193e72263daSmickey #define BOOTARG_CONSDEV 5 194e72263daSmickey typedef struct _bios_consdev { 195e72263daSmickey dev_t consdev; 196e72263daSmickey int conspeed; 197a1e303c3Skettenis int consaddr; 198a1e303c3Skettenis int consfreq; 199e7940adfSderaadt } __packed bios_consdev_t; 2008f7785e7Smickey 201012ea299Sniklas #define BOOTARG_SMPINFO 6 /* struct mp_float[] */ 202012ea299Sniklas 2038847d4f8Sderaadt #define BOOTARG_BOOTMAC 7 2048847d4f8Sderaadt typedef struct _bios_bootmac { 2058847d4f8Sderaadt char mac[6]; 206e7940adfSderaadt } __packed bios_bootmac_t; 2078847d4f8Sderaadt 2081336e6b8Sdlg #define BOOTARG_DDB 8 2091336e6b8Sdlg typedef struct _bios_ddb { 2101336e6b8Sdlg int db_console; 2111336e6b8Sdlg } __packed bios_ddb_t; 2121336e6b8Sdlg 21358db950fSjsing #define BOOTARG_BOOTDUID 9 21458db950fSjsing typedef struct _bios_bootduid { 215331b9dcdSjsing u_char duid[8]; 21658db950fSjsing } __packed bios_bootduid_t; 217331b9dcdSjsing 2187ddb4085Sjsing #define BOOTARG_BOOTSR 10 2197ddb4085Sjsing #define BOOTSR_UUID_MAX 16 2207ddb4085Sjsing #define BOOTSR_CRYPTO_MAXKEYBYTES 32 2217ddb4085Sjsing typedef struct _bios_bootsr { 222*f721f560Skettenis uint8_t uuid[BOOTSR_UUID_MAX]; 223*f721f560Skettenis uint8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; 2247ddb4085Sjsing } __packed bios_bootsr_t; 2257ddb4085Sjsing 226c6a916fdSderaadt #define BOOTARG_EFIINFO 11 227c6a916fdSderaadt typedef struct _bios_efiinfo { 228c6a916fdSderaadt uint64_t config_acpi; 229c6a916fdSderaadt uint64_t config_smbios; 230c6a916fdSderaadt uint64_t fb_addr; 231c6a916fdSderaadt uint64_t fb_size; 232c6a916fdSderaadt uint32_t fb_height; 233c6a916fdSderaadt uint32_t fb_width; 234c6a916fdSderaadt uint32_t fb_pixpsl; /* pixels per scan line */ 235c6a916fdSderaadt uint32_t fb_red_mask; 236c6a916fdSderaadt uint32_t fb_green_mask; 237c6a916fdSderaadt uint32_t fb_blue_mask; 238c6a916fdSderaadt uint32_t fb_reserved_mask; 239c6a916fdSderaadt } __packed bios_efiinfo_t; 240c6a916fdSderaadt 2414a222fdfSjsg #define BOOTARG_UCODE 12 2424a222fdfSjsg typedef struct _bios_ucode { 2434a222fdfSjsg uint64_t uc_addr; 2444a222fdfSjsg uint64_t uc_size; 2454a222fdfSjsg } __packed bios_ucode_t; 2464a222fdfSjsg 2479251768bSmickey #if defined(_KERNEL) || defined (_STANDALONE) 2489251768bSmickey 2499251768bSmickey #ifdef _LOCORE 2509251768bSmickey #define DOINT(n) int $0x20+(n) 2519251768bSmickey #else 2529251768bSmickey #define DOINT(n) "int $0x20+(" #n ")" 2539251768bSmickey 2541b74ce2eSespie extern volatile struct BIOS_regs { 255*f721f560Skettenis uint32_t biosr_ax; 256*f721f560Skettenis uint32_t biosr_cx; 257*f721f560Skettenis uint32_t biosr_dx; 258*f721f560Skettenis uint32_t biosr_bx; 259*f721f560Skettenis uint32_t biosr_bp; 260*f721f560Skettenis uint32_t biosr_si; 261*f721f560Skettenis uint32_t biosr_di; 262*f721f560Skettenis uint32_t biosr_ds; 263*f721f560Skettenis uint32_t biosr_es; 264e7940adfSderaadt } __packed BIOS_regs; 26556427238Sweingart 26612f60ca1Smickey #ifdef _KERNEL 267bf9bb2acSmickey #include <machine/bus.h> 268bf9bb2acSmickey 26912f60ca1Smickey struct bios_attach_args { 270f63689adSderaadt char *ba_name; 271f63689adSderaadt u_int ba_func; 272f63689adSderaadt bus_space_tag_t ba_iot; 273f63689adSderaadt bus_space_tag_t ba_memt; 274b9a71df3Smickey union { 275cf55e9acSmickey void *_p; 276f63689adSderaadt bios_apminfo_t *_ba_apmp; 277f63689adSderaadt paddr_t _ba_acpipbase; 278b9a71df3Smickey } _; 27912f60ca1Smickey }; 28012f60ca1Smickey 281f63689adSderaadt #define ba_apmp _._ba_apmp 282f63689adSderaadt #define ba_acpipbase _._ba_acpipbase 283b9a71df3Smickey 284cc066b41Smickey struct consdev; 285bbada368Smickey struct proc; 286bbada368Smickey 287c4071fd1Smillert int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); 288cc066b41Smickey 289c4071fd1Smillert void bios_getopt(void); 29012f60ca1Smickey 2916661564bSmickey /* bios32.c */ 292*f721f560Skettenis int bios32_service(uint32_t, bios32_entry_t, bios32_entry_info_t); 29391d0ccc5Smlarkin void bios32_cleanup(void); 2946661564bSmickey 295dca6f5deSniklas extern u_int bootapiver; 29665b9873dSmickey extern bios_memmap_t *bios_memmap; 297c6a916fdSderaadt extern bios_efiinfo_t *bios_efiinfo; 2984a222fdfSjsg extern bios_ucode_t *bios_ucode; 299012ea299Sniklas extern void *bios_smpinfo; 300012ea299Sniklas extern bios_pciinfo_t *bios_pciinfo; 301dca6f5deSniklas 30212f60ca1Smickey #endif /* _KERNEL */ 30312f60ca1Smickey #endif /* _LOCORE */ 30412f60ca1Smickey #endif /* _KERNEL || _STANDALONE */ 30512f60ca1Smickey 3062fa72412Spirofti #endif /* _MACHINE_BIOSVAR_H_ */ 307