Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <[email protected]>
---
 UefiCpuPkg/CpuDxe/CpuDxe.inf |  1 +
 UefiCpuPkg/CpuDxe/CpuMp.c    | 38 +++++++++++++++++++++++++++++++++++++-
 UefiCpuPkg/CpuDxe/CpuMp.h    | 29 +++++++++++++++++++++++++++++
 UefiCpuPkg/UefiCpuPkg.dsc    |  1 +
 4 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.inf b/UefiCpuPkg/CpuDxe/CpuDxe.inf
index 48015f8..9ec490d 100644
--- a/UefiCpuPkg/CpuDxe/CpuDxe.inf
+++ b/UefiCpuPkg/CpuDxe/CpuDxe.inf
@@ -42,6 +42,7 @@
   UefiLib
   CpuExceptionHandlerLib
   TimerLib
+  SynchronizationLib
 
 [Sources]
   ApStartup.c
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index d5c31ca..6423bfa 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -17,6 +17,8 @@
 
 UINTN gApStackSize;
 
+MP_SYSTEM_DATA mMpSystemData;
+
 VOID *mCommonStack = 0;
 VOID *mTopOfApCommonStack = 0;
 VOID *mApStackStart = 0;
@@ -61,6 +63,32 @@ ApEntryPointInC (
   CpuSleep ();
 }
 
+/**
+  Prepare the System Data.
+
+  @retval EFI_SUCCESS     the System Data finished initilization.
+
+**/
+EFI_STATUS
+InitMpSystemData (
+  VOID
+  )
+{
+  UINTN          CpuIndex;
+  CPU_DATA_BLOCK *CpuData;
+
+  for (CpuIndex = 0; CpuIndex < mMpSystemData.NumberOfProcessors; CpuIndex++) {
+    CpuData = &mMpSystemData.CpuDatas[CpuIndex];
+    CpuData->Info.StatusFlag = PROCESSOR_ENABLED_BIT | 
PROCESSOR_HEALTH_STATUS_BIT;
+    if (CpuIndex == 0) {
+      CpuData->Info.StatusFlag |= PROCESSOR_AS_BSP_BIT;
+      CpuData->Info.ProcessorId = GetApicId ();
+    }
+    InitializeSpinLock (&CpuData->CpuDataLock);
+  }
+
+  return EFI_SUCCESS;
+}
 
 /**
   Initialize Multi-processor support.
@@ -82,7 +110,15 @@ InitializeMpSupport (
   gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);
 
   mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES ((mNumberOfProcessors - 1) 
* gApStackSize));
-  ASSERT (mApStackStart != 0x0);
+  ASSERT (mApStackStart != NULL);
+
+  mMpSystemData.NumberOfProcessors = mNumberOfProcessors;
+  mMpSystemData.NumberOfEnabledProcessors = mNumberOfProcessors;
+
+  mMpSystemData.CpuDatas = AllocateZeroPool (sizeof (CPU_DATA_BLOCK) * 
mNumberOfProcessors);
+  ASSERT(mMpSystemData.CpuDatas != NULL);
+
+  InitMpSystemData ();
 
   mAllApsInitFinished = TRUE;
 }
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h
index 88ef8a2..1b28d04 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.h
+++ b/UefiCpuPkg/CpuDxe/CpuMp.h
@@ -16,6 +16,7 @@
 #define _CPU_MP_H_
 
 #include <Protocol/MpService.h>
+#include <Library/SynchronizationLib.h>
 
 /**
   Initialize Multi-processor support
@@ -76,5 +77,33 @@ AsmApDoneWithCommonStack (
   VOID
   );
 
+typedef enum {
+  CpuStateIdle,
+  CpuStateBlocked,
+  CpuStateReady,
+  CpuStateBuzy,
+  CpuStateFinished
+} CPU_STATE;
+
+/**
+  Define Individual Processor Data block.
+
+**/
+typedef struct {
+  EFI_PROCESSOR_INFORMATION      Info;
+  SPIN_LOCK                      CpuDataLock;
+  CPU_STATE volatile             State;
+} 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;
+
 #endif // _CPU_MP_H_
 
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 70d5bb0..9fa9270 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -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
-- 
1.9.3


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to