Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2 | /* |
Heinrich Schuchardt | da8f900 | 2019-07-03 20:27:24 +0200 | [diff] [blame] | 3 | * EFI application boot time services |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 4 | * |
Heinrich Schuchardt | da8f900 | 2019-07-03 20:27:24 +0200 | [diff] [blame] | 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 8 | #include <common.h> |
Ilias Apalodimas | 4cc0632 | 2020-10-22 01:04:20 +0300 | [diff] [blame] | 9 | #include <bootm.h> |
Heinrich Schuchardt | 368ca64 | 2017-10-05 16:14:14 +0200 | [diff] [blame] | 10 | #include <div64.h> |
Ilias Apalodimas | c539fb8 | 2020-10-22 01:04:21 +0300 | [diff] [blame] | 11 | #include <dm/device.h> |
| 12 | #include <dm/root.h> |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 13 | #include <efi_loader.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 14 | #include <irq_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 16 | #include <malloc.h> |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 17 | #include <pe.h> |
Ilias Apalodimas | 4cc0632 | 2020-10-22 01:04:20 +0300 | [diff] [blame] | 18 | #include <time.h> |
Simon Glass | 48b6c6b | 2019-11-14 12:57:16 -0700 | [diff] [blame] | 19 | #include <u-boot/crc.h> |
Ilias Apalodimas | c539fb8 | 2020-10-22 01:04:21 +0300 | [diff] [blame] | 20 | #include <usb.h> |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 21 | #include <watchdog.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 22 | #include <asm/global_data.h> |
AKASHI Takahiro | 4cbba2b | 2021-07-20 14:57:02 +0900 | [diff] [blame] | 23 | #include <asm/setjmp.h> |
Ilias Apalodimas | 4cc0632 | 2020-10-22 01:04:20 +0300 | [diff] [blame] | 24 | #include <linux/libfdt_env.h> |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 28 | /* Task priority level */ |
Heinrich Schuchardt | f8d4ec3 | 2017-11-06 21:17:47 +0100 | [diff] [blame] | 29 | static efi_uintn_t efi_tpl = TPL_APPLICATION; |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 30 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 31 | /* This list contains all the EFI objects our payload has access to */ |
| 32 | LIST_HEAD(efi_obj_list); |
| 33 | |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 34 | /* List of all events */ |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 35 | __efi_runtime_data LIST_HEAD(efi_events); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 36 | |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 37 | /* List of queued events */ |
| 38 | LIST_HEAD(efi_event_queue); |
| 39 | |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 40 | /* Flag to disable timer activity in ExitBootServices() */ |
| 41 | static bool timers_enabled = true; |
| 42 | |
Heinrich Schuchardt | 628dbd7 | 2020-11-12 21:26:28 +0100 | [diff] [blame] | 43 | /* Flag used by the selftest to avoid detaching devices in ExitBootServices() */ |
| 44 | bool efi_st_keep_devices; |
| 45 | |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 46 | /* List of all events registered by RegisterProtocolNotify() */ |
| 47 | LIST_HEAD(efi_register_notify_events); |
| 48 | |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 49 | /* Handle of the currently executing image */ |
| 50 | static efi_handle_t current_image; |
| 51 | |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 52 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 53 | /* |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 54 | * The "gd" pointer lives in a register on ARM and RISC-V that we declare |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 55 | * fixed when compiling U-Boot. However, the payload does not know about that |
| 56 | * restriction so we need to manually swap its and our view of that register on |
| 57 | * EFI callback entry/exit. |
| 58 | */ |
Heinrich Schuchardt | 1a3732c | 2020-05-27 01:58:30 +0200 | [diff] [blame] | 59 | static volatile gd_t *efi_gd, *app_gd; |
Simon Glass | cdfe696 | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 60 | #endif |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 61 | |
Heinrich Schuchardt | 7250623 | 2019-02-09 14:10:39 +0100 | [diff] [blame] | 62 | /* 1 if inside U-Boot code, 0 if inside EFI payload code */ |
| 63 | static int entry_count = 1; |
Rob Clark | e7896c3 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 64 | static int nesting_level; |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 65 | /* GUID of the device tree table */ |
| 66 | const efi_guid_t efi_guid_fdt = EFI_FDT_GUID; |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 67 | /* GUID of the EFI_DRIVER_BINDING_PROTOCOL */ |
| 68 | const efi_guid_t efi_guid_driver_binding_protocol = |
| 69 | EFI_DRIVER_BINDING_PROTOCOL_GUID; |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 70 | |
Heinrich Schuchardt | 672d99e | 2018-02-18 15:17:51 +0100 | [diff] [blame] | 71 | /* event group ExitBootServices() invoked */ |
| 72 | const efi_guid_t efi_guid_event_group_exit_boot_services = |
| 73 | EFI_EVENT_GROUP_EXIT_BOOT_SERVICES; |
Heinrich Schuchardt | 44772c4 | 2021-11-16 18:46:27 +0100 | [diff] [blame] | 74 | /* event group before ExitBootServices() invoked */ |
| 75 | const efi_guid_t efi_guid_event_group_before_exit_boot_services = |
| 76 | EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES; |
Heinrich Schuchardt | 672d99e | 2018-02-18 15:17:51 +0100 | [diff] [blame] | 77 | /* event group SetVirtualAddressMap() invoked */ |
| 78 | const efi_guid_t efi_guid_event_group_virtual_address_change = |
| 79 | EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE; |
| 80 | /* event group memory map changed */ |
| 81 | const efi_guid_t efi_guid_event_group_memory_map_change = |
| 82 | EFI_EVENT_GROUP_MEMORY_MAP_CHANGE; |
| 83 | /* event group boot manager about to boot */ |
| 84 | const efi_guid_t efi_guid_event_group_ready_to_boot = |
| 85 | EFI_EVENT_GROUP_READY_TO_BOOT; |
| 86 | /* event group ResetSystem() invoked (before ExitBootServices) */ |
| 87 | const efi_guid_t efi_guid_event_group_reset_system = |
| 88 | EFI_EVENT_GROUP_RESET_SYSTEM; |
Heinrich Schuchardt | 485956d | 2020-12-04 03:33:41 +0100 | [diff] [blame] | 89 | /* GUIDs of the Load File and Load File2 protocols */ |
| 90 | const efi_guid_t efi_guid_load_file_protocol = EFI_LOAD_FILE_PROTOCOL_GUID; |
| 91 | const efi_guid_t efi_guid_load_file2_protocol = EFI_LOAD_FILE2_PROTOCOL_GUID; |
Masahisa Kojima | cd1fe7d | 2021-10-26 17:27:24 +0900 | [diff] [blame] | 92 | /* GUID of the SMBIOS table */ |
| 93 | const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; |
Heinrich Schuchardt | 672d99e | 2018-02-18 15:17:51 +0100 | [diff] [blame] | 94 | |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 95 | static efi_status_t EFIAPI efi_disconnect_controller( |
| 96 | efi_handle_t controller_handle, |
| 97 | efi_handle_t driver_image_handle, |
| 98 | efi_handle_t child_handle); |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 99 | |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 100 | /* Called on every callback entry */ |
| 101 | int __efi_entry_check(void) |
| 102 | { |
| 103 | int ret = entry_count++ == 0; |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 104 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 105 | assert(efi_gd); |
| 106 | app_gd = gd; |
Heinrich Schuchardt | 1a3732c | 2020-05-27 01:58:30 +0200 | [diff] [blame] | 107 | set_gd(efi_gd); |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 108 | #endif |
| 109 | return ret; |
| 110 | } |
| 111 | |
| 112 | /* Called on every callback exit */ |
| 113 | int __efi_exit_check(void) |
| 114 | { |
| 115 | int ret = --entry_count == 0; |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 116 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
Heinrich Schuchardt | 1a3732c | 2020-05-27 01:58:30 +0200 | [diff] [blame] | 117 | set_gd(app_gd); |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 118 | #endif |
| 119 | return ret; |
| 120 | } |
| 121 | |
Heinrich Schuchardt | c594941 | 2020-07-18 09:53:01 +0200 | [diff] [blame] | 122 | /** |
| 123 | * efi_save_gd() - save global data register |
| 124 | * |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 125 | * On the ARM and RISC-V architectures gd is mapped to a fixed register. |
Heinrich Schuchardt | c594941 | 2020-07-18 09:53:01 +0200 | [diff] [blame] | 126 | * As this register may be overwritten by an EFI payload we save it here |
| 127 | * and restore it on every callback entered. |
| 128 | * |
| 129 | * This function is called after relocation from initr_reloc_global_data(). |
| 130 | */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 131 | void efi_save_gd(void) |
| 132 | { |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 133 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 134 | efi_gd = gd; |
Simon Glass | cdfe696 | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 135 | #endif |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Heinrich Schuchardt | c594941 | 2020-07-18 09:53:01 +0200 | [diff] [blame] | 138 | /** |
| 139 | * efi_restore_gd() - restore global data register |
| 140 | * |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 141 | * On the ARM and RISC-V architectures gd is mapped to a fixed register. |
Heinrich Schuchardt | c594941 | 2020-07-18 09:53:01 +0200 | [diff] [blame] | 142 | * Restore it after returning from the UEFI world to the value saved via |
| 143 | * efi_save_gd(). |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 144 | */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 145 | void efi_restore_gd(void) |
| 146 | { |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 147 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 148 | /* Only restore if we're already in EFI context */ |
| 149 | if (!efi_gd) |
| 150 | return; |
Heinrich Schuchardt | 1a3732c | 2020-05-27 01:58:30 +0200 | [diff] [blame] | 151 | set_gd(efi_gd); |
Simon Glass | cdfe696 | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 152 | #endif |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 155 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 156 | * indent_string() - returns a string for indenting with two spaces per level |
| 157 | * @level: indent level |
Heinrich Schuchardt | 091cf43 | 2018-01-24 19:21:36 +0100 | [diff] [blame] | 158 | * |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 159 | * A maximum of ten indent levels is supported. Higher indent levels will be |
| 160 | * truncated. |
| 161 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 162 | * Return: A string for indenting with two spaces per level is |
| 163 | * returned. |
Rob Clark | e7896c3 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 164 | */ |
| 165 | static const char *indent_string(int level) |
| 166 | { |
| 167 | const char *indent = " "; |
| 168 | const int max = strlen(indent); |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 169 | |
Rob Clark | e7896c3 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 170 | level = min(max, level * 2); |
| 171 | return &indent[max - level]; |
| 172 | } |
| 173 | |
Heinrich Schuchardt | 4d66489 | 2017-08-18 17:45:16 +0200 | [diff] [blame] | 174 | const char *__efi_nesting(void) |
| 175 | { |
| 176 | return indent_string(nesting_level); |
| 177 | } |
| 178 | |
Rob Clark | e7896c3 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 179 | const char *__efi_nesting_inc(void) |
| 180 | { |
| 181 | return indent_string(nesting_level++); |
| 182 | } |
| 183 | |
| 184 | const char *__efi_nesting_dec(void) |
| 185 | { |
| 186 | return indent_string(--nesting_level); |
| 187 | } |
| 188 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 189 | /** |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 190 | * efi_event_is_queued() - check if an event is queued |
| 191 | * |
| 192 | * @event: event |
| 193 | * Return: true if event is queued |
| 194 | */ |
| 195 | static bool efi_event_is_queued(struct efi_event *event) |
| 196 | { |
| 197 | return !!event->queue_link.next; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * efi_process_event_queue() - process event queue |
| 202 | */ |
| 203 | static void efi_process_event_queue(void) |
| 204 | { |
| 205 | while (!list_empty(&efi_event_queue)) { |
| 206 | struct efi_event *event; |
| 207 | efi_uintn_t old_tpl; |
| 208 | |
| 209 | event = list_first_entry(&efi_event_queue, struct efi_event, |
| 210 | queue_link); |
| 211 | if (efi_tpl >= event->notify_tpl) |
| 212 | return; |
| 213 | list_del(&event->queue_link); |
| 214 | event->queue_link.next = NULL; |
| 215 | event->queue_link.prev = NULL; |
| 216 | /* Events must be executed at the event's TPL */ |
| 217 | old_tpl = efi_tpl; |
| 218 | efi_tpl = event->notify_tpl; |
| 219 | EFI_CALL_VOID(event->notify_function(event, |
| 220 | event->notify_context)); |
| 221 | efi_tpl = old_tpl; |
| 222 | if (event->type == EVT_NOTIFY_SIGNAL) |
| 223 | event->is_signaled = 0; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 228 | * efi_queue_event() - queue an EFI event |
| 229 | * @event: event to signal |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 230 | * |
| 231 | * This function queues the notification function of the event for future |
| 232 | * execution. |
| 233 | * |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 234 | */ |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 235 | static void efi_queue_event(struct efi_event *event) |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 236 | { |
Heinrich Schuchardt | ec94690 | 2020-03-06 21:56:10 +0100 | [diff] [blame] | 237 | struct efi_event *item; |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 238 | |
| 239 | if (!event->notify_function) |
| 240 | return; |
| 241 | |
| 242 | if (!efi_event_is_queued(event)) { |
| 243 | /* |
| 244 | * Events must be notified in order of decreasing task priority |
| 245 | * level. Insert the new event accordingly. |
| 246 | */ |
| 247 | list_for_each_entry(item, &efi_event_queue, queue_link) { |
| 248 | if (item->notify_tpl < event->notify_tpl) { |
| 249 | list_add_tail(&event->queue_link, |
| 250 | &item->queue_link); |
| 251 | event = NULL; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | if (event) |
| 256 | list_add_tail(&event->queue_link, &efi_event_queue); |
Heinrich Schuchardt | 3ef4c85 | 2020-12-28 00:25:34 +0100 | [diff] [blame] | 257 | efi_process_event_queue(); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 261 | /** |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 262 | * is_valid_tpl() - check if the task priority level is valid |
| 263 | * |
| 264 | * @tpl: TPL level to check |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 265 | * Return: status code |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 266 | */ |
Heinrich Schuchardt | 8126a1e | 2023-02-10 08:50:06 +0100 | [diff] [blame] | 267 | static efi_status_t is_valid_tpl(efi_uintn_t tpl) |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 268 | { |
| 269 | switch (tpl) { |
| 270 | case TPL_APPLICATION: |
| 271 | case TPL_CALLBACK: |
| 272 | case TPL_NOTIFY: |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 273 | return EFI_SUCCESS; |
| 274 | default: |
| 275 | return EFI_INVALID_PARAMETER; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 280 | * efi_signal_event() - signal an EFI event |
| 281 | * @event: event to signal |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 282 | * |
Heinrich Schuchardt | 9de0fb7 | 2020-12-28 00:59:09 +0100 | [diff] [blame] | 283 | * This function signals an event. If the event belongs to an event group, all |
| 284 | * events of the group are signaled. If they are of type EVT_NOTIFY_SIGNAL, |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 285 | * their notification function is queued. |
| 286 | * |
| 287 | * For the SignalEvent service see efi_signal_event_ext. |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 288 | */ |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 289 | void efi_signal_event(struct efi_event *event) |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 290 | { |
Heinrich Schuchardt | 0b4de56 | 2019-06-06 01:51:50 +0200 | [diff] [blame] | 291 | if (event->is_signaled) |
| 292 | return; |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 293 | if (event->group) { |
| 294 | struct efi_event *evt; |
| 295 | |
| 296 | /* |
| 297 | * The signaled state has to set before executing any |
| 298 | * notification function |
| 299 | */ |
| 300 | list_for_each_entry(evt, &efi_events, link) { |
| 301 | if (!evt->group || guidcmp(evt->group, event->group)) |
| 302 | continue; |
| 303 | if (evt->is_signaled) |
| 304 | continue; |
| 305 | evt->is_signaled = true; |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 306 | } |
| 307 | list_for_each_entry(evt, &efi_events, link) { |
| 308 | if (!evt->group || guidcmp(evt->group, event->group)) |
| 309 | continue; |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 310 | efi_queue_event(evt); |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 311 | } |
Heinrich Schuchardt | 66ddc2e | 2019-05-05 00:07:34 +0200 | [diff] [blame] | 312 | } else { |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 313 | event->is_signaled = true; |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 314 | efi_queue_event(event); |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 318 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 319 | * efi_raise_tpl() - raise the task priority level |
| 320 | * @new_tpl: new value of the task priority level |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 321 | * |
| 322 | * This function implements the RaiseTpl service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 323 | * |
| 324 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 325 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 326 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 327 | * Return: old value of the task priority level |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 328 | */ |
Heinrich Schuchardt | f8d4ec3 | 2017-11-06 21:17:47 +0100 | [diff] [blame] | 329 | static unsigned long EFIAPI efi_raise_tpl(efi_uintn_t new_tpl) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 330 | { |
Heinrich Schuchardt | f8d4ec3 | 2017-11-06 21:17:47 +0100 | [diff] [blame] | 331 | efi_uintn_t old_tpl = efi_tpl; |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 332 | |
xypron.glpk@gmx.de | 48df209 | 2017-07-18 20:17:19 +0200 | [diff] [blame] | 333 | EFI_ENTRY("0x%zx", new_tpl); |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 334 | |
| 335 | if (new_tpl < efi_tpl) |
Heinrich Schuchardt | 952e206 | 2019-05-05 11:56:23 +0200 | [diff] [blame] | 336 | EFI_PRINT("WARNING: new_tpl < current_tpl in %s\n", __func__); |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 337 | efi_tpl = new_tpl; |
| 338 | if (efi_tpl > TPL_HIGH_LEVEL) |
| 339 | efi_tpl = TPL_HIGH_LEVEL; |
| 340 | |
| 341 | EFI_EXIT(EFI_SUCCESS); |
| 342 | return old_tpl; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 345 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 346 | * efi_restore_tpl() - lower the task priority level |
| 347 | * @old_tpl: value of the task priority level to be restored |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 348 | * |
| 349 | * This function implements the RestoreTpl service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 350 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 351 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 352 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 353 | */ |
Heinrich Schuchardt | f8d4ec3 | 2017-11-06 21:17:47 +0100 | [diff] [blame] | 354 | static void EFIAPI efi_restore_tpl(efi_uintn_t old_tpl) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 355 | { |
xypron.glpk@gmx.de | 48df209 | 2017-07-18 20:17:19 +0200 | [diff] [blame] | 356 | EFI_ENTRY("0x%zx", old_tpl); |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 357 | |
| 358 | if (old_tpl > efi_tpl) |
Heinrich Schuchardt | 952e206 | 2019-05-05 11:56:23 +0200 | [diff] [blame] | 359 | EFI_PRINT("WARNING: old_tpl > current_tpl in %s\n", __func__); |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 360 | efi_tpl = old_tpl; |
| 361 | if (efi_tpl > TPL_HIGH_LEVEL) |
| 362 | efi_tpl = TPL_HIGH_LEVEL; |
| 363 | |
Heinrich Schuchardt | 59b2095 | 2018-03-24 18:40:21 +0100 | [diff] [blame] | 364 | /* |
| 365 | * Lowering the TPL may have made queued events eligible for execution. |
| 366 | */ |
| 367 | efi_timer_check(); |
| 368 | |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 369 | EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 370 | } |
| 371 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 372 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 373 | * efi_allocate_pages_ext() - allocate memory pages |
| 374 | * @type: type of allocation to be performed |
| 375 | * @memory_type: usage type of the allocated memory |
| 376 | * @pages: number of pages to be allocated |
| 377 | * @memory: allocated memory |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 378 | * |
| 379 | * This function implements the AllocatePages service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 380 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 381 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 382 | * details. |
| 383 | * |
| 384 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 385 | */ |
Masahiro Yamada | b2a05c1 | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 386 | static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 387 | efi_uintn_t pages, |
Masahiro Yamada | b2a05c1 | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 388 | uint64_t *memory) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 389 | { |
| 390 | efi_status_t r; |
| 391 | |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 392 | EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 393 | r = efi_allocate_pages(type, memory_type, pages, memory); |
| 394 | return EFI_EXIT(r); |
| 395 | } |
| 396 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 397 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 398 | * efi_free_pages_ext() - Free memory pages. |
| 399 | * @memory: start of the memory area to be freed |
| 400 | * @pages: number of pages to be freed |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 401 | * |
| 402 | * This function implements the FreePages service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 403 | * |
| 404 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 405 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 406 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 407 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 408 | */ |
Masahiro Yamada | b2a05c1 | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 409 | static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 410 | efi_uintn_t pages) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 411 | { |
| 412 | efi_status_t r; |
| 413 | |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 414 | EFI_ENTRY("%llx, 0x%zx", memory, pages); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 415 | r = efi_free_pages(memory, pages); |
| 416 | return EFI_EXIT(r); |
| 417 | } |
| 418 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 419 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 420 | * efi_get_memory_map_ext() - get map describing memory usage |
| 421 | * @memory_map_size: on entry the size, in bytes, of the memory map buffer, |
| 422 | * on exit the size of the copied memory map |
| 423 | * @memory_map: buffer to which the memory map is written |
| 424 | * @map_key: key for the memory map |
| 425 | * @descriptor_size: size of an individual memory descriptor |
| 426 | * @descriptor_version: version number of the memory descriptor structure |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 427 | * |
| 428 | * This function implements the GetMemoryMap service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 429 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 430 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 431 | * details. |
| 432 | * |
| 433 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 434 | */ |
Masahiro Yamada | b2a05c1 | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 435 | static efi_status_t EFIAPI efi_get_memory_map_ext( |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 436 | efi_uintn_t *memory_map_size, |
Masahiro Yamada | b2a05c1 | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 437 | struct efi_mem_desc *memory_map, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 438 | efi_uintn_t *map_key, |
| 439 | efi_uintn_t *descriptor_size, |
Masahiro Yamada | b2a05c1 | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 440 | uint32_t *descriptor_version) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 441 | { |
| 442 | efi_status_t r; |
| 443 | |
| 444 | EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map, |
| 445 | map_key, descriptor_size, descriptor_version); |
| 446 | r = efi_get_memory_map(memory_map_size, memory_map, map_key, |
| 447 | descriptor_size, descriptor_version); |
| 448 | return EFI_EXIT(r); |
| 449 | } |
| 450 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 451 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 452 | * efi_allocate_pool_ext() - allocate memory from pool |
| 453 | * @pool_type: type of the pool from which memory is to be allocated |
| 454 | * @size: number of bytes to be allocated |
| 455 | * @buffer: allocated memory |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 456 | * |
| 457 | * This function implements the AllocatePool service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 458 | * |
| 459 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 460 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 461 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 462 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 463 | */ |
Stefan Brüns | 5a09aef | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 464 | static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 465 | efi_uintn_t size, |
Stefan Brüns | 5a09aef | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 466 | void **buffer) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 467 | { |
Alexander Graf | 1c34fa8 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 468 | efi_status_t r; |
| 469 | |
Heinrich Schuchardt | e1e8a65 | 2022-02-03 22:21:51 +0100 | [diff] [blame] | 470 | EFI_ENTRY("%d, %zu, %p", pool_type, size, buffer); |
Stefan Brüns | 5a09aef | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 471 | r = efi_allocate_pool(pool_type, size, buffer); |
Alexander Graf | 1c34fa8 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 472 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 475 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 476 | * efi_free_pool_ext() - free memory from pool |
| 477 | * @buffer: start of memory to be freed |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 478 | * |
| 479 | * This function implements the FreePool service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 480 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 481 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 482 | * details. |
| 483 | * |
| 484 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 485 | */ |
Stefan Brüns | 67b67d9 | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 486 | static efi_status_t EFIAPI efi_free_pool_ext(void *buffer) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 487 | { |
Alexander Graf | 1c34fa8 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 488 | efi_status_t r; |
| 489 | |
| 490 | EFI_ENTRY("%p", buffer); |
Stefan Brüns | 67b67d9 | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 491 | r = efi_free_pool(buffer); |
Alexander Graf | 1c34fa8 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 492 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 493 | } |
| 494 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 495 | /** |
Heinrich Schuchardt | 30cd046 | 2019-05-01 09:42:39 +0200 | [diff] [blame] | 496 | * efi_add_handle() - add a new handle to the object list |
| 497 | * |
| 498 | * @handle: handle to be added |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 499 | * |
Heinrich Schuchardt | 30cd046 | 2019-05-01 09:42:39 +0200 | [diff] [blame] | 500 | * The protocols list is initialized. The handle is added to the list of known |
| 501 | * UEFI objects. |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 502 | */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 503 | void efi_add_handle(efi_handle_t handle) |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 504 | { |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 505 | if (!handle) |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 506 | return; |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 507 | INIT_LIST_HEAD(&handle->protocols); |
| 508 | list_add_tail(&handle->link, &efi_obj_list); |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 509 | } |
| 510 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 511 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 512 | * efi_create_handle() - create handle |
| 513 | * @handle: new handle |
Heinrich Schuchardt | eb6106e | 2017-10-26 19:25:49 +0200 | [diff] [blame] | 514 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 515 | * Return: status code |
Heinrich Schuchardt | eb6106e | 2017-10-26 19:25:49 +0200 | [diff] [blame] | 516 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 517 | efi_status_t efi_create_handle(efi_handle_t *handle) |
Heinrich Schuchardt | cd522cb | 2017-08-27 00:51:09 +0200 | [diff] [blame] | 518 | { |
| 519 | struct efi_object *obj; |
Heinrich Schuchardt | cd522cb | 2017-08-27 00:51:09 +0200 | [diff] [blame] | 520 | |
Heinrich Schuchardt | ae1d206 | 2018-05-27 16:47:21 +0200 | [diff] [blame] | 521 | obj = calloc(1, sizeof(struct efi_object)); |
| 522 | if (!obj) |
| 523 | return EFI_OUT_OF_RESOURCES; |
| 524 | |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 525 | efi_add_handle(obj); |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 526 | *handle = obj; |
Heinrich Schuchardt | ae1d206 | 2018-05-27 16:47:21 +0200 | [diff] [blame] | 527 | |
| 528 | return EFI_SUCCESS; |
Heinrich Schuchardt | cd522cb | 2017-08-27 00:51:09 +0200 | [diff] [blame] | 529 | } |
| 530 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 531 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 532 | * efi_search_protocol() - find a protocol on a handle. |
| 533 | * @handle: handle |
| 534 | * @protocol_guid: GUID of the protocol |
| 535 | * @handler: reference to the protocol |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 536 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 537 | * Return: status code |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 538 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 539 | efi_status_t efi_search_protocol(const efi_handle_t handle, |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 540 | const efi_guid_t *protocol_guid, |
| 541 | struct efi_handler **handler) |
| 542 | { |
| 543 | struct efi_object *efiobj; |
| 544 | struct list_head *lhandle; |
| 545 | |
| 546 | if (!handle || !protocol_guid) |
| 547 | return EFI_INVALID_PARAMETER; |
| 548 | efiobj = efi_search_obj(handle); |
| 549 | if (!efiobj) |
| 550 | return EFI_INVALID_PARAMETER; |
| 551 | list_for_each(lhandle, &efiobj->protocols) { |
| 552 | struct efi_handler *protocol; |
| 553 | |
| 554 | protocol = list_entry(lhandle, struct efi_handler, link); |
Heinrich Schuchardt | 2a22db9 | 2022-03-09 19:56:23 +0100 | [diff] [blame] | 555 | if (!guidcmp(&protocol->guid, protocol_guid)) { |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 556 | if (handler) |
| 557 | *handler = protocol; |
| 558 | return EFI_SUCCESS; |
| 559 | } |
| 560 | } |
| 561 | return EFI_NOT_FOUND; |
| 562 | } |
| 563 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 564 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 565 | * efi_remove_protocol() - delete protocol from a handle |
| 566 | * @handle: handle from which the protocol shall be deleted |
| 567 | * @protocol: GUID of the protocol to be deleted |
| 568 | * @protocol_interface: interface of the protocol implementation |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 569 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 570 | * Return: status code |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 571 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 572 | efi_status_t efi_remove_protocol(const efi_handle_t handle, |
| 573 | const efi_guid_t *protocol, |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 574 | void *protocol_interface) |
| 575 | { |
| 576 | struct efi_handler *handler; |
| 577 | efi_status_t ret; |
| 578 | |
| 579 | ret = efi_search_protocol(handle, protocol, &handler); |
| 580 | if (ret != EFI_SUCCESS) |
| 581 | return ret; |
Heinrich Schuchardt | b27594d | 2018-05-11 12:09:21 +0200 | [diff] [blame] | 582 | if (handler->protocol_interface != protocol_interface) |
Heinrich Schuchardt | fdeb1f0 | 2019-05-10 20:06:48 +0200 | [diff] [blame] | 583 | return EFI_NOT_FOUND; |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 584 | list_del(&handler->link); |
| 585 | free(handler); |
| 586 | return EFI_SUCCESS; |
| 587 | } |
| 588 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 589 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 590 | * efi_remove_all_protocols() - delete all protocols from a handle |
| 591 | * @handle: handle from which the protocols shall be deleted |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 592 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 593 | * Return: status code |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 594 | */ |
Heinrich Schuchardt | 8126a1e | 2023-02-10 08:50:06 +0100 | [diff] [blame] | 595 | static efi_status_t efi_remove_all_protocols(const efi_handle_t handle) |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 596 | { |
| 597 | struct efi_object *efiobj; |
Heinrich Schuchardt | a84731d | 2018-01-11 08:15:55 +0100 | [diff] [blame] | 598 | struct efi_handler *protocol; |
| 599 | struct efi_handler *pos; |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 600 | |
| 601 | efiobj = efi_search_obj(handle); |
| 602 | if (!efiobj) |
| 603 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a84731d | 2018-01-11 08:15:55 +0100 | [diff] [blame] | 604 | list_for_each_entry_safe(protocol, pos, &efiobj->protocols, link) { |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 605 | efi_status_t ret; |
| 606 | |
Heinrich Schuchardt | 2a22db9 | 2022-03-09 19:56:23 +0100 | [diff] [blame] | 607 | ret = efi_remove_protocol(handle, &protocol->guid, |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 608 | protocol->protocol_interface); |
| 609 | if (ret != EFI_SUCCESS) |
| 610 | return ret; |
| 611 | } |
| 612 | return EFI_SUCCESS; |
| 613 | } |
| 614 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 615 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 616 | * efi_delete_handle() - delete handle |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 617 | * |
Heinrich Schuchardt | 41cc3c1 | 2019-07-14 11:05:34 +0200 | [diff] [blame] | 618 | * @handle: handle to delete |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 619 | */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 620 | void efi_delete_handle(efi_handle_t handle) |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 621 | { |
Etienne Carriere | b20a42b | 2022-09-07 10:20:13 +0200 | [diff] [blame] | 622 | efi_status_t ret; |
| 623 | |
| 624 | ret = efi_remove_all_protocols(handle); |
| 625 | if (ret == EFI_INVALID_PARAMETER) { |
| 626 | log_err("Can't remove invalid handle %p\n", handle); |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 627 | return; |
Etienne Carriere | b20a42b | 2022-09-07 10:20:13 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 630 | list_del(&handle->link); |
| 631 | free(handle); |
Heinrich Schuchardt | 7d13546 | 2017-12-04 18:03:02 +0100 | [diff] [blame] | 632 | } |
| 633 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 634 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 635 | * efi_is_event() - check if a pointer is a valid event |
| 636 | * @event: pointer to check |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 637 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 638 | * Return: status code |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 639 | */ |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 640 | static efi_status_t efi_is_event(const struct efi_event *event) |
| 641 | { |
| 642 | const struct efi_event *evt; |
| 643 | |
| 644 | if (!event) |
| 645 | return EFI_INVALID_PARAMETER; |
| 646 | list_for_each_entry(evt, &efi_events, link) { |
| 647 | if (evt == event) |
| 648 | return EFI_SUCCESS; |
| 649 | } |
| 650 | return EFI_INVALID_PARAMETER; |
| 651 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 652 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 653 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 654 | * efi_create_event() - create an event |
Heinrich Schuchardt | 41cc3c1 | 2019-07-14 11:05:34 +0200 | [diff] [blame] | 655 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 656 | * @type: type of the event to create |
| 657 | * @notify_tpl: task priority level of the event |
| 658 | * @notify_function: notification function of the event |
| 659 | * @notify_context: pointer passed to the notification function |
| 660 | * @group: event group |
| 661 | * @event: created event |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 662 | * |
| 663 | * This function is used inside U-Boot code to create an event. |
| 664 | * |
| 665 | * For the API function implementing the CreateEvent service see |
| 666 | * efi_create_event_ext. |
| 667 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 668 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 669 | */ |
Heinrich Schuchardt | f8d4ec3 | 2017-11-06 21:17:47 +0100 | [diff] [blame] | 670 | efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl, |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 671 | void (EFIAPI *notify_function) ( |
xypron.glpk@gmx.de | cdbf3ac | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 672 | struct efi_event *event, |
| 673 | void *context), |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 674 | void *notify_context, efi_guid_t *group, |
| 675 | struct efi_event **event) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 676 | { |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 677 | struct efi_event *evt; |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 678 | efi_status_t ret; |
| 679 | int pool_type; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 680 | |
Jonathan Gray | 7758b21 | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 681 | if (event == NULL) |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 682 | return EFI_INVALID_PARAMETER; |
Jonathan Gray | 7758b21 | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 683 | |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 684 | switch (type) { |
| 685 | case 0: |
| 686 | case EVT_TIMER: |
| 687 | case EVT_NOTIFY_SIGNAL: |
| 688 | case EVT_TIMER | EVT_NOTIFY_SIGNAL: |
| 689 | case EVT_NOTIFY_WAIT: |
| 690 | case EVT_TIMER | EVT_NOTIFY_WAIT: |
| 691 | case EVT_SIGNAL_EXIT_BOOT_SERVICES: |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 692 | pool_type = EFI_BOOT_SERVICES_DATA; |
| 693 | break; |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 694 | case EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE: |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 695 | pool_type = EFI_RUNTIME_SERVICES_DATA; |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 696 | break; |
| 697 | default: |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 698 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | 7f0f005 | 2018-07-02 12:53:52 +0200 | [diff] [blame] | 699 | } |
Jonathan Gray | 7758b21 | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 700 | |
Heinrich Schuchardt | 3d83b73 | 2021-01-06 12:55:22 +0100 | [diff] [blame] | 701 | /* |
| 702 | * The UEFI specification requires event notification levels to be |
| 703 | * > TPL_APPLICATION and <= TPL_HIGH_LEVEL. |
| 704 | * |
| 705 | * Parameter NotifyTpl should not be checked if it is not used. |
| 706 | */ |
AKASHI Takahiro | 3f3835d | 2018-08-10 15:36:32 +0900 | [diff] [blame] | 707 | if ((type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL)) && |
Heinrich Schuchardt | 3d83b73 | 2021-01-06 12:55:22 +0100 | [diff] [blame] | 708 | (!notify_function || is_valid_tpl(notify_tpl) != EFI_SUCCESS || |
| 709 | notify_tpl == TPL_APPLICATION)) |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 710 | return EFI_INVALID_PARAMETER; |
Jonathan Gray | 7758b21 | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 711 | |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 712 | ret = efi_allocate_pool(pool_type, sizeof(struct efi_event), |
| 713 | (void **)&evt); |
| 714 | if (ret != EFI_SUCCESS) |
| 715 | return ret; |
| 716 | memset(evt, 0, sizeof(struct efi_event)); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 717 | evt->type = type; |
| 718 | evt->notify_tpl = notify_tpl; |
| 719 | evt->notify_function = notify_function; |
| 720 | evt->notify_context = notify_context; |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 721 | evt->group = group; |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 722 | /* Disable timers on boot up */ |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 723 | evt->trigger_next = -1ULL; |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 724 | list_add_tail(&evt->link, &efi_events); |
| 725 | *event = evt; |
| 726 | return EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 727 | } |
| 728 | |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 729 | /* |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 730 | * efi_create_event_ex() - create an event in a group |
Heinrich Schuchardt | 8126a1e | 2023-02-10 08:50:06 +0100 | [diff] [blame] | 731 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 732 | * @type: type of the event to create |
| 733 | * @notify_tpl: task priority level of the event |
| 734 | * @notify_function: notification function of the event |
| 735 | * @notify_context: pointer passed to the notification function |
| 736 | * @event: created event |
| 737 | * @event_group: event group |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 738 | * |
| 739 | * This function implements the CreateEventEx service. |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 740 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 741 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 742 | * details. |
| 743 | * |
| 744 | * Return: status code |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 745 | */ |
Heinrich Schuchardt | 8126a1e | 2023-02-10 08:50:06 +0100 | [diff] [blame] | 746 | static |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 747 | efi_status_t EFIAPI efi_create_event_ex(uint32_t type, efi_uintn_t notify_tpl, |
| 748 | void (EFIAPI *notify_function) ( |
| 749 | struct efi_event *event, |
| 750 | void *context), |
| 751 | void *notify_context, |
| 752 | efi_guid_t *event_group, |
| 753 | struct efi_event **event) |
| 754 | { |
Heinrich Schuchardt | ce66499 | 2019-05-04 10:12:50 +0200 | [diff] [blame] | 755 | efi_status_t ret; |
| 756 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 757 | EFI_ENTRY("%d, 0x%zx, %p, %p, %pUs", type, notify_tpl, notify_function, |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 758 | notify_context, event_group); |
Heinrich Schuchardt | ce66499 | 2019-05-04 10:12:50 +0200 | [diff] [blame] | 759 | |
| 760 | /* |
| 761 | * The allowable input parameters are the same as in CreateEvent() |
| 762 | * except for the following two disallowed event types. |
| 763 | */ |
| 764 | switch (type) { |
| 765 | case EVT_SIGNAL_EXIT_BOOT_SERVICES: |
| 766 | case EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE: |
| 767 | ret = EFI_INVALID_PARAMETER; |
| 768 | goto out; |
| 769 | } |
| 770 | |
| 771 | ret = efi_create_event(type, notify_tpl, notify_function, |
| 772 | notify_context, event_group, event); |
| 773 | out: |
| 774 | return EFI_EXIT(ret); |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 777 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 778 | * efi_create_event_ext() - create an event |
| 779 | * @type: type of the event to create |
| 780 | * @notify_tpl: task priority level of the event |
| 781 | * @notify_function: notification function of the event |
| 782 | * @notify_context: pointer passed to the notification function |
| 783 | * @event: created event |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 784 | * |
| 785 | * This function implements the CreateEvent service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 786 | * |
| 787 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 788 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 789 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 790 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 791 | */ |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 792 | static efi_status_t EFIAPI efi_create_event_ext( |
Heinrich Schuchardt | f8d4ec3 | 2017-11-06 21:17:47 +0100 | [diff] [blame] | 793 | uint32_t type, efi_uintn_t notify_tpl, |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 794 | void (EFIAPI *notify_function) ( |
| 795 | struct efi_event *event, |
| 796 | void *context), |
| 797 | void *notify_context, struct efi_event **event) |
| 798 | { |
| 799 | EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function, |
| 800 | notify_context); |
| 801 | return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function, |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 802 | notify_context, NULL, event)); |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 803 | } |
| 804 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 805 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 806 | * efi_timer_check() - check if a timer event has occurred |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 807 | * |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 808 | * Check if a timer event has occurred or a queued notification function should |
| 809 | * be called. |
| 810 | * |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 811 | * Our timers have to work without interrupts, so we check whenever keyboard |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 812 | * input or disk accesses happen if enough time elapsed for them to fire. |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 813 | */ |
| 814 | void efi_timer_check(void) |
| 815 | { |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 816 | struct efi_event *evt; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 817 | u64 now = timer_get_us(); |
| 818 | |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 819 | list_for_each_entry(evt, &efi_events, link) { |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 820 | if (!timers_enabled) |
| 821 | continue; |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 822 | if (!(evt->type & EVT_TIMER) || now < evt->trigger_next) |
Heinrich Schuchardt | 8b11a8a | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 823 | continue; |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 824 | switch (evt->trigger_type) { |
Heinrich Schuchardt | 8b11a8a | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 825 | case EFI_TIMER_RELATIVE: |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 826 | evt->trigger_type = EFI_TIMER_STOP; |
Heinrich Schuchardt | 8b11a8a | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 827 | break; |
| 828 | case EFI_TIMER_PERIODIC: |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 829 | evt->trigger_next += evt->trigger_time; |
Heinrich Schuchardt | 8b11a8a | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 830 | break; |
| 831 | default: |
| 832 | continue; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 833 | } |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 834 | evt->is_signaled = false; |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 835 | efi_signal_event(evt); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 836 | } |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 837 | efi_process_event_queue(); |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 838 | schedule(); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 839 | } |
| 840 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 841 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 842 | * efi_set_timer() - set the trigger time for a timer event or stop the event |
| 843 | * @event: event for which the timer is set |
| 844 | * @type: type of the timer |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 845 | * @trigger_time: trigger period in multiples of 100 ns |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 846 | * |
| 847 | * This is the function for internal usage in U-Boot. For the API function |
| 848 | * implementing the SetTimer service see efi_set_timer_ext. |
| 849 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 850 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 851 | */ |
xypron.glpk@gmx.de | 3ecc6bd | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 852 | efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type, |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 853 | uint64_t trigger_time) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 854 | { |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 855 | /* Check that the event is valid */ |
| 856 | if (efi_is_event(event) != EFI_SUCCESS || !(event->type & EVT_TIMER)) |
| 857 | return EFI_INVALID_PARAMETER; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 858 | |
xypron.glpk@gmx.de | 44c4be0 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 859 | /* |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 860 | * The parameter defines a multiple of 100 ns. |
| 861 | * We use multiples of 1000 ns. So divide by 10. |
xypron.glpk@gmx.de | 44c4be0 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 862 | */ |
Heinrich Schuchardt | 368ca64 | 2017-10-05 16:14:14 +0200 | [diff] [blame] | 863 | do_div(trigger_time, 10); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 864 | |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 865 | switch (type) { |
| 866 | case EFI_TIMER_STOP: |
| 867 | event->trigger_next = -1ULL; |
| 868 | break; |
| 869 | case EFI_TIMER_PERIODIC: |
| 870 | case EFI_TIMER_RELATIVE: |
| 871 | event->trigger_next = timer_get_us() + trigger_time; |
| 872 | break; |
| 873 | default: |
| 874 | return EFI_INVALID_PARAMETER; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 875 | } |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 876 | event->trigger_type = type; |
| 877 | event->trigger_time = trigger_time; |
| 878 | event->is_signaled = false; |
| 879 | return EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 880 | } |
| 881 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 882 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 883 | * efi_set_timer_ext() - Set the trigger time for a timer event or stop the |
| 884 | * event |
| 885 | * @event: event for which the timer is set |
| 886 | * @type: type of the timer |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 887 | * @trigger_time: trigger period in multiples of 100 ns |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 888 | * |
| 889 | * This function implements the SetTimer service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 890 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 891 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 892 | * details. |
| 893 | * |
| 894 | * |
| 895 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 896 | */ |
xypron.glpk@gmx.de | 3ecc6bd | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 897 | static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, |
| 898 | enum efi_timer_delay type, |
| 899 | uint64_t trigger_time) |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 900 | { |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 901 | EFI_ENTRY("%p, %d, %llx", event, type, trigger_time); |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 902 | return EFI_EXIT(efi_set_timer(event, type, trigger_time)); |
| 903 | } |
| 904 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 905 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 906 | * efi_wait_for_event() - wait for events to be signaled |
| 907 | * @num_events: number of events to be waited for |
| 908 | * @event: events to be waited for |
| 909 | * @index: index of the event that was signaled |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 910 | * |
| 911 | * This function implements the WaitForEvent service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 912 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 913 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 914 | * details. |
| 915 | * |
| 916 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 917 | */ |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 918 | static efi_status_t EFIAPI efi_wait_for_event(efi_uintn_t num_events, |
xypron.glpk@gmx.de | cdbf3ac | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 919 | struct efi_event **event, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 920 | efi_uintn_t *index) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 921 | { |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 922 | int i; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 923 | |
Heinrich Schuchardt | e1e8a65 | 2022-02-03 22:21:51 +0100 | [diff] [blame] | 924 | EFI_ENTRY("%zu, %p, %p", num_events, event, index); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 925 | |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 926 | /* Check parameters */ |
| 927 | if (!num_events || !event) |
| 928 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Heinrich Schuchardt | 0c150ca | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 929 | /* Check TPL */ |
| 930 | if (efi_tpl != TPL_APPLICATION) |
| 931 | return EFI_EXIT(EFI_UNSUPPORTED); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 932 | for (i = 0; i < num_events; ++i) { |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 933 | if (efi_is_event(event[i]) != EFI_SUCCESS) |
| 934 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 935 | if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL) |
| 936 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Heinrich Schuchardt | 1bbee39 | 2017-10-04 15:03:24 +0200 | [diff] [blame] | 937 | if (!event[i]->is_signaled) |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 938 | efi_queue_event(event[i]); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* Wait for signal */ |
| 942 | for (;;) { |
| 943 | for (i = 0; i < num_events; ++i) { |
Heinrich Schuchardt | 1bbee39 | 2017-10-04 15:03:24 +0200 | [diff] [blame] | 944 | if (event[i]->is_signaled) |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 945 | goto out; |
| 946 | } |
| 947 | /* Allow events to occur. */ |
| 948 | efi_timer_check(); |
| 949 | } |
| 950 | |
| 951 | out: |
| 952 | /* |
| 953 | * Reset the signal which is passed to the caller to allow periodic |
| 954 | * events to occur. |
| 955 | */ |
Heinrich Schuchardt | 1bbee39 | 2017-10-04 15:03:24 +0200 | [diff] [blame] | 956 | event[i]->is_signaled = false; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 957 | if (index) |
| 958 | *index = i; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 959 | |
| 960 | return EFI_EXIT(EFI_SUCCESS); |
| 961 | } |
| 962 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 963 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 964 | * efi_signal_event_ext() - signal an EFI event |
| 965 | * @event: event to signal |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 966 | * |
| 967 | * This function implements the SignalEvent service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 968 | * |
| 969 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 970 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 971 | * |
| 972 | * This functions sets the signaled state of the event and queues the |
| 973 | * notification function for execution. |
| 974 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 975 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 976 | */ |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 977 | static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 978 | { |
| 979 | EFI_ENTRY("%p", event); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 980 | if (efi_is_event(event) != EFI_SUCCESS) |
| 981 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 982 | efi_signal_event(event); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 983 | return EFI_EXIT(EFI_SUCCESS); |
| 984 | } |
| 985 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 986 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 987 | * efi_close_event() - close an EFI event |
| 988 | * @event: event to close |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 989 | * |
| 990 | * This function implements the CloseEvent service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 991 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 992 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 993 | * details. |
| 994 | * |
| 995 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 996 | */ |
xypron.glpk@gmx.de | cdbf3ac | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 997 | static efi_status_t EFIAPI efi_close_event(struct efi_event *event) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 998 | { |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 999 | struct efi_register_notify_event *item, *next; |
| 1000 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1001 | EFI_ENTRY("%p", event); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 1002 | if (efi_is_event(event) != EFI_SUCCESS) |
| 1003 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1004 | |
| 1005 | /* Remove protocol notify registrations for the event */ |
| 1006 | list_for_each_entry_safe(item, next, &efi_register_notify_events, |
| 1007 | link) { |
| 1008 | if (event == item->event) { |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1009 | struct efi_protocol_notification *hitem, *hnext; |
| 1010 | |
| 1011 | /* Remove signaled handles */ |
| 1012 | list_for_each_entry_safe(hitem, hnext, &item->handles, |
| 1013 | link) { |
| 1014 | list_del(&hitem->link); |
| 1015 | free(hitem); |
| 1016 | } |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1017 | list_del(&item->link); |
| 1018 | free(item); |
| 1019 | } |
| 1020 | } |
Heinrich Schuchardt | 35c0cf6 | 2019-06-05 21:00:39 +0200 | [diff] [blame] | 1021 | /* Remove event from queue */ |
| 1022 | if (efi_event_is_queued(event)) |
| 1023 | list_del(&event->queue_link); |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1024 | |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 1025 | list_del(&event->link); |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 1026 | efi_free_pool(event); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 1027 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1030 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1031 | * efi_check_event() - check if an event is signaled |
| 1032 | * @event: event to check |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1033 | * |
| 1034 | * This function implements the CheckEvent service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1035 | * |
| 1036 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1037 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1038 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1039 | * If an event is not signaled yet, the notification function is queued. The |
| 1040 | * signaled state is cleared. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1041 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1042 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1043 | */ |
xypron.glpk@gmx.de | cdbf3ac | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 1044 | static efi_status_t EFIAPI efi_check_event(struct efi_event *event) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1045 | { |
| 1046 | EFI_ENTRY("%p", event); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 1047 | efi_timer_check(); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 1048 | if (efi_is_event(event) != EFI_SUCCESS || |
| 1049 | event->type & EVT_NOTIFY_SIGNAL) |
| 1050 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1051 | if (!event->is_signaled) |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 1052 | efi_queue_event(event); |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 1053 | if (event->is_signaled) { |
| 1054 | event->is_signaled = false; |
| 1055 | return EFI_EXIT(EFI_SUCCESS); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 1056 | } |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 1057 | return EFI_EXIT(EFI_NOT_READY); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1060 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1061 | * efi_search_obj() - find the internal EFI object for a handle |
| 1062 | * @handle: handle to find |
Heinrich Schuchardt | 37ebcba | 2017-10-18 18:13:03 +0200 | [diff] [blame] | 1063 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1064 | * Return: EFI object |
Heinrich Schuchardt | 37ebcba | 2017-10-18 18:13:03 +0200 | [diff] [blame] | 1065 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 1066 | struct efi_object *efi_search_obj(const efi_handle_t handle) |
Heinrich Schuchardt | 37ebcba | 2017-10-18 18:13:03 +0200 | [diff] [blame] | 1067 | { |
Heinrich Schuchardt | 274cc87 | 2017-11-06 21:17:50 +0100 | [diff] [blame] | 1068 | struct efi_object *efiobj; |
Heinrich Schuchardt | 37ebcba | 2017-10-18 18:13:03 +0200 | [diff] [blame] | 1069 | |
Heinrich Schuchardt | 5d8231b | 2019-05-05 10:37:51 +0200 | [diff] [blame] | 1070 | if (!handle) |
| 1071 | return NULL; |
| 1072 | |
Heinrich Schuchardt | 274cc87 | 2017-11-06 21:17:50 +0100 | [diff] [blame] | 1073 | list_for_each_entry(efiobj, &efi_obj_list, link) { |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1074 | if (efiobj == handle) |
Heinrich Schuchardt | 37ebcba | 2017-10-18 18:13:03 +0200 | [diff] [blame] | 1075 | return efiobj; |
| 1076 | } |
Heinrich Schuchardt | 37ebcba | 2017-10-18 18:13:03 +0200 | [diff] [blame] | 1077 | return NULL; |
| 1078 | } |
| 1079 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1080 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1081 | * efi_open_protocol_info_entry() - create open protocol info entry and add it |
| 1082 | * to a protocol |
| 1083 | * @handler: handler of a protocol |
Heinrich Schuchardt | a277d3a | 2018-01-11 08:15:57 +0100 | [diff] [blame] | 1084 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1085 | * Return: open protocol info entry |
Heinrich Schuchardt | a277d3a | 2018-01-11 08:15:57 +0100 | [diff] [blame] | 1086 | */ |
| 1087 | static struct efi_open_protocol_info_entry *efi_create_open_info( |
| 1088 | struct efi_handler *handler) |
| 1089 | { |
| 1090 | struct efi_open_protocol_info_item *item; |
| 1091 | |
| 1092 | item = calloc(1, sizeof(struct efi_open_protocol_info_item)); |
| 1093 | if (!item) |
| 1094 | return NULL; |
| 1095 | /* Append the item to the open protocol info list. */ |
| 1096 | list_add_tail(&item->link, &handler->open_infos); |
| 1097 | |
| 1098 | return &item->info; |
| 1099 | } |
| 1100 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1101 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1102 | * efi_delete_open_info() - remove an open protocol info entry from a protocol |
| 1103 | * @item: open protocol info entry to delete |
Heinrich Schuchardt | a277d3a | 2018-01-11 08:15:57 +0100 | [diff] [blame] | 1104 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1105 | * Return: status code |
Heinrich Schuchardt | a277d3a | 2018-01-11 08:15:57 +0100 | [diff] [blame] | 1106 | */ |
| 1107 | static efi_status_t efi_delete_open_info( |
| 1108 | struct efi_open_protocol_info_item *item) |
| 1109 | { |
| 1110 | list_del(&item->link); |
| 1111 | free(item); |
| 1112 | return EFI_SUCCESS; |
| 1113 | } |
| 1114 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1115 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1116 | * efi_add_protocol() - install new protocol on a handle |
| 1117 | * @handle: handle on which the protocol shall be installed |
| 1118 | * @protocol: GUID of the protocol to be installed |
| 1119 | * @protocol_interface: interface of the protocol implementation |
Heinrich Schuchardt | 5aef61d | 2017-10-26 19:25:53 +0200 | [diff] [blame] | 1120 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1121 | * Return: status code |
Heinrich Schuchardt | 5aef61d | 2017-10-26 19:25:53 +0200 | [diff] [blame] | 1122 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 1123 | efi_status_t efi_add_protocol(const efi_handle_t handle, |
| 1124 | const efi_guid_t *protocol, |
Heinrich Schuchardt | 5aef61d | 2017-10-26 19:25:53 +0200 | [diff] [blame] | 1125 | void *protocol_interface) |
| 1126 | { |
| 1127 | struct efi_object *efiobj; |
| 1128 | struct efi_handler *handler; |
| 1129 | efi_status_t ret; |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1130 | struct efi_register_notify_event *event; |
Heinrich Schuchardt | 5aef61d | 2017-10-26 19:25:53 +0200 | [diff] [blame] | 1131 | |
| 1132 | efiobj = efi_search_obj(handle); |
| 1133 | if (!efiobj) |
| 1134 | return EFI_INVALID_PARAMETER; |
| 1135 | ret = efi_search_protocol(handle, protocol, NULL); |
| 1136 | if (ret != EFI_NOT_FOUND) |
| 1137 | return EFI_INVALID_PARAMETER; |
| 1138 | handler = calloc(1, sizeof(struct efi_handler)); |
| 1139 | if (!handler) |
| 1140 | return EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | 2a22db9 | 2022-03-09 19:56:23 +0100 | [diff] [blame] | 1141 | memcpy((void *)&handler->guid, protocol, sizeof(efi_guid_t)); |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 1142 | handler->protocol_interface = protocol_interface; |
Heinrich Schuchardt | a277d3a | 2018-01-11 08:15:57 +0100 | [diff] [blame] | 1143 | INIT_LIST_HEAD(&handler->open_infos); |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 1144 | list_add_tail(&handler->link, &efiobj->protocols); |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1145 | |
| 1146 | /* Notify registered events */ |
| 1147 | list_for_each_entry(event, &efi_register_notify_events, link) { |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1148 | if (!guidcmp(protocol, &event->protocol)) { |
| 1149 | struct efi_protocol_notification *notif; |
| 1150 | |
| 1151 | notif = calloc(1, sizeof(*notif)); |
| 1152 | if (!notif) { |
| 1153 | list_del(&handler->link); |
| 1154 | free(handler); |
| 1155 | return EFI_OUT_OF_RESOURCES; |
| 1156 | } |
| 1157 | notif->handle = handle; |
| 1158 | list_add_tail(¬if->link, &event->handles); |
Heinrich Schuchardt | ea0f6a8 | 2019-06-07 07:43:24 +0200 | [diff] [blame] | 1159 | event->event->is_signaled = false; |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 1160 | efi_signal_event(event->event); |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1161 | } |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Heinrich Schuchardt | 3d2abc3 | 2018-01-11 08:16:01 +0100 | [diff] [blame] | 1164 | if (!guidcmp(&efi_guid_device_path, protocol)) |
| 1165 | EFI_PRINT("installed device path '%pD'\n", protocol_interface); |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 1166 | return EFI_SUCCESS; |
Heinrich Schuchardt | 5aef61d | 2017-10-26 19:25:53 +0200 | [diff] [blame] | 1167 | } |
| 1168 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1169 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1170 | * efi_install_protocol_interface() - install protocol interface |
| 1171 | * @handle: handle on which the protocol shall be installed |
| 1172 | * @protocol: GUID of the protocol to be installed |
| 1173 | * @protocol_interface_type: type of the interface to be installed, |
| 1174 | * always EFI_NATIVE_INTERFACE |
| 1175 | * @protocol_interface: interface of the protocol implementation |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1176 | * |
Heinrich Schuchardt | 0a27ac8 | 2017-11-06 21:17:44 +0100 | [diff] [blame] | 1177 | * This function implements the InstallProtocolInterface service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1178 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1179 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1180 | * details. |
| 1181 | * |
| 1182 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1183 | */ |
Heinrich Schuchardt | 0a27ac8 | 2017-11-06 21:17:44 +0100 | [diff] [blame] | 1184 | static efi_status_t EFIAPI efi_install_protocol_interface( |
Heinrich Schuchardt | 4f94ec5 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 1185 | efi_handle_t *handle, const efi_guid_t *protocol, |
Heinrich Schuchardt | 0a27ac8 | 2017-11-06 21:17:44 +0100 | [diff] [blame] | 1186 | int protocol_interface_type, void *protocol_interface) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1187 | { |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 1188 | efi_status_t r; |
| 1189 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 1190 | EFI_ENTRY("%p, %pUs, %d, %p", handle, protocol, protocol_interface_type, |
Heinrich Schuchardt | 0a27ac8 | 2017-11-06 21:17:44 +0100 | [diff] [blame] | 1191 | protocol_interface); |
| 1192 | |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 1193 | if (!handle || !protocol || |
| 1194 | protocol_interface_type != EFI_NATIVE_INTERFACE) { |
| 1195 | r = EFI_INVALID_PARAMETER; |
| 1196 | goto out; |
| 1197 | } |
| 1198 | |
| 1199 | /* Create new handle if requested. */ |
| 1200 | if (!*handle) { |
Heinrich Schuchardt | cd522cb | 2017-08-27 00:51:09 +0200 | [diff] [blame] | 1201 | r = efi_create_handle(handle); |
| 1202 | if (r != EFI_SUCCESS) |
| 1203 | goto out; |
Heinrich Schuchardt | 952e206 | 2019-05-05 11:56:23 +0200 | [diff] [blame] | 1204 | EFI_PRINT("new handle %p\n", *handle); |
Heinrich Schuchardt | 50f0210 | 2017-10-26 19:25:43 +0200 | [diff] [blame] | 1205 | } else { |
Heinrich Schuchardt | 952e206 | 2019-05-05 11:56:23 +0200 | [diff] [blame] | 1206 | EFI_PRINT("handle %p\n", *handle); |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 1207 | } |
Heinrich Schuchardt | 865d5f3 | 2017-10-26 19:25:54 +0200 | [diff] [blame] | 1208 | /* Add new protocol */ |
| 1209 | r = efi_add_protocol(*handle, protocol, protocol_interface); |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 1210 | out: |
Heinrich Schuchardt | 0a27ac8 | 2017-11-06 21:17:44 +0100 | [diff] [blame] | 1211 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1212 | } |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 1213 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1214 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1215 | * efi_get_drivers() - get all drivers associated to a controller |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1216 | * @handle: handle of the controller |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 1217 | * @protocol: protocol GUID (optional) |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1218 | * @number_of_drivers: number of child controllers |
| 1219 | * @driver_handle_buffer: handles of the the drivers |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1220 | * |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1221 | * The allocated buffer has to be freed with free(). |
| 1222 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1223 | * Return: status code |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1224 | */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1225 | static efi_status_t efi_get_drivers(efi_handle_t handle, |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1226 | const efi_guid_t *protocol, |
| 1227 | efi_uintn_t *number_of_drivers, |
| 1228 | efi_handle_t **driver_handle_buffer) |
| 1229 | { |
| 1230 | struct efi_handler *handler; |
| 1231 | struct efi_open_protocol_info_item *item; |
| 1232 | efi_uintn_t count = 0, i; |
| 1233 | bool duplicate; |
| 1234 | |
| 1235 | /* Count all driver associations */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1236 | list_for_each_entry(handler, &handle->protocols, link) { |
Heinrich Schuchardt | 2a22db9 | 2022-03-09 19:56:23 +0100 | [diff] [blame] | 1237 | if (protocol && guidcmp(&handler->guid, protocol)) |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1238 | continue; |
| 1239 | list_for_each_entry(item, &handler->open_infos, link) { |
| 1240 | if (item->info.attributes & |
| 1241 | EFI_OPEN_PROTOCOL_BY_DRIVER) |
| 1242 | ++count; |
| 1243 | } |
| 1244 | } |
Heinrich Schuchardt | 7416aef | 2019-06-02 01:43:33 +0200 | [diff] [blame] | 1245 | *number_of_drivers = 0; |
| 1246 | if (!count) { |
| 1247 | *driver_handle_buffer = NULL; |
| 1248 | return EFI_SUCCESS; |
| 1249 | } |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1250 | /* |
| 1251 | * Create buffer. In case of duplicate driver assignments the buffer |
| 1252 | * will be too large. But that does not harm. |
| 1253 | */ |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1254 | *driver_handle_buffer = calloc(count, sizeof(efi_handle_t)); |
| 1255 | if (!*driver_handle_buffer) |
| 1256 | return EFI_OUT_OF_RESOURCES; |
| 1257 | /* Collect unique driver handles */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1258 | list_for_each_entry(handler, &handle->protocols, link) { |
Heinrich Schuchardt | 2a22db9 | 2022-03-09 19:56:23 +0100 | [diff] [blame] | 1259 | if (protocol && guidcmp(&handler->guid, protocol)) |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1260 | continue; |
| 1261 | list_for_each_entry(item, &handler->open_infos, link) { |
| 1262 | if (item->info.attributes & |
| 1263 | EFI_OPEN_PROTOCOL_BY_DRIVER) { |
| 1264 | /* Check this is a new driver */ |
| 1265 | duplicate = false; |
| 1266 | for (i = 0; i < *number_of_drivers; ++i) { |
| 1267 | if ((*driver_handle_buffer)[i] == |
| 1268 | item->info.agent_handle) |
| 1269 | duplicate = true; |
| 1270 | } |
| 1271 | /* Copy handle to buffer */ |
| 1272 | if (!duplicate) { |
| 1273 | i = (*number_of_drivers)++; |
| 1274 | (*driver_handle_buffer)[i] = |
| 1275 | item->info.agent_handle; |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | return EFI_SUCCESS; |
| 1281 | } |
| 1282 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1283 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1284 | * efi_disconnect_all_drivers() - disconnect all drivers from a controller |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1285 | * @handle: handle of the controller |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 1286 | * @protocol: protocol GUID (optional) |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1287 | * @child_handle: handle of the child to destroy |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1288 | * |
| 1289 | * This function implements the DisconnectController service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1290 | * |
| 1291 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1292 | * details. |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1293 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1294 | * Return: status code |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1295 | */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1296 | static efi_status_t efi_disconnect_all_drivers |
| 1297 | (efi_handle_t handle, |
| 1298 | const efi_guid_t *protocol, |
| 1299 | efi_handle_t child_handle) |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1300 | { |
| 1301 | efi_uintn_t number_of_drivers; |
| 1302 | efi_handle_t *driver_handle_buffer; |
| 1303 | efi_status_t r, ret; |
| 1304 | |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1305 | ret = efi_get_drivers(handle, protocol, &number_of_drivers, |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1306 | &driver_handle_buffer); |
| 1307 | if (ret != EFI_SUCCESS) |
| 1308 | return ret; |
Heinrich Schuchardt | 7416aef | 2019-06-02 01:43:33 +0200 | [diff] [blame] | 1309 | if (!number_of_drivers) |
| 1310 | return EFI_SUCCESS; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1311 | ret = EFI_NOT_FOUND; |
| 1312 | while (number_of_drivers) { |
| 1313 | r = EFI_CALL(efi_disconnect_controller( |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1314 | handle, |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 1315 | driver_handle_buffer[--number_of_drivers], |
| 1316 | child_handle)); |
| 1317 | if (r == EFI_SUCCESS) |
| 1318 | ret = r; |
| 1319 | } |
| 1320 | free(driver_handle_buffer); |
| 1321 | return ret; |
| 1322 | } |
| 1323 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1324 | /** |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 1325 | * efi_uninstall_protocol() - uninstall protocol interface |
| 1326 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1327 | * @handle: handle from which the protocol shall be removed |
| 1328 | * @protocol: GUID of the protocol to be removed |
| 1329 | * @protocol_interface: interface to be removed |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1330 | * |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 1331 | * This function DOES NOT delete a handle without installed protocol. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1332 | * |
| 1333 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1334 | */ |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 1335 | static efi_status_t efi_uninstall_protocol |
| 1336 | (efi_handle_t handle, const efi_guid_t *protocol, |
| 1337 | void *protocol_interface) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1338 | { |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1339 | struct efi_object *efiobj; |
Heinrich Schuchardt | 7538c27 | 2017-10-26 19:25:56 +0200 | [diff] [blame] | 1340 | struct efi_handler *handler; |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1341 | struct efi_open_protocol_info_item *item; |
| 1342 | struct efi_open_protocol_info_item *pos; |
Heinrich Schuchardt | 7538c27 | 2017-10-26 19:25:56 +0200 | [diff] [blame] | 1343 | efi_status_t r; |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 1344 | |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1345 | /* Check handle */ |
| 1346 | efiobj = efi_search_obj(handle); |
| 1347 | if (!efiobj) { |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 1348 | r = EFI_INVALID_PARAMETER; |
| 1349 | goto out; |
| 1350 | } |
Heinrich Schuchardt | 7538c27 | 2017-10-26 19:25:56 +0200 | [diff] [blame] | 1351 | /* Find the protocol on the handle */ |
| 1352 | r = efi_search_protocol(handle, protocol, &handler); |
| 1353 | if (r != EFI_SUCCESS) |
| 1354 | goto out; |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1355 | /* Disconnect controllers */ |
| 1356 | efi_disconnect_all_drivers(efiobj, protocol, NULL); |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1357 | /* Close protocol */ |
| 1358 | list_for_each_entry_safe(item, pos, &handler->open_infos, link) { |
| 1359 | if (item->info.attributes == |
| 1360 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL || |
| 1361 | item->info.attributes == EFI_OPEN_PROTOCOL_GET_PROTOCOL || |
| 1362 | item->info.attributes == EFI_OPEN_PROTOCOL_TEST_PROTOCOL) |
| 1363 | list_del(&item->link); |
| 1364 | } |
| 1365 | if (!list_empty(&handler->open_infos)) { |
Heinrich Schuchardt | 7538c27 | 2017-10-26 19:25:56 +0200 | [diff] [blame] | 1366 | r = EFI_ACCESS_DENIED; |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1367 | goto out; |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 1368 | } |
Heinrich Schuchardt | 86637f3 | 2018-01-11 08:16:05 +0100 | [diff] [blame] | 1369 | r = efi_remove_protocol(handle, protocol, protocol_interface); |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 1370 | out: |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 1371 | return r; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1374 | /** |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 1375 | * efi_uninstall_protocol_interface() - uninstall protocol interface |
| 1376 | * @handle: handle from which the protocol shall be removed |
| 1377 | * @protocol: GUID of the protocol to be removed |
| 1378 | * @protocol_interface: interface to be removed |
| 1379 | * |
| 1380 | * This function implements the UninstallProtocolInterface service. |
| 1381 | * |
| 1382 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1383 | * details. |
| 1384 | * |
| 1385 | * Return: status code |
| 1386 | */ |
| 1387 | static efi_status_t EFIAPI efi_uninstall_protocol_interface |
| 1388 | (efi_handle_t handle, const efi_guid_t *protocol, |
| 1389 | void *protocol_interface) |
| 1390 | { |
| 1391 | efi_status_t ret; |
| 1392 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 1393 | EFI_ENTRY("%p, %pUs, %p", handle, protocol, protocol_interface); |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 1394 | |
| 1395 | ret = efi_uninstall_protocol(handle, protocol, protocol_interface); |
| 1396 | if (ret != EFI_SUCCESS) |
| 1397 | goto out; |
| 1398 | |
| 1399 | /* If the last protocol has been removed, delete the handle. */ |
| 1400 | if (list_empty(&handle->protocols)) { |
| 1401 | list_del(&handle->link); |
| 1402 | free(handle); |
| 1403 | } |
| 1404 | out: |
| 1405 | return EFI_EXIT(ret); |
| 1406 | } |
| 1407 | |
| 1408 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1409 | * efi_register_protocol_notify() - register an event for notification when a |
| 1410 | * protocol is installed. |
| 1411 | * @protocol: GUID of the protocol whose installation shall be notified |
| 1412 | * @event: event to be signaled upon installation of the protocol |
| 1413 | * @registration: key for retrieving the registration information |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1414 | * |
| 1415 | * This function implements the RegisterProtocolNotify service. |
| 1416 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 1417 | * for details. |
| 1418 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1419 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1420 | */ |
Jose Marinho | ebb61ee | 2021-03-02 17:26:38 +0000 | [diff] [blame] | 1421 | efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol, |
| 1422 | struct efi_event *event, |
| 1423 | void **registration) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1424 | { |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1425 | struct efi_register_notify_event *item; |
| 1426 | efi_status_t ret = EFI_SUCCESS; |
| 1427 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 1428 | EFI_ENTRY("%pUs, %p, %p", protocol, event, registration); |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (!protocol || !event || !registration) { |
| 1431 | ret = EFI_INVALID_PARAMETER; |
| 1432 | goto out; |
| 1433 | } |
| 1434 | |
| 1435 | item = calloc(1, sizeof(struct efi_register_notify_event)); |
| 1436 | if (!item) { |
| 1437 | ret = EFI_OUT_OF_RESOURCES; |
| 1438 | goto out; |
| 1439 | } |
| 1440 | |
| 1441 | item->event = event; |
Sughosh Ganu | 196f66d | 2019-12-29 00:01:04 +0530 | [diff] [blame] | 1442 | guidcpy(&item->protocol, protocol); |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1443 | INIT_LIST_HEAD(&item->handles); |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1444 | |
| 1445 | list_add_tail(&item->link, &efi_register_notify_events); |
| 1446 | |
| 1447 | *registration = item; |
| 1448 | out: |
| 1449 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1450 | } |
| 1451 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1452 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1453 | * efi_search() - determine if an EFI handle implements a protocol |
Heinrich Schuchardt | 41cc3c1 | 2019-07-14 11:05:34 +0200 | [diff] [blame] | 1454 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1455 | * @search_type: selection criterion |
| 1456 | * @protocol: GUID of the protocol |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1457 | * @handle: handle |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1458 | * |
| 1459 | * See the documentation of the LocateHandle service in the UEFI specification. |
| 1460 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1461 | * Return: 0 if the handle implements the protocol |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1462 | */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1463 | static int efi_search(enum efi_locate_search_type search_type, |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1464 | const efi_guid_t *protocol, efi_handle_t handle) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1465 | { |
Heinrich Schuchardt | 6a43075 | 2017-10-26 19:25:55 +0200 | [diff] [blame] | 1466 | efi_status_t ret; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1467 | |
| 1468 | switch (search_type) { |
Heinrich Schuchardt | 68845f0 | 2017-11-06 21:17:42 +0100 | [diff] [blame] | 1469 | case ALL_HANDLES: |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1470 | return 0; |
Heinrich Schuchardt | 68845f0 | 2017-11-06 21:17:42 +0100 | [diff] [blame] | 1471 | case BY_PROTOCOL: |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 1472 | ret = efi_search_protocol(handle, protocol, NULL); |
Heinrich Schuchardt | 6a43075 | 2017-10-26 19:25:55 +0200 | [diff] [blame] | 1473 | return (ret != EFI_SUCCESS); |
| 1474 | default: |
| 1475 | /* Invalid search type */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1476 | return -1; |
| 1477 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1478 | } |
| 1479 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1480 | /** |
Heinrich Schuchardt | eb61652 | 2019-05-29 07:46:33 +0200 | [diff] [blame] | 1481 | * efi_check_register_notify_event() - check if registration key is valid |
| 1482 | * |
| 1483 | * Check that a pointer is a valid registration key as returned by |
| 1484 | * RegisterProtocolNotify(). |
| 1485 | * |
| 1486 | * @key: registration key |
| 1487 | * Return: valid registration key or NULL |
| 1488 | */ |
| 1489 | static struct efi_register_notify_event *efi_check_register_notify_event |
| 1490 | (void *key) |
| 1491 | { |
| 1492 | struct efi_register_notify_event *event; |
| 1493 | |
| 1494 | list_for_each_entry(event, &efi_register_notify_events, link) { |
| 1495 | if (event == (struct efi_register_notify_event *)key) |
| 1496 | return event; |
| 1497 | } |
| 1498 | return NULL; |
| 1499 | } |
| 1500 | |
| 1501 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1502 | * efi_locate_handle() - locate handles implementing a protocol |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1503 | * |
| 1504 | * @search_type: selection criterion |
| 1505 | * @protocol: GUID of the protocol |
| 1506 | * @search_key: registration key |
| 1507 | * @buffer_size: size of the buffer to receive the handles in bytes |
| 1508 | * @buffer: buffer to receive the relevant handles |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1509 | * |
| 1510 | * This function is meant for U-Boot internal calls. For the API implementation |
| 1511 | * of the LocateHandle service see efi_locate_handle_ext. |
| 1512 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1513 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1514 | */ |
xypron.glpk@gmx.de | cab4dd5 | 2017-08-09 20:55:00 +0200 | [diff] [blame] | 1515 | static efi_status_t efi_locate_handle( |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1516 | enum efi_locate_search_type search_type, |
Heinrich Schuchardt | e547c66 | 2017-10-05 16:35:53 +0200 | [diff] [blame] | 1517 | const efi_guid_t *protocol, void *search_key, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 1518 | efi_uintn_t *buffer_size, efi_handle_t *buffer) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1519 | { |
Heinrich Schuchardt | ec66fc8 | 2017-11-06 21:17:49 +0100 | [diff] [blame] | 1520 | struct efi_object *efiobj; |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 1521 | efi_uintn_t size = 0; |
Heinrich Schuchardt | eb61652 | 2019-05-29 07:46:33 +0200 | [diff] [blame] | 1522 | struct efi_register_notify_event *event; |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1523 | struct efi_protocol_notification *handle = NULL; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1524 | |
Heinrich Schuchardt | ec66fc8 | 2017-11-06 21:17:49 +0100 | [diff] [blame] | 1525 | /* Check parameters */ |
| 1526 | switch (search_type) { |
| 1527 | case ALL_HANDLES: |
| 1528 | break; |
| 1529 | case BY_REGISTER_NOTIFY: |
| 1530 | if (!search_key) |
| 1531 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1532 | /* Check that the registration key is valid */ |
Heinrich Schuchardt | eb61652 | 2019-05-29 07:46:33 +0200 | [diff] [blame] | 1533 | event = efi_check_register_notify_event(search_key); |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1534 | if (!event) |
| 1535 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | 6eec42d | 2019-05-04 17:27:54 +0200 | [diff] [blame] | 1536 | break; |
Heinrich Schuchardt | ec66fc8 | 2017-11-06 21:17:49 +0100 | [diff] [blame] | 1537 | case BY_PROTOCOL: |
| 1538 | if (!protocol) |
| 1539 | return EFI_INVALID_PARAMETER; |
| 1540 | break; |
| 1541 | default: |
| 1542 | return EFI_INVALID_PARAMETER; |
| 1543 | } |
| 1544 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1545 | /* Count how much space we need */ |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1546 | if (search_type == BY_REGISTER_NOTIFY) { |
| 1547 | if (list_empty(&event->handles)) |
| 1548 | return EFI_NOT_FOUND; |
| 1549 | handle = list_first_entry(&event->handles, |
| 1550 | struct efi_protocol_notification, |
| 1551 | link); |
| 1552 | efiobj = handle->handle; |
| 1553 | size += sizeof(void *); |
| 1554 | } else { |
| 1555 | list_for_each_entry(efiobj, &efi_obj_list, link) { |
| 1556 | if (!efi_search(search_type, protocol, efiobj)) |
| 1557 | size += sizeof(void *); |
| 1558 | } |
| 1559 | if (size == 0) |
| 1560 | return EFI_NOT_FOUND; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
Heinrich Schuchardt | c0ee5f3 | 2019-05-04 17:37:32 +0200 | [diff] [blame] | 1563 | if (!buffer_size) |
| 1564 | return EFI_INVALID_PARAMETER; |
| 1565 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1566 | if (*buffer_size < size) { |
| 1567 | *buffer_size = size; |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1568 | return EFI_BUFFER_TOO_SMALL; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
Rob Clark | cdee337 | 2017-08-06 14:10:07 -0400 | [diff] [blame] | 1571 | *buffer_size = size; |
Heinrich Schuchardt | c0ee5f3 | 2019-05-04 17:37:32 +0200 | [diff] [blame] | 1572 | |
Heinrich Schuchardt | c97f947 | 2019-05-10 19:03:49 +0200 | [diff] [blame] | 1573 | /* The buffer size is sufficient but there is no buffer */ |
Heinrich Schuchardt | c0ee5f3 | 2019-05-04 17:37:32 +0200 | [diff] [blame] | 1574 | if (!buffer) |
| 1575 | return EFI_INVALID_PARAMETER; |
Rob Clark | cdee337 | 2017-08-06 14:10:07 -0400 | [diff] [blame] | 1576 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1577 | /* Then fill the array */ |
Heinrich Schuchardt | d375e75 | 2019-05-21 18:19:01 +0200 | [diff] [blame] | 1578 | if (search_type == BY_REGISTER_NOTIFY) { |
| 1579 | *buffer = efiobj; |
| 1580 | list_del(&handle->link); |
| 1581 | } else { |
| 1582 | list_for_each_entry(efiobj, &efi_obj_list, link) { |
| 1583 | if (!efi_search(search_type, protocol, efiobj)) |
| 1584 | *buffer++ = efiobj; |
| 1585 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1586 | } |
| 1587 | |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1588 | return EFI_SUCCESS; |
| 1589 | } |
| 1590 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1591 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1592 | * efi_locate_handle_ext() - locate handles implementing a protocol. |
| 1593 | * @search_type: selection criterion |
| 1594 | * @protocol: GUID of the protocol |
| 1595 | * @search_key: registration key |
| 1596 | * @buffer_size: size of the buffer to receive the handles in bytes |
| 1597 | * @buffer: buffer to receive the relevant handles |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1598 | * |
| 1599 | * This function implements the LocateHandle service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1600 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1601 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1602 | * details. |
| 1603 | * |
| 1604 | * Return: 0 if the handle implements the protocol |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1605 | */ |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1606 | static efi_status_t EFIAPI efi_locate_handle_ext( |
| 1607 | enum efi_locate_search_type search_type, |
Heinrich Schuchardt | e547c66 | 2017-10-05 16:35:53 +0200 | [diff] [blame] | 1608 | const efi_guid_t *protocol, void *search_key, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 1609 | efi_uintn_t *buffer_size, efi_handle_t *buffer) |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1610 | { |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 1611 | EFI_ENTRY("%d, %pUs, %p, %p, %p", search_type, protocol, search_key, |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1612 | buffer_size, buffer); |
| 1613 | |
| 1614 | return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key, |
| 1615 | buffer_size, buffer)); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1618 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1619 | * efi_remove_configuration_table() - collapses configuration table entries, |
| 1620 | * removing index i |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1621 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1622 | * @i: index of the table entry to be removed |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1623 | */ |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 1624 | static void efi_remove_configuration_table(int i) |
| 1625 | { |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 1626 | struct efi_configuration_table *this = &systab.tables[i]; |
| 1627 | struct efi_configuration_table *next = &systab.tables[i + 1]; |
| 1628 | struct efi_configuration_table *end = &systab.tables[systab.nr_tables]; |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 1629 | |
| 1630 | memmove(this, next, (ulong)end - (ulong)next); |
| 1631 | systab.nr_tables--; |
| 1632 | } |
| 1633 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1634 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1635 | * efi_install_configuration_table() - adds, updates, or removes a |
| 1636 | * configuration table |
| 1637 | * @guid: GUID of the installed table |
| 1638 | * @table: table to be installed |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1639 | * |
| 1640 | * This function is used for internal calls. For the API implementation of the |
| 1641 | * InstallConfigurationTable service see efi_install_configuration_table_ext. |
| 1642 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1643 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1644 | */ |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 1645 | efi_status_t efi_install_configuration_table(const efi_guid_t *guid, |
| 1646 | void *table) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1647 | { |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1648 | struct efi_event *evt; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1649 | int i; |
| 1650 | |
Heinrich Schuchardt | 754ce10 | 2018-02-18 00:08:00 +0100 | [diff] [blame] | 1651 | if (!guid) |
| 1652 | return EFI_INVALID_PARAMETER; |
| 1653 | |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 1654 | /* Check for GUID override */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1655 | for (i = 0; i < systab.nr_tables; i++) { |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 1656 | if (!guidcmp(guid, &systab.tables[i].guid)) { |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 1657 | if (table) |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 1658 | systab.tables[i].table = table; |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 1659 | else |
| 1660 | efi_remove_configuration_table(i); |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1661 | goto out; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 1665 | if (!table) |
| 1666 | return EFI_NOT_FOUND; |
| 1667 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1668 | /* No override, check for overflow */ |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 1669 | if (i >= EFI_MAX_CONFIGURATION_TABLES) |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 1670 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1671 | |
| 1672 | /* Add a new entry */ |
Sughosh Ganu | 196f66d | 2019-12-29 00:01:04 +0530 | [diff] [blame] | 1673 | guidcpy(&systab.tables[i].guid, guid); |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 1674 | systab.tables[i].table = table; |
Alexander Graf | 9982e67 | 2016-08-19 01:23:30 +0200 | [diff] [blame] | 1675 | systab.nr_tables = i + 1; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1676 | |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1677 | out: |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 1678 | /* systab.nr_tables may have changed. So we need to update the CRC32 */ |
Heinrich Schuchardt | ac2d4da | 2018-07-07 15:36:05 +0200 | [diff] [blame] | 1679 | efi_update_table_header_crc32(&systab.hdr); |
| 1680 | |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1681 | /* Notify that the configuration table was changed */ |
| 1682 | list_for_each_entry(evt, &efi_events, link) { |
| 1683 | if (evt->group && !guidcmp(evt->group, guid)) { |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 1684 | efi_signal_event(evt); |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 1685 | break; |
| 1686 | } |
| 1687 | } |
| 1688 | |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 1689 | return EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1690 | } |
| 1691 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1692 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1693 | * efi_install_configuration_table_ex() - Adds, updates, or removes a |
| 1694 | * configuration table. |
| 1695 | * @guid: GUID of the installed table |
| 1696 | * @table: table to be installed |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1697 | * |
| 1698 | * This function implements the InstallConfigurationTable service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1699 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1700 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1701 | * details. |
| 1702 | * |
| 1703 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1704 | */ |
Masahisa Kojima | bc38d77 | 2021-10-22 20:24:24 +0900 | [diff] [blame] | 1705 | static efi_status_t |
| 1706 | EFIAPI efi_install_configuration_table_ext(const efi_guid_t *guid, |
| 1707 | void *table) |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 1708 | { |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 1709 | EFI_ENTRY("%pUs, %p", guid, table); |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 1710 | return EFI_EXIT(efi_install_configuration_table(guid, table)); |
| 1711 | } |
| 1712 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1713 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 1714 | * efi_setup_loaded_image() - initialize a loaded image |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1715 | * |
| 1716 | * Initialize a loaded_image_info and loaded_image_info object with correct |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 1717 | * protocols, boot-device, etc. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1718 | * |
Heinrich Schuchardt | 41cc3c1 | 2019-07-14 11:05:34 +0200 | [diff] [blame] | 1719 | * In case of an error \*handle_ptr and \*info_ptr are set to NULL and an error |
Heinrich Schuchardt | 6346a90 | 2019-02-06 19:41:29 +0100 | [diff] [blame] | 1720 | * code is returned. |
| 1721 | * |
| 1722 | * @device_path: device path of the loaded image |
| 1723 | * @file_path: file path of the loaded image |
| 1724 | * @handle_ptr: handle of the loaded image |
| 1725 | * @info_ptr: loaded image protocol |
| 1726 | * Return: status code |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 1727 | */ |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 1728 | efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, |
| 1729 | struct efi_device_path *file_path, |
| 1730 | struct efi_loaded_image_obj **handle_ptr, |
| 1731 | struct efi_loaded_image **info_ptr) |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 1732 | { |
Heinrich Schuchardt | 24d3a66 | 2017-10-26 19:25:58 +0200 | [diff] [blame] | 1733 | efi_status_t ret; |
Heinrich Schuchardt | 6346a90 | 2019-02-06 19:41:29 +0100 | [diff] [blame] | 1734 | struct efi_loaded_image *info = NULL; |
| 1735 | struct efi_loaded_image_obj *obj = NULL; |
AKASHI Takahiro | bbe13da | 2019-03-27 13:40:32 +0900 | [diff] [blame] | 1736 | struct efi_device_path *dp; |
Heinrich Schuchardt | 6346a90 | 2019-02-06 19:41:29 +0100 | [diff] [blame] | 1737 | |
| 1738 | /* In case of EFI_OUT_OF_RESOURCES avoid illegal free by caller. */ |
| 1739 | *handle_ptr = NULL; |
| 1740 | *info_ptr = NULL; |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 1741 | |
| 1742 | info = calloc(1, sizeof(*info)); |
| 1743 | if (!info) |
| 1744 | return EFI_OUT_OF_RESOURCES; |
| 1745 | obj = calloc(1, sizeof(*obj)); |
| 1746 | if (!obj) { |
| 1747 | free(info); |
| 1748 | return EFI_OUT_OF_RESOURCES; |
| 1749 | } |
Heinrich Schuchardt | b27ced4 | 2019-05-01 14:20:18 +0200 | [diff] [blame] | 1750 | obj->header.type = EFI_OBJECT_TYPE_LOADED_IMAGE; |
Heinrich Schuchardt | 24d3a66 | 2017-10-26 19:25:58 +0200 | [diff] [blame] | 1751 | |
Heinrich Schuchardt | 967d7de | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 1752 | /* Add internal object to object list */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 1753 | efi_add_handle(&obj->header); |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 1754 | |
Heinrich Schuchardt | c47f870 | 2018-07-05 08:17:58 +0200 | [diff] [blame] | 1755 | info->revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; |
Heinrich Schuchardt | 24d3a66 | 2017-10-26 19:25:58 +0200 | [diff] [blame] | 1756 | info->file_path = file_path; |
Heinrich Schuchardt | 8a7e09d | 2018-08-26 15:31:52 +0200 | [diff] [blame] | 1757 | info->system_table = &systab; |
Heinrich Schuchardt | 24d3a66 | 2017-10-26 19:25:58 +0200 | [diff] [blame] | 1758 | |
Heinrich Schuchardt | f3996be | 2018-01-26 06:50:54 +0100 | [diff] [blame] | 1759 | if (device_path) { |
Heinrich Schuchardt | 0a04a41 | 2022-03-19 06:35:43 +0100 | [diff] [blame] | 1760 | info->device_handle = efi_dp_find_obj(device_path, NULL, NULL); |
AKASHI Takahiro | bbe13da | 2019-03-27 13:40:32 +0900 | [diff] [blame] | 1761 | |
| 1762 | dp = efi_dp_append(device_path, file_path); |
| 1763 | if (!dp) { |
| 1764 | ret = EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | f3996be | 2018-01-26 06:50:54 +0100 | [diff] [blame] | 1765 | goto failure; |
AKASHI Takahiro | bbe13da | 2019-03-27 13:40:32 +0900 | [diff] [blame] | 1766 | } |
| 1767 | } else { |
| 1768 | dp = NULL; |
Heinrich Schuchardt | f3996be | 2018-01-26 06:50:54 +0100 | [diff] [blame] | 1769 | } |
AKASHI Takahiro | bbe13da | 2019-03-27 13:40:32 +0900 | [diff] [blame] | 1770 | ret = efi_add_protocol(&obj->header, |
| 1771 | &efi_guid_loaded_image_device_path, dp); |
| 1772 | if (ret != EFI_SUCCESS) |
| 1773 | goto failure; |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 1774 | |
| 1775 | /* |
| 1776 | * When asking for the loaded_image interface, just |
| 1777 | * return handle which points to loaded_image_info |
| 1778 | */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 1779 | ret = efi_add_protocol(&obj->header, |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 1780 | &efi_guid_loaded_image, info); |
Heinrich Schuchardt | 24d3a66 | 2017-10-26 19:25:58 +0200 | [diff] [blame] | 1781 | if (ret != EFI_SUCCESS) |
| 1782 | goto failure; |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 1783 | |
Heinrich Schuchardt | d20f512 | 2019-03-19 18:58:58 +0100 | [diff] [blame] | 1784 | *info_ptr = info; |
| 1785 | *handle_ptr = obj; |
Heinrich Schuchardt | 6346a90 | 2019-02-06 19:41:29 +0100 | [diff] [blame] | 1786 | |
Heinrich Schuchardt | 7db9f89 | 2017-12-04 18:03:01 +0100 | [diff] [blame] | 1787 | return ret; |
Heinrich Schuchardt | 24d3a66 | 2017-10-26 19:25:58 +0200 | [diff] [blame] | 1788 | failure: |
| 1789 | printf("ERROR: Failure to install protocols for loaded image\n"); |
Heinrich Schuchardt | 6346a90 | 2019-02-06 19:41:29 +0100 | [diff] [blame] | 1790 | efi_delete_handle(&obj->header); |
| 1791 | free(info); |
Heinrich Schuchardt | 7db9f89 | 2017-12-04 18:03:01 +0100 | [diff] [blame] | 1792 | return ret; |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1795 | /** |
Heinrich Schuchardt | 1d59a57 | 2020-12-04 03:02:03 +0100 | [diff] [blame] | 1796 | * efi_locate_device_path() - Get the device path and handle of an device |
| 1797 | * implementing a protocol |
| 1798 | * @protocol: GUID of the protocol |
| 1799 | * @device_path: device path |
| 1800 | * @device: handle of the device |
| 1801 | * |
| 1802 | * This function implements the LocateDevicePath service. |
| 1803 | * |
| 1804 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 1805 | * details. |
| 1806 | * |
| 1807 | * Return: status code |
| 1808 | */ |
AKASHI Takahiro | 537a693 | 2022-04-28 17:09:38 +0900 | [diff] [blame] | 1809 | efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol, |
| 1810 | struct efi_device_path **device_path, |
| 1811 | efi_handle_t *device) |
Heinrich Schuchardt | 1d59a57 | 2020-12-04 03:02:03 +0100 | [diff] [blame] | 1812 | { |
| 1813 | struct efi_device_path *dp; |
| 1814 | size_t i; |
| 1815 | struct efi_handler *handler; |
| 1816 | efi_handle_t *handles; |
| 1817 | size_t len, len_dp; |
| 1818 | size_t len_best = 0; |
| 1819 | efi_uintn_t no_handles; |
| 1820 | u8 *remainder; |
| 1821 | efi_status_t ret; |
| 1822 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 1823 | EFI_ENTRY("%pUs, %p, %p", protocol, device_path, device); |
Heinrich Schuchardt | 1d59a57 | 2020-12-04 03:02:03 +0100 | [diff] [blame] | 1824 | |
| 1825 | if (!protocol || !device_path || !*device_path) { |
| 1826 | ret = EFI_INVALID_PARAMETER; |
| 1827 | goto out; |
| 1828 | } |
| 1829 | |
| 1830 | /* Find end of device path */ |
| 1831 | len = efi_dp_instance_size(*device_path); |
| 1832 | |
| 1833 | /* Get all handles implementing the protocol */ |
| 1834 | ret = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL, protocol, NULL, |
| 1835 | &no_handles, &handles)); |
| 1836 | if (ret != EFI_SUCCESS) |
| 1837 | goto out; |
| 1838 | |
| 1839 | for (i = 0; i < no_handles; ++i) { |
| 1840 | /* Find the device path protocol */ |
| 1841 | ret = efi_search_protocol(handles[i], &efi_guid_device_path, |
| 1842 | &handler); |
| 1843 | if (ret != EFI_SUCCESS) |
| 1844 | continue; |
| 1845 | dp = (struct efi_device_path *)handler->protocol_interface; |
| 1846 | len_dp = efi_dp_instance_size(dp); |
| 1847 | /* |
| 1848 | * This handle can only be a better fit |
| 1849 | * if its device path length is longer than the best fit and |
| 1850 | * if its device path length is shorter of equal the searched |
| 1851 | * device path. |
| 1852 | */ |
| 1853 | if (len_dp <= len_best || len_dp > len) |
| 1854 | continue; |
| 1855 | /* Check if dp is a subpath of device_path */ |
| 1856 | if (memcmp(*device_path, dp, len_dp)) |
| 1857 | continue; |
| 1858 | if (!device) { |
| 1859 | ret = EFI_INVALID_PARAMETER; |
| 1860 | goto out; |
| 1861 | } |
| 1862 | *device = handles[i]; |
| 1863 | len_best = len_dp; |
| 1864 | } |
| 1865 | if (len_best) { |
| 1866 | remainder = (u8 *)*device_path + len_best; |
| 1867 | *device_path = (struct efi_device_path *)remainder; |
| 1868 | ret = EFI_SUCCESS; |
| 1869 | } else { |
| 1870 | ret = EFI_NOT_FOUND; |
| 1871 | } |
| 1872 | out: |
| 1873 | return EFI_EXIT(ret); |
| 1874 | } |
| 1875 | |
| 1876 | /** |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 1877 | * efi_load_image_from_file() - load an image from file system |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1878 | * |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1879 | * Read a file into a buffer allocated as EFI_BOOT_SERVICES_DATA. It is the |
| 1880 | * callers obligation to update the memory type as needed. |
| 1881 | * |
Heinrich Schuchardt | 471db44 | 2020-12-04 09:27:41 +0100 | [diff] [blame] | 1882 | * @file_path: the path of the image to load |
| 1883 | * @buffer: buffer containing the loaded image |
| 1884 | * @size: size of the loaded image |
| 1885 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 1886 | */ |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 1887 | static |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 1888 | efi_status_t efi_load_image_from_file(struct efi_device_path *file_path, |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1889 | void **buffer, efi_uintn_t *size) |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1890 | { |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1891 | struct efi_file_handle *f; |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 1892 | efi_status_t ret; |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1893 | u64 addr; |
Heinrich Schuchardt | 6b06e0d | 2018-04-03 22:37:11 +0200 | [diff] [blame] | 1894 | efi_uintn_t bs; |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1895 | |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1896 | /* Open file */ |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1897 | f = efi_file_from_path(file_path); |
| 1898 | if (!f) |
Heinrich Schuchardt | 6a41cf2 | 2019-06-11 19:00:56 +0200 | [diff] [blame] | 1899 | return EFI_NOT_FOUND; |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1900 | |
Ilias Apalodimas | 03d0d76 | 2021-03-25 21:55:16 +0200 | [diff] [blame] | 1901 | ret = efi_file_size(f, &bs); |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1902 | if (ret != EFI_SUCCESS) |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1903 | goto error; |
| 1904 | |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1905 | /* |
| 1906 | * When reading the file we do not yet know if it contains an |
| 1907 | * application, a boottime driver, or a runtime driver. So here we |
| 1908 | * allocate a buffer as EFI_BOOT_SERVICES_DATA. The caller has to |
| 1909 | * update the reservation according to the image type. |
| 1910 | */ |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1911 | ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, |
| 1912 | EFI_BOOT_SERVICES_DATA, |
| 1913 | efi_size_in_pages(bs), &addr); |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1914 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1915 | ret = EFI_OUT_OF_RESOURCES; |
| 1916 | goto error; |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1917 | } |
| 1918 | |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 1919 | /* Read file */ |
| 1920 | EFI_CALL(ret = f->read(f, &bs, (void *)(uintptr_t)addr)); |
| 1921 | if (ret != EFI_SUCCESS) |
| 1922 | efi_free_pages(addr, efi_size_in_pages(bs)); |
| 1923 | *buffer = (void *)(uintptr_t)addr; |
| 1924 | *size = bs; |
| 1925 | error: |
| 1926 | EFI_CALL(f->close(f)); |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 1927 | return ret; |
| 1928 | } |
| 1929 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 1930 | /** |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 1931 | * efi_load_image_from_path() - load an image using a file path |
| 1932 | * |
| 1933 | * Read a file into a buffer allocated as EFI_BOOT_SERVICES_DATA. It is the |
| 1934 | * callers obligation to update the memory type as needed. |
| 1935 | * |
| 1936 | * @boot_policy: true for request originating from the boot manager |
| 1937 | * @file_path: the path of the image to load |
| 1938 | * @buffer: buffer containing the loaded image |
| 1939 | * @size: size of the loaded image |
| 1940 | * Return: status code |
| 1941 | */ |
| 1942 | static |
| 1943 | efi_status_t efi_load_image_from_path(bool boot_policy, |
| 1944 | struct efi_device_path *file_path, |
| 1945 | void **buffer, efi_uintn_t *size) |
| 1946 | { |
| 1947 | efi_handle_t device; |
| 1948 | efi_status_t ret; |
Heinrich Schuchardt | a1d8246 | 2022-02-26 12:05:30 +0100 | [diff] [blame] | 1949 | struct efi_device_path *dp, *rem; |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1950 | struct efi_load_file_protocol *load_file_protocol = NULL; |
| 1951 | efi_uintn_t buffer_size; |
| 1952 | uint64_t addr, pages; |
| 1953 | const efi_guid_t *guid; |
Heinrich Schuchardt | 94d7267 | 2023-01-24 20:36:45 +0100 | [diff] [blame] | 1954 | struct efi_handler *handler; |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 1955 | |
| 1956 | /* In case of failure nothing is returned */ |
| 1957 | *buffer = NULL; |
| 1958 | *size = 0; |
| 1959 | |
| 1960 | dp = file_path; |
Heinrich Schuchardt | a1d8246 | 2022-02-26 12:05:30 +0100 | [diff] [blame] | 1961 | device = efi_dp_find_obj(dp, NULL, &rem); |
| 1962 | ret = efi_search_protocol(device, &efi_simple_file_system_protocol_guid, |
| 1963 | NULL); |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 1964 | if (ret == EFI_SUCCESS) |
| 1965 | return efi_load_image_from_file(file_path, buffer, size); |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1966 | |
Heinrich Schuchardt | a1d8246 | 2022-02-26 12:05:30 +0100 | [diff] [blame] | 1967 | ret = efi_search_protocol(device, &efi_guid_load_file_protocol, NULL); |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1968 | if (ret == EFI_SUCCESS) { |
| 1969 | guid = &efi_guid_load_file_protocol; |
| 1970 | } else if (!boot_policy) { |
| 1971 | guid = &efi_guid_load_file2_protocol; |
Heinrich Schuchardt | a1d8246 | 2022-02-26 12:05:30 +0100 | [diff] [blame] | 1972 | ret = efi_search_protocol(device, guid, NULL); |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1973 | } |
| 1974 | if (ret != EFI_SUCCESS) |
| 1975 | return EFI_NOT_FOUND; |
Heinrich Schuchardt | 94d7267 | 2023-01-24 20:36:45 +0100 | [diff] [blame] | 1976 | ret = efi_search_protocol(device, guid, &handler); |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1977 | if (ret != EFI_SUCCESS) |
| 1978 | return EFI_NOT_FOUND; |
| 1979 | buffer_size = 0; |
Heinrich Schuchardt | 94d7267 | 2023-01-24 20:36:45 +0100 | [diff] [blame] | 1980 | load_file_protocol = handler->protocol_interface; |
Heinrich Schuchardt | a1d8246 | 2022-02-26 12:05:30 +0100 | [diff] [blame] | 1981 | ret = EFI_CALL(load_file_protocol->load_file( |
| 1982 | load_file_protocol, rem, boot_policy, |
| 1983 | &buffer_size, NULL)); |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1984 | if (ret != EFI_BUFFER_TOO_SMALL) |
| 1985 | goto out; |
| 1986 | pages = efi_size_in_pages(buffer_size); |
| 1987 | ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, EFI_BOOT_SERVICES_DATA, |
| 1988 | pages, &addr); |
| 1989 | if (ret != EFI_SUCCESS) { |
| 1990 | ret = EFI_OUT_OF_RESOURCES; |
| 1991 | goto out; |
| 1992 | } |
| 1993 | ret = EFI_CALL(load_file_protocol->load_file( |
Heinrich Schuchardt | a1d8246 | 2022-02-26 12:05:30 +0100 | [diff] [blame] | 1994 | load_file_protocol, rem, boot_policy, |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 1995 | &buffer_size, (void *)(uintptr_t)addr)); |
| 1996 | if (ret != EFI_SUCCESS) |
| 1997 | efi_free_pages(addr, pages); |
| 1998 | out: |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 1999 | efi_close_protocol(device, guid, efi_root, NULL); |
Heinrich Schuchardt | 8260827 | 2020-12-06 13:00:15 +0100 | [diff] [blame] | 2000 | if (ret == EFI_SUCCESS) { |
| 2001 | *buffer = (void *)(uintptr_t)addr; |
| 2002 | *size = buffer_size; |
| 2003 | } |
| 2004 | |
| 2005 | return ret; |
Heinrich Schuchardt | 3dd733e | 2020-12-06 10:47:57 +0100 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2009 | * efi_load_image() - load an EFI image into memory |
| 2010 | * @boot_policy: true for request originating from the boot manager |
| 2011 | * @parent_image: the caller's image handle |
| 2012 | * @file_path: the path of the image to load |
| 2013 | * @source_buffer: memory location from which the image is installed |
| 2014 | * @source_size: size of the memory area from which the image is installed |
| 2015 | * @image_handle: handle for the newly installed image |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2016 | * |
| 2017 | * This function implements the LoadImage service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2018 | * |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2019 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 2020 | * for details. |
| 2021 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2022 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2023 | */ |
AKASHI Takahiro | b0ad905 | 2019-03-05 14:53:31 +0900 | [diff] [blame] | 2024 | efi_status_t EFIAPI efi_load_image(bool boot_policy, |
| 2025 | efi_handle_t parent_image, |
| 2026 | struct efi_device_path *file_path, |
| 2027 | void *source_buffer, |
| 2028 | efi_uintn_t source_size, |
| 2029 | efi_handle_t *image_handle) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2030 | { |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 2031 | struct efi_device_path *dp, *fp; |
Tom Rini | 04c4906 | 2018-09-30 10:38:15 -0400 | [diff] [blame] | 2032 | struct efi_loaded_image *info = NULL; |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 2033 | struct efi_loaded_image_obj **image_obj = |
| 2034 | (struct efi_loaded_image_obj **)image_handle; |
Heinrich Schuchardt | d4d7ca9 | 2017-12-04 18:03:03 +0100 | [diff] [blame] | 2035 | efi_status_t ret; |
Heinrich Schuchardt | 47e35a9 | 2019-03-04 17:50:05 +0100 | [diff] [blame] | 2036 | void *dest_buffer; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2037 | |
Heinrich Schuchardt | e1e8a65 | 2022-02-03 22:21:51 +0100 | [diff] [blame] | 2038 | EFI_ENTRY("%d, %p, %pD, %p, %zu, %p", boot_policy, parent_image, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2039 | file_path, source_buffer, source_size, image_handle); |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 2040 | |
Heinrich Schuchardt | b7b1011 | 2019-06-11 18:52:33 +0200 | [diff] [blame] | 2041 | if (!image_handle || (!source_buffer && !file_path) || |
| 2042 | !efi_search_obj(parent_image) || |
| 2043 | /* The parent image handle must refer to a loaded image */ |
| 2044 | !parent_image->type) { |
Heinrich Schuchardt | 2e0a790 | 2019-05-05 16:55:06 +0200 | [diff] [blame] | 2045 | ret = EFI_INVALID_PARAMETER; |
| 2046 | goto error; |
| 2047 | } |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 2048 | |
| 2049 | if (!source_buffer) { |
Heinrich Schuchardt | 471db44 | 2020-12-04 09:27:41 +0100 | [diff] [blame] | 2050 | ret = efi_load_image_from_path(boot_policy, file_path, |
| 2051 | &dest_buffer, &source_size); |
Heinrich Schuchardt | d4d7ca9 | 2017-12-04 18:03:03 +0100 | [diff] [blame] | 2052 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 2053 | goto error; |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 2054 | } else { |
Heinrich Schuchardt | 47e35a9 | 2019-03-04 17:50:05 +0100 | [diff] [blame] | 2055 | dest_buffer = source_buffer; |
Rob Clark | 857a122 | 2017-09-13 18:05:35 -0400 | [diff] [blame] | 2056 | } |
Heinrich Schuchardt | 28b3917 | 2019-04-20 19:24:43 +0000 | [diff] [blame] | 2057 | /* split file_path which contains both the device and file parts */ |
| 2058 | efi_dp_split_file_path(file_path, &dp, &fp); |
Heinrich Schuchardt | e3d3a0c | 2018-12-24 09:19:07 +0100 | [diff] [blame] | 2059 | ret = efi_setup_loaded_image(dp, fp, image_obj, &info); |
Heinrich Schuchardt | 47e35a9 | 2019-03-04 17:50:05 +0100 | [diff] [blame] | 2060 | if (ret == EFI_SUCCESS) |
AKASHI Takahiro | 0e104e3 | 2020-04-14 11:51:44 +0900 | [diff] [blame] | 2061 | ret = efi_load_pe(*image_obj, dest_buffer, source_size, info); |
Heinrich Schuchardt | 47e35a9 | 2019-03-04 17:50:05 +0100 | [diff] [blame] | 2062 | if (!source_buffer) |
| 2063 | /* Release buffer to which file was loaded */ |
| 2064 | efi_free_pages((uintptr_t)dest_buffer, |
| 2065 | efi_size_in_pages(source_size)); |
AKASHI Takahiro | 0e104e3 | 2020-04-14 11:51:44 +0900 | [diff] [blame] | 2066 | if (ret == EFI_SUCCESS || ret == EFI_SECURITY_VIOLATION) { |
Heinrich Schuchardt | 47e35a9 | 2019-03-04 17:50:05 +0100 | [diff] [blame] | 2067 | info->system_table = &systab; |
| 2068 | info->parent_handle = parent_image; |
| 2069 | } else { |
| 2070 | /* The image is invalid. Release all associated resources. */ |
| 2071 | efi_delete_handle(*image_handle); |
| 2072 | *image_handle = NULL; |
| 2073 | free(info); |
| 2074 | } |
Heinrich Schuchardt | c935c2f | 2018-03-07 02:40:51 +0100 | [diff] [blame] | 2075 | error: |
Heinrich Schuchardt | d4d7ca9 | 2017-12-04 18:03:03 +0100 | [diff] [blame] | 2076 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2077 | } |
| 2078 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2079 | /** |
Alexander Graf | fa5246b | 2018-11-15 21:23:47 +0100 | [diff] [blame] | 2080 | * efi_exit_caches() - fix up caches for EFI payloads if necessary |
| 2081 | */ |
| 2082 | static void efi_exit_caches(void) |
| 2083 | { |
Heinrich Schuchardt | 149d5d4 | 2019-07-22 22:04:36 +0200 | [diff] [blame] | 2084 | #if defined(CONFIG_EFI_GRUB_ARM32_WORKAROUND) |
Alexander Graf | fa5246b | 2018-11-15 21:23:47 +0100 | [diff] [blame] | 2085 | /* |
Heinrich Schuchardt | 149d5d4 | 2019-07-22 22:04:36 +0200 | [diff] [blame] | 2086 | * Boooting Linux via GRUB prior to version 2.04 fails on 32bit ARM if |
| 2087 | * caches are enabled. |
| 2088 | * |
| 2089 | * TODO: |
| 2090 | * According to the UEFI spec caches that can be managed via CP15 |
| 2091 | * operations should be enabled. Caches requiring platform information |
| 2092 | * to manage should be disabled. This should not happen in |
| 2093 | * ExitBootServices() but before invoking any UEFI binary is invoked. |
| 2094 | * |
| 2095 | * We want to keep the current workaround while GRUB prior to version |
| 2096 | * 2.04 is still in use. |
Alexander Graf | fa5246b | 2018-11-15 21:23:47 +0100 | [diff] [blame] | 2097 | */ |
Heinrich Schuchardt | 149d5d4 | 2019-07-22 22:04:36 +0200 | [diff] [blame] | 2098 | cleanup_before_linux(); |
Alexander Graf | fa5246b | 2018-11-15 21:23:47 +0100 | [diff] [blame] | 2099 | #endif |
| 2100 | } |
| 2101 | |
| 2102 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2103 | * efi_exit_boot_services() - stop all boot services |
| 2104 | * @image_handle: handle of the loaded image |
| 2105 | * @map_key: key of the memory map |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2106 | * |
| 2107 | * This function implements the ExitBootServices service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2108 | * |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2109 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 2110 | * for details. |
| 2111 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2112 | * All timer events are disabled. For exit boot services events the |
| 2113 | * notification function is called. The boot services are disabled in the |
| 2114 | * system table. |
Heinrich Schuchardt | b1fbb21 | 2018-01-19 20:24:52 +0100 | [diff] [blame] | 2115 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2116 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2117 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 2118 | static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, |
Heinrich Schuchardt | 8bd4f41 | 2019-05-05 21:58:35 +0200 | [diff] [blame] | 2119 | efi_uintn_t map_key) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2120 | { |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 2121 | struct efi_event *evt, *next_event; |
Heinrich Schuchardt | afc3367 | 2019-06-11 20:05:40 +0200 | [diff] [blame] | 2122 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | 2d4c738 | 2017-09-15 10:06:18 +0200 | [diff] [blame] | 2123 | |
Heinrich Schuchardt | 8bd4f41 | 2019-05-05 21:58:35 +0200 | [diff] [blame] | 2124 | EFI_ENTRY("%p, %zx", image_handle, map_key); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2125 | |
Heinrich Schuchardt | 0f233c4 | 2018-07-02 12:53:55 +0200 | [diff] [blame] | 2126 | /* Check that the caller has read the current memory map */ |
Heinrich Schuchardt | afc3367 | 2019-06-11 20:05:40 +0200 | [diff] [blame] | 2127 | if (map_key != efi_memory_map_key) { |
| 2128 | ret = EFI_INVALID_PARAMETER; |
| 2129 | goto out; |
| 2130 | } |
Heinrich Schuchardt | 0f233c4 | 2018-07-02 12:53:55 +0200 | [diff] [blame] | 2131 | |
Heinrich Schuchardt | b1fbb21 | 2018-01-19 20:24:52 +0100 | [diff] [blame] | 2132 | /* Check if ExitBootServices has already been called */ |
| 2133 | if (!systab.boottime) |
Heinrich Schuchardt | afc3367 | 2019-06-11 20:05:40 +0200 | [diff] [blame] | 2134 | goto out; |
Heinrich Schuchardt | b1fbb21 | 2018-01-19 20:24:52 +0100 | [diff] [blame] | 2135 | |
Heinrich Schuchardt | 44772c4 | 2021-11-16 18:46:27 +0100 | [diff] [blame] | 2136 | /* Notify EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES event group. */ |
| 2137 | list_for_each_entry(evt, &efi_events, link) { |
| 2138 | if (evt->group && |
| 2139 | !guidcmp(evt->group, |
| 2140 | &efi_guid_event_group_before_exit_boot_services)) { |
| 2141 | efi_signal_event(evt); |
| 2142 | break; |
| 2143 | } |
| 2144 | } |
| 2145 | |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 2146 | /* Stop all timer related activities */ |
| 2147 | timers_enabled = false; |
| 2148 | |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 2149 | /* Add related events to the event group */ |
| 2150 | list_for_each_entry(evt, &efi_events, link) { |
| 2151 | if (evt->type == EVT_SIGNAL_EXIT_BOOT_SERVICES) |
| 2152 | evt->group = &efi_guid_event_group_exit_boot_services; |
| 2153 | } |
Heinrich Schuchardt | 2d4c738 | 2017-09-15 10:06:18 +0200 | [diff] [blame] | 2154 | /* Notify that ExitBootServices is invoked. */ |
Heinrich Schuchardt | 370c7a8 | 2018-02-18 15:17:50 +0100 | [diff] [blame] | 2155 | list_for_each_entry(evt, &efi_events, link) { |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 2156 | if (evt->group && |
| 2157 | !guidcmp(evt->group, |
| 2158 | &efi_guid_event_group_exit_boot_services)) { |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 2159 | efi_signal_event(evt); |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 2160 | break; |
| 2161 | } |
Heinrich Schuchardt | 2d4c738 | 2017-09-15 10:06:18 +0200 | [diff] [blame] | 2162 | } |
Heinrich Schuchardt | 2d4c738 | 2017-09-15 10:06:18 +0200 | [diff] [blame] | 2163 | |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 2164 | /* Make sure that notification functions are not called anymore */ |
| 2165 | efi_tpl = TPL_HIGH_LEVEL; |
| 2166 | |
Heinrich Schuchardt | 2ac6258 | 2019-06-20 15:25:48 +0200 | [diff] [blame] | 2167 | /* Notify variable services */ |
| 2168 | efi_variables_boot_exit_notify(); |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 2169 | |
Heinrich Schuchardt | 4429d87 | 2019-07-11 20:15:09 +0200 | [diff] [blame] | 2170 | /* Remove all events except EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE */ |
| 2171 | list_for_each_entry_safe(evt, next_event, &efi_events, link) { |
| 2172 | if (evt->type != EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) |
| 2173 | list_del(&evt->link); |
| 2174 | } |
| 2175 | |
Heinrich Schuchardt | 628dbd7 | 2020-11-12 21:26:28 +0100 | [diff] [blame] | 2176 | if (!efi_st_keep_devices) { |
Tom Rini | 669ef7f | 2021-11-19 16:33:04 -0500 | [diff] [blame] | 2177 | bootm_disable_interrupts(); |
Heinrich Schuchardt | 20dbedb | 2020-12-27 15:33:09 +0100 | [diff] [blame] | 2178 | if (IS_ENABLED(CONFIG_USB_DEVICE)) |
Heinrich Schuchardt | 628dbd7 | 2020-11-12 21:26:28 +0100 | [diff] [blame] | 2179 | udc_disconnect(); |
| 2180 | board_quiesce_devices(); |
| 2181 | dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); |
| 2182 | } |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 2183 | |
Heinrich Schuchardt | 1943dbb | 2019-07-05 17:42:16 +0200 | [diff] [blame] | 2184 | /* Patch out unsupported runtime function */ |
| 2185 | efi_runtime_detach(); |
| 2186 | |
Alexander Graf | fa5246b | 2018-11-15 21:23:47 +0100 | [diff] [blame] | 2187 | /* Fix up caches for EFI payloads if necessary */ |
| 2188 | efi_exit_caches(); |
| 2189 | |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 2190 | /* Disable boot time services */ |
Heinrich Schuchardt | b1fbb21 | 2018-01-19 20:24:52 +0100 | [diff] [blame] | 2191 | systab.con_in_handle = NULL; |
| 2192 | systab.con_in = NULL; |
| 2193 | systab.con_out_handle = NULL; |
| 2194 | systab.con_out = NULL; |
| 2195 | systab.stderr_handle = NULL; |
| 2196 | systab.std_err = NULL; |
| 2197 | systab.boottime = NULL; |
| 2198 | |
| 2199 | /* Recalculate CRC32 */ |
Heinrich Schuchardt | 15070db | 2018-06-28 12:45:31 +0200 | [diff] [blame] | 2200 | efi_update_table_header_crc32(&systab.hdr); |
Heinrich Schuchardt | b1fbb21 | 2018-01-19 20:24:52 +0100 | [diff] [blame] | 2201 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2202 | /* Give the payload some time to boot */ |
Heinrich Schuchardt | 18081d4 | 2017-10-18 18:13:04 +0200 | [diff] [blame] | 2203 | efi_set_watchdog(0); |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 2204 | schedule(); |
Heinrich Schuchardt | afc3367 | 2019-06-11 20:05:40 +0200 | [diff] [blame] | 2205 | out: |
Masahisa Kojima | 1ac19bb | 2021-08-13 16:12:41 +0900 | [diff] [blame] | 2206 | if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { |
| 2207 | if (ret != EFI_SUCCESS) |
| 2208 | efi_tcg2_notify_exit_boot_services_failed(); |
| 2209 | } |
| 2210 | |
Heinrich Schuchardt | afc3367 | 2019-06-11 20:05:40 +0200 | [diff] [blame] | 2211 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2212 | } |
| 2213 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2214 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2215 | * efi_get_next_monotonic_count() - get next value of the counter |
| 2216 | * @count: returned value of the counter |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2217 | * |
| 2218 | * This function implements the NextMonotonicCount service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2219 | * |
| 2220 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2221 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2222 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2223 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2224 | */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2225 | static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) |
| 2226 | { |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 2227 | static uint64_t mono; |
Heinrich Schuchardt | ddc787d | 2019-05-17 12:47:17 +0200 | [diff] [blame] | 2228 | efi_status_t ret; |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 2229 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2230 | EFI_ENTRY("%p", count); |
Heinrich Schuchardt | ddc787d | 2019-05-17 12:47:17 +0200 | [diff] [blame] | 2231 | if (!count) { |
| 2232 | ret = EFI_INVALID_PARAMETER; |
| 2233 | goto out; |
| 2234 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2235 | *count = mono++; |
Heinrich Schuchardt | ddc787d | 2019-05-17 12:47:17 +0200 | [diff] [blame] | 2236 | ret = EFI_SUCCESS; |
| 2237 | out: |
| 2238 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2239 | } |
| 2240 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2241 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2242 | * efi_stall() - sleep |
| 2243 | * @microseconds: period to sleep in microseconds |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2244 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2245 | * This function implements the Stall service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2246 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2247 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2248 | * details. |
| 2249 | * |
| 2250 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2251 | */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2252 | static efi_status_t EFIAPI efi_stall(unsigned long microseconds) |
| 2253 | { |
Heinrich Schuchardt | 9912c03 | 2019-06-02 21:12:17 +0200 | [diff] [blame] | 2254 | u64 end_tick; |
| 2255 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2256 | EFI_ENTRY("%ld", microseconds); |
Heinrich Schuchardt | 9912c03 | 2019-06-02 21:12:17 +0200 | [diff] [blame] | 2257 | |
| 2258 | end_tick = get_ticks() + usec_to_tick(microseconds); |
| 2259 | while (get_ticks() < end_tick) |
| 2260 | efi_timer_check(); |
| 2261 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2262 | return EFI_EXIT(EFI_SUCCESS); |
| 2263 | } |
| 2264 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2265 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2266 | * efi_set_watchdog_timer() - reset the watchdog timer |
| 2267 | * @timeout: seconds before reset by watchdog |
| 2268 | * @watchdog_code: code to be logged when resetting |
| 2269 | * @data_size: size of buffer in bytes |
| 2270 | * @watchdog_data: buffer with data describing the reset reason |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2271 | * |
Heinrich Schuchardt | 18081d4 | 2017-10-18 18:13:04 +0200 | [diff] [blame] | 2272 | * This function implements the SetWatchdogTimer service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2273 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2274 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2275 | * details. |
| 2276 | * |
| 2277 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2278 | */ |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2279 | static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, |
| 2280 | uint64_t watchdog_code, |
| 2281 | unsigned long data_size, |
| 2282 | uint16_t *watchdog_data) |
| 2283 | { |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 2284 | EFI_ENTRY("%ld, 0x%llx, %ld, %p", timeout, watchdog_code, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2285 | data_size, watchdog_data); |
Heinrich Schuchardt | 18081d4 | 2017-10-18 18:13:04 +0200 | [diff] [blame] | 2286 | return EFI_EXIT(efi_set_watchdog(timeout)); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2287 | } |
| 2288 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2289 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2290 | * efi_close_protocol() - close a protocol |
| 2291 | * @handle: handle on which the protocol shall be closed |
| 2292 | * @protocol: GUID of the protocol to close |
| 2293 | * @agent_handle: handle of the driver |
| 2294 | * @controller_handle: handle of the controller |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2295 | * |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2296 | * This is the function implementing the CloseProtocol service is for internal |
| 2297 | * usage in U-Boot. For API usage wrapper efi_close_protocol_ext() is provided. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2298 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2299 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2300 | * details. |
| 2301 | * |
| 2302 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2303 | */ |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2304 | efi_status_t efi_close_protocol(efi_handle_t handle, const efi_guid_t *protocol, |
| 2305 | efi_handle_t agent_handle, |
| 2306 | efi_handle_t controller_handle) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2307 | { |
Heinrich Schuchardt | 4fd1ee2 | 2018-01-11 08:15:59 +0100 | [diff] [blame] | 2308 | struct efi_handler *handler; |
| 2309 | struct efi_open_protocol_info_item *item; |
| 2310 | struct efi_open_protocol_info_item *pos; |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2311 | efi_status_t ret; |
Heinrich Schuchardt | 4fd1ee2 | 2018-01-11 08:15:59 +0100 | [diff] [blame] | 2312 | |
Heinrich Schuchardt | 5d8231b | 2019-05-05 10:37:51 +0200 | [diff] [blame] | 2313 | if (!efi_search_obj(agent_handle) || |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2314 | (controller_handle && !efi_search_obj(controller_handle))) |
| 2315 | return EFI_INVALID_PARAMETER; |
| 2316 | ret = efi_search_protocol(handle, protocol, &handler); |
| 2317 | if (ret != EFI_SUCCESS) |
| 2318 | return ret; |
Heinrich Schuchardt | 4fd1ee2 | 2018-01-11 08:15:59 +0100 | [diff] [blame] | 2319 | |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2320 | ret = EFI_NOT_FOUND; |
Heinrich Schuchardt | 4fd1ee2 | 2018-01-11 08:15:59 +0100 | [diff] [blame] | 2321 | list_for_each_entry_safe(item, pos, &handler->open_infos, link) { |
| 2322 | if (item->info.agent_handle == agent_handle && |
| 2323 | item->info.controller_handle == controller_handle) { |
| 2324 | efi_delete_open_info(item); |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2325 | ret = EFI_SUCCESS; |
Heinrich Schuchardt | 4fd1ee2 | 2018-01-11 08:15:59 +0100 | [diff] [blame] | 2326 | } |
| 2327 | } |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 2328 | |
| 2329 | return ret; |
| 2330 | } |
| 2331 | |
| 2332 | /** |
| 2333 | * efi_close_protocol_ext() - close a protocol |
| 2334 | * @handle: handle on which the protocol shall be closed |
| 2335 | * @protocol: GUID of the protocol to close |
| 2336 | * @agent_handle: handle of the driver |
| 2337 | * @controller_handle: handle of the controller |
| 2338 | * |
| 2339 | * This function implements the CloseProtocol service. |
| 2340 | * |
| 2341 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2342 | * details. |
| 2343 | * |
| 2344 | * Return: status code |
| 2345 | */ |
| 2346 | static efi_status_t EFIAPI |
| 2347 | efi_close_protocol_ext(efi_handle_t handle, const efi_guid_t *protocol, |
| 2348 | efi_handle_t agent_handle, |
| 2349 | efi_handle_t controller_handle) |
| 2350 | { |
| 2351 | efi_status_t ret; |
| 2352 | |
| 2353 | EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, agent_handle, |
| 2354 | controller_handle); |
| 2355 | |
| 2356 | ret = efi_close_protocol(handle, protocol, |
| 2357 | agent_handle, controller_handle); |
| 2358 | |
| 2359 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2360 | } |
| 2361 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2362 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2363 | * efi_open_protocol_information() - provide information about then open status |
| 2364 | * of a protocol on a handle |
| 2365 | * @handle: handle for which the information shall be retrieved |
| 2366 | * @protocol: GUID of the protocol |
| 2367 | * @entry_buffer: buffer to receive the open protocol information |
| 2368 | * @entry_count: number of entries available in the buffer |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2369 | * |
| 2370 | * This function implements the OpenProtocolInformation service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2371 | * |
| 2372 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2373 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2374 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2375 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2376 | */ |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 2377 | static efi_status_t EFIAPI efi_open_protocol_information( |
| 2378 | efi_handle_t handle, const efi_guid_t *protocol, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2379 | struct efi_open_protocol_info_entry **entry_buffer, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 2380 | efi_uintn_t *entry_count) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2381 | { |
Heinrich Schuchardt | f2ef22e | 2018-01-11 08:16:00 +0100 | [diff] [blame] | 2382 | unsigned long buffer_size; |
| 2383 | unsigned long count; |
| 2384 | struct efi_handler *handler; |
| 2385 | struct efi_open_protocol_info_item *item; |
| 2386 | efi_status_t r; |
| 2387 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 2388 | EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, entry_buffer, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2389 | entry_count); |
Heinrich Schuchardt | f2ef22e | 2018-01-11 08:16:00 +0100 | [diff] [blame] | 2390 | |
| 2391 | /* Check parameters */ |
| 2392 | if (!entry_buffer) { |
| 2393 | r = EFI_INVALID_PARAMETER; |
| 2394 | goto out; |
| 2395 | } |
| 2396 | r = efi_search_protocol(handle, protocol, &handler); |
| 2397 | if (r != EFI_SUCCESS) |
| 2398 | goto out; |
| 2399 | |
| 2400 | /* Count entries */ |
| 2401 | count = 0; |
| 2402 | list_for_each_entry(item, &handler->open_infos, link) { |
| 2403 | if (item->info.open_count) |
| 2404 | ++count; |
| 2405 | } |
| 2406 | *entry_count = count; |
| 2407 | *entry_buffer = NULL; |
| 2408 | if (!count) { |
| 2409 | r = EFI_SUCCESS; |
| 2410 | goto out; |
| 2411 | } |
| 2412 | |
| 2413 | /* Copy entries */ |
| 2414 | buffer_size = count * sizeof(struct efi_open_protocol_info_entry); |
Heinrich Schuchardt | abb4387 | 2018-10-03 20:02:29 +0200 | [diff] [blame] | 2415 | r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size, |
Heinrich Schuchardt | f2ef22e | 2018-01-11 08:16:00 +0100 | [diff] [blame] | 2416 | (void **)entry_buffer); |
| 2417 | if (r != EFI_SUCCESS) |
| 2418 | goto out; |
| 2419 | list_for_each_entry_reverse(item, &handler->open_infos, link) { |
| 2420 | if (item->info.open_count) |
| 2421 | (*entry_buffer)[--count] = item->info; |
| 2422 | } |
| 2423 | out: |
| 2424 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2427 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2428 | * efi_protocols_per_handle() - get protocols installed on a handle |
| 2429 | * @handle: handle for which the information is retrieved |
| 2430 | * @protocol_buffer: buffer with protocol GUIDs |
| 2431 | * @protocol_buffer_count: number of entries in the buffer |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2432 | * |
| 2433 | * This function implements the ProtocolsPerHandleService. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2434 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2435 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2436 | * details. |
| 2437 | * |
| 2438 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2439 | */ |
Heinrich Schuchardt | b7cb8b4 | 2018-01-11 08:16:09 +0100 | [diff] [blame] | 2440 | static efi_status_t EFIAPI efi_protocols_per_handle( |
| 2441 | efi_handle_t handle, efi_guid_t ***protocol_buffer, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 2442 | efi_uintn_t *protocol_buffer_count) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2443 | { |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2444 | unsigned long buffer_size; |
| 2445 | struct efi_object *efiobj; |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 2446 | struct list_head *protocol_handle; |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2447 | efi_status_t r; |
| 2448 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2449 | EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, |
| 2450 | protocol_buffer_count); |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2451 | |
| 2452 | if (!handle || !protocol_buffer || !protocol_buffer_count) |
| 2453 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 2454 | |
| 2455 | *protocol_buffer = NULL; |
Rob Clark | d51b8ca | 2017-07-20 07:59:39 -0400 | [diff] [blame] | 2456 | *protocol_buffer_count = 0; |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2457 | |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 2458 | efiobj = efi_search_obj(handle); |
| 2459 | if (!efiobj) |
| 2460 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2461 | |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 2462 | /* Count protocols */ |
| 2463 | list_for_each(protocol_handle, &efiobj->protocols) { |
| 2464 | ++*protocol_buffer_count; |
| 2465 | } |
| 2466 | |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 2467 | /* Copy GUIDs */ |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 2468 | if (*protocol_buffer_count) { |
| 2469 | size_t j = 0; |
| 2470 | |
| 2471 | buffer_size = sizeof(efi_guid_t *) * *protocol_buffer_count; |
Heinrich Schuchardt | abb4387 | 2018-10-03 20:02:29 +0200 | [diff] [blame] | 2472 | r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size, |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 2473 | (void **)protocol_buffer); |
| 2474 | if (r != EFI_SUCCESS) |
| 2475 | return EFI_EXIT(r); |
| 2476 | list_for_each(protocol_handle, &efiobj->protocols) { |
| 2477 | struct efi_handler *protocol; |
| 2478 | |
| 2479 | protocol = list_entry(protocol_handle, |
| 2480 | struct efi_handler, link); |
Heinrich Schuchardt | 2a22db9 | 2022-03-09 19:56:23 +0100 | [diff] [blame] | 2481 | (*protocol_buffer)[j] = (void *)&protocol->guid; |
Heinrich Schuchardt | 99ce206 | 2017-11-26 14:05:17 +0100 | [diff] [blame] | 2482 | ++j; |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2483 | } |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2487 | } |
| 2488 | |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 2489 | efi_status_t efi_locate_handle_buffer_int(enum efi_locate_search_type search_type, |
| 2490 | const efi_guid_t *protocol, void *search_key, |
| 2491 | efi_uintn_t *no_handles, efi_handle_t **buffer) |
| 2492 | { |
| 2493 | efi_status_t r; |
| 2494 | efi_uintn_t buffer_size = 0; |
| 2495 | |
| 2496 | if (!no_handles || !buffer) { |
| 2497 | r = EFI_INVALID_PARAMETER; |
| 2498 | goto out; |
| 2499 | } |
| 2500 | *no_handles = 0; |
| 2501 | *buffer = NULL; |
| 2502 | r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, |
| 2503 | *buffer); |
| 2504 | if (r != EFI_BUFFER_TOO_SMALL) |
| 2505 | goto out; |
| 2506 | r = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, buffer_size, |
| 2507 | (void **)buffer); |
| 2508 | if (r != EFI_SUCCESS) |
| 2509 | goto out; |
| 2510 | r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, |
| 2511 | *buffer); |
| 2512 | if (r == EFI_SUCCESS) |
| 2513 | *no_handles = buffer_size / sizeof(efi_handle_t); |
| 2514 | out: |
| 2515 | return r; |
| 2516 | } |
| 2517 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2518 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2519 | * efi_locate_handle_buffer() - locate handles implementing a protocol |
| 2520 | * @search_type: selection criterion |
| 2521 | * @protocol: GUID of the protocol |
| 2522 | * @search_key: registration key |
| 2523 | * @no_handles: number of returned handles |
| 2524 | * @buffer: buffer with the returned handles |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2525 | * |
| 2526 | * This function implements the LocateHandleBuffer service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2527 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2528 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2529 | * details. |
| 2530 | * |
| 2531 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2532 | */ |
AKASHI Takahiro | d99b1b3 | 2020-03-17 11:12:36 +0900 | [diff] [blame] | 2533 | efi_status_t EFIAPI efi_locate_handle_buffer( |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2534 | enum efi_locate_search_type search_type, |
Heinrich Schuchardt | e547c66 | 2017-10-05 16:35:53 +0200 | [diff] [blame] | 2535 | const efi_guid_t *protocol, void *search_key, |
Heinrich Schuchardt | 798a441 | 2017-11-06 21:17:48 +0100 | [diff] [blame] | 2536 | efi_uintn_t *no_handles, efi_handle_t **buffer) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2537 | { |
xypron.glpk@gmx.de | 550a68a | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 2538 | efi_status_t r; |
xypron.glpk@gmx.de | 550a68a | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 2539 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 2540 | EFI_ENTRY("%d, %pUs, %p, %p, %p", search_type, protocol, search_key, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2541 | no_handles, buffer); |
xypron.glpk@gmx.de | 550a68a | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 2542 | |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 2543 | r = efi_locate_handle_buffer_int(search_type, protocol, search_key, |
| 2544 | no_handles, buffer); |
| 2545 | |
xypron.glpk@gmx.de | 550a68a | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 2546 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2547 | } |
| 2548 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2549 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2550 | * efi_locate_protocol() - find an interface implementing a protocol |
| 2551 | * @protocol: GUID of the protocol |
| 2552 | * @registration: registration key passed to the notification function |
| 2553 | * @protocol_interface: interface implementing the protocol |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2554 | * |
| 2555 | * This function implements the LocateProtocol service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2556 | * |
| 2557 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2558 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2559 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2560 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2561 | */ |
Heinrich Schuchardt | e547c66 | 2017-10-05 16:35:53 +0200 | [diff] [blame] | 2562 | static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2563 | void *registration, |
| 2564 | void **protocol_interface) |
| 2565 | { |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2566 | struct efi_handler *handler; |
Heinrich Schuchardt | 57505e9 | 2017-10-26 19:25:57 +0200 | [diff] [blame] | 2567 | efi_status_t ret; |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2568 | struct efi_object *efiobj; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2569 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 2570 | EFI_ENTRY("%pUs, %p, %p", protocol, registration, protocol_interface); |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 2571 | |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2572 | /* |
| 2573 | * The UEFI spec explicitly requires a protocol even if a registration |
| 2574 | * key is provided. This differs from the logic in LocateHandle(). |
| 2575 | */ |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 2576 | if (!protocol || !protocol_interface) |
| 2577 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 2578 | |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2579 | if (registration) { |
| 2580 | struct efi_register_notify_event *event; |
| 2581 | struct efi_protocol_notification *handle; |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 2582 | |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2583 | event = efi_check_register_notify_event(registration); |
| 2584 | if (!event) |
| 2585 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 2586 | /* |
| 2587 | * The UEFI spec requires to return EFI_NOT_FOUND if no |
| 2588 | * protocol instance matches protocol and registration. |
| 2589 | * So let's do the same for a mismatch between protocol and |
| 2590 | * registration. |
| 2591 | */ |
| 2592 | if (guidcmp(&event->protocol, protocol)) |
| 2593 | goto not_found; |
| 2594 | if (list_empty(&event->handles)) |
| 2595 | goto not_found; |
| 2596 | handle = list_first_entry(&event->handles, |
| 2597 | struct efi_protocol_notification, |
| 2598 | link); |
| 2599 | efiobj = handle->handle; |
| 2600 | list_del(&handle->link); |
| 2601 | free(handle); |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 2602 | ret = efi_search_protocol(efiobj, protocol, &handler); |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2603 | if (ret == EFI_SUCCESS) |
| 2604 | goto found; |
| 2605 | } else { |
| 2606 | list_for_each_entry(efiobj, &efi_obj_list, link) { |
| 2607 | ret = efi_search_protocol(efiobj, protocol, &handler); |
| 2608 | if (ret == EFI_SUCCESS) |
| 2609 | goto found; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2610 | } |
| 2611 | } |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2612 | not_found: |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 2613 | *protocol_interface = NULL; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2614 | return EFI_EXIT(EFI_NOT_FOUND); |
Heinrich Schuchardt | 2600eff | 2019-05-29 18:06:46 +0200 | [diff] [blame] | 2615 | found: |
| 2616 | *protocol_interface = handler->protocol_interface; |
| 2617 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2618 | } |
| 2619 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2620 | /** |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2621 | * efi_install_multiple_protocol_interfaces_int() - Install multiple protocol |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2622 | * interfaces |
| 2623 | * @handle: handle on which the protocol interfaces shall be installed |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2624 | * @argptr: va_list of args |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2625 | * |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2626 | * Core functionality of efi_install_multiple_protocol_interfaces |
| 2627 | * Must not be called directly |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2628 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2629 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2630 | */ |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2631 | static efi_status_t EFIAPI |
| 2632 | efi_install_multiple_protocol_interfaces_int(efi_handle_t *handle, |
| 2633 | efi_va_list argptr) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2634 | { |
Heinrich Schuchardt | e547c66 | 2017-10-05 16:35:53 +0200 | [diff] [blame] | 2635 | const efi_guid_t *protocol; |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2636 | void *protocol_interface; |
Heinrich Schuchardt | 61ba10d | 2019-05-16 21:54:04 +0200 | [diff] [blame] | 2637 | efi_handle_t old_handle; |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2638 | efi_status_t ret = EFI_SUCCESS; |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2639 | int i = 0; |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2640 | efi_va_list argptr_copy; |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2641 | |
| 2642 | if (!handle) |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2643 | return EFI_INVALID_PARAMETER; |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2644 | |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2645 | efi_va_copy(argptr_copy, argptr); |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2646 | for (;;) { |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 2647 | protocol = efi_va_arg(argptr, efi_guid_t*); |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2648 | if (!protocol) |
| 2649 | break; |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 2650 | protocol_interface = efi_va_arg(argptr, void*); |
Heinrich Schuchardt | 61ba10d | 2019-05-16 21:54:04 +0200 | [diff] [blame] | 2651 | /* Check that a device path has not been installed before */ |
| 2652 | if (!guidcmp(protocol, &efi_guid_device_path)) { |
| 2653 | struct efi_device_path *dp = protocol_interface; |
| 2654 | |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2655 | ret = EFI_CALL(efi_locate_device_path(protocol, &dp, |
| 2656 | &old_handle)); |
| 2657 | if (ret == EFI_SUCCESS && |
Heinrich Schuchardt | 2934497 | 2019-05-20 19:55:18 +0000 | [diff] [blame] | 2658 | dp->type == DEVICE_PATH_TYPE_END) { |
| 2659 | EFI_PRINT("Path %pD already installed\n", |
| 2660 | protocol_interface); |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2661 | ret = EFI_ALREADY_STARTED; |
Heinrich Schuchardt | 61ba10d | 2019-05-16 21:54:04 +0200 | [diff] [blame] | 2662 | break; |
| 2663 | } |
| 2664 | } |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2665 | ret = EFI_CALL(efi_install_protocol_interface(handle, protocol, |
| 2666 | EFI_NATIVE_INTERFACE, |
| 2667 | protocol_interface)); |
| 2668 | if (ret != EFI_SUCCESS) |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2669 | break; |
| 2670 | i++; |
| 2671 | } |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2672 | if (ret == EFI_SUCCESS) |
| 2673 | goto out; |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2674 | |
Heinrich Schuchardt | ec47f3e | 2017-10-26 19:25:42 +0200 | [diff] [blame] | 2675 | /* If an error occurred undo all changes. */ |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2676 | for (; i; --i) { |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2677 | protocol = efi_va_arg(argptr_copy, efi_guid_t*); |
| 2678 | protocol_interface = efi_va_arg(argptr_copy, void*); |
Heinrich Schuchardt | 4f94ec5 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 2679 | EFI_CALL(efi_uninstall_protocol_interface(*handle, protocol, |
Heinrich Schuchardt | 7cdc17f | 2017-11-06 21:17:45 +0100 | [diff] [blame] | 2680 | protocol_interface)); |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2681 | } |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 2682 | |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2683 | out: |
| 2684 | efi_va_end(argptr_copy); |
| 2685 | return ret; |
| 2686 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2687 | } |
| 2688 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2689 | /** |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2690 | * efi_install_multiple_protocol_interfaces() - Install multiple protocol |
| 2691 | * interfaces |
| 2692 | * @handle: handle on which the protocol interfaces shall be installed |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2693 | * @...: NULL terminated argument list with pairs of protocol GUIDS and |
| 2694 | * interfaces |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2695 | * |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2696 | * |
| 2697 | * This is the function for internal usage in U-Boot. For the API function |
| 2698 | * implementing the InstallMultipleProtocol service see |
| 2699 | * efi_install_multiple_protocol_interfaces_ext() |
| 2700 | * |
| 2701 | * Return: status code |
| 2702 | */ |
| 2703 | efi_status_t EFIAPI |
| 2704 | efi_install_multiple_protocol_interfaces(efi_handle_t *handle, ...) |
| 2705 | { |
| 2706 | efi_status_t ret; |
| 2707 | efi_va_list argptr; |
| 2708 | |
| 2709 | efi_va_start(argptr, handle); |
| 2710 | ret = efi_install_multiple_protocol_interfaces_int(handle, argptr); |
| 2711 | efi_va_end(argptr); |
| 2712 | return ret; |
| 2713 | } |
| 2714 | |
| 2715 | /** |
| 2716 | * efi_install_multiple_protocol_interfaces_ext() - Install multiple protocol |
| 2717 | * interfaces |
| 2718 | * @handle: handle on which the protocol interfaces shall be installed |
| 2719 | * @...: NULL terminated argument list with pairs of protocol GUIDS and |
| 2720 | * interfaces |
| 2721 | * |
| 2722 | * This function implements the MultipleProtocolInterfaces service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2723 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2724 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2725 | * details. |
| 2726 | * |
| 2727 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2728 | */ |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2729 | static efi_status_t EFIAPI |
| 2730 | efi_install_multiple_protocol_interfaces_ext(efi_handle_t *handle, ...) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2731 | { |
| 2732 | EFI_ENTRY("%p", handle); |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2733 | efi_status_t ret; |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 2734 | efi_va_list argptr; |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2735 | |
| 2736 | efi_va_start(argptr, handle); |
| 2737 | ret = efi_install_multiple_protocol_interfaces_int(handle, argptr); |
| 2738 | efi_va_end(argptr); |
| 2739 | return EFI_EXIT(ret); |
| 2740 | } |
| 2741 | |
| 2742 | /** |
| 2743 | * efi_uninstall_multiple_protocol_interfaces_int() - wrapper for uninstall |
| 2744 | * multiple protocol |
| 2745 | * interfaces |
| 2746 | * @handle: handle from which the protocol interfaces shall be removed |
| 2747 | * @argptr: va_list of args |
| 2748 | * |
| 2749 | * Core functionality of efi_uninstall_multiple_protocol_interfaces |
| 2750 | * Must not be called directly |
| 2751 | * |
| 2752 | * Return: status code |
| 2753 | */ |
| 2754 | static efi_status_t EFIAPI |
| 2755 | efi_uninstall_multiple_protocol_interfaces_int(efi_handle_t handle, |
| 2756 | efi_va_list argptr) |
| 2757 | { |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2758 | const efi_guid_t *protocol; |
| 2759 | void *protocol_interface; |
Ilias Apalodimas | 3b820bc | 2022-11-10 10:21:24 +0200 | [diff] [blame] | 2760 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2761 | size_t i = 0; |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2762 | efi_va_list argptr_copy; |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2763 | |
| 2764 | if (!handle) |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2765 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2766 | |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2767 | efi_va_copy(argptr_copy, argptr); |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2768 | for (;;) { |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 2769 | protocol = efi_va_arg(argptr, efi_guid_t*); |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2770 | if (!protocol) |
| 2771 | break; |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 2772 | protocol_interface = efi_va_arg(argptr, void*); |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2773 | ret = efi_uninstall_protocol(handle, protocol, |
| 2774 | protocol_interface); |
| 2775 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2776 | break; |
| 2777 | i++; |
| 2778 | } |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2779 | if (ret == EFI_SUCCESS) { |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 2780 | /* If the last protocol has been removed, delete the handle. */ |
| 2781 | if (list_empty(&handle->protocols)) { |
| 2782 | list_del(&handle->link); |
| 2783 | free(handle); |
| 2784 | } |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2785 | goto out; |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 2786 | } |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2787 | |
| 2788 | /* If an error occurred undo all changes. */ |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2789 | for (; i; --i) { |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2790 | protocol = efi_va_arg(argptr_copy, efi_guid_t*); |
| 2791 | protocol_interface = efi_va_arg(argptr_copy, void*); |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2792 | EFI_CALL(efi_install_protocol_interface(&handle, protocol, |
| 2793 | EFI_NATIVE_INTERFACE, |
| 2794 | protocol_interface)); |
| 2795 | } |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2796 | /* |
| 2797 | * If any errors are generated while the protocol interfaces are being |
| 2798 | * uninstalled, then the protocols uninstalled prior to the error will |
| 2799 | * be reinstalled using InstallProtocolInterface() and the status code |
| 2800 | * EFI_INVALID_PARAMETER is returned. |
| 2801 | */ |
| 2802 | ret = EFI_INVALID_PARAMETER; |
| 2803 | |
| 2804 | out: |
| 2805 | efi_va_end(argptr_copy); |
| 2806 | return ret; |
| 2807 | } |
| 2808 | |
| 2809 | /** |
| 2810 | * efi_uninstall_multiple_protocol_interfaces() - uninstall multiple protocol |
| 2811 | * interfaces |
| 2812 | * @handle: handle from which the protocol interfaces shall be removed |
| 2813 | * @...: NULL terminated argument list with pairs of protocol GUIDS and |
| 2814 | * interfaces |
| 2815 | * |
| 2816 | * This function implements the UninstallMultipleProtocolInterfaces service. |
| 2817 | * |
| 2818 | * This is the function for internal usage in U-Boot. For the API function |
| 2819 | * implementing the UninstallMultipleProtocolInterfaces service see |
| 2820 | * efi_uninstall_multiple_protocol_interfaces_ext() |
| 2821 | * |
| 2822 | * Return: status code |
| 2823 | */ |
| 2824 | efi_status_t EFIAPI |
| 2825 | efi_uninstall_multiple_protocol_interfaces(efi_handle_t handle, ...) |
| 2826 | { |
| 2827 | efi_status_t ret; |
| 2828 | efi_va_list argptr; |
| 2829 | |
| 2830 | efi_va_start(argptr, handle); |
| 2831 | ret = efi_uninstall_multiple_protocol_interfaces_int(handle, argptr); |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 2832 | efi_va_end(argptr); |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2833 | return ret; |
| 2834 | } |
| 2835 | |
| 2836 | /** |
| 2837 | * efi_uninstall_multiple_protocol_interfaces_ext() - uninstall multiple protocol |
| 2838 | * interfaces |
| 2839 | * @handle: handle from which the protocol interfaces shall be removed |
| 2840 | * @...: NULL terminated argument list with pairs of protocol GUIDS and |
| 2841 | * interfaces |
| 2842 | * |
| 2843 | * This function implements the UninstallMultipleProtocolInterfaces service. |
| 2844 | * |
| 2845 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2846 | * details. |
| 2847 | * |
| 2848 | * Return: status code |
| 2849 | */ |
| 2850 | static efi_status_t EFIAPI |
| 2851 | efi_uninstall_multiple_protocol_interfaces_ext(efi_handle_t handle, ...) |
| 2852 | { |
| 2853 | EFI_ENTRY("%p", handle); |
| 2854 | efi_status_t ret; |
| 2855 | efi_va_list argptr; |
Heinrich Schuchardt | a616dcf | 2017-10-26 19:25:44 +0200 | [diff] [blame] | 2856 | |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 2857 | efi_va_start(argptr, handle); |
| 2858 | ret = efi_uninstall_multiple_protocol_interfaces_int(handle, argptr); |
| 2859 | efi_va_end(argptr); |
| 2860 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2861 | } |
| 2862 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2863 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2864 | * efi_calculate_crc32() - calculate cyclic redundancy code |
| 2865 | * @data: buffer with data |
| 2866 | * @data_size: size of buffer in bytes |
| 2867 | * @crc32_p: cyclic redundancy code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2868 | * |
| 2869 | * This function implements the CalculateCrc32 service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2870 | * |
| 2871 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2872 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2873 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2874 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2875 | */ |
Heinrich Schuchardt | f272558 | 2018-07-07 15:36:04 +0200 | [diff] [blame] | 2876 | static efi_status_t EFIAPI efi_calculate_crc32(const void *data, |
| 2877 | efi_uintn_t data_size, |
| 2878 | u32 *crc32_p) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2879 | { |
Heinrich Schuchardt | 3f0282c | 2019-05-16 23:31:29 +0200 | [diff] [blame] | 2880 | efi_status_t ret = EFI_SUCCESS; |
| 2881 | |
Heinrich Schuchardt | f272558 | 2018-07-07 15:36:04 +0200 | [diff] [blame] | 2882 | EFI_ENTRY("%p, %zu", data, data_size); |
Heinrich Schuchardt | 3f0282c | 2019-05-16 23:31:29 +0200 | [diff] [blame] | 2883 | if (!data || !data_size || !crc32_p) { |
| 2884 | ret = EFI_INVALID_PARAMETER; |
| 2885 | goto out; |
| 2886 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2887 | *crc32_p = crc32(0, data, data_size); |
Heinrich Schuchardt | 3f0282c | 2019-05-16 23:31:29 +0200 | [diff] [blame] | 2888 | out: |
| 2889 | return EFI_EXIT(ret); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2890 | } |
| 2891 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2892 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2893 | * efi_copy_mem() - copy memory |
| 2894 | * @destination: destination of the copy operation |
| 2895 | * @source: source of the copy operation |
| 2896 | * @length: number of bytes to copy |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2897 | * |
| 2898 | * This function implements the CopyMem service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2899 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2900 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2901 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2902 | */ |
Heinrich Schuchardt | d0a349e | 2017-10-05 16:35:52 +0200 | [diff] [blame] | 2903 | static void EFIAPI efi_copy_mem(void *destination, const void *source, |
| 2904 | size_t length) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2905 | { |
Heinrich Schuchardt | d0a349e | 2017-10-05 16:35:52 +0200 | [diff] [blame] | 2906 | EFI_ENTRY("%p, %p, %ld", destination, source, (unsigned long)length); |
Heinrich Schuchardt | efba6ba | 2019-01-09 21:41:13 +0100 | [diff] [blame] | 2907 | memmove(destination, source, length); |
Heinrich Schuchardt | a5270e0 | 2017-10-05 16:35:51 +0200 | [diff] [blame] | 2908 | EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2909 | } |
| 2910 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2911 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2912 | * efi_set_mem() - Fill memory with a byte value. |
| 2913 | * @buffer: buffer to fill |
| 2914 | * @size: size of buffer in bytes |
| 2915 | * @value: byte to copy to the buffer |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2916 | * |
| 2917 | * This function implements the SetMem service. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2918 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2919 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 2920 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2921 | */ |
Heinrich Schuchardt | d0a349e | 2017-10-05 16:35:52 +0200 | [diff] [blame] | 2922 | static void EFIAPI efi_set_mem(void *buffer, size_t size, uint8_t value) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2923 | { |
Heinrich Schuchardt | d0a349e | 2017-10-05 16:35:52 +0200 | [diff] [blame] | 2924 | EFI_ENTRY("%p, %ld, 0x%x", buffer, (unsigned long)size, value); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2925 | memset(buffer, value, size); |
Heinrich Schuchardt | a5270e0 | 2017-10-05 16:35:51 +0200 | [diff] [blame] | 2926 | EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 2929 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2930 | * efi_protocol_open() - open protocol interface on a handle |
| 2931 | * @handler: handler of a protocol |
| 2932 | * @protocol_interface: interface implementing the protocol |
| 2933 | * @agent_handle: handle of the driver |
| 2934 | * @controller_handle: handle of the controller |
| 2935 | * @attributes: attributes indicating how to open the protocol |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 2936 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 2937 | * Return: status code |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2938 | */ |
Heinrich Schuchardt | 9c89d14 | 2020-01-10 12:33:59 +0100 | [diff] [blame] | 2939 | efi_status_t efi_protocol_open( |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2940 | struct efi_handler *handler, |
| 2941 | void **protocol_interface, void *agent_handle, |
| 2942 | void *controller_handle, uint32_t attributes) |
| 2943 | { |
| 2944 | struct efi_open_protocol_info_item *item; |
| 2945 | struct efi_open_protocol_info_entry *match = NULL; |
| 2946 | bool opened_by_driver = false; |
| 2947 | bool opened_exclusive = false; |
| 2948 | |
| 2949 | /* If there is no agent, only return the interface */ |
| 2950 | if (!agent_handle) |
| 2951 | goto out; |
| 2952 | |
| 2953 | /* For TEST_PROTOCOL ignore interface attribute */ |
| 2954 | if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) |
| 2955 | *protocol_interface = NULL; |
| 2956 | |
| 2957 | /* |
| 2958 | * Check if the protocol is already opened by a driver with the same |
| 2959 | * attributes or opened exclusively |
| 2960 | */ |
| 2961 | list_for_each_entry(item, &handler->open_infos, link) { |
| 2962 | if (item->info.agent_handle == agent_handle) { |
| 2963 | if ((attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) && |
| 2964 | (item->info.attributes == attributes)) |
| 2965 | return EFI_ALREADY_STARTED; |
Heinrich Schuchardt | da433d5 | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 2966 | } else { |
| 2967 | if (item->info.attributes & |
| 2968 | EFI_OPEN_PROTOCOL_BY_DRIVER) |
| 2969 | opened_by_driver = true; |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2970 | } |
| 2971 | if (item->info.attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) |
| 2972 | opened_exclusive = true; |
| 2973 | } |
| 2974 | |
| 2975 | /* Only one controller can open the protocol exclusively */ |
Heinrich Schuchardt | da433d5 | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 2976 | if (attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) { |
| 2977 | if (opened_exclusive) |
| 2978 | return EFI_ACCESS_DENIED; |
| 2979 | } else if (attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) { |
| 2980 | if (opened_exclusive || opened_by_driver) |
| 2981 | return EFI_ACCESS_DENIED; |
| 2982 | } |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2983 | |
| 2984 | /* Prepare exclusive opening */ |
| 2985 | if (attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) { |
| 2986 | /* Try to disconnect controllers */ |
Heinrich Schuchardt | fa8dddf | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 2987 | disconnect_next: |
| 2988 | opened_by_driver = false; |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2989 | list_for_each_entry(item, &handler->open_infos, link) { |
Heinrich Schuchardt | fa8dddf | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 2990 | efi_status_t ret; |
| 2991 | |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2992 | if (item->info.attributes == |
Heinrich Schuchardt | fa8dddf | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 2993 | EFI_OPEN_PROTOCOL_BY_DRIVER) { |
| 2994 | ret = EFI_CALL(efi_disconnect_controller( |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 2995 | item->info.controller_handle, |
| 2996 | item->info.agent_handle, |
| 2997 | NULL)); |
Heinrich Schuchardt | fa8dddf | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 2998 | if (ret == EFI_SUCCESS) |
| 2999 | /* |
| 3000 | * Child controllers may have been |
| 3001 | * removed from the open_infos list. So |
| 3002 | * let's restart the loop. |
| 3003 | */ |
| 3004 | goto disconnect_next; |
| 3005 | else |
| 3006 | opened_by_driver = true; |
| 3007 | } |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3008 | } |
Heinrich Schuchardt | fa8dddf | 2019-05-30 14:16:31 +0200 | [diff] [blame] | 3009 | /* Only one driver can be connected */ |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3010 | if (opened_by_driver) |
| 3011 | return EFI_ACCESS_DENIED; |
| 3012 | } |
| 3013 | |
| 3014 | /* Find existing entry */ |
| 3015 | list_for_each_entry(item, &handler->open_infos, link) { |
| 3016 | if (item->info.agent_handle == agent_handle && |
Heinrich Schuchardt | 7d69fc3 | 2019-06-01 20:15:10 +0200 | [diff] [blame] | 3017 | item->info.controller_handle == controller_handle && |
| 3018 | item->info.attributes == attributes) |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3019 | match = &item->info; |
| 3020 | } |
| 3021 | /* None found, create one */ |
| 3022 | if (!match) { |
| 3023 | match = efi_create_open_info(handler); |
| 3024 | if (!match) |
| 3025 | return EFI_OUT_OF_RESOURCES; |
| 3026 | } |
| 3027 | |
| 3028 | match->agent_handle = agent_handle; |
| 3029 | match->controller_handle = controller_handle; |
| 3030 | match->attributes = attributes; |
| 3031 | match->open_count++; |
| 3032 | |
| 3033 | out: |
| 3034 | /* For TEST_PROTOCOL ignore interface attribute. */ |
| 3035 | if (attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) |
| 3036 | *protocol_interface = handler->protocol_interface; |
| 3037 | |
| 3038 | return EFI_SUCCESS; |
| 3039 | } |
| 3040 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3041 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3042 | * efi_open_protocol() - open protocol interface on a handle |
| 3043 | * @handle: handle on which the protocol shall be opened |
| 3044 | * @protocol: GUID of the protocol |
| 3045 | * @protocol_interface: interface implementing the protocol |
| 3046 | * @agent_handle: handle of the driver |
| 3047 | * @controller_handle: handle of the controller |
| 3048 | * @attributes: attributes indicating how to open the protocol |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3049 | * |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 3050 | * This function implements the OpenProtocol interface. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 3051 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3052 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3053 | * details. |
| 3054 | * |
| 3055 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 3056 | */ |
Heinrich Schuchardt | 4f94ec5 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 3057 | static efi_status_t EFIAPI efi_open_protocol |
| 3058 | (efi_handle_t handle, const efi_guid_t *protocol, |
| 3059 | void **protocol_interface, efi_handle_t agent_handle, |
| 3060 | efi_handle_t controller_handle, uint32_t attributes) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3061 | { |
Heinrich Schuchardt | e5e78a3 | 2017-11-26 14:05:15 +0100 | [diff] [blame] | 3062 | struct efi_handler *handler; |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3063 | efi_status_t r = EFI_INVALID_PARAMETER; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3064 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 3065 | EFI_ENTRY("%p, %pUs, %p, %p, %p, 0x%x", handle, protocol, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3066 | protocol_interface, agent_handle, controller_handle, |
| 3067 | attributes); |
xypron.glpk@gmx.de | c35c924 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 3068 | |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3069 | if (!handle || !protocol || |
| 3070 | (!protocol_interface && attributes != |
| 3071 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) { |
xypron.glpk@gmx.de | c35c924 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 3072 | goto out; |
| 3073 | } |
| 3074 | |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3075 | switch (attributes) { |
| 3076 | case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: |
| 3077 | case EFI_OPEN_PROTOCOL_GET_PROTOCOL: |
| 3078 | case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: |
| 3079 | break; |
| 3080 | case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: |
| 3081 | if (controller_handle == handle) |
| 3082 | goto out; |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3083 | /* fall-through */ |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3084 | case EFI_OPEN_PROTOCOL_BY_DRIVER: |
| 3085 | case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3086 | /* Check that the controller handle is valid */ |
| 3087 | if (!efi_search_obj(controller_handle)) |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3088 | goto out; |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3089 | /* fall-through */ |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3090 | case EFI_OPEN_PROTOCOL_EXCLUSIVE: |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3091 | /* Check that the agent handle is valid */ |
| 3092 | if (!efi_search_obj(agent_handle)) |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 3093 | goto out; |
| 3094 | break; |
| 3095 | default: |
| 3096 | goto out; |
| 3097 | } |
| 3098 | |
Heinrich Schuchardt | e5e78a3 | 2017-11-26 14:05:15 +0100 | [diff] [blame] | 3099 | r = efi_search_protocol(handle, protocol, &handler); |
Heinrich Schuchardt | b673e4b | 2019-05-05 11:24:53 +0200 | [diff] [blame] | 3100 | switch (r) { |
| 3101 | case EFI_SUCCESS: |
| 3102 | break; |
| 3103 | case EFI_NOT_FOUND: |
| 3104 | r = EFI_UNSUPPORTED; |
| 3105 | goto out; |
| 3106 | default: |
Heinrich Schuchardt | e5e78a3 | 2017-11-26 14:05:15 +0100 | [diff] [blame] | 3107 | goto out; |
Heinrich Schuchardt | b673e4b | 2019-05-05 11:24:53 +0200 | [diff] [blame] | 3108 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3109 | |
Heinrich Schuchardt | 8cb38c0 | 2018-01-11 08:15:58 +0100 | [diff] [blame] | 3110 | r = efi_protocol_open(handler, protocol_interface, agent_handle, |
| 3111 | controller_handle, attributes); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3112 | out: |
| 3113 | return EFI_EXIT(r); |
| 3114 | } |
| 3115 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3116 | /** |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3117 | * efi_start_image() - call the entry point of an image |
| 3118 | * @image_handle: handle of the image |
| 3119 | * @exit_data_size: size of the buffer |
| 3120 | * @exit_data: buffer to receive the exit data of the called image |
| 3121 | * |
| 3122 | * This function implements the StartImage service. |
| 3123 | * |
| 3124 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3125 | * details. |
| 3126 | * |
| 3127 | * Return: status code |
| 3128 | */ |
| 3129 | efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, |
| 3130 | efi_uintn_t *exit_data_size, |
| 3131 | u16 **exit_data) |
| 3132 | { |
| 3133 | struct efi_loaded_image_obj *image_obj = |
| 3134 | (struct efi_loaded_image_obj *)image_handle; |
| 3135 | efi_status_t ret; |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3136 | void *info; |
| 3137 | efi_handle_t parent_image = current_image; |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3138 | efi_status_t exit_status; |
| 3139 | struct jmp_buf_data exit_jmp; |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3140 | |
| 3141 | EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); |
| 3142 | |
AKASHI Takahiro | 0e104e3 | 2020-04-14 11:51:44 +0900 | [diff] [blame] | 3143 | if (!efi_search_obj(image_handle)) |
| 3144 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 3145 | |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3146 | /* Check parameters */ |
Heinrich Schuchardt | ff94bca | 2019-06-11 19:35:20 +0200 | [diff] [blame] | 3147 | if (image_obj->header.type != EFI_OBJECT_TYPE_LOADED_IMAGE) |
| 3148 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 3149 | |
AKASHI Takahiro | 0e104e3 | 2020-04-14 11:51:44 +0900 | [diff] [blame] | 3150 | if (image_obj->auth_status != EFI_IMAGE_AUTH_PASSED) |
| 3151 | return EFI_EXIT(EFI_SECURITY_VIOLATION); |
| 3152 | |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3153 | ret = EFI_CALL(efi_open_protocol(image_handle, &efi_guid_loaded_image, |
| 3154 | &info, NULL, NULL, |
| 3155 | EFI_OPEN_PROTOCOL_GET_PROTOCOL)); |
| 3156 | if (ret != EFI_SUCCESS) |
| 3157 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 3158 | |
Heinrich Schuchardt | 3d44512 | 2019-04-30 17:57:30 +0200 | [diff] [blame] | 3159 | image_obj->exit_data_size = exit_data_size; |
| 3160 | image_obj->exit_data = exit_data; |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3161 | image_obj->exit_status = &exit_status; |
| 3162 | image_obj->exit_jmp = &exit_jmp; |
Heinrich Schuchardt | 3d44512 | 2019-04-30 17:57:30 +0200 | [diff] [blame] | 3163 | |
Masahisa Kojima | 8173cd4 | 2021-08-13 16:12:40 +0900 | [diff] [blame] | 3164 | if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { |
| 3165 | if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) { |
Masahisa Kojima | 6460c3e | 2021-10-26 17:27:25 +0900 | [diff] [blame] | 3166 | ret = efi_tcg2_measure_efi_app_invocation(image_obj); |
Masahisa Kojima | 38155ea | 2021-12-07 14:15:33 +0900 | [diff] [blame] | 3167 | if (ret == EFI_SECURITY_VIOLATION) { |
| 3168 | /* |
| 3169 | * TCG2 Protocol is installed but no TPM device found, |
| 3170 | * this is not expected. |
| 3171 | */ |
| 3172 | return EFI_EXIT(EFI_SECURITY_VIOLATION); |
Masahisa Kojima | 8173cd4 | 2021-08-13 16:12:40 +0900 | [diff] [blame] | 3173 | } |
| 3174 | } |
| 3175 | } |
| 3176 | |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3177 | /* call the image! */ |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3178 | if (setjmp(&exit_jmp)) { |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3179 | /* |
| 3180 | * We called the entry point of the child image with EFI_CALL |
| 3181 | * in the lines below. The child image called the Exit() boot |
| 3182 | * service efi_exit() which executed the long jump that brought |
| 3183 | * us to the current line. This implies that the second half |
| 3184 | * of the EFI_CALL macro has not been executed. |
| 3185 | */ |
Heinrich Schuchardt | f277d94 | 2020-09-10 12:22:54 +0200 | [diff] [blame] | 3186 | #if defined(CONFIG_ARM) || defined(CONFIG_RISCV) |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3187 | /* |
| 3188 | * efi_exit() called efi_restore_gd(). We have to undo this |
| 3189 | * otherwise __efi_entry_check() will put the wrong value into |
| 3190 | * app_gd. |
| 3191 | */ |
Heinrich Schuchardt | 1a3732c | 2020-05-27 01:58:30 +0200 | [diff] [blame] | 3192 | set_gd(app_gd); |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3193 | #endif |
| 3194 | /* |
| 3195 | * To get ready to call EFI_EXIT below we have to execute the |
| 3196 | * missed out steps of EFI_CALL. |
| 3197 | */ |
| 3198 | assert(__efi_entry_check()); |
Heinrich Schuchardt | 952e206 | 2019-05-05 11:56:23 +0200 | [diff] [blame] | 3199 | EFI_PRINT("%lu returned by started image\n", |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3200 | (unsigned long)((uintptr_t)exit_status & |
Heinrich Schuchardt | 952e206 | 2019-05-05 11:56:23 +0200 | [diff] [blame] | 3201 | ~EFI_ERROR_MASK)); |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3202 | current_image = parent_image; |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3203 | return EFI_EXIT(exit_status); |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3204 | } |
| 3205 | |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3206 | current_image = image_handle; |
Heinrich Schuchardt | b27ced4 | 2019-05-01 14:20:18 +0200 | [diff] [blame] | 3207 | image_obj->header.type = EFI_OBJECT_TYPE_STARTED_IMAGE; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 3208 | EFI_PRINT("Jumping into 0x%p\n", image_obj->entry); |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3209 | ret = EFI_CALL(image_obj->entry(image_handle, &systab)); |
| 3210 | |
| 3211 | /* |
Heinrich Schuchardt | b7bc28d | 2020-01-10 22:06:54 +0100 | [diff] [blame] | 3212 | * Control is returned from a started UEFI image either by calling |
| 3213 | * Exit() (where exit data can be provided) or by simply returning from |
| 3214 | * the entry point. In the latter case call Exit() on behalf of the |
| 3215 | * image. |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3216 | */ |
| 3217 | return EFI_CALL(systab.boottime->exit(image_handle, ret, 0, NULL)); |
| 3218 | } |
| 3219 | |
| 3220 | /** |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3221 | * efi_delete_image() - delete loaded image from memory) |
| 3222 | * |
| 3223 | * @image_obj: handle of the loaded image |
| 3224 | * @loaded_image_protocol: loaded image protocol |
| 3225 | */ |
Heinrich Schuchardt | e3bca2a | 2019-06-02 20:02:32 +0200 | [diff] [blame] | 3226 | static efi_status_t efi_delete_image |
| 3227 | (struct efi_loaded_image_obj *image_obj, |
| 3228 | struct efi_loaded_image *loaded_image_protocol) |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3229 | { |
Heinrich Schuchardt | e3bca2a | 2019-06-02 20:02:32 +0200 | [diff] [blame] | 3230 | struct efi_object *efiobj; |
| 3231 | efi_status_t r, ret = EFI_SUCCESS; |
| 3232 | |
| 3233 | close_next: |
| 3234 | list_for_each_entry(efiobj, &efi_obj_list, link) { |
| 3235 | struct efi_handler *protocol; |
| 3236 | |
| 3237 | list_for_each_entry(protocol, &efiobj->protocols, link) { |
| 3238 | struct efi_open_protocol_info_item *info; |
| 3239 | |
| 3240 | list_for_each_entry(info, &protocol->open_infos, link) { |
| 3241 | if (info->info.agent_handle != |
| 3242 | (efi_handle_t)image_obj) |
| 3243 | continue; |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 3244 | r = efi_close_protocol( |
| 3245 | efiobj, &protocol->guid, |
| 3246 | info->info.agent_handle, |
| 3247 | info->info.controller_handle); |
Heinrich Schuchardt | e3bca2a | 2019-06-02 20:02:32 +0200 | [diff] [blame] | 3248 | if (r != EFI_SUCCESS) |
| 3249 | ret = r; |
| 3250 | /* |
| 3251 | * Closing protocols may results in further |
| 3252 | * items being deleted. To play it safe loop |
| 3253 | * over all elements again. |
| 3254 | */ |
| 3255 | goto close_next; |
| 3256 | } |
| 3257 | } |
| 3258 | } |
| 3259 | |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3260 | efi_free_pages((uintptr_t)loaded_image_protocol->image_base, |
| 3261 | efi_size_in_pages(loaded_image_protocol->image_size)); |
| 3262 | efi_delete_handle(&image_obj->header); |
Heinrich Schuchardt | e3bca2a | 2019-06-02 20:02:32 +0200 | [diff] [blame] | 3263 | |
| 3264 | return ret; |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | /** |
Heinrich Schuchardt | 6b3581a | 2019-05-01 19:04:32 +0200 | [diff] [blame] | 3268 | * efi_unload_image() - unload an EFI image |
| 3269 | * @image_handle: handle of the image to be unloaded |
| 3270 | * |
| 3271 | * This function implements the UnloadImage service. |
| 3272 | * |
| 3273 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3274 | * details. |
| 3275 | * |
| 3276 | * Return: status code |
| 3277 | */ |
| 3278 | efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle) |
| 3279 | { |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3280 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | 6b3581a | 2019-05-01 19:04:32 +0200 | [diff] [blame] | 3281 | struct efi_object *efiobj; |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3282 | struct efi_loaded_image *loaded_image_protocol; |
Heinrich Schuchardt | 6b3581a | 2019-05-01 19:04:32 +0200 | [diff] [blame] | 3283 | |
| 3284 | EFI_ENTRY("%p", image_handle); |
Heinrich Schuchardt | 6b3581a | 2019-05-01 19:04:32 +0200 | [diff] [blame] | 3285 | |
Heinrich Schuchardt | 4ed66e5 | 2019-05-01 18:25:45 +0200 | [diff] [blame] | 3286 | efiobj = efi_search_obj(image_handle); |
| 3287 | if (!efiobj) { |
| 3288 | ret = EFI_INVALID_PARAMETER; |
| 3289 | goto out; |
| 3290 | } |
| 3291 | /* Find the loaded image protocol */ |
| 3292 | ret = EFI_CALL(efi_open_protocol(image_handle, &efi_guid_loaded_image, |
| 3293 | (void **)&loaded_image_protocol, |
| 3294 | NULL, NULL, |
| 3295 | EFI_OPEN_PROTOCOL_GET_PROTOCOL)); |
| 3296 | if (ret != EFI_SUCCESS) { |
| 3297 | ret = EFI_INVALID_PARAMETER; |
| 3298 | goto out; |
| 3299 | } |
| 3300 | switch (efiobj->type) { |
| 3301 | case EFI_OBJECT_TYPE_STARTED_IMAGE: |
| 3302 | /* Call the unload function */ |
| 3303 | if (!loaded_image_protocol->unload) { |
| 3304 | ret = EFI_UNSUPPORTED; |
| 3305 | goto out; |
| 3306 | } |
| 3307 | ret = EFI_CALL(loaded_image_protocol->unload(image_handle)); |
| 3308 | if (ret != EFI_SUCCESS) |
| 3309 | goto out; |
| 3310 | break; |
| 3311 | case EFI_OBJECT_TYPE_LOADED_IMAGE: |
| 3312 | break; |
| 3313 | default: |
| 3314 | ret = EFI_INVALID_PARAMETER; |
| 3315 | goto out; |
| 3316 | } |
| 3317 | efi_delete_image((struct efi_loaded_image_obj *)efiobj, |
| 3318 | loaded_image_protocol); |
| 3319 | out: |
| 3320 | return EFI_EXIT(ret); |
Heinrich Schuchardt | 6b3581a | 2019-05-01 19:04:32 +0200 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /** |
Heinrich Schuchardt | 3d44512 | 2019-04-30 17:57:30 +0200 | [diff] [blame] | 3324 | * efi_update_exit_data() - fill exit data parameters of StartImage() |
| 3325 | * |
Heinrich Schuchardt | 74c2529 | 2019-07-14 11:25:06 +0200 | [diff] [blame] | 3326 | * @image_obj: image handle |
| 3327 | * @exit_data_size: size of the exit data buffer |
| 3328 | * @exit_data: buffer with data returned by UEFI payload |
Heinrich Schuchardt | 3d44512 | 2019-04-30 17:57:30 +0200 | [diff] [blame] | 3329 | * Return: status code |
| 3330 | */ |
| 3331 | static efi_status_t efi_update_exit_data(struct efi_loaded_image_obj *image_obj, |
| 3332 | efi_uintn_t exit_data_size, |
| 3333 | u16 *exit_data) |
| 3334 | { |
| 3335 | efi_status_t ret; |
| 3336 | |
| 3337 | /* |
| 3338 | * If exit_data is not provided to StartImage(), exit_data_size must be |
| 3339 | * ignored. |
| 3340 | */ |
| 3341 | if (!image_obj->exit_data) |
| 3342 | return EFI_SUCCESS; |
| 3343 | if (image_obj->exit_data_size) |
| 3344 | *image_obj->exit_data_size = exit_data_size; |
| 3345 | if (exit_data_size && exit_data) { |
| 3346 | ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, |
| 3347 | exit_data_size, |
| 3348 | (void **)image_obj->exit_data); |
| 3349 | if (ret != EFI_SUCCESS) |
| 3350 | return ret; |
| 3351 | memcpy(*image_obj->exit_data, exit_data, exit_data_size); |
| 3352 | } else { |
| 3353 | image_obj->exit_data = NULL; |
| 3354 | } |
| 3355 | return EFI_SUCCESS; |
| 3356 | } |
| 3357 | |
| 3358 | /** |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3359 | * efi_exit() - leave an EFI application or driver |
| 3360 | * @image_handle: handle of the application or driver that is exiting |
| 3361 | * @exit_status: status code |
| 3362 | * @exit_data_size: size of the buffer in bytes |
| 3363 | * @exit_data: buffer with data describing an error |
| 3364 | * |
| 3365 | * This function implements the Exit service. |
| 3366 | * |
| 3367 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3368 | * details. |
| 3369 | * |
| 3370 | * Return: status code |
| 3371 | */ |
| 3372 | static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, |
| 3373 | efi_status_t exit_status, |
| 3374 | efi_uintn_t exit_data_size, |
| 3375 | u16 *exit_data) |
| 3376 | { |
| 3377 | /* |
| 3378 | * TODO: We should call the unload procedure of the loaded |
| 3379 | * image protocol. |
| 3380 | */ |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3381 | efi_status_t ret; |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 3382 | struct efi_loaded_image *loaded_image_protocol; |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3383 | struct efi_loaded_image_obj *image_obj = |
| 3384 | (struct efi_loaded_image_obj *)image_handle; |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3385 | struct jmp_buf_data *exit_jmp; |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3386 | |
| 3387 | EFI_ENTRY("%p, %ld, %zu, %p", image_handle, exit_status, |
| 3388 | exit_data_size, exit_data); |
| 3389 | |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3390 | /* Check parameters */ |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3391 | ret = EFI_CALL(efi_open_protocol(image_handle, &efi_guid_loaded_image, |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 3392 | (void **)&loaded_image_protocol, |
| 3393 | NULL, NULL, |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3394 | EFI_OPEN_PROTOCOL_GET_PROTOCOL)); |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 3395 | if (ret != EFI_SUCCESS) { |
| 3396 | ret = EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3397 | goto out; |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | /* Unloading of unstarted images */ |
| 3401 | switch (image_obj->header.type) { |
| 3402 | case EFI_OBJECT_TYPE_STARTED_IMAGE: |
| 3403 | break; |
| 3404 | case EFI_OBJECT_TYPE_LOADED_IMAGE: |
| 3405 | efi_delete_image(image_obj, loaded_image_protocol); |
| 3406 | ret = EFI_SUCCESS; |
| 3407 | goto out; |
| 3408 | default: |
| 3409 | /* Handle does not refer to loaded image */ |
| 3410 | ret = EFI_INVALID_PARAMETER; |
| 3411 | goto out; |
| 3412 | } |
| 3413 | /* A started image can only be unloaded it is the last one started. */ |
| 3414 | if (image_handle != current_image) { |
| 3415 | ret = EFI_INVALID_PARAMETER; |
| 3416 | goto out; |
| 3417 | } |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3418 | |
Heinrich Schuchardt | 3d44512 | 2019-04-30 17:57:30 +0200 | [diff] [blame] | 3419 | /* Exit data is only foreseen in case of failure. */ |
| 3420 | if (exit_status != EFI_SUCCESS) { |
| 3421 | ret = efi_update_exit_data(image_obj, exit_data_size, |
| 3422 | exit_data); |
| 3423 | /* Exiting has priority. Don't return error to caller. */ |
| 3424 | if (ret != EFI_SUCCESS) |
| 3425 | EFI_PRINT("%s: out of memory\n", __func__); |
| 3426 | } |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3427 | /* efi_delete_image() frees image_obj. Copy before the call. */ |
| 3428 | exit_jmp = image_obj->exit_jmp; |
| 3429 | *image_obj->exit_status = exit_status; |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 3430 | if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION || |
| 3431 | exit_status != EFI_SUCCESS) |
| 3432 | efi_delete_image(image_obj, loaded_image_protocol); |
Heinrich Schuchardt | 3d44512 | 2019-04-30 17:57:30 +0200 | [diff] [blame] | 3433 | |
Masahisa Kojima | 8173cd4 | 2021-08-13 16:12:40 +0900 | [diff] [blame] | 3434 | if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { |
| 3435 | if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) { |
| 3436 | ret = efi_tcg2_measure_efi_app_exit(); |
| 3437 | if (ret != EFI_SUCCESS) { |
| 3438 | log_warning("tcg2 measurement fails(0x%lx)\n", |
| 3439 | ret); |
| 3440 | } |
| 3441 | } |
| 3442 | } |
| 3443 | |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3444 | /* Make sure entry/exit counts for EFI world cross-overs match */ |
| 3445 | EFI_EXIT(exit_status); |
| 3446 | |
| 3447 | /* |
| 3448 | * But longjmp out with the U-Boot gd, not the application's, as |
| 3449 | * the other end is a setjmp call inside EFI context. |
| 3450 | */ |
| 3451 | efi_restore_gd(); |
| 3452 | |
Heinrich Schuchardt | 026c7ec | 2020-12-28 23:24:40 +0100 | [diff] [blame] | 3453 | longjmp(exit_jmp, 1); |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3454 | |
| 3455 | panic("EFI application exited"); |
Heinrich Schuchardt | 8efe079 | 2019-03-26 19:03:17 +0100 | [diff] [blame] | 3456 | out: |
Heinrich Schuchardt | 3758752 | 2019-05-01 20:07:04 +0200 | [diff] [blame] | 3457 | return EFI_EXIT(ret); |
Heinrich Schuchardt | 2650a4d | 2019-03-26 19:02:05 +0100 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3461 | * efi_handle_protocol() - get interface of a protocol on a handle |
| 3462 | * @handle: handle on which the protocol shall be opened |
| 3463 | * @protocol: GUID of the protocol |
| 3464 | * @protocol_interface: interface implementing the protocol |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 3465 | * |
| 3466 | * This function implements the HandleProtocol service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3467 | * |
| 3468 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3469 | * details. |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 3470 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3471 | * Return: status code |
Heinrich Schuchardt | a40db6e | 2017-09-21 18:30:11 +0200 | [diff] [blame] | 3472 | */ |
AKASHI Takahiro | d99b1b3 | 2020-03-17 11:12:36 +0900 | [diff] [blame] | 3473 | efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle, |
| 3474 | const efi_guid_t *protocol, |
| 3475 | void **protocol_interface) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3476 | { |
Heinrich Schuchardt | ef09615 | 2019-06-01 19:29:39 +0200 | [diff] [blame] | 3477 | return efi_open_protocol(handle, protocol, protocol_interface, efi_root, |
xypron.glpk@gmx.de | 1bf5d87 | 2017-06-29 21:16:19 +0200 | [diff] [blame] | 3478 | NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3479 | } |
| 3480 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3481 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3482 | * efi_bind_controller() - bind a single driver to a controller |
| 3483 | * @controller_handle: controller handle |
| 3484 | * @driver_image_handle: driver handle |
| 3485 | * @remain_device_path: remaining path |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3486 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3487 | * Return: status code |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3488 | */ |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3489 | static efi_status_t efi_bind_controller( |
| 3490 | efi_handle_t controller_handle, |
| 3491 | efi_handle_t driver_image_handle, |
| 3492 | struct efi_device_path *remain_device_path) |
| 3493 | { |
| 3494 | struct efi_driver_binding_protocol *binding_protocol; |
| 3495 | efi_status_t r; |
| 3496 | |
| 3497 | r = EFI_CALL(efi_open_protocol(driver_image_handle, |
| 3498 | &efi_guid_driver_binding_protocol, |
| 3499 | (void **)&binding_protocol, |
| 3500 | driver_image_handle, NULL, |
| 3501 | EFI_OPEN_PROTOCOL_GET_PROTOCOL)); |
| 3502 | if (r != EFI_SUCCESS) |
| 3503 | return r; |
| 3504 | r = EFI_CALL(binding_protocol->supported(binding_protocol, |
| 3505 | controller_handle, |
| 3506 | remain_device_path)); |
| 3507 | if (r == EFI_SUCCESS) |
| 3508 | r = EFI_CALL(binding_protocol->start(binding_protocol, |
| 3509 | controller_handle, |
| 3510 | remain_device_path)); |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 3511 | efi_close_protocol(driver_image_handle, |
| 3512 | &efi_guid_driver_binding_protocol, |
| 3513 | driver_image_handle, NULL); |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3514 | return r; |
| 3515 | } |
| 3516 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3517 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3518 | * efi_connect_single_controller() - connect a single driver to a controller |
| 3519 | * @controller_handle: controller |
| 3520 | * @driver_image_handle: driver |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 3521 | * @remain_device_path: remaining path |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3522 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3523 | * Return: status code |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3524 | */ |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3525 | static efi_status_t efi_connect_single_controller( |
| 3526 | efi_handle_t controller_handle, |
| 3527 | efi_handle_t *driver_image_handle, |
| 3528 | struct efi_device_path *remain_device_path) |
| 3529 | { |
| 3530 | efi_handle_t *buffer; |
| 3531 | size_t count; |
| 3532 | size_t i; |
| 3533 | efi_status_t r; |
| 3534 | size_t connected = 0; |
| 3535 | |
| 3536 | /* Get buffer with all handles with driver binding protocol */ |
| 3537 | r = EFI_CALL(efi_locate_handle_buffer(BY_PROTOCOL, |
| 3538 | &efi_guid_driver_binding_protocol, |
| 3539 | NULL, &count, &buffer)); |
| 3540 | if (r != EFI_SUCCESS) |
| 3541 | return r; |
| 3542 | |
Heinrich Schuchardt | da8f900 | 2019-07-03 20:27:24 +0200 | [diff] [blame] | 3543 | /* Context Override */ |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3544 | if (driver_image_handle) { |
| 3545 | for (; *driver_image_handle; ++driver_image_handle) { |
| 3546 | for (i = 0; i < count; ++i) { |
| 3547 | if (buffer[i] == *driver_image_handle) { |
| 3548 | buffer[i] = NULL; |
| 3549 | r = efi_bind_controller( |
| 3550 | controller_handle, |
| 3551 | *driver_image_handle, |
| 3552 | remain_device_path); |
| 3553 | /* |
| 3554 | * For drivers that do not support the |
| 3555 | * controller or are already connected |
| 3556 | * we receive an error code here. |
| 3557 | */ |
| 3558 | if (r == EFI_SUCCESS) |
| 3559 | ++connected; |
| 3560 | } |
| 3561 | } |
| 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | /* |
| 3566 | * TODO: Some overrides are not yet implemented: |
| 3567 | * - Platform Driver Override |
| 3568 | * - Driver Family Override Search |
| 3569 | * - Bus Specific Driver Override |
| 3570 | */ |
| 3571 | |
| 3572 | /* Driver Binding Search */ |
| 3573 | for (i = 0; i < count; ++i) { |
| 3574 | if (buffer[i]) { |
| 3575 | r = efi_bind_controller(controller_handle, |
| 3576 | buffer[i], |
| 3577 | remain_device_path); |
| 3578 | if (r == EFI_SUCCESS) |
| 3579 | ++connected; |
| 3580 | } |
| 3581 | } |
| 3582 | |
| 3583 | efi_free_pool(buffer); |
| 3584 | if (!connected) |
| 3585 | return EFI_NOT_FOUND; |
| 3586 | return EFI_SUCCESS; |
| 3587 | } |
| 3588 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3589 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3590 | * efi_connect_controller() - connect a controller to a driver |
| 3591 | * @controller_handle: handle of the controller |
| 3592 | * @driver_image_handle: handle of the driver |
| 3593 | * @remain_device_path: device path of a child controller |
| 3594 | * @recursive: true to connect all child controllers |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3595 | * |
| 3596 | * This function implements the ConnectController service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3597 | * |
| 3598 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3599 | * details. |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3600 | * |
| 3601 | * First all driver binding protocol handles are tried for binding drivers. |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 3602 | * Afterwards all handles that have opened a protocol of the controller |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3603 | * with EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER are connected to drivers. |
| 3604 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3605 | * Return: status code |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3606 | */ |
| 3607 | static efi_status_t EFIAPI efi_connect_controller( |
| 3608 | efi_handle_t controller_handle, |
| 3609 | efi_handle_t *driver_image_handle, |
| 3610 | struct efi_device_path *remain_device_path, |
| 3611 | bool recursive) |
| 3612 | { |
| 3613 | efi_status_t r; |
| 3614 | efi_status_t ret = EFI_NOT_FOUND; |
| 3615 | struct efi_object *efiobj; |
| 3616 | |
Heinrich Schuchardt | 7c89fb0 | 2018-12-09 16:39:20 +0100 | [diff] [blame] | 3617 | EFI_ENTRY("%p, %p, %pD, %d", controller_handle, driver_image_handle, |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3618 | remain_device_path, recursive); |
| 3619 | |
| 3620 | efiobj = efi_search_obj(controller_handle); |
| 3621 | if (!efiobj) { |
| 3622 | ret = EFI_INVALID_PARAMETER; |
| 3623 | goto out; |
| 3624 | } |
| 3625 | |
| 3626 | r = efi_connect_single_controller(controller_handle, |
| 3627 | driver_image_handle, |
| 3628 | remain_device_path); |
| 3629 | if (r == EFI_SUCCESS) |
| 3630 | ret = EFI_SUCCESS; |
| 3631 | if (recursive) { |
| 3632 | struct efi_handler *handler; |
| 3633 | struct efi_open_protocol_info_item *item; |
| 3634 | |
| 3635 | list_for_each_entry(handler, &efiobj->protocols, link) { |
| 3636 | list_for_each_entry(item, &handler->open_infos, link) { |
| 3637 | if (item->info.attributes & |
| 3638 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) { |
| 3639 | r = EFI_CALL(efi_connect_controller( |
| 3640 | item->info.controller_handle, |
| 3641 | driver_image_handle, |
| 3642 | remain_device_path, |
| 3643 | recursive)); |
| 3644 | if (r == EFI_SUCCESS) |
| 3645 | ret = EFI_SUCCESS; |
| 3646 | } |
| 3647 | } |
| 3648 | } |
| 3649 | } |
Heinrich Schuchardt | da8f900 | 2019-07-03 20:27:24 +0200 | [diff] [blame] | 3650 | /* Check for child controller specified by end node */ |
Heinrich Schuchardt | 760255f | 2018-01-11 08:16:02 +0100 | [diff] [blame] | 3651 | if (ret != EFI_SUCCESS && remain_device_path && |
| 3652 | remain_device_path->type == DEVICE_PATH_TYPE_END) |
| 3653 | ret = EFI_SUCCESS; |
| 3654 | out: |
| 3655 | return EFI_EXIT(ret); |
| 3656 | } |
| 3657 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3658 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3659 | * efi_reinstall_protocol_interface() - reinstall protocol interface |
| 3660 | * @handle: handle on which the protocol shall be reinstalled |
| 3661 | * @protocol: GUID of the protocol to be installed |
| 3662 | * @old_interface: interface to be removed |
| 3663 | * @new_interface: interface to be installed |
Heinrich Schuchardt | 90761b8 | 2018-05-11 12:09:22 +0200 | [diff] [blame] | 3664 | * |
| 3665 | * This function implements the ReinstallProtocolInterface service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3666 | * |
| 3667 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3668 | * details. |
Heinrich Schuchardt | 90761b8 | 2018-05-11 12:09:22 +0200 | [diff] [blame] | 3669 | * |
| 3670 | * The old interface is uninstalled. The new interface is installed. |
| 3671 | * Drivers are connected. |
| 3672 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3673 | * Return: status code |
Heinrich Schuchardt | 90761b8 | 2018-05-11 12:09:22 +0200 | [diff] [blame] | 3674 | */ |
| 3675 | static efi_status_t EFIAPI efi_reinstall_protocol_interface( |
| 3676 | efi_handle_t handle, const efi_guid_t *protocol, |
| 3677 | void *old_interface, void *new_interface) |
| 3678 | { |
| 3679 | efi_status_t ret; |
| 3680 | |
Heinrich Schuchardt | 282249d | 2022-01-16 14:15:31 +0100 | [diff] [blame] | 3681 | EFI_ENTRY("%p, %pUs, %p, %p", handle, protocol, old_interface, |
Heinrich Schuchardt | 90761b8 | 2018-05-11 12:09:22 +0200 | [diff] [blame] | 3682 | new_interface); |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 3683 | |
| 3684 | /* Uninstall protocol but do not delete handle */ |
| 3685 | ret = efi_uninstall_protocol(handle, protocol, old_interface); |
Heinrich Schuchardt | 90761b8 | 2018-05-11 12:09:22 +0200 | [diff] [blame] | 3686 | if (ret != EFI_SUCCESS) |
| 3687 | goto out; |
Heinrich Schuchardt | 1b45134 | 2018-09-28 22:14:17 +0200 | [diff] [blame] | 3688 | |
| 3689 | /* Install the new protocol */ |
| 3690 | ret = efi_add_protocol(handle, protocol, new_interface); |
| 3691 | /* |
| 3692 | * The UEFI spec does not specify what should happen to the handle |
| 3693 | * if in case of an error no protocol interface remains on the handle. |
| 3694 | * So let's do nothing here. |
| 3695 | */ |
Heinrich Schuchardt | 90761b8 | 2018-05-11 12:09:22 +0200 | [diff] [blame] | 3696 | if (ret != EFI_SUCCESS) |
| 3697 | goto out; |
| 3698 | /* |
| 3699 | * The returned status code has to be ignored. |
| 3700 | * Do not create an error if no suitable driver for the handle exists. |
| 3701 | */ |
| 3702 | EFI_CALL(efi_connect_controller(handle, NULL, NULL, true)); |
| 3703 | out: |
| 3704 | return EFI_EXIT(ret); |
| 3705 | } |
| 3706 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3707 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3708 | * efi_get_child_controllers() - get all child controllers associated to a driver |
| 3709 | * @efiobj: handle of the controller |
| 3710 | * @driver_handle: handle of the driver |
| 3711 | * @number_of_children: number of child controllers |
| 3712 | * @child_handle_buffer: handles of the the child controllers |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3713 | * |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3714 | * The allocated buffer has to be freed with free(). |
| 3715 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3716 | * Return: status code |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3717 | */ |
| 3718 | static efi_status_t efi_get_child_controllers( |
| 3719 | struct efi_object *efiobj, |
| 3720 | efi_handle_t driver_handle, |
| 3721 | efi_uintn_t *number_of_children, |
| 3722 | efi_handle_t **child_handle_buffer) |
| 3723 | { |
| 3724 | struct efi_handler *handler; |
| 3725 | struct efi_open_protocol_info_item *item; |
| 3726 | efi_uintn_t count = 0, i; |
| 3727 | bool duplicate; |
| 3728 | |
| 3729 | /* Count all child controller associations */ |
| 3730 | list_for_each_entry(handler, &efiobj->protocols, link) { |
| 3731 | list_for_each_entry(item, &handler->open_infos, link) { |
| 3732 | if (item->info.agent_handle == driver_handle && |
| 3733 | item->info.attributes & |
| 3734 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) |
| 3735 | ++count; |
| 3736 | } |
| 3737 | } |
| 3738 | /* |
| 3739 | * Create buffer. In case of duplicate child controller assignments |
| 3740 | * the buffer will be too large. But that does not harm. |
| 3741 | */ |
| 3742 | *number_of_children = 0; |
Heinrich Schuchardt | 0f321b6 | 2020-07-07 04:21:26 +0200 | [diff] [blame] | 3743 | if (!count) |
| 3744 | return EFI_SUCCESS; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3745 | *child_handle_buffer = calloc(count, sizeof(efi_handle_t)); |
| 3746 | if (!*child_handle_buffer) |
| 3747 | return EFI_OUT_OF_RESOURCES; |
| 3748 | /* Copy unique child handles */ |
| 3749 | list_for_each_entry(handler, &efiobj->protocols, link) { |
| 3750 | list_for_each_entry(item, &handler->open_infos, link) { |
| 3751 | if (item->info.agent_handle == driver_handle && |
| 3752 | item->info.attributes & |
| 3753 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) { |
| 3754 | /* Check this is a new child controller */ |
| 3755 | duplicate = false; |
| 3756 | for (i = 0; i < *number_of_children; ++i) { |
| 3757 | if ((*child_handle_buffer)[i] == |
| 3758 | item->info.controller_handle) |
| 3759 | duplicate = true; |
| 3760 | } |
| 3761 | /* Copy handle to buffer */ |
| 3762 | if (!duplicate) { |
| 3763 | i = (*number_of_children)++; |
| 3764 | (*child_handle_buffer)[i] = |
| 3765 | item->info.controller_handle; |
| 3766 | } |
| 3767 | } |
| 3768 | } |
| 3769 | } |
| 3770 | return EFI_SUCCESS; |
| 3771 | } |
| 3772 | |
Heinrich Schuchardt | 5999917 | 2018-05-11 18:15:41 +0200 | [diff] [blame] | 3773 | /** |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3774 | * efi_disconnect_controller() - disconnect a controller from a driver |
| 3775 | * @controller_handle: handle of the controller |
| 3776 | * @driver_image_handle: handle of the driver |
| 3777 | * @child_handle: handle of the child to destroy |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3778 | * |
| 3779 | * This function implements the DisconnectController service. |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3780 | * |
| 3781 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 3782 | * details. |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3783 | * |
Mario Six | 8fac291 | 2018-07-10 08:40:17 +0200 | [diff] [blame] | 3784 | * Return: status code |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3785 | */ |
| 3786 | static efi_status_t EFIAPI efi_disconnect_controller( |
| 3787 | efi_handle_t controller_handle, |
| 3788 | efi_handle_t driver_image_handle, |
| 3789 | efi_handle_t child_handle) |
| 3790 | { |
| 3791 | struct efi_driver_binding_protocol *binding_protocol; |
| 3792 | efi_handle_t *child_handle_buffer = NULL; |
| 3793 | size_t number_of_children = 0; |
| 3794 | efi_status_t r; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3795 | struct efi_object *efiobj; |
Heinrich Schuchardt | c7ce404 | 2020-10-28 18:45:47 +0100 | [diff] [blame] | 3796 | bool sole_child; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3797 | |
| 3798 | EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, |
| 3799 | child_handle); |
| 3800 | |
| 3801 | efiobj = efi_search_obj(controller_handle); |
| 3802 | if (!efiobj) { |
| 3803 | r = EFI_INVALID_PARAMETER; |
| 3804 | goto out; |
| 3805 | } |
| 3806 | |
| 3807 | if (child_handle && !efi_search_obj(child_handle)) { |
| 3808 | r = EFI_INVALID_PARAMETER; |
| 3809 | goto out; |
| 3810 | } |
| 3811 | |
| 3812 | /* If no driver handle is supplied, disconnect all drivers */ |
| 3813 | if (!driver_image_handle) { |
| 3814 | r = efi_disconnect_all_drivers(efiobj, NULL, child_handle); |
| 3815 | goto out; |
| 3816 | } |
| 3817 | |
| 3818 | /* Create list of child handles */ |
Heinrich Schuchardt | c7ce404 | 2020-10-28 18:45:47 +0100 | [diff] [blame] | 3819 | r = efi_get_child_controllers(efiobj, |
| 3820 | driver_image_handle, |
| 3821 | &number_of_children, |
| 3822 | &child_handle_buffer); |
| 3823 | if (r != EFI_SUCCESS) |
| 3824 | return r; |
| 3825 | sole_child = (number_of_children == 1); |
| 3826 | |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3827 | if (child_handle) { |
| 3828 | number_of_children = 1; |
Heinrich Schuchardt | c7ce404 | 2020-10-28 18:45:47 +0100 | [diff] [blame] | 3829 | free(child_handle_buffer); |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3830 | child_handle_buffer = &child_handle; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | /* Get the driver binding protocol */ |
| 3834 | r = EFI_CALL(efi_open_protocol(driver_image_handle, |
| 3835 | &efi_guid_driver_binding_protocol, |
| 3836 | (void **)&binding_protocol, |
| 3837 | driver_image_handle, NULL, |
| 3838 | EFI_OPEN_PROTOCOL_GET_PROTOCOL)); |
Heinrich Schuchardt | 7962284 | 2019-09-13 18:20:40 +0200 | [diff] [blame] | 3839 | if (r != EFI_SUCCESS) { |
| 3840 | r = EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3841 | goto out; |
Heinrich Schuchardt | 7962284 | 2019-09-13 18:20:40 +0200 | [diff] [blame] | 3842 | } |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3843 | /* Remove the children */ |
| 3844 | if (number_of_children) { |
| 3845 | r = EFI_CALL(binding_protocol->stop(binding_protocol, |
| 3846 | controller_handle, |
| 3847 | number_of_children, |
| 3848 | child_handle_buffer)); |
Heinrich Schuchardt | 7962284 | 2019-09-13 18:20:40 +0200 | [diff] [blame] | 3849 | if (r != EFI_SUCCESS) { |
| 3850 | r = EFI_DEVICE_ERROR; |
| 3851 | goto out; |
| 3852 | } |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3853 | } |
| 3854 | /* Remove the driver */ |
Heinrich Schuchardt | c7ce404 | 2020-10-28 18:45:47 +0100 | [diff] [blame] | 3855 | if (!child_handle || sole_child) { |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3856 | r = EFI_CALL(binding_protocol->stop(binding_protocol, |
| 3857 | controller_handle, |
| 3858 | 0, NULL)); |
Heinrich Schuchardt | 7962284 | 2019-09-13 18:20:40 +0200 | [diff] [blame] | 3859 | if (r != EFI_SUCCESS) { |
| 3860 | r = EFI_DEVICE_ERROR; |
| 3861 | goto out; |
| 3862 | } |
| 3863 | } |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 3864 | efi_close_protocol(driver_image_handle, |
| 3865 | &efi_guid_driver_binding_protocol, |
| 3866 | driver_image_handle, NULL); |
Heinrich Schuchardt | 7962284 | 2019-09-13 18:20:40 +0200 | [diff] [blame] | 3867 | r = EFI_SUCCESS; |
Heinrich Schuchardt | e994328 | 2018-01-11 08:16:04 +0100 | [diff] [blame] | 3868 | out: |
| 3869 | if (!child_handle) |
| 3870 | free(child_handle_buffer); |
| 3871 | return EFI_EXIT(r); |
| 3872 | } |
| 3873 | |
Heinrich Schuchardt | 15070db | 2018-06-28 12:45:31 +0200 | [diff] [blame] | 3874 | static struct efi_boot_services efi_boot_services = { |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3875 | .hdr = { |
Heinrich Schuchardt | e75b3cb | 2018-06-28 12:45:27 +0200 | [diff] [blame] | 3876 | .signature = EFI_BOOT_SERVICES_SIGNATURE, |
| 3877 | .revision = EFI_SPECIFICATION_VERSION, |
Heinrich Schuchardt | 1020425 | 2018-06-28 12:45:29 +0200 | [diff] [blame] | 3878 | .headersize = sizeof(struct efi_boot_services), |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3879 | }, |
| 3880 | .raise_tpl = efi_raise_tpl, |
| 3881 | .restore_tpl = efi_restore_tpl, |
| 3882 | .allocate_pages = efi_allocate_pages_ext, |
| 3883 | .free_pages = efi_free_pages_ext, |
| 3884 | .get_memory_map = efi_get_memory_map_ext, |
Stefan Brüns | 5a09aef | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 3885 | .allocate_pool = efi_allocate_pool_ext, |
Stefan Brüns | 67b67d9 | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 3886 | .free_pool = efi_free_pool_ext, |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 3887 | .create_event = efi_create_event_ext, |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 3888 | .set_timer = efi_set_timer_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3889 | .wait_for_event = efi_wait_for_event, |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 3890 | .signal_event = efi_signal_event_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3891 | .close_event = efi_close_event, |
| 3892 | .check_event = efi_check_event, |
Heinrich Schuchardt | 0a27ac8 | 2017-11-06 21:17:44 +0100 | [diff] [blame] | 3893 | .install_protocol_interface = efi_install_protocol_interface, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3894 | .reinstall_protocol_interface = efi_reinstall_protocol_interface, |
Heinrich Schuchardt | 7cdc17f | 2017-11-06 21:17:45 +0100 | [diff] [blame] | 3895 | .uninstall_protocol_interface = efi_uninstall_protocol_interface, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3896 | .handle_protocol = efi_handle_protocol, |
| 3897 | .reserved = NULL, |
| 3898 | .register_protocol_notify = efi_register_protocol_notify, |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 3899 | .locate_handle = efi_locate_handle_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3900 | .locate_device_path = efi_locate_device_path, |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 3901 | .install_configuration_table = efi_install_configuration_table_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3902 | .load_image = efi_load_image, |
| 3903 | .start_image = efi_start_image, |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 3904 | .exit = efi_exit, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3905 | .unload_image = efi_unload_image, |
| 3906 | .exit_boot_services = efi_exit_boot_services, |
| 3907 | .get_next_monotonic_count = efi_get_next_monotonic_count, |
| 3908 | .stall = efi_stall, |
| 3909 | .set_watchdog_timer = efi_set_watchdog_timer, |
| 3910 | .connect_controller = efi_connect_controller, |
| 3911 | .disconnect_controller = efi_disconnect_controller, |
| 3912 | .open_protocol = efi_open_protocol, |
Heinrich Schuchardt | 5e39433 | 2022-10-07 15:18:15 +0200 | [diff] [blame] | 3913 | .close_protocol = efi_close_protocol_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3914 | .open_protocol_information = efi_open_protocol_information, |
| 3915 | .protocols_per_handle = efi_protocols_per_handle, |
| 3916 | .locate_handle_buffer = efi_locate_handle_buffer, |
| 3917 | .locate_protocol = efi_locate_protocol, |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 3918 | .install_multiple_protocol_interfaces = |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 3919 | efi_install_multiple_protocol_interfaces_ext, |
Heinrich Schuchardt | 9106459 | 2018-02-18 15:17:49 +0100 | [diff] [blame] | 3920 | .uninstall_multiple_protocol_interfaces = |
Ilias Apalodimas | 8ac0ebe | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 3921 | efi_uninstall_multiple_protocol_interfaces_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3922 | .calculate_crc32 = efi_calculate_crc32, |
| 3923 | .copy_mem = efi_copy_mem, |
| 3924 | .set_mem = efi_set_mem, |
Heinrich Schuchardt | 717c458 | 2018-02-04 23:05:13 +0100 | [diff] [blame] | 3925 | .create_event_ex = efi_create_event_ex, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3926 | }; |
| 3927 | |
Simon Glass | 9097537 | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 3928 | static u16 __efi_runtime_data firmware_vendor[] = u"Das U-Boot"; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3929 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 3930 | struct efi_system_table __efi_runtime_data systab = { |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3931 | .hdr = { |
| 3932 | .signature = EFI_SYSTEM_TABLE_SIGNATURE, |
Heinrich Schuchardt | e75b3cb | 2018-06-28 12:45:27 +0200 | [diff] [blame] | 3933 | .revision = EFI_SPECIFICATION_VERSION, |
Heinrich Schuchardt | 1020425 | 2018-06-28 12:45:29 +0200 | [diff] [blame] | 3934 | .headersize = sizeof(struct efi_system_table), |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3935 | }, |
Heinrich Schuchardt | 27685f7 | 2018-06-28 12:45:30 +0200 | [diff] [blame] | 3936 | .fw_vendor = firmware_vendor, |
| 3937 | .fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8, |
Heinrich Schuchardt | 372b893 | 2019-06-15 14:51:06 +0200 | [diff] [blame] | 3938 | .runtime = &efi_runtime_services, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3939 | .nr_tables = 0, |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 3940 | .tables = NULL, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 3941 | }; |
Heinrich Schuchardt | 15070db | 2018-06-28 12:45:31 +0200 | [diff] [blame] | 3942 | |
| 3943 | /** |
| 3944 | * efi_initialize_system_table() - Initialize system table |
| 3945 | * |
Heinrich Schuchardt | 7b4b2a2 | 2018-09-03 05:00:43 +0200 | [diff] [blame] | 3946 | * Return: status code |
Heinrich Schuchardt | 15070db | 2018-06-28 12:45:31 +0200 | [diff] [blame] | 3947 | */ |
| 3948 | efi_status_t efi_initialize_system_table(void) |
| 3949 | { |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 3950 | efi_status_t ret; |
| 3951 | |
| 3952 | /* Allocate configuration table array */ |
| 3953 | ret = efi_allocate_pool(EFI_RUNTIME_SERVICES_DATA, |
| 3954 | EFI_MAX_CONFIGURATION_TABLES * |
| 3955 | sizeof(struct efi_configuration_table), |
| 3956 | (void **)&systab.tables); |
| 3957 | |
Heinrich Schuchardt | 98f8936 | 2019-06-29 02:00:16 +0200 | [diff] [blame] | 3958 | /* |
| 3959 | * These entries will be set to NULL in ExitBootServices(). To avoid |
| 3960 | * relocation in SetVirtualAddressMap(), set them dynamically. |
| 3961 | */ |
Heinrich Schuchardt | ed64768 | 2023-01-04 05:56:09 +0100 | [diff] [blame] | 3962 | systab.con_in_handle = efi_root; |
Heinrich Schuchardt | 98f8936 | 2019-06-29 02:00:16 +0200 | [diff] [blame] | 3963 | systab.con_in = &efi_con_in; |
Heinrich Schuchardt | ed64768 | 2023-01-04 05:56:09 +0100 | [diff] [blame] | 3964 | systab.con_out_handle = efi_root; |
Heinrich Schuchardt | 98f8936 | 2019-06-29 02:00:16 +0200 | [diff] [blame] | 3965 | systab.con_out = &efi_con_out; |
Heinrich Schuchardt | ed64768 | 2023-01-04 05:56:09 +0100 | [diff] [blame] | 3966 | systab.stderr_handle = efi_root; |
Heinrich Schuchardt | 98f8936 | 2019-06-29 02:00:16 +0200 | [diff] [blame] | 3967 | systab.std_err = &efi_con_out; |
| 3968 | systab.boottime = &efi_boot_services; |
| 3969 | |
Heinrich Schuchardt | cf70a73 | 2018-09-03 19:12:24 +0200 | [diff] [blame] | 3970 | /* Set CRC32 field in table headers */ |
Heinrich Schuchardt | 15070db | 2018-06-28 12:45:31 +0200 | [diff] [blame] | 3971 | efi_update_table_header_crc32(&systab.hdr); |
| 3972 | efi_update_table_header_crc32(&efi_runtime_services.hdr); |
| 3973 | efi_update_table_header_crc32(&efi_boot_services.hdr); |
Heinrich Schuchardt | 2f528c2 | 2018-06-28 12:45:32 +0200 | [diff] [blame] | 3974 | |
| 3975 | return ret; |
Heinrich Schuchardt | 15070db | 2018-06-28 12:45:31 +0200 | [diff] [blame] | 3976 | } |