1cb149c66SAlexander Graf /* 2cb149c66SAlexander Graf * EFI application loader 3cb149c66SAlexander Graf * 4cb149c66SAlexander Graf * Copyright (c) 2016 Alexander Graf 5cb149c66SAlexander Graf * 6cb149c66SAlexander Graf * SPDX-License-Identifier: GPL-2.0+ 7cb149c66SAlexander Graf */ 8cb149c66SAlexander Graf 9bee91169SAlexander Graf #include <common.h> 10cb149c66SAlexander Graf #include <part_efi.h> 11cb149c66SAlexander Graf #include <efi_api.h> 12bee91169SAlexander Graf 13bee91169SAlexander Graf /* No need for efi loader support in SPL */ 14bee91169SAlexander Graf #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD) 15bee91169SAlexander Graf 16cb149c66SAlexander Graf #include <linux/list.h> 17cb149c66SAlexander Graf 18bee91169SAlexander Graf /* #define DEBUG_EFI */ 19bee91169SAlexander Graf 20bee91169SAlexander Graf #ifdef DEBUG_EFI 21bee91169SAlexander Graf #define EFI_ENTRY(format, ...) do { \ 22bee91169SAlexander Graf efi_restore_gd(); \ 23bee91169SAlexander Graf printf("EFI: Entry %s(" format ")\n", __func__, ##__VA_ARGS__); \ 24bee91169SAlexander Graf } while(0) 25bee91169SAlexander Graf #else 26bee91169SAlexander Graf #define EFI_ENTRY(format, ...) do { \ 27bee91169SAlexander Graf efi_restore_gd(); \ 28bee91169SAlexander Graf } while(0) 29bee91169SAlexander Graf #endif 30bee91169SAlexander Graf 31bee91169SAlexander Graf #define EFI_EXIT(ret) efi_exit_func(ret); 32bee91169SAlexander Graf 33bee91169SAlexander Graf extern struct efi_system_table systab; 34bee91169SAlexander Graf 35*c1311ad4SAlexander Graf extern const struct efi_simple_text_output_protocol efi_con_out; 36*c1311ad4SAlexander Graf extern const struct efi_simple_input_interface efi_con_in; 37*c1311ad4SAlexander Graf extern const struct efi_console_control_protocol efi_console_control; 38*c1311ad4SAlexander Graf 39*c1311ad4SAlexander Graf extern const efi_guid_t efi_guid_console_control; 40cb149c66SAlexander Graf extern const efi_guid_t efi_guid_device_path; 41cb149c66SAlexander Graf extern const efi_guid_t efi_guid_loaded_image; 42cb149c66SAlexander Graf 43bee91169SAlexander Graf /* 44bee91169SAlexander Graf * While UEFI objects can have callbacks, you can also call functions on 45bee91169SAlexander Graf * protocols (classes) themselves. This struct maps a protocol GUID to its 46bee91169SAlexander Graf * interface (usually a struct with callback functions). 47bee91169SAlexander Graf */ 48bee91169SAlexander Graf struct efi_class_map { 49bee91169SAlexander Graf const efi_guid_t *guid; 50bee91169SAlexander Graf const void *interface; 51bee91169SAlexander Graf }; 52bee91169SAlexander Graf 53bee91169SAlexander Graf /* 54bee91169SAlexander Graf * When the UEFI payload wants to open a protocol on an object to get its 55bee91169SAlexander Graf * interface (usually a struct with callback functions), this struct maps the 56bee91169SAlexander Graf * protocol GUID to the respective protocol handler open function for that 57bee91169SAlexander Graf * object protocol combination. 58bee91169SAlexander Graf */ 59bee91169SAlexander Graf struct efi_handler { 60bee91169SAlexander Graf const efi_guid_t *guid; 61bee91169SAlexander Graf efi_status_t (EFIAPI *open)(void *handle, 62bee91169SAlexander Graf efi_guid_t *protocol, void **protocol_interface, 63bee91169SAlexander Graf void *agent_handle, void *controller_handle, 64bee91169SAlexander Graf uint32_t attributes); 65bee91169SAlexander Graf }; 66bee91169SAlexander Graf 67bee91169SAlexander Graf /* 68bee91169SAlexander Graf * UEFI has a poor man's OO model where one "object" can be polymorphic and have 69bee91169SAlexander Graf * multiple different protocols (classes) attached to it. 70bee91169SAlexander Graf * 71bee91169SAlexander Graf * This struct is the parent struct for all of our actual implementation objects 72bee91169SAlexander Graf * that can include it to make themselves an EFI object 73bee91169SAlexander Graf */ 74bee91169SAlexander Graf struct efi_object { 75bee91169SAlexander Graf /* Every UEFI object is part of a global object list */ 76bee91169SAlexander Graf struct list_head link; 77bee91169SAlexander Graf /* We support up to 4 "protocols" an object can be accessed through */ 78bee91169SAlexander Graf struct efi_handler protocols[4]; 79bee91169SAlexander Graf /* The object spawner can either use this for data or as identifier */ 80bee91169SAlexander Graf void *handle; 81bee91169SAlexander Graf }; 82bee91169SAlexander Graf 83bee91169SAlexander Graf /* This list contains all UEFI objects we know of */ 84bee91169SAlexander Graf extern struct list_head efi_obj_list; 85bee91169SAlexander Graf 86bee91169SAlexander Graf /* 87bee91169SAlexander Graf * Stub implementation for a protocol opener that just returns the handle as 88bee91169SAlexander Graf * interface 89bee91169SAlexander Graf */ 90cb149c66SAlexander Graf efi_status_t efi_return_handle(void *handle, 91cb149c66SAlexander Graf efi_guid_t *protocol, void **protocol_interface, 92cb149c66SAlexander Graf void *agent_handle, void *controller_handle, 93cb149c66SAlexander Graf uint32_t attributes); 94bee91169SAlexander Graf /* Called from places to check whether a timer expired */ 95bee91169SAlexander Graf void efi_timer_check(void); 96bee91169SAlexander Graf /* PE loader implementation */ 97cb149c66SAlexander Graf void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info); 98bee91169SAlexander Graf /* Called once to store the pristine gd pointer */ 99bee91169SAlexander Graf void efi_save_gd(void); 100bee91169SAlexander Graf /* Called from EFI_ENTRY on callback entry to put gd into the gd register */ 101bee91169SAlexander Graf void efi_restore_gd(void); 102bee91169SAlexander Graf /* Called from EFI_EXIT on callback exit to restore the gd register */ 103bee91169SAlexander Graf efi_status_t efi_exit_func(efi_status_t ret); 104bee91169SAlexander Graf 105bee91169SAlexander Graf #else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */ 106bee91169SAlexander Graf 107bee91169SAlexander Graf /* No loader configured, stub out EFI_ENTRY */ 108bee91169SAlexander Graf static inline void efi_restore_gd(void) { } 109bee91169SAlexander Graf 110bee91169SAlexander Graf #endif 111