This patch just separates the smbase relocation logic from PiSmmCpuDxeSmm driver, and moves to the SmmRelocationInit interface. It maintains the original implementation of most functions and leaves the definitions of global variables intact. Further refinements to the code are planned for subsequent patches. Platform shall consume the interface for the smbase relocation if need SMM support. Note: Before using SmmRelocationLib, the PiSmmCpuDxeSmm driver allocates the SMRAM to be used for SMI handler and Save state area of each processor from Smst->AllocatePages(). With SmmRelocationLib, the SMRAM allocation for SMI handlers and Save state areas is moved to early PEI phase (Smst->AllocatePages() service is not available). So, the allocation is done by splitting the SMRAM out of the SMRAM regions reported from gEfiSmmSMramMemoryGuid. So, Platform must produce the gEfiSmmSMramMemoryGuid HOB for SmmRelocationLib usage. Cc: Ray Ni <ray.ni@intel.com> Cc: Zeng Star <star.zeng@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
70 lines
2.0 KiB
C
70 lines
2.0 KiB
C
/** @file
|
|
Semaphore mechanism to indicate to the BSP that an AP has exited SMM
|
|
after SMBASE relocation.
|
|
|
|
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#include "InternalSmmRelocationLib.h"
|
|
|
|
X86_ASSEMBLY_PATCH_LABEL gPatchSmmRelocationOriginalAddressPtr32;
|
|
X86_ASSEMBLY_PATCH_LABEL gPatchRebasedFlagAddr32;
|
|
|
|
UINTN mSmmRelocationOriginalAddress;
|
|
volatile BOOLEAN *mRebasedFlag;
|
|
|
|
/**
|
|
AP Semaphore operation in 32-bit mode while BSP runs in 64-bit mode.
|
|
**/
|
|
VOID
|
|
SmmRelocationSemaphoreComplete32 (
|
|
VOID
|
|
);
|
|
|
|
/**
|
|
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;
|
|
|
|
mRebasedFlag = RebasedFlag;
|
|
PatchInstructionX86 (
|
|
gPatchRebasedFlagAddr32,
|
|
(UINT32)(UINTN)mRebasedFlag,
|
|
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
|
|
);
|
|
|
|
//
|
|
// Use temp value to fix ICC compiler warning
|
|
//
|
|
TempValue = (UINTN)&mSmmRelocationOriginalAddress;
|
|
PatchInstructionX86 (
|
|
gPatchSmmRelocationOriginalAddressPtr32,
|
|
(UINT32)TempValue,
|
|
4
|
|
);
|
|
}
|