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