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 | { |
| 162 | if (event->signaled) |
| 163 | return; |
| 164 | event->signaled = 1; |
| 165 | if (event->type & EVT_NOTIFY_SIGNAL) { |
Heinrich Schuchardt | 91e5b8a | 2017-09-15 10:06:10 +0200 | [diff] [blame^] | 166 | EFI_CALL_VOID(event->notify_function(event, |
| 167 | event->notify_context)); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 168 | } |
| 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; |
| 279 | efi_events[i].signaled = 0; |
| 280 | *event = &efi_events[i]; |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 281 | return EFI_SUCCESS; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 282 | } |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 283 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 284 | } |
| 285 | |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 286 | static efi_status_t EFIAPI efi_create_event_ext( |
xypron.glpk@gmx.de | 3ecc6bd | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 287 | uint32_t type, UINTN notify_tpl, |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 288 | void (EFIAPI *notify_function) ( |
| 289 | struct efi_event *event, |
| 290 | void *context), |
| 291 | void *notify_context, struct efi_event **event) |
| 292 | { |
| 293 | EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function, |
| 294 | notify_context); |
| 295 | return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function, |
| 296 | notify_context, event)); |
| 297 | } |
| 298 | |
| 299 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 300 | /* |
| 301 | * Our timers have to work without interrupts, so we check whenever keyboard |
| 302 | * input or disk accesses happen if enough time elapsed for it to fire. |
| 303 | */ |
| 304 | void efi_timer_check(void) |
| 305 | { |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 306 | int i; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 307 | u64 now = timer_get_us(); |
| 308 | |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 309 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 310 | if (!efi_events[i].type || |
| 311 | !(efi_events[i].type & EVT_TIMER) || |
| 312 | efi_events[i].trigger_type == EFI_TIMER_STOP || |
| 313 | now < efi_events[i].trigger_next) |
| 314 | continue; |
| 315 | if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) { |
| 316 | efi_events[i].trigger_next += |
xypron.glpk@gmx.de | 44c4be0 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 317 | efi_events[i].trigger_time; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 318 | efi_events[i].signaled = 0; |
| 319 | } |
| 320 | efi_signal_event(&efi_events[i]); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 321 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 322 | WATCHDOG_RESET(); |
| 323 | } |
| 324 | |
xypron.glpk@gmx.de | 3ecc6bd | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 325 | 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] | 326 | uint64_t trigger_time) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 327 | { |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 328 | int i; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 329 | |
xypron.glpk@gmx.de | 44c4be0 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 330 | /* |
| 331 | * The parameter defines a multiple of 100ns. |
| 332 | * We use multiples of 1000ns. So divide by 10. |
| 333 | */ |
| 334 | trigger_time = efi_div10(trigger_time); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 335 | |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 336 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 337 | if (event != &efi_events[i]) |
| 338 | continue; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 339 | |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 340 | if (!(event->type & EVT_TIMER)) |
| 341 | break; |
| 342 | switch (type) { |
| 343 | case EFI_TIMER_STOP: |
| 344 | event->trigger_next = -1ULL; |
| 345 | break; |
| 346 | case EFI_TIMER_PERIODIC: |
| 347 | case EFI_TIMER_RELATIVE: |
| 348 | event->trigger_next = |
xypron.glpk@gmx.de | 44c4be0 | 2017-07-18 20:17:23 +0200 | [diff] [blame] | 349 | timer_get_us() + trigger_time; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 350 | break; |
| 351 | default: |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 352 | return EFI_INVALID_PARAMETER; |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 353 | } |
| 354 | event->trigger_type = type; |
| 355 | event->trigger_time = trigger_time; |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 356 | return EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 357 | } |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 358 | return EFI_INVALID_PARAMETER; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 359 | } |
| 360 | |
xypron.glpk@gmx.de | 3ecc6bd | 2017-07-19 19:22:34 +0200 | [diff] [blame] | 361 | static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, |
| 362 | enum efi_timer_delay type, |
| 363 | uint64_t trigger_time) |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 364 | { |
| 365 | EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time); |
| 366 | return EFI_EXIT(efi_set_timer(event, type, trigger_time)); |
| 367 | } |
| 368 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 369 | 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] | 370 | struct efi_event **event, |
| 371 | unsigned long *index) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 372 | { |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 373 | int i, j; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 374 | |
| 375 | EFI_ENTRY("%ld, %p, %p", num_events, event, index); |
| 376 | |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 377 | /* Check parameters */ |
| 378 | if (!num_events || !event) |
| 379 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 380 | for (i = 0; i < num_events; ++i) { |
| 381 | for (j = 0; j < ARRAY_SIZE(efi_events); ++j) { |
| 382 | if (event[i] == &efi_events[j]) |
| 383 | goto known_event; |
| 384 | } |
| 385 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 386 | known_event: |
| 387 | if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL) |
| 388 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 389 | } |
| 390 | |
| 391 | /* Wait for signal */ |
| 392 | for (;;) { |
| 393 | for (i = 0; i < num_events; ++i) { |
| 394 | if (event[i]->signaled) |
| 395 | goto out; |
| 396 | } |
| 397 | /* Allow events to occur. */ |
| 398 | efi_timer_check(); |
| 399 | } |
| 400 | |
| 401 | out: |
| 402 | /* |
| 403 | * Reset the signal which is passed to the caller to allow periodic |
| 404 | * events to occur. |
| 405 | */ |
| 406 | event[i]->signaled = 0; |
| 407 | if (index) |
| 408 | *index = i; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 409 | |
| 410 | return EFI_EXIT(EFI_SUCCESS); |
| 411 | } |
| 412 | |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 413 | 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] | 414 | { |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 415 | int i; |
| 416 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 417 | EFI_ENTRY("%p", event); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 418 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 419 | if (event != &efi_events[i]) |
| 420 | continue; |
| 421 | efi_signal_event(event); |
| 422 | break; |
| 423 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 424 | return EFI_EXIT(EFI_SUCCESS); |
| 425 | } |
| 426 | |
xypron.glpk@gmx.de | cdbf3ac | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 427 | static efi_status_t EFIAPI efi_close_event(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 | event->type = 0; |
| 435 | event->trigger_next = -1ULL; |
| 436 | event->signaled = 0; |
| 437 | return EFI_EXIT(EFI_SUCCESS); |
| 438 | } |
| 439 | } |
| 440 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 441 | } |
| 442 | |
xypron.glpk@gmx.de | cdbf3ac | 2017-07-18 20:17:17 +0200 | [diff] [blame] | 443 | static efi_status_t EFIAPI efi_check_event(struct efi_event *event) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 444 | { |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 445 | int i; |
| 446 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 447 | EFI_ENTRY("%p", event); |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 448 | efi_timer_check(); |
| 449 | for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { |
| 450 | if (event != &efi_events[i]) |
| 451 | continue; |
| 452 | if (!event->type || event->type & EVT_NOTIFY_SIGNAL) |
| 453 | break; |
| 454 | if (event->signaled) |
| 455 | return EFI_EXIT(EFI_SUCCESS); |
| 456 | return EFI_EXIT(EFI_NOT_READY); |
| 457 | } |
| 458 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static efi_status_t EFIAPI efi_install_protocol_interface(void **handle, |
| 462 | efi_guid_t *protocol, int protocol_interface_type, |
| 463 | void *protocol_interface) |
| 464 | { |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 465 | struct list_head *lhandle; |
| 466 | int i; |
| 467 | efi_status_t r; |
| 468 | |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 469 | if (!handle || !protocol || |
| 470 | protocol_interface_type != EFI_NATIVE_INTERFACE) { |
| 471 | r = EFI_INVALID_PARAMETER; |
| 472 | goto out; |
| 473 | } |
| 474 | |
| 475 | /* Create new handle if requested. */ |
| 476 | if (!*handle) { |
| 477 | r = EFI_OUT_OF_RESOURCES; |
| 478 | goto out; |
| 479 | } |
| 480 | /* Find object. */ |
| 481 | list_for_each(lhandle, &efi_obj_list) { |
| 482 | struct efi_object *efiobj; |
| 483 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 484 | |
| 485 | if (efiobj->handle != *handle) |
| 486 | continue; |
| 487 | /* Check if protocol is already installed on the handle. */ |
| 488 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 489 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 490 | |
| 491 | if (!handler->guid) |
| 492 | continue; |
| 493 | if (!guidcmp(handler->guid, protocol)) { |
| 494 | r = EFI_INVALID_PARAMETER; |
| 495 | goto out; |
| 496 | } |
| 497 | } |
| 498 | /* Install protocol in first empty slot. */ |
| 499 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 500 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 501 | |
| 502 | if (handler->guid) |
| 503 | continue; |
| 504 | |
| 505 | handler->guid = protocol; |
| 506 | handler->protocol_interface = protocol_interface; |
| 507 | r = EFI_SUCCESS; |
| 508 | goto out; |
| 509 | } |
| 510 | r = EFI_OUT_OF_RESOURCES; |
| 511 | goto out; |
| 512 | } |
| 513 | r = EFI_INVALID_PARAMETER; |
| 514 | out: |
xypron.glpk@gmx.de | 8b7b5df | 2017-07-11 22:06:18 +0200 | [diff] [blame] | 515 | return r; |
| 516 | } |
| 517 | |
| 518 | static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle, |
| 519 | efi_guid_t *protocol, int protocol_interface_type, |
| 520 | void *protocol_interface) |
| 521 | { |
| 522 | EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type, |
| 523 | protocol_interface); |
| 524 | |
| 525 | return EFI_EXIT(efi_install_protocol_interface(handle, protocol, |
| 526 | protocol_interface_type, |
| 527 | protocol_interface)); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 528 | } |
xypron.glpk@gmx.de | 0581fa8 | 2017-07-11 22:06:16 +0200 | [diff] [blame] | 529 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 530 | static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle, |
| 531 | efi_guid_t *protocol, void *old_interface, |
| 532 | void *new_interface) |
| 533 | { |
| 534 | EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface, |
| 535 | new_interface); |
| 536 | return EFI_EXIT(EFI_ACCESS_DENIED); |
| 537 | } |
| 538 | |
| 539 | static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle, |
| 540 | efi_guid_t *protocol, void *protocol_interface) |
| 541 | { |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 542 | struct list_head *lhandle; |
| 543 | int i; |
| 544 | efi_status_t r = EFI_NOT_FOUND; |
| 545 | |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 546 | if (!handle || !protocol) { |
| 547 | r = EFI_INVALID_PARAMETER; |
| 548 | goto out; |
| 549 | } |
| 550 | |
| 551 | list_for_each(lhandle, &efi_obj_list) { |
| 552 | struct efi_object *efiobj; |
| 553 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 554 | |
| 555 | if (efiobj->handle != handle) |
| 556 | continue; |
| 557 | |
| 558 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 559 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 560 | const efi_guid_t *hprotocol = handler->guid; |
| 561 | |
| 562 | if (!hprotocol) |
| 563 | continue; |
| 564 | if (!guidcmp(hprotocol, protocol)) { |
| 565 | if (handler->protocol_interface) { |
| 566 | r = EFI_ACCESS_DENIED; |
| 567 | } else { |
| 568 | handler->guid = 0; |
| 569 | r = EFI_SUCCESS; |
| 570 | } |
| 571 | goto out; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | out: |
xypron.glpk@gmx.de | a453e46 | 2017-07-11 22:06:19 +0200 | [diff] [blame] | 577 | return r; |
| 578 | } |
| 579 | |
| 580 | static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle, |
| 581 | efi_guid_t *protocol, void *protocol_interface) |
| 582 | { |
| 583 | EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface); |
| 584 | |
| 585 | return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol, |
| 586 | protocol_interface)); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | 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] | 590 | struct efi_event *event, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 591 | void **registration) |
| 592 | { |
| 593 | EFI_ENTRY("%p, %p, %p", protocol, event, registration); |
| 594 | return EFI_EXIT(EFI_OUT_OF_RESOURCES); |
| 595 | } |
| 596 | |
| 597 | static int efi_search(enum efi_locate_search_type search_type, |
| 598 | efi_guid_t *protocol, void *search_key, |
| 599 | struct efi_object *efiobj) |
| 600 | { |
| 601 | int i; |
| 602 | |
| 603 | switch (search_type) { |
| 604 | case all_handles: |
| 605 | return 0; |
| 606 | case by_register_notify: |
| 607 | return -1; |
| 608 | case by_protocol: |
| 609 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 610 | const efi_guid_t *guid = efiobj->protocols[i].guid; |
| 611 | if (guid && !guidcmp(guid, protocol)) |
| 612 | return 0; |
| 613 | } |
| 614 | return -1; |
| 615 | } |
| 616 | |
| 617 | return -1; |
| 618 | } |
| 619 | |
xypron.glpk@gmx.de | cab4dd5 | 2017-08-09 20:55:00 +0200 | [diff] [blame] | 620 | static efi_status_t efi_locate_handle( |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 621 | enum efi_locate_search_type search_type, |
| 622 | efi_guid_t *protocol, void *search_key, |
| 623 | unsigned long *buffer_size, efi_handle_t *buffer) |
| 624 | { |
| 625 | struct list_head *lhandle; |
| 626 | unsigned long size = 0; |
| 627 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 628 | /* Count how much space we need */ |
| 629 | list_for_each(lhandle, &efi_obj_list) { |
| 630 | struct efi_object *efiobj; |
| 631 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 632 | if (!efi_search(search_type, protocol, search_key, efiobj)) { |
| 633 | size += sizeof(void*); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | if (*buffer_size < size) { |
| 638 | *buffer_size = size; |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 639 | return EFI_BUFFER_TOO_SMALL; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 640 | } |
| 641 | |
Rob Clark | cdee337 | 2017-08-06 14:10:07 -0400 | [diff] [blame] | 642 | *buffer_size = size; |
| 643 | if (size == 0) |
| 644 | return EFI_NOT_FOUND; |
| 645 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 646 | /* Then fill the array */ |
| 647 | list_for_each(lhandle, &efi_obj_list) { |
| 648 | struct efi_object *efiobj; |
| 649 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 650 | if (!efi_search(search_type, protocol, search_key, efiobj)) { |
| 651 | *(buffer++) = efiobj->handle; |
| 652 | } |
| 653 | } |
| 654 | |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 655 | return EFI_SUCCESS; |
| 656 | } |
| 657 | |
| 658 | static efi_status_t EFIAPI efi_locate_handle_ext( |
| 659 | enum efi_locate_search_type search_type, |
| 660 | efi_guid_t *protocol, void *search_key, |
| 661 | unsigned long *buffer_size, efi_handle_t *buffer) |
| 662 | { |
| 663 | EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, |
| 664 | buffer_size, buffer); |
| 665 | |
| 666 | return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key, |
| 667 | buffer_size, buffer)); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol, |
| 671 | struct efi_device_path **device_path, |
| 672 | efi_handle_t *device) |
| 673 | { |
| 674 | EFI_ENTRY("%p, %p, %p", protocol, device_path, device); |
| 675 | return EFI_EXIT(EFI_NOT_FOUND); |
| 676 | } |
| 677 | |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 678 | /* Collapses configuration table entries, removing index i */ |
| 679 | static void efi_remove_configuration_table(int i) |
| 680 | { |
| 681 | struct efi_configuration_table *this = &efi_conf_table[i]; |
| 682 | struct efi_configuration_table *next = &efi_conf_table[i+1]; |
| 683 | struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables]; |
| 684 | |
| 685 | memmove(this, next, (ulong)end - (ulong)next); |
| 686 | systab.nr_tables--; |
| 687 | } |
| 688 | |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 689 | 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] | 690 | { |
| 691 | int i; |
| 692 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 693 | /* Check for guid override */ |
| 694 | for (i = 0; i < systab.nr_tables; i++) { |
| 695 | if (!guidcmp(guid, &efi_conf_table[i].guid)) { |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 696 | if (table) |
| 697 | efi_conf_table[i].table = table; |
| 698 | else |
| 699 | efi_remove_configuration_table(i); |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 700 | return EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Alexander Graf | fe3366f | 2017-07-26 13:41:04 +0200 | [diff] [blame] | 704 | if (!table) |
| 705 | return EFI_NOT_FOUND; |
| 706 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 707 | /* No override, check for overflow */ |
| 708 | if (i >= ARRAY_SIZE(efi_conf_table)) |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 709 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 710 | |
| 711 | /* Add a new entry */ |
| 712 | memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); |
| 713 | efi_conf_table[i].table = table; |
Alexander Graf | 9982e67 | 2016-08-19 01:23:30 +0200 | [diff] [blame] | 714 | systab.nr_tables = i + 1; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 715 | |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 716 | return EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 717 | } |
| 718 | |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 719 | static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, |
| 720 | void *table) |
| 721 | { |
| 722 | EFI_ENTRY("%p, %p", guid, table); |
| 723 | return EFI_EXIT(efi_install_configuration_table(guid, table)); |
| 724 | } |
| 725 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 726 | static efi_status_t EFIAPI efi_load_image(bool boot_policy, |
| 727 | efi_handle_t parent_image, |
| 728 | struct efi_device_path *file_path, |
| 729 | void *source_buffer, |
| 730 | unsigned long source_size, |
| 731 | efi_handle_t *image_handle) |
| 732 | { |
| 733 | static struct efi_object loaded_image_info_obj = { |
| 734 | .protocols = { |
| 735 | { |
| 736 | .guid = &efi_guid_loaded_image, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 737 | }, |
| 738 | }, |
| 739 | }; |
| 740 | struct efi_loaded_image *info; |
| 741 | struct efi_object *obj; |
| 742 | |
| 743 | EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, |
| 744 | file_path, source_buffer, source_size, image_handle); |
| 745 | info = malloc(sizeof(*info)); |
xypron.glpk@gmx.de | c35c924 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 746 | loaded_image_info_obj.protocols[0].protocol_interface = info; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 747 | obj = malloc(sizeof(loaded_image_info_obj)); |
| 748 | memset(info, 0, sizeof(*info)); |
| 749 | memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); |
| 750 | obj->handle = info; |
| 751 | info->file_path = file_path; |
| 752 | info->reserved = efi_load_pe(source_buffer, info); |
| 753 | if (!info->reserved) { |
| 754 | free(info); |
| 755 | free(obj); |
| 756 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 757 | } |
| 758 | |
| 759 | *image_handle = info; |
| 760 | list_add_tail(&obj->link, &efi_obj_list); |
| 761 | |
| 762 | return EFI_EXIT(EFI_SUCCESS); |
| 763 | } |
| 764 | |
| 765 | static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, |
| 766 | unsigned long *exit_data_size, |
| 767 | s16 **exit_data) |
| 768 | { |
| 769 | ulong (*entry)(void *image_handle, struct efi_system_table *st); |
| 770 | struct efi_loaded_image *info = image_handle; |
| 771 | |
| 772 | EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); |
| 773 | entry = info->reserved; |
| 774 | |
| 775 | efi_is_direct_boot = false; |
| 776 | |
| 777 | /* call the image! */ |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 778 | if (setjmp(&info->exit_jmp)) { |
| 779 | /* We returned from the child image */ |
| 780 | return EFI_EXIT(info->exit_status); |
| 781 | } |
| 782 | |
Rob Clark | e7896c3 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 783 | __efi_nesting_dec(); |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 784 | __efi_exit_check(); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 785 | entry(image_handle, &systab); |
Rob Clark | 86789d5 | 2017-07-27 08:04:18 -0400 | [diff] [blame] | 786 | __efi_entry_check(); |
Rob Clark | e7896c3 | 2017-07-27 08:04:19 -0400 | [diff] [blame] | 787 | __efi_nesting_inc(); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 788 | |
| 789 | /* Should usually never get here */ |
| 790 | return EFI_EXIT(EFI_SUCCESS); |
| 791 | } |
| 792 | |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 793 | static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, |
| 794 | efi_status_t exit_status, unsigned long exit_data_size, |
| 795 | int16_t *exit_data) |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 796 | { |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 797 | struct efi_loaded_image *loaded_image_info = (void*)image_handle; |
| 798 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 799 | EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, |
| 800 | exit_data_size, exit_data); |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 801 | |
Alexander Graf | 87e787a | 2017-09-03 14:14:17 +0200 | [diff] [blame] | 802 | /* Make sure entry/exit counts for EFI world cross-overs match */ |
Heinrich Schuchardt | 4a4c646 | 2017-08-25 19:53:14 +0200 | [diff] [blame] | 803 | __efi_exit_check(); |
| 804 | |
Alexander Graf | 87e787a | 2017-09-03 14:14:17 +0200 | [diff] [blame] | 805 | /* |
| 806 | * But longjmp out with the U-Boot gd, not the application's, as |
| 807 | * the other end is a setjmp call inside EFI context. |
| 808 | */ |
| 809 | efi_restore_gd(); |
| 810 | |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 811 | loaded_image_info->exit_status = exit_status; |
Alexander Graf | 9d006b7 | 2016-09-27 09:30:32 +0200 | [diff] [blame] | 812 | longjmp(&loaded_image_info->exit_jmp, 1); |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 813 | |
| 814 | panic("EFI application exited"); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static struct efi_object *efi_search_obj(void *handle) |
| 818 | { |
| 819 | struct list_head *lhandle; |
| 820 | |
| 821 | list_for_each(lhandle, &efi_obj_list) { |
| 822 | struct efi_object *efiobj; |
| 823 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 824 | if (efiobj->handle == handle) |
| 825 | return efiobj; |
| 826 | } |
| 827 | |
| 828 | return NULL; |
| 829 | } |
| 830 | |
| 831 | static efi_status_t EFIAPI efi_unload_image(void *image_handle) |
| 832 | { |
| 833 | struct efi_object *efiobj; |
| 834 | |
| 835 | EFI_ENTRY("%p", image_handle); |
| 836 | efiobj = efi_search_obj(image_handle); |
| 837 | if (efiobj) |
| 838 | list_del(&efiobj->link); |
| 839 | |
| 840 | return EFI_EXIT(EFI_SUCCESS); |
| 841 | } |
| 842 | |
| 843 | static void efi_exit_caches(void) |
| 844 | { |
| 845 | #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) |
| 846 | /* |
| 847 | * Grub on 32bit ARM needs to have caches disabled before jumping into |
| 848 | * a zImage, but does not know of all cache layers. Give it a hand. |
| 849 | */ |
| 850 | if (efi_is_direct_boot) |
| 851 | cleanup_before_linux(); |
| 852 | #endif |
| 853 | } |
| 854 | |
| 855 | static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, |
| 856 | unsigned long map_key) |
| 857 | { |
| 858 | EFI_ENTRY("%p, %ld", image_handle, map_key); |
| 859 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 860 | board_quiesce_devices(); |
| 861 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 862 | /* Fix up caches for EFI payloads if necessary */ |
| 863 | efi_exit_caches(); |
| 864 | |
| 865 | /* This stops all lingering devices */ |
| 866 | bootm_disable_interrupts(); |
| 867 | |
| 868 | /* Give the payload some time to boot */ |
| 869 | WATCHDOG_RESET(); |
| 870 | |
| 871 | return EFI_EXIT(EFI_SUCCESS); |
| 872 | } |
| 873 | |
| 874 | static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) |
| 875 | { |
| 876 | static uint64_t mono = 0; |
| 877 | EFI_ENTRY("%p", count); |
| 878 | *count = mono++; |
| 879 | return EFI_EXIT(EFI_SUCCESS); |
| 880 | } |
| 881 | |
| 882 | static efi_status_t EFIAPI efi_stall(unsigned long microseconds) |
| 883 | { |
| 884 | EFI_ENTRY("%ld", microseconds); |
| 885 | udelay(microseconds); |
| 886 | return EFI_EXIT(EFI_SUCCESS); |
| 887 | } |
| 888 | |
| 889 | static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, |
| 890 | uint64_t watchdog_code, |
| 891 | unsigned long data_size, |
| 892 | uint16_t *watchdog_data) |
| 893 | { |
| 894 | EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, |
| 895 | data_size, watchdog_data); |
Rob Clark | d417d2b | 2017-07-25 20:17:59 -0400 | [diff] [blame] | 896 | return efi_unsupported(__func__); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static efi_status_t EFIAPI efi_connect_controller( |
| 900 | efi_handle_t controller_handle, |
| 901 | efi_handle_t *driver_image_handle, |
| 902 | struct efi_device_path *remain_device_path, |
| 903 | bool recursive) |
| 904 | { |
| 905 | EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle, |
| 906 | remain_device_path, recursive); |
| 907 | return EFI_EXIT(EFI_NOT_FOUND); |
| 908 | } |
| 909 | |
| 910 | static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle, |
| 911 | void *driver_image_handle, |
| 912 | void *child_handle) |
| 913 | { |
| 914 | EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, |
| 915 | child_handle); |
| 916 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 917 | } |
| 918 | |
| 919 | static efi_status_t EFIAPI efi_close_protocol(void *handle, |
| 920 | efi_guid_t *protocol, |
| 921 | void *agent_handle, |
| 922 | void *controller_handle) |
| 923 | { |
| 924 | EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle, |
| 925 | controller_handle); |
| 926 | return EFI_EXIT(EFI_NOT_FOUND); |
| 927 | } |
| 928 | |
| 929 | static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, |
| 930 | efi_guid_t *protocol, |
| 931 | struct efi_open_protocol_info_entry **entry_buffer, |
| 932 | unsigned long *entry_count) |
| 933 | { |
| 934 | EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, |
| 935 | entry_count); |
| 936 | return EFI_EXIT(EFI_NOT_FOUND); |
| 937 | } |
| 938 | |
| 939 | static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, |
| 940 | efi_guid_t ***protocol_buffer, |
| 941 | unsigned long *protocol_buffer_count) |
| 942 | { |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 943 | unsigned long buffer_size; |
| 944 | struct efi_object *efiobj; |
| 945 | unsigned long i, j; |
| 946 | struct list_head *lhandle; |
| 947 | efi_status_t r; |
| 948 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 949 | EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, |
| 950 | protocol_buffer_count); |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 951 | |
| 952 | if (!handle || !protocol_buffer || !protocol_buffer_count) |
| 953 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 954 | |
| 955 | *protocol_buffer = NULL; |
Rob Clark | d51b8ca | 2017-07-20 07:59:39 -0400 | [diff] [blame] | 956 | *protocol_buffer_count = 0; |
xypron.glpk@gmx.de | 8960c97 | 2017-07-13 23:24:32 +0200 | [diff] [blame] | 957 | list_for_each(lhandle, &efi_obj_list) { |
| 958 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 959 | |
| 960 | if (efiobj->handle != handle) |
| 961 | continue; |
| 962 | |
| 963 | /* Count protocols */ |
| 964 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 965 | if (efiobj->protocols[i].guid) |
| 966 | ++*protocol_buffer_count; |
| 967 | } |
| 968 | /* Copy guids */ |
| 969 | if (*protocol_buffer_count) { |
| 970 | buffer_size = sizeof(efi_guid_t *) * |
| 971 | *protocol_buffer_count; |
| 972 | r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, |
| 973 | buffer_size, |
| 974 | (void **)protocol_buffer); |
| 975 | if (r != EFI_SUCCESS) |
| 976 | return EFI_EXIT(r); |
| 977 | j = 0; |
| 978 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) { |
| 979 | if (efiobj->protocols[i].guid) { |
| 980 | (*protocol_buffer)[j] = (void *) |
| 981 | efiobj->protocols[i].guid; |
| 982 | ++j; |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | static efi_status_t EFIAPI efi_locate_handle_buffer( |
| 993 | enum efi_locate_search_type search_type, |
| 994 | efi_guid_t *protocol, void *search_key, |
| 995 | unsigned long *no_handles, efi_handle_t **buffer) |
| 996 | { |
xypron.glpk@gmx.de | 550a68a | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 997 | efi_status_t r; |
| 998 | unsigned long buffer_size = 0; |
| 999 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1000 | EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, |
| 1001 | no_handles, buffer); |
xypron.glpk@gmx.de | 550a68a | 2017-07-11 22:06:22 +0200 | [diff] [blame] | 1002 | |
| 1003 | if (!no_handles || !buffer) { |
| 1004 | r = EFI_INVALID_PARAMETER; |
| 1005 | goto out; |
| 1006 | } |
| 1007 | *no_handles = 0; |
| 1008 | *buffer = NULL; |
| 1009 | r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, |
| 1010 | *buffer); |
| 1011 | if (r != EFI_BUFFER_TOO_SMALL) |
| 1012 | goto out; |
| 1013 | r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, |
| 1014 | (void **)buffer); |
| 1015 | if (r != EFI_SUCCESS) |
| 1016 | goto out; |
| 1017 | r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, |
| 1018 | *buffer); |
| 1019 | if (r == EFI_SUCCESS) |
| 1020 | *no_handles = buffer_size / sizeof(void *); |
| 1021 | out: |
| 1022 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1023 | } |
| 1024 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1025 | static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol, |
| 1026 | void *registration, |
| 1027 | void **protocol_interface) |
| 1028 | { |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1029 | struct list_head *lhandle; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1030 | int i; |
| 1031 | |
| 1032 | EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface); |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1033 | |
| 1034 | if (!protocol || !protocol_interface) |
| 1035 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1036 | |
Heinrich Schuchardt | 4d66489 | 2017-08-18 17:45:16 +0200 | [diff] [blame] | 1037 | EFI_PRINT_GUID("protocol", protocol); |
| 1038 | |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1039 | list_for_each(lhandle, &efi_obj_list) { |
| 1040 | struct efi_object *efiobj; |
| 1041 | |
| 1042 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 1043 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 1044 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 1045 | |
| 1046 | if (!handler->guid) |
| 1047 | continue; |
| 1048 | if (!guidcmp(handler->guid, protocol)) { |
| 1049 | *protocol_interface = |
| 1050 | handler->protocol_interface; |
| 1051 | return EFI_EXIT(EFI_SUCCESS); |
| 1052 | } |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1053 | } |
| 1054 | } |
xypron.glpk@gmx.de | 4534ad6 | 2017-07-11 22:06:24 +0200 | [diff] [blame] | 1055 | *protocol_interface = NULL; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1056 | |
| 1057 | return EFI_EXIT(EFI_NOT_FOUND); |
| 1058 | } |
| 1059 | |
| 1060 | static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( |
| 1061 | void **handle, ...) |
| 1062 | { |
| 1063 | EFI_ENTRY("%p", handle); |
xypron.glpk@gmx.de | 83eebc7 | 2017-07-11 22:06:20 +0200 | [diff] [blame] | 1064 | |
| 1065 | va_list argptr; |
| 1066 | efi_guid_t *protocol; |
| 1067 | void *protocol_interface; |
| 1068 | efi_status_t r = EFI_SUCCESS; |
| 1069 | int i = 0; |
| 1070 | |
| 1071 | if (!handle) |
| 1072 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1073 | |
| 1074 | va_start(argptr, handle); |
| 1075 | for (;;) { |
| 1076 | protocol = va_arg(argptr, efi_guid_t*); |
| 1077 | if (!protocol) |
| 1078 | break; |
| 1079 | protocol_interface = va_arg(argptr, void*); |
| 1080 | r = efi_install_protocol_interface(handle, protocol, |
| 1081 | EFI_NATIVE_INTERFACE, |
| 1082 | protocol_interface); |
| 1083 | if (r != EFI_SUCCESS) |
| 1084 | break; |
| 1085 | i++; |
| 1086 | } |
| 1087 | va_end(argptr); |
| 1088 | if (r == EFI_SUCCESS) |
| 1089 | return EFI_EXIT(r); |
| 1090 | |
| 1091 | /* If an error occured undo all changes. */ |
| 1092 | va_start(argptr, handle); |
| 1093 | for (; i; --i) { |
| 1094 | protocol = va_arg(argptr, efi_guid_t*); |
| 1095 | protocol_interface = va_arg(argptr, void*); |
| 1096 | efi_uninstall_protocol_interface(handle, protocol, |
| 1097 | protocol_interface); |
| 1098 | } |
| 1099 | va_end(argptr); |
| 1100 | |
| 1101 | return EFI_EXIT(r); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( |
| 1105 | void *handle, ...) |
| 1106 | { |
| 1107 | EFI_ENTRY("%p", handle); |
| 1108 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 1109 | } |
| 1110 | |
| 1111 | static efi_status_t EFIAPI efi_calculate_crc32(void *data, |
| 1112 | unsigned long data_size, |
| 1113 | uint32_t *crc32_p) |
| 1114 | { |
| 1115 | EFI_ENTRY("%p, %ld", data, data_size); |
| 1116 | *crc32_p = crc32(0, data, data_size); |
| 1117 | return EFI_EXIT(EFI_SUCCESS); |
| 1118 | } |
| 1119 | |
| 1120 | static void EFIAPI efi_copy_mem(void *destination, void *source, |
| 1121 | unsigned long length) |
| 1122 | { |
| 1123 | EFI_ENTRY("%p, %p, %ld", destination, source, length); |
| 1124 | memcpy(destination, source, length); |
| 1125 | } |
| 1126 | |
| 1127 | static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value) |
| 1128 | { |
| 1129 | EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value); |
| 1130 | memset(buffer, value, size); |
| 1131 | } |
| 1132 | |
| 1133 | static efi_status_t EFIAPI efi_open_protocol( |
| 1134 | void *handle, efi_guid_t *protocol, |
| 1135 | void **protocol_interface, void *agent_handle, |
| 1136 | void *controller_handle, uint32_t attributes) |
| 1137 | { |
| 1138 | struct list_head *lhandle; |
| 1139 | int i; |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1140 | efi_status_t r = EFI_INVALID_PARAMETER; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1141 | |
| 1142 | EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol, |
| 1143 | protocol_interface, agent_handle, controller_handle, |
| 1144 | attributes); |
xypron.glpk@gmx.de | c35c924 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 1145 | |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1146 | if (!handle || !protocol || |
| 1147 | (!protocol_interface && attributes != |
| 1148 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) { |
xypron.glpk@gmx.de | c35c924 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 1149 | goto out; |
| 1150 | } |
| 1151 | |
Heinrich Schuchardt | 4d66489 | 2017-08-18 17:45:16 +0200 | [diff] [blame] | 1152 | EFI_PRINT_GUID("protocol", protocol); |
| 1153 | |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1154 | switch (attributes) { |
| 1155 | case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: |
| 1156 | case EFI_OPEN_PROTOCOL_GET_PROTOCOL: |
| 1157 | case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: |
| 1158 | break; |
| 1159 | case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: |
| 1160 | if (controller_handle == handle) |
| 1161 | goto out; |
| 1162 | case EFI_OPEN_PROTOCOL_BY_DRIVER: |
| 1163 | case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: |
| 1164 | if (controller_handle == NULL) |
| 1165 | goto out; |
| 1166 | case EFI_OPEN_PROTOCOL_EXCLUSIVE: |
| 1167 | if (agent_handle == NULL) |
| 1168 | goto out; |
| 1169 | break; |
| 1170 | default: |
| 1171 | goto out; |
| 1172 | } |
| 1173 | |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1174 | list_for_each(lhandle, &efi_obj_list) { |
| 1175 | struct efi_object *efiobj; |
| 1176 | efiobj = list_entry(lhandle, struct efi_object, link); |
| 1177 | |
| 1178 | if (efiobj->handle != handle) |
| 1179 | continue; |
| 1180 | |
| 1181 | for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { |
| 1182 | struct efi_handler *handler = &efiobj->protocols[i]; |
| 1183 | const efi_guid_t *hprotocol = handler->guid; |
| 1184 | if (!hprotocol) |
xypron.glpk@gmx.de | 2cfad48 | 2017-07-11 22:06:17 +0200 | [diff] [blame] | 1185 | continue; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1186 | if (!guidcmp(hprotocol, protocol)) { |
xypron.glpk@gmx.de | c35c924 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 1187 | if (attributes != |
| 1188 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { |
| 1189 | *protocol_interface = |
| 1190 | handler->protocol_interface; |
| 1191 | } |
| 1192 | r = EFI_SUCCESS; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1193 | goto out; |
| 1194 | } |
| 1195 | } |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1196 | goto unsupported; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
xypron.glpk@gmx.de | f097c84 | 2017-07-11 22:06:15 +0200 | [diff] [blame] | 1199 | unsupported: |
| 1200 | r = EFI_UNSUPPORTED; |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1201 | out: |
| 1202 | return EFI_EXIT(r); |
| 1203 | } |
| 1204 | |
| 1205 | static efi_status_t EFIAPI efi_handle_protocol(void *handle, |
| 1206 | efi_guid_t *protocol, |
| 1207 | void **protocol_interface) |
| 1208 | { |
xypron.glpk@gmx.de | 1bf5d87 | 2017-06-29 21:16:19 +0200 | [diff] [blame] | 1209 | return efi_open_protocol(handle, protocol, protocol_interface, NULL, |
| 1210 | NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | static const struct efi_boot_services efi_boot_services = { |
| 1214 | .hdr = { |
| 1215 | .headersize = sizeof(struct efi_table_hdr), |
| 1216 | }, |
| 1217 | .raise_tpl = efi_raise_tpl, |
| 1218 | .restore_tpl = efi_restore_tpl, |
| 1219 | .allocate_pages = efi_allocate_pages_ext, |
| 1220 | .free_pages = efi_free_pages_ext, |
| 1221 | .get_memory_map = efi_get_memory_map_ext, |
Stefan Brüns | 5a09aef | 2016-10-09 22:17:18 +0200 | [diff] [blame] | 1222 | .allocate_pool = efi_allocate_pool_ext, |
Stefan Brüns | 67b67d9 | 2016-10-09 22:17:26 +0200 | [diff] [blame] | 1223 | .free_pool = efi_free_pool_ext, |
xypron.glpk@gmx.de | 852a0e177 | 2017-07-18 20:17:20 +0200 | [diff] [blame] | 1224 | .create_event = efi_create_event_ext, |
xypron.glpk@gmx.de | a587fd1 | 2017-07-18 20:17:21 +0200 | [diff] [blame] | 1225 | .set_timer = efi_set_timer_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1226 | .wait_for_event = efi_wait_for_event, |
xypron.glpk@gmx.de | 3070823 | 2017-07-18 20:17:18 +0200 | [diff] [blame] | 1227 | .signal_event = efi_signal_event_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1228 | .close_event = efi_close_event, |
| 1229 | .check_event = efi_check_event, |
xypron.glpk@gmx.de | 8b7b5df | 2017-07-11 22:06:18 +0200 | [diff] [blame] | 1230 | .install_protocol_interface = efi_install_protocol_interface_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1231 | .reinstall_protocol_interface = efi_reinstall_protocol_interface, |
xypron.glpk@gmx.de | a453e46 | 2017-07-11 22:06:19 +0200 | [diff] [blame] | 1232 | .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1233 | .handle_protocol = efi_handle_protocol, |
| 1234 | .reserved = NULL, |
| 1235 | .register_protocol_notify = efi_register_protocol_notify, |
xypron.glpk@gmx.de | 69f9403 | 2017-07-11 22:06:21 +0200 | [diff] [blame] | 1236 | .locate_handle = efi_locate_handle_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1237 | .locate_device_path = efi_locate_device_path, |
Alexander Graf | c5c1163 | 2016-08-19 01:23:24 +0200 | [diff] [blame] | 1238 | .install_configuration_table = efi_install_configuration_table_ext, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1239 | .load_image = efi_load_image, |
| 1240 | .start_image = efi_start_image, |
Alexander Graf | 988c066 | 2016-05-20 23:28:23 +0200 | [diff] [blame] | 1241 | .exit = efi_exit, |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1242 | .unload_image = efi_unload_image, |
| 1243 | .exit_boot_services = efi_exit_boot_services, |
| 1244 | .get_next_monotonic_count = efi_get_next_monotonic_count, |
| 1245 | .stall = efi_stall, |
| 1246 | .set_watchdog_timer = efi_set_watchdog_timer, |
| 1247 | .connect_controller = efi_connect_controller, |
| 1248 | .disconnect_controller = efi_disconnect_controller, |
| 1249 | .open_protocol = efi_open_protocol, |
| 1250 | .close_protocol = efi_close_protocol, |
| 1251 | .open_protocol_information = efi_open_protocol_information, |
| 1252 | .protocols_per_handle = efi_protocols_per_handle, |
| 1253 | .locate_handle_buffer = efi_locate_handle_buffer, |
| 1254 | .locate_protocol = efi_locate_protocol, |
| 1255 | .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces, |
| 1256 | .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces, |
| 1257 | .calculate_crc32 = efi_calculate_crc32, |
| 1258 | .copy_mem = efi_copy_mem, |
| 1259 | .set_mem = efi_set_mem, |
| 1260 | }; |
| 1261 | |
| 1262 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 1263 | static uint16_t __efi_runtime_data firmware_vendor[] = |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1264 | { 'D','a','s',' ','U','-','b','o','o','t',0 }; |
| 1265 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 1266 | struct efi_system_table __efi_runtime_data systab = { |
Alexander Graf | c15d921 | 2016-03-04 01:09:59 +0100 | [diff] [blame] | 1267 | .hdr = { |
| 1268 | .signature = EFI_SYSTEM_TABLE_SIGNATURE, |
| 1269 | .revision = 0x20005, /* 2.5 */ |
| 1270 | .headersize = sizeof(struct efi_table_hdr), |
| 1271 | }, |
| 1272 | .fw_vendor = (long)firmware_vendor, |
| 1273 | .con_in = (void*)&efi_con_in, |
| 1274 | .con_out = (void*)&efi_con_out, |
| 1275 | .std_err = (void*)&efi_con_out, |
| 1276 | .runtime = (void*)&efi_runtime_services, |
| 1277 | .boottime = (void*)&efi_boot_services, |
| 1278 | .nr_tables = 0, |
| 1279 | .tables = (void*)efi_conf_table, |
| 1280 | }; |