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