1bee91169SAlexander Graf /* 2bee91169SAlexander Graf * EFI application boot time services 3bee91169SAlexander Graf * 4bee91169SAlexander Graf * Copyright (c) 2016 Alexander Graf 5bee91169SAlexander Graf * 6bee91169SAlexander Graf * SPDX-License-Identifier: GPL-2.0+ 7bee91169SAlexander Graf */ 8bee91169SAlexander Graf 9bee91169SAlexander Graf #include <common.h> 10bee91169SAlexander Graf #include <efi_loader.h> 11bee91169SAlexander Graf #include <malloc.h> 12bee91169SAlexander Graf #include <asm/global_data.h> 13bee91169SAlexander Graf #include <libfdt_env.h> 14bee91169SAlexander Graf #include <u-boot/crc.h> 15bee91169SAlexander Graf #include <bootm.h> 16bee91169SAlexander Graf #include <inttypes.h> 17bee91169SAlexander Graf #include <watchdog.h> 18bee91169SAlexander Graf 19bee91169SAlexander Graf DECLARE_GLOBAL_DATA_PTR; 20bee91169SAlexander Graf 21bee91169SAlexander Graf /* This list contains all the EFI objects our payload has access to */ 22bee91169SAlexander Graf LIST_HEAD(efi_obj_list); 23bee91169SAlexander Graf 24bee91169SAlexander Graf /* 25bee91169SAlexander Graf * If we're running on nasty systems (32bit ARM booting into non-EFI Linux) 26bee91169SAlexander Graf * we need to do trickery with caches. Since we don't want to break the EFI 27bee91169SAlexander Graf * aware boot path, only apply hacks when loading exiting directly (breaking 28bee91169SAlexander Graf * direct Linux EFI booting along the way - oh well). 29bee91169SAlexander Graf */ 30bee91169SAlexander Graf static bool efi_is_direct_boot = true; 31bee91169SAlexander Graf 32bee91169SAlexander Graf /* 33bee91169SAlexander Graf * EFI can pass arbitrary additional "tables" containing vendor specific 34bee91169SAlexander Graf * information to the payload. One such table is the FDT table which contains 35bee91169SAlexander Graf * a pointer to a flattened device tree blob. 36bee91169SAlexander Graf * 37bee91169SAlexander Graf * In most cases we want to pass an FDT to the payload, so reserve one slot of 38bee91169SAlexander Graf * config table space for it. The pointer gets populated by do_bootefi_exec(). 39bee91169SAlexander Graf */ 403c63db9cSAlexander Graf static struct efi_configuration_table __efi_runtime_data efi_conf_table[2]; 41bee91169SAlexander Graf 4265e4c0b1SSimon Glass #ifdef CONFIG_ARM 43bee91169SAlexander Graf /* 44bee91169SAlexander Graf * The "gd" pointer lives in a register on ARM and AArch64 that we declare 45bee91169SAlexander Graf * fixed when compiling U-Boot. However, the payload does not know about that 46bee91169SAlexander Graf * restriction so we need to manually swap its and our view of that register on 47bee91169SAlexander Graf * EFI callback entry/exit. 48bee91169SAlexander Graf */ 49bee91169SAlexander Graf static volatile void *efi_gd, *app_gd; 5065e4c0b1SSimon Glass #endif 51bee91169SAlexander Graf 52c160d2f5SRob Clark static int entry_count; 53af65db85SRob Clark static int nesting_level; 54c160d2f5SRob Clark 55c160d2f5SRob Clark /* Called on every callback entry */ 56c160d2f5SRob Clark int __efi_entry_check(void) 57c160d2f5SRob Clark { 58c160d2f5SRob Clark int ret = entry_count++ == 0; 59c160d2f5SRob Clark #ifdef CONFIG_ARM 60c160d2f5SRob Clark assert(efi_gd); 61c160d2f5SRob Clark app_gd = gd; 62c160d2f5SRob Clark gd = efi_gd; 63c160d2f5SRob Clark #endif 64c160d2f5SRob Clark return ret; 65c160d2f5SRob Clark } 66c160d2f5SRob Clark 67c160d2f5SRob Clark /* Called on every callback exit */ 68c160d2f5SRob Clark int __efi_exit_check(void) 69c160d2f5SRob Clark { 70c160d2f5SRob Clark int ret = --entry_count == 0; 71c160d2f5SRob Clark #ifdef CONFIG_ARM 72c160d2f5SRob Clark gd = app_gd; 73c160d2f5SRob Clark #endif 74c160d2f5SRob Clark return ret; 75c160d2f5SRob Clark } 76c160d2f5SRob Clark 77bee91169SAlexander Graf /* Called from do_bootefi_exec() */ 78bee91169SAlexander Graf void efi_save_gd(void) 79bee91169SAlexander Graf { 8065e4c0b1SSimon Glass #ifdef CONFIG_ARM 81bee91169SAlexander Graf efi_gd = gd; 8265e4c0b1SSimon Glass #endif 83bee91169SAlexander Graf } 84bee91169SAlexander Graf 85c160d2f5SRob Clark /* 86c160d2f5SRob Clark * Special case handler for error/abort that just forces things back 87c160d2f5SRob Clark * to u-boot world so we can dump out an abort msg, without any care 88c160d2f5SRob Clark * about returning back to UEFI world. 89c160d2f5SRob Clark */ 90bee91169SAlexander Graf void efi_restore_gd(void) 91bee91169SAlexander Graf { 9265e4c0b1SSimon Glass #ifdef CONFIG_ARM 93bee91169SAlexander Graf /* Only restore if we're already in EFI context */ 94bee91169SAlexander Graf if (!efi_gd) 95bee91169SAlexander Graf return; 96bee91169SAlexander Graf gd = efi_gd; 9765e4c0b1SSimon Glass #endif 98bee91169SAlexander Graf } 99bee91169SAlexander Graf 100af65db85SRob Clark /* 101af65db85SRob Clark * Two spaces per indent level, maxing out at 10.. which ought to be 102af65db85SRob Clark * enough for anyone ;-) 103af65db85SRob Clark */ 104af65db85SRob Clark static const char *indent_string(int level) 105af65db85SRob Clark { 106af65db85SRob Clark const char *indent = " "; 107af65db85SRob Clark const int max = strlen(indent); 108af65db85SRob Clark level = min(max, level * 2); 109af65db85SRob Clark return &indent[max - level]; 110af65db85SRob Clark } 111af65db85SRob Clark 112af65db85SRob Clark const char *__efi_nesting_inc(void) 113af65db85SRob Clark { 114af65db85SRob Clark return indent_string(nesting_level++); 115af65db85SRob Clark } 116af65db85SRob Clark 117af65db85SRob Clark const char *__efi_nesting_dec(void) 118af65db85SRob Clark { 119af65db85SRob Clark return indent_string(--nesting_level); 120af65db85SRob Clark } 121af65db85SRob Clark 1228787b02eSxypron.glpk@gmx.de /* Low 32 bit */ 1238787b02eSxypron.glpk@gmx.de #define EFI_LOW32(a) (a & 0xFFFFFFFFULL) 1248787b02eSxypron.glpk@gmx.de /* High 32 bit */ 1258787b02eSxypron.glpk@gmx.de #define EFI_HIGH32(a) (a >> 32) 1268787b02eSxypron.glpk@gmx.de 1278787b02eSxypron.glpk@gmx.de /* 1288787b02eSxypron.glpk@gmx.de * 64bit division by 10 implemented as multiplication by 1 / 10 1298787b02eSxypron.glpk@gmx.de * 1308787b02eSxypron.glpk@gmx.de * Decimals of one tenth: 0x1 / 0xA = 0x0.19999... 1318787b02eSxypron.glpk@gmx.de */ 1328787b02eSxypron.glpk@gmx.de #define EFI_TENTH 0x199999999999999A 1338787b02eSxypron.glpk@gmx.de static u64 efi_div10(u64 a) 1348787b02eSxypron.glpk@gmx.de { 1358787b02eSxypron.glpk@gmx.de u64 prod; 1368787b02eSxypron.glpk@gmx.de u64 rem; 1378787b02eSxypron.glpk@gmx.de u64 ret; 1388787b02eSxypron.glpk@gmx.de 1398787b02eSxypron.glpk@gmx.de ret = EFI_HIGH32(a) * EFI_HIGH32(EFI_TENTH); 1408787b02eSxypron.glpk@gmx.de prod = EFI_HIGH32(a) * EFI_LOW32(EFI_TENTH); 1418787b02eSxypron.glpk@gmx.de rem = EFI_LOW32(prod); 1428787b02eSxypron.glpk@gmx.de ret += EFI_HIGH32(prod); 1438787b02eSxypron.glpk@gmx.de prod = EFI_LOW32(a) * EFI_HIGH32(EFI_TENTH); 1448787b02eSxypron.glpk@gmx.de rem += EFI_LOW32(prod); 1458787b02eSxypron.glpk@gmx.de ret += EFI_HIGH32(prod); 1468787b02eSxypron.glpk@gmx.de prod = EFI_LOW32(a) * EFI_LOW32(EFI_TENTH); 1478787b02eSxypron.glpk@gmx.de rem += EFI_HIGH32(prod); 1488787b02eSxypron.glpk@gmx.de ret += EFI_HIGH32(rem); 1498787b02eSxypron.glpk@gmx.de /* Round to nearest integer */ 1508787b02eSxypron.glpk@gmx.de if (rem >= (1 << 31)) 1518787b02eSxypron.glpk@gmx.de ++ret; 1528787b02eSxypron.glpk@gmx.de return ret; 1538787b02eSxypron.glpk@gmx.de } 1548787b02eSxypron.glpk@gmx.de 15591be9a77Sxypron.glpk@gmx.de void efi_signal_event(struct efi_event *event) 156c6841592Sxypron.glpk@gmx.de { 157c6841592Sxypron.glpk@gmx.de if (event->signaled) 158c6841592Sxypron.glpk@gmx.de return; 159c6841592Sxypron.glpk@gmx.de event->signaled = 1; 160c6841592Sxypron.glpk@gmx.de if (event->type & EVT_NOTIFY_SIGNAL) { 161a095aadfSRob Clark EFI_CALL(event->notify_function(event, event->notify_context)); 162c6841592Sxypron.glpk@gmx.de } 163c6841592Sxypron.glpk@gmx.de } 164c6841592Sxypron.glpk@gmx.de 165bee91169SAlexander Graf static efi_status_t efi_unsupported(const char *funcname) 166bee91169SAlexander Graf { 167edcef3baSAlexander Graf debug("EFI: App called into unimplemented function %s\n", funcname); 168bee91169SAlexander Graf return EFI_EXIT(EFI_UNSUPPORTED); 169bee91169SAlexander Graf } 170bee91169SAlexander Graf 171503f2695Sxypron.glpk@gmx.de static unsigned long EFIAPI efi_raise_tpl(UINTN new_tpl) 172bee91169SAlexander Graf { 173503f2695Sxypron.glpk@gmx.de EFI_ENTRY("0x%zx", new_tpl); 174bee91169SAlexander Graf return EFI_EXIT(0); 175bee91169SAlexander Graf } 176bee91169SAlexander Graf 177503f2695Sxypron.glpk@gmx.de static void EFIAPI efi_restore_tpl(UINTN old_tpl) 178bee91169SAlexander Graf { 179503f2695Sxypron.glpk@gmx.de EFI_ENTRY("0x%zx", old_tpl); 180b5104821SRob Clark efi_unsupported(__func__); 181bee91169SAlexander Graf } 182bee91169SAlexander Graf 1836e0bf8d8SMasahiro Yamada static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type, 184bee91169SAlexander Graf unsigned long pages, 185bee91169SAlexander Graf uint64_t *memory) 186bee91169SAlexander Graf { 187bee91169SAlexander Graf efi_status_t r; 188bee91169SAlexander Graf 189bee91169SAlexander Graf EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory); 190bee91169SAlexander Graf r = efi_allocate_pages(type, memory_type, pages, memory); 191bee91169SAlexander Graf return EFI_EXIT(r); 192bee91169SAlexander Graf } 193bee91169SAlexander Graf 1946e0bf8d8SMasahiro Yamada static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory, 1956e0bf8d8SMasahiro Yamada unsigned long pages) 196bee91169SAlexander Graf { 197bee91169SAlexander Graf efi_status_t r; 198bee91169SAlexander Graf 199bee91169SAlexander Graf EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages); 200bee91169SAlexander Graf r = efi_free_pages(memory, pages); 201bee91169SAlexander Graf return EFI_EXIT(r); 202bee91169SAlexander Graf } 203bee91169SAlexander Graf 2046e0bf8d8SMasahiro Yamada static efi_status_t EFIAPI efi_get_memory_map_ext( 2056e0bf8d8SMasahiro Yamada unsigned long *memory_map_size, 206bee91169SAlexander Graf struct efi_mem_desc *memory_map, 207bee91169SAlexander Graf unsigned long *map_key, 208bee91169SAlexander Graf unsigned long *descriptor_size, 209bee91169SAlexander Graf uint32_t *descriptor_version) 210bee91169SAlexander Graf { 211bee91169SAlexander Graf efi_status_t r; 212bee91169SAlexander Graf 213bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map, 214bee91169SAlexander Graf map_key, descriptor_size, descriptor_version); 215bee91169SAlexander Graf r = efi_get_memory_map(memory_map_size, memory_map, map_key, 216bee91169SAlexander Graf descriptor_size, descriptor_version); 217bee91169SAlexander Graf return EFI_EXIT(r); 218bee91169SAlexander Graf } 219bee91169SAlexander Graf 220ead1274bSStefan Brüns static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type, 221ead1274bSStefan Brüns unsigned long size, 222bee91169SAlexander Graf void **buffer) 223bee91169SAlexander Graf { 2241cd29f0aSAlexander Graf efi_status_t r; 2251cd29f0aSAlexander Graf 2261cd29f0aSAlexander Graf EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer); 227ead1274bSStefan Brüns r = efi_allocate_pool(pool_type, size, buffer); 2281cd29f0aSAlexander Graf return EFI_EXIT(r); 229bee91169SAlexander Graf } 230bee91169SAlexander Graf 23142417bc8SStefan Brüns static efi_status_t EFIAPI efi_free_pool_ext(void *buffer) 232bee91169SAlexander Graf { 2331cd29f0aSAlexander Graf efi_status_t r; 2341cd29f0aSAlexander Graf 2351cd29f0aSAlexander Graf EFI_ENTRY("%p", buffer); 23642417bc8SStefan Brüns r = efi_free_pool(buffer); 2371cd29f0aSAlexander Graf return EFI_EXIT(r); 238bee91169SAlexander Graf } 239bee91169SAlexander Graf 240bee91169SAlexander Graf /* 241c6841592Sxypron.glpk@gmx.de * Our event capabilities are very limited. Only a small limited 242c6841592Sxypron.glpk@gmx.de * number of events is allowed to coexist. 243bee91169SAlexander Graf */ 244c6841592Sxypron.glpk@gmx.de static struct efi_event efi_events[16]; 245bee91169SAlexander Graf 246b521d29eSxypron.glpk@gmx.de efi_status_t efi_create_event(uint32_t type, UINTN notify_tpl, 2472fd945feSxypron.glpk@gmx.de void (EFIAPI *notify_function) ( 2482fd945feSxypron.glpk@gmx.de struct efi_event *event, 249e275458cSSimon Glass void *context), 2502fd945feSxypron.glpk@gmx.de void *notify_context, struct efi_event **event) 251bee91169SAlexander Graf { 252c6841592Sxypron.glpk@gmx.de int i; 253c6841592Sxypron.glpk@gmx.de 254a95343b8SJonathan Gray if (event == NULL) 25549deb455Sxypron.glpk@gmx.de return EFI_INVALID_PARAMETER; 256a95343b8SJonathan Gray 257a95343b8SJonathan Gray if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT)) 25849deb455Sxypron.glpk@gmx.de return EFI_INVALID_PARAMETER; 259a95343b8SJonathan Gray 260a95343b8SJonathan Gray if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) && 261a95343b8SJonathan Gray notify_function == NULL) 26249deb455Sxypron.glpk@gmx.de return EFI_INVALID_PARAMETER; 263a95343b8SJonathan Gray 264c6841592Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { 265c6841592Sxypron.glpk@gmx.de if (efi_events[i].type) 266c6841592Sxypron.glpk@gmx.de continue; 267c6841592Sxypron.glpk@gmx.de efi_events[i].type = type; 268c6841592Sxypron.glpk@gmx.de efi_events[i].notify_tpl = notify_tpl; 269c6841592Sxypron.glpk@gmx.de efi_events[i].notify_function = notify_function; 270c6841592Sxypron.glpk@gmx.de efi_events[i].notify_context = notify_context; 271c6841592Sxypron.glpk@gmx.de /* Disable timers on bootup */ 272c6841592Sxypron.glpk@gmx.de efi_events[i].trigger_next = -1ULL; 273c6841592Sxypron.glpk@gmx.de efi_events[i].signaled = 0; 274c6841592Sxypron.glpk@gmx.de *event = &efi_events[i]; 27549deb455Sxypron.glpk@gmx.de return EFI_SUCCESS; 276bee91169SAlexander Graf } 27749deb455Sxypron.glpk@gmx.de return EFI_OUT_OF_RESOURCES; 278c6841592Sxypron.glpk@gmx.de } 279bee91169SAlexander Graf 28049deb455Sxypron.glpk@gmx.de static efi_status_t EFIAPI efi_create_event_ext( 281b521d29eSxypron.glpk@gmx.de uint32_t type, UINTN notify_tpl, 28249deb455Sxypron.glpk@gmx.de void (EFIAPI *notify_function) ( 28349deb455Sxypron.glpk@gmx.de struct efi_event *event, 28449deb455Sxypron.glpk@gmx.de void *context), 28549deb455Sxypron.glpk@gmx.de void *notify_context, struct efi_event **event) 28649deb455Sxypron.glpk@gmx.de { 28749deb455Sxypron.glpk@gmx.de EFI_ENTRY("%d, 0x%zx, %p, %p", type, notify_tpl, notify_function, 28849deb455Sxypron.glpk@gmx.de notify_context); 28949deb455Sxypron.glpk@gmx.de return EFI_EXIT(efi_create_event(type, notify_tpl, notify_function, 29049deb455Sxypron.glpk@gmx.de notify_context, event)); 29149deb455Sxypron.glpk@gmx.de } 29249deb455Sxypron.glpk@gmx.de 29349deb455Sxypron.glpk@gmx.de 294bee91169SAlexander Graf /* 295bee91169SAlexander Graf * Our timers have to work without interrupts, so we check whenever keyboard 296bee91169SAlexander Graf * input or disk accesses happen if enough time elapsed for it to fire. 297bee91169SAlexander Graf */ 298bee91169SAlexander Graf void efi_timer_check(void) 299bee91169SAlexander Graf { 300c6841592Sxypron.glpk@gmx.de int i; 301bee91169SAlexander Graf u64 now = timer_get_us(); 302bee91169SAlexander Graf 303c6841592Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { 304c6841592Sxypron.glpk@gmx.de if (!efi_events[i].type || 305c6841592Sxypron.glpk@gmx.de !(efi_events[i].type & EVT_TIMER) || 306c6841592Sxypron.glpk@gmx.de efi_events[i].trigger_type == EFI_TIMER_STOP || 307c6841592Sxypron.glpk@gmx.de now < efi_events[i].trigger_next) 308c6841592Sxypron.glpk@gmx.de continue; 309c6841592Sxypron.glpk@gmx.de if (efi_events[i].trigger_type == EFI_TIMER_PERIODIC) { 310c6841592Sxypron.glpk@gmx.de efi_events[i].trigger_next += 3118787b02eSxypron.glpk@gmx.de efi_events[i].trigger_time; 312c6841592Sxypron.glpk@gmx.de efi_events[i].signaled = 0; 313bee91169SAlexander Graf } 314c6841592Sxypron.glpk@gmx.de efi_signal_event(&efi_events[i]); 315c6841592Sxypron.glpk@gmx.de } 316bee91169SAlexander Graf WATCHDOG_RESET(); 317bee91169SAlexander Graf } 318bee91169SAlexander Graf 319b521d29eSxypron.glpk@gmx.de efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type, 320bee91169SAlexander Graf uint64_t trigger_time) 321bee91169SAlexander Graf { 322c6841592Sxypron.glpk@gmx.de int i; 323bee91169SAlexander Graf 3248787b02eSxypron.glpk@gmx.de /* 3258787b02eSxypron.glpk@gmx.de * The parameter defines a multiple of 100ns. 3268787b02eSxypron.glpk@gmx.de * We use multiples of 1000ns. So divide by 10. 3278787b02eSxypron.glpk@gmx.de */ 3288787b02eSxypron.glpk@gmx.de trigger_time = efi_div10(trigger_time); 329bee91169SAlexander Graf 330c6841592Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { 331c6841592Sxypron.glpk@gmx.de if (event != &efi_events[i]) 332c6841592Sxypron.glpk@gmx.de continue; 333bee91169SAlexander Graf 334c6841592Sxypron.glpk@gmx.de if (!(event->type & EVT_TIMER)) 335c6841592Sxypron.glpk@gmx.de break; 336bee91169SAlexander Graf switch (type) { 337bee91169SAlexander Graf case EFI_TIMER_STOP: 338c6841592Sxypron.glpk@gmx.de event->trigger_next = -1ULL; 339bee91169SAlexander Graf break; 340bee91169SAlexander Graf case EFI_TIMER_PERIODIC: 341bee91169SAlexander Graf case EFI_TIMER_RELATIVE: 342c6841592Sxypron.glpk@gmx.de event->trigger_next = 3438787b02eSxypron.glpk@gmx.de timer_get_us() + trigger_time; 344bee91169SAlexander Graf break; 345bee91169SAlexander Graf default: 346bfc72462Sxypron.glpk@gmx.de return EFI_INVALID_PARAMETER; 347bee91169SAlexander Graf } 348c6841592Sxypron.glpk@gmx.de event->trigger_type = type; 349c6841592Sxypron.glpk@gmx.de event->trigger_time = trigger_time; 350bfc72462Sxypron.glpk@gmx.de return EFI_SUCCESS; 351bee91169SAlexander Graf } 352bfc72462Sxypron.glpk@gmx.de return EFI_INVALID_PARAMETER; 353bfc72462Sxypron.glpk@gmx.de } 354bfc72462Sxypron.glpk@gmx.de 355b521d29eSxypron.glpk@gmx.de static efi_status_t EFIAPI efi_set_timer_ext(struct efi_event *event, 356b521d29eSxypron.glpk@gmx.de enum efi_timer_delay type, 357bfc72462Sxypron.glpk@gmx.de uint64_t trigger_time) 358bfc72462Sxypron.glpk@gmx.de { 359bfc72462Sxypron.glpk@gmx.de EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time); 360bfc72462Sxypron.glpk@gmx.de return EFI_EXIT(efi_set_timer(event, type, trigger_time)); 361c6841592Sxypron.glpk@gmx.de } 362bee91169SAlexander Graf 363bee91169SAlexander Graf static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events, 3642fd945feSxypron.glpk@gmx.de struct efi_event **event, 3652fd945feSxypron.glpk@gmx.de unsigned long *index) 366bee91169SAlexander Graf { 367c6841592Sxypron.glpk@gmx.de int i, j; 368bee91169SAlexander Graf 369bee91169SAlexander Graf EFI_ENTRY("%ld, %p, %p", num_events, event, index); 370bee91169SAlexander Graf 371c6841592Sxypron.glpk@gmx.de /* Check parameters */ 372c6841592Sxypron.glpk@gmx.de if (!num_events || !event) 373c6841592Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 374c6841592Sxypron.glpk@gmx.de for (i = 0; i < num_events; ++i) { 375c6841592Sxypron.glpk@gmx.de for (j = 0; j < ARRAY_SIZE(efi_events); ++j) { 376c6841592Sxypron.glpk@gmx.de if (event[i] == &efi_events[j]) 377c6841592Sxypron.glpk@gmx.de goto known_event; 378c6841592Sxypron.glpk@gmx.de } 379c6841592Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 380c6841592Sxypron.glpk@gmx.de known_event: 381c6841592Sxypron.glpk@gmx.de if (!event[i]->type || event[i]->type & EVT_NOTIFY_SIGNAL) 382c6841592Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 383c6841592Sxypron.glpk@gmx.de } 384c6841592Sxypron.glpk@gmx.de 385c6841592Sxypron.glpk@gmx.de /* Wait for signal */ 386c6841592Sxypron.glpk@gmx.de for (;;) { 387c6841592Sxypron.glpk@gmx.de for (i = 0; i < num_events; ++i) { 388c6841592Sxypron.glpk@gmx.de if (event[i]->signaled) 389c6841592Sxypron.glpk@gmx.de goto out; 390c6841592Sxypron.glpk@gmx.de } 391c6841592Sxypron.glpk@gmx.de /* Allow events to occur. */ 392bee91169SAlexander Graf efi_timer_check(); 393c6841592Sxypron.glpk@gmx.de } 394c6841592Sxypron.glpk@gmx.de 395c6841592Sxypron.glpk@gmx.de out: 396c6841592Sxypron.glpk@gmx.de /* 397c6841592Sxypron.glpk@gmx.de * Reset the signal which is passed to the caller to allow periodic 398c6841592Sxypron.glpk@gmx.de * events to occur. 399c6841592Sxypron.glpk@gmx.de */ 400c6841592Sxypron.glpk@gmx.de event[i]->signaled = 0; 401c6841592Sxypron.glpk@gmx.de if (index) 402c6841592Sxypron.glpk@gmx.de *index = i; 403bee91169SAlexander Graf 404bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 405bee91169SAlexander Graf } 406bee91169SAlexander Graf 407c6841592Sxypron.glpk@gmx.de static efi_status_t EFIAPI efi_signal_event_ext(struct efi_event *event) 408bee91169SAlexander Graf { 409c6841592Sxypron.glpk@gmx.de int i; 410c6841592Sxypron.glpk@gmx.de 411bee91169SAlexander Graf EFI_ENTRY("%p", event); 412c6841592Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { 413c6841592Sxypron.glpk@gmx.de if (event != &efi_events[i]) 414c6841592Sxypron.glpk@gmx.de continue; 415c6841592Sxypron.glpk@gmx.de efi_signal_event(event); 416c6841592Sxypron.glpk@gmx.de break; 417c6841592Sxypron.glpk@gmx.de } 418bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 419bee91169SAlexander Graf } 420bee91169SAlexander Graf 4212fd945feSxypron.glpk@gmx.de static efi_status_t EFIAPI efi_close_event(struct efi_event *event) 422bee91169SAlexander Graf { 423c6841592Sxypron.glpk@gmx.de int i; 424c6841592Sxypron.glpk@gmx.de 425bee91169SAlexander Graf EFI_ENTRY("%p", event); 426c6841592Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { 427c6841592Sxypron.glpk@gmx.de if (event == &efi_events[i]) { 428c6841592Sxypron.glpk@gmx.de event->type = 0; 429c6841592Sxypron.glpk@gmx.de event->trigger_next = -1ULL; 430c6841592Sxypron.glpk@gmx.de event->signaled = 0; 431bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 432bee91169SAlexander Graf } 433c6841592Sxypron.glpk@gmx.de } 434c6841592Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 435c6841592Sxypron.glpk@gmx.de } 436bee91169SAlexander Graf 4372fd945feSxypron.glpk@gmx.de static efi_status_t EFIAPI efi_check_event(struct efi_event *event) 438bee91169SAlexander Graf { 439c6841592Sxypron.glpk@gmx.de int i; 440c6841592Sxypron.glpk@gmx.de 441bee91169SAlexander Graf EFI_ENTRY("%p", event); 442c6841592Sxypron.glpk@gmx.de efi_timer_check(); 443c6841592Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efi_events); ++i) { 444c6841592Sxypron.glpk@gmx.de if (event != &efi_events[i]) 445c6841592Sxypron.glpk@gmx.de continue; 446c6841592Sxypron.glpk@gmx.de if (!event->type || event->type & EVT_NOTIFY_SIGNAL) 447c6841592Sxypron.glpk@gmx.de break; 448c6841592Sxypron.glpk@gmx.de if (event->signaled) 449c6841592Sxypron.glpk@gmx.de return EFI_EXIT(EFI_SUCCESS); 450bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_READY); 451bee91169SAlexander Graf } 452c6841592Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 453c6841592Sxypron.glpk@gmx.de } 454bee91169SAlexander Graf 455bee91169SAlexander Graf static efi_status_t EFIAPI efi_install_protocol_interface(void **handle, 456bee91169SAlexander Graf efi_guid_t *protocol, int protocol_interface_type, 457bee91169SAlexander Graf void *protocol_interface) 458bee91169SAlexander Graf { 459e0549f8aSxypron.glpk@gmx.de struct list_head *lhandle; 460e0549f8aSxypron.glpk@gmx.de int i; 461e0549f8aSxypron.glpk@gmx.de efi_status_t r; 462e0549f8aSxypron.glpk@gmx.de 463e0549f8aSxypron.glpk@gmx.de if (!handle || !protocol || 464e0549f8aSxypron.glpk@gmx.de protocol_interface_type != EFI_NATIVE_INTERFACE) { 465e0549f8aSxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 466e0549f8aSxypron.glpk@gmx.de goto out; 467bee91169SAlexander Graf } 468e0549f8aSxypron.glpk@gmx.de 469e0549f8aSxypron.glpk@gmx.de /* Create new handle if requested. */ 470e0549f8aSxypron.glpk@gmx.de if (!*handle) { 471e0549f8aSxypron.glpk@gmx.de r = EFI_OUT_OF_RESOURCES; 472e0549f8aSxypron.glpk@gmx.de goto out; 473e0549f8aSxypron.glpk@gmx.de } 474e0549f8aSxypron.glpk@gmx.de /* Find object. */ 475e0549f8aSxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 476e0549f8aSxypron.glpk@gmx.de struct efi_object *efiobj; 477e0549f8aSxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 478e0549f8aSxypron.glpk@gmx.de 479e0549f8aSxypron.glpk@gmx.de if (efiobj->handle != *handle) 480e0549f8aSxypron.glpk@gmx.de continue; 481e0549f8aSxypron.glpk@gmx.de /* Check if protocol is already installed on the handle. */ 482e0549f8aSxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 483e0549f8aSxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 484e0549f8aSxypron.glpk@gmx.de 485e0549f8aSxypron.glpk@gmx.de if (!handler->guid) 486e0549f8aSxypron.glpk@gmx.de continue; 487e0549f8aSxypron.glpk@gmx.de if (!guidcmp(handler->guid, protocol)) { 488e0549f8aSxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 489e0549f8aSxypron.glpk@gmx.de goto out; 490e0549f8aSxypron.glpk@gmx.de } 491e0549f8aSxypron.glpk@gmx.de } 492e0549f8aSxypron.glpk@gmx.de /* Install protocol in first empty slot. */ 493e0549f8aSxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 494e0549f8aSxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 495e0549f8aSxypron.glpk@gmx.de 496e0549f8aSxypron.glpk@gmx.de if (handler->guid) 497e0549f8aSxypron.glpk@gmx.de continue; 498e0549f8aSxypron.glpk@gmx.de 499e0549f8aSxypron.glpk@gmx.de handler->guid = protocol; 500e0549f8aSxypron.glpk@gmx.de handler->protocol_interface = protocol_interface; 501e0549f8aSxypron.glpk@gmx.de r = EFI_SUCCESS; 502e0549f8aSxypron.glpk@gmx.de goto out; 503e0549f8aSxypron.glpk@gmx.de } 504e0549f8aSxypron.glpk@gmx.de r = EFI_OUT_OF_RESOURCES; 505e0549f8aSxypron.glpk@gmx.de goto out; 506e0549f8aSxypron.glpk@gmx.de } 507e0549f8aSxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 508e0549f8aSxypron.glpk@gmx.de out: 5098bee5a3cSxypron.glpk@gmx.de return r; 5108bee5a3cSxypron.glpk@gmx.de } 5118bee5a3cSxypron.glpk@gmx.de 5128bee5a3cSxypron.glpk@gmx.de static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle, 5138bee5a3cSxypron.glpk@gmx.de efi_guid_t *protocol, int protocol_interface_type, 5148bee5a3cSxypron.glpk@gmx.de void *protocol_interface) 5158bee5a3cSxypron.glpk@gmx.de { 5168bee5a3cSxypron.glpk@gmx.de EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type, 5178bee5a3cSxypron.glpk@gmx.de protocol_interface); 5188bee5a3cSxypron.glpk@gmx.de 5198bee5a3cSxypron.glpk@gmx.de return EFI_EXIT(efi_install_protocol_interface(handle, protocol, 5208bee5a3cSxypron.glpk@gmx.de protocol_interface_type, 5218bee5a3cSxypron.glpk@gmx.de protocol_interface)); 522e0549f8aSxypron.glpk@gmx.de } 523e0549f8aSxypron.glpk@gmx.de 524bee91169SAlexander Graf static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle, 525bee91169SAlexander Graf efi_guid_t *protocol, void *old_interface, 526bee91169SAlexander Graf void *new_interface) 527bee91169SAlexander Graf { 528bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface, 529bee91169SAlexander Graf new_interface); 530bee91169SAlexander Graf return EFI_EXIT(EFI_ACCESS_DENIED); 531bee91169SAlexander Graf } 532bee91169SAlexander Graf 533bee91169SAlexander Graf static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle, 534bee91169SAlexander Graf efi_guid_t *protocol, void *protocol_interface) 535bee91169SAlexander Graf { 5364b6ed0d7Sxypron.glpk@gmx.de struct list_head *lhandle; 5374b6ed0d7Sxypron.glpk@gmx.de int i; 5384b6ed0d7Sxypron.glpk@gmx.de efi_status_t r = EFI_NOT_FOUND; 5394b6ed0d7Sxypron.glpk@gmx.de 5404b6ed0d7Sxypron.glpk@gmx.de if (!handle || !protocol) { 5414b6ed0d7Sxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 5424b6ed0d7Sxypron.glpk@gmx.de goto out; 5434b6ed0d7Sxypron.glpk@gmx.de } 5444b6ed0d7Sxypron.glpk@gmx.de 5454b6ed0d7Sxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 5464b6ed0d7Sxypron.glpk@gmx.de struct efi_object *efiobj; 5474b6ed0d7Sxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 5484b6ed0d7Sxypron.glpk@gmx.de 5494b6ed0d7Sxypron.glpk@gmx.de if (efiobj->handle != handle) 5504b6ed0d7Sxypron.glpk@gmx.de continue; 5514b6ed0d7Sxypron.glpk@gmx.de 5524b6ed0d7Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 5534b6ed0d7Sxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 5544b6ed0d7Sxypron.glpk@gmx.de const efi_guid_t *hprotocol = handler->guid; 5554b6ed0d7Sxypron.glpk@gmx.de 5564b6ed0d7Sxypron.glpk@gmx.de if (!hprotocol) 5574b6ed0d7Sxypron.glpk@gmx.de continue; 5584b6ed0d7Sxypron.glpk@gmx.de if (!guidcmp(hprotocol, protocol)) { 5594b6ed0d7Sxypron.glpk@gmx.de if (handler->protocol_interface) { 5604b6ed0d7Sxypron.glpk@gmx.de r = EFI_ACCESS_DENIED; 5614b6ed0d7Sxypron.glpk@gmx.de } else { 5624b6ed0d7Sxypron.glpk@gmx.de handler->guid = 0; 5634b6ed0d7Sxypron.glpk@gmx.de r = EFI_SUCCESS; 5644b6ed0d7Sxypron.glpk@gmx.de } 5654b6ed0d7Sxypron.glpk@gmx.de goto out; 5664b6ed0d7Sxypron.glpk@gmx.de } 5674b6ed0d7Sxypron.glpk@gmx.de } 5684b6ed0d7Sxypron.glpk@gmx.de } 5694b6ed0d7Sxypron.glpk@gmx.de 5704b6ed0d7Sxypron.glpk@gmx.de out: 5713d8e1456Sxypron.glpk@gmx.de return r; 5723d8e1456Sxypron.glpk@gmx.de } 5733d8e1456Sxypron.glpk@gmx.de 5743d8e1456Sxypron.glpk@gmx.de static efi_status_t EFIAPI efi_uninstall_protocol_interface_ext(void *handle, 5753d8e1456Sxypron.glpk@gmx.de efi_guid_t *protocol, void *protocol_interface) 5763d8e1456Sxypron.glpk@gmx.de { 5773d8e1456Sxypron.glpk@gmx.de EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface); 5783d8e1456Sxypron.glpk@gmx.de 5793d8e1456Sxypron.glpk@gmx.de return EFI_EXIT(efi_uninstall_protocol_interface(handle, protocol, 5803d8e1456Sxypron.glpk@gmx.de protocol_interface)); 581bee91169SAlexander Graf } 582bee91169SAlexander Graf 583bee91169SAlexander Graf static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol, 5842fd945feSxypron.glpk@gmx.de struct efi_event *event, 585bee91169SAlexander Graf void **registration) 586bee91169SAlexander Graf { 587bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, event, registration); 588bee91169SAlexander Graf return EFI_EXIT(EFI_OUT_OF_RESOURCES); 589bee91169SAlexander Graf } 590bee91169SAlexander Graf 591bee91169SAlexander Graf static int efi_search(enum efi_locate_search_type search_type, 592bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 593bee91169SAlexander Graf struct efi_object *efiobj) 594bee91169SAlexander Graf { 595bee91169SAlexander Graf int i; 596bee91169SAlexander Graf 597bee91169SAlexander Graf switch (search_type) { 598bee91169SAlexander Graf case all_handles: 599bee91169SAlexander Graf return 0; 600bee91169SAlexander Graf case by_register_notify: 601bee91169SAlexander Graf return -1; 602bee91169SAlexander Graf case by_protocol: 603bee91169SAlexander Graf for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 604bee91169SAlexander Graf const efi_guid_t *guid = efiobj->protocols[i].guid; 605bee91169SAlexander Graf if (guid && !guidcmp(guid, protocol)) 606bee91169SAlexander Graf return 0; 607bee91169SAlexander Graf } 608bee91169SAlexander Graf return -1; 609bee91169SAlexander Graf } 610bee91169SAlexander Graf 611bee91169SAlexander Graf return -1; 612bee91169SAlexander Graf } 613bee91169SAlexander Graf 614*ebf199b9Sxypron.glpk@gmx.de static efi_status_t efi_locate_handle( 615bee91169SAlexander Graf enum efi_locate_search_type search_type, 616bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 617bee91169SAlexander Graf unsigned long *buffer_size, efi_handle_t *buffer) 618bee91169SAlexander Graf { 619bee91169SAlexander Graf struct list_head *lhandle; 620bee91169SAlexander Graf unsigned long size = 0; 621bee91169SAlexander Graf 622bee91169SAlexander Graf /* Count how much space we need */ 623bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 624bee91169SAlexander Graf struct efi_object *efiobj; 625bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 626bee91169SAlexander Graf if (!efi_search(search_type, protocol, search_key, efiobj)) { 627bee91169SAlexander Graf size += sizeof(void*); 628bee91169SAlexander Graf } 629bee91169SAlexander Graf } 630bee91169SAlexander Graf 631bee91169SAlexander Graf if (*buffer_size < size) { 632bee91169SAlexander Graf *buffer_size = size; 63326329584Sxypron.glpk@gmx.de return EFI_BUFFER_TOO_SMALL; 634bee91169SAlexander Graf } 635bee91169SAlexander Graf 636bee91169SAlexander Graf /* Then fill the array */ 637bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 638bee91169SAlexander Graf struct efi_object *efiobj; 639bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 640bee91169SAlexander Graf if (!efi_search(search_type, protocol, search_key, efiobj)) { 641bee91169SAlexander Graf *(buffer++) = efiobj->handle; 642bee91169SAlexander Graf } 643bee91169SAlexander Graf } 644bee91169SAlexander Graf 645bee91169SAlexander Graf *buffer_size = size; 64626329584Sxypron.glpk@gmx.de return EFI_SUCCESS; 64726329584Sxypron.glpk@gmx.de } 64826329584Sxypron.glpk@gmx.de 64926329584Sxypron.glpk@gmx.de static efi_status_t EFIAPI efi_locate_handle_ext( 65026329584Sxypron.glpk@gmx.de enum efi_locate_search_type search_type, 65126329584Sxypron.glpk@gmx.de efi_guid_t *protocol, void *search_key, 65226329584Sxypron.glpk@gmx.de unsigned long *buffer_size, efi_handle_t *buffer) 65326329584Sxypron.glpk@gmx.de { 65426329584Sxypron.glpk@gmx.de EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 65526329584Sxypron.glpk@gmx.de buffer_size, buffer); 65626329584Sxypron.glpk@gmx.de 65726329584Sxypron.glpk@gmx.de return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key, 65826329584Sxypron.glpk@gmx.de buffer_size, buffer)); 659bee91169SAlexander Graf } 660bee91169SAlexander Graf 661bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol, 662bee91169SAlexander Graf struct efi_device_path **device_path, 663bee91169SAlexander Graf efi_handle_t *device) 664bee91169SAlexander Graf { 665bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, device_path, device); 666bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 667bee91169SAlexander Graf } 668bee91169SAlexander Graf 669d98cdf6aSAlexander Graf /* Collapses configuration table entries, removing index i */ 670d98cdf6aSAlexander Graf static void efi_remove_configuration_table(int i) 671d98cdf6aSAlexander Graf { 672d98cdf6aSAlexander Graf struct efi_configuration_table *this = &efi_conf_table[i]; 673d98cdf6aSAlexander Graf struct efi_configuration_table *next = &efi_conf_table[i+1]; 674d98cdf6aSAlexander Graf struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables]; 675d98cdf6aSAlexander Graf 676d98cdf6aSAlexander Graf memmove(this, next, (ulong)end - (ulong)next); 677d98cdf6aSAlexander Graf systab.nr_tables--; 678d98cdf6aSAlexander Graf } 679d98cdf6aSAlexander Graf 680488bf12dSAlexander Graf efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table) 681bee91169SAlexander Graf { 682bee91169SAlexander Graf int i; 683bee91169SAlexander Graf 684bee91169SAlexander Graf /* Check for guid override */ 685bee91169SAlexander Graf for (i = 0; i < systab.nr_tables; i++) { 686bee91169SAlexander Graf if (!guidcmp(guid, &efi_conf_table[i].guid)) { 687d98cdf6aSAlexander Graf if (table) 688bee91169SAlexander Graf efi_conf_table[i].table = table; 689d98cdf6aSAlexander Graf else 690d98cdf6aSAlexander Graf efi_remove_configuration_table(i); 691488bf12dSAlexander Graf return EFI_SUCCESS; 692bee91169SAlexander Graf } 693bee91169SAlexander Graf } 694bee91169SAlexander Graf 695d98cdf6aSAlexander Graf if (!table) 696d98cdf6aSAlexander Graf return EFI_NOT_FOUND; 697d98cdf6aSAlexander Graf 698bee91169SAlexander Graf /* No override, check for overflow */ 699bee91169SAlexander Graf if (i >= ARRAY_SIZE(efi_conf_table)) 700488bf12dSAlexander Graf return EFI_OUT_OF_RESOURCES; 701bee91169SAlexander Graf 702bee91169SAlexander Graf /* Add a new entry */ 703bee91169SAlexander Graf memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); 704bee91169SAlexander Graf efi_conf_table[i].table = table; 705aba5e919SAlexander Graf systab.nr_tables = i + 1; 706bee91169SAlexander Graf 707488bf12dSAlexander Graf return EFI_SUCCESS; 708488bf12dSAlexander Graf } 709488bf12dSAlexander Graf 710488bf12dSAlexander Graf static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, 711488bf12dSAlexander Graf void *table) 712488bf12dSAlexander Graf { 713488bf12dSAlexander Graf EFI_ENTRY("%p, %p", guid, table); 714488bf12dSAlexander Graf return EFI_EXIT(efi_install_configuration_table(guid, table)); 715bee91169SAlexander Graf } 716bee91169SAlexander Graf 717bee91169SAlexander Graf static efi_status_t EFIAPI efi_load_image(bool boot_policy, 718bee91169SAlexander Graf efi_handle_t parent_image, 719bee91169SAlexander Graf struct efi_device_path *file_path, 720bee91169SAlexander Graf void *source_buffer, 721bee91169SAlexander Graf unsigned long source_size, 722bee91169SAlexander Graf efi_handle_t *image_handle) 723bee91169SAlexander Graf { 724bee91169SAlexander Graf static struct efi_object loaded_image_info_obj = { 725bee91169SAlexander Graf .protocols = { 726bee91169SAlexander Graf { 727bee91169SAlexander Graf .guid = &efi_guid_loaded_image, 728bee91169SAlexander Graf }, 729bee91169SAlexander Graf }, 730bee91169SAlexander Graf }; 731bee91169SAlexander Graf struct efi_loaded_image *info; 732bee91169SAlexander Graf struct efi_object *obj; 733bee91169SAlexander Graf 734bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, 735bee91169SAlexander Graf file_path, source_buffer, source_size, image_handle); 736bee91169SAlexander Graf info = malloc(sizeof(*info)); 737b5349f74Sxypron.glpk@gmx.de loaded_image_info_obj.protocols[0].protocol_interface = info; 738bee91169SAlexander Graf obj = malloc(sizeof(loaded_image_info_obj)); 739bee91169SAlexander Graf memset(info, 0, sizeof(*info)); 740bee91169SAlexander Graf memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); 741bee91169SAlexander Graf obj->handle = info; 742bee91169SAlexander Graf info->file_path = file_path; 743bee91169SAlexander Graf info->reserved = efi_load_pe(source_buffer, info); 744bee91169SAlexander Graf if (!info->reserved) { 745bee91169SAlexander Graf free(info); 746bee91169SAlexander Graf free(obj); 747bee91169SAlexander Graf return EFI_EXIT(EFI_UNSUPPORTED); 748bee91169SAlexander Graf } 749bee91169SAlexander Graf 750bee91169SAlexander Graf *image_handle = info; 751bee91169SAlexander Graf list_add_tail(&obj->link, &efi_obj_list); 752bee91169SAlexander Graf 753bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 754bee91169SAlexander Graf } 755bee91169SAlexander Graf 756bee91169SAlexander Graf static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, 757bee91169SAlexander Graf unsigned long *exit_data_size, 758bee91169SAlexander Graf s16 **exit_data) 759bee91169SAlexander Graf { 760bee91169SAlexander Graf ulong (*entry)(void *image_handle, struct efi_system_table *st); 761bee91169SAlexander Graf struct efi_loaded_image *info = image_handle; 762bee91169SAlexander Graf 763bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); 764bee91169SAlexander Graf entry = info->reserved; 765bee91169SAlexander Graf 766bee91169SAlexander Graf efi_is_direct_boot = false; 767bee91169SAlexander Graf 768bee91169SAlexander Graf /* call the image! */ 769a86aeaf2SAlexander Graf if (setjmp(&info->exit_jmp)) { 770a86aeaf2SAlexander Graf /* We returned from the child image */ 771a86aeaf2SAlexander Graf return EFI_EXIT(info->exit_status); 772a86aeaf2SAlexander Graf } 773a86aeaf2SAlexander Graf 774af65db85SRob Clark __efi_nesting_dec(); 775c160d2f5SRob Clark __efi_exit_check(); 776bee91169SAlexander Graf entry(image_handle, &systab); 777c160d2f5SRob Clark __efi_entry_check(); 778af65db85SRob Clark __efi_nesting_inc(); 779bee91169SAlexander Graf 780bee91169SAlexander Graf /* Should usually never get here */ 781bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 782bee91169SAlexander Graf } 783bee91169SAlexander Graf 784a86aeaf2SAlexander Graf static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, 785a86aeaf2SAlexander Graf efi_status_t exit_status, unsigned long exit_data_size, 786a86aeaf2SAlexander Graf int16_t *exit_data) 787bee91169SAlexander Graf { 788a86aeaf2SAlexander Graf struct efi_loaded_image *loaded_image_info = (void*)image_handle; 789a86aeaf2SAlexander Graf 790bee91169SAlexander Graf EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, 791bee91169SAlexander Graf exit_data_size, exit_data); 792a86aeaf2SAlexander Graf 793a86aeaf2SAlexander Graf loaded_image_info->exit_status = exit_status; 794692fcdd8SAlexander Graf longjmp(&loaded_image_info->exit_jmp, 1); 795a86aeaf2SAlexander Graf 796a86aeaf2SAlexander Graf panic("EFI application exited"); 797bee91169SAlexander Graf } 798bee91169SAlexander Graf 799bee91169SAlexander Graf static struct efi_object *efi_search_obj(void *handle) 800bee91169SAlexander Graf { 801bee91169SAlexander Graf struct list_head *lhandle; 802bee91169SAlexander Graf 803bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 804bee91169SAlexander Graf struct efi_object *efiobj; 805bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 806bee91169SAlexander Graf if (efiobj->handle == handle) 807bee91169SAlexander Graf return efiobj; 808bee91169SAlexander Graf } 809bee91169SAlexander Graf 810bee91169SAlexander Graf return NULL; 811bee91169SAlexander Graf } 812bee91169SAlexander Graf 813bee91169SAlexander Graf static efi_status_t EFIAPI efi_unload_image(void *image_handle) 814bee91169SAlexander Graf { 815bee91169SAlexander Graf struct efi_object *efiobj; 816bee91169SAlexander Graf 817bee91169SAlexander Graf EFI_ENTRY("%p", image_handle); 818bee91169SAlexander Graf efiobj = efi_search_obj(image_handle); 819bee91169SAlexander Graf if (efiobj) 820bee91169SAlexander Graf list_del(&efiobj->link); 821bee91169SAlexander Graf 822bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 823bee91169SAlexander Graf } 824bee91169SAlexander Graf 825bee91169SAlexander Graf static void efi_exit_caches(void) 826bee91169SAlexander Graf { 827bee91169SAlexander Graf #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) 828bee91169SAlexander Graf /* 829bee91169SAlexander Graf * Grub on 32bit ARM needs to have caches disabled before jumping into 830bee91169SAlexander Graf * a zImage, but does not know of all cache layers. Give it a hand. 831bee91169SAlexander Graf */ 832bee91169SAlexander Graf if (efi_is_direct_boot) 833bee91169SAlexander Graf cleanup_before_linux(); 834bee91169SAlexander Graf #endif 835bee91169SAlexander Graf } 836bee91169SAlexander Graf 837bee91169SAlexander Graf static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, 838bee91169SAlexander Graf unsigned long map_key) 839bee91169SAlexander Graf { 840bee91169SAlexander Graf EFI_ENTRY("%p, %ld", image_handle, map_key); 841bee91169SAlexander Graf 842b7b8410aSAlexander Graf board_quiesce_devices(); 843b7b8410aSAlexander Graf 844bee91169SAlexander Graf /* Fix up caches for EFI payloads if necessary */ 845bee91169SAlexander Graf efi_exit_caches(); 846bee91169SAlexander Graf 847bee91169SAlexander Graf /* This stops all lingering devices */ 848bee91169SAlexander Graf bootm_disable_interrupts(); 849bee91169SAlexander Graf 850bee91169SAlexander Graf /* Give the payload some time to boot */ 851bee91169SAlexander Graf WATCHDOG_RESET(); 852bee91169SAlexander Graf 853bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 854bee91169SAlexander Graf } 855bee91169SAlexander Graf 856bee91169SAlexander Graf static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) 857bee91169SAlexander Graf { 858bee91169SAlexander Graf static uint64_t mono = 0; 859bee91169SAlexander Graf EFI_ENTRY("%p", count); 860bee91169SAlexander Graf *count = mono++; 861bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 862bee91169SAlexander Graf } 863bee91169SAlexander Graf 864bee91169SAlexander Graf static efi_status_t EFIAPI efi_stall(unsigned long microseconds) 865bee91169SAlexander Graf { 866bee91169SAlexander Graf EFI_ENTRY("%ld", microseconds); 867bee91169SAlexander Graf udelay(microseconds); 868bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 869bee91169SAlexander Graf } 870bee91169SAlexander Graf 871bee91169SAlexander Graf static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, 872bee91169SAlexander Graf uint64_t watchdog_code, 873bee91169SAlexander Graf unsigned long data_size, 874bee91169SAlexander Graf uint16_t *watchdog_data) 875bee91169SAlexander Graf { 876bee91169SAlexander Graf EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, 877bee91169SAlexander Graf data_size, watchdog_data); 878b5104821SRob Clark return efi_unsupported(__func__); 879bee91169SAlexander Graf } 880bee91169SAlexander Graf 881bee91169SAlexander Graf static efi_status_t EFIAPI efi_connect_controller( 882bee91169SAlexander Graf efi_handle_t controller_handle, 883bee91169SAlexander Graf efi_handle_t *driver_image_handle, 884bee91169SAlexander Graf struct efi_device_path *remain_device_path, 885bee91169SAlexander Graf bool recursive) 886bee91169SAlexander Graf { 887bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle, 888bee91169SAlexander Graf remain_device_path, recursive); 889bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 890bee91169SAlexander Graf } 891bee91169SAlexander Graf 892bee91169SAlexander Graf static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle, 893bee91169SAlexander Graf void *driver_image_handle, 894bee91169SAlexander Graf void *child_handle) 895bee91169SAlexander Graf { 896bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, 897bee91169SAlexander Graf child_handle); 898bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 899bee91169SAlexander Graf } 900bee91169SAlexander Graf 901bee91169SAlexander Graf static efi_status_t EFIAPI efi_close_protocol(void *handle, 902bee91169SAlexander Graf efi_guid_t *protocol, 903bee91169SAlexander Graf void *agent_handle, 904bee91169SAlexander Graf void *controller_handle) 905bee91169SAlexander Graf { 906bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle, 907bee91169SAlexander Graf controller_handle); 908bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 909bee91169SAlexander Graf } 910bee91169SAlexander Graf 911bee91169SAlexander Graf static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, 912bee91169SAlexander Graf efi_guid_t *protocol, 913bee91169SAlexander Graf struct efi_open_protocol_info_entry **entry_buffer, 914bee91169SAlexander Graf unsigned long *entry_count) 915bee91169SAlexander Graf { 916bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, 917bee91169SAlexander Graf entry_count); 918bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 919bee91169SAlexander Graf } 920bee91169SAlexander Graf 921bee91169SAlexander Graf static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, 922bee91169SAlexander Graf efi_guid_t ***protocol_buffer, 923bee91169SAlexander Graf unsigned long *protocol_buffer_count) 924bee91169SAlexander Graf { 925c0ebfc86Sxypron.glpk@gmx.de unsigned long buffer_size; 926c0ebfc86Sxypron.glpk@gmx.de struct efi_object *efiobj; 927c0ebfc86Sxypron.glpk@gmx.de unsigned long i, j; 928c0ebfc86Sxypron.glpk@gmx.de struct list_head *lhandle; 929c0ebfc86Sxypron.glpk@gmx.de efi_status_t r; 930c0ebfc86Sxypron.glpk@gmx.de 931bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, 932bee91169SAlexander Graf protocol_buffer_count); 933c0ebfc86Sxypron.glpk@gmx.de 934c0ebfc86Sxypron.glpk@gmx.de if (!handle || !protocol_buffer || !protocol_buffer_count) 935c0ebfc86Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 936c0ebfc86Sxypron.glpk@gmx.de 937c0ebfc86Sxypron.glpk@gmx.de *protocol_buffer = NULL; 938661c8327SRob Clark *protocol_buffer_count = 0; 939c0ebfc86Sxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 940c0ebfc86Sxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 941c0ebfc86Sxypron.glpk@gmx.de 942c0ebfc86Sxypron.glpk@gmx.de if (efiobj->handle != handle) 943c0ebfc86Sxypron.glpk@gmx.de continue; 944c0ebfc86Sxypron.glpk@gmx.de 945c0ebfc86Sxypron.glpk@gmx.de /* Count protocols */ 946c0ebfc86Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 947c0ebfc86Sxypron.glpk@gmx.de if (efiobj->protocols[i].guid) 948c0ebfc86Sxypron.glpk@gmx.de ++*protocol_buffer_count; 949c0ebfc86Sxypron.glpk@gmx.de } 950c0ebfc86Sxypron.glpk@gmx.de /* Copy guids */ 951c0ebfc86Sxypron.glpk@gmx.de if (*protocol_buffer_count) { 952c0ebfc86Sxypron.glpk@gmx.de buffer_size = sizeof(efi_guid_t *) * 953c0ebfc86Sxypron.glpk@gmx.de *protocol_buffer_count; 954c0ebfc86Sxypron.glpk@gmx.de r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, 955c0ebfc86Sxypron.glpk@gmx.de buffer_size, 956c0ebfc86Sxypron.glpk@gmx.de (void **)protocol_buffer); 957c0ebfc86Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 958c0ebfc86Sxypron.glpk@gmx.de return EFI_EXIT(r); 959c0ebfc86Sxypron.glpk@gmx.de j = 0; 960c0ebfc86Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) { 961c0ebfc86Sxypron.glpk@gmx.de if (efiobj->protocols[i].guid) { 962c0ebfc86Sxypron.glpk@gmx.de (*protocol_buffer)[j] = (void *) 963c0ebfc86Sxypron.glpk@gmx.de efiobj->protocols[i].guid; 964c0ebfc86Sxypron.glpk@gmx.de ++j; 965c0ebfc86Sxypron.glpk@gmx.de } 966c0ebfc86Sxypron.glpk@gmx.de } 967c0ebfc86Sxypron.glpk@gmx.de } 968c0ebfc86Sxypron.glpk@gmx.de break; 969c0ebfc86Sxypron.glpk@gmx.de } 970c0ebfc86Sxypron.glpk@gmx.de 971c0ebfc86Sxypron.glpk@gmx.de return EFI_EXIT(EFI_SUCCESS); 972bee91169SAlexander Graf } 973bee91169SAlexander Graf 974bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_handle_buffer( 975bee91169SAlexander Graf enum efi_locate_search_type search_type, 976bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 977bee91169SAlexander Graf unsigned long *no_handles, efi_handle_t **buffer) 978bee91169SAlexander Graf { 979c2e703f9Sxypron.glpk@gmx.de efi_status_t r; 980c2e703f9Sxypron.glpk@gmx.de unsigned long buffer_size = 0; 981c2e703f9Sxypron.glpk@gmx.de 982bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 983bee91169SAlexander Graf no_handles, buffer); 984c2e703f9Sxypron.glpk@gmx.de 985c2e703f9Sxypron.glpk@gmx.de if (!no_handles || !buffer) { 986c2e703f9Sxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 987c2e703f9Sxypron.glpk@gmx.de goto out; 988c2e703f9Sxypron.glpk@gmx.de } 989c2e703f9Sxypron.glpk@gmx.de *no_handles = 0; 990c2e703f9Sxypron.glpk@gmx.de *buffer = NULL; 991c2e703f9Sxypron.glpk@gmx.de r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, 992c2e703f9Sxypron.glpk@gmx.de *buffer); 993c2e703f9Sxypron.glpk@gmx.de if (r != EFI_BUFFER_TOO_SMALL) 994c2e703f9Sxypron.glpk@gmx.de goto out; 995c2e703f9Sxypron.glpk@gmx.de r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, 996c2e703f9Sxypron.glpk@gmx.de (void **)buffer); 997c2e703f9Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 998c2e703f9Sxypron.glpk@gmx.de goto out; 999c2e703f9Sxypron.glpk@gmx.de r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, 1000c2e703f9Sxypron.glpk@gmx.de *buffer); 1001c2e703f9Sxypron.glpk@gmx.de if (r == EFI_SUCCESS) 1002c2e703f9Sxypron.glpk@gmx.de *no_handles = buffer_size / sizeof(void *); 1003c2e703f9Sxypron.glpk@gmx.de out: 1004c2e703f9Sxypron.glpk@gmx.de return EFI_EXIT(r); 1005bee91169SAlexander Graf } 1006bee91169SAlexander Graf 1007bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol, 1008bee91169SAlexander Graf void *registration, 1009bee91169SAlexander Graf void **protocol_interface) 1010bee91169SAlexander Graf { 101188adae5eSxypron.glpk@gmx.de struct list_head *lhandle; 1012bee91169SAlexander Graf int i; 1013bee91169SAlexander Graf 1014bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface); 101588adae5eSxypron.glpk@gmx.de 101688adae5eSxypron.glpk@gmx.de if (!protocol || !protocol_interface) 101788adae5eSxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 101888adae5eSxypron.glpk@gmx.de 101988adae5eSxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 102088adae5eSxypron.glpk@gmx.de struct efi_object *efiobj; 102188adae5eSxypron.glpk@gmx.de 102288adae5eSxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 102388adae5eSxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 102488adae5eSxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 102588adae5eSxypron.glpk@gmx.de 102688adae5eSxypron.glpk@gmx.de if (!handler->guid) 102788adae5eSxypron.glpk@gmx.de continue; 102888adae5eSxypron.glpk@gmx.de if (!guidcmp(handler->guid, protocol)) { 102988adae5eSxypron.glpk@gmx.de *protocol_interface = 103088adae5eSxypron.glpk@gmx.de handler->protocol_interface; 1031bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 1032bee91169SAlexander Graf } 1033bee91169SAlexander Graf } 103488adae5eSxypron.glpk@gmx.de } 103588adae5eSxypron.glpk@gmx.de *protocol_interface = NULL; 1036bee91169SAlexander Graf 1037bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 1038bee91169SAlexander Graf } 1039bee91169SAlexander Graf 1040bee91169SAlexander Graf static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( 1041bee91169SAlexander Graf void **handle, ...) 1042bee91169SAlexander Graf { 1043bee91169SAlexander Graf EFI_ENTRY("%p", handle); 104458b83586Sxypron.glpk@gmx.de 104558b83586Sxypron.glpk@gmx.de va_list argptr; 104658b83586Sxypron.glpk@gmx.de efi_guid_t *protocol; 104758b83586Sxypron.glpk@gmx.de void *protocol_interface; 104858b83586Sxypron.glpk@gmx.de efi_status_t r = EFI_SUCCESS; 104958b83586Sxypron.glpk@gmx.de int i = 0; 105058b83586Sxypron.glpk@gmx.de 105158b83586Sxypron.glpk@gmx.de if (!handle) 105258b83586Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 105358b83586Sxypron.glpk@gmx.de 105458b83586Sxypron.glpk@gmx.de va_start(argptr, handle); 105558b83586Sxypron.glpk@gmx.de for (;;) { 105658b83586Sxypron.glpk@gmx.de protocol = va_arg(argptr, efi_guid_t*); 105758b83586Sxypron.glpk@gmx.de if (!protocol) 105858b83586Sxypron.glpk@gmx.de break; 105958b83586Sxypron.glpk@gmx.de protocol_interface = va_arg(argptr, void*); 106058b83586Sxypron.glpk@gmx.de r = efi_install_protocol_interface(handle, protocol, 106158b83586Sxypron.glpk@gmx.de EFI_NATIVE_INTERFACE, 106258b83586Sxypron.glpk@gmx.de protocol_interface); 106358b83586Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 106458b83586Sxypron.glpk@gmx.de break; 106558b83586Sxypron.glpk@gmx.de i++; 106658b83586Sxypron.glpk@gmx.de } 106758b83586Sxypron.glpk@gmx.de va_end(argptr); 106858b83586Sxypron.glpk@gmx.de if (r == EFI_SUCCESS) 106958b83586Sxypron.glpk@gmx.de return EFI_EXIT(r); 107058b83586Sxypron.glpk@gmx.de 107158b83586Sxypron.glpk@gmx.de /* If an error occured undo all changes. */ 107258b83586Sxypron.glpk@gmx.de va_start(argptr, handle); 107358b83586Sxypron.glpk@gmx.de for (; i; --i) { 107458b83586Sxypron.glpk@gmx.de protocol = va_arg(argptr, efi_guid_t*); 107558b83586Sxypron.glpk@gmx.de protocol_interface = va_arg(argptr, void*); 107658b83586Sxypron.glpk@gmx.de efi_uninstall_protocol_interface(handle, protocol, 107758b83586Sxypron.glpk@gmx.de protocol_interface); 107858b83586Sxypron.glpk@gmx.de } 107958b83586Sxypron.glpk@gmx.de va_end(argptr); 108058b83586Sxypron.glpk@gmx.de 108158b83586Sxypron.glpk@gmx.de return EFI_EXIT(r); 1082bee91169SAlexander Graf } 1083bee91169SAlexander Graf 1084bee91169SAlexander Graf static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( 1085bee91169SAlexander Graf void *handle, ...) 1086bee91169SAlexander Graf { 1087bee91169SAlexander Graf EFI_ENTRY("%p", handle); 1088bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 1089bee91169SAlexander Graf } 1090bee91169SAlexander Graf 1091bee91169SAlexander Graf static efi_status_t EFIAPI efi_calculate_crc32(void *data, 1092bee91169SAlexander Graf unsigned long data_size, 1093bee91169SAlexander Graf uint32_t *crc32_p) 1094bee91169SAlexander Graf { 1095bee91169SAlexander Graf EFI_ENTRY("%p, %ld", data, data_size); 1096bee91169SAlexander Graf *crc32_p = crc32(0, data, data_size); 1097bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 1098bee91169SAlexander Graf } 1099bee91169SAlexander Graf 1100bee91169SAlexander Graf static void EFIAPI efi_copy_mem(void *destination, void *source, 1101bee91169SAlexander Graf unsigned long length) 1102bee91169SAlexander Graf { 1103bee91169SAlexander Graf EFI_ENTRY("%p, %p, %ld", destination, source, length); 1104bee91169SAlexander Graf memcpy(destination, source, length); 1105bee91169SAlexander Graf } 1106bee91169SAlexander Graf 1107bee91169SAlexander Graf static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value) 1108bee91169SAlexander Graf { 1109bee91169SAlexander Graf EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value); 1110bee91169SAlexander Graf memset(buffer, value, size); 1111bee91169SAlexander Graf } 1112bee91169SAlexander Graf 1113bee91169SAlexander Graf static efi_status_t EFIAPI efi_open_protocol( 1114bee91169SAlexander Graf void *handle, efi_guid_t *protocol, 1115bee91169SAlexander Graf void **protocol_interface, void *agent_handle, 1116bee91169SAlexander Graf void *controller_handle, uint32_t attributes) 1117bee91169SAlexander Graf { 1118bee91169SAlexander Graf struct list_head *lhandle; 1119bee91169SAlexander Graf int i; 112069baec67Sxypron.glpk@gmx.de efi_status_t r = EFI_INVALID_PARAMETER; 1121bee91169SAlexander Graf 1122bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol, 1123bee91169SAlexander Graf protocol_interface, agent_handle, controller_handle, 1124bee91169SAlexander Graf attributes); 1125b5349f74Sxypron.glpk@gmx.de 112669baec67Sxypron.glpk@gmx.de if (!handle || !protocol || 112769baec67Sxypron.glpk@gmx.de (!protocol_interface && attributes != 112869baec67Sxypron.glpk@gmx.de EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) { 112969baec67Sxypron.glpk@gmx.de goto out; 113069baec67Sxypron.glpk@gmx.de } 113169baec67Sxypron.glpk@gmx.de 113269baec67Sxypron.glpk@gmx.de switch (attributes) { 113369baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: 113469baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_GET_PROTOCOL: 113569baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: 113669baec67Sxypron.glpk@gmx.de break; 113769baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: 113869baec67Sxypron.glpk@gmx.de if (controller_handle == handle) 113969baec67Sxypron.glpk@gmx.de goto out; 114069baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_DRIVER: 114169baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: 114269baec67Sxypron.glpk@gmx.de if (controller_handle == NULL) 114369baec67Sxypron.glpk@gmx.de goto out; 114469baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_EXCLUSIVE: 114569baec67Sxypron.glpk@gmx.de if (agent_handle == NULL) 114669baec67Sxypron.glpk@gmx.de goto out; 114769baec67Sxypron.glpk@gmx.de break; 114869baec67Sxypron.glpk@gmx.de default: 1149b5349f74Sxypron.glpk@gmx.de goto out; 1150b5349f74Sxypron.glpk@gmx.de } 1151b5349f74Sxypron.glpk@gmx.de 1152bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 1153bee91169SAlexander Graf struct efi_object *efiobj; 1154bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 1155bee91169SAlexander Graf 1156bee91169SAlexander Graf if (efiobj->handle != handle) 1157bee91169SAlexander Graf continue; 1158bee91169SAlexander Graf 1159bee91169SAlexander Graf for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 1160bee91169SAlexander Graf struct efi_handler *handler = &efiobj->protocols[i]; 1161bee91169SAlexander Graf const efi_guid_t *hprotocol = handler->guid; 1162bee91169SAlexander Graf if (!hprotocol) 11634b6ed0d7Sxypron.glpk@gmx.de continue; 1164bee91169SAlexander Graf if (!guidcmp(hprotocol, protocol)) { 1165b5349f74Sxypron.glpk@gmx.de if (attributes != 1166b5349f74Sxypron.glpk@gmx.de EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { 1167b5349f74Sxypron.glpk@gmx.de *protocol_interface = 1168b5349f74Sxypron.glpk@gmx.de handler->protocol_interface; 1169b5349f74Sxypron.glpk@gmx.de } 1170b5349f74Sxypron.glpk@gmx.de r = EFI_SUCCESS; 1171bee91169SAlexander Graf goto out; 1172bee91169SAlexander Graf } 1173bee91169SAlexander Graf } 117469baec67Sxypron.glpk@gmx.de goto unsupported; 1175bee91169SAlexander Graf } 1176bee91169SAlexander Graf 117769baec67Sxypron.glpk@gmx.de unsupported: 117869baec67Sxypron.glpk@gmx.de r = EFI_UNSUPPORTED; 1179bee91169SAlexander Graf out: 1180bee91169SAlexander Graf return EFI_EXIT(r); 1181bee91169SAlexander Graf } 1182bee91169SAlexander Graf 1183bee91169SAlexander Graf static efi_status_t EFIAPI efi_handle_protocol(void *handle, 1184bee91169SAlexander Graf efi_guid_t *protocol, 1185bee91169SAlexander Graf void **protocol_interface) 1186bee91169SAlexander Graf { 11878e1d329fSxypron.glpk@gmx.de return efi_open_protocol(handle, protocol, protocol_interface, NULL, 11888e1d329fSxypron.glpk@gmx.de NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); 1189bee91169SAlexander Graf } 1190bee91169SAlexander Graf 1191bee91169SAlexander Graf static const struct efi_boot_services efi_boot_services = { 1192bee91169SAlexander Graf .hdr = { 1193bee91169SAlexander Graf .headersize = sizeof(struct efi_table_hdr), 1194bee91169SAlexander Graf }, 1195bee91169SAlexander Graf .raise_tpl = efi_raise_tpl, 1196bee91169SAlexander Graf .restore_tpl = efi_restore_tpl, 1197bee91169SAlexander Graf .allocate_pages = efi_allocate_pages_ext, 1198bee91169SAlexander Graf .free_pages = efi_free_pages_ext, 1199bee91169SAlexander Graf .get_memory_map = efi_get_memory_map_ext, 1200ead1274bSStefan Brüns .allocate_pool = efi_allocate_pool_ext, 120142417bc8SStefan Brüns .free_pool = efi_free_pool_ext, 120249deb455Sxypron.glpk@gmx.de .create_event = efi_create_event_ext, 1203bfc72462Sxypron.glpk@gmx.de .set_timer = efi_set_timer_ext, 1204bee91169SAlexander Graf .wait_for_event = efi_wait_for_event, 1205c6841592Sxypron.glpk@gmx.de .signal_event = efi_signal_event_ext, 1206bee91169SAlexander Graf .close_event = efi_close_event, 1207bee91169SAlexander Graf .check_event = efi_check_event, 12088bee5a3cSxypron.glpk@gmx.de .install_protocol_interface = efi_install_protocol_interface_ext, 1209bee91169SAlexander Graf .reinstall_protocol_interface = efi_reinstall_protocol_interface, 12103d8e1456Sxypron.glpk@gmx.de .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext, 1211bee91169SAlexander Graf .handle_protocol = efi_handle_protocol, 1212bee91169SAlexander Graf .reserved = NULL, 1213bee91169SAlexander Graf .register_protocol_notify = efi_register_protocol_notify, 121426329584Sxypron.glpk@gmx.de .locate_handle = efi_locate_handle_ext, 1215bee91169SAlexander Graf .locate_device_path = efi_locate_device_path, 1216488bf12dSAlexander Graf .install_configuration_table = efi_install_configuration_table_ext, 1217bee91169SAlexander Graf .load_image = efi_load_image, 1218bee91169SAlexander Graf .start_image = efi_start_image, 1219a86aeaf2SAlexander Graf .exit = efi_exit, 1220bee91169SAlexander Graf .unload_image = efi_unload_image, 1221bee91169SAlexander Graf .exit_boot_services = efi_exit_boot_services, 1222bee91169SAlexander Graf .get_next_monotonic_count = efi_get_next_monotonic_count, 1223bee91169SAlexander Graf .stall = efi_stall, 1224bee91169SAlexander Graf .set_watchdog_timer = efi_set_watchdog_timer, 1225bee91169SAlexander Graf .connect_controller = efi_connect_controller, 1226bee91169SAlexander Graf .disconnect_controller = efi_disconnect_controller, 1227bee91169SAlexander Graf .open_protocol = efi_open_protocol, 1228bee91169SAlexander Graf .close_protocol = efi_close_protocol, 1229bee91169SAlexander Graf .open_protocol_information = efi_open_protocol_information, 1230bee91169SAlexander Graf .protocols_per_handle = efi_protocols_per_handle, 1231bee91169SAlexander Graf .locate_handle_buffer = efi_locate_handle_buffer, 1232bee91169SAlexander Graf .locate_protocol = efi_locate_protocol, 1233bee91169SAlexander Graf .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces, 1234bee91169SAlexander Graf .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces, 1235bee91169SAlexander Graf .calculate_crc32 = efi_calculate_crc32, 1236bee91169SAlexander Graf .copy_mem = efi_copy_mem, 1237bee91169SAlexander Graf .set_mem = efi_set_mem, 1238bee91169SAlexander Graf }; 1239bee91169SAlexander Graf 1240bee91169SAlexander Graf 12413c63db9cSAlexander Graf static uint16_t __efi_runtime_data firmware_vendor[] = 1242bee91169SAlexander Graf { 'D','a','s',' ','U','-','b','o','o','t',0 }; 1243bee91169SAlexander Graf 12443c63db9cSAlexander Graf struct efi_system_table __efi_runtime_data systab = { 1245bee91169SAlexander Graf .hdr = { 1246bee91169SAlexander Graf .signature = EFI_SYSTEM_TABLE_SIGNATURE, 1247bee91169SAlexander Graf .revision = 0x20005, /* 2.5 */ 1248bee91169SAlexander Graf .headersize = sizeof(struct efi_table_hdr), 1249bee91169SAlexander Graf }, 1250bee91169SAlexander Graf .fw_vendor = (long)firmware_vendor, 1251bee91169SAlexander Graf .con_in = (void*)&efi_con_in, 1252bee91169SAlexander Graf .con_out = (void*)&efi_con_out, 1253bee91169SAlexander Graf .std_err = (void*)&efi_con_out, 1254bee91169SAlexander Graf .runtime = (void*)&efi_runtime_services, 1255bee91169SAlexander Graf .boottime = (void*)&efi_boot_services, 1256bee91169SAlexander Graf .nr_tables = 0, 1257bee91169SAlexander Graf .tables = (void*)efi_conf_table, 1258bee91169SAlexander Graf }; 1259