From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by mx.groups.io with SMTP id smtpd.web08.12283.1614097979678251746 for ; Tue, 23 Feb 2021 08:33:00 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=zureoCOD; spf=pass (domain: nuviainc.com, ip: 209.85.221.49, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f49.google.com with SMTP id r3so11573624wro.9 for ; Tue, 23 Feb 2021 08:32:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7dfF8jvCouQ+fxBgtTdfzfB1Q+O0Wa+YnUexEMByeWc=; b=zureoCODRa04XBURM/pKo7vVbOYCOV9oDYoTewtDb6Vvgkna6Jtl2+W8adTEitXbB1 +YFb82oeuGgVFXhMhrSvRgP5JLyKlS7jINIhkqCsx7k9OZ9iRE1WL0qfFN1iag17gF1m h4vnS+HLIp3GUWOw3ZEey+OVoWgStPu62a4aFAFl8zwuYeWAi4khJM0yF1LbCOQKI4du NY/z7oKpvj8FBoGOUpEQg7tbPhiiSsGeN2Po0T8ZaczKul/kd+uGJxK7Uyl6zEZV76pC qCAy4Kn0J2aXeBRhchipUbWdWXNyGBLKCj5667MWJgltij91+cuWMK74LMTBxn2L99Qr 47aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=7dfF8jvCouQ+fxBgtTdfzfB1Q+O0Wa+YnUexEMByeWc=; b=d6NFfLY6728+2aE9GblY/Y1IW0MujQ7GKmcNRmtCTgopOPhFvCSRjEY5v8+rGt0JRK jqiR1dC5NwGYdW9BK2EOI2kMYwAgfp85Pj1TgjTmfQX19zCefU3P5ibe9meXy4c6PqxJ FmvEQRbEShOkojTY1cJkLoPLMZpDOIbcKxCdGLKAJPyThRmeU9MgOM6h84PNiU3lkgR6 fNk7mrPjqZr4vxa6GE4hc/s/iid0lE4ENScAx+h/2UTRh4v5VHqe9dgmra5O6yLSOitE PLGQ/O/tDYfT8kSnevjWqj/S6BpF7UoHpbWBCG8qMjL7I1t/mfJHifgfgeFc3xGQKitz XdvA== X-Gm-Message-State: AOAM532KDomcxorlZ25EPydGoCt3olwQbbhX85lcJmz7nGstytva45oC v5P+QdNhnK7TAkYuZA/Z9NI4HQ== X-Google-Smtp-Source: ABdhPJws+t2dCDlzrDgBPyCohB4XjW6o6tqkM/8HLQIGsIVihy/uzsD74f8YDtwAq+ri3SaJo0ED3g== X-Received: by 2002:a5d:4141:: with SMTP id c1mr4872500wrq.248.1614097978201; Tue, 23 Feb 2021 08:32:58 -0800 (PST) Return-Path: Received: from vanye (cpc1-cmbg19-2-0-cust915.5-4.cable.virginm.net. [82.27.183.148]) by smtp.gmail.com with ESMTPSA id o13sm36669717wro.15.2021.02.23.08.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 08:32:57 -0800 (PST) Date: Tue, 23 Feb 2021 16:32:56 +0000 From: "Leif Lindholm" To: Rebecca Cran Cc: devel@edk2.groups.io, Ard Biesheuvel , Graeme Gregory , Radoslaw Biernacki Subject: Re: [edk2-platforms PATCH v4 1/4] SbsaQemu: Add FdtHelperLib Message-ID: <20210223163256.GE1664@vanye> References: <20210223142635.8807-1-rebecca@nuviainc.com> <20210223142635.8807-2-rebecca@nuviainc.com> MIME-Version: 1.0 In-Reply-To: <20210223142635.8807-2-rebecca@nuviainc.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Feb 23, 2021 at 07:26:32 -0700, Rebecca Cran wrote: > 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/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 5 +- > Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h | 24 ++++++++ > Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c | 62 ++++++++++++++++++++ > Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf | 28 +++++++++ > 5 files changed, 120 insertions(+), 1 deletion(-) > > 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/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > index fb7c1835c3d7..7bf60cd2ded1 100644 > --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c > @@ -487,9 +487,12 @@ InitializeSbsaQemuAcpiDxe ( > { > EFI_STATUS Status; > EFI_ACPI_TABLE_PROTOCOL *AcpiTable; > + UINT32 NumCores; > > // Parse the device tree and get the number of CPUs > - CountCpusFromFdt (); > + NumCores = FdtHelperCountCpus (); > + Status = PcdSet32S (PcdCoreCount, NumCores); > + ASSERT_RETURN_ERROR (Status); > > // Check if ACPI Table Protocol has been installed > Status = gBS->LocateProtocol ( Would this hunk make more sense in 2/4? (I think it breaks bisect here.) No further comments on this set, I think is thise moves, the set can go in. / Leif > diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h b/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h > new file mode 100644 > index 000000000000..e9e7281c1342 > --- /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 > +UINT32 > +FdtHelperCountCpus ( > + 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..411f035ee7d8 > --- /dev/null > +++ b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c > @@ -0,0 +1,62 @@ > +/** @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 > + > +/** 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); > + 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 >