1*199767f8SToomas Soome /*- 2*199767f8SToomas Soome * Copyright (c) 1997 Michael Smith 3*199767f8SToomas Soome * Copyright (c) 1998 Jonathan Lemon 4*199767f8SToomas Soome * All rights reserved. 5*199767f8SToomas Soome * 6*199767f8SToomas Soome * Redistribution and use in source and binary forms, with or without 7*199767f8SToomas Soome * modification, are permitted provided that the following conditions 8*199767f8SToomas Soome * are met: 9*199767f8SToomas Soome * 1. Redistributions of source code must retain the above copyright 10*199767f8SToomas Soome * notice, this list of conditions and the following disclaimer. 11*199767f8SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 12*199767f8SToomas Soome * notice, this list of conditions and the following disclaimer in the 13*199767f8SToomas Soome * documentation and/or other materials provided with the distribution. 14*199767f8SToomas Soome * 15*199767f8SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*199767f8SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*199767f8SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*199767f8SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*199767f8SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*199767f8SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*199767f8SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*199767f8SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*199767f8SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*199767f8SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*199767f8SToomas Soome * SUCH DAMAGE. 26*199767f8SToomas Soome * 27*199767f8SToomas Soome * $FreeBSD$ 28*199767f8SToomas Soome */ 29*199767f8SToomas Soome 30*199767f8SToomas Soome #ifndef _MACHINE_PC_BIOS_H_ 31*199767f8SToomas Soome #define _MACHINE_PC_BIOS_H_ 32*199767f8SToomas Soome 33*199767f8SToomas Soome /* 34*199767f8SToomas Soome * Signature structure for the BIOS32 Service Directory header 35*199767f8SToomas Soome */ 36*199767f8SToomas Soome struct bios32_SDheader 37*199767f8SToomas Soome { 38*199767f8SToomas Soome u_int8_t sig[4]; 39*199767f8SToomas Soome u_int32_t entry; 40*199767f8SToomas Soome u_int8_t revision; 41*199767f8SToomas Soome u_int8_t len; 42*199767f8SToomas Soome u_int8_t cksum; 43*199767f8SToomas Soome u_int8_t pad[5]; 44*199767f8SToomas Soome }; 45*199767f8SToomas Soome 46*199767f8SToomas Soome /* 47*199767f8SToomas Soome * PnP BIOS presence structure 48*199767f8SToomas Soome */ 49*199767f8SToomas Soome struct PnPBIOS_table 50*199767f8SToomas Soome { 51*199767f8SToomas Soome u_int8_t sig[4]; /* "$PnP */ 52*199767f8SToomas Soome u_int8_t version; /* should be 0x10 */ 53*199767f8SToomas Soome u_int8_t len; /* total structure length */ 54*199767f8SToomas Soome u_int16_t control; /* BIOS feature flags */ 55*199767f8SToomas Soome u_int8_t cksum; /* checksum */ 56*199767f8SToomas Soome u_int32_t evflagaddr; /* address of event notificaton flag */ 57*199767f8SToomas Soome u_int16_t rmentryoffset; /* real-mode entry offset */ 58*199767f8SToomas Soome u_int16_t rmentryseg; /* segment */ 59*199767f8SToomas Soome u_int16_t pmentryoffset; /* protected-mode entry offset */ 60*199767f8SToomas Soome u_int32_t pmentrybase; /* segment base */ 61*199767f8SToomas Soome u_int32_t oemdevid; /* motherboard EISA ID */ 62*199767f8SToomas Soome u_int16_t rmbiosseg; /* real-mode BIOS segment */ 63*199767f8SToomas Soome u_int32_t pmdataseg; /* protected-mode data segment */ 64*199767f8SToomas Soome } __packed; 65*199767f8SToomas Soome 66*199767f8SToomas Soome /* 67*199767f8SToomas Soome * PnP BIOS return codes 68*199767f8SToomas Soome */ 69*199767f8SToomas Soome #define PNP_SUCCESS 0x00 70*199767f8SToomas Soome #define PNP_NOT_SET_STATICALLY 0x7f 71*199767f8SToomas Soome #define PNP_UNKNOWN_FUNCTION 0x81 72*199767f8SToomas Soome #define PNP_FUNCTION_NOT_SUPPORTED 0x82 73*199767f8SToomas Soome #define PNP_INVALID_HANDLE 0x83 74*199767f8SToomas Soome #define PNP_BAD_PARAMETER 0x84 75*199767f8SToomas Soome #define PNP_SET_FAILED 0x85 76*199767f8SToomas Soome #define PNP_EVENTS_NOT_PENDING 0x86 77*199767f8SToomas Soome #define PNP_SYSTEM_NOT_DOCKED 0x87 78*199767f8SToomas Soome #define PNP_NO_ISA_PNP_CARDS 0x88 79*199767f8SToomas Soome #define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89 80*199767f8SToomas Soome #define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a 81*199767f8SToomas Soome #define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b 82*199767f8SToomas Soome #define PNP_BUFFER_TOO_SMALL 0x8c 83*199767f8SToomas Soome #define PNP_USE_ESCD_SUPPORT 0x8d 84*199767f8SToomas Soome #define PNP_MESSAGE_NOT_SUPPORTED 0x8e 85*199767f8SToomas Soome #define PNP_HARDWARE_ERROR 0x8f 86*199767f8SToomas Soome 87*199767f8SToomas Soome /* 88*199767f8SToomas Soome * DMI return codes 89*199767f8SToomas Soome */ 90*199767f8SToomas Soome #define DMI_SUCCESS 0x00 91*199767f8SToomas Soome #define DMI_UNKNOWN_FUNCTION 0x81 92*199767f8SToomas Soome #define DMI_FUNCTION_NOT_SUPPORTED 0x82 93*199767f8SToomas Soome #define DMI_INVALID_HANDLE 0x83 94*199767f8SToomas Soome #define DMI_BAD_PARAMETER 0x84 95*199767f8SToomas Soome #define DMI_INVALID_SUBFUNCTION 0x85 96*199767f8SToomas Soome #define DMI_NO_CHANGE 0x86 97*199767f8SToomas Soome #define DMI_ADD_STRUCTURE_FAILED 0x87 98*199767f8SToomas Soome #define DMI_READ_ONLY 0x8d 99*199767f8SToomas Soome #define DMI_LOCK_NOT_SUPPORTED 0x90 100*199767f8SToomas Soome #define DMI_CURRENTLY_LOCKED 0x91 101*199767f8SToomas Soome #define DMI_INVALID_LOCK 0x92 102*199767f8SToomas Soome 103*199767f8SToomas Soome /* 104*199767f8SToomas Soome * format specifiers and defines for bios16() 105*199767f8SToomas Soome * s = short (16 bits) 106*199767f8SToomas Soome * i = int (32 bits) 107*199767f8SToomas Soome * p = pointer (converted to seg:offset) 108*199767f8SToomas Soome * C,D,U = selector (corresponding to code/data/utility segment) 109*199767f8SToomas Soome */ 110*199767f8SToomas Soome #define PNP_COUNT_DEVNODES "sppD", 0x00 111*199767f8SToomas Soome #define PNP_GET_DEVNODE "sppsD", 0x01 112*199767f8SToomas Soome #define PNP_SET_DEVNODE "sspsD", 0x02 113*199767f8SToomas Soome #define PNP_GET_EVENT "spD", 0x03 114*199767f8SToomas Soome #define PNP_SEND_MSG "ssD", 0x04 115*199767f8SToomas Soome #define PNP_GET_DOCK_INFO "spD", 0x05 116*199767f8SToomas Soome 117*199767f8SToomas Soome #define PNP_SEL_PRIBOOT "ssiiisspD", 0x07 118*199767f8SToomas Soome #define PNP_GET_PRIBOOT "sspppppD", 0x08 119*199767f8SToomas Soome #define PNP_SET_RESINFO "spD", 0x09 120*199767f8SToomas Soome #define PNP_GET_RESINFO "spD", 0x0A 121*199767f8SToomas Soome #define PNP_GET_APM_ID "sppD", 0x0B 122*199767f8SToomas Soome 123*199767f8SToomas Soome #define PNP_GET_ISA_INFO "spD", 0x40 124*199767f8SToomas Soome #define PNP_GET_ECSD_INFO "spppD", 0x41 125*199767f8SToomas Soome #define PNP_READ_ESCD "spUD", 0x42 126*199767f8SToomas Soome #define PNP_WRITE_ESCD "spUD", 0x43 127*199767f8SToomas Soome 128*199767f8SToomas Soome #define PNP_GET_DMI_INFO "spppppD", 0x50 129*199767f8SToomas Soome #define PNP_GET_DMI_STRUCTURE "sppUD", 0x51 130*199767f8SToomas Soome #define PNP_SET_DMI_STRUCTURE "sppsUD" 0x52 131*199767f8SToomas Soome #define PNP_GET_DMI_CHANGE "spUD" 0x53 132*199767f8SToomas Soome #define PNP_DMI_CONTROL "sspsUD" 0x54 133*199767f8SToomas Soome #define PNP_GET_GPNV_INFO "sppppD" 0x55 134*199767f8SToomas Soome #define PNP_READ_GPNV_DATA "ssppUD" 0x56 135*199767f8SToomas Soome #define PNP_WRITE_GPNV_DATA "sspsUD" 0x57 136*199767f8SToomas Soome 137*199767f8SToomas Soome #define PNP_BOOT_CHECK "sp", 0x60 138*199767f8SToomas Soome #define PNP_COUNT_IPL "sppp", 0x61 139*199767f8SToomas Soome #define PNP_GET_BOOTPRI "spp", 0x62 140*199767f8SToomas Soome #define PNP_SET_BOOTPRI "sp", 0x63 141*199767f8SToomas Soome #define PNP_GET_LASTBOOT "sp", 0x64 142*199767f8SToomas Soome #define PNP_GET_BOOTFIRST "sp", 0x65 143*199767f8SToomas Soome #define PNP_SET_BOOTFIRST "sp", 0x66 144*199767f8SToomas Soome 145*199767f8SToomas Soome /* 146*199767f8SToomas Soome * PCI BIOS functions 147*199767f8SToomas Soome */ 148*199767f8SToomas Soome #define PCIBIOS_BIOS_PRESENT 0xb101 149*199767f8SToomas Soome #define PCIBIOS_READ_CONFIG_BYTE 0xb108 150*199767f8SToomas Soome #define PCIBIOS_READ_CONFIG_WORD 0xb109 151*199767f8SToomas Soome #define PCIBIOS_READ_CONFIG_DWORD 0xb10a 152*199767f8SToomas Soome #define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b 153*199767f8SToomas Soome #define PCIBIOS_WRITE_CONFIG_WORD 0xb10c 154*199767f8SToomas Soome #define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d 155*199767f8SToomas Soome #define PCIBIOS_GET_IRQ_ROUTING 0xb10e 156*199767f8SToomas Soome #define PCIBIOS_ROUTE_INTERRUPT 0xb10f 157*199767f8SToomas Soome 158*199767f8SToomas Soome /* 159*199767f8SToomas Soome * PCI interrupt routing table. 160*199767f8SToomas Soome * 161*199767f8SToomas Soome * $PIR in the BIOS segment contains a PIR_table 162*199767f8SToomas Soome * int 1a:b106 returns PIR_table in buffer at es:(e)di 163*199767f8SToomas Soome * int 1a:b18e returns PIR_table in buffer at es:(e)di 164*199767f8SToomas Soome * int 1a:b406 returns es:di pointing to the BIOS PIR_table 165*199767f8SToomas Soome */ 166*199767f8SToomas Soome struct PIR_header 167*199767f8SToomas Soome { 168*199767f8SToomas Soome int8_t ph_signature[4]; 169*199767f8SToomas Soome u_int16_t ph_version; 170*199767f8SToomas Soome u_int16_t ph_length; 171*199767f8SToomas Soome u_int8_t ph_router_bus; 172*199767f8SToomas Soome u_int8_t ph_router_dev_fn; 173*199767f8SToomas Soome u_int16_t ph_pci_irqs; 174*199767f8SToomas Soome u_int16_t ph_router_vendor; 175*199767f8SToomas Soome u_int16_t ph_router_device; 176*199767f8SToomas Soome u_int32_t ph_miniport; 177*199767f8SToomas Soome u_int8_t ph_res[11]; 178*199767f8SToomas Soome u_int8_t ph_checksum; 179*199767f8SToomas Soome } __packed; 180*199767f8SToomas Soome 181*199767f8SToomas Soome struct PIR_intpin 182*199767f8SToomas Soome { 183*199767f8SToomas Soome u_int8_t link; 184*199767f8SToomas Soome u_int16_t irqs; 185*199767f8SToomas Soome } __packed; 186*199767f8SToomas Soome 187*199767f8SToomas Soome struct PIR_entry 188*199767f8SToomas Soome { 189*199767f8SToomas Soome u_int8_t pe_bus; 190*199767f8SToomas Soome u_int8_t pe_res1:3; 191*199767f8SToomas Soome u_int8_t pe_device:5; 192*199767f8SToomas Soome struct PIR_intpin pe_intpin[4]; 193*199767f8SToomas Soome u_int8_t pe_slot; 194*199767f8SToomas Soome u_int8_t pe_res3; 195*199767f8SToomas Soome } __packed; 196*199767f8SToomas Soome 197*199767f8SToomas Soome struct PIR_table 198*199767f8SToomas Soome { 199*199767f8SToomas Soome struct PIR_header pt_header; 200*199767f8SToomas Soome struct PIR_entry pt_entry[0]; 201*199767f8SToomas Soome } __packed; 202*199767f8SToomas Soome 203*199767f8SToomas Soome /* 204*199767f8SToomas Soome * Int 15:E820 'SMAP' structure 205*199767f8SToomas Soome */ 206*199767f8SToomas Soome #define SMAP_SIG 0x534D4150 /* 'SMAP' */ 207*199767f8SToomas Soome 208*199767f8SToomas Soome #define SMAP_TYPE_MEMORY 1 209*199767f8SToomas Soome #define SMAP_TYPE_RESERVED 2 210*199767f8SToomas Soome #define SMAP_TYPE_ACPI_RECLAIM 3 211*199767f8SToomas Soome #define SMAP_TYPE_ACPI_NVS 4 212*199767f8SToomas Soome #define SMAP_TYPE_ACPI_ERROR 5 213*199767f8SToomas Soome 214*199767f8SToomas Soome #define SMAP_XATTR_ENABLED 0x00000001 215*199767f8SToomas Soome #define SMAP_XATTR_NON_VOLATILE 0x00000002 216*199767f8SToomas Soome #define SMAP_XATTR_MASK (SMAP_XATTR_ENABLED | SMAP_XATTR_NON_VOLATILE) 217*199767f8SToomas Soome 218*199767f8SToomas Soome struct bios_smap { 219*199767f8SToomas Soome u_int64_t base; 220*199767f8SToomas Soome u_int64_t length; 221*199767f8SToomas Soome u_int32_t type; 222*199767f8SToomas Soome } __packed; 223*199767f8SToomas Soome 224*199767f8SToomas Soome /* Structure extended to include extended attribute field in ACPI 3.0. */ 225*199767f8SToomas Soome struct bios_smap_xattr { 226*199767f8SToomas Soome u_int64_t base; 227*199767f8SToomas Soome u_int64_t length; 228*199767f8SToomas Soome u_int32_t type; 229*199767f8SToomas Soome u_int32_t xattr; 230*199767f8SToomas Soome } __packed; 231*199767f8SToomas Soome 232*199767f8SToomas Soome /* 233*199767f8SToomas Soome * System Management BIOS 234*199767f8SToomas Soome */ 235*199767f8SToomas Soome #define SMBIOS_START 0xf0000 236*199767f8SToomas Soome #define SMBIOS_STEP 0x10 237*199767f8SToomas Soome #define SMBIOS_OFF 0 238*199767f8SToomas Soome #define SMBIOS_LEN 4 239*199767f8SToomas Soome #define SMBIOS_SIG "_SM_" 240*199767f8SToomas Soome 241*199767f8SToomas Soome struct smbios_eps { 242*199767f8SToomas Soome uint8_t anchor_string[4]; /* '_SM_' */ 243*199767f8SToomas Soome uint8_t checksum; 244*199767f8SToomas Soome uint8_t length; 245*199767f8SToomas Soome uint8_t major_version; 246*199767f8SToomas Soome uint8_t minor_version; 247*199767f8SToomas Soome uint16_t maximum_structure_size; 248*199767f8SToomas Soome uint8_t entry_point_revision; 249*199767f8SToomas Soome uint8_t formatted_area[5]; 250*199767f8SToomas Soome uint8_t intermediate_anchor_string[5]; /* '_DMI_' */ 251*199767f8SToomas Soome uint8_t intermediate_checksum; 252*199767f8SToomas Soome uint16_t structure_table_length; 253*199767f8SToomas Soome uint32_t structure_table_address; 254*199767f8SToomas Soome uint16_t number_structures; 255*199767f8SToomas Soome uint8_t BCD_revision; 256*199767f8SToomas Soome }; 257*199767f8SToomas Soome 258*199767f8SToomas Soome struct smbios_structure_header { 259*199767f8SToomas Soome uint8_t type; 260*199767f8SToomas Soome uint8_t length; 261*199767f8SToomas Soome uint16_t handle; 262*199767f8SToomas Soome }; 263*199767f8SToomas Soome 264*199767f8SToomas Soome #ifdef _KERNEL 265*199767f8SToomas Soome #define BIOS_PADDRTOVADDR(x) ((x) + KERNBASE) 266*199767f8SToomas Soome #define BIOS_VADDRTOPADDR(x) ((x) - KERNBASE) 267*199767f8SToomas Soome 268*199767f8SToomas Soome struct bios_oem_signature { 269*199767f8SToomas Soome char * anchor; /* search anchor string in BIOS memory */ 270*199767f8SToomas Soome size_t offset; /* offset from anchor (may be negative) */ 271*199767f8SToomas Soome size_t totlen; /* total length of BIOS string to copy */ 272*199767f8SToomas Soome } __packed; 273*199767f8SToomas Soome 274*199767f8SToomas Soome struct bios_oem_range { 275*199767f8SToomas Soome u_int from; /* shouldn't be below 0xe0000 */ 276*199767f8SToomas Soome u_int to; /* shouldn't be above 0xfffff */ 277*199767f8SToomas Soome } __packed; 278*199767f8SToomas Soome 279*199767f8SToomas Soome struct bios_oem { 280*199767f8SToomas Soome struct bios_oem_range range; 281*199767f8SToomas Soome struct bios_oem_signature signature[]; 282*199767f8SToomas Soome } __packed; 283*199767f8SToomas Soome 284*199767f8SToomas Soome struct segment_info { 285*199767f8SToomas Soome u_int base; 286*199767f8SToomas Soome u_int limit; 287*199767f8SToomas Soome }; 288*199767f8SToomas Soome 289*199767f8SToomas Soome #define BIOSCODE_FLAG 0x01 290*199767f8SToomas Soome #define BIOSDATA_FLAG 0x02 291*199767f8SToomas Soome #define BIOSUTIL_FLAG 0x04 292*199767f8SToomas Soome #define BIOSARGS_FLAG 0x08 293*199767f8SToomas Soome 294*199767f8SToomas Soome struct bios_segments { 295*199767f8SToomas Soome struct segment_info code32; /* 32-bit code (mandatory) */ 296*199767f8SToomas Soome struct segment_info code16; /* 16-bit code */ 297*199767f8SToomas Soome struct segment_info data; /* 16-bit data */ 298*199767f8SToomas Soome struct segment_info util; /* 16-bit utility */ 299*199767f8SToomas Soome struct segment_info args; /* 16-bit args */ 300*199767f8SToomas Soome }; 301*199767f8SToomas Soome 302*199767f8SToomas Soome struct bios_regs { 303*199767f8SToomas Soome u_int eax; 304*199767f8SToomas Soome u_int ebx; 305*199767f8SToomas Soome u_int ecx; 306*199767f8SToomas Soome u_int edx; 307*199767f8SToomas Soome u_int esi; 308*199767f8SToomas Soome u_int edi; 309*199767f8SToomas Soome }; 310*199767f8SToomas Soome 311*199767f8SToomas Soome struct bios_args { 312*199767f8SToomas Soome u_int entry; /* entry point of routine */ 313*199767f8SToomas Soome struct bios_regs r; 314*199767f8SToomas Soome struct bios_segments seg; 315*199767f8SToomas Soome }; 316*199767f8SToomas Soome 317*199767f8SToomas Soome /* 318*199767f8SToomas Soome * BIOS32 Service Directory entry. Caller supplies name, bios32_SDlookup 319*199767f8SToomas Soome * fills in the rest of the details. 320*199767f8SToomas Soome */ 321*199767f8SToomas Soome struct bios32_SDentry 322*199767f8SToomas Soome { 323*199767f8SToomas Soome union 324*199767f8SToomas Soome { 325*199767f8SToomas Soome u_int8_t name[4]; /* service identifier */ 326*199767f8SToomas Soome u_int32_t id; /* as a 32-bit value */ 327*199767f8SToomas Soome } ident; 328*199767f8SToomas Soome u_int32_t base; /* base of service */ 329*199767f8SToomas Soome u_int32_t len; /* service length */ 330*199767f8SToomas Soome u_int32_t entry; /* entrypoint offset from base */ 331*199767f8SToomas Soome vm_offset_t ventry; /* entrypoint in kernel virtual segment */ 332*199767f8SToomas Soome }; 333*199767f8SToomas Soome 334*199767f8SToomas Soome /* 335*199767f8SToomas Soome * Exported lookup results 336*199767f8SToomas Soome */ 337*199767f8SToomas Soome extern struct bios32_SDentry PCIbios; 338*199767f8SToomas Soome 339*199767f8SToomas Soome int bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen); 340*199767f8SToomas Soome uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen, 341*199767f8SToomas Soome int sigofs); 342*199767f8SToomas Soome int bios16(struct bios_args *, char *, ...); 343*199767f8SToomas Soome int bios16_call(struct bios_regs *, char *); 344*199767f8SToomas Soome int bios32(struct bios_regs *, u_int, u_short); 345*199767f8SToomas Soome int bios32_SDlookup(struct bios32_SDentry *ent); 346*199767f8SToomas Soome void set_bios_selectors(struct bios_segments *, int); 347*199767f8SToomas Soome 348*199767f8SToomas Soome #endif 349*199767f8SToomas Soome 350*199767f8SToomas Soome #endif /* _MACHINE_PC_BIOS_H_ */ 351