From nobody Mon Feb 9 04:03:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+91755+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91755+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1658535731; cv=none; d=zohomail.com; s=zohoarc; b=h5gJTSmaUDzAQhOoGaVkLMgli3BxQuLMylLmJjCA96Bj+EuIh7fF7mwtveOssJtb2l9S1zvV4RcaeImv6mVS7l+fwCcQY65gYAq68tfGP8jNztihED/osPFRXEDD56Ryykcsl/R5q+ygGnnr2ksWHdqOtrcJi2NYEXutzG034G0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658535731; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=RCIgzjYzEXMkZDX60mCi1fDHlwi7p3FUkOiT8smoNxI=; b=WWe18vLCUfXVnZi7upH6mI3OSIBzt2jk/tawvHdBzPeXt/Tys1JlYRV+E8Vv2fd/nj5zZqECq8+ld97aV7bY2N5OjLZoJcDwrz4nuGf+lFrxT70rCqkWyO5k80g72fUSLbkB4LFHrwIxpeGnTuMMFdx2igL9OmRN/0h/dm6WNjo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91755+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1658535731307230.35096803186934; Fri, 22 Jul 2022 17:22:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gvBrYY1788612xgUTp9UbNhv; Fri, 22 Jul 2022 17:22:10 -0700 X-Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by mx.groups.io with SMTP id smtpd.web10.1676.1658535730191670103 for ; Fri, 22 Jul 2022 17:22:10 -0700 X-Received: by mail-qk1-f178.google.com with SMTP id l3so4802482qkl.3 for ; Fri, 22 Jul 2022 17:22:10 -0700 (PDT) X-Gm-Message-State: YaGig4mARgGNRQiObam6S9Iex1787277AA= X-Google-Smtp-Source: AGRyM1tKtbcGOlKxLSqpNDxKLZ0i+xR+MtGqBsVIXYXpbzewI50DDKyT7WdESxE/Gg+9uvLJ+pFE1g== X-Received: by 2002:a05:620a:2710:b0:6b5:bf24:10e9 with SMTP id b16-20020a05620a271000b006b5bf2410e9mr1977564qkp.28.1658535729107; Fri, 22 Jul 2022 17:22:09 -0700 (PDT) X-Received: from aturtleortwo-benjamindomain.. ([2607:f2c0:e98c:e:39b7:8453:91b5:69bf]) by smtp.gmail.com with ESMTPSA id z8-20020ac84308000000b0031ee1f0c420sm3766705qtm.10.2022.07.22.17.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 17:22:08 -0700 (PDT) From: "Benjamin Doron" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Ankit Sinha , Isaac Oram , Liming Gao , Eric Dong Subject: [edk2-devel] [PATCH v1 4/5] [WIP] MinPlatformPkg: Implement S3 resume Date: Fri, 22 Jul 2022 20:20:00 -0400 Message-Id: <20220723002001.1309418-5-benjamin.doron00@gmail.com> In-Reply-To: <20220723002001.1309418-1-benjamin.doron00@gmail.com> References: <20220723002001.1309418-1-benjamin.doron00@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,benjamin.doron00@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1658535730; bh=ClB9icheMcrc2GjKh/ZRbYTrTIY4OVsJKfL3WlI6eC0=; h=Cc:Date:From:Reply-To:Subject:To; b=Ph26lXL37rK0NFSpZrxTAyPHP73TM8/ow3MGYbjqQzSMXPzcaact97948xTkPbL8xw7 ABXsMvMcKYqEaHNbmXX20ZLeKbMcf1L8zHKwywHHIGd36pEizjGPRQr4sOBKnfj3HtYWD TbRZqx0bl8nE5OghqotYCleaYYxzn3VHRro= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1658535733384100019 Content-Type: text/plain; charset="utf-8" Allocate memory to use on S3 resume. TODO: Size calculation, confirm implementation goes in this module. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Ankit Sinha Cc: Isaac Oram Cc: Liming Gao Cc: Eric Dong Signed-off-by: Benjamin Doron --- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c = | 133 ++++++++++++++++++++ Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h = | 4 + Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf = | 6 + Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLi= b/FspWrapperHobProcessLib.c | 70 ++++++++++- Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLi= b/PeiFspWrapperHobProcessLib.inf | 2 + Platform/Intel/MinPlatformPkg/Include/AcpiS3MemoryNvData.h = | 22 ++++ Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc = | 4 + Platform/Intel/MinPlatformPkg/Include/Fdf/CorePostMemoryInclude.fdf = | 4 + 8 files changed, 244 insertions(+), 1 deletion(-) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b= /Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index c7e87cbd7d9d..1d369e7a6541 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -1424,6 +1424,135 @@ AcpiEndOfDxeEvent ( IsHardwareChange (); } =20 +/** + Get the mem size in memory type infromation table. + + @return the mem size in memory type infromation table. +**/ +STATIC +UINT64 +GetMemorySizeInMemoryTypeInformation ( + VOID + ) +{ + EFI_STATUS Status; + EFI_MEMORY_TYPE_INFORMATION *MemoryData; + UINT8 Index; + UINTN TempPageNum; + + Status =3D EfiGetSystemConfigurationTable (&gEfiMemoryTypeInformationGui= d, (VOID **) &MemoryData); + + if (EFI_ERROR (Status) || MemoryData =3D=3D NULL) { + return 0; + } + + TempPageNum =3D 0; + for (Index =3D 0; MemoryData[Index].Type !=3D EfiMaxMemoryType; Index++)= { + // + // Accumulate default memory size requirements + // + TempPageNum +=3D MemoryData[Index].NumberOfPages; + } + + return TempPageNum * EFI_PAGE_SIZE; +} + +/** + Get the mem size need to be consumed and reserved for PEI phase resume. + + @return the mem size to be reserved for PEI phase resume. +**/ +STATIC +UINT64 +GetPeiMemSize ( + VOID + ) +{ + #define PEI_ADDITIONAL_MEMORY_SIZE (16 * EFI_PAGE_SIZE) + + UINT64 Size; + + Size =3D GetMemorySizeInMemoryTypeInformation (); + + return PcdGet32 (PcdPeiMinMemSize) + Size + PEI_ADDITIONAL_MEMORY_SIZE; +} + +/** + Allocate EfiACPIMemoryNVS below 4G memory address. + + This function allocates EfiACPIMemoryNVS below 4G memory address. + + @param Size Size of memory to allocate. + + @return Allocated address for output. + +**/ +VOID * +AllocateAcpiNvsMemoryBelow4G ( + IN UINTN Size + ) +{ + UINTN Pages; + EFI_PHYSICAL_ADDRESS Address; + EFI_STATUS Status; + VOID *Buffer; + + Pages =3D EFI_SIZE_TO_PAGES (Size); + Address =3D 0xffffffff; + + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiACPIMemoryNVS, + Pages, + &Address + ); + ASSERT_EFI_ERROR (Status); + + Buffer =3D (VOID *)(UINTN)Address; + ZeroMem (Buffer, Size); + + return Buffer; +} + +/** + Allocates memory to use on S3 resume +**/ +STATIC +VOID +EFIAPI +AllocateS3ResumeMemory ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 S3PeiMemBase; + UINT64 S3PeiMemSize; + ACPI_S3_MEMORY S3MemoryInfo; + + DEBUG ((DEBUG_INFO, "%a() Start\n", __FUNCTION__)); + + S3PeiMemSize =3D GetPeiMemSize (); + S3PeiMemBase =3D (UINTN) AllocateAcpiNvsMemoryBelow4G (S3PeiMemSize); + ASSERT (S3PeiMemBase !=3D 0); + + S3MemoryInfo.S3PeiMemBase =3D S3PeiMemBase; + S3MemoryInfo.S3PeiMemSize =3D S3PeiMemSize; + + DEBUG ((DEBUG_INFO, "S3PeiMemBase: 0x%x\n", S3PeiMemBase)); + DEBUG ((DEBUG_INFO, "S3PeiMemSize: 0x%x\n", S3PeiMemSize)); + + Status =3D gRT->SetVariable ( + ACPI_S3_MEMORY_NV_NAME, + &gEfiAcpiVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACC= ESS, + sizeof (S3MemoryInfo), + &S3MemoryInfo + ); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "%a() End\n", __FUNCTION__)); +} + /** ACPI Platform driver installation function. =20 @@ -1493,5 +1622,9 @@ InstallAcpiPlatform ( InstallMadtFromScratch (); InstallMcfgFromScratch (); =20 + //if (FeaturePcdGet (PcdS3FeatureEnable)) { + AllocateS3ResumeMemory (); + //} + return EFI_SUCCESS; } diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h b= /Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h index 9bdc482f4382..381bdd25f671 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.h @@ -21,8 +21,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include +#include #include #include #include @@ -43,4 +45,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 +#include + #endif diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf= b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf index 31b6c3be3cc1..1b59427d3452 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf @@ -28,6 +28,7 @@ MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec MinPlatformPkg/MinPlatformPkg.dec + IntelFsp2WrapperPkg/IntelFsp2WrapperPkg.dec PcAtChipsetPkg/PcAtChipsetPkg.dec =20 [LibraryClasses] @@ -115,6 +116,9 @@ =20 gMinPlatformPkgTokenSpaceGuid.PcdWsmtProtectionFlags =20 + #gS3FeaturePkgTokenSpaceGuid.PcdS3FeatureEnable + gIntelFsp2WrapperTokenSpaceGuid.PcdPeiMinMemSize + [Protocols] gEfiAcpiTableProtocolGuid ## CONSUMES gEfiMpServiceProtocolGuid ## CONSUMES @@ -124,6 +128,8 @@ gEfiGlobalVariableGuid ## CONSUMES gEfiHobListGuid ## CONSUMES gEfiEndOfDxeEventGroupGuid ## CONSUMES + gEfiMemoryTypeInformationGuid ## CONSUMES + gEfiAcpiVariableGuid ## CONSUMES =20 [Depex] gEfiAcpiTableProtocolGuid AND diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapper= HobProcessLib/FspWrapperHobProcessLib.c b/Platform/Intel/MinPlatformPkg/Fsp= Wrapper/Library/PeiFspWrapperHobProcessLib/FspWrapperHobProcessLib.c index 7ee4d3a31c49..992ec5d41bd8 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProc= essLib/FspWrapperHobProcessLib.c +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProc= essLib/FspWrapperHobProcessLib.c @@ -16,14 +16,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include #include #include #include +#include =20 #include +#include =20 // // Additional pages are used by DXE memory manager. @@ -130,6 +133,55 @@ GetPeiMemSize ( return MinSize + Size + PEI_ADDITIONAL_MEMORY_SIZE; } =20 +/** + Get S3 PEI memory information. + + @note At this point, memory is ready, and PeiServices are available to u= se. + Platform can get some data from SMRAM directly. + + @param[out] S3PeiMemSize PEI memory size to be installed in S3 phase. + @param[out] S3PeiMemBase PEI memory base to be installed in S3 phase. + + @return If S3 PEI memory information is got successfully. +**/ +EFI_STATUS +EFIAPI +GetS3MemoryInfo ( + OUT UINT64 *S3PeiMemSize, + OUT EFI_PHYSICAL_ADDRESS *S3PeiMemBase + ) +{ + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi; + UINTN DataSize; + ACPI_S3_MEMORY S3MemoryInfo; + + *S3PeiMemBase =3D 0; + *S3PeiMemSize =3D 0; + + Status =3D PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NU= LL, (VOID **) &VariablePpi); + ASSERT_EFI_ERROR (Status); + + DataSize =3D sizeof (S3MemoryInfo); + Status =3D VariablePpi->GetVariable ( + VariablePpi, + ACPI_S3_MEMORY_NV_NAME, + &gEfiAcpiVariableGuid, + NULL, + &DataSize, + &S3MemoryInfo + ); + ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + return Status; + } + + *S3PeiMemBase =3D S3MemoryInfo.S3PeiMemBase; + *S3PeiMemSize =3D S3MemoryInfo.S3PeiMemSize; + return EFI_SUCCESS; +} + /** Post FSP-M HOB process for Memory Resource Descriptor. =20 @@ -280,7 +332,7 @@ PostFspmHobProcess ( 0x1000 ); =20 - + if (BootMode !=3D BOOT_ON_S3_RESUME) { // // Capsule mode // @@ -337,7 +389,23 @@ PostFspmHobProcess ( if (Capsule !=3D NULL) { Status =3D Capsule->CreateState ((EFI_PEI_SERVICES **)PeiServices, C= apsuleBuffer, CapsuleBufferLength); } + } else { + // TODO: Must BuildResourceDescriptorHob()? + Status =3D GetS3MemoryInfo (&PeiMemSize, &PeiMemBase); + ASSERT_EFI_ERROR (Status); =20 + DEBUG ((DEBUG_INFO, "S3 resume PeiMemBase : 0x%08x\n", PeiMemBa= se)); + DEBUG ((DEBUG_INFO, "S3 resume PeiMemSize : 0x%08x\n", PeiMemSi= ze)); + + // + // Install efi memory + // + Status =3D PeiServicesInstallPeiMemory ( + PeiMemBase, + PeiMemSize + ); + ASSERT_EFI_ERROR (Status); + } =20 // // Create a memory allocation HOB at fixed location for MP Services PPI = AP wait loop. diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapper= HobProcessLib/PeiFspWrapperHobProcessLib.inf b/Platform/Intel/MinPlatformPk= g/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.= inf index b846e7af1d2d..e2aac36bf018 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProc= essLib/PeiFspWrapperHobProcessLib.inf +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProc= essLib/PeiFspWrapperHobProcessLib.inf @@ -75,7 +75,9 @@ gZeroGuid gEfiGraphicsInfoHobGuid gEfiGraphicsDeviceInfoHobGuid + gEfiAcpiVariableGuid =20 [Ppis] gEfiPeiCapsulePpiGuid ## CONSUMES + gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES gEdkiiSiliconInitializedPpiGuid ## PRODUCES diff --git a/Platform/Intel/MinPlatformPkg/Include/AcpiS3MemoryNvData.h b/P= latform/Intel/MinPlatformPkg/Include/AcpiS3MemoryNvData.h new file mode 100644 index 000000000000..0d75af8e9a03 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/AcpiS3MemoryNvData.h @@ -0,0 +1,22 @@ +/** @file + Header file for NV data structure definition. + +Copyright (c) 2021, Baruch Binyamin Doron +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __ACPI_S3_MEMORY_NV_DATA_H__ +#define __ACPI_S3_MEMORY_NV_DATA_H__ + +// +// NV data structure +// +typedef struct { + UINT64 S3PeiMemBase; + UINT64 S3PeiMemSize; +} ACPI_S3_MEMORY; + +#define ACPI_S3_MEMORY_NV_NAME L"S3MemoryInfo" + +#endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc b= /Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc index 08e50cac075f..0eb0cc8306ee 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiInclude.dsc @@ -41,3 +41,7 @@ NULL|SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256= .inf } !endif + +!if gMinPlatformPkgTokenSpaceGuid.PcdBootToShellOnly =3D=3D FALSE && gS3Fe= aturePkgTokenSpaceGuid.PcdS3FeatureEnable =3D=3D TRUE + MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerf= ormancePei.inf +!endif diff --git a/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePostMemoryInclud= e.fdf b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePostMemoryInclude.fdf index 3c2716d6728a..d8fb6683f7d4 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePostMemoryInclude.fdf +++ b/Platform/Intel/MinPlatformPkg/Include/Fdf/CorePostMemoryInclude.fdf @@ -6,3 +6,7 @@ # SPDX-License-Identifier: BSD-2-Clause-Patent # ## + +!if gMinPlatformPkgTokenSpaceGuid.PcdBootToShellOnly =3D=3D FALSE && gS3Fe= aturePkgTokenSpaceGuid.PcdS3FeatureEnable =3D=3D TRUE + INF MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/Firmwar= ePerformancePei.inf +!endif --=20 2.36.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91755): https://edk2.groups.io/g/devel/message/91755 Mute This Topic: https://groups.io/mt/92559634/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-