From: "Tanmay Jagdale" <tanmay.jagdale@linaro.org>
To: leif@nuviainc.com, graeme@nuviainc.com, devel@edk2.groups.io
Cc: shashi.mallela@linaro.org, Tanmay Jagdale <tanmay.jagdale@linaro.org>
Subject: [PATCH v3 edk2-platforms 4/8] SbsaQemu: Add new ACPI driver and FDT parser to count CPUs
Date: Tue, 25 Aug 2020 19:09:54 +0530 [thread overview]
Message-ID: <20200825133958.17372-5-tanmay.jagdale@linaro.org> (raw)
In-Reply-To: <20200825133958.17372-1-tanmay.jagdale@linaro.org>
- Add a new ACPI driver for the SbsaQemu platform which would
handle any modifications needed for the ACPI tables.
- Add a parser function in this driver which parses the FDT created
by Qemu to determine the number of CPUs and hence update the
PcdCoreCount variable.
Signed-off-by: Tanmay Jagdale <tanmay.jagdale@linaro.org>
---
Silicon/Qemu/SbsaQemu/Acpi.dsc.inc | 1 +
Platform/Qemu/SbsaQemu/SbsaQemu.fdf | 1 +
Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf | 49 +++++++++++++
Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 75 ++++++++++++++++++++
4 files changed, 126 insertions(+)
diff --git a/Silicon/Qemu/SbsaQemu/Acpi.dsc.inc b/Silicon/Qemu/SbsaQemu/Acpi.dsc.inc
index c4a8d7a27b78..593670383750 100644
--- a/Silicon/Qemu/SbsaQemu/Acpi.dsc.inc
+++ b/Silicon/Qemu/SbsaQemu/Acpi.dsc.inc
@@ -33,3 +33,4 @@ [Components.common]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf
Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf
+ Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.fdf b/Platform/Qemu/SbsaQemu/SbsaQemu.fdf
index 4526eaaa02c5..3bcf0bf0040a 100644
--- a/Platform/Qemu/SbsaQemu/SbsaQemu.fdf
+++ b/Platform/Qemu/SbsaQemu/SbsaQemu.fdf
@@ -232,6 +232,7 @@ [FV.FvMain]
#
INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
INF MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf
+ INF Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
INF RuleOverride = ACPITABLE Silicon/Qemu/SbsaQemu/AcpiTables/AcpiTables.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
new file mode 100644
index 000000000000..3795a7e11639
--- /dev/null
+++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
@@ -0,0 +1,49 @@
+## @file
+# This driver modifies ACPI tables for the Qemu SBSA platform
+#
+# Copyright (c) 2020, Linaro Ltd. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001d
+ BASE_NAME = SbsaQemuAcpiDxe
+ FILE_GUID = 6c592dc9-76c8-474f-93b2-bf1e8f15ae35
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+
+ ENTRY_POINT = InitializeSbsaQemuAcpiDxe
+
+[Sources]
+ SbsaQemuAcpiDxe.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ ArmVirtPkg/ArmVirtPkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Qemu/SbsaQemu/SbsaQemu.dec
+
+[LibraryClasses]
+ ArmLib
+ BaseMemoryLib
+ BaseLib
+ DebugLib
+ DxeServicesLib
+ FdtLib
+ PcdLib
+ UefiDriverEntryPoint
+ UefiLib
+ UefiRuntimeServicesTableLib
+
+[Pcd]
+ gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdCoreCount
+ gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdClusterCount
+ gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress
+
+[Depex]
+ TRUE
diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c
new file mode 100644
index 000000000000..75abdae3b8ce
--- /dev/null
+++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c
@@ -0,0 +1,75 @@
+/** @file
+* This file is an ACPI driver for the Qemu SBSA platform.
+*
+* Copyright (c) 2020, Linaro Ltd. All rights reserved.
+*
+* SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiLib.h>
+#include <Protocol/FdtClient.h>
+#include <libfdt.h>
+
+/*
+ * A function that walks through the Device Tree created
+ * by Qemu and counts the number of CPUs present in it.
+ */
+STATIC
+VOID
+CountCpusFromFdt (
+ VOID
+)
+{
+ VOID *DeviceTreeBase;
+ INT32 Node, Prev;
+ RETURN_STATUS PcdStatus;
+ 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;
+ }
+
+ 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;
+ }
+
+ PcdStatus = PcdSet32S (PcdCoreCount, CpuCount);
+ ASSERT_RETURN_ERROR (PcdStatus);
+}
+
+EFI_STATUS
+EFIAPI
+InitializeSbsaQemuAcpiDxe (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ // Parse the device tree and get the number of CPUs
+ CountCpusFromFdt ();
+
+ return EFI_SUCCESS;
+}
--
2.28.0
next prev parent reply other threads:[~2020-08-25 13:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-25 13:39 [PATCH v3 edk2-platforms 0/8] Add ACPI tables support for SbsaQemu Tanmay Jagdale
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 1/8] SbsaQemu: Initial support for static ACPI tables Tanmay Jagdale
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 2/8] SbsaQemu: AcpiTables: Add PCI support and MCFG Table Tanmay Jagdale
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 3/8] SbsaQemu: SbsaQemu.dsc: Move CoreCount and Fdtlib Tanmay Jagdale
2020-08-25 13:39 ` Tanmay Jagdale [this message]
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 5/8] SbsaQemu: AcpiDxe: Create MADT table at runtime Tanmay Jagdale
2020-08-26 15:35 ` graeme
2020-08-26 22:48 ` Graeme Gregory
2020-08-27 2:56 ` Tanmay Jagdale
2020-08-27 9:41 ` Graeme Gregory
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 6/8] SbsaQemu: AcpiDxe: Create SSDT " Tanmay Jagdale
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 7/8] SbsaQemu: AcpiDxe: Create PPTT " Tanmay Jagdale
2020-08-25 13:39 ` [PATCH v3 edk2-platforms 8/8] SbsaQemu: AcpiTables: Add DBG2 Table Tanmay Jagdale
2020-08-25 13:57 ` [PATCH v3 edk2-platforms 0/8] Add ACPI tables support for SbsaQemu Leif Lindholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200825133958.17372-5-tanmay.jagdale@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox