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