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 52bee91169SAlexander Graf /* Called from do_bootefi_exec() */ 53bee91169SAlexander Graf void efi_save_gd(void) 54bee91169SAlexander Graf { 5565e4c0b1SSimon Glass #ifdef CONFIG_ARM 56bee91169SAlexander Graf efi_gd = gd; 5765e4c0b1SSimon Glass #endif 58bee91169SAlexander Graf } 59bee91169SAlexander Graf 60bee91169SAlexander Graf /* Called on every callback entry */ 61bee91169SAlexander Graf void efi_restore_gd(void) 62bee91169SAlexander Graf { 6365e4c0b1SSimon Glass #ifdef CONFIG_ARM 64bee91169SAlexander Graf /* Only restore if we're already in EFI context */ 65bee91169SAlexander Graf if (!efi_gd) 66bee91169SAlexander Graf return; 67bee91169SAlexander Graf 68bee91169SAlexander Graf if (gd != efi_gd) 69bee91169SAlexander Graf app_gd = gd; 70bee91169SAlexander Graf gd = efi_gd; 7165e4c0b1SSimon Glass #endif 72bee91169SAlexander Graf } 73bee91169SAlexander Graf 74bee91169SAlexander Graf /* Called on every callback exit */ 75bee91169SAlexander Graf efi_status_t efi_exit_func(efi_status_t ret) 76bee91169SAlexander Graf { 7765e4c0b1SSimon Glass #ifdef CONFIG_ARM 78bee91169SAlexander Graf gd = app_gd; 7965e4c0b1SSimon Glass #endif 8065e4c0b1SSimon Glass 81bee91169SAlexander Graf return ret; 82bee91169SAlexander Graf } 83bee91169SAlexander Graf 84bee91169SAlexander Graf static efi_status_t efi_unsupported(const char *funcname) 85bee91169SAlexander Graf { 86edcef3baSAlexander Graf debug("EFI: App called into unimplemented function %s\n", funcname); 87bee91169SAlexander Graf return EFI_EXIT(EFI_UNSUPPORTED); 88bee91169SAlexander Graf } 89bee91169SAlexander Graf 90bee91169SAlexander Graf static int guidcmp(const efi_guid_t *g1, const efi_guid_t *g2) 91bee91169SAlexander Graf { 92bee91169SAlexander Graf return memcmp(g1, g2, sizeof(efi_guid_t)); 93bee91169SAlexander Graf } 94bee91169SAlexander Graf 95bee91169SAlexander Graf static unsigned long EFIAPI efi_raise_tpl(unsigned long new_tpl) 96bee91169SAlexander Graf { 97bee91169SAlexander Graf EFI_ENTRY("0x%lx", new_tpl); 98bee91169SAlexander Graf return EFI_EXIT(0); 99bee91169SAlexander Graf } 100bee91169SAlexander Graf 101bee91169SAlexander Graf static void EFIAPI efi_restore_tpl(unsigned long old_tpl) 102bee91169SAlexander Graf { 103bee91169SAlexander Graf EFI_ENTRY("0x%lx", old_tpl); 104bee91169SAlexander Graf EFI_EXIT(efi_unsupported(__func__)); 105bee91169SAlexander Graf } 106bee91169SAlexander Graf 1076e0bf8d8SMasahiro Yamada static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type, 108bee91169SAlexander Graf unsigned long pages, 109bee91169SAlexander Graf uint64_t *memory) 110bee91169SAlexander Graf { 111bee91169SAlexander Graf efi_status_t r; 112bee91169SAlexander Graf 113bee91169SAlexander Graf EFI_ENTRY("%d, %d, 0x%lx, %p", type, memory_type, pages, memory); 114bee91169SAlexander Graf r = efi_allocate_pages(type, memory_type, pages, memory); 115bee91169SAlexander Graf return EFI_EXIT(r); 116bee91169SAlexander Graf } 117bee91169SAlexander Graf 1186e0bf8d8SMasahiro Yamada static efi_status_t EFIAPI efi_free_pages_ext(uint64_t memory, 1196e0bf8d8SMasahiro Yamada unsigned long pages) 120bee91169SAlexander Graf { 121bee91169SAlexander Graf efi_status_t r; 122bee91169SAlexander Graf 123bee91169SAlexander Graf EFI_ENTRY("%"PRIx64", 0x%lx", memory, pages); 124bee91169SAlexander Graf r = efi_free_pages(memory, pages); 125bee91169SAlexander Graf return EFI_EXIT(r); 126bee91169SAlexander Graf } 127bee91169SAlexander Graf 1286e0bf8d8SMasahiro Yamada static efi_status_t EFIAPI efi_get_memory_map_ext( 1296e0bf8d8SMasahiro Yamada unsigned long *memory_map_size, 130bee91169SAlexander Graf struct efi_mem_desc *memory_map, 131bee91169SAlexander Graf unsigned long *map_key, 132bee91169SAlexander Graf unsigned long *descriptor_size, 133bee91169SAlexander Graf uint32_t *descriptor_version) 134bee91169SAlexander Graf { 135bee91169SAlexander Graf efi_status_t r; 136bee91169SAlexander Graf 137bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map, 138bee91169SAlexander Graf map_key, descriptor_size, descriptor_version); 139bee91169SAlexander Graf r = efi_get_memory_map(memory_map_size, memory_map, map_key, 140bee91169SAlexander Graf descriptor_size, descriptor_version); 141bee91169SAlexander Graf return EFI_EXIT(r); 142bee91169SAlexander Graf } 143bee91169SAlexander Graf 144ead1274bSStefan Brüns static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type, 145ead1274bSStefan Brüns unsigned long size, 146bee91169SAlexander Graf void **buffer) 147bee91169SAlexander Graf { 1481cd29f0aSAlexander Graf efi_status_t r; 1491cd29f0aSAlexander Graf 1501cd29f0aSAlexander Graf EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer); 151ead1274bSStefan Brüns r = efi_allocate_pool(pool_type, size, buffer); 1521cd29f0aSAlexander Graf return EFI_EXIT(r); 153bee91169SAlexander Graf } 154bee91169SAlexander Graf 15542417bc8SStefan Brüns static efi_status_t EFIAPI efi_free_pool_ext(void *buffer) 156bee91169SAlexander Graf { 1571cd29f0aSAlexander Graf efi_status_t r; 1581cd29f0aSAlexander Graf 1591cd29f0aSAlexander Graf EFI_ENTRY("%p", buffer); 16042417bc8SStefan Brüns r = efi_free_pool(buffer); 1611cd29f0aSAlexander Graf return EFI_EXIT(r); 162bee91169SAlexander Graf } 163bee91169SAlexander Graf 164bee91169SAlexander Graf /* 165bee91169SAlexander Graf * Our event capabilities are very limited. Only support a single 166bee91169SAlexander Graf * event to exist, so we don't need to maintain lists. 167bee91169SAlexander Graf */ 168bee91169SAlexander Graf static struct { 169bee91169SAlexander Graf enum efi_event_type type; 170bee91169SAlexander Graf u32 trigger_type; 171bee91169SAlexander Graf u32 trigger_time; 172bee91169SAlexander Graf u64 trigger_next; 173bee91169SAlexander Graf unsigned long notify_tpl; 174e275458cSSimon Glass void (EFIAPI *notify_function) (void *event, void *context); 175bee91169SAlexander Graf void *notify_context; 176bee91169SAlexander Graf } efi_event = { 177bee91169SAlexander Graf /* Disable timers on bootup */ 178bee91169SAlexander Graf .trigger_next = -1ULL, 179bee91169SAlexander Graf }; 180bee91169SAlexander Graf 181bee91169SAlexander Graf static efi_status_t EFIAPI efi_create_event( 182bee91169SAlexander Graf enum efi_event_type type, ulong notify_tpl, 183e275458cSSimon Glass void (EFIAPI *notify_function) (void *event, 184e275458cSSimon Glass void *context), 185bee91169SAlexander Graf void *notify_context, void **event) 186bee91169SAlexander Graf { 187bee91169SAlexander Graf EFI_ENTRY("%d, 0x%lx, %p, %p", type, notify_tpl, notify_function, 188bee91169SAlexander Graf notify_context); 189bee91169SAlexander Graf if (efi_event.notify_function) { 190bee91169SAlexander Graf /* We only support one event at a time */ 191bee91169SAlexander Graf return EFI_EXIT(EFI_OUT_OF_RESOURCES); 192bee91169SAlexander Graf } 193bee91169SAlexander Graf 194a95343b8SJonathan Gray if (event == NULL) 195a95343b8SJonathan Gray return EFI_EXIT(EFI_INVALID_PARAMETER); 196a95343b8SJonathan Gray 197a95343b8SJonathan Gray if ((type & EVT_NOTIFY_SIGNAL) && (type & EVT_NOTIFY_WAIT)) 198a95343b8SJonathan Gray return EFI_EXIT(EFI_INVALID_PARAMETER); 199a95343b8SJonathan Gray 200a95343b8SJonathan Gray if ((type & (EVT_NOTIFY_SIGNAL|EVT_NOTIFY_WAIT)) && 201a95343b8SJonathan Gray notify_function == NULL) 202a95343b8SJonathan Gray return EFI_EXIT(EFI_INVALID_PARAMETER); 203a95343b8SJonathan Gray 204bee91169SAlexander Graf efi_event.type = type; 205bee91169SAlexander Graf efi_event.notify_tpl = notify_tpl; 206bee91169SAlexander Graf efi_event.notify_function = notify_function; 207bee91169SAlexander Graf efi_event.notify_context = notify_context; 208bee91169SAlexander Graf *event = &efi_event; 209bee91169SAlexander Graf 210bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 211bee91169SAlexander Graf } 212bee91169SAlexander Graf 213bee91169SAlexander Graf /* 214bee91169SAlexander Graf * Our timers have to work without interrupts, so we check whenever keyboard 215bee91169SAlexander Graf * input or disk accesses happen if enough time elapsed for it to fire. 216bee91169SAlexander Graf */ 217bee91169SAlexander Graf void efi_timer_check(void) 218bee91169SAlexander Graf { 219bee91169SAlexander Graf u64 now = timer_get_us(); 220bee91169SAlexander Graf 221bee91169SAlexander Graf if (now >= efi_event.trigger_next) { 222bee91169SAlexander Graf /* Triggering! */ 223bee91169SAlexander Graf if (efi_event.trigger_type == EFI_TIMER_PERIODIC) 224bee91169SAlexander Graf efi_event.trigger_next += efi_event.trigger_time / 10; 22537a980b3SJonathan Gray if (efi_event.type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL)) 22637a980b3SJonathan Gray efi_event.notify_function(&efi_event, 22737a980b3SJonathan Gray efi_event.notify_context); 228bee91169SAlexander Graf } 229bee91169SAlexander Graf 230bee91169SAlexander Graf WATCHDOG_RESET(); 231bee91169SAlexander Graf } 232bee91169SAlexander Graf 233bee91169SAlexander Graf static efi_status_t EFIAPI efi_set_timer(void *event, int type, 234bee91169SAlexander Graf uint64_t trigger_time) 235bee91169SAlexander Graf { 236bee91169SAlexander Graf /* We don't have 64bit division available everywhere, so limit timer 237bee91169SAlexander Graf * distances to 32bit bits. */ 238bee91169SAlexander Graf u32 trigger32 = trigger_time; 239bee91169SAlexander Graf 240bee91169SAlexander Graf EFI_ENTRY("%p, %d, %"PRIx64, event, type, trigger_time); 241bee91169SAlexander Graf 242bee91169SAlexander Graf if (trigger32 < trigger_time) { 243bee91169SAlexander Graf printf("WARNING: Truncating timer from %"PRIx64" to %x\n", 244bee91169SAlexander Graf trigger_time, trigger32); 245bee91169SAlexander Graf } 246bee91169SAlexander Graf 247bee91169SAlexander Graf if (event != &efi_event) { 248bee91169SAlexander Graf /* We only support one event at a time */ 249bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 250bee91169SAlexander Graf } 251bee91169SAlexander Graf 252bee91169SAlexander Graf switch (type) { 253bee91169SAlexander Graf case EFI_TIMER_STOP: 254bee91169SAlexander Graf efi_event.trigger_next = -1ULL; 255bee91169SAlexander Graf break; 256bee91169SAlexander Graf case EFI_TIMER_PERIODIC: 257bee91169SAlexander Graf case EFI_TIMER_RELATIVE: 258bee91169SAlexander Graf efi_event.trigger_next = timer_get_us() + (trigger32 / 10); 259bee91169SAlexander Graf break; 260bee91169SAlexander Graf default: 261bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 262bee91169SAlexander Graf } 263bee91169SAlexander Graf efi_event.trigger_type = type; 264bee91169SAlexander Graf efi_event.trigger_time = trigger_time; 265bee91169SAlexander Graf 266bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 267bee91169SAlexander Graf } 268bee91169SAlexander Graf 269bee91169SAlexander Graf static efi_status_t EFIAPI efi_wait_for_event(unsigned long num_events, 270bee91169SAlexander Graf void *event, unsigned long *index) 271bee91169SAlexander Graf { 272bee91169SAlexander Graf u64 now; 273bee91169SAlexander Graf 274bee91169SAlexander Graf EFI_ENTRY("%ld, %p, %p", num_events, event, index); 275bee91169SAlexander Graf 276bee91169SAlexander Graf now = timer_get_us(); 277bee91169SAlexander Graf while (now < efi_event.trigger_next) { } 278bee91169SAlexander Graf efi_timer_check(); 279bee91169SAlexander Graf 280bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 281bee91169SAlexander Graf } 282bee91169SAlexander Graf 283bee91169SAlexander Graf static efi_status_t EFIAPI efi_signal_event(void *event) 284bee91169SAlexander Graf { 285bee91169SAlexander Graf EFI_ENTRY("%p", event); 286bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 287bee91169SAlexander Graf } 288bee91169SAlexander Graf 289bee91169SAlexander Graf static efi_status_t EFIAPI efi_close_event(void *event) 290bee91169SAlexander Graf { 291bee91169SAlexander Graf EFI_ENTRY("%p", event); 292bee91169SAlexander Graf efi_event.trigger_next = -1ULL; 293bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 294bee91169SAlexander Graf } 295bee91169SAlexander Graf 296bee91169SAlexander Graf static efi_status_t EFIAPI efi_check_event(void *event) 297bee91169SAlexander Graf { 298bee91169SAlexander Graf EFI_ENTRY("%p", event); 299bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_READY); 300bee91169SAlexander Graf } 301bee91169SAlexander Graf 302bee91169SAlexander Graf static efi_status_t EFIAPI efi_install_protocol_interface(void **handle, 303bee91169SAlexander Graf efi_guid_t *protocol, int protocol_interface_type, 304bee91169SAlexander Graf void *protocol_interface) 305bee91169SAlexander Graf { 306e0549f8aSxypron.glpk@gmx.de struct list_head *lhandle; 307e0549f8aSxypron.glpk@gmx.de int i; 308e0549f8aSxypron.glpk@gmx.de efi_status_t r; 309e0549f8aSxypron.glpk@gmx.de 310e0549f8aSxypron.glpk@gmx.de if (!handle || !protocol || 311e0549f8aSxypron.glpk@gmx.de protocol_interface_type != EFI_NATIVE_INTERFACE) { 312e0549f8aSxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 313e0549f8aSxypron.glpk@gmx.de goto out; 314bee91169SAlexander Graf } 315e0549f8aSxypron.glpk@gmx.de 316e0549f8aSxypron.glpk@gmx.de /* Create new handle if requested. */ 317e0549f8aSxypron.glpk@gmx.de if (!*handle) { 318e0549f8aSxypron.glpk@gmx.de r = EFI_OUT_OF_RESOURCES; 319e0549f8aSxypron.glpk@gmx.de goto out; 320e0549f8aSxypron.glpk@gmx.de } 321e0549f8aSxypron.glpk@gmx.de /* Find object. */ 322e0549f8aSxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 323e0549f8aSxypron.glpk@gmx.de struct efi_object *efiobj; 324e0549f8aSxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 325e0549f8aSxypron.glpk@gmx.de 326e0549f8aSxypron.glpk@gmx.de if (efiobj->handle != *handle) 327e0549f8aSxypron.glpk@gmx.de continue; 328e0549f8aSxypron.glpk@gmx.de /* Check if protocol is already installed on the handle. */ 329e0549f8aSxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 330e0549f8aSxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 331e0549f8aSxypron.glpk@gmx.de 332e0549f8aSxypron.glpk@gmx.de if (!handler->guid) 333e0549f8aSxypron.glpk@gmx.de continue; 334e0549f8aSxypron.glpk@gmx.de if (!guidcmp(handler->guid, protocol)) { 335e0549f8aSxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 336e0549f8aSxypron.glpk@gmx.de goto out; 337e0549f8aSxypron.glpk@gmx.de } 338e0549f8aSxypron.glpk@gmx.de } 339e0549f8aSxypron.glpk@gmx.de /* Install protocol in first empty slot. */ 340e0549f8aSxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 341e0549f8aSxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 342e0549f8aSxypron.glpk@gmx.de 343e0549f8aSxypron.glpk@gmx.de if (handler->guid) 344e0549f8aSxypron.glpk@gmx.de continue; 345e0549f8aSxypron.glpk@gmx.de 346e0549f8aSxypron.glpk@gmx.de handler->guid = protocol; 347e0549f8aSxypron.glpk@gmx.de handler->protocol_interface = protocol_interface; 348e0549f8aSxypron.glpk@gmx.de r = EFI_SUCCESS; 349e0549f8aSxypron.glpk@gmx.de goto out; 350e0549f8aSxypron.glpk@gmx.de } 351e0549f8aSxypron.glpk@gmx.de r = EFI_OUT_OF_RESOURCES; 352e0549f8aSxypron.glpk@gmx.de goto out; 353e0549f8aSxypron.glpk@gmx.de } 354e0549f8aSxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 355e0549f8aSxypron.glpk@gmx.de out: 356*8bee5a3cSxypron.glpk@gmx.de return r; 357*8bee5a3cSxypron.glpk@gmx.de } 358*8bee5a3cSxypron.glpk@gmx.de 359*8bee5a3cSxypron.glpk@gmx.de static efi_status_t EFIAPI efi_install_protocol_interface_ext(void **handle, 360*8bee5a3cSxypron.glpk@gmx.de efi_guid_t *protocol, int protocol_interface_type, 361*8bee5a3cSxypron.glpk@gmx.de void *protocol_interface) 362*8bee5a3cSxypron.glpk@gmx.de { 363*8bee5a3cSxypron.glpk@gmx.de EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type, 364*8bee5a3cSxypron.glpk@gmx.de protocol_interface); 365*8bee5a3cSxypron.glpk@gmx.de 366*8bee5a3cSxypron.glpk@gmx.de return EFI_EXIT(efi_install_protocol_interface(handle, protocol, 367*8bee5a3cSxypron.glpk@gmx.de protocol_interface_type, 368*8bee5a3cSxypron.glpk@gmx.de protocol_interface)); 369e0549f8aSxypron.glpk@gmx.de } 370e0549f8aSxypron.glpk@gmx.de 371bee91169SAlexander Graf static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle, 372bee91169SAlexander Graf efi_guid_t *protocol, void *old_interface, 373bee91169SAlexander Graf void *new_interface) 374bee91169SAlexander Graf { 375bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, old_interface, 376bee91169SAlexander Graf new_interface); 377bee91169SAlexander Graf return EFI_EXIT(EFI_ACCESS_DENIED); 378bee91169SAlexander Graf } 379bee91169SAlexander Graf 380bee91169SAlexander Graf static efi_status_t EFIAPI efi_uninstall_protocol_interface(void *handle, 381bee91169SAlexander Graf efi_guid_t *protocol, void *protocol_interface) 382bee91169SAlexander Graf { 3834b6ed0d7Sxypron.glpk@gmx.de struct list_head *lhandle; 3844b6ed0d7Sxypron.glpk@gmx.de int i; 3854b6ed0d7Sxypron.glpk@gmx.de efi_status_t r = EFI_NOT_FOUND; 3864b6ed0d7Sxypron.glpk@gmx.de 387bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", handle, protocol, protocol_interface); 3884b6ed0d7Sxypron.glpk@gmx.de 3894b6ed0d7Sxypron.glpk@gmx.de if (!handle || !protocol) { 3904b6ed0d7Sxypron.glpk@gmx.de r = EFI_INVALID_PARAMETER; 3914b6ed0d7Sxypron.glpk@gmx.de goto out; 3924b6ed0d7Sxypron.glpk@gmx.de } 3934b6ed0d7Sxypron.glpk@gmx.de 3944b6ed0d7Sxypron.glpk@gmx.de list_for_each(lhandle, &efi_obj_list) { 3954b6ed0d7Sxypron.glpk@gmx.de struct efi_object *efiobj; 3964b6ed0d7Sxypron.glpk@gmx.de efiobj = list_entry(lhandle, struct efi_object, link); 3974b6ed0d7Sxypron.glpk@gmx.de 3984b6ed0d7Sxypron.glpk@gmx.de if (efiobj->handle != handle) 3994b6ed0d7Sxypron.glpk@gmx.de continue; 4004b6ed0d7Sxypron.glpk@gmx.de 4014b6ed0d7Sxypron.glpk@gmx.de for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 4024b6ed0d7Sxypron.glpk@gmx.de struct efi_handler *handler = &efiobj->protocols[i]; 4034b6ed0d7Sxypron.glpk@gmx.de const efi_guid_t *hprotocol = handler->guid; 4044b6ed0d7Sxypron.glpk@gmx.de 4054b6ed0d7Sxypron.glpk@gmx.de if (!hprotocol) 4064b6ed0d7Sxypron.glpk@gmx.de continue; 4074b6ed0d7Sxypron.glpk@gmx.de if (!guidcmp(hprotocol, protocol)) { 4084b6ed0d7Sxypron.glpk@gmx.de if (handler->protocol_interface) { 4094b6ed0d7Sxypron.glpk@gmx.de r = EFI_ACCESS_DENIED; 4104b6ed0d7Sxypron.glpk@gmx.de } else { 4114b6ed0d7Sxypron.glpk@gmx.de handler->guid = 0; 4124b6ed0d7Sxypron.glpk@gmx.de r = EFI_SUCCESS; 4134b6ed0d7Sxypron.glpk@gmx.de } 4144b6ed0d7Sxypron.glpk@gmx.de goto out; 4154b6ed0d7Sxypron.glpk@gmx.de } 4164b6ed0d7Sxypron.glpk@gmx.de } 4174b6ed0d7Sxypron.glpk@gmx.de } 4184b6ed0d7Sxypron.glpk@gmx.de 4194b6ed0d7Sxypron.glpk@gmx.de out: 4204b6ed0d7Sxypron.glpk@gmx.de return EFI_EXIT(r); 421bee91169SAlexander Graf } 422bee91169SAlexander Graf 423bee91169SAlexander Graf static efi_status_t EFIAPI efi_register_protocol_notify(efi_guid_t *protocol, 424bee91169SAlexander Graf void *event, 425bee91169SAlexander Graf void **registration) 426bee91169SAlexander Graf { 427bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, event, registration); 428bee91169SAlexander Graf return EFI_EXIT(EFI_OUT_OF_RESOURCES); 429bee91169SAlexander Graf } 430bee91169SAlexander Graf 431bee91169SAlexander Graf static int efi_search(enum efi_locate_search_type search_type, 432bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 433bee91169SAlexander Graf struct efi_object *efiobj) 434bee91169SAlexander Graf { 435bee91169SAlexander Graf int i; 436bee91169SAlexander Graf 437bee91169SAlexander Graf switch (search_type) { 438bee91169SAlexander Graf case all_handles: 439bee91169SAlexander Graf return 0; 440bee91169SAlexander Graf case by_register_notify: 441bee91169SAlexander Graf return -1; 442bee91169SAlexander Graf case by_protocol: 443bee91169SAlexander Graf for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 444bee91169SAlexander Graf const efi_guid_t *guid = efiobj->protocols[i].guid; 445bee91169SAlexander Graf if (guid && !guidcmp(guid, protocol)) 446bee91169SAlexander Graf return 0; 447bee91169SAlexander Graf } 448bee91169SAlexander Graf return -1; 449bee91169SAlexander Graf } 450bee91169SAlexander Graf 451bee91169SAlexander Graf return -1; 452bee91169SAlexander Graf } 453bee91169SAlexander Graf 454bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_handle( 455bee91169SAlexander Graf enum efi_locate_search_type search_type, 456bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 457bee91169SAlexander Graf unsigned long *buffer_size, efi_handle_t *buffer) 458bee91169SAlexander Graf { 459bee91169SAlexander Graf struct list_head *lhandle; 460bee91169SAlexander Graf unsigned long size = 0; 461bee91169SAlexander Graf 462bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 463bee91169SAlexander Graf buffer_size, buffer); 464bee91169SAlexander Graf 465bee91169SAlexander Graf /* Count how much space we need */ 466bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 467bee91169SAlexander Graf struct efi_object *efiobj; 468bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 469bee91169SAlexander Graf if (!efi_search(search_type, protocol, search_key, efiobj)) { 470bee91169SAlexander Graf size += sizeof(void*); 471bee91169SAlexander Graf } 472bee91169SAlexander Graf } 473bee91169SAlexander Graf 474bee91169SAlexander Graf if (*buffer_size < size) { 475bee91169SAlexander Graf *buffer_size = size; 476bee91169SAlexander Graf return EFI_EXIT(EFI_BUFFER_TOO_SMALL); 477bee91169SAlexander Graf } 478bee91169SAlexander Graf 479bee91169SAlexander Graf /* Then fill the array */ 480bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 481bee91169SAlexander Graf struct efi_object *efiobj; 482bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 483bee91169SAlexander Graf if (!efi_search(search_type, protocol, search_key, efiobj)) { 484bee91169SAlexander Graf *(buffer++) = efiobj->handle; 485bee91169SAlexander Graf } 486bee91169SAlexander Graf } 487bee91169SAlexander Graf 488bee91169SAlexander Graf *buffer_size = size; 489bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 490bee91169SAlexander Graf } 491bee91169SAlexander Graf 492bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_device_path(efi_guid_t *protocol, 493bee91169SAlexander Graf struct efi_device_path **device_path, 494bee91169SAlexander Graf efi_handle_t *device) 495bee91169SAlexander Graf { 496bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, device_path, device); 497bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 498bee91169SAlexander Graf } 499bee91169SAlexander Graf 500488bf12dSAlexander Graf efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table) 501bee91169SAlexander Graf { 502bee91169SAlexander Graf int i; 503bee91169SAlexander Graf 504bee91169SAlexander Graf /* Check for guid override */ 505bee91169SAlexander Graf for (i = 0; i < systab.nr_tables; i++) { 506bee91169SAlexander Graf if (!guidcmp(guid, &efi_conf_table[i].guid)) { 507bee91169SAlexander Graf efi_conf_table[i].table = table; 508488bf12dSAlexander Graf return EFI_SUCCESS; 509bee91169SAlexander Graf } 510bee91169SAlexander Graf } 511bee91169SAlexander Graf 512bee91169SAlexander Graf /* No override, check for overflow */ 513bee91169SAlexander Graf if (i >= ARRAY_SIZE(efi_conf_table)) 514488bf12dSAlexander Graf return EFI_OUT_OF_RESOURCES; 515bee91169SAlexander Graf 516bee91169SAlexander Graf /* Add a new entry */ 517bee91169SAlexander Graf memcpy(&efi_conf_table[i].guid, guid, sizeof(*guid)); 518bee91169SAlexander Graf efi_conf_table[i].table = table; 519aba5e919SAlexander Graf systab.nr_tables = i + 1; 520bee91169SAlexander Graf 521488bf12dSAlexander Graf return EFI_SUCCESS; 522488bf12dSAlexander Graf } 523488bf12dSAlexander Graf 524488bf12dSAlexander Graf static efi_status_t EFIAPI efi_install_configuration_table_ext(efi_guid_t *guid, 525488bf12dSAlexander Graf void *table) 526488bf12dSAlexander Graf { 527488bf12dSAlexander Graf EFI_ENTRY("%p, %p", guid, table); 528488bf12dSAlexander Graf return EFI_EXIT(efi_install_configuration_table(guid, table)); 529bee91169SAlexander Graf } 530bee91169SAlexander Graf 531bee91169SAlexander Graf static efi_status_t EFIAPI efi_load_image(bool boot_policy, 532bee91169SAlexander Graf efi_handle_t parent_image, 533bee91169SAlexander Graf struct efi_device_path *file_path, 534bee91169SAlexander Graf void *source_buffer, 535bee91169SAlexander Graf unsigned long source_size, 536bee91169SAlexander Graf efi_handle_t *image_handle) 537bee91169SAlexander Graf { 538bee91169SAlexander Graf static struct efi_object loaded_image_info_obj = { 539bee91169SAlexander Graf .protocols = { 540bee91169SAlexander Graf { 541bee91169SAlexander Graf .guid = &efi_guid_loaded_image, 542bee91169SAlexander Graf }, 543bee91169SAlexander Graf }, 544bee91169SAlexander Graf }; 545bee91169SAlexander Graf struct efi_loaded_image *info; 546bee91169SAlexander Graf struct efi_object *obj; 547bee91169SAlexander Graf 548bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image, 549bee91169SAlexander Graf file_path, source_buffer, source_size, image_handle); 550bee91169SAlexander Graf info = malloc(sizeof(*info)); 551b5349f74Sxypron.glpk@gmx.de loaded_image_info_obj.protocols[0].protocol_interface = info; 552bee91169SAlexander Graf obj = malloc(sizeof(loaded_image_info_obj)); 553bee91169SAlexander Graf memset(info, 0, sizeof(*info)); 554bee91169SAlexander Graf memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj)); 555bee91169SAlexander Graf obj->handle = info; 556bee91169SAlexander Graf info->file_path = file_path; 557bee91169SAlexander Graf info->reserved = efi_load_pe(source_buffer, info); 558bee91169SAlexander Graf if (!info->reserved) { 559bee91169SAlexander Graf free(info); 560bee91169SAlexander Graf free(obj); 561bee91169SAlexander Graf return EFI_EXIT(EFI_UNSUPPORTED); 562bee91169SAlexander Graf } 563bee91169SAlexander Graf 564bee91169SAlexander Graf *image_handle = info; 565bee91169SAlexander Graf list_add_tail(&obj->link, &efi_obj_list); 566bee91169SAlexander Graf 567bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 568bee91169SAlexander Graf } 569bee91169SAlexander Graf 570bee91169SAlexander Graf static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, 571bee91169SAlexander Graf unsigned long *exit_data_size, 572bee91169SAlexander Graf s16 **exit_data) 573bee91169SAlexander Graf { 574bee91169SAlexander Graf ulong (*entry)(void *image_handle, struct efi_system_table *st); 575bee91169SAlexander Graf struct efi_loaded_image *info = image_handle; 576bee91169SAlexander Graf 577bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data); 578bee91169SAlexander Graf entry = info->reserved; 579bee91169SAlexander Graf 580bee91169SAlexander Graf efi_is_direct_boot = false; 581bee91169SAlexander Graf 582bee91169SAlexander Graf /* call the image! */ 583a86aeaf2SAlexander Graf if (setjmp(&info->exit_jmp)) { 584a86aeaf2SAlexander Graf /* We returned from the child image */ 585a86aeaf2SAlexander Graf return EFI_EXIT(info->exit_status); 586a86aeaf2SAlexander Graf } 587a86aeaf2SAlexander Graf 588bee91169SAlexander Graf entry(image_handle, &systab); 589bee91169SAlexander Graf 590bee91169SAlexander Graf /* Should usually never get here */ 591bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 592bee91169SAlexander Graf } 593bee91169SAlexander Graf 594a86aeaf2SAlexander Graf static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, 595a86aeaf2SAlexander Graf efi_status_t exit_status, unsigned long exit_data_size, 596a86aeaf2SAlexander Graf int16_t *exit_data) 597bee91169SAlexander Graf { 598a86aeaf2SAlexander Graf struct efi_loaded_image *loaded_image_info = (void*)image_handle; 599a86aeaf2SAlexander Graf 600bee91169SAlexander Graf EFI_ENTRY("%p, %ld, %ld, %p", image_handle, exit_status, 601bee91169SAlexander Graf exit_data_size, exit_data); 602a86aeaf2SAlexander Graf 603a86aeaf2SAlexander Graf loaded_image_info->exit_status = exit_status; 604692fcdd8SAlexander Graf longjmp(&loaded_image_info->exit_jmp, 1); 605a86aeaf2SAlexander Graf 606a86aeaf2SAlexander Graf panic("EFI application exited"); 607bee91169SAlexander Graf } 608bee91169SAlexander Graf 609bee91169SAlexander Graf static struct efi_object *efi_search_obj(void *handle) 610bee91169SAlexander Graf { 611bee91169SAlexander Graf struct list_head *lhandle; 612bee91169SAlexander Graf 613bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 614bee91169SAlexander Graf struct efi_object *efiobj; 615bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 616bee91169SAlexander Graf if (efiobj->handle == handle) 617bee91169SAlexander Graf return efiobj; 618bee91169SAlexander Graf } 619bee91169SAlexander Graf 620bee91169SAlexander Graf return NULL; 621bee91169SAlexander Graf } 622bee91169SAlexander Graf 623bee91169SAlexander Graf static efi_status_t EFIAPI efi_unload_image(void *image_handle) 624bee91169SAlexander Graf { 625bee91169SAlexander Graf struct efi_object *efiobj; 626bee91169SAlexander Graf 627bee91169SAlexander Graf EFI_ENTRY("%p", image_handle); 628bee91169SAlexander Graf efiobj = efi_search_obj(image_handle); 629bee91169SAlexander Graf if (efiobj) 630bee91169SAlexander Graf list_del(&efiobj->link); 631bee91169SAlexander Graf 632bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 633bee91169SAlexander Graf } 634bee91169SAlexander Graf 635bee91169SAlexander Graf static void efi_exit_caches(void) 636bee91169SAlexander Graf { 637bee91169SAlexander Graf #if defined(CONFIG_ARM) && !defined(CONFIG_ARM64) 638bee91169SAlexander Graf /* 639bee91169SAlexander Graf * Grub on 32bit ARM needs to have caches disabled before jumping into 640bee91169SAlexander Graf * a zImage, but does not know of all cache layers. Give it a hand. 641bee91169SAlexander Graf */ 642bee91169SAlexander Graf if (efi_is_direct_boot) 643bee91169SAlexander Graf cleanup_before_linux(); 644bee91169SAlexander Graf #endif 645bee91169SAlexander Graf } 646bee91169SAlexander Graf 647bee91169SAlexander Graf static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, 648bee91169SAlexander Graf unsigned long map_key) 649bee91169SAlexander Graf { 650bee91169SAlexander Graf EFI_ENTRY("%p, %ld", image_handle, map_key); 651bee91169SAlexander Graf 652b7b8410aSAlexander Graf board_quiesce_devices(); 653b7b8410aSAlexander Graf 654bee91169SAlexander Graf /* Fix up caches for EFI payloads if necessary */ 655bee91169SAlexander Graf efi_exit_caches(); 656bee91169SAlexander Graf 657bee91169SAlexander Graf /* This stops all lingering devices */ 658bee91169SAlexander Graf bootm_disable_interrupts(); 659bee91169SAlexander Graf 660bee91169SAlexander Graf /* Give the payload some time to boot */ 661bee91169SAlexander Graf WATCHDOG_RESET(); 662bee91169SAlexander Graf 663bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 664bee91169SAlexander Graf } 665bee91169SAlexander Graf 666bee91169SAlexander Graf static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count) 667bee91169SAlexander Graf { 668bee91169SAlexander Graf static uint64_t mono = 0; 669bee91169SAlexander Graf EFI_ENTRY("%p", count); 670bee91169SAlexander Graf *count = mono++; 671bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 672bee91169SAlexander Graf } 673bee91169SAlexander Graf 674bee91169SAlexander Graf static efi_status_t EFIAPI efi_stall(unsigned long microseconds) 675bee91169SAlexander Graf { 676bee91169SAlexander Graf EFI_ENTRY("%ld", microseconds); 677bee91169SAlexander Graf udelay(microseconds); 678bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 679bee91169SAlexander Graf } 680bee91169SAlexander Graf 681bee91169SAlexander Graf static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, 682bee91169SAlexander Graf uint64_t watchdog_code, 683bee91169SAlexander Graf unsigned long data_size, 684bee91169SAlexander Graf uint16_t *watchdog_data) 685bee91169SAlexander Graf { 686bee91169SAlexander Graf EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, 687bee91169SAlexander Graf data_size, watchdog_data); 688bee91169SAlexander Graf return EFI_EXIT(efi_unsupported(__func__)); 689bee91169SAlexander Graf } 690bee91169SAlexander Graf 691bee91169SAlexander Graf static efi_status_t EFIAPI efi_connect_controller( 692bee91169SAlexander Graf efi_handle_t controller_handle, 693bee91169SAlexander Graf efi_handle_t *driver_image_handle, 694bee91169SAlexander Graf struct efi_device_path *remain_device_path, 695bee91169SAlexander Graf bool recursive) 696bee91169SAlexander Graf { 697bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle, 698bee91169SAlexander Graf remain_device_path, recursive); 699bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 700bee91169SAlexander Graf } 701bee91169SAlexander Graf 702bee91169SAlexander Graf static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle, 703bee91169SAlexander Graf void *driver_image_handle, 704bee91169SAlexander Graf void *child_handle) 705bee91169SAlexander Graf { 706bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", controller_handle, driver_image_handle, 707bee91169SAlexander Graf child_handle); 708bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 709bee91169SAlexander Graf } 710bee91169SAlexander Graf 711bee91169SAlexander Graf static efi_status_t EFIAPI efi_close_protocol(void *handle, 712bee91169SAlexander Graf efi_guid_t *protocol, 713bee91169SAlexander Graf void *agent_handle, 714bee91169SAlexander Graf void *controller_handle) 715bee91169SAlexander Graf { 716bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, agent_handle, 717bee91169SAlexander Graf controller_handle); 718bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 719bee91169SAlexander Graf } 720bee91169SAlexander Graf 721bee91169SAlexander Graf static efi_status_t EFIAPI efi_open_protocol_information(efi_handle_t handle, 722bee91169SAlexander Graf efi_guid_t *protocol, 723bee91169SAlexander Graf struct efi_open_protocol_info_entry **entry_buffer, 724bee91169SAlexander Graf unsigned long *entry_count) 725bee91169SAlexander Graf { 726bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p", handle, protocol, entry_buffer, 727bee91169SAlexander Graf entry_count); 728bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 729bee91169SAlexander Graf } 730bee91169SAlexander Graf 731bee91169SAlexander Graf static efi_status_t EFIAPI efi_protocols_per_handle(void *handle, 732bee91169SAlexander Graf efi_guid_t ***protocol_buffer, 733bee91169SAlexander Graf unsigned long *protocol_buffer_count) 734bee91169SAlexander Graf { 735bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", handle, protocol_buffer, 736bee91169SAlexander Graf protocol_buffer_count); 737bee91169SAlexander Graf return EFI_EXIT(EFI_OUT_OF_RESOURCES); 738bee91169SAlexander Graf } 739bee91169SAlexander Graf 740bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_handle_buffer( 741bee91169SAlexander Graf enum efi_locate_search_type search_type, 742bee91169SAlexander Graf efi_guid_t *protocol, void *search_key, 743bee91169SAlexander Graf unsigned long *no_handles, efi_handle_t **buffer) 744bee91169SAlexander Graf { 745bee91169SAlexander Graf EFI_ENTRY("%d, %p, %p, %p, %p", search_type, protocol, search_key, 746bee91169SAlexander Graf no_handles, buffer); 747bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 748bee91169SAlexander Graf } 749bee91169SAlexander Graf 750bee91169SAlexander Graf static struct efi_class_map efi_class_maps[] = { 751bee91169SAlexander Graf { 752bee91169SAlexander Graf .guid = &efi_guid_console_control, 753bee91169SAlexander Graf .interface = &efi_console_control 754bee91169SAlexander Graf }, 755bee91169SAlexander Graf }; 756bee91169SAlexander Graf 757bee91169SAlexander Graf static efi_status_t EFIAPI efi_locate_protocol(efi_guid_t *protocol, 758bee91169SAlexander Graf void *registration, 759bee91169SAlexander Graf void **protocol_interface) 760bee91169SAlexander Graf { 761bee91169SAlexander Graf int i; 762bee91169SAlexander Graf 763bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p", protocol, registration, protocol_interface); 764bee91169SAlexander Graf for (i = 0; i < ARRAY_SIZE(efi_class_maps); i++) { 765bee91169SAlexander Graf struct efi_class_map *curmap = &efi_class_maps[i]; 766bee91169SAlexander Graf if (!guidcmp(protocol, curmap->guid)) { 767bee91169SAlexander Graf *protocol_interface = (void*)curmap->interface; 768bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 769bee91169SAlexander Graf } 770bee91169SAlexander Graf } 771bee91169SAlexander Graf 772bee91169SAlexander Graf return EFI_EXIT(EFI_NOT_FOUND); 773bee91169SAlexander Graf } 774bee91169SAlexander Graf 775bee91169SAlexander Graf static efi_status_t EFIAPI efi_install_multiple_protocol_interfaces( 776bee91169SAlexander Graf void **handle, ...) 777bee91169SAlexander Graf { 778bee91169SAlexander Graf EFI_ENTRY("%p", handle); 779bee91169SAlexander Graf return EFI_EXIT(EFI_OUT_OF_RESOURCES); 780bee91169SAlexander Graf } 781bee91169SAlexander Graf 782bee91169SAlexander Graf static efi_status_t EFIAPI efi_uninstall_multiple_protocol_interfaces( 783bee91169SAlexander Graf void *handle, ...) 784bee91169SAlexander Graf { 785bee91169SAlexander Graf EFI_ENTRY("%p", handle); 786bee91169SAlexander Graf return EFI_EXIT(EFI_INVALID_PARAMETER); 787bee91169SAlexander Graf } 788bee91169SAlexander Graf 789bee91169SAlexander Graf static efi_status_t EFIAPI efi_calculate_crc32(void *data, 790bee91169SAlexander Graf unsigned long data_size, 791bee91169SAlexander Graf uint32_t *crc32_p) 792bee91169SAlexander Graf { 793bee91169SAlexander Graf EFI_ENTRY("%p, %ld", data, data_size); 794bee91169SAlexander Graf *crc32_p = crc32(0, data, data_size); 795bee91169SAlexander Graf return EFI_EXIT(EFI_SUCCESS); 796bee91169SAlexander Graf } 797bee91169SAlexander Graf 798bee91169SAlexander Graf static void EFIAPI efi_copy_mem(void *destination, void *source, 799bee91169SAlexander Graf unsigned long length) 800bee91169SAlexander Graf { 801bee91169SAlexander Graf EFI_ENTRY("%p, %p, %ld", destination, source, length); 802bee91169SAlexander Graf memcpy(destination, source, length); 803bee91169SAlexander Graf } 804bee91169SAlexander Graf 805bee91169SAlexander Graf static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value) 806bee91169SAlexander Graf { 807bee91169SAlexander Graf EFI_ENTRY("%p, %ld, 0x%x", buffer, size, value); 808bee91169SAlexander Graf memset(buffer, value, size); 809bee91169SAlexander Graf } 810bee91169SAlexander Graf 811bee91169SAlexander Graf static efi_status_t EFIAPI efi_open_protocol( 812bee91169SAlexander Graf void *handle, efi_guid_t *protocol, 813bee91169SAlexander Graf void **protocol_interface, void *agent_handle, 814bee91169SAlexander Graf void *controller_handle, uint32_t attributes) 815bee91169SAlexander Graf { 816bee91169SAlexander Graf struct list_head *lhandle; 817bee91169SAlexander Graf int i; 81869baec67Sxypron.glpk@gmx.de efi_status_t r = EFI_INVALID_PARAMETER; 819bee91169SAlexander Graf 820bee91169SAlexander Graf EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol, 821bee91169SAlexander Graf protocol_interface, agent_handle, controller_handle, 822bee91169SAlexander Graf attributes); 823b5349f74Sxypron.glpk@gmx.de 82469baec67Sxypron.glpk@gmx.de if (!handle || !protocol || 82569baec67Sxypron.glpk@gmx.de (!protocol_interface && attributes != 82669baec67Sxypron.glpk@gmx.de EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) { 82769baec67Sxypron.glpk@gmx.de goto out; 82869baec67Sxypron.glpk@gmx.de } 82969baec67Sxypron.glpk@gmx.de 83069baec67Sxypron.glpk@gmx.de switch (attributes) { 83169baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: 83269baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_GET_PROTOCOL: 83369baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: 83469baec67Sxypron.glpk@gmx.de break; 83569baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: 83669baec67Sxypron.glpk@gmx.de if (controller_handle == handle) 83769baec67Sxypron.glpk@gmx.de goto out; 83869baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_DRIVER: 83969baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: 84069baec67Sxypron.glpk@gmx.de if (controller_handle == NULL) 84169baec67Sxypron.glpk@gmx.de goto out; 84269baec67Sxypron.glpk@gmx.de case EFI_OPEN_PROTOCOL_EXCLUSIVE: 84369baec67Sxypron.glpk@gmx.de if (agent_handle == NULL) 84469baec67Sxypron.glpk@gmx.de goto out; 84569baec67Sxypron.glpk@gmx.de break; 84669baec67Sxypron.glpk@gmx.de default: 847b5349f74Sxypron.glpk@gmx.de goto out; 848b5349f74Sxypron.glpk@gmx.de } 849b5349f74Sxypron.glpk@gmx.de 850bee91169SAlexander Graf list_for_each(lhandle, &efi_obj_list) { 851bee91169SAlexander Graf struct efi_object *efiobj; 852bee91169SAlexander Graf efiobj = list_entry(lhandle, struct efi_object, link); 853bee91169SAlexander Graf 854bee91169SAlexander Graf if (efiobj->handle != handle) 855bee91169SAlexander Graf continue; 856bee91169SAlexander Graf 857bee91169SAlexander Graf for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) { 858bee91169SAlexander Graf struct efi_handler *handler = &efiobj->protocols[i]; 859bee91169SAlexander Graf const efi_guid_t *hprotocol = handler->guid; 860bee91169SAlexander Graf if (!hprotocol) 8614b6ed0d7Sxypron.glpk@gmx.de continue; 862bee91169SAlexander Graf if (!guidcmp(hprotocol, protocol)) { 863b5349f74Sxypron.glpk@gmx.de if (attributes != 864b5349f74Sxypron.glpk@gmx.de EFI_OPEN_PROTOCOL_TEST_PROTOCOL) { 865b5349f74Sxypron.glpk@gmx.de *protocol_interface = 866b5349f74Sxypron.glpk@gmx.de handler->protocol_interface; 867b5349f74Sxypron.glpk@gmx.de } 868b5349f74Sxypron.glpk@gmx.de r = EFI_SUCCESS; 869bee91169SAlexander Graf goto out; 870bee91169SAlexander Graf } 871bee91169SAlexander Graf } 87269baec67Sxypron.glpk@gmx.de goto unsupported; 873bee91169SAlexander Graf } 874bee91169SAlexander Graf 87569baec67Sxypron.glpk@gmx.de unsupported: 87669baec67Sxypron.glpk@gmx.de r = EFI_UNSUPPORTED; 877bee91169SAlexander Graf out: 878bee91169SAlexander Graf return EFI_EXIT(r); 879bee91169SAlexander Graf } 880bee91169SAlexander Graf 881bee91169SAlexander Graf static efi_status_t EFIAPI efi_handle_protocol(void *handle, 882bee91169SAlexander Graf efi_guid_t *protocol, 883bee91169SAlexander Graf void **protocol_interface) 884bee91169SAlexander Graf { 8858e1d329fSxypron.glpk@gmx.de return efi_open_protocol(handle, protocol, protocol_interface, NULL, 8868e1d329fSxypron.glpk@gmx.de NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); 887bee91169SAlexander Graf } 888bee91169SAlexander Graf 889bee91169SAlexander Graf static const struct efi_boot_services efi_boot_services = { 890bee91169SAlexander Graf .hdr = { 891bee91169SAlexander Graf .headersize = sizeof(struct efi_table_hdr), 892bee91169SAlexander Graf }, 893bee91169SAlexander Graf .raise_tpl = efi_raise_tpl, 894bee91169SAlexander Graf .restore_tpl = efi_restore_tpl, 895bee91169SAlexander Graf .allocate_pages = efi_allocate_pages_ext, 896bee91169SAlexander Graf .free_pages = efi_free_pages_ext, 897bee91169SAlexander Graf .get_memory_map = efi_get_memory_map_ext, 898ead1274bSStefan Brüns .allocate_pool = efi_allocate_pool_ext, 89942417bc8SStefan Brüns .free_pool = efi_free_pool_ext, 900bee91169SAlexander Graf .create_event = efi_create_event, 901bee91169SAlexander Graf .set_timer = efi_set_timer, 902bee91169SAlexander Graf .wait_for_event = efi_wait_for_event, 903bee91169SAlexander Graf .signal_event = efi_signal_event, 904bee91169SAlexander Graf .close_event = efi_close_event, 905bee91169SAlexander Graf .check_event = efi_check_event, 906*8bee5a3cSxypron.glpk@gmx.de .install_protocol_interface = efi_install_protocol_interface_ext, 907bee91169SAlexander Graf .reinstall_protocol_interface = efi_reinstall_protocol_interface, 908bee91169SAlexander Graf .uninstall_protocol_interface = efi_uninstall_protocol_interface, 909bee91169SAlexander Graf .handle_protocol = efi_handle_protocol, 910bee91169SAlexander Graf .reserved = NULL, 911bee91169SAlexander Graf .register_protocol_notify = efi_register_protocol_notify, 912bee91169SAlexander Graf .locate_handle = efi_locate_handle, 913bee91169SAlexander Graf .locate_device_path = efi_locate_device_path, 914488bf12dSAlexander Graf .install_configuration_table = efi_install_configuration_table_ext, 915bee91169SAlexander Graf .load_image = efi_load_image, 916bee91169SAlexander Graf .start_image = efi_start_image, 917a86aeaf2SAlexander Graf .exit = efi_exit, 918bee91169SAlexander Graf .unload_image = efi_unload_image, 919bee91169SAlexander Graf .exit_boot_services = efi_exit_boot_services, 920bee91169SAlexander Graf .get_next_monotonic_count = efi_get_next_monotonic_count, 921bee91169SAlexander Graf .stall = efi_stall, 922bee91169SAlexander Graf .set_watchdog_timer = efi_set_watchdog_timer, 923bee91169SAlexander Graf .connect_controller = efi_connect_controller, 924bee91169SAlexander Graf .disconnect_controller = efi_disconnect_controller, 925bee91169SAlexander Graf .open_protocol = efi_open_protocol, 926bee91169SAlexander Graf .close_protocol = efi_close_protocol, 927bee91169SAlexander Graf .open_protocol_information = efi_open_protocol_information, 928bee91169SAlexander Graf .protocols_per_handle = efi_protocols_per_handle, 929bee91169SAlexander Graf .locate_handle_buffer = efi_locate_handle_buffer, 930bee91169SAlexander Graf .locate_protocol = efi_locate_protocol, 931bee91169SAlexander Graf .install_multiple_protocol_interfaces = efi_install_multiple_protocol_interfaces, 932bee91169SAlexander Graf .uninstall_multiple_protocol_interfaces = efi_uninstall_multiple_protocol_interfaces, 933bee91169SAlexander Graf .calculate_crc32 = efi_calculate_crc32, 934bee91169SAlexander Graf .copy_mem = efi_copy_mem, 935bee91169SAlexander Graf .set_mem = efi_set_mem, 936bee91169SAlexander Graf }; 937bee91169SAlexander Graf 938bee91169SAlexander Graf 9393c63db9cSAlexander Graf static uint16_t __efi_runtime_data firmware_vendor[] = 940bee91169SAlexander Graf { 'D','a','s',' ','U','-','b','o','o','t',0 }; 941bee91169SAlexander Graf 9423c63db9cSAlexander Graf struct efi_system_table __efi_runtime_data systab = { 943bee91169SAlexander Graf .hdr = { 944bee91169SAlexander Graf .signature = EFI_SYSTEM_TABLE_SIGNATURE, 945bee91169SAlexander Graf .revision = 0x20005, /* 2.5 */ 946bee91169SAlexander Graf .headersize = sizeof(struct efi_table_hdr), 947bee91169SAlexander Graf }, 948bee91169SAlexander Graf .fw_vendor = (long)firmware_vendor, 949bee91169SAlexander Graf .con_in = (void*)&efi_con_in, 950bee91169SAlexander Graf .con_out = (void*)&efi_con_out, 951bee91169SAlexander Graf .std_err = (void*)&efi_con_out, 952bee91169SAlexander Graf .runtime = (void*)&efi_runtime_services, 953bee91169SAlexander Graf .boottime = (void*)&efi_boot_services, 954bee91169SAlexander Graf .nr_tables = 0, 955bee91169SAlexander Graf .tables = (void*)efi_conf_table, 956bee91169SAlexander Graf }; 957