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