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