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