1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #ifndef __EFI_TYPES_H__ 19 #define __EFI_TYPES_H__ 20 21 typedef void* EfiHandle; 22 typedef uint8_t char8_t; 23 typedef uint16_t char16_t; 24 typedef void* EfiEvent; 25 typedef uint64_t EfiPhysicalAddr; 26 typedef uint64_t EfiVirtualAddr; 27 28 typedef struct EfiTableHeader { 29 uint64_t signature; 30 uint32_t revision; 31 uint32_t header_size; 32 uint32_t crc32; 33 uint32_t reserved; 34 } EfiTableHeader; 35 36 typedef struct EfiGuid { 37 uint32_t data1; 38 uint16_t data2; 39 uint16_t data3; 40 uint8_t data4[8]; 41 } EfiGuid; 42 43 typedef struct EfiMemoryAttributesTableHeader { 44 uint32_t version; 45 uint32_t number_of_entries; 46 uint32_t descriptor_size; 47 uint32_t reserved; 48 } EfiMemoryAttributesTableHeader; 49 50 typedef enum EFI_MEMORY_ATTRIBUTE : uint64_t { 51 EMA_UC = 0x0000000000000001, /* uncached */ 52 EMA_WC = 0x0000000000000002, /* write-coalescing */ 53 EMA_WT = 0x0000000000000004, /* write-through */ 54 EMA_WB = 0x0000000000000008, /* write-back */ 55 EMA_WP = 0x0000000000001000, /* write-protect */ 56 EMA_RP = 0x0000000000002000, /* read-protect */ 57 EMA_XP = 0x0000000000004000, /* execute-protect */ 58 EMA_RUNTIME = 0x8000000000000000, 59 } EfiMemoryAttribute; 60 61 typedef struct EfiMemoryDescriptor { 62 uint32_t memory_type; 63 uint32_t padding; 64 EfiPhysicalAddr physical_start; 65 EfiVirtualAddr virtual_start; 66 uint64_t number_of_pages; 67 uint64_t attributes; 68 } EfiMemoryDescriptor; 69 70 typedef struct EfiTime { 71 uint16_t year; 72 uint8_t month; 73 uint8_t day; 74 uint8_t hour; 75 uint8_t minute; 76 uint8_t second; 77 uint8_t pad1; 78 uint32_t nanosecond; 79 int16_t timezone; 80 uint8_t daylight; 81 uint8_t pad2; 82 } EfiTime; 83 84 typedef struct EfiTimeCapabilities { 85 uint32_t resolution; 86 uint32_t accuracy; 87 bool sets_to_zero; 88 } EfiTimeCapabilities; 89 90 typedef struct EfiCapsuleHeader { 91 EfiGuid CapsuleGuid; 92 uint32_t HeaderSize; 93 uint32_t Flags; 94 uint32_t CapsuleImageSize; 95 } EfiCapsuleHeader; 96 97 typedef void (*EfiEventNotify)(EfiEvent event, void* ctx); 98 99 typedef enum EFI_EVENT_TYPE : uint32_t { 100 TIMER = 0x80000000, 101 RUNTIME = 0x40000000, 102 NOTIFY_WAIT = 0x00000100, 103 NOTIFY_SIGNAL = 0x00000200, 104 SIGNAL_EXIT_BOOT_SERVICES = 0x00000201, 105 SIGNAL_VIRTUAL_ADDRESS_CHANGE = 0x60000202, 106 } EfiEventType; 107 108 typedef enum EFI_TPL : size_t { 109 APPLICATION = 4, 110 CALLBACK = 8, 111 NOTIFY = 16, 112 HIGH_LEVEL = 31, 113 } EfiTpl; 114 115 typedef enum EFI_TIMER_DELAY { 116 TIMER_CANCEL, 117 TIMER_PERIODIC, 118 TIMER_RELATIVE 119 } EfiTimerDelay; 120 121 typedef enum { 122 RESERVED_MEMORY_TYPE, 123 LOADER_CODE, 124 LOADER_DATA, 125 BOOT_SERVICES_CODE, 126 BOOT_SERVICES_DATA, 127 RUNTIME_SERVICES_CODE, 128 RUNTIME_SERVICES_DATA, 129 CONVENTIONAL_MEMORY, 130 UNUSABLE_MEMORY, 131 ACPIRECLAIM_MEMORY, 132 ACPIMEMORY_NVS, 133 MEMORY_MAPPED_IO, 134 MEMORY_MAPPED_IOPORT_SPACE, 135 PAL_CODE, 136 PERSISTENT_MEMORY, 137 MAX_MEMORY_TYPE 138 } EFI_MEMORY_TYPE; 139 140 typedef EFI_MEMORY_TYPE EfiMemoryType; 141 142 typedef enum { 143 EFI_RESET_COLD, 144 EFI_RESET_WARM, 145 EFI_RESET_SHUTDOWN, 146 EFI_RESET_PLATFORM_SPECIFIC 147 } EFI_RESET_TYPE; 148 149 typedef EFI_RESET_TYPE EfiResetType; 150 151 #define EFI_ERROR_MASK ((uintptr_t)INTPTR_MAX + 1) 152 #define EFI_ERR(x) (EFI_ERROR_MASK | (x)) 153 154 typedef enum EFI_STATUS : uintptr_t { 155 SUCCESS = 0u, 156 LOAD_ERROR = EFI_ERR(1), 157 INVALID_PARAMETER = EFI_ERR(2), 158 UNSUPPORTED = EFI_ERR(3), 159 BAD_BUFFER_SIZE = EFI_ERR(4), 160 BUFFER_TOO_SMALL = EFI_ERR(5), 161 NOT_READY = EFI_ERR(6), 162 DEVICE_ERROR = EFI_ERR(7), 163 WRITE_PROTECTED = EFI_ERR(8), 164 OUT_OF_RESOURCES = EFI_ERR(9), 165 VOLUME_CORRUPTED = EFI_ERR(10), 166 VOLUME_FULL = EFI_ERR(11), 167 NO_MEDIA = EFI_ERR(12), 168 MEDIA_CHANGED = EFI_ERR(13), 169 NOT_FOUND = EFI_ERR(14), 170 ACCESS_DENIED = EFI_ERR(15), 171 NO_RESPONSE = EFI_ERR(16), 172 NO_MAPPING = EFI_ERR(17), 173 TIMEOUT = EFI_ERR(18), 174 NOT_STARTED = EFI_ERR(19), 175 ALREADY_STARTED = EFI_ERR(20), 176 ABORTED = EFI_ERR(21), 177 ICMP_ERROR = EFI_ERR(22), 178 TFTP_ERROR = EFI_ERR(23), 179 PROTOCOL_ERROR = EFI_ERR(24), 180 INCOMPATIBLE_VERSION = EFI_ERR(25), 181 SECURITY_VIOLATION = EFI_ERR(26), 182 CRC_ERROR = EFI_ERR(27), 183 END_OF_MEDIA = EFI_ERR(28), 184 END_OF_FILE = EFI_ERR(31), 185 INVALID_LANGUAGE = EFI_ERR(32), 186 COMPROMISED_DATA = EFI_ERR(33), 187 IP_ADDRESS_CONFLICT = EFI_ERR(34), 188 HTTP_ERROR = EFI_ERR(35), 189 CONNECTION_FIN = EFI_ERR(104), 190 CONNECTION_RESET = EFI_ERR(105), 191 CONNECTION_REFUSED = EFI_ERR(106), 192 } EfiStatus; 193 194 #endif // __EFI_TYPES_H__ 195