From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) by mx.groups.io with SMTP id smtpd.web08.10312.1614090403760667718 for ; Tue, 23 Feb 2021 06:26:43 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=tah9nUOl; spf=pass (domain: nuviainc.com, ip: 209.85.166.178, mailfrom: rebecca@nuviainc.com) Received: by mail-il1-f178.google.com with SMTP id q9so14238528ilo.1 for ; Tue, 23 Feb 2021 06:26:43 -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=6JvUsJBSzK5EduGxAH2MgnX89uBYcrZX5grYti6ktys=; b=tah9nUOlH42QxfrWXTQ68DegkFyr6CE/CZjkjfbNmAQv6rzvp0sHySndZsmyGkSZlr 9/AmD9ZcHyHe5VQkMHDb+1XuJf4tlsQxtXRMUeCaX8rMppo2PiN/Yo04LNTCYNUwrhJX tIjp12cSFHpHj0bfDE4hswO2+Ip+2l3HSw6OGCu3jEz9dlUvFlY1Zu4AbIxqzh7mQWxy S3NLN/E6Il0Qs3Erb/du++sJvsxgpJBPl6BuWjQS7LbgmZqMwdEtwkBVa4G9tYLQoXUF lyBRuOCe+KsRxHpiSJc0AE+Yc59V7m8fbiUuX6LH9psQ6KrzxW6/p52MrND+ObC7OEBW JMUg== 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=6JvUsJBSzK5EduGxAH2MgnX89uBYcrZX5grYti6ktys=; b=fTXZuUNaF4OECYROLfqg8vo32yBc/FGStBPtU0zUV/DfU2XtHljt/LWc0CAqN0Gomm E6G7IASmjHaEtUtkCdrosqn0wDzuU1dhen1SAiC5Huf1VUabXEErUenbwVbpaIlbgL0M oPJZKJDgDj4fUHl5C/DCcjgD2b3r3NMtG3ospcvLvn79USYvT/WphVJ+Za0fdWWgrl6F DZZjBmEf/DPIK+8RbsLeSlE2OztqAAXeDPhrhsCfW0lwG6w01l69gjgVZw9GlKQcjsGP rTIeHa1inEXCLiZYhLB7GyewvVxlVA7/y8BRYd5Rh9C72XtEBLb9ScqyUjoSvzUW2b6b thNw== X-Gm-Message-State: AOAM530zs7XM6ib+ZMN5ChfH7/jqxwAadVc1aodspIk3JGEMN5I0Vy1n MSaq/69b7Qpf/Nj9LWGIU77kwlNv9GKOJ4UJo2+L9Qr70CvtT3hMO9N4JHbmCq09zQCPh4udWPm b/PurzjeBjitPl82pLt3ADeXns8AZluukmdE13jwaSeHiHGCwASFvdaKh8YGQzWRSS1nGHQ== X-Google-Smtp-Source: ABdhPJzEseMvXsyZYUlX3uNGK81QCvwWCqQSokLRcI44K1m3fCSdtxAcqCHjRseWJocqEvxPfpWDhQ== X-Received: by 2002:a92:d447:: with SMTP id r7mr19651675ilm.272.1614090402808; Tue, 23 Feb 2021 06:26:42 -0800 (PST) Return-Path: Received: from cube.int.bluestop.org (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id b9sm15391541ilo.41.2021.02.23.06.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 06:26:42 -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 v4 1/4] SbsaQemu: Add FdtHelperLib Date: Tue, 23 Feb 2021 07:26:32 -0700 Message-Id: <20210223142635.8807-2-rebecca@nuviainc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210223142635.8807-1-rebecca@nuviainc.com> References: <20210223142635.8807-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 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 ( 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