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