Revision: 16353
http://sourceforge.net/p/edk2/code/16353
Author: jljusten
Date: 2014-11-13 18:26:23 +0000 (Thu, 13 Nov 2014)
Log Message:
-----------
UefiCpuPkg/CpuDxe: introduce MP_SYSTEM_DATA for Mp Service Protocol
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <[email protected]>
Reviewed-by: Jeff Fan <[email protected]>
Modified Paths:
--------------
trunk/edk2/UefiCpuPkg/CpuDxe/CpuDxe.inf
trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c
trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h
trunk/edk2/UefiCpuPkg/UefiCpuPkg.dsc
Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuDxe.inf
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuDxe.inf 2014-11-13 18:26:13 UTC (rev
16352)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuDxe.inf 2014-11-13 18:26:23 UTC (rev
16353)
@@ -42,6 +42,7 @@
UefiLib
CpuExceptionHandlerLib
TimerLib
+ SynchronizationLib
[Sources]
ApStartup.c
Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c 2014-11-13 18:26:13 UTC (rev
16352)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c 2014-11-13 18:26:23 UTC (rev
16353)
@@ -18,12 +18,12 @@
UINTN gMaxLogicalProcessorNumber;
UINTN gApStackSize;
+MP_SYSTEM_DATA mMpSystemData;
+
VOID *mCommonStack = 0;
VOID *mTopOfApCommonStack = 0;
VOID *mApStackStart = 0;
-volatile UINTN mNumberOfProcessors;
-
EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {
NULL, // GetNumberOfProcessors,
NULL, // GetProcessorInfo,
@@ -66,18 +66,86 @@
VOID
)
{
- mNumberOfProcessors++;
- mApStackStart = (UINT8*)mApStackStart + gApStackSize;
+ VOID* TopOfApStack;
+ FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);
+ TopOfApStack = (UINT8*)mApStackStart + gApStackSize;
+ mApStackStart = TopOfApStack;
+
+ mMpSystemData.NumberOfProcessors++;
+
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,
NULL,
NULL,
- mApStackStart);
+ TopOfApStack);
}
+/**
+ This function is called by all processors (both BSP and AP) once and
collects MP related data.
+ @param Bsp TRUE if the CPU is BSP
+ @param ProcessorNumber The specific processor number
+
+ @retval EFI_SUCCESS Data for the processor collected and filled in
+
+**/
+EFI_STATUS
+FillInProcessorInformation (
+ IN BOOLEAN Bsp,
+ IN UINTN ProcessorNumber
+ )
+{
+ CPU_DATA_BLOCK *CpuData;
+ UINT32 ProcessorId;
+
+ CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];
+ ProcessorId = GetApicId ();
+ CpuData->Info.ProcessorId = ProcessorId;
+ CpuData->Info.StatusFlag = PROCESSOR_ENABLED_BIT |
PROCESSOR_HEALTH_STATUS_BIT;
+ if (Bsp) {
+ CpuData->Info.StatusFlag |= PROCESSOR_AS_BSP_BIT;
+ }
+ CpuData->Info.Location.Package = ProcessorId;
+ CpuData->Info.Location.Core = 0;
+ CpuData->Info.Location.Thread = 0;
+ CpuData->State = Bsp ? CpuStateBuzy : CpuStateIdle;
+
+ CpuData->Procedure = NULL;
+ CpuData->Parameter = NULL;
+ InitializeSpinLock (&CpuData->CpuDataLock);
+
+ return EFI_SUCCESS;
+}
+
/**
+ Prepare the System Data.
+
+ @retval EFI_SUCCESS the System Data finished initilization.
+
+**/
+EFI_STATUS
+InitMpSystemData (
+ VOID
+ )
+{
+ ZeroMem (&mMpSystemData, sizeof (MP_SYSTEM_DATA));
+
+ mMpSystemData.NumberOfProcessors = 1;
+ mMpSystemData.NumberOfEnabledProcessors = 1;
+
+ mMpSystemData.CpuDatas = AllocateZeroPool (sizeof (CPU_DATA_BLOCK) *
gMaxLogicalProcessorNumber);
+ ASSERT(mMpSystemData.CpuDatas != NULL);
+
+ //
+ // BSP
+ //
+ FillInProcessorInformation (TRUE, 0);
+
+ return EFI_SUCCESS;
+}
+
+/**
Initialize Multi-processor support.
**/
@@ -110,15 +178,16 @@
mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;
mApStackStart = mTopOfApCommonStack;
- mNumberOfProcessors = 1;
+ InitMpSystemData ();
- if (mNumberOfProcessors == 1) {
+ if (mMpSystemData.NumberOfProcessors == 1) {
FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber *
gApStackSize));
return;
}
- if (mNumberOfProcessors < gMaxLogicalProcessorNumber) {
- FreePages (mApStackStart, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber -
mNumberOfProcessors) *
- gApStackSize));
+ if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {
+ FreePages (mApStackStart, EFI_SIZE_TO_PAGES (
+ (gMaxLogicalProcessorNumber -
mMpSystemData.NumberOfProcessors) *
+ gApStackSize));
}
}
Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h 2014-11-13 18:26:13 UTC (rev
16352)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h 2014-11-13 18:26:23 UTC (rev
16353)
@@ -16,6 +16,7 @@
#define _CPU_MP_H_
#include <Protocol/MpService.h>
+#include <Library/SynchronizationLib.h>
/**
Initialize Multi-processor support.
@@ -77,5 +78,51 @@
VOID
);
+typedef enum {
+ CpuStateIdle,
+ CpuStateBlocked,
+ CpuStateReady,
+ CpuStateBuzy,
+ CpuStateFinished
+} CPU_STATE;
+
+/**
+ Define Individual Processor Data block.
+
+**/
+typedef struct {
+ EFI_PROCESSOR_INFORMATION Info;
+ SPIN_LOCK CpuDataLock;
+ volatile CPU_STATE State;
+
+ EFI_AP_PROCEDURE Procedure;
+ VOID *Parameter;
+} CPU_DATA_BLOCK;
+
+/**
+ Define MP data block which consumes individual processor block.
+
+**/
+typedef struct {
+ CPU_DATA_BLOCK *CpuDatas;
+ UINTN NumberOfProcessors;
+ UINTN NumberOfEnabledProcessors;
+} MP_SYSTEM_DATA;
+
+/**
+ This function is called by all processors (both BSP and AP) once and
collects MP related data.
+
+ @param Bsp TRUE if the CPU is BSP
+ @param ProcessorNumber The specific processor number
+
+ @retval EFI_SUCCESS Data for the processor collected and filled in
+
+**/
+EFI_STATUS
+FillInProcessorInformation (
+ IN BOOLEAN Bsp,
+ IN UINTN ProcessorNumber
+ );
+
#endif // _CPU_MP_H_
Modified: trunk/edk2/UefiCpuPkg/UefiCpuPkg.dsc
===================================================================
--- trunk/edk2/UefiCpuPkg/UefiCpuPkg.dsc 2014-11-13 18:26:13 UTC (rev
16352)
+++ trunk/edk2/UefiCpuPkg/UefiCpuPkg.dsc 2014-11-13 18:26:23 UTC (rev
16353)
@@ -52,6 +52,7 @@
LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf
+
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
[LibraryClasses.common.PEIM]
MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits