public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Joursoir" <chat@joursoir.net>
To: devel@edk2.groups.io
Cc: ray.ni@intel.com, guo.dong@intel.com, benjamin.you@intel.com,
	maurice.ma@intel.com, sean@starlabs.systems, james.lu@intel.com,
	gua.guo@intel.com
Subject: [edk2-devel] [PATCH 1/1] UefiPayloadPkg: Add SMM variable related HOBs support for SBL
Date: Fri, 10 Nov 2023 21:06:48 +0300	[thread overview]
Message-ID: <20231110210648.3ae8c424@reeva> (raw)

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]
-=-=-=-=-=-=-=-=-=-=-=-



             reply	other threads:[~2023-11-10 18:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 18:06 Joursoir [this message]
     [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

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=20231110210648.3ae8c424@reeva \
    --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