]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Efi/Include/EfiTypes.h
026854a32ad455bc59a23fe9a3985980e3ce5786
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Efi / Include / EfiTypes.h
1 /*++
2
3 Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 EfiTypes.h
15
16 Abstract:
17
18 EFI defined types. Use these types when ever possible!
19
20 --*/
21
22 #ifndef _EFI_TYPES_H_
23 #define _EFI_TYPES_H_
24
25 //
26 // EFI Data Types based on ANSI C integer types in EfiBind.h
27 //
28 typedef uint8_t BOOLEAN;
29 typedef intn_t INTN;
30 typedef uintn_t UINTN;
31 typedef int8_t INT8;
32 typedef uint8_t UINT8;
33 typedef int16_t INT16;
34 typedef uint16_t UINT16;
35 typedef int32_t INT32;
36 typedef uint32_t UINT32;
37 typedef int64_t INT64;
38 typedef uint64_t UINT64;
39 typedef char CHAR8;
40 typedef uint16_t CHAR16;
41 typedef UINT64 EFI_LBA;
42
43 //
44 // Modifiers for EFI Data Types used to self document code.
45 // Please see EFI coding convention for proper usage.
46 //
47 #ifndef IN
48 //
49 // Some other envirnments use this construct, so #ifndef to prevent
50 // mulitple definition.
51 //
52 #define IN
53 #define OUT
54 #define OPTIONAL
55 #endif
56
57 #ifndef UNALIGNED
58 #define UNALIGNED
59 #endif
60
61 //
62 // Modifiers for EFI Runtime and Boot Services
63 //
64 #define EFI_RUNTIMESERVICE
65 #define EFI_BOOTSERVICE
66
67 //
68 // Boot Service add in EFI 1.1
69 //
70 #define EFI_BOOTSERVICE11
71
72 //
73 // Modifiers to absract standard types to aid in debug of problems
74 //
75 #define CONST const
76 #define STATIC static
77 #define VOID void
78 #define VOLATILE volatile
79
80 //
81 // Modifier to ensure that all protocol member functions and EFI intrinsics
82 // use the correct C calling convention. All protocol member functions and
83 // EFI intrinsics are required to modify thier member functions with EFIAPI.
84 //
85 #ifndef EFIAPI
86 #define EFIAPI _EFIAPI
87 #endif
88
89 //
90 // EFI Constants. They may exist in other build structures, so #ifndef them.
91 //
92 #ifndef TRUE
93 #define TRUE ((BOOLEAN) (1 == 1))
94 #endif
95
96 #ifndef FALSE
97 #define FALSE ((BOOLEAN) (0 == 1))
98 #endif
99
100 #ifndef NULL
101 #define NULL ((VOID *) 0)
102 #endif
103 //
104 // EFI Data Types derived from other EFI data types.
105 //
106 typedef UINTN EFI_STATUS;
107
108 typedef VOID *EFI_HANDLE;
109 #define NULL_HANDLE ((VOID *) 0)
110
111 typedef VOID *EFI_EVENT;
112 typedef UINTN EFI_TPL;
113
114 typedef struct {
115 UINT32 Data1;
116 UINT16 Data2;
117 UINT16 Data3;
118 UINT8 Data4[8];
119 } EFI_GUID;
120
121 typedef union {
122 EFI_GUID Guid;
123 UINT8 Raw[16];
124 } EFI_GUID_UNION;
125
126 //
127 // EFI Time Abstraction:
128 // Year: 2000 - 20XX
129 // Month: 1 - 12
130 // Day: 1 - 31
131 // Hour: 0 - 23
132 // Minute: 0 - 59
133 // Second: 0 - 59
134 // Nanosecond: 0 - 999,999,999
135 // TimeZone: -1440 to 1440 or 2047
136 //
137 typedef struct {
138 UINT16 Year;
139 UINT8 Month;
140 UINT8 Day;
141 UINT8 Hour;
142 UINT8 Minute;
143 UINT8 Second;
144 UINT8 Pad1;
145 UINT32 Nanosecond;
146 INT16 TimeZone;
147 UINT8 Daylight;
148 UINT8 Pad2;
149 } EFI_TIME;
150
151 //
152 // Bit definitions for EFI_TIME.Daylight
153 //
154 #define EFI_TIME_ADJUST_DAYLIGHT 0x01
155 #define EFI_TIME_IN_DAYLIGHT 0x02
156
157 //
158 // Value definition for EFI_TIME.TimeZone
159 //
160 #define EFI_UNSPECIFIED_TIMEZONE 0x07FF
161
162 //
163 // Networking
164 //
165 typedef struct {
166 UINT8 Addr[4];
167 } EFI_IPv4_ADDRESS;
168
169 typedef struct {
170 UINT8 Addr[16];
171 } EFI_IPv6_ADDRESS;
172
173 typedef struct {
174 UINT8 Addr[32];
175 } EFI_MAC_ADDRESS;
176
177 typedef union {
178 UINT32 Addr[4];
179 EFI_IPv4_ADDRESS v4;
180 EFI_IPv6_ADDRESS v6;
181 } EFI_IP_ADDRESS;
182
183 typedef enum {
184 EfiReservedMemoryType,
185 EfiLoaderCode,
186 EfiLoaderData,
187 EfiBootServicesCode,
188 EfiBootServicesData,
189 EfiRuntimeServicesCode,
190 EfiRuntimeServicesData,
191 EfiConventionalMemory,
192 EfiUnusableMemory,
193 EfiACPIReclaimMemory,
194 EfiACPIMemoryNVS,
195 EfiMemoryMappedIO,
196 EfiMemoryMappedIOPortSpace,
197 EfiPalCode,
198 EfiPersistentMemory,
199 EfiMaxMemoryType
200 } EFI_MEMORY_TYPE;
201
202 typedef enum {
203 AllocateAnyPages,
204 AllocateMaxAddress,
205 AllocateAddress,
206 MaxAllocateType
207 } EFI_ALLOCATE_TYPE;
208
209 typedef struct {
210 UINT64 Signature;
211 UINT32 Revision;
212 UINT32 HeaderSize;
213 UINT32 CRC32;
214 UINT32 Reserved;
215 } EFI_TABLE_HEADER;
216
217 //
218 // possible caching types for the memory range
219 //
220 #define EFI_MEMORY_UC 0x0000000000000001
221 #define EFI_MEMORY_WC 0x0000000000000002
222 #define EFI_MEMORY_WT 0x0000000000000004
223 #define EFI_MEMORY_WB 0x0000000000000008
224 #define EFI_MEMORY_UCE 0x0000000000000010
225
226 //
227 // physical memory protection on range
228 //
229 #define EFI_MEMORY_WP 0x0000000000001000
230 #define EFI_MEMORY_RP 0x0000000000002000
231 #define EFI_MEMORY_XP 0x0000000000004000
232
233 //
234 // range requires a runtime mapping
235 //
236 #define EFI_MEMORY_RUNTIME 0x8000000000000000ULL
237
238 typedef UINT64 EFI_PHYSICAL_ADDRESS;
239 typedef UINT64 EFI_VIRTUAL_ADDRESS;
240
241 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
242 typedef struct {
243 UINT32 Type;
244 UINT32 Pad;
245 EFI_PHYSICAL_ADDRESS PhysicalStart;
246 EFI_VIRTUAL_ADDRESS VirtualStart;
247 UINT64 NumberOfPages;
248 UINT64 Attribute;
249 } EFI_MEMORY_DESCRIPTOR;
250
251 //
252 // The EFI memory allocation functions work in units of EFI_PAGEs that are
253 // 4K. This should in no way be confused with the page size of the processor.
254 // An EFI_PAGE is just the quanta of memory in EFI.
255 //
256 #define EFI_PAGE_SIZE 4096
257 #define EFI_PAGE_MASK 0xFFF
258 #define EFI_PAGE_SHIFT 12
259
260 #define EFI_SIZE_TO_PAGES(a) (((a) >> EFI_PAGE_SHIFT) + (((a) & EFI_PAGE_MASK) ? 1 : 0))
261
262 #define EFI_PAGES_TO_SIZE(a) ( (a) << EFI_PAGE_SHIFT)
263
264 //
265 // ALIGN_POINTER - aligns a pointer to the lowest boundry
266 //
267 #define ALIGN_POINTER(p, s) ((VOID *) (p + ((s - ((UINTN) p)) & (s - 1))))
268
269 //
270 // ALIGN_VARIABLE - aligns a variable up to the next natural boundry for int size of a processor
271 //
272 #define ALIGN_VARIABLE(Value, Adjustment) \
273 (UINTN) Adjustment = 0; \
274 if ((UINTN) Value % sizeof (UINTN)) { \
275 (UINTN) Adjustment = sizeof (UINTN) - ((UINTN) Value % sizeof (UINTN)); \
276 } \
277 Value = (UINTN) Value + (UINTN) Adjustment
278
279 //
280 // EFI_FIELD_OFFSET - returns the byte offset to a field within a structure
281 //
282 #define EFI_FIELD_OFFSET(TYPE,Field) ((UINTN)(&(((TYPE *) 0)->Field)))
283
284 //
285 // CONTAINING_RECORD - returns a pointer to the structure
286 // from one of it's elements.
287 //
288 #define _CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
289
290 //
291 // Define macros to build data structure signatures from characters.
292 //
293 #define EFI_SIGNATURE_16(A, B) ((A) | (B << 8))
294 #define EFI_SIGNATURE_32(A, B, C, D) (EFI_SIGNATURE_16 (A, B) | (EFI_SIGNATURE_16 (C, D) << 16))
295 #define EFI_SIGNATURE_64(A, B, C, D, E, F, G, H) \
296 (EFI_SIGNATURE_32 (A, B, C, D) | ((UINT64) (EFI_SIGNATURE_32 (E, F, G, H)) << 32))
297
298 #endif