From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7A1B2210D43AD for ; Sun, 12 Aug 2018 22:42:04 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2018 22:42:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,232,1531810800"; d="scan'208";a="65665923" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga006.jf.intel.com with ESMTP; 12 Aug 2018 22:42:03 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 12 Aug 2018 22:42:03 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.143]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.205]) with mapi id 14.03.0319.002; Mon, 13 Aug 2018 13:42:01 +0800 From: "Ni, Ruiyu" To: "Dong, Eric" , "edk2-devel@lists.01.org" CC: =?iso-8859-1?Q?Marvin_H=E4user?= , Fan Jeff , Laszlo Ersek Thread-Topic: [Patch v3 5/5] UefiCpuPkg/RegisterCpuFeaturesLib: Combine implementation. Thread-Index: AQHUMGFeHz9e44ir00uvW+B3XaK9aqS9L9Ow Date: Mon, 13 Aug 2018 05:41:21 +0000 Deferred-Delivery: Mon, 13 Aug 2018 05:42:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BDD0778@SHSMSX104.ccr.corp.intel.com> References: <20180810041909.12776-1-eric.dong@intel.com> <20180810041909.12776-6-eric.dong@intel.com> In-Reply-To: <20180810041909.12776-6-eric.dong@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v3 5/5] UefiCpuPkg/RegisterCpuFeaturesLib: Combine implementation. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Aug 2018 05:42:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: Dong, Eric > Sent: Friday, August 10, 2018 12:19 PM > To: edk2-devel@lists.01.org > Cc: Marvin H=E4user ; Fan Jeff > ; Laszlo Ersek ; Ni, Ruiyu > > Subject: [Patch v3 5/5] UefiCpuPkg/RegisterCpuFeaturesLib: Combine > implementation. >=20 > V1 changes: > > Current code logic can't confirm CpuS3DataDxe driver start before > > CpuFeaturesDxe driver. So the assumption in CpuFeaturesDxe not valid. > > Add implementation for AllocateAcpiCpuData function to remove this > > assumption. >=20 > V2 changes: > > Because CpuS3Data memory will be copy to smram at SmmReadToLock > point, > > so the memory type no need to be ACPI NVS type, also the address not > > limit to below 4G. > > This change remove the limit of ACPI NVS memory type and below 4G. >=20 > V3 changes: > > Remove function definition in header file. > > Add STATIC in function implementation. >=20 > Pass OS boot and resume from S3 test. >=20 > Bugz: https://bugzilla.tianocore.org/show_bug.cgi?id=3D959 >=20 > Reported-by: Marvin H=E4user > Suggested-by: Fan Jeff > Cc: Marvin H=E4user > Cc: Fan Jeff > Cc: Laszlo Ersek > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > .../DxeRegisterCpuFeaturesLib.c | 67 ----------- > .../PeiRegisterCpuFeaturesLib.c | 131 ---------------= ------ > .../RegisterCpuFeaturesLib/RegisterCpuFeatures.h | 20 ---- > .../RegisterCpuFeaturesLib.c | 92 +++++++++++++++ > 4 files changed, 92 insertions(+), 218 deletions(-) >=20 > diff --git > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c > index 902a339529..1f34a3f489 100644 > --- > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c > +++ > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLi > +++ b.c > @@ -197,70 +197,3 @@ GetNumberOfProcessor ( > ASSERT_EFI_ERROR (Status); > } >=20 > -/** > - Allocates ACPI NVS memory to save ACPI_CPU_DATA. > - > - @return Pointer to allocated ACPI_CPU_DATA. > -**/ > -ACPI_CPU_DATA * > -AllocateAcpiCpuData ( > - VOID > - ) > -{ > - // > - // CpuS3DataDxe will do it. > - // > - ASSERT (FALSE); > - return NULL; > -} > - > -/** > - Enlarges CPU register table for each processor. > - > - @param[in, out] RegisterTable Pointer processor's CPU register tabl= e > -**/ > -VOID > -EnlargeRegisterTable ( > - IN OUT CPU_REGISTER_TABLE *RegisterTable > - ) > -{ > - EFI_STATUS Status; > - EFI_PHYSICAL_ADDRESS Address; > - UINTN AllocatePages; > - > - Address =3D BASE_4GB - 1; > - AllocatePages =3D RegisterTable->AllocatedSize / EFI_PAGE_SIZE; > - Status =3D gBS->AllocatePages ( > - AllocateMaxAddress, > - EfiACPIMemoryNVS, > - AllocatePages + 1, > - &Address > - ); > - ASSERT_EFI_ERROR (Status); > - > - // > - // If there are records existing in the register table, then copy its = contents > - // to new region and free the old one. > - // > - if (RegisterTable->AllocatedSize > 0) { > - CopyMem ( > - (VOID *) (UINTN) Address, > - (VOID *) (UINTN) RegisterTable->RegisterTableEntry, > - RegisterTable->AllocatedSize > - ); > - // > - // RegisterTableEntry is allocated by gBS->AllocatePages() service. > - // So, gBS->FreePages() service is used to free it. > - // > - gBS->FreePages ( > - RegisterTable->RegisterTableEntry, > - AllocatePages > - ); > - } > - > - // > - // Adjust the allocated size and register table base address. > - // > - RegisterTable->AllocatedSize +=3D EFI_PAGE_SIZE; > - RegisterTable->RegisterTableEntry =3D Address; -} diff --git > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c > index 6804eddf65..82fe268812 100644 > --- > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c > +++ > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLi > +++ b.c > @@ -257,134 +257,3 @@ GetNumberOfProcessor ( > ); > ASSERT_EFI_ERROR (Status); > } > - > -/** > - Allocates ACPI NVS memory to save ACPI_CPU_DATA. > - > - @return Pointer to allocated ACPI_CPU_DATA. > -**/ > -ACPI_CPU_DATA * > -AllocateAcpiCpuData ( > - VOID > - ) > -{ > - EFI_STATUS Status; > - EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; > - UINTN NumberOfCpus; > - UINTN NumberOfEnabledProcessors; > - ACPI_CPU_DATA *AcpiCpuData; > - EFI_PHYSICAL_ADDRESS Address; > - UINTN TableSize; > - CPU_REGISTER_TABLE *RegisterTable; > - UINTN Index; > - EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; > - > - Status =3D PeiServicesAllocatePages ( > - EfiACPIMemoryNVS, > - EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)), > - &Address > - ); > - ASSERT_EFI_ERROR (Status); > - AcpiCpuData =3D (ACPI_CPU_DATA *) (UINTN) Address; > - ASSERT (AcpiCpuData !=3D NULL); > - > - // > - // Get MP Services Protocol > - // > - Status =3D PeiServicesLocatePpi ( > - &gEfiPeiMpServicesPpiGuid, > - 0, > - NULL, > - (VOID **)&CpuMpPpi > - ); > - ASSERT_EFI_ERROR (Status); > - > - // > - // Get the number of CPUs > - // > - Status =3D CpuMpPpi->GetNumberOfProcessors ( > - GetPeiServicesTablePointer (), > - CpuMpPpi, > - &NumberOfCpus, > - &NumberOfEnabledProcessors > - ); > - ASSERT_EFI_ERROR (Status); > - AcpiCpuData->NumberOfCpus =3D (UINT32)NumberOfCpus; > - > - // > - // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable > for all CPUs > - // > - TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); > - Status =3D PeiServicesAllocatePages ( > - EfiACPIMemoryNVS, > - EFI_SIZE_TO_PAGES (TableSize), > - &Address > - ); > - ASSERT_EFI_ERROR (Status); > - RegisterTable =3D (CPU_REGISTER_TABLE *) (UINTN) Address; > - > - for (Index =3D 0; Index < NumberOfCpus; Index++) { > - Status =3D CpuMpPpi->GetProcessorInfo ( > - GetPeiServicesTablePointer (), > - CpuMpPpi, > - Index, > - &ProcessorInfoBuffer > - ); > - ASSERT_EFI_ERROR (Status); > - > - RegisterTable[Index].InitialApicId =3D > (UINT32)ProcessorInfoBuffer.ProcessorId; > - RegisterTable[Index].TableLength =3D 0; > - RegisterTable[Index].AllocatedSize =3D 0; > - RegisterTable[Index].RegisterTableEntry =3D 0; > - > - RegisterTable[NumberOfCpus + Index].InitialApicId =3D > (UINT32)ProcessorInfoBuffer.ProcessorId; > - RegisterTable[NumberOfCpus + Index].TableLength =3D 0; > - RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; > - RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; > - } > - AcpiCpuData->RegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable; > - AcpiCpuData->PreSmmInitRegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus); > - > - return AcpiCpuData; > -} > - > -/** > - Enlarges CPU register table for each processor. > - > - @param[in, out] RegisterTable Pointer processor's CPU register tabl= e > -**/ > -VOID > -EnlargeRegisterTable ( > - IN OUT CPU_REGISTER_TABLE *RegisterTable > - ) > -{ > - EFI_STATUS Status; > - EFI_PHYSICAL_ADDRESS Address; > - UINTN AllocatePages; > - > - AllocatePages =3D RegisterTable->AllocatedSize / EFI_PAGE_SIZE; > - Status =3D PeiServicesAllocatePages ( > - EfiACPIMemoryNVS, > - AllocatePages + 1, > - &Address > - ); > - ASSERT_EFI_ERROR (Status); > - > - // > - // If there are records existing in the register table, then copy its = contents > - // to new region and free the old one. > - // > - if (RegisterTable->AllocatedSize > 0) { > - CopyMem ( > - (VOID *) (UINTN) Address, > - (VOID *) (UINTN) RegisterTable->RegisterTableEntry, > - RegisterTable->AllocatedSize > - ); > - } > - > - // > - // Adjust the allocated size and register table base address. > - // > - RegisterTable->AllocatedSize +=3D EFI_PAGE_SIZE; > - RegisterTable->RegisterTableEntry =3D Address; -} diff --git > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > index 69b412172a..edd266934f 100644 > --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > @@ -87,26 +87,6 @@ GetCpuFeaturesData ( > VOID > ); >=20 > -/** > - Enlarges CPU register table for each processor. > - > - @param[in, out] RegisterTable Pointer processor's CPU register tabl= e > -**/ > -VOID > -EnlargeRegisterTable ( > - IN OUT CPU_REGISTER_TABLE *RegisterTable > - ); > - > -/** > - Allocates ACPI NVS memory to save ACPI_CPU_DATA. > - > - @return Pointer to allocated ACPI_CPU_DATA. > -**/ > -ACPI_CPU_DATA * > -AllocateAcpiCpuData ( > - VOID > - ); > - > /** > Worker function to return processor index. >=20 > diff --git > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > index dd6a82be7a..4143ee4bb1 100644 > --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > +++ > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > @@ -488,6 +488,98 @@ RegisterCpuFeature ( > return RETURN_SUCCESS; > } >=20 > +/** > + Allocates boot service data to save ACPI_CPU_DATA. > + > + @return Pointer to allocated ACPI_CPU_DATA. > +**/ > +STATIC > +ACPI_CPU_DATA * > +AllocateAcpiCpuData ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + UINTN NumberOfCpus; > + UINTN NumberOfEnabledProcessors; > + ACPI_CPU_DATA *AcpiCpuData; > + UINTN TableSize; > + CPU_REGISTER_TABLE *RegisterTable; > + UINTN Index; > + EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; > + > + AcpiCpuData =3D AllocatePages (EFI_SIZE_TO_PAGES (sizeof > + (ACPI_CPU_DATA))); ASSERT (AcpiCpuData !=3D NULL); > + > + GetNumberOfProcessor (&NumberOfCpus, > &NumberOfEnabledProcessors); > + AcpiCpuData->NumberOfCpus =3D (UINT32)NumberOfCpus; > + > + // > + // Allocate buffer for empty RegisterTable and > + PreSmmInitRegisterTable for all CPUs // TableSize =3D 2 * NumberOfCpu= s > + * sizeof (CPU_REGISTER_TABLE); RegisterTable =3D AllocatePages > + (EFI_SIZE_TO_PAGES (TableSize)); ASSERT (RegisterTable !=3D NULL); > + > + for (Index =3D 0; Index < NumberOfCpus; Index++) { > + Status =3D GetProcessorInformation (Index, &ProcessorInfoBuffer); > + ASSERT_EFI_ERROR (Status); > + > + RegisterTable[Index].InitialApicId =3D > (UINT32)ProcessorInfoBuffer.ProcessorId; > + RegisterTable[Index].TableLength =3D 0; > + RegisterTable[Index].AllocatedSize =3D 0; > + RegisterTable[Index].RegisterTableEntry =3D 0; > + > + RegisterTable[NumberOfCpus + Index].InitialApicId =3D > (UINT32)ProcessorInfoBuffer.ProcessorId; > + RegisterTable[NumberOfCpus + Index].TableLength =3D 0; > + RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; > + RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; } > + AcpiCpuData->RegisterTable =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable; > + AcpiCpuData->PreSmmInitRegisterTable =3D > + (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus); > + > + return AcpiCpuData; > +} > + > +/** > + Enlarges CPU register table for each processor. > + > + @param[in, out] RegisterTable Pointer processor's CPU register tabl= e > +**/ > +STATIC > +VOID > +EnlargeRegisterTable ( > + IN OUT CPU_REGISTER_TABLE *RegisterTable > + ) > +{ > + EFI_PHYSICAL_ADDRESS Address; > + UINTN UsedPages; > + > + UsedPages =3D RegisterTable->AllocatedSize / EFI_PAGE_SIZE; Address = =3D > + (UINTN)AllocatePages (UsedPages + 1); ASSERT (Address !=3D 0); > + > + // > + // If there are records existing in the register table, then copy its > + contents // to new region and free the old one. > + // > + if (RegisterTable->AllocatedSize > 0) { > + CopyMem ( > + (VOID *) (UINTN) Address, > + (VOID *) (UINTN) RegisterTable->RegisterTableEntry, > + RegisterTable->AllocatedSize > + ); > + > + FreePages ((VOID *)(UINTN)RegisterTable->RegisterTableEntry, > + UsedPages); } > + > + // > + // Adjust the allocated size and register table base address. > + // > + RegisterTable->AllocatedSize +=3D EFI_PAGE_SIZE; > + RegisterTable->RegisterTableEntry =3D Address; } > + > /** > Add an entry in specified register table. >=20 > -- > 2.15.0.windows.1