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