Revision: 16355
          http://sourceforge.net/p/edk2/code/16355
Author:   jljusten
Date:     2014-11-13 18:26:42 +0000 (Thu, 13 Nov 2014)
Log Message:
-----------
UefiCpuPkg/CpuDxe: implement Mp Protocol:GetNumberOfProcessors()

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <[email protected]>
Reviewed-by: Jeff Fan <[email protected]>

Modified Paths:
--------------
    trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c
    trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h

Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c        2014-11-13 18:26:32 UTC (rev 
16354)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c        2014-11-13 18:26:42 UTC (rev 
16355)
@@ -25,7 +25,7 @@
 VOID *mApStackStart = 0;
 
 EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {
-  NULL, // GetNumberOfProcessors,
+  GetNumberOfProcessors,
   NULL, // GetProcessorInfo,
   NULL, // StartupAllAPs,
   NULL, // StartupThisAP,
@@ -35,6 +35,86 @@
 };
 
 /**
+  Check whether caller processor is BSP.
+
+  @retval  TRUE       the caller is BSP
+  @retval  FALSE      the caller is AP
+
+**/
+BOOLEAN
+IsBSP (
+  VOID
+  )
+{
+  UINTN           CpuIndex;
+  CPU_DATA_BLOCK  *CpuData;
+
+  CpuData = NULL;
+
+  WhoAmI (&mMpServicesTemplate, &CpuIndex);
+  CpuData = &mMpSystemData.CpuDatas[CpuIndex];
+
+  return CpuData->Info.StatusFlag & PROCESSOR_AS_BSP_BIT ? TRUE : FALSE;
+}
+
+/**
+  This service retrieves the number of logical processor in the platform
+  and the number of those logical processors that are enabled on this boot.
+  This service may only be called from the BSP.
+
+  This function is used to retrieve the following information:
+    - The number of logical processors that are present in the system.
+    - The number of enabled logical processors in the system at the instant
+      this call is made.
+
+  Because MP Service Protocol provides services to enable and disable 
processors
+  dynamically, the number of enabled logical processors may vary during the
+  course of a boot session.
+
+  If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
+  If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
+  EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
+  is returned in NumberOfProcessors, the number of currently enabled processor
+  is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
+
+  @param[in]  This                        A pointer to the 
EFI_MP_SERVICES_PROTOCOL
+                                          instance.
+  @param[out] NumberOfProcessors          Pointer to the total number of 
logical
+                                          processors in the system, including 
the BSP
+                                          and disabled APs.
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled 
logical
+                                          processors that exist in system, 
including
+                                          the BSP.
+
+  @retval EFI_SUCCESS             The number of logical processors and enabled
+                                  logical processors was retrieved.
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL.
+  @retval EFI_INVALID_PARAMETER   NumberOfEnabledProcessors is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+GetNumberOfProcessors (
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,
+  OUT UINTN                     *NumberOfProcessors,
+  OUT UINTN                     *NumberOfEnabledProcessors
+  )
+{
+  if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (!IsBSP ()) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  *NumberOfProcessors        = mMpSystemData.NumberOfProcessors;
+  *NumberOfEnabledProcessors = mMpSystemData.NumberOfEnabledProcessors;
+  return EFI_SUCCESS;
+}
+
+/**
   This return the handle number for the calling processor.  This service may be
   called from the BSP and APs.
 

Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h        2014-11-13 18:26:32 UTC (rev 
16354)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h        2014-11-13 18:26:42 UTC (rev 
16355)
@@ -125,6 +125,50 @@
   );
 
 /**
+  This service retrieves the number of logical processor in the platform
+  and the number of those logical processors that are enabled on this boot.
+  This service may only be called from the BSP.
+
+  This function is used to retrieve the following information:
+    - The number of logical processors that are present in the system.
+    - The number of enabled logical processors in the system at the instant
+      this call is made.
+
+  Because MP Service Protocol provides services to enable and disable 
processors
+  dynamically, the number of enabled logical processors may vary during the
+  course of a boot session.
+
+  If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
+  If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
+  EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
+  is returned in NumberOfProcessors, the number of currently enabled processor
+  is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
+
+  @param[in]  This                        A pointer to the 
EFI_MP_SERVICES_PROTOCOL
+                                          instance.
+  @param[out] NumberOfProcessors          Pointer to the total number of 
logical
+                                          processors in the system, including 
the BSP
+                                          and disabled APs.
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled 
logical
+                                          processors that exist in system, 
including
+                                          the BSP.
+
+  @retval EFI_SUCCESS             The number of logical processors and enabled
+                                  logical processors was retrieved.
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL.
+  @retval EFI_INVALID_PARAMETER   NumberOfEnabledProcessors is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+GetNumberOfProcessors (
+  IN  EFI_MP_SERVICES_PROTOCOL  *This,
+  OUT UINTN                     *NumberOfProcessors,
+  OUT UINTN                     *NumberOfEnabledProcessors
+  );
+
+/**
   This return the handle number for the calling processor.  This service may be
   called from the BSP and APs.
 


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to