[PATCH 2/8] device property: Add software-node IRQ affinity masks

From: Leo Yan

Date: Mon Nov 16 2026 - 13:22:30 EST


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@xxxxxxx>
---
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