diff mbox series

[2/3] firmware: arm_ffa: Setup of_node for ffa devices

Message ID 0e863a4baea59865aff0d1b5657f548bc0aa8d2a.1737441631.git.viresh.kumar@linaro.org (mailing list archive)
State New
Headers show
Series firmware: arm_ffa: Add DT support | expand

Commit Message

Viresh Kumar Jan. 21, 2025, 6:56 a.m. UTC
Match and bind the of_node for the FFA device.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/firmware/arm_ffa/bus.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Sudeep Holla Jan. 21, 2025, 9:59 a.m. UTC | #1
On Tue, Jan 21, 2025 at 12:26:39PM +0530, Viresh Kumar wrote:
> Match and bind the of_node for the FFA device.

I am bit confused and need more details than the above line 
Viresh Kumar Jan. 21, 2025, 10:09 a.m. UTC | #2
On 21-01-25, 09:59, Sudeep Holla wrote:
> On Tue, Jan 21, 2025 at 12:26:39PM +0530, Viresh Kumar wrote:
> > Match and bind the of_node for the FFA device.
> 
> I am bit confused and need more details than the above line 
diff mbox series

Patch

diff --git a/drivers/firmware/arm_ffa/bus.c b/drivers/firmware/arm_ffa/bus.c
index dea3eb741d95..ca526e438e71 100644
--- a/drivers/firmware/arm_ffa/bus.c
+++ b/drivers/firmware/arm_ffa/bus.c
@@ -7,6 +7,8 @@ 
 
 #include <linux/arm_ffa.h>
 #include <linux/device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -187,6 +189,32 @@  bool ffa_device_is_valid(struct ffa_device *ffa_dev)
 	return valid;
 }
 
+static void ffa_device_of_setup(struct ffa_device *ffa_dev)
+{
+	struct device_node *np;
+	uuid_t uuid;
+	u32 val;
+
+	/* vm-id and UUID must match */
+	for_each_compatible_node(np, NULL, "arm,ffa") {
+		if (of_property_read_u32(np, "vm-id", &val))
+			continue;
+
+		if (ffa_dev->vm_id != val)
+			continue;
+
+		if (of_property_read_u32_array(np, "uuid", (u32 *)&uuid,
+					       sizeof(uuid) / sizeof(u32)))
+			continue;
+
+		if (!uuid_equal(&ffa_dev->uuid, &uuid))
+			continue;
+
+		device_set_node(&ffa_dev->dev, of_fwnode_handle(np));
+		break;
+	}
+}
+
 struct ffa_device *
 ffa_device_register(const struct ffa_partition_info *part_info,
 		    const struct ffa_ops *ops)
@@ -222,6 +250,8 @@  ffa_device_register(const struct ffa_partition_info *part_info,
 	import_uuid(&uuid, (u8 *)part_info->uuid);
 	uuid_copy(&ffa_dev->uuid, &uuid);
 
+	ffa_device_of_setup(ffa_dev);
+
 	ret = device_register(&ffa_dev->dev);
 	if (ret) {
 		dev_err(dev, "unable to register device %s err=%d\n",