From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.80]) by mx.groups.io with SMTP id smtpd.web08.13309.1633369620744097223 for ; Mon, 04 Oct 2021 10:47:01 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=igzZ3u0e; spf=pass (domain: arm.com, ip: 40.107.20.80, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=er85W6RbKBJfguZ6mjWXiUhZ1rMRm17DBaYVyc4ZXbw=; b=igzZ3u0eS+cxx8svYpTe6XvS5oJ4bulgPc6qpaHbw3z2O/gwVUF2FwwtyYVXxn5yCRBhAyZKY05I+xCj/6iRuyameScEpSJGbXBmCehk7Oq4pDPTnp55zlRfYBrjK+gpHNnOOJv3QQKYq2YJ88JRIxL4sBd3AdG50xAl1sXKZ/o= Received: from DB6PR07CA0017.eurprd07.prod.outlook.com (2603:10a6:6:2d::27) by AM6PR08MB4950.eurprd08.prod.outlook.com (2603:10a6:20b:ea::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15; Mon, 4 Oct 2021 17:46:56 +0000 Received: from DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2d:cafe::91) by DB6PR07CA0017.outlook.office365.com (2603:10a6:6:2d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.8 via Frontend Transport; Mon, 4 Oct 2021 17:46:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT003.mail.protection.outlook.com (10.152.20.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Mon, 4 Oct 2021 17:46:56 +0000 Received: ("Tessian outbound a492f2284909:v103"); Mon, 04 Oct 2021 17:46:56 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 44ad2bcfa96dd046 X-CR-MTA-TID: 64aa7808 Received: from 198db4656981.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 6CF829FE-F111-4B2B-9DDB-1981AB712A71.1; Mon, 04 Oct 2021 17:46:42 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 198db4656981.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 04 Oct 2021 17:46:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kz8g8WuLPcQlzm9OvF1GSAjcMfL7dTJRrHlQFu9FQ2YzHujZV3AVak55wfLF+EsRLA/FTWZkTE1vvntG/jsX06PYBP67ntEqvmGaHK1KKkGOChpX/zcMYOpwUT3of8SLb8Mvs92Rxh9SvQwciB42JDNNaYZ/3xKqgt0j26qHTHFuCm57RhEW+bpGR0XeG9/k9Xk5nNytjwwXAm5TJim/MFaEkZkuj3FvFZKiakzUXu1eYDBcy6J1MXEiWoqpa4GdOxMehEU6UXFRYiy1Wv0XFKfh2pr4GiHAd3xTp36EraM4lcSgPqv/GeM+hOzXRFeOlLFa3xvf7ZLppZOzL2/eGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=er85W6RbKBJfguZ6mjWXiUhZ1rMRm17DBaYVyc4ZXbw=; b=TAk6KUGHrEwto3V/Le5JCwkZX1pSnRAsa5oofaKNYRI10W0eXErowj9wlJGwtrPpT/OSP4by3jz6KeHUPrLrcDWG4WLR0g/qB6IAGk1XBtsk6/k3RT+T/TSfxGpS+ZDb6GZk5/kkV9nkuxkjY2b7KQ1SNXuPZF9QzLQJMOX93lmQxZRoVL95CSDid9y9PzpZKKYyvc/pUzzHvx2sBHZIp9d975bQK83+IFzSMnEckf+QBmKNERto/00BDgHcgxMR11PlMRWhnMCr12jT0YOmzAqYbFb6LXbK6BKSI/RvM2TdDsviPHwxntIveYx1hWv7eVE1nQCWtk/mpetcfSje9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=er85W6RbKBJfguZ6mjWXiUhZ1rMRm17DBaYVyc4ZXbw=; b=igzZ3u0eS+cxx8svYpTe6XvS5oJ4bulgPc6qpaHbw3z2O/gwVUF2FwwtyYVXxn5yCRBhAyZKY05I+xCj/6iRuyameScEpSJGbXBmCehk7Oq4pDPTnp55zlRfYBrjK+gpHNnOOJv3QQKYq2YJ88JRIxL4sBd3AdG50xAl1sXKZ/o= Authentication-Results-Original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by AM6PR08MB4597.eurprd08.prod.outlook.com (2603:10a6:20b:90::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22; Mon, 4 Oct 2021 17:46:40 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::54b5:239d:9896:ee65]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::54b5:239d:9896:ee65%4]) with mapi id 15.20.4566.022; Mon, 4 Oct 2021 17:46:40 +0000 Subject: Re: [edk2-platforms][PATCH v3 1/5] MdeModulePkg: Allow dynamic generation of HEST ACPI table To: Omkar Anand Kulkarni , devel@edk2.groups.io Cc: Ard Biesheuvel , nd References: <20210824053403.24103-1-omkar.kulkarni@arm.com> <20210824053403.24103-2-omkar.kulkarni@arm.com> From: "Sami Mujawar" Message-ID: <260a125c-935a-e196-fb0e-f5c191426dec@arm.com> Date: Mon, 4 Oct 2021 18:46:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 In-Reply-To: <20210824053403.24103-2-omkar.kulkarni@arm.com> X-ClientProxiedBy: LO4P123CA0406.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::15) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 Received: from [10.1.196.43] (217.140.106.52) by LO4P123CA0406.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Mon, 4 Oct 2021 17:46:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e9810d1-bc3f-4337-32e6-08d9875ef58b X-MS-TrafficTypeDiagnostic: AM6PR08MB4597:|AM6PR08MB4950: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 8wPSH+vfWYOT5h9I+Zj/j9EoyU7GUmnFcm74wZIP3kMsvXHqZfqcWZp1p7dCUhpCbBUdBcgnkJmQznwWVy5m8VzGqGEVb9Y3b/kckXtLQxEhTKYMGKC9vn4GWGYMGFxukcvbquWlzBpjE5mjYOZy10sLECzkBkbkhVTP6BLKE5W+/4eQ1mmiUG+DQPK39AFE6LfdQv93bAiL6kGNpqeDGKZrRN6AjS3KyF62GJRaYHX0cK+ArR0yg0CSgiMFwFm7h4KQQky4PqkrfknloJ9oC9F29bGR1iiPLqJG21vfYlKdx6OyIyl39Z7x2P6sf6i+AN4ntTWjsxqGFpWXWqIdkE3jMqGMriRuO0RZUypxYTKZL7dg9yRpPM7LbayNe2hnKCR2kwL6JI4Vi1h+S5MXTXhcqf7/joDv7+TY6NpYOd75wQdOO/msGzQ40araQqPepSFn8m+BS341uOOQ6OtQQnjOOq6uCctG73xOmLwC/QAPUsHjzu5ybQMYWsVJ6RwgjnI09VtdMpYaciDEdUocJZ1vAblaZtKkGLFXp7q5WaQ6CZ2rzgNi70uQarectRVnfsx0BeCfAn1NPBkNqhDFYlM3pPfI0hqZvbe0Rgc7GMeHtG+X9WN2oAi/SpfSpMNeJHSBy0O32qGOE/Ap0fjQydDPaMnaSjaneli2GfutrWUyo9n/h/9QCFtYScgLZhVh/OXXyyUIhW/LBxuN+wB9DbQsVQzdKd8hZ2y7h6HcITsA2oAEHG6tPAwfmCvRSDB6JVlkiIYI3PYshp4qUUqCrA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(53546011)(33964004)(30864003)(52116002)(8936002)(36756003)(83380400001)(86362001)(5660300002)(38350700002)(38100700002)(508600001)(186003)(44832011)(66476007)(6486002)(66946007)(26005)(16576012)(66556008)(31696002)(2616005)(31686004)(4326008)(8676002)(2906002)(956004)(316002)(54906003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4597 Original-Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 700e76ff-c843-4389-7f84-08d9875eebd2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kZei3YCVUmO3jCONJ2WlZMDO+Uc7oLA+VBruQbuacDcJeM6DmcU/CL6HPKUOVJdfxvByJ+QvyEqrlvpbROZ/FtVpslIAkS7OurV2q5r4S6NlNZb5AlOBiXAyxumO9fCRrbOYhCu8fPA2wokdscvgm+iPj+jXLihKX6wrBWLy8ipWV1ndjU+K9XO4jc/yT7GTdx0y/URawCwI7PbdGkwo50D+J7Qbpm0uVvHVAMkcwfjAHwvVCdw5oEMhJEiJXknaFPtEKD0iEtNzPytWyxBACeTrUd0clKjPIwJFLTx7KzRcGP3YoSp9DyPHvmvdx5PC0pJXJI9TjXwWumWSqpPTIVjgtE46NZGLFDEeKYky7xMmlAV1FyTt9vqS6gW6u9ZqhaAm0P9jKxXfs8PWqD5F7nA3Y8NzJmqjGVkDa2Olo4bI4t0/8k7iwVga4PBk55T9C6KfMXzpJNxs1ksD2Jkw7IEPYcIA47ddRBh9fsfpodHZ9OBSbwpV93jRO0JQ9byRXFlh6QGN5wXNKp4XOPL15oTk3EdYg0ymOPN77YRAqExziMNAh0pHjEvSshcolzWRloO8zyTZ35Xh/znjoCOhMfhJgpjNd+eAZ479B6te58wy5dF7F51Mj3wcHjZXfvYKkl1jMLJ5gA8OC+wgOYHtG0LyQr7ffaxx/9AMLmk+flxqAl2xcrz9rzCc0eRGPL6XvPs2fopFMWJ7eZ8u2ruzI8e1yIDGUzeDkRZP8HKXHkU= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(54906003)(356005)(47076005)(8936002)(16576012)(81166007)(53546011)(44832011)(316002)(8676002)(4326008)(33964004)(26005)(82310400003)(36756003)(70206006)(6486002)(508600001)(36860700001)(336012)(70586007)(5660300002)(31696002)(186003)(2906002)(30864003)(956004)(2616005)(86362001)(83380400001)(31686004)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2021 17:46:56.5771 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e9810d1-bc3f-4337-32e6-08d9875ef58b X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4950 Content-Type: multipart/alternative; boundary="------------84B33D1625FF9BCF10AF3349" Content-Language: en-GB --------------84B33D1625FF9BCF10AF3349 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Omkar, Please find my feedback inline marked [SAMI]. Regards, Sami Mujawar On 24/08/2021 06:33 AM, Omkar Anand Kulkarni wrote: > Introduce the HEST table generation protocol that allows platforms to > build the table with multiple error source descriptors and install the > table. The protocol 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 install 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 > --- > MdeModulePkg/MdeModulePkg.dec | 3 + > MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf | 49 +++ > MdeModulePkg/Include/Protocol/HestTable.h | 71 +++++ > MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c | 318 ++++++++++++++++++++ > 4 files changed, 441 insertions(+) > > diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec > index ad84421cf3f7..2cb4ba69d6bf 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -663,6 +663,9 @@ > ## Include/Protocol/VariablePolicy.h > gEdkiiVariablePolicyProtocolGuid = { 0x81D1675C, 0x86F6, 0x48DF, { 0xBD, 0x95, 0x9A, 0x6E, 0x4F, 0x09, 0x25, 0xC3 } } > > + ## Arm Platform HEST table generation protocol > + gHestTableProtocolGuid = { 0x705bdcd9, 0x8c47, 0x457e, { 0xad, 0x0d, 0xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } } > + > [PcdsFeatureFlag] > ## Indicates if the platform can support update capsule across a system reset.

> # TRUE - Supports update capsule across a system reset.
> diff --git a/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf > new file mode 100644 > index 000000000000..91c7385bf7ff > --- /dev/null > +++ b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf > @@ -0,0 +1,49 @@ > +## @file > +# Dxe driver that creates and publishes the HEST table. > +# > +# This driver creates HEST header and provides protocol service to append > +# and install the HEST table. > +# > +# Copyright (c) 2020 - 2021, ARM Limited. All rights reserved. > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001A [SAMI] Use latest INF version. > + 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 [SAMI] Is SgiPlatform.dec, ArmPkg.dec and ArmPlatformPkg.dec needed here? > + > +[LibraryClasses] > + ArmLib [SAMI] Is ArmLib needed here? > + BaseMemoryLib > + DebugLib > + UefiDriverEntryPoint > + UefiLib > + > +[Protocols] > + gEfiAcpiTableProtocolGuid ## PROTOCOL ALWAYS_CONSUMED > + gHestTableProtocolGuid ## PRODUCES > + > +[FixedPcd] > + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId > + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision > + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId > + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision > + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId > + > +[Depex] > + TRUE > diff --git a/MdeModulePkg/Include/Protocol/HestTable.h b/MdeModulePkg/Include/Protocol/HestTable.h > new file mode 100644 > index 000000000000..3b2e1f7d9203 > --- /dev/null > +++ b/MdeModulePkg/Include/Protocol/HestTable.h [SAMI] Should this file be renamed to HestTableProtocol.h? > @@ -0,0 +1,71 @@ > +/** @file > + Builds and installs the HEST ACPI table. > + > + Define the protocol interface that allows HEST ACPI table to be created, > + populated with error record descriptions and installation of the HEST ACPI > + table. > + > + Copyright (c) 2020 - 2021, 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 HEST error source descriptor protocol service. > + > + Protocol service used to append newly collected error source descriptors to > + to an already created HEST table. > + > + @param[in] ErrorSourceDescriptorList List of Error Source Descriptors. > + @param[in] ErrorSourceDescriptorListSize Total Size of Error Source > + Descriptors. > + @param[in] ErrorSourceDescriptorCount Total count of error source > + descriptors. > + > + @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 > +**/ > +typedef > +EFI_STATUS > +(EFIAPI *APPEND_ERROR_SOURCE_DESCRIPTOR) ( > + IN CONST VOID *ErrorSourceDescriptorList, > + IN UINTN ErrorSourceDescriptorListSize, > + IN UINTN ErrorSourceDescriptorCount > + ); > + > +/** > + Install HEST table protocol service. > + > + Installs the HEST table that has been appended with the error source > + descriptors. The checksum of this table is calculated and updated in > + the table header. The HEST table is then installed. > + > + @retval EFI_SUCCESS HEST table is installed successfully. > + @retval EFI_ABORTED HEST table is NULL. > + @retval Other Install service call failed. > +**/ > +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; [SAMI] I think HEST_TABLE_PROTOCOL should be renamed toEDKII_HEST_TABLE_PROTOCOL. Similarly, the function pointers to the interfaces defined by the protocol should also be prefixed with EDKII_, e.g. EDKII_INSTALL_HEST_TABLE. [/SAMI] > + > +extern EFI_GUID gHestTableProtocolGuid; > +#endif // HEST_TABLE_H_ > diff --git a/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c > new file mode 100644 > index 000000000000..87f21acf61f4 > --- /dev/null > +++ b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c > @@ -0,0 +1,318 @@ > +/** @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 table to be installed. > + > + Copyright (c) 2020 - 2021, ARM Limited. All rights reserved. > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + @par Specification Reference: > + - ACPI 6.3, Table 18-382, Hardware Error Source Table > +**/ > + > +#include > +#include [SAMI] Do we need ArmLib.h here? > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +typedef struct { > + VOID *HestTable; /// Pointer to HEST table. > + UINT32 CurrentTableSize; /// Current size of HEST table. > +} HEST_DXE_DRIVER_DATA; > + > +STATIC EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL; > +STATIC HEST_DXE_DRIVER_DATA mHestDriverData; > + > +/** > + Allocate memory for the HEST table header and populate it. > + > + Helper function for this driver, populates the HEST table header. Called once > + in the beginning on first invocation of append error source descriptor > + protocol service. > + > + @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; > + > + // > + // Allocate memory for the HEST table header. > + // > + mHestDriverData.HestTable = > + AllocateZeroPool (sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER)); > + if (mHestDriverData.HestTable == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + mHestDriverData.CurrentTableSize = > + sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER); > + > + HestHeader = (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *) > + mHestDriverData.HestTable; > + > + // > + // Populate the values of the HEST 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) > + ); > + HestHeader->Header.OemTableId = FixedPcdGet64 (PcdAcpiDefaultOemTableId); > + HestHeader->Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision); > + HestHeader->Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId); > + HestHeader->Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision); > + HestHeader->ErrorSourceCount = 0; > + > + return EFI_SUCCESS; > +} > + > +/** > + Append HEST error source descriptor protocol service. > + > + Protocol service used to append newly collected error source descriptors to > + to an already created HEST table. > + > + @param[in] ErrorSourceDescriptorList List of Error Source Descriptors. > + @param[in] ErrorSourceDescriptorListSize Total Size of Error Source > + Descriptors. > + @param[in] ErrorSourceDescriptorCount Total count of error source > + descriptors. > + > + @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 > +**/ > +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, > + "%a: Failed to build HEST header, status: %r\n", > + __FUNCTION__, > + Status > + )); > + return Status; > + } > + } > + > + // > + // Resize the existing HEST table buffer to accommodate the incoming error > + // source descriptors. > + // > + NewTableSize = mHestDriverData.CurrentTableSize + > + ErrorSourceDescriptorListSize; > + mHestDriverData.HestTable = ReallocatePool ( > + mHestDriverData.CurrentTableSize, > + NewTableSize, > + mHestDriverData.HestTable > + ); [SAMI] I think a Linked list based implementation should be used here, instead of using ReallocatePool. This should not be too complicated as the HEST_TABLE_PROTOCOL design already makes this easy. The AppendErrorSourceDescriptor() interface should probably be renamed to AddErrorSourceDescriptor() and can be used to collect the error source information and add it to a LinkedList. The InstallHestTable() can iterate the linked list to collect the error sources and publist the ACPI table. Also, there is a LinkedList implementation in edk2\MdePkg\BaseLib\LinkedList.c that can be used. [/SAMI] > + if (mHestDriverData.HestTable == NULL) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to reallocate memory for HEST table\n", > + __FUNCTION__ > + )); > + 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 table protocol service. > + > + Installs the HEST table that has been appended with the error source > + descriptors. The checksum of this table is calculated and updated in > + the table header. The HEST table is then installed. > + > + @retval EFI_SUCCESS HEST table is installed successfully. > + @retval EFI_ABORTED HEST table is NULL. > + @retval Other Install service call 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 not, there no hardware error > + // sources supported by the platform and no HEST table to publish, return. > + // > + if (mHestDriverData.HestTable == NULL) { > + DEBUG (( > + DEBUG_INFO, > + "HestDxe: No data available to generate HEST table\n" > + )); > + return EFI_NOT_FOUND; > + } > + > + // > + // 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; > + > + Status = mAcpiTableProtocol->InstallAcpiTable ( > + mAcpiTableProtocol, > + HestHeader, > + HestHeader->Header.Length, > + &AcpiTableHandle > + ); > + if (EFI_ERROR (Status)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: HEST table installation failed, status: %r\n", > + __FUNCTION__, > + Status > + )); > + return Status; [SAMI] There would be a memory leak here as mHestDriverData.HestTableis not freed. So just remove the return statement from here. > + } > + > + // > + // Free the HEST table buffer. > + // > + FreePool (mHestDriverData.HestTable); > + DEBUG (( > + DEBUG_INFO, > + "HestDxe: Installed HEST table \n" > + )); > + return Status; > +} > + > +// > +// 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, > + "%a: Failed to locate ACPI table protocol, status: %r\n", > + __FUNCTION__, > + Status > + )); > + return Status; > + } > + > + Status = gBS->InstallProtocolInterface ( > + &Handle, > + &gHestTableProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mHestProtocol > + ); > + if (EFI_ERROR (Status)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to install HEST table generation protocol status: %r\n", > + __FUNCTION__, > + Status > + )); > + return Status; [SAMI] This return statement can be removed as there is already one at the end of the function. > + } > + > + return Status; > +} --------------84B33D1625FF9BCF10AF3349 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Omkar,

Please find my feedback inline marked [SAMI].

Regards,

Sami Mujawar


On 24/08/2021 06:33 AM, Omkar Anand Kulkarni wrote:
Introduce the HEST table generation protocol that allows platforms to
build the table with multiple error source descriptors and install the
table. The protocol 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 install 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>
---
 MdeModulePkg/MdeModulePkg.dec                   |   3 +
 MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf |  49 +++
 MdeModulePkg/Include/Protocol/HestTable.h       |  71 +++++
 MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c   | 318 ++++++++++++++++++++
 4 files changed, 441 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index ad84421cf3f7..2cb4ba69d6bf 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -663,6 +663,9 @@
   ## Include/Protocol/VariablePolicy.h
   gEdkiiVariablePolicyProtocolGuid = { 0x81D1675C, 0x86F6, 0x48DF, { 0xBD, 0x95, 0x9A, 0x6E, 0x4F, 0x09, 0x25, 0xC3 } }
 
+  ## Arm Platform HEST table generation protocol
+  gHestTableProtocolGuid = { 0x705bdcd9, 0x8c47, 0x457e, { 0xad, 0x0d, 0xf7, 0x86, 0xf3, 0x4a, 0x0d, 0x63 } }
+
 [PcdsFeatureFlag]
   ## Indicates if the platform can support update capsule across a system reset.<BR><BR>
   #   TRUE  - Supports update capsule across a system reset.<BR>
diff --git a/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf
new file mode 100644
index 000000000000..91c7385bf7ff
--- /dev/null
+++ b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.inf
@@ -0,0 +1,49 @@
+## @file
+#  Dxe driver that creates and publishes the HEST table.
+#
+#  This driver creates HEST header and provides protocol service to append
+#  and install the HEST table.
+#
+#  Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
[SAMI] Use latest INF version.
+  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
[SAMI] Is SgiPlatform.dec, ArmPkg.dec and ArmPlatformPkg.dec needed here?
+
+[LibraryClasses]
+  ArmLib
[SAMI] Is ArmLib needed here?
+  BaseMemoryLib
+  DebugLib
+  UefiDriverEntryPoint
+  UefiLib
+
+[Protocols]
+  gEfiAcpiTableProtocolGuid         ## PROTOCOL ALWAYS_CONSUMED
+  gHestTableProtocolGuid            ## PRODUCES
+
+[FixedPcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId
+
+[Depex]
+  TRUE
diff --git a/MdeModulePkg/Include/Protocol/HestTable.h b/MdeModulePkg/Include/Protocol/HestTable.h
new file mode 100644
index 000000000000..3b2e1f7d9203
--- /dev/null
+++ b/MdeModulePkg/Include/Protocol/HestTable.h
[SAMI] Should this file be renamed to HestTableProtocol.h?
@@ -0,0 +1,71 @@
+/** @file
+  Builds and installs the HEST ACPI table.
+
+  Define the protocol interface that allows HEST ACPI table to be created,
+  populated with error record descriptions and installation of the HEST ACPI
+  table.
+
+  Copyright (c) 2020 - 2021, 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 HEST error source descriptor protocol service.
+
+  Protocol service used to append newly collected error source descriptors to
+  to an already created HEST table.
+
+  @param[in]  ErrorSourceDescriptorList      List of Error Source Descriptors.
+  @param[in]  ErrorSourceDescriptorListSize  Total Size of Error Source
+                                             Descriptors.
+  @param[in]  ErrorSourceDescriptorCount     Total count of error source
+                                             descriptors.
+
+  @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
+**/
+typedef
+EFI_STATUS
+(EFIAPI *APPEND_ERROR_SOURCE_DESCRIPTOR) (
+  IN CONST VOID *ErrorSourceDescriptorList,
+  IN UINTN      ErrorSourceDescriptorListSize,
+  IN UINTN      ErrorSourceDescriptorCount
+  );
+
+/**
+  Install HEST table protocol service.
+
+  Installs the HEST table that has been appended with the error source
+  descriptors. The checksum of this table is calculated and updated in
+  the table header. The HEST table is then installed.
+
+  @retval  EFI_SUCCESS  HEST table is installed successfully.
+  @retval  EFI_ABORTED  HEST table is NULL.
+  @retval  Other        Install service call failed.
+**/
+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;
[SAMI] I think HEST_TABLE_PROTOCOL  should be renamed to EDKII_HEST_TABLE_PROTOCOL.
Similarly, the function pointers to the interfaces defined by the protocol should also be prefixed with EDKII_, e.g. EDKII_INSTALL_HEST_TABLE.
[/SAMI]
+
+extern EFI_GUID gHestTableProtocolGuid;
+#endif  // HEST_TABLE_H_
diff --git a/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c
new file mode 100644
index 000000000000..87f21acf61f4
--- /dev/null
+++ b/MdeModulePkg/Universal/Apei/HestDxe/HestDxe.c
@@ -0,0 +1,318 @@
+/** @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 table to be installed.
+
+  Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+    - ACPI 6.3, Table 18-382, Hardware Error Source Table
+**/
+
+#include <IndustryStandard/Acpi.h>
+#include <Library/ArmLib.h>
[SAMI] Do we need ArmLib.h here?
+#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 table.
+  UINT32 CurrentTableSize;  /// Current size of HEST table.
+} HEST_DXE_DRIVER_DATA;
+
+STATIC EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;
+STATIC HEST_DXE_DRIVER_DATA mHestDriverData;
+
+/**
+  Allocate memory for the HEST table header and populate it.
+
+  Helper function for this driver, populates the HEST table header. Called once
+  in the beginning on first invocation of append error source descriptor
+  protocol service.
+
+  @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;
+
+  //
+  // Allocate memory for the HEST table header.
+  //
+  mHestDriverData.HestTable =
+    AllocateZeroPool (sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER));
+  if (mHestDriverData.HestTable == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  mHestDriverData.CurrentTableSize =
+    sizeof (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER);
+
+  HestHeader = (EFI_ACPI_6_3_HARDWARE_ERROR_SOURCE_TABLE_HEADER *)
+                  mHestDriverData.HestTable;
+
+  //
+  // Populate the values of the HEST 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)
+    );
+  HestHeader->Header.OemTableId = FixedPcdGet64 (PcdAcpiDefaultOemTableId);
+  HestHeader->Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
+  HestHeader->Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
+  HestHeader->Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
+  HestHeader->ErrorSourceCount = 0;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Append HEST error source descriptor protocol service.
+
+  Protocol service used to append newly collected error source descriptors to
+  to an already created HEST table.
+
+  @param[in]  ErrorSourceDescriptorList      List of Error Source Descriptors.
+  @param[in]  ErrorSourceDescriptorListSize  Total Size of Error Source
+                                             Descriptors.
+  @param[in]  ErrorSourceDescriptorCount     Total count of error source
+                                             descriptors.
+
+  @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
+**/
+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,
+        "%a: Failed to build HEST header, status: %r\n",
+        __FUNCTION__,
+        Status
+        ));
+      return Status;
+    }
+  }
+
+  //
+  // Resize the existing HEST table buffer to accommodate the incoming error
+  // source descriptors.
+  //
+  NewTableSize = mHestDriverData.CurrentTableSize +
+                 ErrorSourceDescriptorListSize;
+  mHestDriverData.HestTable = ReallocatePool (
+                                mHestDriverData.CurrentTableSize,
+                                NewTableSize,
+                                mHestDriverData.HestTable
+                                );
[SAMI] I think a Linked list based implementation should be used here, instead of using ReallocatePool. This should not be too complicated as the HEST_TABLE_PROTOCOL design already makes this easy. The AppendErrorSourceDescriptor() interface should probably be renamed to AddErrorSourceDescriptor() and can be used to collect the error source information and add it to a LinkedList. The InstallHestTable() can iterate the linked list to collect the error sources and publist the ACPI table. Also, there is a LinkedList implementation in edk2\MdePkg\BaseLib\LinkedList.c that can be used.
 [/SAMI]
