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