]> git.baikalelectronics.ru Git - kernel.git/commitdiff
efi: libstub: declare DXE services table
authorBaskov Evgeniy <baskov@ispras.ru>
Thu, 3 Mar 2022 14:21:19 +0000 (17:21 +0300)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 3 May 2022 13:31:01 +0000 (15:31 +0200)
UEFI DXE services are not yet used in kernel code
but are required to manipulate page table memory
protection flags.

Add required declarations to use DXE services functions.

Signed-off-by: Baskov Evgeniy <baskov@ispras.ru>
Link: https://lore.kernel.org/r/20220303142120.1975-2-baskov@ispras.ru
[ardb: ignore absent DXE table but warn if the signature check fails]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/x86/include/asm/efi.h
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/x86-stub.c
include/linux/efi.h

index 98938a68251cc49fc755328edea827fbe52d11df..bed74a0f2932dfdba626b239baddfbd07d06494f 100644 (file)
@@ -357,6 +357,11 @@ static inline u32 efi64_convert_status(efi_status_t status)
                                                   runtime),            \
                                    func, __VA_ARGS__))
 
+#define efi_dxe_call(func, ...)                                                \
+       (efi_is_native()                                                \
+               ? efi_dxe_table->func(__VA_ARGS__)                      \
+               : __efi64_thunk_map(efi_dxe_table, func, __VA_ARGS__))
+
 #else /* CONFIG_EFI_MIXED */
 
 static inline bool efi_is_64bit(void)
index edb77b0621ea3f5da7a2f2a0f2bd066c1925210d..2dc24776899a6d062ac84d201d545172792ffcb9 100644 (file)
@@ -36,6 +36,9 @@ extern bool efi_novamap;
 
 extern const efi_system_table_t *efi_system_table;
 
+typedef union efi_dxe_services_table efi_dxe_services_table_t;
+extern const efi_dxe_services_table_t *efi_dxe_table;
+
 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
                                   efi_system_table_t *sys_table_arg);
 
@@ -44,6 +47,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
 #define efi_is_native()                (true)
 #define efi_bs_call(func, ...) efi_system_table->boottime->func(__VA_ARGS__)
 #define efi_rt_call(func, ...) efi_system_table->runtime->func(__VA_ARGS__)
+#define efi_dxe_call(func, ...)        efi_dxe_table->func(__VA_ARGS__)
 #define efi_table_attr(inst, attr)     (inst->attr)
 #define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__)
 
@@ -329,6 +333,76 @@ union efi_boot_services {
        } mixed_mode;
 };
 
+typedef enum {
+       EfiGcdMemoryTypeNonExistent,
+       EfiGcdMemoryTypeReserved,
+       EfiGcdMemoryTypeSystemMemory,
+       EfiGcdMemoryTypeMemoryMappedIo,
+       EfiGcdMemoryTypePersistent,
+       EfiGcdMemoryTypeMoreReliable,
+       EfiGcdMemoryTypeMaximum
+} efi_gcd_memory_type_t;
+
+typedef struct {
+       efi_physical_addr_t base_address;
+       u64 length;
+       u64 capabilities;
+       u64 attributes;
+       efi_gcd_memory_type_t gcd_memory_type;
+       void *image_handle;
+       void *device_handle;
+} efi_gcd_memory_space_desc_t;
+
+/*
+ * EFI DXE Services table
+ */
+union efi_dxe_services_table {
+       struct {
+               efi_table_hdr_t hdr;
+               void *add_memory_space;
+               void *allocate_memory_space;
+               void *free_memory_space;
+               void *remove_memory_space;
+               efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,
+                                                                    efi_gcd_memory_space_desc_t *);
+               efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,
+                                                                    u64, u64);
+               void *get_memory_space_map;
+               void *add_io_space;
+               void *allocate_io_space;
+               void *free_io_space;
+               void *remove_io_space;
+               void *get_io_space_descriptor;
+               void *get_io_space_map;
+               void *dispatch;
+               void *schedule;
+               void *trust;
+               void *process_firmware_volume;
+               void *set_memory_space_capabilities;
+       };
+       struct {
+               efi_table_hdr_t hdr;
+               u32 add_memory_space;
+               u32 allocate_memory_space;
+               u32 free_memory_space;
+               u32 remove_memory_space;
+               u32 get_memory_space_descriptor;
+               u32 set_memory_space_attributes;
+               u32 get_memory_space_map;
+               u32 add_io_space;
+               u32 allocate_io_space;
+               u32 free_io_space;
+               u32 remove_io_space;
+               u32 get_io_space_descriptor;
+               u32 get_io_space_map;
+               u32 dispatch;
+               u32 schedule;
+               u32 trust;
+               u32 process_firmware_volume;
+               u32 set_memory_space_capabilities;
+       } mixed_mode;
+};
+
 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
 
 union efi_uga_draw_protocol {
index 01ddd4502e28a116f553ffb5b3383e76def9fded..cda60aba2f123e51b9ca5982ee7ad8ed381b3c80 100644 (file)
@@ -22,6 +22,7 @@
 #define MAXMEM_X86_64_4LEVEL (1ull << 46)
 
 const efi_system_table_t *efi_system_table;
+const efi_dxe_services_table_t *efi_dxe_table;
 extern u32 image_offset;
 static efi_loaded_image_t *image = NULL;
 
@@ -677,11 +678,17 @@ unsigned long efi_main(efi_handle_t handle,
        efi_status_t status;
 
        efi_system_table = sys_table_arg;
-
        /* Check if we were booted by the EFI firmware */
        if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
                efi_exit(handle, EFI_INVALID_PARAMETER);
 
+       efi_dxe_table = get_efi_config_table(EFI_DXE_SERVICES_TABLE_GUID);
+       if (efi_dxe_table &&
+           efi_dxe_table->hdr.signature != EFI_DXE_SERVICES_TABLE_SIGNATURE) {
+               efi_warn("Ignoring DXE services table: invalid signature\n");
+               efi_dxe_table = NULL;
+       }
+
        /*
         * If the kernel isn't already loaded at a suitable address,
         * relocate it.
index fd266198f9d8c2e8d82dbe998bc5a5ca513e3a5d..b1f7c6a3e5bf6c6860ce8dfbbb6648cad4d059c2 100644 (file)
@@ -385,6 +385,7 @@ void efi_native_runtime_setup(void);
 #define EFI_LOAD_FILE_PROTOCOL_GUID            EFI_GUID(0x56ec3091, 0x954c, 0x11d2,  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
 #define EFI_LOAD_FILE2_PROTOCOL_GUID           EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e,  0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
 #define EFI_RT_PROPERTIES_TABLE_GUID           EFI_GUID(0xeb66918a, 0x7eef, 0x402a,  0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9)
+#define EFI_DXE_SERVICES_TABLE_GUID            EFI_GUID(0x05ad34ba, 0x6f02, 0x4214,  0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
 
 #define EFI_IMAGE_SECURITY_DATABASE_GUID       EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596,  0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
 #define EFI_SHIM_LOCK_GUID                     EFI_GUID(0x605dab50, 0xe046, 0x4300,  0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
@@ -438,6 +439,7 @@ typedef struct {
 } efi_config_table_type_t;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
+#define EFI_DXE_SERVICES_TABLE_SIGNATURE ((u64)0x565245535f455844ULL)
 
 #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
 #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))