+  if (mHestDriverData.HestTable == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to reallocate memory for HEST table\n",
+      __FUNCTION__
+      ));
+    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 table protocol service.
+
+  Installs the HEST table that has been appended with the error source
+  descriptors. The checksum of this table is calculated and updated in
+  the table header. The HEST table is then installed.
+
+  @retval  EFI_SUCCESS  HEST table is installed successfully.
+  @retval  EFI_ABORTED  HEST table is NULL.
+  @retval  Other        Install service call 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 not, there no hardware error
+  // sources supported by the platform and no HEST table to publish, return.
+  //
+  if (mHestDriverData.HestTable == NULL) {
+    DEBUG ((
+      DEBUG_INFO,
+      "HestDxe: No data available to generate HEST table\n"
+      ));
+    return EFI_NOT_FOUND;
+  }
+
+  //
+  // 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;
+
+  Status = mAcpiTableProtocol->InstallAcpiTable (
+                                 mAcpiTableProtocol,
+                                 HestHeader,
+                                 HestHeader->Header.Length,
+                                 &AcpiTableHandle
+                                 );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: HEST table installation failed, status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
[SAMI] There would be a memory leak here as mHestDriverData.HestTableis not freed. So just remove the return statement from here.
+  }
+
+  //
+  // Free the HEST table buffer.
+  //
+  FreePool (mHestDriverData.HestTable);
+  DEBUG ((
+    DEBUG_INFO,
+    "HestDxe: Installed HEST table \n"
+    ));
+  return Status;
+}
+
+//
+// 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,
+      "%a: Failed to locate ACPI table protocol, status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
+  }
+
+  Status = gBS->InstallProtocolInterface (
+                  &Handle,
+                  &gHestTableProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  &mHestProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to install HEST table generation protocol status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
[SAMI] This return statement can be removed as there is already one at the end of the function.
+  }
+
+  return Status;
+}

--------------84B33D1625FF9BCF10AF3349--