Revision: 16366
          http://sourceforge.net/p/edk2/code/16366
Author:   jljusten
Date:     2014-11-13 18:29:13 +0000 (Thu, 13 Nov 2014)
Log Message:
-----------
UefiCpuPkg/CpuDxe: introduce ResetApStackless()

If timeout expires before AP returns from Procedure, the AP should
be terminated, we introduce ResetApStackLess() to send init IPI
to let AP exit Procedurce and re-available.

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/ApStartup.c
    trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c
    trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h

Modified: trunk/edk2/UefiCpuPkg/CpuDxe/ApStartup.c
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/ApStartup.c    2014-11-13 18:29:01 UTC (rev 
16365)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/ApStartup.c    2014-11-13 18:29:13 UTC (rev 
16366)
@@ -328,3 +328,20 @@
   return EFI_SUCCESS;
 }
 
+/**
+  Resets the Application Processor and directs it to jump to the
+  specified routine.
+
+  The processor jumps to this code in flat mode, but the processor's
+  stack is not initialized.
+
+  @param ProcessorId           the AP of ProcessorId was reset
+**/
+VOID
+ResetApStackless (
+  IN UINT32 ProcessorId
+  )
+{
+  SendInitSipiSipi (ProcessorId,
+                    (UINT32)(UINTN)(VOID*) StartupCode);
+}

Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c        2014-11-13 18:29:01 UTC (rev 
16365)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.c        2014-11-13 18:29:13 UTC (rev 
16366)
@@ -25,6 +25,7 @@
 VOID *mTopOfApCommonStack = 0;
 VOID *mApStackStart = 0;
 
+BOOLEAN mAPsAlreadyInitFinished = FALSE;
 volatile BOOLEAN mStopCheckAllAPsStatus = TRUE;
 
 EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate = {
@@ -1112,6 +1113,7 @@
   IN CPU_DATA_BLOCK  *CpuData
   )
 {
+  ResetApStackless ((UINT32)CpuData->Info.ProcessorId);
 }
 
 /**
@@ -1138,6 +1140,14 @@
 
   AsmApDoneWithCommonStack ();
 
+  //
+  // Avoid forcibly reset AP caused the AP State is not updated.
+  //
+  GetMpSpinLock (CpuData);
+  CpuData->State = CpuStateIdle;
+  CpuData->Procedure = NULL;
+  ReleaseMpSpinLock (CpuData);
+
   while (TRUE) {
     GetMpSpinLock (CpuData);
     ProcedureArgument = CpuData->Parameter;
@@ -1319,13 +1329,27 @@
   VOID
   )
 {
-  VOID* TopOfApStack;
+  VOID*           TopOfApStack;
+  UINTN           ProcessorNumber;
 
-  FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);
-  TopOfApStack  = (UINT8*)mApStackStart + gApStackSize;
-  mApStackStart = TopOfApStack;
+  if (!mAPsAlreadyInitFinished) {
+    FillInProcessorInformation (FALSE, mMpSystemData.NumberOfProcessors);
+    TopOfApStack  = (UINT8*)mApStackStart + gApStackSize;
+    mApStackStart = TopOfApStack;
 
-  mMpSystemData.NumberOfProcessors++;
+    //
+    // Store the Stack address, when reset the AP, We can found the original 
address.
+    //
+    mMpSystemData.CpuDatas[mMpSystemData.NumberOfProcessors].TopOfStack = 
TopOfApStack;
+    mMpSystemData.NumberOfProcessors++;
+    mMpSystemData.NumberOfEnabledProcessors++;
+  } else {
+    WhoAmI (&mMpServicesTemplate, &ProcessorNumber);
+    //
+    // Get the original stack address.
+    //
+    TopOfApStack = mMpSystemData.CpuDatas[ProcessorNumber].TopOfStack;
+  }
 
   SwitchStack (
     (SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,
@@ -1462,6 +1486,8 @@
     return;
   }
 
+  mAPsAlreadyInitFinished = TRUE;
+
   if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {
     FreePages (mApStackStart, EFI_SIZE_TO_PAGES (
                                 (gMaxLogicalProcessorNumber - 
mMpSystemData.NumberOfProcessors) *

Modified: trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h        2014-11-13 18:29:01 UTC (rev 
16365)
+++ trunk/edk2/UefiCpuPkg/CpuDxe/CpuMp.h        2014-11-13 18:29:13 UTC (rev 
16366)
@@ -99,6 +99,7 @@
   EFI_EVENT                      WaitEvent;
   BOOLEAN                        TimeoutActive;
   EFI_EVENT                      CheckThisAPEvent;
+  VOID                           *TopOfStack;
 } CPU_DATA_BLOCK;
 
 /**
@@ -622,5 +623,19 @@
   VOID
   );
 
+/**
+  Resets the Application Processor and directs it to jump to the
+  specified routine.
+
+  The processor jumps to this code in flat mode, but the processor's
+  stack is not initialized.
+
+  @param ProcessorId           the AP of ProcessorId was reset
+**/
+VOID
+ResetApStackless (
+  IN UINT32 ProcessorId
+  );
+
 #endif // _CPU_MP_H_
 


------------------------------------------------------------------------------
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