From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by mx.groups.io with SMTP id smtpd.web10.6312.1661822018292126736 for ; Mon, 29 Aug 2022 18:13:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JK5eIL26; spf=pass (domain: gmail.com, ip: 209.85.167.42, mailfrom: benjamin.doron00@gmail.com) Received: by mail-lf1-f42.google.com with SMTP id bq23so13501525lfb.7 for ; Mon, 29 Aug 2022 18:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=eL2t8OSSFXmlKaPg8/bkVq2ONtRnATHjhsyc5E3q9Fs=; b=JK5eIL26EIv+dKJhERHoI4pRbY/7/8LSWYbNM6CHSbwc2Uf13SfiQ7YIC0nz6snFj4 HNlzspbeLPeBnHChuRY6ymUPaVVyjD+VxqfvUMZGVaZk0rt4MNaRiaMBwjq2PVMnSBHD lX13N2e04XF4FhlqRjJN6kWUA51iA6FTknUzzW7N2dFSItFIJJ5pxOHWvBVKjztitrX6 ZIYlJ60cFhtt16cAUcCWPjKf7CciN7+KWZeDQ6C59WZe3NyPygmhA01C5MHFF8ur7WTn MepoY+nWUUbA24rS6q8ZarLqIqgxVwIjYjKtUtFg4QIC6xdMbu6A+TyIIxR/jd2P8eQX YnRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=eL2t8OSSFXmlKaPg8/bkVq2ONtRnATHjhsyc5E3q9Fs=; b=Lz29DdNywy+6aKSk5kesDeM3/do94LAfJEVA0eJcvnllSxq84JhpMMx6+BQ3skSH82 04lV5dOUpLRsnUMbs/TzwC8j/dZMfNJajLKupwBpwYR1FJud8yvHb2RUVDxl5U3eGooO bZ36yBTNZ9pqCkaEIBnSDm8r5RA3lpME7Gg7537tehzvdqaGt3DTtjStYEB2oiPi3501 uiHk1RpUfoCmeA+T7Cikj6hjgBXHJHEZYQti9Q4g7YqJ35L96lAcQEm72EawO9m7ames dSyXkE9YKY8zL0L2JiaElhipXd3gF8mpfJu6MLHkUHHOqjrQLn8Glq2FDt7/T21o+LwG fh9Q== X-Gm-Message-State: ACgBeo3FJVg2Mtft94F/oLaWqAkvBYScXzgoeYBu5hRVSt0SpvJMkMPb /SH+/wfSS5S5peH7g3e4N/VcrpnoT5IyhxTqpkM= X-Google-Smtp-Source: AA6agR68VgnU1NyiCLx6UThY+NMlmWl/aCQj7+z/u/btlM0hBbd5pxNE7j2FB0sVfMltyeRNNwIbifWhghbmylzr5fw= X-Received: by 2002:a05:6512:687:b0:492:ee7c:5953 with SMTP id t7-20020a056512068700b00492ee7c5953mr7785637lfe.673.1661822016443; Mon, 29 Aug 2022 18:13:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "Benjamin Doron" Date: Mon, 29 Aug 2022 21:13:25 -0400 Message-ID: Subject: Re: [edk2-devel][edk2-platforms][PATCH v1 1/5] IntelSiliconPkg/Feature/PeiSmmAccessLibSmramc: Implement chipset support To: "Ni, Ray" Cc: "Oram, Isaac W" , "devel@edk2.groups.io" , "Desimone, Nathaniel L" , "Sinha, Ankit" , "Chaganty, Rangasai V" Content-Type: multipart/alternative; boundary="000000000000f8592105e76b1689" --000000000000f8592105e76b1689 Content-Type: text/plain; charset="UTF-8" Ray, My primary platform for firmware development is the Skylake laptop I've submitted to the tree. I have a Tigerlake laptop too, but my porting efforts there are generally too WIP to test patches anywhere yet. Regardless, this patch series is intended to support as many platforms as possible. It's my understanding that generally, we're supporting all current client platforms, though there may be silicon-specific differences, particularly in the shim library. Best regards, Benjamin On Mon, 29 Aug 2022 at 20:26, Ni, Ray wrote: > Doran, > Which platform are you using? I thought those platforms are quite old and > no one is using them. > > > -----Original Message----- > > From: Oram, Isaac W > > Sent: Tuesday, August 30, 2022 6:27 AM > > 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 > > > > 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 > register information, but this is pretty stable HW, so it > > is ok. > > > > Regards, > > Isaac > > > > -----Original Message----- > > From: Benjamin Doron > > 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 before EndOfPei (although FSP > notify performs lockdown too). > > > > It seems to me that this library is generic and applicable to all Intel > platforms 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/PeiSmmAccessLibSmramc/PeiSmmAccessLib.c > > > b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/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 +#include > > +#include +#include > +#include > > +#include +#include > +#include > > ++#include +#include > ++#define > > SMM_ACCESS_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('4', '5', 's', > 'a')++///+/// Private data+///+typedef struct {+ > > UINTN Signature;+ 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_PRIVATE_DATA;++#define SMM_ACCESS_PRIVATE_DATA_FROM_THIS(a) > \+ CR (a, \+ > > SMM_ACCESS_PRIVATE_DATA, \+ SmmAccess, \+ > SMM_ACCESS_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 treated. The Open, Close and Lock bits function only > when G_SMRAME bit is set 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)+#define B_SA_SMRAMC_D_CLS_MASK (0x20)+#define > B_SA_SMRAMC_D_OPEN_MASK (0x40)++/**+ 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 SMM agents.++ @param[in] > > PeiServices - General purpose services available to every > PEIM.+ @param[in] This - Pointer to the SMM Access > > Interface.+ @param[in] DescriptorIndex - Region of SMRAM to > Open.++ @retval EFI_SUCCESS - The region was > > successfully opened.+ @retval EFI_DEVICE_ERROR - The region > could not be opened because locked by+ > > chipset.+ @retval EFI_INVALID_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 = > SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ if > > (DescriptorIndex >= SmmAccess->NumberRegions) {+ DEBUG ((DEBUG_WARN, > "SMRAM region out of range\n"));++ > > return EFI_INVALID_PARAMETER;+ } else if > (SmmAccess->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, SMRAMC (8 bit)+ ///+ Address = > PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS, SA_MC_DEV, SA_MC_FUN, > > R_SA_SMRAMC);+ SmramControl = PciSegmentRead8 (Address);+ ///+ /// > Is SMRAM locked?+ ///+ if ((SmramControl > > & B_SA_SMRAMC_D_LCK_MASK) != 0) {+ ///+ /// Cannot Open a locked > region+ ///+ for (Index = 0; Index < > > SmmAccess->NumberRegions; Index++) {+ > SmmAccess->SmramDesc[Index].RegionState |= > > EFI_SMRAM_LOCKED;+ }+ DEBUG ((DEBUG_WARN, "Cannot open a locked > SMRAM region\n"));+ return > > EFI_DEVICE_ERROR;+ }+ ///+ /// Open SMRAM region+ ///+ SmramControl > |= B_SA_SMRAMC_D_OPEN_MASK;+ > > SmramControl &= ~(B_SA_SMRAMC_D_CLS_MASK);++ PciSegmentWrite8 (Address, > SmramControl);+ ///+ /// END > > CHIPSET CODE+ ///++ SmmAccess->SmramDesc[DescriptorIndex].RegionState > &= (UINT64) ~(EFI_SMRAM_CLOSED | > > EFI_ALLOCATED);+ SmmAccess->SmramDesc[DescriptorIndex].RegionState |= > (UINT64) EFI_SMRAM_OPEN;+ > > SmmAccess->SmmAccess.OpenState = TRUE;+ return EFI_SUCCESS;+}++/**+ > This routine accepts a request to "close" a > > region of SMRAM. This is valid for+ compatible SMRAM region.++ > @param[in] 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_DEVICE_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_DATA *SmmAccess;+ BOOLEAN > OpenState;+ UINT8 Index;+ UINT64 > > Address;+ UINT8 SmramControl;++ SmmAccess = > SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ if > > (DescriptorIndex >= SmmAccess->NumberRegions) {+ DEBUG ((DEBUG_WARN, > "SMRAM region out of range\n"));++ > > return EFI_INVALID_PARAMETER;+ } else if > (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_CLOSED) {+ return EFI_DEVICE_ERROR;+ }++ ///+ /// BEGIN > CHIPSET CODE+ ///+ ///+ /// SMRAM > > register is PCI 0:0:0:88, SMRAMC (8 bit)+ ///+ Address = > PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS, SA_MC_DEV, > > SA_MC_FUN, R_SA_SMRAMC);+ SmramControl = PciSegmentRead8 (Address);+ > ///+ /// Is SMRAM locked?+ ///+ if > > ((SmramControl & B_SA_SMRAMC_D_LCK_MASK) != 0) {+ ///+ /// Cannot > Close a locked region+ ///+ for (Index = 0; > > Index < SmmAccess->NumberRegions; Index++) {+ > SmmAccess->SmramDesc[Index].RegionState |= > > EFI_SMRAM_LOCKED;+ }+ DEBUG ((DEBUG_WARN, "Cannot close a locked > SMRAM region\n"));+ return > > EFI_DEVICE_ERROR;+ }+ ///+ /// Close SMRAM region+ ///+ > SmramControl &= ~(B_SA_SMRAMC_D_OPEN_MASK);++ > > PciSegmentWrite8 (Address, SmramControl);+ ///+ /// END CHIPSET CODE+ > ///++ SmmAccess- > > >SmramDesc[DescriptorIndex].RegionState &= (UINT64) ~EFI_SMRAM_OPEN;+ > SmmAccess- > > >SmramDesc[DescriptorIndex].RegionState |= (UINT64) (EFI_SMRAM_CLOSED | > EFI_ALLOCATED);++ //+ // Find out if any > > regions are still open+ //+ OpenState = FALSE;+ for (Index = 0; Index > < SmmAccess->NumberRegions; Index++) {+ if > > ((SmmAccess->SmramDesc[Index].RegionState & EFI_SMRAM_OPEN) == > EFI_SMRAM_OPEN) {+ OpenState = > > TRUE;+ }+ }++ SmmAccess->SmmAccess.OpenState = OpenState;+ return > EFI_SUCCESS;+}++/**+ This routine accepts a > > request to "lock" SMRAM. The+ region could be legacy AB or TSEG near > top of physical memory.+ The use of "lock" means > > that the memory can no longer be opened+ to PEIM.++ @param[in] > PeiServices - General purpose services available > > to every PEIM.+ @param[in] This - Pointer to the SMM > Access Interface.+ @param[in] DescriptorIndex - Region > > of SMRAM to Lock.++ @retval EFI_SUCCESS - The region was > successfully locked.+ @retval EFI_DEVICE_ERROR - > > The region could not be locked because at least+ > one range is still open.+ @retval > > EFI_INVALID_PARAMETER - 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_ACCESS_PRIVATE_DATA *SmmAccess;+ UINT64 Address;+ > UINT8 SmramControl;++ SmmAccess = > > SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ if (DescriptorIndex >= > SmmAccess->NumberRegions) {+ DEBUG > > ((DEBUG_WARN, "SMRAM region out of range\n"));++ return > EFI_INVALID_PARAMETER;+ } else if (SmmAccess- > > >SmmAccess.OpenState) {+ DEBUG ((DEBUG_WARN, "Cannot lock SMRAM when > SMRAM regions are still open\n"));++ > > return EFI_DEVICE_ERROR;+ }++ > SmmAccess->SmramDesc[DescriptorIndex].RegionState |= (UINT64) > > EFI_SMRAM_LOCKED;+ SmmAccess->SmmAccess.LockState = TRUE;++ ///+ /// > BEGIN CHIPSET CODE+ ///+ ///+ /// > > SMRAM register is PCI 0:0:0:88, SMRAMC (8 bit)+ ///+ Address = > PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS, > > SA_MC_DEV, SA_MC_FUN, R_SA_SMRAMC);+ SmramControl = PciSegmentRead8 > (Address);++ ///+ /// Lock the > > SMRAM+ ///+ SmramControl |= B_SA_SMRAMC_D_LCK_MASK;++ > PciSegmentWrite8 (Address, SmramControl);+ ///+ > > /// END CHIPSET CODE+ ///++ return EFI_SUCCESS;+}++/**+ This routine > services a user request to discover the > > SMRAM+ capabilities of this platform. This will report the possible+ > ranges that are possible for SMRAM access, based > > 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] SmramMapSize - Pointer to > > the variable containing size of the+ > buffer to contain the description information.+ @param[in, out] > > SmramMap - Buffer containing the data describing the Smram+ > region descriptors.++ @retval > > EFI_BUFFER_TOO_SMALL - The user did not provide a sufficient buffer.+ > @retval EFI_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 > > *SmramMap+ )+{+ EFI_STATUS Status;+ > SMM_ACCESS_PRIVATE_DATA *SmmAccess;+ UINTN > > NecessaryBufferSize;++ SmmAccess = > SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+ NecessaryBufferSize = > > SmmAccess->NumberRegions * sizeof (EFI_SMRAM_DESCRIPTOR);+ if > (*SmramMapSize < NecessaryBufferSize) {+ > > DEBUG ((DEBUG_WARN, "SMRAM Map Buffer too small\n"));++ Status = > EFI_BUFFER_TOO_SMALL;+ } else {+ > > CopyMem (SmramMap, SmmAccess->SmramDesc, NecessaryBufferSize);+ > Status = EFI_SUCCESS;+ }++ *SmramMapSize > > = 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 > commonly used to control SMM mode memory access > > for S3 resume.++ @retval EFI_SUCCESS - Ppi successfully > started and installed.+ @retval EFI_NOT_FOUND - Ppi > > can't be found.+ @retval EFI_OUT_OF_RESOURCES - Ppi does not have > enough resources to initialize the > > driver.+**/+EFI_STATUS+EFIAPI+PeiInstallSmmAccessPpi (+ VOID+ )+{+ > EFI_STATUS Status;+ UINTN > > Index;+ EFI_PEI_PPI_DESCRIPTOR *PpiList;+ > EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *DescriptorBlock;+ > > SMM_ACCESS_PRIVATE_DATA *SmmAccessPrivate;+ VOID > *HobList;++ //+ // Initialize private data+ > > //+ SmmAccessPrivate = AllocateZeroPool (sizeof > (*SmmAccessPrivate));+ ASSERT (SmmAccessPrivate != NULL);+ if > > (SmmAccessPrivate == NULL) {+ return EFI_OUT_OF_RESOURCES;+ }+ > PpiList = AllocateZeroPool (sizeof > > (*PpiList));+ ASSERT (PpiList != NULL);+ if (PpiList == NULL) {+ > return EFI_OUT_OF_RESOURCES;+ }++ > > SmmAccessPrivate->Signature = SMM_ACCESS_PRIVATE_DATA_SIGNATURE;+ > SmmAccessPrivate->Handle = NULL;++ > > //+ // Get Hob list+ //+ HobList = GetFirstGuidHob > (&gEfiSmmSmramMemoryGuid);+ if (HobList == NULL) {+ DEBUG > > ((DEBUG_WARN, "SmramMemoryReserve HOB not found\n"));+ return > EFI_NOT_FOUND;+ }++ DescriptorBlock = > > (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *) ((UINT8 *) HobList + sizeof > (EFI_HOB_GUID_TYPE));++ //+ // Alloc space for > > SmmAccessPrivate->SmramDesc+ //+ SmmAccessPrivate->SmramDesc = > AllocateZeroPool ((DescriptorBlock- > > >NumberOfSmmReservedRegions) * sizeof (EFI_SMRAM_DESCRIPTOR));+ if > (SmmAccessPrivate->SmramDesc == NULL) > > {+ DEBUG ((DEBUG_WARN, "Alloc SmmAccessPrivate->SmramDesc > fail.\n"));+ return EFI_OUT_OF_RESOURCES;+ }++ > > DEBUG ((DEBUG_INFO, "Alloc SmmAccessPrivate->SmramDesc success.\n"));++ > //+ // use the hob to publish SMRAM > > capabilities+ //+ for (Index = 0; Index < > DescriptorBlock->NumberOfSmmReservedRegions; Index++) {+ > > SmmAccessPrivate->SmramDesc[Index].PhysicalStart = > DescriptorBlock->Descriptor[Index].PhysicalStart;+ > > SmmAccessPrivate->SmramDesc[Index].CpuStart = > DescriptorBlock->Descriptor[Index].CpuStart;+ > > SmmAccessPrivate->SmramDesc[Index].PhysicalSize = > DescriptorBlock->Descriptor[Index].PhysicalSize;+ > > SmmAccessPrivate->SmramDesc[Index].RegionState = > DescriptorBlock->Descriptor[Index].RegionState;+ }++ > > SmmAccessPrivate->NumberRegions = Index;+ > SmmAccessPrivate->SmmAccess.Open = Open;+ > > SmmAccessPrivate->SmmAccess.Close = Close;+ > SmmAccessPrivate->SmmAccess.Lock = Lock;+ > > SmmAccessPrivate->SmmAccess.GetCapabilities = GetCapabilities;+ > SmmAccessPrivate->SmmAccess.LockState = > > FALSE;+ SmmAccessPrivate->SmmAccess.OpenState = FALSE;++ //+ // > Install PPI+ //+ PpiList->Flags = > > (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);+ > PpiList->Guid = > > &gEfiPeiMmAccessPpiGuid;+ PpiList->Ppi = > &SmmAccessPrivate->SmmAccess;++ Status = PeiServicesInstallPpi > > (PpiList);+ ASSERT_EFI_ERROR (Status);++ return EFI_SUCCESS;+}diff > --git > > > a/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccessLibSmramc/PeiSmmAccessLib.inf > > > b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccessLibSmramc/PeiSmmAccessLib.inf > > 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 > > +(c) 2019, Intel Corporation. All rights reserved.
+# > > +SPDX-License-Identifier: > > +BSD-2-Clause-Patent+#+##++[Defines]+INF_VERSION = 0x00010017+BASE_NAME > > += PeiSmmAccessLibSmramc+FILE_GUID = > > +3D28FD4B-F46F-4E24-88AA-9DA09C51BE87+VERSION_STRING = 1.0+MODULE_TYPE = > PEIM+LIBRARY_CLASS = > > > SmmAccessLib+++[LibraryClasses]+BaseMemoryLib+MemoryAllocationLib+DebugLib+HobLib+PciSegmentLib+PeiServicesL > > > ib+++[Packages]+MdePkg/MdePkg.dec+IntelSiliconPkg/IntelSiliconPkg.dec+++[Sources]+PeiSmmAccessLib.c+++[Ppis]+gE > > fiPeiMmAccessPpiGuid ## PRODUCES+++[Guids]+gEfiSmmSmramMemoryGuid-- > > 2.37.2 > > --000000000000f8592105e76b1689 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Ray,
My primary platform for firmware devel= opment is the Skylake laptop I've submitted to the tree. I have a Tiger= lake laptop too, but my porting efforts there are generally too WIP to test= patches anywhere yet.

Regardless, this patch seri= es is intended to support as many platforms as possible. It's my unders= tanding that generally, we're supporting all current client platforms, = though there may be silicon-specific differences, particularly in the shim = library.

Best re= gards,
Benjamin


On Mon, 29 Aug 2= 022 at 20:26, Ni, Ray <ray.ni@intel.= com> wrote:
Doran,
Which platform are you using? I thought those platforms are quite old and n= o one is using them.

> -----Original Message-----
> From: Oram, Isaac W <isaac.w.oram@intel.com>
> Sent: Tuesday, August 30, 2022 6:27 AM
> To: Benjamin Doron <benjamin.doron00@gmail.com>; devel@edk2.groups.io
> Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Sinha, = Ankit <ankit.= sinha@intel.com>; Ni, Ray
> <ray.ni@intel= .com>; Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> Subject: RE: [edk2-devel][edk2-platforms][PATCH v1 1/5] IntelSiliconPk= g/Feature/PeiSmmAccessLibSmramc: Implement
> chipset support
>
> Reviewed-by: Isaac Oram <isaac.w.oram@intel.com>
>
> I would prefer to see contents of sections indented, but it is a nit.<= br> > It might be slightly better to have PcdsFixedAtBuild type PCD for the = register information, but this is pretty stable HW, so it
> is ok.
>
> Regards,
> Isaac
>
> -----Original Message-----
> From: Benjamin Doron <benjamin.doron00@gmail.com>
> Sent: Monday, August 29, 2022 1:36 PM
> To: devel@ed= k2.groups.io
> Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Sinha, = Ankit <ankit.= sinha@intel.com>; Ni, Ray
> <ray.ni@intel= .com>; Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Oram,= Isaac W <is= aac.w.oram@intel.com>
> Subject: [edk2-devel][edk2-platforms][PATCH v1 1/5] IntelSiliconPkg/Fe= ature/PeiSmmAccessLibSmramc: Implement
> chipset support
>
> SMRAM must be opened to retrieve the lockbox for S3, and SMM communica= tion depends on this PPI. For security
> purposes, SMRAM lock must be performed before EndOfPei (although FSP n= otify performs lockdown too).
>
> It seems to me that this library is generic and applicable to all Inte= l platforms in the tree using the MCH SMRAMC register.
>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Ankit Sinha <ankit.sinha@intel.com>
> Cc: Ray Ni <r= ay.ni@intel.com>
> Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>
> Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
> ---
>=C2=A0 .../PeiSmmAccessLibSmramc/PeiSmmAccessLib.c=C2=A0 =C2=A0| 430 ++= ++++++++++++++++
>=C2=A0 .../PeiSmmAccessLibSmramc/PeiSmmAccessLib.inf |=C2=A0 41 ++
>=C2=A0 2 files changed, 471 insertions(+)
>=C2=A0 create mode 100644
> Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccessLi= bSmramc/PeiSmmAccessLib.c
>=C2=A0 create mode 100644
> Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccessLi= bSmramc/PeiSmmAccessLib.inf
>
> diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/P= eiSmmAccessLibSmramc/PeiSmmAccessLib.c
> b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccess= LibSmramc/PeiSmmAccessLib.c
> new file mode 100644
> index 000000000000..5b472bf86abf
> --- /dev/null
> +++ b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAc= ce
> +++ ssLibSmramc/PeiSmmAccessLib.c
> @@ -0,0 +1,430 @@
> +/** @file+=C2=A0 This is to publish the SMM Access Ppi instance.++=C2= =A0 Copyright (c) 2019 - 2020, Intel Corporation. All rights
> reserved.<BR>+=C2=A0 SPDX-License-Identifier: BSD-2-Clause-Paten= t++**/+#include <Library/BaseMemoryLib.h>+#include
> <Library/DebugLib.h>+#include <Library/MemoryAllocationLib.h&= gt;+#include <Library/PciSegmentLib.h>+#include
> <Library/PeiServicesLib.h>+#include <Library/HobLib.h>+#in= clude <Uefi/UefiBaseType.h>+#include
> <Guid/SmramMemoryReserve.h>++#include <Ppi/MmAccess.h>+#in= clude <IndustryStandard/Pci22.h>++#define
> SMM_ACCESS_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('4', '5= 9;, 's', 'a')++///+/// Private data+///+typedef struct {+ > UINTN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Sig= nature;+=C2=A0 EFI_HANDLE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Handle;+= =C2=A0 EFI_PEI_MM_ACCESS_PPI SmmAccess;+=C2=A0 //+=C2=A0 // Local Data for<= br> > SMM Access interface goes here+=C2=A0 //+=C2=A0 UINTN=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0NumberRegions;+=C2=A0 EFI_SMRA= M_DESCRIPTOR=C2=A0 *SmramDesc;+}
> SMM_ACCESS_PRIVATE_DATA;++#define SMM_ACCESS_PRIVATE_DATA_FROM_THIS(a)= \+=C2=A0 =C2=A0 =C2=A0 =C2=A0 CR (a, \+
> SMM_ACCESS_PRIVATE_DATA, \+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SmmAcces= s, \+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SMM_ACCESS_PRIVATE_DATA_SIGNATURE \= +=C2=A0 =C2=A0 =C2=A0 )++//+//
> Common registers:+//+// DEVICE 0 (Memory Controller Hub)+//+#define SA= _MC_BUS=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x00+#define SA_MC_DEV
> 0x00+#define SA_MC_FUN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x00+///+/// = Description:+///=C2=A0 The SMRAMC register controls how accesses to Compati= ble
> SMRAM spaces are treated.=C2=A0 The Open, Close and Lock bits function= only when G_SMRAME bit is set to 1.=C2=A0 Also, the Open
> bit must be reset before the Lock bit is set.+///+#define R_SA_SMRAMC= =C2=A0 (0x88)+#define B_SA_SMRAMC_D_LCK_MASK
> (0x10)+#define B_SA_SMRAMC_D_CLS_MASK=C2=A0 =C2=A0 =C2=A0(0x20)+#defin= e B_SA_SMRAMC_D_OPEN_MASK=C2=A0 =C2=A0 (0x40)++/**+=C2=A0 This
> routine accepts a request to "open" a region of SMRAM.=C2=A0= The+=C2=A0 region could be legacy ABSEG, HSEG, or TSEG near top of
> physical memory.+=C2=A0 The use of "open" means that the mem= ory is visible from all PEIM+=C2=A0 and SMM agents.++=C2=A0 @param[in]
> PeiServices=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-=C2=A0 General purpose s= ervices available to every PEIM.+=C2=A0 @param[in] This=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -=C2=A0 Pointer to the SMM Access
> Interface.+=C2=A0 @param[in] DescriptorIndex=C2=A0 =C2=A0 =C2=A0-=C2= =A0 Region of SMRAM to Open.++=C2=A0 @retval EFI_SUCCESS=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 -=C2=A0 The region was
> successfully opened.+=C2=A0 @retval EFI_DEVICE_ERROR=C2=A0 =C2=A0 =C2= =A0 =C2=A0-=C2=A0 The region could not be opened because locked by+
> chipset.+=C2=A0 @retval EFI_INVALID_PARAMETER=C2=A0 -=C2=A0 The descri= ptor index was out of bounds.+**/+EFI_STATUS+EFIAPI+Open
> (+=C2=A0 IN EFI_PEI_SERVICES=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*= *PeiServices,+=C2=A0 IN EFI_PEI_MM_ACCESS_PPI=C2=A0 =C2=A0 =C2=A0 *This,+= =C2=A0 IN UINTN
> DescriptorIndex+=C2=A0 )+{+=C2=A0 SMM_ACCESS_PRIVATE_DATA *SmmAccess;+= =C2=A0 UINT8=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Index;+=C2=A0 UINT64=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Address;+
> UINT8=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0SmramControl;++=C2=A0 SmmAccess =3D SMM_ACCESS_PRIVATE_DATA_FROM_THIS= (This);+=C2=A0 if
> (DescriptorIndex >=3D SmmAccess->NumberRegions) {+=C2=A0 =C2=A0 = DEBUG ((DEBUG_WARN, "SMRAM region out of range\n"));++
> return EFI_INVALID_PARAMETER;+=C2=A0 } else if (SmmAccess->SmramDes= c[DescriptorIndex].RegionState &
> EFI_SMRAM_LOCKED) {+=C2=A0 =C2=A0 //+=C2=A0 =C2=A0 // Cannot open a &q= uot;locked" region+=C2=A0 =C2=A0 //+=C2=A0 =C2=A0 DEBUG ((DEBUG_WARN, = "Cannot open a locked
> SMRAM region\n"));++=C2=A0 =C2=A0 return EFI_DEVICE_ERROR;+=C2=A0= }++=C2=A0 ///+=C2=A0 /// BEGIN CHIPSET CODE+=C2=A0 ///+=C2=A0 ///+=C2=A0 /= // SMRAM register
> is PCI 0:0:0:88, SMRAMC (8 bit)+=C2=A0 ///+=C2=A0 Address =3D PCI_SEGM= ENT_LIB_ADDRESS (0, SA_MC_BUS, SA_MC_DEV, SA_MC_FUN,
> R_SA_SMRAMC);+=C2=A0 SmramControl =3D PciSegmentRead8 (Address);+=C2= =A0 ///+=C2=A0 ///=C2=A0 Is SMRAM locked?+=C2=A0 ///+=C2=A0 if ((SmramContr= ol
> & B_SA_SMRAMC_D_LCK_MASK) !=3D 0) {+=C2=A0 =C2=A0 ///+=C2=A0 =C2= =A0 /// Cannot Open a locked region+=C2=A0 =C2=A0 ///+=C2=A0 =C2=A0 for (In= dex =3D 0; Index <
> SmmAccess->NumberRegions; Index++) {+=C2=A0 =C2=A0 =C2=A0 SmmAccess= ->SmramDesc[Index].RegionState |=3D
> EFI_SMRAM_LOCKED;+=C2=A0 =C2=A0 }+=C2=A0 =C2=A0 DEBUG ((DEBUG_WARN, &q= uot;Cannot open a locked SMRAM region\n"));+=C2=A0 =C2=A0 return
> EFI_DEVICE_ERROR;+=C2=A0 }+=C2=A0 ///+=C2=A0 /// Open SMRAM region+=C2= =A0 ///+=C2=A0 SmramControl |=3D B_SA_SMRAMC_D_OPEN_MASK;+
> SmramControl &=3D ~(B_SA_SMRAMC_D_CLS_MASK);++=C2=A0 PciSegmentWri= te8 (Address, SmramControl);+=C2=A0 ///+=C2=A0 /// END
> CHIPSET CODE+=C2=A0 ///++=C2=A0 SmmAccess->SmramDesc[DescriptorInde= x].RegionState &=3D (UINT64) ~(EFI_SMRAM_CLOSED |
> EFI_ALLOCATED);+=C2=A0 SmmAccess->SmramDesc[DescriptorIndex].Region= State |=3D (UINT64) EFI_SMRAM_OPEN;+
> SmmAccess->SmmAccess.OpenState =3D TRUE;+=C2=A0 return EFI_SUCCESS;= +}++/**+=C2=A0 This routine accepts a request to "close" a
> region of SMRAM.=C2=A0 This is valid for+=C2=A0 compatible SMRAM regio= n.++=C2=A0 @param[in] PeiServices=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-=C2=A0 = General purpose services
> available to every PEIM.+=C2=A0 @param[in] This=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -=C2=A0 Pointer to the SMM Access Interf= ace.+=C2=A0 @param[in] DescriptorIndex
> -=C2=A0 Region of SMRAM to Close.++=C2=A0 @retval EFI_SUCCESS=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -=C2=A0 The region was successfully clos= ed.+=C2=A0 @retval
> EFI_DEVICE_ERROR=C2=A0 =C2=A0 =C2=A0 =C2=A0-=C2=A0 The region could no= t be closed because locked by+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 chipset.+=C2=A0 @retval
> EFI_INVALID_PARAMETER=C2=A0 -=C2=A0 The descriptor index was out of bo= unds.+**/+EFI_STATUS+EFIAPI+Close (+=C2=A0 IN
> EFI_PEI_SERVICES=C2=A0 =C2=A0 =C2=A0 =C2=A0 **PeiServices,+=C2=A0 IN E= FI_PEI_MM_ACCESS_PPI=C2=A0 =C2=A0*This,+=C2=A0 IN UINTN=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DescriptorIndex+=C2=A0 )+{= +
> SMM_ACCESS_PRIVATE_DATA *SmmAccess;+=C2=A0 BOOLEAN=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0OpenState;+=C2=A0 UINT8=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index;+=C2=A0 UI= NT64
> Address;+=C2=A0 UINT8=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0SmramControl;++=C2=A0 SmmAccess =3D SMM_ACCESS_PRIVATE_= DATA_FROM_THIS (This);+=C2=A0 if
> (DescriptorIndex >=3D SmmAccess->NumberRegions) {+=C2=A0 =C2=A0 = DEBUG ((DEBUG_WARN, "SMRAM region out of range\n"));++
> return EFI_INVALID_PARAMETER;+=C2=A0 } else if (SmmAccess->SmramDes= c[DescriptorIndex].RegionState &
> EFI_SMRAM_LOCKED) {+=C2=A0 =C2=A0 //+=C2=A0 =C2=A0 // Cannot close a &= quot;locked" region+=C2=A0 =C2=A0 //+=C2=A0 =C2=A0 DEBUG ((DEBUG_WARN,= "Cannot close a locked
> SMRAM region\n"));++=C2=A0 =C2=A0 return EFI_DEVICE_ERROR;+=C2=A0= }++=C2=A0 if (SmmAccess->SmramDesc[DescriptorIndex].RegionState & > EFI_SMRAM_CLOSED) {+=C2=A0 =C2=A0 return EFI_DEVICE_ERROR;+=C2=A0 }++= =C2=A0 ///+=C2=A0 /// BEGIN CHIPSET CODE+=C2=A0 ///+=C2=A0 ///+=C2=A0 /// S= MRAM
> register is PCI 0:0:0:88, SMRAMC (8 bit)+=C2=A0 ///+=C2=A0 Address =3D= PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS, SA_MC_DEV,
> SA_MC_FUN, R_SA_SMRAMC);+=C2=A0 SmramControl =3D PciSegmentRead8 (Addr= ess);+=C2=A0 ///+=C2=A0 ///=C2=A0 Is SMRAM locked?+=C2=A0 ///+=C2=A0 if
> ((SmramControl & B_SA_SMRAMC_D_LCK_MASK) !=3D 0) {+=C2=A0 =C2=A0 /= //+=C2=A0 =C2=A0 /// Cannot Close a locked region+=C2=A0 =C2=A0 ///+=C2=A0 = =C2=A0 for (Index =3D 0;
> Index < SmmAccess->NumberRegions; Index++) {+=C2=A0 =C2=A0 =C2= =A0 SmmAccess->SmramDesc[Index].RegionState |=3D
> EFI_SMRAM_LOCKED;+=C2=A0 =C2=A0 }+=C2=A0 =C2=A0 DEBUG ((DEBUG_WARN, &q= uot;Cannot close a locked SMRAM region\n"));+=C2=A0 =C2=A0 return
> EFI_DEVICE_ERROR;+=C2=A0 }+=C2=A0 ///+=C2=A0 /// Close SMRAM region+= =C2=A0 ///+=C2=A0 SmramControl &=3D ~(B_SA_SMRAMC_D_OPEN_MASK);++
> PciSegmentWrite8 (Address, SmramControl);+=C2=A0 ///+=C2=A0 /// END CH= IPSET CODE+=C2=A0 ///++=C2=A0 SmmAccess-
> >SmramDesc[DescriptorIndex].RegionState &=3D (UINT64) ~EFI_SMRA= M_OPEN;+=C2=A0 SmmAccess-
> >SmramDesc[DescriptorIndex].RegionState |=3D (UINT64) (EFI_SMRAM_CL= OSED | EFI_ALLOCATED);++=C2=A0 //+=C2=A0 // Find out if any
> regions are still open+=C2=A0 //+=C2=A0 OpenState =3D FALSE;+=C2=A0 fo= r (Index =3D 0; Index < SmmAccess->NumberRegions; Index++) {+=C2=A0 = =C2=A0 if
> ((SmmAccess->SmramDesc[Index].RegionState & EFI_SMRAM_OPEN) =3D= =3D EFI_SMRAM_OPEN) {+=C2=A0 =C2=A0 =C2=A0 OpenState =3D
> TRUE;+=C2=A0 =C2=A0 }+=C2=A0 }++=C2=A0 SmmAccess->SmmAccess.OpenSta= te =3D OpenState;+=C2=A0 return EFI_SUCCESS;+}++/**+=C2=A0 This routine acc= epts a
> request to "lock" SMRAM.=C2=A0 The+=C2=A0 region could be le= gacy AB or TSEG near top of physical memory.+=C2=A0 The use of "lock&q= uot; means
> that the memory can no longer be opened+=C2=A0 to PEIM.++=C2=A0 @param= [in] PeiServices=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0- General purpose service= s available
> to every PEIM.+=C2=A0 @param[in] This=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 -=C2=A0 Pointer to the SMM Access Interface.+=C2= =A0 @param[in] DescriptorIndex=C2=A0 =C2=A0 =C2=A0-=C2=A0 Region
> of SMRAM to Lock.++=C2=A0 @retval EFI_SUCCESS=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 -=C2=A0 The region was successfully locked.+=C2=A0 @retva= l EFI_DEVICE_ERROR=C2=A0 =C2=A0 =C2=A0 =C2=A0-
> The region could not be locked because at least+=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 one range is still open.+=C2=A0 @retval
> EFI_INVALID_PARAMETER=C2=A0 -=C2=A0 The descriptor index was out of bo= unds.+**/+EFI_STATUS+EFIAPI+Lock (+=C2=A0 IN
> EFI_PEI_SERVICES=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 **PeiServices,+=C2= =A0 IN EFI_PEI_MM_ACCESS_PPI=C2=A0 =C2=A0 =C2=A0*This,+=C2=A0 IN UINTN=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0De= scriptorIndex+=C2=A0 )+{+
> SMM_ACCESS_PRIVATE_DATA *SmmAccess;+=C2=A0 UINT64=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Address;+=C2=A0 UINT8=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0SmramControl;++= =C2=A0 SmmAccess =3D
> SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+=C2=A0 if (DescriptorIndex &= gt;=3D SmmAccess->NumberRegions) {+=C2=A0 =C2=A0 DEBUG
> ((DEBUG_WARN, "SMRAM region out of range\n"));++=C2=A0 =C2= =A0 return EFI_INVALID_PARAMETER;+=C2=A0 } else if (SmmAccess-
> >SmmAccess.OpenState) {+=C2=A0 =C2=A0 DEBUG ((DEBUG_WARN, "Can= not lock SMRAM when SMRAM regions are still open\n"));++
> return EFI_DEVICE_ERROR;+=C2=A0 }++=C2=A0 SmmAccess->SmramDesc[Desc= riptorIndex].RegionState |=3D (UINT64)
> EFI_SMRAM_LOCKED;+=C2=A0 SmmAccess->SmmAccess.LockState =3D TRUE;++= =C2=A0 ///+=C2=A0 /// BEGIN CHIPSET CODE+=C2=A0 ///+=C2=A0 ///+=C2=A0 /// > SMRAM register is PCI 0:0:0:88, SMRAMC (8 bit)+=C2=A0 ///+=C2=A0 Addre= ss =3D PCI_SEGMENT_LIB_ADDRESS (0, SA_MC_BUS,
> SA_MC_DEV, SA_MC_FUN, R_SA_SMRAMC);+=C2=A0 SmramControl =3D PciSegment= Read8 (Address);++=C2=A0 ///+=C2=A0 /// Lock the
> SMRAM+=C2=A0 ///+=C2=A0 SmramControl |=3D B_SA_SMRAMC_D_LCK_MASK;++=C2= =A0 PciSegmentWrite8 (Address, SmramControl);+=C2=A0 ///+
> /// END CHIPSET CODE+=C2=A0 ///++=C2=A0 return EFI_SUCCESS;+}++/**+=C2= =A0 This routine services a user request to discover the
> SMRAM+=C2=A0 capabilities of this platform.=C2=A0 This will report the= possible+=C2=A0 ranges that are possible for SMRAM access, based
> upon the+=C2=A0 memory controller capabilities.++=C2=A0 @param[in] Pei= Services=C2=A0 =C2=A0 =C2=A0 =C2=A0 - General purpose services available to= every
> PEIM.+=C2=A0 @param[in] This=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0-=C2=A0 Pointer to the SMRAM Access Interface.+=C2=A0 @param[i= n, out] SmramMapSize=C2=A0 -=C2=A0 Pointer to
> the variable containing size of the+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0buffer to contain the description information.+=C2=A0 @par= am[in, out]
> SmramMap=C2=A0 =C2=A0 =C2=A0 -=C2=A0 Buffer containing the data descri= bing the Smram+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0region de= scriptors.++=C2=A0 @retval
> EFI_BUFFER_TOO_SMALL=C2=A0 -=C2=A0 The user did not provide a sufficie= nt buffer.+=C2=A0 @retval EFI_SUCCESS=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0-=C2=A0 The user provided a
> sufficiently-sized buffer.+**/+EFI_STATUS+EFIAPI+GetCapabilities (+=C2= =A0 IN EFI_PEI_SERVICES=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 **PeiServices,+=C2=A0 IN
> EFI_PEI_MM_ACCESS_PPI=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*This,+= =C2=A0 IN OUT UINTN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0*SmramMapSize,+=C2=A0 IN OUT EFI_SMRAM_DESCRIPTO= R
> *SmramMap+=C2=A0 )+{+=C2=A0 EFI_STATUS=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 Status;+=C2=A0 SMM_ACCESS_PRIVATE_DATA *SmmAccess;+=C2=A0= UINTN
> NecessaryBufferSize;++=C2=A0 SmmAccess=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0=3D SMM_ACCESS_PRIVATE_DATA_FROM_THIS (This);+=C2=A0 NecessaryBuf= ferSize =3D
> SmmAccess->NumberRegions * sizeof (EFI_SMRAM_DESCRIPTOR);+=C2=A0 if= (*SmramMapSize < NecessaryBufferSize) {+
> DEBUG ((DEBUG_WARN, "SMRAM Map Buffer too small\n"));++=C2= =A0 =C2=A0 Status =3D EFI_BUFFER_TOO_SMALL;+=C2=A0 } else {+
> CopyMem (SmramMap, SmmAccess->SmramDesc, NecessaryBufferSize);+=C2= =A0 =C2=A0 Status =3D EFI_SUCCESS;+=C2=A0 }++=C2=A0 *SmramMapSize
> =3D NecessaryBufferSize;+=C2=A0 return Status;+}++/**+=C2=A0 This func= tion is to install an SMM Access PPI+=C2=A0 - <b>Introduction</b&g= t; \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.++=C2=A0 =C2=A0 @retval EFI_SUCCESS=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0- Ppi successfully started and installed.+=C2=A0 =C2=A0= @retval EFI_NOT_FOUND=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0- Ppi
> can't be found.+=C2=A0 =C2=A0 @retval EFI_OUT_OF_RESOURCES=C2=A0 -= Ppi does not have enough resources to initialize the
> driver.+**/+EFI_STATUS+EFIAPI+PeiInstallSmmAccessPpi (+=C2=A0 VOID+=C2= =A0 )+{+=C2=A0 EFI_STATUS=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 Status;+=C2=A0 UINTN
> Index;+=C2=A0 EFI_PEI_PPI_DESCRIPTOR=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= *PpiList;+=C2=A0 EFI_SMRAM_HOB_DESCRIPTOR_BLOCK=C2=A0 *DescriptorBlock;+ > SMM_ACCESS_PRIVATE_DATA=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*SmmAccessPri= vate;+=C2=A0 VOID=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *HobList;++=C2=A0 //+=C2=A0 // In= itialize private data+
> //+=C2=A0 SmmAccessPrivate=C2=A0 =3D AllocateZeroPool (sizeof (*SmmAcc= essPrivate));+=C2=A0 ASSERT (SmmAccessPrivate !=3D NULL);+=C2=A0 if
> (SmmAccessPrivate =3D=3D NULL) {+=C2=A0 =C2=A0 return EFI_OUT_OF_RESOU= RCES;+=C2=A0 }+=C2=A0 PpiList=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D A= llocateZeroPool (sizeof
> (*PpiList));+=C2=A0 ASSERT (PpiList !=3D NULL);+=C2=A0 if (PpiList =3D= =3D NULL) {+=C2=A0 =C2=A0 return EFI_OUT_OF_RESOURCES;+=C2=A0 }++
> SmmAccessPrivate->Signature =3D SMM_ACCESS_PRIVATE_DATA_SIGNATURE;+= =C2=A0 SmmAccessPrivate->Handle=C2=A0 =C2=A0 =3D NULL;++
> //+=C2=A0 // Get Hob list+=C2=A0 //+=C2=A0 HobList =3D GetFirstGuidHob= (&gEfiSmmSmramMemoryGuid);+=C2=A0 if (HobList =3D=3D NULL) {+=C2=A0 = =C2=A0 DEBUG
> ((DEBUG_WARN, "SmramMemoryReserve HOB not found\n"));+=C2=A0= =C2=A0 return EFI_NOT_FOUND;+=C2=A0 }++=C2=A0 DescriptorBlock =3D
> (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *) ((UINT8 *) HobList + sizeof (EFI_HO= B_GUID_TYPE));++=C2=A0 //+=C2=A0 // Alloc space for
> SmmAccessPrivate->SmramDesc+=C2=A0 //+=C2=A0 SmmAccessPrivate->S= mramDesc =3D AllocateZeroPool ((DescriptorBlock-
> >NumberOfSmmReservedRegions) * sizeof (EFI_SMRAM_DESCRIPTOR));+=C2= =A0 if (SmmAccessPrivate->SmramDesc =3D=3D NULL)
> {+=C2=A0 =C2=A0 DEBUG ((DEBUG_WARN, "Alloc SmmAccessPrivate->S= mramDesc fail.\n"));+=C2=A0 =C2=A0 return EFI_OUT_OF_RESOURCES;+=C2=A0= }++
> DEBUG ((DEBUG_INFO, "Alloc SmmAccessPrivate->SmramDesc success= .\n"));++=C2=A0 //+=C2=A0 // use the hob to publish SMRAM
> capabilities+=C2=A0 //+=C2=A0 for (Index =3D 0; Index < DescriptorB= lock->NumberOfSmmReservedRegions; Index++) {+
> SmmAccessPrivate->SmramDesc[Index].PhysicalStart=C2=A0 =3D Descript= orBlock->Descriptor[Index].PhysicalStart;+
> SmmAccessPrivate->SmramDesc[Index].CpuStart=C2=A0 =C2=A0 =C2=A0 =C2= =A0=3D DescriptorBlock->Descriptor[Index].CpuStart;+
> SmmAccessPrivate->SmramDesc[Index].PhysicalSize=C2=A0 =C2=A0=3D Des= criptorBlock->Descriptor[Index].PhysicalSize;+
> SmmAccessPrivate->SmramDesc[Index].RegionState=C2=A0 =C2=A0 =3D Des= criptorBlock->Descriptor[Index].RegionState;+=C2=A0 }++
> SmmAccessPrivate->NumberRegions=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0=3D Index;+=C2=A0 SmmAccessPrivate->SmmAccess.Open=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D Open;+
> SmmAccessPrivate->SmmAccess.Close=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0=3D Close;+=C2=A0 SmmAccessPrivate->SmmAccess.Lock=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D Lock;+
> SmmAccessPrivate->SmmAccess.GetCapabilities =3D GetCapabilities;+= =C2=A0 SmmAccessPrivate->SmmAccess.LockState=C2=A0 =C2=A0 =C2=A0 =C2=A0= =3D
> FALSE;+=C2=A0 SmmAccessPrivate->SmmAccess.OpenState=C2=A0 =C2=A0 = =C2=A0 =C2=A0=3D FALSE;++=C2=A0 //+=C2=A0 // Install PPI+=C2=A0 //+=C2=A0 P= piList->Flags=C2=A0 =3D
> (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);+= =C2=A0 PpiList->Guid=C2=A0 =C2=A0=3D
> &gEfiPeiMmAccessPpiGuid;+=C2=A0 PpiList->Ppi=C2=A0 =C2=A0 =3D &= amp;SmmAccessPrivate->SmmAccess;++=C2=A0 Status=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =3D PeiServicesInstallPpi
> (PpiList);+=C2=A0 ASSERT_EFI_ERROR (Status);++=C2=A0 return EFI_SUCCES= S;+}diff --git
> a/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccess= LibSmramc/PeiSmmAccessLib.inf
> b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAccess= LibSmramc/PeiSmmAccessLib.inf
> new file mode 100644
> index 000000000000..916346aacff3
> --- /dev/null
> +++ b/Silicon/Intel/IntelSiliconPkg/Feature/SmmAccess/Library/PeiSmmAc= ce
> +++ ssLibSmramc/PeiSmmAccessLib.inf
> @@ -0,0 +1,41 @@
> +## @file+# Library description file for the SmmAccess PPI+#+# Copyrig= ht
> +(c) 2019, Intel Corporation. All rights reserved.<BR>+#
> +SPDX-License-Identifier:
> +BSD-2-Clause-Patent+#+##++[Defines]+INF_VERSION =3D 0x00010017+BASE_N= AME
> +=3D PeiSmmAccessLibSmramc+FILE_GUID =3D
> +3D28FD4B-F46F-4E24-88AA-9DA09C51BE87+VERSION_STRING =3D 1.0+MODULE_TY= PE =3D PEIM+LIBRARY_CLASS =3D
> SmmAccessLib+++[LibraryClasses]+BaseMemoryLib+MemoryAllocationLib+Debu= gLib+HobLib+PciSegmentLib+PeiServicesL
> ib+++[Packages]+MdePkg/MdePkg.dec+IntelSiliconPkg/IntelSiliconPkg.dec+= ++[Sources]+PeiSmmAccessLib.c+++[Ppis]+gE
> fiPeiMmAccessPpiGuid ## PRODUCES+++[Guids]+gEfiSmmSmramMemoryGuid-- > 2.37.2

--000000000000f8592105e76b1689--