xref: /haiku/headers/private/kernel/platform/efi/boot-services.h (revision 2db2b2123bf807aa7d812d0b15438c74bf3124f3)
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/protocol/device-path.h>
9 #include <stdbool.h>
10 
11 #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
12 #define EFI_BOOT_SERVICES_REVISION EFI_SPECIFICATION_VERSION
13 
14 typedef size_t efi_tpl;
15 
16 #define TPL_APPLICATION 4
17 #define TPL_CALLBACK    8
18 #define TPL_NOTIFY     16
19 #define TPL_HIGH_LEVEL 31
20 
21 typedef enum {
22     AllocateAnyPages,
23     AllocateMaxAddress,
24     AllocateAddress,
25     MaxAllocateType
26 } efi_allocate_type;
27 
28 typedef struct {
29     uint32_t Type;
30     uint32_t Padding;
31     efi_physical_addr PhysicalStart;
32     efi_virtual_addr VirtualStart;
33     uint64_t NumberOfPages;
34     uint64_t Attribute;
35 } efi_memory_descriptor;
36 
37 #define EFI_MEMORY_UC 0x0000000000000001
38 #define EFI_MEMORY_WC 0x0000000000000002
39 #define EFI_MEMORY_WT 0x0000000000000004
40 #define EFI_MEMORY_WB 0x0000000000000008
41 #define EFI_MEMORY_UCE 0x0000000000000010
42 #define EFI_MEMORY_WP 0x0000000000001000
43 #define EFI_MEMORY_RP 0x0000000000002000
44 #define EFI_MEMORY_XP 0x0000000000004000
45 #define EFI_MEMORY_NV 0x0000000000008000
46 #define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000
47 #define EFI_MEMORY_RO 0x0000000000020000
48 #define EFI_MEMORY_RUNTIME 0x8000000000000000
49 
50 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
51 
52 typedef enum {
53     EFI_NATIVE_INTERFACE
54 } efi_interface_type;
55 
56 typedef enum {
57     AllHandles,
58     ByRegisterNotify,
59     ByProtocol
60 } efi_locate_search_type;
61 
62 #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
63 #define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
64 #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
65 #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
66 #define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
67 #define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
68 
69 typedef struct {
70     efi_handle agent_handle;
71     efi_handle controller_handle;
72     uint32_t attributes;
73     uint32_t open_count;
74 } efi_open_protocol_information_entry;
75 
76 #define EFI_HII_PACKAGE_LIST_PROTOCOL_GUID \
77     {0x6a1ee763, 0xd47a, 0x43b4, {0xaa, 0xbe, 0xef, 0x1d, 0xe2, 0xab, 0x56, 0xfc}}
78 
79 typedef struct efi_hii_package_list_header efi_hii_package_list_header;
80 typedef efi_hii_package_list_header* efi_hii_package_list_protocol;
81 
82 // fwd declare efi_system_table to break circular dependencies
83 typedef struct efi_system_table efi_system_table;
84 typedef efi_status (*efi_image_entry_point) (efi_handle img, efi_system_table* sys) EFIAPI;
85 
86 typedef struct {
87     efi_table_header Hdr;
88 
89     efi_tpl (*RaiseTPL) (efi_tpl new_tpl) EFIAPI;
90 
91     void (*RestoreTPL) (efi_tpl old_tpl) EFIAPI;
92 
93     efi_status (*AllocatePages) (efi_allocate_type type, efi_memory_type memory_type,
94                                  size_t pages, efi_physical_addr* memory) EFIAPI;
95 
96     efi_status (*FreePages) (efi_physical_addr memory, size_t pages) EFIAPI;
97 
98     efi_status (*GetMemoryMap) (size_t* memory_map_size, efi_memory_descriptor* memory_map,
99                                 size_t* map_key, size_t* desc_size, uint32_t* desc_version) EFIAPI;
100 
101     efi_status (*AllocatePool) (efi_memory_type pool_type, size_t size, void** buf) EFIAPI;
102 
103     efi_status (*FreePool) (void* buf) EFIAPI;
104 
105     efi_status (*CreateEvent) (uint32_t type, efi_tpl notify_tpl,
106                                efi_event_notify notify_fn, void* notify_ctx,
107                                efi_event* event) EFIAPI;
108 
109     efi_status (*SetTimer) (efi_event event, efi_timer_delay type, uint64_t trigger_time) EFIAPI;
110 
111     efi_status (*WaitForEvent) (size_t num_events, efi_event* event, size_t* index) EFIAPI;
112 
113     efi_status (*SignalEvent) (efi_event event) EFIAPI;
114 
115     efi_status (*CloseEvent) (efi_event event) EFIAPI;
116 
117     efi_status (*CheckEvent) (efi_event event) EFIAPI;
118 
119     efi_status (*InstallProtocolInterface) (efi_handle* handle, efi_guid* protocol,
120                                             efi_interface_type intf_type, void* intf) EFIAPI;
121 
122     efi_status (*ReinstallProtocolInterface) (efi_handle hadle, efi_guid* protocol,
123                                               void* old_intf, void* new_intf) EFIAPI;
124 
125     efi_status (*UninstallProtocolInterface) (efi_handle handle, efi_guid* protocol,
126                                               void* intf) EFIAPI;
127 
128     efi_status (*HandleProtocol) (efi_handle handle, efi_guid* protocol, void** intf) EFIAPI;
129 
130     void* Reserved;
131 
132     efi_status (*RegisterProtocolNotify) (efi_guid* protocol, efi_event event,
133                                           void** registration) EFIAPI;
134 
135     efi_status (*LocateHandle) (efi_locate_search_type search_type, efi_guid* protocol,
136                                 void* search_key, size_t* buf_size, efi_handle* buf) EFIAPI;
137 
138     efi_status (*LocateDevicePath) (efi_guid* protocol, efi_device_path_protocol** path,
139                                     efi_handle* device) EFIAPI;
140 
141     efi_status (*InstallConfigurationTable) (efi_guid* guid, void* table) EFIAPI;
142 
143     efi_status (*LoadImage) (bool boot_policy, efi_handle parent_image_handle,
144                              efi_device_path_protocol* path, void* src, size_t src_size,
145                              efi_handle* image_handle) EFIAPI;
146 
147     efi_status (*StartImage) (efi_handle image_handle, size_t* exit_data_size,
148                               char16_t** exit_data) EFIAPI;
149 
150     efi_status (*Exit) (efi_handle image_handle, efi_status exit_status,
151                         size_t exit_data_size, char16_t* exit_data) EFIAPI;
152 
153     efi_status (*UnloadImage) (efi_handle image_handle) EFIAPI;
154 
155     efi_status (*ExitBootServices) (efi_handle image_handle, size_t map_key) EFIAPI;
156 
157     efi_status (*GetNextMonotonicCount) (uint64_t* count) EFIAPI;
158 
159     efi_status (*Stall) (size_t microseconds) EFIAPI;
160 
161     efi_status (*SetWatchdogTimer) (size_t timeout, uint64_t watchdog_code,
162                                     size_t data_size, char16_t* watchdog_data) EFIAPI;
163 
164     efi_status (*ConnectController) (efi_handle controller_handle,
165                                      efi_handle* driver_image_handle,
166                                      efi_device_path_protocol* remaining_path,
167                                      bool recursive) EFIAPI;
168 
169     efi_status (*DisconnectController) (efi_handle controller_handle,
170                                         efi_handle driver_image_handle,
171                                         efi_handle child_handle) EFIAPI;
172 
173     efi_status (*OpenProtocol) (efi_handle handle, efi_guid* protocol, void** intf,
174                                 efi_handle agent_handle, efi_handle controller_handle,
175                                 uint32_t attributes) EFIAPI;
176 
177     efi_status (*CloseProtocol) (efi_handle handle, efi_guid* protocol,
178                                  efi_handle agent_handle, efi_handle controller_handle) EFIAPI;
179 
180     efi_status (*OpenProtocolInformation) (efi_handle handle, efi_guid* protocol,
181                                            efi_open_protocol_information_entry** entry_buf,
182                                            size_t* entry_count) EFIAPI;
183 
184     efi_status (*ProtocolsPerHandle) (efi_handle handle, efi_guid*** protocol_buf,
185                                       size_t* protocol_buf_count) EFIAPI;
186 
187     efi_status (*LocateHandleBuffer) (efi_locate_search_type search_type,
188                                       efi_guid* protocol, void* search_key,
189                                       size_t* num_handles, efi_handle** buf) EFIAPI;
190 
191     efi_status (*LocateProtocol) (efi_guid* protocol, void* registration, void** intf) EFIAPI;
192 
193     efi_status (*InstallMultipleProtocolInterfaces) (efi_handle* handle, ...) EFIAPI;
194 
195     efi_status (*UninstallMultipleProtocolInterfaces) (efi_handle handle, ...) EFIAPI;
196 
197     efi_status (*CalculateCrc32) (void* data, size_t len, uint32_t* crc32) EFIAPI;
198 
199     void (*CopyMem) (void* dest, const void* src, size_t len) EFIAPI;
200 
201     void (*SetMem) (void* buf, size_t len, uint8_t val) EFIAPI;
202 
203     efi_status (*CreateEventEx) (uint32_t type, efi_tpl notify_tpl,
204                                  efi_event_notify notify_fn, const void* notify_ctx,
205                                  const efi_guid* event_group, efi_event* event) EFIAPI;
206 } efi_boot_services;
207