mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
UefiCpuPkg/PiSmmCpuDxeSmm: Move SMM profile data allocation into func
MM can not use the gBS service, so move SMM profile data allocation into function. This can make InitSmmProfileInternal() to a common function for both SMM and MM. Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Star Zeng <star.zeng@intel.com> Cc: Dun Tan <dun.tan@intel.com> Cc: Hongbin1 Zhang <hongbin1.zhang@intel.com> Cc: Wei6 Xu <wei6.xu@intel.com> Cc: Yuanhao Xie <yuanhao.xie@intel.com>
This commit is contained in:
parent
89fe9c5d79
commit
5547d1487c
@ -423,6 +423,43 @@ SetUefiMemMapAttributes (
|
|||||||
PERF_FUNCTION_END ();
|
PERF_FUNCTION_END ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get SmmProfileData.
|
||||||
|
|
||||||
|
@param[in, out] Size Return Size of SmmProfileData.
|
||||||
|
|
||||||
|
@return Address of SmmProfileData
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_PHYSICAL_ADDRESS
|
||||||
|
GetSmmProfileData (
|
||||||
|
IN OUT UINT64 *Size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_PHYSICAL_ADDRESS Base;
|
||||||
|
|
||||||
|
ASSERT (Size != NULL);
|
||||||
|
|
||||||
|
if (mBtsSupported) {
|
||||||
|
*Size = PcdGet32 (PcdCpuSmmProfileSize) + mMsrDsAreaSize;
|
||||||
|
} else {
|
||||||
|
*Size = PcdGet32 (PcdCpuSmmProfileSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
Base = 0xFFFFFFFF;
|
||||||
|
Status = gBS->AllocatePages (
|
||||||
|
AllocateMaxAddress,
|
||||||
|
EfiReservedMemoryType,
|
||||||
|
(UINTN)EFI_SIZE_TO_PAGES (*Size),
|
||||||
|
&Base
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
ZeroMem ((VOID *)(UINTN)Base, (UINTN)*Size);
|
||||||
|
|
||||||
|
return Base;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return if the Address is forbidden as SMM communication buffer.
|
Return if the Address is forbidden as SMM communication buffer.
|
||||||
|
|
||||||
|
@ -267,6 +267,9 @@ extern UINTN mSmmShadowStackSize;
|
|||||||
///
|
///
|
||||||
extern UINT8 mSmmSaveStateRegisterLma;
|
extern UINT8 mSmmSaveStateRegisterLma;
|
||||||
|
|
||||||
|
extern BOOLEAN mBtsSupported;
|
||||||
|
extern UINTN mMsrDsAreaSize;
|
||||||
|
|
||||||
#define PAGE_TABLE_POOL_ALIGNMENT BASE_128KB
|
#define PAGE_TABLE_POOL_ALIGNMENT BASE_128KB
|
||||||
#define PAGE_TABLE_POOL_UNIT_SIZE BASE_128KB
|
#define PAGE_TABLE_POOL_UNIT_SIZE BASE_128KB
|
||||||
#define PAGE_TABLE_POOL_UNIT_PAGES EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)
|
#define PAGE_TABLE_POOL_UNIT_PAGES EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)
|
||||||
@ -910,6 +913,19 @@ SetUefiMemMapAttributes (
|
|||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get SmmProfileData.
|
||||||
|
|
||||||
|
@param[in, out] Size Return Size of SmmProfileData.
|
||||||
|
|
||||||
|
@return Address of SmmProfileData
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_PHYSICAL_ADDRESS
|
||||||
|
GetSmmProfileData (
|
||||||
|
IN OUT UINT64 *Size
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return if the Address is forbidden as SMM communication buffer.
|
Return if the Address is forbidden as SMM communication buffer.
|
||||||
|
|
||||||
|
@ -795,12 +795,11 @@ InitSmmProfileInternal (
|
|||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_PHYSICAL_ADDRESS Base;
|
VOID *Registration;
|
||||||
VOID *Registration;
|
UINTN Index;
|
||||||
UINTN Index;
|
UINTN MsrDsAreaSizePerCpu;
|
||||||
UINTN MsrDsAreaSizePerCpu;
|
UINT64 SmmProfileSize;
|
||||||
UINTN TotalSize;
|
|
||||||
|
|
||||||
mPFEntryCount = (UINTN *)AllocateZeroPool (sizeof (UINTN) * mMaxNumberOfCpus);
|
mPFEntryCount = (UINTN *)AllocateZeroPool (sizeof (UINTN) * mMaxNumberOfCpus);
|
||||||
ASSERT (mPFEntryCount != NULL);
|
ASSERT (mPFEntryCount != NULL);
|
||||||
@ -813,29 +812,15 @@ InitSmmProfileInternal (
|
|||||||
);
|
);
|
||||||
ASSERT (mLastPFEntryPointer != NULL);
|
ASSERT (mLastPFEntryPointer != NULL);
|
||||||
|
|
||||||
//
|
mSmmProfileSize = FixedPcdGet32 (PcdCpuSmmProfileSize);
|
||||||
// Allocate memory for SmmProfile below 4GB.
|
|
||||||
// The base address
|
|
||||||
//
|
|
||||||
mSmmProfileSize = PcdGet32 (PcdCpuSmmProfileSize);
|
|
||||||
ASSERT ((mSmmProfileSize & 0xFFF) == 0);
|
ASSERT ((mSmmProfileSize & 0xFFF) == 0);
|
||||||
|
|
||||||
if (mBtsSupported) {
|
//
|
||||||
TotalSize = mSmmProfileSize + mMsrDsAreaSize;
|
// Get Smm Profile Base
|
||||||
} else {
|
//
|
||||||
TotalSize = mSmmProfileSize;
|
mSmmProfileBase = (SMM_PROFILE_HEADER *)(UINTN)GetSmmProfileData (&SmmProfileSize);
|
||||||
}
|
DEBUG ((DEBUG_ERROR, "SmmProfileBase = 0x%016x.\n", (UINTN)mSmmProfileBase));
|
||||||
|
DEBUG ((DEBUG_ERROR, "SmmProfileSize = 0x%016x.\n", (UINTN)SmmProfileSize));
|
||||||
Base = 0xFFFFFFFF;
|
|
||||||
Status = gBS->AllocatePages (
|
|
||||||
AllocateMaxAddress,
|
|
||||||
EfiReservedMemoryType,
|
|
||||||
EFI_SIZE_TO_PAGES (TotalSize),
|
|
||||||
&Base
|
|
||||||
);
|
|
||||||
ASSERT_EFI_ERROR (Status);
|
|
||||||
ZeroMem ((VOID *)(UINTN)Base, TotalSize);
|
|
||||||
mSmmProfileBase = (SMM_PROFILE_HEADER *)(UINTN)Base;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize SMM profile data header.
|
// Initialize SMM profile data header.
|
||||||
@ -858,7 +843,7 @@ InitSmmProfileInternal (
|
|||||||
mMsrPEBSRecord = (PEBS_RECORD **)AllocateZeroPool (sizeof (PEBS_RECORD *) * mMaxNumberOfCpus);
|
mMsrPEBSRecord = (PEBS_RECORD **)AllocateZeroPool (sizeof (PEBS_RECORD *) * mMaxNumberOfCpus);
|
||||||
ASSERT (mMsrPEBSRecord != NULL);
|
ASSERT (mMsrPEBSRecord != NULL);
|
||||||
|
|
||||||
mMsrDsAreaBase = (MSR_DS_AREA_STRUCT *)((UINTN)Base + mSmmProfileSize);
|
mMsrDsAreaBase = (MSR_DS_AREA_STRUCT *)((UINTN)mSmmProfileBase + mSmmProfileSize);
|
||||||
MsrDsAreaSizePerCpu = mMsrDsAreaSize / mMaxNumberOfCpus;
|
MsrDsAreaSizePerCpu = mMsrDsAreaSize / mMaxNumberOfCpus;
|
||||||
mBTSRecordNumber = (MsrDsAreaSizePerCpu - sizeof (PEBS_RECORD) * PEBS_RECORD_NUMBER - sizeof (MSR_DS_AREA_STRUCT)) / sizeof (BRANCH_TRACE_RECORD);
|
mBTSRecordNumber = (MsrDsAreaSizePerCpu - sizeof (PEBS_RECORD) * PEBS_RECORD_NUMBER - sizeof (MSR_DS_AREA_STRUCT)) / sizeof (BRANCH_TRACE_RECORD);
|
||||||
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
|
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
|
||||||
@ -891,7 +876,7 @@ InitSmmProfileInternal (
|
|||||||
// Update SMM profile entry.
|
// Update SMM profile entry.
|
||||||
//
|
//
|
||||||
mProtectionMemRange[1].Range.Base = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase;
|
mProtectionMemRange[1].Range.Base = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase;
|
||||||
mProtectionMemRange[1].Range.Top = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase + TotalSize;
|
mProtectionMemRange[1].Range.Top = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase + SmmProfileSize;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Allocate memory reserved for creating 4KB pages.
|
// Allocate memory reserved for creating 4KB pages.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user