1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __BOOT_SERVICE_TABLE_H__
19 #define __BOOT_SERVICE_TABLE_H__
20 
21 #include <uefi/protocols/device_path_protocol.h>
22 
23 #include "types.h"
24 
25 typedef enum EFI_LOCATE_HANDLE_SEARCH_TYPE {
26   ALL_HANDLES = 0,
27   BY_REGITER_NOTIFY,
28   BY_PROTOCOL,
29 } EFI_LOCATE_HANDLE_SEARCH_TYPE;
30 
31 typedef EFI_LOCATE_HANDLE_SEARCH_TYPE EfiLocateHandleSearchType;
32 
33 typedef enum { EFI_NATIVE_INTERFACE } EFI_INTERFACE_TYPE;
34 
35 typedef EFI_INTERFACE_TYPE EfiInterfaceType;
36 
37 typedef enum EFI_ALLOCATOR_TYPE {
38   ALLOCATE_ANY_PAGES,
39   ALLOCATE_MAX_ADDRESS,
40   ALLOCATE_ADDRESS,
41   MAX_ALLOCATE_TYPE
42 } EfiAllocatorType;
43 
44 typedef enum EFI_OPEN_PROTOCOL_ATTRIBUTE : uint32_t {
45   BY_HANDLE_PROTOCOL = 0x00000001,
46   GET_PROTOCOL = 0x00000002,
47   TEST_PROTOCOL = 0x00000004,
48   BY_CHILD_CONTROLLER = 0x00000008,
49   BY_DRIVER = 0x00000010,
50   EXCLUSIVE = 0x00000020,
51 } EfiOpenProtocolAttributes;
52 
53 #define EFI_MEMORY_UC 0x0000000000000001ULL
54 #define EFI_MEMORY_WC 0x0000000000000002ULL
55 #define EFI_MEMORY_WT 0x0000000000000004ULL
56 #define EFI_MEMORY_WB 0x0000000000000008ULL
57 #define EFI_MEMORY_UCE 0x0000000000000010ULL
58 
59 typedef struct {
60   uint32_t memory_type;
61   uint32_t padding;
62   EfiPhysicalAddr physical_start;
63   EfiVirtualAddr virtual_start;
64   uint64_t number_of_pages;
65   uint64_t attributes;
66 } EfiMemoryDescriptor;
67 
68 typedef struct {
69   EfiHandle agent_handle;
70   EfiHandle controller_handle;
71   uint32_t attributes;
72   uint32_t open_count;
73 } EfiOpenProtocolInformationEntry;
74 
75 typedef struct {
76   EfiTableHeader hdr;
77   EfiTpl (*raise_tpl)(EfiTpl new_tpl);
78   void (*restore_tpl)(EfiTpl old_tpl);
79   EfiStatus (*allocate_pages)(EfiAllocatorType type, EfiMemoryType memory_type,
80                               size_t pages, EfiPhysicalAddr* memory);
81   EfiStatus (*free_pages)(EfiPhysicalAddr memory, size_t pages);
82   EfiStatus (*get_memory_map)(size_t* memory_map_size,
83                               EfiMemoryDescriptor* memory_map, size_t* map_key,
84                               size_t* desc_size, uint32_t* desc_version);
85   EfiStatus (*allocate_pool)(EfiMemoryType pool_type, size_t size, void** buf);
86   EfiStatus (*free_pool)(void* buf);
87   EfiStatus (*create_event)(EfiEventType type, EfiTpl notify_tpl,
88                             EfiEventNotify notify_fn, void* notify_ctx,
89                             EfiEvent* event);
90   EfiStatus (*set_timer)(EfiEvent event, EfiTimerDelay type,
91                          uint64_t trigger_time);
92   EfiStatus (*wait_for_event)(size_t num_events, EfiEvent* event,
93                               size_t* index);
94   EfiStatus (*signal_event)(EfiEvent event);
95   EfiStatus (*close_event)(EfiEvent event);
96   EfiStatus (*check_event)(EfiEvent event);
97   EfiStatus (*install_protocol_interface)(EfiHandle* handle,
98                                           const EfiGuid* protocol,
99                                           EfiInterfaceType intf_type,
100                                           void* intf);
101   EfiStatus (*reinstall_protocol_interface)(EfiHandle hadle,
102                                             const EfiGuid* protocol,
103                                             void* old_intf, void* new_intf);
104   EfiStatus (*uninstall_protocol_interface)(EfiHandle handle,
105                                             const EfiGuid* protocol,
106                                             void* intf);
107   EfiStatus (*handle_protocol)(EfiHandle handle, const EfiGuid* protocol,
108                                void** intf);
109   void* reserved;
110   EfiStatus (*register_protocol_notify)(const EfiGuid* protocol, EfiEvent event,
111                                         void** registration);
112   EfiStatus (*locate_handle)(EfiLocateHandleSearchType search_type,
113                              const EfiGuid* protocol, void* search_key,
114                              size_t* buf_size, EfiHandle* buf);
115   EfiStatus (*locate_device_path)(const EfiGuid* protocol,
116                                   EfiDevicePathProtocol** path,
117                                   EfiHandle* device);
118   EfiStatus (*install_configuration_table)(const EfiGuid* guid, void* table);
119   EfiStatus (*load_image)(bool boot_policy, EfiHandle parent_image_handle,
120                           EfiDevicePathProtocol* path, void* src,
121                           size_t src_size, EfiHandle* image_handle);
122   EfiStatus (*start_image)(EfiHandle image_handle, size_t* exit_data_size,
123                            char16_t** exit_data);
124   EfiStatus (*exit)(EfiHandle image_handle, EfiStatus exit_status,
125                     size_t exit_data_size, char16_t* exit_data);
126   EfiStatus (*unload_image)(EfiHandle image_handle);
127   EfiStatus (*exit_boot_services)(EfiHandle image_handle, size_t map_key);
128   EfiStatus (*get_next_monotonic_count)(uint64_t* count);
129   EfiStatus (*stall)(size_t microseconds);
130   EfiStatus (*set_watchdog_timer)(size_t timeout, uint64_t watchdog_code,
131                                   size_t data_size, char16_t* watchdog_data);
132   EfiStatus (*connect_controller)(EfiHandle controller_handle,
133                                   EfiHandle* driver_image_handle,
134                                   EfiDevicePathProtocol* remaining_path,
135                                   bool recursive);
136   EfiStatus (*disconnect_controller)(EfiHandle controller_handle,
137                                      EfiHandle driver_image_handle,
138                                      EfiHandle child_handle);
139   EfiStatus (*open_protocol)(EfiHandle handle, const EfiGuid* protocol,
140                              void** intf, EfiHandle agent_handle,
141                              EfiHandle controller_handle,
142                              EfiOpenProtocolAttributes attr);
143   EfiStatus (*close_protocol)(EfiHandle handle, const EfiGuid* protocol,
144                               EfiHandle agent_handle,
145                               EfiHandle controller_handle);
146   EfiStatus (*open_protocol_information)(
147       EfiHandle handle, const EfiGuid* protocol,
148       EfiOpenProtocolInformationEntry** entry_buf, size_t* entry_count);
149   EfiStatus (*protocols_per_handle)(EfiHandle handle, EfiGuid*** protocol_buf,
150                                     size_t* protocol_buf_count);
151   EfiStatus (*locate_handle_buffer)(EfiLocateHandleSearchType search_type,
152                                     const EfiGuid* protocol, void* search_key,
153                                     size_t* num_handles, EfiHandle** buf);
154   EfiStatus (*locate_protocol)(const EfiGuid* protocol, void* registration,
155                                void** intf);
156   EfiStatus (*install_multiple_protocol_interfaces)(EfiHandle* handle, ...);
157   EfiStatus (*uninstall_multiple_protocol_interfaces)(EfiHandle handle, ...);
158   EfiStatus (*calculate_crc32)(void* data, size_t len, uint32_t* crc32);
159   void (*copy_mem)(void* dest, const void* src, size_t len);
160   void (*set_mem)(void* buf, size_t len, uint8_t val);
161   EfiStatus (*create_event_ex)(EfiEventType type, EfiTpl notify_tpl,
162                                EfiEventNotify notify_fn, const void* notify_ctx,
163                                const EfiGuid* event_group, EfiEvent* event);
164 } EfiBootService;
165 
166 #endif  // __BOOT_SERVICE_TABLE_H__