alcyone/SDK/INC/EFI/efidef.h
Quinn Stephens 5c52adf492 [SDK] Big update
Signed-off-by: Quinn Stephens <quinn@osmora.org>
2025-06-11 20:00:34 -04:00

376 lines
8.3 KiB
C

/*++
Copyright (c) 2024-2025, Quinn Stephens.
Provided under the BSD 3-Clause license.
Module Name:
efidef.h
Abstract:
Provides basic EFI type/structure definitions.
--*/
#ifndef _EFIDEF_H
#define _EFIDEF_H
#pragma pack(1)
#ifndef VOID
#define VOID void
#endif
#ifndef CONST
#define CONST const
#endif
#ifndef VOLATILE
#define VOLATILE volatile
#endif
//
// Decorators to show parameter usage.
// IN - Argument passed into routine.
// OUT - Pointed-to value set by routine.
// OPTIONAL - Argument is not required.
//
#ifndef IN
#define IN
#define OUT
#define OPTIONAL
#endif
#ifndef NULL
#if defined(__cplusplus)
#if __cplusplus >= 201103L
#define NULL nullptr
#else
#define NULL 0
#endif
#else
#define NULL ((VOID *) 0)
#endif
#endif
#ifndef TRUE
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || defined(__cplusplus)
#define TRUE true
#define FALSE false
#else
#define TRUE ((BOOLEAN) 1)
#define FALSE ((BOOLEAN) 0)
#endif
#endif
#ifndef FORCEINLINE
#if defined(_MSC_EXTENSIONS)
#define FORCEINLINE __forceinline
#elif defined(__clang__) || defined(__GNUC__)
#define FORCEINLINE __attribute__((always_inline))
#else
#define FORCEINLINE static inline
#endif
#endif
//
// Error code helpers.
//
#define EFIERR(e) (EFI_ERROR_MASK | e)
#define EFIERR_OEM(e) (EFI_ERROR_MASK_OEM | e)
//
// Unsigned integer types.
//
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
typedef uint64_t UINT64;
//
// Signed integer types.
//
typedef int8_t INT8;
typedef int16_t INT16;
typedef int32_t INT32;
typedef int64_t INT64;
//
// Boolean types.
//
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || defined(__cplusplus)
typedef bool BOOLEAN;
#else
typedef UINT8 BOOLEAN;
#endif
//
// Character types.
//
typedef UINT8 CHAR8;
typedef UINT16 CHAR16;
//
// Miscellaneous types.
//
typedef UINTN EFI_STATUS;
typedef UINT64 EFI_LBA;
typedef UINTN EFI_TPL;
typedef VOID *EFI_HANDLE;
typedef VOID *EFI_EVENT;
//
// Static assertion helper.
//
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201103L)
#define STATIC_ASSERT static_assert
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define STATIC_ASSERT _Static_assert
#else
#warning Static assertion not available. Compilation problems may not be detected!
#define STATIC_ASSERT(expression, message)
#endif
//
// Ensure that types are of the correct size.
//
STATIC_ASSERT(sizeof(UINT8) == 1, "sizeof(UINT8) must equal 1");
STATIC_ASSERT(sizeof(UINT16) == 2, "sizeof(UINT16) must equal 2");
STATIC_ASSERT(sizeof(UINT32) == 4, "sizeof(UINT32) must equal 4");
STATIC_ASSERT(sizeof(UINT64) == 8, "sizeof(UINT64) must equal 8");
STATIC_ASSERT(sizeof(INT8) == 1, "sizeof(INT8) must equal 1");
STATIC_ASSERT(sizeof(INT16) == 2, "sizeof(INT16) must equal 2");
STATIC_ASSERT(sizeof(INT32) == 4, "sizeof(INT32) must equal 4");
STATIC_ASSERT(sizeof(INT64) == 8, "sizeof(INT64) must equal 8");
STATIC_ASSERT(sizeof(BOOLEAN) == 1, "sizeof(BOOLEAN) must equal 1");
STATIC_ASSERT(sizeof(CHAR8) == 1, "sizeof(CHAR8) must equal 1");
STATIC_ASSERT(sizeof(CHAR16) == 2, "sizeof(CHAR16) must equal 2");
//
// GUID (Globally Unique IDentifier).
//
typedef struct {
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8 Data4[8];
} EFI_GUID;
//
// Time.
//
typedef struct {
UINT16 Year;
UINT8 Month;
UINT8 Day;
UINT8 Hour;
UINT8 Minute;
UINT8 Second;
UINT8 Pad1;
UINT32 Nanosecond;
INT16 Timezone;
UINT8 Daylight;
UINT8 Pad2;
} EFI_TIME;
//
// For EFI_TIME.Daylight.
//
#define EFI_TIME_ADJUST_DAYLIGHT 0x01
#define EFI_TIME_IN_DAYLIGHT 0x02
//
// For EFI_TIME.TimeZone.
//
#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
//
// Network addresses.
//
typedef struct {
UINT8 Addr[4];
} EFI_IPv4_ADDRESS;
typedef struct {
UINT8 Addr[16];
} EFI_IPv6_ADDRESS;
typedef union {
UINT32 Addr[4];
EFI_IPv4_ADDRESS v4;
EFI_IPv6_ADDRESS v6;
} EFI_IP_ADDRESS;
typedef struct {
UINT8 Addr[32];
} EFI_MAC_ADDRESS;
typedef struct {
UINT8 Address[6];
} BLUETOOTH_ADDRESS;
typedef struct {
UINT8 Address[6];
UINT8 Type;
} BLUETOOTH_LE_ADDRESS;
//
// Memory addresses.
//
typedef UINT64 EFI_PHYSICAL_ADDRESS;
typedef UINT64 EFI_VIRTUAL_ADDRESS;
//
// Memory allocation methods.
//
typedef enum {
//
// Allocate range at any address.
//
AllocateAnyPages,
//
// Allocate range ending at a specific address.
//
AllocateMaxAddress,
//
// Allocate range starting at a specific address.
//
AllocateAddress,
//
// For bounds checking.
//
MaxAllocateType
} EFI_ALLOCATE_TYPE;
//
// Memory types.
//
typedef enum {
EfiReservedMemoryType,
EfiLoaderCode,
EfiLoaderData,
EfiBootServicesCode,
EfiBootServicesData,
EfiRuntimeServicesCode,
EfiRuntimeServicesData,
EfiConventionalMemory,
EfiUnusableMemory,
EfiACPIReclaimMemory,
EfiACPIMemoryNVS,
EfiMemoryMappedIO,
EfiMemoryMappedIOPortSpace,
EfiPalCode,
EfiPersistentMemory,
EfiUnacceptedMemoryType,
EfiMaxMemoryType,
MEMORY_TYPE_OEM_RESERVED_MIN = 0x70000000,
MEMORY_TYPE_OEM_RESERVED_MAX = 0x7FFFFFFF,
MEMORY_TYPE_OS_RESERVED_MIN = 0x80000000,
MEMORY_TYPE_OS_RESERVED_MAX = 0xFFFFFFFF
} EFI_MEMORY_TYPE;
//
// Memory caching attributes.
//
#define EFI_MEMORY_UC 0x0000000000000001
#define EFI_MEMORY_WC 0x0000000000000002
#define EFI_MEMORY_WT 0x0000000000000004
#define EFI_MEMORY_WB 0x0000000000000008
#define EFI_MEMORY_UCE 0x0000000000000010
//
// Memory protection attributes.
//
#define EFI_MEMORY_WP 0x0000000000001000
#define EFI_MEMORY_RP 0x0000000000002000
#define EFI_MEMORY_XP 0x0000000000004000
#define EFI_MEMORY_RO 0x0000000000020000
//
// Miscellaneous memory attributes.
//
#define EFI_MEMORY_NV 0x0000000000008000
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000
#define EFI_MEMORY_SP 0x0000000000040000
#define EFI_MEMORY_CPU_CRYPTO 0x0000000000080000
#define EFI_MEMORY_HOT_PLUGGABLE 0x0000000000100000
#define EFI_MEMORY_ISA_VALID 0x4000000000000000
#define EFI_MEMORY_RUNTIME 0x8000000000000000
//
// Memory type/attribute masks.
//
#define EFI_MEMORY_ISA_MASK 0x0FFFF00000000000
#define EFI_CACHE_ATTRIBUTE_MASK (EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB | EFI_MEMORY_UCE | EFI_MEMORY_WP)
#define EFI_MEMORY_ACCESS_MASK (EFI_MEMORY_RP | EFI_MEMORY_XP | EFI_MEMORY_RO)
#define EFI_MEMORY_ATTRIBUTE_MASK (EFI_MEMORY_ACCESS_MASK | EFI_MEMORY_SP | EFI_MEMORY_CPU_CRYPTO)
//
// Memory descriptor.
//
#define EFI_MEMORY_DESCRIPTOR_VERSION 1
typedef struct {
//
// Memory type (EFI_MEMORY_TYPE) of the region.
//
UINT32 Type;
UINT32 Pad;
//
// Must be aligned on an EFI_PAGE_SIZE-byte boundary.
// Must not be above 0xFFFFFFFFFFFFF000.
//
EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_VIRTUAL_ADDRESS VirtualStart;
//
// Number of EFI_PAGE_SIZE-byte pages.
// Must not be zero.
//
UINT64 NumberOfPages;
//
// Capabilities of the memory region.
//
UINT64 Attribute;
} EFI_MEMORY_DESCRIPTOR;
//
// International language.
//
typedef CHAR8 ISO_639_2;
#define ISO_639_2_ENTRY_SIZE 3
//
// Memory units & address helpers.
//
#define EFI_PAGE_SIZE 4096
#define EFI_PAGE_MASK 0xFFF
#define EFI_PAGE_SHIFT 12
#define EFI_SIZE_TO_PAGES(s) (((s) >> EFI_PAGE_SHIFT) + ((s) & EFI_PAGE_MASK ? 1:0))
//
// OS indications.
//
#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001
#define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION 0x0000000000000002
#define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED 0x0000000000000004
#define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED 0x0000000000000008
#define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED 0x0000000000000010
#define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY 0x0000000000000040
#define EFI_OS_INDICATIONS_JSON_CONFIG_DATA_REFRESH 0x0000000000000080
#pragma pack()
#endif /* !_EFIDEF_H */