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