127822Smsmith/*- 227822Smsmith * Copyright (c) 1997 Michael Smith 349197Smsmith * Copyright (c) 1998 Jonathan Lemon 427822Smsmith * All rights reserved. 527822Smsmith * 627822Smsmith * Redistribution and use in source and binary forms, with or without 727822Smsmith * modification, are permitted provided that the following conditions 827822Smsmith * are met: 927822Smsmith * 1. Redistributions of source code must retain the above copyright 1027822Smsmith * notice, this list of conditions and the following disclaimer. 1127822Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1227822Smsmith * notice, this list of conditions and the following disclaimer in the 1327822Smsmith * documentation and/or other materials provided with the distribution. 1427822Smsmith * 1527822Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1627822Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1727822Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1827822Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1927822Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2027822Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2127822Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2227822Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2327822Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2427822Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2527822Smsmith * SUCH DAMAGE. 2627822Smsmith * 2750477Speter * $FreeBSD$ 2827822Smsmith */ 2927822Smsmith 30130040Sphk#ifndef _MACHINE_PC_BIOS_H_ 31130040Sphk#define _MACHINE_PC_BIOS_H_ 32130040Sphk 3327822Smsmith/* 3427822Smsmith * Signature structure for the BIOS32 Service Directory header 3527822Smsmith */ 3627822Smsmithstruct bios32_SDheader 3727822Smsmith{ 3827822Smsmith u_int8_t sig[4]; 3927822Smsmith u_int32_t entry; 4027822Smsmith u_int8_t revision; 4127822Smsmith u_int8_t len; 4227822Smsmith u_int8_t cksum; 4327822Smsmith u_int8_t pad[5]; 4427822Smsmith}; 4527822Smsmith 4627822Smsmith/* 4749953Smsmith * PnP BIOS presence structure 4849953Smsmith */ 4949953Smsmithstruct PnPBIOS_table 5049953Smsmith{ 5149953Smsmith u_int8_t sig[4]; /* "$PnP */ 5249953Smsmith u_int8_t version; /* should be 0x10 */ 5349953Smsmith u_int8_t len; /* total structure length */ 5449953Smsmith u_int16_t control; /* BIOS feature flags */ 5549953Smsmith u_int8_t cksum; /* checksum */ 5649953Smsmith u_int32_t evflagaddr; /* address of event notificaton flag */ 5749953Smsmith u_int16_t rmentryoffset; /* real-mode entry offset */ 5849953Smsmith u_int16_t rmentryseg; /* segment */ 5949953Smsmith u_int16_t pmentryoffset; /* protected-mode entry offset */ 6049953Smsmith u_int32_t pmentrybase; /* segment base */ 6149953Smsmith u_int32_t oemdevid; /* motherboard EISA ID */ 6249953Smsmith u_int16_t rmbiosseg; /* real-mode BIOS segment */ 6349953Smsmith u_int32_t pmdataseg; /* protected-mode data segment */ 64103870Salfred} __packed; 6549953Smsmith 6649197Smsmith/* 6749953Smsmith * PnP BIOS return codes 6849953Smsmith */ 6949953Smsmith#define PNP_SUCCESS 0x00 7049953Smsmith#define PNP_NOT_SET_STATICALLY 0x7f 7149953Smsmith#define PNP_UNKNOWN_FUNCTION 0x81 72241027Sjhb#define PNP_FUNCTION_NOT_SUPPORTED 0x82 7349953Smsmith#define PNP_INVALID_HANDLE 0x83 7449953Smsmith#define PNP_BAD_PARAMETER 0x84 7549953Smsmith#define PNP_SET_FAILED 0x85 7649953Smsmith#define PNP_EVENTS_NOT_PENDING 0x86 7749953Smsmith#define PNP_SYSTEM_NOT_DOCKED 0x87 7849953Smsmith#define PNP_NO_ISA_PNP_CARDS 0x88 7949953Smsmith#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89 8049953Smsmith#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a 8149953Smsmith#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b 8249953Smsmith#define PNP_BUFFER_TOO_SMALL 0x8c 8349953Smsmith#define PNP_USE_ESCD_SUPPORT 0x8d 8449953Smsmith#define PNP_MESSAGE_NOT_SUPPORTED 0x8e 8549953Smsmith#define PNP_HARDWARE_ERROR 0x8f 8649953Smsmith 8749953Smsmith/* 8849953Smsmith * DMI return codes 8949953Smsmith */ 9049953Smsmith#define DMI_SUCCESS 0x00 9149953Smsmith#define DMI_UNKNOWN_FUNCTION 0x81 9249953Smsmith#define DMI_FUNCTION_NOT_SUPPORTED 0x82 9349953Smsmith#define DMI_INVALID_HANDLE 0x83 9449953Smsmith#define DMI_BAD_PARAMETER 0x84 9549953Smsmith#define DMI_INVALID_SUBFUNCTION 0x85 9649953Smsmith#define DMI_NO_CHANGE 0x86 9749953Smsmith#define DMI_ADD_STRUCTURE_FAILED 0x87 9849953Smsmith#define DMI_READ_ONLY 0x8d 9949953Smsmith#define DMI_LOCK_NOT_SUPPORTED 0x90 10049953Smsmith#define DMI_CURRENTLY_LOCKED 0x91 10149953Smsmith#define DMI_INVALID_LOCK 0x92 10249953Smsmith 10349953Smsmith/* 10449197Smsmith * format specifiers and defines for bios16() 10549197Smsmith * s = short (16 bits) 10649197Smsmith * i = int (32 bits) 10749197Smsmith * p = pointer (converted to seg:offset) 10849197Smsmith * C,D,U = selector (corresponding to code/data/utility segment) 10949197Smsmith */ 11049197Smsmith#define PNP_COUNT_DEVNODES "sppD", 0x00 11149197Smsmith#define PNP_GET_DEVNODE "sppsD", 0x01 11282845Syokota#define PNP_SET_DEVNODE "sspsD", 0x02 11349197Smsmith#define PNP_GET_EVENT "spD", 0x03 11449197Smsmith#define PNP_SEND_MSG "ssD", 0x04 11549197Smsmith#define PNP_GET_DOCK_INFO "spD", 0x05 11649197Smsmith 11749197Smsmith#define PNP_SEL_PRIBOOT "ssiiisspD", 0x07 11849197Smsmith#define PNP_GET_PRIBOOT "sspppppD", 0x08 11949197Smsmith#define PNP_SET_RESINFO "spD", 0x09 12049197Smsmith#define PNP_GET_RESINFO "spD", 0x0A 12149197Smsmith#define PNP_GET_APM_ID "sppD", 0x0B 12249197Smsmith 12349197Smsmith#define PNP_GET_ISA_INFO "spD", 0x40 12449197Smsmith#define PNP_GET_ECSD_INFO "spppD", 0x41 12549197Smsmith#define PNP_READ_ESCD "spUD", 0x42 12649197Smsmith#define PNP_WRITE_ESCD "spUD", 0x43 12749197Smsmith 12849197Smsmith#define PNP_GET_DMI_INFO "spppppD", 0x50 12949953Smsmith#define PNP_GET_DMI_STRUCTURE "sppUD", 0x51 13049953Smsmith#define PNP_SET_DMI_STRUCTURE "sppsUD" 0x52 13149953Smsmith#define PNP_GET_DMI_CHANGE "spUD" 0x53 13249953Smsmith#define PNP_DMI_CONTROL "sspsUD" 0x54 13349953Smsmith#define PNP_GET_GPNV_INFO "sppppD" 0x55 13449953Smsmith#define PNP_READ_GPNV_DATA "ssppUD" 0x56 13549953Smsmith#define PNP_WRITE_GPNV_DATA "sspsUD" 0x57 13649197Smsmith 13749197Smsmith#define PNP_BOOT_CHECK "sp", 0x60 13849197Smsmith#define PNP_COUNT_IPL "sppp", 0x61 13949197Smsmith#define PNP_GET_BOOTPRI "spp", 0x62 14049197Smsmith#define PNP_SET_BOOTPRI "sp", 0x63 14149197Smsmith#define PNP_GET_LASTBOOT "sp", 0x64 14249197Smsmith#define PNP_GET_BOOTFIRST "sp", 0x65 14349197Smsmith#define PNP_SET_BOOTFIRST "sp", 0x66 14449197Smsmith 14559294Smsmith/* 14659294Smsmith * PCI BIOS functions 14759294Smsmith */ 14882035Simp#define PCIBIOS_BIOS_PRESENT 0xb101 14959294Smsmith#define PCIBIOS_READ_CONFIG_BYTE 0xb108 15059294Smsmith#define PCIBIOS_READ_CONFIG_WORD 0xb109 15159294Smsmith#define PCIBIOS_READ_CONFIG_DWORD 0xb10a 15259294Smsmith#define PCIBIOS_WRITE_CONFIG_BYTE 0xb10b 15359294Smsmith#define PCIBIOS_WRITE_CONFIG_WORD 0xb10c 15459294Smsmith#define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d 15567310Smsmith#define PCIBIOS_GET_IRQ_ROUTING 0xb10e 15667310Smsmith#define PCIBIOS_ROUTE_INTERRUPT 0xb10f 15759294Smsmith 15866489Smsmith/* 15967223Simp * PCI interrupt routing table. 16067223Simp * 16167223Simp * $PIR in the BIOS segment contains a PIR_table 16267223Simp * int 1a:b106 returns PIR_table in buffer at es:(e)di 16367223Simp * int 1a:b18e returns PIR_table in buffer at es:(e)di 16467223Simp * int 1a:b406 returns es:di pointing to the BIOS PIR_table 16567223Simp */ 16667223Simpstruct PIR_header 16767223Simp{ 16867223Simp int8_t ph_signature[4]; 16967223Simp u_int16_t ph_version; 17067223Simp u_int16_t ph_length; 17167223Simp u_int8_t ph_router_bus; 17267223Simp u_int8_t ph_router_dev_fn; 17367223Simp u_int16_t ph_pci_irqs; 17467223Simp u_int16_t ph_router_vendor; 17567223Simp u_int16_t ph_router_device; 17667223Simp u_int32_t ph_miniport; 17767223Simp u_int8_t ph_res[11]; 17867223Simp u_int8_t ph_checksum; 179103870Salfred} __packed; 18067223Simp 18167223Simpstruct PIR_intpin 18267223Simp{ 18367223Simp u_int8_t link; 18467223Simp u_int16_t irqs; 185103870Salfred} __packed; 18667223Simp 18767223Simpstruct PIR_entry 18867223Simp{ 18967223Simp u_int8_t pe_bus; 19067223Simp u_int8_t pe_res1:3; 19167223Simp u_int8_t pe_device:5; 19267223Simp struct PIR_intpin pe_intpin[4]; 19367223Simp u_int8_t pe_slot; 19467223Simp u_int8_t pe_res3; 195103870Salfred} __packed; 19667223Simp 19767223Simpstruct PIR_table 19867223Simp{ 19967223Simp struct PIR_header pt_header; 20067223Simp struct PIR_entry pt_entry[0]; 201103870Salfred} __packed; 20267223Simp 20367223Simp/* 20466489Smsmith * Int 15:E820 'SMAP' structure 20566489Smsmith */ 20666489Smsmith#define SMAP_SIG 0x534D4150 /* 'SMAP' */ 207173118Sjhb 208173118Sjhb#define SMAP_TYPE_MEMORY 1 209173118Sjhb#define SMAP_TYPE_RESERVED 2 210173118Sjhb#define SMAP_TYPE_ACPI_RECLAIM 3 211173118Sjhb#define SMAP_TYPE_ACPI_NVS 4 212173118Sjhb#define SMAP_TYPE_ACPI_ERROR 5 213173118Sjhb 214191111Sjkim#define SMAP_XATTR_ENABLED 0x00000001 215191111Sjkim#define SMAP_XATTR_NON_VOLATILE 0x00000002 216191111Sjkim#define SMAP_XATTR_MASK (SMAP_XATTR_ENABLED | SMAP_XATTR_NON_VOLATILE) 217191111Sjkim 21866489Smsmithstruct bios_smap { 21966489Smsmith u_int64_t base; 22066489Smsmith u_int64_t length; 22166489Smsmith u_int32_t type; 222103870Salfred} __packed; 223130040Sphk 224272913Sjhb/* Structure extended to include extended attribute field in ACPI 3.0. */ 225272913Sjhbstruct bios_smap_xattr { 226272913Sjhb u_int64_t base; 227272913Sjhb u_int64_t length; 228272913Sjhb u_int32_t type; 229272913Sjhb u_int32_t xattr; 230272913Sjhb} __packed; 231272913Sjhb 232241027Sjhb/* 233241027Sjhb * System Management BIOS 234241027Sjhb */ 235241027Sjhb#define SMBIOS_START 0xf0000 236241027Sjhb#define SMBIOS_STEP 0x10 237241027Sjhb#define SMBIOS_OFF 0 238241027Sjhb#define SMBIOS_LEN 4 239241027Sjhb#define SMBIOS_SIG "_SM_" 240241027Sjhb 241241027Sjhbstruct smbios_eps { 242241027Sjhb uint8_t anchor_string[4]; /* '_SM_' */ 243241027Sjhb uint8_t checksum; 244241027Sjhb uint8_t length; 245241027Sjhb uint8_t major_version; 246241027Sjhb uint8_t minor_version; 247241027Sjhb uint16_t maximum_structure_size; 248241027Sjhb uint8_t entry_point_revision; 249241027Sjhb uint8_t formatted_area[5]; 250241027Sjhb uint8_t intermediate_anchor_string[5]; /* '_DMI_' */ 251241027Sjhb uint8_t intermediate_checksum; 252241027Sjhb uint16_t structure_table_length; 253241027Sjhb uint32_t structure_table_address; 254241027Sjhb uint16_t number_structures; 255241027Sjhb uint8_t BCD_revision; 256241027Sjhb}; 257241027Sjhb 258241027Sjhbstruct smbios_structure_header { 259241027Sjhb uint8_t type; 260241027Sjhb uint8_t length; 261241027Sjhb uint16_t handle; 262241027Sjhb}; 263241027Sjhb 264241027Sjhb#ifdef _KERNEL 265241027Sjhb#define BIOS_PADDRTOVADDR(x) ((x) + KERNBASE) 266241027Sjhb#define BIOS_VADDRTOPADDR(x) ((x) - KERNBASE) 267241027Sjhb 268148231Sphkstruct bios_oem_signature { 269148231Sphk char * anchor; /* search anchor string in BIOS memory */ 270148231Sphk size_t offset; /* offset from anchor (may be negative) */ 271148231Sphk size_t totlen; /* total length of BIOS string to copy */ 272148231Sphk} __packed; 273241027Sjhb 274148231Sphkstruct bios_oem_range { 275148231Sphk u_int from; /* shouldn't be below 0xe0000 */ 276148231Sphk u_int to; /* shouldn't be above 0xfffff */ 277148231Sphk} __packed; 278241027Sjhb 279148231Sphkstruct bios_oem { 280148231Sphk struct bios_oem_range range; 281148231Sphk struct bios_oem_signature signature[]; 282148231Sphk} __packed; 283130040Sphk 284241027Sjhbstruct segment_info { 285241027Sjhb u_int base; 286241027Sjhb u_int limit; 287241027Sjhb}; 288130040Sphk 289241027Sjhb#define BIOSCODE_FLAG 0x01 290241027Sjhb#define BIOSDATA_FLAG 0x02 291241027Sjhb#define BIOSUTIL_FLAG 0x04 292241027Sjhb#define BIOSARGS_FLAG 0x08 293148231Sphk 294241027Sjhbstruct bios_segments { 295241027Sjhb struct segment_info code32; /* 32-bit code (mandatory) */ 296241027Sjhb struct segment_info code16; /* 16-bit code */ 297241027Sjhb struct segment_info data; /* 16-bit data */ 298241027Sjhb struct segment_info util; /* 16-bit utility */ 299241027Sjhb struct segment_info args; /* 16-bit args */ 300241027Sjhb}; 301241027Sjhb 302241027Sjhbstruct bios_regs { 303241027Sjhb u_int eax; 304241027Sjhb u_int ebx; 305241027Sjhb u_int ecx; 306241027Sjhb u_int edx; 307241027Sjhb u_int esi; 308241027Sjhb u_int edi; 309241027Sjhb}; 310241027Sjhb 311241027Sjhbstruct bios_args { 312241027Sjhb u_int entry; /* entry point of routine */ 313241027Sjhb struct bios_regs r; 314241027Sjhb struct bios_segments seg; 315241027Sjhb}; 316241027Sjhb 317241027Sjhb/* 318241027Sjhb * BIOS32 Service Directory entry. Caller supplies name, bios32_SDlookup 319241027Sjhb * fills in the rest of the details. 320241027Sjhb */ 321241027Sjhbstruct bios32_SDentry 322241027Sjhb{ 323241027Sjhb union 324241027Sjhb { 325241027Sjhb u_int8_t name[4]; /* service identifier */ 326241027Sjhb u_int32_t id; /* as a 32-bit value */ 327241027Sjhb } ident; 328241027Sjhb u_int32_t base; /* base of service */ 329241027Sjhb u_int32_t len; /* service length */ 330241027Sjhb u_int32_t entry; /* entrypoint offset from base */ 331241027Sjhb vm_offset_t ventry; /* entrypoint in kernel virtual segment */ 332241027Sjhb}; 333241027Sjhb 334241027Sjhb/* 335241027Sjhb * Exported lookup results 336241027Sjhb */ 337241027Sjhbextern struct bios32_SDentry PCIbios; 338241027Sjhb 339241027Sjhbint bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen); 340241027Sjhbuint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen, 341241027Sjhb int sigofs); 342241027Sjhbint bios16(struct bios_args *, char *, ...); 343241027Sjhbint bios16_call(struct bios_regs *, char *); 344241027Sjhbint bios32(struct bios_regs *, u_int, u_short); 345241027Sjhbint bios32_SDlookup(struct bios32_SDentry *ent); 346241027Sjhbvoid set_bios_selectors(struct bios_segments *, int); 347241027Sjhb 348241027Sjhb#endif 349241027Sjhb 350130040Sphk#endif /* _MACHINE_PC_BIOS_H_ */ 351