From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by mx.groups.io with SMTP id smtpd.web08.4058.1613706614272301203 for ; Thu, 18 Feb 2021 19:50:14 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=nM3EP5xN; spf=pass (domain: nuviainc.com, ip: 209.85.210.54, mailfrom: rebecca@nuviainc.com) Received: by mail-ot1-f54.google.com with SMTP id b16so3989077otq.1 for ; Thu, 18 Feb 2021 19:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0kCinvZvwm4lgRrTwvx4YBnAkQ3YRiNABAie8xvgJuk=; b=nM3EP5xNJquB2Iy3wDcFVFFKEl0KMIys3BP+c13oey3Y9QZmmQQ/V/sfH/Gq89jB+g BV/4AVnY1CUCRkbCJMPILdklbv50Fqc/gcnH2khKaPkUeD8pgyOViU9RRDyqkq6H0fZn Jvw6Fm2mJGY2w4HYpXGiP3RH6iPNn6NkDiDY1nl0E8vyEU1mDC1kMPq1/sj7TtxLAsox IwvC6TFBZedw7SzdBJaJsQHKeyFo3V5Bd7XQJXyhbkCPUy9J68D9pjdoMYTQyLSYRx9h cCSP2l6JzcfgKzRA9KrgioniLZI/f2CiyCH9yez16n+8Ed0sEeZp/xO51irOn4VU0WUU MJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0kCinvZvwm4lgRrTwvx4YBnAkQ3YRiNABAie8xvgJuk=; b=mRChuWdS53rrFynARKGwwLsy6QflavwV4+AbqLnOfD79N7T1903RsXfMe9VMX1iKul +hhDN5tPGIatcINtMziadrhA4u4JUgoMUqjC445BdKgD1R/J1GZrusOIu8zeMUV8zwsP yWMWwxRNz/CCS4C3koznSioGD4H3BrsCtpsb7/lQ+kCungZ+1YbzvHqdhnvHtdF5f/jJ LYEZLO/9Qj7hmwhqFc4srHlCtD2TGANsJ4c/LBW+GKoOhxe17O4ZCaf025m2yW/Qx+rq JeCMs8/AsynJm2frdEBTDJU4pV+UeHj5sUmHrRmvj8ykkXzYfK4ZMyTOHp2aJxSANC5Y dRKw== X-Gm-Message-State: AOAM531VnGUdeKoSu8q+AGjO7H1PbVV0orhKHGUZ4Qdr0mlje/bmq22z DSAM9gIuQ93sxXoat3wHWuGx2uCAW/Dj5x8c6nSi801QkWW/+9e7jo2x6Rqtxh42CYRxkrucBd5 aSEbK3RLSBnXDpJVyk0jRmWXgUzJUtWixfLlxukiy/hR4FRyfFyxHP8gUByh8GqzXeQ7liw== X-Google-Smtp-Source: ABdhPJzgAYh4on5xfRAjgCj036Wm8gmpG5JPUATBV54CVXJ32bOZzozrJhY7g+eekYgM8SaKVOz3zg== X-Received: by 2002:a9d:32f4:: with SMTP id u107mr5360780otb.308.1613706613257; Thu, 18 Feb 2021 19:50:13 -0800 (PST) Return-Path: 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 k67sm1649522oia.7.2021.02.18.19.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 19:50:12 -0800 (PST) From: "Rebecca Cran" To: devel@edk2.groups.io Cc: Rebecca Cran , Ard Biesheuvel , Leif Lindholm , Graeme Gregory , Radoslaw Biernacki Subject: [edk2-platforms v2 1/3] SbsaQemu: Add FdtHelperLib Date: Thu, 18 Feb 2021 20:50:03 -0700 Message-Id: <20210219035005.457-2-rebecca@nuviainc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219035005.457-1-rebecca@nuviainc.com> References: <20210219035005.457-1-rebecca@nuviainc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The CountCpusFromFdt function is now used in two places. Create FdtHelperLib for this and similar functions. Signed-off-by: Rebecca Cran --- 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/SbsaQemu.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 = FALSE # ARM PL011 UART Driver PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf + FdtHelperLib|Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf + # Debug Support PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf 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/Silicon/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 = (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); + while (1) { + CpuCount++; + Node = fdt_next_subnode (DeviceTreeBase, Prev); + if (Node < 0) { + break; + } + Prev = 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 = 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 + +[FixedPcd] + gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress -- 2.26.2