20#define MAX_TOPA_ENTRY_COUNT 2
26 RtitOutputSchemeSingleRange = 0,
31 BOOLEAN TopaSupported;
32 BOOLEAN SingleRangeSupported;
36 BOOLEAN CycPacketSupported;
40 UINT32 NumberOfProcessors;
42 UINT8 ProcTraceOutputScheme;
43 UINT32 ProcTraceMemSize;
45 UINTN *ThreadMemRegionTable;
46 UINTN AllocatedThreads;
50 BOOLEAN EnableOnBspOnly;
51 BOOLEAN EnablePerformanceCollecting;
78 ASSERT (ConfigData !=
NULL);
81 ConfigData->NumberOfProcessors = (UINT32)NumberOfProcessors;
82 ConfigData->ProcTraceMemSize =
PcdGet32 (PcdCpuProcTraceMemSize);
83 ConfigData->ProcTraceOutputScheme =
PcdGet8 (PcdCpuProcTraceOutputScheme);
84 ConfigData->EnableOnBspOnly =
PcdGetBool (PcdCpuProcTraceBspOnly);
85 ConfigData->EnablePerformanceCollecting =
PcdGetBool (PcdCpuProcTracePerformanceCollecting);
112 IN VOID *ConfigData OPTIONAL
124 ASSERT (ProcTraceData !=
NULL);
125 if ((ProcTraceData->ProcTraceMemSize > RtitTopaMemorySize128M) ||
126 (ProcTraceData->ProcTraceOutputScheme > RtitOutputSchemeToPA))
135 if (Ebx.Bits.IntelProcessorTrace == 0) {
140 ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported = (BOOLEAN)(ProcTraceEcx.
Bits.
RTIT == 1);
141 ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported = (BOOLEAN)(ProcTraceEcx.
Bits.
SingleRangeOutput == 1);
142 if ((ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported && (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeToPA)) ||
143 (ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported && (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeSingleRange)))
148 ProcTraceData->ProcessorData[ProcessorNumber].CycPacketSupported = (BOOLEAN)(ProcTraceEbx.
Bits.
ConfigurablePsb == 1);
179 IN VOID *ConfigData OPTIONAL,
183 UINT32 MemRegionSize;
186 UINTN MemRegionBaseAddr;
187 UINTN *ThreadMemRegionTable;
189 UINTN TopaTableBaseAddr;
190 UINTN AlignedAddress;
209 if (CpuInfo->ProcessorInfo.Location.Thread != 0) {
215 ASSERT (ProcTraceData !=
NULL);
220 CtrlReg.
Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitCtrl.
Uint64;
251 if (ProcTraceData->EnableOnBspOnly && !IsBsp) {
255 MemRegionBaseAddr = 0;
258 if (ProcTraceData->ThreadMemRegionTable ==
NULL) {
260 DEBUG ((DEBUG_INFO,
"Initialize Processor Trace\n"));
266 MemRegionSize = (UINT32)(1 << (ProcTraceData->ProcTraceMemSize + 12));
268 DEBUG ((DEBUG_INFO,
"ProcTrace: MemSize requested: 0x%X \n", MemRegionSize));
281 Alignment = MemRegionSize;
282 if (ProcTraceData->EnableOnBspOnly) {
287 if (MemRegionBaseAddr == 0) {
291 DEBUG ((DEBUG_ERROR,
"ProcTrace: Out of mem, failed to allocate buffer for BSP\n"));
295 DEBUG ((DEBUG_INFO,
"ProcTrace: Allocated PT MemRegionBaseAddr(aligned) for BSP only: 0x%llX.\n", (UINT64)MemRegionBaseAddr));
298 if (ThreadMemRegionTable ==
NULL) {
299 DEBUG ((DEBUG_ERROR,
"Allocate ProcTrace ThreadMemRegionTable Failed\n"));
303 ProcTraceData->ThreadMemRegionTable = ThreadMemRegionTable;
305 for (Index = 0; Index < ProcTraceData->NumberOfProcessors; Index++, ProcTraceData->AllocatedThreads++) {
307 if (AlignedAddress == 0) {
308 DEBUG ((DEBUG_ERROR,
"ProcTrace: Out of mem, allocated only for %d threads\n", ProcTraceData->AllocatedThreads));
313 FreePool ((VOID *)ThreadMemRegionTable);
314 ThreadMemRegionTable =
NULL;
321 ThreadMemRegionTable[Index] = AlignedAddress;
322 DEBUG ((DEBUG_INFO,
"ProcTrace: PT MemRegionBaseAddr(aligned) for thread %d: 0x%llX \n", Index, (UINT64)ThreadMemRegionTable[Index]));
325 DEBUG ((DEBUG_INFO,
"ProcTrace: Allocated PT mem for %d thread \n", ProcTraceData->AllocatedThreads));
329 if (!ProcTraceData->EnableOnBspOnly) {
330 if (ProcessorNumber < ProcTraceData->AllocatedThreads) {
331 MemRegionBaseAddr = ProcTraceData->ThreadMemRegionTable[ProcessorNumber];
344 if (ProcTraceData->ProcessorData[ProcessorNumber].SingleRangeSupported &&
345 (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeSingleRange))
348 DEBUG ((DEBUG_INFO,
"ProcTrace: Enabling Single Range Output scheme \n"));
365 OutputBaseReg.
Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.
Uint64;
366 OutputBaseReg.
Bits.
Base = (MemRegionBaseAddr >> 7) & 0x01FFFFFF;
378 OutputMaskPtrsReg.
Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.
Uint64;
392 if (ProcTraceData->ProcessorData[ProcessorNumber].TopaSupported &&
393 (ProcTraceData->ProcTraceOutputScheme == RtitOutputSchemeToPA))
404 DEBUG ((DEBUG_INFO,
"ProcTrace: Enabling ToPA scheme \n"));
409 if (ProcTraceData->EnableOnBspOnly) {
414 if (TopaTableBaseAddr == 0) {
415 DEBUG ((DEBUG_ERROR,
"ProcTrace: Out of mem, failed to allocate ToPA mem for BSP"));
419 DEBUG ((DEBUG_INFO,
"ProcTrace: Topa table address(aligned) for BSP only: 0x%llX \n", (UINT64)TopaTableBaseAddr));
425 if (TopaMemArray ==
NULL) {
426 DEBUG ((DEBUG_ERROR,
"ProcTrace: Allocate mem for ToPA Failed\n"));
430 ProcTraceData->TopaMemArray = TopaMemArray;
432 for (Index = 0; Index < ProcTraceData->AllocatedThreads; Index++) {
434 if (AlignedAddress == 0) {
435 if (Index < ProcTraceData->AllocatedThreads) {
436 ProcTraceData->AllocatedThreads = Index;
439 DEBUG ((DEBUG_ERROR,
"ProcTrace: Out of mem, allocated ToPA mem only for %d threads\n", ProcTraceData->AllocatedThreads));
452 TopaMemArray[Index] = AlignedAddress;
453 DEBUG ((DEBUG_INFO,
"ProcTrace: Topa table address(aligned) for thread %d is 0x%llX \n", Index, (UINT64)TopaMemArray[Index]));
456 DEBUG ((DEBUG_INFO,
"ProcTrace: Allocated ToPA mem for %d thread \n", ProcTraceData->AllocatedThreads));
460 if (!ProcTraceData->EnableOnBspOnly) {
461 if (ProcessorNumber < ProcTraceData->AllocatedThreads) {
462 TopaTableBaseAddr = ProcTraceData->TopaMemArray[ProcessorNumber];
469 TopaEntryPtr = &TopaTable->TopaEntry[0];
471 TopaEntryPtr->
Bits.
Base = (MemRegionBaseAddr >> 12) & 0x000FFFFF;
473 TopaEntryPtr->
Bits.
Size = ProcTraceData->ProcTraceMemSize;
476 TopaEntryPtr = &TopaTable->TopaEntry[1];
478 TopaEntryPtr->
Bits.
Base = (TopaTableBaseAddr >> 12) & 0x000FFFFF;
485 OutputBaseReg.
Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputBase.
Uint64;
486 OutputBaseReg.
Bits.
Base = (TopaTableBaseAddr >> 7) & 0x01FFFFFF;
498 OutputMaskPtrsReg.
Uint64 = ProcTraceData->ProcessorData[ProcessorNumber].RtitOutputMaskPtrs.
Uint64;
530 if (ProcTraceData->EnablePerformanceCollecting) {
531 if (ProcTraceData->ProcessorData[ProcessorNumber].CycPacketSupported) {
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
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)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateAlignedReservedPages(IN UINTN Pages, IN UINTN Alignment)
#define IS_GOLDMONT_PROCESSOR(DisplayFamily, DisplayModel)
#define IS_GOLDMONT_PLUS_PROCESSOR(DisplayFamily, DisplayModel)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
#define RETURN_OUT_OF_RESOURCES
#define DEBUG(Expression)
#define MSR_IA32_RTIT_OUTPUT_MASK_PTRS
#define MSR_IA32_RTIT_STATUS
#define MSR_IA32_RTIT_CTL
#define MSR_IA32_RTIT_OUTPUT_BASE
#define CPUID_INTEL_PROCESSOR_TRACE
#define CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS
#define CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF
#define PROCESSOR_AS_BSP_BIT
#define PcdGet8(TokenName)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID *EFIAPI ProcTraceGetConfigData(IN UINTN NumberOfProcessors)
RETURN_STATUS EFIAPI ProcTraceInitialize(IN UINTN ProcessorNumber, IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData OPTIONAL, IN BOOLEAN State)
#define MAX_TOPA_ENTRY_COUNT
BOOLEAN EFIAPI ProcTraceSupport(IN UINTN ProcessorNumber, IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData OPTIONAL)
#define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, Value)
#define EFI_SIZE_TO_PAGES(Size)
struct CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF_EBX::@738 Bits
struct CPUID_INTEL_PROCESSOR_TRACE_MAIN_LEAF_ECX::@739 Bits
struct MSR_IA32_RTIT_CTL_REGISTER::@670 Bits
struct MSR_IA32_RTIT_OUTPUT_BASE_REGISTER::@667 Bits
struct MSR_IA32_RTIT_OUTPUT_MASK_PTRS_REGISTER::@668 Bits
struct RTIT_TOPA_TABLE_ENTRY::@669 Bits