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

diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index c48f886..aeb7bc0 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -37,7 +37,7 @@ EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {
   NULL, // StartupThisAP,
   NULL, // SwitchBSP,
   NULL, // EnableDisableAP,
-  NULL  // WhoAmI
+  WhoAmI
 };
 
 /**
@@ -52,19 +52,13 @@ 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;
 }
 
 
@@ -126,6 +120,56 @@ GetNumberOfProcessors (
 }
 
 /**
+  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;
+}
+
+
+/**
   Application Processors do loop routine
   after swtich to its own stack
 
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h
index b18de88..0e0418c 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.h
+++ b/UefiCpuPkg/CpuDxe/CpuMp.h
@@ -182,6 +182,37 @@ GetNumberOfProcessors (
   OUT UINTN                     *NumberOfEnabledProcessors
   );
 
+/**
+  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
+  );
+
 
 #endif // _CPU_MP_H_
 
-- 
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