This patch aims on mProcessorInfo global variable, which can be
defined as local variable in SmmRelocateBases(). With this patch,
no need to allocate the memory for all CPUs to store the
Processor Info.

Cc: Ray Ni <ray...@intel.com>
Cc: Zeng Star <star.z...@intel.com>
Cc: Gerd Hoffmann <kra...@redhat.com>
Cc: Rahul Kumar <rahul1.ku...@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin...@intel.com>
---
 .../Library/SmmRelocationLib/Ia32/Semaphore.c      |  3 -
 .../SmmRelocationLib/InternalSmmRelocationLib.h    |  5 --
 .../Library/SmmRelocationLib/SmmRelocationLib.c    | 78 +++++++---------------
 .../SmmRelocationLib/SmramSaveStateConfig.c        |  3 -
 .../Library/SmmRelocationLib/X64/Semaphore.c       |  3 -
 5 files changed, 24 insertions(+), 68 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c 
b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c
index ba329d6ba2..5d9eea3de9 100644
--- a/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c
+++ b/UefiCpuPkg/Library/SmmRelocationLib/Ia32/Semaphore.c
@@ -15,28 +15,25 @@ volatile BOOLEAN  *mRebasedFlag;
 /**
   Hook return address of SMM Save State so that semaphore code
   can be executed immediately after AP exits SMM to indicate to
   the BSP that an AP has exited SMM after SMBASE relocation.
 
-  @param[in] CpuIndex     The processor index.
   @param[in] RebasedFlag  A pointer to a flag that is set to TRUE
                           immediately after AP exits SMM.
 
 **/
 VOID
 SemaphoreHook (
-  IN UINTN             CpuIndex,
   IN volatile BOOLEAN  *RebasedFlag
   )
 {
   SMRAM_SAVE_STATE_MAP  *CpuState;
 
   mRebasedFlag = RebasedFlag;
 
   CpuState                      = (SMRAM_SAVE_STATE_MAP 
*)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
   mSmmRelocationOriginalAddress = (UINTN)HookReturnFromSmm (
-                                           CpuIndex,
                                            CpuState,
                                            
(UINT64)(UINTN)&SmmRelocationSemaphoreComplete,
                                            
(UINT64)(UINTN)&SmmRelocationSemaphoreComplete
                                            );
 }
