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