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