From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 37CEBAC11AE for ; Fri, 19 Jan 2024 19:22:22 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SCZRgdX9YYhvIu1lUrINpm7KEtOS2PvbhWXyzbvCF70=; c=relaxed/simple; d=groups.io; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Disposition; s=20140610; t=1705692140; v=1; b=OSUCQaMUCTiEBlU0oDXkjNr0rIm0DPi1mQKGiPfz36zU16Hn2rSrMR6GTHQCjjmtac9kwwu+ TiBr4pu3+UbWNpa/pMbAQMmVPo+jXCpV7vQjNlkI5Ejk0GCOTFbZzMy3T/aqfBYoQxsw3WIY8rW eQ1u3vmsv41HBPmosqkNnynw= X-Received: by 127.0.0.2 with SMTP id 75j7YY7687511x1Hs3D9OONl; Fri, 19 Jan 2024 11:22:20 -0800 X-Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by mx.groups.io with SMTP id smtpd.web10.2913.1705692140206579581 for ; Fri, 19 Jan 2024 11:22:20 -0800 X-Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40JFwLNQ013466; Fri, 19 Jan 2024 19:22:19 GMT X-Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vqreq8x0k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 19:22:18 +0000 (GMT) X-Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 40JJMHL4008538 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 19:22:17 GMT X-Received: from qc-i7.hemma.eciton.net (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 19 Jan 2024 11:22:16 -0800 Date: Fri, 19 Jan 2024 19:22:13 +0000 From: "Leif Lindholm" To: Marcin Juszkiewicz CC: , Ard Biesheuvel , Graeme Gregory Subject: Re: [edk2-devel] [PATCH edk2-platforms v2 4/4] Platform/SbsaQemu: move FdtHandlerLib to SbsaQemuHardwareInfoLib Message-ID: References: <20240116-no-dt-for-cpu-v2-0-6cf078d9ab76@linaro.org> <20240116-no-dt-for-cpu-v2-4-6cf078d9ab76@linaro.org> MIME-Version: 1.0 In-Reply-To: <20240116-no-dt-for-cpu-v2-4-6cf078d9ab76@linaro.org> X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-ORIG-GUID: inoAfIR4wbWEOC8yKvN26ehJkCSFnapI X-Proofpoint-GUID: inoAfIR4wbWEOC8yKvN26ehJkCSFnapI Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,quic_llindhol@quicinc.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: XYEOPtouB9HhzSHQY7MBo48Sx7686176AA= Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=OSUCQaMU; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=quicinc.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On Tue, Jan 16, 2024 at 08:48:35 +0100, Marcin Juszkiewicz wrote: > There is no need for EDK2 to know that there is DeviceTree around. > All hardware information is read using functions from > SbsaQemuHardwareInfoLib library. > > Library fallbacks to parsing DT if needed (used with too old TF-A). > > Signed-off-by: Marcin Juszkiewicz Reviewed-by: Leif Lindholm > --- > Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 1 - > .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf | 4 +- > .../SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf | 33 ------- > .../SbsaQemuHardwareInfoLib.inf | 2 + > .../Qemu/SbsaQemu/Include/Library/FdtHelperLib.h | 36 ------- > .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 4 +- > .../SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c | 98 ------------------ > .../SbsaQemuHardwareInfoLib.c | 104 ++++++++++++++++++++ > 8 files changed, 110 insertions(+), 172 deletions(-) > > diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc > index 07cb3490f4cf..bde61651da2e 100644 > --- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc > +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc > @@ -126,7 +126,6 @@ [LibraryClasses.common] > # ARM PL011 UART Driver > PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf > > - FdtHelperLib|Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf > OemMiscLib|Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf > SbsaQemuHardwareInfoLib|Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf > > diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf > index 291743b19115..9bf0a13de5d1 100644 > --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf > +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf > @@ -1,7 +1,7 @@ > ## @file > # This driver modifies ACPI tables for the Qemu SBSA platform > # > -# Copyright (c) 2020, Linaro Ltd. All rights reserved. > +# Copyright (c) Linaro Ltd. All rights reserved. > # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -35,9 +35,9 @@ [LibraryClasses] > BaseLib > DebugLib > DxeServicesLib > - FdtHelperLib > PcdLib > PrintLib > + SbsaQemuHardwareInfoLib > UefiDriverEntryPoint > UefiLib > UefiRuntimeServicesTableLib > diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf > deleted file mode 100644 > index 9c059f3e5851..000000000000 > --- a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf > +++ /dev/null > @@ -1,33 +0,0 @@ > -#/** @file > -# > -# Component description file for FdtHelperLib module > -# > -# Copyright (c) 2021, NUVIA Inc. All rights reserved. > -# > -# SPDX-License-Identifier: BSD-2-Clause-Patent > -# > -#**/ > - > -[Defines] > - INF_VERSION = 1.29 > - BASE_NAME = FdtHelperLib > - FILE_GUID = 34e4396f-c2fc-4f9e-ad58-0f98e99e3875 > - MODULE_TYPE = BASE > - VERSION_STRING = 1.0 > - LIBRARY_CLASS = FdtHelperLib > - > -[Sources.common] > - FdtHelperLib.c > - > -[Packages] > - EmbeddedPkg/EmbeddedPkg.dec > - MdePkg/MdePkg.dec > - Silicon/Qemu/SbsaQemu/SbsaQemu.dec > - > -[LibraryClasses] > - DebugLib > - FdtLib > - PcdLib > - > -[FixedPcd] > - gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress > diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf > index 8c2def1878e6..5358dd339eb3 100644 > --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf > +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf > @@ -27,6 +27,8 @@ [LibraryClasses] > ArmSmcLib > BaseMemoryLib > DebugLib > + FdtLib > > [Pcd] > + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress > gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdCoreCount > diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h b/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h > deleted file mode 100644 > index ea9159857215..000000000000 > --- a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h > +++ /dev/null > @@ -1,36 +0,0 @@ > -/** @file > -* FdtHelperLib.h > -* > -* Copyright (c) 2021, NUVIA Inc. All rights reserved. > -* > -* SPDX-License-Identifier: BSD-2-Clause-Patent > -* > -**/ > - > -#ifndef FDT_HELPER_LIB_ > -#define FDT_HELPER_LIB_ > - > -/** > - Get MPIDR for a given cpu from device tree passed by Qemu. > - > - @param [in] CpuId Index of cpu to retrieve MPIDR value for. > - > - @retval MPIDR value of CPU at index > -**/ > -UINT64 > -FdtHelperGetMpidr ( > - IN UINTN CpuId > - ); > - > -/** Walks through the Device Tree created by Qemu and counts the number > - of CPUs present in it. > - > - @return The number of CPUs present. > -**/ > -EFIAPI > -UINT32 > -FdtHelperCountCpus ( > - VOID > - ); > - > -#endif /* FDT_HELPER_LIB_ */ > diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > index 7ef314ae9f67..c446581b746e 100644 > --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > @@ -15,10 +15,10 @@ > #include > #include > #include > -#include > #include > #include > #include > +#include > #include > #include > #include > @@ -297,7 +297,7 @@ AddMadtTable ( > CopyMem (New, &Gicc, sizeof (EFI_ACPI_6_0_GIC_STRUCTURE)); > GiccPtr = (EFI_ACPI_6_0_GIC_STRUCTURE *) New; > GiccPtr->AcpiProcessorUid = CoreIndex; > - GiccPtr->MPIDR = FdtHelperGetMpidr (CoreIndex); > + GiccPtr->MPIDR = SbsaQemuGetMpidr (CoreIndex); > New += sizeof (EFI_ACPI_6_0_GIC_STRUCTURE); > } > > diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c > deleted file mode 100644 > index 7fdfb055db76..000000000000 > --- a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c > +++ /dev/null > @@ -1,98 +0,0 @@ > -/** @file > -* FdtHelperLib.c > -* > -* Copyright (c) 2021, NUVIA Inc. All rights reserved. > -* Copyright (c) 2020, Linaro Ltd. All rights reserved. > -* > -* SPDX-License-Identifier: BSD-2-Clause-Patent > -* > -**/ > - > -#include > -#include > -#include > -#include > -#include > - > -STATIC INT32 mFdtFirstCpuOffset; > -STATIC INT32 mFdtCpuNodeSize; > - > -/** > - Get MPIDR for a given cpu from device tree passed by Qemu. > - > - @param [in] CpuId Index of cpu to retrieve MPIDR value for. > - > - @retval MPIDR value of CPU at index > -**/ > -UINT64 > -FdtHelperGetMpidr ( > - IN UINTN CpuId > - ) > -{ > - VOID *DeviceTreeBase; > - CONST UINT64 *RegVal; > - INT32 Len; > - > - DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); > - ASSERT (DeviceTreeBase != NULL); > - > - RegVal = fdt_getprop (DeviceTreeBase, > - mFdtFirstCpuOffset + (CpuId * mFdtCpuNodeSize), > - "reg", > - &Len); > - if (!RegVal) { > - DEBUG ((DEBUG_ERROR, "Couldn't find reg property for CPU:%d\n", CpuId)); > - return 0; > - } > - > - return (fdt64_to_cpu (ReadUnaligned64 (RegVal))); > -} > - > -/** Walks through the Device Tree created by Qemu and counts the number > - of CPUs present in it. > - > - @return The number of CPUs present. > -**/ > -EFIAPI > -UINT32 > -FdtHelperCountCpus ( > - VOID > - ) > -{ > - VOID *DeviceTreeBase; > - INT32 Node; > - INT32 Prev; > - INT32 CpuNode; > - UINT32 CpuCount; > - > - DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); > - ASSERT (DeviceTreeBase != NULL); > - > - // Make sure we have a valid device tree blob > - ASSERT (fdt_check_header (DeviceTreeBase) == 0); > - > - CpuNode = fdt_path_offset (DeviceTreeBase, "/cpus"); > - if (CpuNode <= 0) { > - DEBUG ((DEBUG_ERROR, "Unable to locate /cpus in device tree\n")); > - return 0; > - } > - > - CpuCount = 0; > - > - // Walk through /cpus node and count the number of subnodes. > - // The count of these subnodes corresponds to the number of > - // CPUs created by Qemu. > - Prev = fdt_first_subnode (DeviceTreeBase, CpuNode); > - mFdtFirstCpuOffset = Prev; > - while (1) { > - CpuCount++; > - Node = fdt_next_subnode (DeviceTreeBase, Prev); > - if (Node < 0) { > - break; > - } > - mFdtCpuNodeSize = Node - Prev; > - Prev = Node; > - } > - > - return CpuCount; > -} > diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > index 4df973fda75e..900493e02d7f 100644 > --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c > @@ -11,8 +11,112 @@ > #include > #include > #include > +#include > #include > > +/** > + Get MPIDR for a given cpu from device tree passed by Qemu. > + > + @param [in] CpuId Index of cpu to retrieve MPIDR value for. > + > + @retval MPIDR value of CPU at index > +**/ > +UINT64 > +FdtHelperGetMpidr ( > + IN UINTN CpuId > + ) > +{ > + VOID *DeviceTreeBase; > + INT32 Node; > + INT32 Prev; > + UINT32 CpuCount; > + CONST UINT64 *RegVal; > + > + DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); > + ASSERT (DeviceTreeBase != NULL); > + > + // Make sure we have a valid device tree blob > + ASSERT (fdt_check_header (DeviceTreeBase) == 0); > + > + Node = fdt_path_offset (DeviceTreeBase, "/cpus"); > + if (Node <= 0) { > + DEBUG ((DEBUG_ERROR, "Unable to locate /cpus in device tree\n")); > + return 0; > + } > + > + CpuCount = 0; > + > + Prev = fdt_first_subnode (DeviceTreeBase, Node); > + while (1) { > + > + if (CpuCount == CpuId) { > + RegVal = fdt_getprop (DeviceTreeBase, Prev, "reg", NULL); > + if (!RegVal) { > + DEBUG ((DEBUG_ERROR, "Couldn't find reg property for CPU:%d\n", CpuId)); > + return 0; > + } > + return (fdt64_to_cpu (ReadUnaligned64 (RegVal))); > + } > + > + Node = fdt_next_subnode (DeviceTreeBase, Prev); > + if (Node < 0) { > + break; > + } > + Prev = Node; > + CpuCount++; > + } > + > + return 0; /* We did not found MPIDR */ > + > +} > + > +/** Walks through the Device Tree created by Qemu and counts the number > + of CPUs present in it. > + > + @return The number of CPUs present. > +**/ > +EFIAPI > +UINT32 > +FdtHelperCountCpus ( > + VOID > + ) > +{ > + VOID *DeviceTreeBase; > + INT32 Node; > + INT32 Prev; > + UINT32 CpuCount; > + > + DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); > + ASSERT (DeviceTreeBase != NULL); > + > + // Make sure we have a valid device tree blob > + ASSERT (fdt_check_header (DeviceTreeBase) == 0); > + > + Node = fdt_path_offset (DeviceTreeBase, "/cpus"); > + if (Node <= 0) { > + DEBUG ((DEBUG_ERROR, "Unable to locate /cpus in device tree\n")); > + return 0; > + } > + > + CpuCount = 0; > + > + // Walk through /cpus node and count the number of subnodes. > + // The count of these subnodes corresponds to the number of > + // CPUs created by Qemu. > + Prev = fdt_first_subnode (DeviceTreeBase, Node); > + while (1) { > + CpuCount++; > + Node = fdt_next_subnode (DeviceTreeBase, Prev); > + if (Node < 0) { > + break; > + } > + Prev = Node; > + } > + > + return CpuCount; > +} > + > + > /** > Get CPU count from information passed by Qemu. > > > -- > 2.43.0 > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114097): https://edk2.groups.io/g/devel/message/114097 Mute This Topic: https://groups.io/mt/103758017/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-