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 #include <stddef.h> 21 #include <stdint.h> 22 23 using EfiTableHeader = struct EfiTableHeader { 24 uint64_t signature; 25 uint32_t revision; 26 uint32_t header_size; 27 uint32_t crc32; 28 uint32_t reserved; 29 }; 30 31 using EfiGuid = struct EfiGuid { 32 uint32_t data1; 33 uint16_t data2; 34 uint16_t data3; 35 uint8_t data4[8]; 36 }; 37 38 struct EfiEventImpl; 39 40 using EfiHandle = void *; 41 using EfiEvent = EfiEventImpl *; 42 using EfiPhysicalAddr = uint64_t; 43 using EfiVirtualAddr = uint64_t; 44 45 using EfiEventNotify = void (*)(EfiEvent, void *); 46 47 using EfiEventType = enum EFI_EVENT_TYPE : uint32_t { 48 TIMER = 0x80000000, 49 RUNTIME = 0x40000000, 50 NOTIFY_WAIT = 0x00000100, 51 NOTIFY_SIGNAL = 0x00000200, 52 SIGNAL_EXIT_BOOT_SERVICES = 0x00000201, 53 SIGNAL_VIRTUAL_ADDRESS_CHANGE = 0x60000202, 54 }; 55 56 using EfiTpl = enum EFI_TPL : size_t { 57 APPLICATION = 4, 58 CALLBACK = 8, 59 NOTIFY = 16, 60 HIGH_LEVEL = 31, 61 }; 62 63 using EfiTimerDelay = enum EFI_TIMER_DELAY { 64 TIMER_CANCEL, 65 TIMER_PERIODIC, 66 TIMER_RELATIVE 67 }; 68 69 enum EFI_MEMORY_TYPE { 70 RESERVED_MEMORY_TYPE, 71 LOADER_CODE, 72 LOADER_DATA, 73 BOOT_SERVICES_CODE, 74 BOOT_SERVICES_DATA, 75 RUNTIME_SERVICES_CODE, 76 RUNTIME_SERVICES_DATA, 77 CONVENTIONAL_MEMORY, 78 UNUSABLE_MEMORY, 79 ACPIRECLAIM_MEMORY, 80 ACPIMEMORY_NVS, 81 MEMORY_MAPPED_IO, 82 MEMORY_MAPPED_IOPORT_SPACE, 83 PAL_CODE, 84 PERSISTENT_MEMORY, 85 MAX_MEMORY_TYPE 86 }; 87 88 typedef EFI_MEMORY_TYPE EfiMemoryType; 89 90 #define EFI_ERROR_MASK ((uintptr_t)INTPTR_MAX + 1) 91 #define EFI_ERR(x) (EFI_ERROR_MASK | (x)) 92 93 using EfiStatus = enum EFI_STATUS : uintptr_t { 94 SUCCESS = 0u, 95 LOAD_ERROR = EFI_ERR(1), 96 INVALID_PARAMETER = EFI_ERR(2), 97 UNSUPPORTED = EFI_ERR(3), 98 BAD_BUFFER_SIZE = EFI_ERR(4), 99 BUFFER_TOO_SMALL = EFI_ERR(5), 100 NOT_READY = EFI_ERR(6), 101 DEVICE_ERROR = EFI_ERR(7), 102 WRITE_PROTECTED = EFI_ERR(8), 103 OUT_OF_RESOURCES = EFI_ERR(9), 104 VOLUME_CORRUPTED = EFI_ERR(10), 105 VOLUME_FULL = EFI_ERR(11), 106 NO_MEDIA = EFI_ERR(12), 107 MEDIA_CHANGED = EFI_ERR(13), 108 NOT_FOUND = EFI_ERR(14), 109 ACCESS_DENIED = EFI_ERR(15), 110 NO_RESPONSE = EFI_ERR(16), 111 NO_MAPPING = EFI_ERR(17), 112 TIMEOUT = EFI_ERR(18), 113 NOT_STARTED = EFI_ERR(19), 114 ALREADY_STARTED = EFI_ERR(20), 115 ABORTED = EFI_ERR(21), 116 ICMP_ERROR = EFI_ERR(22), 117 TFTP_ERROR = EFI_ERR(23), 118 PROTOCOL_ERROR = EFI_ERR(24), 119 INCOMPATIBLE_VERSION = EFI_ERR(25), 120 SECURITY_VIOLATION = EFI_ERR(26), 121 CRC_ERROR = EFI_ERR(27), 122 END_OF_MEDIA = EFI_ERR(28), 123 END_OF_FILE = EFI_ERR(31), 124 INVALID_LANGUAGE = EFI_ERR(32), 125 COMPROMISED_DATA = EFI_ERR(33), 126 IP_ADDRESS_CONFLICT = EFI_ERR(34), 127 HTTP_ERROR = EFI_ERR(35), 128 CONNECTION_FIN = EFI_ERR(104), 129 CONNECTION_RESET = EFI_ERR(105), 130 CONNECTION_REFUSED = EFI_ERR(106), 131 }; 132 133 /// 134 /// EFI Time Abstraction: 135 /// Year: 1900 - 9999 136 /// Month: 1 - 12 137 /// Day: 1 - 31 138 /// Hour: 0 - 23 139 /// Minute: 0 - 59 140 /// Second: 0 - 59 141 /// Nanosecond: 0 - 999,999,999 142 /// TimeZone: -1440 to 1440 or 2047 143 /// 144 using EfiTime = struct { 145 uint16_t Year; 146 uint8_t Month; 147 uint8_t Day; 148 uint8_t Hour; 149 uint8_t Minute; 150 uint8_t Second; 151 uint8_t Pad1; 152 uint32_t Nanosecond; 153 int16_t TimeZone; 154 uint8_t Daylight; 155 uint8_t Pad2; 156 }; 157 158 /// 159 /// This provides the capabilities of the 160 /// real time clock device as exposed through the EFI interfaces. 161 /// 162 using EFI_TIME_CAPABILITIES = struct { 163 /// 164 /// Provides the reporting resolution of the real-time clock device in 165 /// counts per second. For a normal PC-AT CMOS RTC device, this 166 /// value would be 1 Hz, or 1, to indicate that the device only reports 167 /// the time to the resolution of 1 second. 168 /// 169 uint32_t Resolution; 170 /// 171 /// Provides the timekeeping accuracy of the real-time clock in an 172 /// error rate of 1E-6 parts per million. For a clock with an accuracy 173 /// of 50 parts per million, the value in this field would be 174 /// 50,000,000. 175 /// 176 uint32_t Accuracy; 177 /// 178 /// A TRUE indicates that a time set operation clears the device's 179 /// time below the Resolution reporting level. A FALSE 180 /// indicates that the state below the Resolution level of the 181 /// device is not cleared when the time is set. Normal PC-AT CMOS 182 /// RTC devices set this value to FALSE. 183 /// 184 bool SetsToZero; 185 }; 186 187 #endif // __EFI_TYPES_H__ 188