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