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 EfiMemoryDescriptor {
44   uint32_t memory_type;
45   uint32_t padding;
46   EfiPhysicalAddr physical_start;
47   EfiVirtualAddr virtual_start;
48   uint64_t number_of_pages;
49   uint64_t attributes;
50 } EfiMemoryDescriptor;
51 
52 typedef struct EfiTime {
53   uint16_t year;
54   uint8_t month;
55   uint8_t day;
56   uint8_t hour;
57   uint8_t minute;
58   uint8_t second;
59   uint8_t pad1;
60   uint32_t nanosecond;
61   int16_t timezone;
62   uint8_t daylight;
63   uint8_t pad2;
64 } EfiTime;
65 
66 typedef struct EfiTimeCapabilities {
67   uint32_t resolution;
68   uint32_t accuracy;
69   bool sets_to_zero;
70 } EfiTimeCapabilities;
71 
72 typedef struct EfiCapsuleHeader {
73   EfiGuid CapsuleGuid;
74   uint32_t HeaderSize;
75   uint32_t Flags;
76   uint32_t CapsuleImageSize;
77 } EfiCapsuleHeader;
78 
79 typedef void (*EfiEventNotify)(EfiEvent event, void* ctx);
80 
81 typedef enum EFI_EVENT_TYPE: uint32_t {
82   TIMER = 0x80000000,
83   RUNTIME = 0x40000000,
84   NOTIFY_WAIT = 0x00000100,
85   NOTIFY_SIGNAL = 0x00000200,
86   SIGNAL_EXIT_BOOT_SERVICES = 0x00000201,
87   SIGNAL_VIRTUAL_ADDRESS_CHANGE = 0x60000202,
88 } EfiEventType;
89 
90 typedef enum EFI_TPL: size_t {
91   APPLICATION = 4,
92   CALLBACK = 8,
93   NOTIFY = 16,
94   HIGH_LEVEL = 31,
95 } EfiTpl;
96 
97 typedef enum EFI_TIMER_DELAY { TIMER_CANCEL, TIMER_PERIODIC, TIMER_RELATIVE } EfiTimerDelay;
98 
99 typedef enum {
100   RESERVED_MEMORY_TYPE,
101   LOADER_CODE,
102   LOADER_DATA,
103   BOOT_SERVICES_CODE,
104   BOOT_SERVICES_DATA,
105   RUNTIME_SERVICES_CODE,
106   RUNTIME_SERVICES_DATA,
107   CONVENTIONAL_MEMORY,
108   UNUSABLE_MEMORY,
109   ACPIRECLAIM_MEMORY,
110   ACPIMEMORY_NVS,
111   MEMORY_MAPPED_IO,
112   MEMORY_MAPPED_IOPORT_SPACE,
113   PAL_CODE,
114   PERSISTENT_MEMORY,
115   MAX_MEMORY_TYPE
116 } EFI_MEMORY_TYPE;
117 
118 typedef EFI_MEMORY_TYPE EfiMemoryType;
119 
120 typedef enum {
121   EFI_RESET_COLD,
122   EFI_RESET_WARM,
123   EFI_RESET_SHUTDOWN,
124   EFI_RESET_PLATFORM_SPECIFIC
125 } EFI_RESET_TYPE;
126 
127 typedef EFI_RESET_TYPE EfiResetType;
128 
129 #define EFI_ERROR_MASK ((uintptr_t)INTPTR_MAX + 1)
130 #define EFI_ERR(x) (EFI_ERROR_MASK | (x))
131 
132 typedef enum EFI_STATUS : uintptr_t {
133   SUCCESS = 0u,
134   LOAD_ERROR = EFI_ERR(1),
135   INVALID_PARAMETER = EFI_ERR(2),
136   UNSUPPORTED = EFI_ERR(3),
137   BAD_BUFFER_SIZE = EFI_ERR(4),
138   BUFFER_TOO_SMALL = EFI_ERR(5),
139   NOT_READY = EFI_ERR(6),
140   DEVICE_ERROR = EFI_ERR(7),
141   WRITE_PROTECTED = EFI_ERR(8),
142   OUT_OF_RESOURCES = EFI_ERR(9),
143   VOLUME_CORRUPTED = EFI_ERR(10),
144   VOLUME_FULL = EFI_ERR(11),
145   NO_MEDIA = EFI_ERR(12),
146   MEDIA_CHANGED = EFI_ERR(13),
147   NOT_FOUND = EFI_ERR(14),
148   ACCESS_DENIED = EFI_ERR(15),
149   NO_RESPONSE = EFI_ERR(16),
150   NO_MAPPING = EFI_ERR(17),
151   TIMEOUT = EFI_ERR(18),
152   NOT_STARTED = EFI_ERR(19),
153   ALREADY_STARTED = EFI_ERR(20),
154   ABORTED = EFI_ERR(21),
155   ICMP_ERROR = EFI_ERR(22),
156   TFTP_ERROR = EFI_ERR(23),
157   PROTOCOL_ERROR = EFI_ERR(24),
158   INCOMPATIBLE_VERSION = EFI_ERR(25),
159   SECURITY_VIOLATION = EFI_ERR(26),
160   CRC_ERROR = EFI_ERR(27),
161   END_OF_MEDIA = EFI_ERR(28),
162   END_OF_FILE = EFI_ERR(31),
163   INVALID_LANGUAGE = EFI_ERR(32),
164   COMPROMISED_DATA = EFI_ERR(33),
165   IP_ADDRESS_CONFLICT = EFI_ERR(34),
166   HTTP_ERROR = EFI_ERR(35),
167   CONNECTION_FIN = EFI_ERR(104),
168   CONNECTION_RESET = EFI_ERR(105),
169   CONNECTION_REFUSED = EFI_ERR(106),
170 } EfiStatus;
171 
172 #endif  // __EFI_TYPES_H__
173