1199767f8SToomas Soome /*- 2199767f8SToomas Soome * Copyright (c) 1997 Michael Smith 3199767f8SToomas Soome * Copyright (c) 1998 Jonathan Lemon 4199767f8SToomas Soome * All rights reserved. 5199767f8SToomas Soome * 6199767f8SToomas Soome * Redistribution and use in source and binary forms, with or without 7199767f8SToomas Soome * modification, are permitted provided that the following conditions 8199767f8SToomas Soome * are met: 9199767f8SToomas Soome * 1. Redistributions of source code must retain the above copyright 10199767f8SToomas Soome * notice, this list of conditions and the following disclaimer. 11199767f8SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 12199767f8SToomas Soome * notice, this list of conditions and the following disclaimer in the 13199767f8SToomas Soome * documentation and/or other materials provided with the distribution. 14199767f8SToomas Soome * 15199767f8SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16199767f8SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17199767f8SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18199767f8SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19199767f8SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20199767f8SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21199767f8SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22199767f8SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23199767f8SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24199767f8SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25199767f8SToomas Soome * SUCH DAMAGE. 26199767f8SToomas Soome * 27199767f8SToomas Soome * $FreeBSD$ 28199767f8SToomas Soome */ 29199767f8SToomas Soome 30199767f8SToomas Soome #ifndef _MACHINE_PC_BIOS_H_ 31199767f8SToomas Soome #define _MACHINE_PC_BIOS_H_ 32199767f8SToomas Soome 33*55fea89dSDan Cross /* 34*55fea89dSDan Cross * Signature structure for the BIOS32 Service Directory header 35199767f8SToomas Soome */ 36*55fea89dSDan Cross struct bios32_SDheader 37199767f8SToomas Soome { 38199767f8SToomas Soome u_int8_t sig[4]; 39199767f8SToomas Soome u_int32_t entry; 40199767f8SToomas Soome u_int8_t revision; 41199767f8SToomas Soome u_int8_t len; 42199767f8SToomas Soome u_int8_t cksum; 43199767f8SToomas Soome u_int8_t pad[5]; 44199767f8SToomas Soome }; 45199767f8SToomas Soome 46*55fea89dSDan Cross /* 47199767f8SToomas Soome * PnP BIOS presence structure 48199767f8SToomas Soome */ 49*55fea89dSDan Cross struct PnPBIOS_table 50199767f8SToomas Soome { 51199767f8SToomas Soome u_int8_t sig[4]; /* "$PnP */ 52199767f8SToomas Soome u_int8_t version; /* should be 0x10 */ 53199767f8SToomas Soome u_int8_t len; /* total structure length */ 54199767f8SToomas Soome u_int16_t control; /* BIOS feature flags */ 55199767f8SToomas Soome u_int8_t cksum; /* checksum */ 56199767f8SToomas Soome u_int32_t evflagaddr; /* address of event notificaton flag */ 57199767f8SToomas Soome u_int16_t rmentryoffset; /* real-mode entry offset */ 58199767f8SToomas Soome u_int16_t rmentryseg; /* segment */ 59199767f8SToomas Soome u_int16_t pmentryoffset; /* protected-mode entry offset */ 60199767f8SToomas Soome u_int32_t pmentrybase; /* segment base */ 61199767f8SToomas Soome u_int32_t oemdevid; /* motherboard EISA ID */ 62199767f8SToomas Soome u_int16_t rmbiosseg; /* real-mode BIOS segment */ 63199767f8SToomas Soome u_int32_t pmdataseg; /* protected-mode data segment */ 64199767f8SToomas Soome } __packed; 65199767f8SToomas Soome 66199767f8SToomas Soome /* 67199767f8SToomas Soome * PnP BIOS return codes 68199767f8SToomas Soome */ 69199767f8SToomas Soome #define PNP_SUCCESS 0x00 70199767f8SToomas Soome #define PNP_NOT_SET_STATICALLY 0x7f 71199767f8SToomas Soome #define PNP_UNKNOWN_FUNCTION 0x81 72199767f8SToomas Soome #define PNP_FUNCTION_NOT_SUPPORTED 0x82 73199767f8SToomas Soome #define PNP_INVALID_HANDLE 0x83 74199767f8SToomas Soome #define PNP_BAD_PARAMETER 0x84 75199767f8SToomas Soome #define PNP_SET_FAILED 0x85 76199767f8SToomas Soome #define PNP_EVENTS_NOT_PENDING 0x86 77199767f8SToomas Soome #define PNP_SYSTEM_NOT_DOCKED 0x87 78199767f8SToomas Soome #define PNP_NO_ISA_PNP_CARDS 0x88 79199767f8SToomas Soome #define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89 80199767f8SToomas Soome #define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a 81199767f8SToomas Soome #define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b 82199767f8SToomas Soome #define PNP_BUFFER_TOO_SMALL 0x8c 83199767f8SToomas Soome #define PNP_USE_ESCD_SUPPORT 0x8d 84199767f8SToomas Soome #define PNP_MESSAGE_NOT_SUPPORTED 0x8e 85199767f8SToomas Soome #define PNP_HARDWARE_ERROR 0x8f 86199767f8SToomas Soome 87199767f8SToomas Soome /* 88199767f8SToomas Soome * DMI return codes 89199767f8SToomas Soome */ 90199767f8SToomas Soome #define DMI_SUCCESS 0x00 91199767f8SToomas Soome #define DMI_UNKNOWN_FUNCTION 0x81 92199767f8SToomas Soome #define DMI_FUNCTION_NOT_SUPPORTED 0x82 93199767f8SToomas Soome #define DMI_INVALID_HANDLE 0x83 94199767f8SToomas Soome #define DMI_BAD_PARAMETER 0x84 95199767f8SToomas Soome #define DMI_INVALID_SUBFUNCTION 0x85 96199767f8SToomas Soome #define DMI_NO_CHANGE 0x86 97199767f8SToomas Soome #define DMI_ADD_STRUCTURE_FAILED 0x87 98199767f8SToomas Soome #define DMI_READ_ONLY 0x8d 99199767f8SToomas Soome #define DMI_LOCK_NOT_SUPPORTED 0x90 100199767f8SToomas Soome #define DMI_CURRENTLY_LOCKED 0x91 101199767f8SToomas Soome #define DMI_INVALID_LOCK 0x92 102199767f8SToomas Soome 103199767f8SToomas Soome /* 104199767f8SToomas Soome * format specifiers and defines for bios16() 105199767f8SToomas Soome * s = short (16 bits) 106199767f8SToomas Soome * i = int (32 bits) 107199767f8SToomas Soome * p = pointer (converted to seg:offset) 108199767f8SToomas Soome * C,D,U = selector (corresponding to code/data/utility segment) 109199767f8SToomas Soome */ 110199767f8SToomas Soome #define PNP_COUNT_DEVNODES "sppD", 0x00 111199767f8SToomas Soome #define PNP_GET_DEVNODE "sppsD", 0x01 112199767f8SToomas Soome #define PNP_SET_DEVNODE "sspsD", 0x02 113199767f8SToomas Soome #define PNP_GET_EVENT "spD", 0x03 114199767f8SToomas Soome #define PNP_SEND_MSG "ssD", 0x04 115199767f8SToomas Soome #define PNP_GET_DOCK_INFO "spD", 0x05 116199767f8SToomas Soome 117199767f8SToomas Soome #define PNP_SEL_PRIBOOT "ssiiisspD", 0x07 118199767f8SToomas Soome #define PNP_GET_PRIBOOT "sspppppD", 0x08 119199767f8SToomas Soome #define PNP_SET_RESINFO "spD", 0x09 120199767f8SToomas Soome #define PNP_GET_RESINFO "spD", 0x0A 121199767f8SToomas Soome #define PNP_GET_APM_ID "sppD", 0x0B 122199767f8SToomas Soome 123199767f8SToomas Soome #define PNP_GET_ISA_INFO "spD", 0x40 124199767f8SToomas Soome #define PNP_GET_ECSD_INFO "spppD", 0x41 125199767f8SToomas Soome #define PNP_READ_ESCD "spUD", 0x42 126199767f8SToomas Soome #define PNP_WRITE_ESCD "spUD", 0x43 127199767f8SToomas Soome 128199767f8SToomas Soome #define PNP_GET_DMI_INFO "spppppD", 0x50 129199767f8SToomas Soome #define PNP_GET_DMI_STRUCTURE "sppUD", 0x51 130199767f8SToomas Soome #define PNP_SET_DMI_STRUCTURE "sppsUD" 0x52 131199767f8SToomas Soome #define PNP_GET_DMI_CHANGE "spUD" 0x53 132199767f8SToomas Soome #define PNP_DMI_CONTROL "sspsUD" 0x54 133199767f8SToomas Soome #define PNP_GET_GPNV_INFO "sppppD" 0x55 134199767f8SToomas Soome #define PNP_READ_GPNV_DATA "ssppUD" 0x56 135199767f8SToomas Soome #define PNP_WRITE_GPNV_DATA "sspsUD" 0x57 136199767f8SToomas Soome 137199767f8SToomas Soome #define PNP_BOOT_CHECK "sp", 0x60 138199767f8SToomas Soome #define PNP_COUNT_IPL "sppp", 0x61 139199767f8SToomas Soome #define PNP_GET_BOOTPRI "spp", 0x62 140199767f8SToomas Soome #define PNP_SET_BOOTPRI "sp", 0x63 141199767f8SToomas Soome #define PNP_GET_LASTBOOT "sp", 0x64 142199767f8SToomas Soome #define PNP_GET_BOOTFIRST "sp", 0x65 143199767f8SToomas Soome #define PNP_SET_BOOTFIRST "sp", 0x66 144199767f8SToomas Soome 145199767f8SToomas Soome /* 146199767f8SToomas Soome * PCI BIOS functions 147199767f8SToomas Soome */ 148199767f8SToomas Soome #define PCIBIOS_BIOS_PRESENT 0xb101 149199767f8SToomas Soome #define PCIBIOS_READ_CONFIG_BYTE 0xb108 150199767f8SToomas Soome #define PCIBIOS_READ_CONFIG_WORD 0xb109 151199767f8SToomas Soome #define PCIBIOS_READ_CONFIG_DWORD 0xb10a 152199767f8SToomas Soome #define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b 153199767f8SToomas Soome #define PCIBIOS_WRITE_CONFIG_WORD 0xb10c 154199767f8SToomas Soome #define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d 155199767f8SToomas Soome #define PCIBIOS_GET_IRQ_ROUTING 0xb10e 156199767f8SToomas Soome #define PCIBIOS_ROUTE_INTERRUPT 0xb10f 157199767f8SToomas Soome 158199767f8SToomas Soome /* 159199767f8SToomas Soome * PCI interrupt routing table. 160199767f8SToomas Soome * 161199767f8SToomas Soome * $PIR in the BIOS segment contains a PIR_table 162*55fea89dSDan Cross * int 1a:b106 returns PIR_table in buffer at es:(e)di 163*55fea89dSDan Cross * int 1a:b18e returns PIR_table in buffer at es:(e)di 164199767f8SToomas Soome * int 1a:b406 returns es:di pointing to the BIOS PIR_table 165199767f8SToomas Soome */ 166*55fea89dSDan Cross struct PIR_header 167199767f8SToomas Soome { 168199767f8SToomas Soome int8_t ph_signature[4]; 169199767f8SToomas Soome u_int16_t ph_version; 170199767f8SToomas Soome u_int16_t ph_length; 171199767f8SToomas Soome u_int8_t ph_router_bus; 172199767f8SToomas Soome u_int8_t ph_router_dev_fn; 173199767f8SToomas Soome u_int16_t ph_pci_irqs; 174199767f8SToomas Soome u_int16_t ph_router_vendor; 175199767f8SToomas Soome u_int16_t ph_router_device; 176199767f8SToomas Soome u_int32_t ph_miniport; 177199767f8SToomas Soome u_int8_t ph_res[11]; 178199767f8SToomas Soome u_int8_t ph_checksum; 179199767f8SToomas Soome } __packed; 180199767f8SToomas Soome 181*55fea89dSDan Cross struct PIR_intpin 182199767f8SToomas Soome { 183199767f8SToomas Soome u_int8_t link; 184199767f8SToomas Soome u_int16_t irqs; 185199767f8SToomas Soome } __packed; 186199767f8SToomas Soome 187199767f8SToomas Soome struct PIR_entry 188199767f8SToomas Soome { 189199767f8SToomas Soome u_int8_t pe_bus; 190199767f8SToomas Soome u_int8_t pe_res1:3; 191199767f8SToomas Soome u_int8_t pe_device:5; 192199767f8SToomas Soome struct PIR_intpin pe_intpin[4]; 193199767f8SToomas Soome u_int8_t pe_slot; 194199767f8SToomas Soome u_int8_t pe_res3; 195199767f8SToomas Soome } __packed; 196199767f8SToomas Soome 197*55fea89dSDan Cross struct PIR_table 198199767f8SToomas Soome { 199199767f8SToomas Soome struct PIR_header pt_header; 200199767f8SToomas Soome struct PIR_entry pt_entry[0]; 201199767f8SToomas Soome } __packed; 202199767f8SToomas Soome 203199767f8SToomas Soome /* 204199767f8SToomas Soome * Int 15:E820 'SMAP' structure 205199767f8SToomas Soome */ 206199767f8SToomas Soome #define SMAP_SIG 0x534D4150 /* 'SMAP' */ 207199767f8SToomas Soome 208199767f8SToomas Soome #define SMAP_TYPE_MEMORY 1 209199767f8SToomas Soome #define SMAP_TYPE_RESERVED 2 210199767f8SToomas Soome #define SMAP_TYPE_ACPI_RECLAIM 3 211199767f8SToomas Soome #define SMAP_TYPE_ACPI_NVS 4 212199767f8SToomas Soome #define SMAP_TYPE_ACPI_ERROR 5 213199767f8SToomas Soome 214199767f8SToomas Soome #define SMAP_XATTR_ENABLED 0x00000001 215199767f8SToomas Soome #define SMAP_XATTR_NON_VOLATILE 0x00000002 216199767f8SToomas Soome #define SMAP_XATTR_MASK (SMAP_XATTR_ENABLED | SMAP_XATTR_NON_VOLATILE) 217199767f8SToomas Soome 218199767f8SToomas Soome struct bios_smap { 219199767f8SToomas Soome u_int64_t base; 220199767f8SToomas Soome u_int64_t length; 221199767f8SToomas Soome u_int32_t type; 222199767f8SToomas Soome } __packed; 223199767f8SToomas Soome 224199767f8SToomas Soome /* Structure extended to include extended attribute field in ACPI 3.0. */ 225199767f8SToomas Soome struct bios_smap_xattr { 226199767f8SToomas Soome u_int64_t base; 227199767f8SToomas Soome u_int64_t length; 228199767f8SToomas Soome u_int32_t type; 229199767f8SToomas Soome u_int32_t xattr; 230199767f8SToomas Soome } __packed; 231199767f8SToomas Soome 232199767f8SToomas Soome /* 233199767f8SToomas Soome * System Management BIOS 234199767f8SToomas Soome */ 235199767f8SToomas Soome #define SMBIOS_START 0xf0000 236199767f8SToomas Soome #define SMBIOS_STEP 0x10 237199767f8SToomas Soome #define SMBIOS_OFF 0 238199767f8SToomas Soome #define SMBIOS_LEN 4 239199767f8SToomas Soome #define SMBIOS_SIG "_SM_" 240199767f8SToomas Soome 241199767f8SToomas Soome struct smbios_eps { 242199767f8SToomas Soome uint8_t anchor_string[4]; /* '_SM_' */ 243199767f8SToomas Soome uint8_t checksum; 244199767f8SToomas Soome uint8_t length; 245199767f8SToomas Soome uint8_t major_version; 246199767f8SToomas Soome uint8_t minor_version; 247199767f8SToomas Soome uint16_t maximum_structure_size; 248199767f8SToomas Soome uint8_t entry_point_revision; 249199767f8SToomas Soome uint8_t formatted_area[5]; 250199767f8SToomas Soome uint8_t intermediate_anchor_string[5]; /* '_DMI_' */ 251199767f8SToomas Soome uint8_t intermediate_checksum; 252199767f8SToomas Soome uint16_t structure_table_length; 253199767f8SToomas Soome uint32_t structure_table_address; 254199767f8SToomas Soome uint16_t number_structures; 255199767f8SToomas Soome uint8_t BCD_revision; 256199767f8SToomas Soome }; 257199767f8SToomas Soome 258199767f8SToomas Soome struct smbios_structure_header { 259199767f8SToomas Soome uint8_t type; 260199767f8SToomas Soome uint8_t length; 261199767f8SToomas Soome uint16_t handle; 262199767f8SToomas Soome }; 263199767f8SToomas Soome 264199767f8SToomas Soome #ifdef _KERNEL 265199767f8SToomas Soome #define BIOS_PADDRTOVADDR(x) ((x) + KERNBASE) 266199767f8SToomas Soome #define BIOS_VADDRTOPADDR(x) ((x) - KERNBASE) 267199767f8SToomas Soome 268199767f8SToomas Soome struct bios_oem_signature { 269199767f8SToomas Soome char * anchor; /* search anchor string in BIOS memory */ 270199767f8SToomas Soome size_t offset; /* offset from anchor (may be negative) */ 271199767f8SToomas Soome size_t totlen; /* total length of BIOS string to copy */ 272199767f8SToomas Soome } __packed; 273199767f8SToomas Soome 274199767f8SToomas Soome struct bios_oem_range { 275199767f8SToomas Soome u_int from; /* shouldn't be below 0xe0000 */ 276199767f8SToomas Soome u_int to; /* shouldn't be above 0xfffff */ 277199767f8SToomas Soome } __packed; 278199767f8SToomas Soome 279199767f8SToomas Soome struct bios_oem { 280199767f8SToomas Soome struct bios_oem_range range; 281199767f8SToomas Soome struct bios_oem_signature signature[]; 282199767f8SToomas Soome } __packed; 283199767f8SToomas Soome 284199767f8SToomas Soome struct segment_info { 285199767f8SToomas Soome u_int base; 286199767f8SToomas Soome u_int limit; 287199767f8SToomas Soome }; 288199767f8SToomas Soome 289199767f8SToomas Soome #define BIOSCODE_FLAG 0x01 290199767f8SToomas Soome #define BIOSDATA_FLAG 0x02 291199767f8SToomas Soome #define BIOSUTIL_FLAG 0x04 292199767f8SToomas Soome #define BIOSARGS_FLAG 0x08 293199767f8SToomas Soome 294199767f8SToomas Soome struct bios_segments { 295199767f8SToomas Soome struct segment_info code32; /* 32-bit code (mandatory) */ 296199767f8SToomas Soome struct segment_info code16; /* 16-bit code */ 297199767f8SToomas Soome struct segment_info data; /* 16-bit data */ 298199767f8SToomas Soome struct segment_info util; /* 16-bit utility */ 299199767f8SToomas Soome struct segment_info args; /* 16-bit args */ 300199767f8SToomas Soome }; 301199767f8SToomas Soome 302199767f8SToomas Soome struct bios_regs { 303199767f8SToomas Soome u_int eax; 304199767f8SToomas Soome u_int ebx; 305199767f8SToomas Soome u_int ecx; 306199767f8SToomas Soome u_int edx; 307199767f8SToomas Soome u_int esi; 308199767f8SToomas Soome u_int edi; 309199767f8SToomas Soome }; 310199767f8SToomas Soome 311199767f8SToomas Soome struct bios_args { 312199767f8SToomas Soome u_int entry; /* entry point of routine */ 313199767f8SToomas Soome struct bios_regs r; 314199767f8SToomas Soome struct bios_segments seg; 315199767f8SToomas Soome }; 316199767f8SToomas Soome 317*55fea89dSDan Cross /* 318199767f8SToomas Soome * BIOS32 Service Directory entry. Caller supplies name, bios32_SDlookup 319199767f8SToomas Soome * fills in the rest of the details. 320199767f8SToomas Soome */ 321*55fea89dSDan Cross struct bios32_SDentry 322199767f8SToomas Soome { 323*55fea89dSDan Cross union 324199767f8SToomas Soome { 325199767f8SToomas Soome u_int8_t name[4]; /* service identifier */ 326199767f8SToomas Soome u_int32_t id; /* as a 32-bit value */ 327199767f8SToomas Soome } ident; 328199767f8SToomas Soome u_int32_t base; /* base of service */ 329199767f8SToomas Soome u_int32_t len; /* service length */ 330199767f8SToomas Soome u_int32_t entry; /* entrypoint offset from base */ 331199767f8SToomas Soome vm_offset_t ventry; /* entrypoint in kernel virtual segment */ 332199767f8SToomas Soome }; 333199767f8SToomas Soome 334199767f8SToomas Soome /* 335*55fea89dSDan Cross * Exported lookup results 336199767f8SToomas Soome */ 337199767f8SToomas Soome extern struct bios32_SDentry PCIbios; 338199767f8SToomas Soome 339199767f8SToomas Soome int bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen); 340199767f8SToomas Soome uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen, 341199767f8SToomas Soome int sigofs); 342199767f8SToomas Soome int bios16(struct bios_args *, char *, ...); 343199767f8SToomas Soome int bios16_call(struct bios_regs *, char *); 344199767f8SToomas Soome int bios32(struct bios_regs *, u_int, u_short); 345199767f8SToomas Soome int bios32_SDlookup(struct bios32_SDentry *ent); 346199767f8SToomas Soome void set_bios_selectors(struct bios_segments *, int); 347199767f8SToomas Soome 348199767f8SToomas Soome #endif 349199767f8SToomas Soome 350199767f8SToomas Soome #endif /* _MACHINE_PC_BIOS_H_ */ 351