Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems
@ 2026-11-16 18:21 Leo Yan
  2026-11-16 18:21 ` [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks Leo Yan
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

This series follows Johnny Fan's SPE/TRBE work [1], which requires
ACPI-specific IRQ affinity handling in the drivers. It provides a common
way to describe PPI affinity for devices created from the MADT.

Register one platform device for each group of CPUs with the same MIDR.
Associate a software node with each device to expose its CPU mask through
platform_get_irq_affinity(). SPE and TRBE drivers can then obtain affinity
without ACPI-specific handling or a processor-container companion.

Grouping by MIDR allows CPU PMU events to follow tasks across compatible
CPUs, including CPUs in different processor containers. SPE and TRBE
require a shared GSI within each group. CPU PMUs can also use per-CPU SPIs
and reuse the platform probe path used for DT. Move the common ACPI device
registration to drivers/acpi/arm64/.

This series has been tested on Orion O6, with four little Cortex-A520
cores (CPUs 2-5) and eight big Cortex-A720 cores (CPUs 0-1 and 6-11).
It exposes the following PMU devices:

  # ls /sys/bus/event_source/devices/
  arm_spe_0  armv8_pmuv3_0  armv8_pmuv3_1  breakpoint  cs_etm  kprobe  software  tracepoint  uprobe
  # cat /sys/bus/event_source/devices/armv8_pmuv3_0/cpus
  0-1,6-11
  # cat /sys/bus/event_source/devices/armv8_pmuv3_1/cpus
  2-5
  # cat /sys/bus/event_source/devices/arm_spe_0/cpumask
  0-1,6-11
  # ls /sys/bus/event_source/devices/cs_etm/sinks/
  trbe0  trbe1  trbe10  trbe11  trbe2  trbe3  trbe4  trbe5  trbe6  trbe7  trbe8  trbe9

The CPU PMU masks match the MIDR groups: eight A720 CPUs and four A520
CPUs. SPE uses the A720 mask, and TRBE exposes one sink per CPU.

[1] https://lore.kernel.org/linux-arm-kernel/20261102084153.3975282-1-johnny.fan@cixtech.com/

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Johnny.Fan (1):
      perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes

Leo Yan (7):
      device property: Add firmware node IRQ affinity callbacks
      device property: Add software-node IRQ affinity masks
      perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts
      perf/arm_pmu: Register ACPI CPU PMUs as platform devices
      perf/arm_pmu: Support ACPI devices in the platform probe
      perf/arm_pmu: Use ACPI CPU affinity in IRQ handling
      ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/

 MAINTAINERS                     |   1 +
 arch/arm64/include/asm/acpi.h   |   3 +
 drivers/acpi/arm64/Kconfig      |   4 +
 drivers/acpi/arm64/Makefile     |   1 +
 drivers/acpi/arm64/pmu.c        | 393 +++++++++++++++++++++++++++++++++++
 drivers/acpi/property.c         |   8 +
 drivers/base/platform.c         |   7 +-
 drivers/base/property.c         |  15 ++
 drivers/base/swnode.c           |  53 +++++
 drivers/of/property.c           |   7 +
 drivers/perf/Kconfig            |   4 -
 drivers/perf/Makefile           |   1 -
 drivers/perf/arm_pmu.c          |   3 +-
 drivers/perf/arm_pmu_acpi.c     | 438 ----------------------------------------
 drivers/perf/arm_pmu_platform.c |  62 +++++-
 drivers/perf/arm_pmuv3.c        |   5 +-
 include/linux/cpuhotplug.h      |   1 -
 include/linux/fwnode.h          |   5 +
 include/linux/perf/arm_pmu.h    |  12 +-
 include/linux/property.h        |   6 +
 20 files changed, 552 insertions(+), 477 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261109-acpi_arm_pmu_registration_hmp-6c595cf0d8de

Best regards,
-- 
Leo Yan <leo.yan@arm.com>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:28   ` sashiko-bot
  2026-11-16 18:21 ` [PATCH 2/8] device property: Add software-node IRQ affinity masks Leo Yan
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

Platform IRQ affinity lookup currently selects the OF or ACPI helper
directly. Add fwnode_irq_get_affinity() and an irq_get_affinity operation
implemented by both firmware types.

Use the new helper for platform devices, preserving the existing fallback
to cpu_possible_mask when affinity information is unavailable.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/acpi/property.c  |  8 ++++++++
 drivers/base/platform.c  |  7 +------
 drivers/base/property.c  | 15 +++++++++++++++
 drivers/of/property.c    |  7 +++++++
 include/linux/fwnode.h   |  5 +++++
 include/linux/property.h |  2 ++
 6 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 8ee5a1f0eb4869114c5d282f5808974687d46f5c..558de77bd4442fd7c85797f41b84c13f8fc27c67 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1735,6 +1735,13 @@ static int acpi_fwnode_irq_get(const struct fwnode_handle *fwnode,
 	return res.start;
 }
 
+static const struct cpumask *
+acpi_fwnode_irq_get_affinity(const struct fwnode_handle *fwnode,
+			     unsigned int index)
+{
+	return acpi_irq_get_affinity(ACPI_HANDLE_FWNODE(fwnode), index);
+}
+
 #define DECLARE_ACPI_FWNODE_OPS(ops) \
 	const struct fwnode_operations ops = {				\
 		.device_is_available = acpi_fwnode_device_is_available, \
@@ -1761,6 +1768,7 @@ static int acpi_fwnode_irq_get(const struct fwnode_handle *fwnode,
 		.graph_get_port_parent = acpi_fwnode_get_parent,	\
 		.graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \
 		.irq_get = acpi_fwnode_irq_get,				\
+		.irq_get_affinity = acpi_fwnode_irq_get_affinity,		\
 	};								\
 	EXPORT_SYMBOL_GPL(ops)
 
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 3593d45f4a7ae8207286a7ce0671419c6de556d1..e6352ef63a20cb818d958e7e2a0a9c37170c1769 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -155,12 +155,7 @@ static const struct cpumask *get_irq_affinity(struct platform_device *dev,
 {
 	const struct cpumask *mask = NULL;
 #ifndef CONFIG_SPARC
-	struct fwnode_handle *fwnode = dev_fwnode(&dev->dev);
-
-	if (is_of_node(fwnode))
-		mask = of_irq_get_affinity(to_of_node(fwnode), num);
-	else if (is_acpi_device_node(fwnode))
-		mask = acpi_irq_get_affinity(ACPI_HANDLE_FWNODE(fwnode), num);
+	mask = fwnode_irq_get_affinity(dev_fwnode(&dev->dev), num);
 #endif
 
 	return mask ?: cpu_possible_mask;
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 51109794d7275ddaf4571584d0e77d8573ebb475..b6d9fd3c5bdeec9636e49d2319d2b43a55758a85 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1109,6 +1109,21 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
 }
 EXPORT_SYMBOL(fwnode_irq_get_byname);
 
+/**
+ * fwnode_irq_get_affinity - Get the CPU affinity of an IRQ from a fwnode
+ * @fwnode:	Pointer to the firmware node
+ * @index:	Zero-based index of the IRQ
+ *
+ * Return: A borrowed CPU mask, valid while @fwnode lives, or NULL if no affinity
+ * information is available.
+ */
+const struct cpumask *fwnode_irq_get_affinity(const struct fwnode_handle *fwnode,
+					      unsigned int index)
+{
+	return fwnode_call_ptr_op(fwnode, irq_get_affinity, index);
+}
+EXPORT_SYMBOL_GPL(fwnode_irq_get_affinity);
+
 /**
  * fwnode_graph_get_next_endpoint - Get next endpoint firmware node
  * @fwnode: Pointer to the parent firmware node
diff --git a/drivers/of/property.c b/drivers/of/property.c
index 45e55f61848801ed497702c6cfe501009904c49d..f1426533e7ec0dfdfaef5d1cbb2b6e6acc87a1d2 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1660,6 +1660,12 @@ static int of_fwnode_irq_get(const struct fwnode_handle *fwnode,
 	return of_irq_get(to_of_node(fwnode), index);
 }
 
+static const struct cpumask *
+of_fwnode_irq_get_affinity(const struct fwnode_handle *fwnode, unsigned int index)
+{
+	return of_irq_get_affinity(to_of_node(fwnode), index);
+}
+
 static int match_property_by_path(const char *node_path, const char *prop_name,
 				  const char *value)
 {
@@ -1724,6 +1730,7 @@ const struct fwnode_operations of_fwnode_ops = {
 	.graph_parse_endpoint = of_fwnode_graph_parse_endpoint,
 	.iomap = of_fwnode_iomap,
 	.irq_get = of_fwnode_irq_get,
+	.irq_get_affinity = of_fwnode_irq_get_affinity,
 	.add_links = of_fwnode_add_links,
 };
 EXPORT_SYMBOL_GPL(of_fwnode_ops);
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index a9dcaf7e70765637a0c33af2ae0ac541e15752ad..9f45a58fda6802b924cd67585e51e8f537e6d625 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -28,6 +28,7 @@ enum dev_dma_attr {
 
 struct fwnode_operations;
 struct device;
+struct cpumask;
 
 /*
  * fwnode flags
@@ -138,6 +139,8 @@ struct fwnode_reference_args {
  * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
  * @iomap: Map the I/O memory of a given index for a fwnode.
  * @irq_get: Get the IRQ of a given index for a fwnode.
+ * @irq_get_affinity: Get the CPU affinity of a given IRQ index, or NULL if
+ *		   unavailable. The returned mask is valid while the fwnode lives.
  * @add_links:	Create fwnode links to all the suppliers of the fwnode. Return
  *		zero on success, a negative error code otherwise.
  */
@@ -186,6 +189,8 @@ struct fwnode_operations {
 				    struct fwnode_endpoint *endpoint);
 	void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
 	int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
+	const struct cpumask *(*irq_get_affinity)(const struct fwnode_handle *fwnode,
+						  unsigned int index);
 	int (*add_links)(struct fwnode_handle *fwnode);
 };
 
diff --git a/include/linux/property.h b/include/linux/property.h
index 9143fe4f5c05179e595ba875aafbcb006a740824..08c901015a9ea4b9223a29d07749f88a5d672ea7 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -230,6 +230,8 @@ DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T))
 
 int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
 int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);
+const struct cpumask *fwnode_irq_get_affinity(const struct fwnode_handle *fwnode,
+					      unsigned int index);
 
 unsigned int fwnode_get_child_node_count(const struct fwnode_handle *fwnode);
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/8] device property: Add software-node IRQ affinity masks
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
  2026-11-16 18:21 ` [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:29   ` sashiko-bot
  2026-11-16 18:21 ` [PATCH 3/8] perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes Leo Yan
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

Devices created from firmware tables may need CPU affinity information
without a corresponding firmware node. Allow software nodes to supply
this information through the common firmware node IRQ affinity API.

Add software_node_add_irq_affinity() to copy a CPU mask for an IRQ index,
and implement the software node irq_get_affinity callback. Keep each mask
until the node is released and reject replacement so borrowed masks remain
valid for the node's lifetime.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/base/swnode.c    | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/property.h |  4 ++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index cf495e67f0763ad83a849474152e71d0640c76dd..64d5e12e4871771c20a64162260d92d3e24b4191 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/container_of.h>
+#include <linux/cpumask.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/export.h>
@@ -21,6 +22,7 @@
 #include <linux/string.h>
 #include <linux/sysfs.h>
 #include <linux/types.h>
+#include <linux/xarray.h>
 
 #include "base.h"
 
@@ -31,6 +33,7 @@ struct swnode {
 	int id;
 	/* Device the managed node's lifetime is tied to. */
 	struct device *owner;
+	struct xarray irq_affinity;
 
 	/* hierarchy */
 	struct ida child_ids;
@@ -756,6 +759,13 @@ static int software_node_add_links(struct fwnode_handle *fwnode)
 	return 0;
 }
 
+static const struct cpumask *
+software_node_irq_get_affinity(const struct fwnode_handle *fwnode,
+			       unsigned int index)
+{
+	return xa_load(&to_swnode(fwnode)->irq_affinity, index);
+}
+
 static const struct fwnode_operations software_node_ops = {
 	.get = software_node_get,
 	.put = software_node_put,
@@ -774,6 +784,7 @@ static const struct fwnode_operations software_node_ops = {
 	.graph_get_port_parent = software_node_graph_get_port_parent,
 	.graph_parse_endpoint = software_node_graph_parse_endpoint,
 	.add_links = software_node_add_links,
+	.irq_get_affinity = software_node_irq_get_affinity,
 };
 
 /* -------------------------------------------------------------------------- */
@@ -844,6 +855,8 @@ static void software_node_free(const struct software_node *node)
 static void software_node_release(struct kobject *kobj)
 {
 	struct swnode *swnode = kobj_to_swnode(kobj);
+	struct cpumask *affinity;
+	unsigned long index;
 
 	fwnode_links_purge(&swnode->fwnode);
 
@@ -857,6 +870,9 @@ static void software_node_release(struct kobject *kobj)
 	if (swnode->allocated)
 		software_node_free(swnode->node);
 
+	xa_for_each(&swnode->irq_affinity, index, affinity)
+		kfree(affinity);
+	xa_destroy(&swnode->irq_affinity);
 	ida_destroy(&swnode->child_ids);
 	kfree(swnode);
 }
@@ -891,6 +907,7 @@ swnode_register(const struct software_node *node, struct swnode *parent,
 	fwnode_init(&swnode->fwnode, &software_node_ops);
 
 	ida_init(&swnode->child_ids);
+	xa_init(&swnode->irq_affinity);
 	INIT_LIST_HEAD(&swnode->entry);
 	INIT_LIST_HEAD(&swnode->children);
 
@@ -1050,6 +1067,42 @@ void fwnode_remove_software_node(struct fwnode_handle *fwnode)
 }
 EXPORT_SYMBOL_GPL(fwnode_remove_software_node);
 
+/**
+ * software_node_add_irq_affinity - Add an IRQ affinity mask to a software node
+ * @fwnode: Software node to associate with the mask
+ * @index: Zero-based IRQ index
+ * @affinity: CPU affinity mask to copy
+ *
+ * The copy remains valid until the software node is released. Call this before
+ * publishing the node to interrupt consumers. An existing mask cannot be
+ * replaced, so masks returned by fwnode_irq_get_affinity() remain valid.
+ *
+ * Return: 0 on success, -EINVAL for an invalid node or mask, -EBUSY if the index
+ * already has a mask, or -ENOMEM if allocation fails.
+ */
+int software_node_add_irq_affinity(struct fwnode_handle *fwnode,
+				   unsigned int index,
+				   const struct cpumask *affinity)
+{
+	struct swnode *swnode = to_swnode(fwnode);
+	struct cpumask *mask;
+	int ret;
+
+	if (!swnode || !affinity)
+		return -EINVAL;
+
+	mask = kmemdup(affinity, cpumask_size(), GFP_KERNEL);
+	if (!mask)
+		return -ENOMEM;
+
+	ret = xa_insert(&swnode->irq_affinity, index, mask, GFP_KERNEL);
+	if (ret)
+		kfree(mask);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(software_node_add_irq_affinity);
+
 /**
  * device_add_software_node - Assign software node to a device
  * @dev: The device the software node is meant for.
diff --git a/include/linux/property.h b/include/linux/property.h
index 08c901015a9ea4b9223a29d07749f88a5d672ea7..186a77d1468505a10960efe6cdf7d53750acbf95 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -618,6 +618,10 @@ fwnode_create_software_node(const struct property_entry *properties,
 			    const struct fwnode_handle *parent);
 void fwnode_remove_software_node(struct fwnode_handle *fwnode);
 
+int software_node_add_irq_affinity(struct fwnode_handle *fwnode,
+				   unsigned int index,
+				   const struct cpumask *affinity);
+
 int device_add_software_node(struct device *dev, const struct software_node *node);
 void device_remove_software_node(struct device *dev);
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/8] perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
  2026-11-16 18:21 ` [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks Leo Yan
  2026-11-16 18:21 ` [PATCH 2/8] device property: Add software-node IRQ affinity masks Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:38   ` sashiko-bot
  2026-11-16 18:21 ` [PATCH 4/8] perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts Leo Yan
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

From: "Johnny.Fan" <johnny.fan@cixtech.com>

The MADT describes SPE and TRBE interrupts per CPU, without providing an
ACPI namespace device for each group of compatible CPUs. The existing
registration only supports a homogeneous system.

Group initialized CPUs by MIDR and register one platform device per
group through a common descriptor-based entry point. Keep each CPU's GSI
and CPU number in a mapping record until IRQ resource setup. Deduplicate
shared GSIs and use arm_acpi_pmu_irq_matches() to require the same
mapped IRQ within each group. Warn and exclude CPUs with inconsistent
PPIs.

Associate a software node containing the group's IRQ affinity so drivers
can obtain the CPU mask through platform_get_irq_affinity() without
ACPI-specific handling or a processor-container companion. Create IRQ
resources first, then use arm_acpi_register_sw_node_irq_affinity() to
store the filtered group's PPI affinity at index zero.

Although SPE and TRBE need only one shared PPI per group, introduce
nr_irqs and the irq_maps[] array now to simplify adding CPU PMU support
with per-CPU SPIs in a later patch.

Signed-off-by: Johnny.Fan <johnny.fan@cixtech.com>
Co-developed-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/perf/arm_pmu_acpi.c | 350 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 274 insertions(+), 76 deletions(-)

diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
index ca6bf8f86cfe9be0dc351e41bd620d1d37028dfa..7ae291acb04526d820bdfb9640aaa8352449be54 100644
--- a/drivers/perf/arm_pmu_acpi.c
+++ b/drivers/perf/arm_pmu_acpi.c
@@ -7,11 +7,15 @@
 
 #include <linux/acpi.h>
 #include <linux/cpumask.h>
+#include <linux/err.h>
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/irqdesc.h>
 #include <linux/percpu.h>
 #include <linux/perf/arm_pmu.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/slab.h>
 
 #include <asm/cpu.h>
 #include <asm/cputype.h>
@@ -68,92 +72,297 @@ static void arm_pmu_acpi_unregister_irq(int cpu)
 		acpi_unregister_gsi(gsi);
 }
 
-static int __maybe_unused
-arm_acpi_register_pmu_device(struct platform_device *pdev, u8 len,
-			     u16 (*parse_gsi)(struct acpi_madt_generic_interrupt *))
+struct arm_pmu_acpi_device_info {
+	const char *name;
+	u8 len;
+	u32 (*parse_gsi)(struct acpi_madt_generic_interrupt *gicc);
+};
+
+struct arm_pmu_acpi_irq_map {
+	u32 gsi;
+	int cpu;
+	int irq;	/* Nonzero only for mappings created by this group */
+};
+
+struct arm_pmu_acpi_group {
+	struct cpumask cpus;
+	int nr_irqs;
+	struct arm_pmu_acpi_irq_map irq_maps[];
+};
+
+static struct arm_pmu_acpi_group *
+arm_acpi_alloc_pmu_group(struct arm_pmu_acpi_group **groups, int *nr_groups,
+			 int cpu)
 {
-	int cpu, this_hetid, hetid, irq, ret;
-	u16 this_gsi = 0, gsi = 0;
+	struct arm_pmu_acpi_group *group;
+	unsigned long midr;
+	int i;
 
-	/*
-	 * Ensure that platform device must have IORESOURCE_IRQ
-	 * resource to hold gsi interrupt.
-	 */
-	if (pdev->num_resources != 1)
-		return -ENXIO;
+	midr = per_cpu(cpu_data, cpu).reg_midr;
 
-	if (pdev->resource[0].flags != IORESOURCE_IRQ)
-		return -ENXIO;
+	for (i = 0; i < *nr_groups; i++) {
+		int other;
+
+		group = groups[i];
+		other = cpumask_first(&group->cpus);
+		if (midr != per_cpu(cpu_data, other).reg_midr)
+			continue;
+
+		return group;
+	}
+
+	group = kzalloc_flex(*group, irq_maps, nr_cpu_ids, GFP_KERNEL);
+	if (!group)
+		return ERR_PTR(-ENOMEM);
+	groups[(*nr_groups)++] = group;
+
+	return group;
+}
+
+static void arm_acpi_free_pmu_groups(struct arm_pmu_acpi_group **groups,
+				     int nr_groups)
+{
+	int i;
+
+	for (i = 0; i < nr_groups; i++)
+		kfree(groups[i]);
+
+	kfree(groups);
+}
+
+static struct arm_pmu_acpi_group **
+arm_acpi_alloc_pmu_groups(const struct arm_pmu_acpi_device_info *info,
+			 int *nr_groups_out)
+{
+	struct arm_pmu_acpi_group **groups;
+	int cpu, nr_groups = 0;
+
+	*nr_groups_out = 0;
+
+	groups = kcalloc(num_possible_cpus(), sizeof(*groups), GFP_KERNEL);
+	if (!groups)
+		return NULL;
 
-	/*
-	 * Sanity check all the GICC tables for the same interrupt
-	 * number. For now, only support homogeneous ACPI machines.
-	 */
 	for_each_possible_cpu(cpu) {
 		struct acpi_madt_generic_interrupt *gicc;
+		struct arm_pmu_acpi_group *group;
+		u32 gsi;
+
+		/* CPUs that have never booted have no saved MIDR */
+		if (!per_cpu(cpu_data, cpu).reg_midr)
+			continue;
 
 		gicc = acpi_cpu_get_madt_gicc(cpu);
-		if (gicc->header.length < len)
-			return gsi ? -ENXIO : 0;
-
-		this_gsi = parse_gsi(gicc);
-		this_hetid = find_acpi_cpu_topology_hetero_id(cpu);
-		if (!gsi) {
-			hetid = this_hetid;
-			gsi = this_gsi;
-		} else if (hetid != this_hetid || gsi != this_gsi) {
-			pr_warn("ACPI: %s: must be homogeneous\n", pdev->name);
-			return -ENXIO;
+		if (gicc->header.length < info->len) {
+			pr_warn("ACPI: %s: miss GICC entries\n", info->name);
+			goto out_free;
 		}
+		gsi = info->parse_gsi(gicc);
+		if (!gsi)
+			continue;
+
+		group = arm_acpi_alloc_pmu_group(groups, &nr_groups, cpu);
+		if (IS_ERR(group))
+			goto out_free;
+
+		if (gsi) {
+			struct arm_pmu_acpi_irq_map *map =
+				&group->irq_maps[group->nr_irqs++];
+
+			map->gsi = gsi;
+			map->cpu = cpu;
+		}
+		cpumask_set_cpu(cpu, &group->cpus);
 	}
 
-	if (!this_gsi)
+	*nr_groups_out = nr_groups;
+	return groups;
+
+out_free:
+	arm_acpi_free_pmu_groups(groups, nr_groups);
+	return NULL;
+}
+
+static void arm_acpi_unregister_irq_resource(struct arm_pmu_acpi_group *group)
+{
+	int i;
+
+	/* Leave mappings reused from another group or device intact */
+	for (i = 0; i < group->nr_irqs; i++) {
+		struct arm_pmu_acpi_irq_map *map = &group->irq_maps[i];
+
+		if (!map->irq)
+			continue;
+
+		acpi_unregister_gsi(map->gsi);
+		map->irq = 0;
+	}
+}
+
+static bool arm_acpi_pmu_irq_matches(unsigned int irq, unsigned int other_irq)
+{
+	return irq == other_irq;
+}
+
+static int arm_acpi_map_gsi_irq(u32 gsi, int *irq)
+{
+	unsigned int existing_irq;
+
+	if (!acpi_gsi_to_irq(gsi, &existing_irq)) {
+		*irq = existing_irq;
+		return 0;
+	}
+
+	/* PMU overflow is level-sensitive; ignore the MADT edge flag */
+	*irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH);
+	return *irq;
+}
+
+static int arm_acpi_register_irq_resource(struct platform_device *pdev,
+					  struct arm_pmu_acpi_group *group)
+{
+	struct resource *res;
+	int i, j, nr_irqs = group->nr_irqs, ret;
+
+	if (!nr_irqs)
 		return 0;
 
-	irq = acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH);
-	if (irq < 0) {
-		pr_warn("ACPI: %s Unable to register interrupt: %d\n", pdev->name, gsi);
-		return -ENXIO;
+	res = kcalloc(nr_irqs, sizeof(*res), GFP_KERNEL);
+	if (!res)
+		return -ENOMEM;
+
+	group->nr_irqs = 0;
+	for (i = 0; i < nr_irqs; i++) {
+		struct arm_pmu_acpi_irq_map map = group->irq_maps[i];
+		int irq;
+
+		/* Shared GSIs need one resource */
+		for (j = 0; j < group->nr_irqs; j++) {
+			if (group->irq_maps[j].gsi == map.gsi)
+				break;
+		}
+		if (j < group->nr_irqs)
+			continue;
+
+		/*
+		 * On success, irq contains the mapped IRQ, whether new or
+		 * existing. The return value is positive for a new mapping
+		 * and zero for reuse.
+		 */
+		ret = arm_acpi_map_gsi_irq(map.gsi, &irq);
+		if (ret < 0)
+			goto out_free;
+
+		/* A group must use the same PPI */
+		if (group->nr_irqs && !arm_acpi_pmu_irq_matches(irq, res[0].start)) {
+			pr_warn("ACPI: %s: CPU%d has inconsistent PPI in group, ignoring CPU\n",
+				pdev->name, map.cpu);
+			cpumask_clear_cpu(map.cpu, &group->cpus);
+			/* Leave reused mappings intact */
+			if (ret > 0)
+				acpi_unregister_gsi(map.gsi);
+			continue;
+		}
+
+		map.irq = ret;
+		group->irq_maps[group->nr_irqs] = map;
+		res[group->nr_irqs++] = DEFINE_RES_IRQ(irq);
 	}
 
-	pdev->resource[0].start = irq;
-	ret = platform_device_register(pdev);
+	ret = platform_device_add_resources(pdev, res, group->nr_irqs);
+
+out_free:
+	kfree(res);
+	return ret;
+}
+
+static int arm_acpi_register_sw_node_irq_affinity(struct platform_device *pdev,
+						 struct arm_pmu_acpi_group *group)
+{
+	int ret;
+
+	/* A MIDR group may span several processor containers */
+	ret = device_create_managed_software_node(&pdev->dev, NULL, NULL);
 	if (ret)
-		acpi_unregister_gsi(gsi);
+		return ret;
+
+	return software_node_add_irq_affinity(dev_fwnode(&pdev->dev), 0,
+					      &group->cpus);
+}
+
+static int arm_acpi_register_pmu_device(struct arm_pmu_acpi_group *group,
+					const char *name, int id)
+{
+	struct platform_device *pdev;
+	int ret;
+
+	pdev = platform_device_alloc(name, id);
+	if (!pdev)
+		return -ENOMEM;
+
+	ret = arm_acpi_register_irq_resource(pdev, group);
+	if (ret)
+		goto out_put;
+
+	ret = arm_acpi_register_sw_node_irq_affinity(pdev, group);
+	if (ret)
+		goto out_put;
 
+	ret = platform_device_add(pdev);
+	if (ret)
+		goto out_put;
+
+	return 0;
+
+out_put:
+	platform_device_put(pdev);
+	arm_acpi_unregister_irq_resource(group);
 	return ret;
 }
 
-#if IS_ENABLED(CONFIG_ARM_SPE_PMU)
-static struct resource spe_resources[] = {
-	{
-		/* irq */
-		.flags          = IORESOURCE_IRQ,
+static int __maybe_unused
+arm_acpi_register_pmu_devices(const struct arm_pmu_acpi_device_info *info)
+{
+	struct arm_pmu_acpi_group **groups;
+	int i, nr_groups, nr_devices = 0, last_err = 0, ret;
+
+	groups = arm_acpi_alloc_pmu_groups(info, &nr_groups);
+	if (!groups)
+		return -ENOMEM;
+
+	for (i = 0; i < nr_groups; i++) {
+		if (!groups[i])
+			continue;
+
+		ret = arm_acpi_register_pmu_device(groups[i], info->name, i);
+		if (ret) {
+			pr_warn("ACPI: %s: %*pbl: add device failed (%d)\n",
+				info->name, cpumask_pr_args(&groups[i]->cpus), ret);
+			last_err = ret;
+		} else {
+			nr_devices++;
+		}
 	}
-};
 
-static struct platform_device spe_dev = {
-	.name = ARMV8_SPE_PDEV_NAME,
-	.id = -1,
-	.resource = spe_resources,
-	.num_resources = ARRAY_SIZE(spe_resources)
-};
+	arm_acpi_free_pmu_groups(groups, nr_groups);
+	return nr_devices ? 0 : last_err;
+}
 
-static u16 arm_spe_parse_gsi(struct acpi_madt_generic_interrupt *gicc)
+#if IS_ENABLED(CONFIG_ARM_SPE_PMU)
+static u32 arm_spe_parse_gsi(struct acpi_madt_generic_interrupt *gicc)
 {
 	return gicc->spe_interrupt;
 }
 
-/*
- * For lack of a better place, hook the normal PMU MADT walk
- * and create a SPE device if we detect a recent MADT with
- * a homogeneous PPI mapping.
- */
 static void arm_spe_acpi_register_device(void)
 {
-	int ret = arm_acpi_register_pmu_device(&spe_dev, ACPI_MADT_GICC_SPE,
-					       arm_spe_parse_gsi);
-	if (ret)
+	static const struct arm_pmu_acpi_device_info info = {
+		.name = ARMV8_SPE_PDEV_NAME,
+		.len = ACPI_MADT_GICC_SPE,
+		.parse_gsi = arm_spe_parse_gsi,
+	};
+
+	if (arm_acpi_register_pmu_devices(&info))
 		pr_warn("ACPI: SPE: Unable to register device\n");
 }
 #else
@@ -163,36 +372,25 @@ static inline void arm_spe_acpi_register_device(void)
 #endif /* CONFIG_ARM_SPE_PMU */
 
 #if IS_ENABLED(CONFIG_CORESIGHT_TRBE)
-static struct resource trbe_resources[] = {
-	{
-		/* irq */
-		.flags          = IORESOURCE_IRQ,
-	}
-};
-
-static struct platform_device trbe_dev = {
-	.name = ARMV8_TRBE_PDEV_NAME,
-	.id = -1,
-	.resource = trbe_resources,
-	.num_resources = ARRAY_SIZE(trbe_resources)
-};
-
-static u16 arm_trbe_parse_gsi(struct acpi_madt_generic_interrupt *gicc)
+static u32 arm_trbe_parse_gsi(struct acpi_madt_generic_interrupt *gicc)
 {
 	return gicc->trbe_interrupt;
 }
 
 static void arm_trbe_acpi_register_device(void)
 {
-	int ret = arm_acpi_register_pmu_device(&trbe_dev, ACPI_MADT_GICC_TRBE,
-					       arm_trbe_parse_gsi);
-	if (ret)
+	static const struct arm_pmu_acpi_device_info info = {
+		.name = ARMV8_TRBE_PDEV_NAME,
+		.len = ACPI_MADT_GICC_TRBE,
+		.parse_gsi = arm_trbe_parse_gsi,
+	};
+
+	if (arm_acpi_register_pmu_devices(&info))
 		pr_warn("ACPI: TRBE: Unable to register device\n");
 }
 #else
 static inline void arm_trbe_acpi_register_device(void)
 {
-
 }
 #endif /* CONFIG_CORESIGHT_TRBE */
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/8] perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
                   ` (2 preceding siblings ...)
  2026-11-16 18:21 ` [PATCH 3/8] perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:29   ` sashiko-bot
  2026-11-16 18:21 ` [PATCH 5/8] perf/arm_pmu: Register ACPI CPU PMUs as platform devices Leo Yan
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

CPU PMUs may use a separate SPI for each CPU. Extend the existing IRQ
compatibility check to allow different SPIs in a group while retaining
the same-PPI requirement.

Extend arm_acpi_register_sw_node_irq_affinity() to publish a singleton
CPU mask for each SPI resource, using the CPU recorded in its mapping
entry. Keep the full group mask at index zero for a shared PPI or a
counting-only device with no IRQ resources.

Retain zero-GSI CPU PMU entries for counting-only devices. Trust
firmware to provide GICC interrupt descriptions as specified by ACPI.
SPE and TRBE remain the common registration interface's callers in this
commit.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/perf/arm_pmu_acpi.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
index 7ae291acb04526d820bdfb9640aaa8352449be54..6a7fa8d01f42b1b58e28541a374f005e1955598f 100644
--- a/drivers/perf/arm_pmu_acpi.c
+++ b/drivers/perf/arm_pmu_acpi.c
@@ -16,6 +16,7 @@
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 
 #include <asm/cpu.h>
 #include <asm/cputype.h>
@@ -158,7 +159,8 @@ arm_acpi_alloc_pmu_groups(const struct arm_pmu_acpi_device_info *info,
 			goto out_free;
 		}
 		gsi = info->parse_gsi(gicc);
-		if (!gsi)
+		/* CPU PMUs can count without an overflow interrupt */
+		if (!gsi && strcmp(info->name, ARMV8_PMU_PDEV_NAME))
 			continue;
 
 		group = arm_acpi_alloc_pmu_group(groups, &nr_groups, cpu);
@@ -201,7 +203,8 @@ static void arm_acpi_unregister_irq_resource(struct arm_pmu_acpi_group *group)
 
 static bool arm_acpi_pmu_irq_matches(unsigned int irq, unsigned int other_irq)
 {
-	return irq == other_irq;
+	return irq == other_irq ||
+		(!irq_is_percpu_devid(irq) && !irq_is_percpu_devid(other_irq));
 }
 
 static int arm_acpi_map_gsi_irq(u32 gsi, int *irq)
@@ -253,7 +256,7 @@ static int arm_acpi_register_irq_resource(struct platform_device *pdev,
 		if (ret < 0)
 			goto out_free;
 
-		/* A group must use the same PPI */
+		/* A group must use the same PPI or only SPIs */
 		if (group->nr_irqs && !arm_acpi_pmu_irq_matches(irq, res[0].start)) {
 			pr_warn("ACPI: %s: CPU%d has inconsistent PPI in group, ignoring CPU\n",
 				pdev->name, map.cpu);
@@ -279,15 +282,28 @@ static int arm_acpi_register_irq_resource(struct platform_device *pdev,
 static int arm_acpi_register_sw_node_irq_affinity(struct platform_device *pdev,
 						 struct arm_pmu_acpi_group *group)
 {
-	int ret;
+	struct fwnode_handle *fwnode;
+	struct resource *res;
+	int i, ret;
 
 	/* A MIDR group may span several processor containers */
 	ret = device_create_managed_software_node(&pdev->dev, NULL, NULL);
 	if (ret)
 		return ret;
+	fwnode = dev_fwnode(&pdev->dev);
+
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!res || irq_is_percpu_devid(res->start))
+		return software_node_add_irq_affinity(fwnode, 0, &group->cpus);
+
+	for (i = 0; i < group->nr_irqs; i++) {
+		ret = software_node_add_irq_affinity(fwnode, i,
+						     cpumask_of(group->irq_maps[i].cpu));
+		if (ret)
+			return ret;
+	}
 
-	return software_node_add_irq_affinity(dev_fwnode(&pdev->dev), 0,
-					      &group->cpus);
+	return 0;
 }
 
 static int arm_acpi_register_pmu_device(struct arm_pmu_acpi_group *group,

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/8] perf/arm_pmu: Register ACPI CPU PMUs as platform devices
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
                   ` (3 preceding siblings ...)
  2026-11-16 18:21 ` [PATCH 4/8] perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:21 ` [PATCH 6/8] perf/arm_pmu: Support ACPI devices in the platform probe Leo Yan
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

Register CPU PMU platform devices through arm_acpi_register_pmu_devices(),
reusing the common MIDR grouping, software-node IRQ affinity and IRQ
resource handling.

Name the ACPI platform devices and the PMUv3 driver "arm,armv8-pmuv3".
This lets the following platform-probe change match the device name
against the OF table and select armv8_pmuv3_pmu_init(), preserving the
initializer previously passed directly to arm_pmu_acpi_probe().

Keep the platform-device name outside the ARM_PMU guard so common ACPI
enumeration can use it without the CPU PMU framework.

Remove the legacy ACPI probe, pre-probe IRQ setup, dedicated CPU hotplug
state and associated declarations. Register the PMUv3 platform driver
for both DT and ACPI; the following change adds ACPI support to the
common platform probe path.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 arch/arm64/include/asm/acpi.h |   3 +
 drivers/perf/arm_pmu_acpi.c   | 307 ++++--------------------------------------
 drivers/perf/arm_pmuv3.c      |   5 +-
 include/linux/cpuhotplug.h    |   1 -
 include/linux/perf/arm_pmu.h  |  12 +-
 5 files changed, 29 insertions(+), 299 deletions(-)

diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
index 8a54ca6ba60282ef503e6f900201986b55227d77..80334baa25ca32a01a693076a9ce76f20a1f765a 100644
--- a/arch/arm64/include/asm/acpi.h
+++ b/arch/arm64/include/asm/acpi.h
@@ -40,6 +40,9 @@
 	(!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \
 	(unsigned long)(entry) + (entry)->header.length > (end))
 
+#define ACPI_MADT_GICC_PMU  offsetofend(struct acpi_madt_generic_interrupt, \
+	performance_interrupt)
+
 #define ACPI_MADT_GICC_SPE  (offsetof(struct acpi_madt_generic_interrupt, \
 	spe_interrupt) + sizeof(u16))
 
diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
index 6a7fa8d01f42b1b58e28541a374f005e1955598f..642d385458a05550c63f061bf301f623ecd72253 100644
--- a/drivers/perf/arm_pmu_acpi.c
+++ b/drivers/perf/arm_pmu_acpi.c
@@ -11,7 +11,6 @@
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/irqdesc.h>
-#include <linux/percpu.h>
 #include <linux/perf/arm_pmu.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
@@ -19,59 +18,6 @@
 #include <linux/string.h>
 
 #include <asm/cpu.h>
-#include <asm/cputype.h>
-
-static DEFINE_PER_CPU(struct arm_pmu *, probed_pmus);
-static DEFINE_PER_CPU(int, pmu_irqs);
-
-static int arm_pmu_acpi_register_irq(int cpu)
-{
-	struct acpi_madt_generic_interrupt *gicc;
-	int gsi;
-
-	gicc = acpi_cpu_get_madt_gicc(cpu);
-
-	gsi = gicc->performance_interrupt;
-
-	/*
-	 * Per the ACPI spec, the MADT cannot describe a PMU that doesn't
-	 * have an interrupt. QEMU advertises this by using a GSI of zero,
-	 * which is not known to be valid on any hardware despite being
-	 * valid per the spec. Take the pragmatic approach and reject a
-	 * GSI of zero for now.
-	 */
-	if (!gsi)
-		return 0;
-
-	/*
-	 * Helpfully, the MADT GICC doesn't have a polarity flag for the
-	 * "performance interrupt". Luckily, on compliant GICs the polarity is
-	 * a fixed value in HW (for both SPIs and PPIs) that we cannot change
-	 * from SW.
-	 *
-	 * Here we pass in ACPI_ACTIVE_HIGH to keep the core code happy. This
-	 * may not match the real polarity, but that should not matter.
-	 *
-	 * Other interrupt controllers are not supported with ACPI.
-	 *
-	 * The spec also indicates that the PMU interrupt can be edge
-	 * triggered, which doesn't make any sense (SW needs to clear the
-	 * interrupt condition for the level to drop). Ignore the silly flag.
-	 */
-	return acpi_register_gsi(NULL, gsi, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_HIGH);
-}
-
-static void arm_pmu_acpi_unregister_irq(int cpu)
-{
-	struct acpi_madt_generic_interrupt *gicc;
-	int gsi;
-
-	gicc = acpi_cpu_get_madt_gicc(cpu);
-
-	gsi = gicc->performance_interrupt;
-	if (gsi)
-		acpi_unregister_gsi(gsi);
-}
 
 struct arm_pmu_acpi_device_info {
 	const char *name;
@@ -364,6 +310,29 @@ arm_acpi_register_pmu_devices(const struct arm_pmu_acpi_device_info *info)
 	return nr_devices ? 0 : last_err;
 }
 
+#if IS_ENABLED(CONFIG_ARM_PMUV3)
+static u32 arm_pmu_parse_gsi(struct acpi_madt_generic_interrupt *gicc)
+{
+	return gicc->performance_interrupt;
+}
+
+static void arm_pmu_acpi_register_device(void)
+{
+	static const struct arm_pmu_acpi_device_info info = {
+		.name = ARMV8_PMU_PDEV_NAME,
+		.len = ACPI_MADT_GICC_PMU,
+		.parse_gsi = arm_pmu_parse_gsi,
+	};
+
+	if (arm_acpi_register_pmu_devices(&info))
+		pr_warn("ACPI: CPU PMU: Unable to register device\n");
+}
+#else
+static inline void arm_pmu_acpi_register_device(void)
+{
+}
+#endif
+
 #if IS_ENABLED(CONFIG_ARM_SPE_PMU)
 static u32 arm_spe_parse_gsi(struct acpi_madt_generic_interrupt *gicc)
 {
@@ -410,240 +379,12 @@ static inline void arm_trbe_acpi_register_device(void)
 }
 #endif /* CONFIG_CORESIGHT_TRBE */
 
-static int arm_pmu_acpi_parse_irqs(void)
-{
-	int irq, cpu, irq_cpu, err;
-
-	for_each_possible_cpu(cpu) {
-		irq = arm_pmu_acpi_register_irq(cpu);
-		if (irq < 0) {
-			err = irq;
-			pr_warn("Unable to parse ACPI PMU IRQ for CPU%d: %d\n",
-				cpu, err);
-			goto out_err;
-		} else if (irq == 0) {
-			pr_warn("No ACPI PMU IRQ for CPU%d\n", cpu);
-		}
-
-		/*
-		 * Log and request the IRQ so the core arm_pmu code can manage
-		 * it. We'll have to sanity-check IRQs later when we associate
-		 * them with their PMUs.
-		 */
-		per_cpu(pmu_irqs, cpu) = irq;
-		err = armpmu_request_irq(&probed_pmus, irq, cpu);
-		if (err)
-			goto out_err;
-	}
-
-	return 0;
-
-out_err:
-	for_each_possible_cpu(cpu) {
-		irq = per_cpu(pmu_irqs, cpu);
-		if (!irq)
-			continue;
-
-		arm_pmu_acpi_unregister_irq(cpu);
-
-		/*
-		 * Blat all copies of the IRQ so that we only unregister the
-		 * corresponding GSI once (e.g. when we have PPIs).
-		 */
-		for_each_possible_cpu(irq_cpu) {
-			if (per_cpu(pmu_irqs, irq_cpu) == irq)
-				per_cpu(pmu_irqs, irq_cpu) = 0;
-		}
-	}
-
-	return err;
-}
-
-static struct arm_pmu *arm_pmu_acpi_find_pmu(void)
-{
-	unsigned long cpuid = read_cpuid_id();
-	struct arm_pmu *pmu;
-	int cpu;
-
-	for_each_possible_cpu(cpu) {
-		pmu = per_cpu(probed_pmus, cpu);
-		if (!pmu || pmu->acpi_cpuid != cpuid)
-			continue;
-
-		return pmu;
-	}
-
-	return NULL;
-}
-
-/*
- * Check whether the new IRQ is compatible with those already associated with
- * the PMU (e.g. we don't have mismatched PPIs).
- */
-static bool pmu_irq_matches(struct arm_pmu *pmu, int irq)
-{
-	struct pmu_hw_events __percpu *hw_events = pmu->hw_events;
-	int cpu;
-
-	if (!irq)
-		return true;
-
-	for_each_cpu(cpu, &pmu->supported_cpus) {
-		int other_irq = per_cpu(hw_events->irq, cpu);
-		if (!other_irq)
-			continue;
-
-		if (irq == other_irq)
-			continue;
-		if (!irq_is_percpu_devid(irq) && !irq_is_percpu_devid(other_irq))
-			continue;
-
-		pr_warn("mismatched PPIs detected\n");
-		return false;
-	}
-
-	return true;
-}
-
-static void arm_pmu_acpi_associate_pmu_cpu(struct arm_pmu *pmu,
-					   unsigned int cpu)
-{
-	int irq = per_cpu(pmu_irqs, cpu);
-
-	per_cpu(probed_pmus, cpu) = pmu;
-
-	if (pmu_irq_matches(pmu, irq)) {
-		struct pmu_hw_events __percpu *hw_events;
-		hw_events = pmu->hw_events;
-		per_cpu(hw_events->irq, cpu) = irq;
-	}
-
-	cpumask_set_cpu(cpu, &pmu->supported_cpus);
-}
-
-/*
- * This must run before the common arm_pmu hotplug logic, so that we can
- * associate a CPU and its interrupt before the common code tries to manage the
- * affinity and so on.
- *
- * Note that hotplug events are serialized, so we cannot race with another CPU
- * coming up. The perf core won't open events while a hotplug event is in
- * progress.
- */
-static int arm_pmu_acpi_cpu_starting(unsigned int cpu)
-{
-	struct arm_pmu *pmu;
-
-	/* If we've already probed this CPU, we have nothing to do */
-	if (per_cpu(probed_pmus, cpu))
-		return 0;
-
-	pmu = arm_pmu_acpi_find_pmu();
-	if (!pmu) {
-		pr_warn_ratelimited("Unable to associate CPU%d with a PMU\n",
-				    cpu);
-		return 0;
-	}
-
-	arm_pmu_acpi_associate_pmu_cpu(pmu, cpu);
-	return 0;
-}
-
-static void arm_pmu_acpi_probe_matching_cpus(struct arm_pmu *pmu,
-					     unsigned long cpuid)
-{
-	int cpu;
-
-	for_each_online_cpu(cpu) {
-		unsigned long cpu_cpuid = per_cpu(cpu_data, cpu).reg_midr;
-
-		if (cpu_cpuid == cpuid)
-			arm_pmu_acpi_associate_pmu_cpu(pmu, cpu);
-	}
-}
-
-int arm_pmu_acpi_probe(armpmu_init_fn init_fn)
-{
-	int pmu_idx = 0;
-	unsigned int cpu;
-	int ret;
-
-	ret = arm_pmu_acpi_parse_irqs();
-	if (ret)
-		return ret;
-
-	ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_ACPI_STARTING,
-					"perf/arm/pmu_acpi:starting",
-					arm_pmu_acpi_cpu_starting, NULL);
-	if (ret)
-		return ret;
-
-	/*
-	 * Initialise and register the set of PMUs which we know about right
-	 * now. Ideally we'd do this in arm_pmu_acpi_cpu_starting() so that we
-	 * could handle late hotplug, but this may lead to deadlock since we
-	 * might try to register a hotplug notifier instance from within a
-	 * hotplug notifier.
-	 *
-	 * There's also the problem of having access to the right init_fn,
-	 * without tying this too deeply into the "real" PMU driver.
-	 *
-	 * For the moment, as with the platform/DT case, we need at least one
-	 * of a PMU's CPUs to be online at probe time.
-	 */
-	for_each_online_cpu(cpu) {
-		struct arm_pmu *pmu = per_cpu(probed_pmus, cpu);
-		unsigned long cpuid;
-		char *base_name;
-
-		/* If we've already probed this CPU, we have nothing to do */
-		if (pmu)
-			continue;
-
-		pmu = armpmu_alloc();
-		if (!pmu) {
-			pr_warn("Unable to allocate PMU for CPU%d\n",
-				cpu);
-			return -ENOMEM;
-		}
-
-		cpuid = per_cpu(cpu_data, cpu).reg_midr;
-		pmu->acpi_cpuid = cpuid;
-
-		arm_pmu_acpi_probe_matching_cpus(pmu, cpuid);
-
-		ret = init_fn(pmu);
-		if (ret == -ENODEV) {
-			/* PMU not handled by this driver, or not present */
-			continue;
-		} else if (ret) {
-			pr_warn("Unable to initialise PMU for CPU%d\n", cpu);
-			return ret;
-		}
-
-		base_name = pmu->name;
-		pmu->name = kasprintf(GFP_KERNEL, "%s_%d", base_name, pmu_idx++);
-		if (!pmu->name) {
-			pr_warn("Unable to allocate PMU name for CPU%d\n", cpu);
-			return -ENOMEM;
-		}
-
-		ret = armpmu_register(pmu);
-		if (ret) {
-			pr_warn("Failed to register PMU for CPU%d\n", cpu);
-			kfree(pmu->name);
-			return ret;
-		}
-	}
-
-	return ret;
-}
-
 static int arm_pmu_acpi_init(void)
 {
 	if (acpi_disabled)
 		return 0;
 
+	arm_pmu_acpi_register_device();
 	arm_spe_acpi_register_device();
 	arm_trbe_acpi_register_device();
 
diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
index 03359e078301f85f3bb1beca2b346aa29c822cc8..b0ca236d37e1c8efd859b89a524910a42cf2b062 100644
--- a/drivers/perf/arm_pmuv3.c
+++ b/drivers/perf/arm_pmuv3.c
@@ -1636,10 +1636,7 @@ static int __init armv8_pmu_driver_init(void)
 {
 	int ret;
 
-	if (acpi_disabled)
-		ret = platform_driver_register(&armv8_pmu_driver);
-	else
-		ret = arm_pmu_acpi_probe(armv8_pmuv3_pmu_init);
+	ret = platform_driver_register(&armv8_pmu_driver);
 
 	if (!ret)
 		lockup_detector_retry_init();
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 1b6dba159bb23cf5e6ba312d1e44c7665edadc88..9cefaecbecbe604def627fb07cc3411dee35c90c 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -154,7 +154,6 @@ enum cpuhp_state {
 	CPUHP_AP_ARM_VFP_STARTING,
 	CPUHP_AP_ARM64_DEBUG_MONITORS_STARTING,
 	CPUHP_AP_PERF_ARM_HW_BREAKPOINT_STARTING,
-	CPUHP_AP_PERF_ARM_ACPI_STARTING,
 	CPUHP_AP_PERF_ARM_STARTING,
 	CPUHP_AP_PERF_RISCV_STARTING,
 	CPUHP_AP_ARM_L2X0_STARTING,
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index 02d2c7f45b527d024e60415b11359d346b63cfe8..28c8672b71e24c4298375c17c8788f6ccdae6040 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -126,9 +126,6 @@ struct arm_pmu {
 	DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
 #define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE	0x4000
 	DECLARE_BITMAP(pmceid_ext_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
-
-	/* Only to be used by ACPI probing code */
-	unsigned long acpi_cpuid;
 };
 
 #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
@@ -171,12 +168,6 @@ int arm_pmu_device_probe(struct platform_device *pdev,
 			 const struct of_device_id *of_table,
 			 const struct pmu_probe_info *probe_table);
 
-#ifdef CONFIG_ACPI
-int arm_pmu_acpi_probe(armpmu_init_fn init_fn);
-#else
-static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
-#endif
-
 #ifdef CONFIG_KVM
 void kvm_host_pmu_init(struct arm_pmu *pmu);
 #else
@@ -192,10 +183,9 @@ int armpmu_register(struct arm_pmu *pmu);
 int armpmu_request_irq(struct arm_pmu * __percpu *armpmu, int irq, int cpu);
 void armpmu_free_irq(struct arm_pmu * __percpu *armpmu, int irq, int cpu);
 
-#define ARMV8_PMU_PDEV_NAME "armv8-pmu"
-
 #endif /* CONFIG_ARM_PMU */
 
+#define ARMV8_PMU_PDEV_NAME "arm,armv8-pmuv3"
 #define ARMV8_SPE_PDEV_NAME "arm,spe-v1"
 #define ARMV8_TRBE_PDEV_NAME "arm,trbe"
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 6/8] perf/arm_pmu: Support ACPI devices in the platform probe
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
                   ` (4 preceding siblings ...)
  2026-11-16 18:21 ` [PATCH 5/8] perf/arm_pmu: Register ACPI CPU PMUs as platform devices Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:36   ` sashiko-bot
  2026-11-16 18:21 ` [PATCH 7/8] perf/arm_pmu: Use ACPI CPU affinity in IRQ handling Leo Yan
  2026-11-16 18:21 ` [PATCH 8/8] ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/ Leo Yan
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

Add pmu_get_match_data() to select the initialization callback for DT
and ACPI devices. Use OF match data for devices with a DT node, and
match the platform device name against the existing compatible table
otherwise. This also handles devices described by software nodes.

Return -ENODEV when no initializer or fallback probe table is available.
Append the platform device ID to numbered PMU names, leaving unnumbered
DT device names unchanged.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/perf/arm_pmu_platform.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/arm_pmu_platform.c b/drivers/perf/arm_pmu_platform.c
index 1c9e50a13201528edf4cfbdc2504d305b49d4913..397fdb148dc9b6be083e654e091ecc6a95c4905b 100644
--- a/drivers/perf/arm_pmu_platform.c
+++ b/drivers/perf/arm_pmu_platform.c
@@ -20,7 +20,9 @@
 #include <linux/perf/arm_pmu.h>
 #include <linux/platform_device.h>
 #include <linux/printk.h>
+#include <linux/slab.h>
 #include <linux/smp.h>
+#include <linux/string.h>
 
 static int probe_current_pmu(struct arm_pmu *pmu,
 			     const struct pmu_probe_info *info)
@@ -185,6 +187,23 @@ static void armpmu_free_irqs(struct arm_pmu *armpmu)
 	}
 }
 
+static const void *pmu_get_match_data(struct platform_device *pdev,
+				      const struct of_device_id *of_table)
+{
+	const struct of_device_id *match;
+
+	if (pdev->dev.of_node)
+		return of_device_get_match_data(&pdev->dev);
+
+	/* ACPI platform devices use a compatible string as their name */
+	for (match = of_table; match && match->compatible[0]; match++) {
+		if (!strcmp(pdev->name, match->compatible))
+			return match->data;
+	}
+
+	return NULL;
+}
+
 int arm_pmu_device_probe(struct platform_device *pdev,
 			 const struct of_device_id *of_table,
 			 const struct pmu_probe_info *probe_table)
@@ -205,7 +224,7 @@ int arm_pmu_device_probe(struct platform_device *pdev,
 	if (ret)
 		goto out_free;
 
-	init_fn = of_device_get_match_data(dev);
+	init_fn = pmu_get_match_data(pdev, of_table);
 	if (init_fn) {
 		pmu->secure_access = of_property_read_bool(dev->of_node,
 							   "secure-reg-access");
@@ -220,6 +239,8 @@ int arm_pmu_device_probe(struct platform_device *pdev,
 	} else if (probe_table) {
 		cpumask_setall(&pmu->supported_cpus);
 		ret = probe_current_pmu(pmu, probe_table);
+	} else {
+		ret = -ENODEV;
 	}
 
 	if (ret) {
@@ -227,6 +248,16 @@ int arm_pmu_device_probe(struct platform_device *pdev,
 		goto out_free;
 	}
 
+	/* Append instance suffix (for only ACPI devices) */
+	if (pdev->id >= 0) {
+		pmu->name = devm_kasprintf(dev, GFP_KERNEL, "%s_%d",
+					   pmu->name, pdev->id);
+		if (!pmu->name) {
+			ret = -ENOMEM;
+			goto out_free;
+		}
+	}
+
 	ret = armpmu_request_irqs(pmu);
 	if (ret)
 		goto out_free_irqs;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7/8] perf/arm_pmu: Use ACPI CPU affinity in IRQ handling
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
                   ` (5 preceding siblings ...)
  2026-11-16 18:21 ` [PATCH 6/8] perf/arm_pmu: Support ACPI devices in the platform probe Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:34   ` sashiko-bot
  2026-11-16 18:21 ` [PATCH 8/8] ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/ Leo Yan
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

Read each IRQ resource's CPU mask through platform_get_irq_affinity().
For ACPI SPIs, select the CPU from that resource's singleton mask.

Add pmu_get_irq_affinity() for counting-only PMUs, which have no IRQ
resource to query. Fall back to cpu_possible_mask when firmware provides
no affinity mask.

Select DT handling from the device's OF node. Preserve the DT SPI
interrupt-affinity phandle order and the single-PPI path.

The common platform probe initializes the per-CPU PMU pointers and
supported CPU mask before requesting interrupts. Use that mask in
armpmu_request_irq() and remove the cpu_possible_mask fallback needed
by the former ACPI pre-probe IRQ setup.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 drivers/perf/arm_pmu.c          |  3 +--
 drivers/perf/arm_pmu_platform.c | 29 ++++++++++++++++++++---------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 11506956538925fbc72e1d114d511eb3b76f8687..67d1791ab49fe7714983fe30e4ea351dc2ea9ac5 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -631,8 +631,7 @@ int armpmu_request_irq(struct arm_pmu * __percpu *pcpu_armpmu, int irq, int cpu)
 {
 	int err = 0;
 	struct arm_pmu **armpmu = per_cpu_ptr(pcpu_armpmu, cpu);
-	const struct cpumask *affinity = *armpmu ? &(*armpmu)->supported_cpus :
-						   cpu_possible_mask; /* ACPI */
+	const struct cpumask *affinity = &(*armpmu)->supported_cpus;
 	const irq_handler_t handler = armpmu_dispatch_irq;
 	const struct pmu_irq_ops *irq_ops;
 
diff --git a/drivers/perf/arm_pmu_platform.c b/drivers/perf/arm_pmu_platform.c
index 397fdb148dc9b6be083e654e091ecc6a95c4905b..5ca211798b60ae3e0b9459aba2170f9c84d8f9c7 100644
--- a/drivers/perf/arm_pmu_platform.c
+++ b/drivers/perf/arm_pmu_platform.c
@@ -20,6 +20,7 @@
 #include <linux/perf/arm_pmu.h>
 #include <linux/platform_device.h>
 #include <linux/printk.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/smp.h>
 #include <linux/string.h>
@@ -63,11 +64,24 @@ static bool pmu_has_irq_affinity(struct device_node *node)
 	return of_property_present(node, "interrupt-affinity");
 }
 
-static int pmu_parse_irq_affinity(struct device *dev, int i)
+static const struct cpumask *pmu_get_irq_affinity(struct device *dev)
+{
+	const struct cpumask *affinity;
+
+	affinity = fwnode_irq_get_affinity(dev_fwnode(dev), 0);
+	return affinity ?: cpu_possible_mask;
+}
+
+static int pmu_parse_irq_affinity(struct device *dev, int i,
+				  const struct cpumask *affinity)
 {
 	struct device_node *dn;
 	int cpu;
 
+	/* ACPI software nodes provide a singleton CPU mask for each SPI */
+	if (!dev->of_node)
+		return cpumask_first(affinity);
+
 	/*
 	 * If we don't have an interrupt-affinity property, we guess irq
 	 * affinity matches our logical CPU order, as we used to assume.
@@ -104,14 +118,10 @@ static int pmu_parse_irqs(struct arm_pmu *pmu)
 	if (num_irqs < 0)
 		return dev_err_probe(dev, num_irqs, "unable to count PMU IRQs\n");
 
-	/*
-	 * In this case we have no idea which CPUs are covered by the PMU.
-	 * To match our prior behaviour, we assume all CPUs in this case.
-	 */
 	if (num_irqs == 0) {
 		dev_warn(dev, "no irqs for PMU, sampling events not supported\n");
 		pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
-		cpumask_setall(&pmu->supported_cpus);
+		cpumask_copy(&pmu->supported_cpus, pmu_get_irq_affinity(dev));
 		return 0;
 	}
 
@@ -124,13 +134,14 @@ static int pmu_parse_irqs(struct arm_pmu *pmu)
 			return pmu_parse_percpu_irq(pmu, irq, affinity);
 	}
 
-	if (nr_cpu_ids != 1 && !pmu_has_irq_affinity(dev->of_node))
+	if (dev->of_node && nr_cpu_ids != 1 && !pmu_has_irq_affinity(dev->of_node))
 		dev_warn(dev, "no interrupt-affinity property, guessing.\n");
 
 	for (i = 0; i < num_irqs; i++) {
+		const struct cpumask *affinity;
 		int cpu, irq;
 
-		irq = platform_get_irq(pdev, i);
+		irq = platform_get_irq_affinity(pdev, i, &affinity);
 		if (WARN_ON(irq <= 0))
 			continue;
 
@@ -139,7 +150,7 @@ static int pmu_parse_irqs(struct arm_pmu *pmu)
 			return -EINVAL;
 		}
 
-		cpu = pmu_parse_irq_affinity(dev, i);
+		cpu = pmu_parse_irq_affinity(dev, i, affinity);
 		if (cpu < 0)
 			return cpu;
 		if (cpu >= nr_cpu_ids)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 8/8] ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/
  2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
                   ` (6 preceding siblings ...)
  2026-11-16 18:21 ` [PATCH 7/8] perf/arm_pmu: Use ACPI CPU affinity in IRQ handling Leo Yan
@ 2026-11-16 18:21 ` Leo Yan
  2026-11-16 18:37   ` sashiko-bot
  7 siblings, 1 reply; 16+ messages in thread
From: Leo Yan @ 2026-11-16 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Johan Hovold, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Bartosz Golaszewski,
	Saravana Kannan, Will Deacon, Thomas Gleixner, Peter Zijlstra,
	Lorenzo Pieralisi, Hanjun Guo, Jeremy Linton, Marc Zyngier,
	Mark Rutland, Sudeep Holla, Rob Herring, Catalin Marinas
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Anshuman Khandual,
	Al Grant, Johnny.Fan, linux-acpi, linux-kernel, driver-core,
	devicetree, linux-arm-kernel, linux-perf-users, Leo Yan

The ACPI PMU code now registers platform devices for the CPU PMU, SPE
and TRBE. Move it to drivers/acpi/arm64/pmu.c with the other Arm ACPI
device enumeration code.

Move its Kconfig entry alongside it and rename the hidden ARM_PMU_ACPI
symbol to ACPI_PMU. Drop the ARM_PMU dependency: enumeration does not
use the CPU PMU framework, and each device type is guarded by its driver
configuration. This allows SPE and TRBE enumeration with ARM_PMU disabled.

Keep the default-y setting, update the build guard and retain PMU
maintainer coverage for the new path.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 MAINTAINERS                                       | 1 +
 drivers/acpi/arm64/Kconfig                        | 4 ++++
 drivers/acpi/arm64/Makefile                       | 1 +
 drivers/{perf/arm_pmu_acpi.c => acpi/arm64/pmu.c} | 0
 drivers/perf/Kconfig                              | 4 ----
 drivers/perf/Makefile                             | 1 -
 6 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index ccbcdc0799b9fb8cc2b4dc139906e1584e096c46..f12a37cf20e13583c949b6fa7d9f5eb08e260566 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2445,6 +2445,7 @@ F:	arch/arm*/include/asm/hw_breakpoint.h
 F:	arch/arm*/include/asm/perf_event.h
 F:	arch/arm*/kernel/hw_breakpoint.c
 F:	arch/arm*/kernel/perf_*
+F:	drivers/acpi/arm64/pmu.c
 F:	drivers/perf/
 F:	include/linux/perf/arm_pmu*.h
 
diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig
index f2fd79f22e7d836b07401eb055725b2632ba624c..b4dd7f4d257e005b32d34012169ac595dcdee468 100644
--- a/drivers/acpi/arm64/Kconfig
+++ b/drivers/acpi/arm64/Kconfig
@@ -24,3 +24,7 @@ config ACPI_APMT
 
 config ACPI_MPAM
 	bool
+
+config ACPI_PMU
+	depends on ACPI
+	def_bool y
diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile
index 9390b57cb56481c547ebb896c58cf3e37a980827..f09e4506954d897caa44481a83f81ca65cfb7d96 100644
--- a/drivers/acpi/arm64/Makefile
+++ b/drivers/acpi/arm64/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_ACPI_FFH)		+= ffh.o
 obj-$(CONFIG_ACPI_GTDT) 	+= gtdt.o
 obj-$(CONFIG_ACPI_IORT) 	+= iort.o
 obj-$(CONFIG_ACPI_MPAM) 	+= mpam.o
+obj-$(CONFIG_ACPI_PMU)		+= pmu.o
 obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o
 obj-$(CONFIG_ARM_AMBA)		+= amba.o
 obj-y				+= dma.o init.o
diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/acpi/arm64/pmu.c
similarity index 100%
rename from drivers/perf/arm_pmu_acpi.c
rename to drivers/acpi/arm64/pmu.c
diff --git a/drivers/perf/Kconfig b/drivers/perf/Kconfig
index 245e7bb763b9947afc0330689b15d1b73d567f25..e9d61d5dbd1f174cc3862cf7f7823896df9d07d6 100644
--- a/drivers/perf/Kconfig
+++ b/drivers/perf/Kconfig
@@ -129,10 +129,6 @@ config ANDES_CUSTOM_PMU
 
 	  If you don't know what to do here, say "Y".
 
-config ARM_PMU_ACPI
-	depends on ARM_PMU && ACPI
-	def_bool y
-
 config ARM_SMMU_V3_PMU
 	 tristate "ARM SMMUv3 Performance Monitors Extension"
 	 depends on ARM64 || (COMPILE_TEST && 64BIT)
diff --git a/drivers/perf/Makefile b/drivers/perf/Makefile
index eb8a022dad9a7a78433d42e9424c632d187debea..ddbae5f627ad8bcbe9d7e6c29293429562d85037 100644
--- a/drivers/perf/Makefile
+++ b/drivers/perf/Makefile
@@ -5,7 +5,6 @@ obj-$(CONFIG_ARM_CMN) += arm-cmn.o
 obj-$(CONFIG_ARM_DSU_PMU) += arm_dsu_pmu.o
 obj-$(CONFIG_ARM_NI) += arm-ni.o
 obj-$(CONFIG_ARM_PMU) += arm_pmu.o arm_pmu_platform.o
-obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o
 obj-$(CONFIG_ARM_PMUV3) += arm_pmuv3.o
 obj-$(CONFIG_ARM_V6_PMU) += arm_v6_pmu.o
 obj-$(CONFIG_ARM_V7_PMU) += arm_v7_pmu.o

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks
  2026-11-16 18:21 ` [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks Leo Yan
@ 2026-11-16 18:28   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:28 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

> Platform IRQ affinity lookup currently selects the OF or ACPI helper
> directly. Add fwnode_irq_get_affinity() and an irq_get_affinity operation
> implemented by both firmware types.
> 
> Use the new helper for platform devices, preserving the existing fallback
> to cpu_possible_mask when affinity information is unavailable.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/8] device property: Add software-node IRQ affinity masks
  2026-11-16 18:21 ` [PATCH 2/8] device property: Add software-node IRQ affinity masks Leo Yan
@ 2026-11-16 18:29   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:29 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

> Devices created from firmware tables may need CPU affinity information
> without a corresponding firmware node. Allow software nodes to supply
> this information through the common firmware node IRQ affinity API.
> 
> Add software_node_add_irq_affinity() to copy a CPU mask for an IRQ index,
> and implement the software node irq_get_affinity callback. Keep each mask
> until the node is released and reject replacement so borrowed masks remain
> valid for the node's lifetime.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=2


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/8] perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts
  2026-11-16 18:21 ` [PATCH 4/8] perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts Leo Yan
@ 2026-11-16 18:29   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:29 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

> CPU PMUs may use a separate SPI for each CPU. Extend the existing IRQ
> compatibility check to allow different SPIs in a group while retaining
> the same-PPI requirement.
> 
> Extend arm_acpi_register_sw_node_irq_affinity() to publish a singleton
> CPU mask for each SPI resource, using the CPU recorded in its mapping
> entry. Keep the full group mask at index zero for a shared PPI or a
> counting-only device with no IRQ resources.
> 
> Retain zero-GSI CPU PMU entries for counting-only devices. Trust
> firmware to provide GICC interrupt descriptions as specified by ACPI.
> SPE and TRBE remain the common registration interface's callers in this
> commit.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=4


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 7/8] perf/arm_pmu: Use ACPI CPU affinity in IRQ handling
  2026-11-16 18:21 ` [PATCH 7/8] perf/arm_pmu: Use ACPI CPU affinity in IRQ handling Leo Yan
@ 2026-11-16 18:34   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:34 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

> Read each IRQ resource's CPU mask through platform_get_irq_affinity().
> For ACPI SPIs, select the CPU from that resource's singleton mask.
> 
> Add pmu_get_irq_affinity() for counting-only PMUs, which have no IRQ
> resource to query. Fall back to cpu_possible_mask when firmware provides
> no affinity mask.
> 
> Select DT handling from the device's OF node. Preserve the DT SPI
> interrupt-affinity phandle order and the single-PPI path.
> 
> The common platform probe initializes the per-CPU PMU pointers and
> supported CPU mask before requesting interrupts. Use that mask in
> armpmu_request_irq() and remove the cpu_possible_mask fallback needed
> by the former ACPI pre-probe IRQ setup.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=7


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/8] perf/arm_pmu: Support ACPI devices in the platform probe
  2026-11-16 18:21 ` [PATCH 6/8] perf/arm_pmu: Support ACPI devices in the platform probe Leo Yan
@ 2026-11-16 18:36   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:36 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

> Add pmu_get_match_data() to select the initialization callback for DT
> and ACPI devices. Use OF match data for devices with a DT node, and
> match the platform device name against the existing compatible table
> otherwise. This also handles devices described by software nodes.
> 
> Return -ENODEV when no initializer or fallback probe table is available.
> Append the platform device ID to numbered PMU names, leaving unnumbered
> DT device names unchanged.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=6


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 8/8] ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/
  2026-11-16 18:21 ` [PATCH 8/8] ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/ Leo Yan
