r_efi/
system.rs

1//! UEFI System Integration
2//!
3//! This header defines the structures and types of the surrounding system of an UEFI application.
4//! It contains the definitions of the system table, the runtime and boot services, as well as
5//! common types.
6//!
7//! We do not document the behavior of each of these types and functions. They follow the UEFI
8//! specification, which does a well-enough job of documenting each. This file just provides you
9//! the rust definitions of each symbol and some limited hints on some pecularities.
10
11//
12// Time Management
13//
14// UEFI time management is modeled around the EFI_TIME structure, which represents any arbitrary
15// timestamp. The runtime and boot services provide helper functions to query and set the system
16// time.
17//
18
19pub const TIME_ADJUST_DAYLIGHT: u8 = 0x01u8;
20pub const TIME_IN_DAYLIGHT: u8 = 0x02u8;
21
22pub const UNSPECIFIED_TIMEZONE: i16 = 0x07ffi16;
23
24// Cannot derive `Eq` etc. due to uninitialized `pad2` field.
25#[repr(C)]
26#[derive(Clone, Copy, Debug, Default)]
27pub struct Time {
28    pub year: u16,
29    pub month: u8,
30    pub day: u8,
31    pub hour: u8,
32    pub minute: u8,
33    pub second: u8,
34    pub pad1: u8,
35    pub nanosecond: u32,
36    pub timezone: i16,
37    pub daylight: u8,
38    pub pad2: u8,
39}
40
41#[repr(C)]
42#[derive(Clone, Copy, Debug)]
43pub struct TimeCapabilities {
44    pub resolution: u32,
45    pub accuracy: u32,
46    pub sets_to_zero: crate::base::Boolean,
47}
48
49//
50// UEFI Variables
51//
52// UEFI systems provide a way to store global variables. These can be persistent or volatile. The
53// variable store must be provided by the platform, but persistent storage might not be available.
54//
55
56pub const VARIABLE_NON_VOLATILE: u32 = 0x00000001u32;
57pub const VARIABLE_BOOTSERVICE_ACCESS: u32 = 0x00000002u32;
58pub const VARIABLE_RUNTIME_ACCESS: u32 = 0x00000004u32;
59pub const VARIABLE_HARDWARE_ERROR_RECORD: u32 = 0x00000008u32;
60pub const VARIABLE_AUTHENTICATED_WRITE_ACCESS: u32 = 0x00000010u32;
61pub const VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS: u32 = 0x00000020u32;
62pub const VARIABLE_APPEND_WRITE: u32 = 0x00000040u32;
63pub const VARIABLE_ENHANCED_AUTHENTICATED_ACCESS: u32 = 0x00000080u32;
64
65pub const VARIABLE_AUTHENTICATION_3_CERT_ID_SHA256: u32 = 0x1u32;
66
67#[repr(C)]
68#[derive(Clone, Copy, Debug)]
69pub struct VariableAuthentication3CertId<const N: usize = 0> {
70    pub r#type: u8,
71    pub id_size: u32,
72    pub id: [u8; N],
73}
74
75#[repr(C)]
76#[derive(Clone, Copy, Debug)]
77pub struct VariableAuthentication<const N: usize = 0> {
78    pub monotonic_count: u64,
79    pub auth_info: [u8; N], // WIN_CERTIFICATE_UEFI_ID from PE/COFF
80}
81
82#[repr(C)]
83#[derive(Clone, Copy, Debug)]
84pub struct VariableAuthentication2<const N: usize = 0> {
85    pub timestamp: Time,
86    pub auth_info: [u8; N], // WIN_CERTIFICATE_UEFI_ID from PE/COFF
87}
88
89pub const VARIABLE_AUTHENTICATION_3_TIMESTAMP_TYPE: u32 = 0x1u32;
90pub const VARIABLE_AUTHENTICATION_3_NONCE_TYPE: u32 = 0x2u32;
91
92#[repr(C)]
93#[derive(Clone, Copy, Debug)]
94pub struct VariableAuthentication3 {
95    pub version: u8,
96    pub r#type: u8,
97    pub metadata_size: u32,
98    pub flags: u32,
99}
100
101#[repr(C)]
102#[derive(Clone, Copy, Debug)]
103pub struct VariableAuthentication3Nonce<const N: usize = 0> {
104    pub nonce_size: u32,
105    pub nonce: [u8; N],
106}
107
108pub const HARDWARE_ERROR_VARIABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
109    0x414E6BDD,
110    0xE47B,
111    0x47cc,
112    0xB2,
113    0x44,
114    &[0xBB, 0x61, 0x02, 0x0C, 0xF5, 0x16],
115);
116
117//
118// Virtual Mappings
119//
120// UEFI runs in an 1-to-1 mapping from virtual to physical addresses. But once you exit boot
121// services, you can apply any address mapping you want, as long as you inform UEFI about it (or,
122// alternatively, stop using the UEFI runtime services).
123//
124
125pub const OPTIONAL_POINTER: u32 = 0x00000001u32;
126
127//
128// System Reset
129//
130// UEFI provides access to firmware functions to reset the system. This includes a wide variety of
131// different possible resets.
132//
133
134pub type ResetType = u32;
135
136pub const RESET_COLD: ResetType = 0x00000000;
137pub const RESET_WARM: ResetType = 0x00000001;
138pub const RESET_SHUTDOWN: ResetType = 0x00000002;
139pub const RESET_PLATFORM_SPECIFIC: ResetType = 0x00000003;
140
141//
142// Update Capsules
143//
144// The process of firmware updates is generalized in UEFI. There are small blobs called capsules
145// that you can push into the firmware to be run either immediately or on next reboot.
146//
147
148#[repr(C)]
149#[derive(Clone, Copy)]
150pub union CapsuleBlockDescriptorUnion {
151    pub data_block: crate::base::PhysicalAddress,
152    pub continuation_pointer: crate::base::PhysicalAddress,
153}
154
155#[repr(C)]
156#[derive(Clone, Copy)]
157pub struct CapsuleBlockDescriptor {
158    pub length: u64,
159    pub data: CapsuleBlockDescriptorUnion,
160}
161
162pub const CAPSULE_FLAGS_PERSIST_ACROSS_RESET: u32 = 0x00010000u32;
163pub const CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE: u32 = 0x00020000u32;
164pub const CAPSULE_FLAGS_INITIATE_RESET: u32 = 0x00040000u32;
165
166#[repr(C)]
167#[derive(Clone, Copy, Debug)]
168pub struct CapsuleHeader {
169    pub capsule_guid: crate::base::Guid,
170    pub header_size: u32,
171    pub flags: u32,
172    pub capsule_image_size: u32,
173}
174
175pub const OS_INDICATIONS_BOOT_TO_FW_UI: u64 = 0x0000000000000001u64;
176pub const OS_INDICATIONS_TIMESTAMP_REVOCATION: u64 = 0x0000000000000002u64;
177pub const OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED: u64 = 0x0000000000000004u64;
178pub const OS_INDICATIONS_FMP_CAPSULE_SUPPORTED: u64 = 0x0000000000000008u64;
179pub const OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED: u64 = 0x0000000000000010u64;
180pub const OS_INDICATIONS_START_OS_RECOVERY: u64 = 0x0000000000000020u64;
181pub const OS_INDICATIONS_START_PLATFORM_RECOVERY: u64 = 0x0000000000000040u64;
182
183pub const CAPSULE_REPORT_GUID: crate::base::Guid = crate::base::Guid::from_fields(
184    0x39b68c46,
185    0xf7fb,
186    0x441b,
187    0xb6,
188    0xec,
189    &[0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3],
190);
191
192#[repr(C)]
193#[derive(Clone, Copy, Debug)]
194pub struct CapsuleResultVariableHeader {
195    pub variable_total_size: u32,
196    pub reserved: u32,
197    pub capsule_guid: crate::base::Guid,
198    pub capsule_processed: Time,
199    pub capsule_status: crate::base::Status,
200}
201
202#[repr(C)]
203#[derive(Clone, Copy, Debug)]
204pub struct CapsuleResultVariableFMP<const N: usize = 0> {
205    pub version: u16,
206    pub payload_index: u8,
207    pub update_image_index: u8,
208    pub update_image_type_id: crate::base::Guid,
209    pub capsule_file_name_and_target: [crate::base::Char16; N],
210}
211
212//
213// Tasks
214//
215// UEFI uses a simplified task model, and only ever runs on a single CPU. Usually, there is only
216// one single task running on the system, which is the current execution. No interrupts are
217// supported, other than timer interrupts. That is, all device management must be reliant on
218// polling.
219//
220// You can, however, register callbacks to be run by the UEFI core. That is, either when execution
221// is returned to the UEFI core, or when a timer interrupt fires, the scheduler will run the
222// highest priority task next, interrupting the current task. You can use simple
223// task-priority-levels (TPL) to adjust the priority of your callbacks and current task.
224//
225
226pub const EVT_TIMER: u32 = 0x80000000u32;
227pub const EVT_RUNTIME: u32 = 0x40000000u32;
228pub const EVT_NOTIFY_WAIT: u32 = 0x00000100u32;
229pub const EVT_NOTIFY_SIGNAL: u32 = 0x00000200u32;
230pub const EVT_SIGNAL_EXIT_BOOT_SERVICES: u32 = 0x00000201u32;
231pub const EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE: u32 = 0x60000202u32;
232
233pub type EventNotify = eficall! {fn(crate::base::Event, *mut core::ffi::c_void)};
234
235pub const EVENT_GROUP_EXIT_BOOT_SERVICES: crate::base::Guid = crate::base::Guid::from_fields(
236    0x27abf055,
237    0xb1b8,
238    0x4c26,
239    0x80,
240    0x48,
241    &[0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf],
242);
243pub const EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES: crate::base::Guid = crate::base::Guid::from_fields(
244    0x8be0e274,
245    0x3970,
246    0x4b44,
247    0x80,
248    0xc5,
249    &[0x1a, 0xb9, 0x50, 0x2f, 0x3b, 0xfc],
250);
251pub const EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE: crate::base::Guid = crate::base::Guid::from_fields(
252    0x13fa7698,
253    0xc831,
254    0x49c7,
255    0x87,
256    0xea,
257    &[0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96],
258);
259pub const EVENT_GROUP_MEMORY_MAP_CHANGE: crate::base::Guid = crate::base::Guid::from_fields(
260    0x78bee926,
261    0x692f,
262    0x48fd,
263    0x9e,
264    0xdb,
265    &[0x1, 0x42, 0x2e, 0xf0, 0xd7, 0xab],
266);
267pub const EVENT_GROUP_READY_TO_BOOT: crate::base::Guid = crate::base::Guid::from_fields(
268    0x7ce88fb3,
269    0x4bd7,
270    0x4679,
271    0x87,
272    0xa8,
273    &[0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b],
274);
275pub const EVENT_GROUP_AFTER_READY_TO_BOOT: crate::base::Guid = crate::base::Guid::from_fields(
276    0x3a2a00ad,
277    0x98b9,
278    0x4cdf,
279    0xa4,
280    0x78,
281    &[0x70, 0x27, 0x77, 0xf1, 0xc1, 0x0b],
282);
283pub const EVENT_GROUP_RESET_SYSTEM: crate::base::Guid = crate::base::Guid::from_fields(
284    0x62da6a56,
285    0x13fb,
286    0x485a,
287    0xa8,
288    0xda,
289    &[0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b],
290);
291
292pub type TimerDelay = u32;
293
294pub const TIMER_CANCEL: TimerDelay = 0x00000000;
295pub const TIMER_PERIODIC: TimerDelay = 0x00000001;
296pub const TIMER_RELATIVE: TimerDelay = 0x00000002;
297
298pub const TPL_APPLICATION: crate::base::Tpl = 4;
299pub const TPL_CALLBACK: crate::base::Tpl = 8;
300pub const TPL_NOTIFY: crate::base::Tpl = 16;
301pub const TPL_HIGH_LEVEL: crate::base::Tpl = 31;
302
303//
304// Memory management
305//
306// The UEFI boot services provide you pool-allocation helpers to reserve memory. The region for
307// each allocation can be selected by the caller, allowing to reserve memory that even survives
308// beyond boot services. However, dynamic allocations can only performed via boot services, so no
309// dynamic modifications can be done once you exit boot services.
310//
311
312pub type AllocateType = u32;
313
314pub const ALLOCATE_ANY_PAGES: AllocateType = 0x00000000;
315pub const ALLOCATE_MAX_ADDRESS: AllocateType = 0x00000001;
316pub const ALLOCATE_ADDRESS: AllocateType = 0x00000002;
317
318pub type MemoryType = u32;
319
320pub const RESERVED_MEMORY_TYPE: MemoryType = 0x00000000;
321pub const LOADER_CODE: MemoryType = 0x00000001;
322pub const LOADER_DATA: MemoryType = 0x00000002;
323pub const BOOT_SERVICES_CODE: MemoryType = 0x00000003;
324pub const BOOT_SERVICES_DATA: MemoryType = 0x00000004;
325pub const RUNTIME_SERVICES_CODE: MemoryType = 0x00000005;
326pub const RUNTIME_SERVICES_DATA: MemoryType = 0x00000006;
327pub const CONVENTIONAL_MEMORY: MemoryType = 0x00000007;
328pub const UNUSABLE_MEMORY: MemoryType = 0x00000008;
329pub const ACPI_RECLAIM_MEMORY: MemoryType = 0x00000009;
330pub const ACPI_MEMORY_NVS: MemoryType = 0x0000000a;
331pub const MEMORY_MAPPED_IO: MemoryType = 0x0000000b;
332pub const MEMORY_MAPPED_IO_PORT_SPACE: MemoryType = 0x0000000c;
333pub const PAL_CODE: MemoryType = 0x0000000d;
334pub const PERSISTENT_MEMORY: MemoryType = 0x0000000e;
335pub const UNACCEPTED_MEMORY_TYPE: MemoryType = 0x0000000f;
336
337pub const MEMORY_UC: u64 = 0x0000000000000001u64;
338pub const MEMORY_WC: u64 = 0x0000000000000002u64;
339pub const MEMORY_WT: u64 = 0x0000000000000004u64;
340pub const MEMORY_WB: u64 = 0x0000000000000008u64;
341pub const MEMORY_UCE: u64 = 0x0000000000000010u64;
342pub const MEMORY_WP: u64 = 0x0000000000001000u64;
343pub const MEMORY_RP: u64 = 0x0000000000002000u64;
344pub const MEMORY_XP: u64 = 0x0000000000004000u64;
345pub const MEMORY_NV: u64 = 0x0000000000008000u64;
346pub const MEMORY_MORE_RELIABLE: u64 = 0x0000000000010000u64;
347pub const MEMORY_RO: u64 = 0x0000000000020000u64;
348pub const MEMORY_SP: u64 = 0x0000000000040000u64;
349pub const MEMORY_CPU_CRYPTO: u64 = 0x0000000000080000u64;
350pub const MEMORY_RUNTIME: u64 = 0x8000000000000000u64;
351pub const MEMORY_ISA_VALID: u64 = 0x4000000000000000u64;
352pub const MEMORY_ISA_MASK: u64 = 0x0FFFF00000000000u64;
353
354/// Mask of memory attributes that specify cacheability attributes. No symbol
355/// is defined by the spec, but the attributes are annotated in the spec. Note
356/// that `MEMORY_WP`, despite its name, is treated as cacheability attribute.
357/// Use `MEMORY_RO` as replacement access attribute (see the spec for details).
358pub const CACHE_ATTRIBUTE_MASK: u64 =
359    MEMORY_UC | MEMORY_WC | MEMORY_WT | MEMORY_WB | MEMORY_UCE | MEMORY_WP;
360
361/// Mask of memory attributes that specify access protection attributes. No
362/// symbol is defined by the spec, but the attributes are annotated in the
363/// spec. Note that `MEMORY_WP` is treated as cacheability attribute, and its
364/// access protection functionality is replaced by `MEMORY_RO`.
365pub const MEMORY_ACCESS_MASK: u64 = MEMORY_RP | MEMORY_XP | MEMORY_RO;
366
367/// Mask of memory attributes that specify properties of a memory region that
368/// can be managed via the CPU architecture protocol.
369pub const MEMORY_ATTRIBUTE_MASK: u64 = MEMORY_ACCESS_MASK | MEMORY_SP | MEMORY_CPU_CRYPTO;
370
371pub const MEMORY_DESCRIPTOR_VERSION: u32 = 0x00000001u32;
372
373#[repr(C)]
374#[derive(Clone, Copy, Debug)]
375pub struct MemoryDescriptor {
376    pub r#type: u32,
377    pub physical_start: crate::base::PhysicalAddress,
378    pub virtual_start: crate::base::VirtualAddress,
379    pub number_of_pages: u64,
380    pub attribute: u64,
381}
382
383//
384// Protocol Management
385//
386// The UEFI driver model provides ways to have bus-drivers, device-drivers, and applications as
387// separate, independent entities. They use protocols to communicate, and handles to refer to
388// common state. Drivers and devices can be registered dynamically at runtime, and can support
389// hotplugging.
390//
391
392pub type InterfaceType = u32;
393
394pub const NATIVE_INTERFACE: InterfaceType = 0x00000000;
395
396pub type LocateSearchType = u32;
397
398pub const ALL_HANDLES: LocateSearchType = 0x00000000;
399pub const BY_REGISTER_NOTIFY: LocateSearchType = 0x00000001;
400pub const BY_PROTOCOL: LocateSearchType = 0x00000002;
401
402pub const OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: u32 = 0x00000001u32;
403pub const OPEN_PROTOCOL_GET_PROTOCOL: u32 = 0x00000002u32;
404pub const OPEN_PROTOCOL_TEST_PROTOCOL: u32 = 0x00000004u32;
405pub const OPEN_PROTOCOL_BY_CHILD_CONTROLLER: u32 = 0x00000008u32;
406pub const OPEN_PROTOCOL_BY_DRIVER: u32 = 0x00000010u32;
407pub const OPEN_PROTOCOL_EXCLUSIVE: u32 = 0x00000020u32;
408
409#[repr(C)]
410#[derive(Clone, Copy, Debug)]
411pub struct OpenProtocolInformationEntry {
412    pub agent_handle: crate::base::Handle,
413    pub controller_handle: crate::base::Handle,
414    pub attributes: u32,
415    pub open_count: u32,
416}
417
418//
419// Configuration Tables
420//
421// The system table contains an array of auxiliary tables, indexed by their GUID, called
422// configuration tables. Each table uses the generic ConfigurationTable structure as header.
423//
424
425#[repr(C)]
426#[derive(Clone, Copy, Debug)]
427pub struct ConfigurationTable {
428    pub vendor_guid: crate::base::Guid,
429    pub vendor_table: *mut core::ffi::c_void,
430}
431
432pub const RT_PROPERTIES_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
433    0xeb66918a,
434    0x7eef,
435    0x402a,
436    0x84,
437    0x2e,
438    &[0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9],
439);
440
441pub const RT_PROPERTIES_TABLE_VERSION: u16 = 0x0001;
442
443pub const RT_SUPPORTED_GET_TIME: u32 = 0x0000001;
444pub const RT_SUPPORTED_SET_TIME: u32 = 0x0000002;
445pub const RT_SUPPORTED_GET_WAKEUP_TIME: u32 = 0x0000004;
446pub const RT_SUPPORTED_SET_WAKEUP_TIME: u32 = 0x0000008;
447pub const RT_SUPPORTED_GET_VARIABLE: u32 = 0x00000010;
448pub const RT_SUPPORTED_GET_NEXT_VARIABLE_NAME: u32 = 0x00000020;
449pub const RT_SUPPORTED_SET_VARIABLE: u32 = 0x00000040;
450pub const RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP: u32 = 0x00000080;
451pub const RT_SUPPORTED_CONVERT_POINTER: u32 = 0x00000100;
452pub const RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT: u32 = 0x00000200;
453pub const RT_SUPPORTED_RESET_SYSTEM: u32 = 0x00000400;
454pub const RT_SUPPORTED_UPDATE_CAPSULE: u32 = 0x00000800;
455pub const RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES: u32 = 0x00001000;
456pub const RT_SUPPORTED_QUERY_VARIABLE_INFO: u32 = 0x00002000;
457
458#[repr(C)]
459#[derive(Clone, Copy, Debug)]
460pub struct RtPropertiesTable {
461    pub version: u16,
462    pub length: u16,
463    pub runtime_services_supported: u32,
464}
465
466pub const PROPERTIES_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
467    0x880aaca3,
468    0x4adc,
469    0x4a04,
470    0x90,
471    0x79,
472    &[0xb7, 0x47, 0x34, 0x8, 0x25, 0xe5],
473);
474
475pub const PROPERTIES_TABLE_VERSION: u32 = 0x00010000u32;
476
477pub const PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA: u64 = 0x1u64;
478
479#[repr(C)]
480#[derive(Clone, Copy, Debug)]
481pub struct PropertiesTable {
482    pub version: u32,
483    pub length: u32,
484    pub memory_protection_attribute: u64,
485}
486
487pub const MEMORY_ATTRIBUTES_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
488    0xdcfa911d,
489    0x26eb,
490    0x469f,
491    0xa2,
492    0x20,
493    &[0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20],
494);
495
496pub const MEMORY_ATTRIBUTES_TABLE_VERSION: u32 = 0x00000001u32;
497
498#[repr(C)]
499#[derive(Clone, Copy, Debug)]
500pub struct MemoryAttributesTable<const N: usize = 0> {
501    pub version: u32,
502    pub number_of_entries: u32,
503    pub descriptor_size: u32,
504    pub reserved: u32,
505    pub entry: [MemoryDescriptor; N],
506}
507
508pub const CONFORMANCE_PROFILES_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
509    0x36122546,
510    0xf7e7,
511    0x4c8f,
512    0xbd,
513    0x9b,
514    &[0xeb, 0x85, 0x25, 0xb5, 0x0c, 0x0b],
515);
516
517pub const CONFORMANCE_PROFILES_TABLE_VERSION: u16 = 0x0001;
518
519pub const CONFORMANCE_PROFILES_UEFI_SPEC_GUID: crate::base::Guid = crate::base::Guid::from_fields(
520    0x523c91af,
521    0xa195,
522    0x4382,
523    0x81,
524    0x8d,
525    &[0x29, 0x5f, 0xe4, 0x00, 0x64, 0x65],
526);
527
528#[repr(C)]
529#[derive(Clone, Copy, Debug)]
530pub struct ConformanceProfilesTable<const N: usize = 0> {
531    pub version: u16,
532    pub number_of_profiles: u16,
533    pub conformance_profiles: [crate::base::Guid; N],
534}
535
536//
537// External Configuration Tables
538//
539// This lists the Guids of configuration tables of other industry standards, as listed in
540// the UEFI specification. See each standard for details on the data included in each table.
541//
542
543pub const ACPI_10_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
544    0xeb9d2d30,
545    0x2d88,
546    0x11d3,
547    0x9a,
548    0x16,
549    &[0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d],
550);
551
552pub const ACPI_20_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
553    0x8868e871,
554    0xe4f1,
555    0x11d3,
556    0xbc,
557    0x22,
558    &[0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81],
559);
560
561pub const DTB_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
562    0xb1b621d5,
563    0xf19c,
564    0x41a5,
565    0x83,
566    0x0b,
567    &[0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0],
568);
569
570pub const JSON_CAPSULE_DATA_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
571    0x35e7a725,
572    0x8dd2,
573    0x4cac,
574    0x80,
575    0x11,
576    &[0x33, 0xcd, 0xa8, 0x10, 0x90, 0x56],
577);
578
579pub const JSON_CAPSULE_RESULT_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
580    0xdbc461c3,
581    0xb3de,
582    0x422a,
583    0xb9,
584    0xb4,
585    &[0x98, 0x86, 0xfd, 0x49, 0xa1, 0xe5],
586);
587
588pub const JSON_CONFIG_DATA_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
589    0x87367f87,
590    0x1119,
591    0x41ce,
592    0xaa,
593    0xec,
594    &[0x8b, 0xe0, 0x11, 0x1f, 0x55, 0x8a],
595);
596
597pub const MPS_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
598    0xeb9d2d2f,
599    0x2d88,
600    0x11d3,
601    0x9a,
602    0x16,
603    &[0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d],
604);
605
606pub const SAL_SYSTEM_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
607    0xeb9d2d32,
608    0x2d88,
609    0x11d3,
610    0x9a,
611    0x16,
612    &[0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d],
613);
614
615pub const SMBIOS_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
616    0xeb9d2d31,
617    0x2d88,
618    0x11d3,
619    0x9a,
620    0x16,
621    &[0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d],
622);
623
624pub const SMBIOS3_TABLE_GUID: crate::base::Guid = crate::base::Guid::from_fields(
625    0xf2fd1544,
626    0x9794,
627    0x4a2c,
628    0x99,
629    0x2e,
630    &[0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94],
631);
632
633//
634// Global Tables
635//
636// UEFI uses no global state, so all access to UEFI internal state is done through vtables you get
637// passed to your entry-point. The global entry is the system-table, which encorporates several
638// sub-tables, including the runtime and boot service tables, and configuration tables (including
639// vendor extensions).
640//
641
642pub const SPECIFICATION_REVISION: u32 = SYSTEM_TABLE_REVISION;
643
644#[repr(C)]
645#[derive(Clone, Copy, Debug)]
646pub struct TableHeader {
647    pub signature: u64,
648    pub revision: u32,
649    pub header_size: u32,
650    pub crc32: u32,
651    pub reserved: u32,
652}
653
654pub const RUNTIME_SERVICES_SIGNATURE: u64 = 0x56524553544e5552u64; // "RUNTSERV"
655pub const RUNTIME_SERVICES_REVISION: u32 = SPECIFICATION_REVISION;
656
657pub type RuntimeGetTime = eficall! {fn(
658    *mut Time,
659    *mut TimeCapabilities,
660) -> crate::base::Status};
661
662pub type RuntimeSetTime = eficall! {fn(
663    *mut Time,
664) -> crate::base::Status};
665
666pub type RuntimeGetWakeupTime = eficall! {fn(
667    *mut crate::base::Boolean,
668    *mut crate::base::Boolean,
669    *mut Time,
670) -> crate::base::Status};
671
672pub type RuntimeSetWakeupTime = eficall! {fn(
673    crate::base::Boolean,
674    *mut Time,
675) -> crate::base::Status};
676
677pub type RuntimeSetVirtualAddressMap = eficall! {fn(
678    usize,
679    usize,
680    u32,
681    *mut MemoryDescriptor,
682) -> crate::base::Status};
683
684pub type RuntimeConvertPointer = eficall! {fn(
685    usize,
686    *mut *mut core::ffi::c_void,
687) -> crate::base::Status};
688
689pub type RuntimeGetVariable = eficall! {fn(
690    *mut crate::base::Char16,
691    *mut crate::base::Guid,
692    *mut u32,
693    *mut usize,
694    *mut core::ffi::c_void,
695) -> crate::base::Status};
696
697pub type RuntimeGetNextVariableName = eficall! {fn(
698    *mut usize,
699    *mut crate::base::Char16,
700    *mut crate::base::Guid,
701) -> crate::base::Status};
702
703pub type RuntimeSetVariable = eficall! {fn(
704    *mut crate::base::Char16,
705    *mut crate::base::Guid,
706    u32,
707    usize,
708    *mut core::ffi::c_void,
709) -> crate::base::Status};
710
711pub type RuntimeGetNextHighMonoCount = eficall! {fn(
712    *mut u32,
713) -> crate::base::Status};
714
715pub type RuntimeResetSystem = eficall! {fn(
716    ResetType,
717    crate::base::Status,
718    usize,
719    *mut core::ffi::c_void,
720)};
721
722pub type RuntimeUpdateCapsule = eficall! {fn(
723    *mut *mut CapsuleHeader,
724    usize,
725    crate::base::PhysicalAddress,
726) -> crate::base::Status};
727
728pub type RuntimeQueryCapsuleCapabilities = eficall! {fn(
729    *mut *mut CapsuleHeader,
730    usize,
731    *mut u64,
732    *mut ResetType,
733) -> crate::base::Status};
734
735pub type RuntimeQueryVariableInfo = eficall! {fn(
736    u32,
737    *mut u64,
738    *mut u64,
739    *mut u64,
740) -> crate::base::Status};
741
742#[repr(C)]
743pub struct RuntimeServices {
744    pub hdr: TableHeader,
745
746    pub get_time: RuntimeGetTime,
747    pub set_time: RuntimeSetTime,
748    pub get_wakeup_time: RuntimeGetWakeupTime,
749    pub set_wakeup_time: RuntimeSetWakeupTime,
750
751    pub set_virtual_address_map: RuntimeSetVirtualAddressMap,
752    pub convert_pointer: RuntimeConvertPointer,
753
754    pub get_variable: RuntimeGetVariable,
755    pub get_next_variable_name: RuntimeGetNextVariableName,
756    pub set_variable: RuntimeSetVariable,
757
758    pub get_next_high_mono_count: RuntimeGetNextHighMonoCount,
759    pub reset_system: RuntimeResetSystem,
760
761    pub update_capsule: RuntimeUpdateCapsule,
762    pub query_capsule_capabilities: RuntimeQueryCapsuleCapabilities,
763    pub query_variable_info: RuntimeQueryVariableInfo,
764}
765
766pub const BOOT_SERVICES_SIGNATURE: u64 = 0x56524553544f4f42u64; // "BOOTSERV"
767pub const BOOT_SERVICES_REVISION: u32 = SPECIFICATION_REVISION;
768
769pub type BootRaiseTpl = eficall! {fn(
770    crate::base::Tpl,
771) -> crate::base::Tpl};
772
773pub type BootRestoreTpl = eficall! {fn(
774    crate::base::Tpl,
775)};
776
777pub type BootAllocatePages = eficall! {fn(
778    AllocateType,
779    MemoryType,
780    usize,
781    *mut crate::base::PhysicalAddress,
782) -> crate::base::Status};
783
784pub type BootFreePages = eficall! {fn(
785    crate::base::PhysicalAddress,
786    usize,
787) -> crate::base::Status};
788
789pub type BootGetMemoryMap = eficall! {fn(
790    *mut usize,
791    *mut MemoryDescriptor,
792    *mut usize,
793    *mut usize,
794    *mut u32,
795) -> crate::base::Status};
796
797pub type BootAllocatePool = eficall! {fn(
798    MemoryType,
799    usize,
800    *mut *mut core::ffi::c_void,
801) -> crate::base::Status};
802
803pub type BootFreePool = eficall! {fn(
804    *mut core::ffi::c_void,
805) -> crate::base::Status};
806
807pub type BootCreateEvent = eficall! {fn(
808    u32,
809    crate::base::Tpl,
810    Option<EventNotify>,
811    *mut core::ffi::c_void,
812    *mut crate::base::Event,
813) -> crate::base::Status};
814
815pub type BootSetTimer = eficall! {fn(
816    crate::base::Event,
817    TimerDelay,
818    u64,
819) -> crate::base::Status};
820
821pub type BootWaitForEvent = eficall! {fn(
822    usize,
823    *mut crate::base::Event,
824    *mut usize,
825) -> crate::base::Status};
826
827pub type BootSignalEvent = eficall! {fn(
828    crate::base::Event,
829) -> crate::base::Status};
830
831pub type BootCloseEvent = eficall! {fn(
832    crate::base::Event,
833) -> crate::base::Status};
834
835pub type BootCheckEvent = eficall! {fn(
836    crate::base::Event,
837) -> crate::base::Status};
838
839pub type BootInstallProtocolInterface = eficall! {fn(
840    *mut crate::base::Handle,
841    *mut crate::base::Guid,
842    InterfaceType,
843    *mut core::ffi::c_void,
844) -> crate::base::Status};
845
846pub type BootReinstallProtocolInterface = eficall! {fn(
847    crate::base::Handle,
848    *mut crate::base::Guid,
849    *mut core::ffi::c_void,
850    *mut core::ffi::c_void,
851) -> crate::base::Status};
852
853pub type BootUninstallProtocolInterface = eficall! {fn(
854    crate::base::Handle,
855    *mut crate::base::Guid,
856    *mut core::ffi::c_void,
857) -> crate::base::Status};
858
859pub type BootHandleProtocol = eficall! {fn(
860    crate::base::Handle,
861    *mut crate::base::Guid,
862    *mut *mut core::ffi::c_void,
863) -> crate::base::Status};
864
865pub type BootRegisterProtocolNotify = eficall! {fn(
866    *mut crate::base::Guid,
867    crate::base::Event,
868    *mut *mut core::ffi::c_void,
869) -> crate::base::Status};
870
871pub type BootLocateHandle = eficall! {fn(
872    LocateSearchType,
873    *mut crate::base::Guid,
874    *mut core::ffi::c_void,
875    *mut usize,
876    *mut crate::base::Handle,
877) -> crate::base::Status};
878
879pub type BootLocateDevicePath = eficall! {fn(
880    *mut crate::base::Guid,
881    *mut *mut crate::protocols::device_path::Protocol,
882    *mut crate::base::Handle,
883) -> crate::base::Status};
884
885pub type BootInstallConfigurationTable = eficall! {fn(
886    *mut crate::base::Guid,
887    *mut core::ffi::c_void,
888) -> crate::base::Status};
889
890pub type BootLoadImage = eficall! {fn(
891    crate::base::Boolean,
892    crate::base::Handle,
893    *mut crate::protocols::device_path::Protocol,
894    *mut core::ffi::c_void,
895    usize,
896    *mut crate::base::Handle,
897) -> crate::base::Status};
898
899pub type BootStartImage = eficall! {fn(
900    crate::base::Handle,
901    *mut usize,
902    *mut *mut crate::base::Char16,
903) -> crate::base::Status};
904
905pub type BootExit = eficall! {fn(
906    crate::base::Handle,
907    crate::base::Status,
908    usize,
909    *mut crate::base::Char16,
910) -> crate::base::Status};
911
912pub type BootUnloadImage = eficall! {fn(
913    crate::base::Handle,
914) -> crate::base::Status};
915
916pub type BootExitBootServices = eficall! {fn(
917    crate::base::Handle,
918    usize,
919) -> crate::base::Status};
920
921pub type BootGetNextMonotonicCount = eficall! {fn(
922    *mut u64,
923) -> crate::base::Status};
924
925pub type BootStall = eficall! {fn(
926    usize,
927) -> crate::base::Status};
928
929pub type BootSetWatchdogTimer = eficall! {fn(
930    usize,
931    u64,
932    usize,
933    *mut crate::base::Char16,
934) -> crate::base::Status};
935
936pub type BootConnectController = eficall! {fn(
937    crate::base::Handle,
938    *mut crate::base::Handle,
939    *mut crate::protocols::device_path::Protocol,
940    crate::base::Boolean,
941) -> crate::base::Status};
942
943pub type BootDisconnectController = eficall! {fn(
944    crate::base::Handle,
945    crate::base::Handle,
946    crate::base::Handle,
947) -> crate::base::Status};
948
949pub type BootOpenProtocol = eficall! {fn(
950    crate::base::Handle,
951    *mut crate::base::Guid,
952    *mut *mut core::ffi::c_void,
953    crate::base::Handle,
954    crate::base::Handle,
955    u32,
956) -> crate::base::Status};
957
958pub type BootCloseProtocol = eficall! {fn(
959    crate::base::Handle,
960    *mut crate::base::Guid,
961    crate::base::Handle,
962    crate::base::Handle,
963) -> crate::base::Status};
964
965pub type BootOpenProtocolInformation = eficall! {fn(
966    crate::base::Handle,
967    *mut crate::base::Guid,
968    *mut *mut OpenProtocolInformationEntry,
969    *mut usize,
970) -> crate::base::Status};
971
972pub type BootProtocolsPerHandle = eficall! {fn(
973    crate::base::Handle,
974    *mut *mut *mut crate::base::Guid,
975    *mut usize,
976) -> crate::base::Status};
977
978pub type BootLocateHandleBuffer = eficall! {fn(
979    LocateSearchType,
980    *mut crate::base::Guid,
981    *mut core::ffi::c_void,
982    *mut usize,
983    *mut *mut crate::base::Handle,
984) -> crate::base::Status};
985
986pub type BootLocateProtocol = eficall! {fn(
987    *mut crate::base::Guid,
988    *mut core::ffi::c_void,
989    *mut *mut core::ffi::c_void,
990) -> crate::base::Status};
991
992pub type BootInstallMultipleProtocolInterfaces = eficall! {fn(
993    *mut crate::base::Handle,
994    // XXX: Actual definition is variadic. See eficall!{} for details.
995    *mut core::ffi::c_void,
996    *mut core::ffi::c_void,
997) -> crate::base::Status};
998
999pub type BootUninstallMultipleProtocolInterfaces = eficall! {fn(
1000    crate::base::Handle,
1001    // XXX: Actual definition is variadic. See eficall!{} for details.
1002    *mut core::ffi::c_void,
1003    *mut core::ffi::c_void,
1004) -> crate::base::Status};
1005
1006pub type BootCalculateCrc32 = eficall! {fn(
1007    *mut core::ffi::c_void,
1008    usize,
1009    *mut u32,
1010) -> crate::base::Status};
1011
1012pub type BootCopyMem = eficall! {fn(
1013    *mut core::ffi::c_void,
1014    *mut core::ffi::c_void,
1015    usize,
1016)};
1017
1018pub type BootSetMem = eficall! {fn(
1019    *mut core::ffi::c_void,
1020    usize,
1021    u8,
1022)};
1023
1024pub type BootCreateEventEx = eficall! {fn(
1025    u32,
1026    crate::base::Tpl,
1027    Option<EventNotify>,
1028    *const core::ffi::c_void,
1029    *const crate::base::Guid,
1030    *mut crate::base::Event,
1031) -> crate::base::Status};
1032
1033#[repr(C)]
1034pub struct BootServices {
1035    pub hdr: TableHeader,
1036
1037    pub raise_tpl: BootRaiseTpl,
1038    pub restore_tpl: BootRestoreTpl,
1039
1040    pub allocate_pages: BootAllocatePages,
1041    pub free_pages: BootFreePages,
1042    pub get_memory_map: BootGetMemoryMap,
1043    pub allocate_pool: BootAllocatePool,
1044    pub free_pool: BootFreePool,
1045
1046    pub create_event: BootCreateEvent,
1047    pub set_timer: BootSetTimer,
1048    pub wait_for_event: BootWaitForEvent,
1049    pub signal_event: BootSignalEvent,
1050    pub close_event: BootCloseEvent,
1051    pub check_event: BootCheckEvent,
1052
1053    pub install_protocol_interface: BootInstallProtocolInterface,
1054    pub reinstall_protocol_interface: BootReinstallProtocolInterface,
1055    pub uninstall_protocol_interface: BootUninstallProtocolInterface,
1056    pub handle_protocol: BootHandleProtocol,
1057    pub reserved: *mut core::ffi::c_void,
1058    pub register_protocol_notify: BootRegisterProtocolNotify,
1059    pub locate_handle: BootLocateHandle,
1060    pub locate_device_path: BootLocateDevicePath,
1061
1062    pub install_configuration_table: BootInstallConfigurationTable,
1063
1064    pub load_image: BootLoadImage,
1065    pub start_image: BootStartImage,
1066    pub exit: BootExit,
1067    pub unload_image: BootUnloadImage,
1068    pub exit_boot_services: BootExitBootServices,
1069
1070    pub get_next_monotonic_count: BootGetNextMonotonicCount,
1071    pub stall: BootStall,
1072    pub set_watchdog_timer: BootSetWatchdogTimer,
1073
1074    // 1.1+
1075    pub connect_controller: BootConnectController,
1076    pub disconnect_controller: BootDisconnectController,
1077
1078    pub open_protocol: BootOpenProtocol,
1079    pub close_protocol: BootCloseProtocol,
1080    pub open_protocol_information: BootOpenProtocolInformation,
1081
1082    pub protocols_per_handle: BootProtocolsPerHandle,
1083    pub locate_handle_buffer: BootLocateHandleBuffer,
1084    pub locate_protocol: BootLocateProtocol,
1085    pub install_multiple_protocol_interfaces: BootInstallMultipleProtocolInterfaces,
1086    pub uninstall_multiple_protocol_interfaces: BootUninstallMultipleProtocolInterfaces,
1087
1088    pub calculate_crc32: BootCalculateCrc32,
1089
1090    pub copy_mem: BootCopyMem,
1091    pub set_mem: BootSetMem,
1092
1093    // 2.0+
1094    pub create_event_ex: BootCreateEventEx,
1095}
1096
1097pub const SYSTEM_TABLE_REVISION_2_70: u32 = (2 << 16) | (70);
1098pub const SYSTEM_TABLE_REVISION_2_60: u32 = (2 << 16) | (60);
1099pub const SYSTEM_TABLE_REVISION_2_50: u32 = (2 << 16) | (50);
1100pub const SYSTEM_TABLE_REVISION_2_40: u32 = (2 << 16) | (40);
1101pub const SYSTEM_TABLE_REVISION_2_31: u32 = (2 << 16) | (31);
1102pub const SYSTEM_TABLE_REVISION_2_30: u32 = (2 << 16) | (30);
1103pub const SYSTEM_TABLE_REVISION_2_20: u32 = (2 << 16) | (20);
1104pub const SYSTEM_TABLE_REVISION_2_10: u32 = (2 << 16) | (10);
1105pub const SYSTEM_TABLE_REVISION_2_00: u32 = (2 << 16) | (0);
1106pub const SYSTEM_TABLE_REVISION_1_10: u32 = (1 << 16) | (10);
1107pub const SYSTEM_TABLE_REVISION_1_02: u32 = (1 << 16) | (2);
1108
1109pub const SYSTEM_TABLE_SIGNATURE: u64 = 0x5453595320494249u64; // "IBI SYST"
1110pub const SYSTEM_TABLE_REVISION: u32 = SYSTEM_TABLE_REVISION_2_70;
1111
1112#[repr(C)]
1113pub struct SystemTable {
1114    pub hdr: TableHeader,
1115    pub firmware_vendor: *mut crate::base::Char16,
1116    pub firmware_revision: u32,
1117
1118    pub console_in_handle: crate::base::Handle,
1119    pub con_in: *mut crate::protocols::simple_text_input::Protocol,
1120    pub console_out_handle: crate::base::Handle,
1121    pub con_out: *mut crate::protocols::simple_text_output::Protocol,
1122    pub standard_error_handle: crate::base::Handle,
1123    pub std_err: *mut crate::protocols::simple_text_output::Protocol,
1124
1125    pub runtime_services: *mut RuntimeServices,
1126    pub boot_services: *mut BootServices,
1127
1128    pub number_of_table_entries: usize,
1129    pub configuration_table: *mut ConfigurationTable,
1130}