bios.h revision 302408
15483Swollman/*-
25483Swollman * Copyright (c) 1997 Michael Smith
35483Swollman * Copyright (c) 1998 Jonathan Lemon
45483Swollman * All rights reserved.
55483Swollman *
65483Swollman * Redistribution and use in source and binary forms, with or without
75483Swollman * modification, are permitted provided that the following conditions
85483Swollman * are met:
95483Swollman * 1. Redistributions of source code must retain the above copyright
105483Swollman *    notice, this list of conditions and the following disclaimer.
115483Swollman * 2. Redistributions in binary form must reproduce the above copyright
12263142Seadler *    notice, this list of conditions and the following disclaimer in the
135483Swollman *    documentation and/or other materials provided with the distribution.
145483Swollman *
155483Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
165483Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
175483Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
185483Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
195483Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
205483Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
215483Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
225483Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
235483Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
245483Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
255483Swollman * SUCH DAMAGE.
265483Swollman *
275483Swollman * $FreeBSD: stable/11/sys/i386/include/pc/bios.h 270828 2014-08-29 21:25:47Z jhb $
285483Swollman */
2967662Snik
305483Swollman#ifndef _MACHINE_PC_BIOS_H_
315483Swollman#define _MACHINE_PC_BIOS_H_
325483Swollman
335483Swollman/*
345483Swollman * Signature structure for the BIOS32 Service Directory header
3569341Sru */
3667662Snikstruct bios32_SDheader
3767662Snik{
3867662Snik    u_int8_t	sig[4];
3967662Snik    u_int32_t	entry;
405483Swollman    u_int8_t	revision;
4167662Snik    u_int8_t	len;
425483Swollman    u_int8_t	cksum;
435483Swollman    u_int8_t	pad[5];
445483Swollman};
455483Swollman
465483Swollman/*
475483Swollman * PnP BIOS presence structure
485483Swollman */
495483Swollmanstruct PnPBIOS_table
505483Swollman{
5197109Sru    u_int8_t	sig[4];			/* "$PnP */
525483Swollman    u_int8_t	version;		/* should be 0x10 */
535483Swollman    u_int8_t	len;    		/* total structure length */
545483Swollman    u_int16_t	control;		/* BIOS feature flags */
555483Swollman    u_int8_t	cksum;			/* checksum */
565483Swollman    u_int32_t	evflagaddr;		/* address of event notificaton flag */
575483Swollman    u_int16_t	rmentryoffset;		/* real-mode entry offset */
5897109Sru    u_int16_t	rmentryseg;		/*                 segment */
5967662Snik    u_int16_t	pmentryoffset;		/* protected-mode entry offset */
605483Swollman    u_int32_t	pmentrybase;		/*                segment base */
615483Swollman    u_int32_t	oemdevid;		/* motherboard EISA ID */
625483Swollman    u_int16_t	rmbiosseg;		/* real-mode BIOS segment */
635483Swollman    u_int32_t	pmdataseg;		/* protected-mode data segment */
6497109Sru} __packed;
6567662Snik
665483Swollman/*
675483Swollman * PnP BIOS return codes
685483Swollman */
695483Swollman#define PNP_SUCCESS				0x00
7097109Sru#define PNP_NOT_SET_STATICALLY			0x7f
7167662Snik#define PNP_UNKNOWN_FUNCTION			0x81
725483Swollman#define PNP_FUNCTION_NOT_SUPPORTED		0x82
735483Swollman#define PNP_INVALID_HANDLE			0x83
745483Swollman#define PNP_BAD_PARAMETER			0x84
755483Swollman#define PNP_SET_FAILED				0x85
765483Swollman#define PNP_EVENTS_NOT_PENDING			0x86
775483Swollman#define PNP_SYSTEM_NOT_DOCKED			0x87
785483Swollman#define PNP_NO_ISA_PNP_CARDS			0x88
7997109Sru#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
8067662Snik#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY	0x8a
815483Swollman#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
825483Swollman#define PNP_BUFFER_TOO_SMALL			0x8c
8367662Snik#define PNP_USE_ESCD_SUPPORT			0x8d
8467662Snik#define PNP_MESSAGE_NOT_SUPPORTED		0x8e
8567662Snik#define PNP_HARDWARE_ERROR			0x8f
8667662Snik
875483Swollman/*
885483Swollman * DMI return codes
895483Swollman */
905483Swollman#define DMI_SUCCESS				0x00
915483Swollman#define DMI_UNKNOWN_FUNCTION			0x81
925483Swollman#define DMI_FUNCTION_NOT_SUPPORTED		0x82
935483Swollman#define DMI_INVALID_HANDLE			0x83
945483Swollman#define DMI_BAD_PARAMETER			0x84
955483Swollman#define DMI_INVALID_SUBFUNCTION			0x85
965483Swollman#define DMI_NO_CHANGE				0x86
975483Swollman#define DMI_ADD_STRUCTURE_FAILED		0x87
985483Swollman#define DMI_READ_ONLY				0x8d
995483Swollman#define DMI_LOCK_NOT_SUPPORTED			0x90
10097109Sru#define DMI_CURRENTLY_LOCKED			0x91
10167662Snik#define DMI_INVALID_LOCK			0x92
1025483Swollman
1035483Swollman/*
1045483Swollman * format specifiers and defines for bios16()
1055483Swollman *     s	= short (16 bits)
1065483Swollman *     i	= int (32 bits)
10767662Snik *     p	= pointer (converted to seg:offset)
1085483Swollman *     C,D,U 	= selector (corresponding to code/data/utility segment)
1095483Swollman */
1105483Swollman#define PNP_COUNT_DEVNODES	"sppD",		0x00
1115483Swollman#define PNP_GET_DEVNODE		"sppsD",	0x01
1125483Swollman#define PNP_SET_DEVNODE		"sspsD",	0x02
11397109Sru#define PNP_GET_EVENT		"spD",		0x03
11497109Sru#define PNP_SEND_MSG		"ssD",		0x04
11567662Snik#define PNP_GET_DOCK_INFO	"spD",		0x05
1165483Swollman
1175483Swollman#define PNP_SEL_PRIBOOT		"ssiiisspD",	0x07
1185483Swollman#define PNP_GET_PRIBOOT		"sspppppD",	0x08
1195483Swollman#define PNP_SET_RESINFO		"spD",		0x09
1205483Swollman#define PNP_GET_RESINFO		"spD",		0x0A
1215483Swollman#define PNP_GET_APM_ID		"sppD",		0x0B
1225483Swollman
1235483Swollman#define PNP_GET_ISA_INFO	"spD",		0x40
1245483Swollman#define PNP_GET_ECSD_INFO	"spppD",	0x41
1255483Swollman#define PNP_READ_ESCD		"spUD",		0x42
1265483Swollman#define PNP_WRITE_ESCD		"spUD",		0x43
1275483Swollman
1285483Swollman#define PNP_GET_DMI_INFO	"spppppD",	0x50
1295483Swollman#define PNP_GET_DMI_STRUCTURE	"sppUD",	0x51
13067662Snik#define PNP_SET_DMI_STRUCTURE	"sppsUD"	0x52
1315483Swollman#define PNP_GET_DMI_CHANGE	"spUD"		0x53
1325483Swollman#define PNP_DMI_CONTROL		"sspsUD"	0x54
1335483Swollman#define PNP_GET_GPNV_INFO	"sppppD"	0x55
1345483Swollman#define PNP_READ_GPNV_DATA	"ssppUD"	0x56
13597109Sru#define PNP_WRITE_GPNV_DATA	"sspsUD"	0x57
13667662Snik
1375483Swollman#define PNP_BOOT_CHECK		"sp",		0x60
1385483Swollman#define PNP_COUNT_IPL		"sppp",		0x61
13967662Snik#define PNP_GET_BOOTPRI		"spp",		0x62
14067662Snik#define PNP_SET_BOOTPRI		"sp",		0x63
14167662Snik#define PNP_GET_LASTBOOT	"sp",		0x64
14267662Snik#define PNP_GET_BOOTFIRST	"sp",		0x65
1435483Swollman#define PNP_SET_BOOTFIRST	"sp",		0x66
1445483Swollman
1455483Swollman/*
14667662Snik * PCI BIOS functions
1475483Swollman */
1485483Swollman#define PCIBIOS_BIOS_PRESENT		0xb101
14967662Snik#define PCIBIOS_READ_CONFIG_BYTE	0xb108
15067662Snik#define PCIBIOS_READ_CONFIG_WORD	0xb109
15167662Snik#define PCIBIOS_READ_CONFIG_DWORD	0xb10a
15267662Snik#define PCIBIOS_WRITE_CONFIG_BYTE	0xb10b
1535483Swollman#define PCIBIOS_WRITE_CONFIG_WORD	0xb10c
1545483Swollman#define PCIBIOS_WRITE_CONFIG_DWORD	0xb10d
1555483Swollman#define PCIBIOS_GET_IRQ_ROUTING		0xb10e
1565483Swollman#define PCIBIOS_ROUTE_INTERRUPT		0xb10f
15767662Snik
1585483Swollman/*
1595483Swollman * PCI interrupt routing table.
1605483Swollman *
1615483Swollman * $PIR in the BIOS segment contains a PIR_table
16297109Sru * int 1a:b106 returns PIR_table in buffer at es:(e)di
16367662Snik * int 1a:b18e returns PIR_table in buffer at es:(e)di
1645483Swollman * int 1a:b406 returns es:di pointing to the BIOS PIR_table
1655483Swollman */
1665483Swollmanstruct PIR_header
1675483Swollman{
16897109Sru    int8_t	ph_signature[4];
16967662Snik    u_int16_t	ph_version;
1705483Swollman    u_int16_t	ph_length;
1715483Swollman    u_int8_t	ph_router_bus;
1725483Swollman    u_int8_t	ph_router_dev_fn;
1735483Swollman    u_int16_t	ph_pci_irqs;
1745483Swollman    u_int16_t	ph_router_vendor;
17597109Sru    u_int16_t	ph_router_device;
17667662Snik    u_int32_t	ph_miniport;
1775483Swollman    u_int8_t	ph_res[11];
1785483Swollman    u_int8_t	ph_checksum;
1795483Swollman} __packed;
1805483Swollman
1815483Swollmanstruct PIR_intpin
18267662Snik{
1835483Swollman    u_int8_t	link;
1845483Swollman    u_int16_t	irqs;
18567662Snik} __packed;
18667662Snik
18767662Snikstruct PIR_entry
18867662Snik{
1895483Swollman    u_int8_t		pe_bus;
1905483Swollman    u_int8_t		pe_res1:3;
1915483Swollman    u_int8_t		pe_device:5;
1925483Swollman    struct PIR_intpin	pe_intpin[4];
1935483Swollman    u_int8_t	pe_slot;
1945483Swollman    u_int8_t	pe_res3;
1955483Swollman} __packed;
1965483Swollman
19767662Snikstruct PIR_table
19867662Snik{
19967662Snik    struct PIR_header	pt_header;
20067662Snik    struct PIR_entry	pt_entry[0];
2015483Swollman} __packed;
2025483Swollman
2035483Swollman/*
20467662Snik * Int 15:E820 'SMAP' structure
2055483Swollman */
2065483Swollman#define SMAP_SIG	0x534D4150			/* 'SMAP' */
20767662Snik
20867662Snik#define	SMAP_TYPE_MEMORY	1
20967662Snik#define	SMAP_TYPE_RESERVED	2
21067662Snik#define	SMAP_TYPE_ACPI_RECLAIM	3
2115483Swollman#define	SMAP_TYPE_ACPI_NVS	4
2125483Swollman#define	SMAP_TYPE_ACPI_ERROR	5
2135483Swollman
21467662Snik#define	SMAP_XATTR_ENABLED	0x00000001
2155483Swollman#define	SMAP_XATTR_NON_VOLATILE	0x00000002
2165483Swollman#define	SMAP_XATTR_MASK		(SMAP_XATTR_ENABLED | SMAP_XATTR_NON_VOLATILE)
21767662Snik
21867662Snikstruct bios_smap {
21967662Snik    u_int64_t	base;
22067662Snik    u_int64_t	length;
2215483Swollman    u_int32_t	type;
2225483Swollman} __packed;
22367662Snik
2245483Swollman/* Structure extended to include extended attribute field in ACPI 3.0. */
2255483Swollmanstruct bios_smap_xattr {
22667662Snik    u_int64_t	base;
22767662Snik    u_int64_t	length;
22867662Snik    u_int32_t	type;
22967662Snik    u_int32_t	xattr;
2305483Swollman} __packed;
2315483Swollman
2325483Swollman/*
23367662Snik * System Management BIOS
2345483Swollman */
2355483Swollman#define	SMBIOS_START	0xf0000
23667662Snik#define	SMBIOS_STEP	0x10
23767662Snik#define	SMBIOS_OFF	0
23867662Snik#define	SMBIOS_LEN	4
23967662Snik#define	SMBIOS_SIG	"_SM_"
2405483Swollman
2415483Swollmanstruct smbios_eps {
2425483Swollman	uint8_t		anchor_string[4];		/* '_SM_' */
24367662Snik	uint8_t		checksum;
2445483Swollman	uint8_t		length;
2455483Swollman	uint8_t		major_version;
24667662Snik	uint8_t		minor_version;
24767662Snik	uint16_t	maximum_structure_size;
24867662Snik	uint8_t		entry_point_revision;
24967662Snik	uint8_t		formatted_area[5];
2505483Swollman	uint8_t		intermediate_anchor_string[5];	/* '_DMI_' */
2515483Swollman	uint8_t		intermediate_checksum;
25267662Snik	uint16_t	structure_table_length;
2535483Swollman	uint32_t	structure_table_address;
2545483Swollman	uint16_t	number_structures;
25567662Snik	uint8_t		BCD_revision;
25667662Snik};
25767662Snik
25867662Snikstruct smbios_structure_header {
2595483Swollman	uint8_t		type;
2605483Swollman	uint8_t		length;
2615483Swollman	uint16_t	handle;
26267662Snik};
2635483Swollman
2645483Swollman#ifdef _KERNEL
26567662Snik#define BIOS_PADDRTOVADDR(x)	((x) + KERNBASE)
26667662Snik#define BIOS_VADDRTOPADDR(x)	((x) - KERNBASE)
26767662Snik
26867662Snikstruct bios_oem_signature {
2695483Swollman	char * anchor;		/* search anchor string in BIOS memory */
2705483Swollman	size_t offset;		/* offset from anchor (may be negative) */
2715483Swollman	size_t totlen;		/* total length of BIOS string to copy */
2725483Swollman} __packed;
27367662Snik
27423384Swoschstruct bios_oem_range {
27523384Swosch	u_int from;		/* shouldn't be below 0xe0000 */
27667662Snik	u_int to;		/* shouldn't be above 0xfffff */
27767662Snik} __packed;
27867662Snik
27967662Snikstruct bios_oem {
28023384Swosch	struct bios_oem_range range;
28123384Swosch	struct bios_oem_signature signature[];
28223384Swosch} __packed;
28323384Swosch
28423384Swoschstruct segment_info {
28523384Swosch	u_int	base;
286	u_int	limit;
287};
288
289#define BIOSCODE_FLAG	0x01
290#define BIOSDATA_FLAG	0x02
291#define BIOSUTIL_FLAG	0x04
292#define BIOSARGS_FLAG	0x08
293
294struct bios_segments {
295	struct	segment_info code32;		/* 32-bit code (mandatory) */
296	struct	segment_info code16;		/* 16-bit code */
297	struct	segment_info data;		/* 16-bit data */
298	struct	segment_info util;		/* 16-bit utility */
299	struct	segment_info args;		/* 16-bit args */
300};
301
302struct bios_regs {
303	u_int	eax;
304	u_int	ebx;
305	u_int	ecx;
306	u_int	edx;
307	u_int	esi;
308	u_int	edi;
309};
310
311struct bios_args {
312	u_int	entry;				/* entry point of routine */
313	struct	bios_regs r;
314	struct	bios_segments seg;
315};
316
317/*
318 * BIOS32 Service Directory entry.  Caller supplies name, bios32_SDlookup
319 * fills in the rest of the details.
320 */
321struct bios32_SDentry
322{
323    union
324    {
325	u_int8_t	name[4];	/* service identifier */
326	u_int32_t	id;		/* as a 32-bit value */
327    } ident;
328    u_int32_t	base;			/* base of service */
329    u_int32_t	len;			/* service length */
330    u_int32_t	entry;			/* entrypoint offset from base */
331    vm_offset_t	ventry;			/* entrypoint in kernel virtual segment */
332};
333
334/*
335 * Exported lookup results
336 */
337extern struct bios32_SDentry	PCIbios;
338
339int	bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen);
340uint32_t bios_sigsearch(uint32_t start, u_char *sig, int siglen, int paralen,
341	    int sigofs);
342int	bios16(struct bios_args *, char *, ...);
343int	bios16_call(struct bios_regs *, char *);
344int	bios32(struct bios_regs *, u_int, u_short);
345int	bios32_SDlookup(struct bios32_SDentry *ent);
346void	set_bios_selectors(struct bios_segments *, int);
347
348#endif
349
350#endif /* _MACHINE_PC_BIOS_H_ */
351