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