]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MpInitLib: Add MP Initialize library class definition
authorJeff Fan <jeff.fan@intel.com>
Tue, 19 Jul 2016 01:39:45 +0000 (09:39 +0800)
committerJeff Fan <jeff.fan@intel.com>
Wed, 17 Aug 2016 11:57:41 +0000 (19:57 +0800)
MP Initialize library provides basic functionalities to do APs initialization,
to manage MP information and to wakeup APs to execute AP task.

It could be consumed by CPU MP PEI or DXE drivers to provide CPU MP PPI/Protocol
services.

v4:
  1. MpInitLibGetProcessorInfo():
     Update HealthData type from UINT32 to EFI_HEALTH_FLAGS.
     Add #include <Ppi/SecPlatformInformation.h>
  2. MpInitLibSwitchBSP():
     Return EFI_DEVICE_ERROR instead of EFI_SUCCESS if the calling processor is
     an AP.
  3. MpInitLibStartupThisAP():
     Fix several incorrect references to "APs" to match PI spec.
  4. MpInitLibSwitchBSP() and MpInitLibEnableDisableAP():
     Fix incorrect description on ProcessorNumber.
  5. Trim whitespace at end of line.

v3:
  1. Add whitespace after MpInitLibInitialize
  2. Rename MpInitLibSwitchBsp to MpInitLibSwitchBSP to match PI spec

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Giri P Mudusuru <giri.p.mudusuru@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Giri P Mudusuru <giri.p.mudusuru@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Michael Kinney <michael.d.kinney@intel.com>
UefiCpuPkg/Include/Library/MpInitLib.h [new file with mode: 0644]
UefiCpuPkg/UefiCpuPkg.dec

