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