Home | History | Annotate | Line # | Download | only in efi
      1  1.3  riastrad /*	$NetBSD: efi.h,v 1.3 2023/05/22 16:27:49 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*-
      4  1.1  riastrad  * Copyright (c) 2004 Marcel Moolenaar
      5  1.1  riastrad  * All rights reserved.
      6  1.1  riastrad  *
      7  1.1  riastrad  * Redistribution and use in source and binary forms, with or without
      8  1.1  riastrad  * modification, are permitted provided that the following conditions
      9  1.1  riastrad  * are met:
     10  1.1  riastrad  *
     11  1.1  riastrad  * 1. Redistributions of source code must retain the above copyright
     12  1.1  riastrad  *    notice, this list of conditions and the following disclaimer.
     13  1.1  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  riastrad  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  riastrad  *    documentation and/or other materials provided with the distribution.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  1.1  riastrad  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  1.1  riastrad  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  1.1  riastrad  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  1.1  riastrad  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  1.1  riastrad  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  1.1  riastrad  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.1  riastrad  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  1.1  riastrad  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  1.1  riastrad  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  1.1  riastrad  */
     28  1.1  riastrad 
     29  1.1  riastrad #ifndef	_DEV_EFI_EFI_H_
     30  1.1  riastrad #define	_DEV_EFI_EFI_H_
     31  1.1  riastrad 
     32  1.1  riastrad /*
     33  1.1  riastrad  * Machine-independent UEFI protocol definitions.  Based on:
     34  1.1  riastrad  *
     35  1.1  riastrad  *	Unified Extensible Firmware Interface (UEFI) Specification,
     36  1.1  riastrad  *	Version 2.9, UEFI Forum, Inc., March 2021.
     37  1.1  riastrad  *
     38  1.1  riastrad  * https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf
     39  1.1  riastrad  */
     40  1.1  riastrad 
     41  1.2  riastrad #if defined(__i386__) || defined(__x86_64__)
     42  1.2  riastrad #define	EFIAPI	__attribute__((__ms_abi__))
     43  1.2  riastrad #else
     44  1.2  riastrad #define	EFIAPI	/* empty */
     45  1.2  riastrad #endif
     46  1.2  riastrad 
     47  1.3  riastrad #ifdef _LP64
     48  1.3  riastrad #define	EFIERR(x)		(0x8000000000000000 | (x))
     49  1.3  riastrad #else
     50  1.3  riastrad #define	EFIERR(x)		(0x80000000 | (x))
     51  1.3  riastrad #endif
     52  1.3  riastrad 
     53  1.3  riastrad #define	EFI_SUCCESS		0
     54  1.3  riastrad #define	EFI_INVALID_PARAMETER	EFIERR(2)
     55  1.3  riastrad #define	EFI_UNSUPPORTED		EFIERR(3)
     56  1.3  riastrad #define	EFI_BUFFER_TOO_SMALL	EFIERR(5)
     57  1.3  riastrad #define	EFI_DEVICE_ERROR	EFIERR(7)
     58  1.3  riastrad #define	EFI_WRITE_PROTECTED	EFIERR(8)
     59  1.3  riastrad #define	EFI_OUT_OF_RESOURCES	EFIERR(9)
     60  1.3  riastrad #define	EFI_NOT_FOUND		EFIERR(14)
     61  1.3  riastrad #define	EFI_SECURITY_VIOLATION	EFIERR(26)
     62  1.3  riastrad 
     63  1.1  riastrad enum efi_reset {
     64  1.1  riastrad 	EFI_RESET_COLD,
     65  1.1  riastrad 	EFI_RESET_WARM,
     66  1.1  riastrad 	EFI_RESET_SHUTDOWN,
     67  1.1  riastrad 	EFI_RESET_PLATFORM_SPECIFIC,
     68  1.1  riastrad };
     69  1.1  riastrad 
     70  1.1  riastrad typedef uint16_t	efi_char;
     71  1.1  riastrad typedef unsigned long efi_status;
     72  1.1  riastrad 
     73  1.1  riastrad struct efi_cfgtbl {
     74  1.1  riastrad 	struct uuid	ct_uuid;
     75  1.1  riastrad 	void		*ct_data;
     76  1.1  riastrad };
     77  1.1  riastrad 
     78  1.1  riastrad struct efi_md {
     79  1.1  riastrad 	uint32_t	md_type;
     80  1.1  riastrad #define	EFI_MD_TYPE_NULL	0
     81  1.1  riastrad #define	EFI_MD_TYPE_CODE	1	/* Loader text. */
     82  1.1  riastrad #define	EFI_MD_TYPE_DATA	2	/* Loader data. */
     83  1.1  riastrad #define	EFI_MD_TYPE_BS_CODE	3	/* Boot services text. */
     84  1.1  riastrad #define	EFI_MD_TYPE_BS_DATA	4	/* Boot services data. */
     85  1.1  riastrad #define	EFI_MD_TYPE_RT_CODE	5	/* Runtime services text. */
     86  1.1  riastrad #define	EFI_MD_TYPE_RT_DATA	6	/* Runtime services data. */
     87  1.1  riastrad #define	EFI_MD_TYPE_FREE	7	/* Unused/free memory. */
     88  1.1  riastrad #define	EFI_MD_TYPE_BAD		8	/* Bad memory */
     89  1.1  riastrad #define	EFI_MD_TYPE_RECLAIM	9	/* ACPI reclaimable memory. */
     90  1.1  riastrad #define	EFI_MD_TYPE_FIRMWARE	10	/* ACPI NV memory */
     91  1.1  riastrad #define	EFI_MD_TYPE_IOMEM	11	/* Memory-mapped I/O. */
     92  1.1  riastrad #define	EFI_MD_TYPE_IOPORT	12	/* I/O port space. */
     93  1.1  riastrad #define	EFI_MD_TYPE_PALCODE	13	/* PAL */
     94  1.1  riastrad #define	EFI_MD_TYPE_PMEM	14	/* Persistent memory. */
     95  1.1  riastrad 	uint32_t	__pad;
     96  1.1  riastrad 	uint64_t	md_phys;
     97  1.1  riastrad 	uint64_t	md_virt;
     98  1.1  riastrad 	uint64_t	md_pages;
     99  1.1  riastrad 	uint64_t	md_attr;
    100  1.1  riastrad #define	EFI_MD_ATTR_UC		0x0000000000000001UL
    101  1.1  riastrad #define	EFI_MD_ATTR_WC		0x0000000000000002UL
    102  1.1  riastrad #define	EFI_MD_ATTR_WT		0x0000000000000004UL
    103  1.1  riastrad #define	EFI_MD_ATTR_WB		0x0000000000000008UL
    104  1.1  riastrad #define	EFI_MD_ATTR_UCE		0x0000000000000010UL
    105  1.1  riastrad #define	EFI_MD_ATTR_WP		0x0000000000001000UL
    106  1.1  riastrad #define	EFI_MD_ATTR_RP		0x0000000000002000UL
    107  1.1  riastrad #define	EFI_MD_ATTR_XP		0x0000000000004000UL
    108  1.1  riastrad #define	EFI_MD_ATTR_NV		0x0000000000008000UL
    109  1.1  riastrad #define	EFI_MD_ATTR_MORE_RELIABLE 0x0000000000010000UL
    110  1.1  riastrad #define	EFI_MD_ATTR_RO		0x0000000000020000UL
    111  1.1  riastrad #define	EFI_MD_ATTR_SP		0x0000000000040000UL
    112  1.1  riastrad #define	EFI_MD_ATTR_CPU_CRYPTO	0x0000000000080000UL
    113  1.1  riastrad #define	EFI_MD_ATTR_RT		0x8000000000000000UL
    114  1.1  riastrad };
    115  1.1  riastrad 
    116  1.1  riastrad struct efi_tm {
    117  1.1  riastrad 	uint16_t	tm_year;		/* 1998 - 20XX */
    118  1.1  riastrad 	uint8_t		tm_mon;			/* 1 - 12 */
    119  1.1  riastrad 	uint8_t		tm_mday;		/* 1 - 31 */
    120  1.1  riastrad 	uint8_t		tm_hour;		/* 0 - 23 */
    121  1.1  riastrad 	uint8_t		tm_min;			/* 0 - 59 */
    122  1.1  riastrad 	uint8_t		tm_sec;			/* 0 - 59 */
    123  1.1  riastrad 	uint8_t		__pad1;
    124  1.1  riastrad 	uint32_t	tm_nsec;		/* 0 - 999,999,999 */
    125  1.1  riastrad 	int16_t		tm_tz;			/* -1440 to 1440 or 2047 */
    126  1.1  riastrad 	uint8_t		tm_dst;
    127  1.1  riastrad 	uint8_t		__pad2;
    128  1.1  riastrad };
    129  1.1  riastrad 
    130  1.1  riastrad struct efi_tmcap {
    131  1.1  riastrad 	uint32_t	tc_res;		/* 1e-6 parts per million */
    132  1.1  riastrad 	uint32_t	tc_prec;	/* hertz */
    133  1.1  riastrad 	uint8_t		tc_stz;		/* Set clears sub-second time */
    134  1.1  riastrad };
    135  1.1  riastrad 
    136  1.1  riastrad struct efi_tblhdr {
    137  1.1  riastrad 	uint64_t	th_sig;
    138  1.1  riastrad 	uint32_t	th_rev;
    139  1.1  riastrad 	uint32_t	th_hdrsz;
    140  1.1  riastrad 	uint32_t	th_crc32;
    141  1.1  riastrad 	uint32_t	__res;
    142  1.1  riastrad };
    143  1.1  riastrad 
    144  1.1  riastrad struct efi_rt {
    145  1.1  riastrad 	struct efi_tblhdr rt_hdr;
    146  1.2  riastrad 	efi_status	(*rt_gettime)(struct efi_tm *, struct efi_tmcap *)
    147  1.2  riastrad 			    EFIAPI;
    148  1.2  riastrad 	efi_status	(*rt_settime)(struct efi_tm *) EFIAPI;
    149  1.1  riastrad 	efi_status	(*rt_getwaketime)(uint8_t *, uint8_t *,
    150  1.2  riastrad 			    struct efi_tm *) EFIAPI;
    151  1.2  riastrad 	efi_status	(*rt_setwaketime)(uint8_t, struct efi_tm *) EFIAPI;
    152  1.1  riastrad 	efi_status	(*rt_setvirtual)(u_long, u_long, uint32_t,
    153  1.2  riastrad 			    struct efi_md *) EFIAPI;
    154  1.2  riastrad 	efi_status	(*rt_cvtptr)(u_long, void **) EFIAPI;
    155  1.1  riastrad 	efi_status	(*rt_getvar)(efi_char *, struct uuid *, uint32_t *,
    156  1.2  riastrad 			    u_long *, void *) EFIAPI;
    157  1.2  riastrad 	efi_status	(*rt_scanvar)(u_long *, efi_char *, struct uuid *)
    158  1.2  riastrad 			    EFIAPI;
    159  1.1  riastrad 	efi_status	(*rt_setvar)(efi_char *, struct uuid *, uint32_t,
    160  1.2  riastrad 			    u_long, void *) EFIAPI;
    161  1.2  riastrad 	efi_status	(*rt_gethicnt)(uint32_t *) EFIAPI;
    162  1.1  riastrad 	efi_status	(*rt_reset)(enum efi_reset, efi_status, u_long,
    163  1.2  riastrad 			    efi_char *) EFIAPI;
    164  1.1  riastrad };
    165  1.1  riastrad 
    166  1.1  riastrad struct efi_systbl {
    167  1.1  riastrad 	struct efi_tblhdr st_hdr;
    168  1.1  riastrad #define	EFI_SYSTBL_SIG	0x5453595320494249UL
    169  1.1  riastrad 	efi_char	*st_fwvendor;
    170  1.1  riastrad 	uint32_t	st_fwrev;
    171  1.1  riastrad #ifdef _LP64
    172  1.1  riastrad 	uint32_t	__pad;
    173  1.1  riastrad #endif
    174  1.1  riastrad 	void		*st_cin;
    175  1.1  riastrad 	void		*st_cinif;
    176  1.1  riastrad 	void		*st_cout;
    177  1.1  riastrad 	void		*st_coutif;
    178  1.1  riastrad 	void		*st_cerr;
    179  1.1  riastrad 	void		*st_cerrif;
    180  1.1  riastrad 	struct efi_rt	*st_rt;
    181  1.1  riastrad 	void		*st_bs;
    182  1.1  riastrad 	u_long		st_entries;
    183  1.1  riastrad 	struct efi_cfgtbl *st_cfgtbl;
    184  1.1  riastrad };
    185  1.1  riastrad #ifdef _LP64
    186  1.1  riastrad __CTASSERT(sizeof(struct efi_systbl) == 120);
    187  1.1  riastrad #else
    188  1.1  riastrad __CTASSERT(sizeof(struct efi_systbl) == 72);
    189  1.1  riastrad #endif
    190  1.1  riastrad 
    191  1.1  riastrad #endif	/* _DEV_EFI_EFI_H_ */
    192