]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuDxe: introduce MP_SYSTEM_DATA for Mp Service Protocol
authorChen Fan <chen.fan.fnst@cn.fujitsu.com>
Thu, 13 Nov 2014 18:26:23 +0000 (18:26 +0000)
committerjljusten <jljusten@Edk2>
Thu, 13 Nov 2014 18:26:23 +0000 (18:26 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16353 6f19259b-4bc3-4df7-8a09-765794883524

UefiCpuPkg/CpuDxe/CpuDxe.inf
UefiCpuPkg/CpuDxe/CpuMp.c
UefiCpuPkg/CpuDxe/CpuMp.h
UefiCpuPkg/UefiCpuPkg.dsc

index aa37269de70c3ae2ddfb786b7016c39bd84e42e8..61bc55a445f659d9fe8ba1abdf5b5d0f88157ded 100644 (file)
@@ -42,6 +42,7 @@
   UefiLib\r
   CpuExceptionHandlerLib\r
   TimerLib\r
+  SynchronizationLib\r
 \r
 [Sources]\r
   ApStartup.c\r
index e3734c27908bd31199c2e22ba5df309440441f6a..de599dad6a51423a00c9566b6c9c66237d65ce98 100644 (file)
 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
@@ -66,16 +66,84 @@ ApEntryPointInC (
   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
@@ -110,15 +178,16 @@ InitializeMpSupport (
   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
index 157ac36c48d0162c01a37c827fd1b6610123d0b4..481f7b16183527af8d181e9ceec984fb1a8638ac 100644 (file)
@@ -16,6 +16,7 @@
 #define _CPU_MP_H_\r
 \r
 #include <Protocol/MpService.h>\r
+#include <Library/SynchronizationLib.h>\r
 \r
 /**\r
   Initialize Multi-processor support.\r
@@ -77,5 +78,51 @@ AsmApDoneWithCommonStack (
   VOID\r
   );\r
 \r
+typedef enum {\r
+  CpuStateIdle,\r
+  CpuStateBlocked,\r
+  CpuStateReady,\r
+  CpuStateBuzy,\r
+  CpuStateFinished\r
+} CPU_STATE;\r
+\r
+/**\r
+  Define Individual Processor Data block.\r
+\r
+**/\r
+typedef struct {\r
+  EFI_PROCESSOR_INFORMATION      Info;\r
+  SPIN_LOCK                      CpuDataLock;\r
+  volatile CPU_STATE             State;\r
+\r
+  EFI_AP_PROCEDURE               Procedure;\r
+  VOID                           *Parameter;\r
+} CPU_DATA_BLOCK;\r
+\r
+/**\r
+  Define MP data block which consumes individual processor block.\r
+\r
+**/\r
+typedef struct {\r
+  CPU_DATA_BLOCK              *CpuDatas;\r
+  UINTN                       NumberOfProcessors;\r
+  UINTN                       NumberOfEnabledProcessors;\r
+} MP_SYSTEM_DATA;\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
 #endif // _CPU_MP_H_\r
 \r
index 70d5bb032d30263220558f54bbdc5d9013266273..9fa9270d6e4798479a213906b8b6090f00e861e3 100644 (file)
@@ -52,6 +52,7 @@
   LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf\r
   ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf\r
   CpuExceptionHandlerLib|MdeModulePkg/Library/CpuExceptionHandlerLibNull/CpuExceptionHandlerLibNull.inf  \r
+  SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf\r
 \r
 [LibraryClasses.common.PEIM]\r
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r