Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <[email protected]>
---
 UefiCpuPkg/CpuDxe/CpuMp.c | 81 ++++++++++++++++++++++++++++++++++++-----------
 UefiCpuPkg/CpuDxe/CpuMp.h | 15 +++++++++
 2 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index fce015c..a962904 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -28,24 +28,29 @@ UINTN mNumberOfProcessors;
 BOOLEAN mAllApsInitFinished = FALSE;
 UINTN mApDoneCount = 0;
 
+
+EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {
+  GetNumberOfProcessors,
+  NULL, // GetProcessorInfo,
+  NULL, // StartupAllAps,
+  NULL, // StartupThisAP,
+  NULL, // SwitchBSP,
+  NULL, // EnableDisableAP,
+  WhoAmI
+};
+
 BOOLEAN
 IsBSP (
   VOID
   )
 {
-  UINTN ProcessorId;
   UINTN CpuIndex;
   CPU_DATA_BLOCK  *CpuData = NULL;
 
-  ProcessorId = GetApicId ();
-  for (CpuIndex = 0; CpuIndex < mMpSystemData.NumberOfProcessors; CpuIndex++) {
-    if (mMpSystemData.CpuDatas[CpuIndex].Info.ProcessorId == ProcessorId) {
-      CpuData = &mMpSystemData.CpuDatas[CpuIndex];
-      break;
-    }
-  }
+  WhoAmI (&mMpServicesTemplate, &CpuIndex);
+  CpuData = &mMpSystemData.CpuDatas[CpuIndex];
 
-  return (CpuData) && (CpuData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT) ? TRUE 
: FALSE;
+  return CpuData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT ? TRUE : FALSE;
 }
 
 
@@ -106,16 +111,56 @@ GetNumberOfProcessors (
   return EFI_SUCCESS;
 }
 
+/**
+  This return the handle number for the calling processor.  This service may be
+  called from the BSP and APs.
+
+  This service returns the processor handle number for the calling processor.
+  The returned value is in the range from 0 to the total number of logical
+  processors minus 1. The total number of logical processors can be retrieved
+  with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
+  called from the BSP and APs. If ProcessorNumber is NULL, then 
EFI_INVALID_PARAMETER
+  is returned. Otherwise, the current processors handle number is returned in
+  ProcessorNumber, and EFI_SUCCESS is returned.
+
+  @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL 
instance.
+  @param[in] ProcessorNumber   The handle number of AP that is to become the 
new
+                               BSP. The range is from 0 to the total number of
+                               logical processors minus 1. The total number of
+                               logical processors can be retrieved by
+                               
EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
+
+  @retval EFI_SUCCESS             The current processor handle number was 
returned
+                                  in ProcessorNumber.
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+WhoAmI (
+  IN EFI_MP_SERVICES_PROTOCOL  *This,
+  OUT UINTN                    *ProcessorNumber
+  )
+{
+  UINTN   Index;
+  UINT32  ProcessorId;
+
+  if (ProcessorNumber == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ProcessorId = GetApicId ();
+  for (Index = 0; Index < mMpSystemData.NumberOfProcessors; Index++) {
+    if (mMpSystemData.CpuDatas[Index].Info.ProcessorId == ProcessorId) {
+      break;
+    }
+  }
+
+  *ProcessorNumber = Index;
+  return EFI_SUCCESS;
+}
+
 
-EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {
-  GetNumberOfProcessors,
-  NULL, // GetProcessorInfo,
-  NULL, // StartupAllAps,
-  NULL, // StartupThisAP,
-  NULL, // SwitchBSP,
-  NULL, // EnableDisableAP,
-  NULL  // WhoAmI
-};
 
 VOID
 ProcessorToIdleState (
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h
index 03cc438..3324544 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.h
+++ b/UefiCpuPkg/CpuDxe/CpuMp.h
@@ -69,6 +69,21 @@ AsmApReleaseLock (
   VOID
   );
 
+EFI_STATUS
+EFIAPI
+GetNumberOfProcessors (
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,
+  OUT UINTN                     *NumberOfProcessors,
+  OUT UINTN                     *NumberOfEnabledProcessors
+  );
+
+EFI_STATUS
+EFIAPI
+WhoAmI (
+  IN EFI_MP_SERVICES_PROTOCOL  *This,
+  OUT UINTN                    *ProcessorNumber
+  );
+
 typedef enum {
   CPU_STATE_IDLE,
   CPU_STATE_BLOCKED,
-- 
1.9.3


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to