From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smarthost01a.sbp.mail.zen.net.uk (smarthost01a.sbp.mail.zen.net.uk [212.23.1.1])
 by mx.groups.io with SMTP id smtpd.web11.27850.1647853821260766491
 for <devel@edk2.groups.io>;
 Mon, 21 Mar 2022 02:10:22 -0700
Authentication-Results: mx.groups.io;
 dkim=missing; spf=permerror, err=parse error for token &{10 18 sdn.klaviyomail.com}: permanent DNS error (domain: starlabs.systems, ip: 212.23.1.1, mailfrom: sean@starlabs.systems)
Received: from [51.148.147.4] (helo=sean-StarBook.lan)
	by smarthost01a.sbp.mail.zen.net.uk with esmtp (Exim 4.90_1)
	(envelope-from <sean@starlabs.systems>)
	id 1nWE3P-0007HO-Es; Mon, 21 Mar 2022 09:10:19 +0000
From: "Sean Rhodes" <sean@starlabs.systems>
To: devel@edk2.groups.io
Cc: Patrick Rudolph <patrick.rudolph@9elements.com>,
	Guo Dong <guo.dong@intel.com>,
	Ray Ni <ray.ni@intel.com>,
	Maurice Ma <maurice.ma@intel.com>,
	Benjamin You <benjamin.you@intel.com>,
	Sean Rhodes <sean@starlabs.systems>
Subject: [PATCH 3/5] UefiPayloadPkg: Add SmmStoreInfoGuid
Date: Mon, 21 Mar 2022 09:10:11 +0000
Message-Id: <bc757fd9aae96078ab48edb53acfc17a8ceced99.1647853813.git.sean@starlabs.systems>
X-Mailer: git-send-email 2.32.0
In-Reply-To: <cc0ee7344cac85aee468ebdcc65aa9fc95a431e5.1647853813.git.sean@starlabs.systems>
References: <cc0ee7344cac85aee468ebdcc65aa9fc95a431e5.1647853813.git.sean@starlabs.systems>
MIME-Version: 1.0
X-Originating-smarthost01a-IP: [51.148.147.4]
Feedback-ID: 51.148.147.4
Content-Transfer-Encoding: quoted-printable

From: Patrick Rudolph <patrick.rudolph@9elements.com>

Add a new InfoHob that contains the SmmStore information passed from
coreboot tables when the SMMSTOREV2 feature is enabled.

This will be used to implement the FVB in top of the MM installed by
coreboot.

Cc: Guo Dong <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
 .../Include/Guid/SmmStoreInfoGuid.h           | 27 ++++++++++++
 .../Include/Library/SmmStoreParseLib.h        | 29 +++++++++++++
 .../Library/CbParseLib/CbParseLib.c           | 43 +++++++++++++++++++
 .../Library/SblParseLib/SblParseLib.c         | 18 ++++++++
 .../UefiPayloadEntry/UefiPayloadEntry.c       | 13 ++++++
 .../UefiPayloadEntry/UefiPayloadEntry.h       |  2 +
 .../UefiPayloadEntry/UefiPayloadEntry.inf     |  1 +
 UefiPayloadPkg/UefiPayloadPkg.dec             |  2 +
 8 files changed, 135 insertions(+)
 create mode 100644 UefiPayloadPkg/Include/Guid/SmmStoreInfoGuid.h
 create mode 100644 UefiPayloadPkg/Include/Library/SmmStoreParseLib.h

