From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by mx.groups.io with SMTP id smtpd.web12.34304.1613998791821548903 for ; Mon, 22 Feb 2021 04:59:52 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=wSnMEyjj; spf=pass (domain: nuviainc.com, ip: 209.85.128.45, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f45.google.com with SMTP id l13so4703960wmg.5 for ; Mon, 22 Feb 2021 04:59:51 -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=bLZ+DqTQvI8QO+9HtnyF954ZfjBbA0vnxa6JAswC1Ps=; b=wSnMEyjjzC1mbCdi5AU8lUF/tfcX4KQ9XqdBqZvQx7lefU2vDmTQudey2ZKRkpnugd 2FmocCeZD5hUE/SFU+BSaO/6XOyGw/DEpJnKC6V4h2UiA0rXBxHk89G+0Uvb+h4SpATX mIRiOYh5X2N5hNXjEDMGp7tHlekykn35qE9T5/JVOBP2ZPMnOlawBO/McMwmi81E2joW 2Z564CRVCEoQpNLhaccgADmGXrDS+vrCxS0cry9PQ8wF2mI7k+y0qxzoE03BOECXAB5b 6BNLM/K3b46fPAgvoj8i5iloBqOgTUfDlTqWQswU0i5rcAdTM3IWzdk1deAV2qx6cPRe RRvw== 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=bLZ+DqTQvI8QO+9HtnyF954ZfjBbA0vnxa6JAswC1Ps=; b=gJRl3cMHY5zNIqTTeJD/ljkZ8h1WpOVjCFjticNgjmWwkmUzcx7u5/sptIa1N5SjWf 6S8jbi1/pHY0lPgwHCwULKJFjuMbr+Wex5eokptCnJ/a7Qa0PKWXJzenCzf9Y5XOO/7w 4sl4O3m7y+ulhcOSFVVNBQqow9x/16jWwgsYWbGd1C4IusxP0jdAvEsjMRJTzsOPAdBB aF7Nxoc/c+POt9OvQKAa29mMPTxiU5att/onBOR+w9jpY69GUMLUSSwwGnw7TNiEEp/2 Wetu040VmQklH+CJgMXGoHMc82Apuqjun9ucxo3XGY1R+i5FUIyd7duXUG8LGvmStuKs +f1Q== X-Gm-Message-State: AOAM532TTdHmjUUdb2s6hmu37AjqKx1zJamagq4htxsGYoH2SGSRAhRB mYaJ1Wjsn86CYtk2dcwUsuQHhw== X-Google-Smtp-Source: ABdhPJxHtdOyVNsCNjd2t5IfyMpkQS8AYpa+ysZqzOWDK1+692kHmZaxj9P1RDTcNPkTOtsowF809Q== X-Received: by 2002:a05:600c:3588:: with SMTP id p8mr19899088wmq.71.1613998790400; Mon, 22 Feb 2021 04:59:50 -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 m24sm8151586wmc.18.2021.02.22.04.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 04:59:50 -0800 (PST) Date: Mon, 22 Feb 2021 12:59:48 +0000 From: "Leif Lindholm" To: Rebecca Cran Cc: devel@edk2.groups.io, Ard Biesheuvel , Graeme Gregory , Radoslaw Biernacki Subject: Re: [edk2-platforms PATCH v3 1/3] SbsaQemu: Add FdtHelperLib Message-ID: <20210222125948.GT1664@vanye> References: <20210219035741.1467-1-rebecca@nuviainc.com> <20210219035741.1467-2-rebecca@nuviainc.com> MIME-Version: 1.0 In-Reply-To: <20210219035741.1467-2-rebecca@nuviainc.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Feb 18, 2021 at 20:57:39 -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 One comment below, you can fold in or not and still keep the reviewed-by. > --- > 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 There is no inherent need to restrict this function to a 16-bit return value (and on RISC architectures, this generally means extra masking going on). Indeed, the implementation uses a 32-bit value, then returns the bottom 16 bits of that. I guess this ends up going into a 16-bit field somewhere else? Another way to deal with that would be to take the full 32-bit value and ASSERT at the point of stuffing the table. / Leif > +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 >