From nobody Mon Feb 9 12:15:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+66823+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66823+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1604070075; cv=none; d=zohomail.com; s=zohoarc; b=Sf8OxhYw1wJTg1VFzY1wwC5MtUZ//l1lv2HqzLLFvacMMD9SYfFZ4qVgqKzLSQ+P6YGJMDY8vVsQSscBpxGVzTRFsHua5Lp/tdDfyH78mtWZVVmKqHPHElTTS4al+j5NikDmlKxdZd+k8l4GmHoRff7uCr67jW+8KsI1X+FloJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604070075; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=dwqr4B22NaxllNR00udKY1QWuWHWDokUr03/BGVgc7I=; b=VBadkbWT1o4VPY5u4xck1FgZQ0VwfTLj35f+2xA286UpdZNqNaZxI0GQ0wmuwgodjLlhNj7psQ54uq+HIryveAcsf1ZHVC5lyPQPLT84FVpuuz4ZdLKGTXHy4rLoxiUh30GtVBgauhqDrpwuqC1bo+pkhQTxf3Ai0UTGh1+oQyE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66823+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1604070075469295.9206806669034; Fri, 30 Oct 2020 08:01:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MrRiYY1788612x8zuj6ag1lU; Fri, 30 Oct 2020 08:01:12 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.10497.1604046987144042202 for ; Fri, 30 Oct 2020 01:36:27 -0700 X-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 BC6E3143D; Fri, 30 Oct 2020 01:36:26 -0700 (PDT) X-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 D281D3F719; Fri, 30 Oct 2020 01:36:24 -0700 (PDT) From: "Omkar Anand Kulkarni" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Jiewen Yao Subject: [edk2-devel] [PATCH 1/3] ArmPlatformPkg: Allow dynamic generation of HEST ACPI table Date: Fri, 30 Oct 2020 14:06:09 +0530 Message-Id: <20201030083611.8196-2-omkar.kulkarni@arm.com> In-Reply-To: <20201030083611.8196-1-omkar.kulkarni@arm.com> References: <20201030083611.8196-1-omkar.kulkarni@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,omkar.kulkarni@arm.com X-Gm-Message-State: vAnJ3Vk5J5vxlN0SfLA5UXKJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604070072; bh=FENMjp9RpwMK0HP/DBO6ET0vOOmclrQPkLnTkhz3lfc=; h=Cc:Date:From:Reply-To:Subject:To; b=xQRZ/+I8geexkBzjSU7Wn/eqIhDYB3Y2F3aceh4PB/1NuFLXnAUiBjnzdzaqO5sDt8I 3+Zv9iYZ5+4PNg3iI7fbAaVqYHqt6xz4WBEJhFx3F/z+bcArXz5b/BnzA7G2x9QJcaIPX uRBd3TiVA3/MEG4VHpAk09+0FR7lIdoKI5A= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Omkar Anand Kulkarni --- 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/ArmPlatform= Pkg.dec index 696d636aacee..23c5b768f677 100644 --- a/ArmPlatformPkg/ArmPlatformPkg.dec +++ b/ArmPlatformPkg/ArmPlatformPkg.dec @@ -110,3 +110,7 @@ gArmPlatformTokenSpaceGuid.PcdPL031RtcPpmAccuracy|300000000|UINT32|0x000= 00022 =20 gArmPlatformTokenSpaceGuid.PcdWatchdogCount|0x0|UINT32|0x00000033 + +[Protocols.common] + ## Arm Platform HEST table generation protocol + gHestTableProtocolGuid =3D { 0x705bdcd9, 0x8c47, 0x457e, { 0xad, 0x0d, 0= xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } } diff --git a/ArmPlatformPkg/Drivers/Apei/HestDxe/HestDxe.inf b/ArmPlatformP= kg/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 =3D 0x0001001A + BASE_NAME =3D HestDxe + FILE_GUID =3D 933099a2-ef71-4e00-82aa-a79b1e0a3b38 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D 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/I= nclude/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 desc= riptors + into the HEST ACPI table being prepared for installation. + + @param[in] ErrorSourceDescriptorList List of Error Source Descriptor= s. + @param[in] ErrorSourceDescriptorListSize Total Size of the ErrorSourceDe= scriptorList. + @param[in] ErrorSourceDescriptorCount Total count of error source des= criptors in + ErrorSourceDescriptorList. + + @retval EFI_SUCCESS Appending the error source desc= riptors + successful. + @retval EFI_OUT_OF_RESOURCES Buffer reallocation failed for = the HEST + table. + @retval EFI_INVALID_PARAMETER Null ErrorSourceDescriptorList = param or + ErrorSourceDescriptorListSize i= s 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 ad= d the + error source descriptors into the HEST table. It also allows the resulti= ng HEST + ACPI table to be installed. + + Copyright (c) 2020, ARM Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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 =3D NULL; +STATIC HEST_DXE_DRIVER_DATA mHestDriverData; + +/** + Helper function to reallocate memory pool for every new error source des= criptor + 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 =3D + ReallocateHestTableMemory ( + 0, + sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER), + NULL + ); + if (mHestDriverData.HestTable =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mHestDriverData.CurrentTableSize =3D + sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER); + + // + // Populate the values of the HEST ACPI table header. + // + HestHeader.Header.Signature =3D EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE= _SIGNATURE; + HestHeader.Header.Revision =3D EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_= REVISION; + CopyMem ( + &HestHeader.Header.OemId, + FixedPcdGetPtr (PcdAcpiDefaultOemId), + sizeof (HestHeader.Header.OemId) + ); + TempOemTableId =3D FixedPcdGet64 (PcdAcpiDefaultOemTableId); + CopyMem ( + &HestHeader.Header.OemTableId, + &TempOemTableId, + sizeof (HestHeader.Header.OemTableId) + ); + HestHeader.Header.OemRevision =3D PcdGet32 (PcdAcpiDefaultOemRevision); + HestHeader.Header.CreatorId =3D PcdGet32 (PcdAcpiDefaultCreatorId); + HestHeader.Header.CreatorRevision =3D PcdGet32 (PcdAcpiDefaultCreatorRev= ision); + HestHeader.ErrorSourceCount =3D 0; + CopyMem (mHestDriverData.HestTable, &HestHeader, sizeof (HestHeader)); + + return EFI_SUCCESS; +} + +/** + Append HEST error source descriptor protocol service. + + @param[in] ErrorSourceDescriptorList List of Error Source Descriptor= s. + @param[in] ErrorSourceDescriptorListSize Total Size of the ErrorSourceDe= scriptorList. + @param[in] ErrorSourceDescriptorCount Total count of error source des= criptors in + ErrorSourceDescriptorList. + + @retval EFI_SUCCESS Appending the error source desc= riptors + successful. + @retval EFI_OUT_OF_RESOURCES Buffer reallocation failed for = the HEST + table. + @retval EFI_INVALID_PARAMETER Null ErrorSourceDescriptorList = param or + ErrorSourceDescriptorListSize i= s 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 =3D=3D NULL) + || (ErrorSourceDescriptorListSize =3D=3D 0)) { + return EFI_INVALID_PARAMETER; + } + + // + // Create a HEST table header if not already created. + // + if (mHestDriverData.HestTable =3D=3D NULL) { + Status =3D BuildHestHeader (); + if (Status =3D=3D 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 err= or source + // descriptors. + // + NewTableSize =3D mHestDriverData.CurrentTableSize + + ErrorSourceDescriptorListSize; + mHestDriverData.HestTable =3D ReallocateHestTableMemory ( + mHestDriverData.CurrentTableSize, + NewTableSize, + mHestDriverData.HestTable + ); + if (mHestDriverData.HestTable =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "HestDxe: Failed to reallocate memory for HEST ta= ble\n")); + return EFI_OUT_OF_RESOURCES; + } + + // + // Copy the incoming error source descriptors into HEST table. + // + ErrorDescriptorPtr =3D (VOID *)mHestDriverData.HestTable + + mHestDriverData.CurrentTableSize; + HestHeaderPtr =3D (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *) + mHestDriverData.HestTable; + CopyMem ( + ErrorDescriptorPtr, + ErrorSourceDescriptorList, + ErrorSourceDescriptorListSize + ); + mHestDriverData.CurrentTableSize =3D NewTableSize; + HestHeaderPtr->Header.Length =3D mHestDriverData.CurrentTableSize; + HestHeaderPtr->ErrorSourceCount +=3D 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 =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "HestDxe: No data available to generate HEST tabl= e\n")); + return EFI_ABORTED; + } + + // + // Valid data for HEST table found. Update the header checksum and insta= ll the + // HEST table. + // + HestHeader =3D (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *) + mHestDriverData.HestTable; + HestHeader->Header.Checksum =3D CalculateCheckSum8 ( + (UINT8 *)HestHeader, + HestHeader->Header.Length + ); + + Status =3D mAcpiTableProtocol->InstallAcpiTable ( + mAcpiTableProtocol, + HestHeader, + HestHeader->Header.Length, + &AcpiTableHandle + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "HestDxe: HEST ACPI table installation failed, st= atus: %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 =3D { + 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 a= nd + location the Acpi table protocol. + @retval Other On Failure to locate ACPI table protocol or insta= ll + of HEST table generation protocol. + +**/ +EFI_STATUS +EFIAPI +HestInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_HANDLE Handle =3D NULL; + EFI_STATUS Status; + + Status =3D 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 =3D 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; +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#66823): https://edk2.groups.io/g/devel/message/66823 Mute This Topic: https://groups.io/mt/77913841/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-