UefiCpuPkg/RegisterCpuFeaturesLib: Avoid AP calls PeiService.

V3:
   Define union to specify the ppi or protocol.

V2:
1. Initialize CpuFeaturesData->MpService in CpuInitDataInitialize
   and make this function been called at the begin of the
   initialization.
2. let all other functions use CpuFeaturesData->MpService install
   of locate the protocol itself.

V1:
GetProcessorIndex function calls GetMpPpi to get the MP Ppi.
Ap will calls GetProcessorIndex function which final let AP calls
PeiService.

This patch avoid GetProcessorIndex call PeiService.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1411

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Eric Dong
2019-01-04 13:37:29 +08:00
parent a6416d91c3
commit 7217b8796d
4 changed files with 98 additions and 77 deletions

View File

@@ -68,15 +68,15 @@ GetCpuFeaturesData (
/**
Worker function to get MP PPI service pointer.
@return PEI PPI service pointer.
@return MP_SERVICES variable.
**/
EFI_PEI_MP_SERVICES_PPI *
GetMpPpi (
MP_SERVICES
GetMpService (
VOID
)
{
EFI_STATUS Status;
EFI_PEI_MP_SERVICES_PPI *CpuMpPpi;
MP_SERVICES MpService;
//
// Get MP Services Protocol
@@ -85,29 +85,36 @@ GetMpPpi (
&gEfiPeiMpServicesPpiGuid,
0,
NULL,
(VOID **)&CpuMpPpi
(VOID **)&MpService.Ppi
);
ASSERT_EFI_ERROR (Status);
return CpuMpPpi;
return MpService;
}
/**
Worker function to return processor index.
@param CpuFeaturesData Cpu Feature Data structure.
@return The processor index.
**/
UINTN
GetProcessorIndex (
VOID
IN CPU_FEATURES_DATA *CpuFeaturesData
)
{
EFI_STATUS Status;
EFI_PEI_MP_SERVICES_PPI *CpuMpPpi;
UINTN ProcessorIndex;
CpuMpPpi = GetMpPpi ();
CpuMpPpi = CpuFeaturesData->MpService.Ppi;
Status = CpuMpPpi->WhoAmI(GetPeiServicesTablePointer (), CpuMpPpi, &ProcessorIndex);
//
// For two reasons which use NULL for WhoAmI:
// 1. This function will be called by APs and AP should not use PeiServices Table
// 2. Check WhoAmI implementation, this parameter will not be used.
//
Status = CpuMpPpi->WhoAmI(NULL, CpuMpPpi, &ProcessorIndex);
ASSERT_EFI_ERROR (Status);
return ProcessorIndex;
}
@@ -130,8 +137,11 @@ GetProcessorInformation (
{
EFI_PEI_MP_SERVICES_PPI *CpuMpPpi;
EFI_STATUS Status;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
CpuMpPpi = CpuFeaturesData->MpService.Ppi;
CpuMpPpi = GetMpPpi ();
Status = CpuMpPpi->GetProcessorInfo (
GetPeiServicesTablePointer(),
CpuMpPpi,
@@ -160,17 +170,7 @@ StartupAPsWorker (
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
//
// Get MP Services Protocol
//
Status = PeiServicesLocatePpi (
&gEfiPeiMpServicesPpiGuid,
0,
NULL,
(VOID **)&CpuMpPpi
);
ASSERT_EFI_ERROR (Status);
CpuMpPpi = CpuFeaturesData->MpService.Ppi;
//
// Wakeup all APs for data collection.
@@ -198,17 +198,10 @@ SwitchNewBsp (
{
EFI_STATUS Status;
EFI_PEI_MP_SERVICES_PPI *CpuMpPpi;
CPU_FEATURES_DATA *CpuFeaturesData;
//
// Get MP Services Protocol
//
Status = PeiServicesLocatePpi (
&gEfiPeiMpServicesPpiGuid,
0,
NULL,
(VOID **)&CpuMpPpi
);
ASSERT_EFI_ERROR (Status);
CpuFeaturesData = GetCpuFeaturesData ();
CpuMpPpi = CpuFeaturesData->MpService.Ppi;
//
// Wakeup all APs for data collection.
@@ -240,17 +233,10 @@ GetNumberOfProcessor (
{
EFI_STATUS Status;
EFI_PEI_MP_SERVICES_PPI *CpuMpPpi;
CPU_FEATURES_DATA *CpuFeaturesData;
//
// Get MP Services Protocol
//
Status = PeiServicesLocatePpi (
&gEfiPeiMpServicesPpiGuid,
0,
NULL,
(VOID **)&CpuMpPpi
);
ASSERT_EFI_ERROR (Status);
CpuFeaturesData = GetCpuFeaturesData ();
CpuMpPpi = CpuFeaturesData->MpService.Ppi;
//
// Get the number of CPUs
@@ -283,7 +269,7 @@ CpuFeaturesInitialize (
CpuFeaturesData = GetCpuFeaturesData ();
OldBspNumber = GetProcessorIndex();
OldBspNumber = GetProcessorIndex (CpuFeaturesData);
CpuFeaturesData->BspNumber = OldBspNumber;
//