All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baskov Evgeniy <baskov@ispras.ru>
To: grub-devel@gnu.org
Cc: Baskov Evgeniy <baskov@ispras.ru>
Subject: [PATCH RFC 1/3] efi: provide definitions of DXE services table
Date: Thu,  7 Apr 2022 06:32:26 +0300	[thread overview]
Message-ID: <20220407033228.30242-2-baskov@ispras.ru> (raw)
In-Reply-To: <20220407033228.30242-1-baskov@ispras.ru>

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



  reply	other threads:[~2022-04-07 14:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07  3:32 [PATCH RFC 0/3] EFI memory attributes Baskov Evgeniy
2022-04-07  3:32 ` Baskov Evgeniy [this message]
2022-04-11  7:12   ` [PATCH RFC 1/3] efi: provide definitions of DXE services table Paul Menzel
2022-04-14 15:15     ` baskov
2022-04-07  3:32 ` [PATCH RFC 2/3] relocator: allocate trampoline in lower 640k Baskov Evgeniy
2022-04-07  3:32 ` [PATCH RFC 3/3] efi: explicitly set memory attributes for memory Baskov Evgeniy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220407033228.30242-2-baskov@ispras.ru \
    --to=baskov@ispras.ru \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.