From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.53]) by mx.groups.io with SMTP id smtpd.web11.13408.1633369644475975144 for ; Mon, 04 Oct 2021 10:47:25 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=BEk3jSBU; spf=pass (domain: arm.com, ip: 40.107.7.53, 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=YMevtTxtXQY4moEzMjAMm/jO2YFycxLO1cG060RuWuk=; b=BEk3jSBU73wJMX+ff843nrXtUiIGyrto8K8rt2Mh3ASweTpgrtlDkXi/mf0hQkM6tLhUTo4fPY/+GiaotKywugQASJ2C3/4MH72Jr2Lf2tQUPN7Rs/Dsr4PUoJgw9sO9iA8Vj+GyIsCRXsBPE26T08thUnAkQb9XQu8IYd8Njvo= Received: from DB7PR02CA0023.eurprd02.prod.outlook.com (2603:10a6:10:52::36) by DB6PR0802MB2311.eurprd08.prod.outlook.com (2603:10a6:4:87::22) 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:47:20 +0000 Received: from DB5EUR03FT052.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:52:cafe::26) by DB7PR02CA0023.outlook.office365.com (2603:10a6:10:52::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13 via Frontend Transport; Mon, 4 Oct 2021 17:47:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.33.187.114) 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.33.187.114 as permitted sender) receiver=protection.outlook.com; client-ip=63.33.187.114; helo=64aa7808-outbound-2.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-2.mta.getcheckrecipient.com (63.33.187.114) by DB5EUR03FT052.mail.protection.outlook.com (10.152.21.82) 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:47:20 +0000 Received: ("Tessian outbound 173d710607ad:v103"); Mon, 04 Oct 2021 17:47:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f23b03c83635096e X-CR-MTA-TID: 64aa7808 Received: from 31d137376b3c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C69B7379-790F-4F69-B615-E2F3FC5CD57E.1; Mon, 04 Oct 2021 17:47:09 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 31d137376b3c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 04 Oct 2021 17:47:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vnt6o3ri1tKspPUo4bFP2ZooX/D6NMCqVb9PWSoiBgi0VyMLDBi+MfRQ+2FB+TtSM1fDtUBhrb1j0o9PPe1v4hOTR6h3pgEwGJUbDydhAWa0DDrGEaRFATiiB7w4mNfuZEU2kBp5Ll7oOiI4v7vo91oTUbcJmFQ7xNByKnhhBYOwudusO71kqhykkun9gIacAWTJDSaANDmVQjD8KOlNgQPbfis74Q5/68OQVKACul2O0rChCcoICMBpGLovFzeJpmoZUC1LMGBobB+SlCMWRuVDngx+TbS0+PWyQEEvj/dJAZ6LqdFIjSVQ3LVg2d2dExhQxhajlzor6Yp4sm3s0A== 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=YMevtTxtXQY4moEzMjAMm/jO2YFycxLO1cG060RuWuk=; b=hyHtvtVmNjtqiKovMlrB6GO0TzrjaQPSdThjNKWrpvYIabxDLRhE6owsDd/RP0ixy6huLmYWZl4/REeZGGlG7/6+COVX7y0cxk/Zyj3TR3nU8WoWI8clhfuDdcVF/pfA7OnTDEajVbYNereIVVRDb5sUR/Xlsk9IREPyFI2R1dnZ5QTk1Mg8un5wIp3vdBGxx2dD/7SHSOqkdXI40iYcf7dEJyzJa+llKpTNAUqvXnyKBTmm3XcMnzmDGb5F6hg4O+slUrMbgJdxtyiisvRzjC5udsAsTaE1WxCKCod8NkTUn5ylJWajnDG0lfgfJnVTGzuHBRgkctm+tDJ5Naxjvg== 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=YMevtTxtXQY4moEzMjAMm/jO2YFycxLO1cG060RuWuk=; b=BEk3jSBU73wJMX+ff843nrXtUiIGyrto8K8rt2Mh3ASweTpgrtlDkXi/mf0hQkM6tLhUTo4fPY/+GiaotKywugQASJ2C3/4MH72Jr2Lf2tQUPN7Rs/Dsr4PUoJgw9sO9iA8Vj+GyIsCRXsBPE26T08thUnAkQb9XQu8IYd8Njvo= 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 AM5PR0801MB1715.eurprd08.prod.outlook.com (2603:10a6:203:3c::10) 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:47:06 +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:47:06 +0000 Subject: Re: [edk2-platforms][PATCH v3 3/5] ArmPlatformPkg: retreive error source descriptors from MM To: Omkar Anand Kulkarni , devel@edk2.groups.io Cc: Ard Biesheuvel , nd References: <20210824053403.24103-1-omkar.kulkarni@arm.com> <20210824053403.24103-4-omkar.kulkarni@arm.com> From: "Sami Mujawar" Message-ID: <9da53ed1-e933-a149-5510-2421dbf89db3@arm.com> Date: Mon, 4 Oct 2021 18:47:09 +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-4-omkar.kulkarni@arm.com> X-ClientProxiedBy: LO2P265CA0506.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::13) 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 LO2P265CA0506.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.22 via Frontend Transport; Mon, 4 Oct 2021 17:47:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cba4314c-5592-4ba3-1cd0-08d9875f0393 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1715:|DB6PR0802MB2311: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:1265;OLM:1265; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: UC433yOyOac6aR2ONUuQ6daI1nhnDq9x2dDaKfcbES13D1OfH7JW7HfgMtsuFC9ZAXiObkKfxnM1/mdPullPochhcfFf3f2nyhrfinwSE4U+A57yTWuaQICMPWem5cxj89nZyVArwn7yXoBfS1tt9w1ge9IDzsucVHDLFGkYtMvM6YnadIL4TX1PQOvkDX+A3btwRV2aRA1ocNrbqLQZDO0+7tu6lx9GZeaWv2orXcL5Nutnlktzer2SVsBCmz9OPvAMGY3DJlOKzCrBWp51SKcZRariU9vi/CrfdrynpacuSlNxcM2Y4OYD7/L34f95XrlUP76fo5bKPeWHSdhWEDuhadxBKYseVXEh7LOmZvK4izyl6LATQwEfk8ALG9iD9Rtt8Fp75l9xwEEnNcdJOCHzvTv9OCNRMBSY9IvV5ll42FJamy65o+rwdt6j6E8mIv7N7/GbipUaomyTjPC/6hjFuAA0JibeLOHhZwmtUuH9WRhqwXqYp1dSgjrVymsCtIHOyFskiZz27PxsNNgon4FAhtDlM8KO1gtxDMGj4eucjtTOf5R7qONyvQoTLVVfmB7LCn86zLtKiWgep7KVzqiC/e8vSnX7u+FPfH5EWWZLVW54hFG8+LdstORVw6OvSB63pEzu/m5CLxyPUjUUCTB2xTkE8q0iIxY2YdQaS5EWPUAX9v0QKi7jNspDySZrmf6dZMD5BbBaJ020gIccbWIpQLEie3J95bNTHmgiQL23cTN+E7BKJidR0YlfXkWznd5R6WvBg7eGL6Ii7bTj3g== 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)(6486002)(86362001)(508600001)(316002)(31696002)(54906003)(66556008)(66476007)(83380400001)(38350700002)(38100700002)(16576012)(30864003)(2616005)(31686004)(956004)(5660300002)(8936002)(8676002)(4326008)(53546011)(33964004)(66946007)(52116002)(186003)(26005)(2906002)(19627235002)(44832011)(36756003)(45980500001)(43740500002)(559001)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1715 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: DB5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: e955857a-3adc-4081-e12c-08d9875efb10 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b95xC8R0jP3zTK/Z9m0gXmhmZX+KM9mZcqpGK7zPKqthTR5IcVyDK9mhaHYnTkFI4ceHIDnqH0vWi/qd8o9DzuzXcg9oVTjTJNwk0cSPpX3DjAkpO73ImbYkKS0C3N2B7tSV+l8NXPoPVdathD6+/DwGsGu2BD2Du5dSvrhG7YxCa2gLX00/wV/ykixEMx0wTaYivg0bINLpPgTK2mNCnEaIlIondNXB/sYk9WTh9BIH3TsC144ygLINJG/HCaTLFUSBY3i+Qupmf0dxsap+RwC0qywLxDidr2voZMEGQADviTEf/AohZZGWC/O7vKnQgrZUqKrMIs3EFlJXfkY3LScwI8mDeMhTZBWD4/On80CaHE6OW/mKwwJmd2snANfhCEU47Fxi4MkBYrW0UmlsD4XcNV03u69hCALFyfv79kqpecVUo8Pf5By7ZeqUwzd9F0jLhIQhhBYeSXEnkvyofteKtp5xQKnlnGNVSNY7j1FTspEGHesw1gSbok6LzF5RMkxBD3uT2M0E+pvWy0ACEJIZ0E47CrXI0Ru7QsbWqheFv7d0y6yBiNqdV7u3fwD/5f/Z+5QF0QeKJVB+4azOBRLx/NF0ycELxc4FeJ2akqgaMTmfMEHfznNqe0cehWCLg34MA8yeC16fpC/CK0jv3EzrTbrHZU9iYdDo/8pRS1k8sS12TmhzjfSVyRTbu0MdyNSf/15v3vKduq5NecpKbc0VO1URlhXElXNFHLywP5s= X-Forefront-Antispam-Report: CIP:63.33.187.114;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-2.mta.getcheckrecipient.com;PTR:ec2-63-33-187-114.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(33964004)(356005)(8936002)(53546011)(81166007)(8676002)(44832011)(86362001)(70206006)(26005)(70586007)(82310400003)(36860700001)(31696002)(508600001)(336012)(316002)(30864003)(5660300002)(956004)(2616005)(16576012)(31686004)(36756003)(186003)(83380400001)(47076005)(4326008)(6486002)(2906002)(54906003)(19627235002)(43740500002)(579004)(559001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2021 17:47:20.1091 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cba4314c-5592-4ba3-1cd0-08d9875f0393 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.33.187.114];Helo=[64aa7808-outbound-2.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2311 Content-Type: multipart/alternative; boundary="------------DC89725EAD233D8E67B33739" Content-Language: en-GB --------------DC89725EAD233D8E67B33739 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Omkar, Please find my response inline marked [SAMI]. Regards, Sami Mujawar On 24/08/2021 06:34 AM, Omkar Anand Kulkarni wrote: > 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 | 45 +++ > ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf | 51 ++++ > ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h | 37 +++ > MdePkg/Include/Protocol/MmCommunication.h | 2 + [SAMI] I think this patch needs to be split as MmCommunication.h is from MdePkg while all other files are in ArmPlatformPkg. > ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c | 309 +++++++++++++++++++ > ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c | 312 ++++++++++++++++++++ > 7 files changed, 763 insertions(+) > > diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatformPkg.dec > index 446d93b880f9..a400f175726e 100644 > --- a/ArmPlatformPkg/ArmPlatformPkg.dec > +++ b/ArmPlatformPkg/ArmPlatformPkg.dec > @@ -52,6 +52,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 > @@ -128,5 +130,10 @@ > > gArmPlatformTokenSpaceGuid.PcdWatchdogCount|0x0|UINT32|0x00000033 > > +[PcdsFixedAtBuild, PcdsPatchableInModule] > + ## ACPI CPER memory space > + gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferBase|0x00000000|UINT64|0x00000046 > + gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferSize|0x00000000|UINT64|0x00000047 > + > [Protocols.common] > gMmHestErrorSourceDescProtocolGuid = { 0x560bf236, 0xa4a8, 0x4d69, { 0xbc, 0xf6, 0xc2, 0x97, 0x24, 0x10, 0x9d, 0x91 } } > diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf > new file mode 100644 > index 000000000000..b16ff2353aa5 > --- /dev/null > +++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf > @@ -0,0 +1,45 @@ > +## @file > +# DXE driver to get secure error sources. > +# > +# DXE driver to retrieve the error source descriptors from Standalone MM and > +# append those to 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 = 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 > + MdeModulePkg/MdeModulePkg.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..9d566de9bec3 > --- /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 - 2021, ARM Limited. All rights reserved. > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001A [SAMI] Use latest INF version. > + 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] > + TRUE > diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h > new file mode 100644 > index 000000000000..6ddc6bd21922 > --- /dev/null > +++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h > @@ -0,0 +1,37 @@ > +/** @file > + Data structures for error source descriptor information. > + > + This data structure forms the CommBuffer part of the MM Communication > + protocol used for communicating the Hardware Error sources form MM to > + Non-MM environment. > + > + Copyright (c) 2020 - 2021, 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/MdePkg/Include/Protocol/MmCommunication.h b/MdePkg/Include/Protocol/MmCommunication.h > index 34c3e2b5a9e3..acde54971fd9 100644 > --- a/MdePkg/Include/Protocol/MmCommunication.h > +++ b/MdePkg/Include/Protocol/MmCommunication.h > @@ -12,6 +12,8 @@ > #ifndef _MM_COMMUNICATION_H_ > #define _MM_COMMUNICATION_H_ > > +#define MM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data)) > + > #pragma pack(1) > > /// > diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c > new file mode 100644 > index 000000000000..28de8daf2f5e > --- /dev/null > +++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c > @@ -0,0 +1,309 @@ > +/** @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. > + > + This driver collects the secure error source descriptor information from the > + MM drviers that implement HEST error source protocol. Instead of directly > + communicating with the individual MM drivers, it calls into > + HestErrorSourceStandaloneMM driver which is a gatway MM driver. This MM driver > + in-turn communicates with individual MM drivers collecting the error source > + descriptor information. > + > + Once all the error source descriptor information is retrieved the driver > + appends the descriptors to HEST table using the HestDxe driver. > + > + Copyright (c) 2020 - 2021, ARM Limited. All rights reserved. > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "HestMmErrorSourceCommon.h" > + > +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; > + [SAMI] It may be good to add a check to see if CommBuffSize is at least the minimum required size. > + // > + // 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, > + NULL, > + (VOID *)*CommBuffer, > + NULL > + ); > + [SAMI] Unless you intend to assert or log the status code you could directly return the value returned by mMmCommunication2->Communicate(). > + 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; > + > + // > + // Retrieve the count, length and the actual eror source descriptors from > + // the MM drivers. Do this by performing two MM Communicate calls, in the > + // first call pass CommBuffer which is atleast of the size of error source > + // descriptor info structure. Followed by another communicate call with > + // CommBuffer allocated to required buffer size to hold all descriptors. > + // > + // Allocate CommBuffer atleast the size of error source descriptor info > + // structure. > + CommBufferSize = > + MM_COMMUNICATE_HEADER_SIZE + HEST_ERROR_SOURCE_DESC_INFO_SIZE; > + CommunicationHeader = AllocateZeroPool (CommBufferSize); > + if (CommunicationHeader == NULL) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to allocate memory for CommunicationHeader\n", > + __FUNCTION__ > + )); > + return EFI_OUT_OF_RESOURCES; > + } > + > + // > + // Make the first MM Communicate call to HestErrorSourceStandaloneMM gateway > + // driver, which returns the required buffer size adequate to hold all the > + // desctriptor information. > + // > + Status = GetErrorSourceDescriptors (CommBufferSize, &CommunicationHeader); > + if ((EFI_ERROR (Status)) && > + (Status != EFI_BUFFER_TOO_SMALL)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: MM Communicate protocol call failed, status: %r\n", > + __FUNCTION__, > + 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, > + "HesErrorSourceDxe: HEST error source(s) not found\n" > + )); > + FreePool (CommunicationHeader); > + return EFI_NOT_FOUND; > + } > + > + // > + // 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 = AllocateZeroPool (CommBufferSize); > + if (CommunicationHeader == NULL) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to allocate memory for CommunicationHeader\n", > + __FUNCTION__ > + )); > + return EFI_OUT_OF_RESOURCES; > + } > + > + // > + // Make second MM Communicate call to HestErrorSourceStandaloneMM driver to > + // get the error source descriptors from the MM drivers. > + // > + Status = GetErrorSourceDescriptors (CommBufferSize, &CommunicationHeader); > + if (EFI_ERROR (Status)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: MM Communicate protocol failed, status: %r\n", > + __FUNCTION__, > + 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, > + "HestErrorSourceDxe: Error source descriptor list is empty" > + )); > + FreePool (CommunicationHeader); > + return EFI_NOT_FOUND; > + } > + > + DEBUG (( > + DEBUG_INFO, > + "HestErrorSourceDxe: 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, > + "%a: Failed to append error source(s), status: %r\n", > + __FUNCTION__, > + 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, > + "%a: Failed to locate HEST table generation protocol, status:%r\n", > + __FUNCTION__, > + Status > + )); > + return Status; > + } > + > + Status = gBS->LocateProtocol ( > + &gEfiMmCommunication2ProtocolGuid, > + NULL, > + (VOID **)&mMmCommunication2 > + ); > + if (EFI_ERROR (Status)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to locate MMCommunication2 driver protocol, status:%r\n", > + __FUNCTION__, > + 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, > + "%a: Failed appending error source desc to HEST table, status:%r\n", > + __FUNCTION__, > + Status > + )); > + } > + return EFI_SUCCESS; > +} > diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c > new file mode 100644 > index 000000000000..75dc31438180 > --- /dev/null > +++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c > @@ -0,0 +1,312 @@ > +/** @file > + MM HEST error source gateway driver. > + > + This MM 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. > + > + The MM driver acts as a single point of contact to collect secure hardware > + error sources from the MM drivers. It loops over all the MM drivers that > + implement HEST error source descriptor protocol and collects error source > + descriptor information along with the error source count and length. > + > + Copyright (c) 2020 - 2021, 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 = 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, > + "%a: No implementation of MmHestErrorSourceDescProtocol found, \ > + Status:%r\n", > + __FUNCTION__, > + 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 that > + is 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. > + > + @retval EFI_SUCCESS CommBuffer has valid data. > + @retval EFI_BAD_BUFFER_SIZE CommBufferSize not adequate. [SAMI] I think this should be EFI_BUFFER_TOO_SMALL, right? > + @retval 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 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) { > + // > + // Ensures that the communication buffer has enough space to atleast hold > + // the ErrSourceDescCount and ErrSourceDescSize elements of the > + // HEST_ERROR_SOURCE_DESC_INFO structure. > + // > + DEBUG (( > + DEBUG_ERROR, > + "%a: Invalid CommBufferSize parameter\n", > + __FUNCTION__ > + )); > + return EFI_INVALID_PARAMETER; [SAMI] I don't understand why this check is needed. Can you explain, please? > + } > + > + // > + // 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 = AllocateZeroPool (HandleBufferSize); > + if (HandleBuffer == NULL) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to allocate memory for HandleBuffer\n", > + __FUNCTION__ > + )); > + 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. > + // > + // This loop collects and adds the length of error source descriptors and > + // its count from all the the MM drivers implementing HEST error source. > + // descriptor protocol. The total length and count values retrieved help > + // to determine weather the CommBuffer is big enough to hold the descriptor > + // information. > + // As mentioned in the HEST error source descriptor protocol definition, > + // Buffer parameter set to NULL ensures only length and the count values > + // are returned from the driver and no error source information is copied to > + // Buffer. > + // > + 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. > + // [SAMI] The SourceLength and SourceCount variables must be initialised to 0 here. > + Status = HestErrSourceDescProtocolHandle->GetHestErrorSourceDescriptors ( > + HestErrSourceDescProtocolHandle, > + NULL, > + &SourceLength, > + &SourceCount > + ); > + if (Status == EFI_INVALID_PARAMETER) { [SAMI] Please see my earlier comment. EFI_INVALID_PARAMETER is not the correct value to be returned here. It should beEFI_BUFFER_TOO_SMALL. > + 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) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Invalid CommBufferSize parameter\n", > + __FUNCTION__ > + )); > + FreePool (HandleBuffer); > + return EFI_BUFFER_TOO_SMALL; [SAMI] If EFI_BUFFER_TOO_SMALL is returned it is expected that the caller will be provided with information on the size of the buffer required. However, that does not seem to be the case here as CommBufferSize is not an OUT parameter. If this is an unrecoverable error, or if the caller is not expected to probe the size then the return code should be EFI_BAD_BUFFER_SIZE and my comment in the function documentation header can be ignored. Can you check what is should happen here, please? [/SAMI] > + } > + > + // > + // CommBuffer size is adequate to return all the error source descriptors. > + // So go ahead and 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 information. > + // > + // Calls into each MM driver that implement the HEST error source descriptor > + // protocol. Here the Buffer parameter passed to the protocol service is > + // valid. So the MM driver when called copies the descriptor information. > + // > + 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) { [SAMI] if (!EFI_ERROR (Status)) ? > + ErrorSourcePtr += SourceLength; > + } > + } > + > + // Free the buffer holding all the protocol handles. > + FreePool (HandleBuffer); > + > + return Status; > +} > + > +/** > + 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, > + "%a: Mmi handler registration failed with status : %r\n", > + __FUNCTION__, > + Status > + )); > + return Status; [SAMI] This return statment can be removed. > + } > + > + return Status; > +} --------------DC89725EAD233D8E67B33739 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Omkar,

Please find my response inline marked [SAMI].

Regards,

Sami Mujawar

On 24/08/2021 06:34 AM, Omkar Anand Kulkarni wrote:
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          |  45 +++
 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.inf |  51 ++++
 ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h       |  37 +++
 MdePkg/Include/Protocol/MmCommunication.h                                 |   2 +
[SAMI] I think this patch needs to be split as MmCommunication.h is from MdePkg while all other files are in ArmPlatformPkg.
 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c            | 309 +++++++++++++++++++
 ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c   | 312 ++++++++++++++++++++
 7 files changed, 763 insertions(+)

diff --git a/ArmPlatformPkg/ArmPlatformPkg.dec b/ArmPlatformPkg/ArmPlatformPkg.dec
index 446d93b880f9..a400f175726e 100644
--- a/ArmPlatformPkg/ArmPlatformPkg.dec
+++ b/ArmPlatformPkg/ArmPlatformPkg.dec
@@ -52,6 +52,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
@@ -128,5 +130,10 @@
 
   gArmPlatformTokenSpaceGuid.PcdWatchdogCount|0x0|UINT32|0x00000033
 
+[PcdsFixedAtBuild, PcdsPatchableInModule]
+  ## ACPI CPER memory space
+  gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferBase|0x00000000|UINT64|0x00000046
+  gArmPlatformTokenSpaceGuid.PcdGhesGenericErrorDataMmBufferSize|0x00000000|UINT64|0x00000047
+
 [Protocols.common]
   gMmHestErrorSourceDescProtocolGuid = { 0x560bf236, 0xa4a8, 0x4d69, { 0xbc, 0xf6, 0xc2, 0x97, 0x24, 0x10, 0x9d, 0x91 } }
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf
new file mode 100644
index 000000000000..b16ff2353aa5
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.inf
@@ -0,0 +1,45 @@
+## @file
+#  DXE driver to get secure error sources.
+#
+#  DXE driver to retrieve the error source descriptors from Standalone MM and
+#  append those to 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                      = 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
+  MdeModulePkg/MdeModulePkg.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..9d566de9bec3
--- /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 - 2021, ARM Limited. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
[SAMI] Use latest INF version.
+  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]
+  TRUE
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h
new file mode 100644
index 000000000000..6ddc6bd21922
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestMmErrorSourceCommon.h
@@ -0,0 +1,37 @@
+/** @file
+  Data structures for error source descriptor information.
+
+  This data structure forms the CommBuffer part of the MM Communication
+  protocol used for communicating the Hardware Error sources form MM to
+  Non-MM environment.
+
+  Copyright (c) 2020 - 2021, 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/MdePkg/Include/Protocol/MmCommunication.h b/MdePkg/Include/Protocol/MmCommunication.h
index 34c3e2b5a9e3..acde54971fd9 100644
--- a/MdePkg/Include/Protocol/MmCommunication.h
+++ b/MdePkg/Include/Protocol/MmCommunication.h
@@ -12,6 +12,8 @@
 #ifndef _MM_COMMUNICATION_H_
 #define _MM_COMMUNICATION_H_
 
+#define MM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data))
+
 #pragma pack(1)
 
 ///
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c
new file mode 100644
index 000000000000..28de8daf2f5e
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceDxe.c
@@ -0,0 +1,309 @@
+/** @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.
+
+  This driver collects the secure error source descriptor information from the
+  MM drviers that implement HEST error source protocol. Instead of directly
+  communicating with the individual MM drivers, it calls into
+  HestErrorSourceStandaloneMM driver which is a gatway MM driver. This MM driver
+  in-turn communicates with individual MM drivers collecting the error source
+  descriptor information.
+
+  Once all the error source descriptor information is retrieved the driver
+  appends the descriptors to HEST table using the HestDxe driver.
+
+  Copyright (c) 2020 - 2021, 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"
+
+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;
+
[SAMI] It may be good to add a check to see if CommBuffSize is at least the minimum required size.
+  //
+  // 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,
+                                NULL,
+                                (VOID *)*CommBuffer,
+                                NULL
+                                );
+
[SAMI] Unless you intend to assert or log the status code you could directly return the value returned by mMmCommunication2->Communicate().
+  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;
+
+  //
+  // Retrieve the count, length and the actual eror source descriptors from
+  // the MM drivers. Do this by performing two MM Communicate calls, in the
+  // first call pass CommBuffer which is atleast of the size of error source
+  // descriptor info structure. Followed by another communicate call with
+  // CommBuffer allocated to required buffer size to hold all descriptors.
+  //
+  // Allocate CommBuffer atleast the size of error source descriptor info
+  // structure.
+  CommBufferSize =
+    MM_COMMUNICATE_HEADER_SIZE + HEST_ERROR_SOURCE_DESC_INFO_SIZE;
+  CommunicationHeader = AllocateZeroPool (CommBufferSize);
+  if (CommunicationHeader == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to allocate memory for CommunicationHeader\n",
+      __FUNCTION__
+      ));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // Make the first MM Communicate call to HestErrorSourceStandaloneMM gateway
+  // driver, which returns the required buffer size adequate to hold all the
+  // desctriptor information.
+  //
+  Status = GetErrorSourceDescriptors (CommBufferSize, &CommunicationHeader);
+  if ((EFI_ERROR (Status)) &&
+      (Status != EFI_BUFFER_TOO_SMALL)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: MM Communicate protocol call failed, status: %r\n",
+      __FUNCTION__,
+      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,
+      "HesErrorSourceDxe: HEST error source(s) not found\n"
+      ));
+    FreePool (CommunicationHeader);
+    return EFI_NOT_FOUND;
+  }
+
+  //
+  // 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 = AllocateZeroPool (CommBufferSize);
+  if (CommunicationHeader == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to allocate memory for CommunicationHeader\n",
+      __FUNCTION__
+      ));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // Make second MM Communicate call to HestErrorSourceStandaloneMM driver to
+  // get the error source descriptors from the MM drivers.
+  //
+  Status = GetErrorSourceDescriptors (CommBufferSize, &CommunicationHeader);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: MM Communicate protocol failed, status: %r\n",
+      __FUNCTION__,
+      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,
+      "HestErrorSourceDxe: Error source descriptor list is empty"
+      ));
+    FreePool (CommunicationHeader);
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "HestErrorSourceDxe: 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,
+      "%a: Failed to append error source(s), status: %r\n",
+      __FUNCTION__,
+      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,
+      "%a: Failed to locate HEST table generation protocol, status:%r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
+  }
+
+  Status = gBS->LocateProtocol (
+                  &gEfiMmCommunication2ProtocolGuid,
+                  NULL,
+                  (VOID **)&mMmCommunication2
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to locate MMCommunication2 driver protocol, status:%r\n",
+      __FUNCTION__,
+      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,
+      "%a: Failed appending error source desc to HEST table, status:%r\n",
+      __FUNCTION__,
+      Status
+      ));
+  }
+  return EFI_SUCCESS;
+}
diff --git a/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c
new file mode 100644
index 000000000000..75dc31438180
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/HestMmErrorSources/HestErrorSourceStandaloneMm.c
@@ -0,0 +1,312 @@
+/** @file
+  MM HEST error source gateway driver.
+
+  This MM 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.
+
+  The MM driver acts as a single point of contact to collect secure hardware
+  error sources from the MM drivers. It loops over all the MM drivers that
+  implement HEST error source descriptor protocol and collects error source
+  descriptor information along with the error source count and length.
+
+  Copyright (c) 2020 - 2021, 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,
+      "%a: No implementation of MmHestErrorSourceDescProtocol found, \
+       Status:%r\n",
+      __FUNCTION__,
+      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 that
+                                   is 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.
+
+  @retval  EFI_SUCCESS            CommBuffer has valid data.
+  @retval  EFI_BAD_BUFFER_SIZE    CommBufferSize not adequate.
[SAMI] I think this should be EFI_BUFFER_TOO_SMALL, right?
+  @retval  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     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) {
+    //
+    // Ensures that the communication buffer has enough space to atleast hold
+    // the ErrSourceDescCount and ErrSourceDescSize elements of the
+    // HEST_ERROR_SOURCE_DESC_INFO structure.
+    //
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Invalid CommBufferSize parameter\n",
+      __FUNCTION__
+      ));
+    return EFI_INVALID_PARAMETER;
[SAMI] I don't understand why this check is needed. Can you explain, please?
+  }
+
+  //
+  // 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 = AllocateZeroPool (HandleBufferSize);
+  if (HandleBuffer == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to allocate memory for HandleBuffer\n",
+      __FUNCTION__
+      ));
+    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.
+  //
+  // This loop collects and adds the length of error source descriptors and
+  // its count from all the the MM drivers implementing HEST error source.
+  // descriptor protocol. The total length and count values retrieved help
+  // to determine weather the CommBuffer is big enough to hold the descriptor
+  // information.
+  // As mentioned in the HEST error source descriptor protocol definition,
+  // Buffer parameter set to NULL ensures only length and the count values
+  // are returned from the driver and no error source information is copied to
+  // Buffer.
+  //
+  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.
+    //
[SAMI] The SourceLength and SourceCount variables must be initialised to 0 here.
+    Status = HestErrSourceDescProtocolHandle->GetHestErrorSourceDescriptors (
+                                                HestErrSourceDescProtocolHandle,
+                                                NULL,
+                                                &SourceLength,
+                                                &SourceCount
+                                                );
+    if (Status == EFI_INVALID_PARAMETER) {
[SAMI] Please see my earlier comment. EFI_INVALID_PARAMETER is not the correct value to be returned here. It should be EFI_BUFFER_TOO_SMALL.
+      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) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Invalid CommBufferSize parameter\n",
+      __FUNCTION__
+      ));
+    FreePool (HandleBuffer);
+    return EFI_BUFFER_TOO_SMALL;
[SAMI] If EFI_BUFFER_TOO_SMALL is returned it is expected that the caller will be provided with information on the size of the buffer required. However, that does not seem to be the case here as CommBufferSize is not an OUT parameter.
If this is an unrecoverable error, or if the caller is not expected to probe the size then the return code should be EFI_BAD_BUFFER_SIZE and my comment in the function documentation header can be ignored.
Can you check what is should happen here, please?
[/SAMI]
+  }
+
+  //
+  // CommBuffer size is adequate to return all the error source descriptors.
+  // So go ahead and 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 information.
+  //
+  // Calls into each MM driver that implement the HEST error source descriptor
+  // protocol. Here the Buffer parameter passed to the protocol service is
+  // valid. So the MM driver when called copies the descriptor information.
+  //
+  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) {
[SAMI] if (!EFI_ERROR (Status)) ?
+      ErrorSourcePtr += SourceLength;
+    }
+  }
+
+  // Free the buffer holding all the protocol handles.
+  FreePool (HandleBuffer);
+
+  return Status;
+}
+
+/**
+  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,
+      "%a: Mmi handler registration failed with status : %r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
[SAMI] This return statment can be removed.
+  }
+
+  return Status;
+}

--------------DC89725EAD233D8E67B33739--