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