@ 2026-11-16 18:37   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:37 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

> The ACPI PMU code now registers platform devices for the CPU PMU, SPE
> and TRBE. Move it to drivers/acpi/arm64/pmu.c with the other Arm ACPI
> device enumeration code.
> 
> Move its Kconfig entry alongside it and rename the hidden ARM_PMU_ACPI
> symbol to ACPI_PMU. Drop the ARM_PMU dependency: enumeration does not
> use the CPU PMU framework, and each device type is guarded by its driver
> configuration. This allows SPE and TRBE enumeration with ARM_PMU disabled.
> 
> Keep the default-y setting, update the build guard and retain PMU
> maintainer coverage for the new path.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=8


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/8] perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes
  2026-11-16 18:21 ` [PATCH 3/8] perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes Leo Yan
@ 2026-11-16 18:38   ` sashiko-bot
  0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-11-16 18:38 UTC (permalink / raw)
  To: Leo Yan; +Cc: devicetree, linux-perf-users, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf/arm_pmu: arm_acpi_alloc_pmu_groups() fails and warns on
  older MADT tables
--

commit 0dc63259559ab5780db0b0b7b9fa3866f77b52f2
Author: Johnny.Fan <johnny.fan@cixtech.com>

perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes

This commit groups initialized CPUs by MIDR and registers one SPE or TRBE
platform device per group with a software node describing its IRQ
affinity.

> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
> index ca6bf8f86cfe9..7ae291acb0452 100644
> --- a/drivers/perf/arm_pmu_acpi.c
> +++ b/drivers/perf/arm_pmu_acpi.c
[ ... ]
> @@ -68,92 +72,297 @@ static void arm_pmu_acpi_unregister_irq(int cpu)
[ ... ]
> +static struct arm_pmu_acpi_group **
> +arm_acpi_alloc_pmu_groups(const struct arm_pmu_acpi_device_info *info,
> +			 int *nr_groups_out)
> +{
> +	struct arm_pmu_acpi_group **groups;
> +	int cpu, nr_groups = 0;
> +
> +	*nr_groups_out = 0;
> +
> +	groups = kcalloc(num_possible_cpus(), sizeof(*groups), GFP_KERNEL);
> +	if (!groups)
> +		return NULL;
>  
> -	/*
> -	 * Sanity check all the GICC tables for the same interrupt
> -	 * number. For now, only support homogeneous ACPI machines.
> -	 */
>  	for_each_possible_cpu(cpu) {
>  		struct acpi_madt_generic_interrupt *gicc;
> +		struct arm_pmu_acpi_group *group;
> +		u32 gsi;
> +
> +		/* CPUs that have never booted have no saved MIDR */
> +		if (!per_cpu(cpu_data, cpu).reg_midr)
> +			continue;
>  
>  		gicc = acpi_cpu_get_madt_gicc(cpu);
> -		if (gicc->header.length < len)
> -			return gsi ? -ENXIO : 0;
> -
> -		this_gsi = parse_gsi(gicc);
> -		this_hetid = find_acpi_cpu_topology_hetero_id(cpu);
> -		if (!gsi) {
> -			hetid = this_hetid;
> -			gsi = this_gsi;
> -		} else if (hetid != this_hetid || gsi != this_gsi) {
> -			pr_warn("ACPI: %s: must be homogeneous\n", pdev->name);
> -			return -ENXIO;
> +		if (gicc->header.length < info->len) {
> +			pr_warn("ACPI: %s: miss GICC entries\n", info->name);
> +			goto out_free;
>  		}

[Severity: Medium]
Does this cause spurious boot warnings on platforms with older MADT
revisions?

Previously, gicc->header.length < len returned 0 silently when no prior
CPU had advertised a non-zero GSI.  Now, on systems with MADT GICC entries
predating ACPI 6.3 (for SPE) or ACPI 6.5 (for TRBE),
arm_acpi_alloc_pmu_groups() logs a warning and returns NULL, which
arm_acpi_register_pmu_devices() turns into -ENOMEM and a second "Unable
to register device" warning in arm_spe_acpi_register_device() and
arm_trbe_acpi_register_device().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-acpi_arm_pmu_registration_hmp-v1-0-0371d4eca626@arm.com?part=3

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-11-16 18:38 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 18:21 [PATCH 0/8] ACPI: arm64: Support PMU on Heterogeneous Systems Leo Yan
2026-11-16 18:21 ` [PATCH 1/8] device property: Add firmware node IRQ affinity callbacks Leo Yan
2026-11-16 18:28   ` sashiko-bot
2026-11-16 18:21 ` [PATCH 2/8] device property: Add software-node IRQ affinity masks Leo Yan
2026-11-16 18:29   ` sashiko-bot
2026-11-16 18:21 ` [PATCH 3/8] perf/arm_pmu: Register ACPI SPE and TRBE devices with software nodes Leo Yan
2026-11-16 18:38   ` sashiko-bot
2026-11-16 18:21 ` [PATCH 4/8] perf/arm_pmu: Prepare ACPI registration for per-CPU interrupts Leo Yan
2026-11-16 18:29   ` sashiko-bot
2026-11-16 18:21 ` [PATCH 5/8] perf/arm_pmu: Register ACPI CPU PMUs as platform devices Leo Yan
2026-11-16 18:21 ` [PATCH 6/8] perf/arm_pmu: Support ACPI devices in the platform probe Leo Yan
2026-11-16 18:36   ` sashiko-bot
2026-11-16 18:21 ` [PATCH 7/8] perf/arm_pmu: Use ACPI CPU affinity in IRQ handling Leo Yan
2026-11-16 18:34   ` sashiko-bot
2026-11-16 18:21 ` [PATCH 8/8] ACPI: arm64: Move PMU device registration to drivers/acpi/arm64/ Leo Yan
2026-11-16 18:37   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox