]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MpInitLib: Implementation of MpInitLibStartupThisAP()
authorJeff Fan <jeff.fan@intel.com>
Thu, 21 Jul 2016 13:31:47 +0000 (21:31 +0800)
committerJeff Fan <jeff.fan@intel.com>
Wed, 17 Aug 2016 12:02:26 +0000 (20:02 +0800)
v4:
  1. Simply the internal function StartupThisAPWorker()'s comment
     header due to it is duplicated with MpInitLibStartupThisAP().

v3:
  1. Use CamelCase for mStopCheckAllApsStatus and
     CheckAndUpdateApsStatus().

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: Michael Kinney <michael.d.kinney@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Michael Kinney <michael.d.kinney@intel.com>
UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg/Library/MpInitLib/PeiMpLib.c

index bd132404cc448859aec3c39068e30abbb5e241b6..75845bd8382c0a00939cec8749a3c613fcb6d506 100644 (file)
@@ -390,7 +390,25 @@ MpInitLibStartupThisAP (
   OUT BOOLEAN                   *Finished               OPTIONAL\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // temporarily stop checkAllApsStatus for avoid resource dead-lock.\r
+  //\r
+  mStopCheckAllApsStatus = TRUE;\r
+\r
+  Status = StartupThisAPWorker (\r
+             Procedure,\r
+             ProcessorNumber,\r
+             WaitEvent,\r
+             TimeoutInMicroseconds,\r
+             ProcedureArgument,\r
+             Finished\r
+             );\r
+\r
+  mStopCheckAllApsStatus = FALSE;\r
+\r
+  return Status;\r
 }\r
 \r
 /**\r
index 2691af289a2a573369bf0849944d6436cd3f0efd..c10dcd3fcb68db0514e738e684cba97d5743fc17 100644 (file)
@@ -1719,6 +1719,118 @@ MpInitLibGetNumberOfProcessors (
 }\r
 \r
 \r
+/**\r
+  Worker function to let 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\r
+                                      enabled APs of the system.\r
+  @param[in]  ProcessorNumber         The handle number of the AP.\r
+  @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
+                                      service.\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.\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure for\r
+                                      all APs.\r
+  @param[out] Finished                If AP returns from Procedure before the\r
+                                      timeout expires, its content is set to TRUE.\r
+                                      Otherwise, the value is set to FALSE.\r
+\r
+  @retval EFI_SUCCESS             In blocking mode, specified AP finished before\r
+                                  the timeout expires.\r
+  @retval others                  Failed to Startup AP.\r
+\r
+**/\r
+EFI_STATUS\r
+StartupThisAPWorker (\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
+  EFI_STATUS              Status;\r
+  CPU_MP_DATA             *CpuMpData;\r
+  CPU_AP_DATA             *CpuData;\r
+  UINTN                   CallerNumber;\r
+\r
+  CpuMpData = GetCpuMpData ();\r
+\r
+  if (Finished != NULL) {\r
+    *Finished = FALSE;\r
+  }\r
+\r
+  //\r
+  // Check whether caller processor is BSP\r
+  //\r
+  MpInitLibWhoAmI (&CallerNumber);\r
+  if (CallerNumber != CpuMpData->BspNumber) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Check whether processor with the handle specified by ProcessorNumber exists\r
+  //\r
+  if (ProcessorNumber >= CpuMpData->CpuCount) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Check whether specified processor is BSP\r
+  //\r
+  if (ProcessorNumber == CpuMpData->BspNumber) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Check parameter Procedure\r
+  //\r
+  if (Procedure == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Update AP state\r
+  //\r
+  CheckAndUpdateApsStatus ();\r
+\r
+  //\r
+  // Check whether specified AP is disabled\r
+  //\r
+  if (GetApState (&CpuMpData->CpuData[ProcessorNumber]) == CpuStateDisabled) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If WaitEvent is not NULL, execute in non-blocking mode.\r
+  // BSP saves data for CheckAPsStatus(), and returns EFI_SUCCESS.\r
+  // CheckAPsStatus() will check completion and timeout periodically.\r
+  //\r
+  CpuData = &CpuMpData->CpuData[ProcessorNumber];\r
+  CpuData->WaitEvent    = WaitEvent;\r
+  CpuData->Finished     = Finished;\r
+  CpuData->ExpectedTime = CalculateTimeout (TimeoutInMicroseconds, &CpuData->CurrentTime);\r
+  CpuData->TotalTime    = 0;\r
+\r
+  WakeUpAP (CpuMpData, FALSE, ProcessorNumber, Procedure, ProcedureArgument);\r
+\r
+  //\r
+  // If WaitEvent is NULL, execute in blocking mode.\r
+  // BSP checks AP's state until it finishes or TimeoutInMicrosecsond expires.\r
+  //\r
+  Status = EFI_SUCCESS;\r
+  if (WaitEvent == NULL) {\r
+    do {\r
+      Status = CheckThisAP (ProcessorNumber);\r
+    } while (Status == EFI_NOT_READY);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   Get pointer to CPU MP Data structure from GUIDed HOB.\r
 \r
index eba6713df8970d8ef30f13c3dbd14c6602a48916..04ffba566dda1049fbeb0a859c1d2bf550f0001f 100644 (file)
@@ -347,6 +347,39 @@ InitMpGlobalData (
   IN CPU_MP_DATA               *CpuMpData\r
   );\r
 \r
+/**\r
+  Worker function to let 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\r
+                                      enabled APs of the system.\r
+  @param[in]  ProcessorNumber         The handle number of the AP.\r
+  @param[in]  WaitEvent               The event created by the caller with CreateEvent()\r
+                                      service.\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.\r
+  @param[in]  ProcedureArgument       The parameter passed into Procedure for\r
+                                      all APs.\r
+  @param[out] Finished                If AP returns from Procedure before the\r
+                                      timeout expires, its content is set to TRUE.\r
+                                      Otherwise, the value is set to FALSE.\r
+\r
+  @retval EFI_SUCCESS             In blocking mode, specified AP finished before\r
+                                  the timeout expires.\r
+  @retval others                  Failed to Startup AP.\r
+\r
+**/\r
+EFI_STATUS\r
+StartupThisAPWorker (\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
   Worker function to switch the requested AP to be the BSP from that point onward.\r
 \r
index 64451596cf4e9e06a832acced74d47a2114cb9ee..4ea8fa96a191a4ccd19d263ab5d13806334602b3 100644 (file)
@@ -538,7 +538,18 @@ MpInitLibStartupThisAP (
   OUT BOOLEAN                   *Finished               OPTIONAL\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  if (WaitEvent != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return StartupThisAPWorker (\r
+           Procedure,\r
+           ProcessorNumber,\r
+           NULL,\r
+           TimeoutInMicroseconds,\r
+           ProcedureArgument,\r
+           Finished\r
+           );\r
 }\r
 \r
 /**\r