[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 1/3] efi: provide definitions of DXE services table
From: |
Baskov Evgeniy |
Subject: |
[PATCH RFC 1/3] efi: provide definitions of DXE services table |
Date: |
Thu, 7 Apr 2022 06:32:26 +0300 |
DXE services can be used to change memory attributes
on systems where EFI use stricter policies about memory
access rights and sets NX flag on some pages required by
grub to executable.
Signed-off-by: Baskov Evgeniy <baskov@ispras.ru>
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index 40434ee9d..e164102b1 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -53,6 +53,17 @@ grub_efi_locate_protocol (grub_efi_guid_t *protocol, void
*registration)
return interface;
}
+void *
+grub_efi_get_config_table(grub_efi_guid_t *guid)
+{
+ grub_efi_uintn_t n_entries = grub_efi_system_table->num_table_entries;
+ grub_efi_configuration_table_t *entry =
grub_efi_system_table->configuration_table;
+ for (; n_entries > 0; n_entries--, entry++)
+ if (0 == grub_memcmp (&entry->vendor_guid, guid, sizeof (*guid)))
+ return entry->vendor_table;
+ return NULL;
+}
+
/* Return the array of handles which meet the requirement. If successful,
the number of handles is stored in NUM_HANDLES. The array is allocated
from the heap. */
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index 86db96994..90009feb6 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -1352,6 +1352,154 @@ struct grub_efi_runtime_services
};
typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
+typedef enum
+ {
+ GRUB_EFI_GCD_MEMORY_TYPE_NON_EXISTENT,
+ GRUB_EFI_GCD_MEMORY_TYPE_RESERVED,
+ GRUB_EFI_GCD_MEMORY_TYPE_SYSTEM_MEMORY,
+ GRUB_EFI_GCD_MEMORY_TYPE_MEMORY_MAPPED_IO,
+ GRUB_EFI_GCD_MEMORY_TYPE_PERSISTENT,
+ GRUB_EFI_GCD_MEMORY_TYPE_MORE_RELIABLE,
+ GRUB_EFI_GCD_MEMORY_TYPE_MAXIMUM
+ }
+grub_efi_gcd_memory_type_t;
+
+typedef enum
+ {
+ GRUB_EFI_GCD_ALLOCATE_ANY_SEARCH_BOTTOM_UP,
+ GRUB_EFI_GCD_ALLOCATE_MAX_ADDRESS_SEARCH_BOTTOM_UP,
+ GRUB_EFI_GCD_ALLOCATE_ADDRESS,
+ GRUB_EFI_GCD_ALLOCATE_ANY_SEARCH_TOP_DOWN,
+ GRUB_EFI_GCD_ALLOCATE_MAX_ADDRESS_SEARCH_TOP_DOWN,
+ GRUB_EFI_GCD_MAX_ALLOCATE_TYPE
+ }
+grub_efi_gcd_allocate_type_t;
+
+struct grub_efi_gcd_memory_space_descriptor
+{
+ grub_efi_physical_address_t base_address;
+ grub_efi_uint64_t length;
+ grub_efi_uint64_t capabilities;
+ grub_efi_uint64_t attributes;
+ grub_efi_gcd_memory_type_t gcd_memory_type;
+ grub_efi_handle_t image_handle;
+ grub_efi_handle_t device_handle;
+};
+typedef struct grub_efi_gcd_memory_space_descriptor
+ grub_efi_gcd_memory_space_descriptor_t;
+
+typedef enum
+ {
+ GRUB_EFI_GCD_IO_TYPE_NON_EXISTENT,
+ GRUB_EFI_GCD_IO_TYPE_RESERVED,
+ GRUB_EFI_GCD_IO_TYPE_IO,
+ GRUB_EFI_GCD_IO_TYPE_MAXIMUM
+ }
+grub_efi_gcd_io_type_t;
+
+struct grub_efi_gcd_io_space_descriptor
+{
+ grub_efi_physical_address_t base_address;
+ grub_efi_uint64_t length;
+ grub_efi_gcd_io_type_t gcd_io_type;
+ grub_efi_handle_t image_handle;
+ grub_efi_handle_t device_handle;
+};
+typedef struct grub_efi_gcd_io_space_descriptor
+ grub_efi_gcd_io_space_descriptor_t;
+
+struct grub_efi_dxe_services {
+ grub_efi_table_header_t hdr;
+
+ grub_efi_status_t
+ (*add_memory_space) (grub_efi_gcd_memory_type_t gcd_memory_type,
+ grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length,
+ grub_efi_uint64_t capabilities);
+
+ grub_efi_status_t
+ (*allocate_memory_space) (grub_efi_gcd_allocate_type_t gcd_allocate_type,
+ grub_efi_gcd_memory_type_t gcd_memory_type,
+ grub_efi_uintn_t alignment,
+ grub_efi_uint64_t length,
+ grub_efi_physical_address_t *base_address,
+ grub_efi_handle_t *image_handle,
+ grub_efi_handle_t *device_handle);
+
+ grub_efi_status_t
+ (*free_memory_space) (grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length);
+
+ grub_efi_status_t
+ (*remove_memory_space) (grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length);
+
+ grub_efi_status_t
+ (*get_memory_space_descriptor) (grub_efi_physical_address_t base_address,
+ grub_efi_gcd_memory_space_descriptor_t
*descriptor);
+
+ grub_efi_status_t
+ (*set_memory_space_attributes) (grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length,
+ grub_efi_uint64_t attributes);
+
+ grub_efi_status_t
+ (*get_memory_space_map) (grub_efi_uintn_t *number_of_descriptors,
+ grub_efi_gcd_memory_space_descriptor_t
**memory_space_map);
+
+ grub_efi_status_t
+ (*add_io_space) (grub_efi_gcd_io_type_t gcd_io_type,
+ grub_efi_physical_address_t base_address,
+ grub_efi_uintn_t length);
+
+ grub_efi_status_t
+ (*allocate_io_space) (grub_efi_gcd_allocate_type_t allocate_type,
+ grub_efi_gcd_io_type_t gcd_io_type,
+ grub_efi_uintn_t alignment,
+ grub_efi_uint64_t length,
+ grub_efi_physical_address_t *base_address,
+ grub_efi_handle_t image_handle,
+ grub_efi_handle_t device_handle);
+
+ grub_efi_status_t
+ (*free_io_space) (grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length);
+
+ grub_efi_status_t
+ (*remove_io_space) (grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length);
+
+ grub_efi_status_t
+ (*get_io_space_descriptor) (grub_efi_physical_address_t base_address,
+ grub_efi_gcd_io_space_descriptor_t *descriptor);
+
+ grub_efi_status_t
+ (*get_io_space_map) (grub_efi_uintn_t *number_of_descriptors,
+ grub_efi_gcd_io_space_descriptor_t **io_space_map);
+
+ grub_efi_status_t
+ (*dispatch) (void);
+
+ grub_efi_status_t
+ (*schedule) (grub_efi_handle_t firmware_volume_handle,
+ const grub_efi_guid_t *file_name);
+
+ grub_efi_status_t
+ (*trust) (grub_efi_handle_t firmware_volume_handle,
+ const grub_efi_guid_t *file_name);
+
+ grub_efi_status_t
+ (*process_firmware_volume)(const void *firmware_volume_header,
+ grub_efi_uintn_t size,
+ grub_efi_handle_t *firmware_volume_handle);
+
+ grub_efi_status_t
+ (*set_memory_space_capabilities) (grub_efi_physical_address_t base_address,
+ grub_efi_uint64_t length,
+ grub_efi_uint64_t capabilities);
+} GRUB_PACKED;
+typedef struct grub_efi_dxe_services grub_efi_dxe_services_t;
+
struct grub_efi_configuration_table
{
grub_efi_packed_guid_t vendor_guid;
@@ -1361,6 +1509,7 @@ typedef struct grub_efi_configuration_table
grub_efi_configuration_table_t;
#define GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE 0x5453595320494249LL
#define GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552LL
+#define GRUB_EFI_DXE_SERVICES_SIGNATURE 0x565245535f455844LL
struct grub_efi_serial_io_interface
{
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index eb2dfdfce..95f4ead0d 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -27,6 +27,9 @@
/* Functions. */
void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol,
void *registration);
+
+void *EXPORT_FUNC(grub_efi_get_config_table) (grub_efi_guid_t *guid);
+
grub_efi_handle_t *
EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type,
grub_efi_guid_t *protocol,
--
2.35.1