From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.26833.1683292720492435873 for ; Fri, 05 May 2023 06:18:40 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7E2161FB; Fri, 5 May 2023 06:19:24 -0700 (PDT) Received: from e126645.arm.com (e126645.nice.arm.com [10.34.100.110]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6AC4E3F64C; Fri, 5 May 2023 06:18:39 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Thomas Abraham , Sami Mujawar Subject: [PATCH v1 3/3] Platform/ARM: Juno: Generate _CPC objects for JunoR2 Date: Fri, 5 May 2023 15:18:30 +0200 Message-Id: <20230505131830.1310792-4-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230505131830.1310792-1-Pierre.Gondois@arm.com> References: <20230505131830.1310792-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pierre Gondois The SsdtCpuTopologyGenerator can generate _CPC objects. This is done by querying the SCP for the relevant performance state information through SCMI. CM_ARM_CPC_INFO are then populated and used to generate _CPC objects in the Ssdt Cpu topology. Use the ArmScmiInfoLib and add the handling to generate _CPC information. Note that using _CPC is only possible if SCP is correctly tuned to advertise performance levels on an abstract and unified scale. A basic check is done to prevent the _CPC generation otherwise. The following performance level values where used for testing: - little CPUs OPPs: [181, 322, 383] * 1000 - big CPUs OPPs: [512, 833, 1024] * 1024 Signed-off-by: Pierre Gondois --- .../ConfigurationManager.c | 237 +++++++++++++++++- .../ConfigurationManager.h | 10 + .../ConfigurationManagerDxe.inf | 1 + 3 files changed, 245 insertions(+), 3 deletions(-) diff --git a/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManag= erDxe/ConfigurationManager.c b/Platform/ARM/JunoPkg/ConfigurationManager/= ConfigurationManagerDxe/ConfigurationManager.c index 2b881e61be50..971efc17c8f7 100644 --- a/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManagerDxe/C= onfigurationManager.c +++ b/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManagerDxe/C= onfigurationManager.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -756,6 +757,8 @@ EDKII_PLATFORM_REPOSITORY_INFO ArmJunoPlatformReposit= oryInfo =3D { 4, }, }, + { // CPC info, dynamically populated. + }, }; =20 /** A helper function for returning the Configuration Manager Objects. @@ -1212,6 +1215,60 @@ GetPsdInfo ( return EFI_SUCCESS; } =20 +/** Return Cpc Info. + + @param [in] This Pointer to the Configuration Manager P= rotocol. + @param [in] CmObjectId The Object ID of the CM object request= ed + @param [in] SearchToken A unique token for identifying the req= uested + CM_ARM_PCI_INTERRUPT_MAP_INFO object. + @param [in, out] CmObject Pointer to the Configuration Manager O= bject + descriptor describing the requested Ob= ject. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object information is not= found. +**/ +EFI_STATUS +EFIAPI +GetCpcInfo ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST This, + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN SearchToken, + IN OUT CM_OBJ_DESCRIPTOR * CONST CmObject + ) +{ + EDKII_PLATFORM_REPOSITORY_INFO * PlatformRepo; + UINT32 TotalObjCount; + UINT32 ObjIndex; + + if ((This =3D=3D NULL) || (CmObject =3D=3D NULL)) { + ASSERT (This !=3D NULL); + ASSERT (CmObject !=3D NULL); + return EFI_INVALID_PARAMETER; + } + + PlatformRepo =3D This->PlatRepoInfo; + + if (PlatformRepo->JunoRevision !=3D JUNO_REVISION_R2) { + /* Only support _CPC generation on Juno R2 for now. */ + return EFI_UNSUPPORTED; + } + + TotalObjCount =3D ARRAY_SIZE (PlatformRepo->CpcInfo); + + for (ObjIndex =3D 0; ObjIndex < TotalObjCount; ObjIndex++) { + if (SearchToken =3D=3D (CM_OBJECT_TOKEN)&PlatformRepo->CpcInfo[ObjIn= dex]) { + CmObject->ObjectId =3D CmObjectId; + CmObject->Size =3D sizeof (PlatformRepo->CpcInfo[ObjIndex]); + CmObject->Data =3D (VOID*)&PlatformRepo->CpcInfo[ObjIndex]; + CmObject->Count =3D 1; + return EFI_SUCCESS; + } + } + + return EFI_SUCCESS; +} + /** Return a list of Configuration Manager object references pointed to = by the given input token. =20 @@ -1621,6 +1678,19 @@ GetArmNameSpaceObject ( ); break; =20 + case EArmObjCpcInfo: + Status =3D HandleCmObjectRefByToken ( + This, + CmObjectId, + PlatformRepo->CpcInfo, + sizeof (PlatformRepo->CpcInfo), + ARRAY_SIZE (PlatformRepo->CpcInfo), + Token, + GetCpcInfo, + CmObject + ); + break; + default: { Status =3D EFI_NOT_FOUND; DEBUG (( @@ -1776,6 +1846,150 @@ EDKII_CONFIGURATION_MANAGER_PROTOCOL ArmJunoPlatf= ormConfigManagerProtocol =3D { &ArmJunoPlatformRepositoryInfo }; =20 +/** Clear Cpc information. + + If populating _CPC information fails, remove GicC tokens pointing + to Cpc CmObj to avoid creating corrupted _CPC objects. + + @param [in] PlatformRepo Platfom Info repository. + + @retval EFI_SUCCESS Success. +**/ +STATIC +EFI_STATUS +EFIAPI +ClearCpcInfo ( + EDKII_PLATFORM_REPOSITORY_INFO *PlatformRepo + ) +{ + CM_ARM_GICC_INFO *GicCInfo; + + GicCInfo =3D (CM_ARM_GICC_INFO*)&PlatformRepo->GicCInfo; + + GicCInfo[0].CpcToken =3D CM_NULL_TOKEN; + GicCInfo[1].CpcToken =3D CM_NULL_TOKEN; + GicCInfo[2].CpcToken =3D CM_NULL_TOKEN; + GicCInfo[3].CpcToken =3D CM_NULL_TOKEN; + GicCInfo[4].CpcToken =3D CM_NULL_TOKEN; + GicCInfo[5].CpcToken =3D CM_NULL_TOKEN; + + return EFI_SUCCESS; +} + +/** Use the SCMI protocol to populate CPC objects dynamically. + + @param [in] PlatformRepo Platfom Info repository. + @param [in] DomainId Id of the DVFS domain to probe. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_UNSUPPORTED Not supported. + @retval !(EFI_SUCCESS) An error occured. +**/ +STATIC +EFI_STATUS +EFIAPI +PopulateCpcInfo ( + EDKII_PLATFORM_REPOSITORY_INFO *PlatformRepo, + IN UINT32 DomainId + ) +{ + EFI_STATUS Status; + CM_ARM_GICC_INFO *GicCInfo; + AML_CPC_INFO *CpcInfo; + + if ((PlatformRepo =3D=3D NULL) || + ((DomainId !=3D PSD_BIG_DOMAIN_ID) && + (DomainId !=3D PSD_LITTLE_DOMAIN_ID))) { + Status =3D EFI_INVALID_PARAMETER; + ASSERT_EFI_ERROR (Status); + return Status; + } + + if (PlatformRepo->JunoRevision !=3D JUNO_REVISION_R2) { + /* Available frequencies are different on Juno R[0|1|2]. _CPC was + * only tested on Juno R2, so only enable support for this version. + */ + return EFI_UNSUPPORTED; + } + + CpcInfo =3D &PlatformRepo->CpcInfo[DomainId]; + GicCInfo =3D (CM_ARM_GICC_INFO*)&PlatformRepo->GicCInfo; + + Status =3D ArmScmiInfoGetFastChannel ( + PlatformRepo->PsdInfo[DomainId].Domain, + CpcInfo + ); + if (EFI_ERROR (Status)) { + return Status; + } + + /* CPPC must advertise performances on a 'continuous, abstract, unit-l= ess + performance scale', i.e. CPU performances on an asymmetric platform + nust be represented on a unified scale. + CPU performance values are obtained from SCP through SCMI and adver= tised + to the OS via the _CPC objects. SCP currently maps performance requ= ests + to frequency requests. + Thus, SCP must be modified to advertise (and correctly handle) + performance values on a unified scale. + + Check that SCP is using a unified scale by checking that the advert= ised + lowest/nominal frequencies are not the default ones. + */ + if (((DomainId =3D=3D PSD_BIG_DOMAIN_ID) && + (CpcInfo->LowestPerformanceInteger =3D=3D HZ_TO_KHZ(JUNO_R2_BIG_L= OWEST_FREQ)) && + (CpcInfo->NominalPerformanceInteger =3D=3D HZ_TO_KHZ(JUNO_R2_BIG_= NOMINAL_FREQ))) || + ((DomainId =3D=3D PSD_LITTLE_DOMAIN_ID) && + (CpcInfo->LowestPerformanceInteger =3D=3D HZ_TO_KHZ(JUNO_R2_LITTL= E_LOWEST_FREQ)) && + (CpcInfo->NominalPerformanceInteger =3D=3D HZ_TO_KHZ(JUNO_R2_LITT= LE_NOMINAL_FREQ)))) { + return EFI_UNSUPPORTED; + } + + // Juno R2's lowest/nominal frequencies. + // Nominal frequency !=3D Highest frequency. + if (DomainId =3D=3D PSD_BIG_DOMAIN_ID) { + CpcInfo->LowestFrequencyInteger =3D JUNO_R2_BIG_LOWEST_FREQ; + CpcInfo->NominalFrequencyInteger =3D JUNO_R2_BIG_NOMINAL_FREQ; + } else { + CpcInfo->LowestFrequencyInteger =3D JUNO_R2_LITTLE_LOWEST_FREQ; + CpcInfo->NominalFrequencyInteger =3D JUNO_R2_LITTLE_NOMINAL_FREQ; + } + + // The mapping Psd -> CPUs is available here. + if (DomainId =3D=3D PSD_BIG_DOMAIN_ID) { + GicCInfo[0].CpcToken =3D (CM_OBJECT_TOKEN)CpcInfo; + GicCInfo[1].CpcToken =3D (CM_OBJECT_TOKEN)CpcInfo; + } else { + GicCInfo[2].CpcToken =3D (CM_OBJECT_TOKEN)CpcInfo; + GicCInfo[3].CpcToken =3D (CM_OBJECT_TOKEN)CpcInfo; + GicCInfo[4].CpcToken =3D (CM_OBJECT_TOKEN)CpcInfo; + GicCInfo[5].CpcToken =3D (CM_OBJECT_TOKEN)CpcInfo; + } + + /* + Arm advises to use FFH to the following registers which uses AMU cou= nters: + - ReferencePerformanceCounterRegister + - DeliveredPerformanceCounterRegister + Cf. Arm Functional Fixed Hardware Specification + s3.2 Performance management and Collaborative Processor Performance = Control + + Since, AMU is not supported by the Juno, clear these registers. + */ + CpcInfo->ReferencePerformanceCounterRegister.AddressSpaceId =3D EFI_AC= PI_6_4_SYSTEM_MEMORY; + CpcInfo->ReferencePerformanceCounterRegister.RegisterBitWidth =3D 0; + CpcInfo->ReferencePerformanceCounterRegister.RegisterBitOffset =3D 0; + CpcInfo->ReferencePerformanceCounterRegister.AccessSize =3D 0; + CpcInfo->ReferencePerformanceCounterRegister.Address =3D 0; + + CpcInfo->DeliveredPerformanceCounterRegister.AddressSpaceId =3D EFI_AC= PI_6_4_SYSTEM_MEMORY; + CpcInfo->DeliveredPerformanceCounterRegister.RegisterBitWidth =3D 0; + CpcInfo->DeliveredPerformanceCounterRegister.RegisterBitOffset =3D 0; + CpcInfo->DeliveredPerformanceCounterRegister.AccessSize =3D 0; + CpcInfo->DeliveredPerformanceCounterRegister.Address =3D 0; + + return Status; +} + /** Entrypoint of Configuration Manager Dxe. =20 @@ -1795,6 +2009,8 @@ ConfigurationManagerDxeInitialize ( ) { EFI_STATUS Status; + UINT32 Index; + BOOLEAN CpcFailed; =20 Status =3D gBS->InstallProtocolInterface ( &ImageHandle, @@ -1809,7 +2025,7 @@ ConfigurationManagerDxeInitialize ( " Status =3D %r\n", Status )); - goto error_handler; + return Status; } =20 Status =3D InitializePlatformRepository ( @@ -1824,6 +2040,21 @@ ConfigurationManagerDxeInitialize ( )); } =20 -error_handler: - return Status; + CpcFailed =3D FALSE; + for (Index =3D 0; Index < PSD_DOMAIN_COUNT; Index++) { + Status =3D PopulateCpcInfo (&ArmJunoPlatformRepositoryInfo, Index); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "WARN: Could not populate _CPC.\n")); + CpcFailed =3D TRUE; + break; + } + } + + if (CpcFailed) { + // _CPC information is not mandatory and SCP might not support some + // SCMI requests. Failing should not prevent from booting. + ClearCpcInfo (&ArmJunoPlatformRepositoryInfo); + } + + return EFI_SUCCESS; } diff --git a/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManag= erDxe/ConfigurationManager.h b/Platform/ARM/JunoPkg/ConfigurationManager/= ConfigurationManagerDxe/ConfigurationManager.h index 4082a6f059a5..4c4643b56c96 100644 --- a/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManagerDxe/C= onfigurationManager.h +++ b/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManagerDxe/C= onfigurationManager.h @@ -211,6 +211,13 @@ typedef EFI_STATUS (*CM_OBJECT_HANDLER_PROC) ( #define PSD_LITTLE_DOMAIN_ID 1 #define PSD_DOMAIN_COUNT 2 =20 +/* JUNO R2 frequency values, in KHz. */ +#define JUNO_R2_BIG_LOWEST_FREQ (600000) +#define JUNO_R2_BIG_NOMINAL_FREQ (1000000) +#define JUNO_R2_LITTLE_LOWEST_FREQ (450000) +#define JUNO_R2_LITTLE_NOMINAL_FREQ (800000) +#define HZ_TO_KHZ(Freq) (Freq * 1000) + /** A structure describing the platform configuration manager repository information */ @@ -301,6 +308,9 @@ typedef struct PlatformRepositoryInfo { // Power domains CM_ARM_PSD_INFO PsdInfo[PSD_DOMAIN_COUNT]; =20 + // Cpc info (1 for each PSD domain) + CM_ARM_CPC_INFO CpcInfo[PSD_DOMAIN_COUNT]; + /// Juno Board Revision UINT32 JunoRevision; } EDKII_PLATFORM_REPOSITORY_INFO; diff --git a/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManag= erDxe/ConfigurationManagerDxe.inf b/Platform/ARM/JunoPkg/ConfigurationMan= ager/ConfigurationManagerDxe/ConfigurationManagerDxe.inf index 91bffe8d5d82..688996549337 100644 --- a/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManagerDxe/C= onfigurationManagerDxe.inf +++ b/Platform/ARM/JunoPkg/ConfigurationManager/ConfigurationManagerDxe/C= onfigurationManagerDxe.inf @@ -35,6 +35,7 @@ [Packages] =20 [LibraryClasses] ArmPlatformLib + ArmScmiInfoLib PrintLib UefiBootServicesTableLib UefiDriverEntryPoint --=20 2.25.1