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