UINTN gMaxLogicalProcessorNumber;\r
UINTN gApStackSize;\r
\r
+MP_SYSTEM_DATA mMpSystemData;\r
+\r
VOID *mCommonStack = 0;\r
VOID *mTopOfApCommonStack = 0;\r
VOID *mApStackStart = 0;\r
\r
-volatile UINTN mNumberOfProcessors;\r
-\r
EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {\r
NULL, // GetNumberOfProcessors,\r
NULL, // GetProcessorInfo,\r
VOID\r
)\r
{\r
- mNumberOfProcessors++;\r
- mApStackStart = (UINT8*)mApStackStart + gApStackSize;\r
+ VOID* TopOfApStack;\r
+\r
+ FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);\r
+ TopOfApStack = (UINT8*)mApStackStart + gApStackSize;\r
+ mApStackStart = TopOfApStack;\r
+\r
+ mMpSystemData.NumberOfProcessors++;\r
\r
SwitchStack (\r
(SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,\r
NULL,\r
NULL,\r
- mApStackStart);\r
+ TopOfApStack);\r
+}\r
+\r
+/**\r
+ This function is called by all processors (both BSP and AP) once and collects MP related data.\r
+\r
+ @param Bsp TRUE if the CPU is BSP\r
+ @param ProcessorNumber The specific processor number\r
+\r
+ @retval EFI_SUCCESS Data for the processor collected and filled in\r
+\r
+**/\r
+EFI_STATUS\r
+FillInProcessorInformation (\r
+ IN BOOLEAN Bsp,\r
+ IN UINTN ProcessorNumber\r
+ )\r
+{\r
+ CPU_DATA_BLOCK *CpuData;\r
+ UINT32 ProcessorId;\r
+\r
+ CpuData = &mMpSystemData.CpuDatas[ProcessorNumber];\r
+ ProcessorId = GetApicId ();\r
+ CpuData->Info.ProcessorId = ProcessorId;\r
+ CpuData->Info.StatusFlag = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT;\r
+ if (Bsp) {\r
+ CpuData->Info.StatusFlag |= PROCESSOR_AS_BSP_BIT;\r
+ }\r
+ CpuData->Info.Location.Package = ProcessorId;\r
+ CpuData->Info.Location.Core = 0;\r
+ CpuData->Info.Location.Thread = 0;\r
+ CpuData->State = Bsp ? CpuStateBuzy : CpuStateIdle;\r
+\r
+ CpuData->Procedure = NULL;\r
+ CpuData->Parameter = NULL;\r
+ InitializeSpinLock (&CpuData->CpuDataLock);\r
+\r
+ return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Prepare the System Data.\r
+\r
+ @retval EFI_SUCCESS the System Data finished initilization.\r
+\r
+**/\r
+EFI_STATUS\r
+InitMpSystemData (\r
+ VOID\r
+ )\r
+{\r
+ ZeroMem (&mMpSystemData, sizeof (MP_SYSTEM_DATA));\r
+\r
+ mMpSystemData.NumberOfProcessors = 1;\r
+ mMpSystemData.NumberOfEnabledProcessors = 1;\r
+\r
+ mMpSystemData.CpuDatas = AllocateZeroPool (sizeof (CPU_DATA_BLOCK) * gMaxLogicalProcessorNumber);\r
+ ASSERT(mMpSystemData.CpuDatas != NULL);\r
+\r
+ //\r
+ // BSP\r
+ //\r
+ FillInProcessorInformation (TRUE, 0);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
\r
/**\r
Initialize Multi-processor support.\r
mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r
mApStackStart = mTopOfApCommonStack;\r
\r
- mNumberOfProcessors = 1;\r
+ InitMpSystemData ();\r
\r
- if (mNumberOfProcessors == 1) {\r
+ if (mMpSystemData.NumberOfProcessors == 1) {\r
FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
return;\r
}\r
\r
- if (mNumberOfProcessors < gMaxLogicalProcessorNumber) {\r
- FreePages (mApStackStart, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber - mNumberOfProcessors) *\r
- gApStackSize));\r
+ if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {\r
+ FreePages (mApStackStart, EFI_SIZE_TO_PAGES (\r
+ (gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) *\r
+ gApStackSize));\r
}\r
}\r