From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.10670.1604046991475943201 for ; Fri, 30 Oct 2020 01:36:31 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: omkar.kulkarni@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2F928143D; Fri, 30 Oct 2020 01:36:31 -0700 (PDT) Received: from usa.arm.com (a076764.blr.arm.com [10.162.16.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4E9DB3F719; Fri, 30 Oct 2020 01:36:29 -0700 (PDT) From: "Omkar Anand Kulkarni" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Jiewen Yao Subject: [PATCH 3/3] ArmPlatformPkg: retreive error source descriptors from MM Date: Fri, 30 Oct 2020 14:06:11 +0530 Message-Id: <20201030083611.8196-4-omkar.kulkarni@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201030083611.8196-1-omkar.kulkarni@arm.com> References: <20201030083611.8196-1-omkar.kulkarni@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 Signed-off-by: Omkar Anand Kulkarni --- ArmPlatformPkg/ArmPlatformPkg.dec = | 7 + ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf = | 41 +++ ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.in= f | 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/ArmPlatfo= rmPkg.dec index 8fc44c40e813..3c12d795121e 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dec +++ b/ArmPlatformPkg/ArmPlatformPkg.dec @@ -35,6 +35,8 @@ =20 [Guids.common] gArmPlatformTokenSpaceGuid =3D { 0x9c0aaed4, 0x74c5, 0x4043, { 0xb4,= 0x17, 0xa3, 0x22, 0x38, 0x14, 0xce, 0x76 } } + gArmPlatformHestErrorSourcesGuid =3D { 0x76b8ab43, 0x822d, 0x4b00, { 0= x9f, 0xd0, 0xf4, 0xa5, 0x35, 0x82, 0x47, 0x0a } } + gMmHestGetErrorSourceInfoGuid =3D { 0x7d602951, 0x678e, 0x4cc4, { 0x98= , 0xd9, 0xe3, 0x76, 0x04, 0xf6, 0x93, 0x0d } } =20 [PcdsFeatureFlag.common] gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores|FALSE|BOO= LEAN|0x00000004 @@ -111,6 +113,11 @@ =20 gArmPlatformTokenSpaceGuid.PcdWatchdogCount|0x0|UINT32|0x00000033 =20 +[PcdsFixedAtBuild, PcdsPatchableInModule] + ## ACPI CPER memory space + gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferBase|0x00000= 000|UINT64|0x00000046 + gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferSize|0x00000= 000|UINT64|0x00000047 + [Protocols.common] ## Arm Platform HEST table generation protocol gHestTableProtocolGuid =3D { 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 M= M 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 =3D 0x0001001A + BASE_NAME =3D HestMmErrorSourceDxe + FILE_GUID =3D 76b8ab43-822d-4b00-9fd0-f4a53582470= a + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D 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/HestErrorSourceSta= ndaloneMm.inf b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSource= StandaloneMm.inf new file mode 100644 index 000000000000..cf215ddd8d50 --- /dev/null +++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandalone= Mm.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 =3D 0x0001001A + BASE_NAME =3D HestErrorSourceStandaloneMm + FILE_GUID =3D 3ddbebcc-9841-4ef8-87fa-305843c1922= d + MODULE_TYPE =3D MM_STANDALONE + VERSION_STRING =3D 1.0 + PI_SPECIFICATION_VERSION =3D 0x00010032 + ENTRY_POINT =3D StandaloneMmHestErrorSourceInitiali= ze + +[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/HestMmErrorSourceC= ommon.h b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceComm= on.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_D= ESC_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 dri= vers. + + The drivers entry point locates the MM Communication protocol and call= s 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 ta= ble + generation protocol. + + Copyright (c) 2020, ARM Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#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 =3D + CommBuffSize - + sizeof ((*CommBuffer)->HeaderGuid) - + sizeof ((*CommBuffer)->MessageLength); + + // + // Call into the Standalone MM using the MM Communicate protocol. + // + Status =3D mMmCommunication2->Communicate ( + mMmCommunication2, + (VOID *)*CommBuffer, + (VOID *)*CommBuffer, + NULL + ); + + return Status; +} + +/** + Collect HEST error source descriptors from all Standalone MM drivers a= nd append + them to the HEST table. + + Use MM Communication Protocol to communicate and collect the error sou= rce + descriptor information from Standalone MM. Check for the required buff= er size + returned by the MM driver. Allocate buffer of adequate size and call a= gain into + MM. + + @retval EFI_SUCCESS Successful to collect and append the erro= r 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 =3D NULL; + HEST_ERROR_SOURCE_DESC_INFO *ErrorSourceDescInfo; + EFI_STATUS Status; + UINTN CommBufferSize; + + // + // Find out the number of error source descriptors that StandaloneMM s= upports + // and length of the buffer to be supplied to retrieve those error sou= rce + // descriptors. Do this by providing a buffer of size that is just suf= ficient + // 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 sou= rces. + // + CommBufferSize =3D MM_COMMUNICATE_HEADER_SIZE + HEST_ERROR_SOURCE_DESC= _INFO_SIZE; + CommunicationHeader =3D AllocatePool (CommBufferSize); + if (CommunicationHeader =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Call to retrieve the length of required buffer. + Status =3D GetErrorSourceDescriptors (CommBufferSize, &CommunicationHe= ader); + if ((EFI_ERROR (Status)) && + (Status !=3D 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 =3D (HEST_ERROR_SOURCE_DESC_INFO *)(CommunicationH= eader->Data); + if ((ErrorSourceDescInfo->ErrSourceDescSize =3D=3D 0) || + (ErrorSourceDescInfo->ErrSourceDescCount =3D=3D 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 so= urce + // descriptors. Required size of communication buffer =3D + // MM communicate metadata. + (error source desc info struct + error s= ource + // descriptor size) + // + CommBufferSize =3D + MM_COMMUNICATE_HEADER_SIZE + + HEST_ERROR_SOURCE_DESC_INFO_SIZE + + ErrorSourceDescInfo->ErrSourceDescSize; + + // Free old MM Communicate buffer and allocate a new buffer of require= d size. + FreePool (CommunicationHeader); + CommunicationHeader =3D AllocatePool (CommBufferSize); + if (CommunicationHeader =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Call to get the error source descriptors. + Status =3D GetErrorSourceDescriptors (CommBufferSize, &CommunicationHe= ader); + 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 =3D (HEST_ERROR_SOURCE_DESC_INFO *)(CommunicationH= eader->Data); + if (ErrorSourceDescInfo->ErrSourceDescList =3D=3D NULL) { + DEBUG ((DEBUG_INFO, "Error source descriptor list is empty")); + FreePool (CommunicationHeader); + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_INFO, "HEST ErrorSources: TotalCount =3D %d TotalLength = =3D %d \n", + ErrorSourceDescInfo->ErrSourceDescCount, + ErrorSourceDescInfo->ErrSourceDescSize)); + // + // Append the error source descriptors to HEST table using the HEST ta= ble + // generation protocol. + // + Status =3D 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. Usi= ng 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 p= oint. + +**/ +EFI_STATUS +EFIAPI +HestErrorSourceInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status =3D 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 =3D 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 =3D 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/HestErrorSourceSta= ndaloneMm.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceSt= andaloneMm.c new file mode 100644 index 000000000000..9d0c1f744579 --- /dev/null +++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandalone= Mm.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 + +#include +#include +#include +#include + +#include +#include "HestMmErrorSourceCommon.h" + +STATIC EFI_MM_SYSTEM_TABLE *mMmst =3D NULL; + +/** + Returns an array of handles that implement the HEST error source descr= iptor + 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 t= he list + of handles. + + @retval EFI_SUCCESS The array of handles returned in HandleB= uffer. + @retval EFI_NOT_FOUND No implementation present for the protoc= ol. + @retval Other For any other error. + +**/ +STATIC +EFI_STATUS +GetHestErrorSourceProtocolHandles ( + IN OUT UINTN *HandleBufferSize, + OUT EFI_HANDLE **HandleBuffer + ) +{ + EFI_STATUS Status; + + Status =3D mMmst->MmLocateHandle ( + ByProtocol, + &gMmHestErrorSourceDescProtocolGuid, + NULL, + HandleBufferSize, + *HandleBuffer + ); + if ((EFI_ERROR (Status)) && + (Status !=3D 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 hand= ler by + MmiHandlerRegister(). + @param[in] Context Points to an optional handler context w= hich was + specified when the handler was register= ed. + @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 =3D 0; + UINTN SourceLength =3D 0; + VOID *ErrorSourcePtr; + UINTN TotalSourceLength =3D 0; + UINTN TotalSourceCount =3D 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 pro= tocol. + + // Get the buffer size required to store list of handles for the proto= col. + HandleBuffer =3D NULL; + HandleBufferSize =3D 0; + Status =3D GetHestErrorSourceProtocolHandles (&HandleBufferSize, &Hand= leBuffer); + if ((Status =3D=3D EFI_NOT_FOUND) || + (HandleBufferSize =3D=3D 0)) + { + return Status; + } + + // Allocate memory for HandleBuffer of size HandleBufferSize. + HandleBuffer =3D AllocatePool (HandleBufferSize); + if (HandleBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Get the list of handles. + Status =3D GetHestErrorSourceProtocolHandles (&HandleBufferSize, &Hand= leBuffer); + if ((EFI_ERROR (Status)) || + (HandleBuffer =3D=3D NULL)) + { + FreePool (HandleBuffer); + return Status; + } + + // Count of handles for the protocol. + HandleCount =3D HandleBufferSize / sizeof (EFI_HANDLE); + + // + // Loop to get the count and length of the error source descriptors fr= om all + // the MM drivers implementing HEST error source descriptor protocol. + // + for (Index =3D 0; Index < HandleCount; ++Index) { + Status =3D 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 =3D HestErrSourceDescProtocolHandle->GetHestErrorSourceDescri= ptors ( + HestErrSourceDescProtoco= lHandle, + NULL, + &SourceLength, + &SourceCount + ); + if (Status =3D=3D EFI_INVALID_PARAMETER) { + TotalSourceLength +=3D SourceLength; + TotalSourceCount +=3D SourceCount; + } + } + + // Set the count and length in the error source descriptor. + ErrorSourceInfoList =3D (HEST_ERROR_SOURCE_DESC_INFO *)(CommBuffer); + ErrorSourceInfoList->ErrSourceDescCount =3D TotalSourceCount; + ErrorSourceInfoList->ErrSourceDescSize =3D TotalSourceLength; + + // + // Check the size of CommBuffer, it should atleast be of size + // TotalSourceLength + HEST_ERROR_SOURCE_DESC_INFO_SIZE. + // + TotalSourceLength =3D 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 descript= ors. + // Populate it with the error source descriptor information. + // + + // Buffer pointer to append the Error Descriptors data. + ErrorSourcePtr =3D ErrorSourceInfoList->ErrSourceDescList; + + // Loop to retrieve error source descriptors. + for (Index =3D 0; Index < HandleCount; ++Index) { + Status =3D mMmst->MmHandleProtocol ( + HandleBuffer[Index], + &gMmHestErrorSourceDescProtocolGuid, + (VOID **)&HestErrSourceDescProtocolHandle + ); + if (EFI_ERROR (Status)) { + continue; + } + + Status =3D HestErrSourceDescProtocolHandle->GetHestErrorSourceDescri= ptors ( + HestErrSourceDescProtoco= lHandle, + (VOID **)&ErrorSourcePtr= , + &SourceLength, + &SourceCount + ); + if (Status =3D=3D EFI_SUCCESS) { + ErrorSourcePtr +=3D 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 f= rom all + the MM drivers implementing the MM_HEST_ERROR_SOURCE_DESC_PROTOCOL. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point registered handler successfull= y. + @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 !=3D NULL); + mMmst =3D SystemTable; + + Status =3D 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; +} --=20 2.17.1