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 43470AC14B4 for ; Wed, 6 Mar 2024 11:42:08 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lgXwPmjdRGDjsTaInbsyPAtQbTL8cDx/N7jG5oQGRiI=; c=relaxed/simple; d=groups.io; h=From:Date:Subject:MIME-Version:Message-Id:References:In-Reply-To:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20240206; t=1709725326; v=1; b=ju2/SrOuDf8AplmlAG3D1ZfbHNDQVI/W6PPVLC6rvfk4sFbqg1owKvxi+jTrtK8AvQo69iQl 3waPbRQHkieMnXi+dZugeORR3SxyeA53DG3oRIvf+RXZw5i8tvXStFsNjx38bdAjvYp7bgroy2q O/NYCixiOuqpS8VRK5u1rKDEq83PvHmVXTBTlJ632NCH1pKbyyHETmsL4jMmg+2ceasRkgWpMkh DphyZXUp36yvCpGGsy4tiWeCr8hFtDuBnLfnde3OVTP4sRdk/ZNbY/KjGej0uG7VVHD2FQiToFP n6TKaLgui/otAL0HFiukpCZ8YT64MLP+PUAa2Pl89Umgw== X-Received: by 127.0.0.2 with SMTP id xQLBYY7687511xVXvERqTtFH; Wed, 06 Mar 2024 03:42:06 -0800 X-Received: from muminek.juszkiewicz.com.pl (muminek.juszkiewicz.com.pl [213.251.184.221]) by mx.groups.io with SMTP id smtpd.web11.9859.1709725325990353320 for ; Wed, 06 Mar 2024 03:42:06 -0800 X-Received: from localhost (localhost [127.0.0.1]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTP id E93FF260839; Wed, 6 Mar 2024 12:42:03 +0100 (CET) X-Virus-Scanned: Debian amavis at juszkiewicz.com.pl X-Received: from muminek.juszkiewicz.com.pl ([127.0.0.1]) by localhost (muminek.juszkiewicz.com.pl [127.0.0.1]) (amavis, port 10024) with ESMTP id RHrxix1biXM2; Wed, 6 Mar 2024 12:42:02 +0100 (CET) X-Received: from [172.17.0.1] (83.11.22.169.ipv4.supernova.orange.pl [83.11.22.169]) by muminek.juszkiewicz.com.pl (Postfix) with ESMTPSA id 8C3B1260837; Wed, 6 Mar 2024 12:41:59 +0100 (CET) From: "Marcin Juszkiewicz" Date: Wed, 06 Mar 2024 03:42:06 -0800 Subject: [edk2-devel] [PATCH edk2-platforms v6 7/7] Platform/SbsaQemu: add DeviceTree fallbacks to parse memory information MIME-Version: 1.0 Message-Id: <20240306-no-dt-for-cpu-v6-7-acd8727a1b59@linaro.org> References: <20240306-no-dt-for-cpu-v6-0-acd8727a1b59@linaro.org> In-Reply-To: <20240306-no-dt-for-cpu-v6-0-acd8727a1b59@linaro.org> To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Graeme Gregory , Xiong Yining , Chen Baozi , Marcin Juszkiewicz 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,marcin.juszkiewicz@linaro.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 0fb66pvQeuR9UbJG0VxyY4Qfx7686176AA= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b="ju2/SrOu"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linaro.org (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 From: Xiong Yining Add the DeviceTree fallbacks to parsing the information about memory if the related SMC calls Failed. Signed-off-by: Xiong Yining Signed-off-by: Chen Baozi --- .../SbsaQemuHardwareInfoLib.c | 106 ++++++++++++++++= +++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemu= HardwareInfoLib.c b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/S= bsaQemuHardwareInfoLib.c index 88b50e46c072..d63cfbf7d5ef 100644 --- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwar= eInfoLib.c +++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwar= eInfoLib.c @@ -118,6 +118,106 @@ FdtHelperCountCpus ( return CpuCount; } =20 +/** + Walks through the Device Tree created by Qemu and counts the number of M= emory node present in it. + + @retval the number of memory nodes. +**/ +UINT32 +FdtHelperMemNodeCount ( + VOID + ) +{ + VOID *DeviceTreeBase; + CONST CHAR8 *Type; + UINT32 MemNodeCount; + INT32 Node; + INT32 Prev; + INT32 Len; + + DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); + ASSERT (DeviceTreeBase !=3D NULL); + + // Make sure we have a valid device tree blob + ASSERT (fdt_check_header (DeviceTreeBase) =3D=3D 0); + + MemNodeCount =3D 0; + for (Prev =3D 0;; Prev =3D Node) { + Node =3D fdt_next_node (DeviceTreeBase, Prev, NULL); + if (Node < 0){ + break; + } + + Type =3D fdt_getprop (DeviceTreeBase, Node, "device_type", &Len); + if (Type && AsciiStrnCmp (Type, "memory", Len) =3D=3D 0) { + MemNodeCount++; + } + } + + return MemNodeCount; +} + +/** Walks through the Device Tree created by Qemu and counts the adress=E3= =80=81size and node-id of the Memory node present in it. + + @param [in] MemoryId Index of memory to retrieve memory information= . + + @retval memory infomation for given memory node. +**/ +MemoryInfo +FdtHelperGetMemInfo ( + IN UINTN MemoryId +) +{ + VOID *DeviceTreeBase; + CONST UINT64 *RegProp; + CONST UINT32 *NodeProp; + CONST CHAR8 *Type; + INT64 MemNodeCount; + INT32 Len; + INT32 Node; + INT32 Prev; + MemoryInfo MemInfo =3D {0}; + + DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); + ASSERT (DeviceTreeBase !=3D NULL); + + // Make sure we have a valid device tree blob + ASSERT (fdt_check_header (DeviceTreeBase) =3D=3D 0); + + MemNodeCount =3D 0; + + for (Prev =3D 0;; Prev =3D Node){ + Node =3D fdt_next_node (DeviceTreeBase, Prev, NULL); + if (Node < 0){ + break; + } + + Type =3D fdt_getprop (DeviceTreeBase, Node, "device_type", &Len); + if (Type && AsciiStrnCmp (Type, "memory", Len) =3D=3D 0){ + if (MemoryId =3D=3D MemNodeCount){ + RegProp =3D fdt_getprop (DeviceTreeBase, Node, "reg", &Len); + if (RegProp !=3D 0 && Len =3D=3D (2 * sizeof (UINT64))) { + MemInfo.AddressBase =3D fdt64_to_cpu (ReadUnaligned64 (RegProp= )); + MemInfo.AddressSize=3D fdt64_to_cpu (ReadUnaligned64 (RegProp = + 1)); + } else { + DEBUG ((DEBUG_ERROR, "Failed to find the address and size of the= memory")); + } + + NodeProp=3D fdt_getprop (DeviceTreeBase, Node, "numa-node-id", &Le= n); + if (NodeProp){ + MemInfo.NodeId=3D fdt32_to_cpu (ReadUnaligned32 (NodeProp)); + } else { + DEBUG ((DEBUG_ERROR, "Failed to find the node-id of the memory")= ); + } + } + + MemNodeCount ++; + } + } + + return MemInfo; +} + /** Get CPU count from information passed by Qemu. =20 @@ -212,7 +312,8 @@ SbsaQemuGetMemNodeCount ( =20 SmcResult =3D ArmCallSmc0 (SIP_SVC_GET_MEMORY_NODE_COUNT, &Arg0, NULL, N= ULL); if (SmcResult !=3D SMC_SIP_CALL_SUCCESS) { - DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE_COUNT call failed.\n")); + DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE_COUNT call failed. We ha= ve to get the number of memory nodes from DT.\n")); + Arg0 =3D FdtHelperMemNodeCount(); } =20 DEBUG(( DEBUG_INFO, "The number of the memory nodes is %ld\n", Arg0)); @@ -234,7 +335,8 @@ SbsaQemuGetMemInfo ( =20 SmcResult =3D ArmCallSmc1 (SIP_SVC_GET_MEMORY_NODE, &Arg0, &Arg1, &Arg2)= ; if (SmcResult !=3D SMC_SIP_CALL_SUCCESS) { - DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE call failed.\n")); + DEBUG ((DEBUG_ERROR, "SIP_SVC_GET_MEMORY_NODE call failed. We have to = get memory info from DT.\n")); + MemInfo =3D FdtHelperGetMemInfo(MemoryId); } else { MemInfo.NodeId =3D Arg0; MemInfo.AddressBase =3D Arg1; --=20 2.44.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116432): https://edk2.groups.io/g/devel/message/116432 Mute This Topic: https://groups.io/mt/104763770/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-