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