diff --git a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h 
b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h
index ede61b956f..d1387f2dfb 100644
--- a/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h
+++ b/UefiCpuPkg/Library/SmmRelocationLib/InternalSmmRelocationLib.h
@@ -81,12 +81,10 @@ SmmRelocationSemaphoreComplete (
   Hook the code executed immediately after an RSM instruction on the currently
   executing CPU.  The mode of code executed immediately after RSM must be
   detected, and the appropriate hook must be selected.  Always clear the auto
   HALT restart flag if it is set.
 
-  @param[in]     CpuIndex                 The processor index for the currently
-                                          executing CPU.
   @param[in,out] CpuState                 Pointer to SMRAM Save State Map for 
the
                                           currently executing CPU.
   @param[in]     NewInstructionPointer32  Instruction pointer to use if 
resuming to
                                           32-bit mode from 64-bit SMM.
   @param[in]     NewInstructionPointer    Instruction pointer to use if 
resuming to
@@ -96,29 +94,26 @@ SmmRelocationSemaphoreComplete (
 
 **/
 UINT64
 EFIAPI
 HookReturnFromSmm (
-  IN     UINTN                 CpuIndex,
   IN OUT SMRAM_SAVE_STATE_MAP  *CpuState,
   IN     UINT64                NewInstructionPointer32,
   IN     UINT64                NewInstructionPointer
   );
 
 /**
   Hook return address of SMM Save State so that semaphore code
   can be executed immediately after AP exits SMM to indicate to
   the BSP that an AP has exited SMM after SMBASE relocation.
 
-  @param[in] CpuIndex     The processor index.
   @param[in] RebasedFlag  A pointer to a flag that is set to TRUE
                           immediately after AP exits SMM.
 
 **/
 VOID
 SemaphoreHook (
-  IN UINTN             CpuIndex,
   IN volatile BOOLEAN  *RebasedFlag
   );
 
 /**
   This function fixes up the address of the global variable or function
diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c 
b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c
index 3694a07cbb..7e65bbf929 100644
--- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c
+++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c
@@ -14,15 +14,10 @@
 #include "InternalSmmRelocationLib.h"
 
 UINTN  mMaxNumberOfCpus = 1;
 UINTN  mNumberOfCpus    = 1;
 
-//
-// Record all Processors Info
-//
-EFI_PROCESSOR_INFORMATION  *mProcessorInfo = NULL;
-
 //
 // IDT used during SMM Init
 //
 IA32_DESCRIPTOR  gcSmmInitIdtr;
 
@@ -138,37 +133,26 @@ VOID
 EFIAPI
 SmmInitHandler (
   VOID
   )
 {
-  UINT32  ApicId;
-  UINTN   Index;
-
   //
   // Update SMM IDT entries' code segment and load IDT
   //
   AsmWriteIdtr (&gcSmmInitIdtr);
-  ApicId = GetApicId ();
-
-  for (Index = 0; Index < mNumberOfCpus; Index++) {
-    if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) {
-      //
-      // Configure SmBase.
-      //
-      ConfigureSmBase (mSmBase);
 
-      //
-      // Hook return after RSM to set SMM re-based flag
-      // SMM re-based flag can't be set before RSM, because SMM save state 
context might be override
-      // by next AP flow before it take effect.
-      //
-      SemaphoreHook (Index, &mRebased);
-      return;
-    }
-  }
+  //
+  // Configure SmBase.
+  //
+  ConfigureSmBase (mSmBase);
 
-  ASSERT (FALSE);
+  //
+  // Hook return after RSM to set SMM re-based flag
+  // SMM re-based flag can't be set before RSM, because SMM save state context 
might be override
+  // by next AP flow before it take effect.
+  //
+  SemaphoreHook (&mRebased);
 }
 
 /**
   Relocate SmmBases for each processor.
   Execute on first boot and all S3 resumes
@@ -185,17 +169,19 @@ SmmRelocateBases (
   IN EDKII_PEI_MP_SERVICES2_PPI  *MpServices2,
   IN EFI_PHYSICAL_ADDRESS        SmmRelocationStart,
   IN UINTN                       TileSize
   )
 {
-  UINT8                 BakBuf[BACK_BUF_SIZE];
-  SMRAM_SAVE_STATE_MAP  BakBuf2;
-  SMRAM_SAVE_STATE_MAP  *CpuStatePtr;
-  UINT8                 *U8Ptr;
-  UINTN                 Index;
-  UINTN                 BspIndex;
-  UINT32                BspApicId;
+  EFI_STATUS                 Status;
+  UINT8                      BakBuf[BACK_BUF_SIZE];
+  SMRAM_SAVE_STATE_MAP       BakBuf2;
+  SMRAM_SAVE_STATE_MAP       *CpuStatePtr;
+  UINT8                      *U8Ptr;
+  UINTN                      Index;
+  UINTN                      BspIndex;
+  UINT32                     BspApicId;
+  EFI_PROCESSOR_INFORMATION  ProcessorInfo;
 
   //
   // Make sure the reserved size is large enough for procedure SmmInitTemplate.
   //
   ASSERT (sizeof (BakBuf) >= gcSmmInitSize);
@@ -230,14 +216,17 @@ SmmRelocateBases (
   // Relocate SM bases for all APs
   // This is APs' 1st SMI - rebase will be done here, and APs' default SMI 
handler will be overridden by gcSmmInitTemplate
   //
   BspIndex = (UINTN)-1;
   for (Index = 0; Index < mNumberOfCpus; Index++) {
-    if (BspApicId != (UINT32)mProcessorInfo[Index].ProcessorId) {
+    Status = MpServices2->GetProcessorInfo (MpServices2, Index | 
CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo);
+    ASSERT_EFI_ERROR (Status);
+
+    if (BspApicId != (UINT32)ProcessorInfo.ProcessorId) {
       mRebased = FALSE;
       mSmBase  = GetSmBase (Index, SmmRelocationStart, TileSize);
-      SendSmiIpi ((UINT32)mProcessorInfo[Index].ProcessorId);
+      SendSmiIpi ((UINT32)ProcessorInfo.ProcessorId);
       //
       // Wait for this AP to finish its 1st SMI
       //
       while (!mRebased) {
       }
@@ -443,11 +432,10 @@ SmmRelocationInit (
   UINTN                 TileSize;
   UINT64                SmmRelocationSize;
   EFI_PHYSICAL_ADDRESS  SmmRelocationStart;
   UINTN                 SmmStackSize;
   UINT8                 *SmmStacks;
-  UINTN                 Index;
 
   SmmRelocationStart = 0;
   SmmStacks          = NULL;
 
   DEBUG ((DEBUG_INFO, "SmmRelocationInit Start \n"));
@@ -473,28 +461,10 @@ SmmRelocationInit (
     mMaxNumberOfCpus = mNumberOfCpus;
   }
 
   ASSERT (mNumberOfCpus <= mMaxNumberOfCpus);
 
-  //
-  // Retrieve the Processor Info for all CPUs
-  //
-  mProcessorInfo = (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof 
(EFI_PROCESSOR_INFORMATION) * mMaxNumberOfCpus);
-  if (mProcessorInfo == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto ON_EXIT;
-  }
-
-  for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
-    if (Index < mNumberOfCpus) {
-      Status = MpServices2->GetProcessorInfo (MpServices2, Index | 
CPU_V2_EXTENDED_TOPOLOGY, &mProcessorInfo[Index]);
-      if (EFI_ERROR (Status)) {
-        goto ON_EXIT;
-      }
-    }
-  }
-
   //
   // Calculate SmmRelocationSize for all of the tiles.
   //
   // The CPU save state and code for the SMI entry point are tiled within an 
SMRAM
   // allocated buffer. The minimum size of this buffer for a uniprocessor 
system
diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c 
b/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c
index d3a0bb9b89..76d798aba5 100644
--- a/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c
+++ b/UefiCpuPkg/Library/SmmRelocationLib/SmramSaveStateConfig.c
@@ -82,12 +82,10 @@ ConfigureSmBase (
   Hook the code executed immediately after an RSM instruction on the currently
   executing CPU.  The mode of code executed immediately after RSM must be
   detected, and the appropriate hook must be selected.  Always clear the auto
   HALT restart flag if it is set.
 
-  @param[in]     CpuIndex                 The processor index for the currently
-                                          executing CPU.
   @param[in,out] CpuState                 Pointer to SMRAM Save State Map for 
the
                                           currently executing CPU.
   @param[in]     NewInstructionPointer32  Instruction pointer to use if 
resuming to
                                           32-bit mode from 64-bit SMM.
   @param[in]     NewInstructionPointer    Instruction pointer to use if 
resuming to
@@ -97,11 +95,10 @@ ConfigureSmBase (
 
 **/
 UINT64
 EFIAPI
 HookReturnFromSmm (
-  IN     UINTN                 CpuIndex,
   IN OUT SMRAM_SAVE_STATE_MAP  *CpuState,
   IN     UINT64                NewInstructionPointer32,
   IN     UINT64                NewInstructionPointer
   )
 {
diff --git a/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c 
b/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c
index 53f3084363..cd6778e3fc 100644
--- a/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c
+++ b/UefiCpuPkg/Library/SmmRelocationLib/X64/Semaphore.c
@@ -26,18 +26,16 @@ SmmRelocationSemaphoreComplete32 (
 /**
   Hook return address of SMM Save State so that semaphore code
   can be executed immediately after AP exits SMM to indicate to
   the BSP that an AP has exited SMM after SMBASE relocation.
 
-  @param[in] CpuIndex     The processor index.
   @param[in] RebasedFlag  A pointer to a flag that is set to TRUE
                           immediately after AP exits SMM.
 
 **/
 VOID
 SemaphoreHook (
-  IN UINTN             CpuIndex,
   IN volatile BOOLEAN  *RebasedFlag
   )
 {
   SMRAM_SAVE_STATE_MAP  *CpuState;
   UINTN                 TempValue;
@@ -49,11 +47,10 @@ SemaphoreHook (
     4
     );
 
   CpuState                      = (SMRAM_SAVE_STATE_MAP 
*)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
   mSmmRelocationOriginalAddress = HookReturnFromSmm (
-                                    CpuIndex,
                                     CpuState,
                                     
(UINT64)(UINTN)&SmmRelocationSemaphoreComplete32,
                                     
(UINT64)(UINTN)&SmmRelocationSemaphoreComplete
                                     );
 
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117950): https://edk2.groups.io/g/devel/message/117950
Mute This Topic: https://groups.io/mt/105593573/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to