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> |
| 10 | #include <efi_loader.h> |
| 11 | #include <malloc.h> |
| 12 | #include <asm/global_data.h> |
| 13 | #include <libfdt_env.h> |
| 14 | #include <u-boot/crc.h> |
| 15 | #include <bootm.h> |
| 16 | #include <inttypes.h> |
| 17 | #include <watchdog.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Heinrich Schuchardt | 32f4b2f | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 21 | /* Task priority level */ |
| 22 | static UINTN efi_tpl = TPL_APPLICATION; |
| 23 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 24 | /* This list contains all the EFI objects our payload has access to */ |
| 25 | LIST_HEAD(efi_obj_list); |
| 26 | |
| 27 | /* |
| 28 | * If we're running on nasty systems (32bit ARM booting into non-EFI Linux) |
| 29 | * we need to do trickery with caches. Since we don't want to break the EFI |
| 30 | * aware boot path, only apply hacks when loading exiting directly (breaking |
| 31 | * direct Linux EFI booting along the way - oh well). |
| 32 | */ |
| 33 | static bool efi_is_direct_boot = true; |
| 34 | |
| 35 | /* |
| 36 | * EFI can pass arbitrary additional "tables" containing vendor specific |
| 37 | * information to the payload. One such table is the FDT table which contains |
| 38 | * a pointer to a flattened device tree blob. |
| 39 | * |
| 40 | * In most cases we want to pass an FDT to the payload, so reserve one slot of |
| 41 | * config table space for it. The pointer gets populated by do_bootefi_exec(). |
| 42 | */ |
Alexander Graf | 3c63db9 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 43 | static struct efi_configuration_table __efi_runtime_data efi_conf_table[2]; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 44 | |
Simon Glass | 65e4c0b | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 45 | #ifdef CONFIG_ARM |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 46 | /* |
| 47 | * The "gd" pointer lives in a register on ARM and AArch64 that we declare |
| 48 | * fixed when compiling U-Boot. However, the payload does not know about that |
| 49 | * restriction so we need to manually swap its and our view of that register on |
| 50 | * EFI callback entry/exit. |
| 51 | */ |
| 52 | static volatile void *efi_gd, *app_gd; |
Simon Glass | 65e4c0b | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 53 | #endif |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 54 | |
Rob Clark | c160d2f | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 55 | static int entry_count; |
Rob Clark | af65db8 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 56 | static int nesting_level; |
Rob Clark | c160d2f | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 57 | |
| 58 | /* Called on every callback entry */ |
| 59 | int __efi_entry_check(void) |
| 60 | { |
| 61 | int ret = entry_count++ == 0; |
| 62 | #ifdef CONFIG_ARM |
| 63 | assert(efi_gd); |
| 64 | app_gd = gd; |
| 65 | gd = efi_gd; |
| 66 | #endif |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | /* Called on every callback exit */ |
| 71 | int __efi_exit_check(void) |
| 72 | { |
| 73 | int ret = --entry_count == 0; |
| 74 | #ifdef CONFIG_ARM |
| 75 | gd = app_gd; |
| 76 | #endif |
| 77 | return ret; |
| 78 | } |
| 79 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 80 | /* Called from do_bootefi_exec() */ |
| 81 | void efi_save_gd(void) |
| 82 | { |
Simon Glass | 65e4c0b | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 83 | #ifdef CONFIG_ARM |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 84 | efi_gd = gd; |
Simon Glass | 65e4c0b | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 85 | #endif |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Rob Clark | c160d2f | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 88 | /* |
| 89 | * Special case handler for error/abort that just forces things back |
| 90 | * to u-boot world so we can dump out an abort msg, without any care |
| 91 | * about returning back to UEFI world. |
| 92 | */ |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 93 | void efi_restore_gd(void) |
| 94 | { |
Simon Glass | 65e4c0b | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 95 | #ifdef CONFIG_ARM |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 96 | /* Only restore if we're already in EFI context */ |
| 97 | if (!efi_gd) |
| 98 | return; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 99 | gd = efi_gd; |
Simon Glass | 65e4c0b | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 100 | #endif |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Rob Clark | af65db8 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 103 | /* |
| 104 | * Two spaces per indent level, maxing out at 10.. which ought to be |
| 105 | * enough for anyone ;-) |
| 106 | */ |
| 107 | static const char *indent_string(int level) |
| 108 | { |
| 109 | const char *indent = " "; |
| 110 | const int max = strlen(indent); |
| 111 | level = min(max, level * 2); |
| 112 | return &indent[max - level]; |
| 113 | } |
| 114 | |
Heinrich Schuchardt | ae0bd3a | 2017-08-18 17:45:16 +0200 | [diff] [blame] | 115 | const char *__efi_nesting(void) |
| 116 | { |
| 117 | return indent_string(nesting_level); |
| 118 | } |
| 119 | |
Rob Clark | af65db8 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 120 | const char *__efi_nesting_inc(void) |
| 121 | { |
| 122 | return indent_string(nesting_level++); |
| 123 | } |
| 124 | |
| 125 | const char *__efi_nesting_dec(void) |
| 126 | { |
| 127 | return indent_string(--nesting_level); |
| 128 | } |
| 129 | |
xypron.glpk@gmx.de | 8787b02 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 130 | /* Low 32 bit */ |
| 131 | #define EFI_LOW32(a) (a & 0xFFFFFFFFULL) |
| 132 | /* High 32 bit */ |
| 133 | #define EFI_HIGH32(a) (a >> 32) |
| 134 | |
| 135 | /* |
| 136 | * 64bit division by 10 implemented as multiplication by 1 / 10 |
| 137 | * |
| 138 | * Decimals of one tenth: 0x1 / 0xA = 0x0.19999... |
| 139 | */ |
| 140 | #define EFI_TENTH 0x199999999999999A |
| 141 | static u64 efi_div10(u64 a) |
| 142 | { |
| 143 | u64 prod; |
| 144 | u64 rem; |
| 145 | u64 ret; |
| 146 | |
| 147 | ret = EFI_HIGH32(a) * EFI_HIGH32(EFI_TENTH); |
| 148 | prod = EFI_HIGH32(a) * EFI_LOW32(EFI_TENTH); |
| 149 | rem = EFI_LOW32(prod); |
| 150 | ret += EFI_HIGH32(prod); |
| 151 | prod = EFI_LOW32(a) * EFI_HIGH32(EFI_TENTH); |
| 152 | rem += EFI_LOW32(prod); |
| 153 | ret += EFI_HIGH32(prod); |
| 154 | prod = EFI_LOW32(a) * EFI_LOW32(EFI_TENTH); |
| 155 | rem += EFI_HIGH32(prod); |
| 156 | ret += EFI_HIGH32(rem); |
| 157 | /* Round to nearest integer */ |
| 158 | if (rem >= (1 << 31)) |
| 159 | ++ret; |
| 160 | return ret; |
| 161 | } |
| 162 | |
xypron.glpk@gmx.de | 91be9a7 | 2017-07-18 20:17:22 +0200 | [diff] [blame] | 163 | void efi_signal_event(struct efi_event *event) |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 164 | { |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 165 | if (event->notify_function) { |
| 166 | event->queued = 1; |
Heinrich Schuchardt | 32f4b2f | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 167 | /* Check TPL */ |
| 168 | if (efi_tpl >= event->notify_tpl) |
| 169 | return; |
Heinrich Schuchardt | ea630ce | 2017-09-15 10:06:10 +0200 | [diff] [blame] | 170 | EFI_CALL_VOID(event->notify_function(event, |
| 171 | event->notify_context)); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 172 | } |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 173 | event->queued = 0; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 176 | static efi_status_t efi_unsupported(const char *funcname) |
| 177 | { |
Alexander Graf | edcef3b | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 178 | debug("EFI: App called into unimplemented function %s\n", funcname); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 179 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 180 | } |
| 181 | |
xypron.glpk@gmx.de | 503f269 | 2017-07-18 20:17:19 +0200 | [diff] [blame] | 182 | static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 183 | { |
Heinrich Schuchardt | 32f4b2f | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 184 | UINTN old_tpl = efi_tpl; |
| 185 | |
xypron.glpk@gmx.de | 503f269 | 2017-07-18 20:17:19 +0200 | [diff] [blame] | 186 | EFI_ENTRY("0x%zx", new_tpl); |
Heinrich Schuchardt | 32f4b2f | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 187 | |
| 188 | if (new_tpl < efi_tpl) |
| 189 | debug("WARNING: new_tpl < current_tpl in %s\n", __func__); |
| 190 | efi_tpl = new_tpl; |
| 191 | if (efi_tpl > TPL_HIGH_LEVEL) |
| 192 | efi_tpl = TPL_HIGH_LEVEL; |
| 193 | |
| 194 | EFI_EXIT(EFI_SUCCESS); |
| 195 | return old_tpl; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 196 | } |
| 197 | |
xypron.glpk@gmx.de | 503f269 | 2017-07-18 20:17:19 +0200 | [diff] [blame] | 198 | static void EFIAPI efi_restore_tpl(UINTN old_tpl) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 199 | { |
xypron.glpk@gmx.de | 503f269 | 2017-07-18 20:17:19 +0200 | [diff] [blame] | 200 | EFI_ENTRY("0x%zx", old_tpl); |
Heinrich Schuchardt | 32f4b2f | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 201 | |
| 202 | if (old_tpl > efi_tpl) |
| 203 | debug("WARNING: old_tpl > current_tpl in %s\n", __func__); |
| 204 | efi_tpl = old_tpl; |
| 205 | if (efi_tpl > TPL_HIGH_LEVEL) |
| 206 | efi_tpl = TPL_HIGH_LEVEL; |
| 207 | |
| 208 | EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Masahiro Yamada | 6e0bf8d | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 211 | static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type, |
| 212 | unsigned long pages, |
| 213 | uint64_t *memory) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 214 | { |
| 215 | efi_status_t r; |
| 216 | |
| 217 | EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory); |
| 218 | r = efi_allocate_pages(type, memory_type, pages, memory); |
| 219 | return EFI_EXIT(r); |
| 220 | } |
| 221 | |
Masahiro Yamada | 6e0bf8d | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 222 | static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory, |
| 223 | unsigned long pages) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 224 | { |
| 225 | efi_status_t r; |
| 226 | |
| 227 | EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages); |
| 228 | r = efi_free_pages(memory, pages); |
| 229 | return EFI_EXIT(r); |
| 230 | } |
| 231 | |
Masahiro Yamada | 6e0bf8d | 2017-06-22 17:49:03 +0900 | [diff] [blame] | 232 | static efi_status_t EFIAPI efi_get_memory_map_ext( |
| 233 | unsigned long *memory_map_size, |
| 234 | struct efi_mem_desc *memory_map, |
| 235 | unsigned long *map_key, |
| 236 | unsigned long *descriptor_size, |
| 237 | uint32_t *descriptor_version) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 238 | { |
| 239 | efi_status_t r; |
| 240 | |
| 241 | EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map, |
| 242 | map_key, descriptor_size, descriptor_version); |
| 243 | r = efi_get_memory_map(memory_map_size, memory_map, map_key, |
| 244 | descriptor_size, descriptor_version); |
| 245 | return EFI_EXIT(r); |
| 246 | } |
| 247 | |
Stefan Brüns | ead1274 | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 248 | static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type, |
| 249 | unsigned long size, |
| 250 | void **buffer) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 251 | { |
Alexander Graf | 1cd29f0 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 252 | efi_status_t r; |
| 253 | |
| 254 | EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer); |
Stefan Brüns | ead1274 | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 255 | r = efi_allocate_pool(pool_type, size, buffer); |
Alexander Graf | 1cd29f0 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 256 | return EFI_EXIT(r); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Stefan Brüns | 42417bc | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 259 | static efi_status_t EFIAPI efi_free_pool_ext(void *buffer) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 260 | { |
Alexander Graf | 1cd29f0 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 261 | efi_status_t r; |
| 262 | |
| 263 | EFI_ENTRY("%p", buffer); |
Stefan Brüns | 42417bc | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 264 | r = efi_free_pool(buffer); |
Alexander Graf | 1cd29f0 | 2016-03-24 01:37:37 +0100 | [diff] [blame] | 265 | return EFI_EXIT(r); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 269 | * Our event capabilities are very limited. Only a small limited |
| 270 | * number of events is allowed to coexist. |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 271 | */ |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 272 | static struct efi_event efi_events[16]; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 273 | |
xypron.glpk@gmx.de | b521d29 | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 274 | efi_status_t efi_create_event(uint32_t type, UINTN notify_tpl, |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 275 | void (EFIAPI *notify_function) ( |
xypron.glpk@gmx.de | 2fd945f | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 276 | struct efi_event *event, |
| 277 | void *context), |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 278 | void *notify_context, struct efi_event **event) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 279 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 280 | int i; |
| 281 | |
Jonathan Gray | a95343b | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 282 | if (event == NULL) |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 283 | return EFI_INVALID_PARAMETER; |
Jonathan Gray | a95343b | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 284 | |
| 285 | if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT)) |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 286 | return EFI_INVALID_PARAMETER; |
Jonathan Gray | a95343b | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 287 | |
| 288 | if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) && |
| 289 | notify_function == NULL) |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 290 | return EFI_INVALID_PARAMETER; |
Jonathan Gray | a95343b | 2017-03-12 19:26:07 +1100 | [diff] [blame] | 291 | |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 292 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 293 | if (efi_events[i].type) |
| 294 | continue; |
| 295 | efi_events[i].type = type; |
| 296 | efi_events[i].notify_tpl = notify_tpl; |
| 297 | efi_events[i].notify_function = notify_function; |
| 298 | efi_events[i].notify_context = notify_context; |
| 299 | /* Disable timers on bootup */ |
| 300 | efi_events[i].trigger_next = -1ULL; |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 301 | efi_events[i].queued = 0; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 302 | efi_events[i].signaled = 0; |
| 303 | *event = &efi_events[i]; |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 304 | return EFI_SUCCESS; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 305 | } |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 306 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 307 | } |
| 308 | |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 309 | static efi_status_t EFIAPI efi_create_event_ext( |
xypron.glpk@gmx.de | b521d29 | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 310 | uint32_t type, UINTN notify_tpl, |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 311 | void (EFIAPI *notify_function) ( |
| 312 | struct efi_event *event, |
| 313 | void *context), |
| 314 | void *notify_context, struct efi_event **event) |
| 315 | { |
| 316 | EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function, |
| 317 | notify_context); |
| 318 | return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function, |
| 319 | notify_context, event)); |
| 320 | } |
| 321 | |
| 322 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 323 | /* |
| 324 | * Our timers have to work without interrupts, so we check whenever keyboard |
| 325 | * input or disk accesses happen if enough time elapsed for it to fire. |
| 326 | */ |
| 327 | void efi_timer_check(void) |
| 328 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 329 | int i; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 330 | u64 now = timer_get_us(); |
| 331 | |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 332 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 333 | if (!efi_events[i].type) |
| 334 | continue; |
| 335 | if (efi_events[i].queued) |
| 336 | efi_signal_event(&efi_events[i]); |
| 337 | if (!(efi_events[i].type & EVT_TIMER) || |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 338 | now < efi_events[i].trigger_next) |
| 339 | continue; |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 340 | switch (efi_events[i].trigger_type) { |
| 341 | case EFI_TIMER_RELATIVE: |
| 342 | efi_events[i].trigger_type = EFI_TIMER_STOP; |
| 343 | break; |
| 344 | case EFI_TIMER_PERIODIC: |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 345 | efi_events[i].trigger_next += |
xypron.glpk@gmx.de | 8787b02 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 346 | efi_events[i].trigger_time; |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 347 | break; |
| 348 | default: |
| 349 | continue; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 350 | } |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 351 | efi_events[i].signaled = 1; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 352 | efi_signal_event(&efi_events[i]); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 353 | } |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 354 | WATCHDOG_RESET(); |
| 355 | } |
| 356 | |
xypron.glpk@gmx.de | b521d29 | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 357 | 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] | 358 | uint64_t trigger_time) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 359 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 360 | int i; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 361 | |
xypron.glpk@gmx.de | 8787b02 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 362 | /* |
| 363 | * The parameter defines a multiple of 100ns. |
| 364 | * We use multiples of 1000ns. So divide by 10. |
| 365 | */ |
| 366 | trigger_time = efi_div10(trigger_time); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 367 | |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 368 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 369 | if (event != &efi_events[i]) |
| 370 | continue; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 371 | |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 372 | if (!(event->type & EVT_TIMER)) |
| 373 | break; |
| 374 | switch (type) { |
| 375 | case EFI_TIMER_STOP: |
| 376 | event->trigger_next = -1ULL; |
| 377 | break; |
| 378 | case EFI_TIMER_PERIODIC: |
| 379 | case EFI_TIMER_RELATIVE: |
| 380 | event->trigger_next = |
xypron.glpk@gmx.de | 8787b02 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 381 | timer_get_us() + trigger_time; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 382 | break; |
| 383 | default: |
xypron.glpk@gmx.de | bfc7246 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 384 | return EFI_INVALID_PARAMETER; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 385 | } |
| 386 | event->trigger_type = type; |
| 387 | event->trigger_time = trigger_time; |
Heinrich Schuchardt | 2eca845 | 2017-09-15 10:06:14 +0200 | [diff] [blame] | 388 | event->signaled = 0; |
xypron.glpk@gmx.de | bfc7246 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 389 | return EFI_SUCCESS; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 390 | } |
xypron.glpk@gmx.de | bfc7246 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 391 | return EFI_INVALID_PARAMETER; |
| 392 | } |
| 393 | |
xypron.glpk@gmx.de | b521d29 | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 394 | static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, |
| 395 | enum efi_timer_delay type, |
| 396 | uint64_t trigger_time) |
xypron.glpk@gmx.de | bfc7246 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 397 | { |
| 398 | EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time); |
| 399 | return EFI_EXIT(efi_set_timer(event, type, trigger_time)); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events, |
xypron.glpk@gmx.de | 2fd945f | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 403 | struct efi_event **event, |
| 404 | unsigned long *index) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 405 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 406 | int i, j; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 407 | |
| 408 | EFI_ENTRY("%ld, %p, %p", num_events, event, index); |
| 409 | |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 410 | /* Check parameters */ |
| 411 | if (!num_events || !event) |
| 412 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Heinrich Schuchardt | 32f4b2f | 2017-09-15 10:06:16 +0200 | [diff] [blame] | 413 | /* Check TPL */ |
| 414 | if (efi_tpl != TPL_APPLICATION) |
| 415 | return EFI_EXIT(EFI_UNSUPPORTED); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 416 | for (i = 0; i < num_events; ++i) { |
| 417 | for (j = 0; j < ARRAY_SIZE(efi_events); ++j) { |
| 418 | if (event[i] == &efi_events[j]) |
| 419 | goto known_event; |
| 420 | } |
| 421 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 422 | known_event: |
| 423 | if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL) |
| 424 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 425 | if (!event[i]->signaled) |
| 426 | efi_signal_event(event[i]); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /* Wait for signal */ |
| 430 | for (;;) { |
| 431 | for (i = 0; i < num_events; ++i) { |
| 432 | if (event[i]->signaled) |
| 433 | goto out; |
| 434 | } |
| 435 | /* Allow events to occur. */ |
| 436 | efi_timer_check(); |
| 437 | } |
| 438 | |
| 439 | out: |
| 440 | /* |
| 441 | * Reset the signal which is passed to the caller to allow periodic |
| 442 | * events to occur. |
| 443 | */ |
| 444 | event[i]->signaled = 0; |
| 445 | if (index) |
| 446 | *index = i; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 447 | |
| 448 | return EFI_EXIT(EFI_SUCCESS); |
| 449 | } |
| 450 | |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 451 | 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] | 452 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 453 | int i; |
| 454 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 455 | EFI_ENTRY("%p", event); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 456 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 457 | if (event != &efi_events[i]) |
| 458 | continue; |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 459 | if (event->signaled) |
| 460 | break; |
| 461 | event->signaled = 1; |
| 462 | if (event->type & EVT_NOTIFY_SIGNAL) |
| 463 | efi_signal_event(event); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 464 | break; |
| 465 | } |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 466 | return EFI_EXIT(EFI_SUCCESS); |
| 467 | } |
| 468 | |
xypron.glpk@gmx.de | 2fd945f | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 469 | static efi_status_t EFIAPI efi_close_event(struct efi_event *event) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 470 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 471 | int i; |
| 472 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 473 | EFI_ENTRY("%p", event); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 474 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 475 | if (event == &efi_events[i]) { |
| 476 | event->type = 0; |
| 477 | event->trigger_next = -1ULL; |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 478 | event->queued = 0; |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 479 | event->signaled = 0; |
| 480 | return EFI_EXIT(EFI_SUCCESS); |
| 481 | } |
| 482 | } |
| 483 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 484 | } |
| 485 | |
xypron.glpk@gmx.de | 2fd945f | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 486 | static efi_status_t EFIAPI efi_check_event(struct efi_event *event) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 487 | { |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 488 | int i; |
| 489 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 490 | EFI_ENTRY("%p", event); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 491 | efi_timer_check(); |
| 492 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 493 | if (event != &efi_events[i]) |
| 494 | continue; |
| 495 | if (!event->type || event->type & EVT_NOTIFY_SIGNAL) |
| 496 | break; |
Heinrich Schuchardt | ca62a4f | 2017-09-15 10:06:13 +0200 | [diff] [blame] | 497 | if (!event->signaled) |
| 498 | efi_signal_event(event); |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 499 | if (event->signaled) |
| 500 | return EFI_EXIT(EFI_SUCCESS); |
| 501 | return EFI_EXIT(EFI_NOT_READY); |
| 502 | } |
| 503 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static efi_status_t EFIAPI efi_install_protocol_interface(void **handle, |
| 507 | efi_guid_t *protocol, int protocol_interface_type, |
| 508 | void *protocol_interface) |
| 509 | { |
xypron.glpk@gmx.de | e0549f8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 510 | struct list_head *lhandle; |
| 511 | int i; |
| 512 | efi_status_t r; |
| 513 | |
xypron.glpk@gmx.de | e0549f8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 514 | if (!handle || !protocol || |
| 515 | protocol_interface_type != EFI_NATIVE_INTERFACE) { |
| 516 | r = EFI_INVALID_PARAMETER; |
| 517 | goto out; |
| 518 | } |
| 519 | |
| 520 | /* Create new handle if requested. */ |
| 521 | if (!*handle) { |
| 522 | r = EFI_OUT_OF_RESOURCES; |
| 523 | goto out; |
| 524 | } |
| 525 | /* Find object. */ |
| 526 | list_for_each(lhandle, &efi_obj_list) { |
| 527 | struct efi_object *efiobj; |
| 528 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 529 | |
| 530 | if (efiobj->handle != *handle) |
| 531 | continue; |
| 532 | /* Check if protocol is already installed on the handle. */ |
| 533 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 534 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 535 | |
| 536 | if (!handler->guid) |
| 537 | continue; |
| 538 | if (!guidcmp(handler->guid, protocol)) { |
| 539 | r = EFI_INVALID_PARAMETER; |
| 540 | goto out; |
| 541 | } |
| 542 | } |
| 543 | /* Install protocol in first empty slot. */ |
| 544 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 545 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 546 | |
| 547 | if (handler->guid) |
| 548 | continue; |
| 549 | |
| 550 | handler->guid = protocol; |
| 551 | handler->protocol_interface = protocol_interface; |
| 552 | r = EFI_SUCCESS; |
| 553 | goto out; |
| 554 | } |
| 555 | r = EFI_OUT_OF_RESOURCES; |
| 556 | goto out; |
| 557 | } |
| 558 | r = EFI_INVALID_PARAMETER; |
| 559 | out: |
xypron.glpk@gmx.de | 8bee5a3 | 2017-07-11 22:06:18 +0200 | [diff] [blame] | 560 | return r; |
| 561 | } |
| 562 | |
| 563 | static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle, |
| 564 | efi_guid_t *protocol, int protocol_interface_type, |
| 565 | void *protocol_interface) |
| 566 | { |
| 567 | EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type, |
| 568 | protocol_interface); |
| 569 | |
| 570 | return EFI_EXIT(efi_install_protocol_interface(handle, protocol, |
| 571 | protocol_interface_type, |
| 572 | protocol_interface)); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 573 | } |
xypron.glpk@gmx.de | e0549f8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 574 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 575 | static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle, |
| 576 | efi_guid_t *protocol, void *old_interface, |
| 577 | void *new_interface) |
| 578 | { |
| 579 | EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface, |
| 580 | new_interface); |
| 581 | return EFI_EXIT(EFI_ACCESS_DENIED); |
| 582 | } |
| 583 | |
| 584 | static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle, |
| 585 | efi_guid_t *protocol, void *protocol_interface) |
| 586 | { |
xypron.glpk@gmx.de | 4b6ed0d | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 587 | struct list_head *lhandle; |
| 588 | int i; |
| 589 | efi_status_t r = EFI_NOT_FOUND; |
| 590 | |
xypron.glpk@gmx.de | 4b6ed0d | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 591 | if (!handle || !protocol) { |
| 592 | r = EFI_INVALID_PARAMETER; |
| 593 | goto out; |
| 594 | } |
| 595 | |
| 596 | list_for_each(lhandle, &efi_obj_list) { |
| 597 | struct efi_object *efiobj; |
| 598 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 599 | |
| 600 | if (efiobj->handle != handle) |
| 601 | continue; |
| 602 | |
| 603 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 604 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 605 | const efi_guid_t *hprotocol = handler->guid; |
| 606 | |
| 607 | if (!hprotocol) |
| 608 | continue; |
| 609 | if (!guidcmp(hprotocol, protocol)) { |
| 610 | if (handler->protocol_interface) { |
| 611 | r = EFI_ACCESS_DENIED; |
| 612 | } else { |
| 613 | handler->guid = 0; |
| 614 | r = EFI_SUCCESS; |
| 615 | } |
| 616 | goto out; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | out: |
xypron.glpk@gmx.de | 3d8e145 | 2017-07-11 22:06:19 +0200 | [diff] [blame] | 622 | return r; |
| 623 | } |
| 624 | |
| 625 | static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle, |
| 626 | efi_guid_t *protocol, void *protocol_interface) |
| 627 | { |
| 628 | EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface); |
| 629 | |
| 630 | return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol, |
| 631 | protocol_interface)); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol, |
xypron.glpk@gmx.de | 2fd945f | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 635 | struct efi_event *event, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 636 | void **registration) |
| 637 | { |
| 638 | EFI_ENTRY("%p, %p, %p", protocol, event, registration); |
| 639 | return EFI_EXIT(EFI_OUT_OF_RESOURCES); |
| 640 | } |
| 641 | |
| 642 | static int efi_search(enum efi_locate_search_type search_type, |
| 643 | efi_guid_t *protocol, void *search_key, |
| 644 | struct efi_object *efiobj) |
| 645 | { |
| 646 | int i; |
| 647 | |
| 648 | switch (search_type) { |
| 649 | case all_handles: |
| 650 | return 0; |
| 651 | case by_register_notify: |
| 652 | return -1; |
| 653 | case by_protocol: |
| 654 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 655 | const efi_guid_t *guid = efiobj->protocols[i].guid; |
| 656 | if (guid && !guidcmp(guid, protocol)) |
| 657 | return 0; |
| 658 | } |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | return -1; |
| 663 | } |
| 664 | |
xypron.glpk@gmx.de | ebf199b | 2017-08-09 20:55:00 +0200 | [diff] [blame] | 665 | static efi_status_t efi_locate_handle( |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 666 | enum efi_locate_search_type search_type, |
| 667 | efi_guid_t *protocol, void *search_key, |
| 668 | unsigned long *buffer_size, efi_handle_t *buffer) |
| 669 | { |
| 670 | struct list_head *lhandle; |
| 671 | unsigned long size = 0; |
| 672 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 673 | /* Count how much space we need */ |
| 674 | list_for_each(lhandle, &efi_obj_list) { |
| 675 | struct efi_object *efiobj; |
| 676 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 677 | if (!efi_search(search_type, protocol, search_key, efiobj)) { |
| 678 | size += sizeof(void*); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | if (*buffer_size < size) { |
| 683 | *buffer_size = size; |
xypron.glpk@gmx.de | 2632958 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 684 | return EFI_BUFFER_TOO_SMALL; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Rob Clark | 796a78c | 2017-08-06 14:10:07 -0400 | [diff] [blame] | 687 | *buffer_size = size; |
| 688 | if (size == 0) |
| 689 | return EFI_NOT_FOUND; |
| 690 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 691 | /* Then fill the array */ |
| 692 | list_for_each(lhandle, &efi_obj_list) { |
| 693 | struct efi_object *efiobj; |
| 694 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 695 | if (!efi_search(search_type, protocol, search_key, efiobj)) { |
| 696 | *(buffer++) = efiobj->handle; |
| 697 | } |
| 698 | } |
| 699 | |
xypron.glpk@gmx.de | 2632958 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 700 | return EFI_SUCCESS; |
| 701 | } |
| 702 | |
| 703 | static efi_status_t EFIAPI efi_locate_handle_ext( |
| 704 | enum efi_locate_search_type search_type, |
| 705 | efi_guid_t *protocol, void *search_key, |
| 706 | unsigned long *buffer_size, efi_handle_t *buffer) |
| 707 | { |
| 708 | EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, |
| 709 | buffer_size, buffer); |
| 710 | |
| 711 | return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key, |
| 712 | buffer_size, buffer)); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol, |
| 716 | struct efi_device_path **device_path, |
| 717 | efi_handle_t *device) |
| 718 | { |
Rob Clark | b66c60d | 2017-09-13 18:05:28 -0400 | [diff] [blame] | 719 | struct efi_object *efiobj; |
| 720 | |
| 721 | EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device); |
| 722 | |
| 723 | efiobj = efi_dp_find_obj(*device_path, device_path); |
| 724 | if (!efiobj) |
| 725 | return EFI_EXIT(EFI_NOT_FOUND); |
| 726 | |
| 727 | *device = efiobj->handle; |
| 728 | |
| 729 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 730 | } |
| 731 | |
Alexander Graf | d98cdf6 | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 732 | /* Collapses configuration table entries, removing index i */ |
| 733 | static void efi_remove_configuration_table(int i) |
| 734 | { |
| 735 | struct efi_configuration_table *this = &efi_conf_table[i]; |
| 736 | struct efi_configuration_table *next = &efi_conf_table[i+1]; |
| 737 | struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables]; |
| 738 | |
| 739 | memmove(this, next, (ulong)end - (ulong)next); |
| 740 | systab.nr_tables--; |
| 741 | } |
| 742 | |
Alexander Graf | 488bf12 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 743 | 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] | 744 | { |
| 745 | int i; |
| 746 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 747 | /* Check for guid override */ |
| 748 | for (i = 0; i < systab.nr_tables; i++) { |
| 749 | if (!guidcmp(guid, &efi_conf_table[i].guid)) { |
Alexander Graf | d98cdf6 | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 750 | if (table) |
| 751 | efi_conf_table[i].table = table; |
| 752 | else |
| 753 | efi_remove_configuration_table(i); |
Alexander Graf | 488bf12 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 754 | return EFI_SUCCESS; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
Alexander Graf | d98cdf6 | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 758 | if (!table) |
| 759 | return EFI_NOT_FOUND; |
| 760 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 761 | /* No override, check for overflow */ |
| 762 | if (i >= ARRAY_SIZE(efi_conf_table)) |
Alexander Graf | 488bf12 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 763 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 764 | |
| 765 | /* Add a new entry */ |
| 766 | memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); |
| 767 | efi_conf_table[i].table = table; |
Alexander Graf | aba5e91 | 2016-08-19 01:23:30 +0200 | [diff] [blame] | 768 | systab.nr_tables = i + 1; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 769 | |
Alexander Graf | 488bf12 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 770 | return EFI_SUCCESS; |
| 771 | } |
| 772 | |
| 773 | static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, |
| 774 | void *table) |
| 775 | { |
| 776 | EFI_ENTRY("%p, %p", guid, table); |
| 777 | return EFI_EXIT(efi_install_configuration_table(guid, table)); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 780 | /* Initialize a loaded_image_info + loaded_image_info object with correct |
| 781 | * protocols, boot-device, etc. |
| 782 | */ |
| 783 | void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *obj, |
| 784 | struct efi_device_path *device_path, |
| 785 | struct efi_device_path *file_path) |
| 786 | { |
| 787 | obj->handle = info; |
| 788 | |
| 789 | /* |
| 790 | * When asking for the device path interface, return |
| 791 | * bootefi_device_path |
| 792 | */ |
| 793 | obj->protocols[0].guid = &efi_guid_device_path; |
| 794 | obj->protocols[0].protocol_interface = device_path; |
| 795 | |
| 796 | /* |
| 797 | * When asking for the loaded_image interface, just |
| 798 | * return handle which points to loaded_image_info |
| 799 | */ |
| 800 | obj->protocols[1].guid = &efi_guid_loaded_image; |
| 801 | obj->protocols[1].protocol_interface = info; |
| 802 | |
| 803 | obj->protocols[2].guid = &efi_guid_console_control; |
| 804 | obj->protocols[2].protocol_interface = (void *)&efi_console_control; |
| 805 | |
| 806 | obj->protocols[3].guid = &efi_guid_device_path_to_text_protocol; |
| 807 | obj->protocols[3].protocol_interface = |
| 808 | (void *)&efi_device_path_to_text; |
| 809 | |
| 810 | info->file_path = file_path; |
| 811 | info->device_handle = efi_dp_find_obj(device_path, NULL); |
| 812 | |
| 813 | list_add_tail(&obj->link, &efi_obj_list); |
| 814 | } |
| 815 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 816 | static efi_status_t EFIAPI efi_load_image(bool boot_policy, |
| 817 | efi_handle_t parent_image, |
| 818 | struct efi_device_path *file_path, |
| 819 | void *source_buffer, |
| 820 | unsigned long source_size, |
| 821 | efi_handle_t *image_handle) |
| 822 | { |
| 823 | static struct efi_object loaded_image_info_obj = { |
| 824 | .protocols = { |
| 825 | { |
| 826 | .guid = &efi_guid_loaded_image, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 827 | }, |
| 828 | }, |
| 829 | }; |
| 830 | struct efi_loaded_image *info; |
| 831 | struct efi_object *obj; |
| 832 | |
| 833 | EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, |
| 834 | file_path, source_buffer, source_size, image_handle); |
| 835 | info = malloc(sizeof(*info)); |
xypron.glpk@gmx.de | b5349f7 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 836 | loaded_image_info_obj.protocols[0].protocol_interface = info; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 837 | obj = malloc(sizeof(loaded_image_info_obj)); |
| 838 | memset(info, 0, sizeof(*info)); |
| 839 | memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); |
| 840 | obj->handle = info; |
| 841 | info->file_path = file_path; |
| 842 | info->reserved = efi_load_pe(source_buffer, info); |
| 843 | if (!info->reserved) { |
| 844 | free(info); |
| 845 | free(obj); |
| 846 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 847 | } |
| 848 | |
| 849 | *image_handle = info; |
| 850 | list_add_tail(&obj->link, &efi_obj_list); |
| 851 | |
| 852 | return EFI_EXIT(EFI_SUCCESS); |
| 853 | } |
| 854 | |
| 855 | static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, |
| 856 | unsigned long *exit_data_size, |
| 857 | s16 **exit_data) |
| 858 | { |
| 859 | ulong (*entry)(void *image_handle, struct efi_system_table *st); |
| 860 | struct efi_loaded_image *info = image_handle; |
| 861 | |
| 862 | EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); |
| 863 | entry = info->reserved; |
| 864 | |
| 865 | efi_is_direct_boot = false; |
| 866 | |
| 867 | /* call the image! */ |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 868 | if (setjmp(&info->exit_jmp)) { |
| 869 | /* We returned from the child image */ |
| 870 | return EFI_EXIT(info->exit_status); |
| 871 | } |
| 872 | |
Rob Clark | af65db8 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 873 | __efi_nesting_dec(); |
Rob Clark | c160d2f | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 874 | __efi_exit_check(); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 875 | entry(image_handle, &systab); |
Rob Clark | c160d2f | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 876 | __efi_entry_check(); |
Rob Clark | af65db8 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 877 | __efi_nesting_inc(); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 878 | |
| 879 | /* Should usually never get here */ |
| 880 | return EFI_EXIT(EFI_SUCCESS); |
| 881 | } |
| 882 | |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 883 | static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, |
| 884 | efi_status_t exit_status, unsigned long exit_data_size, |
| 885 | int16_t *exit_data) |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 886 | { |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 887 | struct efi_loaded_image *loaded_image_info = (void*)image_handle; |
| 888 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 889 | EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, |
| 890 | exit_data_size, exit_data); |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 891 | |
Alexander Graf | a148920 | 2017-09-03 14:14:17 +0200 | [diff] [blame] | 892 | /* Make sure entry/exit counts for EFI world cross-overs match */ |
Heinrich Schuchardt | da94073 | 2017-08-25 19:53:14 +0200 | [diff] [blame] | 893 | __efi_exit_check(); |
| 894 | |
Alexander Graf | a148920 | 2017-09-03 14:14:17 +0200 | [diff] [blame] | 895 | /* |
| 896 | * But longjmp out with the U-Boot gd, not the application's, as |
| 897 | * the other end is a setjmp call inside EFI context. |
| 898 | */ |
| 899 | efi_restore_gd(); |
| 900 | |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 901 | loaded_image_info->exit_status = exit_status; |
Alexander Graf | 692fcdd | 2016-09-27 09:30:32 +0200 | [diff] [blame] | 902 | longjmp(&loaded_image_info->exit_jmp, 1); |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 903 | |
| 904 | panic("EFI application exited"); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | static struct efi_object *efi_search_obj(void *handle) |
| 908 | { |
| 909 | struct list_head *lhandle; |
| 910 | |
| 911 | list_for_each(lhandle, &efi_obj_list) { |
| 912 | struct efi_object *efiobj; |
| 913 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 914 | if (efiobj->handle == handle) |
| 915 | return efiobj; |
| 916 | } |
| 917 | |
| 918 | return NULL; |
| 919 | } |
| 920 | |
| 921 | static efi_status_t EFIAPI efi_unload_image(void *image_handle) |
| 922 | { |
| 923 | struct efi_object *efiobj; |
| 924 | |
| 925 | EFI_ENTRY("%p", image_handle); |
| 926 | efiobj = efi_search_obj(image_handle); |
| 927 | if (efiobj) |
| 928 | list_del(&efiobj->link); |
| 929 | |
| 930 | return EFI_EXIT(EFI_SUCCESS); |
| 931 | } |
| 932 | |
| 933 | static void efi_exit_caches(void) |
| 934 | { |
| 935 | #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) |
| 936 | /* |
| 937 | * Grub on 32bit ARM needs to have caches disabled before jumping into |
| 938 | * a zImage, but does not know of all cache layers. Give it a hand. |
| 939 | */ |
| 940 | if (efi_is_direct_boot) |
| 941 | cleanup_before_linux(); |
| 942 | #endif |
| 943 | } |
| 944 | |
| 945 | static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, |
| 946 | unsigned long map_key) |
| 947 | { |
Heinrich Schuchardt | 152a263 | 2017-09-15 10:06:18 +0200 | [diff] [blame] | 948 | int i; |
| 949 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 950 | EFI_ENTRY("%p, %ld", image_handle, map_key); |
| 951 | |
Heinrich Schuchardt | 152a263 | 2017-09-15 10:06:18 +0200 | [diff] [blame] | 952 | /* Notify that ExitBootServices is invoked. */ |
| 953 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 954 | if (efi_events[i].type != EVT_SIGNAL_EXIT_BOOT_SERVICES) |
| 955 | continue; |
| 956 | efi_signal_event(&efi_events[i]); |
| 957 | } |
| 958 | /* Make sure that notification functions are not called anymore */ |
| 959 | efi_tpl = TPL_HIGH_LEVEL; |
| 960 | |
Alexander Graf | b7b8410 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 961 | board_quiesce_devices(); |
| 962 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 963 | /* Fix up caches for EFI payloads if necessary */ |
| 964 | efi_exit_caches(); |
| 965 | |
| 966 | /* This stops all lingering devices */ |
| 967 | bootm_disable_interrupts(); |
| 968 | |
| 969 | /* Give the payload some time to boot */ |
| 970 | WATCHDOG_RESET(); |
| 971 | |
| 972 | return EFI_EXIT(EFI_SUCCESS); |
| 973 | } |
| 974 | |
| 975 | static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) |
| 976 | { |
| 977 | static uint64_t mono = 0; |
| 978 | EFI_ENTRY("%p", count); |
| 979 | *count = mono++; |
| 980 | return EFI_EXIT(EFI_SUCCESS); |
| 981 | } |
| 982 | |
| 983 | static efi_status_t EFIAPI efi_stall(unsigned long microseconds) |
| 984 | { |
| 985 | EFI_ENTRY("%ld", microseconds); |
| 986 | udelay(microseconds); |
| 987 | return EFI_EXIT(EFI_SUCCESS); |
| 988 | } |
| 989 | |
| 990 | static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, |
| 991 | uint64_t watchdog_code, |
| 992 | unsigned long data_size, |
| 993 | uint16_t *watchdog_data) |
| 994 | { |
| 995 | EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, |
| 996 | data_size, watchdog_data); |
Rob Clark | b510482 | 2017-07-25 20:17:59 -0400 | [diff] [blame] | 997 | return efi_unsupported(__func__); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | static efi_status_t EFIAPI efi_connect_controller( |
| 1001 | efi_handle_t controller_handle, |
| 1002 | efi_handle_t *driver_image_handle, |
| 1003 | struct efi_device_path *remain_device_path, |
| 1004 | bool recursive) |
| 1005 | { |
| 1006 | EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle, |
| 1007 | remain_device_path, recursive); |
| 1008 | return EFI_EXIT(EFI_NOT_FOUND); |
| 1009 | } |
| 1010 | |
| 1011 | static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle, |
| 1012 | void *driver_image_handle, |
| 1013 | void *child_handle) |
| 1014 | { |
| 1015 | EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, |
| 1016 | child_handle); |
| 1017 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1018 | } |
| 1019 | |
| 1020 | static efi_status_t EFIAPI efi_close_protocol(void *handle, |
| 1021 | efi_guid_t *protocol, |
| 1022 | void *agent_handle, |
| 1023 | void *controller_handle) |
| 1024 | { |
| 1025 | EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle, |
| 1026 | controller_handle); |
| 1027 | return EFI_EXIT(EFI_NOT_FOUND); |
| 1028 | } |
| 1029 | |
| 1030 | static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, |
| 1031 | efi_guid_t *protocol, |
| 1032 | struct efi_open_protocol_info_entry **entry_buffer, |
| 1033 | unsigned long *entry_count) |
| 1034 | { |
| 1035 | EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, |
| 1036 | entry_count); |
| 1037 | return EFI_EXIT(EFI_NOT_FOUND); |
| 1038 | } |
| 1039 | |
| 1040 | static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, |
| 1041 | efi_guid_t ***protocol_buffer, |
| 1042 | unsigned long *protocol_buffer_count) |
| 1043 | { |
xypron.glpk@gmx.de | c0ebfc8 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 1044 | unsigned long buffer_size; |
| 1045 | struct efi_object *efiobj; |
| 1046 | unsigned long i, j; |
| 1047 | struct list_head *lhandle; |
| 1048 | efi_status_t r; |
| 1049 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1050 | EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, |
| 1051 | protocol_buffer_count); |
xypron.glpk@gmx.de | c0ebfc8 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 1052 | |
| 1053 | if (!handle || !protocol_buffer || !protocol_buffer_count) |
| 1054 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1055 | |
| 1056 | *protocol_buffer = NULL; |
Rob Clark | 661c832 | 2017-07-20 07:59:39 -0400 | [diff] [blame] | 1057 | *protocol_buffer_count = 0; |
xypron.glpk@gmx.de | c0ebfc8 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 1058 | list_for_each(lhandle, &efi_obj_list) { |
| 1059 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 1060 | |
| 1061 | if (efiobj->handle != handle) |
| 1062 | continue; |
| 1063 | |
| 1064 | /* Count protocols */ |
| 1065 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 1066 | if (efiobj->protocols[i].guid) |
| 1067 | ++*protocol_buffer_count; |
| 1068 | } |
| 1069 | /* Copy guids */ |
| 1070 | if (*protocol_buffer_count) { |
| 1071 | buffer_size = sizeof(efi_guid_t *) * |
| 1072 | *protocol_buffer_count; |
| 1073 | r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, |
| 1074 | buffer_size, |
| 1075 | (void **)protocol_buffer); |
| 1076 | if (r != EFI_SUCCESS) |
| 1077 | return EFI_EXIT(r); |
| 1078 | j = 0; |
| 1079 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) { |
| 1080 | if (efiobj->protocols[i].guid) { |
| 1081 | (*protocol_buffer)[j] = (void *) |
| 1082 | efiobj->protocols[i].guid; |
| 1083 | ++j; |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static efi_status_t EFIAPI efi_locate_handle_buffer( |
| 1094 | enum efi_locate_search_type search_type, |
| 1095 | efi_guid_t *protocol, void *search_key, |
| 1096 | unsigned long *no_handles, efi_handle_t **buffer) |
| 1097 | { |
xypron.glpk@gmx.de | c2e703f | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 1098 | efi_status_t r; |
| 1099 | unsigned long buffer_size = 0; |
| 1100 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1101 | EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, |
| 1102 | no_handles, buffer); |
xypron.glpk@gmx.de | c2e703f | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 1103 | |
| 1104 | if (!no_handles || !buffer) { |
| 1105 | r = EFI_INVALID_PARAMETER; |
| 1106 | goto out; |
| 1107 | } |
| 1108 | *no_handles = 0; |
| 1109 | *buffer = NULL; |
| 1110 | r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, |
| 1111 | *buffer); |
| 1112 | if (r != EFI_BUFFER_TOO_SMALL) |
| 1113 | goto out; |
| 1114 | r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, |
| 1115 | (void **)buffer); |
| 1116 | if (r != EFI_SUCCESS) |
| 1117 | goto out; |
| 1118 | r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, |
| 1119 | *buffer); |
| 1120 | if (r == EFI_SUCCESS) |
| 1121 | *no_handles = buffer_size / sizeof(void *); |
| 1122 | out: |
| 1123 | return EFI_EXIT(r); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1126 | static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol, |
| 1127 | void *registration, |
| 1128 | void **protocol_interface) |
| 1129 | { |
xypron.glpk@gmx.de | 88adae5 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1130 | struct list_head *lhandle; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1131 | int i; |
| 1132 | |
| 1133 | EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface); |
xypron.glpk@gmx.de | 88adae5 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1134 | |
| 1135 | if (!protocol || !protocol_interface) |
| 1136 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1137 | |
Heinrich Schuchardt | ae0bd3a | 2017-08-18 17:45:16 +0200 | [diff] [blame] | 1138 | EFI_PRINT_GUID("protocol", protocol); |
| 1139 | |
xypron.glpk@gmx.de | 88adae5 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1140 | list_for_each(lhandle, &efi_obj_list) { |
| 1141 | struct efi_object *efiobj; |
| 1142 | |
| 1143 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 1144 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 1145 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 1146 | |
| 1147 | if (!handler->guid) |
| 1148 | continue; |
| 1149 | if (!guidcmp(handler->guid, protocol)) { |
| 1150 | *protocol_interface = |
| 1151 | handler->protocol_interface; |
| 1152 | return EFI_EXIT(EFI_SUCCESS); |
| 1153 | } |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1154 | } |
| 1155 | } |
xypron.glpk@gmx.de | 88adae5 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1156 | *protocol_interface = NULL; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1157 | |
| 1158 | return EFI_EXIT(EFI_NOT_FOUND); |
| 1159 | } |
| 1160 | |
| 1161 | static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( |
| 1162 | void **handle, ...) |
| 1163 | { |
| 1164 | EFI_ENTRY("%p", handle); |
xypron.glpk@gmx.de | 58b8358 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 1165 | |
| 1166 | va_list argptr; |
| 1167 | efi_guid_t *protocol; |
| 1168 | void *protocol_interface; |
| 1169 | efi_status_t r = EFI_SUCCESS; |
| 1170 | int i = 0; |
| 1171 | |
| 1172 | if (!handle) |
| 1173 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1174 | |
| 1175 | va_start(argptr, handle); |
| 1176 | for (;;) { |
| 1177 | protocol = va_arg(argptr, efi_guid_t*); |
| 1178 | if (!protocol) |
| 1179 | break; |
| 1180 | protocol_interface = va_arg(argptr, void*); |
| 1181 | r = efi_install_protocol_interface(handle, protocol, |
| 1182 | EFI_NATIVE_INTERFACE, |
| 1183 | protocol_interface); |
| 1184 | if (r != EFI_SUCCESS) |
| 1185 | break; |
| 1186 | i++; |
| 1187 | } |
| 1188 | va_end(argptr); |
| 1189 | if (r == EFI_SUCCESS) |
| 1190 | return EFI_EXIT(r); |
| 1191 | |
| 1192 | /* If an error occured undo all changes. */ |
| 1193 | va_start(argptr, handle); |
| 1194 | for (; i; --i) { |
| 1195 | protocol = va_arg(argptr, efi_guid_t*); |
| 1196 | protocol_interface = va_arg(argptr, void*); |
| 1197 | efi_uninstall_protocol_interface(handle, protocol, |
| 1198 | protocol_interface); |
| 1199 | } |
| 1200 | va_end(argptr); |
| 1201 | |
| 1202 | return EFI_EXIT(r); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( |
| 1206 | void *handle, ...) |
| 1207 | { |
| 1208 | EFI_ENTRY("%p", handle); |
| 1209 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1210 | } |
| 1211 | |
| 1212 | static efi_status_t EFIAPI efi_calculate_crc32(void *data, |
| 1213 | unsigned long data_size, |
| 1214 | uint32_t *crc32_p) |
| 1215 | { |
| 1216 | EFI_ENTRY("%p, %ld", data, data_size); |
| 1217 | *crc32_p = crc32(0, data, data_size); |
| 1218 | return EFI_EXIT(EFI_SUCCESS); |
| 1219 | } |
| 1220 | |
| 1221 | static void EFIAPI efi_copy_mem(void *destination, void *source, |
| 1222 | unsigned long length) |
| 1223 | { |
| 1224 | EFI_ENTRY("%p, %p, %ld", destination, source, length); |
| 1225 | memcpy(destination, source, length); |
| 1226 | } |
| 1227 | |
| 1228 | static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value) |
| 1229 | { |
| 1230 | EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value); |
| 1231 | memset(buffer, value, size); |
| 1232 | } |
| 1233 | |
| 1234 | static efi_status_t EFIAPI efi_open_protocol( |
| 1235 | void *handle, efi_guid_t *protocol, |
| 1236 | void **protocol_interface, void *agent_handle, |
| 1237 | void *controller_handle, uint32_t attributes) |
| 1238 | { |
| 1239 | struct list_head *lhandle; |
| 1240 | int i; |
xypron.glpk@gmx.de | 69baec6 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1241 | efi_status_t r = EFI_INVALID_PARAMETER; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1242 | |
| 1243 | EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol, |
| 1244 | protocol_interface, agent_handle, controller_handle, |
| 1245 | attributes); |
xypron.glpk@gmx.de | b5349f7 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 1246 | |
xypron.glpk@gmx.de | 69baec6 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1247 | if (!handle || !protocol || |
| 1248 | (!protocol_interface && attributes != |
| 1249 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) { |
| 1250 | goto out; |
| 1251 | } |
| 1252 | |
Heinrich Schuchardt | ae0bd3a | 2017-08-18 17:45:16 +0200 | [diff] [blame] | 1253 | EFI_PRINT_GUID("protocol", protocol); |
| 1254 | |
xypron.glpk@gmx.de | 69baec6 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1255 | switch (attributes) { |
| 1256 | case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: |
| 1257 | case EFI_OPEN_PROTOCOL_GET_PROTOCOL: |
| 1258 | case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: |
| 1259 | break; |
| 1260 | case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: |
| 1261 | if (controller_handle == handle) |
| 1262 | goto out; |
| 1263 | case EFI_OPEN_PROTOCOL_BY_DRIVER: |
| 1264 | case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: |
| 1265 | if (controller_handle == NULL) |
| 1266 | goto out; |
| 1267 | case EFI_OPEN_PROTOCOL_EXCLUSIVE: |
| 1268 | if (agent_handle == NULL) |
| 1269 | goto out; |
| 1270 | break; |
| 1271 | default: |
xypron.glpk@gmx.de | b5349f7 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 1272 | goto out; |
| 1273 | } |
| 1274 | |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1275 | list_for_each(lhandle, &efi_obj_list) { |
| 1276 | struct efi_object *efiobj; |
| 1277 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 1278 | |
| 1279 | if (efiobj->handle != handle) |
| 1280 | continue; |
| 1281 | |
| 1282 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 1283 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 1284 | const efi_guid_t *hprotocol = handler->guid; |
| 1285 | if (!hprotocol) |
xypron.glpk@gmx.de | 4b6ed0d | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 1286 | continue; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1287 | if (!guidcmp(hprotocol, protocol)) { |
xypron.glpk@gmx.de | b5349f7 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 1288 | if (attributes != |
| 1289 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { |
| 1290 | *protocol_interface = |
| 1291 | handler->protocol_interface; |
| 1292 | } |
| 1293 | r = EFI_SUCCESS; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1294 | goto out; |
| 1295 | } |
| 1296 | } |
xypron.glpk@gmx.de | 69baec6 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1297 | goto unsupported; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
xypron.glpk@gmx.de | 69baec6 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1300 | unsupported: |
| 1301 | r = EFI_UNSUPPORTED; |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1302 | out: |
| 1303 | return EFI_EXIT(r); |
| 1304 | } |
| 1305 | |
| 1306 | static efi_status_t EFIAPI efi_handle_protocol(void *handle, |
| 1307 | efi_guid_t *protocol, |
| 1308 | void **protocol_interface) |
| 1309 | { |
xypron.glpk@gmx.de | 8e1d329 | 2017-06-29 21:16:19 +0200 | [diff] [blame] | 1310 | return efi_open_protocol(handle, protocol, protocol_interface, NULL, |
| 1311 | NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static const struct efi_boot_services efi_boot_services = { |
| 1315 | .hdr = { |
| 1316 | .headersize = sizeof(struct efi_table_hdr), |
| 1317 | }, |
| 1318 | .raise_tpl = efi_raise_tpl, |
| 1319 | .restore_tpl = efi_restore_tpl, |
| 1320 | .allocate_pages = efi_allocate_pages_ext, |
| 1321 | .free_pages = efi_free_pages_ext, |
| 1322 | .get_memory_map = efi_get_memory_map_ext, |
Stefan Brüns | ead1274 | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 1323 | .allocate_pool = efi_allocate_pool_ext, |
Stefan Brüns | 42417bc | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 1324 | .free_pool = efi_free_pool_ext, |
xypron.glpk@gmx.de | 49deb45 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 1325 | .create_event = efi_create_event_ext, |
xypron.glpk@gmx.de | bfc7246 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 1326 | .set_timer = efi_set_timer_ext, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1327 | .wait_for_event = efi_wait_for_event, |
xypron.glpk@gmx.de | c684159 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 1328 | .signal_event = efi_signal_event_ext, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1329 | .close_event = efi_close_event, |
| 1330 | .check_event = efi_check_event, |
xypron.glpk@gmx.de | 8bee5a3 | 2017-07-11 22:06:18 +0200 | [diff] [blame] | 1331 | .install_protocol_interface = efi_install_protocol_interface_ext, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1332 | .reinstall_protocol_interface = efi_reinstall_protocol_interface, |
xypron.glpk@gmx.de | 3d8e145 | 2017-07-11 22:06:19 +0200 | [diff] [blame] | 1333 | .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1334 | .handle_protocol = efi_handle_protocol, |
| 1335 | .reserved = NULL, |
| 1336 | .register_protocol_notify = efi_register_protocol_notify, |
xypron.glpk@gmx.de | 2632958 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1337 | .locate_handle = efi_locate_handle_ext, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1338 | .locate_device_path = efi_locate_device_path, |
Alexander Graf | 488bf12 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 1339 | .install_configuration_table = efi_install_configuration_table_ext, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1340 | .load_image = efi_load_image, |
| 1341 | .start_image = efi_start_image, |
Alexander Graf | a86aeaf | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 1342 | .exit = efi_exit, |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1343 | .unload_image = efi_unload_image, |
| 1344 | .exit_boot_services = efi_exit_boot_services, |
| 1345 | .get_next_monotonic_count = efi_get_next_monotonic_count, |
| 1346 | .stall = efi_stall, |
| 1347 | .set_watchdog_timer = efi_set_watchdog_timer, |
| 1348 | .connect_controller = efi_connect_controller, |
| 1349 | .disconnect_controller = efi_disconnect_controller, |
| 1350 | .open_protocol = efi_open_protocol, |
| 1351 | .close_protocol = efi_close_protocol, |
| 1352 | .open_protocol_information = efi_open_protocol_information, |
| 1353 | .protocols_per_handle = efi_protocols_per_handle, |
| 1354 | .locate_handle_buffer = efi_locate_handle_buffer, |
| 1355 | .locate_protocol = efi_locate_protocol, |
| 1356 | .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces, |
| 1357 | .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces, |
| 1358 | .calculate_crc32 = efi_calculate_crc32, |
| 1359 | .copy_mem = efi_copy_mem, |
| 1360 | .set_mem = efi_set_mem, |
| 1361 | }; |
| 1362 | |
| 1363 | |
Alexander Graf | 3c63db9 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 1364 | static uint16_t __efi_runtime_data firmware_vendor[] = |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1365 | { 'D','a','s',' ','U','-','b','o','o','t',0 }; |
| 1366 | |
Alexander Graf | 3c63db9 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 1367 | struct efi_system_table __efi_runtime_data systab = { |
Alexander Graf | bee9116 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1368 | .hdr = { |
| 1369 | .signature = EFI_SYSTEM_TABLE_SIGNATURE, |
| 1370 | .revision = 0x20005, /* 2.5 */ |
| 1371 | .headersize = sizeof(struct efi_table_hdr), |
| 1372 | }, |
| 1373 | .fw_vendor = (long)firmware_vendor, |
| 1374 | .con_in = (void*)&efi_con_in, |
| 1375 | .con_out = (void*)&efi_con_out, |
| 1376 | .std_err = (void*)&efi_con_out, |
| 1377 | .runtime = (void*)&efi_runtime_services, |
| 1378 | .boottime = (void*)&efi_boot_services, |
| 1379 | .nr_tables = 0, |
| 1380 | .tables = (void*)efi_conf_table, |
| 1381 | }; |