summaryrefslogtreecommitdiff
path: root/UefiCpuPkg
diff options
context:
space:
mode:
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r--UefiCpuPkg/CpuDxe/ApStartup.c17
-rw-r--r--UefiCpuPkg/CpuDxe/CpuMp.c36
-rw-r--r--UefiCpuPkg/CpuDxe/CpuMp.h15
3 files changed, 63 insertions, 5 deletions
diff --git a/UefiCpuPkg/CpuDxe/ApStartup.c b/UefiCpuPkg/CpuDxe/ApStartup.c
index 801f7f8611..7613b47942 100644
--- a/UefiCpuPkg/CpuDxe/ApStartup.c
+++ b/UefiCpuPkg/CpuDxe/ApStartup.c
@@ -328,3 +328,20 @@ StartApsStackless (
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);
+}
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c
index 029e8d4331..13fcda5859 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.c
+++ b/UefiCpuPkg/CpuDxe/CpuMp.c
@@ -25,6 +25,7 @@ VOID *mCommonStack = 0;
VOID *mTopOfApCommonStack = 0;
VOID *mApStackStart = 0;
+BOOLEAN mAPsAlreadyInitFinished = FALSE;
volatile BOOLEAN mStopCheckAllAPsStatus = TRUE;
EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {
@@ -1112,6 +1113,7 @@ ResetProcessorToIdleState (
IN CPU_DATA_BLOCK *CpuData
)
{
+ ResetApStackless ((UINT32)CpuData->Info.ProcessorId);
}
/**
@@ -1138,6 +1140,14 @@ ProcessorToIdleState (
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 @@ ApEntryPointInC (
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 @@ InitializeMpSupport (
return;
}
+ mAPsAlreadyInitFinished = TRUE;
+
if (mMpSystemData.NumberOfProcessors < gMaxLogicalProcessorNumber) {
FreePages (mApStackStart, EFI_SIZE_TO_PAGES (
(gMaxLogicalProcessorNumber - mMpSystemData.NumberOfProcessors) *
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h
index 2b1717d410..4254419a93 100644
--- a/UefiCpuPkg/CpuDxe/CpuMp.h
+++ b/UefiCpuPkg/CpuDxe/CpuMp.h
@@ -99,6 +99,7 @@ typedef struct {
EFI_EVENT WaitEvent;
BOOLEAN TimeoutActive;
EFI_EVENT CheckThisAPEvent;
+ VOID *TopOfStack;
} CPU_DATA_BLOCK;
/**
@@ -622,5 +623,19 @@ FreeApStartupCode (
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_