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