1 /**
2 	Based on Uefi/UefiBaseType.h file, original notice:
3 
4 	Defines data types and constants introduced in UEFI.
5 	
6 	Also based on Uefi/UefiMultiPhase.h file, original notice:
7 	This includes some definitions introduced in UEFI that will be used in both PEI and DXE phases.
8 
9 	Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
10 	This program and the accompanying materials
11 	are licensed and made available under the terms and conditions of the BSD License
12 	which accompanies this distribution.  The full text of the license may be found at
13 	http://opensource.org/licenses/bsd-license.php
14 
15 	THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 	WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 **/
18 module uefi.base_type;
19 
20 import uefi.bind;
21 import uefi.base;
22 
23 public:
24 extern (C):
25 
26 //
27 // Basic data type definitions introduced in UEFI.
28 //
29 
30 ///
31 /// 128-bit buffer containing a unique identifier value.
32 ///
33 alias EFI_GUID = GUID;
34 ///
35 /// Function return status for EFI API.
36 ///
37 alias EFI_STATUS = RETURN_STATUS;
38 ///
39 /// A collection of related interfaces.
40 ///
41 alias EFI_HANDLE = VOID*;
42 ///
43 /// Handle to an event structure.
44 ///
45 alias EFI_EVENT = VOID*;
46 ///
47 /// Task priority level.
48 ///
49 alias EFI_TPL = UINTN;
50 ///
51 /// Logical block address.
52 ///
53 alias EFI_LBA = UINT64;
54 
55 ///
56 /// 64-bit physical memory address.
57 ///
58 alias EFI_PHYSICAL_ADDRESS = UINT64;
59 
60 ///
61 /// 64-bit virtual memory address.
62 ///
63 alias EFI_VIRTUAL_ADDRESS = UINT64;
64 
65 /// EFI Time Abstraction:
66 struct EFI_TIME
67 {
68     ///  Year:       1900 - 9999
69     UINT16 Year;
70     ///  Month:      1 - 12
71     UINT8 Month;
72     ///  Day:        1 - 31
73     UINT8 Day;
74     ///  Hour:       0 - 23
75     UINT8 Hour;
76     ///  Minute:     0 - 59
77     UINT8 Minute;
78     ///  Second:     0 - 59
79     UINT8 Second;
80     /// -
81     UINT8 Pad1;
82     ///  Nanosecond: 0 - 999,999,999
83     UINT32 Nanosecond;
84     ///  TimeZone:   -1440 to 1440 or 2047
85     INT16 TimeZone;
86     /// -
87     UINT8 Daylight;
88     /// -
89     UINT8 Pad2;
90 }
91 
92 ///
93 /// 4-byte buffer. An IPv4 internet protocol address.
94 ///
95 struct EFI_IPv4_ADDRESS
96 {
97     UINT8[4] Addr;
98 }
99 
100 ///
101 /// 16-byte buffer. An IPv6 internet protocol address.
102 ///
103 struct EFI_IPv6_ADDRESS
104 {
105     UINT8[16] Addr;
106 }
107 
108 ///
109 /// 32-byte buffer containing a network Media Access Control address.
110 ///
111 struct EFI_MAC_ADDRESS
112 {
113     UINT8[32] Addr;
114 }
115 
116 ///
117 /// 16-byte buffer aligned on a 4-byte boundary.
118 /// An IPv4 or IPv6 internet protocol address.
119 ///
120 union EFI_IP_ADDRESS
121 {
122     UINT32[4] Addr;
123     EFI_IPv4_ADDRESS v4;
124     EFI_IPv6_ADDRESS v6;
125 }
126 
127 ///
128 /// Enumeration of EFI_STATUS.
129 ///
130 enum : EFI_STATUS
131 {
132     EFI_SUCCESS = RETURN_SUCCESS,
133     EFI_LOAD_ERROR = RETURN_LOAD_ERROR,
134     EFI_INVALID_PARAMETER = RETURN_INVALID_PARAMETER,
135     EFI_UNSUPPORTED = RETURN_UNSUPPORTED,
136     EFI_BAD_BUFFER_SIZE = RETURN_BAD_BUFFER_SIZE,
137     EFI_BUFFER_TOO_SMALL = RETURN_BUFFER_TOO_SMALL,
138     EFI_NOT_READY = RETURN_NOT_READY,
139     EFI_DEVICE_ERROR = RETURN_DEVICE_ERROR,
140     EFI_WRITE_PROTECTED = RETURN_WRITE_PROTECTED,
141     EFI_OUT_OF_RESOURCES = RETURN_OUT_OF_RESOURCES,
142     EFI_VOLUME_CORRUPTED = RETURN_VOLUME_CORRUPTED,
143     EFI_VOLUME_FULL = RETURN_VOLUME_FULL,
144     EFI_NO_MEDIA = RETURN_NO_MEDIA,
145     EFI_MEDIA_CHANGED = RETURN_MEDIA_CHANGED,
146     EFI_NOT_FOUND = RETURN_NOT_FOUND,
147     EFI_ACCESS_DENIED = RETURN_ACCESS_DENIED,
148     EFI_NO_RESPONSE = RETURN_NO_RESPONSE,
149     EFI_NO_MAPPING = RETURN_NO_MAPPING,
150     EFI_TIMEOUT = RETURN_TIMEOUT,
151     EFI_NOT_STARTED = RETURN_NOT_STARTED,
152     EFI_ALREADY_STARTED = RETURN_ALREADY_STARTED,
153     EFI_ABORTED = RETURN_ABORTED,
154     EFI_ICMP_ERROR = RETURN_ICMP_ERROR,
155     EFI_TFTP_ERROR = RETURN_TFTP_ERROR,
156     EFI_PROTOCOL_ERROR = RETURN_PROTOCOL_ERROR,
157     EFI_INCOMPATIBLE_VERSION = RETURN_INCOMPATIBLE_VERSION,
158     EFI_SECURITY_VIOLATION = RETURN_SECURITY_VIOLATION,
159     EFI_CRC_ERROR = RETURN_CRC_ERROR,
160     EFI_END_OF_MEDIA = RETURN_END_OF_MEDIA,
161     EFI_END_OF_FILE = RETURN_END_OF_FILE,
162     EFI_INVALID_LANGUAGE = RETURN_INVALID_LANGUAGE,
163     EFI_COMPROMISED_DATA = RETURN_COMPROMISED_DATA,
164     EFI_WARN_UNKNOWN_GLYPH = RETURN_WARN_UNKNOWN_GLYPH,
165     EFI_WARN_DELETE_FAILURE = RETURN_WARN_DELETE_FAILURE,
166     EFI_WARN_WRITE_FAILURE = RETURN_WARN_WRITE_FAILURE,
167     EFI_WARN_BUFFER_TOO_SMALL = RETURN_WARN_BUFFER_TOO_SMALL,
168     EFI_WARN_STALE_DATA = RETURN_WARN_STALE_DATA
169 }
170 
171 ///
172 /// Define macro to encode the status code.
173 /// 
174 alias EFIERR = ENCODE_ERROR;
175 alias EFI_ERROR = RETURN_ERROR;
176 
177 enum : EFI_STATUS
178 {
179     /// ICMP error definitions
180     EFI_NETWORK_UNREACHABLE = EFIERR!(100),
181     /// ditto
182     EFI_HOST_UNREACHABLE = EFIERR!(101),
183     /// ditto 
184     EFI_PROTOCOL_UNREACHABLE = EFIERR!(102),
185     /// ditto
186     EFI_PORT_UNREACHABLE = EFIERR!(103),
187 
188     /// Tcp connection status definitions
189     EFI_CONNECTION_FIN = EFIERR!(104),
190     /// ditto
191     EFI_CONNECTION_RESET = EFIERR!(105),
192     /// ditto
193     EFI_CONNECTION_REFUSED = EFIERR!(106)
194 }
195 
196 /// The EFI memory allocation functions work in units of EFI_PAGEs that are
197 /// 4KB. This should in no way be confused with the page size of the processor.
198 /// An EFI_PAGE is just the quanta of memory in EFI.
199 enum EFI_PAGE_SIZE = SIZE_4KB;
200 enum EFI_PAGE_MASK = 0xFFF;
201 enum EFI_PAGE_SHIFT = 12;
202 
203 /**
204   Macro that converts a size, in bytes, to a number of EFI_PAGESs.
205 
206   Params:  
207   Size =    A size in bytes.  This parameter is assumed to be type UINTN.  
208                     Passing in a parameter that is larger than UINTN may produce 
209                     unexpected results.
210 
211   Returns:  The number of EFI_PAGESs associated with the number of bytes specified
212            by Size.
213 
214 **/
215 auto EFI_SIZE_TO_PAGES(T)(T Size)
216 {
217     return ((Size) >> EFI_PAGE_SHIFT) + (((Size) & EFI_PAGE_MASK) ? 1 : 0);
218 }
219 
220 /**
221   Macro that converts a number of EFI_PAGEs to a size in bytes.
222 
223   Params:  
224   Pages  =  The number of EFI_PAGES.  This parameter is assumed to be 
225                     type UINTN.  Passing in a parameter that is larger than 
226                     UINTN may produce unexpected results.
227 
228   Returns:  The number of bytes associated with the number of EFI_PAGEs specified 
229            by Pages.
230   
231 **/
232 auto EFI_PAGES_TO_SIZE(T)(T Pages)
233 {
234     return (Pages) << EFI_PAGE_SHIFT;
235 }
236 
237 ///
238 /// PE32+ Machine type for IA32 UEFI images.
239 ///
240 enum EFI_IMAGE_MACHINE_IA32 = 0x014C;
241 
242 ///
243 /// PE32+ Machine type for IA64 UEFI images.
244 ///
245 enum EFI_IMAGE_MACHINE_IA64 = 0x0200;
246 
247 ///
248 /// PE32+ Machine type for EBC UEFI images.
249 ///
250 enum EFI_IMAGE_MACHINE_EBC = 0x0EBC;
251 
252 ///
253 /// PE32+ Machine type for X64 UEFI images.
254 ///
255 enum EFI_IMAGE_MACHINE_X64 = 0x8664;
256 
257 ///
258 /// PE32+ Machine type for ARM mixed ARM and Thumb/Thumb2 images.
259 ///
260 enum EFI_IMAGE_MACHINE_ARMTHUMB_MIXED = 0x01C2;
261 
262 ///
263 /// PE32+ Machine type for AARCH64 A64 images.
264 ///
265 enum EFI_IMAGE_MACHINE_AARCH64 = 0xAA64;
266 
267 //  UEFI Multi Phase
268 
269 alias EFI_MEMORY_TYPE = UINT32;
270 ///
271 /// Enumeration of memory types introduced in UEFI.
272 ///
273 enum : EFI_MEMORY_TYPE
274 {
275     ///
276     /// Not used.
277     ///
278     EfiReservedMemoryType,
279     ///
280     /// The code portions of a loaded application.
281     /// (Note that UEFI OS loaders are UEFI applications.)
282     ///
283     EfiLoaderCode,
284     ///
285     /// The data portions of a loaded application and the default data allocation
286     /// type used by an application to allocate pool memory.
287     ///
288     EfiLoaderData,
289     ///
290     /// The code portions of a loaded Boot Services Driver.
291     ///
292     EfiBootServicesCode,
293     ///
294     /// The data portions of a loaded Boot Serves Driver, and the default data
295     /// allocation type used by a Boot Services Driver to allocate pool memory.
296     ///
297     EfiBootServicesData,
298     ///
299     /// The code portions of a loaded Runtime Services Driver.
300     ///
301     EfiRuntimeServicesCode,
302     ///
303     /// The data portions of a loaded Runtime Services Driver and the default
304     /// data allocation type used by a Runtime Services Driver to allocate pool memory.
305     ///
306     EfiRuntimeServicesData,
307     ///
308     /// Free (unallocated) memory.
309     ///
310     EfiConventionalMemory,
311     ///
312     /// Memory in which errors have been detected.
313     ///
314     EfiUnusableMemory,
315     ///
316     /// Memory that holds the ACPI tables.
317     ///
318     EfiACPIReclaimMemory,
319     ///
320     /// Address space reserved for use by the firmware.
321     ///
322     EfiACPIMemoryNVS,
323     ///
324     /// Used by system firmware to request that a memory-mapped IO region
325     /// be mapped by the OS to a virtual address so it can be accessed by EFI runtime services.
326     ///
327     EfiMemoryMappedIO,
328     ///
329     /// System memory-mapped IO region that is used to translate memory
330     /// cycles to IO cycles by the processor.
331     ///
332     EfiMemoryMappedIOPortSpace,
333     ///
334     /// Address space reserved by the firmware for code that is part of the processor.
335     ///
336     EfiPalCode,
337     ///
338     /// A memory region that operates as EfiConventionalMemory, 
339     /// however it happens to also support byte-addressable non-volatility.
340     ///
341     EfiPersistentMemory,
342     EfiMaxMemoryType
343 }
344 
345 alias EFI_RESET_TYPE = UINT32;
346 ///
347 /// Enumeration of reset types.
348 ///
349 enum : EFI_RESET_TYPE
350 {
351     ///
352     /// Used to induce a system-wide reset. This sets all circuitry within the
353     /// system to its initial state.  This type of reset is asynchronous to system
354     /// operation and operates withgout regard to cycle boundaries.  EfiColdReset
355     /// is tantamount to a system power cycle.
356     ///
357     EfiResetCold,
358     ///
359     /// Used to induce a system-wide initialization. The processors are set to their
360     /// initial state, and pending cycles are not corrupted.  If the system does
361     /// not support this reset type, then an EfiResetCold must be performed.
362     ///
363     EfiResetWarm,
364     ///
365     /// Used to induce an entry into a power state equivalent to the ACPI G2/S5 or G3
366     /// state.  If the system does not support this reset type, then when the system
367     /// is rebooted, it should exhibit the EfiResetCold attributes.
368     ///
369     EfiResetShutdown,
370     ///
371     /// Used to induce a system-wide reset. The exact type of the reset is defined by
372     /// the EFI_GUID that follows the Null-terminated Unicode string passed into
373     /// ResetData. If the platform does not recognize the EFI_GUID in ResetData the
374     /// platform must pick a supported reset type to perform. The platform may
375     /// optionally log the parameters from any non-normal reset that occurs.
376     ///
377     EfiResetPlatformSpecific
378 }
379 
380 ///
381 /// Data structure that precedes all of the standard EFI table types.
382 ///
383 struct EFI_TABLE_HEADER
384 {
385     ///
386     /// A 64-bit signature that identifies the type of table that follows.
387     /// Unique signatures have been generated for the EFI System Table,
388     /// the EFI Boot Services Table, and the EFI Runtime Services Table.
389     ///
390     UINT64 Signature;
391     ///
392     /// The revision of the EFI Specification to which this table
393     /// conforms. The upper 16 bits of this field contain the major
394     /// revision value, and the lower 16 bits contain the minor revision
395     /// value. The minor revision values are limited to the range of 00..99.
396     ///
397     UINT32 Revision;
398     ///
399     /// The size, in bytes, of the entire table including the EFI_TABLE_HEADER.
400     ///
401     UINT32 HeaderSize;
402     ///
403     /// The 32-bit CRC for the entire table. This value is computed by
404     /// setting this field to 0, and computing the 32-bit CRC for HeaderSize bytes.
405     ///
406     UINT32 CRC32;
407     ///
408     /// Reserved field that must be set to 0.
409     ///
410     UINT32 Reserved;
411 }
412 
413 ///
414 /// Attributes of variable.
415 ///
416 enum EFI_VARIABLE_NON_VOLATILE = 0x00000001;
417 enum EFI_VARIABLE_BOOTSERVICE_ACCESS = 0x00000002;
418 enum EFI_VARIABLE_RUNTIME_ACCESS = 0x00000004;
419 ///
420 /// This attribute is identified by the mnemonic 'HR'
421 /// elsewhere in this specification.
422 ///
423 enum EFI_VARIABLE_HARDWARE_ERROR_RECORD = 0x00000008;
424 ///
425 /// Attributes of Authenticated Variable
426 ///
427 enum EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS = 0x00000010;
428 enum EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS = 0x00000020;
429 enum EFI_VARIABLE_APPEND_WRITE = 0x00000040;
430 
431 // TODO: WIN_CERTIFICATE_UEFI_GUID-dependent structures