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