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