* [PATCH 0/3] ArmPlatformPkg: Introduce dynamic generation of HEST table
@ 2020-10-30 8:36 omkar.kulkarni
2020-10-30 8:36 ` [PATCH 1/3] ArmPlatformPkg: Allow dynamic generation of HEST ACPI table Omkar Anand Kulkarni
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: omkar.kulkarni @ 2020-10-30 8:36 UTC (permalink / raw)
To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Sami Mujawar, Jiewen Yao
This patch series adds support for dynamic creation of the HEST ACPI
table with the error source descritors reterived from various other
error handling drivers, including those implemented in StandaloneMM.
The first patch adds a HEST table generation driver and introduces HEST
table protocol. The driver enables dynamic creation of HEST ACPI table.
The driver implements HEST table protocol serives to append error source
descriptors to the table and install the fully populated HEST table.
This enables other drivers to append and publish error source descriptor
information to HEST table. The append protocol service when called for
the first time creates HEST table and populates it with HEST header
information. So on subsequent calls made to append service only error
source descriptor information be appended at the end of HEST table.
After all the hardware error source descriptors are added to the HEST
table, install protocol service is used to publish the HEST table to
OSPM.
The second patch introduces a protocol definition to Get HEST error
source descriptors from StandaloneMM. The protocol should be implemented
by MM drivers that publish it's error sources as error source
descriptors via HEST ACPI table.
The third patch is combination of Hest Error Source DXE and its
Standalone MM counterpart. These are responsible to collect all RAS
error sources that are implemented as MM drivers. DXE driver
communicates with Standalone MM driver using MM Communicate 2 protocol.
First call into the Standalone MM is returned with the size of MM
Communicate buffer required to hold all error source descriptor
information. The DXE driver then allocates MM Communicate buffer buffer
required to hold Error Source descriptor information like count of error
source descriptors, total length of error source descriptors and
the descriptor information itself and calls agian into Standalone MM.
The MM counterpart of this driver is implemented as a gateway driver
and DXE driver communicates only with it to get information on the error
source descriptors supported by drivers in MM. Standalone MM driver
locates all handles implementing Get Error Source Descriptor protocol.
Loops over the handles and calls into respective MM driver.
Omkar Anand Kulkarni (3):
ArmPlatformPkg: Allow dynamic generation of HEST ACPI table
ArmPlatformPkg: add definition for MM_HEST_ERROR_SOURCE_DESC_PROTOCOL
ArmPlatformPkg: retreive error source descriptors from MM
ArmPlatformPkg/ArmPlatformPkg.dec | 12 +
.../Drivers/Apei/HestDxe/HestDxe.inf | 45 +++
.../HestMmErrorSources/HestErrorSourceDxe.inf | 41 +++
.../HestErrorSourceStandaloneMm.inf | 51 +++
.../HestMmErrorSourceCommon.h | 33 ++
.../Include/Protocol/HestErrorSourceInfo.h | 64 ++++
ArmPlatformPkg/Include/Protocol/HestTable.h | 66 ++++
ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.c | 320 ++++++++++++++++++
.../HestMmErrorSources/HestErrorSourceDxe.c | 257 ++++++++++++++
.../HestErrorSourceStandaloneMm.c | 282 +++++++++++++++
10 files changed, 1171 insertions(+)
create mode 100644 ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.inf
create mode 100644 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf
create mode 100644 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf
create mode 100644 ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h
create mode 100644 ArmPlatformPkg/Include/Protocol/HestErrorSourceInfo.h
create mode 100644 ArmPlatformPkg/Include/Protocol/HestTable.h
create mode 100644 ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.c
create mode 100644 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c
create mode 100644 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] ArmPlatformPkg: Allow dynamic generation of HEST ACPI table
2020-10-30 8:36 [PATCH 0/3] ArmPlatformPkg: Introduce dynamic generation of HEST table omkar.kulkarni
@ 2020-10-30 8:36 ` Omkar Anand Kulkarni
2020-10-30 8:36 ` [PATCH 2/3] ArmPlatformPkg: add definition for MM_HEST_ERROR_SOURCE_DESC_PROTOCOL Omkar Anand Kulkarni
2020-10-30 8:36 ` [PATCH 3/3] ArmPlatformPkg: retreive error source descriptors from MM Omkar Anand Kulkarni
2 siblings, 0 replies; 4+ messages in thread
From: Omkar Anand Kulkarni @ 2020-10-30 8:36 UTC (permalink / raw)
To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Sami Mujawar, Jiewen Yao
Introduce the HEST table generation protocol that allows platforms to
build the table with multiple error source descriptors and install the
table. The protocols provides two interfaces. The first interface allows
for adding multiple error source descriptors into the HEST table. The
second interface can then be used to dynamically installed the fully
populated HEST table. This allows multiple drivers and/or libraries to
dynamically register error source descriptors into the HEST table.
Co-authored-by: Thomas Abraham <thomas.abraham@arm.com>
Signed-off-by: Omkar Anand Kulkarni <omkar.kulkarni@arm.com>
---
ArmPlatformPkg/ArmPlatformPkg.dec | 4 +
ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.inf | 45 +++
ArmPlatformPkg/Include/Protocol/HestTable.h | 66 ++++
ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.c | 320 ++++++++++++++++++++
4 files changed, 435 insertions(+)
diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatformPkg.dec
index 696d636aacee..23c5b768f677 100644
--- a/ArmPlatformPkg/ArmPlatformPkg.dec
+++ b/ArmPlatformPkg/ArmPlatformPkg.dec
@@ -110,3 +110,7 @@
gArmPlatformTokenSpaceGuid.PcdPL031RtcPpmAccuracy|300000000|UINT32|0x00000022
gArmPlatformTokenSpaceGuid.PcdWatchdogCount|0x0|UINT32|0x00000033
+
+[Protocols.common]
+ ## Arm Platform HEST table generation protocol
+ gHestTableProtocolGuid = { 0x705bdcd9, 0x8c47, 0x457e, { 0xad, 0x0d, 0xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } }
diff --git a/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.inf b/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.inf
new file mode 100644
index 000000000000..670f53476800
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.inf
@@ -0,0 +1,45 @@
+## @file
+# DXE driver that creates and publishes the HEST ACPI table.
+#
+# Copyright (c) 2018-2020, ARM Limited. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = HestDxe
+ FILE_GUID = 933099a2-ef71-4e00-82aa-a79b1e0a3b38
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = HestInitialize
+
+[Sources.Common]
+ HestDxe.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Platform/ARM/SgiPkg/SgiPlatform.dec
+
+[LibraryClasses]
+ ArmLib
+ BaseMemoryLib
+ DebugLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[Protocols]
+ gEfiAcpiTableProtocolGuid ## PROTOCOL ALWAYS_CONSUMED
+ gHestTableProtocolGuid ## PRODUCES
+
+[FixedPcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision
+
+[Depex]
+ gEfiAcpiSdtProtocolGuid
diff --git a/ArmPlatformPkg/Include/Protocol/HestTable.h b/ArmPlatformPkg/Include/Protocol/HestTable.h
new file mode 100644
index 000000000000..3905aab044dc
--- /dev/null
+++ b/ArmPlatformPkg/Include/Protocol/HestTable.h
@@ -0,0 +1,66 @@
+/** @file
+ Provides protocol to create and install the HEST ACPI for the
+ platform.
+
+ Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef HEST_TABLE_H_
+#define HEST_TABLE_H_
+
+#define HEST_TABLE_PROTOCOL_GUID \
+ { \
+ 0x705bdcd9, 0x8c47, 0x457e, \
+ { 0xad, 0x0d, 0xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } \
+ }
+
+/**
+ Append a list of error source descriptors to the HEST table.
+
+ Allows error source list producer module to append its error source descriptors
+ into the HEST ACPI table being prepared for installation.
+
+ @param[in] ErrorSourceDescriptorList List of Error Source Descriptors.
+ @param[in] ErrorSourceDescriptorListSize Total Size of the ErrorSourceDescriptorList.
+ @param[in] ErrorSourceDescriptorCount Total count of error source descriptors in
+ ErrorSourceDescriptorList.
+
+ @retval EFI_SUCCESS Appending the error source descriptors
+ successful.
+ @retval EFI_OUT_OF_RESOURCES Buffer reallocation failed for the HEST
+ table.
+ @retval EFI_INVALID_PARAMETER Null ErrorSourceDescriptorList param or
+ ErrorSourceDescriptorListSize is 0.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *APPEND_ERROR_SOURCE_DESCRIPTOR) (
+ IN CONST VOID *ErrorSourceDescriptorList,
+ IN UINTN ErrorSourceDescriptorListSize,
+ IN UINTN ErrorSourceDescriptorCount
+ );
+
+/**
+ Install ACPI HEST table.
+
+ @retval EFI_SUCCESS On ACPI HEST table installation success.
+ @retval Other On ACPI HEST table installation failure.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *INSTALL_HEST_TABLE) (VOID);
+
+//
+// HEST_TABLE_PROTOCOL enables creation and installation of HEST table
+//
+typedef struct {
+ APPEND_ERROR_SOURCE_DESCRIPTOR AppendErrorSourceDescriptors;
+ INSTALL_HEST_TABLE InstallHestTable;
+} HEST_TABLE_PROTOCOL;
+
+extern EFI_GUID gHestTableProtocolGuid;
+#endif // HEST_TABLE_H_
diff --git a/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.c b/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.c
new file mode 100644
index 000000000000..35de14aaf05c
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.c
@@ -0,0 +1,320 @@
+/** @file
+ Builds and installs the HEST ACPI table.
+
+ This driver installs a protocol that can be used to create and install a HEST
+ ACPI table. The protocol allows one or more error source producers to add the
+ error source descriptors into the HEST table. It also allows the resulting HEST
+ ACPI table to be installed.
+
+ Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/Acpi.h>
+
+#include <Library/ArmLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/AcpiSystemDescriptionTable.h>
+#include <Protocol/AcpiTable.h>
+#include <Protocol/HestTable.h>
+
+typedef struct {
+ VOID *HestTable; /// Pointer to HEST ACPI table.
+ UINT32 CurrentTableSize; /// Current size of HEST ACPI table.
+} HEST_DXE_DRIVER_DATA;
+
+STATIC EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;
+STATIC HEST_DXE_DRIVER_DATA mHestDriverData;
+
+/**
+ Helper function to reallocate memory pool for every new error source descriptor
+ added.
+
+ @param[in] OldTableSize Old memory pool size.
+ @param[in] NewTableSize Required memory pool size.
+ @param[in, out] OldBuffer Current memory buffer pointer holding the HEST
+ table data.
+
+ @retval New pointer to reallocated memory pool.
+
+**/
+STATIC
+VOID*
+ReallocateHestTableMemory (
+ IN UINT32 OldTableSize,
+ IN UINT32 NewTableSize,
+ IN OUT VOID *OldBuffer
+ )
+{
+ return ReallocateReservedPool (
+ OldTableSize,
+ NewTableSize,
+ OldBuffer
+ );
+}
+
+/**
+ Allocate memory for the HEST ACPI table header and populate it.
+
+ @retval EFI_SUCCESS On successful creation of HEST header.
+ @retval EFI_OUT_OF_RESOURCES If system is out of memory recources.
+
+**/
+STATIC
+EFI_STATUS
+BuildHestHeader (VOID)
+{
+ EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER HestHeader;
+ UINT64 TempOemTableId;
+
+ //
+ // Allocate memory for the HEST ACPI table header.
+ //
+ mHestDriverData.HestTable =
+ ReallocateHestTableMemory (
+ 0,
+ sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER),
+ NULL
+ );
+ if (mHestDriverData.HestTable == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ mHestDriverData.CurrentTableSize =
+ sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER);
+
+ //
+ // Populate the values of the HEST ACPI table header.
+ //
+ HestHeader.Header.Signature = EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_SIGNATURE;
+ HestHeader.Header.Revision = EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_REVISION;
+ CopyMem (
+ &HestHeader.Header.OemId,
+ FixedPcdGetPtr (PcdAcpiDefaultOemId),
+ sizeof (HestHeader.Header.OemId)
+ );
+ TempOemTableId = FixedPcdGet64 (PcdAcpiDefaultOemTableId);
+ CopyMem (
+ &HestHeader.Header.OemTableId,
+ &TempOemTableId,
+ sizeof (HestHeader.Header.OemTableId)
+ );
+ HestHeader.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
+ HestHeader.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
+ HestHeader.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
+ HestHeader.ErrorSourceCount = 0;
+ CopyMem (mHestDriverData.HestTable, &HestHeader, sizeof (HestHeader));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Append HEST error source descriptor protocol service.
+
+ @param[in] ErrorSourceDescriptorList List of Error Source Descriptors.
+ @param[in] ErrorSourceDescriptorListSize Total Size of the ErrorSourceDescriptorList.
+ @param[in] ErrorSourceDescriptorCount Total count of error source descriptors in
+ ErrorSourceDescriptorList.
+
+ @retval EFI_SUCCESS Appending the error source descriptors
+ successful.
+ @retval EFI_OUT_OF_RESOURCES Buffer reallocation failed for the HEST
+ table.
+ @retval EFI_INVALID_PARAMETER Null ErrorSourceDescriptorList param or
+ ErrorSourceDescriptorListSize is 0.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+AppendErrorSourceDescriptor (
+ IN CONST VOID *ErrorSourceDescriptorList,
+ IN UINTN ErrorSourceDescriptorListSize,
+ IN UINTN ErrorSourceDescriptorCount
+ )
+{
+ EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *HestHeaderPtr;
+ EFI_STATUS Status;
+ UINT32 NewTableSize;
+ VOID *ErrorDescriptorPtr;
+
+ if ((ErrorSourceDescriptorList == NULL)
+ || (ErrorSourceDescriptorListSize == 0)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Create a HEST table header if not already created.
+ //
+ if (mHestDriverData.HestTable == NULL) {
+ Status = BuildHestHeader ();
+ if (Status == EFI_OUT_OF_RESOURCES) {
+ DEBUG ((DEBUG_ERROR, "HestDxe: Failed to build HEST header, status: %r\n",
+ Status));
+ return Status;
+ }
+ }
+
+ //
+ // Resize the existing HEST table buffer to accommodate the incoming error source
+ // descriptors.
+ //
+ NewTableSize = mHestDriverData.CurrentTableSize +
+ ErrorSourceDescriptorListSize;
+ mHestDriverData.HestTable = ReallocateHestTableMemory (
+ mHestDriverData.CurrentTableSize,
+ NewTableSize,
+ mHestDriverData.HestTable
+ );
+ if (mHestDriverData.HestTable == NULL) {
+ DEBUG ((DEBUG_ERROR, "HestDxe: Failed to reallocate memory for HEST table\n"));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Copy the incoming error source descriptors into HEST table.
+ //
+ ErrorDescriptorPtr = (VOID *)mHestDriverData.HestTable +
+ mHestDriverData.CurrentTableSize;
+ HestHeaderPtr = (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *)
+ mHestDriverData.HestTable;
+ CopyMem (
+ ErrorDescriptorPtr,
+ ErrorSourceDescriptorList,
+ ErrorSourceDescriptorListSize
+ );
+ mHestDriverData.CurrentTableSize = NewTableSize;
+ HestHeaderPtr->Header.Length = mHestDriverData.CurrentTableSize;
+ HestHeaderPtr->ErrorSourceCount += ErrorSourceDescriptorCount;
+
+ DEBUG ((DEBUG_INFO, "HestDxe: %d Error source descriptor(s) added \n",
+ ErrorSourceDescriptorCount));
+ return EFI_SUCCESS;
+}
+
+/**
+ Install HEST ACPI table protocol service.
+
+ @retval EFI_SUCCESS ACPI HEST table is installed successfully.
+ @retval EFI_ABORTED HEST table is NULL.
+ @retval Other Install HEST ACPI table failed.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+InstallHestAcpiTable (VOID)
+{
+ EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *HestHeader;
+ EFI_STATUS Status;
+ UINTN AcpiTableHandle;
+
+ //
+ // Check if we have valid HEST table data.
+ //
+ if (mHestDriverData.HestTable == NULL) {
+ DEBUG ((DEBUG_ERROR, "HestDxe: No data available to generate HEST table\n"));
+ return EFI_ABORTED;
+ }
+
+ //
+ // Valid data for HEST table found. Update the header checksum and install the
+ // HEST table.
+ //
+ HestHeader = (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *)
+ mHestDriverData.HestTable;
+ HestHeader->Header.Checksum = CalculateCheckSum8 (
+ (UINT8 *)HestHeader,
+ HestHeader->Header.Length
+ );
+
+ Status = mAcpiTableProtocol->InstallAcpiTable (
+ mAcpiTableProtocol,
+ HestHeader,
+ HestHeader->Header.Length,
+ &AcpiTableHandle
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "HestDxe: HEST ACPI table installation failed, status: %r\n",
+ Status));
+ return Status;
+ }
+
+ //
+ // Free the HEST table buffer.
+ //
+ FreePool (mHestDriverData.HestTable);
+ DEBUG ((DEBUG_INFO, "HestDxe: Installed HEST ACPI table \n"));
+ return EFI_SUCCESS;
+}
+
+//
+// HEST table generation protocol instance.
+//
+STATIC HEST_TABLE_PROTOCOL mHestProtocol = {
+ AppendErrorSourceDescriptor,
+ InstallHestAcpiTable
+};
+
+/**
+ The Entry Point for HEST DXE driver.
+
+ This function installs the HEST table creation and installation protocol
+ services.
+
+ @param[in] ImageHandle Handle to the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS On successful installation of protocol services and
+ location the Acpi table protocol.
+ @retval Other On Failure to locate ACPI table protocol or install
+ of HEST table generation protocol.
+
+**/
+EFI_STATUS
+EFIAPI
+HestInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_HANDLE Handle = NULL;
+ EFI_STATUS Status;
+
+ Status = gBS->LocateProtocol (
+ &gEfiAcpiTableProtocolGuid,
+ NULL,
+ (VOID **)&mAcpiTableProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "HestDxe: Failed to locate ACPI table protocol, status: %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ Status = gBS->InstallProtocolInterface (
+ &Handle,
+ &gHestTableProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mHestProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "HestDxe: Failed to install HEST table generation protocol status: %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] ArmPlatformPkg: add definition for MM_HEST_ERROR_SOURCE_DESC_PROTOCOL
2020-10-30 8:36 [PATCH 0/3] ArmPlatformPkg: Introduce dynamic generation of HEST table omkar.kulkarni
2020-10-30 8:36 ` [PATCH 1/3] ArmPlatformPkg: Allow dynamic generation of HEST ACPI table Omkar Anand Kulkarni
@ 2020-10-30 8:36 ` Omkar Anand Kulkarni
2020-10-30 8:36 ` [PATCH 3/3] ArmPlatformPkg: retreive error source descriptors from MM Omkar Anand Kulkarni
2 siblings, 0 replies; 4+ messages in thread
From: Omkar Anand Kulkarni @ 2020-10-30 8:36 UTC (permalink / raw)
To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Sami Mujawar, Jiewen Yao
Add the protocol definition of the MM_HEST_ERROR_SOURCE_DESC_PROTOCOL
protocol. This protocol can be implemented by MM drivers to publish
error source descriptors that have to be populated into HEST table.
Co-authored-by: Thomas Abraham <thomas.abraham@arm.com>
Signed-off-by: Omkar Anand Kulkarni <omkar.kulkarni@arm.com>
---
ArmPlatformPkg/ArmPlatformPkg.dec | 1 +
ArmPlatformPkg/Include/Protocol/HestErrorSourceInfo.h | 64 ++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatformPkg.dec
index 23c5b768f677..8fc44c40e813 100644
--- a/ArmPlatformPkg/ArmPlatformPkg.dec
+++ b/ArmPlatformPkg/ArmPlatformPkg.dec
@@ -114,3 +114,4 @@
[Protocols.common]
## Arm Platform HEST table generation protocol
gHestTableProtocolGuid = { 0x705bdcd9, 0x8c47, 0x457e, { 0xad, 0x0d, 0xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } }
+ gMmHestErrorSourceDescProtocolGuid = { 0x560bf236, 0xa4a8, 0x4d69, { 0xbc, 0xf6, 0xc2, 0x97, 0x24, 0x10, 0x9d, 0x91 } }
diff --git a/ArmPlatformPkg/Include/Protocol/HestErrorSourceInfo.h b/ArmPlatformPkg/Include/Protocol/HestErrorSourceInfo.h
new file mode 100644
index 000000000000..396a7cc48ee9
--- /dev/null
+++ b/ArmPlatformPkg/Include/Protocol/HestErrorSourceInfo.h
@@ -0,0 +1,64 @@
+/** @file
+ Standalone MM protocol to get the HEST secure error source descriptor
+ information.
+
+ Drivers must implement his protocol in order to pusblih their Hardware
+ error source descriptor information to OS through the HEST ACPI table.
+
+ Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MM_HEST_ERROR_SOURCE_DESC_
+#define MM_HEST_ERROR_SOURCE_DESC_
+
+#define MM_HEST_ERROR_SOURCE_DESC_PROTOCOL_GUID \
+ { \
+ 0x560bf236, 0xa4a8, 0x4d69, { 0xbc, 0xf6, 0xc2, 0x97, 0x24, 0x10, 0x9d, 0x91 } \
+ }
+
+typedef struct MM_HEST_ERROR_SOURCE_DESC_PROTOCOL_
+ MM_HEST_ERROR_SOURCE_DESC_PROTOCOL;
+
+/**
+ Get HEST Secure Error Source Descriptors.
+
+ The drivers implementing this protocol must convey the total count and total
+ length of the error sources the driver has along with the actual error source
+ descriptors.
+ If the user of this driver calls the protocol by passing NULL as Buffer parameter.
+ Then protocol shall return EFI_INVALID_PARAMETR with the total length and count of
+ the error source descriptor it supports.
+
+ @param[in] This Instance of MM_HEST_ERROR_SOURCE_DESC_PROTOCOL.
+ @param[out] Buffer Buffer to be appended with the error source descriptors information.
+ @param[out] ErrorSourcesLength Total length of all the error source descriptors.
+ @param[out] ErrorSourceCount Count of total error source descriptors supported by the
+ driver.
+
+ retval EFI_SUCCESS If the Buffer is valid and is filled with valid Error Source
+ descriptor data.
+ retval EFI_INVALID_PARAMTER Buffer is NULL.
+ retval Other If no error source descriptor information is available.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *MM_HEST_GET_ERROR_SOURCE_DESCRIPTORS) (
+ IN MM_HEST_ERROR_SOURCE_DESC_PROTOCOL *This,
+ OUT VOID **Buffer,
+ OUT UINTN *ErrorSourcesLength,
+ OUT UINTN *ErrorSourcesCount
+ );
+
+//
+// Protocol declaration
+//
+struct MM_HEST_ERROR_SOURCE_DESC_PROTOCOL_ {
+ MM_HEST_GET_ERROR_SOURCE_DESCRIPTORS GetHestErrorSourceDescriptors;
+};
+
+extern EFI_GUID gMmHestErrorSourceDescProtocolGuid;
+
+#endif // MM_HEST_ERROR_SOURCE_DESC_
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] ArmPlatformPkg: retreive error source descriptors from MM
2020-10-30 8:36 [PATCH 0/3] ArmPlatformPkg: Introduce dynamic generation of HEST table omkar.kulkarni
2020-10-30 8:36 ` [PATCH 1/3] ArmPlatformPkg: Allow dynamic generation of HEST ACPI table Omkar Anand Kulkarni
2020-10-30 8:36 ` [PATCH 2/3] ArmPlatformPkg: add definition for MM_HEST_ERROR_SOURCE_DESC_PROTOCOL Omkar Anand Kulkarni
@ 2020-10-30 8:36 ` Omkar Anand Kulkarni
2 siblings, 0 replies; 4+ messages in thread
From: Omkar Anand Kulkarni @ 2020-10-30 8:36 UTC (permalink / raw)
To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Sami Mujawar, Jiewen Yao
Add a driver that retreives error source descriptors from MM and
populates those into the HEST ACPI table. The error source descriptors
that are available from the MM side are retreived using MM Communicate 2
protocol.
The first call into the MM returns the size of MM Communicate buffer
required to hold all error source descriptor info. The communication
buffer of that size is then allocated and the second call into MM
returns the error source descriptors in the communication buffer.
The retreived error source descriptors are then appended to the HEST
table.
Co-authored-by: Thomas Abraham <thomas.abraham@arm.com>
Signed-off-by: Omkar Anand Kulkarni <omkar.kulkarni@arm.com>
---
ArmPlatformPkg/ArmPlatformPkg.dec | 7 +
ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf | 41 +++
ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf | 51 ++++
ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h | 33 +++
ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c | 257 ++++++++++++++++++
ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c | 282 ++++++++++++++++++++
6 files changed, 671 insertions(+)
diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatformPkg.dec
index 8fc44c40e813..3c12d795121e 100644
--- a/ArmPlatformPkg/ArmPlatformPkg.dec
+++ b/ArmPlatformPkg/ArmPlatformPkg.dec
@@ -35,6 +35,8 @@
[Guids.common]
gArmPlatformTokenSpaceGuid = { 0x9c0aaed4, 0x74c5, 0x4043, { 0xb4, 0x17, 0xa3, 0x22, 0x38, 0x14, 0xce, 0x76 } }
+ gArmPlatformHestErrorSourcesGuid = { 0x76b8ab43, 0x822d, 0x4b00, { 0x9f, 0xd0, 0xf4, 0xa5, 0x35, 0x82, 0x47, 0x0a } }
+ gMmHestGetErrorSourceInfoGuid = { 0x7d602951, 0x678e, 0x4cc4, { 0x98, 0xd9, 0xe3, 0x76, 0x04, 0xf6, 0x93, 0x0d } }
[PcdsFeatureFlag.common]
gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|FALSE|BOOLEAN|0x00000004
@@ -111,6 +113,11 @@
gArmPlatformTokenSpaceGuid.PcdWatchdogCount|0x0|UINT32|0x00000033
+[PcdsFixedAtBuild, PcdsPatchableInModule]
+ ## ACPI CPER memory space
+ gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferBase|0x00000000|UINT64|0x00000046
+ gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferSize|0x00000000|UINT64|0x00000047
+
[Protocols.common]
## Arm Platform HEST table generation protocol
gHestTableProtocolGuid = { 0x705bdcd9, 0x8c47, 0x457e, { 0xad, 0x0d, 0xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } }
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf
new file mode 100644
index 000000000000..514f60fbafd4
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf
@@ -0,0 +1,41 @@
+## @file
+# DXE driver to retrieve the error source descriptors from Standalone MM and append
+# those to the HEST table.
+#
+# Copyright (c) 2020, ARM Limited. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = HestMmErrorSourceDxe
+ FILE_GUID = 76b8ab43-822d-4b00-9fd0-f4a53582470a
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = HestErrorSourceInitialize
+
+[Sources.common]
+ HestErrorSourceDxe.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ MdePkg/MdePkg.dec
+ StandaloneMmPkg/StandaloneMmPkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ DxeServicesTableLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[Guids]
+ gMmHestGetErrorSourceInfoGuid ## PRODUCES
+
+[Protocols]
+ gHestTableProtocolGuid ## CONSUMES
+ gEfiMmCommunication2ProtocolGuid
+
+[Depex]
+ gHestTableProtocolGuid AND gEfiMmCommunication2ProtocolGuid
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf
new file mode 100644
index 000000000000..cf215ddd8d50
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf
@@ -0,0 +1,51 @@
+## @file
+# HEST error source gateway Standalone MM driver.
+#
+# Collects HEST error source descriptors,by communicating with all the MM drivers
+# implementing the HEST error source descriptor protocol.
+#
+# Copyright (c) 2020, ARM Limited. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = HestErrorSourceStandaloneMm
+ FILE_GUID = 3ddbebcc-9841-4ef8-87fa-305843c1922d
+ MODULE_TYPE = MM_STANDALONE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x00010032
+ ENTRY_POINT = StandaloneMmHestErrorSourceInitialize
+
+[Sources]
+ HestErrorSourceStandaloneMm.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ StandaloneMmPkg/StandaloneMmPkg.dec
+
+[LibraryClasses]
+ ArmLib
+ ArmSvcLib
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
+ StandaloneMmDriverEntryPoint
+
+[Protocols]
+ gMmHestErrorSourceDescProtocolGuid
+
+[Guids]
+ gMmHestGetErrorSourceInfoGuid ##PRODUCES
+ gEfiStandaloneMmNonSecureBufferGuid
+
+[FixedPcd]
+ gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferBase
+ gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferSize
+
+[Depex]
+ gMmHestErrorSourceDescProtocolGuid
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h
new file mode 100644
index 000000000000..2929f05607ac
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h
@@ -0,0 +1,33 @@
+/** @file
+ Define data structure for error source descriptor information.
+
+ Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef HEST_ERROR_SOURCE_DESCRIPTOR_H_
+#define HEST_ERROR_SOURCE_DESCRIPTOR_H_
+
+#define HEST_ERROR_SOURCE_DESC_INFO_SIZE (OFFSET_OF (HEST_ERROR_SOURCE_DESC_INFO, ErrSourceDescList))
+
+//
+// Data Structure to communicate the error source descriptor information from
+// Standalone MM.
+//
+typedef struct {
+ //
+ // Total count of error source descriptors.
+ //
+ UINTN ErrSourceDescCount;
+ //
+ // Total size of all the error source descriptors.
+ //
+ UINTN ErrSourceDescSize;
+ //
+ // Array of error source descriptors that is ErrSourceDescSize in size.
+ //
+ UINT8 ErrSourceDescList[1];
+} HEST_ERROR_SOURCE_DESC_INFO;
+
+#endif // HEST_ERROR_SOURCE_DESCRIPTOR_H_
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c
new file mode 100644
index 000000000000..539424f2f4d6
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c
@@ -0,0 +1,257 @@
+/** @file
+ Collects and appends the HEST error source descriptors from the MM drivers.
+
+ The drivers entry point locates the MM Communication protocol and calls into
+ Standalone MM to get the HEST error sources length and count. It also
+ retrieves descriptor information.
+ The information is then used to build the HEST table using the HEST table
+ generation protocol.
+
+ Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/Acpi.h>
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/MmCommunication2.h>
+#include <Protocol/HestTable.h>
+
+#include "HestMmErrorSourceCommon.h"
+
+#define MM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data))
+
+STATIC HEST_TABLE_PROTOCOL *mHestProtocol;
+STATIC EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2;
+
+/**
+ Retrieve the error source descriptors from Standalone MM.
+
+ Initialize the MM comminication buffer by assigning the MM service to
+ invoke as gMmHestGetErrorSourceInfoGuid. Use the MM communication
+ protocol to retrieve the error source descriptors.
+
+ @param[in] CommBuffSize Size of communicate buffer.
+ @param[in, out] CommBuffer The communicate buffer.
+
+ @retval EFI_SUCCESS MM Communicate protocol call successful.
+ @retval Other MM Communicate protocol call failed.
+
+**/
+STATIC
+EFI_STATUS
+GetErrorSourceDescriptors (
+ IN UINTN CommBuffSize,
+ IN OUT EFI_MM_COMMUNICATE_HEADER **CommBuffer
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Initialize the CommBuffer with MM Communicate metadata.
+ //
+ CopyGuid (&(*CommBuffer)->HeaderGuid, &gMmHestGetErrorSourceInfoGuid);
+ (*CommBuffer)->MessageLength =
+ CommBuffSize -
+ sizeof ((*CommBuffer)->HeaderGuid) -
+ sizeof ((*CommBuffer)->MessageLength);
+
+ //
+ // Call into the Standalone MM using the MM Communicate protocol.
+ //
+ Status = mMmCommunication2->Communicate (
+ mMmCommunication2,
+ (VOID *)*CommBuffer,
+ (VOID *)*CommBuffer,
+ NULL
+ );
+
+ return Status;
+}
+
+/**
+ Collect HEST error source descriptors from all Standalone MM drivers and append
+ them to the HEST table.
+
+ Use MM Communication Protocol to communicate and collect the error source
+ descriptor information from Standalone MM. Check for the required buffer size
+ returned by the MM driver. Allocate buffer of adequate size and call again into
+ MM.
+
+ @retval EFI_SUCCESS Successful to collect and append the error source
+ descriptors to HEST table.
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failure.
+ @retval Other For any other error.
+
+**/
+STATIC
+EFI_STATUS
+AppendMmErrorSources (VOID)
+{
+ EFI_MM_COMMUNICATE_HEADER *CommunicationHeader = NULL;
+ HEST_ERROR_SOURCE_DESC_INFO *ErrorSourceDescInfo;
+ EFI_STATUS Status;
+ UINTN CommBufferSize;
+
+ //
+ // Find out the number of error source descriptors that StandaloneMM supports
+ // and length of the buffer to be supplied to retrieve those error source
+ // descriptors. Do this by providing a buffer of size that is just sufficient
+ // to hold the error source descriptor info. In response to this, the error
+ // source descriptor that is returned contains the actual size of the
+ // communication buffer that is required to retrieve all the error sources.
+ //
+ CommBufferSize = MM_COMMUNICATE_HEADER_SIZE + HEST_ERROR_SOURCE_DESC_INFO_SIZE;
+ CommunicationHeader = AllocatePool (CommBufferSize);
+ if (CommunicationHeader == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // Call to retrieve the length of required buffer.
+ Status = GetErrorSourceDescriptors (CommBufferSize, &CommunicationHeader);
+ if ((EFI_ERROR (Status)) &&
+ (Status != EFI_BAD_BUFFER_SIZE)) {
+ DEBUG ((DEBUG_ERROR, "MM Communicate protocol call failed, status: %r\n",
+ Status));
+ FreePool (CommunicationHeader);
+ return Status;
+ }
+
+ // Check for the length of Error Source descriptors.
+ ErrorSourceDescInfo = (HEST_ERROR_SOURCE_DESC_INFO *)(CommunicationHeader->Data);
+ if ((ErrorSourceDescInfo->ErrSourceDescSize == 0) ||
+ (ErrorSourceDescInfo->ErrSourceDescCount == 0)) {
+ DEBUG ((DEBUG_INFO, "HEST error source(s) not found\n"));
+ FreePool (CommunicationHeader);
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Allocate CommBuffer of required size to accomodate all the error source
+ // descriptors. Required size of communication buffer =
+ // MM communicate metadata. + (error source desc info struct + error source
+ // descriptor size)
+ //
+ CommBufferSize =
+ MM_COMMUNICATE_HEADER_SIZE +
+ HEST_ERROR_SOURCE_DESC_INFO_SIZE +
+ ErrorSourceDescInfo->ErrSourceDescSize;
+
+ // Free old MM Communicate buffer and allocate a new buffer of required size.
+ FreePool (CommunicationHeader);
+ CommunicationHeader = AllocatePool (CommBufferSize);
+ if (CommunicationHeader == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // Call to get the error source descriptors.
+ Status = GetErrorSourceDescriptors (CommBufferSize, &CommunicationHeader);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "MM Communicate protocol failed, status: %r\n",
+ Status));
+ FreePool (CommunicationHeader);
+ return Status;
+ }
+
+ //
+ // Retrieve the HEST error source descriptor information. Ensure that there
+ // is a valid list of error source descriptors.
+ //
+ ErrorSourceDescInfo = (HEST_ERROR_SOURCE_DESC_INFO *)(CommunicationHeader->Data);
+ if (ErrorSourceDescInfo->ErrSourceDescList == NULL) {
+ DEBUG ((DEBUG_INFO, "Error source descriptor list is empty"));
+ FreePool (CommunicationHeader);
+ return EFI_SUCCESS;
+ }
+
+ DEBUG ((DEBUG_INFO, "HEST ErrorSources: TotalCount = %d TotalLength = %d \n",
+ ErrorSourceDescInfo->ErrSourceDescCount,
+ ErrorSourceDescInfo->ErrSourceDescSize));
+ //
+ // Append the error source descriptors to HEST table using the HEST table
+ // generation protocol.
+ //
+ Status = mHestProtocol->AppendErrorSourceDescriptors (
+ ErrorSourceDescInfo->ErrSourceDescList,
+ ErrorSourceDescInfo->ErrSourceDescSize,
+ ErrorSourceDescInfo->ErrSourceDescCount
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to append error source(s), status: %r\n",
+ Status));
+ }
+
+ FreePool (CommunicationHeader);
+ return Status;
+}
+
+/**
+ The Entry Point for Hest Error Source DXE driver.
+
+ Locates the Hest Table generation and MM Communication2 protocols. Using the
+ MM Communication2, the driver collects the Error Source Descriptor(s) from
+ Standalone MM. It then appends those Error Source Descriptor(s) to the Hest
+ table using the Hest Table generation protocol.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Other Some error occurred when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+HestErrorSourceInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gBS->LocateProtocol (
+ &gHestTableProtocolGuid,
+ NULL,
+ (VOID **)&mHestProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "Failed to locate HEST table generation protocol, status:%r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ Status = gBS->LocateProtocol (
+ &gEfiMmCommunication2ProtocolGuid,
+ NULL,
+ (VOID **)&mMmCommunication2
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "Failed to locate MMCommunication2 driver protocol, status:%r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ //
+ // Append HEST error sources retrieved from StandaloneMM, if any, into the HEST
+ // ACPI table.
+ //
+ Status = AppendMmErrorSources ();
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "HEST table creation faied, status:%r\n",
+ Status));
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c
new file mode 100644
index 000000000000..9d0c1f744579
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c
@@ -0,0 +1,282 @@
+/** @file
+ MM HEST error source gateway driver.
+
+ This driver installs a handler which can be used to retrieve the error source
+ descriptors from the all MM drivers implementing the HEST error source
+ descriptor protocol.
+
+ Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <Protocol/HestErrorSourceInfo.h>
+#include "HestMmErrorSourceCommon.h"
+
+STATIC EFI_MM_SYSTEM_TABLE *mMmst = NULL;
+
+/**
+ Returns an array of handles that implement the HEST error source descriptor
+ protocol.
+
+ Passing HandleBuffer as NULL will return the actual size of the buffer
+ required to hold the array of handles implementing the protocol.
+
+ @param[in, out] HandleBufferSize The size of the HandleBuffer.
+ @param[out] HandleBuffer A pointer to the buffer containing the list
+ of handles.
+
+ @retval EFI_SUCCESS The array of handles returned in HandleBuffer.
+ @retval EFI_NOT_FOUND No implementation present for the protocol.
+ @retval Other For any other error.
+
+**/
+STATIC
+EFI_STATUS
+GetHestErrorSourceProtocolHandles (
+ IN OUT UINTN *HandleBufferSize,
+ OUT EFI_HANDLE **HandleBuffer
+ )
+{
+ EFI_STATUS Status;
+
+ Status = mMmst->MmLocateHandle (
+ ByProtocol,
+ &gMmHestErrorSourceDescProtocolGuid,
+ NULL,
+ HandleBufferSize,
+ *HandleBuffer
+ );
+ if ((EFI_ERROR (Status)) &&
+ (Status != EFI_BUFFER_TOO_SMALL))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "No implementation of MmHestErrorSourceDescProtocol found, Status:%r\n",
+ Status
+ ));
+ return EFI_NOT_FOUND;
+ }
+
+ return Status;
+}
+
+/**
+ MMI handler to retrieve HEST error source descriptor information.
+
+ Handler for MMI service that returns the supported HEST error source
+ descriptors in MM. This handler populates the CommBuffer with the
+ list of all error source descriptors, prepended with the length and
+ the number of descriptors populated into CommBuffer.
+
+ @param[in] DispatchHandle The unique handle assigned to this handler by
+ MmiHandlerRegister().
+ @param[in] Context Points to an optional handler context which was
+ specified when the handler was registered.
+ @param[in, out] CommBuffer Buffer used for communication of HEST error
+ source descriptors.
+ @param[in, out] CommBufferSize The size of the CommBuffer.
+
+ @return EFI_SUCCESS CommBuffer has valid data.
+ @return EFI_BAD_BUFFER_SIZE CommBufferSize not adequate.
+ @return EFI_OUT_OF_RESOURCES System out of memory resources.
+ @retval EFI_INVALID_PARAMETER Invalid CommBufferSize recieved.
+ @retval Other For any other error.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+HestErrorSourcesInfoMmiHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context, OPTIONAL
+ IN OUT VOID *CommBuffer, OPTIONAL
+ IN OUT UINTN *CommBufferSize OPTIONAL
+ )
+{
+ MM_HEST_ERROR_SOURCE_DESC_PROTOCOL *HestErrSourceDescProtocolHandle;
+ HEST_ERROR_SOURCE_DESC_INFO *ErrorSourceInfoList;
+ EFI_HANDLE *HandleBuffer;
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ UINTN HandleBufferSize;
+ UINTN Index;
+ UINTN SourceCount = 0;
+ UINTN SourceLength = 0;
+ VOID *ErrorSourcePtr;
+ UINTN TotalSourceLength = 0;
+ UINTN TotalSourceCount = 0;
+
+ if (*CommBufferSize < HEST_ERROR_SOURCE_DESC_INFO_SIZE) {
+ //
+ // Ensure that the communication buffer has enough space to hold the
+ // ErrSourceDescCount and ErrSourceDescSize elements of the
+ // HEST_ERROR_SOURCE_DESC_INFO structure
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Get all handles that implement the HEST error source descriptor protocol.
+
+ // Get the buffer size required to store list of handles for the protocol.
+ HandleBuffer = NULL;
+ HandleBufferSize = 0;
+ Status = GetHestErrorSourceProtocolHandles (&HandleBufferSize, &HandleBuffer);
+ if ((Status == EFI_NOT_FOUND) ||
+ (HandleBufferSize == 0))
+ {
+ return Status;
+ }
+
+ // Allocate memory for HandleBuffer of size HandleBufferSize.
+ HandleBuffer = AllocatePool (HandleBufferSize);
+ if (HandleBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // Get the list of handles.
+ Status = GetHestErrorSourceProtocolHandles (&HandleBufferSize, &HandleBuffer);
+ if ((EFI_ERROR (Status)) ||
+ (HandleBuffer == NULL))
+ {
+ FreePool (HandleBuffer);
+ return Status;
+ }
+
+ // Count of handles for the protocol.
+ HandleCount = HandleBufferSize / sizeof (EFI_HANDLE);
+
+ //
+ // Loop to get the count and length of the error source descriptors from all
+ // the MM drivers implementing HEST error source descriptor protocol.
+ //
+ for (Index = 0; Index < HandleCount; ++Index) {
+ Status = mMmst->MmHandleProtocol (
+ HandleBuffer[Index],
+ &gMmHestErrorSourceDescProtocolGuid,
+ (VOID **)&HestErrSourceDescProtocolHandle
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ //
+ // Protocol called with Buffer parameter passed as NULL, must return
+ // error source length and error count for that driver.
+ //
+ Status = HestErrSourceDescProtocolHandle->GetHestErrorSourceDescriptors (
+ HestErrSourceDescProtocolHandle,
+ NULL,
+ &SourceLength,
+ &SourceCount
+ );
+ if (Status == EFI_INVALID_PARAMETER) {
+ TotalSourceLength += SourceLength;
+ TotalSourceCount += SourceCount;
+ }
+ }
+
+ // Set the count and length in the error source descriptor.
+ ErrorSourceInfoList = (HEST_ERROR_SOURCE_DESC_INFO *)(CommBuffer);
+ ErrorSourceInfoList->ErrSourceDescCount = TotalSourceCount;
+ ErrorSourceInfoList->ErrSourceDescSize = TotalSourceLength;
+
+ //
+ // Check the size of CommBuffer, it should atleast be of size
+ // TotalSourceLength + HEST_ERROR_SOURCE_DESC_INFO_SIZE.
+ //
+ TotalSourceLength = TotalSourceLength + HEST_ERROR_SOURCE_DESC_INFO_SIZE;
+ if ((*CommBufferSize) < TotalSourceLength) {
+ FreePool (HandleBuffer);
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ //
+ // CommBuffer size is adequate to return all the error source descriptors.
+ // Populate it with the error source descriptor information.
+ //
+
+ // Buffer pointer to append the Error Descriptors data.
+ ErrorSourcePtr = ErrorSourceInfoList->ErrSourceDescList;
+
+ // Loop to retrieve error source descriptors.
+ for (Index = 0; Index < HandleCount; ++Index) {
+ Status = mMmst->MmHandleProtocol (
+ HandleBuffer[Index],
+ &gMmHestErrorSourceDescProtocolGuid,
+ (VOID **)&HestErrSourceDescProtocolHandle
+ );
+ if (EFI_ERROR (Status)) {
+ continue;
+ }
+
+ Status = HestErrSourceDescProtocolHandle->GetHestErrorSourceDescriptors (
+ HestErrSourceDescProtocolHandle,
+ (VOID **)&ErrorSourcePtr,
+ &SourceLength,
+ &SourceCount
+ );
+ if (Status == EFI_SUCCESS) {
+ ErrorSourcePtr += SourceLength;
+ }
+ }
+
+ // Free the buffer holding all the protocol handles.
+ FreePool (HandleBuffer);
+
+ // Initialize CPER memory.
+ SetMem (
+ (VOID *)FixedPcdGet64 (PcdGhesGenericErrorDataMmBufferBase),
+ FixedPcdGet64 (PcdGhesGenericErrorDataMmBufferSize),
+ 0
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Entry point for this Stanalone MM driver.
+
+ Registers an MMI handler that retrieves the error source descriptors from all
+ the MM drivers implementing the MM_HEST_ERROR_SOURCE_DESC_PROTOCOL.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point registered handler successfully.
+ @retval Other Some error occurred when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+StandaloneMmHestErrorSourceInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_HANDLE DispatchHandle;
+ EFI_STATUS Status;
+
+ ASSERT (SystemTable != NULL);
+ mMmst = SystemTable;
+
+ Status = mMmst->MmiHandlerRegister (
+ HestErrorSourcesInfoMmiHandler,
+ &gMmHestGetErrorSourceInfoGuid,
+ &DispatchHandle
+ );
+ if (EFI_ERROR(Status)) {
+ DEBUG ((DEBUG_ERROR, "MMI handler registration failed with status : %r\n",
+ Status));
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-30 8:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-30 8:36 [PATCH 0/3] ArmPlatformPkg: Introduce dynamic generation of HEST table omkar.kulkarni
2020-10-30 8:36 ` [PATCH 1/3] ArmPlatformPkg: Allow dynamic generation of HEST ACPI table Omkar Anand Kulkarni
2020-10-30 8:36 ` [PATCH 2/3] ArmPlatformPkg: add definition for MM_HEST_ERROR_SOURCE_DESC_PROTOCOL Omkar Anand Kulkarni
2020-10-30 8:36 ` [PATCH 3/3] ArmPlatformPkg: retreive error source descriptors from MM Omkar Anand Kulkarni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox