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> 130e00a84cSMasahiro Yamada #include <linux/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 614ebf199b9Sxypron.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 636796a78cbSRob Clark *buffer_size = size; 637796a78cbSRob Clark if (size == 0) 638796a78cbSRob Clark return EFI_NOT_FOUND; 639796a78cbSRob Clark 640bee91169SAlexander Graf /* Then fill the array */ 641bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 642bee91169SAlexander Graf struct efi_object *efiobj; 643bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 644bee91169SAlexander Graf if (!efi_search(search_type, protocol, search_key, efiobj)) { 645bee91169SAlexander Graf *(buffer++) = efiobj->handle; 646bee91169SAlexander Graf } 647bee91169SAlexander Graf } 648bee91169SAlexander Graf 64926329584Sxypron.glpk@gmx.de return EFI_SUCCESS; 65026329584Sxypron.glpk@gmx.de } 65126329584Sxypron.glpk@gmx.de 65226329584Sxypron.glpk@gmx.de static efi_status_t EFIAPI efi_locate_handle_ext( 65326329584Sxypron.glpk@gmx.de enum efi_locate_search_type search_type, 65426329584Sxypron.glpk@gmx.de efi_guid_t *protocol, void *search_key, 65526329584Sxypron.glpk@gmx.de unsigned long *buffer_size, efi_handle_t *buffer) 65626329584Sxypron.glpk@gmx.de { 65726329584Sxypron.glpk@gmx.de EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 65826329584Sxypron.glpk@gmx.de buffer_size, buffer); 65926329584Sxypron.glpk@gmx.de 66026329584Sxypron.glpk@gmx.de return EFI_EXIT(efi_locate_handle(search_type, protocol, search_key, 66126329584Sxypron.glpk@gmx.de buffer_size, buffer)); 662bee91169SAlexander Graf } 663bee91169SAlexander Graf 664bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol, 665bee91169SAlexander Graf struct efi_device_path **device_path, 666bee91169SAlexander Graf efi_handle_t *device) 667bee91169SAlexander Graf { 668*1fa8dee8SRob Clark struct efi_object *efiobj; 669*1fa8dee8SRob Clark 670*1fa8dee8SRob Clark EFI_ENTRY("%pUl, %p, %p", protocol, device_path, device); 671*1fa8dee8SRob Clark 672*1fa8dee8SRob Clark efiobj = efi_dp_find_obj(*device_path, device_path); 673*1fa8dee8SRob Clark if (!efiobj) 674bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 675*1fa8dee8SRob Clark 676*1fa8dee8SRob Clark *device = efiobj->handle; 677*1fa8dee8SRob Clark 678*1fa8dee8SRob Clark return EFI_EXIT(EFI_SUCCESS); 679bee91169SAlexander Graf } 680bee91169SAlexander Graf 681d98cdf6aSAlexander Graf /* Collapses configuration table entries, removing index i */ 682d98cdf6aSAlexander Graf static void efi_remove_configuration_table(int i) 683d98cdf6aSAlexander Graf { 684d98cdf6aSAlexander Graf struct efi_configuration_table *this = &efi_conf_table[i]; 685d98cdf6aSAlexander Graf struct efi_configuration_table *next = &efi_conf_table[i+1]; 686d98cdf6aSAlexander Graf struct efi_configuration_table *end = &efi_conf_table[systab.nr_tables]; 687d98cdf6aSAlexander Graf 688d98cdf6aSAlexander Graf memmove(this, next, (ulong)end - (ulong)next); 689d98cdf6aSAlexander Graf systab.nr_tables--; 690d98cdf6aSAlexander Graf } 691d98cdf6aSAlexander Graf 692488bf12dSAlexander Graf efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table) 693bee91169SAlexander Graf { 694bee91169SAlexander Graf int i; 695bee91169SAlexander Graf 696bee91169SAlexander Graf /* Check for guid override */ 697bee91169SAlexander Graf for (i = 0; i < systab.nr_tables; i++) { 698bee91169SAlexander Graf if (!guidcmp(guid, &efi_conf_table[i].guid)) { 699d98cdf6aSAlexander Graf if (table) 700bee91169SAlexander Graf efi_conf_table[i].table = table; 701d98cdf6aSAlexander Graf else 702d98cdf6aSAlexander Graf efi_remove_configuration_table(i); 703488bf12dSAlexander Graf return EFI_SUCCESS; 704bee91169SAlexander Graf } 705bee91169SAlexander Graf } 706bee91169SAlexander Graf 707d98cdf6aSAlexander Graf if (!table) 708d98cdf6aSAlexander Graf return EFI_NOT_FOUND; 709d98cdf6aSAlexander Graf 710bee91169SAlexander Graf /* No override, check for overflow */ 711bee91169SAlexander Graf if (i >= ARRAY_SIZE(efi_conf_table)) 712488bf12dSAlexander Graf return EFI_OUT_OF_RESOURCES; 713bee91169SAlexander Graf 714bee91169SAlexander Graf /* Add a new entry */ 715bee91169SAlexander Graf memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); 716bee91169SAlexander Graf efi_conf_table[i].table = table; 717aba5e919SAlexander Graf systab.nr_tables = i + 1; 718bee91169SAlexander Graf 719488bf12dSAlexander Graf return EFI_SUCCESS; 720488bf12dSAlexander Graf } 721488bf12dSAlexander Graf 722488bf12dSAlexander Graf static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, 723488bf12dSAlexander Graf void *table) 724488bf12dSAlexander Graf { 725488bf12dSAlexander Graf EFI_ENTRY("%p, %p", guid, table); 726488bf12dSAlexander Graf return EFI_EXIT(efi_install_configuration_table(guid, table)); 727bee91169SAlexander Graf } 728bee91169SAlexander Graf 729bee91169SAlexander Graf static efi_status_t EFIAPI efi_load_image(bool boot_policy, 730bee91169SAlexander Graf efi_handle_t parent_image, 731bee91169SAlexander Graf struct efi_device_path *file_path, 732bee91169SAlexander Graf void *source_buffer, 733bee91169SAlexander Graf unsigned long source_size, 734bee91169SAlexander Graf efi_handle_t *image_handle) 735bee91169SAlexander Graf { 736bee91169SAlexander Graf static struct efi_object loaded_image_info_obj = { 737bee91169SAlexander Graf .protocols = { 738bee91169SAlexander Graf { 739bee91169SAlexander Graf .guid = &efi_guid_loaded_image, 740bee91169SAlexander Graf }, 741bee91169SAlexander Graf }, 742bee91169SAlexander Graf }; 743bee91169SAlexander Graf struct efi_loaded_image *info; 744bee91169SAlexander Graf struct efi_object *obj; 745bee91169SAlexander Graf 746bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, 747bee91169SAlexander Graf file_path, source_buffer, source_size, image_handle); 748bee91169SAlexander Graf info = malloc(sizeof(*info)); 749b5349f74Sxypron.glpk@gmx.de loaded_image_info_obj.protocols[0].protocol_interface = info; 750bee91169SAlexander Graf obj = malloc(sizeof(loaded_image_info_obj)); 751bee91169SAlexander Graf memset(info, 0, sizeof(*info)); 752bee91169SAlexander Graf memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); 753bee91169SAlexander Graf obj->handle = info; 754bee91169SAlexander Graf info->file_path = file_path; 755bee91169SAlexander Graf info->reserved = efi_load_pe(source_buffer, info); 756bee91169SAlexander Graf if (!info->reserved) { 757bee91169SAlexander Graf free(info); 758bee91169SAlexander Graf free(obj); 759bee91169SAlexander Graf return EFI_EXIT(EFI_UNSUPPORTED); 760bee91169SAlexander Graf } 761bee91169SAlexander Graf 762bee91169SAlexander Graf *image_handle = info; 763bee91169SAlexander Graf list_add_tail(&obj->link, &efi_obj_list); 764bee91169SAlexander Graf 765bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 766bee91169SAlexander Graf } 767bee91169SAlexander Graf 768bee91169SAlexander Graf static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, 769bee91169SAlexander Graf unsigned long *exit_data_size, 770bee91169SAlexander Graf s16 **exit_data) 771bee91169SAlexander Graf { 772bee91169SAlexander Graf ulong (*entry)(void *image_handle, struct efi_system_table *st); 773bee91169SAlexander Graf struct efi_loaded_image *info = image_handle; 774bee91169SAlexander Graf 775bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); 776bee91169SAlexander Graf entry = info->reserved; 777bee91169SAlexander Graf 778bee91169SAlexander Graf efi_is_direct_boot = false; 779bee91169SAlexander Graf 780bee91169SAlexander Graf /* call the image! */ 781a86aeaf2SAlexander Graf if (setjmp(&info->exit_jmp)) { 782a86aeaf2SAlexander Graf /* We returned from the child image */ 783a86aeaf2SAlexander Graf return EFI_EXIT(info->exit_status); 784a86aeaf2SAlexander Graf } 785a86aeaf2SAlexander Graf 786af65db85SRob Clark __efi_nesting_dec(); 787c160d2f5SRob Clark __efi_exit_check(); 788bee91169SAlexander Graf entry(image_handle, &systab); 789c160d2f5SRob Clark __efi_entry_check(); 790af65db85SRob Clark __efi_nesting_inc(); 791bee91169SAlexander Graf 792bee91169SAlexander Graf /* Should usually never get here */ 793bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 794bee91169SAlexander Graf } 795bee91169SAlexander Graf 796a86aeaf2SAlexander Graf static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, 797a86aeaf2SAlexander Graf efi_status_t exit_status, unsigned long exit_data_size, 798a86aeaf2SAlexander Graf int16_t *exit_data) 799bee91169SAlexander Graf { 800a86aeaf2SAlexander Graf struct efi_loaded_image *loaded_image_info = (void*)image_handle; 801a86aeaf2SAlexander Graf 802bee91169SAlexander Graf EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, 803bee91169SAlexander Graf exit_data_size, exit_data); 804a86aeaf2SAlexander Graf 805a86aeaf2SAlexander Graf loaded_image_info->exit_status = exit_status; 806692fcdd8SAlexander Graf longjmp(&loaded_image_info->exit_jmp, 1); 807a86aeaf2SAlexander Graf 808a86aeaf2SAlexander Graf panic("EFI application exited"); 809bee91169SAlexander Graf } 810bee91169SAlexander Graf 811bee91169SAlexander Graf static struct efi_object *efi_search_obj(void *handle) 812bee91169SAlexander Graf { 813bee91169SAlexander Graf struct list_head *lhandle; 814bee91169SAlexander Graf 815bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 816bee91169SAlexander Graf struct efi_object *efiobj; 817bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 818bee91169SAlexander Graf if (efiobj->handle == handle) 819bee91169SAlexander Graf return efiobj; 820bee91169SAlexander Graf } 821bee91169SAlexander Graf 822bee91169SAlexander Graf return NULL; 823bee91169SAlexander Graf } 824bee91169SAlexander Graf 825bee91169SAlexander Graf static efi_status_t EFIAPI efi_unload_image(void *image_handle) 826bee91169SAlexander Graf { 827bee91169SAlexander Graf struct efi_object *efiobj; 828bee91169SAlexander Graf 829bee91169SAlexander Graf EFI_ENTRY("%p", image_handle); 830bee91169SAlexander Graf efiobj = efi_search_obj(image_handle); 831bee91169SAlexander Graf if (efiobj) 832bee91169SAlexander Graf list_del(&efiobj->link); 833bee91169SAlexander Graf 834bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 835bee91169SAlexander Graf } 836bee91169SAlexander Graf 837bee91169SAlexander Graf static void efi_exit_caches(void) 838bee91169SAlexander Graf { 839bee91169SAlexander Graf #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) 840bee91169SAlexander Graf /* 841bee91169SAlexander Graf * Grub on 32bit ARM needs to have caches disabled before jumping into 842bee91169SAlexander Graf * a zImage, but does not know of all cache layers. Give it a hand. 843bee91169SAlexander Graf */ 844bee91169SAlexander Graf if (efi_is_direct_boot) 845bee91169SAlexander Graf cleanup_before_linux(); 846bee91169SAlexander Graf #endif 847bee91169SAlexander Graf } 848bee91169SAlexander Graf 849bee91169SAlexander Graf static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, 850bee91169SAlexander Graf unsigned long map_key) 851bee91169SAlexander Graf { 852bee91169SAlexander Graf EFI_ENTRY("%p, %ld", image_handle, map_key); 853bee91169SAlexander Graf 854b7b8410aSAlexander Graf board_quiesce_devices(); 855b7b8410aSAlexander Graf 856bee91169SAlexander Graf /* Fix up caches for EFI payloads if necessary */ 857bee91169SAlexander Graf efi_exit_caches(); 858bee91169SAlexander Graf 859bee91169SAlexander Graf /* This stops all lingering devices */ 860bee91169SAlexander Graf bootm_disable_interrupts(); 861bee91169SAlexander Graf 862bee91169SAlexander Graf /* Give the payload some time to boot */ 863bee91169SAlexander Graf WATCHDOG_RESET(); 864bee91169SAlexander Graf 865bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 866bee91169SAlexander Graf } 867bee91169SAlexander Graf 868bee91169SAlexander Graf static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) 869bee91169SAlexander Graf { 870bee91169SAlexander Graf static uint64_t mono = 0; 871bee91169SAlexander Graf EFI_ENTRY("%p", count); 872bee91169SAlexander Graf *count = mono++; 873bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 874bee91169SAlexander Graf } 875bee91169SAlexander Graf 876bee91169SAlexander Graf static efi_status_t EFIAPI efi_stall(unsigned long microseconds) 877bee91169SAlexander Graf { 878bee91169SAlexander Graf EFI_ENTRY("%ld", microseconds); 879bee91169SAlexander Graf udelay(microseconds); 880bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 881bee91169SAlexander Graf } 882bee91169SAlexander Graf 883bee91169SAlexander Graf static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, 884bee91169SAlexander Graf uint64_t watchdog_code, 885bee91169SAlexander Graf unsigned long data_size, 886bee91169SAlexander Graf uint16_t *watchdog_data) 887bee91169SAlexander Graf { 888bee91169SAlexander Graf EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, 889bee91169SAlexander Graf data_size, watchdog_data); 890b5104821SRob Clark return efi_unsupported(__func__); 891bee91169SAlexander Graf } 892bee91169SAlexander Graf 893bee91169SAlexander Graf static efi_status_t EFIAPI efi_connect_controller( 894bee91169SAlexander Graf efi_handle_t controller_handle, 895bee91169SAlexander Graf efi_handle_t *driver_image_handle, 896bee91169SAlexander Graf struct efi_device_path *remain_device_path, 897bee91169SAlexander Graf bool recursive) 898bee91169SAlexander Graf { 899bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle, 900bee91169SAlexander Graf remain_device_path, recursive); 901bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 902bee91169SAlexander Graf } 903bee91169SAlexander Graf 904bee91169SAlexander Graf static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle, 905bee91169SAlexander Graf void *driver_image_handle, 906bee91169SAlexander Graf void *child_handle) 907bee91169SAlexander Graf { 908bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, 909bee91169SAlexander Graf child_handle); 910bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 911bee91169SAlexander Graf } 912bee91169SAlexander Graf 913bee91169SAlexander Graf static efi_status_t EFIAPI efi_close_protocol(void *handle, 914bee91169SAlexander Graf efi_guid_t *protocol, 915bee91169SAlexander Graf void *agent_handle, 916bee91169SAlexander Graf void *controller_handle) 917bee91169SAlexander Graf { 918bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle, 919bee91169SAlexander Graf controller_handle); 920bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 921bee91169SAlexander Graf } 922bee91169SAlexander Graf 923bee91169SAlexander Graf static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, 924bee91169SAlexander Graf efi_guid_t *protocol, 925bee91169SAlexander Graf struct efi_open_protocol_info_entry **entry_buffer, 926bee91169SAlexander Graf unsigned long *entry_count) 927bee91169SAlexander Graf { 928bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, 929bee91169SAlexander Graf entry_count); 930bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 931bee91169SAlexander Graf } 932bee91169SAlexander Graf 933bee91169SAlexander Graf static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, 934bee91169SAlexander Graf efi_guid_t ***protocol_buffer, 935bee91169SAlexander Graf unsigned long *protocol_buffer_count) 936bee91169SAlexander Graf { 937c0ebfc86Sxypron.glpk@gmx.de unsigned long buffer_size; 938c0ebfc86Sxypron.glpk@gmx.de struct efi_object *efiobj; 939c0ebfc86Sxypron.glpk@gmx.de unsigned long i, j; 940c0ebfc86Sxypron.glpk@gmx.de struct list_head *lhandle; 941c0ebfc86Sxypron.glpk@gmx.de efi_status_t r; 942c0ebfc86Sxypron.glpk@gmx.de 943bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, 944bee91169SAlexander Graf protocol_buffer_count); 945c0ebfc86Sxypron.glpk@gmx.de 946c0ebfc86Sxypron.glpk@gmx.de if (!handle || !protocol_buffer || !protocol_buffer_count) 947c0ebfc86Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 948c0ebfc86Sxypron.glpk@gmx.de 949c0ebfc86Sxypron.glpk@gmx.de *protocol_buffer = NULL; 950661c8327SRob Clark *protocol_buffer_count = 0; 951c0ebfc86Sxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 952c0ebfc86Sxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 953c0ebfc86Sxypron.glpk@gmx.de 954c0ebfc86Sxypron.glpk@gmx.de if (efiobj->handle != handle) 955c0ebfc86Sxypron.glpk@gmx.de continue; 956c0ebfc86Sxypron.glpk@gmx.de 957c0ebfc86Sxypron.glpk@gmx.de /* Count protocols */ 958c0ebfc86Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 959c0ebfc86Sxypron.glpk@gmx.de if (efiobj->protocols[i].guid) 960c0ebfc86Sxypron.glpk@gmx.de ++*protocol_buffer_count; 961c0ebfc86Sxypron.glpk@gmx.de } 962c0ebfc86Sxypron.glpk@gmx.de /* Copy guids */ 963c0ebfc86Sxypron.glpk@gmx.de if (*protocol_buffer_count) { 964c0ebfc86Sxypron.glpk@gmx.de buffer_size = sizeof(efi_guid_t *) * 965c0ebfc86Sxypron.glpk@gmx.de *protocol_buffer_count; 966c0ebfc86Sxypron.glpk@gmx.de r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, 967c0ebfc86Sxypron.glpk@gmx.de buffer_size, 968c0ebfc86Sxypron.glpk@gmx.de (void **)protocol_buffer); 969c0ebfc86Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 970c0ebfc86Sxypron.glpk@gmx.de return EFI_EXIT(r); 971c0ebfc86Sxypron.glpk@gmx.de j = 0; 972c0ebfc86Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); ++i) { 973c0ebfc86Sxypron.glpk@gmx.de if (efiobj->protocols[i].guid) { 974c0ebfc86Sxypron.glpk@gmx.de (*protocol_buffer)[j] = (void *) 975c0ebfc86Sxypron.glpk@gmx.de efiobj->protocols[i].guid; 976c0ebfc86Sxypron.glpk@gmx.de ++j; 977c0ebfc86Sxypron.glpk@gmx.de } 978c0ebfc86Sxypron.glpk@gmx.de } 979c0ebfc86Sxypron.glpk@gmx.de } 980c0ebfc86Sxypron.glpk@gmx.de break; 981c0ebfc86Sxypron.glpk@gmx.de } 982c0ebfc86Sxypron.glpk@gmx.de 983c0ebfc86Sxypron.glpk@gmx.de return EFI_EXIT(EFI_SUCCESS); 984bee91169SAlexander Graf } 985bee91169SAlexander Graf 986bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_handle_buffer( 987bee91169SAlexander Graf enum efi_locate_search_type search_type, 988bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 989bee91169SAlexander Graf unsigned long *no_handles, efi_handle_t **buffer) 990bee91169SAlexander Graf { 991c2e703f9Sxypron.glpk@gmx.de efi_status_t r; 992c2e703f9Sxypron.glpk@gmx.de unsigned long buffer_size = 0; 993c2e703f9Sxypron.glpk@gmx.de 994bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 995bee91169SAlexander Graf no_handles, buffer); 996c2e703f9Sxypron.glpk@gmx.de 997c2e703f9Sxypron.glpk@gmx.de if (!no_handles || !buffer) { 998c2e703f9Sxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 999c2e703f9Sxypron.glpk@gmx.de goto out; 1000c2e703f9Sxypron.glpk@gmx.de } 1001c2e703f9Sxypron.glpk@gmx.de *no_handles = 0; 1002c2e703f9Sxypron.glpk@gmx.de *buffer = NULL; 1003c2e703f9Sxypron.glpk@gmx.de r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, 1004c2e703f9Sxypron.glpk@gmx.de *buffer); 1005c2e703f9Sxypron.glpk@gmx.de if (r != EFI_BUFFER_TOO_SMALL) 1006c2e703f9Sxypron.glpk@gmx.de goto out; 1007c2e703f9Sxypron.glpk@gmx.de r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, buffer_size, 1008c2e703f9Sxypron.glpk@gmx.de (void **)buffer); 1009c2e703f9Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 1010c2e703f9Sxypron.glpk@gmx.de goto out; 1011c2e703f9Sxypron.glpk@gmx.de r = efi_locate_handle(search_type, protocol, search_key, &buffer_size, 1012c2e703f9Sxypron.glpk@gmx.de *buffer); 1013c2e703f9Sxypron.glpk@gmx.de if (r == EFI_SUCCESS) 1014c2e703f9Sxypron.glpk@gmx.de *no_handles = buffer_size / sizeof(void *); 1015c2e703f9Sxypron.glpk@gmx.de out: 1016c2e703f9Sxypron.glpk@gmx.de return EFI_EXIT(r); 1017bee91169SAlexander Graf } 1018bee91169SAlexander Graf 1019bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol, 1020bee91169SAlexander Graf void *registration, 1021bee91169SAlexander Graf void **protocol_interface) 1022bee91169SAlexander Graf { 102388adae5eSxypron.glpk@gmx.de struct list_head *lhandle; 1024bee91169SAlexander Graf int i; 1025bee91169SAlexander Graf 1026bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface); 102788adae5eSxypron.glpk@gmx.de 102888adae5eSxypron.glpk@gmx.de if (!protocol || !protocol_interface) 102988adae5eSxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 103088adae5eSxypron.glpk@gmx.de 103188adae5eSxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 103288adae5eSxypron.glpk@gmx.de struct efi_object *efiobj; 103388adae5eSxypron.glpk@gmx.de 103488adae5eSxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 103588adae5eSxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 103688adae5eSxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 103788adae5eSxypron.glpk@gmx.de 103888adae5eSxypron.glpk@gmx.de if (!handler->guid) 103988adae5eSxypron.glpk@gmx.de continue; 104088adae5eSxypron.glpk@gmx.de if (!guidcmp(handler->guid, protocol)) { 104188adae5eSxypron.glpk@gmx.de *protocol_interface = 104288adae5eSxypron.glpk@gmx.de handler->protocol_interface; 1043bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 1044bee91169SAlexander Graf } 1045bee91169SAlexander Graf } 104688adae5eSxypron.glpk@gmx.de } 104788adae5eSxypron.glpk@gmx.de *protocol_interface = NULL; 1048bee91169SAlexander Graf 1049bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 1050bee91169SAlexander Graf } 1051bee91169SAlexander Graf 1052bee91169SAlexander Graf static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( 1053bee91169SAlexander Graf void **handle, ...) 1054bee91169SAlexander Graf { 1055bee91169SAlexander Graf EFI_ENTRY("%p", handle); 105658b83586Sxypron.glpk@gmx.de 105758b83586Sxypron.glpk@gmx.de va_list argptr; 105858b83586Sxypron.glpk@gmx.de efi_guid_t *protocol; 105958b83586Sxypron.glpk@gmx.de void *protocol_interface; 106058b83586Sxypron.glpk@gmx.de efi_status_t r = EFI_SUCCESS; 106158b83586Sxypron.glpk@gmx.de int i = 0; 106258b83586Sxypron.glpk@gmx.de 106358b83586Sxypron.glpk@gmx.de if (!handle) 106458b83586Sxypron.glpk@gmx.de return EFI_EXIT(EFI_INVALID_PARAMETER); 106558b83586Sxypron.glpk@gmx.de 106658b83586Sxypron.glpk@gmx.de va_start(argptr, handle); 106758b83586Sxypron.glpk@gmx.de for (;;) { 106858b83586Sxypron.glpk@gmx.de protocol = va_arg(argptr, efi_guid_t*); 106958b83586Sxypron.glpk@gmx.de if (!protocol) 107058b83586Sxypron.glpk@gmx.de break; 107158b83586Sxypron.glpk@gmx.de protocol_interface = va_arg(argptr, void*); 107258b83586Sxypron.glpk@gmx.de r = efi_install_protocol_interface(handle, protocol, 107358b83586Sxypron.glpk@gmx.de EFI_NATIVE_INTERFACE, 107458b83586Sxypron.glpk@gmx.de protocol_interface); 107558b83586Sxypron.glpk@gmx.de if (r != EFI_SUCCESS) 107658b83586Sxypron.glpk@gmx.de break; 107758b83586Sxypron.glpk@gmx.de i++; 107858b83586Sxypron.glpk@gmx.de } 107958b83586Sxypron.glpk@gmx.de va_end(argptr); 108058b83586Sxypron.glpk@gmx.de if (r == EFI_SUCCESS) 108158b83586Sxypron.glpk@gmx.de return EFI_EXIT(r); 108258b83586Sxypron.glpk@gmx.de 108358b83586Sxypron.glpk@gmx.de /* If an error occured undo all changes. */ 108458b83586Sxypron.glpk@gmx.de va_start(argptr, handle); 108558b83586Sxypron.glpk@gmx.de for (; i; --i) { 108658b83586Sxypron.glpk@gmx.de protocol = va_arg(argptr, efi_guid_t*); 108758b83586Sxypron.glpk@gmx.de protocol_interface = va_arg(argptr, void*); 108858b83586Sxypron.glpk@gmx.de efi_uninstall_protocol_interface(handle, protocol, 108958b83586Sxypron.glpk@gmx.de protocol_interface); 109058b83586Sxypron.glpk@gmx.de } 109158b83586Sxypron.glpk@gmx.de va_end(argptr); 109258b83586Sxypron.glpk@gmx.de 109358b83586Sxypron.glpk@gmx.de return EFI_EXIT(r); 1094bee91169SAlexander Graf } 1095bee91169SAlexander Graf 1096bee91169SAlexander Graf static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( 1097bee91169SAlexander Graf void *handle, ...) 1098bee91169SAlexander Graf { 1099bee91169SAlexander Graf EFI_ENTRY("%p", handle); 1100bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 1101bee91169SAlexander Graf } 1102bee91169SAlexander Graf 1103bee91169SAlexander Graf static efi_status_t EFIAPI efi_calculate_crc32(void *data, 1104bee91169SAlexander Graf unsigned long data_size, 1105bee91169SAlexander Graf uint32_t *crc32_p) 1106bee91169SAlexander Graf { 1107bee91169SAlexander Graf EFI_ENTRY("%p, %ld", data, data_size); 1108bee91169SAlexander Graf *crc32_p = crc32(0, data, data_size); 1109bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 1110bee91169SAlexander Graf } 1111bee91169SAlexander Graf 1112bee91169SAlexander Graf static void EFIAPI efi_copy_mem(void *destination, void *source, 1113bee91169SAlexander Graf unsigned long length) 1114bee91169SAlexander Graf { 1115bee91169SAlexander Graf EFI_ENTRY("%p, %p, %ld", destination, source, length); 1116bee91169SAlexander Graf memcpy(destination, source, length); 1117bee91169SAlexander Graf } 1118bee91169SAlexander Graf 1119bee91169SAlexander Graf static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value) 1120bee91169SAlexander Graf { 1121bee91169SAlexander Graf EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value); 1122bee91169SAlexander Graf memset(buffer, value, size); 1123bee91169SAlexander Graf } 1124bee91169SAlexander Graf 1125bee91169SAlexander Graf static efi_status_t EFIAPI efi_open_protocol( 1126bee91169SAlexander Graf void *handle, efi_guid_t *protocol, 1127bee91169SAlexander Graf void **protocol_interface, void *agent_handle, 1128bee91169SAlexander Graf void *controller_handle, uint32_t attributes) 1129bee91169SAlexander Graf { 1130bee91169SAlexander Graf struct list_head *lhandle; 1131bee91169SAlexander Graf int i; 113269baec67Sxypron.glpk@gmx.de efi_status_t r = EFI_INVALID_PARAMETER; 1133bee91169SAlexander Graf 1134bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol, 1135bee91169SAlexander Graf protocol_interface, agent_handle, controller_handle, 1136bee91169SAlexander Graf attributes); 1137b5349f74Sxypron.glpk@gmx.de 113869baec67Sxypron.glpk@gmx.de if (!handle || !protocol || 113969baec67Sxypron.glpk@gmx.de (!protocol_interface && attributes != 114069baec67Sxypron.glpk@gmx.de EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) { 114169baec67Sxypron.glpk@gmx.de goto out; 114269baec67Sxypron.glpk@gmx.de } 114369baec67Sxypron.glpk@gmx.de 114469baec67Sxypron.glpk@gmx.de switch (attributes) { 114569baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: 114669baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_GET_PROTOCOL: 114769baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: 114869baec67Sxypron.glpk@gmx.de break; 114969baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: 115069baec67Sxypron.glpk@gmx.de if (controller_handle == handle) 115169baec67Sxypron.glpk@gmx.de goto out; 115269baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_DRIVER: 115369baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: 115469baec67Sxypron.glpk@gmx.de if (controller_handle == NULL) 115569baec67Sxypron.glpk@gmx.de goto out; 115669baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_EXCLUSIVE: 115769baec67Sxypron.glpk@gmx.de if (agent_handle == NULL) 115869baec67Sxypron.glpk@gmx.de goto out; 115969baec67Sxypron.glpk@gmx.de break; 116069baec67Sxypron.glpk@gmx.de default: 1161b5349f74Sxypron.glpk@gmx.de goto out; 1162b5349f74Sxypron.glpk@gmx.de } 1163b5349f74Sxypron.glpk@gmx.de 1164bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 1165bee91169SAlexander Graf struct efi_object *efiobj; 1166bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 1167bee91169SAlexander Graf 1168bee91169SAlexander Graf if (efiobj->handle != handle) 1169bee91169SAlexander Graf continue; 1170bee91169SAlexander Graf 1171bee91169SAlexander Graf for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 1172bee91169SAlexander Graf struct efi_handler *handler = &efiobj->protocols[i]; 1173bee91169SAlexander Graf const efi_guid_t *hprotocol = handler->guid; 1174bee91169SAlexander Graf if (!hprotocol) 11754b6ed0d7Sxypron.glpk@gmx.de continue; 1176bee91169SAlexander Graf if (!guidcmp(hprotocol, protocol)) { 1177b5349f74Sxypron.glpk@gmx.de if (attributes != 1178b5349f74Sxypron.glpk@gmx.de EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { 1179b5349f74Sxypron.glpk@gmx.de *protocol_interface = 1180b5349f74Sxypron.glpk@gmx.de handler->protocol_interface; 1181b5349f74Sxypron.glpk@gmx.de } 1182b5349f74Sxypron.glpk@gmx.de r = EFI_SUCCESS; 1183bee91169SAlexander Graf goto out; 1184bee91169SAlexander Graf } 1185bee91169SAlexander Graf } 118669baec67Sxypron.glpk@gmx.de goto unsupported; 1187bee91169SAlexander Graf } 1188bee91169SAlexander Graf 118969baec67Sxypron.glpk@gmx.de unsupported: 119069baec67Sxypron.glpk@gmx.de r = EFI_UNSUPPORTED; 1191bee91169SAlexander Graf out: 1192bee91169SAlexander Graf return EFI_EXIT(r); 1193bee91169SAlexander Graf } 1194bee91169SAlexander Graf 1195bee91169SAlexander Graf static efi_status_t EFIAPI efi_handle_protocol(void *handle, 1196bee91169SAlexander Graf efi_guid_t *protocol, 1197bee91169SAlexander Graf void **protocol_interface) 1198bee91169SAlexander Graf { 11998e1d329fSxypron.glpk@gmx.de return efi_open_protocol(handle, protocol, protocol_interface, NULL, 12008e1d329fSxypron.glpk@gmx.de NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); 1201bee91169SAlexander Graf } 1202bee91169SAlexander Graf 1203bee91169SAlexander Graf static const struct efi_boot_services efi_boot_services = { 1204bee91169SAlexander Graf .hdr = { 1205bee91169SAlexander Graf .headersize = sizeof(struct efi_table_hdr), 1206bee91169SAlexander Graf }, 1207bee91169SAlexander Graf .raise_tpl = efi_raise_tpl, 1208bee91169SAlexander Graf .restore_tpl = efi_restore_tpl, 1209bee91169SAlexander Graf .allocate_pages = efi_allocate_pages_ext, 1210bee91169SAlexander Graf .free_pages = efi_free_pages_ext, 1211bee91169SAlexander Graf .get_memory_map = efi_get_memory_map_ext, 1212ead1274bSStefan Brüns .allocate_pool = efi_allocate_pool_ext, 121342417bc8SStefan Brüns .free_pool = efi_free_pool_ext, 121449deb455Sxypron.glpk@gmx.de .create_event = efi_create_event_ext, 1215bfc72462Sxypron.glpk@gmx.de .set_timer = efi_set_timer_ext, 1216bee91169SAlexander Graf .wait_for_event = efi_wait_for_event, 1217c6841592Sxypron.glpk@gmx.de .signal_event = efi_signal_event_ext, 1218bee91169SAlexander Graf .close_event = efi_close_event, 1219bee91169SAlexander Graf .check_event = efi_check_event, 12208bee5a3cSxypron.glpk@gmx.de .install_protocol_interface = efi_install_protocol_interface_ext, 1221bee91169SAlexander Graf .reinstall_protocol_interface = efi_reinstall_protocol_interface, 12223d8e1456Sxypron.glpk@gmx.de .uninstall_protocol_interface = efi_uninstall_protocol_interface_ext, 1223bee91169SAlexander Graf .handle_protocol = efi_handle_protocol, 1224bee91169SAlexander Graf .reserved = NULL, 1225bee91169SAlexander Graf .register_protocol_notify = efi_register_protocol_notify, 122626329584Sxypron.glpk@gmx.de .locate_handle = efi_locate_handle_ext, 1227bee91169SAlexander Graf .locate_device_path = efi_locate_device_path, 1228488bf12dSAlexander Graf .install_configuration_table = efi_install_configuration_table_ext, 1229bee91169SAlexander Graf .load_image = efi_load_image, 1230bee91169SAlexander Graf .start_image = efi_start_image, 1231a86aeaf2SAlexander Graf .exit = efi_exit, 1232bee91169SAlexander Graf .unload_image = efi_unload_image, 1233bee91169SAlexander Graf .exit_boot_services = efi_exit_boot_services, 1234bee91169SAlexander Graf .get_next_monotonic_count = efi_get_next_monotonic_count, 1235bee91169SAlexander Graf .stall = efi_stall, 1236bee91169SAlexander Graf .set_watchdog_timer = efi_set_watchdog_timer, 1237bee91169SAlexander Graf .connect_controller = efi_connect_controller, 1238bee91169SAlexander Graf .disconnect_controller = efi_disconnect_controller, 1239bee91169SAlexander Graf .open_protocol = efi_open_protocol, 1240bee91169SAlexander Graf .close_protocol = efi_close_protocol, 1241bee91169SAlexander Graf .open_protocol_information = efi_open_protocol_information, 1242bee91169SAlexander Graf .protocols_per_handle = efi_protocols_per_handle, 1243bee91169SAlexander Graf .locate_handle_buffer = efi_locate_handle_buffer, 1244bee91169SAlexander Graf .locate_protocol = efi_locate_protocol, 1245bee91169SAlexander Graf .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces, 1246bee91169SAlexander Graf .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces, 1247bee91169SAlexander Graf .calculate_crc32 = efi_calculate_crc32, 1248bee91169SAlexander Graf .copy_mem = efi_copy_mem, 1249bee91169SAlexander Graf .set_mem = efi_set_mem, 1250bee91169SAlexander Graf }; 1251bee91169SAlexander Graf 1252bee91169SAlexander Graf 12533c63db9cSAlexander Graf static uint16_t __efi_runtime_data firmware_vendor[] = 1254bee91169SAlexander Graf { 'D','a','s',' ','U','-','b','o','o','t',0 }; 1255bee91169SAlexander Graf 12563c63db9cSAlexander Graf struct efi_system_table __efi_runtime_data systab = { 1257bee91169SAlexander Graf .hdr = { 1258bee91169SAlexander Graf .signature = EFI_SYSTEM_TABLE_SIGNATURE, 1259bee91169SAlexander Graf .revision = 0x20005, /* 2.5 */ 1260bee91169SAlexander Graf .headersize = sizeof(struct efi_table_hdr), 1261bee91169SAlexander Graf }, 1262bee91169SAlexander Graf .fw_vendor = (long)firmware_vendor, 1263bee91169SAlexander Graf .con_in = (void*)&efi_con_in, 1264bee91169SAlexander Graf .con_out = (void*)&efi_con_out, 1265bee91169SAlexander Graf .std_err = (void*)&efi_con_out, 1266bee91169SAlexander Graf .runtime = (void*)&efi_runtime_services, 1267bee91169SAlexander Graf .boottime = (void*)&efi_boot_services, 1268bee91169SAlexander Graf .nr_tables = 0, 1269bee91169SAlexander Graf .tables = (void*)efi_conf_table, 1270bee91169SAlexander Graf }; 1271