From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ncT35-0001Qt-BA for mharc-grub-devel@gnu.org; Thu, 07 Apr 2022 10:23:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncItn-0005ch-3K for grub-devel@gnu.org; Wed, 06 Apr 2022 23:33:31 -0400 Received: from mail.ispras.ru ([83.149.199.84]:38860) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncItk-0007RA-Nl for grub-devel@gnu.org; Wed, 06 Apr 2022 23:33:30 -0400 Received: from localhost.localdomain (unknown [80.240.223.29]) by mail.ispras.ru (Postfix) with ESMTPSA id 0F3404076B21; Thu, 7 Apr 2022 03:32:59 +0000 (UTC) From: Baskov Evgeniy To: grub-devel@gnu.org Cc: Baskov Evgeniy Subject: [PATCH RFC 1/3] efi: provide definitions of DXE services table Date: Thu, 7 Apr 2022 06:32:26 +0300 Message-Id: <20220407033228.30242-2-baskov@ispras.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407033228.30242-1-baskov@ispras.ru> References: <20220407033228.30242-1-baskov@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=83.149.199.84; envelope-from=baskov@ispras.ru; helo=mail.ispras.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 07 Apr 2022 10:23:45 -0400 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2022 03:33:31 -0000 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 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