From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by mx.groups.io with SMTP id smtpd.web10.8995.1598340245533509724 for ; Tue, 25 Aug 2020 00:24:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=bZ11JJ+x; spf=pass (domain: linaro.org, ip: 209.85.216.66, mailfrom: tanmay.jagdale@linaro.org) Received: by mail-pj1-f66.google.com with SMTP id q1so768465pjd.1 for ; Tue, 25 Aug 2020 00:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mBYZ4VY2PLlbBS8W75KJdSbYH84lYPasHJgO4/LXq8U=; b=bZ11JJ+xist3EJVvDkiH7Oeix2/7LO1kktCH9nzJW3tQZ8TzfoEs2FaCUdaTPC/tpK ELjs4lgXUCB/6XTK6X7Mlq7IXURaAtOvPdAYIoWe81hV7y9vA/+9P9uPUdwlNgDQTeAv J5WnqV5e1rPMGMq0sF1i2ryYzviz8MKIzWU6i3rvRDGTFvcKT1gRdGTngiDdCMq1SfQj s5pfiCDr7QWXZYcwGaKZDDKeUpVYpXdmAJQJHPCALvMjj5pxJUjbg3bQWFN9PJnCaw6l ZDWCA811sRxwhTgf6xLrWRpphO5hVAZ49ViDBPF0MYVXaPj+0+wdmd6Az6yd0obus49k 2Arg== 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=mBYZ4VY2PLlbBS8W75KJdSbYH84lYPasHJgO4/LXq8U=; b=Ijuda40usd6RmdmldnYwEuJSKcnpRrpZg1F+yJtCsxDGOtT/A3KnXKn1wqZX086T7x r2K/qmRyBKBypJsZy3dKjfl3Vs7/DX5b3+TOTLwOh0XU0kDTcDSBi6jX8JtFgOBV6qMN BqokuPUQ8Z7SbhBYwPbphsCbcTw/NQkfHnJKieC+7drAwG9BJlQEaHJu2z+iEzM293mw XJQlRZj9z9eCXXVemVNyUBZ6i1F3uuLyCeWteo/5znAskbybaOzXNiWaMHtQxix7yqzO v0EMkioc9voDgmtAanqDe/nyXU6ycT64YVlBWsM7VnU8FfkO0VG6uAbHPIaUtSW/O0hT JkDw== X-Gm-Message-State: AOAM530+oUQOIdJsMRL3UvKOO2BUADERDXWyxQq/6yGRd3QPBIe9ySiF taRUcKuaiRsn50r/sRD8GP0hXA== X-Google-Smtp-Source: ABdhPJwWji7ZPm6BOrmw5ZskRBU6CLfzNlHcAH1YQU43CIODk7IRI3aZORGj4KRVxJ+oSOcIGGRNRA== X-Received: by 2002:a17:90b:1b12:: with SMTP id nu18mr532117pjb.126.1598340245080; Tue, 25 Aug 2020 00:24:05 -0700 (PDT) Return-Path: Received: from bean-canyon.localdomain ([106.51.140.68]) by smtp.googlemail.com with ESMTPSA id d5sm1722417pjw.18.2020.08.25.00.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 00:24:04 -0700 (PDT) From: "Tanmay Jagdale" To: leif@nuviainc.com, graeme@nuviainc.com, shashi.mallela@linaro.org, devel@edk2.groups.io Cc: paul.isaacs@linaro.org, tanmay@marvell.com, Tanmay Jagdale Subject: [PATCH v2 edk2-platforms 4/8] SbsaQemu: Add new ACPI driver and FDT parser to count CPUs Date: Tue, 25 Aug 2020 12:53:18 +0530 Message-Id: <20200825072322.10848-5-tanmay.jagdale@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200825072322.10848-1-tanmay.jagdale@linaro.org> References: <20200825072322.10848-1-tanmay.jagdale@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit - 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 --- 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 | 76 ++++++++++++++++++++ 4 files changed, 127 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..d0d413891e81 --- /dev/null +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c @@ -0,0 +1,76 @@ +/** @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 +#include +#include +#include +#include +#include +#include + +/* + * 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((EFI_D_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; + } + ASSERT (CpuCount > 0); + + 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