UefiCpuPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the UefiCpuPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:17 -08:00
committed by mergify[bot]
parent 91415a36ae
commit 053e878bfb
143 changed files with 14130 additions and 13035 deletions

View File

@@ -77,5 +77,5 @@ GetCpuSteppingId (
AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL);
return (UINT8) Eax.Bits.SteppingId;
return (UINT8)Eax.Bits.SteppingId;
}

View File

@@ -44,13 +44,14 @@ LocalApicBaseAddressMsrSupported (
AsmCpuid (1, &RegEax, NULL, NULL, NULL);
FamilyId = BitFieldRead32 (RegEax, 8, 11);
if (FamilyId == 0x04 || FamilyId == 0x05) {
if ((FamilyId == 0x04) || (FamilyId == 0x05)) {
//
// CPUs with a FamilyId of 0x04 or 0x05 do not support the
// Local APIC Base Address MSR
//
return FALSE;
}
return TRUE;
}
@@ -78,8 +79,8 @@ GetLocalApicBaseAddress (
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
return (UINTN)(LShiftU64 ((UINT64) ApicBaseMsr.Bits.ApicBaseHi, 32)) +
(((UINTN)ApicBaseMsr.Bits.ApicBase) << 12);
return (UINTN)(LShiftU64 ((UINT64)ApicBaseMsr.Bits.ApicBaseHi, 32)) +
(((UINTN)ApicBaseMsr.Bits.ApicBase) << 12);
}
/**
@@ -93,7 +94,7 @@ GetLocalApicBaseAddress (
VOID
EFIAPI
SetLocalApicBaseAddress (
IN UINTN BaseAddress
IN UINTN BaseAddress
)
{
MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
@@ -109,8 +110,8 @@ SetLocalApicBaseAddress (
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
ApicBaseMsr.Bits.ApicBase = (UINT32) (BaseAddress >> 12);
ApicBaseMsr.Bits.ApicBaseHi = (UINT32) (RShiftU64((UINT64) BaseAddress, 32));
ApicBaseMsr.Bits.ApicBase = (UINT32)(BaseAddress >> 12);
ApicBaseMsr.Bits.ApicBaseHi = (UINT32)(RShiftU64 ((UINT64)BaseAddress, 32));
AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
}
@@ -137,7 +138,7 @@ ReadLocalApicReg (
ASSERT ((MmioOffset & 0xf) == 0);
ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);
return MmioRead32 (GetLocalApicBaseAddress() + MmioOffset);
return MmioRead32 (GetLocalApicBaseAddress () + MmioOffset);
}
/**
@@ -157,14 +158,14 @@ ReadLocalApicReg (
VOID
EFIAPI
WriteLocalApicReg (
IN UINTN MmioOffset,
IN UINT32 Value
IN UINTN MmioOffset,
IN UINT32 Value
)
{
ASSERT ((MmioOffset & 0xf) == 0);
ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);
MmioWrite32 (GetLocalApicBaseAddress() + MmioOffset, Value);
MmioWrite32 (GetLocalApicBaseAddress () + MmioOffset, Value);
}
/**
@@ -177,13 +178,13 @@ WriteLocalApicReg (
**/
VOID
SendIpi (
IN UINT32 IcrLow,
IN UINT32 ApicId
IN UINT32 IcrLow,
IN UINT32 ApicId
)
{
LOCAL_APIC_ICR_LOW IcrLowReg;
UINT32 IcrHigh;
BOOLEAN InterruptState;
LOCAL_APIC_ICR_LOW IcrLowReg;
UINT32 IcrHigh;
BOOLEAN InterruptState;
ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);
ASSERT (ApicId <= 0xff);
@@ -222,7 +223,6 @@ SendIpi (
WriteLocalApicReg (XAPIC_ICR_HIGH_OFFSET, IcrHigh);
SetInterruptState (InterruptState);
}
//
@@ -244,21 +244,21 @@ GetApicMode (
)
{
DEBUG_CODE_BEGIN ();
{
MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
{
MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
//
// Check to see if the CPU supports the APIC Base Address MSR
//
if (LocalApicBaseAddressMsrSupported ()) {
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
//
// Check to see if the CPU supports the APIC Base Address MSR
// Local APIC should have been enabled
//
if (LocalApicBaseAddressMsrSupported ()) {
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
//
// Local APIC should have been enabled
//
ASSERT (ApicBaseMsr.Bits.EN != 0);
ASSERT (ApicBaseMsr.Bits.EXTD == 0);
}
ASSERT (ApicBaseMsr.Bits.EN != 0);
ASSERT (ApicBaseMsr.Bits.EXTD == 0);
}
}
DEBUG_CODE_END ();
return LOCAL_APIC_MODE_XAPIC;
}
@@ -299,9 +299,9 @@ GetInitialApicId (
VOID
)
{
UINT32 ApicId;
UINT32 MaxCpuIdIndex;
UINT32 RegEbx;
UINT32 ApicId;
UINT32 MaxCpuIdIndex;
UINT32 RegEbx;
ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);
@@ -338,7 +338,7 @@ GetApicId (
VOID
)
{
UINT32 ApicId;
UINT32 ApicId;
ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);
@@ -347,9 +347,10 @@ GetApicId (
// If the initial local APIC ID is less 0x100, read APIC ID from
// XAPIC_ID_OFFSET, otherwise return the initial local APIC ID.
//
ApicId = ReadLocalApicReg (XAPIC_ID_OFFSET);
ApicId = ReadLocalApicReg (XAPIC_ID_OFFSET);
ApicId >>= 24;
}
return ApicId;
}
@@ -378,16 +379,16 @@ GetApicVersion (
VOID
EFIAPI
SendFixedIpi (
IN UINT32 ApicId,
IN UINT8 Vector
IN UINT32 ApicId,
IN UINT8 Vector
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Vector = Vector;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Vector = Vector;
SendIpi (IcrLow.Uint32, ApicId);
}
@@ -401,16 +402,16 @@ SendFixedIpi (
VOID
EFIAPI
SendFixedIpiAllExcludingSelf (
IN UINT8 Vector
IN UINT8 Vector
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
IcrLow.Bits.Level = 1;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
IcrLow.Bits.Vector = Vector;
IcrLow.Bits.Vector = Vector;
SendIpi (IcrLow.Uint32, 0);
}
@@ -424,14 +425,14 @@ SendFixedIpiAllExcludingSelf (
VOID
EFIAPI
SendSmiIpi (
IN UINT32 ApicId
IN UINT32 ApicId
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Level = 1;
SendIpi (IcrLow.Uint32, ApicId);
}
@@ -446,11 +447,11 @@ SendSmiIpiAllExcludingSelf (
VOID
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
IcrLow.Bits.Level = 1;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
SendIpi (IcrLow.Uint32, 0);
}
@@ -465,14 +466,14 @@ SendSmiIpiAllExcludingSelf (
VOID
EFIAPI
SendInitIpi (
IN UINT32 ApicId
IN UINT32 ApicId
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Level = 1;
SendIpi (IcrLow.Uint32, ApicId);
}
@@ -487,11 +488,11 @@ SendInitIpiAllExcludingSelf (
VOID
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
IcrLow.Bits.Level = 1;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
SendIpi (IcrLow.Uint32, 0);
}
@@ -511,21 +512,21 @@ SendInitIpiAllExcludingSelf (
VOID
EFIAPI
SendInitSipiSipi (
IN UINT32 ApicId,
IN UINT32 StartupRoutine
IN UINT32 ApicId,
IN UINT32 StartupRoutine
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
ASSERT (StartupRoutine < 0x100000);
ASSERT ((StartupRoutine & 0xfff) == 0);
SendInitIpi (ApicId);
MicroSecondDelay (PcdGet32(PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Level = 1;
SendIpi (IcrLow.Uint32, ApicId);
if (!StandardSignatureIsAuthenticAMD ()) {
MicroSecondDelay (200);
@@ -547,20 +548,20 @@ SendInitSipiSipi (
VOID
EFIAPI
SendInitSipiSipiAllExcludingSelf (
IN UINT32 StartupRoutine
IN UINT32 StartupRoutine
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
ASSERT (StartupRoutine < 0x100000);
ASSERT ((StartupRoutine & 0xfff) == 0);
SendInitIpiAllExcludingSelf ();
MicroSecondDelay (PcdGet32(PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
IcrLow.Bits.Level = 1;
MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
SendIpi (IcrLow.Uint32, 0);
if (!StandardSignatureIsAuthenticAMD ()) {
@@ -616,13 +617,13 @@ ProgramVirtualWireMode (
VOID
)
{
LOCAL_APIC_SVR Svr;
LOCAL_APIC_LVT_LINT Lint;
LOCAL_APIC_SVR Svr;
LOCAL_APIC_LVT_LINT Lint;
//
// Enable the APIC via SVR and set the spurious interrupt to use Int 00F.
//
Svr.Uint32 = ReadLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET);
Svr.Uint32 = ReadLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET);
Svr.Bits.SpuriousVector = 0xf;
Svr.Bits.SoftwareEnable = 1;
WriteLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET, Svr.Uint32);
@@ -630,21 +631,21 @@ ProgramVirtualWireMode (
//
// Program the LINT0 vector entry as ExtInt. Not masked, edge, active high.
//
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_EXTINT;
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_EXTINT;
Lint.Bits.InputPinPolarity = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
WriteLocalApicReg (XAPIC_LVT_LINT0_OFFSET, Lint.Uint32);
//
// Program the LINT0 vector entry as NMI. Not masked, edge, active high.
//
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_NMI;
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_NMI;
Lint.Bits.InputPinPolarity = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
WriteLocalApicReg (XAPIC_LVT_LINT1_OFFSET, Lint.Uint32);
}
@@ -659,13 +660,13 @@ DisableLvtInterrupts (
VOID
)
{
LOCAL_APIC_LVT_LINT LvtLint;
LOCAL_APIC_LVT_LINT LvtLint;
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
LvtLint.Bits.Mask = 1;
WriteLocalApicReg (XAPIC_LVT_LINT0_OFFSET, LvtLint.Uint32);
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
LvtLint.Bits.Mask = 1;
WriteLocalApicReg (XAPIC_LVT_LINT1_OFFSET, LvtLint.Uint32);
}
@@ -712,15 +713,15 @@ GetApicTimerCurrentCount (
VOID
EFIAPI
InitializeApicTimer (
IN UINTN DivideValue,
IN UINT32 InitCount,
IN BOOLEAN PeriodicMode,
IN UINT8 Vector
IN UINTN DivideValue,
IN UINT32 InitCount,
IN BOOLEAN PeriodicMode,
IN UINT8 Vector
)
{
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
UINT32 Divisor;
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
UINT32 Divisor;
//
// Ensure local APIC is in software-enabled state.
@@ -734,10 +735,10 @@ InitializeApicTimer (
if (DivideValue != 0) {
ASSERT (DivideValue <= 128);
ASSERT (DivideValue == GetPowerOfTwo32((UINT32)DivideValue));
ASSERT (DivideValue == GetPowerOfTwo32 ((UINT32)DivideValue));
Divisor = (UINT32)((HighBitSet32 ((UINT32)DivideValue) - 1) & 0x7);
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Dcr.Bits.DivideValue1 = (Divisor & 0x3);
Dcr.Bits.DivideValue2 = (Divisor >> 2);
WriteLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET, Dcr.Uint32);
@@ -752,7 +753,8 @@ InitializeApicTimer (
} else {
LvtTimer.Bits.TimerMode = 0;
}
LvtTimer.Bits.Mask = 0;
LvtTimer.Bits.Mask = 0;
LvtTimer.Bits.Vector = Vector;
WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32);
}
@@ -774,25 +776,25 @@ GetApicTimerState (
OUT UINT8 *Vector OPTIONAL
)
{
UINT32 Divisor;
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
UINT32 Divisor;
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
//
// Check the APIC Software Enable/Disable bit (bit 8) in Spurious-Interrupt
// Vector Register.
// This bit will be 1, if local APIC is software enabled.
//
ASSERT ((ReadLocalApicReg(XAPIC_SPURIOUS_VECTOR_OFFSET) & BIT8) != 0);
ASSERT ((ReadLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET) & BIT8) != 0);
if (DivideValue != NULL) {
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Divisor = Dcr.Bits.DivideValue1 | (Dcr.Bits.DivideValue2 << 2);
Divisor = (Divisor + 1) & 0x7;
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Divisor = Dcr.Bits.DivideValue1 | (Dcr.Bits.DivideValue2 << 2);
Divisor = (Divisor + 1) & 0x7;
*DivideValue = ((UINTN)1) << Divisor;
}
if (PeriodicMode != NULL || Vector != NULL) {
if ((PeriodicMode != NULL) || (Vector != NULL)) {
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
if (PeriodicMode != NULL) {
if (LvtTimer.Bits.TimerMode == 1) {
@@ -801,8 +803,9 @@ GetApicTimerState (
*PeriodicMode = FALSE;
}
}
if (Vector != NULL) {
*Vector = (UINT8) LvtTimer.Bits.Vector;
*Vector = (UINT8)LvtTimer.Bits.Vector;
}
}
}
@@ -816,9 +819,9 @@ EnableApicTimerInterrupt (
VOID
)
{
LOCAL_APIC_LVT_TIMER LvtTimer;
LOCAL_APIC_LVT_TIMER LvtTimer;
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Bits.Mask = 0;
WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32);
}
@@ -832,9 +835,9 @@ DisableApicTimerInterrupt (
VOID
)
{
LOCAL_APIC_LVT_TIMER LvtTimer;
LOCAL_APIC_LVT_TIMER LvtTimer;
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Bits.Mask = 1;
WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32);
}
@@ -851,7 +854,7 @@ GetApicTimerInterruptState (
VOID
)
{
LOCAL_APIC_LVT_TIMER LvtTimer;
LOCAL_APIC_LVT_TIMER LvtTimer;
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
return (BOOLEAN)(LvtTimer.Bits.Mask == 0);
@@ -944,6 +947,7 @@ GetApicMsiValue (
MsiData.Bits.Level = 1;
}
}
return MsiData.Uint64;
}
@@ -995,12 +999,15 @@ GetProcessorLocationByApicId (
if (Thread != NULL) {
*Thread = 0;
}
if (Core != NULL) {
*Core = 0;
}
if (Package != NULL) {
*Package = 0;
}
return;
}
@@ -1008,7 +1015,7 @@ GetProcessorLocationByApicId (
// Assume three-level mapping of APIC ID: Package|Core|Thread.
//
ThreadBits = 0;
CoreBits = 0;
CoreBits = 0;
//
// Get max index of CPUID
@@ -1022,7 +1029,7 @@ GetProcessorLocationByApicId (
//
TopologyLeafSupported = FALSE;
if (MaxStandardCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
AsmCpuidEx(
AsmCpuidEx (
CPUID_EXTENDED_TOPOLOGY,
0,
&ExtendedTopologyEax.Uint32,
@@ -1065,6 +1072,7 @@ GetProcessorLocationByApicId (
CoreBits = ExtendedTopologyEax.Bits.ApicIdShift - ThreadBits;
break;
}
SubIndex++;
} while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID);
}
@@ -1085,7 +1093,7 @@ GetProcessorLocationByApicId (
//
// Check for topology extensions on AMD processor
//
if (StandardSignatureIsAuthenticAMD()) {
if (StandardSignatureIsAuthenticAMD ()) {
if (MaxExtendedCpuIdIndex >= CPUID_AMD_PROCESSOR_TOPOLOGY) {
AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, &AmdExtendedCpuSigEcx.Uint32, NULL);
if (AmdExtendedCpuSigEcx.Bits.TopologyExtensions != 0) {
@@ -1102,8 +1110,7 @@ GetProcessorLocationByApicId (
MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.Bits.ThreadsPerCore + 1);
}
}
}
else {
} else {
//
// Extract core count based on CACHE information
//
@@ -1115,16 +1122,18 @@ GetProcessorLocationByApicId (
}
}
ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1);
CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1);
ThreadBits = (UINTN)(HighBitSet32 (MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1);
CoreBits = (UINTN)(HighBitSet32 (MaxCoresPerPackage - 1) + 1);
}
if (Thread != NULL) {
*Thread = InitialApicId & ((1 << ThreadBits) - 1);
}
if (Core != NULL) {
*Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1);
}
if (Package != NULL) {
*Package = (InitialApicId >> (ThreadBits + CoreBits));
}
@@ -1158,13 +1167,13 @@ GetProcessorLocation2ByApicId (
OUT UINT32 *Thread OPTIONAL
)
{
CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax;
CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx;
UINT32 MaxStandardCpuIdIndex;
UINT32 Index;
UINTN LevelType;
UINT32 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
UINT32 *Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax;
CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx;
UINT32 MaxStandardCpuIdIndex;
UINT32 Index;
UINTN LevelType;
UINT32 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
UINT32 *Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
for (LevelType = 0; LevelType < ARRAY_SIZE (Bits); LevelType++) {
Bits[LevelType] = 0;
@@ -1178,12 +1187,15 @@ GetProcessorLocation2ByApicId (
if (Die != NULL) {
*Die = 0;
}
if (Tile != NULL) {
*Tile = 0;
}
if (Module != NULL) {
*Module = 0;
}
GetProcessorLocationByApicId (InitialApicId, Package, Core, Thread);
return;
}
@@ -1193,7 +1205,7 @@ GetProcessorLocation2ByApicId (
// is the preferred mechanism for enumerating topology.
//
for (Index = 0; ; Index++) {
AsmCpuidEx(
AsmCpuidEx (
CPUID_V2_EXTENDED_TOPOLOGY,
Index,
&ExtendedTopologyEax.Uint32,
@@ -1211,6 +1223,7 @@ GetProcessorLocation2ByApicId (
if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID) {
break;
}
ASSERT (LevelType < ARRAY_SIZE (Bits));
Bits[LevelType] = ExtendedTopologyEax.Bits.ApicIdShift;
}
@@ -1226,18 +1239,19 @@ GetProcessorLocation2ByApicId (
}
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1] = Package;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE ] = Die;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE ] = Tile;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_MODULE ] = Module;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE ] = Core;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT ] = Thread;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE] = Die;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE] = Tile;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_MODULE] = Module;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE] = Core;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT] = Thread;
Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1] = 32;
for ( LevelType = CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT
; LevelType <= CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1
; LevelType ++
) {
; LevelType <= CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1
; LevelType++
)
{
if (Location[LevelType] != NULL) {
//
// Bits[i] holds the number of bits to shift right on x2APIC ID to get a unique

View File

@@ -45,13 +45,14 @@ LocalApicBaseAddressMsrSupported (
AsmCpuid (1, &RegEax, NULL, NULL, NULL);
FamilyId = BitFieldRead32 (RegEax, 8, 11);
if (FamilyId == 0x04 || FamilyId == 0x05) {
if ((FamilyId == 0x04) || (FamilyId == 0x05)) {
//
// CPUs with a FamilyId of 0x04 or 0x05 do not support the
// Local APIC Base Address MSR
//
return FALSE;
}
return TRUE;
}
@@ -79,8 +80,8 @@ GetLocalApicBaseAddress (
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
return (UINTN)(LShiftU64 ((UINT64) ApicBaseMsr.Bits.ApicBaseHi, 32)) +
(((UINTN)ApicBaseMsr.Bits.ApicBase) << 12);
return (UINTN)(LShiftU64 ((UINT64)ApicBaseMsr.Bits.ApicBaseHi, 32)) +
(((UINTN)ApicBaseMsr.Bits.ApicBase) << 12);
}
/**
@@ -94,7 +95,7 @@ GetLocalApicBaseAddress (
VOID
EFIAPI
SetLocalApicBaseAddress (
IN UINTN BaseAddress
IN UINTN BaseAddress
)
{
MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
@@ -110,8 +111,8 @@ SetLocalApicBaseAddress (
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
ApicBaseMsr.Bits.ApicBase = (UINT32) (BaseAddress >> 12);
ApicBaseMsr.Bits.ApicBaseHi = (UINT32) (RShiftU64((UINT64) BaseAddress, 32));
ApicBaseMsr.Bits.ApicBase = (UINT32)(BaseAddress >> 12);
ApicBaseMsr.Bits.ApicBaseHi = (UINT32)(RShiftU64 ((UINT64)BaseAddress, 32));
AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
}
@@ -135,12 +136,12 @@ ReadLocalApicReg (
IN UINTN MmioOffset
)
{
UINT32 MsrIndex;
UINT32 MsrIndex;
ASSERT ((MmioOffset & 0xf) == 0);
if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {
return MmioRead32 (GetLocalApicBaseAddress() + MmioOffset);
return MmioRead32 (GetLocalApicBaseAddress () + MmioOffset);
} else {
//
// DFR is not supported in x2APIC mode.
@@ -174,16 +175,16 @@ ReadLocalApicReg (
VOID
EFIAPI
WriteLocalApicReg (
IN UINTN MmioOffset,
IN UINT32 Value
IN UINTN MmioOffset,
IN UINT32 Value
)
{
UINT32 MsrIndex;
UINT32 MsrIndex;
ASSERT ((MmioOffset & 0xf) == 0);
if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {
MmioWrite32 (GetLocalApicBaseAddress() + MmioOffset, Value);
MmioWrite32 (GetLocalApicBaseAddress () + MmioOffset, Value);
} else {
//
// DFR is not supported in x2APIC mode.
@@ -216,15 +217,15 @@ WriteLocalApicReg (
**/
VOID
SendIpi (
IN UINT32 IcrLow,
IN UINT32 ApicId
IN UINT32 IcrLow,
IN UINT32 ApicId
)
{
UINT64 MsrValue;
LOCAL_APIC_ICR_LOW IcrLowReg;
UINTN LocalApciBaseAddress;
UINT32 IcrHigh;
BOOLEAN InterruptState;
UINT64 MsrValue;
LOCAL_APIC_ICR_LOW IcrLowReg;
UINTN LocalApciBaseAddress;
UINT32 IcrHigh;
BOOLEAN InterruptState;
//
// Legacy APIC or X2APIC?
@@ -237,7 +238,7 @@ SendIpi (
//
// Get base address of this LAPIC
//
LocalApciBaseAddress = GetLocalApicBaseAddress();
LocalApciBaseAddress = GetLocalApicBaseAddress ();
//
// Save existing contents of ICR high 32 bits
@@ -271,13 +272,12 @@ SendIpi (
MmioWrite32 (LocalApciBaseAddress + XAPIC_ICR_HIGH_OFFSET, IcrHigh);
SetInterruptState (InterruptState);
} else {
//
// For x2APIC, A single MSR write to the Interrupt Command Register is required for dispatching an
// interrupt in x2APIC mode.
//
MsrValue = LShiftU64 ((UINT64) ApicId, 32) | IcrLow;
MsrValue = LShiftU64 ((UINT64)ApicId, 32) | IcrLow;
AsmWriteMsr64 (X2APIC_MSR_ICR_ADDRESS, MsrValue);
}
}
@@ -354,7 +354,7 @@ SetApicMode (
case LOCAL_APIC_MODE_XAPIC:
break;
case LOCAL_APIC_MODE_X2APIC:
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
ApicBaseMsr.Bits.EXTD = 1;
AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
break;
@@ -368,9 +368,9 @@ SetApicMode (
// Transition from x2APIC mode to xAPIC mode is a two-step process:
// x2APIC -> Local APIC disabled -> xAPIC
//
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
ApicBaseMsr.Bits.EXTD = 0;
ApicBaseMsr.Bits.EN = 0;
ApicBaseMsr.Bits.EN = 0;
AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
ApicBaseMsr.Bits.EN = 1;
AsmWriteMsr64 (MSR_IA32_APIC_BASE, ApicBaseMsr.Uint64);
@@ -398,9 +398,9 @@ GetInitialApicId (
VOID
)
{
UINT32 ApicId;
UINT32 MaxCpuIdIndex;
UINT32 RegEbx;
UINT32 ApicId;
UINT32 MaxCpuIdIndex;
UINT32 RegEbx;
if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {
//
@@ -419,6 +419,7 @@ GetInitialApicId (
return ApicId;
}
}
AsmCpuid (CPUID_VERSION_INFO, NULL, &RegEbx, NULL, NULL);
return RegEbx >> 24;
} else {
@@ -437,8 +438,8 @@ GetApicId (
VOID
)
{
UINT32 ApicId;
UINT32 InitApicId;
UINT32 ApicId;
UINT32 InitApicId;
ApicId = ReadLocalApicReg (XAPIC_ID_OFFSET);
if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {
@@ -473,16 +474,16 @@ GetApicVersion (
VOID
EFIAPI
SendFixedIpi (
IN UINT32 ApicId,
IN UINT8 Vector
IN UINT32 ApicId,
IN UINT8 Vector
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Vector = Vector;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Vector = Vector;
SendIpi (IcrLow.Uint32, ApicId);
}
@@ -496,16 +497,16 @@ SendFixedIpi (
VOID
EFIAPI
SendFixedIpiAllExcludingSelf (
IN UINT8 Vector
IN UINT8 Vector
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
IcrLow.Bits.Level = 1;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
IcrLow.Bits.Vector = Vector;
IcrLow.Bits.Vector = Vector;
SendIpi (IcrLow.Uint32, 0);
}
@@ -519,14 +520,14 @@ SendFixedIpiAllExcludingSelf (
VOID
EFIAPI
SendSmiIpi (
IN UINT32 ApicId
IN UINT32 ApicId
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Level = 1;
SendIpi (IcrLow.Uint32, ApicId);
}
@@ -541,11 +542,11 @@ SendSmiIpiAllExcludingSelf (
VOID
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
IcrLow.Bits.Level = 1;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
SendIpi (IcrLow.Uint32, 0);
}
@@ -560,14 +561,14 @@ SendSmiIpiAllExcludingSelf (
VOID
EFIAPI
SendInitIpi (
IN UINT32 ApicId
IN UINT32 ApicId
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Level = 1;
SendIpi (IcrLow.Uint32, ApicId);
}
@@ -582,11 +583,11 @@ SendInitIpiAllExcludingSelf (
VOID
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
IcrLow.Bits.Level = 1;
IcrLow.Uint32 = 0;
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
SendIpi (IcrLow.Uint32, 0);
}
@@ -606,21 +607,21 @@ SendInitIpiAllExcludingSelf (
VOID
EFIAPI
SendInitSipiSipi (
IN UINT32 ApicId,
IN UINT32 StartupRoutine
IN UINT32 ApicId,
IN UINT32 StartupRoutine
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
ASSERT (StartupRoutine < 0x100000);
ASSERT ((StartupRoutine & 0xfff) == 0);
SendInitIpi (ApicId);
MicroSecondDelay (PcdGet32(PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
IcrLow.Bits.Level = 1;
IcrLow.Bits.Level = 1;
SendIpi (IcrLow.Uint32, ApicId);
if (!StandardSignatureIsAuthenticAMD ()) {
MicroSecondDelay (200);
@@ -642,20 +643,20 @@ SendInitSipiSipi (
VOID
EFIAPI
SendInitSipiSipiAllExcludingSelf (
IN UINT32 StartupRoutine
IN UINT32 StartupRoutine
)
{
LOCAL_APIC_ICR_LOW IcrLow;
LOCAL_APIC_ICR_LOW IcrLow;
ASSERT (StartupRoutine < 0x100000);
ASSERT ((StartupRoutine & 0xfff) == 0);
SendInitIpiAllExcludingSelf ();
MicroSecondDelay (PcdGet32(PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
IcrLow.Bits.Level = 1;
MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
IcrLow.Uint32 = 0;
IcrLow.Bits.Vector = (StartupRoutine >> 12);
IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
IcrLow.Bits.Level = 1;
IcrLow.Bits.DestinationShorthand = LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF;
SendIpi (IcrLow.Uint32, 0);
if (!StandardSignatureIsAuthenticAMD ()) {
@@ -711,13 +712,13 @@ ProgramVirtualWireMode (
VOID
)
{
LOCAL_APIC_SVR Svr;
LOCAL_APIC_LVT_LINT Lint;
LOCAL_APIC_SVR Svr;
LOCAL_APIC_LVT_LINT Lint;
//
// Enable the APIC via SVR and set the spurious interrupt to use Int 00F.
//
Svr.Uint32 = ReadLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET);
Svr.Uint32 = ReadLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET);
Svr.Bits.SpuriousVector = 0xf;
Svr.Bits.SoftwareEnable = 1;
WriteLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET, Svr.Uint32);
@@ -725,21 +726,21 @@ ProgramVirtualWireMode (
//
// Program the LINT0 vector entry as ExtInt. Not masked, edge, active high.
//
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_EXTINT;
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_EXTINT;
Lint.Bits.InputPinPolarity = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
WriteLocalApicReg (XAPIC_LVT_LINT0_OFFSET, Lint.Uint32);
//
// Program the LINT0 vector entry as NMI. Not masked, edge, active high.
//
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_NMI;
Lint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
Lint.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_NMI;
Lint.Bits.InputPinPolarity = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
Lint.Bits.TriggerMode = 0;
Lint.Bits.Mask = 0;
WriteLocalApicReg (XAPIC_LVT_LINT1_OFFSET, Lint.Uint32);
}
@@ -754,13 +755,13 @@ DisableLvtInterrupts (
VOID
)
{
LOCAL_APIC_LVT_LINT LvtLint;
LOCAL_APIC_LVT_LINT LvtLint;
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT0_OFFSET);
LvtLint.Bits.Mask = 1;
WriteLocalApicReg (XAPIC_LVT_LINT0_OFFSET, LvtLint.Uint32);
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
LvtLint.Uint32 = ReadLocalApicReg (XAPIC_LVT_LINT1_OFFSET);
LvtLint.Bits.Mask = 1;
WriteLocalApicReg (XAPIC_LVT_LINT1_OFFSET, LvtLint.Uint32);
}
@@ -807,15 +808,15 @@ GetApicTimerCurrentCount (
VOID
EFIAPI
InitializeApicTimer (
IN UINTN DivideValue,
IN UINT32 InitCount,
IN BOOLEAN PeriodicMode,
IN UINT8 Vector
IN UINTN DivideValue,
IN UINT32 InitCount,
IN BOOLEAN PeriodicMode,
IN UINT8 Vector
)
{
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
UINT32 Divisor;
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
UINT32 Divisor;
//
// Ensure local APIC is in software-enabled state.
@@ -829,10 +830,10 @@ InitializeApicTimer (
if (DivideValue != 0) {
ASSERT (DivideValue <= 128);
ASSERT (DivideValue == GetPowerOfTwo32((UINT32)DivideValue));
ASSERT (DivideValue == GetPowerOfTwo32 ((UINT32)DivideValue));
Divisor = (UINT32)((HighBitSet32 ((UINT32)DivideValue) - 1) & 0x7);
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Dcr.Bits.DivideValue1 = (Divisor & 0x3);
Dcr.Bits.DivideValue2 = (Divisor >> 2);
WriteLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET, Dcr.Uint32);
@@ -847,7 +848,8 @@ InitializeApicTimer (
} else {
LvtTimer.Bits.TimerMode = 0;
}
LvtTimer.Bits.Mask = 0;
LvtTimer.Bits.Mask = 0;
LvtTimer.Bits.Vector = Vector;
WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32);
}
@@ -869,25 +871,25 @@ GetApicTimerState (
OUT UINT8 *Vector OPTIONAL
)
{
UINT32 Divisor;
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
UINT32 Divisor;
LOCAL_APIC_DCR Dcr;
LOCAL_APIC_LVT_TIMER LvtTimer;
//
// Check the APIC Software Enable/Disable bit (bit 8) in Spurious-Interrupt
// Vector Register.
// This bit will be 1, if local APIC is software enabled.
//
ASSERT ((ReadLocalApicReg(XAPIC_SPURIOUS_VECTOR_OFFSET) & BIT8) != 0);
ASSERT ((ReadLocalApicReg (XAPIC_SPURIOUS_VECTOR_OFFSET) & BIT8) != 0);
if (DivideValue != NULL) {
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Divisor = Dcr.Bits.DivideValue1 | (Dcr.Bits.DivideValue2 << 2);
Divisor = (Divisor + 1) & 0x7;
Dcr.Uint32 = ReadLocalApicReg (XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET);
Divisor = Dcr.Bits.DivideValue1 | (Dcr.Bits.DivideValue2 << 2);
Divisor = (Divisor + 1) & 0x7;
*DivideValue = ((UINTN)1) << Divisor;
}
if (PeriodicMode != NULL || Vector != NULL) {
if ((PeriodicMode != NULL) || (Vector != NULL)) {
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
if (PeriodicMode != NULL) {
if (LvtTimer.Bits.TimerMode == 1) {
@@ -896,8 +898,9 @@ GetApicTimerState (
*PeriodicMode = FALSE;
}
}
if (Vector != NULL) {
*Vector = (UINT8) LvtTimer.Bits.Vector;
*Vector = (UINT8)LvtTimer.Bits.Vector;
}
}
}
@@ -911,9 +914,9 @@ EnableApicTimerInterrupt (
VOID
)
{
LOCAL_APIC_LVT_TIMER LvtTimer;
LOCAL_APIC_LVT_TIMER LvtTimer;
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Bits.Mask = 0;
WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32);
}
@@ -927,9 +930,9 @@ DisableApicTimerInterrupt (
VOID
)
{
LOCAL_APIC_LVT_TIMER LvtTimer;
LOCAL_APIC_LVT_TIMER LvtTimer;
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
LvtTimer.Bits.Mask = 1;
WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32);
}
@@ -946,7 +949,7 @@ GetApicTimerInterruptState (
VOID
)
{
LOCAL_APIC_LVT_TIMER LvtTimer;
LOCAL_APIC_LVT_TIMER LvtTimer;
LvtTimer.Uint32 = ReadLocalApicReg (XAPIC_LVT_TIMER_OFFSET);
return (BOOLEAN)(LvtTimer.Bits.Mask == 0);
@@ -1039,6 +1042,7 @@ GetApicMsiValue (
MsiData.Bits.Level = 1;
}
}
return MsiData.Uint64;
}
@@ -1090,12 +1094,15 @@ GetProcessorLocationByApicId (
if (Thread != NULL) {
*Thread = 0;
}
if (Core != NULL) {
*Core = 0;
}
if (Package != NULL) {
*Package = 0;
}
return;
}
@@ -1103,7 +1110,7 @@ GetProcessorLocationByApicId (
// Assume three-level mapping of APIC ID: Package|Core|Thread.
//
ThreadBits = 0;
CoreBits = 0;
CoreBits = 0;
//
// Get max index of CPUID
@@ -1117,7 +1124,7 @@ GetProcessorLocationByApicId (
//
TopologyLeafSupported = FALSE;
if (MaxStandardCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
AsmCpuidEx(
AsmCpuidEx (
CPUID_EXTENDED_TOPOLOGY,
0,
&ExtendedTopologyEax.Uint32,
@@ -1160,6 +1167,7 @@ GetProcessorLocationByApicId (
CoreBits = ExtendedTopologyEax.Bits.ApicIdShift - ThreadBits;
break;
}
SubIndex++;
} while (LevelType != CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID);
}
@@ -1180,7 +1188,7 @@ GetProcessorLocationByApicId (
//
// Check for topology extensions on AMD processor
//
if (StandardSignatureIsAuthenticAMD()) {
if (StandardSignatureIsAuthenticAMD ()) {
if (MaxExtendedCpuIdIndex >= CPUID_AMD_PROCESSOR_TOPOLOGY) {
AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, &AmdExtendedCpuSigEcx.Uint32, NULL);
if (AmdExtendedCpuSigEcx.Bits.TopologyExtensions != 0) {
@@ -1197,8 +1205,7 @@ GetProcessorLocationByApicId (
MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.Bits.ThreadsPerCore + 1);
}
}
}
else {
} else {
//
// Extract core count based on CACHE information
//
@@ -1210,16 +1217,18 @@ GetProcessorLocationByApicId (
}
}
ThreadBits = (UINTN)(HighBitSet32(MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1);
CoreBits = (UINTN)(HighBitSet32(MaxCoresPerPackage - 1) + 1);
ThreadBits = (UINTN)(HighBitSet32 (MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1);
CoreBits = (UINTN)(HighBitSet32 (MaxCoresPerPackage - 1) + 1);
}
if (Thread != NULL) {
*Thread = InitialApicId & ((1 << ThreadBits) - 1);
}
if (Core != NULL) {
*Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1);
}
if (Package != NULL) {
*Package = (InitialApicId >> (ThreadBits + CoreBits));
}
@@ -1253,13 +1262,13 @@ GetProcessorLocation2ByApicId (
OUT UINT32 *Thread OPTIONAL
)
{
CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax;
CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx;
UINT32 MaxStandardCpuIdIndex;
UINT32 Index;
UINTN LevelType;
UINT32 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
UINT32 *Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax;
CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx;
UINT32 MaxStandardCpuIdIndex;
UINT32 Index;
UINTN LevelType;
UINT32 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
UINT32 *Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
for (LevelType = 0; LevelType < ARRAY_SIZE (Bits); LevelType++) {
Bits[LevelType] = 0;
@@ -1273,12 +1282,15 @@ GetProcessorLocation2ByApicId (
if (Die != NULL) {
*Die = 0;
}
if (Tile != NULL) {
*Tile = 0;
}
if (Module != NULL) {
*Module = 0;
}
GetProcessorLocationByApicId (InitialApicId, Package, Core, Thread);
return;
}
@@ -1288,7 +1300,7 @@ GetProcessorLocation2ByApicId (
// is the preferred mechanism for enumerating topology.
//
for (Index = 0; ; Index++) {
AsmCpuidEx(
AsmCpuidEx (
CPUID_V2_EXTENDED_TOPOLOGY,
Index,
&ExtendedTopologyEax.Uint32,
@@ -1306,6 +1318,7 @@ GetProcessorLocation2ByApicId (
if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID) {
break;
}
ASSERT (LevelType < ARRAY_SIZE (Bits));
Bits[LevelType] = ExtendedTopologyEax.Bits.ApicIdShift;
}
@@ -1321,18 +1334,19 @@ GetProcessorLocation2ByApicId (
}
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1] = Package;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE ] = Die;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE ] = Tile;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_MODULE ] = Module;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE ] = Core;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT ] = Thread;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE] = Die;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE] = Tile;
Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_MODULE] = Module;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE] = Core;
Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT] = Thread;
Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1] = 32;
for ( LevelType = CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT
; LevelType <= CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1
; LevelType ++
) {
; LevelType <= CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1
; LevelType++
)
{
if (Location[LevelType] != NULL) {
//
// Bits[i] holds the number of bits to shift right on x2APIC ID to get a unique

View File

@@ -17,21 +17,31 @@
**/
VOID
CpuCacheInfoPrintCpuCacheInfoTable (
IN CPU_CACHE_INFO *CpuCacheInfo,
IN UINTN CpuCacheInfoCount
IN CPU_CACHE_INFO *CpuCacheInfo,
IN UINTN CpuCacheInfoCount
)
{
UINTN Index;
UINTN Index;
DEBUG ((DEBUG_INFO, "+-------+--------------------------------------------------------------------------------------+\n"));
DEBUG ((DEBUG_INFO, "| Index | Packge CoreType CacheLevel CacheType CacheWays (FA|DM) CacheSizeinKB CacheCount |\n"));
DEBUG ((DEBUG_INFO, "+-------+--------------------------------------------------------------------------------------+\n"));
for (Index = 0; Index < CpuCacheInfoCount; Index++) {
DEBUG ((DEBUG_INFO, "| %4x | %4x %2x %2x %2x %4x ( %x| %x) %8x %4x |\n",
Index, CpuCacheInfo[Index].Package, CpuCacheInfo[Index].CoreType, CpuCacheInfo[Index].CacheLevel,
CpuCacheInfo[Index].CacheType, CpuCacheInfo[Index].CacheWays, CpuCacheInfo[Index].FullyAssociativeCache,
CpuCacheInfo[Index].DirectMappedCache, CpuCacheInfo[Index].CacheSizeinKB, CpuCacheInfo[Index].CacheCount));
DEBUG ((
DEBUG_INFO,
"| %4x | %4x %2x %2x %2x %4x ( %x| %x) %8x %4x |\n",
Index,
CpuCacheInfo[Index].Package,
CpuCacheInfo[Index].CoreType,
CpuCacheInfo[Index].CacheLevel,
CpuCacheInfo[Index].CacheType,
CpuCacheInfo[Index].CacheWays,
CpuCacheInfo[Index].FullyAssociativeCache,
CpuCacheInfo[Index].DirectMappedCache,
CpuCacheInfo[Index].CacheSizeinKB,
CpuCacheInfo[Index].CacheCount
));
}
DEBUG ((DEBUG_INFO, "+-------+--------------------------------------------------------------------------------------+\n"));
@@ -50,24 +60,24 @@ CpuCacheInfoPrintCpuCacheInfoTable (
INTN
EFIAPI
CpuCacheInfoCompare (
IN CONST VOID *Buffer1,
IN CONST VOID *Buffer2
IN CONST VOID *Buffer1,
IN CONST VOID *Buffer2
)
{
CPU_CACHE_INFO_COMPARATOR Comparator1, Comparator2;
CPU_CACHE_INFO_COMPARATOR Comparator1, Comparator2;
ZeroMem (&Comparator1, sizeof (Comparator1));
ZeroMem (&Comparator2, sizeof (Comparator2));
Comparator1.Bits.Package = ((CPU_CACHE_INFO*)Buffer1)->Package;
Comparator1.Bits.CoreType = ((CPU_CACHE_INFO*)Buffer1)->CoreType;
Comparator1.Bits.CacheLevel = ((CPU_CACHE_INFO*)Buffer1)->CacheLevel;
Comparator1.Bits.CacheType = ((CPU_CACHE_INFO*)Buffer1)->CacheType;
Comparator1.Bits.Package = ((CPU_CACHE_INFO *)Buffer1)->Package;
Comparator1.Bits.CoreType = ((CPU_CACHE_INFO *)Buffer1)->CoreType;
Comparator1.Bits.CacheLevel = ((CPU_CACHE_INFO *)Buffer1)->CacheLevel;
Comparator1.Bits.CacheType = ((CPU_CACHE_INFO *)Buffer1)->CacheType;
Comparator2.Bits.Package = ((CPU_CACHE_INFO*)Buffer2)->Package;
Comparator2.Bits.CoreType = ((CPU_CACHE_INFO*)Buffer2)->CoreType;
Comparator2.Bits.CacheLevel = ((CPU_CACHE_INFO*)Buffer2)->CacheLevel;
Comparator2.Bits.CacheType = ((CPU_CACHE_INFO*)Buffer2)->CacheType;
Comparator2.Bits.Package = ((CPU_CACHE_INFO *)Buffer2)->Package;
Comparator2.Bits.CoreType = ((CPU_CACHE_INFO *)Buffer2)->CoreType;
Comparator2.Bits.CacheLevel = ((CPU_CACHE_INFO *)Buffer2)->CacheLevel;
Comparator2.Bits.CacheType = ((CPU_CACHE_INFO *)Buffer2)->CacheType;
if (Comparator1.Uint64 == Comparator2.Uint64) {
return 0;
@@ -89,15 +99,15 @@ CpuCacheInfoCompare (
**/
UINT32
CpuCacheInfoGetNumberOfPackages (
IN CPUID_PROCESSOR_INFO *ProcessorInfo,
IN UINTN NumberOfProcessors,
IN OUT UINT32 *Package
IN CPUID_PROCESSOR_INFO *ProcessorInfo,
IN UINTN NumberOfProcessors,
IN OUT UINT32 *Package
)
{
UINTN ProcessorIndex;
UINT32 PackageIndex;
UINT32 PackageCount;
UINT32 CurrentPackage;
UINTN ProcessorIndex;
UINT32 PackageIndex;
UINT32 PackageCount;
UINT32 CurrentPackage;
PackageCount = 0;
@@ -135,21 +145,21 @@ CpuCacheInfoGetNumberOfPackages (
@retval Return the number of CoreType of requested package.
**/
UINTN
CpuCacheInfoGetNumberOfCoreTypePerPackage(
IN CPUID_PROCESSOR_INFO *ProcessorInfo,
IN UINTN NumberOfProcessors,
IN UINTN Package
CpuCacheInfoGetNumberOfCoreTypePerPackage (
IN CPUID_PROCESSOR_INFO *ProcessorInfo,
IN UINTN NumberOfProcessors,
IN UINTN Package
)
{
UINTN ProcessorIndex;
UINTN ProcessorIndex;
//
// Core Type value comes from CPUID.1Ah.EAX[31:24].
// So max number of core types should be MAX_UINT8.
//
UINT8 CoreType[MAX_UINT8];
UINTN CoreTypeIndex;
UINTN CoreTypeCount;
UINT8 CurrentCoreType;
UINT8 CoreType[MAX_UINT8];
UINTN CoreTypeIndex;
UINTN CoreTypeCount;
UINT8 CurrentCoreType;
//
// CoreType array is empty.
@@ -192,23 +202,23 @@ CpuCacheInfoGetNumberOfCoreTypePerPackage(
VOID
EFIAPI
CpuCacheInfoCollectCoreAndCacheData (
IN OUT VOID *Buffer
IN OUT VOID *Buffer
)
{
UINTN ProcessorIndex;
UINT32 CpuidMaxInput;
UINT8 CacheParamLeafIndex;
CPUID_CACHE_PARAMS_EAX CacheParamEax;
CPUID_CACHE_PARAMS_EBX CacheParamEbx;
UINT32 CacheParamEcx;
CPUID_CACHE_PARAMS_EDX CacheParamEdx;
CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX NativeModelIdAndCoreTypeEax;
COLLECT_CPUID_CACHE_DATA_CONTEXT *Context;
CPUID_CACHE_DATA *CacheData;
UINTN ProcessorIndex;
UINT32 CpuidMaxInput;
UINT8 CacheParamLeafIndex;
CPUID_CACHE_PARAMS_EAX CacheParamEax;
CPUID_CACHE_PARAMS_EBX CacheParamEbx;
UINT32 CacheParamEcx;
CPUID_CACHE_PARAMS_EDX CacheParamEdx;
CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX NativeModelIdAndCoreTypeEax;
COLLECT_CPUID_CACHE_DATA_CONTEXT *Context;
CPUID_CACHE_DATA *CacheData;
Context = (COLLECT_CPUID_CACHE_DATA_CONTEXT *)Buffer;
Context = (COLLECT_CPUID_CACHE_DATA_CONTEXT *)Buffer;
ProcessorIndex = CpuCacheInfoWhoAmI (Context->MpServices);
CacheData = &Context->CacheData[MAX_NUM_OF_CACHE_PARAMS_LEAF * ProcessorIndex];
CacheData = &Context->CacheData[MAX_NUM_OF_CACHE_PARAMS_LEAF * ProcessorIndex];
AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);
@@ -218,7 +228,7 @@ CpuCacheInfoCollectCoreAndCacheData (
Context->ProcessorInfo[ProcessorIndex].CoreType = 0;
if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
Context->ProcessorInfo[ProcessorIndex].CoreType = (UINT8) NativeModelIdAndCoreTypeEax.Bits.CoreType;
Context->ProcessorInfo[ProcessorIndex].CoreType = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
}
//
@@ -240,7 +250,7 @@ CpuCacheInfoCollectCoreAndCacheData (
CacheData[CacheParamLeafIndex].DirectMappedCache = (UINT8)(CacheParamEdx.Bits.ComplexCacheIndexing == 0);
CacheData[CacheParamLeafIndex].CacheShareBits = (UINT16)CacheParamEax.Bits.MaximumAddressableIdsForLogicalProcessors;
CacheData[CacheParamLeafIndex].CacheSizeinKB = (CacheParamEbx.Bits.Ways + 1) *
(CacheParamEbx.Bits.LinePartitions + 1) * (CacheParamEbx.Bits.LineSize + 1) * (CacheParamEcx + 1) / SIZE_1KB;
(CacheParamEbx.Bits.LinePartitions + 1) * (CacheParamEbx.Bits.LineSize + 1) * (CacheParamEcx + 1) / SIZE_1KB;
CacheParamLeafIndex++;
}
@@ -264,25 +274,25 @@ CpuCacheInfoCollectCoreAndCacheData (
**/
EFI_STATUS
CpuCacheInfoCollectCpuCacheInfoData (
IN CPUID_CACHE_DATA *CacheData,
IN CPUID_PROCESSOR_INFO *ProcessorInfo,
IN UINTN NumberOfProcessors,
IN OUT CPU_CACHE_INFO *CacheInfo,
IN OUT UINTN *CacheInfoCount
IN CPUID_CACHE_DATA *CacheData,
IN CPUID_PROCESSOR_INFO *ProcessorInfo,
IN UINTN NumberOfProcessors,
IN OUT CPU_CACHE_INFO *CacheInfo,
IN OUT UINTN *CacheInfoCount
)
{
EFI_STATUS Status;
UINT32 NumberOfPackage;
UINT32 Package[MAX_NUM_OF_PACKAGE];
UINTN PackageIndex;
UINTN TotalNumberOfCoreType;
UINTN MaxCacheInfoCount;
CPU_CACHE_INFO *LocalCacheInfo;
UINTN CacheInfoIndex;
UINTN LocalCacheInfoCount;
UINTN Index;
UINTN NextIndex;
CPU_CACHE_INFO SortBuffer;
EFI_STATUS Status;
UINT32 NumberOfPackage;
UINT32 Package[MAX_NUM_OF_PACKAGE];
UINTN PackageIndex;
UINTN TotalNumberOfCoreType;
UINTN MaxCacheInfoCount;
CPU_CACHE_INFO *LocalCacheInfo;
UINTN CacheInfoIndex;
UINTN LocalCacheInfoCount;
UINTN Index;
UINTN NextIndex;
CPU_CACHE_INFO SortBuffer;
//
// Get number of Packages and Package ID.
@@ -299,7 +309,7 @@ CpuCacheInfoCollectCpuCacheInfoData (
}
MaxCacheInfoCount = TotalNumberOfCoreType * MAX_NUM_OF_CACHE_PARAMS_LEAF;
LocalCacheInfo = AllocatePages (EFI_SIZE_TO_PAGES (MaxCacheInfoCount * sizeof (*LocalCacheInfo)));
LocalCacheInfo = AllocatePages (EFI_SIZE_TO_PAGES (MaxCacheInfoCount * sizeof (*LocalCacheInfo)));
ASSERT (LocalCacheInfo != NULL);
if (LocalCacheInfo == NULL) {
return EFI_OUT_OF_RESOURCES;
@@ -320,12 +330,13 @@ CpuCacheInfoCollectCpuCacheInfoData (
continue;
}
if (CacheData[Index].CacheLevel == CacheData[NextIndex].CacheLevel &&
CacheData[Index].CacheType == CacheData[NextIndex].CacheType &&
ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package == ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package &&
ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType == ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType &&
(ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~CacheData[Index].CacheShareBits) ==
(ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~CacheData[NextIndex].CacheShareBits)) {
if ((CacheData[Index].CacheLevel == CacheData[NextIndex].CacheLevel) &&
(CacheData[Index].CacheType == CacheData[NextIndex].CacheType) &&
(ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package == ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package) &&
(ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType == ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType) &&
((ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~CacheData[Index].CacheShareBits) ==
(ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~CacheData[NextIndex].CacheShareBits)))
{
CacheData[NextIndex].CacheSizeinKB = 0; // uses the sharing cache
}
}
@@ -334,10 +345,11 @@ CpuCacheInfoCollectCpuCacheInfoData (
// For the cache that already exists in LocalCacheInfo, increase its CacheCount.
//
for (CacheInfoIndex = 0; CacheInfoIndex < LocalCacheInfoCount; CacheInfoIndex++) {
if (LocalCacheInfo[CacheInfoIndex].Package == ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package &&
LocalCacheInfo[CacheInfoIndex].CoreType == ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType &&
LocalCacheInfo[CacheInfoIndex].CacheLevel == CacheData[Index].CacheLevel &&
LocalCacheInfo[CacheInfoIndex].CacheType == CacheData[Index].CacheType) {
if ((LocalCacheInfo[CacheInfoIndex].Package == ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package) &&
(LocalCacheInfo[CacheInfoIndex].CoreType == ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType) &&
(LocalCacheInfo[CacheInfoIndex].CacheLevel == CacheData[Index].CacheLevel) &&
(LocalCacheInfo[CacheInfoIndex].CacheType == CacheData[Index].CacheType))
{
LocalCacheInfo[CacheInfoIndex].CacheCount++;
break;
}
@@ -370,11 +382,11 @@ CpuCacheInfoCollectCpuCacheInfoData (
//
// Sort LocalCacheInfo array by CPU package ID, core type, cache level and cache type.
//
QuickSort (LocalCacheInfo, LocalCacheInfoCount, sizeof (*LocalCacheInfo), CpuCacheInfoCompare, (VOID*) &SortBuffer);
QuickSort (LocalCacheInfo, LocalCacheInfoCount, sizeof (*LocalCacheInfo), CpuCacheInfoCompare, (VOID *)&SortBuffer);
CopyMem (CacheInfo, LocalCacheInfo, sizeof (*CacheInfo) * LocalCacheInfoCount);
DEBUG_CODE (
CpuCacheInfoPrintCpuCacheInfoTable (CacheInfo, LocalCacheInfoCount);
);
);
Status = EFI_SUCCESS;
}
@@ -405,23 +417,23 @@ CpuCacheInfoCollectCpuCacheInfoData (
EFI_STATUS
EFIAPI
GetCpuCacheInfo (
IN OUT CPU_CACHE_INFO *CpuCacheInfo,
IN OUT UINTN *CpuCacheInfoCount
IN OUT CPU_CACHE_INFO *CpuCacheInfo,
IN OUT UINTN *CpuCacheInfoCount
)
{
EFI_STATUS Status;
UINT32 CpuidMaxInput;
UINT32 NumberOfProcessors;
UINTN CacheDataCount;
UINTN ProcessorIndex;
EFI_PROCESSOR_INFORMATION ProcessorInfo;
EFI_STATUS Status;
UINT32 CpuidMaxInput;
UINT32 NumberOfProcessors;
UINTN CacheDataCount;
UINTN ProcessorIndex;
EFI_PROCESSOR_INFORMATION ProcessorInfo;
COLLECT_CPUID_CACHE_DATA_CONTEXT Context;
if (CpuCacheInfoCount == NULL) {
return EFI_INVALID_PARAMETER;
}
if (*CpuCacheInfoCount != 0 && CpuCacheInfo == NULL) {
if ((*CpuCacheInfoCount != 0) && (CpuCacheInfo == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -445,13 +457,14 @@ GetCpuCacheInfo (
if (Context.ProcessorInfo == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Initialize COLLECT_CPUID_CACHE_DATA_CONTEXT.CacheData.
// CacheData array consists of CPUID_CACHE_DATA data structure for each Cpuid Cache Parameter Leaf
// per logical processor. The array begin with data of each Cache Parameter Leaf of processor 0, followed
// by data of each Cache Parameter Leaf of processor 1 ...
//
CacheDataCount = NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_LEAF;
CacheDataCount = NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_LEAF;
Context.CacheData = AllocatePages (EFI_SIZE_TO_PAGES (CacheDataCount * sizeof (*Context.CacheData)));
ASSERT (Context.CacheData != NULL);
if (Context.CacheData == NULL) {
@@ -467,7 +480,7 @@ GetCpuCacheInfo (
for (ProcessorIndex = 0; ProcessorIndex < NumberOfProcessors; ProcessorIndex++) {
CpuCacheInfoGetProcessorInfo (Context.MpServices, ProcessorIndex, &ProcessorInfo);
Context.ProcessorInfo[ProcessorIndex].Package = ProcessorInfo.Location.Package;
Context.ProcessorInfo[ProcessorIndex].ApicId = (UINT32) ProcessorInfo.ProcessorId;
Context.ProcessorInfo[ProcessorIndex].ApicId = (UINT32)ProcessorInfo.ProcessorId;
}
//

View File

@@ -23,10 +23,10 @@
**/
EFI_STATUS
CpuCacheInfoGetMpServices (
OUT MP_SERVICES *MpServices
OUT MP_SERVICES *MpServices
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices->Protocol);
ASSERT_EFI_ERROR (Status);
@@ -43,12 +43,12 @@ CpuCacheInfoGetMpServices (
**/
VOID
CpuCacheInfoStartupAllCPUs (
IN MP_SERVICES MpServices,
IN EFI_AP_PROCEDURE Procedure,
IN VOID *ProcedureArgument
IN MP_SERVICES MpServices,
IN EFI_AP_PROCEDURE Procedure,
IN VOID *ProcedureArgument
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Procedure, FALSE, NULL, 0, ProcedureArgument, NULL);
if (Status == EFI_NOT_STARTED) {
@@ -58,6 +58,7 @@ CpuCacheInfoStartupAllCPUs (
//
Status = EFI_SUCCESS;
}
ASSERT_EFI_ERROR (Status);
Procedure (ProcedureArgument);
@@ -72,12 +73,12 @@ CpuCacheInfoStartupAllCPUs (
**/
VOID
CpuCacheInfoGetProcessorInfo (
IN MP_SERVICES MpServices,
IN UINTN ProcessorNum,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
IN MP_SERVICES MpServices,
IN UINTN ProcessorNum,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MpServices.Protocol->GetProcessorInfo (MpServices.Protocol, ProcessorNum, ProcessorInfo);
ASSERT_EFI_ERROR (Status);
@@ -92,11 +93,11 @@ CpuCacheInfoGetProcessorInfo (
**/
UINT32
CpuCacheInfoWhoAmI (
IN MP_SERVICES MpServices
IN MP_SERVICES MpServices
)
{
EFI_STATUS Status;
UINTN ProcessorNum;
EFI_STATUS Status;
UINTN ProcessorNum;
Status = MpServices.Protocol->WhoAmI (MpServices.Protocol, &ProcessorNum);
ASSERT_EFI_ERROR (Status);
@@ -113,12 +114,12 @@ CpuCacheInfoWhoAmI (
**/
UINT32
CpuCacheInfoGetNumberOfProcessors (
IN MP_SERVICES MpServices
IN MP_SERVICES MpServices
)
{
EFI_STATUS Status;
UINTN NumberOfProcessor;
UINTN NumberOfEnabledProcessor;
EFI_STATUS Status;
UINTN NumberOfProcessor;
UINTN NumberOfEnabledProcessor;
Status = MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, &NumberOfProcessor, &NumberOfEnabledProcessor);
ASSERT_EFI_ERROR (Status);

View File

@@ -25,24 +25,24 @@ typedef union {
// Type of the cache that this package's this type of logical processor corresponds to.
// Value = CPUID.04h:EAX[04:00]
//
UINT32 CacheType : 5;
UINT32 CacheType : 5;
//
// Level of the cache that this package's this type of logical processor corresponds to.
// Value = CPUID.04h:EAX[07:05]
//
UINT32 CacheLevel : 3;
UINT32 CacheLevel : 3;
//
// Core type of logical processor.
// Value = CPUID.1Ah:EAX[31:24]
//
UINT32 CoreType : 8;
UINT32 Reserved : 16;
UINT32 CoreType : 8;
UINT32 Reserved : 16;
//
// Package number.
//
UINT32 Package;
UINT32 Package;
} Bits;
UINT64 Uint64;
UINT64 Uint64;
} CPU_CACHE_INFO_COMPARATOR;
typedef struct {
@@ -50,17 +50,17 @@ typedef struct {
// Package ID, the information comes from
// EFI_CPU_PHYSICAL_LOCATION.Package
//
UINT32 Package;
UINT32 Package;
//
// APIC ID, the information comes from
// EFI_PROCESSOR_INFORMATION.ProcessorId
//
UINT32 ApicId;
UINT32 ApicId;
//
// Core type of logical processor.
// Value = CPUID.1Ah:EAX[31:24]
//
UINT8 CoreType;
UINT8 CoreType;
} CPUID_PROCESSOR_INFO;
typedef struct {
@@ -68,39 +68,39 @@ typedef struct {
// Level of the cache.
// Value = CPUID.04h:EAX[07:05]
//
UINT8 CacheLevel : 3;
UINT8 CacheLevel : 3;
//
// Type of the cache.
// Value = CPUID.04h:EAX[04:00]
//
UINT8 CacheType : 5;
UINT8 CacheType : 5;
//
// Ways of associativity.
// Value = CPUID.04h:EBX[31:22]
//
UINT16 CacheWays : 10;
UINT16 CacheWays : 10;
//
// Fully associative cache.
// Value = CPUID.04h:EAX[09]
//
UINT16 FullyAssociativeCache : 1;
UINT16 FullyAssociativeCache : 1;
//
// Direct mapped cache.
// Value = CPUID.04h:EDX[02]
//
UINT16 DirectMappedCache : 1;
UINT16 Reserved : 4;
UINT16 DirectMappedCache : 1;
UINT16 Reserved : 4;
//
// Cache share bits.
// Value = CPUID.04h:EAX[25:14]
//
UINT16 CacheShareBits;
UINT16 CacheShareBits;
//
// Size of single cache.
// Value = (CPUID.04h:EBX[31:22] + 1) * (CPUID.04h:EBX[21:12] + 1) *
// (CPUID.04h:EBX[11:00] + 1) * (CPUID.04h:ECX[31:00] + 1)
//
UINT32 CacheSizeinKB;
UINT32 CacheSizeinKB;
} CPUID_CACHE_DATA;
typedef union {
@@ -109,24 +109,23 @@ typedef union {
} MP_SERVICES;
typedef struct {
MP_SERVICES MpServices;
CPUID_PROCESSOR_INFO *ProcessorInfo;
CPUID_CACHE_DATA *CacheData;
MP_SERVICES MpServices;
CPUID_PROCESSOR_INFO *ProcessorInfo;
CPUID_CACHE_DATA *CacheData;
} COLLECT_CPUID_CACHE_DATA_CONTEXT;
/*
Defines the maximum count of Deterministic Cache Parameters Leaf of all APs and BSP.
To save boot time, skip starting up all APs to calculate each AP's count of Deterministic
Cache Parameters Leaf, so use a definition instead.
Anyway, definition value will be checked in CpuCacheInfoCollectCoreAndCacheData function.
*/
#define MAX_NUM_OF_CACHE_PARAMS_LEAF 6
#define MAX_NUM_OF_CACHE_PARAMS_LEAF 6
/*
Defines the maximum count of packages.
*/
#define MAX_NUM_OF_PACKAGE 100
#define MAX_NUM_OF_PACKAGE 100
/**
Get EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL pointer.
@@ -139,7 +138,7 @@ typedef struct {
**/
EFI_STATUS
CpuCacheInfoGetMpServices (
OUT MP_SERVICES *MpServices
OUT MP_SERVICES *MpServices
);
/**
@@ -151,9 +150,9 @@ CpuCacheInfoGetMpServices (
**/
VOID
CpuCacheInfoStartupAllCPUs (
IN MP_SERVICES MpServices,
IN EFI_AP_PROCEDURE Procedure,
IN VOID *ProcedureArgument
IN MP_SERVICES MpServices,
IN EFI_AP_PROCEDURE Procedure,
IN VOID *ProcedureArgument
);
/**
@@ -165,9 +164,9 @@ CpuCacheInfoStartupAllCPUs (
**/
VOID
CpuCacheInfoGetProcessorInfo (
IN MP_SERVICES MpServices,
IN UINTN ProcessorNum,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
IN MP_SERVICES MpServices,
IN UINTN ProcessorNum,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
);
/**
@@ -179,7 +178,7 @@ CpuCacheInfoGetProcessorInfo (
**/
UINT32
CpuCacheInfoWhoAmI (
IN MP_SERVICES MpServices
IN MP_SERVICES MpServices
);
/**
@@ -191,6 +190,7 @@ CpuCacheInfoWhoAmI (
**/
UINT32
CpuCacheInfoGetNumberOfProcessors (
IN MP_SERVICES MpServices
IN MP_SERVICES MpServices
);
#endif

View File

@@ -24,10 +24,10 @@
**/
EFI_STATUS
CpuCacheInfoGetMpServices (
OUT MP_SERVICES *MpServices
OUT MP_SERVICES *MpServices
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = PeiServicesLocatePpi (&gEdkiiPeiMpServices2PpiGuid, 0, NULL, (VOID **)&MpServices->Ppi);
ASSERT_EFI_ERROR (Status);
@@ -44,12 +44,12 @@ CpuCacheInfoGetMpServices (
**/
VOID
CpuCacheInfoStartupAllCPUs (
IN MP_SERVICES MpServices,
IN EFI_AP_PROCEDURE Procedure,
IN VOID *ProcedureArgument
IN MP_SERVICES MpServices,
IN EFI_AP_PROCEDURE Procedure,
IN VOID *ProcedureArgument
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MpServices.Ppi->StartupAllCPUs (MpServices.Ppi, Procedure, 0, ProcedureArgument);
ASSERT_EFI_ERROR (Status);
@@ -64,12 +64,12 @@ CpuCacheInfoStartupAllCPUs (
**/
VOID
CpuCacheInfoGetProcessorInfo (
IN MP_SERVICES MpServices,
IN UINTN ProcessorNum,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
IN MP_SERVICES MpServices,
IN UINTN ProcessorNum,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = MpServices.Ppi->GetProcessorInfo (MpServices.Ppi, ProcessorNum, ProcessorInfo);
ASSERT_EFI_ERROR (Status);
@@ -84,11 +84,11 @@ CpuCacheInfoGetProcessorInfo (
**/
UINT32
CpuCacheInfoWhoAmI (
IN MP_SERVICES MpServices
IN MP_SERVICES MpServices
)
{
EFI_STATUS Status;
UINTN ProcessorNum;
EFI_STATUS Status;
UINTN ProcessorNum;
Status = MpServices.Ppi->WhoAmI (MpServices.Ppi, &ProcessorNum);
ASSERT_EFI_ERROR (Status);
@@ -105,12 +105,12 @@ CpuCacheInfoWhoAmI (
**/
UINT32
CpuCacheInfoGetNumberOfProcessors (
IN MP_SERVICES MpServices
IN MP_SERVICES MpServices
)
{
EFI_STATUS Status;
UINTN NumberOfProcessor;
UINTN NumberOfEnabledProcessor;
EFI_STATUS Status;
UINTN NumberOfProcessor;
UINTN NumberOfEnabledProcessor;
Status = MpServices.Ppi->GetNumberOfProcessors (MpServices.Ppi, &NumberOfProcessor, &NumberOfEnabledProcessor);
ASSERT_EFI_ERROR (Status);

View File

@@ -23,7 +23,7 @@ AesniGetConfigData (
IN UINTN NumberOfProcessors
)
{
UINT64 *ConfigData;
UINT64 *ConfigData;
ConfigData = AllocateZeroPool (sizeof (UINT64) * NumberOfProcessors);
ASSERT (ConfigData != NULL);
@@ -54,14 +54,15 @@ AesniSupport (
IN VOID *ConfigData OPTIONAL
)
{
MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *MsrFeatureConfig;
MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *MsrFeatureConfig;
if (CpuInfo->CpuIdVersionInfoEcx.Bits.AESNI == 1) {
MsrFeatureConfig = (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *) ConfigData;
MsrFeatureConfig = (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *)ConfigData;
ASSERT (MsrFeatureConfig != NULL);
MsrFeatureConfig[ProcessorNumber].Uint64 = AsmReadMsr64 (MSR_SANDY_BRIDGE_FEATURE_CONFIG);
return TRUE;
}
return FALSE;
}
@@ -91,7 +92,7 @@ AesniInitialize (
IN BOOLEAN State
)
{
MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *MsrFeatureConfig;
MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *MsrFeatureConfig;
//
// SANDY_BRIDGE, SILVERMONT, XEON_5600, XEON_7, and XEON_PHI have the same MSR index,
@@ -102,7 +103,7 @@ AesniInitialize (
// programming it.
//
if (CpuInfo->ProcessorInfo.Location.Thread == 0) {
MsrFeatureConfig = (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *) ConfigData;
MsrFeatureConfig = (MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER *)ConfigData;
ASSERT (MsrFeatureConfig != NULL);
if ((MsrFeatureConfig[ProcessorNumber].Bits.AESConfiguration & BIT0) == 0) {
CPU_REGISTER_TABLE_WRITE_FIELD (
@@ -115,5 +116,6 @@ AesniInitialize (
);
}
}
return RETURN_SUCCESS;
}

View File

@@ -66,7 +66,7 @@ C1eInitialize (
// MSR_NEHALEM_POWER_CTL once for each package.
//
if ((CpuInfo->First.Thread == 0) || (CpuInfo->First.Core == 0)) {
return RETURN_SUCCESS;
return RETURN_SUCCESS;
}
CPU_REGISTER_TABLE_WRITE_FIELD (

View File

@@ -9,8 +9,8 @@
#include "CpuCommonFeatures.h"
typedef struct {
CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax;
MSR_IA32_CLOCK_MODULATION_REGISTER ClockModulation;
CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax;
MSR_IA32_CLOCK_MODULATION_REGISTER ClockModulation;
} CLOCK_MODULATION_CONFIG_DATA;
/**
@@ -28,7 +28,7 @@ ClockModulationGetConfigData (
IN UINTN NumberOfProcessors
)
{
UINT32 *ConfigData;
UINT32 *ConfigData;
ConfigData = AllocateZeroPool (sizeof (CLOCK_MODULATION_CONFIG_DATA) * NumberOfProcessors);
ASSERT (ConfigData != NULL);
@@ -59,10 +59,10 @@ ClockModulationSupport (
IN VOID *ConfigData OPTIONAL
)
{
CLOCK_MODULATION_CONFIG_DATA *CmConfigData;
CLOCK_MODULATION_CONFIG_DATA *CmConfigData;
if (CpuInfo->CpuIdVersionInfoEdx.Bits.ACPI == 1) {
CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *) ConfigData;
CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *)ConfigData;
ASSERT (CmConfigData != NULL);
AsmCpuid (
CPUID_THERMAL_POWER_MANAGEMENT,
@@ -74,6 +74,7 @@ ClockModulationSupport (
CmConfigData[ProcessorNumber].ClockModulation.Uint64 = AsmReadMsr64 (MSR_IA32_CLOCK_MODULATION);
return TRUE;
}
return FALSE;
}
@@ -103,15 +104,15 @@ ClockModulationInitialize (
IN BOOLEAN State
)
{
CLOCK_MODULATION_CONFIG_DATA *CmConfigData;
MSR_IA32_CLOCK_MODULATION_REGISTER *ClockModulation;
CLOCK_MODULATION_CONFIG_DATA *CmConfigData;
MSR_IA32_CLOCK_MODULATION_REGISTER *ClockModulation;
CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *) ConfigData;
CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *)ConfigData;
ASSERT (CmConfigData != NULL);
ClockModulation = &CmConfigData[ProcessorNumber].ClockModulation;
if (State) {
ClockModulation->Bits.OnDemandClockModulationEnable = 1;
ClockModulation->Bits.OnDemandClockModulationEnable = 1;
ClockModulation->Bits.OnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) >> 1;
if (CmConfigData[ProcessorNumber].ThermalPowerManagementEax.Bits.ECMD == 1) {
ClockModulation->Bits.ExtendedOnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) & BIT0;

View File

@@ -860,7 +860,7 @@ X2ApicInitialize (
VOID *
EFIAPI
PpinGetConfigData (
IN UINTN NumberOfProcessors
IN UINTN NumberOfProcessors
);
/**

View File

@@ -20,7 +20,7 @@ CpuCommonFeaturesLibConstructor (
VOID
)
{
RETURN_STATUS Status;
RETURN_STATUS Status;
if (IsCpuFeatureSupported (CPU_FEATURE_AESNI)) {
Status = RegisterCpuFeature (
@@ -33,6 +33,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_MWAIT)) {
Status = RegisterCpuFeature (
"MWAIT",
@@ -44,6 +45,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_ACPI)) {
Status = RegisterCpuFeature (
"ACPI",
@@ -55,6 +57,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_EIST)) {
Status = RegisterCpuFeature (
"EIST",
@@ -66,6 +69,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_FASTSTRINGS)) {
Status = RegisterCpuFeature (
"FastStrings",
@@ -77,6 +81,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER)) {
Status = RegisterCpuFeature (
"Lock Feature Control Register",
@@ -88,6 +93,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_SMX)) {
Status = RegisterCpuFeature (
"SMX",
@@ -100,6 +106,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_VMX)) {
Status = RegisterCpuFeature (
"VMX",
@@ -112,6 +119,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_LIMIT_CPUID_MAX_VAL)) {
Status = RegisterCpuFeature (
"Limit CpuId Maximum Value",
@@ -123,6 +131,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_MCE)) {
Status = RegisterCpuFeature (
"Machine Check Enable",
@@ -134,6 +143,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_MCA)) {
Status = RegisterCpuFeature (
"Machine Check Architect",
@@ -145,6 +155,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_MCG_CTL)) {
Status = RegisterCpuFeature (
"MCG_CTL",
@@ -156,6 +167,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_PENDING_BREAK)) {
Status = RegisterCpuFeature (
"Pending Break",
@@ -167,6 +179,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_C1E)) {
Status = RegisterCpuFeature (
"C1E",
@@ -178,6 +191,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) {
Status = RegisterCpuFeature (
"X2Apic",
@@ -189,6 +203,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_PPIN)) {
Status = RegisterCpuFeature (
"PPIN",
@@ -200,6 +215,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_LMCE)) {
Status = RegisterCpuFeature (
"LMCE",
@@ -212,6 +228,7 @@ CpuCommonFeaturesLibConstructor (
);
ASSERT_EFI_ERROR (Status);
}
if (IsCpuFeatureSupported (CPU_FEATURE_PROC_TRACE)) {
Status = RegisterCpuFeature (
"Proc Trace",
@@ -226,6 +243,3 @@ CpuCommonFeaturesLibConstructor (
return RETURN_SUCCESS;
}

View File

@@ -69,7 +69,8 @@ EistInitialize (
//
if (IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}

View File

@@ -40,7 +40,8 @@ FastStringsInitialize (
//
if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}

View File

@@ -68,7 +68,8 @@ VmxInitialize (
//
if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}
@@ -146,7 +147,8 @@ LockFeatureControlRegisterInitialize (
//
if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}
@@ -218,7 +220,7 @@ SmxInitialize (
IN BOOLEAN State
)
{
RETURN_STATUS Status;
RETURN_STATUS Status;
//
// The scope of Lock bit in the MSR_IA32_FEATURE_CONTROL is core for
@@ -226,7 +228,8 @@ SmxInitialize (
// core.
//
if (IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}
@@ -236,7 +239,7 @@ SmxInitialize (
if (State && (!IsCpuFeatureInSetting (CPU_FEATURE_VMX))) {
DEBUG ((DEBUG_WARN, "Warning :: Can't enable SMX feature when VMX feature not enabled, disable it.\n"));
State = FALSE;
State = FALSE;
Status = RETURN_UNSUPPORTED;
}
@@ -247,7 +250,7 @@ SmxInitialize (
IA32_CR4,
Bits.SMXE,
(State) ? 1 : 0
)
)
CPU_REGISTER_TABLE_TEST_THEN_WRITE_FIELD (
ProcessorNumber,

View File

@@ -72,7 +72,8 @@ LimitCpuidMaxvalInitialize (
IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}

View File

@@ -102,6 +102,7 @@ McaSupport (
if (!MceSupport (ProcessorNumber, CpuInfo, ConfigData)) {
return FALSE;
}
return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCA == 1);
}
@@ -144,7 +145,8 @@ McaInitialize (
IS_SKYLAKE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_XEON_PHI_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}
@@ -162,7 +164,7 @@ McaInitialize (
if (State) {
McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
for (BankIndex = 0; BankIndex < (UINT32) McgCap.Bits.Count; BankIndex++) {
for (BankIndex = 0; BankIndex < (UINT32)McgCap.Bits.Count; BankIndex++) {
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,
@@ -172,7 +174,7 @@ McaInitialize (
}
if (PcdGetBool (PcdIsPowerOnReset)) {
for (BankIndex = 0; BankIndex < (UINTN) McgCap.Bits.Count; BankIndex++) {
for (BankIndex = 0; BankIndex < (UINTN)McgCap.Bits.Count; BankIndex++) {
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,
@@ -215,6 +217,7 @@ McgCtlSupport (
if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
return FALSE;
}
McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
return (McgCap.Bits.MCG_CTL_P == 1);
}
@@ -249,7 +252,7 @@ McgCtlInitialize (
ProcessorNumber,
Msr,
MSR_IA32_MCG_CTL,
(State)? MAX_UINT64 : 0
(State) ? MAX_UINT64 : 0
);
return RETURN_SUCCESS;
}
@@ -279,7 +282,7 @@ LmceSupport (
IN VOID *ConfigData OPTIONAL
)
{
MSR_IA32_MCG_CAP_REGISTER McgCap;
MSR_IA32_MCG_CAP_REGISTER McgCap;
if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) {
return FALSE;
@@ -287,9 +290,10 @@ LmceSupport (
McgCap.Uint64 = AsmReadMsr64 (MSR_IA32_MCG_CAP);
if (ProcessorNumber == 0) {
DEBUG ((DEBUG_INFO, "LMCE enable = %x\n", (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0)));
DEBUG ((DEBUG_INFO, "LMCE enable = %x\n", (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0)));
}
return (BOOLEAN) (McgCap.Bits.MCG_LMCE_P != 0);
return (BOOLEAN)(McgCap.Bits.MCG_LMCE_P != 0);
}
/**
@@ -325,7 +329,8 @@ LmceInitialize (
//
if (IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}

View File

@@ -70,7 +70,8 @@ MonitorMwaitInitialize (
IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}

View File

@@ -36,9 +36,11 @@ PendingBreakSupport (
IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_PENTIUM_M_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_PENTIUM_M_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
return (CpuInfo->CpuIdVersionInfoEdx.Bits.PBE == 1);
}
return FALSE;
}

View File

@@ -20,10 +20,10 @@
VOID *
EFIAPI
PpinGetConfigData (
IN UINTN NumberOfProcessors
IN UINTN NumberOfProcessors
)
{
VOID *ConfigData;
VOID *ConfigData;
ConfigData = AllocateZeroPool (sizeof (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER) * NumberOfProcessors);
ASSERT (ConfigData != NULL);
@@ -55,8 +55,8 @@ PpinSupport (
IN VOID *ConfigData OPTIONAL
)
{
MSR_IVY_BRIDGE_PLATFORM_INFO_1_REGISTER PlatformInfo;
MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *MsrPpinCtrl;
MSR_IVY_BRIDGE_PLATFORM_INFO_1_REGISTER PlatformInfo;
MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *MsrPpinCtrl;
if ((CpuInfo->DisplayFamily == 0x06) &&
((CpuInfo->DisplayModel == 0x3E) || // Xeon E5 V2
@@ -65,13 +65,14 @@ PpinSupport (
(CpuInfo->DisplayModel == 0x55) || // Xeon Processor Scalable
(CpuInfo->DisplayModel == 0x57) || // Xeon Phi processor 3200, 5200, 7200 series.
(CpuInfo->DisplayModel == 0x85) // Future Xeon phi processor
)) {
))
{
//
// Check whether platform support this feature.
//
PlatformInfo.Uint64 = AsmReadMsr64 (MSR_IVY_BRIDGE_PLATFORM_INFO_1);
if (PlatformInfo.Bits.PPIN_CAP != 0) {
MsrPpinCtrl = (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *) ConfigData;
MsrPpinCtrl = (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *)ConfigData;
ASSERT (MsrPpinCtrl != NULL);
MsrPpinCtrl[ProcessorNumber].Uint64 = AsmReadMsr64 (MSR_IVY_BRIDGE_PPIN_CTL);
return TRUE;
@@ -112,9 +113,9 @@ PpinInitialize (
IN BOOLEAN State
)
{
MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *MsrPpinCtrl;
MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *MsrPpinCtrl;
MsrPpinCtrl = (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *) ConfigData;
MsrPpinCtrl = (MSR_IVY_BRIDGE_PPIN_CTL_REGISTER *)ConfigData;
ASSERT (MsrPpinCtrl != NULL);
//
@@ -143,14 +144,14 @@ PpinInitialize (
// According to SDM, once Enable_PPIN is set, attempt to write 1 to LockOut will cause #GP.
//
MsrPpinCtrl[ProcessorNumber].Bits.Enable_PPIN = 1;
MsrPpinCtrl[ProcessorNumber].Bits.LockOut = 0;
MsrPpinCtrl[ProcessorNumber].Bits.LockOut = 0;
} else {
//
// Disable and Lock.
// According to SDM, writing 1 to LockOut is permitted only if Enable_PPIN is clear.
//
MsrPpinCtrl[ProcessorNumber].Bits.Enable_PPIN = 0;
MsrPpinCtrl[ProcessorNumber].Bits.LockOut = 1;
MsrPpinCtrl[ProcessorNumber].Bits.LockOut = 1;
}
CPU_REGISTER_TABLE_WRITE64 (

View File

@@ -17,8 +17,7 @@
/// be terminated by an entry with the END bit set to 1, so 2
/// entries are required to use a single valid entry.
///
#define MAX_TOPA_ENTRY_COUNT 2
#define MAX_TOPA_ENTRY_COUNT 2
///
/// Processor trace output scheme selection.
@@ -29,25 +28,25 @@ typedef enum {
} RTIT_OUTPUT_SCHEME;
typedef struct {
BOOLEAN TopaSupported;
BOOLEAN SingleRangeSupported;
MSR_IA32_RTIT_CTL_REGISTER RtitCtrl;
MSR_IA32_RTIT_OUTPUT_BASE_REGISTER RtitOutputBase;
MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER RtitOutputMaskPtrs;
BOOLEAN TopaSupported;
BOOLEAN SingleRangeSupported;
MSR_IA32_RTIT_CTL_REGISTER RtitCtrl;
MSR_IA32_RTIT_OUTPUT_BASE_REGISTER RtitOutputBase;
MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER RtitOutputMaskPtrs;
} PROC_TRACE_PROCESSOR_DATA;
typedef struct {
UINT32 NumberOfProcessors;
UINT32 NumberOfProcessors;
UINT8 ProcTraceOutputScheme;
UINT32 ProcTraceMemSize;
UINT8 ProcTraceOutputScheme;
UINT32 ProcTraceMemSize;
UINTN *ThreadMemRegionTable;
UINTN AllocatedThreads;
UINTN *ThreadMemRegionTable;
UINTN AllocatedThreads;
UINTN *TopaMemArray;
UINTN *TopaMemArray;
PROC_TRACE_PROCESSOR_DATA *ProcessorData;
PROC_TRACE_PROCESSOR_DATA *ProcessorData;
} PROC_TRACE_DATA;
typedef struct {
@@ -73,10 +72,10 @@ ProcTraceGetConfigData (
ConfigData = AllocateZeroPool (sizeof (PROC_TRACE_DATA) + sizeof (PROC_TRACE_PROCESSOR_DATA) * NumberOfProcessors);
ASSERT (ConfigData != NULL);
ConfigData->ProcessorData = (PROC_TRACE_PROCESSOR_DATA *) ((UINT8*) ConfigData + sizeof (PROC_TRACE_DATA));
ConfigData->ProcessorData = (PROC_TRACE_PROCESSOR_DATA *)((UINT8 *)ConfigData + sizeof (PROC_TRACE_DATA));
ConfigData->NumberOfProcessors = (UINT32) NumberOfProcessors;
ConfigData->ProcTraceMemSize = PcdGet32 (PcdCpuProcTraceMemSize);
ConfigData->NumberOfProcessors = (UINT32)NumberOfProcessors;
ConfigData->ProcTraceMemSize = PcdGet32 (PcdCpuProcTraceMemSize);
ConfigData->ProcTraceOutputScheme = PcdGet8 (PcdCpuProcTraceOutputScheme);
return ConfigData;
@@ -107,17 +106,18 @@ ProcTraceSupport (
IN VOID *ConfigData OPTIONAL
)
{
PROC_TRACE_DATA *ProcTraceData;
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_EBX Ebx;
CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF_ECX Ecx;
PROC_TRACE_DATA *ProcTraceData;
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_EBX Ebx;
CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF_ECX Ecx;
//
// Check if ProcTraceMemorySize option is enabled (0xFF means disable by user)
//
ProcTraceData = (PROC_TRACE_DATA *) ConfigData;
ProcTraceData = (PROC_TRACE_DATA *)ConfigData;
ASSERT (ProcTraceData != NULL);
if ((ProcTraceData->ProcTraceMemSize > RtitTopaMemorySize128M) ||
(ProcTraceData->ProcTraceOutputScheme > RtitOutputSchemeToPA)) {
(ProcTraceData->ProcTraceOutputScheme > RtitOutputSchemeToPA))
{
return FALSE;
}
@@ -130,12 +130,13 @@ ProcTraceSupport (
}
AsmCpuidEx (CPUID_INTEL_PROCESSOR_TRACE, CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF, NULL, NULL, &Ecx.Uint32, NULL);
ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported = (BOOLEAN) (Ecx.Bits.RTIT == 1);
ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported = (BOOLEAN) (Ecx.Bits.SingleRangeOutput == 1);
ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported = (BOOLEAN)(Ecx.Bits.RTIT == 1);
ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported = (BOOLEAN)(Ecx.Bits.SingleRangeOutput == 1);
if ((ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported && (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeToPA)) ||
(ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported && (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeSingleRange))) {
ProcTraceData->ProcessorData[ProcessorNumber].RtitCtrl.Uint64 = AsmReadMsr64 (MSR_IA32_RTIT_CTL);
ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.Uint64 = AsmReadMsr64 (MSR_IA32_RTIT_OUTPUT_BASE);
(ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported && (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeSingleRange)))
{
ProcTraceData->ProcessorData[ProcessorNumber].RtitCtrl.Uint64 = AsmReadMsr64 (MSR_IA32_RTIT_CTL);
ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.Uint64 = AsmReadMsr64 (MSR_IA32_RTIT_OUTPUT_BASE);
ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.Uint64 = AsmReadMsr64 (MSR_IA32_RTIT_OUTPUT_MASK_PTRS);
return TRUE;
}
@@ -170,36 +171,37 @@ ProcTraceInitialize (
IN BOOLEAN State
)
{
UINT32 MemRegionSize;
UINTN Pages;
UINTN Alignment;
UINTN MemRegionBaseAddr;
UINTN *ThreadMemRegionTable;
UINTN Index;
UINTN TopaTableBaseAddr;
UINTN AlignedAddress;
UINTN *TopaMemArray;
PROC_TRACE_TOPA_TABLE *TopaTable;
PROC_TRACE_DATA *ProcTraceData;
BOOLEAN FirstIn;
MSR_IA32_RTIT_CTL_REGISTER CtrlReg;
MSR_IA32_RTIT_STATUS_REGISTER StatusReg;
MSR_IA32_RTIT_OUTPUT_BASE_REGISTER OutputBaseReg;
UINT32 MemRegionSize;
UINTN Pages;
UINTN Alignment;
UINTN MemRegionBaseAddr;
UINTN *ThreadMemRegionTable;
UINTN Index;
UINTN TopaTableBaseAddr;
UINTN AlignedAddress;
UINTN *TopaMemArray;
PROC_TRACE_TOPA_TABLE *TopaTable;
PROC_TRACE_DATA *ProcTraceData;
BOOLEAN FirstIn;
MSR_IA32_RTIT_CTL_REGISTER CtrlReg;
MSR_IA32_RTIT_STATUS_REGISTER StatusReg;
MSR_IA32_RTIT_OUTPUT_BASE_REGISTER OutputBaseReg;
MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER OutputMaskPtrsReg;
RTIT_TOPA_TABLE_ENTRY *TopaEntryPtr;
RTIT_TOPA_TABLE_ENTRY *TopaEntryPtr;
//
// The scope of the MSR_IA32_RTIT_* is core for below processor type, only program
// MSR_IA32_RTIT_* for thread 0 in each core.
//
if (IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {
IS_GOLDMONT_PLUS_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel))
{
if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
return RETURN_SUCCESS;
}
}
ProcTraceData = (PROC_TRACE_DATA *) ConfigData;
ProcTraceData = (PROC_TRACE_DATA *)ConfigData;
ASSERT (ProcTraceData != NULL);
//
@@ -235,7 +237,7 @@ ProcTraceInitialize (
}
MemRegionBaseAddr = 0;
FirstIn = FALSE;
FirstIn = FALSE;
if (ProcTraceData->ThreadMemRegionTable == NULL) {
FirstIn = TRUE;
@@ -245,7 +247,7 @@ ProcTraceInitialize (
///
/// Refer to PROC_TRACE_MEM_SIZE Table for Size Encoding
///
MemRegionSize = (UINT32) (1 << (ProcTraceData->ProcTraceMemSize + 12));
MemRegionSize = (UINT32)(1 << (ProcTraceData->ProcTraceMemSize + 12));
if (FirstIn) {
DEBUG ((DEBUG_INFO, "ProcTrace: MemSize requested: 0x%X \n", MemRegionSize));
}
@@ -258,32 +260,34 @@ ProcTraceInitialize (
// address base in MSR, IA32_RTIT_OUTPUT_BASE (560h) bits 47:12. Note that all regions must be
// aligned based on their size, not just 4K. Thus a 2M region must have bits 20:12 cleared.
//
ThreadMemRegionTable = (UINTN *) AllocatePool (ProcTraceData->NumberOfProcessors * sizeof (UINTN *));
ThreadMemRegionTable = (UINTN *)AllocatePool (ProcTraceData->NumberOfProcessors * sizeof (UINTN *));
if (ThreadMemRegionTable == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate ProcTrace ThreadMemRegionTable Failed\n"));
return RETURN_OUT_OF_RESOURCES;
}
ProcTraceData->ThreadMemRegionTable = ThreadMemRegionTable;
for (Index = 0; Index < ProcTraceData->NumberOfProcessors; Index++, ProcTraceData->AllocatedThreads++) {
Pages = EFI_SIZE_TO_PAGES (MemRegionSize);
Alignment = MemRegionSize;
AlignedAddress = (UINTN) AllocateAlignedReservedPages (Pages, Alignment);
Pages = EFI_SIZE_TO_PAGES (MemRegionSize);
Alignment = MemRegionSize;
AlignedAddress = (UINTN)AllocateAlignedReservedPages (Pages, Alignment);
if (AlignedAddress == 0) {
DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, allocated only for %d threads\n", ProcTraceData->AllocatedThreads));
if (Index == 0) {
//
// Could not allocate for BSP even
//
FreePool ((VOID *) ThreadMemRegionTable);
FreePool ((VOID *)ThreadMemRegionTable);
ThreadMemRegionTable = NULL;
return RETURN_OUT_OF_RESOURCES;
}
break;
}
ThreadMemRegionTable[Index] = AlignedAddress;
DEBUG ((DEBUG_INFO, "ProcTrace: PT MemRegionBaseAddr(aligned) for thread %d: 0x%llX \n", Index, (UINT64) ThreadMemRegionTable[Index]));
DEBUG ((DEBUG_INFO, "ProcTrace: PT MemRegionBaseAddr(aligned) for thread %d: 0x%llX \n", Index, (UINT64)ThreadMemRegionTable[Index]));
}
DEBUG ((DEBUG_INFO, "ProcTrace: Allocated PT mem for %d thread \n", ProcTraceData->AllocatedThreads));
@@ -303,7 +307,8 @@ ProcTraceInitialize (
// Single Range output scheme
//
if (ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported &&
(ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeSingleRange)) {
(ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeSingleRange))
{
if (FirstIn) {
DEBUG ((DEBUG_INFO, "ProcTrace: Enabling Single Range Output scheme \n"));
}
@@ -322,9 +327,9 @@ ProcTraceInitialize (
//
// Program MSR IA32_RTIT_OUTPUT_BASE (0x560) bits[63:7] with the allocated Memory Region
//
OutputBaseReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.Uint64;
OutputBaseReg.Bits.Base = (MemRegionBaseAddr >> 7) & 0x01FFFFFF;
OutputBaseReg.Bits.BaseHi = RShiftU64 ((UINT64) MemRegionBaseAddr, 32) & 0xFFFFFFFF;
OutputBaseReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.Uint64;
OutputBaseReg.Bits.Base = (MemRegionBaseAddr >> 7) & 0x01FFFFFF;
OutputBaseReg.Bits.BaseHi = RShiftU64 ((UINT64)MemRegionBaseAddr, 32) & 0xFFFFFFFF;
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,
@@ -335,9 +340,9 @@ ProcTraceInitialize (
//
// Program the Mask bits for the Memory Region to MSR IA32_RTIT_OUTPUT_MASK_PTRS (561h)
//
OutputMaskPtrsReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.Uint64;
OutputMaskPtrsReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.Uint64;
OutputMaskPtrsReg.Bits.MaskOrTableOffset = ((MemRegionSize - 1) >> 7) & 0x01FFFFFF;
OutputMaskPtrsReg.Bits.OutputOffset = RShiftU64 (MemRegionSize - 1, 32) & 0xFFFFFFFF;
OutputMaskPtrsReg.Bits.OutputOffset = RShiftU64 (MemRegionSize - 1, 32) & 0xFFFFFFFF;
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,
@@ -350,7 +355,8 @@ ProcTraceInitialize (
// ToPA(Table of physical address) scheme
//
if (ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported &&
(ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeToPA)) {
(ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeToPA))
{
//
// Create ToPA structure aligned at 4KB for each logical thread
// with at least 2 entries by 8 bytes size each. The first entry
@@ -364,35 +370,38 @@ ProcTraceInitialize (
//
// Let BSP allocate ToPA table mem for all threads
//
TopaMemArray = (UINTN *) AllocatePool (ProcTraceData->AllocatedThreads * sizeof (UINTN *));
TopaMemArray = (UINTN *)AllocatePool (ProcTraceData->AllocatedThreads * sizeof (UINTN *));
if (TopaMemArray == NULL) {
DEBUG ((DEBUG_ERROR, "ProcTrace: Allocate mem for ToPA Failed\n"));
return RETURN_OUT_OF_RESOURCES;
}
ProcTraceData->TopaMemArray = TopaMemArray;
for (Index = 0; Index < ProcTraceData->AllocatedThreads; Index++) {
Pages = EFI_SIZE_TO_PAGES (sizeof (PROC_TRACE_TOPA_TABLE));
Alignment = 0x1000;
AlignedAddress = (UINTN) AllocateAlignedReservedPages (Pages, Alignment);
Pages = EFI_SIZE_TO_PAGES (sizeof (PROC_TRACE_TOPA_TABLE));
Alignment = 0x1000;
AlignedAddress = (UINTN)AllocateAlignedReservedPages (Pages, Alignment);
if (AlignedAddress == 0) {
if (Index < ProcTraceData->AllocatedThreads) {
ProcTraceData->AllocatedThreads = Index;
}
DEBUG ((DEBUG_ERROR, "ProcTrace: Out of mem, allocated ToPA mem only for %d threads\n", ProcTraceData->AllocatedThreads));
if (Index == 0) {
//
// Could not allocate for BSP even
//
FreePool ((VOID *) TopaMemArray);
FreePool ((VOID *)TopaMemArray);
TopaMemArray = NULL;
return RETURN_OUT_OF_RESOURCES;
}
break;
}
TopaMemArray[Index] = AlignedAddress;
DEBUG ((DEBUG_INFO, "ProcTrace: Topa table address(aligned) for thread %d is 0x%llX \n", Index, (UINT64) TopaMemArray[Index]));
DEBUG ((DEBUG_INFO, "ProcTrace: Topa table address(aligned) for thread %d is 0x%llX \n", Index, (UINT64)TopaMemArray[Index]));
}
DEBUG ((DEBUG_INFO, "ProcTrace: Allocated ToPA mem for %d thread \n", ProcTraceData->AllocatedThreads));
@@ -404,26 +413,26 @@ ProcTraceInitialize (
return RETURN_SUCCESS;
}
TopaTable = (PROC_TRACE_TOPA_TABLE *) TopaTableBaseAddr;
TopaEntryPtr = &TopaTable->TopaEntry[0];
TopaEntryPtr->Uint64 = 0;
TopaEntryPtr->Bits.Base = (MemRegionBaseAddr >> 12) & 0x000FFFFF;
TopaEntryPtr->Bits.BaseHi = RShiftU64 ((UINT64) MemRegionBaseAddr, 32) & 0xFFFFFFFF;
TopaEntryPtr->Bits.Size = ProcTraceData->ProcTraceMemSize;
TopaEntryPtr->Bits.END = 0;
TopaTable = (PROC_TRACE_TOPA_TABLE *)TopaTableBaseAddr;
TopaEntryPtr = &TopaTable->TopaEntry[0];
TopaEntryPtr->Uint64 = 0;
TopaEntryPtr->Bits.Base = (MemRegionBaseAddr >> 12) & 0x000FFFFF;
TopaEntryPtr->Bits.BaseHi = RShiftU64 ((UINT64)MemRegionBaseAddr, 32) & 0xFFFFFFFF;
TopaEntryPtr->Bits.Size = ProcTraceData->ProcTraceMemSize;
TopaEntryPtr->Bits.END = 0;
TopaEntryPtr = &TopaTable->TopaEntry[1];
TopaEntryPtr->Uint64 = 0;
TopaEntryPtr->Bits.Base = (TopaTableBaseAddr >> 12) & 0x000FFFFF;
TopaEntryPtr->Bits.BaseHi = RShiftU64 ((UINT64) TopaTableBaseAddr, 32) & 0xFFFFFFFF;
TopaEntryPtr->Bits.END = 1;
TopaEntryPtr = &TopaTable->TopaEntry[1];
TopaEntryPtr->Uint64 = 0;
TopaEntryPtr->Bits.Base = (TopaTableBaseAddr >> 12) & 0x000FFFFF;
TopaEntryPtr->Bits.BaseHi = RShiftU64 ((UINT64)TopaTableBaseAddr, 32) & 0xFFFFFFFF;
TopaEntryPtr->Bits.END = 1;
//
// Program the MSR IA32_RTIT_OUTPUT_BASE (0x560) bits[63:7] with ToPA base
//
OutputBaseReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.Uint64;
OutputBaseReg.Bits.Base = (TopaTableBaseAddr >> 7) & 0x01FFFFFF;
OutputBaseReg.Bits.BaseHi = RShiftU64 ((UINT64) TopaTableBaseAddr, 32) & 0xFFFFFFFF;
OutputBaseReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.Uint64;
OutputBaseReg.Bits.Base = (TopaTableBaseAddr >> 7) & 0x01FFFFFF;
OutputBaseReg.Bits.BaseHi = RShiftU64 ((UINT64)TopaTableBaseAddr, 32) & 0xFFFFFFFF;
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,
@@ -434,9 +443,9 @@ ProcTraceInitialize (
//
// Set the MSR IA32_RTIT_OUTPUT_MASK (0x561) bits[63:7] to 0
//
OutputMaskPtrsReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.Uint64;
OutputMaskPtrsReg.Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.Uint64;
OutputMaskPtrsReg.Bits.MaskOrTableOffset = 0;
OutputMaskPtrsReg.Bits.OutputOffset = 0;
OutputMaskPtrsReg.Bits.OutputOffset = 0;
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,
@@ -458,10 +467,10 @@ ProcTraceInitialize (
///
/// Enable the Processor Trace feature from MSR IA32_RTIT_CTL (570h)
///
CtrlReg.Bits.OS = 1;
CtrlReg.Bits.User = 1;
CtrlReg.Bits.OS = 1;
CtrlReg.Bits.User = 1;
CtrlReg.Bits.BranchEn = 1;
CtrlReg.Bits.TraceEn = 1;
CtrlReg.Bits.TraceEn = 1;
CPU_REGISTER_TABLE_WRITE64 (
ProcessorNumber,
Msr,

View File

@@ -23,7 +23,7 @@ X2ApicGetConfigData (
IN UINTN NumberOfProcessors
)
{
BOOLEAN *ConfigData;
BOOLEAN *ConfigData;
ConfigData = AllocateZeroPool (sizeof (BOOLEAN) * NumberOfProcessors);
ASSERT (ConfigData != NULL);
@@ -56,10 +56,10 @@ X2ApicSupport (
IN VOID *ConfigData OPTIONAL
)
{
BOOLEAN *X2ApicEnabled;
BOOLEAN *X2ApicEnabled;
ASSERT (ConfigData != NULL);
X2ApicEnabled = (BOOLEAN *) ConfigData;
X2ApicEnabled = (BOOLEAN *)ConfigData;
//
// *ConfigData indicates if X2APIC enabled on current processor
//
@@ -94,7 +94,7 @@ X2ApicInitialize (
IN BOOLEAN State
)
{
BOOLEAN *X2ApicEnabled;
BOOLEAN *X2ApicEnabled;
//
// The scope of the MSR_IA32_APIC_BASE is core for below processor type, only program
@@ -107,7 +107,7 @@ X2ApicInitialize (
}
ASSERT (ConfigData != NULL);
X2ApicEnabled = (BOOLEAN *) ConfigData;
X2ApicEnabled = (BOOLEAN *)ConfigData;
if (X2ApicEnabled[ProcessorNumber]) {
PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD (
ProcessorNumber,
@@ -133,5 +133,6 @@ X2ApicInitialize (
);
}
}
return RETURN_SUCCESS;
}

View File

@@ -14,15 +14,15 @@
//
// 1 means an error code will be pushed, otherwise 0
//
CONST UINT32 mErrorCodeFlag = 0x20227d00;
CONST UINT32 mErrorCodeFlag = 0x20227d00;
//
// Define the maximum message length
//
#define MAX_DEBUG_MESSAGE_LENGTH 0x100
CONST CHAR8 mExceptionReservedStr[] = "Reserved";
CONST CHAR8 *mExceptionNameStr[] = {
CONST CHAR8 mExceptionReservedStr[] = "Reserved";
CONST CHAR8 *mExceptionNameStr[] = {
"#DE - Divide Error",
"#DB - Debug",
"NMI Interrupt",
@@ -66,10 +66,10 @@ CONST CHAR8 *mExceptionNameStr[] = {
**/
CONST CHAR8 *
GetExceptionNameStr (
IN EFI_EXCEPTION_TYPE ExceptionType
IN EFI_EXCEPTION_TYPE ExceptionType
)
{
if ((UINTN) ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {
if ((UINTN)ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {
return mExceptionNameStr[ExceptionType];
} else {
return mExceptionReservedStr;
@@ -115,13 +115,13 @@ InternalPrintMessage (
**/
VOID
DumpModuleImageInfo (
IN UINTN CurrentEip
IN UINTN CurrentEip
)
{
EFI_STATUS Status;
UINTN Pe32Data;
VOID *PdbPointer;
VOID *EntryPoint;
EFI_STATUS Status;
UINTN Pe32Data;
VOID *PdbPointer;
VOID *EntryPoint;
Pe32Data = PeCoffSearchImageBase (CurrentEip);
if (Pe32Data == 0) {
@@ -130,20 +130,22 @@ DumpModuleImageInfo (
//
// Find Image Base entry point
//
Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);
Status = PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint);
if (EFI_ERROR (Status)) {
EntryPoint = NULL;
}
InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data);
if (PdbPointer != NULL) {
InternalPrintMessage ("%a", PdbPointer);
} else {
InternalPrintMessage ("(No PDB) " );
InternalPrintMessage ("(No PDB) ");
}
InternalPrintMessage (
" (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
(VOID *) Pe32Data,
(VOID *)Pe32Data,
EntryPoint
);
}
@@ -162,9 +164,9 @@ DumpModuleImageInfo (
**/
EFI_STATUS
ReadAndVerifyVectorInfo (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
OUT RESERVED_VECTORS_DATA *ReservedVector,
IN UINTN VectorCount
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
OUT RESERVED_VECTORS_DATA *ReservedVector,
IN UINTN VectorCount
)
{
while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
@@ -174,10 +176,13 @@ ReadAndVerifyVectorInfo (
//
return EFI_INVALID_PARAMETER;
}
if (VectorInfo->VectorNumber < VectorCount) {
ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;
}
VectorInfo ++;
VectorInfo++;
}
return EFI_SUCCESS;
}

View File

@@ -20,21 +20,21 @@
#include <Library/SynchronizationLib.h>
#include <Library/CpuExceptionHandlerLib.h>
#define CPU_EXCEPTION_NUM 32
#define CPU_INTERRUPT_NUM 256
#define HOOKAFTER_STUB_SIZE 16
#define CPU_EXCEPTION_NUM 32
#define CPU_INTERRUPT_NUM 256
#define HOOKAFTER_STUB_SIZE 16
//
// Exception Error Code of Page-Fault Exception
//
#define IA32_PF_EC_P BIT0
#define IA32_PF_EC_WR BIT1
#define IA32_PF_EC_US BIT2
#define IA32_PF_EC_RSVD BIT3
#define IA32_PF_EC_ID BIT4
#define IA32_PF_EC_PK BIT5
#define IA32_PF_EC_SS BIT6
#define IA32_PF_EC_SGX BIT15
#define IA32_PF_EC_P BIT0
#define IA32_PF_EC_WR BIT1
#define IA32_PF_EC_US BIT2
#define IA32_PF_EC_RSVD BIT3
#define IA32_PF_EC_ID BIT4
#define IA32_PF_EC_PK BIT5
#define IA32_PF_EC_SS BIT6
#define IA32_PF_EC_SGX BIT15
#include "ArchInterruptDefs.h"
@@ -47,26 +47,26 @@
#define CPU_KNOWN_GOOD_STACK_SIZE \
FixedPcdGet32 (PcdCpuKnownGoodStackSize)
#define CPU_TSS_GDT_SIZE (SIZE_2KB + CPU_TSS_DESC_SIZE + CPU_TSS_SIZE)
#define CPU_TSS_GDT_SIZE (SIZE_2KB + CPU_TSS_DESC_SIZE + CPU_TSS_SIZE)
//
// Record exception handler information
//
typedef struct {
UINTN ExceptionStart;
UINTN ExceptionStubHeaderSize;
UINTN HookAfterStubHeaderStart;
UINTN ExceptionStart;
UINTN ExceptionStubHeaderSize;
UINTN HookAfterStubHeaderStart;
} EXCEPTION_HANDLER_TEMPLATE_MAP;
typedef struct {
UINTN IdtEntryCount;
SPIN_LOCK DisplayMessageSpinLock;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
UINTN IdtEntryCount;
SPIN_LOCK DisplayMessageSpinLock;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
} EXCEPTION_HANDLER_DATA;
extern CONST UINT32 mErrorCodeFlag;
extern CONST UINTN mDoFarReturnFlag;
extern CONST UINT32 mErrorCodeFlag;
extern CONST UINTN mDoFarReturnFlag;
/**
Return address map of exception handler template so that C code can generate
@@ -77,7 +77,7 @@ extern CONST UINTN mDoFarReturnFlag;
VOID
EFIAPI
AsmGetTemplateAddressMap (
OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap
OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap
);
/**
@@ -90,8 +90,8 @@ AsmGetTemplateAddressMap (
**/
VOID
ArchUpdateIdtEntry (
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
IN UINTN InterruptHandler
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
IN UINTN InterruptHandler
);
/**
@@ -102,7 +102,7 @@ ArchUpdateIdtEntry (
**/
UINTN
ArchGetIdtHandler (
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
);
/**
@@ -128,7 +128,7 @@ InternalPrintMessage (
**/
VOID
DumpModuleImageInfo (
IN UINTN CurrentEip
IN UINTN CurrentEip
);
/**
@@ -139,8 +139,8 @@ DumpModuleImageInfo (
**/
VOID
DumpImageAndCpuContent (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
);
/**
@@ -157,8 +157,8 @@ DumpImageAndCpuContent (
**/
EFI_STATUS
InitializeCpuExceptionHandlersWorker (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
);
/**
@@ -180,9 +180,9 @@ InitializeCpuExceptionHandlersWorker (
**/
EFI_STATUS
RegisterCpuInterruptHandlerWorker (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
);
/**
@@ -210,9 +210,9 @@ UpdateIdtTable (
**/
VOID
ArchSaveExceptionContext (
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
);
/**
@@ -224,9 +224,9 @@ ArchSaveExceptionContext (
**/
VOID
ArchRestoreExceptionContext (
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
);
/**
@@ -240,9 +240,9 @@ ArchRestoreExceptionContext (
VOID
EFIAPI
AsmVectorNumFixup (
IN VOID *NewVectorAddr,
IN UINT8 VectorNum,
IN VOID *OldVectorAddr
IN VOID *NewVectorAddr,
IN UINT8 VectorNum,
IN VOID *OldVectorAddr
);
/**
@@ -258,9 +258,9 @@ AsmVectorNumFixup (
**/
EFI_STATUS
ReadAndVerifyVectorInfo (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
OUT RESERVED_VECTORS_DATA *ReservedVector,
IN UINTN VectorCount
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
OUT RESERVED_VECTORS_DATA *ReservedVector,
IN UINTN VectorCount
);
/**
@@ -272,7 +272,7 @@ ReadAndVerifyVectorInfo (
**/
CONST CHAR8 *
GetExceptionNameStr (
IN EFI_EXCEPTION_TYPE ExceptionType
IN EFI_EXCEPTION_TYPE ExceptionType
);
/**
@@ -284,9 +284,9 @@ GetExceptionNameStr (
**/
VOID
CommonExceptionHandlerWorker (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
);
/**
@@ -301,7 +301,7 @@ CommonExceptionHandlerWorker (
**/
EFI_STATUS
ArchSetupExceptionStack (
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
);
/**
@@ -318,4 +318,3 @@ AsmGetTssTemplateMap (
);
#endif

View File

@@ -12,17 +12,17 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
CONST UINTN mDoFarReturnFlag = 0;
CONST UINTN mDoFarReturnFlag = 0;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
UINTN mEnabledInterruptNum = 0;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
UINTN mEnabledInterruptNum = 0;
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER *
CPU_KNOWN_GOOD_STACK_SIZE];
UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER *
CPU_KNOWN_GOOD_STACK_SIZE];
UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
/**
Common exception handler.
@@ -33,8 +33,8 @@ UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
VOID
EFIAPI
CommonExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
@@ -59,7 +59,7 @@ CommonExceptionHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
mExceptionHandlerData.ReservedVectors = mReservedVectorsData;
@@ -87,19 +87,19 @@ InitializeCpuExceptionHandlers (
EFI_STATUS
EFIAPI
InitializeCpuInterruptHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
EFI_STATUS Status;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
IA32_DESCRIPTOR IdtDescriptor;
UINTN IdtEntryCount;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
UINTN Index;
UINTN InterruptEntry;
UINT8 *InterruptEntryCode;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
EFI_STATUS Status;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
IA32_DESCRIPTOR IdtDescriptor;
UINTN IdtEntryCount;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
UINTN Index;
UINTN InterruptEntry;
UINT8 *InterruptEntryCode;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
Status = gBS->AllocatePool (
EfiBootServicesCode,
@@ -107,7 +107,7 @@ InitializeCpuInterruptHandlers (
(VOID **)&ReservedVectors
);
ASSERT (!EFI_ERROR (Status) && ReservedVectors != NULL);
SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);
SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);
if (VectorInfo != NULL) {
Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_INTERRUPT_NUM);
if (EFI_ERROR (Status)) {
@@ -127,6 +127,7 @@ InitializeCpuInterruptHandlers (
if (IdtEntryCount > CPU_INTERRUPT_NUM) {
IdtEntryCount = CPU_INTERRUPT_NUM;
}
//
// Create Interrupt Descriptor Table and Copy the old IDT table in
//
@@ -144,18 +145,18 @@ InitializeCpuInterruptHandlers (
);
ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);
InterruptEntry = (UINTN) InterruptEntryCode;
for (Index = 0; Index < CPU_INTERRUPT_NUM; Index ++) {
InterruptEntry = (UINTN)InterruptEntryCode;
for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {
CopyMem (
(VOID *) InterruptEntry,
(VOID *) TemplateMap.ExceptionStart,
(VOID *)InterruptEntry,
(VOID *)TemplateMap.ExceptionStart,
TemplateMap.ExceptionStubHeaderSize
);
AsmVectorNumFixup ((VOID *) InterruptEntry, (UINT8) Index, (VOID *) TemplateMap.ExceptionStart);
AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID *)TemplateMap.ExceptionStart);
InterruptEntry += TemplateMap.ExceptionStubHeaderSize;
}
TemplateMap.ExceptionStart = (UINTN) InterruptEntryCode;
TemplateMap.ExceptionStart = (UINTN)InterruptEntryCode;
mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;
mExceptionHandlerData.ReservedVectors = ReservedVectors;
mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;
@@ -166,9 +167,9 @@ InitializeCpuInterruptHandlers (
//
// Load Interrupt Descriptor Table
//
IdtDescriptor.Base = (UINTN) IdtTable;
IdtDescriptor.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
AsmWriteIdtr ((IA32_DESCRIPTOR *) &IdtDescriptor);
IdtDescriptor.Base = (UINTN)IdtTable;
IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
AsmWriteIdtr ((IA32_DESCRIPTOR *)&IdtDescriptor);
return EFI_SUCCESS;
}
@@ -199,8 +200,8 @@ InitializeCpuInterruptHandlers (
EFI_STATUS
EFIAPI
RegisterCpuInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
)
{
return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
@@ -230,14 +231,14 @@ RegisterCpuInterruptHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlersEx (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
)
{
EFI_STATUS Status;
CPU_EXCEPTION_INIT_DATA EssData;
IA32_DESCRIPTOR Idtr;
IA32_DESCRIPTOR Gdtr;
EFI_STATUS Status;
CPU_EXCEPTION_INIT_DATA EssData;
IA32_DESCRIPTOR Idtr;
IA32_DESCRIPTOR Gdtr;
//
// To avoid repeat initialization of default handlers, the caller should pass
@@ -246,7 +247,7 @@ InitializeCpuExceptionHandlersEx (
// version instead; or this method must be implemented as a simple wrapper of
// non-ex version of it, if this version has to be called.
//
if (InitData == NULL || InitData->X64.InitDefaultHandlers) {
if ((InitData == NULL) || InitData->X64.InitDefaultHandlers) {
Status = InitializeCpuExceptionHandlers (VectorInfo);
} else {
Status = EFI_SUCCESS;
@@ -263,25 +264,26 @@ InitializeCpuExceptionHandlersEx (
AsmReadIdtr (&Idtr);
AsmReadGdtr (&Gdtr);
EssData.X64.Revision = CPU_EXCEPTION_INIT_DATA_REV;
EssData.X64.KnownGoodStackTop = (UINTN)mNewStack + sizeof (mNewStack);
EssData.X64.KnownGoodStackSize = CPU_KNOWN_GOOD_STACK_SIZE;
EssData.X64.StackSwitchExceptions = CPU_STACK_SWITCH_EXCEPTION_LIST;
EssData.X64.Revision = CPU_EXCEPTION_INIT_DATA_REV;
EssData.X64.KnownGoodStackTop = (UINTN)mNewStack + sizeof (mNewStack);
EssData.X64.KnownGoodStackSize = CPU_KNOWN_GOOD_STACK_SIZE;
EssData.X64.StackSwitchExceptions = CPU_STACK_SWITCH_EXCEPTION_LIST;
EssData.X64.StackSwitchExceptionNumber = CPU_STACK_SWITCH_EXCEPTION_NUMBER;
EssData.X64.IdtTable = (VOID *)Idtr.Base;
EssData.X64.IdtTableSize = Idtr.Limit + 1;
EssData.X64.GdtTable = mNewGdt;
EssData.X64.GdtTableSize = sizeof (mNewGdt);
EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;
EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;
EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;
EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;
EssData.X64.IdtTable = (VOID *)Idtr.Base;
EssData.X64.IdtTableSize = Idtr.Limit + 1;
EssData.X64.GdtTable = mNewGdt;
EssData.X64.GdtTableSize = sizeof (mNewGdt);
EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;
EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;
EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;
EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;
InitData = &EssData;
}
Status = ArchSetupExceptionStack (InitData);
}
}
return Status;
return Status;
}

View File

@@ -18,13 +18,13 @@
**/
VOID
ArchUpdateIdtEntry (
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
IN UINTN InterruptHandler
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
IN UINTN InterruptHandler
)
{
IdtEntry->Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry->Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry->Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
IdtEntry->Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry->Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry->Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
}
/**
@@ -35,7 +35,7 @@ ArchUpdateIdtEntry (
**/
UINTN
ArchGetIdtHandler (
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
)
{
return (UINTN)IdtEntry->Bits.OffsetLow + (((UINTN)IdtEntry->Bits.OffsetHigh) << 16);
@@ -50,13 +50,13 @@ ArchGetIdtHandler (
**/
VOID
ArchSaveExceptionContext (
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
IA32_EFLAGS32 Eflags;
RESERVED_VECTORS_DATA *ReservedVectors;
IA32_EFLAGS32 Eflags;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
//
@@ -71,13 +71,13 @@ ArchSaveExceptionContext (
//
// Clear IF flag to avoid old IDT handler enable interrupt by IRET
//
Eflags.UintN = SystemContext.SystemContextIa32->Eflags;
Eflags.Bits.IF = 0;
Eflags.UintN = SystemContext.SystemContextIa32->Eflags;
Eflags.Bits.IF = 0;
SystemContext.SystemContextIa32->Eflags = Eflags.UintN;
//
// Modify the EIP in stack, then old IDT handler will return to HookAfterStubBegin.
//
SystemContext.SystemContextIa32->Eip = (UINTN) ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
SystemContext.SystemContextIa32->Eip = (UINTN)ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
}
/**
@@ -89,14 +89,14 @@ ArchSaveExceptionContext (
**/
VOID
ArchRestoreExceptionContext (
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
RESERVED_VECTORS_DATA *ReservedVectors;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
SystemContext.SystemContextIa32->Eflags = ReservedVectors[ExceptionType].OldFlags;
SystemContext.SystemContextIa32->Cs = ReservedVectors[ExceptionType].OldCs;
SystemContext.SystemContextIa32->Eip = ReservedVectors[ExceptionType].OldIp;
@@ -116,32 +116,33 @@ ArchRestoreExceptionContext (
**/
EFI_STATUS
ArchSetupExceptionStack (
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
)
{
IA32_DESCRIPTOR Gdtr;
IA32_DESCRIPTOR Idtr;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
IA32_TSS_DESCRIPTOR *TssDesc;
IA32_TASK_STATE_SEGMENT *Tss;
UINTN StackTop;
UINTN Index;
UINTN Vector;
UINTN TssBase;
UINTN GdtSize;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
IA32_DESCRIPTOR Gdtr;
IA32_DESCRIPTOR Idtr;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
IA32_TSS_DESCRIPTOR *TssDesc;
IA32_TASK_STATE_SEGMENT *Tss;
UINTN StackTop;
UINTN Index;
UINTN Vector;
UINTN TssBase;
UINTN GdtSize;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
if (StackSwitchData == NULL ||
StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV ||
StackSwitchData->Ia32.KnownGoodStackTop == 0 ||
StackSwitchData->Ia32.KnownGoodStackSize == 0 ||
StackSwitchData->Ia32.StackSwitchExceptions == NULL ||
StackSwitchData->Ia32.StackSwitchExceptionNumber == 0 ||
StackSwitchData->Ia32.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM ||
StackSwitchData->Ia32.GdtTable == NULL ||
StackSwitchData->Ia32.IdtTable == NULL ||
StackSwitchData->Ia32.ExceptionTssDesc == NULL ||
StackSwitchData->Ia32.ExceptionTss == NULL) {
if ((StackSwitchData == NULL) ||
(StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV) ||
(StackSwitchData->Ia32.KnownGoodStackTop == 0) ||
(StackSwitchData->Ia32.KnownGoodStackSize == 0) ||
(StackSwitchData->Ia32.StackSwitchExceptions == NULL) ||
(StackSwitchData->Ia32.StackSwitchExceptionNumber == 0) ||
(StackSwitchData->Ia32.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM) ||
(StackSwitchData->Ia32.GdtTable == NULL) ||
(StackSwitchData->Ia32.IdtTable == NULL) ||
(StackSwitchData->Ia32.ExceptionTssDesc == NULL) ||
(StackSwitchData->Ia32.ExceptionTss == NULL))
{
return EFI_INVALID_PARAMETER;
}
@@ -159,7 +160,8 @@ ArchSetupExceptionStack (
}
if ((UINTN)StackSwitchData->Ia32.ExceptionTssDesc + StackSwitchData->Ia32.ExceptionTssDescSize >
((UINTN)(StackSwitchData->Ia32.GdtTable) + StackSwitchData->Ia32.GdtTableSize)) {
((UINTN)(StackSwitchData->Ia32.GdtTable) + StackSwitchData->Ia32.GdtTableSize))
{
return EFI_INVALID_PARAMETER;
}
@@ -168,11 +170,14 @@ ArchSetupExceptionStack (
// specified.
//
if (StackSwitchData->Ia32.ExceptionTssDescSize <
sizeof (IA32_TSS_DESCRIPTOR) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1)) {
sizeof (IA32_TSS_DESCRIPTOR) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1))
{
return EFI_INVALID_PARAMETER;
}
if (StackSwitchData->Ia32.ExceptionTssSize <
sizeof (IA32_TASK_STATE_SEGMENT) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1)) {
sizeof (IA32_TASK_STATE_SEGMENT) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1))
{
return EFI_INVALID_PARAMETER;
}
@@ -191,13 +196,14 @@ ArchSetupExceptionStack (
(UINTN)(StackSwitchData->Ia32.GdtTable);
if ((UINTN)StackSwitchData->Ia32.GdtTable != Gdtr.Base) {
CopyMem (StackSwitchData->Ia32.GdtTable, (VOID *)Gdtr.Base, Gdtr.Limit + 1);
Gdtr.Base = (UINTN)StackSwitchData->Ia32.GdtTable;
Gdtr.Base = (UINTN)StackSwitchData->Ia32.GdtTable;
Gdtr.Limit = (UINT16)GdtSize - 1;
}
if ((UINTN)StackSwitchData->Ia32.IdtTable != Idtr.Base) {
Idtr.Base = (UINTN)StackSwitchData->Ia32.IdtTable;
}
if (StackSwitchData->Ia32.IdtTableSize > 0) {
Idtr.Limit = (UINT16)(StackSwitchData->Ia32.IdtTableSize - 1);
}
@@ -208,14 +214,14 @@ ArchSetupExceptionStack (
//
TssBase = (UINTN)Tss;
TssDesc->Uint64 = 0;
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
TssDesc->Bits.P = 1;
TssDesc->Bits.LimitHigh = 0;
TssDesc->Bits.BaseHigh = (UINT8)(TssBase >> 24);
TssDesc->Uint64 = 0;
TssDesc->Bits.LimitLow = sizeof (IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
TssDesc->Bits.P = 1;
TssDesc->Bits.LimitHigh = 0;
TssDesc->Bits.BaseHigh = (UINT8)(TssBase >> 24);
//
// Fixup exception task descriptor and task-state segment
@@ -234,7 +240,7 @@ ArchSetupExceptionStack (
TssBase = (UINTN)Tss;
TssDesc->Uint64 = 0;
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.LimitLow = sizeof (IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
@@ -246,14 +252,15 @@ ArchSetupExceptionStack (
// Fixup TSS
//
Vector = StackSwitchData->Ia32.StackSwitchExceptions[Index];
if (Vector >= CPU_EXCEPTION_NUM ||
Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)) {
if ((Vector >= CPU_EXCEPTION_NUM) ||
(Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)))
{
continue;
}
ZeroMem (Tss, sizeof (*Tss));
Tss->EIP = (UINT32)(TemplateMap.ExceptionStart
+ Vector * TemplateMap.ExceptionStubHeaderSize);
Tss->EIP = (UINT32)(TemplateMap.ExceptionStart
+ Vector * TemplateMap.ExceptionStubHeaderSize);
Tss->EFLAGS = 0x2;
Tss->ESP = StackTop;
Tss->CR3 = AsmReadCr3 ();
@@ -264,7 +271,7 @@ ArchSetupExceptionStack (
Tss->FS = AsmReadFs ();
Tss->GS = AsmReadGs ();
StackTop -= StackSwitchData->Ia32.KnownGoodStackSize;
StackTop -= StackSwitchData->Ia32.KnownGoodStackSize;
//
// Update IDT to use Task Gate for given exception
@@ -303,8 +310,8 @@ ArchSetupExceptionStack (
VOID
EFIAPI
DumpCpuContext (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
InternalPrintMessage (
@@ -331,8 +338,10 @@ DumpCpuContext (
(SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_SGX) != 0
);
}
InternalPrintMessage ("\n");
}
InternalPrintMessage (
"EIP - %08x, CS - %08x, EFLAGS - %08x\n",
SystemContext.SystemContextIa32->Eip,
@@ -406,8 +415,8 @@ DumpCpuContext (
**/
VOID
DumpImageAndCpuContent (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
DumpCpuContext (ExceptionType, SystemContext);
@@ -415,7 +424,8 @@ DumpImageAndCpuContent (
// Dump module image base and module entry point by EIP
//
if ((ExceptionType == EXCEPT_IA32_PAGE_FAULT) &&
((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0)) {
((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0))
{
//
// The EIP in SystemContext could not be used
// if it is page fault with I/D set.

View File

@@ -10,29 +10,29 @@
#define _ARCH_CPU_INTERRUPT_DEFS_H_
typedef struct {
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
BOOLEAN ExceptionDataFlag;
UINTN OldIdtHandler;
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
BOOLEAN ExceptionDataFlag;
UINTN OldIdtHandler;
} EXCEPTION_HANDLER_CONTEXT;
//
// Register Structure Definitions
//
typedef struct {
EFI_STATUS_CODE_DATA Header;
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
EFI_STATUS_CODE_DATA Header;
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
} CPU_STATUS_CODE_TEMPLATE;
typedef struct {
SPIN_LOCK SpinLock;
UINT32 ApicId;
UINT32 Attribute;
UINTN ExceptonHandler;
UINTN OldFlags;
UINTN OldCs;
UINTN OldIp;
UINTN ExceptionData;
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
SPIN_LOCK SpinLock;
UINT32 ApicId;
UINT32 Attribute;
UINTN ExceptonHandler;
UINTN OldFlags;
UINTN OldCs;
UINTN OldIp;
UINTN ExceptionData;
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
} RESERVED_VECTORS_DATA;
#define CPU_TSS_DESC_SIZE \

View File

@@ -13,11 +13,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
CONST UINTN mDoFarReturnFlag = 0;
CONST UINTN mDoFarReturnFlag = 0;
typedef struct {
UINT8 ExceptionStubHeader[HOOKAFTER_STUB_SIZE];
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
UINT8 ExceptionStubHeader[HOOKAFTER_STUB_SIZE];
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
} EXCEPTION0_STUB_HEADER;
/**
@@ -34,9 +34,9 @@ GetExceptionHandlerData (
VOID
)
{
IA32_DESCRIPTOR IdtDescriptor;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
IA32_DESCRIPTOR IdtDescriptor;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
AsmReadIdtr (&IdtDescriptor);
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
@@ -56,12 +56,13 @@ GetExceptionHandlerData (
**/
VOID
SetExceptionHandlerData (
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
IA32_DESCRIPTOR IdtDescriptor;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
IA32_DESCRIPTOR IdtDescriptor;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
//
// Duplicate the exception #0 stub header in pool and cache the ExceptionHandlerData just after the stub header.
// So AP can get the ExceptionHandlerData by reading the IDT[0].
@@ -89,8 +90,8 @@ SetExceptionHandlerData (
VOID
EFIAPI
CommonExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
@@ -120,12 +121,12 @@ CommonExceptionHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
EFI_STATUS Status;
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_STATUS Status;
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);
ASSERT (ReservedVectors != NULL);
@@ -166,7 +167,7 @@ InitializeCpuExceptionHandlers (
EFI_STATUS
EFIAPI
InitializeCpuInterruptHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
return EFI_UNSUPPORTED;
@@ -198,8 +199,8 @@ InitializeCpuInterruptHandlers (
EFI_STATUS
EFIAPI
RegisterCpuInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
)
{
return EFI_UNSUPPORTED;
@@ -230,11 +231,11 @@ RegisterCpuInterruptHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlersEx (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// To avoid repeat initialization of default handlers, the caller should pass
@@ -243,7 +244,7 @@ InitializeCpuExceptionHandlersEx (
// version instead; or this method must be implemented as a simple wrapper of
// non-ex version of it, if this version has to be called.
//
if (InitData == NULL || InitData->Ia32.InitDefaultHandlers) {
if ((InitData == NULL) || InitData->Ia32.InitDefaultHandlers) {
Status = InitializeCpuExceptionHandlers (VectorInfo);
} else {
Status = EFI_SUCCESS;
@@ -253,10 +254,10 @@ InitializeCpuExceptionHandlersEx (
//
// Initializing stack switch is only necessary for Stack Guard functionality.
//
if (PcdGetBool (PcdCpuStackGuard) && InitData != NULL) {
if (PcdGetBool (PcdCpuStackGuard) && (InitData != NULL)) {
Status = ArchSetupExceptionStack (InitData);
}
}
return Status;
return Status;
}

View File

@@ -19,14 +19,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
CommonExceptionHandlerWorker (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
EXCEPTION_HANDLER_CONTEXT *ExceptionHandlerContext;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
EXCEPTION_HANDLER_CONTEXT *ExceptionHandlerContext;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
if (ExceptionType == VC_EXCEPTION) {
EFI_STATUS Status;
@@ -45,68 +45,72 @@ CommonExceptionHandlerWorker (
}
}
ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (SystemContext.SystemContextIa32);
ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *)(UINTN)(SystemContext.SystemContextIa32);
ReservedVectors = ExceptionHandlerData->ReservedVectors;
ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler;
switch (ReservedVectors[ExceptionType].Attribute) {
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
//
// The new exception handler registered by RegisterCpuInterruptHandler() is executed BEFORE original handler.
// Save the original handler to stack so the assembly code can jump to it instead of returning from handler.
//
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
break;
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
while (TRUE) {
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
//
// If spin-lock can be acquired, it's the first time entering here.
// The new exception handler registered by RegisterCpuInterruptHandler() is executed BEFORE original handler.
// Save the original handler to stack so the assembly code can jump to it instead of returning from handler.
//
if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
break;
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
while (TRUE) {
//
// The new exception handler registered by RegisterCpuInterruptHandler() is executed AFTER original handler.
// Save the original handler to stack but skip running the new handler so the original handler is executed
// firstly.
// If spin-lock can be acquired, it's the first time entering here.
//
ReservedVectors[ExceptionType].ApicId = GetApicId ();
ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
return;
if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {
//
// The new exception handler registered by RegisterCpuInterruptHandler() is executed AFTER original handler.
// Save the original handler to stack but skip running the new handler so the original handler is executed
// firstly.
//
ReservedVectors[ExceptionType].ApicId = GetApicId ();
ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
return;
}
//
// If spin-lock cannot be acquired, it's the second time entering here.
// 'break' instead of 'return' is used so the new exception handler can be executed.
//
if (ReservedVectors[ExceptionType].ApicId == GetApicId ()) {
//
// Old IDT handler has been executed, then restore CPU exception content to
// run new exception handler.
//
ArchRestoreExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
//
// Release spin lock for ApicId
//
ReleaseSpinLock (&ReservedVectors[ExceptionType].SpinLock);
break;
}
CpuPause ();
}
break;
case 0xffffffff:
break;
default:
//
// If spin-lock cannot be acquired, it's the second time entering here.
// 'break' instead of 'return' is used so the new exception handler can be executed.
// It should never reach here
//
if (ReservedVectors[ExceptionType].ApicId == GetApicId ()) {
//
// Old IDT handler has been executed, then restore CPU exception content to
// run new exception handler.
//
ArchRestoreExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
//
// Release spin lock for ApicId
//
ReleaseSpinLock (&ReservedVectors[ExceptionType].SpinLock);
break;
}
CpuPause ();
}
break;
case 0xffffffff:
break;
default:
//
// It should never reach here
//
CpuDeadLoop ();
break;
CpuDeadLoop ();
break;
}
if (ExternalInterruptHandler != NULL &&
ExternalInterruptHandler[ExceptionType] != NULL) {
(ExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContext);
if ((ExternalInterruptHandler != NULL) &&
(ExternalInterruptHandler[ExceptionType] != NULL))
{
(ExternalInterruptHandler[ExceptionType])(ExceptionType, SystemContext);
} else if (ExceptionType < CPU_EXCEPTION_NUM) {
//
// Get Spinlock to display CPU information
@@ -114,6 +118,7 @@ CommonExceptionHandlerWorker (
while (!AcquireSpinLockOrFail (&ExceptionHandlerData->DisplayMessageSpinLock)) {
CpuPause ();
}
//
// Initialize the serial port before dumping.
//
@@ -151,10 +156,10 @@ UpdateIdtTable (
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
UINT16 CodeSegment;
UINTN Index;
UINTN InterruptHandler;
RESERVED_VECTORS_DATA *ReservedVectors;
UINT16 CodeSegment;
UINTN Index;
UINTN InterruptHandler;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
//
@@ -162,47 +167,47 @@ UpdateIdtTable (
//
CodeSegment = AsmReadCs ();
for (Index = 0; Index < ExceptionHandlerData->IdtEntryCount; Index ++) {
for (Index = 0; Index < ExceptionHandlerData->IdtEntryCount; Index++) {
IdtTable[Index].Bits.Selector = CodeSegment;
//
// Check reserved vectors attributes
//
switch (ReservedVectors[Index].Attribute) {
case EFI_VECTOR_HANDOFF_DO_NOT_HOOK:
//
// Keep original IDT entry
//
continue;
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
InitializeSpinLock (&ReservedVectors[Index].SpinLock);
CopyMem (
(VOID *) ReservedVectors[Index].HookAfterStubHeaderCode,
(VOID *) TemplateMap->HookAfterStubHeaderStart,
TemplateMap->ExceptionStubHeaderSize
);
AsmVectorNumFixup (
(VOID *) ReservedVectors[Index].HookAfterStubHeaderCode,
(UINT8) Index,
(VOID *) TemplateMap->HookAfterStubHeaderStart
);
case EFI_VECTOR_HANDOFF_DO_NOT_HOOK:
//
// Keep original IDT entry
//
continue;
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
InitializeSpinLock (&ReservedVectors[Index].SpinLock);
CopyMem (
(VOID *)ReservedVectors[Index].HookAfterStubHeaderCode,
(VOID *)TemplateMap->HookAfterStubHeaderStart,
TemplateMap->ExceptionStubHeaderSize
);
AsmVectorNumFixup (
(VOID *)ReservedVectors[Index].HookAfterStubHeaderCode,
(UINT8)Index,
(VOID *)TemplateMap->HookAfterStubHeaderStart
);
//
// Go on the following code
//
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
//
// Save original IDT handler address
//
ReservedVectors[Index].ExceptonHandler = ArchGetIdtHandler (&IdtTable[Index]);
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
//
// Save original IDT handler address
//
ReservedVectors[Index].ExceptonHandler = ArchGetIdtHandler (&IdtTable[Index]);
//
// Go on the following code
//
default:
//
// Update new IDT entry
//
InterruptHandler = TemplateMap->ExceptionStart + Index * TemplateMap->ExceptionStubHeaderSize;
ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
break;
default:
//
// Update new IDT entry
//
InterruptHandler = TemplateMap->ExceptionStart + Index * TemplateMap->ExceptionStubHeaderSize;
ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
break;
}
}
}
@@ -221,19 +226,19 @@ UpdateIdtTable (
**/
EFI_STATUS
InitializeCpuExceptionHandlersWorker (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
EFI_STATUS Status;
IA32_DESCRIPTOR IdtDescriptor;
UINTN IdtEntryCount;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_STATUS Status;
IA32_DESCRIPTOR IdtDescriptor;
UINTN IdtEntryCount;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
if (VectorInfo != NULL) {
Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_EXCEPTION_NUM);
if (EFI_ERROR (Status)) {
@@ -253,7 +258,7 @@ InitializeCpuExceptionHandlersWorker (
IdtEntryCount = CPU_EXCEPTION_NUM;
}
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
AsmGetTemplateAddressMap (&TemplateMap);
ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
@@ -282,33 +287,33 @@ InitializeCpuExceptionHandlersWorker (
**/
EFI_STATUS
RegisterCpuInterruptHandlerWorker (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
UINTN EnabledInterruptNum;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
UINTN EnabledInterruptNum;
RESERVED_VECTORS_DATA *ReservedVectors;
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
EnabledInterruptNum = ExceptionHandlerData->IdtEntryCount;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler;
if (InterruptType < 0 || InterruptType >= (EFI_EXCEPTION_TYPE)EnabledInterruptNum ||
ReservedVectors[InterruptType].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {
if ((InterruptType < 0) || (InterruptType >= (EFI_EXCEPTION_TYPE)EnabledInterruptNum) ||
(ReservedVectors[InterruptType].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK))
{
return EFI_UNSUPPORTED;
}
if (InterruptHandler == NULL && ExternalInterruptHandler[InterruptType] == NULL) {
if ((InterruptHandler == NULL) && (ExternalInterruptHandler[InterruptType] == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (InterruptHandler != NULL && ExternalInterruptHandler[InterruptType] != NULL) {
if ((InterruptHandler != NULL) && (ExternalInterruptHandler[InterruptType] != NULL)) {
return EFI_ALREADY_STARTED;
}
ExternalInterruptHandler[InterruptType] = InterruptHandler;
return EFI_SUCCESS;
}

View File

@@ -10,7 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/VmgExitLib.h>
#include "CpuExceptionCommon.h"
CONST UINTN mDoFarReturnFlag = 0;
CONST UINTN mDoFarReturnFlag = 0;
/**
Common exception handler.
@@ -21,8 +21,8 @@ CONST UINTN mDoFarReturnFlag = 0;
VOID
EFIAPI
CommonExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
if (ExceptionType == VC_EXCEPTION) {
@@ -79,26 +79,27 @@ CommonExceptionHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
EFI_STATUS Status;
RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];
IA32_DESCRIPTOR IdtDescriptor;
UINTN IdtEntryCount;
UINT16 CodeSegment;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
UINTN Index;
UINTN InterruptHandler;
EFI_STATUS Status;
RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];
IA32_DESCRIPTOR IdtDescriptor;
UINTN IdtEntryCount;
UINT16 CodeSegment;
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
UINTN Index;
UINTN InterruptHandler;
if (VectorInfo != NULL) {
SetMem ((VOID *) ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
SetMem ((VOID *)ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);
if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
}
//
// Read IDT descriptor and calculate IDT size
//
@@ -110,6 +111,7 @@ InitializeCpuExceptionHandlers (
//
IdtEntryCount = CPU_EXCEPTION_NUM;
}
//
// Use current CS as the segment selector of interrupt gate in IDT
//
@@ -117,7 +119,7 @@ InitializeCpuExceptionHandlers (
AsmGetTemplateAddressMap (&TemplateMap);
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
for (Index = 0; Index < IdtEntryCount; Index ++) {
for (Index = 0; Index < IdtEntryCount; Index++) {
IdtTable[Index].Bits.Selector = CodeSegment;
//
// Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK
@@ -128,12 +130,14 @@ InitializeCpuExceptionHandlers (
continue;
}
}
//
// Update IDT entry
//
InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;
ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
}
return EFI_SUCCESS;
}
@@ -156,7 +160,7 @@ InitializeCpuExceptionHandlers (
EFI_STATUS
EFIAPI
InitializeCpuInterruptHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
return EFI_UNSUPPORTED;
@@ -188,8 +192,8 @@ InitializeCpuInterruptHandlers (
EFI_STATUS
EFIAPI
RegisterCpuInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
)
{
return EFI_UNSUPPORTED;
@@ -220,8 +224,8 @@ RegisterCpuInterruptHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlersEx (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
)
{
return InitializeCpuExceptionHandlers (VectorInfo);

View File

@@ -9,16 +9,17 @@
#include <PiSmm.h>
#include "CpuExceptionCommon.h"
CONST UINTN mDoFarReturnFlag = 1;
CONST UINTN mDoFarReturnFlag = 1;
//
// Spin lock for CPU information display
//
SPIN_LOCK mDisplayMessageSpinLock;
SPIN_LOCK mDisplayMessageSpinLock;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
/**
Common exception handler.
@@ -28,8 +29,8 @@ EXCEPTION_HANDLER_DATA mExceptionHandlerData;
VOID
EFIAPI
CommonExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
@@ -54,7 +55,7 @@ CommonExceptionHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
mExceptionHandlerData.ReservedVectors = mReservedVectorsData;
@@ -82,7 +83,7 @@ InitializeCpuExceptionHandlers (
EFI_STATUS
EFIAPI
InitializeCpuInterruptHandlers (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
)
{
return EFI_UNSUPPORTED;
@@ -114,8 +115,8 @@ InitializeCpuInterruptHandlers (
EFI_STATUS
EFIAPI
RegisterCpuInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
)
{
return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
@@ -146,8 +147,8 @@ RegisterCpuInterruptHandler (
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlersEx (
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
)
{
return InitializeCpuExceptionHandlers (VectorInfo);

View File

@@ -17,8 +17,8 @@
**/
VOID
ArchUpdateIdtEntry (
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
IN UINTN InterruptHandler
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
IN UINTN InterruptHandler
)
{
IdtEntry->Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
@@ -35,11 +35,11 @@ ArchUpdateIdtEntry (
**/
UINTN
ArchGetIdtHandler (
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
)
{
return IdtEntry->Bits.OffsetLow + (((UINTN) IdtEntry->Bits.OffsetHigh) << 16) +
(((UINTN) IdtEntry->Bits.OffsetUpper) << 32);
return IdtEntry->Bits.OffsetLow + (((UINTN)IdtEntry->Bits.OffsetHigh) << 16) +
(((UINTN)IdtEntry->Bits.OffsetUpper) << 32);
}
/**
@@ -51,13 +51,13 @@ ArchGetIdtHandler (
**/
VOID
ArchSaveExceptionContext (
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
IA32_EFLAGS32 Eflags;
RESERVED_VECTORS_DATA *ReservedVectors;
IA32_EFLAGS32 Eflags;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
//
@@ -74,13 +74,13 @@ ArchSaveExceptionContext (
//
// Clear IF flag to avoid old IDT handler enable interrupt by IRET
//
Eflags.UintN = SystemContext.SystemContextX64->Rflags;
Eflags.Bits.IF = 0;
Eflags.UintN = SystemContext.SystemContextX64->Rflags;
Eflags.Bits.IF = 0;
SystemContext.SystemContextX64->Rflags = Eflags.UintN;
//
// Modify the EIP in stack, then old IDT handler will return to HookAfterStubBegin.
//
SystemContext.SystemContextX64->Rip = (UINTN) ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
SystemContext.SystemContextX64->Rip = (UINTN)ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
}
/**
@@ -92,14 +92,14 @@ ArchSaveExceptionContext (
**/
VOID
ArchRestoreExceptionContext (
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
IN UINTN ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext,
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
)
{
RESERVED_VECTORS_DATA *ReservedVectors;
RESERVED_VECTORS_DATA *ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
ReservedVectors = ExceptionHandlerData->ReservedVectors;
SystemContext.SystemContextX64->Ss = ReservedVectors[ExceptionType].OldSs;
SystemContext.SystemContextX64->Rsp = ReservedVectors[ExceptionType].OldSp;
SystemContext.SystemContextX64->Rflags = ReservedVectors[ExceptionType].OldFlags;
@@ -121,31 +121,32 @@ ArchRestoreExceptionContext (
**/
EFI_STATUS
ArchSetupExceptionStack (
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
)
{
IA32_DESCRIPTOR Gdtr;
IA32_DESCRIPTOR Idtr;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
IA32_TSS_DESCRIPTOR *TssDesc;
IA32_TASK_STATE_SEGMENT *Tss;
UINTN StackTop;
UINTN Index;
UINTN Vector;
UINTN TssBase;
UINTN GdtSize;
IA32_DESCRIPTOR Gdtr;
IA32_DESCRIPTOR Idtr;
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
IA32_TSS_DESCRIPTOR *TssDesc;
IA32_TASK_STATE_SEGMENT *Tss;
UINTN StackTop;
UINTN Index;
UINTN Vector;
UINTN TssBase;
UINTN GdtSize;
if (StackSwitchData == NULL ||
StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV ||
StackSwitchData->X64.KnownGoodStackTop == 0 ||
StackSwitchData->X64.KnownGoodStackSize == 0 ||
StackSwitchData->X64.StackSwitchExceptions == NULL ||
StackSwitchData->X64.StackSwitchExceptionNumber == 0 ||
StackSwitchData->X64.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM ||
StackSwitchData->X64.GdtTable == NULL ||
StackSwitchData->X64.IdtTable == NULL ||
StackSwitchData->X64.ExceptionTssDesc == NULL ||
StackSwitchData->X64.ExceptionTss == NULL) {
if ((StackSwitchData == NULL) ||
(StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV) ||
(StackSwitchData->X64.KnownGoodStackTop == 0) ||
(StackSwitchData->X64.KnownGoodStackSize == 0) ||
(StackSwitchData->X64.StackSwitchExceptions == NULL) ||
(StackSwitchData->X64.StackSwitchExceptionNumber == 0) ||
(StackSwitchData->X64.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM) ||
(StackSwitchData->X64.GdtTable == NULL) ||
(StackSwitchData->X64.IdtTable == NULL) ||
(StackSwitchData->X64.ExceptionTssDesc == NULL) ||
(StackSwitchData->X64.ExceptionTss == NULL))
{
return EFI_INVALID_PARAMETER;
}
@@ -163,7 +164,8 @@ ArchSetupExceptionStack (
}
if (((UINTN)StackSwitchData->X64.ExceptionTssDesc + StackSwitchData->X64.ExceptionTssDescSize) >
((UINTN)(StackSwitchData->X64.GdtTable) + StackSwitchData->X64.GdtTableSize)) {
((UINTN)(StackSwitchData->X64.GdtTable) + StackSwitchData->X64.GdtTableSize))
{
return EFI_INVALID_PARAMETER;
}
@@ -173,6 +175,7 @@ ArchSetupExceptionStack (
if (StackSwitchData->X64.ExceptionTssDescSize < sizeof (IA32_TSS_DESCRIPTOR)) {
return EFI_INVALID_PARAMETER;
}
if (StackSwitchData->X64.ExceptionTssSize < sizeof (IA32_TASK_STATE_SEGMENT)) {
return EFI_INVALID_PARAMETER;
}
@@ -196,13 +199,14 @@ ArchSetupExceptionStack (
(UINTN)(StackSwitchData->X64.GdtTable);
if ((UINTN)StackSwitchData->X64.GdtTable != Gdtr.Base) {
CopyMem (StackSwitchData->X64.GdtTable, (VOID *)Gdtr.Base, Gdtr.Limit + 1);
Gdtr.Base = (UINTN)StackSwitchData->X64.GdtTable;
Gdtr.Base = (UINTN)StackSwitchData->X64.GdtTable;
Gdtr.Limit = (UINT16)GdtSize - 1;
}
if ((UINTN)StackSwitchData->X64.IdtTable != Idtr.Base) {
Idtr.Base = (UINTN)StackSwitchData->X64.IdtTable;
}
if (StackSwitchData->X64.IdtTableSize > 0) {
Idtr.Limit = (UINT16)(StackSwitchData->X64.IdtTableSize - 1);
}
@@ -213,16 +217,16 @@ ArchSetupExceptionStack (
//
TssBase = (UINTN)Tss;
TssDesc->Uint128.Uint64 = 0;
TssDesc->Uint128.Uint64_1= 0;
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMidl = (UINT8)(TssBase >> 16);
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
TssDesc->Bits.P = 1;
TssDesc->Bits.LimitHigh = 0;
TssDesc->Bits.BaseMidh = (UINT8)(TssBase >> 24);
TssDesc->Bits.BaseHigh = (UINT32)(TssBase >> 32);
TssDesc->Uint128.Uint64 = 0;
TssDesc->Uint128.Uint64_1 = 0;
TssDesc->Bits.LimitLow = sizeof (IA32_TASK_STATE_SEGMENT) - 1;
TssDesc->Bits.BaseLow = (UINT16)TssBase;
TssDesc->Bits.BaseMidl = (UINT8)(TssBase >> 16);
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
TssDesc->Bits.P = 1;
TssDesc->Bits.LimitHigh = 0;
TssDesc->Bits.BaseMidh = (UINT8)(TssBase >> 24);
TssDesc->Bits.BaseHigh = (UINT32)(TssBase >> 32);
//
// Fixup exception task descriptor and task-state segment
@@ -236,16 +240,18 @@ ArchSetupExceptionStack (
// Fixup IST
//
Tss->IST[Index] = StackTop;
StackTop -= StackSwitchData->X64.KnownGoodStackSize;
StackTop -= StackSwitchData->X64.KnownGoodStackSize;
//
// Set the IST field to enable corresponding IST
//
Vector = StackSwitchData->X64.StackSwitchExceptions[Index];
if (Vector >= CPU_EXCEPTION_NUM ||
Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)) {
if ((Vector >= CPU_EXCEPTION_NUM) ||
(Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)))
{
continue;
}
IdtTable[Vector].Bits.Reserved_0 = (UINT8)(Index + 1);
}
@@ -276,8 +282,8 @@ ArchSetupExceptionStack (
VOID
EFIAPI
DumpCpuContext (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
InternalPrintMessage (
@@ -304,8 +310,10 @@ DumpCpuContext (
(SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_SGX) != 0
);
}
InternalPrintMessage ("\n");
}
InternalPrintMessage (
"RIP - %016lx, CS - %016lx, RFLAGS - %016lx\n",
SystemContext.SystemContextX64->Rip,
@@ -406,8 +414,8 @@ DumpCpuContext (
**/
VOID
DumpImageAndCpuContent (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
DumpCpuContext (ExceptionType, SystemContext);
@@ -415,7 +423,8 @@ DumpImageAndCpuContent (
// Dump module image base and module entry point by RIP
//
if ((ExceptionType == EXCEPT_IA32_PAGE_FAULT) &&
((SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_ID) != 0)) {
((SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_ID) != 0))
{
//
// The RIP in SystemContext could not be used
// if it is page fault with I/D set.

View File

@@ -10,9 +10,9 @@
#define _ARCH_CPU_INTERRUPT_DEFS_H_
typedef struct {
EFI_SYSTEM_CONTEXT_X64 SystemContext;
BOOLEAN ExceptionDataFlag;
UINTN OldIdtHandler;
EFI_SYSTEM_CONTEXT_X64 SystemContext;
BOOLEAN ExceptionDataFlag;
UINTN OldIdtHandler;
} EXCEPTION_HANDLER_CONTEXT;
//
@@ -24,20 +24,20 @@ typedef struct {
} CPU_STATUS_CODE_TEMPLATE;
typedef struct {
SPIN_LOCK SpinLock;
UINT32 ApicId;
UINT32 Attribute;
UINTN ExceptonHandler;
UINTN OldSs;
UINTN OldSp;
UINTN OldFlags;
UINTN OldCs;
UINTN OldIp;
UINTN ExceptionData;
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
SPIN_LOCK SpinLock;
UINT32 ApicId;
UINT32 Attribute;
UINTN ExceptonHandler;
UINTN OldSs;
UINTN OldSp;
UINTN OldFlags;
UINTN OldCs;
UINTN OldIp;
UINTN ExceptionData;
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
} RESERVED_VECTORS_DATA;
#define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR)
#define CPU_TSS_SIZE sizeof (IA32_TASK_STATE_SEGMENT)
#define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR)
#define CPU_TSS_SIZE sizeof (IA32_TASK_STATE_SEGMENT)
#endif

View File

@@ -38,4 +38,3 @@ InternalGetPerformanceCounterFrequency (
{
return CpuidCoreClockCalculateTscFrequency ();
}

View File

@@ -13,7 +13,9 @@
#include <Library/DebugLib.h>
#include <Register/Cpuid.h>
GUID mCpuCrystalFrequencyHobGuid = { 0xe1ec5ad0, 0x8569, 0x46bd, { 0x8d, 0xcd, 0x3b, 0x9f, 0x6f, 0x45, 0x82, 0x7a } };
GUID mCpuCrystalFrequencyHobGuid = {
0xe1ec5ad0, 0x8569, 0x46bd, { 0x8d, 0xcd, 0x3b, 0x9f, 0x6f, 0x45, 0x82, 0x7a }
};
/**
Internal function to retrieves the 64-bit frequency in Hz.
@@ -41,11 +43,11 @@ CpuidCoreClockCalculateTscFrequency (
VOID
)
{
UINT64 TscFrequency;
UINT64 CoreXtalFrequency;
UINT32 RegEax;
UINT32 RegEbx;
UINT32 RegEcx;
UINT64 TscFrequency;
UINT64 CoreXtalFrequency;
UINT32 RegEax;
UINT32 RegEbx;
UINT32 RegEcx;
//
// Use CPUID leaf 0x15 Time Stamp Counter and Nominal Core Crystal Clock Information
@@ -57,11 +59,12 @@ CpuidCoreClockCalculateTscFrequency (
//
// If EAX or EBX returns 0, the XTAL ratio is not enumerated.
//
if (RegEax == 0 || RegEbx ==0 ) {
if ((RegEax == 0) || (RegEbx == 0)) {
ASSERT (RegEax != 0);
ASSERT (RegEbx != 0);
return 0;
}
//
// If ECX returns 0, the XTAL frequency is not enumerated.
// And PcdCpuCoreCrystalClockFrequency defined should base on processor series.
@@ -69,7 +72,7 @@ CpuidCoreClockCalculateTscFrequency (
if (RegEcx == 0) {
CoreXtalFrequency = PcdGet64 (PcdCpuCoreCrystalClockFrequency);
} else {
CoreXtalFrequency = (UINT64) RegEcx;
CoreXtalFrequency = (UINT64)RegEcx;
}
//
@@ -99,7 +102,7 @@ InternalCpuDelay (
//
// The target timer count is calculated here
//
Ticks = AsmReadTsc() + Delay;
Ticks = AsmReadTsc () + Delay;
//
// Wait until time out
@@ -107,8 +110,8 @@ InternalCpuDelay (
// Thus, this function must be called within 10 years of reset since
// Intel guarantees a minimum of 10 years before the TSC wraps.
//
while (AsmReadTsc() <= Ticks) {
CpuPause();
while (AsmReadTsc () <= Ticks) {
CpuPause ();
}
}
@@ -128,7 +131,6 @@ MicroSecondDelay (
IN UINTN MicroSeconds
)
{
InternalCpuDelay (
DivU64x32 (
MultU64x64 (
@@ -136,8 +138,8 @@ MicroSecondDelay (
InternalGetPerformanceCounterFrequency ()
),
1000000u
)
);
)
);
return MicroSeconds;
}
@@ -158,7 +160,6 @@ NanoSecondDelay (
IN UINTN NanoSeconds
)
{
InternalCpuDelay (
DivU64x32 (
MultU64x64 (
@@ -166,8 +167,8 @@ NanoSecondDelay (
InternalGetPerformanceCounterFrequency ()
),
1000000000u
)
);
)
);
return NanoSeconds;
}
@@ -230,6 +231,7 @@ GetPerformanceCounterProperties (
if (EndValue != NULL) {
*EndValue = 0xffffffffffffffffULL;
}
return InternalGetPerformanceCounterFrequency ();
}
@@ -269,9 +271,9 @@ GetTimeInNanoSecond (
// Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
// i.e. highest bit set in Remainder should <= 33.
//
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
Remainder = RShiftU64 (Remainder, (UINTN) Shift);
Frequency = RShiftU64 (Frequency, (UINTN) Shift);
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
Remainder = RShiftU64 (Remainder, (UINTN)Shift);
Frequency = RShiftU64 (Frequency, (UINTN)Shift);
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
return NanoSeconds;

View File

@@ -25,7 +25,7 @@ GetProcessorMicrocodeSignature (
VOID
)
{
MSR_IA32_BIOS_SIGN_ID_REGISTER BiosSignIdMsr;
MSR_IA32_BIOS_SIGN_ID_REGISTER BiosSignIdMsr;
AsmWriteMsr64 (MSR_IA32_BIOS_SIGN_ID, 0);
AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, NULL);
@@ -44,12 +44,12 @@ GetProcessorMicrocodeCpuId (
EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId
)
{
MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr;
MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr;
ASSERT (MicrocodeCpuId != NULL);
PlatformIdMsr.Uint64 = AsmReadMsr64 (MSR_IA32_PLATFORM_ID);
MicrocodeCpuId->PlatformId = (UINT8) PlatformIdMsr.Bits.PlatformId;
PlatformIdMsr.Uint64 = AsmReadMsr64 (MSR_IA32_PLATFORM_ID);
MicrocodeCpuId->PlatformId = (UINT8)PlatformIdMsr.Bits.PlatformId;
AsmCpuid (CPUID_VERSION_INFO, &MicrocodeCpuId->ProcessorSignature, NULL, NULL, NULL);
}
@@ -71,10 +71,10 @@ GetProcessorMicrocodeCpuId (
UINT32
EFIAPI
GetMicrocodeLength (
IN CPU_MICROCODE_HEADER *Microcode
IN CPU_MICROCODE_HEADER *Microcode
)
{
UINT32 TotalSize;
UINT32 TotalSize;
ASSERT (Microcode != NULL);
@@ -82,6 +82,7 @@ GetMicrocodeLength (
if (Microcode->DataSize != 0) {
TotalSize = Microcode->TotalSize;
}
return TotalSize;
}
@@ -95,12 +96,12 @@ GetMicrocodeLength (
VOID
EFIAPI
LoadMicrocode (
IN CPU_MICROCODE_HEADER *Microcode
IN CPU_MICROCODE_HEADER *Microcode
)
{
ASSERT (Microcode != NULL);
AsmWriteMsr64 (MSR_IA32_BIOS_UPDT_TRIG, (UINT64) (UINTN) (Microcode + 1));
AsmWriteMsr64 (MSR_IA32_BIOS_UPDT_TRIG, (UINT64)(UINTN)(Microcode + 1));
}
/**
@@ -119,13 +120,13 @@ LoadMicrocode (
**/
BOOLEAN
IsProcessorMatchedMicrocode (
IN UINT32 ProcessorSignature,
IN UINT32 ProcessorFlags,
IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId,
IN UINTN MicrocodeCpuIdCount
IN UINT32 ProcessorSignature,
IN UINT32 ProcessorFlags,
IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId,
IN UINTN MicrocodeCpuIdCount
)
{
UINTN Index;
UINTN Index;
if (MicrocodeCpuIdCount == 0) {
return TRUE;
@@ -133,7 +134,8 @@ IsProcessorMatchedMicrocode (
for (Index = 0; Index < MicrocodeCpuIdCount; Index++) {
if ((ProcessorSignature == MicrocodeCpuId[Index].ProcessorSignature) &&
(ProcessorFlags & (1 << MicrocodeCpuId[Index].PlatformId)) != 0) {
((ProcessorFlags & (1 << MicrocodeCpuId[Index].PlatformId)) != 0))
{
return TRUE;
}
}
@@ -182,22 +184,22 @@ IsProcessorMatchedMicrocode (
BOOLEAN
EFIAPI
IsValidMicrocode (
IN CPU_MICROCODE_HEADER *Microcode,
IN UINTN MicrocodeLength,
IN UINT32 MinimumRevision,
IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuIds,
IN UINTN MicrocodeCpuIdCount,
IN BOOLEAN VerifyChecksum
IN CPU_MICROCODE_HEADER *Microcode,
IN UINTN MicrocodeLength,
IN UINT32 MinimumRevision,
IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuIds,
IN UINTN MicrocodeCpuIdCount,
IN BOOLEAN VerifyChecksum
)
{
UINTN Index;
UINT32 DataSize;
UINT32 TotalSize;
CPU_MICROCODE_EXTENDED_TABLE *ExtendedTable;
CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader;
UINT32 ExtendedTableLength;
UINT32 Sum32;
BOOLEAN Match;
UINTN Index;
UINT32 DataSize;
UINT32 TotalSize;
CPU_MICROCODE_EXTENDED_TABLE *ExtendedTable;
CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader;
UINT32 ExtendedTableLength;
UINT32 Sum32;
BOOLEAN Match;
ASSERT (Microcode != NULL);
@@ -206,7 +208,7 @@ IsValidMicrocode (
// the input microcode buffer is so small that even cannot contain the header.
// the input microcode buffer is so large that exceeds MAX_ADDRESS.
//
if ((MicrocodeLength < sizeof (CPU_MICROCODE_HEADER)) || (MicrocodeLength > (MAX_ADDRESS - (UINTN) Microcode))) {
if ((MicrocodeLength < sizeof (CPU_MICROCODE_HEADER)) || (MicrocodeLength > (MAX_ADDRESS - (UINTN)Microcode))) {
return FALSE;
}
@@ -249,7 +251,7 @@ IsValidMicrocode (
//
// The summation of all DWORDs in microcode should be zero.
//
if (VerifyChecksum && (CalculateSum32 ((UINT32 *) Microcode, TotalSize) != 0)) {
if (VerifyChecksum && (CalculateSum32 ((UINT32 *)Microcode, TotalSize) != 0)) {
return FALSE;
}
@@ -272,29 +274,34 @@ IsValidMicrocode (
if ((ExtendedTableLength < sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER)) || ((ExtendedTableLength % 4) != 0)) {
return FALSE;
}
//
// Extended Table exist, check if the CPU in support list
//
ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *) ((UINTN) (Microcode + 1) + DataSize);
ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *)((UINTN)(Microcode + 1) + DataSize);
if (ExtendedTableHeader->ExtendedSignatureCount > MAX_UINT32 / sizeof (CPU_MICROCODE_EXTENDED_TABLE)) {
return FALSE;
}
if (ExtendedTableHeader->ExtendedSignatureCount * sizeof (CPU_MICROCODE_EXTENDED_TABLE)
> ExtendedTableLength - sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER)) {
return FALSE;
}
//
// Check the extended table checksum
//
if (VerifyChecksum && (CalculateSum32 ((UINT32 *) ExtendedTableHeader, ExtendedTableLength) != 0)) {
> ExtendedTableLength - sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER))
{
return FALSE;
}
ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *) (ExtendedTableHeader + 1);
for (Index = 0; Index < ExtendedTableHeader->ExtendedSignatureCount; Index ++) {
//
// Check the extended table checksum
//
if (VerifyChecksum && (CalculateSum32 ((UINT32 *)ExtendedTableHeader, ExtendedTableLength) != 0)) {
return FALSE;
}
ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *)(ExtendedTableHeader + 1);
for (Index = 0; Index < ExtendedTableHeader->ExtendedSignatureCount; Index++) {
if (VerifyChecksum &&
(ExtendedTable[Index].ProcessorSignature.Uint32 + ExtendedTable[Index].ProcessorFlag
+ ExtendedTable[Index].Checksum != Sum32)) {
+ ExtendedTable[Index].Checksum != Sum32))
{
//
// The extended table entry is valid when the summation of Processor Signature, Processor Flags
// and Checksum equal to the coresponding summation from primary header. Because:
@@ -308,6 +315,7 @@ IsValidMicrocode (
//
continue;
}
Match = IsProcessorMatchedMicrocode (
ExtendedTable[Index].ProcessorSignature.Uint32,
ExtendedTable[Index].ProcessorFlag,
@@ -318,5 +326,6 @@ IsValidMicrocode (
return TRUE;
}
}
return FALSE;
}

View File

@@ -18,21 +18,21 @@
#include <Protocol/Timer.h>
#define AP_SAFE_STACK_SIZE 128
#define AP_SAFE_STACK_SIZE 128
CPU_MP_DATA *mCpuMpData = NULL;
EFI_EVENT mCheckAllApsEvent = NULL;
EFI_EVENT mMpInitExitBootServicesEvent = NULL;
EFI_EVENT mLegacyBootEvent = NULL;
volatile BOOLEAN mStopCheckAllApsStatus = TRUE;
VOID *mReservedApLoopFunc = NULL;
UINTN mReservedTopOfApStack;
volatile UINT32 mNumberToFinish = 0;
CPU_MP_DATA *mCpuMpData = NULL;
EFI_EVENT mCheckAllApsEvent = NULL;
EFI_EVENT mMpInitExitBootServicesEvent = NULL;
EFI_EVENT mLegacyBootEvent = NULL;
volatile BOOLEAN mStopCheckAllApsStatus = TRUE;
VOID *mReservedApLoopFunc = NULL;
UINTN mReservedTopOfApStack;
volatile UINT32 mNumberToFinish = 0;
//
// Begin wakeup buffer allocation below 0x88000
//
STATIC EFI_PHYSICAL_ADDRESS mSevEsDxeWakeupBuffer = 0x88000;
STATIC EFI_PHYSICAL_ADDRESS mSevEsDxeWakeupBuffer = 0x88000;
/**
Enable Debug Agent to support source debugging on AP function.
@@ -70,7 +70,7 @@ GetCpuMpData (
**/
VOID
SaveCpuMpData (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
)
{
mCpuMpData = CpuMpData;
@@ -86,12 +86,12 @@ SaveCpuMpData (
**/
UINTN
GetWakeupBuffer (
IN UINTN WakeupBufferSize
IN UINTN WakeupBufferSize
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS StartAddress;
EFI_MEMORY_TYPE MemoryType;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS StartAddress;
EFI_MEMORY_TYPE MemoryType;
if (PcdGetBool (PcdSevEsIsEnabled)) {
MemoryType = EfiReservedMemoryType;
@@ -115,6 +115,7 @@ GetWakeupBuffer (
} else {
StartAddress = 0x88000;
}
Status = gBS->AllocatePages (
AllocateMaxAddress,
MemoryType,
@@ -123,7 +124,7 @@ GetWakeupBuffer (
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
StartAddress = (EFI_PHYSICAL_ADDRESS) -1;
StartAddress = (EFI_PHYSICAL_ADDRESS)-1;
} else if (PcdGetBool (PcdSevEsIsEnabled)) {
//
// Next SEV-ES wakeup buffer allocation must be below this allocation
@@ -131,10 +132,14 @@ GetWakeupBuffer (
mSevEsDxeWakeupBuffer = StartAddress;
}
DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
(UINTN) StartAddress, WakeupBufferSize));
DEBUG ((
DEBUG_INFO,
"WakeupBufferStart = %x, WakeupBufferSize = %x\n",
(UINTN)StartAddress,
WakeupBufferSize
));
return (UINTN) StartAddress;
return (UINTN)StartAddress;
}
/**
@@ -151,19 +156,19 @@ GetWakeupBuffer (
**/
UINTN
GetModeTransitionBuffer (
IN UINTN BufferSize
IN UINTN BufferSize
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS StartAddress;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS StartAddress;
StartAddress = BASE_4GB - 1;
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiBootServicesCode,
EFI_SIZE_TO_PAGES (BufferSize),
&StartAddress
);
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiBootServicesCode,
EFI_SIZE_TO_PAGES (BufferSize),
&StartAddress
);
if (EFI_ERROR (Status)) {
StartAddress = 0;
}
@@ -194,27 +199,27 @@ GetSevEsAPMemory (
// Allocate 1 page for AP jump table page
//
StartAddress = BASE_4GB - 1;
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiReservedMemoryType,
1,
&StartAddress
);
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiReservedMemoryType,
1,
&StartAddress
);
ASSERT_EFI_ERROR (Status);
DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory = %lx\n", (UINTN) StartAddress));
DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory = %lx\n", (UINTN)StartAddress));
//
// Save the SevEsAPMemory as the AP jump table.
//
Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
Ghcb = Msr.Ghcb;
Ghcb = Msr.Ghcb;
VmgInit (Ghcb, &InterruptState);
VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress);
VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64)(UINTN)StartAddress);
VmgDone (Ghcb, InterruptState);
return (UINTN) StartAddress;
return (UINTN)StartAddress;
}
/**
@@ -226,9 +231,9 @@ CheckAndUpdateApsStatus (
VOID
)
{
UINTN ProcessorNumber;
EFI_STATUS Status;
CPU_MP_DATA *CpuMpData;
UINTN ProcessorNumber;
EFI_STATUS Status;
CPU_MP_DATA *CpuMpData;
CpuMpData = GetCpuMpData ();
@@ -236,13 +241,12 @@ CheckAndUpdateApsStatus (
// First, check whether pending StartupAllAPs() exists.
//
if (CpuMpData->WaitEvent != NULL) {
Status = CheckAllAPs ();
//
// If all APs finish for StartupAllAPs(), signal the WaitEvent for it.
//
if (Status != EFI_NOT_READY) {
Status = gBS->SignalEvent (CpuMpData->WaitEvent);
Status = gBS->SignalEvent (CpuMpData->WaitEvent);
CpuMpData->WaitEvent = NULL;
}
}
@@ -251,7 +255,6 @@ CheckAndUpdateApsStatus (
// Second, check whether pending StartupThisAPs() callings exist.
//
for (ProcessorNumber = 0; ProcessorNumber < CpuMpData->CpuCount; ProcessorNumber++) {
if (CpuMpData->CpuData[ProcessorNumber].WaitEvent == NULL) {
continue;
}
@@ -260,7 +263,7 @@ CheckAndUpdateApsStatus (
if (Status != EFI_NOT_READY) {
gBS->SignalEvent (CpuMpData->CpuData[ProcessorNumber].WaitEvent);
CpuMpData->CpuData[ProcessorNumber].WaitEvent = NULL;
CpuMpData->CpuData[ProcessorNumber].WaitEvent = NULL;
}
}
}
@@ -279,8 +282,8 @@ CheckAndUpdateApsStatus (
VOID
EFIAPI
CheckApsStatus (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
//
@@ -307,18 +310,20 @@ GetProtectedMode16CS (
UINTN GdtEntryCount;
UINT16 Index;
Index = (UINT16) -1;
Index = (UINT16)-1;
AsmReadGdtr (&GdtrDesc);
GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);
GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;
GdtEntry = (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base;
for (Index = 0; Index < GdtEntryCount; Index++) {
if (GdtEntry->Bits.L == 0) {
if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB == 0) {
if ((GdtEntry->Bits.Type > 8) && (GdtEntry->Bits.DB == 0)) {
break;
}
}
GdtEntry++;
}
ASSERT (Index != GdtEntryCount);
return Index * 8;
}
@@ -340,15 +345,17 @@ GetProtectedModeCS (
AsmReadGdtr (&GdtrDesc);
GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);
GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;
GdtEntry = (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base;
for (Index = 0; Index < GdtEntryCount; Index++) {
if (GdtEntry->Bits.L == 0) {
if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB == 1) {
if ((GdtEntry->Bits.Type > 8) && (GdtEntry->Bits.DB == 1)) {
break;
}
}
GdtEntry++;
}
ASSERT (Index != GdtEntryCount);
return Index * 8;
}
@@ -364,11 +371,11 @@ RelocateApLoop (
IN OUT VOID *Buffer
)
{
CPU_MP_DATA *CpuMpData;
BOOLEAN MwaitSupport;
ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
UINTN ProcessorNumber;
UINTN StackStart;
CPU_MP_DATA *CpuMpData;
BOOLEAN MwaitSupport;
ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc;
UINTN ProcessorNumber;
UINTN StackStart;
MpInitLibWhoAmI (&ProcessorNumber);
CpuMpData = GetCpuMpData ();
@@ -378,13 +385,14 @@ RelocateApLoop (
} else {
StackStart = mReservedTopOfApStack;
}
AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoopFunc;
AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP)(UINTN)mReservedApLoopFunc;
AsmRelocateApLoopFunc (
MwaitSupport,
CpuMpData->ApTargetCState,
CpuMpData->PmCodeSegment,
StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
(UINTN) &mNumberToFinish,
(UINTN)&mNumberToFinish,
CpuMpData->Pm16CodeSegment,
CpuMpData->SevEsAPBuffer,
CpuMpData->WakeupBuffer
@@ -406,32 +414,32 @@ RelocateApLoop (
VOID
EFIAPI
MpInitChangeApLoopCallback (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
CPU_MP_DATA *CpuMpData;
CPU_MP_DATA *CpuMpData;
CpuMpData = GetCpuMpData ();
CpuMpData->PmCodeSegment = GetProtectedModeCS ();
CpuMpData = GetCpuMpData ();
CpuMpData->PmCodeSegment = GetProtectedModeCS ();
CpuMpData->Pm16CodeSegment = GetProtectedMode16CS ();
CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
mNumberToFinish = CpuMpData->CpuCount - 1;
CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode);
mNumberToFinish = CpuMpData->CpuCount - 1;
WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE);
while (mNumberToFinish > 0) {
CpuPause ();
}
if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer != (UINTN) -1)) {
if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer != (UINTN)-1)) {
//
// There are APs present. Re-use reserved memory area below 1MB from
// WakeupBuffer as the area to be used for transitioning to 16-bit mode
// in support of booting of the AP by an OS.
//
CopyMem (
(VOID *) CpuMpData->WakeupBuffer,
(VOID *) (CpuMpData->AddressMap.RendezvousFunnelAddress +
CpuMpData->AddressMap.SwitchToRealPM16ModeOffset),
(VOID *)CpuMpData->WakeupBuffer,
(VOID *)(CpuMpData->AddressMap.RendezvousFunnelAddress +
CpuMpData->AddressMap.SwitchToRealPM16ModeOffset),
CpuMpData->AddressMap.SwitchToRealPM16ModeSize
);
}
@@ -446,16 +454,16 @@ MpInitChangeApLoopCallback (
**/
VOID
InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Address;
UINTN ApSafeBufferSize;
UINTN Index;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
UINTN StackBase;
CPU_INFO_IN_HOB *CpuInfoInHob;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Address;
UINTN ApSafeBufferSize;
UINTN Index;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
UINTN StackBase;
CPU_INFO_IN_HOB *CpuInfoInHob;
SaveCpuMpData (CpuMpData);
@@ -485,7 +493,7 @@ InitMpGlobalData (
//
CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {
if (CpuInfoInHob != NULL && CpuInfoInHob[Index].ApTopOfStack != 0) {
if ((CpuInfoInHob != NULL) && (CpuInfoInHob[Index].ApTopOfStack != 0)) {
StackBase = (UINTN)CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize;
} else {
StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;
@@ -501,8 +509,12 @@ InitMpGlobalData (
);
ASSERT_EFI_ERROR (Status);
DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",
(UINT64)StackBase, (UINT64)Index));
DEBUG ((
DEBUG_INFO,
"Stack Guard set at %lx [cpu%lu]!\n",
(UINT64)StackBase,
(UINT64)Index
));
}
}
@@ -514,9 +526,11 @@ InitMpGlobalData (
// Allocating it in advance since memory services are not available in
// Exit Boot Services callback function.
//
ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
CpuMpData->AddressMap.RelocateApLoopFuncSize
));
ApSafeBufferSize = EFI_PAGES_TO_SIZE (
EFI_SIZE_TO_PAGES (
CpuMpData->AddressMap.RelocateApLoopFuncSize
)
);
Address = BASE_4GB - 1;
Status = gBS->AllocatePages (
AllocateMaxAddress,
@@ -526,7 +540,7 @@ InitMpGlobalData (
);
ASSERT_EFI_ERROR (Status);
mReservedApLoopFunc = (VOID *) (UINTN) Address;
mReservedApLoopFunc = (VOID *)(UINTN)Address;
ASSERT (mReservedApLoopFunc != NULL);
//
@@ -545,9 +559,11 @@ InitMpGlobalData (
);
}
ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
CpuMpData->CpuCount * AP_SAFE_STACK_SIZE
));
ApSafeBufferSize = EFI_PAGES_TO_SIZE (
EFI_SIZE_TO_PAGES (
CpuMpData->CpuCount * AP_SAFE_STACK_SIZE
)
);
Address = BASE_4GB - 1;
Status = gBS->AllocatePages (
AllocateMaxAddress,
@@ -557,7 +573,7 @@ InitMpGlobalData (
);
ASSERT_EFI_ERROR (Status);
mReservedTopOfApStack = (UINTN) Address + ApSafeBufferSize;
mReservedTopOfApStack = (UINTN)Address + ApSafeBufferSize;
ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);
CopyMem (
mReservedApLoopFunc,
@@ -684,15 +700,15 @@ InitMpGlobalData (
EFI_STATUS
EFIAPI
MpInitLibStartupAllAPs (
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Temporarily stop checkAllApsStatus for avoid resource dead-lock.
@@ -791,15 +807,15 @@ MpInitLibStartupAllAPs (
EFI_STATUS
EFIAPI
MpInitLibStartupThisAP (
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// temporarily stop checkAllApsStatus for avoid resource dead-lock.
@@ -849,19 +865,19 @@ MpInitLibStartupThisAP (
EFI_STATUS
EFIAPI
MpInitLibSwitchBSP (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
)
{
EFI_STATUS Status;
EFI_TIMER_ARCH_PROTOCOL *Timer;
UINT64 TimerPeriod;
EFI_STATUS Status;
EFI_TIMER_ARCH_PROTOCOL *Timer;
UINT64 TimerPeriod;
TimerPeriod = 0;
//
// Locate Timer Arch Protocol
//
Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **) &Timer);
Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&Timer);
if (EFI_ERROR (Status)) {
Timer = NULL;
}
@@ -922,13 +938,13 @@ MpInitLibSwitchBSP (
EFI_STATUS
EFIAPI
MpInitLibEnableDisableAP (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
)
{
EFI_STATUS Status;
BOOLEAN TempStopCheckState;
EFI_STATUS Status;
BOOLEAN TempStopCheckState;
TempStopCheckState = FALSE;
//
@@ -961,7 +977,7 @@ MpInitLibEnableDisableAP (
**/
EFI_STATUS
PlatformShadowMicrocode (
IN OUT CPU_MP_DATA *CpuMpData
IN OUT CPU_MP_DATA *CpuMpData
)
{
//

View File

@@ -18,17 +18,17 @@
**/
VOID
MicrocodeDetect (
IN CPU_MP_DATA *CpuMpData,
IN UINTN ProcessorNumber
IN CPU_MP_DATA *CpuMpData,
IN UINTN ProcessorNumber
)
{
CPU_MICROCODE_HEADER *Microcode;
UINTN MicrocodeEnd;
CPU_AP_DATA *BspData;
UINT32 LatestRevision;
CPU_MICROCODE_HEADER *LatestMicrocode;
UINT32 ThreadId;
EDKII_PEI_MICROCODE_CPU_ID MicrocodeCpuId;
CPU_MICROCODE_HEADER *Microcode;
UINTN MicrocodeEnd;
CPU_AP_DATA *BspData;
UINT32 LatestRevision;
CPU_MICROCODE_HEADER *LatestMicrocode;
UINT32 ThreadId;
EDKII_PEI_MICROCODE_CPU_ID MicrocodeCpuId;
if (CpuMpData->MicrocodePatchRegionSize == 0) {
//
@@ -47,7 +47,7 @@ MicrocodeDetect (
GetProcessorMicrocodeCpuId (&MicrocodeCpuId);
if (ProcessorNumber != (UINTN) CpuMpData->BspNumber) {
if (ProcessorNumber != (UINTN)CpuMpData->BspNumber) {
//
// Direct use microcode of BSP if AP is the same as BSP.
// Assume BSP calls this routine() before AP.
@@ -55,8 +55,9 @@ MicrocodeDetect (
BspData = &(CpuMpData->CpuData[CpuMpData->BspNumber]);
if ((BspData->ProcessorSignature == MicrocodeCpuId.ProcessorSignature) &&
(BspData->PlatformId == MicrocodeCpuId.PlatformId) &&
(BspData->MicrocodeEntryAddr != 0)) {
LatestMicrocode = (CPU_MICROCODE_HEADER *)(UINTN) BspData->MicrocodeEntryAddr;
(BspData->MicrocodeEntryAddr != 0))
{
LatestMicrocode = (CPU_MICROCODE_HEADER *)(UINTN)BspData->MicrocodeEntryAddr;
LatestRevision = LatestMicrocode->UpdateRevision;
goto LoadMicrocode;
}
@@ -69,11 +70,11 @@ MicrocodeDetect (
//
LatestRevision = 0;
LatestMicrocode = NULL;
Microcode = (CPU_MICROCODE_HEADER *) (UINTN) CpuMpData->MicrocodePatchAddress;
MicrocodeEnd = (UINTN) Microcode + (UINTN) CpuMpData->MicrocodePatchRegionSize;
Microcode = (CPU_MICROCODE_HEADER *)(UINTN)CpuMpData->MicrocodePatchAddress;
MicrocodeEnd = (UINTN)Microcode + (UINTN)CpuMpData->MicrocodePatchRegionSize;
do {
if (!IsValidMicrocode (Microcode, MicrocodeEnd - (UINTN) Microcode, LatestRevision, &MicrocodeCpuId, 1, TRUE)) {
if (!IsValidMicrocode (Microcode, MicrocodeEnd - (UINTN)Microcode, LatestRevision, &MicrocodeCpuId, 1, TRUE)) {
//
// It is the padding data between the microcode patches for microcode patches alignment.
// Because the microcode patch is the multiple of 1-KByte, the padding data should not
@@ -81,14 +82,15 @@ MicrocodeDetect (
// alignment value should be larger than 1-KByte. We could skip SIZE_1KB padding data to
// find the next possible microcode patch header.
//
Microcode = (CPU_MICROCODE_HEADER *) ((UINTN) Microcode + SIZE_1KB);
Microcode = (CPU_MICROCODE_HEADER *)((UINTN)Microcode + SIZE_1KB);
continue;
}
LatestMicrocode = Microcode;
LatestRevision = LatestMicrocode->UpdateRevision;
Microcode = (CPU_MICROCODE_HEADER *) (((UINTN) Microcode) + GetMicrocodeLength (Microcode));
} while ((UINTN) Microcode < MicrocodeEnd);
Microcode = (CPU_MICROCODE_HEADER *)(((UINTN)Microcode) + GetMicrocodeLength (Microcode));
} while ((UINTN)Microcode < MicrocodeEnd);
LoadMicrocode:
if (LatestRevision != 0) {
@@ -97,7 +99,7 @@ LoadMicrocode:
// patch header) for each processor even it's the same as the loaded one.
// It will be used when building the microcode patch cache HOB.
//
CpuMpData->CpuData[ProcessorNumber].MicrocodeEntryAddr = (UINTN) LatestMicrocode;
CpuMpData->CpuData[ProcessorNumber].MicrocodeEntryAddr = (UINTN)LatestMicrocode;
}
if (LatestRevision > GetProcessorMicrocodeSignature ()) {
@@ -109,6 +111,7 @@ LoadMicrocode:
//
LoadMicrocode (LatestMicrocode);
}
//
// It's possible that the microcode fails to load. Just capture the CPU microcode revision after loading.
//
@@ -129,15 +132,15 @@ LoadMicrocode:
**/
VOID
ShadowMicrocodePatchWorker (
IN OUT CPU_MP_DATA *CpuMpData,
IN MICROCODE_PATCH_INFO *Patches,
IN UINTN PatchCount,
IN UINTN TotalLoadSize
IN OUT CPU_MP_DATA *CpuMpData,
IN MICROCODE_PATCH_INFO *Patches,
IN UINTN PatchCount,
IN UINTN TotalLoadSize
)
{
UINTN Index;
VOID *MicrocodePatchInRam;
UINT8 *Walker;
UINTN Index;
VOID *MicrocodePatchInRam;
UINT8 *Walker;
ASSERT ((Patches != NULL) && (PatchCount != 0));
@@ -152,7 +155,7 @@ ShadowMicrocodePatchWorker (
for (Walker = MicrocodePatchInRam, Index = 0; Index < PatchCount; Index++) {
CopyMem (
Walker,
(VOID *) Patches[Index].Address,
(VOID *)Patches[Index].Address,
Patches[Index].Size
);
Walker += Patches[Index].Size;
@@ -161,13 +164,15 @@ ShadowMicrocodePatchWorker (
//
// Update the microcode patch related fields in CpuMpData
//
CpuMpData->MicrocodePatchAddress = (UINTN) MicrocodePatchInRam;
CpuMpData->MicrocodePatchAddress = (UINTN)MicrocodePatchInRam;
CpuMpData->MicrocodePatchRegionSize = TotalLoadSize;
DEBUG ((
DEBUG_INFO,
"%a: Required microcode patches have been loaded at 0x%lx, with size 0x%lx.\n",
__FUNCTION__, CpuMpData->MicrocodePatchAddress, CpuMpData->MicrocodePatchRegionSize
__FUNCTION__,
CpuMpData->MicrocodePatchAddress,
CpuMpData->MicrocodePatchRegionSize
));
return;
@@ -181,19 +186,19 @@ ShadowMicrocodePatchWorker (
**/
VOID
ShadowMicrocodePatchByPcd (
IN OUT CPU_MP_DATA *CpuMpData
IN OUT CPU_MP_DATA *CpuMpData
)
{
UINTN Index;
CPU_MICROCODE_HEADER *MicrocodeEntryPoint;
UINTN MicrocodeEnd;
UINTN TotalSize;
MICROCODE_PATCH_INFO *PatchInfoBuffer;
UINTN MaxPatchNumber;
UINTN PatchCount;
UINTN TotalLoadSize;
EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuIds;
BOOLEAN Valid;
UINTN Index;
CPU_MICROCODE_HEADER *MicrocodeEntryPoint;
UINTN MicrocodeEnd;
UINTN TotalSize;
MICROCODE_PATCH_INFO *PatchInfoBuffer;
UINTN MaxPatchNumber;
UINTN PatchCount;
UINTN TotalLoadSize;
EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuIds;
BOOLEAN Valid;
//
// Initialize the microcode patch related fields in CpuMpData as the values
@@ -203,10 +208,10 @@ ShadowMicrocodePatchByPcd (
CpuMpData->MicrocodePatchAddress = PcdGet64 (PcdCpuMicrocodePatchAddress);
CpuMpData->MicrocodePatchRegionSize = PcdGet64 (PcdCpuMicrocodePatchRegionSize);
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) CpuMpData->MicrocodePatchAddress;
MicrocodeEnd = (UINTN) MicrocodeEntryPoint +
(UINTN) CpuMpData->MicrocodePatchRegionSize;
if ((MicrocodeEntryPoint == NULL) || ((UINTN) MicrocodeEntryPoint == MicrocodeEnd)) {
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *)(UINTN)CpuMpData->MicrocodePatchAddress;
MicrocodeEnd = (UINTN)MicrocodeEntryPoint +
(UINTN)CpuMpData->MicrocodePatchRegionSize;
if ((MicrocodeEntryPoint == NULL) || ((UINTN)MicrocodeEntryPoint == MicrocodeEnd)) {
//
// There is no microcode patches
//
@@ -242,7 +247,7 @@ ShadowMicrocodePatchByPcd (
do {
Valid = IsValidMicrocode (
MicrocodeEntryPoint,
MicrocodeEnd - (UINTN) MicrocodeEntryPoint,
MicrocodeEnd - (UINTN)MicrocodeEntryPoint,
0,
MicrocodeCpuIds,
CpuMpData->CpuCount,
@@ -252,7 +257,7 @@ ShadowMicrocodePatchByPcd (
//
// Padding data between the microcode patches, skip 1KB to check next entry.
//
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEntryPoint) + SIZE_1KB);
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *)(((UINTN)MicrocodeEntryPoint) + SIZE_1KB);
continue;
}
@@ -277,6 +282,7 @@ ShadowMicrocodePatchByPcd (
if (PatchInfoBuffer == NULL) {
goto OnExit;
}
MaxPatchNumber = MaxPatchNumber * 2;
}
@@ -285,21 +291,23 @@ ShadowMicrocodePatchByPcd (
//
// Store the information of this microcode patch
//
PatchInfoBuffer[PatchCount - 1].Address = (UINTN) MicrocodeEntryPoint;
PatchInfoBuffer[PatchCount - 1].Address = (UINTN)MicrocodeEntryPoint;
PatchInfoBuffer[PatchCount - 1].Size = TotalSize;
TotalLoadSize += TotalSize;
TotalLoadSize += TotalSize;
//
// Process the next microcode patch
//
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) ((UINTN) MicrocodeEntryPoint + TotalSize);
} while ((UINTN) MicrocodeEntryPoint < MicrocodeEnd);
MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *)((UINTN)MicrocodeEntryPoint + TotalSize);
} while ((UINTN)MicrocodeEntryPoint < MicrocodeEnd);
if (PatchCount != 0) {
DEBUG ((
DEBUG_INFO,
"%a: 0x%x microcode patches will be loaded into memory, with size 0x%x.\n",
__FUNCTION__, PatchCount, TotalLoadSize
__FUNCTION__,
PatchCount,
TotalLoadSize
));
ShadowMicrocodePatchWorker (CpuMpData, PatchInfoBuffer, PatchCount, TotalLoadSize);
@@ -309,6 +317,7 @@ OnExit:
if (PatchInfoBuffer != NULL) {
FreePool (PatchInfoBuffer);
}
FreePages (MicrocodeCpuIds, EFI_SIZE_TO_PAGES (CpuMpData->CpuCount * sizeof (EDKII_PEI_MICROCODE_CPU_ID)));
}
@@ -319,10 +328,10 @@ OnExit:
**/
VOID
ShadowMicrocodeUpdatePatch (
IN OUT CPU_MP_DATA *CpuMpData
IN OUT CPU_MP_DATA *CpuMpData
)
{
EFI_STATUS Status;
EFI_STATUS Status;
Status = PlatformShadowMicrocode (CpuMpData);
if (EFI_ERROR (Status)) {
@@ -347,16 +356,16 @@ ShadowMicrocodeUpdatePatch (
**/
BOOLEAN
GetMicrocodePatchInfoFromHob (
UINT64 *Address,
UINT64 *RegionSize
UINT64 *Address,
UINT64 *RegionSize
)
{
EFI_HOB_GUID_TYPE *GuidHob;
EDKII_MICROCODE_PATCH_HOB *MicrocodePathHob;
EFI_HOB_GUID_TYPE *GuidHob;
EDKII_MICROCODE_PATCH_HOB *MicrocodePathHob;
GuidHob = GetFirstGuidHob (&gEdkiiMicrocodePatchHobGuid);
if (GuidHob == NULL) {
DEBUG((DEBUG_INFO, "%a: Microcode patch cache HOB is not found.\n", __FUNCTION__));
DEBUG ((DEBUG_INFO, "%a: Microcode patch cache HOB is not found.\n", __FUNCTION__));
return FALSE;
}
@@ -365,9 +374,12 @@ GetMicrocodePatchInfoFromHob (
*Address = MicrocodePathHob->MicrocodePatchAddress;
*RegionSize = MicrocodePathHob->MicrocodePatchRegionSize;
DEBUG((
DEBUG_INFO, "%a: MicrocodeBase = 0x%lx, MicrocodeSize = 0x%lx\n",
__FUNCTION__, *Address, *RegionSize
DEBUG ((
DEBUG_INFO,
"%a: MicrocodeBase = 0x%lx, MicrocodeSize = 0x%lx\n",
__FUNCTION__,
*Address,
*RegionSize
));
return TRUE;

File diff suppressed because it is too large Load Diff

View File

@@ -36,7 +36,7 @@
#include <Guid/MicrocodePatchHob.h>
#define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')
#define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')
#define CPU_INIT_MP_LIB_HOB_GUID \
{ \
@@ -46,14 +46,14 @@
//
// The MP data for switch BSP
//
#define CPU_SWITCH_STATE_IDLE 0
#define CPU_SWITCH_STATE_STORED 1
#define CPU_SWITCH_STATE_LOADED 2
#define CPU_SWITCH_STATE_IDLE 0
#define CPU_SWITCH_STATE_STORED 1
#define CPU_SWITCH_STATE_LOADED 2
//
// Default maximum number of entries to store the microcode patches information
//
#define DEFAULT_MAX_MICROCODE_PATCH_NUM 8
#define DEFAULT_MAX_MICROCODE_PATCH_NUM 8
//
// Data structure for microcode patch information
@@ -67,10 +67,10 @@ typedef struct {
// CPU exchange information for switch BSP
//
typedef struct {
UINT8 State; // offset 0
UINTN StackPointer; // offset 4 / 8
IA32_DESCRIPTOR Gdtr; // offset 8 / 16
IA32_DESCRIPTOR Idtr; // offset 14 / 26
UINT8 State; // offset 0
UINTN StackPointer; // offset 4 / 8
IA32_DESCRIPTOR Gdtr; // offset 8 / 16
IA32_DESCRIPTOR Idtr; // offset 14 / 26
} CPU_EXCHANGE_ROLE_INFO;
//
@@ -111,41 +111,41 @@ typedef enum {
// CPU volatile registers around INIT-SIPI-SIPI
//
typedef struct {
UINTN Cr0;
UINTN Cr3;
UINTN Cr4;
UINTN Dr0;
UINTN Dr1;
UINTN Dr2;
UINTN Dr3;
UINTN Dr6;
UINTN Dr7;
IA32_DESCRIPTOR Gdtr;
IA32_DESCRIPTOR Idtr;
UINT16 Tr;
UINTN Cr0;
UINTN Cr3;
UINTN Cr4;
UINTN Dr0;
UINTN Dr1;
UINTN Dr2;
UINTN Dr3;
UINTN Dr6;
UINTN Dr7;
IA32_DESCRIPTOR Gdtr;
IA32_DESCRIPTOR Idtr;
UINT16 Tr;
} CPU_VOLATILE_REGISTERS;
//
// AP related data
//
typedef struct {
SPIN_LOCK ApLock;
volatile UINT32 *StartupApSignal;
volatile UINTN ApFunction;
volatile UINTN ApFunctionArgument;
BOOLEAN CpuHealthy;
volatile CPU_STATE State;
CPU_VOLATILE_REGISTERS VolatileRegisters;
BOOLEAN Waiting;
BOOLEAN *Finished;
UINT64 ExpectedTime;
UINT64 CurrentTime;
UINT64 TotalTime;
EFI_EVENT WaitEvent;
UINT32 ProcessorSignature;
UINT8 PlatformId;
UINT64 MicrocodeEntryAddr;
UINT32 MicrocodeRevision;
SPIN_LOCK ApLock;
volatile UINT32 *StartupApSignal;
volatile UINTN ApFunction;
volatile UINTN ApFunctionArgument;
BOOLEAN CpuHealthy;
volatile CPU_STATE State;
CPU_VOLATILE_REGISTERS VolatileRegisters;
BOOLEAN Waiting;
BOOLEAN *Finished;
UINT64 ExpectedTime;
UINT64 CurrentTime;
UINT64 TotalTime;
EFI_EVENT WaitEvent;
UINT32 ProcessorSignature;
UINT8 PlatformId;
UINT64 MicrocodeEntryAddr;
UINT32 MicrocodeRevision;
} CPU_AP_DATA;
//
@@ -156,10 +156,10 @@ typedef struct {
//
#pragma pack (1)
typedef struct {
UINT32 InitialApicId;
UINT32 ApicId;
UINT32 Health;
UINT64 ApTopOfStack;
UINT32 InitialApicId;
UINT32 ApicId;
UINT32 Health;
UINT64 ApTopOfStack;
} CPU_INFO_IN_HOB;
#pragma pack ()
@@ -169,20 +169,20 @@ typedef struct {
// It is natural aligned by design.
//
typedef struct {
UINT8 *RendezvousFunnelAddress;
UINTN ModeEntryOffset;
UINTN RendezvousFunnelSize;
UINT8 *RelocateApLoopFuncAddress;
UINTN RelocateApLoopFuncSize;
UINTN ModeTransitionOffset;
UINTN SwitchToRealSize;
UINTN SwitchToRealOffset;
UINTN SwitchToRealNoNxOffset;
UINTN SwitchToRealPM16ModeOffset;
UINTN SwitchToRealPM16ModeSize;
UINT8 *RendezvousFunnelAddress;
UINTN ModeEntryOffset;
UINTN RendezvousFunnelSize;
UINT8 *RelocateApLoopFuncAddress;
UINTN RelocateApLoopFuncSize;
UINTN ModeTransitionOffset;
UINTN SwitchToRealSize;
UINTN SwitchToRealOffset;
UINTN SwitchToRealNoNxOffset;
UINTN SwitchToRealPM16ModeOffset;
UINTN SwitchToRealPM16ModeSize;
} MP_ASSEMBLY_ADDRESS_MAP;
typedef struct _CPU_MP_DATA CPU_MP_DATA;
typedef struct _CPU_MP_DATA CPU_MP_DATA;
#pragma pack(1)
@@ -192,33 +192,33 @@ typedef struct _CPU_MP_DATA CPU_MP_DATA;
// into this structure are used in assembly code in this module
//
typedef struct {
UINTN StackStart;
UINTN StackSize;
UINTN CFunction;
IA32_DESCRIPTOR GdtrProfile;
IA32_DESCRIPTOR IdtrProfile;
UINTN BufferStart;
UINTN ModeOffset;
UINTN ApIndex;
UINTN CodeSegment;
UINTN DataSegment;
UINTN EnableExecuteDisable;
UINTN Cr3;
UINTN InitFlag;
CPU_INFO_IN_HOB *CpuInfo;
UINTN NumApsExecuting;
CPU_MP_DATA *CpuMpData;
UINTN InitializeFloatingPointUnitsAddress;
UINT32 ModeTransitionMemory;
UINT16 ModeTransitionSegment;
UINT32 ModeHighMemory;
UINT16 ModeHighSegment;
UINTN StackStart;
UINTN StackSize;
UINTN CFunction;
IA32_DESCRIPTOR GdtrProfile;
IA32_DESCRIPTOR IdtrProfile;
UINTN BufferStart;
UINTN ModeOffset;
UINTN ApIndex;
UINTN CodeSegment;
UINTN DataSegment;
UINTN EnableExecuteDisable;
UINTN Cr3;
UINTN InitFlag;
CPU_INFO_IN_HOB *CpuInfo;
UINTN NumApsExecuting;
CPU_MP_DATA *CpuMpData;
UINTN InitializeFloatingPointUnitsAddress;
UINT32 ModeTransitionMemory;
UINT16 ModeTransitionSegment;
UINT32 ModeHighMemory;
UINT16 ModeHighSegment;
//
// Enable5LevelPaging indicates whether 5-level paging is enabled in long mode.
//
BOOLEAN Enable5LevelPaging;
BOOLEAN SevEsIsEnabled;
UINTN GhcbBase;
BOOLEAN Enable5LevelPaging;
BOOLEAN SevEsIsEnabled;
UINTN GhcbBase;
} MP_CPU_EXCHANGE_INFO;
#pragma pack()
@@ -227,55 +227,55 @@ typedef struct {
// CPU MP Data save in memory
//
struct _CPU_MP_DATA {
UINT64 CpuInfoInHob;
UINT32 CpuCount;
UINT32 BspNumber;
UINT64 CpuInfoInHob;
UINT32 CpuCount;
UINT32 BspNumber;
//
// The above fields data will be passed from PEI to DXE
// Please make sure the fields offset same in the different
// architecture.
//
SPIN_LOCK MpLock;
UINTN Buffer;
UINTN CpuApStackSize;
MP_ASSEMBLY_ADDRESS_MAP AddressMap;
UINTN WakeupBuffer;
UINTN WakeupBufferHigh;
UINTN BackupBuffer;
UINTN BackupBufferSize;
SPIN_LOCK MpLock;
UINTN Buffer;
UINTN CpuApStackSize;
MP_ASSEMBLY_ADDRESS_MAP AddressMap;
UINTN WakeupBuffer;
UINTN WakeupBufferHigh;
UINTN BackupBuffer;
UINTN BackupBufferSize;
volatile UINT32 FinishedCount;
UINT32 RunningCount;
BOOLEAN SingleThread;
EFI_AP_PROCEDURE Procedure;
VOID *ProcArguments;
BOOLEAN *Finished;
UINT64 ExpectedTime;
UINT64 CurrentTime;
UINT64 TotalTime;
EFI_EVENT WaitEvent;
UINTN **FailedCpuList;
volatile UINT32 FinishedCount;
UINT32 RunningCount;
BOOLEAN SingleThread;
EFI_AP_PROCEDURE Procedure;
VOID *ProcArguments;
BOOLEAN *Finished;
UINT64 ExpectedTime;
UINT64 CurrentTime;
UINT64 TotalTime;
EFI_EVENT WaitEvent;
UINTN **FailedCpuList;
AP_INIT_STATE InitFlag;
BOOLEAN SwitchBspFlag;
UINTN NewBspNumber;
CPU_EXCHANGE_ROLE_INFO BSPInfo;
CPU_EXCHANGE_ROLE_INFO APInfo;
MTRR_SETTINGS MtrrTable;
UINT8 ApLoopMode;
UINT8 ApTargetCState;
UINT16 PmCodeSegment;
UINT16 Pm16CodeSegment;
CPU_AP_DATA *CpuData;
volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
AP_INIT_STATE InitFlag;
BOOLEAN SwitchBspFlag;
UINTN NewBspNumber;
CPU_EXCHANGE_ROLE_INFO BSPInfo;
CPU_EXCHANGE_ROLE_INFO APInfo;
MTRR_SETTINGS MtrrTable;
UINT8 ApLoopMode;
UINT8 ApTargetCState;
UINT16 PmCodeSegment;
UINT16 Pm16CodeSegment;
CPU_AP_DATA *CpuData;
volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
UINT32 CurrentTimerCount;
UINTN DivideValue;
UINT8 Vector;
BOOLEAN PeriodicMode;
BOOLEAN TimerInterruptState;
UINT64 MicrocodePatchAddress;
UINT64 MicrocodePatchRegionSize;
UINT32 CurrentTimerCount;
UINTN DivideValue;
UINT8 Vector;
BOOLEAN PeriodicMode;
BOOLEAN TimerInterruptState;
UINT64 MicrocodePatchAddress;
UINT64 MicrocodePatchRegionSize;
//
// Whether need to use Init-Sipi-Sipi to wake up the APs.
@@ -284,25 +284,25 @@ struct _CPU_MP_DATA {
// will be hardcode change to HLT mode by PiSmmCpuDxeSmm
// driver.
//
BOOLEAN WakeUpByInitSipiSipi;
BOOLEAN WakeUpByInitSipiSipi;
BOOLEAN SevEsIsEnabled;
UINTN SevEsAPBuffer;
UINTN SevEsAPResetStackStart;
CPU_MP_DATA *NewCpuMpData;
BOOLEAN SevEsIsEnabled;
UINTN SevEsAPBuffer;
UINTN SevEsAPResetStackStart;
CPU_MP_DATA *NewCpuMpData;
UINT64 GhcbBase;
UINT64 GhcbBase;
};
#define AP_SAFE_STACK_SIZE 128
#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE
#define AP_SAFE_STACK_SIZE 128
#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE
#pragma pack(1)
typedef struct {
UINT8 InsnBuffer[8];
UINT16 Rip;
UINT16 Segment;
UINT8 InsnBuffer[8];
UINT16 Rip;
UINT16 Segment;
} SEV_ES_AP_JMP_FAR;
#pragma pack()
@@ -322,14 +322,14 @@ typedef struct {
**/
typedef
VOID
(EFIAPI AP_RESET) (
(EFIAPI AP_RESET)(
IN UINTN BufferStart,
IN UINT16 Code16,
IN UINT16 Code32,
IN UINTN StackStart
);
extern EFI_GUID mCpuInitMpLibHobGuid;
extern EFI_GUID mCpuInitMpLibHobGuid;
/**
Assembly code to place AP into safe loop mode.
@@ -347,7 +347,7 @@ extern EFI_GUID mCpuInitMpLibHobGuid;
**/
typedef
VOID
(EFIAPI * ASM_RELOCATE_AP_LOOP) (
(EFIAPI *ASM_RELOCATE_AP_LOOP)(
IN BOOLEAN MwaitSupport,
IN UINTN ApTargetCState,
IN UINTN PmCodeSegment,
@@ -367,7 +367,7 @@ VOID
VOID
EFIAPI
AsmGetAddressMap (
OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
);
/**
@@ -382,8 +382,8 @@ AsmGetAddressMap (
VOID
EFIAPI
AsmExchangeRole (
IN CPU_EXCHANGE_ROLE_INFO *MyInfo,
IN CPU_EXCHANGE_ROLE_INFO *OthersInfo
IN CPU_EXCHANGE_ROLE_INFO *MyInfo,
IN CPU_EXCHANGE_ROLE_INFO *OthersInfo
);
/**
@@ -403,10 +403,9 @@ GetCpuMpData (
**/
VOID
SaveCpuMpData (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
);
/**
Get available system memory below 1MB by specified size.
@@ -417,7 +416,7 @@ SaveCpuMpData (
**/
UINTN
GetWakeupBuffer (
IN UINTN WakeupBufferSize
IN UINTN WakeupBufferSize
);
/**
@@ -434,7 +433,7 @@ GetWakeupBuffer (
**/
UINTN
GetModeTransitionBuffer (
IN UINTN BufferSize
IN UINTN BufferSize
);
/**
@@ -463,12 +462,12 @@ GetSevEsAPMemory (
**/
VOID
WakeUpAP (
IN CPU_MP_DATA *CpuMpData,
IN BOOLEAN Broadcast,
IN UINTN ProcessorNumber,
IN EFI_AP_PROCEDURE Procedure OPTIONAL,
IN VOID *ProcedureArgument OPTIONAL,
IN BOOLEAN WakeUpDisabledAps OPTIONAL
IN CPU_MP_DATA *CpuMpData,
IN BOOLEAN Broadcast,
IN UINTN ProcessorNumber,
IN EFI_AP_PROCEDURE Procedure OPTIONAL,
IN VOID *ProcedureArgument OPTIONAL,
IN BOOLEAN WakeUpDisabledAps OPTIONAL
);
/**
@@ -478,7 +477,7 @@ WakeUpAP (
**/
VOID
InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
);
/**
@@ -515,13 +514,13 @@ InitMpGlobalData (
**/
EFI_STATUS
StartupAllCPUsWorker (
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN BOOLEAN ExcludeBsp,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN BOOLEAN ExcludeBsp,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
);
/**
@@ -549,12 +548,12 @@ StartupAllCPUsWorker (
**/
EFI_STATUS
StartupThisAPWorker (
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
);
/**
@@ -570,8 +569,8 @@ StartupThisAPWorker (
**/
EFI_STATUS
SwitchBSPWorker (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
);
/**
@@ -590,9 +589,9 @@ SwitchBSPWorker (
**/
EFI_STATUS
EnableDisableApWorker (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
);
/**
@@ -618,7 +617,7 @@ GetCpuMpDataFromGuidedHob (
**/
EFI_STATUS
CheckThisAP (
IN UINTN ProcessorNumber
IN UINTN ProcessorNumber
);
/**
@@ -655,8 +654,8 @@ CheckAndUpdateApsStatus (
**/
VOID
MicrocodeDetect (
IN CPU_MP_DATA *CpuMpData,
IN UINTN ProcessorNumber
IN CPU_MP_DATA *CpuMpData,
IN UINTN ProcessorNumber
);
/**
@@ -666,7 +665,7 @@ MicrocodeDetect (
**/
VOID
ShadowMicrocodeUpdatePatch (
IN OUT CPU_MP_DATA *CpuMpData
IN OUT CPU_MP_DATA *CpuMpData
);
/**
@@ -686,8 +685,8 @@ ShadowMicrocodeUpdatePatch (
**/
BOOLEAN
GetMicrocodePatchInfoFromHob (
UINT64 *Address,
UINT64 *RegionSize
UINT64 *Address,
UINT64 *RegionSize
);
/**
@@ -721,8 +720,8 @@ EnableDebugAgent (
**/
EFI_STATUS
GetProcessorNumber (
IN CPU_MP_DATA *CpuMpData,
OUT UINTN *ProcessorNumber
IN CPU_MP_DATA *CpuMpData,
OUT UINTN *ProcessorNumber
);
/**
@@ -738,7 +737,7 @@ GetProcessorNumber (
**/
EFI_STATUS
PlatformShadowMicrocode (
IN OUT CPU_MP_DATA *CpuMpData
IN OUT CPU_MP_DATA *CpuMpData
);
#endif

View File

@@ -11,7 +11,7 @@
#include <Guid/S3SmmInitDone.h>
#include <Ppi/ShadowMicrocode.h>
STATIC UINT64 mSevEsPeiWakeupBuffer = BASE_1MB;
STATIC UINT64 mSevEsPeiWakeupBuffer = BASE_1MB;
/**
S3 SMM Init Done notification function.
@@ -26,16 +26,15 @@ STATIC UINT64 mSevEsPeiWakeupBuffer = BASE_1MB;
EFI_STATUS
EFIAPI
NotifyOnS3SmmInitDonePpi (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
IN VOID *InvokePpi
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
IN VOID *InvokePpi
);
//
// Global function
//
EFI_PEI_NOTIFY_DESCRIPTOR mS3SmmInitDoneNotifyDesc = {
EFI_PEI_NOTIFY_DESCRIPTOR mS3SmmInitDoneNotifyDesc = {
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEdkiiS3SmmInitDoneGuid,
NotifyOnS3SmmInitDonePpi
@@ -54,12 +53,12 @@ EFI_PEI_NOTIFY_DESCRIPTOR mS3SmmInitDoneNotifyDesc = {
EFI_STATUS
EFIAPI
NotifyOnS3SmmInitDonePpi (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
IN VOID *InvokePpi
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
IN VOID *InvokePpi
)
{
CPU_MP_DATA *CpuMpData;
CPU_MP_DATA *CpuMpData;
CpuMpData = GetCpuMpData ();
@@ -76,7 +75,6 @@ NotifyOnS3SmmInitDonePpi (
return EFI_SUCCESS;
}
/**
Enable Debug Agent to support source debugging on AP function.
@@ -110,8 +108,9 @@ GetCpuMpData (
ASSERT (CpuMpData != NULL);
} else {
AsmReadIdtr (&Idtr);
CpuMpData = (CPU_MP_DATA *) (Idtr.Base + Idtr.Limit + 1);
CpuMpData = (CPU_MP_DATA *)(Idtr.Base + Idtr.Limit + 1);
}
return CpuMpData;
}
@@ -122,17 +121,18 @@ GetCpuMpData (
**/
VOID
SaveCpuMpData (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
)
{
UINT64 Data64;
UINT64 Data64;
//
// Build location of CPU MP DATA buffer in HOB
//
Data64 = (UINT64) (UINTN) CpuMpData;
Data64 = (UINT64)(UINTN)CpuMpData;
BuildGuidDataHob (
&mCpuInitMpLibHobGuid,
(VOID *) &Data64,
(VOID *)&Data64,
sizeof (UINT64)
);
}
@@ -148,15 +148,15 @@ SaveCpuMpData (
**/
BOOLEAN
CheckOverlapWithAllocatedBuffer (
IN UINT64 WakeupBufferStart,
IN UINT64 WakeupBufferEnd
IN UINT64 WakeupBufferStart,
IN UINT64 WakeupBufferEnd
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
BOOLEAN Overlapped;
UINT64 MemoryStart;
UINT64 MemoryEnd;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
BOOLEAN Overlapped;
UINT64 MemoryStart;
UINT64 MemoryEnd;
Overlapped = FALSE;
//
@@ -176,8 +176,10 @@ CheckOverlapWithAllocatedBuffer (
break;
}
}
Hob.Raw = GET_NEXT_HOB (Hob);
}
return Overlapped;
}
@@ -191,12 +193,12 @@ CheckOverlapWithAllocatedBuffer (
**/
UINTN
GetWakeupBuffer (
IN UINTN WakeupBufferSize
IN UINTN WakeupBufferSize
)
{
EFI_PEI_HOB_POINTERS Hob;
UINT64 WakeupBufferStart;
UINT64 WakeupBufferEnd;
EFI_PEI_HOB_POINTERS Hob;
UINT64 WakeupBufferStart;
UINT64 WakeupBufferEnd;
WakeupBufferSize = (WakeupBufferSize + SIZE_4KB - 1) & ~(SIZE_4KB - 1);
@@ -216,14 +218,16 @@ GetWakeupBuffer (
(EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED |
EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED |
EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED
)) == 0)
) {
)) == 0)
)
{
//
// Need memory under 1MB to be collected here
//
WakeupBufferEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
if (PcdGetBool (PcdSevEsIsEnabled) &&
WakeupBufferEnd > mSevEsPeiWakeupBuffer) {
(WakeupBufferEnd > mSevEsPeiWakeupBuffer))
{
//
// SEV-ES Wakeup buffer should be under 1MB and under any previous one
//
@@ -234,6 +238,7 @@ GetWakeupBuffer (
//
WakeupBufferEnd = BASE_1MB;
}
while (WakeupBufferEnd > WakeupBufferSize) {
//
// Wakeup buffer should be aligned on 4KB
@@ -242,6 +247,7 @@ GetWakeupBuffer (
if (WakeupBufferStart < Hob.ResourceDescriptor->PhysicalStart) {
break;
}
if (CheckOverlapWithAllocatedBuffer (WakeupBufferStart, WakeupBufferEnd)) {
//
// If this range is overlapped with existing allocated buffer, skip it
@@ -250,8 +256,13 @@ GetWakeupBuffer (
WakeupBufferEnd -= WakeupBufferSize;
continue;
}
DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",
WakeupBufferStart, WakeupBufferSize));
DEBUG ((
DEBUG_INFO,
"WakeupBufferStart = %x, WakeupBufferSize = %x\n",
WakeupBufferStart,
WakeupBufferSize
));
if (PcdGetBool (PcdSevEsIsEnabled)) {
//
@@ -265,13 +276,14 @@ GetWakeupBuffer (
}
}
}
//
// Find the next HOB
//
Hob.Raw = GET_NEXT_HOB (Hob);
}
return (UINTN) -1;
return (UINTN)-1;
}
/**
@@ -288,7 +300,7 @@ GetWakeupBuffer (
**/
UINTN
GetModeTransitionBuffer (
IN UINTN BufferSize
IN UINTN BufferSize
)
{
//
@@ -336,17 +348,17 @@ CheckAndUpdateApsStatus (
**/
VOID
BuildMicrocodeCacheHob (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
)
{
EDKII_MICROCODE_PATCH_HOB *MicrocodeHob;
UINTN HobDataLength;
UINT32 Index;
EDKII_MICROCODE_PATCH_HOB *MicrocodeHob;
UINTN HobDataLength;
UINT32 Index;
HobDataLength = sizeof (EDKII_MICROCODE_PATCH_HOB) +
sizeof (UINT64) * CpuMpData->CpuCount;
MicrocodeHob = AllocatePool (HobDataLength);
MicrocodeHob = AllocatePool (HobDataLength);
if (MicrocodeHob == NULL) {
ASSERT (FALSE);
return;
@@ -387,7 +399,7 @@ BuildMicrocodeCacheHob (
**/
VOID
InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
IN CPU_MP_DATA *CpuMpData
)
{
EFI_STATUS Status;
@@ -480,12 +492,12 @@ InitMpGlobalData (
EFI_STATUS
EFIAPI
MpInitLibStartupAllAPs (
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
)
{
if (WaitEvent != NULL) {
@@ -577,12 +589,12 @@ MpInitLibStartupAllAPs (
EFI_STATUS
EFIAPI
MpInitLibStartupThisAP (
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
)
{
if (WaitEvent != NULL) {
@@ -628,8 +640,8 @@ MpInitLibStartupThisAP (
EFI_STATUS
EFIAPI
MpInitLibSwitchBSP (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
)
{
return SwitchBSPWorker (ProcessorNumber, EnableOldBSP);
@@ -668,9 +680,9 @@ MpInitLibSwitchBSP (
EFI_STATUS
EFIAPI
MpInitLibEnableDisableAP (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
)
{
return EnableDisableApWorker (ProcessorNumber, EnableAP, HealthFlag);
@@ -689,29 +701,29 @@ MpInitLibEnableDisableAP (
**/
EFI_STATUS
PlatformShadowMicrocode (
IN OUT CPU_MP_DATA *CpuMpData
IN OUT CPU_MP_DATA *CpuMpData
)
{
EFI_STATUS Status;
EDKII_PEI_SHADOW_MICROCODE_PPI *ShadowMicrocodePpi;
UINTN CpuCount;
EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId;
UINTN Index;
UINTN BufferSize;
VOID *Buffer;
EFI_STATUS Status;
EDKII_PEI_SHADOW_MICROCODE_PPI *ShadowMicrocodePpi;
UINTN CpuCount;
EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId;
UINTN Index;
UINTN BufferSize;
VOID *Buffer;
Status = PeiServicesLocatePpi (
&gEdkiiPeiShadowMicrocodePpiGuid,
0,
NULL,
(VOID **) &ShadowMicrocodePpi
(VOID **)&ShadowMicrocodePpi
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
CpuCount = CpuMpData->CpuCount;
MicrocodeCpuId = (EDKII_PEI_MICROCODE_CPU_ID *) AllocateZeroPool (sizeof (EDKII_PEI_MICROCODE_CPU_ID) * CpuCount);
CpuCount = CpuMpData->CpuCount;
MicrocodeCpuId = (EDKII_PEI_MICROCODE_CPU_ID *)AllocateZeroPool (sizeof (EDKII_PEI_MICROCODE_CPU_ID) * CpuCount);
if (MicrocodeCpuId == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -722,24 +734,26 @@ PlatformShadowMicrocode (
}
Status = ShadowMicrocodePpi->ShadowMicrocode (
ShadowMicrocodePpi,
CpuCount,
MicrocodeCpuId,
&BufferSize,
&Buffer
);
ShadowMicrocodePpi,
CpuCount,
MicrocodeCpuId,
&BufferSize,
&Buffer
);
FreePool (MicrocodeCpuId);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
CpuMpData->MicrocodePatchAddress = (UINTN) Buffer;
CpuMpData->MicrocodePatchAddress = (UINTN)Buffer;
CpuMpData->MicrocodePatchRegionSize = BufferSize;
DEBUG ((
DEBUG_INFO,
"%a: Required microcode patches have been loaded at 0x%lx, with size 0x%lx.\n",
__FUNCTION__, CpuMpData->MicrocodePatchAddress, CpuMpData->MicrocodePatchRegionSize
__FUNCTION__,
CpuMpData->MicrocodePatchAddress,
CpuMpData->MicrocodePatchRegionSize
));
return EFI_SUCCESS;

View File

@@ -63,8 +63,8 @@ MpInitLibInitialize (
EFI_STATUS
EFIAPI
MpInitLibGetNumberOfProcessors (
OUT UINTN *NumberOfProcessors OPTIONAL,
OUT UINTN *NumberOfEnabledProcessors OPTIONAL
OUT UINTN *NumberOfProcessors OPTIONAL,
OUT UINTN *NumberOfEnabledProcessors OPTIONAL
)
{
*NumberOfProcessors = 1;
@@ -103,13 +103,15 @@ MpInitLibGetProcessorInfo (
if (ProcessorInfoBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if (ProcessorNumber != 0) {
return EFI_NOT_FOUND;
}
ProcessorInfoBuffer->ProcessorId = 0;
ProcessorInfoBuffer->StatusFlag = PROCESSOR_AS_BSP_BIT |
PROCESSOR_ENABLED_BIT |
PROCESSOR_HEALTH_STATUS_BIT;
ProcessorInfoBuffer->ProcessorId = 0;
ProcessorInfoBuffer->StatusFlag = PROCESSOR_AS_BSP_BIT |
PROCESSOR_ENABLED_BIT |
PROCESSOR_HEALTH_STATUS_BIT;
ProcessorInfoBuffer->Location.Package = 0;
ProcessorInfoBuffer->Location.Core = 0;
ProcessorInfoBuffer->Location.Thread = 0;
@@ -117,12 +119,13 @@ MpInitLibGetProcessorInfo (
GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);
if (GuidHob != NULL) {
SecPlatformInformation = GET_GUID_HOB_DATA (GuidHob);
HealthData->Uint32 = SecPlatformInformation->IA32HealthFlags.Uint32;
HealthData->Uint32 = SecPlatformInformation->IA32HealthFlags.Uint32;
} else {
DEBUG ((DEBUG_INFO, "Does not find any HOB stored CPU BIST information!\n"));
HealthData->Uint32 = 0;
}
}
return EFI_SUCCESS;
}
@@ -204,12 +207,12 @@ MpInitLibGetProcessorInfo (
EFI_STATUS
EFIAPI
MpInitLibStartupAllAPs (
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
)
{
return EFI_NOT_STARTED;
@@ -289,12 +292,12 @@ MpInitLibStartupAllAPs (
EFI_STATUS
EFIAPI
MpInitLibStartupThisAP (
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
)
{
return EFI_INVALID_PARAMETER;
@@ -329,8 +332,8 @@ MpInitLibStartupThisAP (
EFI_STATUS
EFIAPI
MpInitLibSwitchBSP (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
)
{
return EFI_UNSUPPORTED;
@@ -369,9 +372,9 @@ MpInitLibSwitchBSP (
EFI_STATUS
EFIAPI
MpInitLibEnableDisableAP (
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
)
{
return EFI_UNSUPPORTED;
@@ -396,12 +399,13 @@ MpInitLibEnableDisableAP (
EFI_STATUS
EFIAPI
MpInitLibWhoAmI (
OUT UINTN *ProcessorNumber
OUT UINTN *ProcessorNumber
)
{
if (ProcessorNumber == NULL) {
return EFI_INVALID_PARAMETER;
}
*ProcessorNumber = 0;
return EFI_SUCCESS;
}
@@ -427,9 +431,9 @@ MpInitLibWhoAmI (
EFI_STATUS
EFIAPI
MpInitLibStartupAllCPUs (
IN EFI_AP_PROCEDURE Procedure,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL
IN EFI_AP_PROCEDURE Procedure,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL
)
{
if (Procedure == NULL) {

File diff suppressed because it is too large Load Diff

View File

@@ -8,11 +8,11 @@
#include "MtrrLibUnitTest.h"
STATIC CONST MTRR_LIB_SYSTEM_PARAMETER mDefaultSystemParameter = {
STATIC CONST MTRR_LIB_SYSTEM_PARAMETER mDefaultSystemParameter = {
42, TRUE, TRUE, CacheUncacheable, 12
};
STATIC MTRR_LIB_SYSTEM_PARAMETER mSystemParameters[] = {
STATIC MTRR_LIB_SYSTEM_PARAMETER mSystemParameters[] = {
{ 38, TRUE, TRUE, CacheUncacheable, 12 },
{ 38, TRUE, TRUE, CacheWriteBack, 12 },
{ 38, TRUE, TRUE, CacheWriteThrough, 12 },
@@ -32,7 +32,7 @@ STATIC MTRR_LIB_SYSTEM_PARAMETER mSystemParameters[] = {
{ 48, TRUE, TRUE, CacheWriteCombining, 12 },
};
UINT32 mFixedMtrrsIndex[] = {
UINT32 mFixedMtrrsIndex[] = {
MSR_IA32_MTRR_FIX64K_00000,
MSR_IA32_MTRR_FIX16K_80000,
MSR_IA32_MTRR_FIX16K_A0000,
@@ -54,18 +54,18 @@ STATIC_ASSERT (
// Context structure to be used for most of the test cases.
//
typedef struct {
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
} MTRR_LIB_TEST_CONTEXT;
//
// Context structure to be used for GetFirmwareVariableMtrrCount() test.
//
typedef struct {
UINT32 NumberOfReservedVariableMtrrs;
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
UINT32 NumberOfReservedVariableMtrrs;
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
} MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT;
STATIC CHAR8 *mCacheDescription[] = { "UC", "WC", "N/A", "N/A", "WT", "WP", "WB" };
STATIC CHAR8 *mCacheDescription[] = { "UC", "WC", "N/A", "N/A", "WT", "WP", "WB" };
/**
Compare the actual memory ranges against expected memory ranges and return PASS when they match.
@@ -87,6 +87,7 @@ VerifyMemoryRanges (
)
{
UINTN Index;
UT_ASSERT_EQUAL (ExpectedMemoryRangeCount, ActualRangeCount);
for (Index = 0; Index < ExpectedMemoryRangeCount; Index++) {
UT_ASSERT_EQUAL (ExpectedMemoryRanges[Index].BaseAddress, ActualRanges[Index].BaseAddress);
@@ -105,11 +106,12 @@ VerifyMemoryRanges (
**/
VOID
DumpMemoryRanges (
MTRR_MEMORY_RANGE *Ranges,
UINTN RangeCount
MTRR_MEMORY_RANGE *Ranges,
UINTN RangeCount
)
{
UINTN Index;
UINTN Index;
for (Index = 0; Index < RangeCount; Index++) {
UT_LOG_INFO ("\t{ 0x%016llx, 0x%016llx, %a },\n", Ranges[Index].BaseAddress, Ranges[Index].Length, mCacheDescription[Ranges[Index].Type]);
}
@@ -130,17 +132,17 @@ DumpMemoryRanges (
**/
VOID
GenerateRandomMemoryTypeCombination (
IN UINT32 TotalCount,
OUT UINT32 *UcCount,
OUT UINT32 *WtCount,
OUT UINT32 *WbCount,
OUT UINT32 *WpCount,
OUT UINT32 *WcCount
IN UINT32 TotalCount,
OUT UINT32 *UcCount,
OUT UINT32 *WtCount,
OUT UINT32 *WbCount,
OUT UINT32 *WpCount,
OUT UINT32 *WcCount
)
{
UINTN Index;
UINT32 TotalMtrrCount;
UINT32 *CountPerType[5];
UINTN Index;
UINT32 TotalMtrrCount;
UINT32 *CountPerType[5];
CountPerType[0] = UcCount;
CountPerType[1] = WtCount;
@@ -183,38 +185,47 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
IN UNIT_TEST_CONTEXT Context
)
{
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
RETURN_STATUS Status;
UINT32 UcCount;
UINT32 WtCount;
UINT32 WbCount;
UINT32 WpCount;
UINT32 WcCount;
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
RETURN_STATUS Status;
UINT32 UcCount;
UINT32 WtCount;
UINT32 WbCount;
UINT32 WpCount;
UINT32 WcCount;
UINT32 MtrrIndex;
UINT8 *Scratch;
UINTN ScratchSize;
MTRR_SETTINGS LocalMtrrs;
UINT32 MtrrIndex;
UINT8 *Scratch;
UINTN ScratchSize;
MTRR_SETTINGS LocalMtrrs;
MTRR_MEMORY_RANGE RawMtrrRange[MTRR_NUMBER_OF_VARIABLE_MTRR];
MTRR_MEMORY_RANGE ExpectedMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ExpectedVariableMtrrUsage;
UINTN ExpectedMemoryRangesCount;
MTRR_MEMORY_RANGE RawMtrrRange[MTRR_NUMBER_OF_VARIABLE_MTRR];
MTRR_MEMORY_RANGE ExpectedMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ExpectedVariableMtrrUsage;
UINTN ExpectedMemoryRangesCount;
MTRR_MEMORY_RANGE ActualMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ActualVariableMtrrUsage;
UINTN ActualMemoryRangesCount;
MTRR_MEMORY_RANGE ActualMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ActualVariableMtrrUsage;
UINTN ActualMemoryRangesCount;
MTRR_SETTINGS *Mtrrs[2];
MTRR_SETTINGS *Mtrrs[2];
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *) Context;
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *)Context;
GenerateRandomMemoryTypeCombination (
SystemParameter->VariableMtrrCount - PatchPcdGet32 (PcdCpuNumberOfReservedVariableMtrrs),
&UcCount, &WtCount, &WbCount, &WpCount, &WcCount
&UcCount,
&WtCount,
&WbCount,
&WpCount,
&WcCount
);
GenerateValidAndConfigurableMtrrPairs (
SystemParameter->PhysicalAddressBits, RawMtrrRange,
UcCount, WtCount, WbCount, WpCount, WcCount
SystemParameter->PhysicalAddressBits,
RawMtrrRange,
UcCount,
WtCount,
WbCount,
WpCount,
WcCount
);
ExpectedVariableMtrrUsage = UcCount + WtCount + WbCount + WpCount + WcCount;
@@ -222,13 +233,20 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
GetEffectiveMemoryRanges (
SystemParameter->DefaultCacheType,
SystemParameter->PhysicalAddressBits,
RawMtrrRange, ExpectedVariableMtrrUsage,
ExpectedMemoryRanges, &ExpectedMemoryRangesCount
RawMtrrRange,
ExpectedVariableMtrrUsage,
ExpectedMemoryRanges,
&ExpectedMemoryRangesCount
);
UT_LOG_INFO (
"Total MTRR [%d]: UC=%d, WT=%d, WB=%d, WP=%d, WC=%d\n",
ExpectedVariableMtrrUsage, UcCount, WtCount, WbCount, WpCount, WcCount
ExpectedVariableMtrrUsage,
UcCount,
WtCount,
WbCount,
WpCount,
WcCount
);
UT_LOG_INFO ("--- Expected Memory Ranges [%d] ---\n", ExpectedMemoryRangesCount);
DumpMemoryRanges (ExpectedMemoryRanges, ExpectedMemoryRangesCount);
@@ -244,21 +262,28 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
for (MtrrIndex = 0; MtrrIndex < ARRAY_SIZE (Mtrrs); MtrrIndex++) {
Scratch = calloc (ScratchSize, sizeof (UINT8));
Status = MtrrSetMemoryAttributesInMtrrSettings (Mtrrs[MtrrIndex], Scratch, &ScratchSize, ExpectedMemoryRanges, ExpectedMemoryRangesCount);
Status = MtrrSetMemoryAttributesInMtrrSettings (Mtrrs[MtrrIndex], Scratch, &ScratchSize, ExpectedMemoryRanges, ExpectedMemoryRangesCount);
if (Status == RETURN_BUFFER_TOO_SMALL) {
Scratch = realloc (Scratch, ScratchSize);
Status = MtrrSetMemoryAttributesInMtrrSettings (Mtrrs[MtrrIndex], Scratch, &ScratchSize, ExpectedMemoryRanges, ExpectedMemoryRangesCount);
Status = MtrrSetMemoryAttributesInMtrrSettings (Mtrrs[MtrrIndex], Scratch, &ScratchSize, ExpectedMemoryRanges, ExpectedMemoryRangesCount);
}
UT_ASSERT_STATUS_EQUAL (Status, RETURN_SUCCESS);
if (Mtrrs[MtrrIndex] == NULL) {
ZeroMem (&LocalMtrrs, sizeof (LocalMtrrs));
MtrrGetAllMtrrs (&LocalMtrrs);
}
ActualMemoryRangesCount = ARRAY_SIZE (ActualMemoryRanges);
CollectTestResult (
SystemParameter->DefaultCacheType, SystemParameter->PhysicalAddressBits, SystemParameter->VariableMtrrCount,
&LocalMtrrs, ActualMemoryRanges, &ActualMemoryRangesCount, &ActualVariableMtrrUsage
SystemParameter->DefaultCacheType,
SystemParameter->PhysicalAddressBits,
SystemParameter->VariableMtrrCount,
&LocalMtrrs,
ActualMemoryRanges,
&ActualMemoryRangesCount,
&ActualVariableMtrrUsage
);
UT_LOG_INFO ("--- Actual Memory Ranges [%d] ---\n", ActualMemoryRangesCount);
@@ -284,20 +309,20 @@ UnitTestMtrrSetMemoryAttributesInMtrrSettings (
UNIT_TEST_STATUS
EFIAPI
UnitTestInvalidMemoryLayouts (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
MTRR_MEMORY_RANGE Ranges[MTRR_NUMBER_OF_VARIABLE_MTRR * 2 + 1];
UINTN RangeCount;
UINT64 MaxAddress;
UINT32 Index;
UINT64 BaseAddress;
UINT64 Length;
RETURN_STATUS Status;
UINTN ScratchSize;
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
MTRR_MEMORY_RANGE Ranges[MTRR_NUMBER_OF_VARIABLE_MTRR * 2 + 1];
UINTN RangeCount;
UINT64 MaxAddress;
UINT32 Index;
UINT64 BaseAddress;
UINT64 Length;
RETURN_STATUS Status;
UINTN ScratchSize;
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *) Context;
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *)Context;
RangeCount = Random32 (1, ARRAY_SIZE (Ranges));
MaxAddress = 1ull << SystemParameter->PhysicalAddressBits;
@@ -313,13 +338,15 @@ UnitTestInvalidMemoryLayouts (
Ranges[Index].Type = GenerateRandomCacheType ();
Status = MtrrSetMemoryAttribute (
Ranges[Index].BaseAddress, Ranges[Index].Length, Ranges[Index].Type
);
Ranges[Index].BaseAddress,
Ranges[Index].Length,
Ranges[Index].Type
);
UT_ASSERT_TRUE (RETURN_ERROR (Status));
}
ScratchSize = 0;
Status = MtrrSetMemoryAttributesInMtrrSettings (NULL, NULL, &ScratchSize, Ranges, RangeCount);
Status = MtrrSetMemoryAttributesInMtrrSettings (NULL, NULL, &ScratchSize, Ranges, RangeCount);
UT_ASSERT_TRUE (RETURN_ERROR (Status));
return UNIT_TEST_PASSED;
@@ -344,7 +371,7 @@ UnitTestIsMtrrSupported (
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
//
@@ -357,8 +384,8 @@ UnitTestIsMtrrSupported (
//
// MTRR capability on in CPUID leaf, but no variable or fixed MTRRs.
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 0;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 0;
SystemParameter.FixedMtrrSupported = FALSE;
InitializeMtrrRegs (&SystemParameter);
UT_ASSERT_FALSE (IsMtrrSupported ());
@@ -366,8 +393,8 @@ UnitTestIsMtrrSupported (
//
// MTRR capability on in CPUID leaf, but no variable MTRRs.
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 0;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 0;
SystemParameter.FixedMtrrSupported = TRUE;
InitializeMtrrRegs (&SystemParameter);
UT_ASSERT_FALSE (IsMtrrSupported ());
@@ -375,8 +402,8 @@ UnitTestIsMtrrSupported (
//
// MTRR capability on in CPUID leaf, but no fixed MTRRs.
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 7;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 7;
SystemParameter.FixedMtrrSupported = FALSE;
InitializeMtrrRegs (&SystemParameter);
UT_ASSERT_FALSE (IsMtrrSupported ());
@@ -384,8 +411,8 @@ UnitTestIsMtrrSupported (
//
// MTRR capability on in CPUID leaf with both variable and fixed MTRRs.
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 7;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 7;
SystemParameter.FixedMtrrSupported = TRUE;
InitializeMtrrRegs (&SystemParameter);
UT_ASSERT_TRUE (IsMtrrSupported ());
@@ -409,11 +436,11 @@ UnitTestGetVariableMtrrCount (
IN UNIT_TEST_CONTEXT Context
)
{
UINT32 Result;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
UINT32 Result;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
//
@@ -445,7 +472,7 @@ UnitTestGetVariableMtrrCount (
InitializeMtrrRegs (&SystemParameter);
UT_EXPECT_ASSERT_FAILURE (GetVariableMtrrCount (), NULL);
SystemParameter.MtrrSupported = TRUE;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = MAX_UINT8;
InitializeMtrrRegs (&SystemParameter);
UT_EXPECT_ASSERT_FAILURE (GetVariableMtrrCount (), NULL);
@@ -469,12 +496,12 @@ UnitTestGetFirmwareVariableMtrrCount (
IN UNIT_TEST_CONTEXT Context
)
{
UINT32 Result;
UINT32 ReservedMtrrs;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *LocalContext;
UINT32 Result;
UINT32 ReservedMtrrs;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *) Context;
LocalContext = (MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
@@ -516,7 +543,7 @@ UnitTestGetFirmwareVariableMtrrCount (
//
// Negative test case when Fixed MTRRs are not supported
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.FixedMtrrSupported = FALSE;
InitializeMtrrRegs (&SystemParameter);
PatchPcdSet32 (PcdCpuNumberOfReservedVariableMtrrs, 2);
@@ -527,7 +554,7 @@ UnitTestGetFirmwareVariableMtrrCount (
// Expect ASSERT() if variable MTRR count is > MTRR_NUMBER_OF_VARIABLE_MTRR
//
SystemParameter.FixedMtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = MTRR_NUMBER_OF_VARIABLE_MTRR + 1;
SystemParameter.VariableMtrrCount = MTRR_NUMBER_OF_VARIABLE_MTRR + 1;
InitializeMtrrRegs (&SystemParameter);
UT_EXPECT_ASSERT_FAILURE (GetFirmwareVariableMtrrCount (), NULL);
@@ -569,17 +596,17 @@ UnitTestMtrrGetFixedMtrr (
IN UNIT_TEST_CONTEXT Context
)
{
MTRR_FIXED_SETTINGS *Result;
MTRR_FIXED_SETTINGS ExpectedFixedSettings;
MTRR_FIXED_SETTINGS FixedSettings;
UINTN Index;
UINTN MsrIndex;
UINTN ByteIndex;
UINT64 MsrValue;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
MTRR_FIXED_SETTINGS *Result;
MTRR_FIXED_SETTINGS ExpectedFixedSettings;
MTRR_FIXED_SETTINGS FixedSettings;
UINTN Index;
UINTN MsrIndex;
UINTN ByteIndex;
UINT64 MsrValue;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
InitializeMtrrRegs (&SystemParameter);
@@ -594,6 +621,7 @@ UnitTestMtrrGetFixedMtrr (
for (ByteIndex = 0; ByteIndex < sizeof (UINT64); ByteIndex++) {
MsrValue = MsrValue | LShiftU64 (GenerateRandomCacheType (), ByteIndex * 8);
}
ExpectedFixedSettings.Mtrr[MsrIndex] = MsrValue;
AsmWriteMsr64 (mFixedMtrrsIndex[MsrIndex], MsrValue);
}
@@ -631,18 +659,18 @@ UnitTestMtrrGetFixedMtrr (
UNIT_TEST_STATUS
EFIAPI
UnitTestMtrrGetAllMtrrs (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
MTRR_SETTINGS *Result;
MTRR_SETTINGS Mtrrs;
MTRR_SETTINGS ExpectedMtrrs;
MTRR_VARIABLE_SETTING VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
UINT32 Index;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
MTRR_SETTINGS *Result;
MTRR_SETTINGS Mtrrs;
MTRR_SETTINGS ExpectedMtrrs;
MTRR_VARIABLE_SETTING VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
UINT32 Index;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
InitializeMtrrRegs (&SystemParameter);
@@ -652,6 +680,7 @@ UnitTestMtrrGetAllMtrrs (
AsmWriteMsr64 (MSR_IA32_MTRR_PHYSBASE0 + (Index << 1), VariableMtrr[Index].Base);
AsmWriteMsr64 (MSR_IA32_MTRR_PHYSMASK0 + (Index << 1), VariableMtrr[Index].Mask);
}
Result = MtrrGetAllMtrrs (&Mtrrs);
UT_ASSERT_EQUAL ((UINTN)Result, (UINTN)&Mtrrs);
UT_ASSERT_MEM_EQUAL (Mtrrs.Variables.Mtrr, VariableMtrr, sizeof (MTRR_VARIABLE_SETTING) * SystemParameter.VariableMtrrCount);
@@ -671,7 +700,7 @@ UnitTestMtrrGetAllMtrrs (
//
// Expect ASSERT() if variable MTRR count is > MTRR_NUMBER_OF_VARIABLE_MTRR
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = MTRR_NUMBER_OF_VARIABLE_MTRR + 1;
InitializeMtrrRegs (&SystemParameter);
UT_EXPECT_ASSERT_FAILURE (MtrrGetAllMtrrs (&Mtrrs), NULL);
@@ -695,21 +724,21 @@ UnitTestMtrrSetAllMtrrs (
IN UNIT_TEST_CONTEXT Context
)
{
MTRR_SETTINGS *Result;
MTRR_SETTINGS Mtrrs;
UINT32 Index;
MSR_IA32_MTRR_DEF_TYPE_REGISTER Default;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
MTRR_SETTINGS *Result;
MTRR_SETTINGS Mtrrs;
UINT32 Index;
MSR_IA32_MTRR_DEF_TYPE_REGISTER Default;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_LIB_TEST_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
InitializeMtrrRegs (&SystemParameter);
Default.Uint64 = 0;
Default.Bits.E = 1;
Default.Bits.FE = 1;
Default.Uint64 = 0;
Default.Bits.E = 1;
Default.Bits.FE = 1;
Default.Bits.Type = GenerateRandomCacheType ();
ZeroMem (&Mtrrs, sizeof (Mtrrs));
@@ -717,6 +746,7 @@ UnitTestMtrrSetAllMtrrs (
for (Index = 0; Index < SystemParameter.VariableMtrrCount; Index++) {
GenerateRandomMtrrPair (SystemParameter.PhysicalAddressBits, GenerateRandomCacheType (), &Mtrrs.Variables.Mtrr[Index], NULL);
}
Result = MtrrSetAllMtrrs (&Mtrrs);
UT_ASSERT_EQUAL ((UINTN)Result, (UINTN)&Mtrrs);
@@ -745,18 +775,18 @@ UnitTestMtrrGetMemoryAttributeInVariableMtrr (
IN UNIT_TEST_CONTEXT Context
)
{
MTRR_LIB_TEST_CONTEXT *LocalContext;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
UINT32 Result;
MTRR_VARIABLE_SETTING VariableSetting[MTRR_NUMBER_OF_VARIABLE_MTRR];
VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
UINT64 ValidMtrrBitsMask;
UINT64 ValidMtrrAddressMask;
UINT32 Index;
MSR_IA32_MTRR_PHYSBASE_REGISTER Base;
MSR_IA32_MTRR_PHYSMASK_REGISTER Mask;
MTRR_LIB_TEST_CONTEXT *LocalContext;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
UINT32 Result;
MTRR_VARIABLE_SETTING VariableSetting[MTRR_NUMBER_OF_VARIABLE_MTRR];
VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
UINT64 ValidMtrrBitsMask;
UINT64 ValidMtrrAddressMask;
UINT32 Index;
MSR_IA32_MTRR_PHYSBASE_REGISTER Base;
MSR_IA32_MTRR_PHYSMASK_REGISTER Mask;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
@@ -770,16 +800,17 @@ UnitTestMtrrGetMemoryAttributeInVariableMtrr (
AsmWriteMsr64 (MSR_IA32_MTRR_PHYSBASE0 + (Index << 1), VariableSetting[Index].Base);
AsmWriteMsr64 (MSR_IA32_MTRR_PHYSMASK0 + (Index << 1), VariableSetting[Index].Mask);
}
Result = MtrrGetMemoryAttributeInVariableMtrr (ValidMtrrBitsMask, ValidMtrrAddressMask, VariableMtrr);
UT_ASSERT_EQUAL (Result, SystemParameter.VariableMtrrCount);
for (Index = 0; Index < SystemParameter.VariableMtrrCount; Index++) {
Base.Uint64 = VariableMtrr[Index].BaseAddress;
Base.Bits.Type = (UINT32) VariableMtrr[Index].Type;
Base.Bits.Type = (UINT32)VariableMtrr[Index].Type;
UT_ASSERT_EQUAL (Base.Uint64, VariableSetting[Index].Base);
Mask.Uint64 = ~(VariableMtrr[Index].Length - 1) & ValidMtrrBitsMask;
Mask.Bits.V = 1;
Mask.Uint64 = ~(VariableMtrr[Index].Length - 1) & ValidMtrrBitsMask;
Mask.Bits.V = 1;
UT_ASSERT_EQUAL (Mask.Uint64, VariableSetting[Index].Mask);
}
@@ -794,7 +825,7 @@ UnitTestMtrrGetMemoryAttributeInVariableMtrr (
//
// Expect ASSERT() if variable MTRR count is > MTRR_NUMBER_OF_VARIABLE_MTRR
//
SystemParameter.MtrrSupported = TRUE;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = MTRR_NUMBER_OF_VARIABLE_MTRR + 1;
InitializeMtrrRegs (&SystemParameter);
UT_EXPECT_ASSERT_FAILURE (MtrrGetMemoryAttributeInVariableMtrr (ValidMtrrBitsMask, ValidMtrrAddressMask, VariableMtrr), NULL);
@@ -837,11 +868,11 @@ UnitTestMtrrGetDefaultMemoryType (
IN UNIT_TEST_CONTEXT Context
)
{
MTRR_LIB_TEST_CONTEXT *LocalContext;
UINTN Index;
MTRR_MEMORY_CACHE_TYPE Result;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_MEMORY_CACHE_TYPE CacheType[5];
MTRR_LIB_TEST_CONTEXT *LocalContext;
UINTN Index;
MTRR_MEMORY_CACHE_TYPE Result;
MTRR_LIB_SYSTEM_PARAMETER SystemParameter;
MTRR_MEMORY_CACHE_TYPE CacheType[5];
CacheType[0] = CacheUncacheable;
CacheType[1] = CacheWriteCombining;
@@ -849,7 +880,7 @@ UnitTestMtrrGetDefaultMemoryType (
CacheType[3] = CacheWriteProtected;
CacheType[4] = CacheWriteBack;
LocalContext = (MTRR_LIB_TEST_CONTEXT *) Context;
LocalContext = (MTRR_LIB_TEST_CONTEXT *)Context;
CopyMem (&SystemParameter, LocalContext->SystemParameter, sizeof (SystemParameter));
//
@@ -871,15 +902,15 @@ UnitTestMtrrGetDefaultMemoryType (
Result = MtrrGetDefaultMemoryType ();
UT_ASSERT_EQUAL (Result, CacheUncacheable);
SystemParameter.MtrrSupported = TRUE;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.FixedMtrrSupported = FALSE;
InitializeMtrrRegs (&SystemParameter);
Result = MtrrGetDefaultMemoryType ();
UT_ASSERT_EQUAL (Result, CacheUncacheable);
SystemParameter.MtrrSupported = TRUE;
SystemParameter.MtrrSupported = TRUE;
SystemParameter.FixedMtrrSupported = TRUE;
SystemParameter.VariableMtrrCount = 0;
SystemParameter.VariableMtrrCount = 0;
InitializeMtrrRegs (&SystemParameter);
Result = MtrrGetDefaultMemoryType ();
UT_ASSERT_EQUAL (Result, CacheUncacheable);
@@ -903,37 +934,46 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
IN UNIT_TEST_CONTEXT Context
)
{
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
RETURN_STATUS Status;
UINT32 UcCount;
UINT32 WtCount;
UINT32 WbCount;
UINT32 WpCount;
UINT32 WcCount;
CONST MTRR_LIB_SYSTEM_PARAMETER *SystemParameter;
RETURN_STATUS Status;
UINT32 UcCount;
UINT32 WtCount;
UINT32 WbCount;
UINT32 WpCount;
UINT32 WcCount;
UINTN MtrrIndex;
UINTN Index;
MTRR_SETTINGS LocalMtrrs;
UINTN MtrrIndex;
UINTN Index;
MTRR_SETTINGS LocalMtrrs;
MTRR_MEMORY_RANGE RawMtrrRange[MTRR_NUMBER_OF_VARIABLE_MTRR];
MTRR_MEMORY_RANGE ExpectedMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ExpectedVariableMtrrUsage;
UINTN ExpectedMemoryRangesCount;
MTRR_MEMORY_RANGE RawMtrrRange[MTRR_NUMBER_OF_VARIABLE_MTRR];
MTRR_MEMORY_RANGE ExpectedMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ExpectedVariableMtrrUsage;
UINTN ExpectedMemoryRangesCount;
MTRR_MEMORY_RANGE ActualMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ActualVariableMtrrUsage;
UINTN ActualMemoryRangesCount;
MTRR_MEMORY_RANGE ActualMemoryRanges[MTRR_NUMBER_OF_FIXED_MTRR * sizeof (UINT64) + 2 * MTRR_NUMBER_OF_VARIABLE_MTRR + 1];
UINT32 ActualVariableMtrrUsage;
UINTN ActualMemoryRangesCount;
MTRR_SETTINGS *Mtrrs[2];
MTRR_SETTINGS *Mtrrs[2];
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *) Context;
SystemParameter = (MTRR_LIB_SYSTEM_PARAMETER *)Context;
GenerateRandomMemoryTypeCombination (
SystemParameter->VariableMtrrCount - PatchPcdGet32 (PcdCpuNumberOfReservedVariableMtrrs),
&UcCount, &WtCount, &WbCount, &WpCount, &WcCount
&UcCount,
&WtCount,
&WbCount,
&WpCount,
&WcCount
);
GenerateValidAndConfigurableMtrrPairs (
SystemParameter->PhysicalAddressBits, RawMtrrRange,
UcCount, WtCount, WbCount, WpCount, WcCount
SystemParameter->PhysicalAddressBits,
RawMtrrRange,
UcCount,
WtCount,
WbCount,
WpCount,
WcCount
);
ExpectedVariableMtrrUsage = UcCount + WtCount + WbCount + WpCount + WcCount;
@@ -941,8 +981,10 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
GetEffectiveMemoryRanges (
SystemParameter->DefaultCacheType,
SystemParameter->PhysicalAddressBits,
RawMtrrRange, ExpectedVariableMtrrUsage,
ExpectedMemoryRanges, &ExpectedMemoryRangesCount
RawMtrrRange,
ExpectedVariableMtrrUsage,
ExpectedMemoryRanges,
&ExpectedMemoryRangesCount
);
UT_LOG_INFO ("--- Expected Memory Ranges [%d] ---\n", ExpectedMemoryRangesCount);
@@ -964,7 +1006,7 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
ExpectedMemoryRanges[Index].Type
);
UT_ASSERT_TRUE (Status == RETURN_SUCCESS || Status == RETURN_OUT_OF_RESOURCES || Status == RETURN_BUFFER_TOO_SMALL);
if (Status == RETURN_OUT_OF_RESOURCES || Status == RETURN_BUFFER_TOO_SMALL) {
if ((Status == RETURN_OUT_OF_RESOURCES) || (Status == RETURN_BUFFER_TOO_SMALL)) {
return UNIT_TEST_SKIPPED;
}
}
@@ -973,10 +1015,16 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
ZeroMem (&LocalMtrrs, sizeof (LocalMtrrs));
MtrrGetAllMtrrs (&LocalMtrrs);
}
ActualMemoryRangesCount = ARRAY_SIZE (ActualMemoryRanges);
CollectTestResult (
SystemParameter->DefaultCacheType, SystemParameter->PhysicalAddressBits, SystemParameter->VariableMtrrCount,
&LocalMtrrs, ActualMemoryRanges, &ActualMemoryRangesCount, &ActualVariableMtrrUsage
SystemParameter->DefaultCacheType,
SystemParameter->PhysicalAddressBits,
SystemParameter->VariableMtrrCount,
&LocalMtrrs,
ActualMemoryRanges,
&ActualMemoryRangesCount,
&ActualVariableMtrrUsage
);
UT_LOG_INFO ("--- Actual Memory Ranges [%d] ---\n", ActualMemoryRangesCount);
DumpMemoryRanges (ActualMemoryRanges, ActualMemoryRangesCount);
@@ -989,7 +1037,6 @@ UnitTestMtrrSetMemoryAttributeInMtrrSettings (
return UNIT_TEST_PASSED;
}
/**
Prep routine for UnitTestGetFirmwareVariableMtrrCount().
@@ -1003,7 +1050,7 @@ SavePcdValue (
{
MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *) Context;
LocalContext = (MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *)Context;
LocalContext->NumberOfReservedVariableMtrrs = PatchPcdGet32 (PcdCpuNumberOfReservedVariableMtrrs);
return UNIT_TEST_PASSED;
}
@@ -1021,7 +1068,7 @@ RestorePcdValue (
{
MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *LocalContext;
LocalContext = (MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *) Context;
LocalContext = (MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT *)Context;
PatchPcdSet32 (PcdCpuNumberOfReservedVariableMtrrs, LocalContext->NumberOfReservedVariableMtrrs);
}
@@ -1040,20 +1087,20 @@ STATIC
EFI_STATUS
EFIAPI
UnitTestingEntry (
UINTN Iteration
UINTN Iteration
)
{
EFI_STATUS Status;
UNIT_TEST_FRAMEWORK_HANDLE Framework;
UNIT_TEST_SUITE_HANDLE MtrrApiTests;
UINTN Index;
UINTN SystemIndex;
MTRR_LIB_TEST_CONTEXT Context;
MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT GetFirmwareVariableMtrrCountContext;
EFI_STATUS Status;
UNIT_TEST_FRAMEWORK_HANDLE Framework;
UNIT_TEST_SUITE_HANDLE MtrrApiTests;
UINTN Index;
UINTN SystemIndex;
MTRR_LIB_TEST_CONTEXT Context;
MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT GetFirmwareVariableMtrrCountContext;
Context.SystemParameter = &mDefaultSystemParameter;
GetFirmwareVariableMtrrCountContext.SystemParameter = &mDefaultSystemParameter;
Framework = NULL;
Framework = NULL;
//
// Setup the test framework for running the tests.
@@ -1077,24 +1124,26 @@ UnitTestingEntry (
Status = EFI_OUT_OF_RESOURCES;
goto EXIT;
}
AddTestCase (MtrrApiTests, "Test IsMtrrSupported", "MtrrSupported", UnitTestIsMtrrSupported, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test GetVariableMtrrCount", "GetVariableMtrrCount", UnitTestGetVariableMtrrCount, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test GetFirmwareVariableMtrrCount", "GetFirmwareVariableMtrrCount", UnitTestGetFirmwareVariableMtrrCount, SavePcdValue, RestorePcdValue, &GetFirmwareVariableMtrrCountContext);
AddTestCase (MtrrApiTests, "Test MtrrGetMemoryAttribute", "MtrrGetMemoryAttribute", UnitTestMtrrGetMemoryAttribute, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetFixedMtrr", "MtrrGetFixedMtrr", UnitTestMtrrGetFixedMtrr, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetAllMtrrs", "MtrrGetAllMtrrs", UnitTestMtrrGetAllMtrrs, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrSetAllMtrrs", "MtrrSetAllMtrrs", UnitTestMtrrSetAllMtrrs, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test IsMtrrSupported", "MtrrSupported", UnitTestIsMtrrSupported, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test GetVariableMtrrCount", "GetVariableMtrrCount", UnitTestGetVariableMtrrCount, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test GetFirmwareVariableMtrrCount", "GetFirmwareVariableMtrrCount", UnitTestGetFirmwareVariableMtrrCount, SavePcdValue, RestorePcdValue, &GetFirmwareVariableMtrrCountContext);
AddTestCase (MtrrApiTests, "Test MtrrGetMemoryAttribute", "MtrrGetMemoryAttribute", UnitTestMtrrGetMemoryAttribute, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetFixedMtrr", "MtrrGetFixedMtrr", UnitTestMtrrGetFixedMtrr, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetAllMtrrs", "MtrrGetAllMtrrs", UnitTestMtrrGetAllMtrrs, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrSetAllMtrrs", "MtrrSetAllMtrrs", UnitTestMtrrSetAllMtrrs, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetMemoryAttributeInVariableMtrr", "MtrrGetMemoryAttributeInVariableMtrr", UnitTestMtrrGetMemoryAttributeInVariableMtrr, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrDebugPrintAllMtrrs", "MtrrDebugPrintAllMtrrs", UnitTestMtrrDebugPrintAllMtrrs, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetDefaultMemoryType", "MtrrGetDefaultMemoryType", UnitTestMtrrGetDefaultMemoryType, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrDebugPrintAllMtrrs", "MtrrDebugPrintAllMtrrs", UnitTestMtrrDebugPrintAllMtrrs, NULL, NULL, &Context);
AddTestCase (MtrrApiTests, "Test MtrrGetDefaultMemoryType", "MtrrGetDefaultMemoryType", UnitTestMtrrGetDefaultMemoryType, NULL, NULL, &Context);
for (SystemIndex = 0; SystemIndex < ARRAY_SIZE (mSystemParameters); SystemIndex++) {
for (Index = 0; Index < Iteration; Index++) {
AddTestCase (MtrrApiTests, "Test InvalidMemoryLayouts", "InvalidMemoryLayouts", UnitTestInvalidMemoryLayouts, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributeInMtrrSettings", "MtrrSetMemoryAttributeInMtrrSettings", UnitTestMtrrSetMemoryAttributeInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
AddTestCase (MtrrApiTests, "Test InvalidMemoryLayouts", "InvalidMemoryLayouts", UnitTestInvalidMemoryLayouts, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributeInMtrrSettings", "MtrrSetMemoryAttributeInMtrrSettings", UnitTestMtrrSetMemoryAttributeInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
AddTestCase (MtrrApiTests, "Test MtrrSetMemoryAttributesInMtrrSettings", "MtrrSetMemoryAttributesInMtrrSettings", UnitTestMtrrSetMemoryAttributesInMtrrSettings, InitializeSystem, NULL, &mSystemParameters[SystemIndex]);
}
}
//
// Execute the tests.
//
@@ -1118,14 +1167,14 @@ EXIT:
**/
INT32
main (
INT32 Argc,
CHAR8 *Argv[]
INT32 Argc,
CHAR8 *Argv[]
)
{
UINTN Count;
UINTN Count;
DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
srand ((unsigned int) time (NULL));
srand ((unsigned int)time (NULL));
//
// MtrrLibUnitTest generate-random-numbers <path to MtrrLib/UnitTest/RandomNumber.c> <random-number count>

View File

@@ -29,21 +29,21 @@
#include <Register/Cpuid.h>
#include <Register/Msr.h>
#define UNIT_TEST_APP_NAME "MtrrLib Unit Tests"
#define UNIT_TEST_APP_VERSION "1.0"
#define UNIT_TEST_APP_NAME "MtrrLib Unit Tests"
#define UNIT_TEST_APP_VERSION "1.0"
#define SCRATCH_BUFFER_SIZE SIZE_16KB
#define SCRATCH_BUFFER_SIZE SIZE_16KB
typedef struct {
UINT8 PhysicalAddressBits;
BOOLEAN MtrrSupported;
BOOLEAN FixedMtrrSupported;
MTRR_MEMORY_CACHE_TYPE DefaultCacheType;
UINT32 VariableMtrrCount;
UINT8 PhysicalAddressBits;
BOOLEAN MtrrSupported;
BOOLEAN FixedMtrrSupported;
MTRR_MEMORY_CACHE_TYPE DefaultCacheType;
UINT32 VariableMtrrCount;
} MTRR_LIB_SYSTEM_PARAMETER;
extern UINT32 mFixedMtrrsIndex[];
extern BOOLEAN mRandomInput;
extern UINT32 mFixedMtrrsIndex[];
extern BOOLEAN mRandomInput;
/**
Initialize the MTRR registers.
@@ -64,7 +64,7 @@ InitializeMtrrRegs (
UNIT_TEST_STATUS
EFIAPI
InitializeSystem (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
);
/**
@@ -88,13 +88,13 @@ GenerateRandomCacheType (
**/
VOID
GenerateValidAndConfigurableMtrrPairs (
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 UcCount,
IN UINT32 WtCount,
IN UINT32 WbCount,
IN UINT32 WpCount,
IN UINT32 WcCount
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 UcCount,
IN UINT32 WtCount,
IN UINT32 WbCount,
IN UINT32 WpCount,
IN UINT32 WcCount
);
/**
@@ -109,12 +109,12 @@ GenerateValidAndConfigurableMtrrPairs (
**/
VOID
GetEffectiveMemoryRanges (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
OUT MTRR_MEMORY_RANGE *MemoryRanges,
OUT UINTN *MemoryRangeCount
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
OUT MTRR_MEMORY_RANGE *MemoryRanges,
OUT UINTN *MemoryRangeCount
);
/**
@@ -127,10 +127,10 @@ GetEffectiveMemoryRanges (
**/
VOID
GenerateRandomMtrrPair (
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_CACHE_TYPE CacheType,
OUT MTRR_VARIABLE_SETTING *MtrrPair OPTIONAL,
OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_CACHE_TYPE CacheType,
OUT MTRR_VARIABLE_SETTING *MtrrPair OPTIONAL,
OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL
);
/**
@@ -146,13 +146,13 @@ GenerateRandomMtrrPair (
**/
VOID
CollectTestResult (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN UINT32 VariableMtrrCount,
IN MTRR_SETTINGS *Mtrrs,
OUT MTRR_MEMORY_RANGE *Ranges,
IN OUT UINTN *RangeCount,
OUT UINT32 *MtrrCount
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN UINT32 VariableMtrrCount,
IN MTRR_SETTINGS *Mtrrs,
OUT MTRR_MEMORY_RANGE *Ranges,
IN OUT UINTN *RangeCount,
OUT UINT32 *MtrrCount
);
/**
@@ -189,7 +189,8 @@ Random32 (
**/
VOID
GenerateRandomNumbers (
CHAR8 *FilePath,
UINTN Count
CHAR8 *FilePath,
UINTN Count
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -8,9 +8,9 @@
#include "MtrrLibUnitTest.h"
MTRR_MEMORY_CACHE_TYPE mMemoryCacheTypes[] = {
MTRR_MEMORY_CACHE_TYPE mMemoryCacheTypes[] = {
CacheUncacheable, CacheWriteCombining, CacheWriteThrough, CacheWriteProtected, CacheWriteBack
};
};
UINT64 mFixedMtrrsValue[MTRR_NUMBER_OF_FIXED_MTRR];
MSR_IA32_MTRR_PHYSBASE_REGISTER mVariableMtrrsPhysBase[MTRR_NUMBER_OF_VARIABLE_MTRR];
@@ -20,10 +20,10 @@ MSR_IA32_MTRRCAP_REGISTER mMtrrCapMsr;
CPUID_VERSION_INFO_EDX mCpuidVersionInfoEdx;
CPUID_VIR_PHY_ADDRESS_SIZE_EAX mCpuidVirPhyAddressSizeEax;
BOOLEAN mRandomInput;
UINTN mNumberIndex = 0;
extern UINTN mNumbers[];
extern UINTN mNumberCount;
BOOLEAN mRandomInput;
UINTN mNumberIndex = 0;
extern UINTN mNumbers[];
extern UINTN mNumberCount;
/**
Return a random number between 0 and RAND_MAX.
@@ -65,8 +65,8 @@ CHAR8 mContentTemplate[] = {
**/
VOID
GenerateRandomNumbers (
CHAR8 *FilePath,
UINTN Count
CHAR8 *FilePath,
UINTN Count
)
{
FILE *File;
@@ -78,8 +78,10 @@ GenerateRandomNumbers (
if (Index % 10 == 0) {
fprintf (File, "\n ");
}
fprintf (File, " %d,", rand ());
}
fprintf (File, "\n};\n");
fclose (File);
}
@@ -112,38 +114,41 @@ GenerateRandomNumbers (
UINT32
EFIAPI
UnitTestMtrrLibAsmCpuid (
IN UINT32 Index,
OUT UINT32 *Eax OPTIONAL,
OUT UINT32 *Ebx OPTIONAL,
OUT UINT32 *Ecx OPTIONAL,
OUT UINT32 *Edx OPTIONAL
IN UINT32 Index,
OUT UINT32 *Eax OPTIONAL,
OUT UINT32 *Ebx OPTIONAL,
OUT UINT32 *Ecx OPTIONAL,
OUT UINT32 *Edx OPTIONAL
)
{
switch (Index) {
case CPUID_VERSION_INFO:
if (Edx != NULL) {
*Edx = mCpuidVersionInfoEdx.Uint32;
}
return Index;
break;
case CPUID_EXTENDED_FUNCTION:
if (Eax != NULL) {
*Eax = CPUID_VIR_PHY_ADDRESS_SIZE;
}
return Index;
break;
case CPUID_VIR_PHY_ADDRESS_SIZE:
if (Eax != NULL) {
*Eax = mCpuidVirPhyAddressSizeEax.Uint32;
}
return Index;
break;
case CPUID_VERSION_INFO:
if (Edx != NULL) {
*Edx = mCpuidVersionInfoEdx.Uint32;
}
return Index;
break;
case CPUID_EXTENDED_FUNCTION:
if (Eax != NULL) {
*Eax = CPUID_VIR_PHY_ADDRESS_SIZE;
}
return Index;
break;
case CPUID_VIR_PHY_ADDRESS_SIZE:
if (Eax != NULL) {
*Eax = mCpuidVirPhyAddressSizeEax.Uint32;
}
return Index;
break;
}
//
// Should never fall through to here
//
ASSERT(FALSE);
ASSERT (FALSE);
return Index;
}
@@ -163,11 +168,11 @@ UnitTestMtrrLibAsmCpuid (
**/
UINT64
EFIAPI
UnitTestMtrrLibAsmReadMsr64(
UnitTestMtrrLibAsmReadMsr64 (
IN UINT32 MsrIndex
)
{
UINT32 Index;
UINT32 Index;
for (Index = 0; Index < ARRAY_SIZE (mFixedMtrrsValue); Index++) {
if (MsrIndex == mFixedMtrrsIndex[Index]) {
@@ -176,7 +181,8 @@ UnitTestMtrrLibAsmReadMsr64(
}
if ((MsrIndex >= MSR_IA32_MTRR_PHYSBASE0) &&
(MsrIndex <= MSR_IA32_MTRR_PHYSMASK0 + (MTRR_NUMBER_OF_VARIABLE_MTRR << 1))) {
(MsrIndex <= MSR_IA32_MTRR_PHYSMASK0 + (MTRR_NUMBER_OF_VARIABLE_MTRR << 1)))
{
if (MsrIndex % 2 == 0) {
Index = (MsrIndex - MSR_IA32_MTRR_PHYSBASE0) >> 1;
return mVariableMtrrsPhysBase[Index].Uint64;
@@ -197,7 +203,7 @@ UnitTestMtrrLibAsmReadMsr64(
//
// Should never fall through to here
//
ASSERT(FALSE);
ASSERT (FALSE);
return 0;
}
@@ -220,12 +226,12 @@ UnitTestMtrrLibAsmReadMsr64(
**/
UINT64
EFIAPI
UnitTestMtrrLibAsmWriteMsr64(
IN UINT32 MsrIndex,
IN UINT64 Value
UnitTestMtrrLibAsmWriteMsr64 (
IN UINT32 MsrIndex,
IN UINT64 Value
)
{
UINT32 Index;
UINT32 Index;
for (Index = 0; Index < ARRAY_SIZE (mFixedMtrrsValue); Index++) {
if (MsrIndex == mFixedMtrrsIndex[Index]) {
@@ -235,13 +241,14 @@ UnitTestMtrrLibAsmWriteMsr64(
}
if ((MsrIndex >= MSR_IA32_MTRR_PHYSBASE0) &&
(MsrIndex <= MSR_IA32_MTRR_PHYSMASK0 + (MTRR_NUMBER_OF_VARIABLE_MTRR << 1))) {
(MsrIndex <= MSR_IA32_MTRR_PHYSMASK0 + (MTRR_NUMBER_OF_VARIABLE_MTRR << 1)))
{
if (MsrIndex % 2 == 0) {
Index = (MsrIndex - MSR_IA32_MTRR_PHYSBASE0) >> 1;
Index = (MsrIndex - MSR_IA32_MTRR_PHYSBASE0) >> 1;
mVariableMtrrsPhysBase[Index].Uint64 = Value;
return Value;
} else {
Index = (MsrIndex - MSR_IA32_MTRR_PHYSMASK0) >> 1;
Index = (MsrIndex - MSR_IA32_MTRR_PHYSMASK0) >> 1;
mVariableMtrrsPhysMask[Index].Uint64 = Value;
return Value;
}
@@ -260,7 +267,7 @@ UnitTestMtrrLibAsmWriteMsr64(
//
// Should never fall through to here
//
ASSERT(FALSE);
ASSERT (FALSE);
return 0;
}
@@ -275,7 +282,7 @@ InitializeMtrrRegs (
IN MTRR_LIB_SYSTEM_PARAMETER *SystemParameter
)
{
UINT32 Index;
UINT32 Index;
SetMem (mFixedMtrrsValue, sizeof (mFixedMtrrsValue), SystemParameter->DefaultCacheType);
@@ -325,10 +332,10 @@ InitializeMtrrRegs (
UNIT_TEST_STATUS
EFIAPI
InitializeSystem (
IN UNIT_TEST_CONTEXT Context
IN UNIT_TEST_CONTEXT Context
)
{
return InitializeMtrrRegs ((MTRR_LIB_SYSTEM_PARAMETER *) Context);
return InitializeMtrrRegs ((MTRR_LIB_SYSTEM_PARAMETER *)Context);
}
/**
@@ -344,34 +351,34 @@ InitializeSystem (
**/
VOID
CollectTestResult (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN UINT32 VariableMtrrCount,
IN MTRR_SETTINGS *Mtrrs,
OUT MTRR_MEMORY_RANGE *Ranges,
IN OUT UINTN *RangeCount,
OUT UINT32 *MtrrCount
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN UINT32 VariableMtrrCount,
IN MTRR_SETTINGS *Mtrrs,
OUT MTRR_MEMORY_RANGE *Ranges,
IN OUT UINTN *RangeCount,
OUT UINT32 *MtrrCount
)
{
UINTN Index;
UINT64 MtrrValidBitsMask;
UINT64 MtrrValidAddressMask;
MTRR_MEMORY_RANGE RawMemoryRanges[ARRAY_SIZE (Mtrrs->Variables.Mtrr)];
UINTN Index;
UINT64 MtrrValidBitsMask;
UINT64 MtrrValidAddressMask;
MTRR_MEMORY_RANGE RawMemoryRanges[ARRAY_SIZE (Mtrrs->Variables.Mtrr)];
ASSERT (Mtrrs != NULL);
ASSERT (VariableMtrrCount <= ARRAY_SIZE (Mtrrs->Variables.Mtrr));
MtrrValidBitsMask = (1ull << PhysicalAddressBits) - 1;
MtrrValidBitsMask = (1ull << PhysicalAddressBits) - 1;
MtrrValidAddressMask = MtrrValidBitsMask & ~0xFFFull;
*MtrrCount = 0;
for (Index = 0; Index < VariableMtrrCount; Index++) {
if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *) &Mtrrs->Variables.Mtrr[Index].Mask)->Bits.V == 1) {
if (((MSR_IA32_MTRR_PHYSMASK_REGISTER *)&Mtrrs->Variables.Mtrr[Index].Mask)->Bits.V == 1) {
RawMemoryRanges[*MtrrCount].BaseAddress = Mtrrs->Variables.Mtrr[Index].Base & MtrrValidAddressMask;
RawMemoryRanges[*MtrrCount].Type =
((MSR_IA32_MTRR_PHYSBASE_REGISTER *) &Mtrrs->Variables.Mtrr[Index].Base)->Bits.Type;
RawMemoryRanges[*MtrrCount].Length =
((~(Mtrrs->Variables.Mtrr[Index].Mask & MtrrValidAddressMask)) & MtrrValidBitsMask) + 1;
((MSR_IA32_MTRR_PHYSBASE_REGISTER *)&Mtrrs->Variables.Mtrr[Index].Base)->Bits.Type;
RawMemoryRanges[*MtrrCount].Length =
((~(Mtrrs->Variables.Mtrr[Index].Mask & MtrrValidAddressMask)) & MtrrValidBitsMask) + 1;
(*MtrrCount)++;
}
}
@@ -392,7 +399,7 @@ Random32 (
UINT32 Limit
)
{
return (UINT32) (((double) Rand () / RAND_MAX) * (Limit - Start)) + Start;
return (UINT32)(((double)Rand () / RAND_MAX) * (Limit - Start)) + Start;
}
/**
@@ -408,7 +415,7 @@ Random64 (
UINT64 Limit
)
{
return (UINT64) (((double) Rand () / RAND_MAX) * (Limit - Start)) + Start;
return (UINT64)(((double)Rand () / RAND_MAX) * (Limit - Start)) + Start;
}
/**
@@ -421,30 +428,30 @@ Random64 (
**/
VOID
GenerateRandomMtrrPair (
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_CACHE_TYPE CacheType,
OUT MTRR_VARIABLE_SETTING *MtrrPair OPTIONAL,
OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_CACHE_TYPE CacheType,
OUT MTRR_VARIABLE_SETTING *MtrrPair OPTIONAL,
OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL
)
{
MSR_IA32_MTRR_PHYSBASE_REGISTER PhysBase;
MSR_IA32_MTRR_PHYSMASK_REGISTER PhysMask;
UINT32 SizeShift;
UINT32 BaseShift;
UINT64 RandomBoundary;
UINT64 MaxPhysicalAddress;
UINT64 RangeSize;
UINT64 RangeBase;
UINT64 PhysBasePhyMaskValidBitsMask;
MSR_IA32_MTRR_PHYSBASE_REGISTER PhysBase;
MSR_IA32_MTRR_PHYSMASK_REGISTER PhysMask;
UINT32 SizeShift;
UINT32 BaseShift;
UINT64 RandomBoundary;
UINT64 MaxPhysicalAddress;
UINT64 RangeSize;
UINT64 RangeBase;
UINT64 PhysBasePhyMaskValidBitsMask;
MaxPhysicalAddress = 1ull << PhysicalAddressBits;
do {
SizeShift = Random32 (12, PhysicalAddressBits - 1);
RangeSize = 1ull << SizeShift;
BaseShift = Random32 (SizeShift, PhysicalAddressBits - 1);
BaseShift = Random32 (SizeShift, PhysicalAddressBits - 1);
RandomBoundary = Random64 (0, 1ull << (PhysicalAddressBits - BaseShift));
RangeBase = RandomBoundary << BaseShift;
RangeBase = RandomBoundary << BaseShift;
} while (RangeBase < SIZE_1MB || RangeBase > MaxPhysicalAddress - 1);
PhysBasePhyMaskValidBitsMask = (MaxPhysicalAddress - 1) & 0xfffffffffffff000ULL;
@@ -468,7 +475,6 @@ GenerateRandomMtrrPair (
}
}
/**
Check whether the Range overlaps with any one in Ranges.
@@ -480,9 +486,9 @@ GenerateRandomMtrrPair (
**/
BOOLEAN
RangesOverlap (
IN MTRR_MEMORY_RANGE *Range,
IN MTRR_MEMORY_RANGE *Ranges,
IN UINTN Count
IN MTRR_MEMORY_RANGE *Range,
IN MTRR_MEMORY_RANGE *Ranges,
IN UINTN Count
)
{
while (Count-- != 0) {
@@ -491,11 +497,13 @@ RangesOverlap (
// 1. range#2.base is in the middle of range#1
// 2. range#1.base is in the middle of range#2
//
if ((Range->BaseAddress <= Ranges[Count].BaseAddress && Ranges[Count].BaseAddress < Range->BaseAddress + Range->Length)
|| (Ranges[Count].BaseAddress <= Range->BaseAddress && Range->BaseAddress < Ranges[Count].BaseAddress + Ranges[Count].Length)) {
if ( ((Range->BaseAddress <= Ranges[Count].BaseAddress) && (Ranges[Count].BaseAddress < Range->BaseAddress + Range->Length))
|| ((Ranges[Count].BaseAddress <= Range->BaseAddress) && (Range->BaseAddress < Ranges[Count].BaseAddress + Ranges[Count].Length)))
{
return TRUE;
}
}
return FALSE;
}
@@ -512,16 +520,16 @@ RangesOverlap (
**/
VOID
GenerateValidAndConfigurableMtrrPairs (
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 UcCount,
IN UINT32 WtCount,
IN UINT32 WbCount,
IN UINT32 WpCount,
IN UINT32 WcCount
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 UcCount,
IN UINT32 WtCount,
IN UINT32 WbCount,
IN UINT32 WpCount,
IN UINT32 WcCount
)
{
UINT32 Index;
UINT32 Index;
//
// 1. Generate UC, WT, WB in order.
@@ -567,7 +575,7 @@ GenerateRandomCacheType (
VOID
)
{
return mMemoryCacheTypes[Random32 (0, ARRAY_SIZE (mMemoryCacheTypes) - 1)];
return mMemoryCacheTypes[Random32 (0, ARRAY_SIZE (mMemoryCacheTypes) - 1)];
}
/**
@@ -586,19 +594,20 @@ GenerateRandomCacheType (
**/
INT32
CompareFuncUint64 (
CONST VOID * Left,
CONST VOID * Right
CONST VOID *Left,
CONST VOID *Right
)
{
INT64 Delta;
Delta = (*(UINT64*)Left - *(UINT64*)Right);
if (Delta > 0) {
return 1;
} else if (Delta == 0) {
return 0;
} else {
return -1;
}
INT64 Delta;
Delta = (*(UINT64 *)Left - *(UINT64 *)Right);
if (Delta > 0) {
return 1;
} else if (Delta == 0) {
return 0;
} else {
return -1;
}
}
/**
@@ -611,13 +620,14 @@ CompareFuncUint64 (
**/
VOID
DetermineMemoryCacheType (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN OUT MTRR_MEMORY_RANGE *Range,
IN MTRR_MEMORY_RANGE *Ranges,
IN UINT32 RangeCount
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN OUT MTRR_MEMORY_RANGE *Range,
IN MTRR_MEMORY_RANGE *Ranges,
IN UINT32 RangeCount
)
{
UINT32 Index;
UINT32 Index;
Range->Type = CacheInvalid;
for (Index = 0; Index < RangeCount; Index++) {
if (RangesOverlap (Range, &Ranges[Index], 1)) {
@@ -643,16 +653,18 @@ DetermineMemoryCacheType (
**/
UINT32
GetNextDifferentElementInSortedArray (
IN UINT32 Index,
IN UINT64 *Array,
IN UINT32 Count
IN UINT32 Index,
IN UINT64 *Array,
IN UINT32 Count
)
{
UINT64 CurrentElement;
UINT64 CurrentElement;
CurrentElement = Array[Index];
while (CurrentElement == Array[Index] && Index < Count) {
Index++;
}
return Index;
}
@@ -664,12 +676,12 @@ GetNextDifferentElementInSortedArray (
**/
VOID
RemoveDuplicatesInSortedArray (
IN OUT UINT64 *Array,
IN OUT UINT32 *Count
IN OUT UINT64 *Array,
IN OUT UINT32 *Count
)
{
UINT32 Index;
UINT32 NewCount;
UINT32 Index;
UINT32 NewCount;
Index = 0;
NewCount = 0;
@@ -678,6 +690,7 @@ RemoveDuplicatesInSortedArray (
NewCount++;
Index = GetNextDifferentElementInSortedArray (Index, Array, *Count);
}
*Count = NewCount;
}
@@ -690,11 +703,11 @@ RemoveDuplicatesInSortedArray (
**/
BOOLEAN
AddressInRange (
IN UINT64 Address,
IN MTRR_MEMORY_RANGE Range
IN UINT64 Address,
IN MTRR_MEMORY_RANGE Range
)
{
return (Address >= Range.BaseAddress) && (Address <= Range.BaseAddress + Range.Length - 1);
return (Address >= Range.BaseAddress) && (Address <= Range.BaseAddress + Range.Length - 1);
}
/**
@@ -706,13 +719,14 @@ AddressInRange (
**/
UINT64
GetOverlapBitFlag (
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
IN UINT64 Address
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
IN UINT64 Address
)
{
UINT64 OverlapBitFlag;
UINT32 Index;
UINT64 OverlapBitFlag;
UINT32 Index;
OverlapBitFlag = 0;
for (Index = 0; Index < RawMemoryRangeCount; Index++) {
if (AddressInRange (Address, RawMemoryRanges[Index])) {
@@ -736,14 +750,23 @@ GetOverlapBitFlag (
**/
UINT32
CheckOverlapBitFlagsRelation (
IN UINT64 Flag1,
IN UINT64 Flag2
IN UINT64 Flag1,
IN UINT64 Flag2
)
{
if (Flag1 == Flag2) return 0;
if ((Flag1 | Flag2) == Flag2) return 1;
if ((Flag1 | Flag2) == Flag1) return 2;
return 3;
if (Flag1 == Flag2) {
return 0;
}
if ((Flag1 | Flag2) == Flag2) {
return 1;
}
if ((Flag1 | Flag2) == Flag1) {
return 2;
}
return 3;
}
/**
@@ -758,20 +781,21 @@ CheckOverlapBitFlagsRelation (
**/
BOOLEAN
IsEndpointInRanges (
IN UINT64 Endpoint,
IN MTRR_MEMORY_RANGE *Ranges,
IN UINTN RangeCount
IN UINT64 Endpoint,
IN MTRR_MEMORY_RANGE *Ranges,
IN UINTN RangeCount
)
{
UINT32 Index;
for (Index = 0; Index < RangeCount; Index++) {
if (AddressInRange (Endpoint, Ranges[Index])) {
return TRUE;
}
}
return FALSE;
}
UINT32 Index;
for (Index = 0; Index < RangeCount; Index++) {
if (AddressInRange (Endpoint, Ranges[Index])) {
return TRUE;
}
}
return FALSE;
}
/**
Compact adjacent ranges of the same type.
@@ -783,26 +807,26 @@ IsEndpointInRanges (
**/
VOID
CompactAndExtendEffectiveMtrrMemoryRanges (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE **EffectiveMtrrMemoryRanges,
IN OUT UINTN *EffectiveMtrrMemoryRangesCount
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE **EffectiveMtrrMemoryRanges,
IN OUT UINTN *EffectiveMtrrMemoryRangesCount
)
{
UINT64 MaxAddress;
UINTN NewRangesCountAtMost;
MTRR_MEMORY_RANGE *NewRanges;
UINTN NewRangesCountActual;
MTRR_MEMORY_RANGE *CurrentRangeInNewRanges;
MTRR_MEMORY_CACHE_TYPE CurrentRangeTypeInOldRanges;
UINT64 MaxAddress;
UINTN NewRangesCountAtMost;
MTRR_MEMORY_RANGE *NewRanges;
UINTN NewRangesCountActual;
MTRR_MEMORY_RANGE *CurrentRangeInNewRanges;
MTRR_MEMORY_CACHE_TYPE CurrentRangeTypeInOldRanges;
MTRR_MEMORY_RANGE *OldRanges;
MTRR_MEMORY_RANGE OldLastRange;
UINTN OldRangesIndex;
MTRR_MEMORY_RANGE *OldRanges;
MTRR_MEMORY_RANGE OldLastRange;
UINTN OldRangesIndex;
NewRangesCountActual = 0;
NewRangesCountAtMost = *EffectiveMtrrMemoryRangesCount + 2; // At most with 2 more range entries.
NewRanges = (MTRR_MEMORY_RANGE *) calloc (NewRangesCountAtMost, sizeof (MTRR_MEMORY_RANGE));
NewRanges = (MTRR_MEMORY_RANGE *)calloc (NewRangesCountAtMost, sizeof (MTRR_MEMORY_RANGE));
OldRanges = *EffectiveMtrrMemoryRanges;
if (OldRanges[0].BaseAddress > 0) {
NewRanges[NewRangesCountActual].BaseAddress = 0;
@@ -814,44 +838,45 @@ CompactAndExtendEffectiveMtrrMemoryRanges (
OldRangesIndex = 0;
while (OldRangesIndex < *EffectiveMtrrMemoryRangesCount) {
CurrentRangeTypeInOldRanges = OldRanges[OldRangesIndex].Type;
CurrentRangeInNewRanges = NULL;
if (NewRangesCountActual > 0) // We need to check CurrentNewRange first before generate a new NewRange.
{
CurrentRangeInNewRanges = NULL;
if (NewRangesCountActual > 0) {
// We need to check CurrentNewRange first before generate a new NewRange.
CurrentRangeInNewRanges = &NewRanges[NewRangesCountActual - 1];
}
if (CurrentRangeInNewRanges != NULL && CurrentRangeInNewRanges->Type == CurrentRangeTypeInOldRanges) {
if ((CurrentRangeInNewRanges != NULL) && (CurrentRangeInNewRanges->Type == CurrentRangeTypeInOldRanges)) {
CurrentRangeInNewRanges->Length += OldRanges[OldRangesIndex].Length;
} else {
NewRanges[NewRangesCountActual].BaseAddress = OldRanges[OldRangesIndex].BaseAddress;
NewRanges[NewRangesCountActual].Length += OldRanges[OldRangesIndex].Length;
NewRanges[NewRangesCountActual].Type = CurrentRangeTypeInOldRanges;
while (OldRangesIndex + 1 < *EffectiveMtrrMemoryRangesCount && OldRanges[OldRangesIndex + 1].Type == CurrentRangeTypeInOldRanges)
{
while (OldRangesIndex + 1 < *EffectiveMtrrMemoryRangesCount && OldRanges[OldRangesIndex + 1].Type == CurrentRangeTypeInOldRanges) {
OldRangesIndex++;
NewRanges[NewRangesCountActual].Length += OldRanges[OldRangesIndex].Length;
}
NewRangesCountActual++;
}
OldRangesIndex++;
}
MaxAddress = (1ull << PhysicalAddressBits) - 1;
OldLastRange = OldRanges[(*EffectiveMtrrMemoryRangesCount) - 1];
MaxAddress = (1ull << PhysicalAddressBits) - 1;
OldLastRange = OldRanges[(*EffectiveMtrrMemoryRangesCount) - 1];
CurrentRangeInNewRanges = &NewRanges[NewRangesCountActual - 1];
if (OldLastRange.BaseAddress + OldLastRange.Length - 1 < MaxAddress) {
if (CurrentRangeInNewRanges->Type == DefaultType) {
CurrentRangeInNewRanges->Length = MaxAddress - CurrentRangeInNewRanges->BaseAddress + 1;
} else {
NewRanges[NewRangesCountActual].BaseAddress = OldLastRange.BaseAddress + OldLastRange.Length;
NewRanges[NewRangesCountActual].Length = MaxAddress - NewRanges[NewRangesCountActual].BaseAddress + 1;
NewRanges[NewRangesCountActual].Type = DefaultType;
NewRanges[NewRangesCountActual].Length = MaxAddress - NewRanges[NewRangesCountActual].BaseAddress + 1;
NewRanges[NewRangesCountActual].Type = DefaultType;
NewRangesCountActual++;
}
}
free (*EffectiveMtrrMemoryRanges);
*EffectiveMtrrMemoryRanges = NewRanges;
*EffectiveMtrrMemoryRanges = NewRanges;
*EffectiveMtrrMemoryRangesCount = NewRangesCountActual;
}
@@ -865,20 +890,20 @@ CompactAndExtendEffectiveMtrrMemoryRanges (
**/
VOID
CollectEndpoints (
IN OUT UINT64 *Endpoints,
IN OUT UINT32 *EndPointCount,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount
IN OUT UINT64 *Endpoints,
IN OUT UINT32 *EndPointCount,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount
)
{
UINT32 Index;
UINT32 RawRangeIndex;
UINT32 Index;
UINT32 RawRangeIndex;
ASSERT ((RawMemoryRangeCount << 1) == *EndPointCount);
for (Index = 0; Index < *EndPointCount; Index += 2) {
RawRangeIndex = Index >> 1;
Endpoints[Index] = RawMemoryRanges[RawRangeIndex].BaseAddress;
RawRangeIndex = Index >> 1;
Endpoints[Index] = RawMemoryRanges[RawRangeIndex].BaseAddress;
Endpoints[Index + 1] = RawMemoryRanges[RawRangeIndex].BaseAddress + RawMemoryRanges[RawRangeIndex].Length - 1;
}
@@ -898,41 +923,41 @@ CollectEndpoints (
**/
VOID
GetEffectiveMemoryRanges (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
OUT MTRR_MEMORY_RANGE *MemoryRanges,
OUT UINTN *MemoryRangeCount
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
OUT MTRR_MEMORY_RANGE *MemoryRanges,
OUT UINTN *MemoryRangeCount
)
{
UINTN Index;
UINT32 AllEndPointsCount;
UINT64 *AllEndPointsInclusive;
UINT32 AllRangePiecesCountMax;
MTRR_MEMORY_RANGE *AllRangePieces;
UINTN AllRangePiecesCountActual;
UINT64 OverlapBitFlag1;
UINT64 OverlapBitFlag2;
INT32 OverlapFlagRelation;
UINTN Index;
UINT32 AllEndPointsCount;
UINT64 *AllEndPointsInclusive;
UINT32 AllRangePiecesCountMax;
MTRR_MEMORY_RANGE *AllRangePieces;
UINTN AllRangePiecesCountActual;
UINT64 OverlapBitFlag1;
UINT64 OverlapBitFlag2;
INT32 OverlapFlagRelation;
if (RawMemoryRangeCount == 0) {
MemoryRanges[0].BaseAddress = 0;
MemoryRanges[0].Length = (1ull << PhysicalAddressBits);
MemoryRanges[0].Type = DefaultType;
*MemoryRangeCount = 1;
*MemoryRangeCount = 1;
return;
}
AllEndPointsCount = RawMemoryRangeCount << 1;
AllEndPointsInclusive = calloc (AllEndPointsCount, sizeof (UINT64));
AllRangePiecesCountMax = RawMemoryRangeCount * 3 + 1;
AllRangePieces = calloc (AllRangePiecesCountMax, sizeof (MTRR_MEMORY_RANGE));
AllEndPointsCount = RawMemoryRangeCount << 1;
AllEndPointsInclusive = calloc (AllEndPointsCount, sizeof (UINT64));
AllRangePiecesCountMax = RawMemoryRangeCount * 3 + 1;
AllRangePieces = calloc (AllRangePiecesCountMax, sizeof (MTRR_MEMORY_RANGE));
CollectEndpoints (AllEndPointsInclusive, &AllEndPointsCount, RawMemoryRanges, RawMemoryRangeCount);
for (Index = 0, AllRangePiecesCountActual = 0; Index < AllEndPointsCount - 1; Index++) {
OverlapBitFlag1 = GetOverlapBitFlag (RawMemoryRanges, RawMemoryRangeCount, AllEndPointsInclusive[Index]);
OverlapBitFlag2 = GetOverlapBitFlag (RawMemoryRanges, RawMemoryRangeCount, AllEndPointsInclusive[Index + 1]);
OverlapBitFlag1 = GetOverlapBitFlag (RawMemoryRanges, RawMemoryRangeCount, AllEndPointsInclusive[Index]);
OverlapBitFlag2 = GetOverlapBitFlag (RawMemoryRanges, RawMemoryRangeCount, AllEndPointsInclusive[Index + 1]);
OverlapFlagRelation = CheckOverlapBitFlagsRelation (OverlapBitFlag1, OverlapBitFlag2);
switch (OverlapFlagRelation) {
case 0: // [1, 2]
@@ -955,18 +980,23 @@ GetEffectiveMemoryRanges (
AllRangePieces[AllRangePiecesCountActual].Length = 1;
AllRangePiecesCountActual++;
}
break;
case 3: // (1, 2)
AllRangePieces[AllRangePiecesCountActual].BaseAddress = AllEndPointsInclusive[Index] + 1;
AllRangePieces[AllRangePiecesCountActual].Length = (AllEndPointsInclusive[Index + 1] - 1) - (AllEndPointsInclusive[Index] + 1) + 1;
if (AllRangePieces[AllRangePiecesCountActual].Length == 0) // Only in case 3 can exists Length=0, we should skip such "segment".
if (AllRangePieces[AllRangePiecesCountActual].Length == 0) {
// Only in case 3 can exists Length=0, we should skip such "segment".
break;
}
AllRangePiecesCountActual++;
if (!IsEndpointInRanges (AllEndPointsInclusive[Index], AllRangePieces, AllRangePiecesCountActual)) {
AllRangePieces[AllRangePiecesCountActual].BaseAddress = AllEndPointsInclusive[Index];
AllRangePieces[AllRangePiecesCountActual].Length = 1;
AllRangePiecesCountActual++;
}
break;
default:
ASSERT (FALSE);

View File

@@ -30,7 +30,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_PEI_PPI_DESCRIPTOR *
EFIAPI
SecPlatformMain (
IN OUT EFI_SEC_PEI_HAND_OFF *SecCoreData
IN OUT EFI_SEC_PEI_HAND_OFF *SecCoreData
)
{
return NULL;
@@ -50,9 +50,9 @@ SecPlatformMain (
EFI_STATUS
EFIAPI
SecPlatformInformation (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN OUT UINT64 *StructureSize,
OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
IN CONST EFI_PEI_SERVICES **PeiServices,
IN OUT UINT64 *StructureSize,
OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord
)
{
return EFI_SUCCESS;

View File

@@ -13,7 +13,7 @@
#include "RegisterCpuFeatures.h"
CPU_FEATURES_DATA mCpuFeaturesData = {0};
CPU_FEATURES_DATA mCpuFeaturesData = { 0 };
/**
Worker function to get CPU_FEATURES_DATA pointer.
@@ -38,17 +38,17 @@ GetMpService (
VOID
)
{
EFI_STATUS Status;
MP_SERVICES MpService;
EFI_STATUS Status;
MP_SERVICES MpService;
//
// Get MP Services Protocol
//
Status = gBS->LocateProtocol (
&gEfiMpServiceProtocolGuid,
NULL,
(VOID **)&MpService.Protocol
);
&gEfiMpServiceProtocolGuid,
NULL,
(VOID **)&MpService.Protocol
);
ASSERT_EFI_ERROR (Status);
return MpService;
@@ -63,15 +63,15 @@ GetMpService (
**/
UINTN
GetProcessorIndex (
IN CPU_FEATURES_DATA *CpuFeaturesData
IN CPU_FEATURES_DATA *CpuFeaturesData
)
{
EFI_STATUS Status;
UINTN ProcessorIndex;
EFI_MP_SERVICES_PROTOCOL *MpServices;
EFI_STATUS Status;
UINTN ProcessorIndex;
EFI_MP_SERVICES_PROTOCOL *MpServices;
MpServices = CpuFeaturesData->MpService.Protocol;
Status = MpServices->WhoAmI(MpServices, &ProcessorIndex);
Status = MpServices->WhoAmI (MpServices, &ProcessorIndex);
ASSERT_EFI_ERROR (Status);
return ProcessorIndex;
}
@@ -88,22 +88,22 @@ GetProcessorIndex (
**/
EFI_STATUS
GetProcessorInformation (
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
)
{
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
MpServices = CpuFeaturesData->MpService.Protocol;
MpServices = CpuFeaturesData->MpService.Protocol;
Status = MpServices->GetProcessorInfo (
MpServices,
ProcessorNumber,
ProcessorInfoBuffer
);
MpServices,
ProcessorNumber,
ProcessorInfoBuffer
);
return Status;
}
@@ -117,29 +117,29 @@ GetProcessorInformation (
**/
VOID
StartupAllAPsWorker (
IN EFI_AP_PROCEDURE Procedure,
IN EFI_EVENT MpEvent
IN EFI_AP_PROCEDURE Procedure,
IN EFI_EVENT MpEvent
)
{
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
MpServices = CpuFeaturesData->MpService.Protocol;
MpServices = CpuFeaturesData->MpService.Protocol;
//
// Wakeup all APs
//
Status = MpServices->StartupAllAPs (
MpServices,
Procedure,
FALSE,
MpEvent,
0,
CpuFeaturesData,
NULL
);
MpServices,
Procedure,
FALSE,
MpEvent,
0,
CpuFeaturesData,
NULL
);
ASSERT_EFI_ERROR (Status);
}
@@ -150,24 +150,24 @@ StartupAllAPsWorker (
**/
VOID
SwitchNewBsp (
IN UINTN ProcessorNumber
IN UINTN ProcessorNumber
)
{
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
MpServices = CpuFeaturesData->MpService.Protocol;
MpServices = CpuFeaturesData->MpService.Protocol;
//
// Wakeup all APs
//
Status = MpServices->SwitchBSP (
MpServices,
ProcessorNumber,
TRUE
);
MpServices,
ProcessorNumber,
TRUE
);
ASSERT_EFI_ERROR (Status);
}
@@ -183,16 +183,16 @@ SwitchNewBsp (
**/
VOID
GetNumberOfProcessor (
OUT UINTN *NumberOfCpus,
OUT UINTN *NumberOfEnabledProcessors
OUT UINTN *NumberOfCpus,
OUT UINTN *NumberOfEnabledProcessors
)
{
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpServices;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
MpServices = CpuFeaturesData->MpService.Protocol;
MpServices = CpuFeaturesData->MpService.Protocol;
//
// Get the number of CPUs
@@ -219,14 +219,14 @@ CpuFeaturesInitialize (
VOID
)
{
CPU_FEATURES_DATA *CpuFeaturesData;
UINTN OldBspNumber;
EFI_EVENT MpEvent;
EFI_STATUS Status;
CPU_FEATURES_DATA *CpuFeaturesData;
UINTN OldBspNumber;
EFI_EVENT MpEvent;
EFI_STATUS Status;
CpuFeaturesData = GetCpuFeaturesData ();
OldBspNumber = GetProcessorIndex (CpuFeaturesData);
OldBspNumber = GetProcessorIndex (CpuFeaturesData);
CpuFeaturesData->BspNumber = OldBspNumber;
//
@@ -263,6 +263,7 @@ CpuFeaturesInitialize (
do {
Status = gBS->CheckEvent (MpEvent);
} while (Status == EFI_NOT_READY);
ASSERT_EFI_ERROR (Status);
}
@@ -273,4 +274,3 @@ CpuFeaturesInitialize (
SwitchNewBsp (CpuFeaturesData->BspNumber);
}
}

View File

@@ -20,7 +20,7 @@
0xa694c467, 0x697a, 0x446b, { 0xb9, 0x29, 0x5b, 0x14, 0xa0, 0xcf, 0x39, 0xf } \
}
EFI_GUID mRegisterCpuFeaturesHobGuid = REGISTER_CPU_FEATURES_GUID;
EFI_GUID mRegisterCpuFeaturesHobGuid = REGISTER_CPU_FEATURES_GUID;
/**
Worker function to get CPU_FEATURES_DATA pointer.
@@ -32,16 +32,16 @@ GetCpuFeaturesData (
VOID
)
{
CPU_FEATURES_DATA *CpuInitData;
EFI_HOB_GUID_TYPE *GuidHob;
VOID *DataInHob;
UINT64 Data64;
CPU_FEATURES_DATA *CpuInitData;
EFI_HOB_GUID_TYPE *GuidHob;
VOID *DataInHob;
UINT64 Data64;
CpuInitData = NULL;
GuidHob = GetFirstGuidHob (&mRegisterCpuFeaturesHobGuid);
GuidHob = GetFirstGuidHob (&mRegisterCpuFeaturesHobGuid);
if (GuidHob != NULL) {
DataInHob = GET_GUID_HOB_DATA (GuidHob);
CpuInitData = (CPU_FEATURES_DATA *) (*(UINTN *) DataInHob);
DataInHob = GET_GUID_HOB_DATA (GuidHob);
CpuInitData = (CPU_FEATURES_DATA *)(*(UINTN *)DataInHob);
ASSERT (CpuInitData != NULL);
} else {
CpuInitData = AllocateZeroPool (sizeof (CPU_FEATURES_DATA));
@@ -49,10 +49,10 @@ GetCpuFeaturesData (
//
// Build location of CPU MP DATA buffer in HOB
//
Data64 = (UINT64) (UINTN) CpuInitData;
Data64 = (UINT64)(UINTN)CpuInitData;
BuildGuidDataHob (
&mRegisterCpuFeaturesHobGuid,
(VOID *) &Data64,
(VOID *)&Data64,
sizeof (UINT64)
);
}
@@ -70,8 +70,8 @@ GetMpService (
VOID
)
{
EFI_STATUS Status;
MP_SERVICES MpService;
EFI_STATUS Status;
MP_SERVICES MpService;
//
// Get MP Services2 Ppi
@@ -95,12 +95,12 @@ GetMpService (
**/
UINTN
GetProcessorIndex (
IN CPU_FEATURES_DATA *CpuFeaturesData
IN CPU_FEATURES_DATA *CpuFeaturesData
)
{
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
UINTN ProcessorIndex;
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
UINTN ProcessorIndex;
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
@@ -126,22 +126,22 @@ GetProcessorIndex (
**/
EFI_STATUS
GetProcessorInformation (
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
)
{
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
EFI_STATUS Status;
CPU_FEATURES_DATA *CpuFeaturesData;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
EFI_STATUS Status;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
Status = CpuMp2Ppi->GetProcessorInfo (
CpuMp2Ppi,
ProcessorNumber,
ProcessorInfoBuffer
);
CpuMp2Ppi,
ProcessorNumber,
ProcessorInfoBuffer
);
return Status;
}
@@ -155,27 +155,27 @@ GetProcessorInformation (
**/
VOID
StartupAllAPsWorker (
IN EFI_AP_PROCEDURE Procedure,
IN EFI_EVENT MpEvent
IN EFI_AP_PROCEDURE Procedure,
IN EFI_EVENT MpEvent
)
{
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
//
// Wakeup all APs for data collection.
//
Status = CpuMp2Ppi->StartupAllAPs (
CpuMp2Ppi,
Procedure,
FALSE,
0,
CpuFeaturesData
);
CpuMp2Ppi,
Procedure,
FALSE,
0,
CpuFeaturesData
);
ASSERT_EFI_ERROR (Status);
}
@@ -188,12 +188,12 @@ StartupAllAPsWorker (
**/
VOID
StartupAllCPUsWorker (
IN EFI_AP_PROCEDURE Procedure
IN EFI_AP_PROCEDURE Procedure
)
{
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
@@ -201,12 +201,12 @@ StartupAllCPUsWorker (
// Get MP Services2 Ppi
//
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
Status = CpuMp2Ppi->StartupAllCPUs (
CpuMp2Ppi,
Procedure,
0,
CpuFeaturesData
);
Status = CpuMp2Ppi->StartupAllCPUs (
CpuMp2Ppi,
Procedure,
0,
CpuFeaturesData
);
ASSERT_EFI_ERROR (Status);
}
@@ -217,24 +217,24 @@ StartupAllCPUsWorker (
**/
VOID
SwitchNewBsp (
IN UINTN ProcessorNumber
IN UINTN ProcessorNumber
)
{
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
//
// Wakeup all APs for data collection.
//
Status = CpuMp2Ppi->SwitchBSP (
CpuMp2Ppi,
ProcessorNumber,
TRUE
);
CpuMp2Ppi,
ProcessorNumber,
TRUE
);
ASSERT_EFI_ERROR (Status);
}
@@ -250,25 +250,25 @@ SwitchNewBsp (
**/
VOID
GetNumberOfProcessor (
OUT UINTN *NumberOfCpus,
OUT UINTN *NumberOfEnabledProcessors
OUT UINTN *NumberOfCpus,
OUT UINTN *NumberOfEnabledProcessors
)
{
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
CpuMp2Ppi = CpuFeaturesData->MpService.Ppi;
//
// Get the number of CPUs
//
Status = CpuMp2Ppi->GetNumberOfProcessors (
CpuMp2Ppi,
NumberOfCpus,
NumberOfEnabledProcessors
);
CpuMp2Ppi,
NumberOfCpus,
NumberOfEnabledProcessors
);
ASSERT_EFI_ERROR (Status);
}
@@ -286,12 +286,12 @@ CpuFeaturesInitialize (
VOID
)
{
CPU_FEATURES_DATA *CpuFeaturesData;
UINTN OldBspNumber;
CPU_FEATURES_DATA *CpuFeaturesData;
UINTN OldBspNumber;
CpuFeaturesData = GetCpuFeaturesData ();
OldBspNumber = GetProcessorIndex (CpuFeaturesData);
OldBspNumber = GetProcessorIndex (CpuFeaturesData);
CpuFeaturesData->BspNumber = OldBspNumber;
//
@@ -306,4 +306,3 @@ CpuFeaturesInitialize (
SwitchNewBsp (CpuFeaturesData->BspNumber);
}
}

View File

@@ -27,66 +27,66 @@
#define CPU_FEATURE_ENTRY_SIGNATURE SIGNATURE_32 ('C', 'F', 'E', 'S')
#define CPU_FEATURE_NAME_SIZE 128
#define CPU_FEATURE_NAME_SIZE 128
typedef struct {
REGISTER_CPU_FEATURE_INFORMATION CpuInfo;
UINT8 *FeaturesSupportedMask;
LIST_ENTRY OrderList;
REGISTER_CPU_FEATURE_INFORMATION CpuInfo;
UINT8 *FeaturesSupportedMask;
LIST_ENTRY OrderList;
} CPU_FEATURES_INIT_ORDER;
typedef struct {
UINT32 Signature;
LIST_ENTRY Link;
UINT8 *FeatureMask;
CHAR8 *FeatureName;
CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc;
CPU_FEATURE_SUPPORT SupportFunc;
CPU_FEATURE_INITIALIZE InitializeFunc;
UINT8 *ThreadBeforeFeatureBitMask;
UINT8 *ThreadAfterFeatureBitMask;
UINT8 *CoreBeforeFeatureBitMask;
UINT8 *CoreAfterFeatureBitMask;
UINT8 *PackageBeforeFeatureBitMask;
UINT8 *PackageAfterFeatureBitMask;
VOID *ConfigData;
BOOLEAN BeforeAll;
BOOLEAN AfterAll;
UINT32 Signature;
LIST_ENTRY Link;
UINT8 *FeatureMask;
CHAR8 *FeatureName;
CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc;
CPU_FEATURE_SUPPORT SupportFunc;
CPU_FEATURE_INITIALIZE InitializeFunc;
UINT8 *ThreadBeforeFeatureBitMask;
UINT8 *ThreadAfterFeatureBitMask;
UINT8 *CoreBeforeFeatureBitMask;
UINT8 *CoreAfterFeatureBitMask;
UINT8 *PackageBeforeFeatureBitMask;
UINT8 *PackageAfterFeatureBitMask;
VOID *ConfigData;
BOOLEAN BeforeAll;
BOOLEAN AfterAll;
} CPU_FEATURES_ENTRY;
//
// Flags used when program the register.
//
typedef struct {
volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
volatile UINT32 *CoreSemaphoreCount; // Semaphore containers used to program Core semaphore.
volatile UINT32 *PackageSemaphoreCount; // Semaphore containers used to program Package semaphore.
volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
volatile UINT32 *CoreSemaphoreCount; // Semaphore containers used to program Core semaphore.
volatile UINT32 *PackageSemaphoreCount; // Semaphore containers used to program Package semaphore.
} PROGRAM_CPU_REGISTER_FLAGS;
typedef union {
EFI_MP_SERVICES_PROTOCOL *Protocol;
EDKII_PEI_MP_SERVICES2_PPI *Ppi;
EFI_MP_SERVICES_PROTOCOL *Protocol;
EDKII_PEI_MP_SERVICES2_PPI *Ppi;
} MP_SERVICES;
typedef struct {
UINTN FeaturesCount;
UINT32 BitMaskSize;
LIST_ENTRY FeatureList;
UINTN FeaturesCount;
UINT32 BitMaskSize;
LIST_ENTRY FeatureList;
CPU_FEATURES_INIT_ORDER *InitOrder;
UINT8 *CapabilityPcd;
UINT8 *SettingPcd;
CPU_FEATURES_INIT_ORDER *InitOrder;
UINT8 *CapabilityPcd;
UINT8 *SettingPcd;
UINT32 NumberOfCpus;
ACPI_CPU_DATA *AcpiCpuData;
UINT32 NumberOfCpus;
ACPI_CPU_DATA *AcpiCpuData;
CPU_REGISTER_TABLE *RegisterTable;
CPU_REGISTER_TABLE *PreSmmRegisterTable;
UINTN BspNumber;
CPU_REGISTER_TABLE *RegisterTable;
CPU_REGISTER_TABLE *PreSmmRegisterTable;
UINTN BspNumber;
PROGRAM_CPU_REGISTER_FLAGS CpuFlags;
PROGRAM_CPU_REGISTER_FLAGS CpuFlags;
MP_SERVICES MpService;
MP_SERVICES MpService;
} CPU_FEATURES_DATA;
#define CPU_FEATURE_ENTRY_FROM_LINK(a) \
@@ -116,7 +116,7 @@ GetCpuFeaturesData (
**/
UINTN
GetProcessorIndex (
IN CPU_FEATURES_DATA *CpuFeaturesData
IN CPU_FEATURES_DATA *CpuFeaturesData
);
/**
@@ -131,8 +131,8 @@ GetProcessorIndex (
**/
EFI_STATUS
GetProcessorInformation (
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
);
/**
@@ -145,8 +145,8 @@ GetProcessorInformation (
**/
VOID
StartupAllAPsWorker (
IN EFI_AP_PROCEDURE Procedure,
IN EFI_EVENT MpEvent
IN EFI_AP_PROCEDURE Procedure,
IN EFI_EVENT MpEvent
);
/**
@@ -161,8 +161,8 @@ StartupAllAPsWorker (
**/
VOID
GetNumberOfProcessor (
OUT UINTN *NumberOfCpus,
OUT UINTN *NumberOfEnabledProcessors
OUT UINTN *NumberOfCpus,
OUT UINTN *NumberOfEnabledProcessors
);
/**
@@ -172,7 +172,7 @@ GetNumberOfProcessor (
**/
VOID
SwitchNewBsp (
IN UINTN ProcessorNumber
IN UINTN ProcessorNumber
);
/**
@@ -184,8 +184,8 @@ SwitchNewBsp (
**/
VOID
DumpCpuFeatureMask (
IN UINT8 *FeatureMask,
IN UINT32 BitMaskSize
IN UINT8 *FeatureMask,
IN UINT32 BitMaskSize
);
/**
@@ -212,9 +212,9 @@ DumpCpuFeature (
**/
CPU_FEATURE_DEPENDENCE_TYPE
DetectFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN UINT8 *NextCpuFeatureMask
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN UINT8 *NextCpuFeatureMask
);
/**
@@ -228,9 +228,9 @@ DetectFeatureScope (
**/
CPU_FEATURE_DEPENDENCE_TYPE
DetectNoneNeighborhoodFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN LIST_ENTRY *FeatureList
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN LIST_ENTRY *FeatureList
);
/**
@@ -242,7 +242,7 @@ DetectNoneNeighborhoodFeatureScope (
VOID
EFIAPI
SetProcessorRegister (
IN OUT VOID *Buffer
IN OUT VOID *Buffer
);
/**

View File

@@ -17,17 +17,18 @@
**/
VOID
DumpCpuFeatureMask (
IN UINT8 *FeatureMask,
IN UINT32 BitMaskSize
IN UINT8 *FeatureMask,
IN UINT32 BitMaskSize
)
{
UINTN Index;
UINT8 *Data8;
UINTN Index;
UINT8 *Data8;
Data8 = (UINT8 *) FeatureMask;
Data8 = (UINT8 *)FeatureMask;
for (Index = 0; Index < BitMaskSize; Index++) {
DEBUG ((DEBUG_INFO, " %02x ", *Data8++));
}
DEBUG ((DEBUG_INFO, "\n"));
}
@@ -44,7 +45,6 @@ DumpCpuFeature (
IN UINT32 BitMaskSize
)
{
if (CpuFeature->FeatureName != NULL) {
DEBUG ((DEBUG_INFO, "FeatureName: %a\n", CpuFeature->FeatureName));
} else {
@@ -64,8 +64,8 @@ DumpCpuFeature (
**/
BOOLEAN
IsBitMaskMatchCheck (
IN UINT8 *FeatureMask,
IN UINT8 *DependentBitMask
IN UINT8 *FeatureMask,
IN UINT8 *DependentBitMask
)
{
UINTN Index;
@@ -82,6 +82,7 @@ IsBitMaskMatchCheck (
return TRUE;
}
}
return FALSE;
}
@@ -98,14 +99,14 @@ IsBitMaskMatchCheck (
**/
BOOLEAN
FindSpecifyFeature (
IN LIST_ENTRY *FeatureList,
IN LIST_ENTRY *CurrentEntry,
IN BOOLEAN SearchFormer,
IN UINT8 *FeatureMask
IN LIST_ENTRY *FeatureList,
IN LIST_ENTRY *CurrentEntry,
IN BOOLEAN SearchFormer,
IN UINT8 *FeatureMask
)
{
CPU_FEATURES_ENTRY *CpuFeature;
LIST_ENTRY *NextEntry;
CPU_FEATURES_ENTRY *CpuFeature;
LIST_ENTRY *NextEntry;
//
// Check whether exist the not neighborhood entry first.
@@ -165,9 +166,9 @@ FindSpecifyFeature (
**/
CPU_FEATURE_DEPENDENCE_TYPE
DetectFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN UINT8 *NextCpuFeatureMask
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN UINT8 *NextCpuFeatureMask
)
{
//
@@ -185,17 +186,20 @@ DetectFeatureScope (
if (Before) {
if ((CpuFeature->PackageBeforeFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->PackageBeforeFeatureBitMask)) {
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->PackageBeforeFeatureBitMask))
{
return PackageDepType;
}
if ((CpuFeature->CoreBeforeFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->CoreBeforeFeatureBitMask)) {
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->CoreBeforeFeatureBitMask))
{
return CoreDepType;
}
if ((CpuFeature->ThreadBeforeFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->ThreadBeforeFeatureBitMask)) {
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->ThreadBeforeFeatureBitMask))
{
return ThreadDepType;
}
@@ -203,17 +207,20 @@ DetectFeatureScope (
}
if ((CpuFeature->PackageAfterFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->PackageAfterFeatureBitMask)) {
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->PackageAfterFeatureBitMask))
{
return PackageDepType;
}
if ((CpuFeature->CoreAfterFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->CoreAfterFeatureBitMask)) {
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->CoreAfterFeatureBitMask))
{
return CoreDepType;
}
if ((CpuFeature->ThreadAfterFeatureBitMask != NULL) &&
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->ThreadAfterFeatureBitMask)) {
IsBitMaskMatchCheck (NextCpuFeatureMask, CpuFeature->ThreadAfterFeatureBitMask))
{
return ThreadDepType;
}
@@ -231,24 +238,27 @@ DetectFeatureScope (
**/
CPU_FEATURE_DEPENDENCE_TYPE
DetectNoneNeighborhoodFeatureScope (
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN LIST_ENTRY *FeatureList
IN CPU_FEATURES_ENTRY *CpuFeature,
IN BOOLEAN Before,
IN LIST_ENTRY *FeatureList
)
{
if (Before) {
if ((CpuFeature->PackageBeforeFeatureBitMask != NULL) &&
FindSpecifyFeature(FeatureList, &CpuFeature->Link, FALSE, CpuFeature->PackageBeforeFeatureBitMask)) {
FindSpecifyFeature (FeatureList, &CpuFeature->Link, FALSE, CpuFeature->PackageBeforeFeatureBitMask))
{
return PackageDepType;
}
if ((CpuFeature->CoreBeforeFeatureBitMask != NULL) &&
FindSpecifyFeature(FeatureList, &CpuFeature->Link, FALSE, CpuFeature->CoreBeforeFeatureBitMask)) {
FindSpecifyFeature (FeatureList, &CpuFeature->Link, FALSE, CpuFeature->CoreBeforeFeatureBitMask))
{
return CoreDepType;
}
if ((CpuFeature->ThreadBeforeFeatureBitMask != NULL) &&
FindSpecifyFeature(FeatureList, &CpuFeature->Link, FALSE, CpuFeature->ThreadBeforeFeatureBitMask)) {
FindSpecifyFeature (FeatureList, &CpuFeature->Link, FALSE, CpuFeature->ThreadBeforeFeatureBitMask))
{
return ThreadDepType;
}
@@ -256,17 +266,20 @@ DetectNoneNeighborhoodFeatureScope (
}
if ((CpuFeature->PackageAfterFeatureBitMask != NULL) &&
FindSpecifyFeature(FeatureList, &CpuFeature->Link, TRUE, CpuFeature->PackageAfterFeatureBitMask)) {
FindSpecifyFeature (FeatureList, &CpuFeature->Link, TRUE, CpuFeature->PackageAfterFeatureBitMask))
{
return PackageDepType;
}
if ((CpuFeature->CoreAfterFeatureBitMask != NULL) &&
FindSpecifyFeature(FeatureList, &CpuFeature->Link, TRUE, CpuFeature->CoreAfterFeatureBitMask)) {
FindSpecifyFeature (FeatureList, &CpuFeature->Link, TRUE, CpuFeature->CoreAfterFeatureBitMask))
{
return CoreDepType;
}
if ((CpuFeature->ThreadAfterFeatureBitMask != NULL) &&
FindSpecifyFeature(FeatureList, &CpuFeature->Link, TRUE, CpuFeature->ThreadAfterFeatureBitMask)) {
FindSpecifyFeature (FeatureList, &CpuFeature->Link, TRUE, CpuFeature->ThreadAfterFeatureBitMask))
{
return ThreadDepType;
}
@@ -294,17 +307,17 @@ DetectNoneNeighborhoodFeatureScope (
**/
BOOLEAN
AdjustFeaturesDependence (
IN OUT CPU_FEATURES_ENTRY *PreviousFeature,
IN OUT CPU_FEATURES_ENTRY *CurrentFeature,
IN CPU_FEATURES_ENTRY *FindFeature,
IN BOOLEAN Before
IN OUT CPU_FEATURES_ENTRY *PreviousFeature,
IN OUT CPU_FEATURES_ENTRY *CurrentFeature,
IN CPU_FEATURES_ENTRY *FindFeature,
IN BOOLEAN Before
)
{
CPU_FEATURE_DEPENDENCE_TYPE PreDependType;
CPU_FEATURE_DEPENDENCE_TYPE CurrentDependType;
CPU_FEATURE_DEPENDENCE_TYPE PreDependType;
CPU_FEATURE_DEPENDENCE_TYPE CurrentDependType;
PreDependType = DetectFeatureScope(PreviousFeature, Before, FindFeature->FeatureMask);
CurrentDependType = DetectFeatureScope(CurrentFeature, Before, FindFeature->FeatureMask);
PreDependType = DetectFeatureScope (PreviousFeature, Before, FindFeature->FeatureMask);
CurrentDependType = DetectFeatureScope (CurrentFeature, Before, FindFeature->FeatureMask);
//
// If previous feature has no dependence with the find featue.
@@ -336,16 +349,16 @@ AdjustFeaturesDependence (
**/
VOID
AdjustEntry (
IN LIST_ENTRY *FeatureList,
IN OUT LIST_ENTRY *FindEntry,
IN OUT LIST_ENTRY *CurrentEntry,
IN BOOLEAN Before
IN LIST_ENTRY *FeatureList,
IN OUT LIST_ENTRY *FindEntry,
IN OUT LIST_ENTRY *CurrentEntry,
IN BOOLEAN Before
)
{
LIST_ENTRY *PreviousEntry;
CPU_FEATURES_ENTRY *PreviousFeature;
CPU_FEATURES_ENTRY *CurrentFeature;
CPU_FEATURES_ENTRY *FindFeature;
LIST_ENTRY *PreviousEntry;
CPU_FEATURES_ENTRY *PreviousFeature;
CPU_FEATURES_ENTRY *CurrentFeature;
CPU_FEATURES_ENTRY *FindFeature;
//
// For CPU feature which has core or package type dependence, later code need to insert
@@ -363,11 +376,10 @@ AdjustEntry (
if (Before) {
PreviousEntry = GetPreviousNode (FeatureList, FindEntry);
} else {
PreviousEntry = GetNextNode (FeatureList, FindEntry);
}
CurrentFeature = CPU_FEATURE_ENTRY_FROM_LINK (CurrentEntry);
CurrentFeature = CPU_FEATURE_ENTRY_FROM_LINK (CurrentEntry);
RemoveEntryList (CurrentEntry);
if (IsNull (FeatureList, PreviousEntry)) {
@@ -407,7 +419,6 @@ AdjustEntry (
}
}
/**
Checks and adjusts current CPU features per dependency relationship.
@@ -419,14 +430,14 @@ AdjustEntry (
**/
BOOLEAN
InsertToBeforeEntry (
IN LIST_ENTRY *FeatureList,
IN LIST_ENTRY *CurrentEntry,
IN UINT8 *FeatureMask
IN LIST_ENTRY *FeatureList,
IN LIST_ENTRY *CurrentEntry,
IN UINT8 *FeatureMask
)
{
LIST_ENTRY *CheckEntry;
CPU_FEATURES_ENTRY *CheckFeature;
BOOLEAN Swapped;
LIST_ENTRY *CheckEntry;
CPU_FEATURES_ENTRY *CheckFeature;
BOOLEAN Swapped;
Swapped = FALSE;
@@ -441,6 +452,7 @@ InsertToBeforeEntry (
Swapped = TRUE;
break;
}
CheckEntry = CheckEntry->ForwardLink;
}
@@ -458,14 +470,14 @@ InsertToBeforeEntry (
**/
BOOLEAN
InsertToAfterEntry (
IN LIST_ENTRY *FeatureList,
IN LIST_ENTRY *CurrentEntry,
IN UINT8 *FeatureMask
IN LIST_ENTRY *FeatureList,
IN LIST_ENTRY *CurrentEntry,
IN UINT8 *FeatureMask
)
{
LIST_ENTRY *CheckEntry;
CPU_FEATURES_ENTRY *CheckFeature;
BOOLEAN Swapped;
LIST_ENTRY *CheckEntry;
CPU_FEATURES_ENTRY *CheckFeature;
BOOLEAN Swapped;
Swapped = FALSE;
@@ -480,6 +492,7 @@ InsertToAfterEntry (
Swapped = TRUE;
break;
}
CheckEntry = CheckEntry->ForwardLink;
}
@@ -493,22 +506,22 @@ InsertToAfterEntry (
**/
VOID
CheckCpuFeaturesDependency (
IN LIST_ENTRY *FeatureList
IN LIST_ENTRY *FeatureList
)
{
LIST_ENTRY *CurrentEntry;
CPU_FEATURES_ENTRY *CpuFeature;
LIST_ENTRY *CheckEntry;
CPU_FEATURES_ENTRY *CheckFeature;
BOOLEAN Swapped;
LIST_ENTRY *TempEntry;
LIST_ENTRY *NextEntry;
LIST_ENTRY *CurrentEntry;
CPU_FEATURES_ENTRY *CpuFeature;
LIST_ENTRY *CheckEntry;
CPU_FEATURES_ENTRY *CheckFeature;
BOOLEAN Swapped;
LIST_ENTRY *TempEntry;
LIST_ENTRY *NextEntry;
CurrentEntry = GetFirstNode (FeatureList);
while (!IsNull (FeatureList, CurrentEntry)) {
Swapped = FALSE;
Swapped = FALSE;
CpuFeature = CPU_FEATURE_ENTRY_FROM_LINK (CurrentEntry);
NextEntry = CurrentEntry->ForwardLink;
NextEntry = CurrentEntry->ForwardLink;
if (CpuFeature->BeforeAll) {
//
// Check all features dispatched before this entry
@@ -526,8 +539,10 @@ CheckCpuFeaturesDependency (
Swapped = TRUE;
break;
}
CheckEntry = CheckEntry->ForwardLink;
}
if (Swapped) {
CurrentEntry = NextEntry;
continue;
@@ -550,11 +565,13 @@ CheckCpuFeaturesDependency (
RemoveEntryList (CurrentEntry);
InsertHeadList (CheckEntry, CurrentEntry);
CurrentEntry = TempEntry;
Swapped = TRUE;
Swapped = TRUE;
break;
}
CheckEntry = CheckEntry->ForwardLink;
}
if (Swapped) {
CurrentEntry = NextEntry;
continue;
@@ -622,18 +639,18 @@ CheckCpuFeaturesDependency (
**/
RETURN_STATUS
RegisterCpuFeatureWorker (
IN CPU_FEATURES_DATA *CpuFeaturesData,
IN CPU_FEATURES_ENTRY *CpuFeature
IN CPU_FEATURES_DATA *CpuFeaturesData,
IN CPU_FEATURES_ENTRY *CpuFeature
)
{
EFI_STATUS Status;
CPU_FEATURES_ENTRY *CpuFeatureEntry;
LIST_ENTRY *Entry;
BOOLEAN FeatureExist;
EFI_STATUS Status;
CPU_FEATURES_ENTRY *CpuFeatureEntry;
LIST_ENTRY *Entry;
BOOLEAN FeatureExist;
FeatureExist = FALSE;
FeatureExist = FALSE;
CpuFeatureEntry = NULL;
Entry = GetFirstNode (&CpuFeaturesData->FeatureList);
Entry = GetFirstNode (&CpuFeaturesData->FeatureList);
while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) {
CpuFeatureEntry = CPU_FEATURE_ENTRY_FROM_LINK (Entry);
if (CompareMem (CpuFeature->FeatureMask, CpuFeatureEntry->FeatureMask, CpuFeaturesData->BitMaskSize) == 0) {
@@ -643,6 +660,7 @@ RegisterCpuFeatureWorker (
FeatureExist = TRUE;
break;
}
Entry = Entry->ForwardLink;
}
@@ -661,55 +679,71 @@ RegisterCpuFeatureWorker (
if (CpuFeature->GetConfigDataFunc != NULL) {
CpuFeatureEntry->GetConfigDataFunc = CpuFeature->GetConfigDataFunc;
}
if (CpuFeature->SupportFunc != NULL) {
CpuFeatureEntry->SupportFunc = CpuFeature->SupportFunc;
}
if (CpuFeature->InitializeFunc != NULL) {
CpuFeatureEntry->InitializeFunc = CpuFeature->InitializeFunc;
}
if (CpuFeature->FeatureName != NULL) {
if (CpuFeatureEntry->FeatureName == NULL) {
CpuFeatureEntry->FeatureName = AllocatePool (CPU_FEATURE_NAME_SIZE);
ASSERT (CpuFeatureEntry->FeatureName != NULL);
}
Status = AsciiStrCpyS (CpuFeatureEntry->FeatureName, CPU_FEATURE_NAME_SIZE, CpuFeature->FeatureName);
ASSERT_EFI_ERROR (Status);
FreePool (CpuFeature->FeatureName);
}
if (CpuFeature->ThreadBeforeFeatureBitMask != NULL) {
if (CpuFeatureEntry->ThreadBeforeFeatureBitMask != NULL) {
FreePool (CpuFeatureEntry->ThreadBeforeFeatureBitMask);
}
CpuFeatureEntry->ThreadBeforeFeatureBitMask = CpuFeature->ThreadBeforeFeatureBitMask;
}
if (CpuFeature->ThreadAfterFeatureBitMask != NULL) {
if (CpuFeatureEntry->ThreadAfterFeatureBitMask != NULL) {
FreePool (CpuFeatureEntry->ThreadAfterFeatureBitMask);
}
CpuFeatureEntry->ThreadAfterFeatureBitMask = CpuFeature->ThreadAfterFeatureBitMask;
}
if (CpuFeature->CoreBeforeFeatureBitMask != NULL) {
if (CpuFeatureEntry->CoreBeforeFeatureBitMask != NULL) {
FreePool (CpuFeatureEntry->CoreBeforeFeatureBitMask);
}
CpuFeatureEntry->CoreBeforeFeatureBitMask = CpuFeature->CoreBeforeFeatureBitMask;
}
if (CpuFeature->CoreAfterFeatureBitMask != NULL) {
if (CpuFeatureEntry->CoreAfterFeatureBitMask != NULL) {
FreePool (CpuFeatureEntry->CoreAfterFeatureBitMask);
}
CpuFeatureEntry->CoreAfterFeatureBitMask = CpuFeature->CoreAfterFeatureBitMask;
}
if (CpuFeature->PackageBeforeFeatureBitMask != NULL) {
if (CpuFeatureEntry->PackageBeforeFeatureBitMask != NULL) {
FreePool (CpuFeatureEntry->PackageBeforeFeatureBitMask);
}
CpuFeatureEntry->PackageBeforeFeatureBitMask = CpuFeature->PackageBeforeFeatureBitMask;
}
if (CpuFeature->PackageAfterFeatureBitMask != NULL) {
if (CpuFeatureEntry->PackageAfterFeatureBitMask != NULL) {
FreePool (CpuFeatureEntry->PackageAfterFeatureBitMask);
}
CpuFeatureEntry->PackageAfterFeatureBitMask = CpuFeature->PackageAfterFeatureBitMask;
}
@@ -719,6 +753,7 @@ RegisterCpuFeatureWorker (
FreePool (CpuFeature->FeatureMask);
FreePool (CpuFeature);
}
//
// Verify CPU features dependency can change CPU feature order
//
@@ -735,12 +770,12 @@ RegisterCpuFeatureWorker (
**/
VOID
SetCpuFeaturesBitMask (
IN UINT8 **FeaturesBitMask,
IN UINT32 Feature,
IN UINTN BitMaskSize
IN UINT8 **FeaturesBitMask,
IN UINT32 Feature,
IN UINTN BitMaskSize
)
{
UINT8 *CpuFeaturesBitMask;
UINT8 *CpuFeaturesBitMask;
ASSERT (FeaturesBitMask != NULL);
CpuFeaturesBitMask = *FeaturesBitMask;
@@ -751,7 +786,7 @@ SetCpuFeaturesBitMask (
}
CpuFeaturesBitMask += (Feature / 8);
*CpuFeaturesBitMask |= (UINT8) (1 << (Feature % 8));
*CpuFeaturesBitMask |= (UINT8)(1 << (Feature % 8));
}
/**
@@ -803,27 +838,27 @@ SetCpuFeaturesBitMask (
RETURN_STATUS
EFIAPI
RegisterCpuFeature (
IN CHAR8 *FeatureName OPTIONAL,
IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc OPTIONAL,
IN CPU_FEATURE_SUPPORT SupportFunc OPTIONAL,
IN CPU_FEATURE_INITIALIZE InitializeFunc OPTIONAL,
IN CHAR8 *FeatureName OPTIONAL,
IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc OPTIONAL,
IN CPU_FEATURE_SUPPORT SupportFunc OPTIONAL,
IN CPU_FEATURE_INITIALIZE InitializeFunc OPTIONAL,
...
)
{
EFI_STATUS Status;
VA_LIST Marker;
UINT32 Feature;
CPU_FEATURES_ENTRY *CpuFeature;
UINT8 *FeatureMask;
UINT8 *ThreadBeforeFeatureBitMask;
UINT8 *ThreadAfterFeatureBitMask;
UINT8 *CoreBeforeFeatureBitMask;
UINT8 *CoreAfterFeatureBitMask;
UINT8 *PackageBeforeFeatureBitMask;
UINT8 *PackageAfterFeatureBitMask;
BOOLEAN BeforeAll;
BOOLEAN AfterAll;
CPU_FEATURES_DATA *CpuFeaturesData;
EFI_STATUS Status;
VA_LIST Marker;
UINT32 Feature;
CPU_FEATURES_ENTRY *CpuFeature;
UINT8 *FeatureMask;
UINT8 *ThreadBeforeFeatureBitMask;
UINT8 *ThreadAfterFeatureBitMask;
UINT8 *CoreBeforeFeatureBitMask;
UINT8 *CoreAfterFeatureBitMask;
UINT8 *PackageBeforeFeatureBitMask;
UINT8 *PackageAfterFeatureBitMask;
BOOLEAN BeforeAll;
BOOLEAN AfterAll;
CPU_FEATURES_DATA *CpuFeaturesData;
FeatureMask = NULL;
ThreadBeforeFeatureBitMask = NULL;
@@ -832,8 +867,8 @@ RegisterCpuFeature (
CoreAfterFeatureBitMask = NULL;
PackageBeforeFeatureBitMask = NULL;
PackageAfterFeatureBitMask = NULL;
BeforeAll = FALSE;
AfterAll = FALSE;
BeforeAll = FALSE;
AfterAll = FALSE;
CpuFeaturesData = GetCpuFeaturesData ();
if (CpuFeaturesData->FeaturesCount == 0) {
@@ -844,7 +879,7 @@ RegisterCpuFeature (
//
ASSERT (PcdGetSize (PcdCpuFeaturesSetting) == PcdGetSize (PcdCpuFeaturesCapability));
ASSERT (PcdGetSize (PcdCpuFeaturesSetting) == PcdGetSize (PcdCpuFeaturesSupport));
CpuFeaturesData->BitMaskSize = (UINT32) PcdGetSize (PcdCpuFeaturesSetting);
CpuFeaturesData->BitMaskSize = (UINT32)PcdGetSize (PcdCpuFeaturesSetting);
}
VA_START (Marker, InitializeFunc);
@@ -853,19 +888,27 @@ RegisterCpuFeature (
//
// It's invalid to require a feature is before AND after all other features.
//
ASSERT ((Feature & (CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL))
!= (CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL));
ASSERT (
(Feature & (CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL))
!= (CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL)
);
//
// It's invalid to require feature A is before AND after before feature B,
// either in thread level, core level or package level.
//
ASSERT ((Feature & (CPU_FEATURE_THREAD_BEFORE | CPU_FEATURE_THREAD_AFTER))
!= (CPU_FEATURE_THREAD_BEFORE | CPU_FEATURE_THREAD_AFTER));
ASSERT ((Feature & (CPU_FEATURE_CORE_BEFORE | CPU_FEATURE_CORE_AFTER))
!= (CPU_FEATURE_CORE_BEFORE | CPU_FEATURE_CORE_AFTER));
ASSERT ((Feature & (CPU_FEATURE_PACKAGE_BEFORE | CPU_FEATURE_PACKAGE_AFTER))
!= (CPU_FEATURE_PACKAGE_BEFORE | CPU_FEATURE_PACKAGE_AFTER));
ASSERT (
(Feature & (CPU_FEATURE_THREAD_BEFORE | CPU_FEATURE_THREAD_AFTER))
!= (CPU_FEATURE_THREAD_BEFORE | CPU_FEATURE_THREAD_AFTER)
);
ASSERT (
(Feature & (CPU_FEATURE_CORE_BEFORE | CPU_FEATURE_CORE_AFTER))
!= (CPU_FEATURE_CORE_BEFORE | CPU_FEATURE_CORE_AFTER)
);
ASSERT (
(Feature & (CPU_FEATURE_PACKAGE_BEFORE | CPU_FEATURE_PACKAGE_AFTER))
!= (CPU_FEATURE_PACKAGE_BEFORE | CPU_FEATURE_PACKAGE_AFTER)
);
if (Feature < CPU_FEATURE_THREAD_BEFORE) {
BeforeAll = ((Feature & CPU_FEATURE_BEFORE_ALL) != 0) ? TRUE : FALSE;
AfterAll = ((Feature & CPU_FEATURE_AFTER_ALL) != 0) ? TRUE : FALSE;
@@ -885,8 +928,10 @@ RegisterCpuFeature (
} else if ((Feature & CPU_FEATURE_PACKAGE_AFTER) != 0) {
SetCpuFeaturesBitMask (&PackageAfterFeatureBitMask, Feature & ~CPU_FEATURE_PACKAGE_AFTER, CpuFeaturesData->BitMaskSize);
}
Feature = VA_ARG (Marker, UINT32);
}
VA_END (Marker);
CpuFeature = AllocateZeroPool (sizeof (CPU_FEATURES_ENTRY));
@@ -905,7 +950,7 @@ RegisterCpuFeature (
CpuFeature->SupportFunc = SupportFunc;
CpuFeature->InitializeFunc = InitializeFunc;
if (FeatureName != NULL) {
CpuFeature->FeatureName = AllocatePool (CPU_FEATURE_NAME_SIZE);
CpuFeature->FeatureName = AllocatePool (CPU_FEATURE_NAME_SIZE);
ASSERT (CpuFeature->FeatureName != NULL);
Status = AsciiStrCpyS (CpuFeature->FeatureName, CPU_FEATURE_NAME_SIZE, FeatureName);
ASSERT_EFI_ERROR (Status);
@@ -927,18 +972,18 @@ GetAcpiCpuData (
VOID
)
{
EFI_STATUS Status;
UINTN NumberOfCpus;
UINTN NumberOfEnabledProcessors;
ACPI_CPU_DATA *AcpiCpuData;
UINTN TableSize;
CPU_REGISTER_TABLE *RegisterTable;
UINTN Index;
EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
EFI_STATUS Status;
UINTN NumberOfCpus;
UINTN NumberOfEnabledProcessors;
ACPI_CPU_DATA *AcpiCpuData;
UINTN TableSize;
CPU_REGISTER_TABLE *RegisterTable;
UINTN Index;
EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
AcpiCpuData = (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress);
AcpiCpuData = (ACPI_CPU_DATA *)(UINTN)PcdGet64 (PcdCpuS3DataAddress);
if (AcpiCpuData == NULL) {
AcpiCpuData = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)));
AcpiCpuData = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)));
ASSERT (AcpiCpuData != NULL);
ZeroMem (AcpiCpuData, sizeof (ACPI_CPU_DATA));
@@ -952,14 +997,15 @@ GetAcpiCpuData (
AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus;
}
if (AcpiCpuData->CpuFeatureInitData.RegisterTable == 0 ||
AcpiCpuData->CpuFeatureInitData.PreSmmInitRegisterTable == 0) {
if ((AcpiCpuData->CpuFeatureInitData.RegisterTable == 0) ||
(AcpiCpuData->CpuFeatureInitData.PreSmmInitRegisterTable == 0))
{
//
// Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs
//
NumberOfCpus = AcpiCpuData->NumberOfCpus;
TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
RegisterTable = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
NumberOfCpus = AcpiCpuData->NumberOfCpus;
TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
RegisterTable = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
ASSERT (RegisterTable != NULL);
for (Index = 0; Index < NumberOfCpus; Index++) {
@@ -976,9 +1022,11 @@ GetAcpiCpuData (
RegisterTable[NumberOfCpus + Index].AllocatedSize = 0;
RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0;
}
if (AcpiCpuData->CpuFeatureInitData.RegisterTable == 0) {
AcpiCpuData->CpuFeatureInitData.RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable;
}
if (AcpiCpuData->CpuFeatureInitData.PreSmmInitRegisterTable == 0) {
AcpiCpuData->CpuFeatureInitData.PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus);
}
@@ -995,14 +1043,14 @@ GetAcpiCpuData (
STATIC
VOID
EnlargeRegisterTable (
IN OUT CPU_REGISTER_TABLE *RegisterTable
IN OUT CPU_REGISTER_TABLE *RegisterTable
)
{
EFI_PHYSICAL_ADDRESS Address;
UINTN UsedPages;
UsedPages = RegisterTable->AllocatedSize / EFI_PAGE_SIZE;
Address = (UINTN)AllocatePages (UsedPages + 1);
Address = (UINTN)AllocatePages (UsedPages + 1);
ASSERT (Address != 0);
//
@@ -1011,8 +1059,8 @@ EnlargeRegisterTable (
//
if (RegisterTable->AllocatedSize > 0) {
CopyMem (
(VOID *) (UINTN) Address,
(VOID *) (UINTN) RegisterTable->RegisterTableEntry,
(VOID *)(UINTN)Address,
(VOID *)(UINTN)RegisterTable->RegisterTableEntry,
RegisterTable->AllocatedSize
);
@@ -1045,27 +1093,27 @@ EnlargeRegisterTable (
**/
VOID
CpuRegisterTableWriteWorker (
IN BOOLEAN PreSmmFlag,
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT8 ValidBitStart,
IN UINT8 ValidBitLength,
IN UINT64 Value,
IN BOOLEAN TestThenWrite
IN BOOLEAN PreSmmFlag,
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT8 ValidBitStart,
IN UINT8 ValidBitLength,
IN UINT64 Value,
IN BOOLEAN TestThenWrite
)
{
CPU_FEATURES_DATA *CpuFeaturesData;
ACPI_CPU_DATA *AcpiCpuData;
CPU_REGISTER_TABLE *RegisterTable;
CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry;
CPU_FEATURES_DATA *CpuFeaturesData;
ACPI_CPU_DATA *AcpiCpuData;
CPU_REGISTER_TABLE *RegisterTable;
CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry;
CpuFeaturesData = GetCpuFeaturesData ();
if (CpuFeaturesData->RegisterTable == NULL) {
AcpiCpuData = GetAcpiCpuData ();
ASSERT ((AcpiCpuData != NULL) && (AcpiCpuData->CpuFeatureInitData.RegisterTable != 0));
CpuFeaturesData->RegisterTable = (CPU_REGISTER_TABLE *) (UINTN) AcpiCpuData->CpuFeatureInitData.RegisterTable;
CpuFeaturesData->PreSmmRegisterTable = (CPU_REGISTER_TABLE *) (UINTN) AcpiCpuData->CpuFeatureInitData.PreSmmInitRegisterTable;
CpuFeaturesData->RegisterTable = (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->CpuFeatureInitData.RegisterTable;
CpuFeaturesData->PreSmmRegisterTable = (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->CpuFeatureInitData.PreSmmInitRegisterTable;
}
if (PreSmmFlag) {
@@ -1081,10 +1129,10 @@ CpuRegisterTableWriteWorker (
//
// Append entry in the register table.
//
RegisterTableEntry = (CPU_REGISTER_TABLE_ENTRY *) (UINTN) RegisterTable->RegisterTableEntry;
RegisterTableEntry = (CPU_REGISTER_TABLE_ENTRY *)(UINTN)RegisterTable->RegisterTableEntry;
RegisterTableEntry[RegisterTable->TableLength].RegisterType = RegisterType;
RegisterTableEntry[RegisterTable->TableLength].Index = (UINT32) Index;
RegisterTableEntry[RegisterTable->TableLength].HighIndex = (UINT32) RShiftU64 (Index, 32);
RegisterTableEntry[RegisterTable->TableLength].Index = (UINT32)Index;
RegisterTableEntry[RegisterTable->TableLength].HighIndex = (UINT32)RShiftU64 (Index, 32);
RegisterTableEntry[RegisterTable->TableLength].ValidBitStart = ValidBitStart;
RegisterTableEntry[RegisterTable->TableLength].ValidBitLength = ValidBitLength;
RegisterTableEntry[RegisterTable->TableLength].Value = Value;
@@ -1110,18 +1158,18 @@ CpuRegisterTableWriteWorker (
VOID
EFIAPI
CpuRegisterTableWrite (
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT64 ValueMask,
IN UINT64 Value
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT64 ValueMask,
IN UINT64 Value
)
{
UINT8 Start;
UINT8 End;
UINT8 Length;
UINT8 Start;
UINT8 End;
UINT8 Length;
Start = (UINT8)LowBitSet64 (ValueMask);
Start = (UINT8)LowBitSet64 (ValueMask);
End = (UINT8)HighBitSet64 (ValueMask);
Length = End - Start + 1;
CpuRegisterTableWriteWorker (FALSE, ProcessorNumber, RegisterType, Index, Start, Length, Value, FALSE);
@@ -1144,18 +1192,18 @@ CpuRegisterTableWrite (
VOID
EFIAPI
CpuRegisterTableTestThenWrite (
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT64 ValueMask,
IN UINT64 Value
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT64 ValueMask,
IN UINT64 Value
)
{
UINT8 Start;
UINT8 End;
UINT8 Length;
UINT8 Start;
UINT8 End;
UINT8 Length;
Start = (UINT8)LowBitSet64 (ValueMask);
Start = (UINT8)LowBitSet64 (ValueMask);
End = (UINT8)HighBitSet64 (ValueMask);
Length = End - Start + 1;
CpuRegisterTableWriteWorker (FALSE, ProcessorNumber, RegisterType, Index, Start, Length, Value, TRUE);
@@ -1178,18 +1226,18 @@ CpuRegisterTableTestThenWrite (
VOID
EFIAPI
PreSmmCpuRegisterTableWrite (
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT64 ValueMask,
IN UINT64 Value
IN UINTN ProcessorNumber,
IN REGISTER_TYPE RegisterType,
IN UINT64 Index,
IN UINT64 ValueMask,
IN UINT64 Value
)
{
UINT8 Start;
UINT8 End;
UINT8 Length;
Start = (UINT8)LowBitSet64 (ValueMask);
Start = (UINT8)LowBitSet64 (ValueMask);
End = (UINT8)HighBitSet64 (ValueMask);
Length = End - Start + 1;
CpuRegisterTableWriteWorker (TRUE, ProcessorNumber, RegisterType, Index, Start, Length, Value, FALSE);
@@ -1208,14 +1256,15 @@ PreSmmCpuRegisterTableWrite (
**/
BOOLEAN
IsCpuFeatureSetInCpuPcd (
IN UINT8 *CpuBitMask,
IN UINTN CpuBitMaskSize,
IN UINT32 Feature
IN UINT8 *CpuBitMask,
IN UINTN CpuBitMaskSize,
IN UINT32 Feature
)
{
if ((Feature >> 3) >= CpuBitMaskSize) {
return FALSE;
}
return ((*(CpuBitMask + (Feature >> 3)) & (1 << (Feature & 0x07))) != 0);
}
@@ -1236,7 +1285,7 @@ IsCpuFeatureSetInCpuPcd (
BOOLEAN
EFIAPI
IsCpuFeatureSupported (
IN UINT32 Feature
IN UINT32 Feature
)
{
return IsCpuFeatureSetInCpuPcd (
@@ -1260,7 +1309,7 @@ IsCpuFeatureSupported (
BOOLEAN
EFIAPI
IsCpuFeatureInSetting (
IN UINT32 Feature
IN UINT32 Feature
)
{
return IsCpuFeatureSetInCpuPcd (
@@ -1280,11 +1329,11 @@ IsCpuFeatureInSetting (
VOID
EFIAPI
SwitchBspAfterFeaturesInitialize (
IN UINTN ProcessorNumber
IN UINTN ProcessorNumber
)
{
CPU_FEATURES_DATA *CpuFeaturesData;
CPU_FEATURES_DATA *CpuFeaturesData;
CpuFeaturesData = GetCpuFeaturesData ();
CpuFeaturesData = GetCpuFeaturesData ();
CpuFeaturesData->BspNumber = ProcessorNumber;
}

View File

@@ -27,10 +27,10 @@ InternalX86GetTimerFrequency (
VOID
)
{
UINTN Divisor;
UINTN Divisor;
GetApicTimerState (&Divisor, NULL, NULL);
return PcdGet32(PcdFSBClock) / (UINT32)Divisor;
return PcdGet32 (PcdFSBClock) / (UINT32)Divisor;
}
/**
@@ -48,13 +48,13 @@ InternalX86GetTimerFrequency (
VOID
EFIAPI
InternalX86Delay (
IN UINT32 Delay
IN UINT32 Delay
)
{
INT32 Ticks;
UINT32 Times;
UINT32 InitCount;
UINT32 StartTick;
INT32 Ticks;
UINT32 Times;
UINT32 InitCount;
UINT32 StartTick;
//
// In case Delay is too larger, separate it into several small delay slot.
@@ -65,13 +65,13 @@ InternalX86Delay (
//
InitCount = GetApicTimerInitCount ();
ASSERT (InitCount != 0);
Times = Delay / (InitCount / 2);
Delay = Delay % (InitCount / 2);
Times = Delay / (InitCount / 2);
Delay = Delay % (InitCount / 2);
//
// Get Start Tick and do delay
//
StartTick = GetApicTimerCurrentCount ();
StartTick = GetApicTimerCurrentCount ();
do {
//
// Wait until time out by Delay value
@@ -111,7 +111,7 @@ InternalX86Delay (
UINTN
EFIAPI
MicroSecondDelay (
IN UINTN MicroSeconds
IN UINTN MicroSeconds
)
{
InternalX86Delay (
@@ -139,7 +139,7 @@ MicroSecondDelay (
UINTN
EFIAPI
NanoSecondDelay (
IN UINTN NanoSeconds
IN UINTN NanoSeconds
)
{
InternalX86Delay (
@@ -200,8 +200,8 @@ GetPerformanceCounter (
UINT64
EFIAPI
GetPerformanceCounterProperties (
OUT UINT64 *StartValue OPTIONAL,
OUT UINT64 *EndValue OPTIONAL
OUT UINT64 *StartValue OPTIONAL,
OUT UINT64 *EndValue OPTIONAL
)
{
if (StartValue != NULL) {
@@ -212,7 +212,7 @@ GetPerformanceCounterProperties (
*EndValue = 0;
}
return (UINT64) InternalX86GetTimerFrequency ();
return (UINT64)InternalX86GetTimerFrequency ();
}
/**
@@ -229,7 +229,7 @@ GetPerformanceCounterProperties (
UINT64
EFIAPI
GetTimeInNanoSecond (
IN UINT64 Ticks
IN UINT64 Ticks
)
{
UINT64 Frequency;
@@ -251,9 +251,9 @@ GetTimeInNanoSecond (
// Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34,
// i.e. highest bit set in Remainder should <= 33.
//
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
Remainder = RShiftU64 (Remainder, (UINTN) Shift);
Frequency = RShiftU64 (Frequency, (UINTN) Shift);
Shift = MAX (0, HighBitSet64 (Remainder) - 33);
Remainder = RShiftU64 (Remainder, (UINTN)Shift);
Frequency = RShiftU64 (Frequency, (UINTN)Shift);
NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL);
return NanoSeconds;

View File

@@ -14,9 +14,9 @@
///
/// Page Table Entry
///
#define IA32_PG_P BIT0
#define IA32_PG_RW BIT1
#define IA32_PG_PS BIT7
#define IA32_PG_P BIT0
#define IA32_PG_RW BIT1
#define IA32_PG_PS BIT7
/**
@@ -28,14 +28,14 @@
**/
VOID
StmGen4GPageTable (
IN UINTN PageTableBase
IN UINTN PageTableBase
)
{
UINTN Index;
UINT32 *Pte;
UINT32 Address;
UINTN Index;
UINT32 *Pte;
UINT32 Address;
Pte = (UINT32*)(UINTN)PageTableBase;
Pte = (UINT32 *)(UINTN)PageTableBase;
Address = 0;
for (Index = 0; Index < SIZE_4KB / sizeof (*Pte); Index++) {
@@ -63,7 +63,7 @@ StmGen4GPageTable (
UINT32
EFIAPI
SmmStmExceptionHandler (
IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context
IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context
)
{
// TBD - SmmStmExceptionHandler, record information

View File

@@ -34,8 +34,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// MSRs required for configuration of SMM Code Access Check
//
#define SMM_FEATURES_LIB_IA32_MCA_CAP 0x17D
#define SMM_CODE_ACCESS_CHK_BIT BIT58
#define SMM_FEATURES_LIB_IA32_MCA_CAP 0x17D
#define SMM_CODE_ACCESS_CHK_BIT BIT58
//
// Set default value to assume SMRR is not supported
@@ -86,7 +86,7 @@ CpuFeaturesLibInitialization (
AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx);
FamilyId = (RegEax >> 8) & 0xf;
ModelId = (RegEax >> 4) & 0xf;
if (FamilyId == 0x06 || FamilyId == 0x0f) {
if ((FamilyId == 0x06) || (FamilyId == 0x0f)) {
ModelId = ModelId | ((RegEax >> 12) & 0xf0);
}
@@ -110,7 +110,7 @@ CpuFeaturesLibInitialization (
// SMRR Physical Base and SMM Physical Mask MSRs are not available.
//
if (FamilyId == 0x06) {
if (ModelId == 0x1C || ModelId == 0x26 || ModelId == 0x27 || ModelId == 0x35 || ModelId == 0x36) {
if ((ModelId == 0x1C) || (ModelId == 0x26) || (ModelId == 0x27) || (ModelId == 0x35) || (ModelId == 0x36)) {
mSmrrSupported = FALSE;
}
}
@@ -123,7 +123,7 @@ CpuFeaturesLibInitialization (
// Processor Family MSRs
//
if (FamilyId == 0x06) {
if (ModelId == 0x17 || ModelId == 0x0f) {
if ((ModelId == 0x17) || (ModelId == 0x0f)) {
mSmrrPhysBaseMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE;
mSmrrPhysMaskMsr = SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSMASK;
}
@@ -204,7 +204,7 @@ SmmCpuFeaturesInitializeProcessor (
//
// Configure SMBASE.
//
CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);
CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];
//
@@ -216,7 +216,7 @@ SmmCpuFeaturesInitializeProcessor (
// accessing SMRR base/mask MSRs. If Lock(BIT0) of MSR_FEATURE_CONTROL MSR(0x3A)
// is set, then the MSR is locked and can not be modified.
//
if (mSmrrSupported && mSmrrPhysBaseMsr == SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE) {
if (mSmrrSupported && (mSmrrPhysBaseMsr == SMM_FEATURES_LIB_IA32_CORE_SMRR_PHYSBASE)) {
FeatureControl = AsmReadMsr64 (SMM_FEATURES_LIB_IA32_FEATURE_CONTROL);
if ((FeatureControl & BIT3) == 0) {
if ((FeatureControl & BIT0) == 0) {
@@ -242,7 +242,8 @@ SmmCpuFeaturesInitializeProcessor (
//
if ((CpuHotPlugData->SmrrSize < SIZE_4KB) ||
(CpuHotPlugData->SmrrSize != GetPowerOfTwo32 (CpuHotPlugData->SmrrSize)) ||
((CpuHotPlugData->SmrrBase & ~(CpuHotPlugData->SmrrSize - 1)) != CpuHotPlugData->SmrrBase)) {
((CpuHotPlugData->SmrrBase & ~(CpuHotPlugData->SmrrSize - 1)) != CpuHotPlugData->SmrrBase))
{
//
// Print message and halt if CPU is Monarch
//
@@ -263,7 +264,7 @@ SmmCpuFeaturesInitializeProcessor (
AsmCpuid (CPUID_VERSION_INFO, &RegEax, NULL, NULL, &RegEdx);
FamilyId = (RegEax >> 8) & 0xf;
ModelId = (RegEax >> 4) & 0xf;
if (FamilyId == 0x06 || FamilyId == 0x0f) {
if ((FamilyId == 0x06) || (FamilyId == 0x0f)) {
ModelId = ModelId | ((RegEax >> 12) & 0xf0);
}
@@ -276,10 +277,11 @@ SmmCpuFeaturesInitializeProcessor (
// Intel(R) Core(TM) Processor Family MSRs.
//
if (FamilyId == 0x06) {
if (ModelId == 0x3C || ModelId == 0x45 || ModelId == 0x46 ||
ModelId == 0x3D || ModelId == 0x47 || ModelId == 0x4E || ModelId == 0x4F ||
ModelId == 0x3F || ModelId == 0x56 || ModelId == 0x57 || ModelId == 0x5C ||
ModelId == 0x8C) {
if ((ModelId == 0x3C) || (ModelId == 0x45) || (ModelId == 0x46) ||
(ModelId == 0x3D) || (ModelId == 0x47) || (ModelId == 0x4E) || (ModelId == 0x4F) ||
(ModelId == 0x3F) || (ModelId == 0x56) || (ModelId == 0x57) || (ModelId == 0x5C) ||
(ModelId == 0x8C))
{
//
// Check to see if the CPU supports the SMM Code Access Check feature
// Do not access this MSR unless the CPU supports the SmmRegFeatureControl
@@ -382,7 +384,7 @@ SmmCpuFeaturesDisableSmrr (
)
{
if (mSmrrSupported && mNeedConfigureMtrrs) {
AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64(mSmrrPhysMaskMsr) & ~EFI_MSR_SMRR_PHYS_MASK_VALID);
AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64 (mSmrrPhysMaskMsr) & ~EFI_MSR_SMRR_PHYS_MASK_VALID);
}
}
@@ -397,7 +399,7 @@ SmmCpuFeaturesReenableSmrr (
)
{
if (mSmrrSupported && mNeedConfigureMtrrs) {
AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64(mSmrrPhysMaskMsr) | EFI_MSR_SMRR_PHYS_MASK_VALID);
AsmWriteMsr64 (mSmrrPhysMaskMsr, AsmReadMsr64 (mSmrrPhysMaskMsr) | EFI_MSR_SMRR_PHYS_MASK_VALID);
}
}
@@ -458,9 +460,10 @@ SmmCpuFeaturesIsSmmRegisterSupported (
IN SMM_REG_NAME RegName
)
{
if (mSmmFeatureControlSupported && RegName == SmmRegFeatureControl) {
if (mSmmFeatureControlSupported && (RegName == SmmRegFeatureControl)) {
return TRUE;
}
return FALSE;
}
@@ -483,9 +486,10 @@ SmmCpuFeaturesGetSmmRegister (
IN SMM_REG_NAME RegName
)
{
if (mSmmFeatureControlSupported && RegName == SmmRegFeatureControl) {
if (mSmmFeatureControlSupported && (RegName == SmmRegFeatureControl)) {
return AsmReadMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL);
}
return 0;
}
@@ -508,7 +512,7 @@ SmmCpuFeaturesSetSmmRegister (
IN UINT64 Value
)
{
if (mSmmFeatureControlSupported && RegName == SmmRegFeatureControl) {
if (mSmmFeatureControlSupported && (RegName == SmmRegFeatureControl)) {
AsmWriteMsr64 (SMM_FEATURES_LIB_SMM_FEATURE_CONTROL, Value);
}
}
@@ -605,9 +609,8 @@ SmmCpuFeaturesCompleteSmmReadyToLock (
VOID *
EFIAPI
SmmCpuFeaturesAllocatePageTableMemory (
IN UINTN Pages
IN UINTN Pages
)
{
return NULL;
}

View File

@@ -24,21 +24,21 @@
#include "CpuFeaturesLib.h"
#include "SmmStm.h"
#define TXT_EVTYPE_BASE 0x400
#define TXT_EVTYPE_STM_HASH (TXT_EVTYPE_BASE + 14)
#define TXT_EVTYPE_BASE 0x400
#define TXT_EVTYPE_STM_HASH (TXT_EVTYPE_BASE + 14)
#define RDWR_ACCS 3
#define FULL_ACCS 7
#define RDWR_ACCS 3
#define FULL_ACCS 7
EFI_HANDLE mStmSmmCpuHandle = NULL;
BOOLEAN mLockLoadMonitor = FALSE;
BOOLEAN mLockLoadMonitor = FALSE;
//
// Template of STM_RSC_END structure for copying.
//
GLOBAL_REMOVE_IF_UNREFERENCED STM_RSC_END mRscEndNode = {
{END_OF_RESOURCES, sizeof (STM_RSC_END)},
GLOBAL_REMOVE_IF_UNREFERENCED STM_RSC_END mRscEndNode = {
{ END_OF_RESOURCES, sizeof (STM_RSC_END) },
};
GLOBAL_REMOVE_IF_UNREFERENCED UINT8 *mStmResourcesPtr = NULL;
@@ -52,7 +52,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mStmState = 0;
// System Configuration Table pointing to STM Configuration Table
//
GLOBAL_REMOVE_IF_UNREFERENCED
EFI_SM_MONITOR_INIT_PROTOCOL mSmMonitorInitProtocol = {
EFI_SM_MONITOR_INIT_PROTOCOL mSmMonitorInitProtocol = {
LoadMonitor,
AddPiResource,
DeletePiResource,
@@ -60,10 +60,7 @@ EFI_SM_MONITOR_INIT_PROTOCOL mSmMonitorInitProtocol = {
GetMonitorState,
};
#define CPUID1_EDX_XD_SUPPORT 0x100000
#define CPUID1_EDX_XD_SUPPORT 0x100000
//
// External global variables associated with SMI Handler Template
@@ -146,10 +143,10 @@ SmmCpuFeaturesLibStmConstructor (
//
// Retrieve MSEG location from MSEG SRAM HOB
//
SmramDescriptor = (EFI_SMRAM_DESCRIPTOR *) GET_GUID_HOB_DATA (GuidHob);
SmramDescriptor = (EFI_SMRAM_DESCRIPTOR *)GET_GUID_HOB_DATA (GuidHob);
if (SmramDescriptor->PhysicalSize > 0) {
mMsegBase = (UINTN)SmramDescriptor->CpuStart;
mMsegSize = (UINTN)SmramDescriptor->PhysicalSize;
mMsegBase = (UINTN)SmramDescriptor->CpuStart;
mMsegSize = (UINTN)SmramDescriptor->PhysicalSize;
}
} else if (PcdGet32 (PcdCpuMsegSize) > 0) {
//
@@ -162,6 +159,7 @@ SmmCpuFeaturesLibStmConstructor (
DEBUG ((DEBUG_ERROR, "Not enough SMRAM resource to allocate MSEG size %08x\n", PcdGet32 (PcdCpuMsegSize)));
}
}
if (mMsegBase > 0) {
DEBUG ((DEBUG_INFO, "MsegBase: 0x%08x, MsegSize: 0x%08x\n", mMsegBase, mMsegSize));
}
@@ -251,16 +249,16 @@ SmmCpuFeaturesInstallSmiHandler (
IN UINT32 Cr3
)
{
EFI_STATUS Status;
TXT_PROCESSOR_SMM_DESCRIPTOR *Psd;
VOID *Hob;
UINT32 RegEax;
UINT32 RegEdx;
EFI_PROCESSOR_INFORMATION ProcessorInfo;
EFI_STATUS Status;
TXT_PROCESSOR_SMM_DESCRIPTOR *Psd;
VOID *Hob;
UINT32 RegEax;
UINT32 RegEdx;
EFI_PROCESSOR_INFORMATION ProcessorInfo;
CopyMem ((VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET), &gcStmPsd, sizeof (gcStmPsd));
Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET);
Psd->SmmGdtPtr = GdtBase;
Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET);
Psd->SmmGdtPtr = GdtBase;
Psd->SmmGdtSize = (UINT32)GdtSize;
//
@@ -293,49 +291,49 @@ SmmCpuFeaturesInstallSmiHandler (
//
// Set the value at the top of the CPU stack to the CPU Index
//
*(UINTN*)(UINTN)gStmSmiStack = CpuIndex;
*(UINTN *)(UINTN)gStmSmiStack = CpuIndex;
//
// Copy template to CPU specific SMI handler location
//
CopyMem (
(VOID*)((UINTN)SmBase + SMM_HANDLER_OFFSET),
(VOID*)gcStmSmiHandlerTemplate,
(VOID *)((UINTN)SmBase + SMM_HANDLER_OFFSET),
(VOID *)gcStmSmiHandlerTemplate,
gcStmSmiHandlerSize
);
Psd->SmmSmiHandlerRip = SmBase + SMM_HANDLER_OFFSET + gcStmSmiHandlerOffset;
Psd->SmmSmiHandlerRsp = (UINTN)SmiStack + StackSize - sizeof(UINTN);
Psd->SmmSmiHandlerRsp = (UINTN)SmiStack + StackSize - sizeof (UINTN);
Psd->SmmCr3 = Cr3;
DEBUG((DEBUG_INFO, "CpuSmmStmExceptionStackSize - %x\n", PcdGet32(PcdCpuSmmStmExceptionStackSize)));
DEBUG((DEBUG_INFO, "Pages - %x\n", EFI_SIZE_TO_PAGES(PcdGet32(PcdCpuSmmStmExceptionStackSize))));
Psd->StmProtectionExceptionHandler.SpeRsp = (UINT64)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (PcdGet32 (PcdCpuSmmStmExceptionStackSize)));
DEBUG ((DEBUG_INFO, "CpuSmmStmExceptionStackSize - %x\n", PcdGet32 (PcdCpuSmmStmExceptionStackSize)));
DEBUG ((DEBUG_INFO, "Pages - %x\n", EFI_SIZE_TO_PAGES (PcdGet32 (PcdCpuSmmStmExceptionStackSize))));
Psd->StmProtectionExceptionHandler.SpeRsp = (UINT64)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (PcdGet32 (PcdCpuSmmStmExceptionStackSize)));
Psd->StmProtectionExceptionHandler.SpeRsp += EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (PcdGet32 (PcdCpuSmmStmExceptionStackSize)));
Psd->BiosHwResourceRequirementsPtr = (UINT64)(UINTN)GetStmResource ();
Psd->BiosHwResourceRequirementsPtr = (UINT64)(UINTN)GetStmResource ();
//
// Get the APIC ID for the CPU specified by CpuIndex
//
Status = mSmmCpuFeaturesLibMpService->GetProcessorInfo (
mSmmCpuFeaturesLibMpService,
CpuIndex,
&ProcessorInfo
);
mSmmCpuFeaturesLibMpService,
CpuIndex,
&ProcessorInfo
);
ASSERT_EFI_ERROR (Status);
Psd->LocalApicId = (UINT32)ProcessorInfo.ProcessorId;
Psd->AcpiRsdp = 0;
Psd->AcpiRsdp = 0;
Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
if (Hob != NULL) {
Psd->PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
Psd->PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;
} else {
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
if (RegEax >= 0x80000008) {
AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
Psd->PhysicalAddressBits = (UINT8) RegEax;
Psd->PhysicalAddressBits = (UINT8)RegEax;
} else {
Psd->PhysicalAddressBits = 36;
}
@@ -385,6 +383,7 @@ SmmEndOfDxeEventNotify (
break;
}
}
if (Rsdp == NULL) {
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
if (CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpi10TableGuid)) {
@@ -416,8 +415,8 @@ StmSmmConfigurationTableInit (
VOID
)
{
EFI_STATUS Status;
VOID *Registration;
EFI_STATUS Status;
VOID *Registration;
Status = gSmst->SmmInstallProtocolInterface (
&mStmSmmCpuHandle,
@@ -468,19 +467,19 @@ GetMonitorState (
**/
BOOLEAN
HandleSingleResource (
IN STM_RSC *Resource,
IN STM_RSC *Record
IN STM_RSC *Resource,
IN STM_RSC *Record
)
{
UINT64 ResourceLo;
UINT64 ResourceHi;
UINT64 RecordLo;
UINT64 RecordHi;
UINT64 ResourceLo;
UINT64 ResourceHi;
UINT64 RecordLo;
UINT64 RecordHi;
ResourceLo = 0;
ResourceHi = 0;
RecordLo = 0;
RecordHi = 0;
RecordLo = 0;
RecordHi = 0;
//
// Calling code is responsible for making sure that
@@ -488,62 +487,69 @@ HandleSingleResource (
// thus we use just one of them as switch variable.
//
switch (Resource->Header.RscType) {
case MEM_RANGE:
case MMIO_RANGE:
ResourceLo = Resource->Mem.Base;
ResourceHi = Resource->Mem.Base + Resource->Mem.Length;
RecordLo = Record->Mem.Base;
RecordHi = Record->Mem.Base + Record->Mem.Length;
if (Resource->Mem.RWXAttributes != Record->Mem.RWXAttributes) {
if ((ResourceLo == RecordLo) && (ResourceHi == RecordHi)) {
Record->Mem.RWXAttributes = Resource->Mem.RWXAttributes | Record->Mem.RWXAttributes;
return TRUE;
} else {
case MEM_RANGE:
case MMIO_RANGE:
ResourceLo = Resource->Mem.Base;
ResourceHi = Resource->Mem.Base + Resource->Mem.Length;
RecordLo = Record->Mem.Base;
RecordHi = Record->Mem.Base + Record->Mem.Length;
if (Resource->Mem.RWXAttributes != Record->Mem.RWXAttributes) {
if ((ResourceLo == RecordLo) && (ResourceHi == RecordHi)) {
Record->Mem.RWXAttributes = Resource->Mem.RWXAttributes | Record->Mem.RWXAttributes;
return TRUE;
} else {
return FALSE;
}
}
break;
case IO_RANGE:
case TRAPPED_IO_RANGE:
ResourceLo = (UINT64)Resource->Io.Base;
ResourceHi = (UINT64)Resource->Io.Base + (UINT64)Resource->Io.Length;
RecordLo = (UINT64)Record->Io.Base;
RecordHi = (UINT64)Record->Io.Base + (UINT64)Record->Io.Length;
break;
case PCI_CFG_RANGE:
if ((Resource->PciCfg.OriginatingBusNumber != Record->PciCfg.OriginatingBusNumber) ||
(Resource->PciCfg.LastNodeIndex != Record->PciCfg.LastNodeIndex))
{
return FALSE;
}
}
break;
case IO_RANGE:
case TRAPPED_IO_RANGE:
ResourceLo = (UINT64) Resource->Io.Base;
ResourceHi = (UINT64) Resource->Io.Base + (UINT64) Resource->Io.Length;
RecordLo = (UINT64) Record->Io.Base;
RecordHi = (UINT64) Record->Io.Base + (UINT64) Record->Io.Length;
break;
case PCI_CFG_RANGE:
if ((Resource->PciCfg.OriginatingBusNumber != Record->PciCfg.OriginatingBusNumber) ||
(Resource->PciCfg.LastNodeIndex != Record->PciCfg.LastNodeIndex)) {
return FALSE;
}
if (CompareMem (Resource->PciCfg.PciDevicePath, Record->PciCfg.PciDevicePath, sizeof(STM_PCI_DEVICE_PATH_NODE) * (Resource->PciCfg.LastNodeIndex + 1)) != 0) {
return FALSE;
}
ResourceLo = (UINT64) Resource->PciCfg.Base;
ResourceHi = (UINT64) Resource->PciCfg.Base + (UINT64) Resource->PciCfg.Length;
RecordLo = (UINT64) Record->PciCfg.Base;
RecordHi = (UINT64) Record->PciCfg.Base + (UINT64) Record->PciCfg.Length;
if (Resource->PciCfg.RWAttributes != Record->PciCfg.RWAttributes) {
if ((ResourceLo == RecordLo) && (ResourceHi == RecordHi)) {
Record->PciCfg.RWAttributes = Resource->PciCfg.RWAttributes | Record->PciCfg.RWAttributes;
return TRUE;
} else {
if (CompareMem (Resource->PciCfg.PciDevicePath, Record->PciCfg.PciDevicePath, sizeof (STM_PCI_DEVICE_PATH_NODE) * (Resource->PciCfg.LastNodeIndex + 1)) != 0) {
return FALSE;
}
}
break;
case MACHINE_SPECIFIC_REG:
//
// Special case - merge MSR masks in place.
//
if (Resource->Msr.MsrIndex != Record->Msr.MsrIndex) {
ResourceLo = (UINT64)Resource->PciCfg.Base;
ResourceHi = (UINT64)Resource->PciCfg.Base + (UINT64)Resource->PciCfg.Length;
RecordLo = (UINT64)Record->PciCfg.Base;
RecordHi = (UINT64)Record->PciCfg.Base + (UINT64)Record->PciCfg.Length;
if (Resource->PciCfg.RWAttributes != Record->PciCfg.RWAttributes) {
if ((ResourceLo == RecordLo) && (ResourceHi == RecordHi)) {
Record->PciCfg.RWAttributes = Resource->PciCfg.RWAttributes | Record->PciCfg.RWAttributes;
return TRUE;
} else {
return FALSE;
}
}
break;
case MACHINE_SPECIFIC_REG:
//
// Special case - merge MSR masks in place.
//
if (Resource->Msr.MsrIndex != Record->Msr.MsrIndex) {
return FALSE;
}
Record->Msr.ReadMask |= Resource->Msr.ReadMask;
Record->Msr.WriteMask |= Resource->Msr.WriteMask;
return TRUE;
default:
return FALSE;
}
Record->Msr.ReadMask |= Resource->Msr.ReadMask;
Record->Msr.WriteMask |= Resource->Msr.WriteMask;
return TRUE;
default:
return FALSE;
}
//
// If resources are disjoint
//
@@ -557,6 +563,7 @@ HandleSingleResource (
if ((ResourceLo >= RecordLo) && (ResourceHi <= RecordHi)) {
return TRUE;
}
//
// Resources are overlapping.
// Resource and record are merged.
@@ -565,22 +572,22 @@ HandleSingleResource (
ResourceHi = (ResourceHi > RecordHi) ? ResourceHi : RecordHi;
switch (Resource->Header.RscType) {
case MEM_RANGE:
case MMIO_RANGE:
Record->Mem.Base = ResourceLo;
Record->Mem.Length = ResourceHi - ResourceLo;
break;
case IO_RANGE:
case TRAPPED_IO_RANGE:
Record->Io.Base = (UINT16) ResourceLo;
Record->Io.Length = (UINT16) (ResourceHi - ResourceLo);
break;
case PCI_CFG_RANGE:
Record->PciCfg.Base = (UINT16) ResourceLo;
Record->PciCfg.Length = (UINT16) (ResourceHi - ResourceLo);
break;
default:
return FALSE;
case MEM_RANGE:
case MMIO_RANGE:
Record->Mem.Base = ResourceLo;
Record->Mem.Length = ResourceHi - ResourceLo;
break;
case IO_RANGE:
case TRAPPED_IO_RANGE:
Record->Io.Base = (UINT16)ResourceLo;
Record->Io.Length = (UINT16)(ResourceHi - ResourceLo);
break;
case PCI_CFG_RANGE:
Record->PciCfg.Base = (UINT16)ResourceLo;
Record->PciCfg.Length = (UINT16)(ResourceHi - ResourceLo);
break;
default:
return FALSE;
}
return TRUE;
@@ -595,10 +602,10 @@ HandleSingleResource (
**/
VOID
AddSingleResource (
IN STM_RSC *Resource
IN STM_RSC *Resource
)
{
STM_RSC *Record;
STM_RSC *Record;
Record = (STM_RSC *)mStmResourcesPtr;
@@ -606,6 +613,7 @@ AddSingleResource (
if (Record->Header.RscType == END_OF_RESOURCES) {
break;
}
//
// Go to next record if resource and record types don't match.
//
@@ -613,12 +621,14 @@ AddSingleResource (
Record = (STM_RSC *)((UINTN)Record + Record->Header.Length);
continue;
}
//
// Record is handled inside of procedure - don't adjust.
//
if (HandleSingleResource (Resource, Record)) {
return ;
return;
}
Record = (STM_RSC *)((UINTN)Record + Record->Header.Length);
}
@@ -626,19 +636,19 @@ AddSingleResource (
// Add resource to the end of area.
//
CopyMem (
mStmResourcesPtr + mStmResourceSizeUsed - sizeof(mRscEndNode),
mStmResourcesPtr + mStmResourceSizeUsed - sizeof (mRscEndNode),
Resource,
Resource->Header.Length
);
CopyMem (
mStmResourcesPtr + mStmResourceSizeUsed - sizeof(mRscEndNode) + Resource->Header.Length,
mStmResourcesPtr + mStmResourceSizeUsed - sizeof (mRscEndNode) + Resource->Header.Length,
&mRscEndNode,
sizeof(mRscEndNode)
sizeof (mRscEndNode)
);
mStmResourceSizeUsed += Resource->Header.Length;
mStmResourceSizeUsed += Resource->Header.Length;
mStmResourceSizeAvailable = mStmResourceTotalSize - mStmResourceSizeUsed;
return ;
return;
}
/**
@@ -652,13 +662,13 @@ AddSingleResource (
**/
VOID
AddResource (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
)
{
UINT32 Count;
UINTN Index;
STM_RSC *Resource;
UINT32 Count;
UINTN Index;
STM_RSC *Resource;
if (NumEntries == 0) {
Count = 0xFFFFFFFF;
@@ -670,12 +680,14 @@ AddResource (
for (Index = 0; Index < Count; Index++) {
if (Resource->Header.RscType == END_OF_RESOURCES) {
return ;
return;
}
AddSingleResource (Resource);
Resource = (STM_RSC *)((UINTN)Resource + Resource->Header.Length);
}
return ;
return;
}
/**
@@ -692,14 +704,14 @@ AddResource (
**/
BOOLEAN
ValidateResource (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
)
{
UINT32 Count;
UINTN Index;
STM_RSC *Resource;
UINTN SubIndex;
UINT32 Count;
UINTN Index;
STM_RSC *Resource;
UINTN SubIndex;
//
// If NumEntries == 0 make it very big. Scan will be terminated by
@@ -724,21 +736,23 @@ ValidateResource (
switch (Resource->Header.RscType) {
case END_OF_RESOURCES:
if (Resource->Header.Length != sizeof (STM_RSC_END)) {
return FALSE;
return FALSE;
}
//
// If we are passed actual number of resources to add,
// END_OF_RESOURCES structure between them is considered an
// error. If NumEntries == 0 END_OF_RESOURCES is a termination.
//
if (NumEntries != 0) {
return FALSE;
return FALSE;
} else {
//
// If NumEntries == 0 and list reached end - return success.
//
return TRUE;
}
break;
case MEM_RANGE:
@@ -750,6 +764,7 @@ ValidateResource (
if (Resource->Mem.RWXAttributes > FULL_ACCS) {
return FALSE;
}
break;
case IO_RANGE:
@@ -761,35 +776,42 @@ ValidateResource (
if ((Resource->Io.Base + Resource->Io.Length) > 0xFFFF) {
return FALSE;
}
break;
case PCI_CFG_RANGE:
DEBUG ((DEBUG_INFO, "ValidateResource - PCI (0x%02x, 0x%08x, 0x%02x, 0x%02x)\n", Resource->PciCfg.OriginatingBusNumber, Resource->PciCfg.LastNodeIndex, Resource->PciCfg.PciDevicePath[0].PciDevice, Resource->PciCfg.PciDevicePath[0].PciFunction));
if (Resource->Header.Length != sizeof (STM_RSC_PCI_CFG_DESC) + (sizeof(STM_PCI_DEVICE_PATH_NODE) * Resource->PciCfg.LastNodeIndex)) {
if (Resource->Header.Length != sizeof (STM_RSC_PCI_CFG_DESC) + (sizeof (STM_PCI_DEVICE_PATH_NODE) * Resource->PciCfg.LastNodeIndex)) {
return FALSE;
}
for (SubIndex = 0; SubIndex <= Resource->PciCfg.LastNodeIndex; SubIndex++) {
if ((Resource->PciCfg.PciDevicePath[SubIndex].PciDevice > 0x1F) || (Resource->PciCfg.PciDevicePath[SubIndex].PciFunction > 7)) {
return FALSE;
}
}
if ((Resource->PciCfg.Base + Resource->PciCfg.Length) > 0x1000) {
return FALSE;
}
break;
case MACHINE_SPECIFIC_REG:
if (Resource->Header.Length != sizeof (STM_RSC_MSR_DESC)) {
return FALSE;
}
break;
default :
default:
DEBUG ((DEBUG_ERROR, "ValidateResource - Unknown RscType(%x)\n", Resource->Header.RscType));
return FALSE;
}
Resource = (STM_RSC *)((UINTN)Resource + Resource->Header.Length);
}
return TRUE;
}
@@ -808,13 +830,13 @@ ValidateResource (
**/
UINTN
GetResourceSize (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
)
{
UINT32 Count;
UINTN Index;
STM_RSC *Resource;
UINT32 Count;
UINTN Index;
STM_RSC *Resource;
Resource = ResourceList;
@@ -837,6 +859,7 @@ GetResourceSize (
if (Resource->Header.RscType == END_OF_RESOURCES) {
break;
}
Resource = (STM_RSC *)((UINTN)Resource + Resource->Header.Length);
}
@@ -859,8 +882,8 @@ GetResourceSize (
EFI_STATUS
EFIAPI
AddPiResource (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
)
{
EFI_STATUS Status;
@@ -884,7 +907,7 @@ AddPiResource (
//
// First time allocation
//
NewResourceSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (ResourceSize + sizeof(mRscEndNode)));
NewResourceSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (ResourceSize + sizeof (mRscEndNode)));
DEBUG ((DEBUG_INFO, "Allocate - 0x%08x\n", NewResourceSize));
Status = gSmst->SmmAllocatePages (
AllocateAnyPages,
@@ -899,11 +922,11 @@ AddPiResource (
//
// Copy EndResource for initialization
//
mStmResourcesPtr = (UINT8 *)(UINTN)NewResource;
mStmResourcesPtr = (UINT8 *)(UINTN)NewResource;
mStmResourceTotalSize = NewResourceSize;
CopyMem (mStmResourcesPtr, &mRscEndNode, sizeof(mRscEndNode));
mStmResourceSizeUsed = sizeof(mRscEndNode);
mStmResourceSizeAvailable = mStmResourceTotalSize - sizeof(mRscEndNode);
CopyMem (mStmResourcesPtr, &mRscEndNode, sizeof (mRscEndNode));
mStmResourceSizeUsed = sizeof (mRscEndNode);
mStmResourceSizeAvailable = mStmResourceTotalSize - sizeof (mRscEndNode);
//
// Let SmmCore change resource ptr
@@ -925,6 +948,7 @@ AddPiResource (
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem ((VOID *)(UINTN)NewResource, mStmResourcesPtr, mStmResourceSizeUsed);
mStmResourceSizeAvailable = NewResourceSize - mStmResourceSizeUsed;
@@ -934,7 +958,7 @@ AddPiResource (
);
mStmResourceTotalSize = NewResourceSize;
mStmResourcesPtr = (UINT8 *)(UINTN)NewResource;
mStmResourcesPtr = (UINT8 *)(UINTN)NewResource;
//
// Let SmmCore change resource ptr
@@ -966,8 +990,8 @@ AddPiResource (
EFI_STATUS
EFIAPI
DeletePiResource (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
)
{
if (ResourceList != NULL) {
@@ -975,12 +999,13 @@ DeletePiResource (
ASSERT (FALSE);
return EFI_UNSUPPORTED;
}
//
// Delete all
//
CopyMem (mStmResourcesPtr, &mRscEndNode, sizeof(mRscEndNode));
mStmResourceSizeUsed = sizeof(mRscEndNode);
mStmResourceSizeAvailable = mStmResourceTotalSize - sizeof(mRscEndNode);
CopyMem (mStmResourcesPtr, &mRscEndNode, sizeof (mRscEndNode));
mStmResourceSizeUsed = sizeof (mRscEndNode);
mStmResourceSizeAvailable = mStmResourceTotalSize - sizeof (mRscEndNode);
return EFI_SUCCESS;
}
@@ -1000,8 +1025,8 @@ DeletePiResource (
EFI_STATUS
EFIAPI
GetPiResource (
OUT STM_RSC *ResourceList,
IN OUT UINT32 *ResourceSize
OUT STM_RSC *ResourceList,
IN OUT UINT32 *ResourceSize
)
{
if (*ResourceSize < mStmResourceSizeUsed) {
@@ -1029,7 +1054,7 @@ EnableMsegMsr (
{
MSR_IA32_SMM_MONITOR_CTL_REGISTER SmmMonitorCtl;
SmmMonitorCtl.Uint64 = AsmReadMsr64 (MSR_IA32_SMM_MONITOR_CTL);
SmmMonitorCtl.Uint64 = AsmReadMsr64 (MSR_IA32_SMM_MONITOR_CTL);
SmmMonitorCtl.Bits.Valid = 1;
AsmWriteMsr64 (MSR_IA32_SMM_MONITOR_CTL, SmmMonitorCtl.Uint64);
}
@@ -1067,18 +1092,18 @@ GetVmcsSize (
**/
BOOLEAN
StmCheckStmImage (
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
)
{
UINTN MinMsegSize;
STM_HEADER *StmHeader;
IA32_VMX_MISC_REGISTER VmxMiscMsr;
UINTN MinMsegSize;
STM_HEADER *StmHeader;
IA32_VMX_MISC_REGISTER VmxMiscMsr;
//
// Check to see if STM image is compatible with CPU
//
StmHeader = (STM_HEADER *)(UINTN)StmImage;
StmHeader = (STM_HEADER *)(UINTN)StmImage;
VmxMiscMsr.Uint64 = AsmReadMsr64 (MSR_IA32_VMX_MISC);
if (StmHeader->HwStmHdr.MsegHeaderRevision != VmxMiscMsr.Bits.MsegRevisionIdentifier) {
DEBUG ((DEBUG_ERROR, "STM Image not compatible with CPU\n"));
@@ -1101,8 +1126,8 @@ StmCheckStmImage (
//
// We will create page table, just in case that SINIT does not create it.
//
if (MinMsegSize < StmHeader->HwStmHdr.Cr3Offset + EFI_PAGES_TO_SIZE(6)) {
MinMsegSize = StmHeader->HwStmHdr.Cr3Offset + EFI_PAGES_TO_SIZE(6);
if (MinMsegSize < StmHeader->HwStmHdr.Cr3Offset + EFI_PAGES_TO_SIZE (6)) {
MinMsegSize = StmHeader->HwStmHdr.Cr3Offset + EFI_PAGES_TO_SIZE (6);
}
}
@@ -1133,8 +1158,8 @@ StmCheckStmImage (
**/
VOID
StmLoadStmImage (
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
)
{
MSR_IA32_SMM_MONITOR_CTL_REGISTER SmmMonitorCtl;
@@ -1145,7 +1170,7 @@ StmLoadStmImage (
// Get MSEG base address from MSR_IA32_SMM_MONITOR_CTL
//
SmmMonitorCtl.Uint64 = AsmReadMsr64 (MSR_IA32_SMM_MONITOR_CTL);
MsegBase = SmmMonitorCtl.Bits.MsegBase << 12;
MsegBase = SmmMonitorCtl.Bits.MsegBase << 12;
//
// Zero all of MSEG base address
@@ -1181,8 +1206,8 @@ StmLoadStmImage (
EFI_STATUS
EFIAPI
LoadMonitor (
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
)
{
MSR_IA32_SMM_MONITOR_CTL_REGISTER SmmMonitorCtl;
@@ -1201,7 +1226,7 @@ LoadMonitor (
}
// Record STM_HASH to PCR 0, just in case it is NOT TXT launch, we still need provide the evidence.
TpmMeasureAndLogData(
TpmMeasureAndLogData (
0, // PcrIndex
TXT_EVTYPE_STM_HASH, // EventType
NULL, // EventLog
@@ -1226,7 +1251,7 @@ LoadMonitor (
**/
VOID *
GetStmResource(
GetStmResource (
VOID
)
{
@@ -1241,19 +1266,19 @@ GetStmResource(
**/
VOID
NotifyStmResourceChange (
VOID *StmResource
VOID *StmResource
)
{
UINTN Index;
TXT_PROCESSOR_SMM_DESCRIPTOR *Psd;
for (Index = 0; Index < gSmst->NumberOfCpus; Index++) {
Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)((UINTN)gSmst->CpuSaveState[Index] - SMRAM_SAVE_STATE_MAP_OFFSET + TXT_SMM_PSD_OFFSET);
Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)((UINTN)gSmst->CpuSaveState[Index] - SMRAM_SAVE_STATE_MAP_OFFSET + TXT_SMM_PSD_OFFSET);
Psd->BiosHwResourceRequirementsPtr = (UINT64)(UINTN)StmResource;
}
return ;
}
return;
}
/**
This is STM setup BIOS callback.
@@ -1278,4 +1303,3 @@ SmmStmTeardown (
{
mStmState &= ~EFI_SM_MONITOR_STATE_ACTIVATED;
}

View File

@@ -21,7 +21,7 @@
**/
VOID
StmGen4GPageTable (
IN UINTN PageTableBase
IN UINTN PageTableBase
);
/**
@@ -42,10 +42,9 @@ StmGen4GPageTable (
UINT32
EFIAPI
SmmStmExceptionHandler (
IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context
IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context
);
/**
Get STM state.
@@ -73,8 +72,8 @@ GetMonitorState (
EFI_STATUS
EFIAPI
LoadMonitor (
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
IN EFI_PHYSICAL_ADDRESS StmImage,
IN UINTN StmImageSize
);
/**
@@ -94,7 +93,7 @@ EFI_STATUS
EFIAPI
AddPiResource (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN UINT32 NumEntries OPTIONAL
);
/**
@@ -113,8 +112,8 @@ AddPiResource (
EFI_STATUS
EFIAPI
DeletePiResource (
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
IN STM_RSC *ResourceList,
IN UINT32 NumEntries OPTIONAL
);
/**
@@ -133,8 +132,8 @@ DeletePiResource (
EFI_STATUS
EFIAPI
GetPiResource (
OUT STM_RSC *ResourceList,
IN OUT UINT32 *ResourceSize
OUT STM_RSC *ResourceList,
IN OUT UINT32 *ResourceSize
);
/**
@@ -153,7 +152,7 @@ StmSmmConfigurationTableInit (
**/
VOID
NotifyStmResourceChange (
IN VOID *StmResource
IN VOID *StmResource
);
/**
@@ -174,6 +173,6 @@ GetStmResource (
VOID
EFIAPI
SmmCpuFeaturesLibStmSmiEntryFixupAddress (
);
);
#endif

View File

@@ -14,9 +14,9 @@
///
/// Page Table Entry
///
#define IA32_PG_P BIT0
#define IA32_PG_RW BIT1
#define IA32_PG_PS BIT7
#define IA32_PG_P BIT0
#define IA32_PG_RW BIT1
#define IA32_PG_PS BIT7
/**
@@ -28,22 +28,22 @@
**/
VOID
StmGen4GPageTable (
IN UINTN PageTableBase
IN UINTN PageTableBase
)
{
UINTN Index;
UINTN SubIndex;
UINT64 *Pde;
UINT64 *Pte;
UINT64 *Pml4;
UINTN Index;
UINTN SubIndex;
UINT64 *Pde;
UINT64 *Pte;
UINT64 *Pml4;
Pml4 = (UINT64*)(UINTN)PageTableBase;
Pml4 = (UINT64 *)(UINTN)PageTableBase;
PageTableBase += SIZE_4KB;
*Pml4 = PageTableBase | IA32_PG_RW | IA32_PG_P;
*Pml4 = PageTableBase | IA32_PG_RW | IA32_PG_P;
Pde = (UINT64*)(UINTN)PageTableBase;
Pde = (UINT64 *)(UINTN)PageTableBase;
PageTableBase += SIZE_4KB;
Pte = (UINT64 *)(UINTN)PageTableBase;
Pte = (UINT64 *)(UINTN)PageTableBase;
for (Index = 0; Index < 4; Index++) {
*Pde = PageTableBase | IA32_PG_RW | IA32_PG_P;
@@ -75,7 +75,7 @@ StmGen4GPageTable (
UINT32
EFIAPI
SmmStmExceptionHandler (
IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context
IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context
)
{
// TBD - SmmStmExceptionHandler, record information

View File

@@ -69,7 +69,7 @@ ClearTopLevelSmiStatus (
EFI_STATUS
EFIAPI
PlatformSmmBspElection (
OUT BOOLEAN *IsBsp
OUT BOOLEAN *IsBsp
)
{
return EFI_NOT_READY;
@@ -92,10 +92,10 @@ PlatformSmmBspElection (
EFI_STATUS
EFIAPI
GetPlatformPageTableAttribute (
IN UINT64 Address,
IN OUT SMM_PAGE_SIZE_TYPE *PageSize,
IN OUT UINTN *NumOfPages,
IN OUT UINTN *PageAttribute
IN UINT64 Address,
IN OUT SMM_PAGE_SIZE_TYPE *PageSize,
IN OUT UINTN *NumOfPages,
IN OUT UINTN *PageAttribute
)
{
return EFI_UNSUPPORTED;

View File

@@ -35,15 +35,15 @@
UINT64
EFIAPI
VmgExit (
IN OUT GHCB *Ghcb,
IN UINT64 ExitCode,
IN UINT64 ExitInfo1,
IN UINT64 ExitInfo2
IN OUT GHCB *Ghcb,
IN UINT64 ExitCode,
IN UINT64 ExitInfo1,
IN UINT64 ExitInfo2
)
{
GHCB_EVENT_INJECTION Event;
Event.Uint64 = 0;
Event.Uint64 = 0;
Event.Elements.Vector = GP_EXCEPTION;
Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
Event.Elements.Valid = 1;
@@ -65,8 +65,8 @@ VmgExit (
VOID
EFIAPI
VmgInit (
IN OUT GHCB *Ghcb,
IN OUT BOOLEAN *InterruptState
IN OUT GHCB *Ghcb,
IN OUT BOOLEAN *InterruptState
)
{
}
@@ -85,8 +85,8 @@ VmgInit (
VOID
EFIAPI
VmgDone (
IN OUT GHCB *Ghcb,
IN BOOLEAN InterruptState
IN OUT GHCB *Ghcb,
IN BOOLEAN InterruptState
)
{
}
@@ -104,8 +104,8 @@ VmgDone (
VOID
EFIAPI
VmgSetOffsetValid (
IN OUT GHCB *Ghcb,
IN GHCB_REGISTER Offset
IN OUT GHCB *Ghcb,
IN GHCB_REGISTER Offset
)
{
}
@@ -126,8 +126,8 @@ VmgSetOffsetValid (
BOOLEAN
EFIAPI
VmgIsOffsetValid (
IN GHCB *Ghcb,
IN GHCB_REGISTER Offset
IN GHCB *Ghcb,
IN GHCB_REGISTER Offset
)
{
return FALSE;