From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (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 C27A5210C7ACE for ; Fri, 10 Aug 2018 09:34:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1647D819703B; Fri, 10 Aug 2018 16:34:43 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-207.rdu2.redhat.com [10.10.120.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48051215670D; Fri, 10 Aug 2018 16:34:41 +0000 (UTC) To: Eric Dong , edk2-devel@lists.01.org Cc: =?UTF-8?Q?Marvin_H=c3=a4user?= , Fan Jeff , Ruiyu Ni References: <20180810041909.12776-1-eric.dong@intel.com> <20180810041909.12776-6-eric.dong@intel.com> From: Laszlo Ersek Message-ID: Date: Fri, 10 Aug 2018 18:34:40 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180810041909.12776-6-eric.dong@intel.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 10 Aug 2018 16:34:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 10 Aug 2018 16:34:43 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' 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: Fri, 10 Aug 2018 16:34:44 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 08/10/18 06:19, Eric Dong wrote: > 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. > > 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. > > V3 changes: >> Remove function definition in header file. >> Add STATIC in function implementation. > > Pass OS boot and resume from S3 test. > > Bugz: https://bugzilla.tianocore.org/show_bug.cgi?id=959 > > Reported-by: Marvin Häuser > Suggested-by: Fan Jeff > Cc: Marvin Häuser > 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(-) > > 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/DxeRegisterCpuFeaturesLib.c > @@ -197,70 +197,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 > - ) > -{ > - // > - // CpuS3DataDxe will do it. > - // > - ASSERT (FALSE); > - return NULL; > -} > - > -/** > - Enlarges CPU register table for each processor. > - > - @param[in, out] RegisterTable Pointer processor's CPU register table > -**/ > -VOID > -EnlargeRegisterTable ( > - IN OUT CPU_REGISTER_TABLE *RegisterTable > - ) > -{ > - EFI_STATUS Status; > - EFI_PHYSICAL_ADDRESS Address; > - UINTN AllocatePages; > - > - Address = BASE_4GB - 1; > - AllocatePages = RegisterTable->AllocatedSize / EFI_PAGE_SIZE; > - Status = 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 += EFI_PAGE_SIZE; > - RegisterTable->RegisterTableEntry = 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/PeiRegisterCpuFeaturesLib.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 = PeiServicesAllocatePages ( > - EfiACPIMemoryNVS, > - EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)), > - &Address > - ); > - ASSERT_EFI_ERROR (Status); > - AcpiCpuData = (ACPI_CPU_DATA *) (UINTN) Address; > - ASSERT (AcpiCpuData != NULL); > - > - // > - // Get MP Services Protocol > - // > - Status = PeiServicesLocatePpi ( > - &gEfiPeiMpServicesPpiGuid, > - 0, > - NULL, > - (VOID **)&CpuMpPpi > - ); > - ASSERT_EFI_ERROR (Status); > - > - // > - // Get the number of CPUs > - // > - Status = CpuMpPpi->GetNumberOfProcessors ( > - GetPeiServicesTablePointer (), > - CpuMpPpi, > - &NumberOfCpus, > - &NumberOfEnabledProcessors > - ); > - ASSERT_EFI_ERROR (Status); > - AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus; > - > - // > - // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs > - // > - TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); > - Status = PeiServicesAllocatePages ( > - EfiACPIMemoryNVS, > - EFI_SIZE_TO_PAGES (TableSize), > - &Address > - ); > - ASSERT_EFI_ERROR (Status); > - RegisterTable = (CPU_REGISTER_TABLE *) (UINTN) Address; > - > - for (Index = 0; Index < NumberOfCpus; Index++) { > - Status = CpuMpPpi->GetProcessorInfo ( > - GetPeiServicesTablePointer (), > - CpuMpPpi, > - Index, > - &ProcessorInfoBuffer > - ); > - ASSERT_EFI_ERROR (Status); > - > - RegisterTable[Index].InitialApicId = (UINT32)ProcessorInfoBuffer.ProcessorId; > - RegisterTable[Index].TableLength = 0; > - RegisterTable[Index].AllocatedSize = 0; > - RegisterTable[Index].RegisterTableEntry = 0; > - > - RegisterTable[NumberOfCpus + Index].InitialApicId = (UINT32)ProcessorInfoBuffer.ProcessorId; > - RegisterTable[NumberOfCpus + Index].TableLength = 0; > - RegisterTable[NumberOfCpus + Index].AllocatedSize = 0; > - RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0; > - } > - AcpiCpuData->RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable; > - AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus); > - > - return AcpiCpuData; > -} > - > -/** > - Enlarges CPU register table for each processor. > - > - @param[in, out] RegisterTable Pointer processor's CPU register table > -**/ > -VOID > -EnlargeRegisterTable ( > - IN OUT CPU_REGISTER_TABLE *RegisterTable > - ) > -{ > - EFI_STATUS Status; > - EFI_PHYSICAL_ADDRESS Address; > - UINTN AllocatePages; > - > - AllocatePages = RegisterTable->AllocatedSize / EFI_PAGE_SIZE; > - Status = 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 += EFI_PAGE_SIZE; > - RegisterTable->RegisterTableEntry = 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 > ); > > -/** > - Enlarges CPU register table for each processor. > - > - @param[in, out] RegisterTable Pointer processor's CPU register table > -**/ > -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. > > 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; > } > > +/** > + 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 = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA))); > + ASSERT (AcpiCpuData != NULL); > + > + GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors); > + AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus; > + > + // > + // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs > + // > + TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); > + RegisterTable = AllocatePages (EFI_SIZE_TO_PAGES (TableSize)); > + ASSERT (RegisterTable != NULL); > + > + for (Index = 0; Index < NumberOfCpus; Index++) { > + Status = GetProcessorInformation (Index, &ProcessorInfoBuffer); > + ASSERT_EFI_ERROR (Status); > + > + RegisterTable[Index].InitialApicId = (UINT32)ProcessorInfoBuffer.ProcessorId; > + RegisterTable[Index].TableLength = 0; > + RegisterTable[Index].AllocatedSize = 0; > + RegisterTable[Index].RegisterTableEntry = 0; > + > + RegisterTable[NumberOfCpus + Index].InitialApicId = (UINT32)ProcessorInfoBuffer.ProcessorId; > + RegisterTable[NumberOfCpus + Index].TableLength = 0; > + RegisterTable[NumberOfCpus + Index].AllocatedSize = 0; > + RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0; > + } > + AcpiCpuData->RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable; > + AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus); > + > + return AcpiCpuData; > +} > + > +/** > + Enlarges CPU register table for each processor. > + > + @param[in, out] RegisterTable Pointer processor's CPU register table > +**/ > +STATIC > +VOID > +EnlargeRegisterTable ( > + IN OUT CPU_REGISTER_TABLE *RegisterTable > + ) > +{ > + EFI_PHYSICAL_ADDRESS Address; > + UINTN UsedPages; > + > + UsedPages = RegisterTable->AllocatedSize / EFI_PAGE_SIZE; > + Address = (UINTN)AllocatePages (UsedPages + 1); > + ASSERT (Address != 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 += EFI_PAGE_SIZE; > + RegisterTable->RegisterTableEntry = Address; > +} > + > /** > Add an entry in specified register table. > > Reviewed-by: Laszlo Ersek