26 DEBUG ((DEBUG_INFO,
"+-------+--------------------------------------------------------------------------------------+\n"));
27 DEBUG ((DEBUG_INFO,
"| Index | Packge CoreType CacheLevel CacheType CacheWays (FA|DM) CacheSizeinKB CacheCount |\n"));
28 DEBUG ((DEBUG_INFO,
"+-------+--------------------------------------------------------------------------------------+\n"));
30 for (Index = 0; Index < CpuCacheInfoCount; Index++) {
33 "| %4x | %4x %2x %2x %2x %4x ( %x| %x) %8x %4x |\n",
35 CpuCacheInfo[Index].Package,
36 CpuCacheInfo[Index].CoreType,
37 CpuCacheInfo[Index].CacheLevel,
38 CpuCacheInfo[Index].CacheType,
39 CpuCacheInfo[Index].CacheWays,
40 CpuCacheInfo[Index].FullyAssociativeCache,
41 CpuCacheInfo[Index].DirectMappedCache,
42 CpuCacheInfo[Index].CacheSizeinKB,
43 CpuCacheInfo[Index].CacheCount
47 DEBUG ((DEBUG_INFO,
"+-------+--------------------------------------------------------------------------------------+\n"));
69 ZeroMem (&Comparator1,
sizeof (Comparator1));
70 ZeroMem (&Comparator2,
sizeof (Comparator2));
74 Comparator1.Bits.CacheLevel = ((
CPU_CACHE_INFO *)Buffer1)->CacheLevel;
75 Comparator1.Bits.CacheType = ((
CPU_CACHE_INFO *)Buffer1)->CacheType;
79 Comparator2.Bits.CacheLevel = ((
CPU_CACHE_INFO *)Buffer2)->CacheLevel;
80 Comparator2.Bits.CacheType = ((
CPU_CACHE_INFO *)Buffer2)->CacheType;
82 if (Comparator1.Uint64 == Comparator2.Uint64) {
84 }
else if (Comparator1.Uint64 > Comparator2.Uint64) {
104 IN OUT UINT32 *Package
107 UINTN ProcessorIndex;
110 UINT32 CurrentPackage;
114 for (ProcessorIndex = 0; ProcessorIndex < NumberOfProcessors; ProcessorIndex++) {
115 CurrentPackage = ProcessorInfo[ProcessorIndex].Package;
120 for (PackageIndex = 0; PackageIndex < PackageCount; PackageIndex++) {
121 if (CurrentPackage == Package[PackageIndex]) {
129 if (PackageIndex == PackageCount) {
130 ASSERT (PackageCount < MAX_NUM_OF_PACKAGE);
131 Package[PackageCount++] = CurrentPackage;
154 UINTN ProcessorIndex;
159 UINT8 CoreType[MAX_UINT8];
162 UINT8 CurrentCoreType;
169 for (ProcessorIndex = 0; ProcessorIndex < NumberOfProcessors; ProcessorIndex++) {
170 CurrentCoreType = ProcessorInfo[ProcessorIndex].CoreType;
172 if (ProcessorInfo[ProcessorIndex].Package != Package) {
179 for (CoreTypeIndex = 0; CoreTypeIndex < CoreTypeCount; CoreTypeIndex++) {
180 if (CurrentCoreType == CoreType[CoreTypeIndex]) {
188 if (CoreTypeIndex == CoreTypeCount) {
189 ASSERT (CoreTypeCount < MAX_UINT8);
190 CoreType[CoreTypeCount++] = CurrentCoreType;
194 return CoreTypeCount;
208 UINTN ProcessorIndex;
209 UINT32 CpuidMaxInput;
210 UINT8 CacheParamLeafIndex;
213 UINT32 CacheParamEcx;
221 CacheData = &Context->CacheData[MAX_NUM_OF_CACHE_PARAMS_LEAF * ProcessorIndex];
228 Context->ProcessorInfo[ProcessorIndex].CoreType = 0;
231 Context->ProcessorInfo[ProcessorIndex].CoreType = (UINT8)NativeModelIdAndCoreTypeEax.
Bits.
CoreType;
237 CacheParamLeafIndex = 0;
239 while (CacheParamLeafIndex < MAX_NUM_OF_CACHE_PARAMS_LEAF) {
246 CacheData[CacheParamLeafIndex].CacheLevel = (UINT8)CacheParamEax.
Bits.
CacheLevel;
247 CacheData[CacheParamLeafIndex].CacheType = (UINT8)CacheParamEax.
Bits.
CacheType;
248 CacheData[CacheParamLeafIndex].CacheWays = (UINT16)CacheParamEbx.
Bits.
Ways;
252 CacheData[CacheParamLeafIndex].CacheSizeinKB = (CacheParamEbx.
Bits.
Ways + 1) *
255 CacheParamLeafIndex++;
285 UINT32 NumberOfPackage;
286 UINT32 Package[MAX_NUM_OF_PACKAGE];
288 UINTN TotalNumberOfCoreType;
289 UINTN MaxCacheInfoCount;
291 UINTN CacheInfoIndex;
292 UINTN LocalCacheInfoCount;
306 TotalNumberOfCoreType = 0;
307 for (PackageIndex = 0; PackageIndex < NumberOfPackage; PackageIndex++) {
311 MaxCacheInfoCount = TotalNumberOfCoreType * MAX_NUM_OF_CACHE_PARAMS_LEAF;
313 ASSERT (LocalCacheInfo !=
NULL);
314 if (LocalCacheInfo ==
NULL) {
315 return EFI_OUT_OF_RESOURCES;
318 LocalCacheInfoCount = 0;
320 for (Index = 0; Index < NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_LEAF; Index++) {
321 if (CacheData[Index].CacheSizeinKB == 0) {
328 for (NextIndex = Index + 1; NextIndex < NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_LEAF; NextIndex++) {
329 if (CacheData[NextIndex].CacheSizeinKB == 0) {
333 if ((CacheData[Index].CacheLevel == CacheData[NextIndex].CacheLevel) &&
334 (CacheData[Index].CacheType == CacheData[NextIndex].CacheType) &&
335 (ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package == ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package) &&
336 (ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType == ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType) &&
337 ((ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~CacheData[Index].CacheShareBits) ==
338 (ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~CacheData[NextIndex].CacheShareBits)))
340 CacheData[NextIndex].CacheSizeinKB = 0;
347 for (CacheInfoIndex = 0; CacheInfoIndex < LocalCacheInfoCount; CacheInfoIndex++) {
348 if ((LocalCacheInfo[CacheInfoIndex].Package == ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package) &&
349 (LocalCacheInfo[CacheInfoIndex].CoreType == ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType) &&
350 (LocalCacheInfo[CacheInfoIndex].CacheLevel == CacheData[Index].CacheLevel) &&
351 (LocalCacheInfo[CacheInfoIndex].CacheType == CacheData[Index].CacheType) &&
352 (LocalCacheInfo[CacheInfoIndex].CacheSizeinKB == CacheData[Index].CacheSizeinKB))
354 LocalCacheInfo[CacheInfoIndex].CacheCount++;
363 if (CacheInfoIndex == LocalCacheInfoCount) {
364 ASSERT (LocalCacheInfoCount < MaxCacheInfoCount);
366 LocalCacheInfo[LocalCacheInfoCount].Package = ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package;
367 LocalCacheInfo[LocalCacheInfoCount].CoreType = ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType;
368 LocalCacheInfo[LocalCacheInfoCount].CacheLevel = CacheData[Index].CacheLevel;
369 LocalCacheInfo[LocalCacheInfoCount].CacheType = CacheData[Index].CacheType;
370 LocalCacheInfo[LocalCacheInfoCount].CacheWays = CacheData[Index].CacheWays;
371 LocalCacheInfo[LocalCacheInfoCount].FullyAssociativeCache = CacheData[Index].FullyAssociativeCache;
372 LocalCacheInfo[LocalCacheInfoCount].DirectMappedCache = CacheData[Index].DirectMappedCache;
373 LocalCacheInfo[LocalCacheInfoCount].CacheSizeinKB = CacheData[Index].CacheSizeinKB;
374 LocalCacheInfo[LocalCacheInfoCount].CacheCount = 1;
376 LocalCacheInfoCount++;
380 if (*CacheInfoCount < LocalCacheInfoCount) {
381 Status = EFI_BUFFER_TOO_SMALL;
387 CopyMem (CacheInfo, LocalCacheInfo,
sizeof (*CacheInfo) * LocalCacheInfoCount);
394 *CacheInfoCount = LocalCacheInfoCount;
426 UINT32 CpuidMaxInput;
427 UINT32 NumberOfProcessors;
428 UINTN CacheDataCount;
429 UINTN ProcessorIndex;
433 if (CpuCacheInfoCount ==
NULL) {
434 return EFI_INVALID_PARAMETER;
437 if ((*CpuCacheInfoCount != 0) && (CpuCacheInfo ==
NULL)) {
438 return EFI_INVALID_PARAMETER;
443 return EFI_UNSUPPORTED;
457 ASSERT (Context.ProcessorInfo !=
NULL);
458 if (Context.ProcessorInfo ==
NULL) {
459 return EFI_OUT_OF_RESOURCES;
468 CacheDataCount = NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_LEAF;
470 ASSERT (Context.CacheData !=
NULL);
471 if (Context.CacheData ==
NULL) {
473 return EFI_OUT_OF_RESOURCES;
476 ZeroMem (Context.CacheData, CacheDataCount * sizeof (*Context.CacheData));
481 for (ProcessorIndex = 0; ProcessorIndex < NumberOfProcessors; ProcessorIndex++) {
483 Context.ProcessorInfo[ProcessorIndex].Package = ProcessorInfo.
Location.
Package;
484 Context.ProcessorInfo[ProcessorIndex].ApicId = (UINT32)ProcessorInfo.
ProcessorId;
VOID EFIAPI QuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN BASE_SORT_COMPARE CompareFunction, OUT VOID *BufferOneElement)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT32 CpuCacheInfoGetNumberOfPackages(IN CPUID_PROCESSOR_INFO *ProcessorInfo, IN UINTN NumberOfProcessors, IN OUT UINT32 *Package)
VOID EFIAPI CpuCacheInfoCollectCoreAndCacheData(IN OUT VOID *Buffer)
EFI_STATUS EFIAPI GetCpuCacheInfo(IN OUT CPU_CACHE_INFO *CpuCacheInfo, IN OUT UINTN *CpuCacheInfoCount)
UINTN CpuCacheInfoGetNumberOfCoreTypePerPackage(IN CPUID_PROCESSOR_INFO *ProcessorInfo, IN UINTN NumberOfProcessors, IN UINTN Package)
VOID CpuCacheInfoPrintCpuCacheInfoTable(IN CPU_CACHE_INFO *CpuCacheInfo, IN UINTN CpuCacheInfoCount)
INTN EFIAPI CpuCacheInfoCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
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)
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)
UINT32 CpuCacheInfoWhoAmI(IN MP_SERVICES MpServices)
EFI_STATUS CpuCacheInfoGetMpServices(OUT MP_SERVICES *MpServices)
UINT32 CpuCacheInfoGetNumberOfProcessors(IN MP_SERVICES MpServices)
VOID CpuCacheInfoGetProcessorInfo(IN MP_SERVICES MpServices, IN UINTN ProcessorNum, OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo)
VOID CpuCacheInfoStartupAllCPUs(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN VOID *ProcedureArgument)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
#define DEBUG(Expression)
#define DEBUG_CODE(Expression)
#define CPUID_HYBRID_INFORMATION_MAIN_LEAF
#define CPUID_CACHE_PARAMS
#define CPUID_HYBRID_INFORMATION
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_CPU_PHYSICAL_LOCATION Location
struct CPUID_CACHE_PARAMS_EAX::@698 Bits
UINT32 MaximumAddressableIdsForLogicalProcessors
UINT32 FullyAssociativeCache
struct CPUID_CACHE_PARAMS_EBX::@699 Bits
struct CPUID_CACHE_PARAMS_EDX::@700 Bits
UINT32 ComplexCacheIndexing
struct CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX::@748 Bits