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.web10.24257.1638621073372547167 for ; Sat, 04 Dec 2021 04:31:13 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: chandni.cherukuri@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 0C70B6D; Sat, 4 Dec 2021 04:31:13 -0800 (PST) Received: from usa.arm.com (a074744.blr.arm.com [10.162.17.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 60FC83F766; Sat, 4 Dec 2021 04:31:11 -0800 (PST) From: "chandni cherukuri" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Sami Mujawar , Chandni Cherukuri Subject: [edk2-platforms][PATCH V1 10/11] Platform/ARM/Morello: Add support to parse NT_FW_CONFIG Date: Sat, 4 Dec 2021 18:00:41 +0530 Message-Id: <20211204123042.32140-11-chandni.cherukuri@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211204123042.32140-1-chandni.cherukuri@arm.com> References: <20211204123042.32140-1-chandni.cherukuri@arm.com> From: sah01 Support has been added to parse NT_FW_CONFIG DTB to get the platform information. Signed-off-by: sahil Signed-off-by: Chandni Cherukuri --- Platform/ARM/Morello/MorelloPlatform.dec | 5 + Platform/ARM/Morello/Library/PlatformLib/PlatformLibFvp.inf | 6 ++ Platform/ARM/Morello/Library/PlatformLib/PlatformLibSoc.inf | 6 ++ Platform/ARM/Morello/Include/MorelloPlatform.h | 18 +++- Platform/ARM/Morello/Library/PlatformLib/PlatformLib.c | 9 ++ Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemFvp.c | 74 ++++++++++++- Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemSoc.c | 113 +++++++++++++++++++- Platform/ARM/Morello/Library/PlatformLib/AArch64/Helper.S | 2 + 8 files changed, 225 insertions(+), 8 deletions(-) diff --git a/Platform/ARM/Morello/MorelloPlatform.dec b/Platform/ARM/Morello/MorelloPlatform.dec index 07701e7611b8..3aec23b03b00 100644 --- a/Platform/ARM/Morello/MorelloPlatform.dec +++ b/Platform/ARM/Morello/MorelloPlatform.dec @@ -22,6 +22,8 @@ Include # Root include for the package [Guids.common] + # ARM Morello Platform Info descriptor + gArmMorelloPlatformInfoDescriptorGuid = { 0x891422EF, 0x5377, 0x459E, { 0xA5, 0x42, 0x7A, 0xA2, 0x1A, 0x55, 0x54, 0x7F } } gArmMorelloTokenSpaceGuid = { 0x0A8C3A78, 0xA56F, 0x4788, { 0x83, 0xB4, 0xCD, 0x29, 0x62, 0x96, 0x77, 0x51 } } [PcdsFixedAtBuild] @@ -82,3 +84,6 @@ gArmMorelloTokenSpaceGuid.PcdRamDiskSupported|FALSE|BOOLEAN|0x00000007 gArmMorelloTokenSpaceGuid.PcdVirtioBlkSupported|FALSE|BOOLEAN|0x00000008 gArmMorelloTokenSpaceGuid.PcdVirtioNetSupported|FALSE|BOOLEAN|0x0000002C + +[Ppis] + gNtFwConfigDtInfoPpiGuid = { 0x8E289A83, 0x44E1, 0x41CF, { 0xA7, 0x41, 0x83, 0x80, 0x89, 0x23, 0x43, 0xA3 } } diff --git a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibFvp.inf b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibFvp.inf index d4c8744c0954..0f87a18da184 100644 --- a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibFvp.inf +++ b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibFvp.inf @@ -18,10 +18,14 @@ [Packages] ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec Platform/ARM/Morello/MorelloPlatform.dec +[LibraryClasses] + FdtLib + [Sources.common] PlatformLib.c PlatformLibMemFvp.c @@ -46,7 +50,9 @@ gArmTokenSpaceGuid.PcdSystemMemorySize [Guids] + gArmMorelloPlatformInfoDescriptorGuid gEfiHobListGuid ## CONSUMES ## SystemTable [Ppis] gArmMpCoreInfoPpiGuid + gNtFwConfigDtInfoPpiGuid diff --git a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibSoc.inf b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibSoc.inf index 0a36a5fe50a5..cc0687ebcaaa 100644 --- a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibSoc.inf +++ b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibSoc.inf @@ -18,10 +18,14 @@ [Packages] ArmPkg/ArmPkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + EmbeddedPkg/EmbeddedPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec Platform/ARM/Morello/MorelloPlatform.dec +[LibraryClasses] + FdtLib + [Sources.common] PlatformLib.c PlatformLibMemSoc.c @@ -56,7 +60,9 @@ gArmTokenSpaceGuid.PcdSystemMemorySize [Guids] + gArmMorelloPlatformInfoDescriptorGuid gEfiHobListGuid ## CONSUMES ## SystemTable [Ppis] gArmMpCoreInfoPpiGuid + gNtFwConfigDtInfoPpiGuid diff --git a/Platform/ARM/Morello/Include/MorelloPlatform.h b/Platform/ARM/Morello/Include/MorelloPlatform.h index 8b3233025958..c55bb04445cb 100644 --- a/Platform/ARM/Morello/Include/MorelloPlatform.h +++ b/Platform/ARM/Morello/Include/MorelloPlatform.h @@ -51,13 +51,23 @@ */ #pragma pack(1) +typedef struct { + UINT64 LocalDdrSize; ///< Local DDR memory size in Bytes + UINT64 RemoteDdrSize; ///< Remote DDR memory size in Bytes + UINT8 RemoteChipCount; ///< Remote chip count in C2C mode + UINT8 Mode; ///< 0 - Single Chip, 1 - Chip to Chip (C2C) + UINT32 SccConfig; ///< Contains SCC configuration from BOOT_GPR1 register +} MORELLO_PLAT_INFO_SOC; + typedef struct { UINT64 LocalDdrSize; ///< Local DDR memory size in Bytes - UINT64 RemoteDdrSize; ///< Remote DDR memory size in Bytes - UINT8 SlaveCount; ///< Slave count in C2C mode - UINT8 Mode; ///< 0 - Single Chip, 1 - Chip to Chip (C2C) -} MORELLO_PLAT_INFO; +} MORELLO_PLAT_INFO_FVP; #pragma pack() +// NT_FW_CONFIG DT structure +typedef struct { + UINT64 NtFwConfigDtAddr; +} MORELLO_NT_FW_CONFIG_INFO_PPI; + #endif //MORELLO_PLATFORM_H_ diff --git a/Platform/ARM/Morello/Library/PlatformLib/PlatformLib.c b/Platform/ARM/Morello/Library/PlatformLib/PlatformLib.c index 52318a62911a..b46b3fcc2a7b 100644 --- a/Platform/ARM/Morello/Library/PlatformLib/PlatformLib.c +++ b/Platform/ARM/Morello/Library/PlatformLib/PlatformLib.c @@ -8,7 +8,10 @@ #include #include #include +#include +UINT64 NtFwConfigDtBlob; +STATIC MORELLO_NT_FW_CONFIG_INFO_PPI mNtFwConfigDtInfoPpi; STATIC ARM_CORE_INFO mCoreInfoTable[] = { { 0x0, 0x0 }, // Cluster 0, Core 0 { 0x0, 0x1 }, // Cluster 0, Core 1 @@ -44,6 +47,7 @@ ArmPlatformInitialize ( IN UINTN MpId ) { + mNtFwConfigDtInfoPpi.NtFwConfigDtAddr = NtFwConfigDtBlob; return RETURN_SUCCESS; } @@ -76,6 +80,11 @@ STATIC EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = { EFI_PEI_PPI_DESCRIPTOR_PPI, &gArmMpCoreInfoPpiGuid, &mMpCoreInfoPpi + }, + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gNtFwConfigDtInfoPpiGuid, + &mNtFwConfigDtInfoPpi } }; diff --git a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemFvp.c b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemFvp.c index 54a870cfb3ba..9c1da9a25fcd 100644 --- a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemFvp.c +++ b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemFvp.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include // The total number of descriptors, including the final "end-of-table" descriptor. @@ -39,6 +41,60 @@ STATIC CONST CHAR8 *gTblAttrDesc[] = { gTblAttrDesc[VirtualMemoryTable[Index].Attributes] \ )); +/** A helper function to locate the NtFwConfig PPI and get the base address of + NT_FW_CONFIG DT from which values are obtained using FDT helper functions. + + @param [out] plat_info Pointer to the MORELLO PLATFORM_INFO HOB + + @retval EFI_SUCCESS Success. + returns EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +GetMorelloPlatInfo ( + OUT MORELLO_PLAT_INFO_FVP *plat_info +) +{ + CONST UINT64 *Property; + INT32 Offset; + CONST VOID *NtFwCfgDtBlob; + MORELLO_NT_FW_CONFIG_INFO_PPI *NtFwConfigInfoPpi; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi ( + &gNtFwConfigDtInfoPpiGuid, + 0, + NULL, + (VOID**)&NtFwConfigInfoPpi + ); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "PeiServicesLocatePpi failed with error %r\n", Status)); + return EFI_INVALID_PARAMETER; + } + + NtFwCfgDtBlob = (VOID *)(UINTN)NtFwConfigInfoPpi->NtFwConfigDtAddr; + if (fdt_check_header (NtFwCfgDtBlob) != 0) { + DEBUG ((DEBUG_ERROR, "Invalid DTB file %p passed\n", NtFwCfgDtBlob)); + return EFI_INVALID_PARAMETER; + } + + Offset = fdt_subnode_offset (NtFwCfgDtBlob, 0, "platform-info"); + if (Offset == -FDT_ERR_NOTFOUND) { + DEBUG ((DEBUG_ERROR, "Invalid DTB : platform-info node not found\n")); + return EFI_INVALID_PARAMETER; + } + + Property = fdt_getprop (NtFwCfgDtBlob, Offset, "local-ddr-size", NULL); + if (Property == NULL) { + DEBUG ((DEBUG_ERROR, "local-ddr-size property not found\n")); + return EFI_INVALID_PARAMETER; + } + + plat_info->LocalDdrSize = fdt64_to_cpu (ReadUnaligned64 (Property)); + return EFI_SUCCESS; +} + /** Returns the Virtual Memory Map of the platform. @@ -57,13 +113,27 @@ ArmPlatformGetVirtualMemoryMap ( UINTN Index; ARM_MEMORY_REGION_DESCRIPTOR * VirtualMemoryTable; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; - MORELLO_PLAT_INFO * PlatInfo; + MORELLO_PLAT_INFO_FVP * PlatInfo; UINT64 DramBlock2Size; + EFI_STATUS Status; Index = 0; DramBlock2Size = 0; - PlatInfo = (MORELLO_PLAT_INFO *)MORELLO_PLAT_INFO_STRUCT_BASE; + // Create platform info HOB + PlatInfo = (MORELLO_PLAT_INFO_FVP *)BuildGuidHob ( + &gArmMorelloPlatformInfoDescriptorGuid, + sizeof (MORELLO_PLAT_INFO_FVP) + ); + if (PlatInfo == NULL) { + DEBUG ((DEBUG_ERROR, "Platform HOB is NULL\n")); + ASSERT (FALSE); + return; + } + + Status = GetMorelloPlatInfo (PlatInfo); + ASSERT (Status == 0); + if (PlatInfo->LocalDdrSize > MORELLO_DRAM_BLOCK1_SIZE) { DramBlock2Size = PlatInfo->LocalDdrSize - MORELLO_DRAM_BLOCK1_SIZE; } diff --git a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemSoc.c b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemSoc.c index 5140764c54bc..49e4994176a9 100644 --- a/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemSoc.c +++ b/Platform/ARM/Morello/Library/PlatformLib/PlatformLibMemSoc.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include // The total number of descriptors, including the final "end-of-table" descriptor. @@ -39,6 +41,97 @@ gTblAttrDesc[VirtualMemoryTable[Index].Attributes] \ )); +/** A helper function to locate the NtFwConfig PPI and get the base address of + NT_FW_CONFIG DT from which values are obtained using FDT helper functions. + + @param [out] plat_info Pointer to the MORELLO PLATFORM_INFO HOB + + @retval EFI_SUCCESS Success. + returns EFI_INVALID_PARAMETER A parameter is invalid. +**/ +EFI_STATUS +GetMorelloPlatInfo ( + OUT MORELLO_PLAT_INFO_SOC *plat_info + ) +{ + CONST UINT32 *Property; + CONST UINT64 *DdrProperty; + INT32 Offset; + CONST VOID *NtFwCfgDtBlob; + MORELLO_NT_FW_CONFIG_INFO_PPI *NtFwConfigInfoPpi; + EFI_STATUS Status; + + Status = PeiServicesLocatePpi ( + &gNtFwConfigDtInfoPpiGuid, + 0, + NULL, + (VOID **)&NtFwConfigInfoPpi + ); + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "PeiServicesLocatePpi failed with error %r\n", + Status + )); + return EFI_INVALID_PARAMETER; + } + + NtFwCfgDtBlob = (VOID *)(UINTN)NtFwConfigInfoPpi->NtFwConfigDtAddr; + if (fdt_check_header (NtFwCfgDtBlob) != 0) { + DEBUG ((DEBUG_ERROR, "Invalid DTB file %p passed\n", NtFwCfgDtBlob)); + return EFI_INVALID_PARAMETER; + } + + Offset = fdt_subnode_offset (NtFwCfgDtBlob, 0, "platform-info"); + if (Offset == -FDT_ERR_NOTFOUND) { + DEBUG ((DEBUG_ERROR, "Invalid DTB : platform-info node not found\n")); + return EFI_INVALID_PARAMETER; + } + + DdrProperty = fdt_getprop (NtFwCfgDtBlob, Offset, "local-ddr-size", NULL); + if (DdrProperty == NULL) { + DEBUG ((DEBUG_ERROR, "local-ddr-size property not found\n")); + return EFI_INVALID_PARAMETER; + } + + plat_info->LocalDdrSize = fdt64_to_cpu (ReadUnaligned64 (DdrProperty)); + + DdrProperty = fdt_getprop (NtFwCfgDtBlob, Offset, "remote-ddr-size", NULL); + if (DdrProperty == NULL) { + DEBUG ((DEBUG_ERROR, "remote-ddr-size property not found\n")); + return EFI_INVALID_PARAMETER; + } + + plat_info->RemoteDdrSize = fdt64_to_cpu (ReadUnaligned64 (DdrProperty)); + + Property = fdt_getprop (NtFwCfgDtBlob, Offset, "remote-chip-count", NULL); + if (Property == NULL) { + DEBUG ((DEBUG_ERROR, "remote-chip-count property not found\n")); + return EFI_INVALID_PARAMETER; + } + + plat_info->RemoteChipCount = fdt32_to_cpu (*Property); + + Property = fdt_getprop (NtFwCfgDtBlob, Offset, "multichip-mode", NULL); + if (Property == NULL) { + DEBUG ((DEBUG_ERROR, "multichip-mode property not found\n")); + return EFI_INVALID_PARAMETER; + } + + plat_info->Mode = fdt32_to_cpu (*Property); + + Property = fdt_getprop (NtFwCfgDtBlob, Offset, "scc-config", NULL); + if (Property == NULL) { + DEBUG ((DEBUG_ERROR, "scc-config property not found\n")); + return EFI_INVALID_PARAMETER; + } + + plat_info->SccConfig = fdt32_to_cpu (*Property); + + return EFI_SUCCESS; +} + /** Returns the Virtual Memory Map of the platform. @@ -57,17 +150,33 @@ ArmPlatformGetVirtualMemoryMap ( UINTN Index; ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; - MORELLO_PLAT_INFO *PlatInfo; + MORELLO_PLAT_INFO_SOC *PlatInfo; UINT64 DramBlock2Size; + EFI_STATUS Status; Index = 0; DramBlock2Size = 0; - PlatInfo = (MORELLO_PLAT_INFO *)MORELLO_PLAT_INFO_STRUCT_BASE; + // Create platform info HOB + PlatInfo = (MORELLO_PLAT_INFO_SOC *)BuildGuidHob ( + &gArmMorelloPlatformInfoDescriptorGuid, + sizeof (MORELLO_PLAT_INFO_SOC) + ); + + if (PlatInfo == NULL) { + DEBUG ((DEBUG_ERROR, "Platform HOB is NULL\n")); + ASSERT (FALSE); + return; + } + + Status = GetMorelloPlatInfo (PlatInfo); + ASSERT (Status == 0); + if (PlatInfo->LocalDdrSize > MORELLO_DRAM_BLOCK1_SIZE) { DramBlock2Size = PlatInfo->LocalDdrSize - MORELLO_DRAM_BLOCK1_SIZE; } + DEBUG ((DEBUG_ERROR, "DramBlock2Size is 0x%lx\n", DramBlock2Size)); if (DramBlock2Size != 0) { ResourceAttributes = EFI_RESOURCE_ATTRIBUTE_PRESENT | diff --git a/Platform/ARM/Morello/Library/PlatformLib/AArch64/Helper.S b/Platform/ARM/Morello/Library/PlatformLib/AArch64/Helper.S index 0bc624dfd2b4..d71cab916c75 100644 --- a/Platform/ARM/Morello/Library/PlatformLib/AArch64/Helper.S +++ b/Platform/ARM/Morello/Library/PlatformLib/AArch64/Helper.S @@ -19,6 +19,8 @@ // the UEFI firmware through the CPU registers. // ASM_FUNC(ArmPlatformPeiBootAction) + adr x10, NtFwConfigDtBlob + str x0, [x10] ret // -- 2.17.1