public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Joursoir" <chat@joursoir.net>
To: devel@edk2.groups.io
Cc: ardb@kernel.org, michael.d.kinney@intel.com,
	gaoliming@byosoft.com.cn, zhiguang.liu@intel.com,
	Alexander Goncharov <chat@joursoir.net>
Subject: [edk2-devel] [PATCH 1/2] MdeModulePkg: Introduce and use PcdMemoryAttributesTableVersion
Date: Tue,  6 Feb 2024 16:25:51 +0300	[thread overview]
Message-ID: <20240206132552.245545-2-chat@joursoir.net> (raw)
In-Reply-To: <20240206132552.245545-1-chat@joursoir.net>

Linux kernel supports the memory attributes table v2 since version 6.2.
However, UEFI can be used with older kernel versions that are still
maintainable. So instead of relying on a macro that defines the memory
attributes table, a corresponding PCD is introduced to decide which
version of the table UEFI should create.

Signed-off-by: Alexander Goncharov <chat@joursoir.net>
---
 MdeModulePkg/Core/Dxe/DxeMain.inf                  | 1 +
 MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 4 ++--
 MdeModulePkg/MdeModulePkg.dec                      | 4 ++++
 MdeModulePkg/MdeModulePkg.uni                      | 4 ++++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf
index 090970aec6..a59cd117c5 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain.inf
+++ b/MdeModulePkg/Core/Dxe/DxeMain.inf
@@ -177,6 +177,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber     ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable            ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxEfiSystemTablePointerAddress         ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryAttributesTableVersion            ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileMemoryType                 ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask               ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfileDriverPath                 ## CONSUMES
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
index e9343a2c4e..4df7b140f6 100644
--- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
+++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
@@ -181,10 +181,10 @@ InstallMemoryAttributesTable (
   //
   MemoryAttributesTable = AllocatePool (sizeof (EFI_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount);
   ASSERT (MemoryAttributesTable != NULL);
-  MemoryAttributesTable->Version         = EFI_MEMORY_ATTRIBUTES_TABLE_VERSION;
+  MemoryAttributesTable->Version         = PcdGet32 (PcdMemoryAttributesTableVersion);
   MemoryAttributesTable->NumberOfEntries = RuntimeEntryCount;
   MemoryAttributesTable->DescriptorSize  = (UINT32)DescriptorSize;
-  if (gMemoryAttributesTableForwardCfi) {
+  if (MemoryAttributesTable->Version > 0x01 && gMemoryAttributesTableForwardCfi) {
     MemoryAttributesTable->Flags = EFI_MEMORY_ATTRIBUTES_FLAGS_RT_FORWARD_CONTROL_FLOW_GUARD;
   } else {
     MemoryAttributesTable->Flags = 0;
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index a2cd83345f..3ef8e6d3e5 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1523,6 +1523,10 @@
   # @Prompt Exposed ACPI table versions.
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x3E|UINT32|0x0001004c
 
+  ## Indicates which Memory Attributes Table version exposed to the OS.
+  # @Prompt Exposed Memory Attributes Table version.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryAttributesTableVersion|0x00000002|UINT32|0x12f85350
+
   ## This PCD defines the MAX repair count.
   #  The default value is 0 that means infinite.
   # @Prompt MAX repair count
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index a17d34d60b..b1b8d5f976 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -955,6 +955,10 @@
                                                                                              "BIT 4 - EFI_ACPI_TABLE_VERSION_4_0.<BR>\n"
                                                                                              "BIT 5 - EFI_ACPI_TABLE_VERSION_5_0.<BR>"
 
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMemoryAttributesTableVersion_PROMPT  #language en-US "Exposed Memory Attributes Table version."
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMemoryAttributesTableVersion_HELP  #language en-US "Indicates which Memory Attributes Table version exposed to the OS."
+
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHiiOsRuntimeSupport_PROMPT  #language en-US "Enable export HII data and configuration to be used in OS runtime."
 
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHiiOsRuntimeSupport_HELP  #language en-US "Indicates if HII data and configuration has been exported.<BR><BR>\n"
-- 
2.43.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115160): https://edk2.groups.io/g/devel/message/115160
Mute This Topic: https://groups.io/mt/104197278/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-02-06 13:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 13:25 [edk2-devel] [PATCH 0/2] Introduce and use PCD for Memory Attributes Table Joursoir
2024-02-06 13:25 ` Joursoir [this message]
2024-02-06 13:25 ` [edk2-devel] [PATCH 2/2] MdePkg: Drop unused EFI_MEMORY_ATTRIBUTES_TABLE_VERSION macro Joursoir

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-list 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=20240206132552.245545-2-chat@joursoir.net \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox