From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web09.3516.1610675687397696960 for ; Thu, 14 Jan 2021 17:54:47 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: yun.lou@intel.com) IronPort-SDR: veaNuTdeHioOgVb3AR6d8q5wrVsFHkIknqgWhUhDrl0B0Gy6+UuWcV9EhBnXuFngRUdyNLZd5k O4z9C7EwlnbQ== X-IronPort-AV: E=McAfee;i="6000,8403,9864"; a="242549319" X-IronPort-AV: E=Sophos;i="5.79,347,1602572400"; d="scan'208";a="242549319" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2021 17:54:46 -0800 IronPort-SDR: 21Q0AiP46MpFr2hpejq4T3+MJKx8XNKjcHBVT7K3DeX6W8eToTqFf1i1jcJi5+SnfVjhTpRtcY LoR2/RKgZb3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,347,1602572400"; d="scan'208";a="401128022" Received: from shwdeopenlab102.ccr.corp.intel.com ([10.239.183.61]) by fmsmga002.fm.intel.com with ESMTP; 14 Jan 2021 17:54:44 -0800 From: "Jason Lou" To: devel@edk2.groups.io Cc: Jason , Ray Ni , Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v6 2/2] UefiCpuPkg/CpuCacheInfoLib: Add new CpuCacheInfoLib. Date: Fri, 15 Jan 2021 09:54:16 +0800 Message-Id: <20210115015416.3567-2-yun.lou@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210115015416.3567-1-yun.lou@intel.com> References: <20210115015416.3567-1-yun.lou@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3105 This new library uses a platform agnostic algorithm to get CPU cache information. It provides user with an API(GetCpuCacheInfo) to get detailed CPU cache information by each package, each core type included in this package, and each cache level & type. This library can be used by code that produces SMBIOS_TABLE_TYPE7 SMBIOS table. Signed-off-by: Jason Lou Cc: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek Cc: Rahul Kumar --- UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c | 440 +++++++= +++++++++++++ UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.c | 120 ++++++ UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.c | 119 ++++++ UefiCpuPkg/Include/Library/CpuCacheInfoLib.h | 76 ++++ UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.uni | 15 + UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf | 43 ++ UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h | 159 +++++++ UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf | 43 ++ UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 4 + 10 files changed, 1022 insertions(+) diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c b/UefiCpu= Pkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c new file mode 100644 index 000000000000..5606642c31f3 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.c @@ -0,0 +1,440 @@ +/** @file=0D + Provides cache info for each package, core type, cache level and cache t= ype.=0D +=0D + Copyright (c) 2020 Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "InternalCpuCacheInfoLib.h"=0D +=0D +/**=0D + Print CpuCacheInfo array.=0D +=0D + @param[in] CpuCacheInfo Pointer to the CpuCacheInfo array.=0D + @param[in] CpuCacheInfoCount The length of CpuCacheInfo array.=0D +=0D +**/=0D +VOID=0D +CpuCacheInfoPrintCpuCacheInfoTable (=0D + IN CPU_CACHE_INFO *CpuCacheInfo,=0D + IN UINTN CpuCacheInfoCount=0D + )=0D +{=0D + UINTN Index;=0D +=0D + DEBUG ((DEBUG_INFO, "+-------+------------------------------------------= -------------------------------------+\n"));=0D + DEBUG ((DEBUG_INFO, "| Index | Packge CoreType CacheLevel CacheType = CacheWays CacheSizeinKB CacheCount |\n"));=0D + DEBUG ((DEBUG_INFO, "+-------+------------------------------------------= -------------------------------------+\n"));=0D +=0D + for (Index =3D 0; Index < CpuCacheInfoCount; Index++) {=0D + DEBUG ((DEBUG_INFO, "| %4x | %4x %2x %2x %2x = %4x %8x %4x |\n", Index,=0D + CpuCacheInfo[Index].Package, CpuCacheInfo[Index].CoreType, CpuCach= eInfo[Index].CacheLevel,=0D + CpuCacheInfo[Index].CacheType, CpuCacheInfo[Index].CacheWays, CpuC= acheInfo[Index].CacheSizeinKB,=0D + CpuCacheInfo[Index].CacheCount));=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "+-------+------------------------------------------= -------------------------------------+\n"));=0D +}=0D +=0D +/**=0D + Get the total number of package and package ID in the platform.=0D +=0D + @param[in] ProcessorInfo Pointer to the ProcessorInfo array.= =0D + @param[in] NumberOfProcessors Total number of logical processors i= n the platform.=0D + @param[in, out] Package Pointer to the Package array.=0D +=0D + @retval Return the total number of package and package ID in the platfo= rm.=0D +**/=0D +UINT32=0D +CpuCacheInfoGetNumberOfPackages (=0D + IN CPUID_PROCESSOR_INFO *ProcessorInfo,=0D + IN UINTN NumberOfProcessors,=0D + IN OUT UINT32 *Package=0D + )=0D +{=0D + UINTN ProcessorIndex;=0D + UINT32 PackageIndex;=0D + UINT32 PackageCount;=0D + UINT32 CurrentPackage;=0D +=0D + PackageCount =3D 0;=0D +=0D + for (ProcessorIndex =3D 0; ProcessorIndex < NumberOfProcessors; Processo= rIndex++) {=0D + CurrentPackage =3D ProcessorInfo[ProcessorIndex].Package;=0D +=0D + //=0D + // For the package that already exists in Package array, break out the= loop.=0D + //=0D + for (PackageIndex =3D 0; PackageIndex < PackageCount; PackageIndex++) = {=0D + if (CurrentPackage =3D=3D Package[PackageIndex]) {=0D + break;=0D + }=0D + }=0D +=0D + //=0D + // For the new package, save it in Package array.=0D + //=0D + if (PackageIndex =3D=3D PackageCount) {=0D + ASSERT (PackageCount < MAX_NUM_OF_PACKAGE);=0D + Package[PackageCount++] =3D CurrentPackage;=0D + }=0D + }=0D +=0D + return PackageCount;=0D +}=0D +=0D +/**=0D + Get the number of CoreType of requested package.=0D +=0D + @param[in] ProcessorInfo Pointer to the ProcessorInfo array.=0D + @param[in] NumberOfProcessors Total number of logical processors in th= e platform.=0D + @param[in] Package The requested package number.=0D +=0D + @retval Return the number of CoreType of requested package.=0D +**/=0D +UINTN=0D +CpuCacheInfoGetNumberOfCoreTypePerPackage(=0D + IN CPUID_PROCESSOR_INFO *ProcessorInfo,=0D + IN UINTN NumberOfProcessors,=0D + IN UINTN Package=0D + )=0D +{=0D + UINTN ProcessorIndex;=0D + //=0D + // Core Type value comes from CPUID.1Ah.EAX[31:24].=0D + // So max number of core types should be MAX_UINT8.=0D + //=0D + UINT8 CoreType[MAX_UINT8];=0D + UINTN CoreTypeIndex;=0D + UINTN CoreTypeCount;=0D + UINT8 CurrentCoreType;=0D +=0D + //=0D + // CoreType array is empty.=0D + //=0D + CoreTypeCount =3D 0;=0D +=0D + for (ProcessorIndex =3D 0; ProcessorIndex < NumberOfProcessors; Processo= rIndex++) {=0D + CurrentCoreType =3D ProcessorInfo[ProcessorIndex].CoreType;=0D +=0D + if (ProcessorInfo[ProcessorIndex].Package !=3D Package) {=0D + continue;=0D + }=0D +=0D + //=0D + // For the type that already exists in CoreType array, break out the l= oop.=0D + //=0D + for (CoreTypeIndex =3D 0; CoreTypeIndex < CoreTypeCount; CoreTypeIndex= ++) {=0D + if (CurrentCoreType =3D=3D CoreType[CoreTypeIndex]) {=0D + break;=0D + }=0D + }=0D +=0D + //=0D + // For the new type, save it in CoreType array.=0D + //=0D + if (CoreTypeIndex =3D=3D CoreTypeCount) {=0D + ASSERT (CoreTypeCount < MAX_UINT8);=0D + CoreType[CoreTypeCount++] =3D CurrentCoreType;=0D + }=0D + }=0D +=0D + return CoreTypeCount;=0D +}=0D +=0D +/**=0D + Collect core and cache information of calling processor via CPUID instru= ctions.=0D +=0D + @param[in, out] Buffer The pointer to private data buffer.= =0D +**/=0D +VOID=0D +CpuCacheInfoCollectCoreAndCacheData (=0D + IN OUT VOID *Buffer=0D + )=0D +{=0D + UINTN ProcessorIndex;=0D + UINT32 CpuidMaxInput;=0D + UINT8 CacheParamLeafIndex;=0D + CPUID_CACHE_PARAMS_EAX CacheParamEax;=0D + CPUID_CACHE_PARAMS_EBX CacheParamEbx;=0D + UINT32 CacheParamEcx;=0D + CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX NativeModelIdAndCoreTypeEax;=0D + COLLECT_CPUID_CACHE_DATA_CONTEXT *Context;=0D + CPUID_CACHE_DATA *CacheData;=0D +=0D + Context =3D (COLLECT_CPUID_CACHE_DATA_CONTEXT *)Buffer;=0D + ProcessorIndex =3D CpuCacheInfoWhoAmI (Context->MpServices);=0D + CacheData =3D &Context->CacheData[MAX_NUM_OF_CACHE_PARAMS_LEAF * Process= orIndex];=0D +=0D + AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);=0D +=0D + //=0D + // get CoreType if CPUID_HYBRID_INFORMATION leaf is supported.=0D + //=0D + Context->ProcessorInfo[ProcessorIndex].CoreType =3D 0;=0D + if (CpuidMaxInput >=3D CPUID_HYBRID_INFORMATION) {=0D + AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_SUB_LEA= F, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);=0D + Context->ProcessorInfo[ProcessorIndex].CoreType =3D (UINT8) NativeMode= lIdAndCoreTypeEax.Bits.CoreType;=0D + }=0D +=0D + //=0D + // cache hierarchy starts with an index value of 0.=0D + //=0D + CacheParamLeafIndex =3D 0;=0D +=0D + while (CacheParamLeafIndex < MAX_NUM_OF_CACHE_PARAMS_LEAF) {=0D + AsmCpuidEx (CPUID_CACHE_PARAMS, CacheParamLeafIndex, &CacheParamEax.Ui= nt32, &CacheParamEbx.Uint32, &CacheParamEcx, NULL);=0D +=0D + if (CacheParamEax.Bits.CacheType =3D=3D 0) {=0D + break;=0D + }=0D +=0D + CacheData[CacheParamLeafIndex].CacheLevel =3D (UINT8)CacheParamEax= .Bits.CacheLevel;=0D + CacheData[CacheParamLeafIndex].CacheType =3D (UINT8)CacheParamEax= .Bits.CacheType;=0D + CacheData[CacheParamLeafIndex].CacheWays =3D (UINT16)CacheParamEb= x.Bits.Ways;=0D + CacheData[CacheParamLeafIndex].CacheShareBits =3D (UINT16)CacheParamEa= x.Bits.MaximumAddressableIdsForLogicalProcessors;=0D + CacheData[CacheParamLeafIndex].CacheSizeinKB =3D (CacheParamEbx.Bits.= Ways + 1) *=0D + (CacheParamEbx.Bits.LinePartitions + 1) * (CacheParamEbx.Bits.Line= Size + 1) * (CacheParamEcx + 1) / SIZE_1KB;=0D +=0D + CacheParamLeafIndex++;=0D + }=0D +}=0D +=0D +/**=0D + Collect CacheInfo data from the CacheData.=0D +=0D + @param[in] CacheData Pointer to the CacheData array.=0D + @param[in] ProcessorInfo Pointer to the ProcessorInfo array.= =0D + @param[in] NumberOfProcessors Total number of logical processors i= n the platform.=0D + @param[in, out] CacheInfo Pointer to the CacheInfo array.=0D + @param[in, out] CacheInfoCount As input, point to the length of res= ponse CacheInfo array.=0D + As output, point to the actual lengt= h of response CacheInfo array.=0D +=0D + @retval EFI_SUCCESS Function completed successfully.= =0D + @retval EFI_OUT_OF_RESOURCES Required resources could not be = allocated.=0D + @retval EFI_BUFFER_TOO_SMALL CacheInfoCount is too small to h= old the response CacheInfo=0D + array. CacheInfoCount has been u= pdated with the length needed=0D + to complete the request.=0D +**/=0D +EFI_STATUS=0D +CpuCacheInfoCollectCpuCacheInfoData (=0D + IN CPUID_CACHE_DATA *CacheData,=0D + IN CPUID_PROCESSOR_INFO *ProcessorInfo,=0D + IN UINTN NumberOfProcessors,=0D + IN OUT CPU_CACHE_INFO *CacheInfo,=0D + IN OUT UINTN *CacheInfoCount=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 NumberOfPackage;=0D + UINT32 Package[MAX_NUM_OF_PACKAGE];=0D + UINTN PackageIndex;=0D + UINTN TotalNumberOfCoreType;=0D + UINTN MaxCacheInfoCount;=0D + CPU_CACHE_INFO *LocalCacheInfo;=0D + UINTN CacheInfoIndex;=0D + UINTN LocalCacheInfoCount;=0D + UINTN Index;=0D + UINTN NextIndex;=0D +=0D + //=0D + // Get number of Packages and Package ID.=0D + //=0D + NumberOfPackage =3D CpuCacheInfoGetNumberOfPackages (ProcessorInfo, Numb= erOfProcessors, Package);=0D +=0D + //=0D + // Get number of core types for each package and count the total number.= =0D + // E.g. If Package1 and Package2 both have 2 core types, the total numbe= r is 4.=0D + //=0D + TotalNumberOfCoreType =3D 0;=0D + for (PackageIndex =3D 0; PackageIndex < NumberOfPackage; PackageIndex++)= {=0D + TotalNumberOfCoreType +=3D CpuCacheInfoGetNumberOfCoreTypePerPackage (= ProcessorInfo, NumberOfProcessors, Package[PackageIndex]);=0D + }=0D +=0D + MaxCacheInfoCount =3D TotalNumberOfCoreType * MAX_NUM_OF_CACHE_PARAMS_LE= AF;=0D + LocalCacheInfo =3D AllocatePages (EFI_SIZE_TO_PAGES (MaxCacheInfoCount *= sizeof (*LocalCacheInfo)));=0D + ASSERT (LocalCacheInfo !=3D NULL);=0D + if (LocalCacheInfo =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + LocalCacheInfoCount =3D 0;=0D +=0D + for (Index =3D 0; Index < NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_L= EAF; Index++) {=0D + if (CacheData[Index].CacheSizeinKB =3D=3D 0) {=0D + continue;=0D + }=0D +=0D + //=0D + // For the sharing caches, clear their CacheSize.=0D + //=0D + for (NextIndex =3D Index + 1; NextIndex < NumberOfProcessors * MAX_NUM= _OF_CACHE_PARAMS_LEAF; NextIndex++) {=0D + if (CacheData[NextIndex].CacheSizeinKB =3D=3D 0) {=0D + continue;=0D + }=0D +=0D + if (CacheData[Index].CacheLevel =3D=3D CacheData[NextIndex].CacheLev= el &&=0D + CacheData[Index].CacheType =3D=3D CacheData[NextIndex].CacheType= &&=0D + ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package =3D= =3D ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package &&=0D + ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType =3D= =3D ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType &&=0D + (ProcessorInfo[Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId & ~C= acheData[Index].CacheShareBits) =3D=3D=0D + (ProcessorInfo[NextIndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].ApicId = & ~CacheData[NextIndex].CacheShareBits)) {=0D + CacheData[NextIndex].CacheSizeinKB =3D 0; // uses the sharing cach= e=0D + }=0D + }=0D +=0D + //=0D + // For the cache that already exists in LocalCacheInfo, increase its C= acheCount.=0D + //=0D + for (CacheInfoIndex =3D 0; CacheInfoIndex < LocalCacheInfoCount; Cache= InfoIndex++) {=0D + if (LocalCacheInfo[CacheInfoIndex].Package =3D=3D ProcessorInfo[I= ndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package &&=0D + LocalCacheInfo[CacheInfoIndex].CoreType =3D=3D ProcessorInfo[I= ndex / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType &&=0D + LocalCacheInfo[CacheInfoIndex].CacheLevel =3D=3D CacheData[Index= ].CacheLevel &&=0D + LocalCacheInfo[CacheInfoIndex].CacheType =3D=3D CacheData[Index= ].CacheType) {=0D + LocalCacheInfo[CacheInfoIndex].CacheCount++;=0D + break;=0D + }=0D + }=0D +=0D + //=0D + // For the new cache with different Package, CoreType, CacheLevel or C= acheType, copy its=0D + // data into LocalCacheInfo buffer.=0D + //=0D + if (CacheInfoIndex =3D=3D LocalCacheInfoCount) {=0D + ASSERT (LocalCacheInfoCount < MaxCacheInfoCount);=0D +=0D + LocalCacheInfo[LocalCacheInfoCount].Package =3D ProcessorInfo[= Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].Package;=0D + LocalCacheInfo[LocalCacheInfoCount].CoreType =3D ProcessorInfo[= Index / MAX_NUM_OF_CACHE_PARAMS_LEAF].CoreType;=0D + LocalCacheInfo[LocalCacheInfoCount].CacheLevel =3D CacheData[Inde= x].CacheLevel;=0D + LocalCacheInfo[LocalCacheInfoCount].CacheType =3D CacheData[Inde= x].CacheType;=0D + LocalCacheInfo[LocalCacheInfoCount].CacheWays =3D CacheData[Inde= x].CacheWays;=0D + LocalCacheInfo[LocalCacheInfoCount].CacheSizeinKB =3D CacheData[Inde= x].CacheSizeinKB;=0D + LocalCacheInfo[LocalCacheInfoCount].CacheCount =3D 1;=0D +=0D + LocalCacheInfoCount++;=0D + }=0D + }=0D +=0D + if (*CacheInfoCount < LocalCacheInfoCount) {=0D + Status =3D EFI_BUFFER_TOO_SMALL;=0D + } else {=0D + CopyMem (CacheInfo, LocalCacheInfo, sizeof (*CacheInfo) * LocalCacheIn= foCount);=0D + DEBUG_CODE (=0D + CpuCacheInfoPrintCpuCacheInfoTable (CacheInfo, LocalCacheInfoCount);= =0D + );=0D + Status =3D EFI_SUCCESS;=0D + }=0D +=0D + *CacheInfoCount =3D LocalCacheInfoCount;=0D +=0D + FreePages (LocalCacheInfo, EFI_SIZE_TO_PAGES (MaxCacheInfoCount * sizeof= (*LocalCacheInfo)));=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Get CpuCacheInfo data array.=0D +=0D + @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array.=0D + @param[in, out] CpuCacheInfoCount As input, point to the length of res= ponse CpuCacheInfo array.=0D + As output, point to the actual lengt= h of response CpuCacheInfo array.=0D +=0D + @retval EFI_SUCCESS Function completed successfully.= =0D + @retval EFI_INVALID_PARAMETER CpuCacheInfoCount is NULL.=0D + @retval EFI_INVALID_PARAMETER CpuCacheInfo is NULL while CpuCa= cheInfoCount contains the value=0D + greater than zero.=0D + @retval EFI_UNSUPPORTED Processor does not support CPUID= _CACHE_PARAMS Leaf.=0D + @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI or EF= I_MP_SERVICES_PROTOCOL interface=0D + is not found.=0D + @retval EFI_OUT_OF_RESOURCES Required resources could not be = allocated.=0D + @retval EFI_BUFFER_TOO_SMALL CpuCacheInfoCount is too small t= o hold the response CpuCacheInfo=0D + array. CpuCacheInfoCount has bee= n updated with the length needed=0D + to complete the request.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +GetCpuCacheInfo (=0D + IN OUT CPU_CACHE_INFO *CpuCacheInfo,=0D + IN OUT UINTN *CpuCacheInfoCount=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 CpuidMaxInput;=0D + UINT32 NumberOfProcessors;=0D + UINTN CacheDataCount;=0D + UINTN ProcessorIndex;=0D + EFI_PROCESSOR_INFORMATION ProcessorInfo;=0D + COLLECT_CPUID_CACHE_DATA_CONTEXT Context;=0D +=0D + if (CpuCacheInfoCount =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (*CpuCacheInfoCount !=3D 0 && CpuCacheInfo =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);=0D + if (CpuidMaxInput < CPUID_CACHE_PARAMS) {=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + //=0D + // Initialize COLLECT_CPUID_CACHE_DATA_CONTEXT.MpServices.=0D + //=0D + Status =3D CpuCacheInfoGetMpServices (&Context.MpServices);=0D + if (EFI_ERROR(Status)) {=0D + return Status;=0D + }=0D +=0D + NumberOfProcessors =3D CpuCacheInfoGetNumberOfProcessors (Context.MpServ= ices);=0D +=0D + //=0D + // Initialize COLLECT_CPUID_CACHE_DATA_CONTEXT.ProcessorInfo.=0D + //=0D + Context.ProcessorInfo =3D AllocatePages (EFI_SIZE_TO_PAGES (NumberOfProc= essors * sizeof (*Context.ProcessorInfo)));=0D + ASSERT (Context.ProcessorInfo !=3D NULL);=0D + if (Context.ProcessorInfo =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D + //=0D + // Initialize COLLECT_CPUID_CACHE_DATA_CONTEXT.CacheData.=0D + // CacheData array consists of CPUID_CACHE_DATA data structure for each = Cpuid Cache Parameter Leaf=0D + // per logical processor. The array begin with data of each Cache Parame= ter Leaf of processor 0, followed=0D + // by data of each Cache Parameter Leaf of processor 1 ...=0D + //=0D + CacheDataCount =3D NumberOfProcessors * MAX_NUM_OF_CACHE_PARAMS_LEAF;=0D + Context.CacheData =3D AllocatePages (EFI_SIZE_TO_PAGES (CacheDataCount *= sizeof (*Context.CacheData)));=0D + ASSERT (Context.CacheData !=3D NULL);=0D + if (Context.CacheData =3D=3D NULL) {=0D + FreePages (Context.ProcessorInfo, EFI_SIZE_TO_PAGES (NumberOfProcessor= s * sizeof (*Context.ProcessorInfo)));=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + ZeroMem (Context.CacheData, CacheDataCount * sizeof (*Context.CacheData)= );=0D +=0D + //=0D + // Collect Package ID and APIC ID of all processors.=0D + //=0D + for (ProcessorIndex =3D 0; ProcessorIndex < NumberOfProcessors; Processo= rIndex++) {=0D + CpuCacheInfoGetProcessorInfo (Context.MpServices, ProcessorIndex, &Pro= cessorInfo);=0D + Context.ProcessorInfo[ProcessorIndex].Package =3D ProcessorInfo.Locati= on.Package;=0D + Context.ProcessorInfo[ProcessorIndex].ApicId =3D (UINT32) ProcessorIn= fo.ProcessorId;=0D + }=0D +=0D + //=0D + // Wakeup all processors for CacheData(core type and cache data) collect= ion.=0D + //=0D + CpuCacheInfoStartupAllCPUs (Context.MpServices, (EFI_AP_PROCEDURE)CpuCac= heInfoCollectCoreAndCacheData, &Context);=0D +=0D + //=0D + // Collect CpuCacheInfo data from CacheData.=0D + //=0D + Status =3D CpuCacheInfoCollectCpuCacheInfoData (Context.CacheData, Conte= xt.ProcessorInfo, NumberOfProcessors, CpuCacheInfo, CpuCacheInfoCount);=0D +=0D + FreePages (Context.CacheData, EFI_SIZE_TO_PAGES (CacheDataCount * sizeof= (*Context.CacheData)));=0D + FreePages (Context.ProcessorInfo, EFI_SIZE_TO_PAGES (NumberOfProcessors = * sizeof (*Context.ProcessorInfo)));=0D +=0D + return Status;=0D +}=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.c b/Uefi= CpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.c new file mode 100644 index 000000000000..bb788e36146b --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.c @@ -0,0 +1,120 @@ +/** @file=0D + Provides cache info for each package, core type, cache level and cache t= ype.=0D +=0D + Copyright (c) 2020 Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Get EFI_MP_SERVICES_PROTOCOL pointer.=0D +=0D + @param[out] MpServices A pointer to the buffer where EFI_MP_SERVICES_= PROTOCOL is stored=0D +=0D + @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned= =0D + @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not foun= d=0D +**/=0D +EFI_STATUS=0D +CpuCacheInfoGetMpServices (=0D + OUT MP_SERVICES *MpServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID = **)&MpServices->Protocol);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Activate all of the logical processors.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D + @param[in] Procedure A pointer to the function to be run on e= nabled logical processors.=0D + @param[in] ProcedureArgument The parameter passed into Procedure for = all enabled logical processors.=0D +**/=0D +VOID=0D +CpuCacheInfoStartupAllCPUs (=0D + IN MP_SERVICES MpServices,=0D + IN EFI_AP_PROCEDURE Procedure,=0D + IN VOID *ProcedureArgument=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Proc= edure, FALSE, NULL, 0, ProcedureArgument, NULL);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Procedure (ProcedureArgument);=0D +}=0D +=0D +/**=0D + Get detailed information of the requested logical processor.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D + @param[in] ProcessorNum The requested logical processor number.= =0D + @param[out] ProcessorInfo A pointer to the buffer where the proces= sor information is stored=0D +**/=0D +VOID=0D +CpuCacheInfoGetProcessorInfo (=0D + IN MP_SERVICES MpServices,=0D + IN UINTN ProcessorNum,=0D + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D MpServices.Protocol->GetProcessorInfo (MpServices.Protocol, P= rocessorNum, ProcessorInfo);=0D + ASSERT_EFI_ERROR (Status);=0D +}=0D +=0D +/**=0D + Get the logical processor number.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D +=0D + @retval Return the logical processor number.=0D +**/=0D +UINT32=0D +CpuCacheInfoWhoAmI (=0D + IN MP_SERVICES MpServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN ProcessorNum;=0D +=0D + Status =3D MpServices.Protocol->WhoAmI (MpServices.Protocol, &ProcessorN= um);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return (UINT32)ProcessorNum;=0D +}=0D +=0D +/**=0D + Get the total number of logical processors in the platform.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D +=0D + @retval Return the total number of logical processors.=0D +**/=0D +UINT32=0D +CpuCacheInfoGetNumberOfProcessors (=0D + IN MP_SERVICES MpServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN NumberOfProcessor;=0D + UINTN NumberOfEnabledProcessor;=0D +=0D + Status =3D MpServices.Protocol->GetNumberOfProcessors (MpServices.Protoc= ol, &NumberOfProcessor, &NumberOfEnabledProcessor);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return (UINT32)NumberOfProcessor;=0D +}=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.c b/Uefi= CpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.c new file mode 100644 index 000000000000..06c160421b00 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.c @@ -0,0 +1,119 @@ +/** @file=0D + Provides cache info for each package, core type, cache level and cache t= ype.=0D +=0D + Copyright (c) 2020 Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Get EDKII_PEI_MP_SERVICES2_PPI pointer.=0D +=0D + @param[out] MpServices A pointer to the buffer where EDKII_PEI_MP_SER= VICES2_PPI is stored=0D +=0D + @retval EFI_SUCCESS EDKII_PEI_MP_SERVICES2_PPI interface is return= ed=0D + @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI interface is not fo= und=0D +**/=0D +EFI_STATUS=0D +CpuCacheInfoGetMpServices (=0D + OUT MP_SERVICES *MpServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D PeiServicesLocatePpi (&gEdkiiPeiMpServices2PpiGuid, 0, NULL, = (VOID **)&MpServices->Ppi);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Activate all of the logical processors.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D + @param[in] Procedure A pointer to the function to be run on e= nabled logical processors.=0D + @param[in] ProcedureArgument The parameter passed into Procedure for = all enabled logical processors.=0D +**/=0D +VOID=0D +CpuCacheInfoStartupAllCPUs (=0D + IN MP_SERVICES MpServices,=0D + IN EFI_AP_PROCEDURE Procedure,=0D + IN VOID *ProcedureArgument=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D MpServices.Ppi->StartupAllCPUs (MpServices.Ppi, Procedure, 0,= ProcedureArgument);=0D + ASSERT_EFI_ERROR (Status);=0D +}=0D +=0D +/**=0D + Get detailed information of the requested logical processor.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D + @param[in] ProcessorNum The requested logical processor number.= =0D + @param[out] ProcessorInfo A pointer to the buffer where the proces= sor information is stored=0D +**/=0D +VOID=0D +CpuCacheInfoGetProcessorInfo (=0D + IN MP_SERVICES MpServices,=0D + IN UINTN ProcessorNum,=0D + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D MpServices.Ppi->GetProcessorInfo (MpServices.Ppi, ProcessorNu= m, ProcessorInfo);=0D + ASSERT_EFI_ERROR (Status);=0D +}=0D +=0D +/**=0D + Get the logical processor number.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D +=0D + @retval Return the logical processor number.=0D +**/=0D +UINT32=0D +CpuCacheInfoWhoAmI (=0D + IN MP_SERVICES MpServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN ProcessorNum;=0D +=0D + Status =3D MpServices.Ppi->WhoAmI (MpServices.Ppi, &ProcessorNum);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return (UINT32)ProcessorNum;=0D +}=0D +=0D +/**=0D + Get the total number of logical processors in the platform.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D +=0D + @retval Return the total number of logical processors.=0D +**/=0D +UINT32=0D +CpuCacheInfoGetNumberOfProcessors (=0D + IN MP_SERVICES MpServices=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN NumberOfProcessor;=0D + UINTN NumberOfEnabledProcessor;=0D +=0D + Status =3D MpServices.Ppi->GetNumberOfProcessors (MpServices.Ppi, &Numbe= rOfProcessor, &NumberOfEnabledProcessor);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return (UINT32)NumberOfProcessor;=0D +}=0D diff --git a/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h b/UefiCpuPkg/Incl= ude/Library/CpuCacheInfoLib.h new file mode 100644 index 000000000000..a23b8b12b5ee --- /dev/null +++ b/UefiCpuPkg/Include/Library/CpuCacheInfoLib.h @@ -0,0 +1,76 @@ +/** @file=0D + Header file for CPU Cache info Library.=0D +=0D + Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef _CPU_CACHE_INFO_LIB_H_=0D +#define _CPU_CACHE_INFO_LIB_H_=0D +=0D +typedef struct {=0D + //=0D + // Package number.=0D + //=0D + UINT32 Package;=0D + //=0D + // Core type of logical processor.=0D + // Value =3D CPUID.1Ah:EAX[31:24]=0D + //=0D + UINT8 CoreType;=0D + //=0D + // Level of the cache that this package's this type of logical processor= corresponds to.=0D + // Value =3D CPUID.04h:EAX[07:05]=0D + //=0D + UINT8 CacheLevel : 3;=0D + //=0D + // Type of the cache that this package's this type of logical processor = corresponds to.=0D + // Value =3D CPUID.04h:EAX[04:00]=0D + //=0D + UINT8 CacheType : 5;=0D + //=0D + // Ways of associativity.=0D + // Value =3D CPUID.04h:EBX[31:22]=0D + //=0D + UINT16 CacheWays;=0D + //=0D + // Size of single cache that this package's this type of logical process= or corresponds to.=0D + // Value =3D (CPUID.04h:EBX[31:22] + 1) * (CPUID.04h:EBX[21:12] + 1) *=0D + // (CPUID.04h:EBX[11:00] + 1) * (CPUID.04h:ECX[31:00] + 1)=0D + //=0D + UINT32 CacheSizeinKB;=0D + //=0D + // Number of the cache that this package's this type of logical processo= r corresponds to.=0D + // Have subtracted the number of caches that are shared.=0D + //=0D + UINT16 CacheCount;=0D +} CPU_CACHE_INFO;=0D +=0D +/**=0D + Get CpuCacheInfo data array.=0D +=0D + @param[in, out] CpuCacheInfo Pointer to the CpuCacheInfo array.=0D + @param[in, out] CpuCacheInfoCount As input, point to the length of res= ponse CpuCacheInfo array.=0D + As output, point to the actual lengt= h of response CpuCacheInfo array.=0D +=0D + @retval EFI_SUCCESS Function completed successfully.= =0D + @retval EFI_INVALID_PARAMETER CpuCacheInfoCount is NULL.=0D + @retval EFI_INVALID_PARAMETER CpuCacheInfo is NULL while CpuCa= cheInfoCount contains the value=0D + greater than zero.=0D + @retval EFI_UNSUPPORTED Processor does not support CPUID= _CACHE_PARAMS Leaf.=0D + @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI or EF= I_MP_SERVICES_PROTOCOL interface=0D + is not found.=0D + @retval EFI_OUT_OF_RESOURCES Required resources could not be = allocated.=0D + @retval EFI_BUFFER_TOO_SMALL CpuCacheInfoCount is too small t= o hold the response CpuCacheInfo=0D + array. CpuCacheInfoCount has bee= n updated with the length needed=0D + to complete the request.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +GetCpuCacheInfo (=0D + IN OUT CPU_CACHE_INFO *CpuCacheInfo,=0D + IN OUT UINTN *CpuCacheInfoCount=0D + );=0D +=0D +#endif=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.uni b/UefiC= puPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.uni new file mode 100644 index 000000000000..1bc801f15f84 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/CpuCacheInfoLib.uni @@ -0,0 +1,15 @@ +// /** @file=0D +// CPU Cache Info Library=0D +//=0D +// Provides cache info for each package, core type, cache level and cache = type.=0D +//=0D +// Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "CPU Cache Info Li= brary"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "Provides cache in= fo for each package, core type, cache level and cache type."=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf b/Ue= fiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf new file mode 100644 index 000000000000..1fd45380b871 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf @@ -0,0 +1,43 @@ +## @file=0D +# CPU Cache Info Library instance for DXE driver.=0D +#=0D +# Provides cache info for each package, core type, cache level and cache = type.=0D +#=0D +# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D DxeCpuCacheInfoLib=0D + FILE_GUID =3D B25C288F-C309-41F1-8325-37E64DC5EA3D= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D CpuCacheInfoLib|DXE_DRIVER UEFI_APPLI= CATION=0D + MODULE_UNI_FILE =3D CpuCacheInfoLib.uni=0D +=0D +[Sources]=0D + InternalCpuCacheInfoLib.h=0D + CpuCacheInfoLib.c=0D + DxeCpuCacheInfoLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + BaseMemoryLib=0D + MemoryAllocationLib=0D + UefiBootServicesTableLib=0D +=0D +[Protocols]=0D + gEfiMpServiceProtocolGuid=0D +=0D +[Pcd]=0D +=0D +[Depex]=0D + TRUE=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h b= /UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h new file mode 100644 index 000000000000..de56db9c0cbe --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/InternalCpuCacheInfoLib.h @@ -0,0 +1,159 @@ +/** @file=0D + Internal header file for CPU Cache info Library.=0D +=0D + Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef _INTERNAL_CPU_CACHE_INFO_LIB_H_=0D +#define _INTERNAL_CPU_CACHE_INFO_LIB_H_=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +typedef struct {=0D + //=0D + // Package ID, the information comes from=0D + // EFI_CPU_PHYSICAL_LOCATION.Package=0D + //=0D + UINT32 Package;=0D + //=0D + // APIC ID, the information comes from=0D + // EFI_PROCESSOR_INFORMATION.ProcessorId=0D + //=0D + UINT32 ApicId;=0D + //=0D + // Core type of logical processor.=0D + // Value =3D CPUID.1Ah:EAX[31:24]=0D + //=0D + UINT8 CoreType;=0D +} CPUID_PROCESSOR_INFO;=0D +=0D +typedef struct {=0D + //=0D + // Level of the cache.=0D + // Value =3D CPUID.04h:EAX[07:05]=0D + //=0D + UINT8 CacheLevel : 3;=0D + //=0D + // Type of the cache.=0D + // Value =3D CPUID.04h:EAX[04:00]=0D + //=0D + UINT8 CacheType : 5;=0D + //=0D + // Ways of associativity.=0D + // Value =3D CPUID.04h:EBX[31:22]=0D + //=0D + UINT16 CacheWays;=0D + //=0D + // Cache share bits.=0D + // Value =3D CPUID.04h:EAX[25:14]=0D + //=0D + UINT16 CacheShareBits;=0D + //=0D + // Size of single cache.=0D + // Value =3D (CPUID.04h:EBX[31:22] + 1) * (CPUID.04h:EBX[21:12] + 1) *=0D + // (CPUID.04h:EBX[11:00] + 1) * (CPUID.04h:ECX[31:00] + 1)=0D + //=0D + UINT32 CacheSizeinKB;=0D +} CPUID_CACHE_DATA;=0D +=0D +typedef union {=0D + EDKII_PEI_MP_SERVICES2_PPI *Ppi;=0D + EFI_MP_SERVICES_PROTOCOL *Protocol;=0D +} MP_SERVICES;=0D +=0D +typedef struct {=0D + MP_SERVICES MpServices;=0D + CPUID_PROCESSOR_INFO *ProcessorInfo;=0D + CPUID_CACHE_DATA *CacheData;=0D +} COLLECT_CPUID_CACHE_DATA_CONTEXT;=0D +=0D +=0D +/*=0D + Defines the maximum count of Deterministic Cache Parameters Leaf of all = APs and BSP.=0D + To save boot time, skip starting up all APs to calculate each AP's count= of Deterministic=0D + Cache Parameters Leaf, so use a definition instead.=0D + Anyway, definition value will be checked in CpuCacheInfoCollectCoreAndCa= cheData function.=0D +*/=0D +#define MAX_NUM_OF_CACHE_PARAMS_LEAF 6=0D +=0D +/*=0D + Defines the maximum count of packages.=0D +*/=0D +#define MAX_NUM_OF_PACKAGE 100=0D +=0D +/**=0D + Get EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_PROTOCOL pointer.=0D +=0D + @param[out] MpServices A pointer to the buffer where EDKII_PEI_MP_SER= VICES2_PPI or=0D + EFI_MP_SERVICES_PROTOCOL is stored=0D +=0D + @retval EFI_SUCCESS EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_= PROTOCOL interface is returned=0D + @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI or EFI_MP_SERVICES_= PROTOCOL interface is not found=0D +**/=0D +EFI_STATUS=0D +CpuCacheInfoGetMpServices (=0D + OUT MP_SERVICES *MpServices=0D + );=0D +=0D +/**=0D + Activate all of the logical processors.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D + @param[in] Procedure A pointer to the function to be run on e= nabled logical processors.=0D + @param[in] ProcedureArgument The parameter passed into Procedure for = all enabled logical processors.=0D +**/=0D +VOID=0D +CpuCacheInfoStartupAllCPUs (=0D + IN MP_SERVICES MpServices,=0D + IN EFI_AP_PROCEDURE Procedure,=0D + IN VOID *ProcedureArgument=0D + );=0D +=0D +/**=0D + Get detailed information of the requested logical processor.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D + @param[in] ProcessorNum The requested logical processor number.= =0D + @param[out] ProcessorInfo A pointer to the buffer where the proces= sor information is stored=0D +**/=0D +VOID=0D +CpuCacheInfoGetProcessorInfo (=0D + IN MP_SERVICES MpServices,=0D + IN UINTN ProcessorNum,=0D + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo=0D + );=0D +=0D +/**=0D + Get the logical processor number.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D +=0D + @retval Return the logical processor number.=0D +**/=0D +UINT32=0D +CpuCacheInfoWhoAmI (=0D + IN MP_SERVICES MpServices=0D + );=0D +=0D +/**=0D + Get the total number of logical processors in the platform.=0D +=0D + @param[in] MpServices MP_SERVICES structure.=0D +=0D + @retval Return the total number of logical processors.=0D +**/=0D +UINT32=0D +CpuCacheInfoGetNumberOfProcessors (=0D + IN MP_SERVICES MpServices=0D + );=0D +#endif=0D diff --git a/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf b/Ue= fiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf new file mode 100644 index 000000000000..c8aa33c95a8f --- /dev/null +++ b/UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf @@ -0,0 +1,43 @@ +## @file=0D +# CPU Cache Info Library instance for PEI module.=0D +#=0D +# Provides cache info for each package, core type, cache level and cache = type.=0D +#=0D +# Copyright (c) 2020, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D PeiCpuCacheInfoLib=0D + FILE_GUID =3D CFEE2DBE-53B2-4916-84CA-0BA83C3DDA6E= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D CpuCacheInfoLib|PEIM=0D + MODULE_UNI_FILE =3D CpuCacheInfoLib.uni=0D +=0D +[Sources]=0D + InternalCpuCacheInfoLib.h=0D + CpuCacheInfoLib.c=0D + PeiCpuCacheInfoLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + BaseMemoryLib=0D + MemoryAllocationLib=0D + PeiServicesTablePointerLib=0D +=0D +[Ppis]=0D + gEdkiiPeiMpServices2PpiGuid=0D +=0D +[Pcd]=0D +=0D +[Depex]=0D + TRUE=0D diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index d83c084467b3..a639ce5412e4 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -56,6 +56,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Provides function to support VMGEXIT processing.=0D VmgExitLib|Include/Library/VmgExitLib.h=0D =0D + ## @libraryclass Provides function to get CPU cache information.=0D + CpuCacheInfoLib|Include/Library/CpuCacheInfoLib.h=0D +=0D [Guids]=0D gUefiCpuPkgTokenSpaceGuid =3D { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,= 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}=0D gMsegSmramGuid =3D { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,= 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}=0D diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index b2b6d78a71b0..5834eafaa200 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -75,6 +75,7 @@ [LibraryClasses.common.PEIM] LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf=0D MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf=0D RegisterCpuFeaturesLib|UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegi= sterCpuFeaturesLib.inf=0D + CpuCacheInfoLib|UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.in= f=0D =0D [LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM]=0D PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/= PeiServicesTablePointerLibIdt.inf=0D @@ -86,6 +87,7 @@ [LibraryClasses.common.DXE_DRIVER] CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf=0D MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf=0D RegisterCpuFeaturesLib|UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegi= sterCpuFeaturesLib.inf=0D + CpuCacheInfoLib|UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.in= f=0D =0D [LibraryClasses.common.DXE_SMM_DRIVER]=0D SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableL= ib.inf=0D @@ -109,6 +111,8 @@ [Components] UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf=0D UefiCpuPkg/Library/CpuTimerLib/DxeCpuTimerLib.inf=0D UefiCpuPkg/Library/CpuTimerLib/PeiCpuTimerLib.inf=0D + UefiCpuPkg/Library/CpuCacheInfoLib/PeiCpuCacheInfoLib.inf=0D + UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.inf=0D =0D [Components.IA32, Components.X64]=0D UefiCpuPkg/CpuDxe/CpuDxe.inf=0D --=20 2.28.0.windows.1