From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=hF9TfUtO; spf=pass (domain: nuviainc.com, ip: 209.85.222.181, mailfrom: rebecca@nuviainc.com) Received: by mail-qk1-f181.google.com with SMTP id t63so4463728qkc.1 for ; Thu, 18 Feb 2021 19:57:52 -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=hF9TfUtORD6JB3oEdwHiW9lyPwF7zrH0g89A447PthJ0aBPi/nJs0+Wt3y9z1iMH1S E3dfmGQLnoxaKaCbacZiJtddtql/N8XfBAWHavE1KJ+hhnpw//IU0DWZolAfNLaxopvd j8q+jz3kgqQOW8HMeACuhERPWHi56+laKp5iEj/S6cFUw34ps33o/UN/YqEGHylknEFW 4j+QGsaG5EyYHpSVEA9tpcgTr5DFiddprq3g4mrh0Z2d7bfJ8fk6O2GmMuV/dEfYMdLt DSIAvqDlaOrApENYen4ti0mOPyt5l5vWDjyb2aEnF303kQfGPnYdZ8rQJF/RYoi22Axn 7kLA== 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=tgBxuD8q7S4ib2CHAfA2m2HyQltjaozgP/CmEynmULT27+zVyC7czlVp4dypUUCQqG WTpYfm9IvnZMpjBWo9vQ4PN3E9KdVFfTCh7RcMx5esQRi61TCasa/xQXPqGvF1xsSLfV rMbotCA85gELwdMmtKumOymI1fd0YoDtTbSFeEMgekWjjQJCLOkRfW8ux97Kf0FJpAxp hhmO50sDDOHdmsmkzIFnjtxUxYXHiD9zYUvF177VG45QqlBINh7RvhjOwvDU4VE0UWot P+GRii4N6jJUUMeBJqbFYJ03fdGrpt2bw54VxIHLoEv6VW08jZm6UnurZ/vk4EmYfggg fp4w== X-Gm-Message-State: AOAM533EgvykwHws/vp3QgPGgRWpOHTbMCS2ncn00zLv+FAZF2R6t0x8 p1Tw5pULJA3no/yk4qWJtnGyFlUoXupf0AZSpDaZ47BENphMWXw27bGaGIhiXJY0LLXcftuuSbg Lcz1G+399O9gfml5Ilvr5jMMDulqduhEXH8TV0lRIOnWwX1dKz9Kcj73qb0pjUANIlzbA6w== 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) 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 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-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> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219035741.1467-1-rebecca@nuviainc.com> References: <20210219035741.1467-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