UefiCpuPkg/MpInitLib: Save CPU MP Data pointer

In PeiMpInitLib, save CPU MP Data pointer into one local Guided HOB.
In DxeMpInitLib, save CPU MP Data pointer into one global variable.

Add helper functions GetCpuMpData()/SaveCpuMpData().

v5:
  1. Move CPU_INIT_MP_LIB_HOB_GUID from MpLib.c to MpLib.h to make
     all C files visible.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Giri P Mudusuru <giri.p.mudusuru@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Michael Kinney <michael.d.kinney@intel.com>
This commit is contained in:
Jeff Fan 2016-07-21 16:08:12 +08:00
parent 94f63c765f
commit 93ca4c0fd7
4 changed files with 174 additions and 0 deletions

View File

@ -13,6 +13,48 @@
**/ **/
#include "MpLib.h" #include "MpLib.h"
CPU_MP_DATA *mCpuMpData = NULL;
/**
Get the pointer to CPU MP Data structure.
@return The pointer to CPU MP Data structure.
**/
CPU_MP_DATA *
GetCpuMpData (
VOID
)
{
ASSERT (mCpuMpData != NULL);
return mCpuMpData;
}
/**
Save the pointer to CPU MP Data structure.
@param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
**/
VOID
SaveCpuMpData (
IN CPU_MP_DATA *CpuMpData
)
{
mCpuMpData = CpuMpData;
}
/**
Initialize global data for MP support.
@param[in] CpuMpData The pointer to CPU MP Data structure.
**/
VOID
InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
)
{
SaveCpuMpData (CpuMpData);
}
/** /**
This service executes a caller provided function on all enabled APs. This service executes a caller provided function on all enabled APs.

View File

@ -14,6 +14,8 @@
#include "MpLib.h" #include "MpLib.h"
EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;
/** /**
Get the Application Processors state. Get the Application Processors state.
@ -303,6 +305,12 @@ MpInitLibInitialize (
// //
MtrrGetAllMtrrs (&CpuMpData->MtrrTable); MtrrGetAllMtrrs (&CpuMpData->MtrrTable);
//
// Initialize global data for MP support
//
InitMpGlobalData (CpuMpData);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -386,3 +394,25 @@ MpInitLibGetNumberOfProcessors (
{ {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/**
Get pointer to CPU MP Data structure from GUIDed HOB.
@return The pointer to CPU MP Data structure.
**/
CPU_MP_DATA *
GetCpuMpDataFromGuidedHob (
VOID
)
{
EFI_HOB_GUID_TYPE *GuidHob;
VOID *DataInHob;
CPU_MP_DATA *CpuMpData;
CpuMpData = NULL;
GuidHob = GetFirstGuidHob (&mCpuInitMpLibHobGuid);
if (GuidHob != NULL) {
DataInHob = GET_GUID_HOB_DATA (GuidHob);
CpuMpData = (CPU_MP_DATA *) (*(UINTN *) DataInHob);
}
return CpuMpData;
}

View File

@ -35,6 +35,11 @@
#include <Library/MtrrLib.h> #include <Library/MtrrLib.h>
#include <Library/HobLib.h> #include <Library/HobLib.h>
#define CPU_INIT_MP_LIB_HOB_GUID \
{ \
0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \
}
// //
// AP loop state when APs are in idle state // AP loop state when APs are in idle state
// It's value is the same with PcdCpuApLoopMode // It's value is the same with PcdCpuApLoopMode
@ -198,6 +203,9 @@ struct _CPU_MP_DATA {
CPU_AP_DATA *CpuData; CPU_AP_DATA *CpuData;
volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo; volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
}; };
extern EFI_GUID mCpuInitMpLibHobGuid;
/** /**
Assembly code to place AP into safe loop mode. Assembly code to place AP into safe loop mode.
@ -232,6 +240,46 @@ AsmGetAddressMap (
OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
); );
/**
Get the pointer to CPU MP Data structure.
@return The pointer to CPU MP Data structure.
**/
CPU_MP_DATA *
GetCpuMpData (
VOID
);
/**
Save the pointer to CPU MP Data structure.
@param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
**/
VOID
SaveCpuMpData (
IN CPU_MP_DATA *CpuMpData
);
/**
Initialize global data for MP support.
@param[in] CpuMpData The pointer to CPU MP Data structure.
**/
VOID
InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
);
/**
Get pointer to CPU MP Data structure from GUIDed HOB.
@return The pointer to CPU MP Data structure.
**/
CPU_MP_DATA *
GetCpuMpDataFromGuidedHob (
VOID
);
/** /**
Detect whether specified processor can find matching microcode patch and load it. Detect whether specified processor can find matching microcode patch and load it.

View File

@ -14,6 +14,60 @@
#include "MpLib.h" #include "MpLib.h"
/**
Get pointer to CPU MP Data structure.
@return The pointer to CPU MP Data structure.
**/
CPU_MP_DATA *
GetCpuMpData (
VOID
)
{
CPU_MP_DATA *CpuMpData;
CpuMpData = GetCpuMpDataFromGuidedHob ();
ASSERT (CpuMpData != NULL);
return CpuMpData;
}
/**
Save the pointer to CPU MP Data structure.
@param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
**/
VOID
SaveCpuMpData (
IN CPU_MP_DATA *CpuMpData
)
{
UINT64 Data64;
//
// Build location of CPU MP DATA buffer in HOB
//
Data64 = (UINT64) (UINTN) CpuMpData;
BuildGuidDataHob (
&mCpuInitMpLibHobGuid,
(VOID *) &Data64,
sizeof (UINT64)
);
}
/**
Initialize global data for MP support.
@param[in] CpuMpData The pointer to CPU MP Data structure.
**/
VOID
InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
)
{
SaveCpuMpData (CpuMpData);
}
/** /**
This service executes a caller provided function on all enabled APs. This service executes a caller provided function on all enabled APs.