From nobody Mon Nov 25 12:32:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+71804+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71804+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1613707073246582.051479622415; Thu, 18 Feb 2021 19:57:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SRO6YY1788612xe6vDxHHAMj; Thu, 18 Feb 2021 19:57:52 -0800 X-Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by mx.groups.io with SMTP id smtpd.web08.4115.1613707072243620967 for ; Thu, 18 Feb 2021 19:57:52 -0800 X-Received: by mail-qk1-f181.google.com with SMTP id t63so4463728qkc.1 for ; Thu, 18 Feb 2021 19:57:52 -0800 (PST) X-Gm-Message-State: rQNoJVPGOUnbKV7PWBieRosQx1787277AA= X-Google-Smtp-Source: ABdhPJzAX0AJjPby8sgWz8/YXt+iJ9NqbxzCJHJ4+cVi9MxYAAKPliiAZ0rRr1dxdxSltax7ABmq4w== X-Received: by 2002:a37:8a04:: with SMTP id m4mr7687902qkd.78.1613707071084; Thu, 18 Feb 2021 19:57:51 -0800 (PST) X-Received: from cube.nuviainc.com (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id z28sm5633919qkj.72.2021.02.18.19.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 19:57:50 -0800 (PST) From: "Rebecca Cran" To: devel@edk2.groups.io Cc: Rebecca Cran , Ard Biesheuvel , Leif Lindholm , Graeme Gregory , Radoslaw Biernacki Subject: [edk2-devel] [edk2-platforms PATCH v3 1/3] SbsaQemu: Add FdtHelperLib Date: Thu, 18 Feb 2021 20:57:39 -0700 Message-Id: <20210219035741.1467-2-rebecca@nuviainc.com> In-Reply-To: <20210219035741.1467-1-rebecca@nuviainc.com> References: <20210219035741.1467-1-rebecca@nuviainc.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,rebecca@nuviainc.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613707072; bh=JtM1Gg3v3tc6VlRfB8iSgZ4hGp6O+stur1bYrHP2PaE=; h=Cc:Date:From:Reply-To:Subject:To; b=RYTZGJgVDRSIkzD3rolqZYRzejnOoJOWNCqa0z++2Z8gWmU/HF+g+gm4CMRiKSnqdll XyxSh4fRs43bjPqwKFdPKB5Tvc8FCjdfCeEApKHjj4/4spfeVXxOxhB7vfaeiwNm5uufY 0upWubbD6f/B1qG7X6hChtxIS6hR7NFogR8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The CountCpusFromFdt function is now used in two places. Create FdtHelperLib for this and similar functions. Signed-off-by: Rebecca Cran Reviewed-by: Leif Lindholm --- Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 2 + Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h | 24 +++++++ Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c | 69 +++++++++= +++++++++++ Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf | 28 ++++++++ 4 files changed, 123 insertions(+) diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc b/Platform/Qemu/SbsaQemu/S= bsaQemu.dsc index f6af3f9111ee..8faad3eda217 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc @@ -121,6 +121,8 @@ DEFINE NETWORK_HTTP_BOOT_ENABLE =3D FALSE # ARM PL011 UART Driver PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf =20 + FdtHelperLib|Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf + # Debug Support PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCof= fExtraActionLib.inf DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.i= nf diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h b/Silicon= /Qemu/SbsaQemu/Include/Library/FdtHelperLib.h new file mode 100644 index 000000000000..eac47349a3d7 --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h @@ -0,0 +1,24 @@ +/** @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_ + +/** Walks through the Device Tree created by Qemu and counts the number + of CPUs present in it. + + @return The number of CPUs present. +**/ +EFIAPI +UINT16 +CountCpusFromFdt ( + VOID + ); + +#endif /* FDT_HELPER_LIB_ */ diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c b/Si= licon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c new file mode 100644 index 000000000000..c399fec5f9c7 --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c @@ -0,0 +1,69 @@ +/** @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 +* +**/ + + +/** Walks through the Device Tree created by Qemu and counts the number + of CPUs present in it. + + @return The number of CPUs present. +**/ + +#include +#include +#include +#include +#include + +/** Walks through the Device Tree created by Qemu and counts the number + of CPUs present in it. + + @return The number of CPUs present. +**/ +EFIAPI +UINT16 +CountCpusFromFdt ( + VOID + ) +{ + VOID *DeviceTreeBase; + INT32 Node; + INT32 Prev; + INT32 CpuNode; + INT32 CpuCount; + + 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); + + CpuNode =3D fdt_path_offset (DeviceTreeBase, "/cpus"); + if (CpuNode <=3D 0) { + DEBUG ((DEBUG_ERROR, "Unable to locate /cpus in device tree\n")); + return 0; + } + + CpuCount =3D 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 =3D fdt_first_subnode (DeviceTreeBase, CpuNode); + while (1) { + CpuCount++; + Node =3D fdt_next_subnode (DeviceTreeBase, Prev); + if (Node < 0) { + break; + } + Prev =3D Node; + } + + return CpuCount; +} diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf b/= Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf new file mode 100644 index 000000000000..d84c16f888d1 --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf @@ -0,0 +1,28 @@ +#/** @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 =3D 1.29 + BASE_NAME =3D FdtHelperLib + FILE_GUID =3D 34e4396f-c2fc-4f9e-ad58-0f98e99e3875 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D FdtHelperLib + +[Sources.common] + FdtHelperLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + Silicon/Qemu/SbsaQemu/SbsaQemu.dec + +[FixedPcd] + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress --=20 2.26.2 -=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 (#71804): https://edk2.groups.io/g/devel/message/71804 Mute This Topic: https://groups.io/mt/80748480/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-