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