55 case MSR_IA32_X2APIC_ISR1:
56 case MSR_IA32_X2APIC_ISR2:
57 case MSR_IA32_X2APIC_ISR3:
58 case MSR_IA32_X2APIC_ISR4:
59 case MSR_IA32_X2APIC_ISR5:
60 case MSR_IA32_X2APIC_ISR6:
61 case MSR_IA32_X2APIC_ISR7:
63 case MSR_IA32_X2APIC_TMR1:
64 case MSR_IA32_X2APIC_TMR2:
65 case MSR_IA32_X2APIC_TMR3:
66 case MSR_IA32_X2APIC_TMR4:
67 case MSR_IA32_X2APIC_TMR5:
68 case MSR_IA32_X2APIC_TMR6:
69 case MSR_IA32_X2APIC_TMR7:
71 case MSR_IA32_X2APIC_IRR1:
72 case MSR_IA32_X2APIC_IRR2:
73 case MSR_IA32_X2APIC_IRR3:
74 case MSR_IA32_X2APIC_IRR4:
75 case MSR_IA32_X2APIC_IRR5:
76 case MSR_IA32_X2APIC_IRR6:
77 case MSR_IA32_X2APIC_IRR7:
102 Status =
TdVmCall (TDVMCALL_RDMSR, (UINT64)MsrIndex, 0, 0, 0, &Val);
104 TdVmCall (TDVMCALL_HALT, 0, 0, 0, 0, 0);
131 Status =
TdVmCall (TDVMCALL_WRMSR, (UINT64)MsrIndex, Value, 0, 0, 0);
133 TdVmCall (TDVMCALL_HALT, 0, 0, 0, 0, 0);
192 if ((FamilyId == 0x04) || (FamilyId == 0x05)) {
222 return PcdGet32 (PcdCpuLocalApicBaseAddress);
247 ASSERT ((BaseAddress & (SIZE_4KB - 1)) == 0);
258 ApicBaseMsr.
Bits.
ApicBase = (UINT32)(BaseAddress >> 12);
285 ASSERT ((MmioOffset & 0xf) == 0);
293 ASSERT (MmioOffset != XAPIC_ICR_DFR_OFFSET);
298 ASSERT (MmioOffset != XAPIC_ICR_HIGH_OFFSET);
300 MsrIndex = (UINT32)(MmioOffset >> 4) + X2APIC_MSR_BASE_ADDRESS;
328 ASSERT ((MmioOffset & 0xf) == 0);
336 ASSERT (MmioOffset != XAPIC_ICR_DFR_OFFSET);
341 ASSERT (MmioOffset != XAPIC_ICR_HIGH_OFFSET);
342 ASSERT (MmioOffset != XAPIC_ICR_LOW_OFFSET);
344 MsrIndex = (UINT32)(MmioOffset >> 4) + X2APIC_MSR_BASE_ADDRESS;
370 UINTN LocalApciBaseAddress;
372 BOOLEAN InterruptState;
378 ASSERT (ApicId <= 0xff);
390 IcrHigh =
MmioRead32 (LocalApciBaseAddress + XAPIC_ICR_HIGH_OFFSET);
397 IcrLowReg.Uint32 =
MmioRead32 (LocalApciBaseAddress + XAPIC_ICR_LOW_OFFSET);
403 MmioWrite32 (LocalApciBaseAddress + XAPIC_ICR_HIGH_OFFSET, ApicId << 24);
404 MmioWrite32 (LocalApciBaseAddress + XAPIC_ICR_LOW_OFFSET, IcrLow);
410 IcrLowReg.Uint32 =
MmioRead32 (LocalApciBaseAddress + XAPIC_ICR_LOW_OFFSET);
416 MmioWrite32 (LocalApciBaseAddress + XAPIC_ICR_HIGH_OFFSET, IcrHigh);
424 MsrValue =
LShiftU64 ((UINT64)ApicId, 32) | IcrLow;
460 ASSERT (ApicBaseMsr.
Bits.
EN != 0);
546 UINT32 MaxCpuIdIndex;
562 if ((RegEbx & (BIT16 - 1)) != 0) {
590 ApicId = ((InitApicId =
GetInitialApicId ()) < 0x100) ? (ApicId >> 24) : InitApicId;
628 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
629 IcrLow.Bits.
Level = 1;
630 IcrLow.Bits.
Vector = Vector;
631 SendIpi (IcrLow.Uint32, ApicId);
650 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_FIXED;
651 IcrLow.Bits.
Level = 1;
653 IcrLow.Bits.
Vector = Vector;
673 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
674 IcrLow.Bits.
Level = 1;
675 SendIpi (IcrLow.Uint32, ApicId);
692 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_SMI;
693 IcrLow.Bits.
Level = 1;
714 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
715 IcrLow.Bits.
Level = 1;
716 SendIpi (IcrLow.Uint32, ApicId);
733 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_INIT;
734 IcrLow.Bits.
Level = 1;
750 IN UINT32 StartupRoutine
755 ASSERT (StartupRoutine < 0x100000);
756 ASSERT ((StartupRoutine & 0xfff) == 0);
759 IcrLow.Bits.
Vector = (StartupRoutine >> 12);
760 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
761 IcrLow.Bits.
Level = 1;
782 IN UINT32 StartupRoutine
787 ASSERT (StartupRoutine < 0x100000);
788 ASSERT ((StartupRoutine & 0xfff) == 0);
793 IcrLow.Bits.
Vector = (StartupRoutine >> 12);
794 IcrLow.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
795 IcrLow.Bits.
Level = 1;
796 SendIpi (IcrLow.Uint32, ApicId);
799 SendIpi (IcrLow.Uint32, ApicId);
817 IN UINT32 StartupRoutine
891 Lint.Bits.
DeliveryMode = LOCAL_APIC_DELIVERY_MODE_EXTINT;
922 LvtLint.Bits.
Mask = 1;
926 LvtLint.Bits.
Mask = 1;
974 IN BOOLEAN PeriodicMode,
987 if (DivideValue != 0) {
988 ASSERT (DivideValue <= 128);
990 Divisor = (UINT32)((
HighBitSet32 ((UINT32)DivideValue) - 1) & 0x7);
1008 LvtTimer.Bits.
Mask = 0;
1009 LvtTimer.Bits.
Vector = Vector;
1031 OUT BOOLEAN *PeriodicMode OPTIONAL,
1032 OUT UINT8 *Vector OPTIONAL
1046 if (DivideValue !=
NULL) {
1049 Divisor = (Divisor + 1) & 0x7;
1050 *DivideValue = ((
UINTN)1) << Divisor;
1053 if ((PeriodicMode !=
NULL) || (Vector !=
NULL)) {
1055 if (PeriodicMode !=
NULL) {
1057 *PeriodicMode =
TRUE;
1059 *PeriodicMode =
FALSE;
1063 if (Vector !=
NULL) {
1064 *Vector = (UINT8)LvtTimer.Bits.
Vector;
1081 LvtTimer.Bits.
Mask = 0;
1097 LvtTimer.Bits.
Mask = 1;
1116 return (BOOLEAN)(LvtTimer.Bits.
Mask == 0);
1149 MsiAddress.Uint32 = 0;
1152 return MsiAddress.Uint32;
1188 IN BOOLEAN LevelTriggered,
1189 IN BOOLEAN AssertionLevel
1194 ASSERT (Vector >= 0x10 && Vector <= 0xFE);
1195 ASSERT (DeliveryMode < 8 && DeliveryMode != 6 && DeliveryMode != 3);
1198 MsiData.Bits.
Vector = Vector;
1200 if (LevelTriggered) {
1202 if (AssertionLevel) {
1203 MsiData.Bits.
Level = 1;
1207 return MsiData.Uint64;
1225 IN UINT32 InitialApicId,
1226 OUT UINT32 *Package OPTIONAL,
1227 OUT UINT32 *Core OPTIONAL,
1228 OUT UINT32 *Thread OPTIONAL
1231 BOOLEAN TopologyLeafSupported;
1241 UINT32 MaxStandardCpuIdIndex;
1242 UINT32 MaxExtendedCpuIdIndex;
1245 UINT32 MaxLogicProcessorsPerPackage;
1246 UINT32 MaxCoresPerPackage;
1254 if (VersionInfoEdx.
Bits.
HTT == 0) {
1255 if (Thread !=
NULL) {
1263 if (Package !=
NULL) {
1286 TopologyLeafSupported =
FALSE;
1291 &ExtendedTopologyEax.
Uint32,
1292 &ExtendedTopologyEbx.
Uint32,
1293 &ExtendedTopologyEcx.
Uint32,
1303 TopologyLeafSupported =
TRUE;
1310 ASSERT (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT);
1322 &ExtendedTopologyEax.
Uint32,
1324 &ExtendedTopologyEcx.
Uint32,
1328 if (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE) {
1338 if (!TopologyLeafSupported) {
1348 MaxCoresPerPackage = 1;
1367 MaxCoresPerPackage = MaxLogicProcessorsPerPackage / (AmdProcessorTopologyEbx.
Bits.
ThreadsPerCore + 1);
1376 if (CacheParamsEax.
Uint32 != 0) {
1382 ThreadBits = (
UINTN)(
HighBitSet32 (MaxLogicProcessorsPerPackage / MaxCoresPerPackage - 1) + 1);
1386 if (Thread !=
NULL) {
1387 *Thread = InitialApicId & ((1 << ThreadBits) - 1);
1391 *Core = (InitialApicId >> ThreadBits) & ((1 << CoreBits) - 1);
1394 if (Package !=
NULL) {
1395 *Package = (InitialApicId >> (ThreadBits + CoreBits));
1417 IN UINT32 InitialApicId,
1418 OUT UINT32 *Package OPTIONAL,
1419 OUT UINT32 *Die OPTIONAL,
1420 OUT UINT32 *Tile OPTIONAL,
1421 OUT UINT32 *Module OPTIONAL,
1422 OUT UINT32 *Core OPTIONAL,
1423 OUT UINT32 *Thread OPTIONAL
1429 UINT32 MaxExtendedCpuIdIndex;
1430 UINT32 TopologyLevel;
1431 UINT32 PreviousLevel;
1442 if (Module !=
NULL) {
1456 &ExtendedTopologyEax.
Uint32,
1457 &ExtendedTopologyEbx.
Uint32,
1458 &ExtendedTopologyEcx.
Uint32,
1468 Data = InitialApicId >> PreviousLevel;
1469 Data &= (1 << (ExtendedTopologyEax.
Bits.
ApicIdShift - PreviousLevel)) - 1;
1472 case CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT:
1473 if (Thread !=
NULL) {
1478 case CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE:
1485 if (Module !=
NULL) {
1490 case CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE:
1504 if (Package !=
NULL) {
1505 *Package = InitialApicId >> PreviousLevel;
1511 if (TopologyLevel == 0) {
1537 IN UINT32 InitialApicId,
1538 OUT UINT32 *Package OPTIONAL,
1539 OUT UINT32 *Die OPTIONAL,
1540 OUT UINT32 *Tile OPTIONAL,
1541 OUT UINT32 *Module OPTIONAL,
1542 OUT UINT32 *Core OPTIONAL,
1543 OUT UINT32 *Thread OPTIONAL
1549 UINT32 MaxStandardCpuIdIndex;
1552 UINT32 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
1553 UINT32 *Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 2];
1560 for (LevelType = 0; LevelType <
ARRAY_SIZE (Bits); LevelType++) {
1561 Bits[LevelType] = 0;
1586 if (Module !=
NULL) {
1598 for (Index = 0; ; Index++) {
1602 &ExtendedTopologyEax.
Uint32,
1604 &ExtendedTopologyEcx.
Uint32,
1613 ASSERT ((Index != 0) || (LevelType == CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT));
1622 for (LevelType = CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE; LevelType <
ARRAY_SIZE (Bits); LevelType++) {
1627 if (Bits[LevelType] == 0) {
1628 Bits[LevelType] = Bits[LevelType - 1];
1632 Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1] = Package;
1633 Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE] = Die;
1634 Location[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_TILE] = Tile;
1636 Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE] = Core;
1637 Location[CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT] = Thread;
1639 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1] = 32;
1641 for ( LevelType = CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT
1642 ; LevelType <= CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_DIE + 1
1646 if (Location[LevelType] !=
NULL) {
1651 *Location[LevelType] = InitialApicId >> Bits[LevelType - 1];
1656 *Location[LevelType] &= (1 << (Bits[LevelType] - Bits[LevelType - 1])) - 1;
UINTN EFIAPI MicroSecondDelay(IN UINTN MicroSeconds)
BOOLEAN EFIAPI SetInterruptState(IN BOOLEAN InterruptState)
BOOLEAN EFIAPI SaveAndDisableInterrupts(VOID)
UINT32 EFIAPI GetPowerOfTwo32(IN UINT32 Operand)
VOID EFIAPI MemoryFence(VOID)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
INTN EFIAPI HighBitSet32(IN UINT32 Operand)
UINTN EFIAPI TdVmCall(IN UINT64 Leaf, IN UINT64 Arg1, IN UINT64 Arg2, IN UINT64 Arg3, IN UINT64 Arg4, IN OUT VOID *Results)
UINT32 EFIAPI BitFieldRead32(IN UINT32 Operand, IN UINTN StartBit, IN UINTN EndBit)
VOID EFIAPI SendInitSipiSipiAllExcludingSelf(IN UINT32 StartupRoutine)
VOID EFIAPI SendFixedIpiAllExcludingSelf(IN UINT8 Vector)
VOID EFIAPI InitializeLocalApicSoftwareEnable(IN BOOLEAN Enable)
UINT32 EFIAPI ReadLocalApicReg(IN UINTN MmioOffset)
VOID EFIAPI SendSmiIpi(IN UINT32 ApicId)
UINT32 EFIAPI GetApicVersion(VOID)
BOOLEAN EFIAPI GetApicTimerInterruptState(VOID)
VOID EFIAPI SetLocalApicBaseAddress(IN UINTN BaseAddress)
UINT32 EFIAPI GetApicId(VOID)
VOID EFIAPI DisableLvtInterrupts(VOID)
VOID EFIAPI GetApicTimerState(OUT UINTN *DivideValue OPTIONAL, OUT BOOLEAN *PeriodicMode OPTIONAL, OUT UINT8 *Vector OPTIONAL)
VOID EFIAPI SendInitIpi(IN UINT32 ApicId)
UINT32 EFIAPI GetInitialApicId(VOID)
VOID EFIAPI SendInitIpiAllExcludingSelf(VOID)
UINT64 LocalApicReadMsrReg64(IN UINT32 MsrIndex)
BOOLEAN LocalApicBaseAddressMsrSupported(VOID)
VOID EFIAPI SendSmiIpiAllExcludingSelf(VOID)
UINTN EFIAPI GetApicMode(VOID)
VOID EFIAPI ProgramVirtualWireMode(VOID)
BOOLEAN AccessMsrTdxCall(IN UINT32 MsrIndex)
VOID EFIAPI EnableApicTimerInterrupt(VOID)
UINT32 EFIAPI GetApicMsiAddress(VOID)
VOID AmdGetProcessorLocation2ByApicId(IN UINT32 InitialApicId, OUT UINT32 *Package OPTIONAL, OUT UINT32 *Die OPTIONAL, OUT UINT32 *Tile OPTIONAL, OUT UINT32 *Module OPTIONAL, OUT UINT32 *Core OPTIONAL, OUT UINT32 *Thread OPTIONAL)
VOID SendIpi(IN UINT32 IcrLow, IN UINT32 ApicId)
VOID EFIAPI SendStartupIpiAllExcludingSelf(IN UINT32 StartupRoutine)
VOID EFIAPI SendFixedIpi(IN UINT32 ApicId, IN UINT8 Vector)
VOID EFIAPI WriteLocalApicReg(IN UINTN MmioOffset, IN UINT32 Value)
VOID EFIAPI SetApicMode(IN UINTN ApicMode)
UINT32 EFIAPI GetApicTimerInitCount(VOID)
UINTN EFIAPI GetLocalApicBaseAddress(VOID)
UINT64 EFIAPI GetApicMsiValue(IN UINT8 Vector, IN UINTN DeliveryMode, IN BOOLEAN LevelTriggered, IN BOOLEAN AssertionLevel)
VOID EFIAPI GetProcessorLocation2ByApicId(IN UINT32 InitialApicId, OUT UINT32 *Package OPTIONAL, OUT UINT32 *Die OPTIONAL, OUT UINT32 *Tile OPTIONAL, OUT UINT32 *Module OPTIONAL, OUT UINT32 *Core OPTIONAL, OUT UINT32 *Thread OPTIONAL)
VOID EFIAPI GetProcessorLocationByApicId(IN UINT32 InitialApicId, OUT UINT32 *Package OPTIONAL, OUT UINT32 *Core OPTIONAL, OUT UINT32 *Thread OPTIONAL)
VOID EFIAPI InitializeApicTimer(IN UINTN DivideValue, IN UINT32 InitCount, IN BOOLEAN PeriodicMode, IN UINT8 Vector)
VOID EFIAPI SendApicEoi(VOID)
UINT32 LocalApicReadMsrReg32(IN UINT32 MsrIndex)
UINT32 EFIAPI GetApicTimerCurrentCount(VOID)
VOID EFIAPI SendInitSipiSipi(IN UINT32 ApicId, IN UINT32 StartupRoutine)
VOID EFIAPI DisableApicTimerInterrupt(VOID)
UINT32 LocalApicWriteMsrReg32(IN UINT32 MsrIndex, IN UINT32 Value)
UINT64 LocalApicWriteMsrReg64(IN UINT32 MsrIndex, IN UINT64 Value)
UINT32 EFIAPI AsmCpuidEx(IN UINT32 Index, IN UINT32 SubIndex, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define LOCAL_APIC_MODE_X2APIC
x2APIC mode.
#define LOCAL_APIC_MODE_XAPIC
xAPIC mode.
#define ARRAY_SIZE(Array)
#define AMD_CPUID_EXTENDED_TOPOLOGY
#define CPUID_AMD_PROCESSOR_TOPOLOGY
#define MSR_IA32_X2APIC_ISR0
#define MSR_IA32_APIC_BASE
#define MSR_IA32_X2APIC_EOI
#define MSR_IA32_X2APIC_IRR0
#define MSR_IA32_X2APIC_TPR
#define MSR_IA32_X2APIC_TMR0
#define MSR_IA32_X2APIC_PPR
#define CPUID_CACHE_PARAMS
#define CPUID_VERSION_INFO
#define CPUID_EXTENDED_TOPOLOGY
#define CPUID_V2_EXTENDED_TOPOLOGY
#define CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYPE_MODULE
#define CPUID_EXTENDED_CPU_SIG
#define CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
BOOLEAN EFIAPI TdIsEnabled()
#define PcdGet32(TokenName)
BOOLEAN EFIAPI StandardSignatureIsAuthenticAMD(VOID)
struct CPUID_AMD_EXTENDED_CPU_SIG_ECX::@592 Bits
UINT32 TopologyExtensions
struct CPUID_AMD_PROCESSOR_TOPOLOGY_EBX::@598 Bits
struct CPUID_AMD_VIR_PHY_ADDRESS_SIZE_ECX::@596 Bits
struct CPUID_CACHE_PARAMS_EAX::@698 Bits
UINT32 MaximumAddressableIdsForLogicalProcessors
struct CPUID_EXTENDED_TOPOLOGY_EAX::@714 Bits
struct CPUID_EXTENDED_TOPOLOGY_EBX::@715 Bits
struct CPUID_EXTENDED_TOPOLOGY_ECX::@716 Bits
struct CPUID_VERSION_INFO_EBX::@694 Bits
UINT32 MaximumAddressableIdsForLogicalProcessors
struct CPUID_VERSION_INFO_EDX::@696 Bits
UINT32 DivideValue1
Low 2 bits of the divide value.
UINT32 DivideValue2
Highest 1 bit of the divide value.
UINT32 Vector
The vector number of the interrupt being sent.
UINT32 DeliveryMode
Specifies the type of IPI to be sent.
UINT32 Level
0 for the INIT level de-assert delivery mode. Otherwise 1.
UINT32 DestinationShorthand
A shorthand notation to specify the destination of the interrupt.
UINT32 DeliveryStatus
Indicates the IPI delivery status. This field is reserved in x2APIC mode.
UINT32 TriggerMode
0:edge, 1:level.
UINT32 InputPinPolarity
Interrupt Input Pin Polarity.
UINT32 DeliveryMode
Specifies the type of interrupt to be sent.
UINT32 Mask
0: Not masked, 1: Masked.
UINT32 Vector
The vector number of the interrupt being sent.
UINT32 TimerMode
0: One-shot, 1: Periodic.
UINT32 Mask
0: Not masked, 1: Masked.
UINT32 BaseAddress
Must be 0FEEH.
UINT32 DestinationId
Specifies the Destination ID.
UINT32 DeliveryMode
Specifies the type of interrupt to be sent.
UINT32 Level
0:Deassert, 1:Assert. Ignored for Edge triggered interrupts.
UINT32 TriggerMode
0:Edge, 1:Level.
UINT32 Vector
Interrupt vector in range 010h..0FEH.
UINT32 SpuriousVector
Spurious Vector.
UINT32 SoftwareEnable
APIC Software Enable/Disable.
struct MSR_IA32_APIC_BASE_REGISTER::@627 Bits