Commit 3ba75c13 authored by Baskov Evgeniy's avatar Baskov Evgeniy Committed by Ard Biesheuvel

efi: libstub: declare DXE services table

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: default avatarBaskov 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: default avatarArd Biesheuvel <ardb@kernel.org>
parent aa480379
...@@ -357,6 +357,11 @@ static inline u32 efi64_convert_status(efi_status_t status) ...@@ -357,6 +357,11 @@ static inline u32 efi64_convert_status(efi_status_t status)
runtime), \ runtime), \
func, __VA_ARGS__)) 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 */ #else /* CONFIG_EFI_MIXED */
static inline bool efi_is_64bit(void) static inline bool efi_is_64bit(void)
......
...@@ -36,6 +36,9 @@ extern bool efi_novamap; ...@@ -36,6 +36,9 @@ extern bool efi_novamap;
extern const efi_system_table_t *efi_system_table; 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_status_t __efiapi efi_pe_entry(efi_handle_t handle,
efi_system_table_t *sys_table_arg); efi_system_table_t *sys_table_arg);
...@@ -44,6 +47,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, ...@@ -44,6 +47,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
#define efi_is_native() (true) #define efi_is_native() (true)
#define efi_bs_call(func, ...) efi_system_table->boottime->func(__VA_ARGS__) #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_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_table_attr(inst, attr) (inst->attr)
#define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__) #define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__)
...@@ -329,6 +333,76 @@ union efi_boot_services { ...@@ -329,6 +333,76 @@ union efi_boot_services {
} mixed_mode; } 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; typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
union efi_uga_draw_protocol { union efi_uga_draw_protocol {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#define MAXMEM_X86_64_4LEVEL (1ull << 46) #define MAXMEM_X86_64_4LEVEL (1ull << 46)
const efi_system_table_t *efi_system_table; const efi_system_table_t *efi_system_table;
const efi_dxe_services_table_t *efi_dxe_table;
extern u32 image_offset; extern u32 image_offset;
static efi_loaded_image_t *image = NULL; static efi_loaded_image_t *image = NULL;
...@@ -677,11 +678,17 @@ unsigned long efi_main(efi_handle_t handle, ...@@ -677,11 +678,17 @@ unsigned long efi_main(efi_handle_t handle,
efi_status_t status; efi_status_t status;
efi_system_table = sys_table_arg; efi_system_table = sys_table_arg;
/* Check if we were booted by the EFI firmware */ /* Check if we were booted by the EFI firmware */
if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
efi_exit(handle, EFI_INVALID_PARAMETER); 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, * If the kernel isn't already loaded at a suitable address,
* relocate it. * relocate it.
......
...@@ -385,6 +385,7 @@ void efi_native_runtime_setup(void); ...@@ -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_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_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_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_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) #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
...@@ -438,6 +439,7 @@ typedef struct { ...@@ -438,6 +439,7 @@ typedef struct {
} efi_config_table_type_t; } efi_config_table_type_t;
#define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL) #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_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
#define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20)) #define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment