public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH 1/1] UefiPayloadPkg: Add SMM variable related HOBs support for SBL
@ 2023-11-10 18:06 Joursoir
  0 siblings, 0 replies; 2+ messages in thread
From: Joursoir @ 2023-11-10 18:06 UTC (permalink / raw)
  To: devel; +Cc: ray.ni, guo.dong, benjamin.you, maurice.ma, sean, james.lu,
	gua.guo

When UefiPayloadPkg is compiled with SMM_SUPPORT enabled and
VARIABLE_SUPPORT set to SPI, the following HOBs must be
available:

* gSmmRegisterInfoGuid
* gEfiSmmSmramMemoryGuid
* gSpiFlashInfoGuid
* gNvVariableInfoGuid
* gS3CommunicationGuid

Migrate these HOBs information from the bootloader HOB space to the
UEFI payload HOB space. Parse them in misc function, so it won't fail
if there would be no HOBs.

This patch was tested on Slim Bootloader with latest UEFI payload, and
it worked as expected.

Signed-off-by: Alexander Goncharov <chat@joursoir.net>
---
 .../Library/SblParseLib/SblParseLib.c         | 109 ++++++++++++++++--
 .../Library/SblParseLib/SblParseLib.inf       |   5 +
 2 files changed, 107 insertions(+), 7 deletions(-)

diff --git a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
index d88238bfdc..a4cf90618b 100644
--- a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
+++ b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
@@ -16,6 +16,11 @@
 #include <Library/BlParseLib.h>
 #include <IndustryStandard/Acpi.h>
 #include <UniversalPayload/PciRootBridges.h>
+#include <Guid/SmmRegisterInfoGuid.h>
+#include <Guid/SmramMemoryReserve.h>
+#include <Guid/SpiFlashInfoGuid.h>
+#include <Guid/NvVariableInfoGuid.h>
+#include <Guid/SmmS3CommunicationInfoGuid.h>
 
 /**
   This function retrieves the parameter base address from boot loader.
@@ -264,6 +269,17 @@ ParseMiscInfo (
   RETURN_STATUS                       Status;
   UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES  *BlRootBridgesHob;
   UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES  *PldRootBridgesHob;
+  PLD_SMM_REGISTERS                   *BlSmmRegisterHob;
+  PLD_SMM_REGISTERS                   *PldSmmRegisterHob;
+  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK      *BlSmmMemoryHob;
+  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK      *PldSmmMemoryHob;
+  SPI_FLASH_INFO                      *BlSpiFlashInfoHob;
+  SPI_FLASH_INFO                      *PldSpiFlashInfoHob;
+  NV_VARIABLE_INFO                    *BlNvVariableHob;
+  NV_VARIABLE_INFO                    *PldNvVariableHob;
+  PLD_S3_COMMUNICATION                *BlS3CommunicationHob;
+  PLD_S3_COMMUNICATION                *PldS3CommunicationHob;
+  UINT32                              Length;
 
   Status           = RETURN_NOT_FOUND;
   BlRootBridgesHob = (UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGES *)GetGuidHobDataFromSbl (
@@ -278,13 +294,92 @@ ParseMiscInfo (
                           BlRootBridgesHob->Header.Length
                           );
     ASSERT (PldRootBridgesHob != NULL);
-    if (PldRootBridgesHob != NULL) {
-      CopyMem (PldRootBridgesHob, BlRootBridgesHob, BlRootBridgesHob->Header.Length);
-      DEBUG ((DEBUG_INFO, "Create PCI root bridge info guid hob\n"));
-      Status = RETURN_SUCCESS;
-    } else {
-      Status = RETURN_OUT_OF_RESOURCES;
-    }
+    if (PldRootBridgesHob == NULL)
+      return RETURN_OUT_OF_RESOURCES;
+
+    CopyMem (PldRootBridgesHob, BlRootBridgesHob, BlRootBridgesHob->Header.Length);
+    DEBUG ((DEBUG_INFO, "Create PCI root bridge info guid hob\n"));
+    Status = RETURN_SUCCESS;
+  }
+
+  //
+  // Create SMM info hob.
+  //
+  BlSmmRegisterHob = (PLD_SMM_REGISTERS *)GetGuidHobDataFromSbl (&gSmmRegisterInfoGuid);
+  if (BlSmmRegisterHob != NULL) {
+    Length = sizeof (PLD_SMM_REGISTERS) + 5 * sizeof (PLD_GENERIC_REGISTER);
+    PldSmmRegisterHob = BuildGuidHob (&gSmmRegisterInfoGuid, Length);
+    ASSERT (PldSmmRegisterHob != NULL);
+    if (PldSmmRegisterHob == NULL)
+      return RETURN_OUT_OF_RESOURCES;
+
+    CopyMem (PldSmmRegisterHob, BlSmmRegisterHob, Length);
+    DEBUG ((DEBUG_INFO, "Created SMM info hob\n"));
+    Status = RETURN_SUCCESS;
+  }
+
+  //
+  // Create SMM memory hob.
+  //
+  BlSmmMemoryHob = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)GetGuidHobDataFromSbl (&gEfiSmmSmramMemoryGuid);
+  if (BlSmmMemoryHob != NULL) {
+    Length = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + sizeof (EFI_SMRAM_DESCRIPTOR);
+    PldSmmMemoryHob = BuildGuidHob (&gEfiSmmSmramMemoryGuid, Length);
+    ASSERT (PldSmmMemoryHob != NULL);
+    if (PldSmmMemoryHob == NULL)
+      return RETURN_OUT_OF_RESOURCES;
+
+    CopyMem (PldSmmMemoryHob, BlSmmMemoryHob, Length);
+    DEBUG ((DEBUG_INFO, "Created SMM memory hob\n"));
+    Status = RETURN_SUCCESS;
+  }
+
+  //
+  // Create SPI flash info hob.
+  //
+  BlSpiFlashInfoHob = (SPI_FLASH_INFO *)GetGuidHobDataFromSbl (&gSpiFlashInfoGuid);
+  if (BlSpiFlashInfoHob != NULL) {
+    Length = sizeof (SPI_FLASH_INFO);
+    PldSpiFlashInfoHob = BuildGuidHob (&gSpiFlashInfoGuid, Length);
+    ASSERT (PldSpiFlashInfoHob != NULL);
+    if (PldSpiFlashInfoHob == NULL)
+      return RETURN_OUT_OF_RESOURCES;
+
+    CopyMem (PldSpiFlashInfoHob, BlSpiFlashInfoHob, Length);
+    DEBUG ((DEBUG_INFO, "Created SPI flash info hob\n"));
+    Status = RETURN_SUCCESS;
+  }
+
+  //
+  // Create SPI flash variable info hob.
+  //
+  BlNvVariableHob = (NV_VARIABLE_INFO *)GetGuidHobDataFromSbl (&gNvVariableInfoGuid);
+  if (BlNvVariableHob != NULL) {
+    Length = sizeof (NV_VARIABLE_INFO);
+    PldNvVariableHob = BuildGuidHob (&gNvVariableInfoGuid, Length);
+    ASSERT (PldNvVariableHob != NULL);
+    if (PldNvVariableHob == NULL)
+      return RETURN_OUT_OF_RESOURCES;
+
+    CopyMem (PldNvVariableHob, BlNvVariableHob, Length);
+    DEBUG ((DEBUG_INFO, "Created SPI flash variable info hob\n"));
+    Status = RETURN_SUCCESS;
+  }
+
+  //
+  // Create SMM S3 communication hob.
+  //
+  BlS3CommunicationHob = (PLD_S3_COMMUNICATION *)GetGuidHobDataFromSbl (&gS3CommunicationGuid);
+  if (BlS3CommunicationHob != NULL) {
+    Length = sizeof (PLD_S3_COMMUNICATION);
+    PldS3CommunicationHob = BuildGuidHob (&gS3CommunicationGuid, Length);
+    ASSERT (PldS3CommunicationHob != NULL);
+    if (PldS3CommunicationHob == NULL)
+      return RETURN_OUT_OF_RESOURCES;
+
+    CopyMem (PldS3CommunicationHob, BlS3CommunicationHob, Length);
+    DEBUG ((DEBUG_INFO, "Created SMM S3 communication hob\n"));
+    Status = RETURN_SUCCESS;
   }
 
   return Status;
diff --git a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
index f83a10ccd8..1c77d86a86 100644
--- a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
+++ b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
@@ -41,6 +41,11 @@
   gEfiGraphicsInfoHobGuid
   gEfiGraphicsDeviceInfoHobGuid
   gUniversalPayloadPciRootBridgeInfoGuid
+  gSmmRegisterInfoGuid
+  gEfiSmmSmramMemoryGuid
+  gSpiFlashInfoGuid
+  gNvVariableInfoGuid
+  gS3CommunicationGuid
 
 [Pcd]
   gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter
-- 
2.42.1



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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-14 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1796553B09588C08.3202@groups.io>
2023-12-14 15:48 ` [edk2-devel] [PATCH 1/1] UefiPayloadPkg: Add SMM variable related HOBs support for SBL Joursoir
2023-11-10 18:06 Joursoir

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox