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