From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mx.groups.io with SMTP id smtpd.web10.8428.1614692312137108593 for ; Tue, 02 Mar 2021 05:38:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=kvrlxgFA; spf=pass (domain: nuviainc.com, ip: 209.85.128.52, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f52.google.com with SMTP id n4so2772071wmq.3 for ; Tue, 02 Mar 2021 05:38:31 -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:mime-version :content-transfer-encoding; bh=o8T6K8HnU4B+OhquTaNAMdRfvoFUCVt4+vQp/gL3vfc=; b=kvrlxgFAKT+C6ov3H40exxl3BptRbDabdCh7/yyrhmUpWgHudlG+zJWH39Rrw91n/t NHVnEFH/DIEfbgXv5ItvFbq6NgeyoBSrl/iof81D7lpALkMRgPGTYcLU+FNOFPWx37H0 ouo2vTSOqU7nRGd+2zsrrRBqQi1m8SNExJzHr2rU7uRrTmYsV8ogTBhYYcCNELFH7PEL +X+l3lVOOhuOtqZtlwzwZQJivRrZuqKJEK14JgecqPj6FFkeApeKCMUEQfqvi5XtwXQe DwXSzVTqfIjMpDTQJrJL/tJALLao2+BZdiiXVygI6K1GMFg427KIypYfqIRf/iW9mXfr Wwug== 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:mime-version :content-transfer-encoding; bh=o8T6K8HnU4B+OhquTaNAMdRfvoFUCVt4+vQp/gL3vfc=; b=s4nRLBCHKDlckJl8Wm215ZFtUff4zGIS2mgckvKJSCLAJqB8ukO274/11mNBL+OWh/ 8IljoZqTtDaWWSo2U+ZGEZIWRA1t4cRJH+HtNYi0Z72eTsgv3gDfVeBEhRfeGTX5jgvB yQY0QTGqTS1XkB4tH3YPamapMYCums+KkNfCc5s1zGa1CMQX+T1kluv9PukpuhwiWvy2 trbP8Pz0oJlVkUVYfYGNle6DIJrZv5NJeGLsPlO1v4M4pN79HNozWWvsmCI6D/Go3oby Hfzi563g0c90YnITDRNPsieznysR/g4BMmi+Qc8N/o5Rt9T0lBHcQULUvOFGxfSJ3I1j ll6A== X-Gm-Message-State: AOAM533HuYEtr/7SO8iJcYM6UMwwRYpRxA+DgE8Dxo0IWezip9Obrxp0 pXr4PFP8NCiqbwh8rUKyYbcPeFY5Oy7fntyhyuCusU15bigQFOgdiFRVn/xmBSdp9yDQJzzWTI/ 17MX/YMjobx8ur9p//jYbmh8Qm4VHDx42qnea3RGjtBzWnmzUSjFb5D1ruCWAH7i3tA== X-Google-Smtp-Source: ABdhPJzXr6POHZ7o7rXTPK4drC2+/eQENWAaz8yHVS3RlCjOHqsQRodIDmYXuoBBhgwDojtlI0pZQw== X-Received: by 2002:a05:600c:4ec6:: with SMTP id g6mr4267254wmq.2.1614692310331; Tue, 02 Mar 2021 05:38:30 -0800 (PST) Return-Path: Received: from vanye.hemma.eciton.net (cpc1-cmbg19-2-0-cust915.5-4.cable.virginm.net. [82.27.183.148]) by smtp.gmail.com with ESMTPSA id f22sm2634861wmc.33.2021.03.02.05.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 05:38:29 -0800 (PST) From: "Leif Lindholm" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Graeme Gregory , Radoslaw Biernacki , Tanmay Jagdale , Rebecca Cran , Marcin Juszkiewicz Subject: [PATCH edk2-platforms 1/1] Silicon/Qemu: Move SbsaQemu MPIDR-retrieval function to FdtHelperLib Date: Tue, 2 Mar 2021 13:38:28 +0000 Message-Id: <20210302133828.19321-1-leif@nuviainc.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit 822634fc1bf1 ("SbsaQemu: Update SbsaQemuAcpiDxe to use FdtHelperLib") replaced the CountCpusFromFdt() function in SbsaQemuAcpiDxe with a call to FdtHelperCountCpus() in FdtHelperLib. This ended up leaving static variables FdtFirstCpuOffset and FdtCpuNodeSize uninitialised, such that the GetMpidr() function kept returning the value for cpu 0. Resolve this by moving the GetMpidr() function over to FdtHelperLib, where it can again share these variables with FdtHelperCountCpus(). Fix up coding style issues as part of copy: - Add m prefix to module-global variables. - Add doxygen function comment header. Cc: Ard Biesheuvel Cc: Graeme Gregory Cc: Radoslaw Biernacki Cc: Tanmay Jagdale Cc: Rebecca Cran Reported-by: Marcin Juszkiewicz Signed-off-by: Leif Lindholm --- Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf | 2 -- Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf | 5 +++ Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h | 12 +++++++ Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c | 35 +------------------ Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c | 36 ++++++++++++++++++++ 5 files changed, 54 insertions(+), 36 deletions(-) diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf index a58ebfaf76d5..c6de685bd2c4 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf @@ -35,7 +35,6 @@ [LibraryClasses] DebugLib DxeServicesLib FdtHelperLib - FdtLib PcdLib PrintLib UefiDriverEntryPoint @@ -46,7 +45,6 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdCoreCount gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdClusterCount - gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress [Depex] gEfiAcpiTableProtocolGuid ## CONSUMES diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf index d84c16f888d1..9c059f3e5851 100644 --- a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf +++ b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf @@ -24,5 +24,10 @@ [Packages] MdePkg/MdePkg.dec Silicon/Qemu/SbsaQemu/SbsaQemu.dec +[LibraryClasses] + DebugLib + FdtLib + PcdLib + [FixedPcd] gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h b/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h index f9045fd5df45..ea9159857215 100644 --- a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h +++ b/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h @@ -10,6 +10,18 @@ #ifndef FDT_HELPER_LIB_ #define FDT_HELPER_LIB_ +/** + Get MPIDR for a given cpu from device tree passed by Qemu. + + @param [in] CpuId Index of cpu to retrieve MPIDR value for. + + @retval MPIDR value of CPU at index +**/ +UINT64 +FdtHelperGetMpidr ( + IN UINTN CpuId + ); + /** Walks through the Device Tree created by Qemu and counts the number of CPUs present in it. diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c index 84120f1c1b51..b8901030ecd0 100644 --- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c +++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c @@ -20,39 +20,6 @@ #include #include #include -#include -#include - -STATIC INT32 FdtFirstCpuOffset; -STATIC INT32 FdtCpuNodeSize; - -/* - * Get MPIDR from device tree passed by Qemu - */ -STATIC -UINT64 -GetMpidr ( - IN UINTN CpuId - ) -{ - VOID *DeviceTreeBase; - CONST UINT64 *RegVal; - INT32 Len; - - DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); - ASSERT (DeviceTreeBase != NULL); - - RegVal = fdt_getprop (DeviceTreeBase, - FdtFirstCpuOffset + (CpuId * FdtCpuNodeSize), - "reg", - &Len); - if (!RegVal) { - DEBUG ((DEBUG_ERROR, "Couldn't find reg property for CPU:%d\n", CpuId)); - return 0; - } - - return (fdt64_to_cpu (ReadUnaligned64 (RegVal))); -} /* * A Function to Compute the ACPI Table Checksum @@ -159,7 +126,7 @@ AddMadtTable ( CopyMem (New, &Gicc, sizeof (EFI_ACPI_6_0_GIC_STRUCTURE)); GiccPtr = (EFI_ACPI_6_0_GIC_STRUCTURE *) New; GiccPtr->AcpiProcessorUid = CoreIndex; - GiccPtr->MPIDR = GetMpidr (CoreIndex); + GiccPtr->MPIDR = FdtHelperGetMpidr (CoreIndex); New += sizeof (EFI_ACPI_6_0_GIC_STRUCTURE); } diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c index bbd756f01a21..7fdfb055db76 100644 --- a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c +++ b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c @@ -14,6 +14,40 @@ #include #include +STATIC INT32 mFdtFirstCpuOffset; +STATIC INT32 mFdtCpuNodeSize; + +/** + Get MPIDR for a given cpu from device tree passed by Qemu. + + @param [in] CpuId Index of cpu to retrieve MPIDR value for. + + @retval MPIDR value of CPU at index +**/ +UINT64 +FdtHelperGetMpidr ( + IN UINTN CpuId + ) +{ + VOID *DeviceTreeBase; + CONST UINT64 *RegVal; + INT32 Len; + + DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeBaseAddress); + ASSERT (DeviceTreeBase != NULL); + + RegVal = fdt_getprop (DeviceTreeBase, + mFdtFirstCpuOffset + (CpuId * mFdtCpuNodeSize), + "reg", + &Len); + if (!RegVal) { + DEBUG ((DEBUG_ERROR, "Couldn't find reg property for CPU:%d\n", CpuId)); + return 0; + } + + return (fdt64_to_cpu (ReadUnaligned64 (RegVal))); +} + /** Walks through the Device Tree created by Qemu and counts the number of CPUs present in it. @@ -49,12 +83,14 @@ FdtHelperCountCpus ( // The count of these subnodes corresponds to the number of // CPUs created by Qemu. Prev = fdt_first_subnode (DeviceTreeBase, CpuNode); + mFdtFirstCpuOffset = Prev; while (1) { CpuCount++; Node = fdt_next_subnode (DeviceTreeBase, Prev); if (Node < 0) { break; } + mFdtCpuNodeSize = Node - Prev; Prev = Node; } -- 2.20.1