diff --git a/UefiCpuPkg/Include/Library/MpInitLib.h b/UefiCpuPkg/Include/Library/MpInitLib.h
new file mode 100644 (file)
index 0000000..3e19382
--- /dev/null
@@ -0,0 +1,353 @@
+/** @file\r
+  Multiple-Processor initialization Library.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __MP_INIT_LIB_H__\r
+#define __MP_INIT_LIB_H__\r
+\r
+#include <Ppi/SecPlatformInformation.h>\r
+#include <Protocol/MpService.h>\r
+\r
+/**\r
+  MP Initialize Library initialization.\r
+\r
+  This service will allocate AP reset vector and wakeup all APs to do APs\r
+  initialization.\r
+\r
+  This service must be invoked before all other MP Initialize Library\r
+  service are invoked.\r
+\r
+  @retval  EFI_SUCCESS           MP initialization succeeds.\r
+  @retval  Others                MP initialization fails.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibInitialize (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Retrieves the number of logical processor in the platform and the number of\r
+  those logical processors that are enabled on this boot. This service may only\r
+  be called from the BSP.\r
+\r
+  @param[out] NumberOfProcessors          Pointer to the total number of logical\r
+                                          processors in the system, including the BSP\r
+                                          and disabled APs.\r
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled logical\r
+                                          processors that exist in system, including\r
+                                          the BSP.\r
+\r
+  @retval EFI_SUCCESS             The number of logical processors and enabled\r
+                                  logical processors was retrieved.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL and NumberOfEnabledProcessors\r
+                                  is NULL.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibGetNumberOfProcessors (\r
+  OUT UINTN                     *NumberOfProcessors,       OPTIONAL\r
+  OUT UINTN                     *NumberOfEnabledProcessors OPTIONAL\r
+  );\r
+\r
+/**\r
+  Gets detailed MP-related information on the requested processor at the\r
+  instant this call is made. This service may only be called from the BSP.\r
+\r
+  @param[in]  ProcessorNumber       The handle number of processor.\r
+  @param[out] ProcessorInfoBuffer   A pointer to the buffer where information for\r
+                                    the requested processor is deposited.\r
+  @param[out] HealthData            Return processor health data.\r
+\r
+  @retval EFI_SUCCESS             Processor information was returned.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorInfoBuffer is NULL.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist in the platform.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibGetProcessorInfo (\r
+  IN  UINTN                      ProcessorNumber,\r
+  OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer,\r
+  OUT EFI_HEALTH_FLAGS           *HealthData  OPTIONAL\r
+  );\r
+\r
+/**\r
+  This service executes a caller provided function on all enabled APs.\r
+\r
+  @param[in]  Procedure               A pointer to the function to be run on\r
+                                      enabled APs of the system. See type\r
+                                      EFI_AP_PROCEDURE.\r
+  @param[in]  SingleThread            If TRUE, then all the enabled APs execute\r
+                                      the function specified by Procedure one by\r
+                                      one, in ascending order of processor handle\r
+                                      number.  If FALSE, then all the enabled APs\r
+                                      execute the function specified by Procedure\r
+                                      simultaneously.\r
+  @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
+                                      service.  If it is NULL, then execute in\r
+                                      blocking mode. BSP waits until all APs finish\r
+                                      or TimeoutInMicroSeconds expires.  If it's\r
+                                      not NULL, then execute in non-blocking mode.\r
+                                      BSP requests the function specified by\r
+                                      Procedure to be started on all the enabled\r
+                                      APs, and go on executing immediately. If\r
+                                      all return from Procedure, or TimeoutInMicroSeconds\r
+                                      expires, this event is signaled. The BSP\r
+                                      can use the CheckEvent() or WaitForEvent()\r
+                                      services to check the state of event.  Type\r
+                                      EFI_EVENT is defined in CreateEvent() in\r
+                                      the Unified Extensible Firmware Interface\r
+                                      Specification.\r
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds for\r
+                                      APs to return from Procedure, either for\r
+                                      blocking or non-blocking mode. Zero means\r
+                                      infinity.  If the timeout expires before\r
+                                      all APs return from Procedure, then Procedure\r
+                                      on the failed APs is terminated. All enabled\r
+                                      APs are available for next function assigned\r
+                                      by MpInitLibStartupAllAPs() or\r
+                                      MPInitLibStartupThisAP().\r
+                                      If the timeout expires in blocking mode,\r
+                                      BSP returns EFI_TIMEOUT.  If the timeout\r
+                                      expires in non-blocking mode, WaitEvent\r
+                                      is signaled with SignalEvent().\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure for\r
+                                      all APs.\r
+  @param[out] FailedCpuList           If NULL, this parameter is ignored. Otherwise,\r
+                                      if all APs finish successfully, then its\r
+                                      content is set to NULL. If not all APs\r
+                                      finish before timeout expires, then its\r
+                                      content is set to address of the buffer\r
+                                      holding handle numbers of the failed APs.\r
+                                      The buffer is allocated by MP Initialization\r
+                                      library, and it's the caller's responsibility to\r
+                                      free the buffer with FreePool() service.\r
+                                      In blocking mode, it is ready for consumption\r
+                                      when the call returns. In non-blocking mode,\r
+                                      it is ready when WaitEvent is signaled.  The\r
+                                      list of failed CPU is terminated by\r
+                                      END_OF_CPU_LIST.\r
+\r
+  @retval EFI_SUCCESS             In blocking mode, all APs have finished before\r
+                                  the timeout expired.\r
+  @retval EFI_SUCCESS             In non-blocking mode, function has been dispatched\r
+                                  to all enabled APs.\r
+  @retval EFI_UNSUPPORTED         A non-blocking mode request was made after the\r
+                                  UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
+                                  signaled.\r
+  @retval EFI_UNSUPPORTED         WaitEvent is not NULL if non-blocking mode is not\r
+                                  supported.\r
+  @retval EFI_DEVICE_ERROR        Caller processor is AP.\r
+  @retval EFI_NOT_STARTED         No enabled APs exist in the system.\r
+  @retval EFI_NOT_READY           Any enabled APs are busy.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+  @retval EFI_TIMEOUT             In blocking mode, the timeout expired before\r
+                                  all enabled APs have finished.\r
+  @retval EFI_INVALID_PARAMETER   Procedure is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibStartupAllAPs (\r
+  IN  EFI_AP_PROCEDURE          Procedure,\r
+  IN  BOOLEAN                   SingleThread,\r
+  IN  EFI_EVENT                 WaitEvent               OPTIONAL,\r
+  IN  UINTN                     TimeoutInMicroseconds,\r
+  IN  VOID                      *ProcedureArgument      OPTIONAL,\r
+  OUT UINTN                     **FailedCpuList         OPTIONAL\r
+  );\r
+\r
+/**\r
+  This service lets the caller get one enabled AP to execute a caller-provided\r
+  function.\r
+\r
+  @param[in]  Procedure               A pointer to the function to be run on the\r
+                                      designated AP of the system. See type\r
+                                      EFI_AP_PROCEDURE.\r
+  @param[in]  ProcessorNumber         The handle number of the AP. The range is\r
+                                      from 0 to the total number of logical\r
+                                      processors minus 1. The total number of\r
+                                      logical processors can be retrieved by\r
+                                      MpInitLibGetNumberOfProcessors().\r
+  @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
+                                      service.  If it is NULL, then execute in\r
+                                      blocking mode. BSP waits until this AP finish\r
+                                      or TimeoutInMicroSeconds expires.  If it's\r
+                                      not NULL, then execute in non-blocking mode.\r
+                                      BSP requests the function specified by\r
+                                      Procedure to be started on this AP,\r
+                                      and go on executing immediately. If this AP\r
+                                      return from Procedure or TimeoutInMicroSeconds\r
+                                      expires, this event is signaled. The BSP\r
+                                      can use the CheckEvent() or WaitForEvent()\r
+                                      services to check the state of event.  Type\r
+                                      EFI_EVENT is defined in CreateEvent() in\r
+                                      the Unified Extensible Firmware Interface\r
+                                      Specification.\r
+  @param[in]  TimeoutInMicrosecsond   Indicates the time limit in microseconds for\r
+                                      this AP to finish this Procedure, either for\r
+                                      blocking or non-blocking mode. Zero means\r
+                                      infinity.  If the timeout expires before\r
+                                      this AP returns from Procedure, then Procedure\r
+                                      on the AP is terminated. The\r
+                                      AP is available for next function assigned\r
+                                      by MpInitLibStartupAllAPs() or\r
+                                      MpInitLibStartupThisAP().\r
+                                      If the timeout expires in blocking mode,\r
+                                      BSP returns EFI_TIMEOUT.  If the timeout\r
+                                      expires in non-blocking mode, WaitEvent\r
+                                      is signaled with SignalEvent().\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure on the\r
+                                      specified AP.\r
+  @param[out] Finished                If NULL, this parameter is ignored.  In\r
+                                      blocking mode, this parameter is ignored.\r
+                                      In non-blocking mode, if AP returns from\r
+                                      Procedure before the timeout expires, its\r
+                                      content is set to TRUE. Otherwise, the\r
+                                      value is set to FALSE. The caller can\r
+                                      determine if the AP returned from Procedure\r
+                                      by evaluating this value.\r
+\r
+  @retval EFI_SUCCESS             In blocking mode, specified AP finished before\r
+                                  the timeout expires.\r
+  @retval EFI_SUCCESS             In non-blocking mode, the function has been\r
+                                  dispatched to specified AP.\r
+  @retval EFI_UNSUPPORTED         A non-blocking mode request was made after the\r
+                                  UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
+                                  signaled.\r
+  @retval EFI_UNSUPPORTED         WaitEvent is not NULL if non-blocking mode is not\r
+                                  supported.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_TIMEOUT             In blocking mode, the timeout expired before\r
+                                  the specified AP has finished.\r
+  @retval EFI_NOT_READY           The specified AP is busy.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the BSP or disabled AP.\r
+  @retval EFI_INVALID_PARAMETER   Procedure is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibStartupThisAP (\r
+  IN  EFI_AP_PROCEDURE          Procedure,\r
+  IN  UINTN                     ProcessorNumber,\r
+  IN  EFI_EVENT                 WaitEvent               OPTIONAL,\r
+  IN  UINTN                     TimeoutInMicroseconds,\r
+  IN  VOID                      *ProcedureArgument      OPTIONAL,\r
+  OUT BOOLEAN                   *Finished               OPTIONAL\r
+  );\r
+\r
+/**\r
+  This service switches the requested AP to be the BSP from that point onward.\r
+  This service changes the BSP for all purposes. This call can only be performed\r
+  by the current BSP.\r
+\r
+  @param[in] ProcessorNumber   The handle number of AP that is to become the new\r
+                               BSP. The range is from 0 to the total number of\r
+                               logical processors minus 1. The total number of\r
+                               logical processors can be retrieved by\r
+                               MpInitLibGetNumberOfProcessors().\r
+  @param[in] EnableOldBSP      If TRUE, then the old BSP will be listed as an\r
+                               enabled AP. Otherwise, it will be disabled.\r
+\r
+  @retval EFI_SUCCESS             BSP successfully switched.\r
+  @retval EFI_UNSUPPORTED         Switching the BSP cannot be completed prior to\r
+                                  this service returning.\r
+  @retval EFI_UNSUPPORTED         Switching the BSP is not supported.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the current BSP or\r
+                                  a disabled AP.\r
+  @retval EFI_NOT_READY           The specified AP is busy.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibSwitchBSP (\r
+  IN UINTN                     ProcessorNumber,\r
+  IN BOOLEAN                   EnableOldBSP\r
+  );\r
+\r
+/**\r
+  This service lets the caller enable or disable an AP from this point onward.\r
+  This service may only be called from the BSP.\r
+\r
+  @param[in] ProcessorNumber   The handle number of AP.\r
+                               The range is from 0 to the total number of\r
+                               logical processors minus 1. The total number of\r
+                               logical processors can be retrieved by\r
+                               MpInitLibGetNumberOfProcessors().\r
+  @param[in] EnableAP          Specifies the new state for the processor for\r
+                               enabled, FALSE for disabled.\r
+  @param[in] HealthFlag        If not NULL, a pointer to a value that specifies\r
+                               the new health status of the AP. This flag\r
+                               corresponds to StatusFlag defined in\r
+                               EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r
+                               the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r
+                               bits are ignored.  If it is NULL, this parameter\r
+                               is ignored.\r
+\r
+  @retval EFI_SUCCESS             The specified AP was enabled or disabled successfully.\r
+  @retval EFI_UNSUPPORTED         Enabling or disabling an AP cannot be completed\r
+                                  prior to this service returning.\r
+  @retval EFI_UNSUPPORTED         Enabling or disabling an AP is not supported.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_NOT_FOUND           Processor with the handle specified by ProcessorNumber\r
+                                  does not exist.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the BSP.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibEnableDisableAP (\r
+  IN  UINTN                     ProcessorNumber,\r
+  IN  BOOLEAN                   EnableAP,\r
+  IN  UINT32                    *HealthFlag OPTIONAL\r
+  );\r
+\r
+/**\r
+  This return the handle number for the calling processor.  This service may be\r
+  called from the BSP and APs.\r
+\r
+  @param[out] ProcessorNumber  Pointer to the handle number of AP.\r
+                               The range is from 0 to the total number of\r
+                               logical processors minus 1. The total number of\r
+                               logical processors can be retrieved by\r
+                               MpInitLibGetNumberOfProcessors().\r
+\r
+  @retval EFI_SUCCESS             The current processor handle number was returned\r
+                                  in ProcessorNumber.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorNumber is NULL.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MpInitLibWhoAmI (\r
+  OUT UINTN                    *ProcessorNumber\r
+  );\r
+\r
+#endif\r
index ef46318a893517eb29f413b96fdf0bb8c54d9b5a..8674533d0b55559c06e2614db6214805ac40796e 100644 (file)
   ##\r
   SmmCpuFeaturesLib|Include/Library/SmmCpuFeaturesLib.h\r
 \r
+  ##  @libraryclass  Provides functions to support MP services on CpuMpPei and CpuDxe module.\r
+  ##\r
+  MpInitLib|Include/Library/MpInitLib.h\r
+\r
 [Guids]\r
   gUefiCpuPkgTokenSpaceGuid      = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}\r
 \r