mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-24 06:04:52 +02:00
UefiCpuPkg/PiSmmCpuDxeSmm: Using MSRs semaphores in aligned buffer
Update MSRs semaphores to the ones in allocated aligned semaphores buffer. If MSRs semaphores is not enough, allocate one page more. Cc: Michael Kinney <michael.d.kinney@intel.com> Cc: Feng Tian <feng.tian@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan <jeff.fan@intel.com> Reviewed-by: Feng Tian <feng.tian@intel.com> Reviewed-by: Michael Kinney <michael.d.kinney@intel.com> Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
695e62d141
commit
dc99315b87
@ -57,7 +57,7 @@ VOID *mGdtForAp = NULL;
|
|||||||
VOID *mIdtForAp = NULL;
|
VOID *mIdtForAp = NULL;
|
||||||
VOID *mMachineCheckHandlerForAp = NULL;
|
VOID *mMachineCheckHandlerForAp = NULL;
|
||||||
MP_MSR_LOCK *mMsrSpinLocks = NULL;
|
MP_MSR_LOCK *mMsrSpinLocks = NULL;
|
||||||
UINTN mMsrSpinLockCount = MSR_SPIN_LOCK_INIT_NUM;
|
UINTN mMsrSpinLockCount;
|
||||||
UINTN mMsrCount = 0;
|
UINTN mMsrCount = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,7 +76,7 @@ GetMsrSpinLockByIndex (
|
|||||||
UINTN Index;
|
UINTN Index;
|
||||||
for (Index = 0; Index < mMsrCount; Index++) {
|
for (Index = 0; Index < mMsrCount; Index++) {
|
||||||
if (MsrIndex == mMsrSpinLocks[Index].MsrIndex) {
|
if (MsrIndex == mMsrSpinLocks[Index].MsrIndex) {
|
||||||
return &mMsrSpinLocks[Index].SpinLock;
|
return mMsrSpinLocks[Index].SpinLock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -93,30 +93,52 @@ InitMsrSpinLockByIndex (
|
|||||||
IN UINT32 MsrIndex
|
IN UINT32 MsrIndex
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
UINTN MsrSpinLockCount;
|
||||||
UINTN NewMsrSpinLockCount;
|
UINTN NewMsrSpinLockCount;
|
||||||
|
UINTN Index;
|
||||||
|
UINTN AddedSize;
|
||||||
|
|
||||||
if (mMsrSpinLocks == NULL) {
|
if (mMsrSpinLocks == NULL) {
|
||||||
mMsrSpinLocks = (MP_MSR_LOCK *) AllocatePool (sizeof (MP_MSR_LOCK) * mMsrSpinLockCount);
|
MsrSpinLockCount = mSmmCpuSemaphores.SemaphoreMsr.AvailableCounter;
|
||||||
|
mMsrSpinLocks = (MP_MSR_LOCK *) AllocatePool (sizeof (MP_MSR_LOCK) * MsrSpinLockCount);
|
||||||
ASSERT (mMsrSpinLocks != NULL);
|
ASSERT (mMsrSpinLocks != NULL);
|
||||||
|
for (Index = 0; Index < MsrSpinLockCount; Index++) {
|
||||||
|
mMsrSpinLocks[Index].SpinLock =
|
||||||
|
(SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreMsr.Msr + Index * mSemaphoreSize);
|
||||||
|
mMsrSpinLocks[Index].MsrIndex = (UINT32)-1;
|
||||||
|
}
|
||||||
|
mMsrSpinLockCount = MsrSpinLockCount;
|
||||||
|
mSmmCpuSemaphores.SemaphoreMsr.AvailableCounter = 0;
|
||||||
}
|
}
|
||||||
if (GetMsrSpinLockByIndex (MsrIndex) == NULL) {
|
if (GetMsrSpinLockByIndex (MsrIndex) == NULL) {
|
||||||
//
|
//
|
||||||
// Initialize spin lock for MSR programming
|
// Initialize spin lock for MSR programming
|
||||||
//
|
//
|
||||||
mMsrSpinLocks[mMsrCount].MsrIndex = MsrIndex;
|
mMsrSpinLocks[mMsrCount].MsrIndex = MsrIndex;
|
||||||
InitializeSpinLock (&mMsrSpinLocks[mMsrCount].SpinLock);
|
InitializeSpinLock (mMsrSpinLocks[mMsrCount].SpinLock);
|
||||||
mMsrCount ++;
|
mMsrCount ++;
|
||||||
if (mMsrCount == mMsrSpinLockCount) {
|
if (mMsrCount == mMsrSpinLockCount) {
|
||||||
//
|
//
|
||||||
// If MSR spin lock buffer is full, enlarge it
|
// If MSR spin lock buffer is full, enlarge it
|
||||||
//
|
//
|
||||||
NewMsrSpinLockCount = mMsrSpinLockCount + MSR_SPIN_LOCK_INIT_NUM;
|
AddedSize = SIZE_4KB;
|
||||||
|
mSmmCpuSemaphores.SemaphoreMsr.Msr =
|
||||||
|
AllocatePages (EFI_SIZE_TO_PAGES(AddedSize));
|
||||||
|
ASSERT (mSmmCpuSemaphores.SemaphoreMsr.Msr != NULL);
|
||||||
|
NewMsrSpinLockCount = mMsrSpinLockCount + AddedSize / mSemaphoreSize;
|
||||||
mMsrSpinLocks = ReallocatePool (
|
mMsrSpinLocks = ReallocatePool (
|
||||||
sizeof (MP_MSR_LOCK) * mMsrSpinLockCount,
|
sizeof (MP_MSR_LOCK) * mMsrSpinLockCount,
|
||||||
sizeof (MP_MSR_LOCK) * NewMsrSpinLockCount,
|
sizeof (MP_MSR_LOCK) * NewMsrSpinLockCount,
|
||||||
mMsrSpinLocks
|
mMsrSpinLocks
|
||||||
);
|
);
|
||||||
|
ASSERT (mMsrSpinLocks != NULL);
|
||||||
mMsrSpinLockCount = NewMsrSpinLockCount;
|
mMsrSpinLockCount = NewMsrSpinLockCount;
|
||||||
|
for (Index = mMsrCount; Index < mMsrSpinLockCount; Index++) {
|
||||||
|
mMsrSpinLocks[Index].SpinLock =
|
||||||
|
(SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreMsr.Msr +
|
||||||
|
(Index - mMsrCount) * mSemaphoreSize);
|
||||||
|
mMsrSpinLocks[Index].MsrIndex = (UINT32)-1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ typedef struct {
|
|||||||
#define MSR_SPIN_LOCK_INIT_NUM 15
|
#define MSR_SPIN_LOCK_INIT_NUM 15
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SPIN_LOCK SpinLock;
|
SPIN_LOCK *SpinLock;
|
||||||
UINT32 MsrIndex;
|
UINT32 MsrIndex;
|
||||||
} MP_MSR_LOCK;
|
} MP_MSR_LOCK;
|
||||||
|
|
||||||
@ -409,6 +409,8 @@ extern UINTN mSmmStackArrayEnd;
|
|||||||
extern UINTN mSmmStackSize;
|
extern UINTN mSmmStackSize;
|
||||||
extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService;
|
extern EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService;
|
||||||
extern IA32_DESCRIPTOR gcSmiInitGdtr;
|
extern IA32_DESCRIPTOR gcSmiInitGdtr;
|
||||||
|
extern SMM_CPU_SEMAPHORES mSmmCpuSemaphores;
|
||||||
|
extern UINTN mSemaphoreSize;
|
||||||
extern SPIN_LOCK *mPFLock;
|
extern SPIN_LOCK *mPFLock;
|
||||||
extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;
|
extern SPIN_LOCK *mConfigSmmCodeAccessCheckLock;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user