diff --git a/UefiPayloadPkg/Include/Guid/SmmStoreInfoGuid.h b/UefiPayloadPk=
g/Include/Guid/SmmStoreInfoGuid.h
new file mode 100644
index 0000000000..d5dcb8218f
--- /dev/null
+++ b/UefiPayloadPkg/Include/Guid/SmmStoreInfoGuid.h
@@ -0,0 +1,27 @@
+/** @file=0D
+  This file defines the hob structure for coreboot's SmmStore.=0D
+=0D
+  Copyright (c) 2022, 9elements GmbH<BR>=0D
+  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#ifndef SMMSTORE_GUID_H_=0D
+#define SMMSTORE_GUID_H_=0D
+=0D
+///=0D
+/// System Table Information GUID=0D
+///=0D
+extern EFI_GUID  gEfiSmmStoreInfoHobGuid;=0D
+=0D
+typedef struct {=0D
+  UINT64    ComBuffer;=0D
+  UINT32    ComBufferSize;=0D
+  UINT32    NumBlocks;=0D
+  UINT32    BlockSize;=0D
+  UINT64    MmioAddress;=0D
+  UINT8     ApmCmd;=0D
+  UINT8     Reserved0[3];=0D
+} SMMSTORE_INFO;=0D
+=0D
+#endif // SMMSTORE_GUID_H_=0D
diff --git a/UefiPayloadPkg/Include/Library/SmmStoreParseLib.h b/UefiPayloa=
dPkg/Include/Library/SmmStoreParseLib.h
new file mode 100644
index 0000000000..0b5b8f8aba
--- /dev/null
+++ b/UefiPayloadPkg/Include/Library/SmmStoreParseLib.h
@@ -0,0 +1,29 @@
+/** @file=0D
+  This library will parse the coreboot table in memory and extract those r=
equired=0D
+  information.=0D
+=0D
+  Copyright (c) 2021, Star Labs Systems. All rights reserved.<BR>=0D
+  SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#ifndef SMM_STORE_PARSE_LIB_H_=0D
+#define SMM_STORE_PARSE_LIB_H_=0D
+=0D
+#include <Guid/SmmStoreInfoGuid.h>=0D
+=0D
+/**=0D
+  Find the SmmStore HOB.=0D
+=0D
+  @param  SmmStoreInfo       Pointer to the SMMSTORE_INFO structure=0D
+=0D
+  @retval RETURN_SUCCESS     Successfully find the Smm store buffer inform=
ation.=0D
+  @retval RETURN_NOT_FOUND   Failed to find the Smm store buffer informati=
on .=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+ParseSmmStoreInfo (=0D
+  OUT SMMSTORE_INFO  *SmmStoreInfo=0D
+  );=0D
+=0D
+#endif // SMM_STORE_PARSE_LIB_H_=0D
diff --git a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c b/UefiPayloadPk=
g/Library/CbParseLib/CbParseLib.c
index 8a353f77f6..5c7efec3ec 100644
--- a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
+++ b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
@@ -14,6 +14,7 @@
 #include <Library/PcdLib.h>=0D
 #include <Library/IoLib.h>=0D
 #include <Library/BlParseLib.h>=0D
+#include <Library/SmmStoreParseLib.h>=0D
 #include <IndustryStandard/Acpi.h>=0D
 #include <Coreboot.h>=0D
 =0D
@@ -604,3 +605,45 @@ ParseMiscInfo (
 {=0D
   return RETURN_SUCCESS;=0D
 }=0D
+=0D
+/**=0D
+  Find the SmmStore HOB.=0D
+=0D
+  @param  SmmStoreInfo       Pointer to the SMMSTORE_INFO structure=0D
+=0D
+  @retval RETURN_SUCCESS     Successfully find the Smm store buffer inform=
ation.=0D
+  @retval RETURN_NOT_FOUND   Failed to find the Smm store buffer informati=
on .=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+ParseSmmStoreInfo (=0D
+  OUT SMMSTORE_INFO  *SmmStoreInfo=0D
+  )=0D
+{=0D
+  struct cb_smmstorev2  *CbSSRec;=0D
+=0D
+  if (SmmStoreInfo =3D=3D NULL) {=0D
+    return RETURN_INVALID_PARAMETER;=0D
+  }=0D
+=0D
+  CbSSRec =3D FindCbTag (CB_TAG_SMMSTOREV2);=0D
+  if (CbSSRec =3D=3D NULL) {=0D
+    return RETURN_NOT_FOUND;=0D
+  }=0D
+=0D
+  DEBUG ((DEBUG_INFO, "Found Smm Store information\n"));=0D
+  DEBUG ((DEBUG_INFO, "block size: 0x%x\n", CbSSRec->block_size));=0D
+  DEBUG ((DEBUG_INFO, "number of blocks: 0x%x\n", CbSSRec->num_blocks));=0D
+  DEBUG ((DEBUG_INFO, "communication buffer: 0x%x\n", CbSSRec->com_buffer)=
);=0D
+  DEBUG ((DEBUG_INFO, "communication buffer size: 0x%x\n", CbSSRec->com_bu=
ffer_size));=0D
+  DEBUG ((DEBUG_INFO, "MMIO address of store: 0x%x\n", CbSSRec->mmap_addr)=
);=0D
+=0D
+  SmmStoreInfo->ComBuffer     =3D CbSSRec->com_buffer;=0D
+  SmmStoreInfo->ComBufferSize =3D CbSSRec->com_buffer_size;=0D
+  SmmStoreInfo->BlockSize     =3D CbSSRec->block_size;=0D
+  SmmStoreInfo->NumBlocks     =3D CbSSRec->num_blocks;=0D
+  SmmStoreInfo->MmioAddress   =3D CbSSRec->mmap_addr;=0D
+  SmmStoreInfo->ApmCmd        =3D CbSSRec->apm_cmd;=0D
+=0D
+  return RETURN_SUCCESS;=0D
+}=0D
diff --git a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c b/UefiPayload=
Pkg/Library/SblParseLib/SblParseLib.c
index d88238bfdc..6875fa9934 100644
--- a/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
+++ b/UefiPayloadPkg/Library/SblParseLib/SblParseLib.c
@@ -14,6 +14,7 @@
 #include <Library/IoLib.h>=0D
 #include <Library/HobLib.h>=0D
 #include <Library/BlParseLib.h>=0D
+#include <Library/SmmStoreParseLib.h>=0D
 #include <IndustryStandard/Acpi.h>=0D
 #include <UniversalPayload/PciRootBridges.h>=0D
 =0D
@@ -289,3 +290,20 @@ ParseMiscInfo (
 =0D
   return Status;=0D
 }=0D
+=0D
+/**=0D
+  Find the SmmStore HOB.=0D
+=0D
+  @param  SmmStoreInfo       Pointer to the SMMSTORE_INFO structure=0D
+=0D
+  @retval RETURN_SUCCESS     Successfully find the Smm store buffer inform=
ation.=0D
+  @retval RETURN_NOT_FOUND   Failed to find the Smm store buffer informati=
on .=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+ParseSmmStoreInfo (=0D
+  OUT SMMSTORE_INFO  *SmmStoreInfo=0D
+  )=0D
+{=0D
+  return RETURN_NOT_FOUND;=0D
+}=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPaylo=
adPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 780348eadf..7f37283515 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -259,6 +259,8 @@ BuildHobFromBl (
 {=0D
   EFI_STATUS                        Status;=0D
   ACPI_BOARD_INFO                   *AcpiBoardInfo;=0D
+  SMMSTORE_INFO                     SmmStoreInfo;=0D
+  SMMSTORE_INFO                     *NewSmmStoreInfo;=0D
   EFI_PEI_GRAPHICS_INFO_HOB         GfxInfo;=0D
   EFI_PEI_GRAPHICS_INFO_HOB         *NewGfxInfo;=0D
   EFI_PEI_GRAPHICS_DEVICE_INFO_HOB  GfxDeviceInfo;=0D
@@ -305,6 +307,17 @@ BuildHobFromBl (
     DEBUG ((DEBUG_INFO, "Created graphics device info hob\n"));=0D
   }=0D
 =0D
+  //=0D
+  // Create guid hob for SmmStore=0D
+  //=0D
+  Status =3D ParseSmmStoreInfo (&SmmStoreInfo);=0D
+  if (!EFI_ERROR (Status)) {=0D
+    NewSmmStoreInfo =3D BuildGuidHob (&gEfiSmmStoreInfoHobGuid, sizeof (Sm=
mStoreInfo));=0D
+    ASSERT (NewSmmStoreInfo !=3D NULL);=0D
+    CopyMem (NewSmmStoreInfo, &SmmStoreInfo, sizeof (SmmStoreInfo));=0D
+    DEBUG ((DEBUG_INFO, "Created SmmStore info hob\n"));=0D
+  }=0D
+=0D
   //=0D
   // Creat SmBios table Hob=0D
   //=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo=
adPkg/UefiPayloadEntry/UefiPayloadEntry.h
index 56e0a4c639..037ebbda36 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -22,6 +22,7 @@
 #include <Library/IoLib.h>=0D
 #include <Library/PeCoffLib.h>=0D
 #include <Library/BlParseLib.h>=0D
+#include <Library/SmmStoreParseLib.h>=0D
 #include <Library/PlatformSupportLib.h>=0D
 #include <Library/UefiCpuLib.h>=0D
 #include <IndustryStandard/Acpi.h>=0D
@@ -36,6 +37,7 @@
 #include <UniversalPayload/ExtraData.h>=0D
 #include <UniversalPayload/SerialPortInfo.h>=0D
 #include <Guid/PcdDataBaseSignatureGuid.h>=0D
+#include <Guid/SmmStoreInfoGuid.h>=0D
 =0D
 #define LEGACY_8259_MASK_REGISTER_MASTER  0x21=0D
 #define LEGACY_8259_MASK_REGISTER_SLAVE   0xA1=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPay=
loadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index c4e4339ede..6dcd6d956d 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -65,6 +65,7 @@
   gUniversalPayloadSmbiosTableGuid=0D
   gUniversalPayloadAcpiTableGuid=0D
   gUniversalPayloadSerialPortInfoGuid=0D
+  gEfiSmmStoreInfoHobGuid=0D
 =0D
 [FeaturePcd.IA32]=0D
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode      ## CONSUME=
S=0D
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload=
Pkg.dec
index 4051172caf..fcf62dd8c8 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -42,6 +42,8 @@
   gSmmRegisterInfoGuid     =3D { 0xaa9bd7a7, 0xcafb, 0x4499, { 0xa4, 0xa9,=
 0xb, 0x34, 0x6b, 0x40, 0xa6, 0x22 } }=0D
   gS3CommunicationGuid     =3D { 0x88e31ba1, 0x1856, 0x4b8b, { 0xbb, 0xdf,=
 0xf8, 0x16, 0xdd, 0x94, 0xa, 0xef } }=0D
 =0D
+  gEfiSmmStoreInfoHobGuid  =3D { 0xf585ca19, 0x881b, 0x44fb, { 0x3f, 0x3d,=
 0x81, 0x89, 0x7c, 0x57, 0xbb, 0x01 } }=0D
+=0D
 [Ppis]=0D
   gEfiPayLoadHobBasePpiGuid =3D { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6,=
 0xb2, 0x26, 0xf1, 0x61, 0x73, 0x89} }=0D
 =0D
--=20
2.32.0