Continuing the pattern seen in the previous patches, we now incorporate
code from Quark_EDKII_v1.1.0/IA32FamilyCpuBasePkg/CpuMpDxe that populates
- ACPI_CPU_DATA.StackAddress,
- ACPI_CPU_DATA.StackSize.

During normal boot, CpuS3DataDxe allocates stack in the entry point for
all the APs in AcpiNVS memory. In the EFI_SMM_CONFIGURATION_PROTOCOL
installation callback, the address of that block, and the individual AP
stack size gets exposed.

On the S3 resume path:
- PiSmmCpuDxeSmm parametrizes the AP startup vector (in the exchange area)
  with the location and size of the AP stack in AcpiNVS, read from
  ACPI_CPU_DATA. (See PrepareApStartupVector() in
  "UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c".)

- When APs swarm the startup vector in
  "UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.S", they serialize on the
  "ProgramStack" logic. No matter the order they claim and vacate the
  critical section, they keep incrementing the StackStart field in the
  exchange area by StackSize, and each AP ends up assigning a distinct
  value to its own %esp.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---

Notes:
    v2:
    - Reword commit message: PiSmmCpuDxeSmm lives under UefiCpuPkg now. Plus
      Mike renamed PrepareAPStartupVector() to PrepareApStartupVector();
      update the reference in the commit message.

 OvmfPkg/QuarkPort/CpuS3DataDxe/CpuS3DataDxe.inf  |  2 ++
 OvmfPkg/QuarkPort/CpuS3DataDxe/MpCommon.h        |  1 +
 OvmfPkg/QuarkPort/CpuS3DataDxe/ProcessorConfig.c | 28 ++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/OvmfPkg/QuarkPort/CpuS3DataDxe/CpuS3DataDxe.inf 
b/OvmfPkg/QuarkPort/CpuS3DataDxe/CpuS3DataDxe.inf
index 7440c2d..4ade193 100644
--- a/OvmfPkg/QuarkPort/CpuS3DataDxe/CpuS3DataDxe.inf
+++ b/OvmfPkg/QuarkPort/CpuS3DataDxe/CpuS3DataDxe.inf
@@ -85,9 +85,11 @@ [Protocols]
 [FeaturePcd]
 
 [FixedPcd]
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber
 
 [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuS3DataAddress
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdEbdaReservedMemorySize
 
 [Depex]
diff --git a/OvmfPkg/QuarkPort/CpuS3DataDxe/MpCommon.h 
b/OvmfPkg/QuarkPort/CpuS3DataDxe/MpCommon.h
index bb4a0f8..8f47da2 100644
--- a/OvmfPkg/QuarkPort/CpuS3DataDxe/MpCommon.h
+++ b/OvmfPkg/QuarkPort/CpuS3DataDxe/MpCommon.h
@@ -68,6 +68,7 @@ typedef  struct {
 #pragma pack()
 
 typedef struct {
+  VOID              *StackStart;
   IA32_DESCRIPTOR   GdtrProfile;
   IA32_DESCRIPTOR   IdtrProfile;
 } MP_CPU_EXCHANGE_INFO;
diff --git a/OvmfPkg/QuarkPort/CpuS3DataDxe/ProcessorConfig.c 
b/OvmfPkg/QuarkPort/CpuS3DataDxe/ProcessorConfig.c
index f1f07b0..3498230 100644
--- a/OvmfPkg/QuarkPort/CpuS3DataDxe/ProcessorConfig.c
+++ b/OvmfPkg/QuarkPort/CpuS3DataDxe/ProcessorConfig.c
@@ -43,6 +43,26 @@ EFI_EVENT                           
mSmmConfigurationNotificationEvent;
 EFI_HANDLE                          mImageHandle;
 
 /**
+  Prepares memory region for processor configuration.
+  
+  This function prepares memory region for processor configuration.
+
+**/
+VOID
+PrepareMemoryForConfiguration (
+  VOID
+  )
+{
+  //
+  // Claim memory for AP stack.
+  //
+  mExchangeInfo->StackStart = AllocateAcpiNvsMemoryBelow4G (
+                                PcdGet32 (PcdCpuMaxLogicalProcessorNumber) *
+                                PcdGet32 (PcdCpuApStackSize)
+                                );
+}
+
+/**
   Event notification that is fired every time a gEfiSmmConfigurationProtocol
   installs.
 
@@ -110,6 +130,11 @@ ProcessorConfiguration (
   //
   WakeupAPAndCollectBist ();
 
+  //
+  // Prepare data in memory for processor configuration
+  //
+  PrepareMemoryForConfiguration ();
+
   return EFI_SUCCESS;
 }
 
@@ -206,6 +231,9 @@ SaveCpuS3Data (
     (EFI_PHYSICAL_ADDRESS) (UINTN) &(MpCpuSavedData->GdtrProfile);
   mAcpiCpuData->IdtrProfile    =
     (EFI_PHYSICAL_ADDRESS) (UINTN) &(MpCpuSavedData->IdtrProfile);
+  mAcpiCpuData->StackAddress   =
+    (EFI_PHYSICAL_ADDRESS) (UINTN) mExchangeInfo->StackStart;
+  mAcpiCpuData->StackSize      = PcdGet32 (PcdCpuApStackSize);
 
   mAcpiCpuData->ApMachineCheckHandlerBase = mApMachineCheckHandlerBase;
   mAcpiCpuData->ApMachineCheckHandlerSize = mApMachineCheckHandlerSize;
-- 
1.8.3.1


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to