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