xref: /haiku/headers/private/kernel/platform/efi/runtime-services.h (revision a5061ecec55353a5f394759473f1fd6df04890da)
1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <efi/types.h>
8 #include <efi/boot-services.h>
9 
10 #define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552
11 #define EFI_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_VERSION
12 
13 #define EFI_VARIABLE_NON_VOLATILE                          0x00000001
14 #define EFI_VARIABLE_BOOTSERVICE_ACCESS                    0x00000002
15 #define EFI_VARIABLE_RUNTIME_ACCESS                        0x00000004
16 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD                 0x00000008
17 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS            0x00000010
18 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
19 #define EFI_VARIABLE_APPEND_WRITE                          0x00000040
20 
21 // TODO: implement the win_certificate structs if we need them
22 //typedef struct {
23 //    uint64_t MonotonicCount;
24 //    win_certificate_uefi_guid AuthInfo;
25 //} efi_variable_authentication;
26 //
27 //typedef struct {
28 //    efi_time TimeStamp;
29 //    win_certificate_uefi_guid AuthInfo;
30 //} efi_variable_authentication_2;
31 
32 #define EFI_HARDWARE_ERROR_VARIABLE \
33     {0x414e6bdd, 0xe47b, 0x47cc, {0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c, 0xf5, 0x16}}
34 
35 #define EFI_GLOBAL_VARIABLE \
36 	{0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C}}
37 
38 typedef struct {
39     uint16_t Year;
40     uint8_t  Month;
41     uint8_t  Day;
42     uint8_t  Hour;
43     uint8_t  Minute;
44     uint8_t  Second;
45     uint8_t  Pad1;
46     uint32_t Nanosecond;
47     int16_t  TimeZone;
48     uint8_t  Daylight;
49     uint8_t  Pad2;
50 } efi_time;
51 
52 #define EFI_TIME_ADJUST_DAYLIGHT 0x01
53 #define EFI_TIME_IN_DAYLIGHT     0x02
54 
55 #define EFI_UNSPECIFIED_TIMEZONE 0x07FF
56 
57 typedef struct {
58     uint32_t Resolution;
59     uint32_t Accuracy;
60     bool SetsToZero;
61 } efi_time_capabilities;
62 
63 #define EFI_OPTIONAL_PTR 0x00000001
64 
65 typedef enum {
66     EfiResetCold,
67     EfiResetWarm,
68     EfiResetShutdown,
69     EfiResetPlatformSpecific
70 } efi_reset_type;
71 
72 typedef struct {
73     uint64_t Length;
74     union {
75         efi_physical_addr DataBlock;
76         efi_physical_addr ContinuationPointer;
77     } Union;
78 } efi_capsule_block_descriptor;
79 
80 typedef struct {
81     efi_guid CapsuleGuid;
82     uint32_t HeaderSize;
83     uint32_t Flags;
84     uint32_t CapsuleImageSize;
85 } efi_capsule_header;
86 
87 #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET  0x00010000
88 #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000
89 #define CAPSULE_FLAGS_INITIATE_RESET        0x00040000
90 
91 #define EFI_OS_INDICATIONS_BOOT_TO_FW_UI                   0x0000000000000001
92 #define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION            0x0000000000000002
93 #define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED 0x0000000000000004
94 #define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED           0x0000000000000008
95 #define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED    0x0000000000000010
96 #define EFI_OS_INDICATIONS_START_OS_RECOVERY               0x0000000000000020
97 #define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY         0x0000000000000040
98 
99 #define EFI_CAPSULE_REPORT_GUID \
100     {0x39b68c46, 0xf7fb, 0x441b, {0xb6, 0xec, 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3}}
101 
102 typedef struct {
103     uint32_t VariableTotalSize;
104     uint32_t Reserved;
105     efi_guid CapsuleGuid;
106     efi_time CapsuleProcessed;
107     efi_status CapsuleStatus;
108 } efi_capsule_result_variable_header;
109 
110 typedef struct {
111     efi_table_header Hdr;
112 
113     efi_status (*GetTime) (efi_time* time, efi_time_capabilities* capabilities) EFIAPI;
114 
115     efi_status (*SetTime) (efi_time* time) EFIAPI;
116 
117     efi_status (*GetWakeupTime) (bool* enabled, bool* pending, efi_time* time) EFIAPI;
118 
119     efi_status (*SetWakeupTime) (bool enable, efi_time* time) EFIAPI;
120 
121     efi_status (*SetVirtualAddressMap) (size_t memory_map_size, size_t desc_size,
122                                         uint32_t desc_version,
123                                         efi_memory_descriptor* virtual_map) EFIAPI;
124 
125     efi_status (*ConvertPointer) (size_t debug_disposition, void** addr) EFIAPI;
126 
127     efi_status (*GetVariable) (char16_t* var_name, efi_guid* vendor_guid,
128                                uint32_t* attributes, size_t* data_size, void* data) EFIAPI;
129 
130     efi_status (*GetNextVariableName) (size_t* var_name_size, char16_t* var_name,
131                                        efi_guid* vendor_guid) EFIAPI;
132 
133     efi_status (*SetVariable) (char16_t* var_name, efi_guid* vendor_guid,
134                                uint32_t attributes, size_t data_size, void* data) EFIAPI;
135 
136     efi_status (*GetNextHighMonotonicCount) (uint32_t* high_count) EFIAPI;
137 
138     efi_status (*ResetSystem) (efi_reset_type reset_type, efi_status reset_status,
139                                size_t data_size, void* reset_data) EFIAPI;
140 
141     efi_status (*UpdateCapsule) (efi_capsule_header** capsule_header_array,
142                                  size_t capsule_count,
143                                  efi_physical_addr scatter_gather_list) EFIAPI;
144 
145     efi_status (*QueryCapsuleCapabilities) (efi_capsule_header** capsule_header_array,
146                                             size_t capsule_count,
147                                             uint64_t* max_capsule_size,
148                                             efi_reset_type* reset_type) EFIAPI;
149 
150     efi_status (*QueryVariableInfo) (uint32_t attributes,
151                                      uint64_t* max_var_storage_size,
152                                      uint64_t* remaining_var_storage_size,
153                                      uint64_t* max_var_size) EFIAPI;
154 } efi_runtime_services;
155