From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.4639.1661812043617714076 for ; Mon, 29 Aug 2022 15:27:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=hxwi0UmB; spf=permerror, err=too many SPF records (domain: intel.com, ip: 192.55.52.136, mailfrom: isaac.w.oram@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661812043; x=1693348043; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Jz7h6jBLukPwmCR+AyKx4yMaA6fIv6LN75CcLLu2EuU=; b=hxwi0UmB7x/oTHdLdH82wWsdVW4CNJXov61lcFNvPESp33/6xNXY8aW1 LX/F7N+YaFuVBHHbmv2gCxRU2it+iAI3lc0TCst9B0scCdSa9l+Kx9lKj +dfwMycUxeTlBQpnc+hYOM5Q7RCXx6cXd1JGtZzJkQEOTlNhs6ax5hVoN X79bhkF9wz3QsErD6pDFkZ3nzqVnUIJ3IJE6oOe/THFyFvfU5mvFNW6p/ 2ddDymWqqNizmi5XA0EPijXvQ/z7Tb/i/arVsozRKKFc52tbqy3BpF9Ws 6jEDLBHom/e2lY2AAUm2ZbsLidxooVpMZ+m5Ib83NEU2omN6By1x3CNvm Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10454"; a="274762977" X-IronPort-AV: E=Sophos;i="5.93,273,1654585200"; d="scan'208";a="274762977" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2022 15:27:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,273,1654585200"; d="scan'208";a="856869537" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga006.fm.intel.com with ESMTP; 29 Aug 2022 15:27:23 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 29 Aug 2022 15:27:22 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 29 Aug 2022 15:27:22 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Mon, 29 Aug 2022 15:27:22 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.168) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Mon, 29 Aug 2022 15:27:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bb0vDHlHmrcvrmrPF0XtGsknHd7Fy92qz7cc7IVZwBDXgYPOfZF4jxhwxhcoLmqETUQd5509tJHbmQeiSTixd2fWYT7aQruMlD41oVDl/XWVNDAd/Kc/J6dxuK2KoyATzEKXEBY1VifYFWO9JzqpGXLDZ2m+xYIv8ilatvKn1MSJv4UaZzqDqx5KvTWj1wMtmSnOz5apg7UmqLvEXcsrLRTIONY2J77wDhPDfMcl3wO2r/yuoBoT8FzolY7I4CRtKgLh2rbuVSd8NBrs8pfglAJpYBlGNgMOceziiWFlhaqNp2JcA8yyAIk21vWJ9IB/Lk5W4AutlatHPvUH4rKb3A== 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=PeUsrFHKwL2mlySHZRlmGlukbLhnOCTjZaQmlONlzL4=; b=kICl8YO5sCCmOHoLRExmZP4rvt4OnsNe1pFLY45T63qu4YFZHnyFM6rPnncAaOmatTfz7Z9wnej6K2drbdT+gtD0xNlD6ijPPlrPa+NA6Dh/BpyjSun/70HJv2oXNCBrmL+5OArNaCo/0alTKuKoH7aXIus8F6V97KSBe/fv+Z1Ly9XYd+ij7dv+ziT3RGF8zyudeM+TIMsEBA9GPgjCtkbrhQFM6i9R1T97bHpu8ykf68XH7H1Y4r+CfhpxfzymqfqeZjO3dhtm8t/48K3naLAPJr4SF9ZGYTEnMUP4Bsnhxo/Nb3TURRkS1Lmt70bY2emk1T/E0i2lN2FZq9WBNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from SA1PR11MB5801.namprd11.prod.outlook.com (2603:10b6:806:23d::13) by BL3PR11MB6481.namprd11.prod.outlook.com (2603:10b6:208:3bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Mon, 29 Aug 2022 22:27:18 +0000 Received: from SA1PR11MB5801.namprd11.prod.outlook.com ([fe80::4149:e96e:480e:e1c3]) by SA1PR11MB5801.namprd11.prod.outlook.com ([fe80::4149:e96e:480e:e1c3%6]) with mapi id 15.20.5566.021; Mon, 29 Aug 2022 22:27:18 +0000 From: "Oram, Isaac W" To: Benjamin Doron , "devel@edk2.groups.io" CC: "Desimone, Nathaniel L" , "Sinha, Ankit" , "Ni, Ray" , "Chaganty, Rangasai V" Subject: Re: [edk2-devel][edk2-platforms][PATCH v1 1/5] IntelSiliconPkg/Feature/PeiSmmAccessLibSmramc: Implement chipset support Thread-Topic: [edk2-devel][edk2-platforms][PATCH v1 1/5] IntelSiliconPkg/Feature/PeiSmmAccessLibSmramc: Implement chipset support Thread-Index: AQHYu+chckJrQKnqa0G5yNgUUQ1PA63GYbqQ Date: Mon, 29 Aug 2022 22:27:17 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.500.17 dlp-reaction: no-action authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 08d490da-d4e2-467f-445a-08da8a0da1d3 x-ms-traffictypediagnostic: BL3PR11MB6481:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0BCKQ+l+2oRBYndUY+/fnHXPkzBUibQ95qnOY380rgjiUZHN+TQravJX6sgoSjeJeGHuNfCX+zCUqX6DwVwfPe6B85QE2/7UMeIi1VUJPHPOvE6lxLbVQtrYvd+2cgNOvPDkIBDHE69K1WEj3Lpwgj1yyzh8y02M30eMg/V8IFVdMjhfXhKND+A5FwMjuL8nRRwNcXgh0jkmAugr36BgMGA7Gn18mf/CJMwgoO1dsUjxruTHVZSXjMMoV7RAGXf6KRlnY0Bf1MZGj1Jr/ncrRkCRgOO5hKLevSQeuuBca0F8IKzU4VdF/fNylq51dn6VE++NVN7akfsmkhsu8g4WgnWgbqYBSsTpoPOGrtNp8O6qftn6jMHLs74SdLETasuHA2cnxpfHztUpyyk7ywaoCXhFcg1dzruCLNI0F1DtIupJtX9lT0yiw2s/I0357aUeSmFiN+MeI/v4xIJA5GSqdFucYqk2xhP600FdoceaHmiB4d7RNqTZTvmmmWyPVytQxgHUeGDQdGBDMT5jMkAKGSGQGPX86pyfbq/RquEQGy6iSD1kEA6PS41TDAzj9KXqo2xaGcLHLtjyjFyHUOefD58BCGMy0QhFDJRZPxiJikSPodDXrmXuB95JG/YrL12N7l9tHgODB1PFRlvGaxDXlRfZpWPqTPH1YVGYnT0P4zlbfKMDYlIqRvdzmW3gqnbY1rFkr6IMdsSZOcpA1ImTEo4X38Shx1Gr/EURLZuErIWnyu79zVxFPgzsJjXUgkGnQVdF2UWrXNeIv0wWAqPlqsyWq05ebhJX4EmN0N+z7qc= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA1PR11MB5801.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(396003)(346002)(366004)(39860400002)(376002)(136003)(9686003)(6506007)(82960400001)(86362001)(53546011)(107886003)(33656002)(7696005)(26005)(122000001)(186003)(83380400001)(38070700005)(478600001)(71200400001)(41300700001)(55016003)(316002)(66446008)(4326008)(64756008)(66946007)(66476007)(76116006)(66556008)(54906003)(110136005)(8676002)(8936002)(52536014)(38100700002)(5660300002)(30864003)(2906002)(213903007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?PMIPZYB8urfl0P4d9Wb+VYYdCvKMoxdg8cUv7GxOVIM8Q8XDbD7s32/HYQg0?= =?us-ascii?Q?M03kztjn/TzyqfL7XOvhRcjN6rWYAG/drzN/c4ZgBbeq1kV/A4slnlYqZW1o?= =?us-ascii?Q?Nh5Z74NFsdc9QcEW2vKxTPPl458vQPgNLZ6TRgcEh6P8b7gVdlk8T+YRKjLt?= =?us-ascii?Q?Iazq3tTEMy9LeOX4UjWkgDp4SQ3HwqCxi9MfVwNPY6tWWD846vzxaOwjrb2a?= =?us-ascii?Q?GKwJsbzfXKyWSOpbjZj3KlTc2mybtU1mUqDXXC3I84eOy4BbNFuVvqL6UU5W?= =?us-ascii?Q?byfefNxSXcTWeR4taSymCkCC+C0F/iApB+3A7ZF+QEp2uIWC1bgyJsHbxccf?= =?us-ascii?Q?Yu7pmQU2BdfDmJuP1EtRhB/4ZPcvmPAwkEIr2Nmd+qOgPQ3d1C5kfT8jH+4C?= =?us-ascii?Q?ujc9+0HT7HkuguxUULluO1CohEp7OgoBR9s00sx2jkSjjS6+wS1bqCVtKBBK?= =?us-ascii?Q?oWOFYgtJIQO6UksEDia5yChgm254+T8OBgHCM2q9qmSWbAS8KbZrmiyW4Mxs?= =?us-ascii?Q?y3RZ6PNdE3hqJ6pq2MVVHyrs4Ht20OvQcOWBtCgaLcXVhAxpxAMT6AQwnw4K?= =?us-ascii?Q?gX1DSPwLdC1aQAodcWm32UrF/futLEvCbBFdnCr+97IhAig5qRdk5o4J/4YW?= =?us-ascii?Q?LqksQrYcfASahXsCMQPx8avIuBVFwu0mRd9+R7LteysXvPxp1Kfgd5WhpCEe?= =?us-ascii?Q?GrY9Lns7wbRySpMjcOPtc5SSUEcTm7RYjttezMZuBHnP/2EMW3gNEsqao5Il?= =?us-ascii?Q?4RvS8A8AttoSJT8Xxh8iCdjPlEpE77UHUrsDeixxWhn4jcVWoerv/IW/7+Mm?= =?us-ascii?Q?IW1sbUbjE4oztXy7UQhEgQj2Mqk0ClyySKnkkaRn+Z/pMMzm3C1Q98PFyqID?= =?us-ascii?Q?7jlrcB5ceBJklz4j/P24QGSOFG3lbiCx/GSBj+9tzvI4O6SG92dlnm/UYCZ4?= =?us-ascii?Q?0tc2uI4NOTjciD0RletfHcGWU1s0Eu8046DnasCB0MsXJaJO/xCv9bFic61a?= =?us-ascii?Q?8U+IOS6TqMnH0fLglrsCvQ4XEuVPx8zF1iuLqV5XtqULeV8vn4gDejM3da4X?= =?us-ascii?Q?gcj15eYVSuFT5FbpUmClvMXTdAxQ7P8RuWeIIrMm2J3JZKL/LTGDEIxfSmcY?= =?us-ascii?Q?fFIrIwzK2Hm9qiV+UkyH5D2z4u0/2WPI5ebf89Yr7zInJPyP+R0N6teuBzlH?= =?us-ascii?Q?/Li591kuaseZ8UCD1/PH2RPOc7d9/0A3NEQW+HSUZzhiqVvzQy6ZYT/MwX78?= =?us-ascii?Q?32W0AuJX/1bZ0d2SQ6ZNpMkYa15gMRe3QzvPj151CZdMmDFsHnyjbMhYsvly?= =?us-ascii?Q?FsyBcMJmuhAJx+brCEtBzyek/YnMWGwFvHzirHgPjsRuGSlfLgEMSK8eHuSC?= =?us-ascii?Q?ixIU0CkaEAA6hiqUvR9DdBKklCGhQxGPnr8oheCKhi3uvdhuwDfQQWvdc4FH?= =?us-ascii?Q?dApLOfQY+W2FdWuZeqQn3LvemhEZGCqjJEcclEDZBXaU7ZBOD/TjYRKUU9OD?= =?us-ascii?Q?wfZGiWP+KwXA7dB6LoxGkYm/X7QkYwZMacgARfC4HwRY3VaQJ+TmOZJJIF1p?= =?us-ascii?Q?By6fFvEZ/UXy9XNKPbfQzbdwsaxMkSY6E+EqxQLn?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA1PR11MB5801.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08d490da-d4e2-467f-445a-08da8a0da1d3 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2022 22:27:18.0219 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 6zzf4QSkkoUts2qbFQU7bpbxMnSCdptI4Vg1Kzr62TtpTsuum7h4zZZVdnIjsuREgSmaFLDCqfRhCuaOsc/ScQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6481 Return-Path: isaac.w.oram@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Isaac Oram I would prefer to see contents of sections indented, but it is a nit. It might be slightly better to have PcdsFixedAtBuild type PCD for the regis= ter information, but this is pretty stable HW, so it is ok. Regards, Isaac -----Original Message----- From: Benjamin Doron =20 Sent: Monday, August 29, 2022 1:36 PM To: devel@edk2.groups.io Cc: Desimone, Nathaniel L ; Sinha, Ankit ; Ni, Ray ; Chaganty, Rangasai V ; Oram, Isaac W Subject: [edk2-devel][edk2-platforms][PATCH v1 1/5] IntelSiliconPkg/Feature= /PeiSmmAccessLibSmramc: Implement chipset support SMRAM must be opened to retrieve the lockbox for S3, and SMM communication = depends on this PPI. For security purposes, SMRAM lock must be performed be= fore EndOfPei (although FSP notify performs lockdown too). It seems to me that this library is generic and applicable to all Intel pla= tforms in the tree using the MCH SMRAMC register. Cc: Nate DeSimone Cc: Ankit Sinha Cc: Ray Ni Cc: Rangasai V Chaganty Cc: Isaac Oram Signed-off-by: Benjamin Doron --- .../PeiSmmAccessLibSmramc/PeiSmmAccessLib.c | 430 ++++++++++++++++++ .../PeiSmmAccessLibSmramc/PeiSmmAccessLib.inf | 41 ++ 2 files changed, 471 insertions(+) create mode 100644 Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library= /PeiSmmAccessLibSmramc/PeiSmmAccessLib.c create mode 100644 Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library= /PeiSmmAccessLibSmramc/PeiSmmAccessLib.inf diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmm= AccessLibSmramc/PeiSmmAccessLib.c b/Silicon/Intel/IntelSiliconPkg/Feature/S= mmAccess/Library/PeiSmmAccessLibSmramc/PeiSmmAccessLib.c new file mode 100644 index 000000000000..5b472bf86abf --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAcce +++ ssLibSmramc/PeiSmmAccessLib.c @@ -0,0 +1,430 @@ +/** @file+ This is to publish the SMM Access Ppi instance.++ Copyright (= c) 2019 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-= Identifier: BSD-2-Clause-Patent++**/+#include +#in= clude +#include +#includ= e +#include +#include +#include +#include ++#include +#include ++#= define SMM_ACCESS_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('4', '5', 's', 'a')+= +///+/// Private data+///+typedef struct {+ UINTN Signatur= e;+ EFI_HANDLE Handle;+ EFI_PEI_MM_ACCESS_PPI SmmAccess;+ //+= // Local Data for SMM Access interface goes here+ //+ UINTN = NumberRegions;+ EFI_SMRAM_DESCRIPTOR *SmramDesc;+} SMM_ACCESS_PRIVAT= E_DATA;++#define SMM_ACCESS_PRIVATE_DATA_FROM_THIS(a) \+ CR (a, \+ = SMM_ACCESS_PRIVATE_DATA, \+ SmmAccess, \+ SMM_ACC= ESS_PRIVATE_DATA_SIGNATURE \+ )++//+// Common registers:+//+// DEVICE = 0 (Memory Controller Hub)+//+#define SA_MC_BUS 0x00+#define SA_MC_= DEV 0x00+#define SA_MC_FUN 0x00+///+/// Description:+/// = The SMRAMC register controls how accesses to Compatible SMRAM spaces are t= reated. The Open, Close and Lock bits function only when G_SMRAME bit is s= et to 1. Also, the Open bit must be reset before the Lock bit is set.+///+= #define R_SA_SMRAMC (0x88)+#define B_SA_SMRAMC_D_LCK_MASK (0x10)+#defi= ne B_SA_SMRAMC_D_CLS_MASK (0x20)+#define B_SA_SMRAMC_D_OPEN_MASK (0x= 40)++/**+ This routine accepts a request to "open" a region of SMRAM. The= + region could be legacy ABSEG, HSEG, or TSEG near top of physical memory.= + The use of "open" means that the memory is visible from all PEIM+ and S= MM agents.++ @param[in] PeiServices - General purpose services av= ailable to every PEIM.+ @param[in] This - Pointer to the S= MM Access Interface.+ @param[in] DescriptorIndex - Region of SMRAM to= Open.++ @retval EFI_SUCCESS - The region was successfully ope= ned.+ @retval EFI_DEVICE_ERROR - The region could not be opened bec= ause locked by+ chipset.+ @retval EFI_I= NVALID_PARAMETER - The descriptor index was out of bounds.+**/+EFI_STATUS= +EFIAPI+Open (+ IN EFI_PEI_SERVICES **PeiServices,+ IN EFI_PEI_= MM_ACCESS_PPI *This,+ IN UINTN DescriptorIndex+ = )+{+ SMM_ACCESS_PRIVATE_DATA *SmmAccess;+ UINT8 Index;= + UINT64 Address;+ UINT8 SmramControl;= ++ SmmAccess =3D SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ if (Descripto= rIndex >=3D SmmAccess->NumberRegions) {+ DEBUG ((DEBUG_WARN, "SMRAM regi= on out of range\n"));++ return EFI_INVALID_PARAMETER;+ } else if (SmmAc= cess->SmramDesc[DescriptorIndex].RegionState & EFI_SMRAM_LOCKED) {+ //+ = // Cannot open a "locked" region+ //+ DEBUG ((DEBUG_WARN, "Cannot = open a locked SMRAM region\n"));++ return EFI_DEVICE_ERROR;+ }++ ///+ = /// BEGIN CHIPSET CODE+ ///+ ///+ /// SMRAM register is PCI 0:0:0:88, S= MRAMC (8 bit)+ ///+ Address =3D PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS, SA= _MC_DEV, SA_MC_FUN, R_SA_SMRAMC);+ SmramControl =3D PciSegmentRead8 (Addre= ss);+ ///+ /// Is SMRAM locked?+ ///+ if ((SmramControl & B_SA_SMRAMC_= D_LCK_MASK) !=3D 0) {+ ///+ /// Cannot Open a locked region+ ///+ = for (Index =3D 0; Index < SmmAccess->NumberRegions; Index++) {+ Smm= Access->SmramDesc[Index].RegionState |=3D EFI_SMRAM_LOCKED;+ }+ DEBUG= ((DEBUG_WARN, "Cannot open a locked SMRAM region\n"));+ return EFI_DEVI= CE_ERROR;+ }+ ///+ /// Open SMRAM region+ ///+ SmramControl |=3D B_SA_= SMRAMC_D_OPEN_MASK;+ SmramControl &=3D ~(B_SA_SMRAMC_D_CLS_MASK);++ PciSe= gmentWrite8 (Address, SmramControl);+ ///+ /// END CHIPSET CODE+ ///++ = SmmAccess->SmramDesc[DescriptorIndex].RegionState &=3D (UINT64) ~(EFI_SMRAM= _CLOSED | EFI_ALLOCATED);+ SmmAccess->SmramDesc[DescriptorIndex].RegionSta= te |=3D (UINT64) EFI_SMRAM_OPEN;+ SmmAccess->SmmAccess.OpenState =3D TRUE;= + return EFI_SUCCESS;+}++/**+ This routine accepts a request to "close" a= region of SMRAM. This is valid for+ compatible SMRAM region.++ @param[i= n] PeiServices - General purpose services available to every PEIM.= + @param[in] This - Pointer to the SMM Access Interface.+ = @param[in] DescriptorIndex - Region of SMRAM to Close.++ @retval EFI= _SUCCESS - The region was successfully closed.+ @retval EFI_DE= VICE_ERROR - The region could not be closed because locked by+ = chipset.+ @retval EFI_INVALID_PARAMETER - = The descriptor index was out of bounds.+**/+EFI_STATUS+EFIAPI+Close (+ IN = EFI_PEI_SERVICES **PeiServices,+ IN EFI_PEI_MM_ACCESS_PPI *This,+= IN UINTN DescriptorIndex+ )+{+ SMM_ACCESS_PRIVATE_DAT= A *SmmAccess;+ BOOLEAN OpenState;+ UINT8 = Index;+ UINT64 Address;+ UINT8 Smram= Control;++ SmmAccess =3D SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ if (D= escriptorIndex >=3D SmmAccess->NumberRegions) {+ DEBUG ((DEBUG_WARN, "SM= RAM region out of range\n"));++ return EFI_INVALID_PARAMETER;+ } else i= f (SmmAccess->SmramDesc[DescriptorIndex].RegionState & EFI_SMRAM_LOCKED) {+= //+ // Cannot close a "locked" region+ //+ DEBUG ((DEBUG_WARN,= "Cannot close a locked SMRAM region\n"));++ return EFI_DEVICE_ERROR;+ = }++ if (SmmAccess->SmramDesc[DescriptorIndex].RegionState & EFI_SMRAM_CLOS= ED) {+ return EFI_DEVICE_ERROR;+ }++ ///+ /// BEGIN CHIPSET CODE+ //= /+ ///+ /// SMRAM register is PCI 0:0:0:88, SMRAMC (8 bit)+ ///+ Addres= s =3D PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS, SA_MC_DEV, SA_MC_FUN, R_SA_SMR= AMC);+ SmramControl =3D PciSegmentRead8 (Address);+ ///+ /// Is SMRAM l= ocked?+ ///+ if ((SmramControl & B_SA_SMRAMC_D_LCK_MASK) !=3D 0) {+ //= /+ /// Cannot Close a locked region+ ///+ for (Index =3D 0; Index = < SmmAccess->NumberRegions; Index++) {+ SmmAccess->SmramDesc[Index].Re= gionState |=3D EFI_SMRAM_LOCKED;+ }+ DEBUG ((DEBUG_WARN, "Cannot clos= e a locked SMRAM region\n"));+ return EFI_DEVICE_ERROR;+ }+ ///+ /// = Close SMRAM region+ ///+ SmramControl &=3D ~(B_SA_SMRAMC_D_OPEN_MASK);++ = PciSegmentWrite8 (Address, SmramControl);+ ///+ /// END CHIPSET CODE+ /= //++ SmmAccess->SmramDesc[DescriptorIndex].RegionState &=3D (UINT64) ~EFI_= SMRAM_OPEN;+ SmmAccess->SmramDesc[DescriptorIndex].RegionState |=3D (UINT6= 4) (EFI_SMRAM_CLOSED | EFI_ALLOCATED);++ //+ // Find out if any regions a= re still open+ //+ OpenState =3D FALSE;+ for (Index =3D 0; Index < SmmAc= cess->NumberRegions; Index++) {+ if ((SmmAccess->SmramDesc[Index].Region= State & EFI_SMRAM_OPEN) =3D=3D EFI_SMRAM_OPEN) {+ OpenState =3D TRUE;+= }+ }++ SmmAccess->SmmAccess.OpenState =3D OpenState;+ return EFI_SUC= CESS;+}++/**+ This routine accepts a request to "lock" SMRAM. The+ regio= n could be legacy AB or TSEG near top of physical memory.+ The use of "loc= k" means that the memory can no longer be opened+ to PEIM.++ @param[in] P= eiServices - General purpose services available to every PEIM.+ @p= aram[in] This - Pointer to the SMM Access Interface.+ @par= am[in] DescriptorIndex - Region of SMRAM to Lock.++ @retval EFI_SUCCE= SS - The region was successfully locked.+ @retval EFI_DEVICE_E= RROR - The region could not be locked because at least+ = one range is still open.+ @retval EFI_INVALID_PARAM= ETER - The descriptor index was out of bounds.+**/+EFI_STATUS+EFIAPI+Lock= (+ IN EFI_PEI_SERVICES **PeiServices,+ IN EFI_PEI_MM_ACCESS_PPI= *This,+ IN UINTN DescriptorIndex+ )+{+ SMM_ACCE= SS_PRIVATE_DATA *SmmAccess;+ UINT64 Address;+ UINT8 = SmramControl;++ SmmAccess =3D SMM_ACCESS_PRIVATE_DATA_FROM_T= HIS (This);+ if (DescriptorIndex >=3D SmmAccess->NumberRegions) {+ DEBU= G ((DEBUG_WARN, "SMRAM region out of range\n"));++ return EFI_INVALID_PA= RAMETER;+ } else if (SmmAccess->SmmAccess.OpenState) {+ DEBUG ((DEBUG_W= ARN, "Cannot lock SMRAM when SMRAM regions are still open\n"));++ return= EFI_DEVICE_ERROR;+ }++ SmmAccess->SmramDesc[DescriptorIndex].RegionState= |=3D (UINT64) EFI_SMRAM_LOCKED;+ SmmAccess->SmmAccess.LockState =3D TRUE;= ++ ///+ /// BEGIN CHIPSET CODE+ ///+ ///+ /// SMRAM register is PCI 0:= 0:0:88, SMRAMC (8 bit)+ ///+ Address =3D PCI_SEGMENT_LIB_ADDRESS (0, SA_M= C_BUS, SA_MC_DEV, SA_MC_FUN, R_SA_SMRAMC);+ SmramControl =3D PciSegmentRea= d8 (Address);++ ///+ /// Lock the SMRAM+ ///+ SmramControl |=3D B_SA_SM= RAMC_D_LCK_MASK;++ PciSegmentWrite8 (Address, SmramControl);+ ///+ /// E= ND CHIPSET CODE+ ///++ return EFI_SUCCESS;+}++/**+ This routine services= a user request to discover the SMRAM+ capabilities of this platform. Thi= s will report the possible+ ranges that are possible for SMRAM access, bas= ed upon the+ memory controller capabilities.++ @param[in] PeiServices = - General purpose services available to every PEIM.+ @param[in] This = - Pointer to the SMRAM Access Interface.+ @param[in, out] Sm= ramMapSize - Pointer to the variable containing size of the+ = buffer to contain the description information.+ @par= am[in, out] SmramMap - Buffer containing the data describing the Smra= m+ region descriptors.++ @retval EFI_BUF= FER_TOO_SMALL - The user did not provide a sufficient buffer.+ @retval E= FI_SUCCESS - The user provided a sufficiently-sized buffer.+**/+= EFI_STATUS+EFIAPI+GetCapabilities (+ IN EFI_PEI_SERVICES **= PeiServices,+ IN EFI_PEI_MM_ACCESS_PPI *This,+ IN OUT UINTN = *SmramMapSize,+ IN OUT EFI_SMRAM_DESCRIPTOR *Smr= amMap+ )+{+ EFI_STATUS Status;+ SMM_ACCESS_PRIVATE_DATA *Sm= mAccess;+ UINTN NecessaryBufferSize;++ SmmAccess = =3D SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ NecessaryBufferSize =3D= SmmAccess->NumberRegions * sizeof (EFI_SMRAM_DESCRIPTOR);+ if (*SmramMapS= ize < NecessaryBufferSize) {+ DEBUG ((DEBUG_WARN, "SMRAM Map Buffer too = small\n"));++ Status =3D EFI_BUFFER_TOO_SMALL;+ } else {+ CopyMem (S= mramMap, SmmAccess->SmramDesc, NecessaryBufferSize);+ Status =3D EFI_SUC= CESS;+ }++ *SmramMapSize =3D NecessaryBufferSize;+ return Status;+}++/**= + This function is to install an SMM Access PPI+ - Introduction \n= + An API to install an instance of EFI_PEI_MM_ACCESS_PPI. This PPI is co= mmonly used to control SMM mode memory access for S3 resume.++ @retval E= FI_SUCCESS - Ppi successfully started and installed.+ @retval = EFI_NOT_FOUND - Ppi can't be found.+ @retval EFI_OUT_OF_RESOURCE= S - Ppi does not have enough resources to initialize the driver.+**/+EFI_S= TATUS+EFIAPI+PeiInstallSmmAccessPpi (+ VOID+ )+{+ EFI_STATUS = Status;+ UINTN Index;+ EFI_PEI_PPI_DE= SCRIPTOR *PpiList;+ EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *DescriptorBl= ock;+ SMM_ACCESS_PRIVATE_DATA *SmmAccessPrivate;+ VOID = *HobList;++ //+ // Initialize private data+ //+ SmmAcc= essPrivate =3D AllocateZeroPool (sizeof (*SmmAccessPrivate));+ ASSERT (Sm= mAccessPrivate !=3D NULL);+ if (SmmAccessPrivate =3D=3D NULL) {+ return= EFI_OUT_OF_RESOURCES;+ }+ PpiList =3D AllocateZeroPool (sizeof= (*PpiList));+ ASSERT (PpiList !=3D NULL);+ if (PpiList =3D=3D NULL) {+ = return EFI_OUT_OF_RESOURCES;+ }++ SmmAccessPrivate->Signature =3D SMM_A= CCESS_PRIVATE_DATA_SIGNATURE;+ SmmAccessPrivate->Handle =3D NULL;++ //= + // Get Hob list+ //+ HobList =3D GetFirstGuidHob (&gEfiSmmSmramMemoryG= uid);+ if (HobList =3D=3D NULL) {+ DEBUG ((DEBUG_WARN, "SmramMemoryRese= rve HOB not found\n"));+ return EFI_NOT_FOUND;+ }++ DescriptorBlock = =3D (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *) ((UINT8 *) HobList + sizeof (EFI_HOB= _GUID_TYPE));++ //+ // Alloc space for SmmAccessPrivate->SmramDesc+ //+ = SmmAccessPrivate->SmramDesc =3D AllocateZeroPool ((DescriptorBlock->Number= OfSmmReservedRegions) * sizeof (EFI_SMRAM_DESCRIPTOR));+ if (SmmAccessPriv= ate->SmramDesc =3D=3D NULL) {+ DEBUG ((DEBUG_WARN, "Alloc SmmAccessPriva= te->SmramDesc fail.\n"));+ return EFI_OUT_OF_RESOURCES;+ }++ DEBUG ((D= EBUG_INFO, "Alloc SmmAccessPrivate->SmramDesc success.\n"));++ //+ // use= the hob to publish SMRAM capabilities+ //+ for (Index =3D 0; Index < Des= criptorBlock->NumberOfSmmReservedRegions; Index++) {+ SmmAccessPrivate->= SmramDesc[Index].PhysicalStart =3D DescriptorBlock->Descriptor[Index].Phys= icalStart;+ SmmAccessPrivate->SmramDesc[Index].CpuStart =3D Descri= ptorBlock->Descriptor[Index].CpuStart;+ SmmAccessPrivate->SmramDesc[Inde= x].PhysicalSize =3D DescriptorBlock->Descriptor[Index].PhysicalSize;+ = SmmAccessPrivate->SmramDesc[Index].RegionState =3D DescriptorBlock->Desc= riptor[Index].RegionState;+ }++ SmmAccessPrivate->NumberRegions = =3D Index;+ SmmAccessPrivate->SmmAccess.Open =3D Open;+ Smm= AccessPrivate->SmmAccess.Close =3D Close;+ SmmAccessPrivate->Smm= Access.Lock =3D Lock;+ SmmAccessPrivate->SmmAccess.GetCapabilit= ies =3D GetCapabilities;+ SmmAccessPrivate->SmmAccess.LockState =3D = FALSE;+ SmmAccessPrivate->SmmAccess.OpenState =3D FALSE;++ //+ // = Install PPI+ //+ PpiList->Flags =3D (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PE= I_PPI_DESCRIPTOR_TERMINATE_LIST);+ PpiList->Guid =3D &gEfiPeiMmAccessPpi= Guid;+ PpiList->Ppi =3D &SmmAccessPrivate->SmmAccess;++ Status = =3D PeiServicesInstallPpi (PpiList);+ ASSERT_EFI_ERROR (Status);++ retu= rn EFI_SUCCESS;+}diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/SmmAcce= ss/Library/PeiSmmAccessLibSmramc/PeiSmmAccessLib.inf b/Silicon/Intel/IntelS= iliconPkg/Feature/SmmAccess/Library/PeiSmmAccessLibSmramc/PeiSmmAccessLib.i= nf new file mode 100644 index 000000000000..916346aacff3 --- /dev/null +++ b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAcce +++ ssLibSmramc/PeiSmmAccessLib.inf @@ -0,0 +1,41 @@ +## @file+# Library description file for the SmmAccess PPI+#+# Copyright=20 +(c) 2019, Intel Corporation. All rights reserved.
+#=20 +SPDX-License-Identifier:=20 +BSD-2-Clause-Patent+#+##++[Defines]+INF_VERSION =3D 0x00010017+BASE_NAME=20 +=3D PeiSmmAccessLibSmramc+FILE_GUID =3D=20 +3D28FD4B-F46F-4E24-88AA-9DA09C51BE87+VERSION_STRING =3D 1.0+MODULE_TYPE = =3D PEIM+LIBRARY_CLASS =3D SmmAccessLib+++[LibraryClasses]+BaseMemoryLib+Me= moryAllocationLib+DebugLib+HobLib+PciSegmentLib+PeiServicesLib+++[Packages]= +MdePkg/MdePkg.dec+IntelSiliconPkg/IntelSiliconPkg.dec+++[Sources]+PeiSmmAc= cessLib.c+++[Ppis]+gEfiPeiMmAccessPpiGuid ## PRODUCES+++[Guids]+gEfiSmmSmra= mMemoryGuid-- 2.37.2