[PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function

Yeoreum Yun yeoreum.yun at arm.com
Fri Nov 27 07:28:31 PST 2026


Somce of protocol based on the smc is not enough to match smccc-device
and smccc-driver with func_id only.

For example, firme interface will create smccc-device per service
and this requires to chech whether firme smccc-device is for each
service.

To resolve this, add match function and match parameter for device
which is set at the time of smccc-device creation so that smccc-driver
could match proper smccc-device with match parameter and driver specific
match function.

This match parameter is defined under smc func-id. IOW, devices which
share the func-id should have the same type for module parameter so
that each driver under the same func-id can check extra one with
match parameter type.

Signed-off-by: Yeoreum Yun <yeoreum.yun at arm.com>
---
 drivers/firmware/smccc/bus.c   | 24 ++++++++++++++++--------
 drivers/firmware/smccc/smccc.c |  3 ++-
 include/linux/arm-smccc-bus.h  |  5 ++++-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/smccc/bus.c b/drivers/firmware/smccc/bus.c
index 0357a7c48af0b..4a1182153bef8 100644
--- a/drivers/firmware/smccc/bus.c
+++ b/drivers/firmware/smccc/bus.c
@@ -11,15 +11,20 @@ static int arm_smccc_bus_match(struct device *dev,
 {
 	const struct arm_smccc_device_id *id_table;
 	const struct arm_smccc_device *smccc_dev = to_arm_smccc_device(dev);
+	const struct arm_smccc_driver *smccc_drv = to_arm_smccc_driver(drv);
 
-	id_table = to_arm_smccc_driver(drv)->id_table;
+	id_table = smccc_drv->id_table;
 	if (!id_table)
 		return 0;
 
-	while (id_table->func_id) {
-		if (smccc_dev->func_id == id_table->func_id)
-			return 1;
-		id_table++;
+	for (; id_table->func_id; id_table++) {
+		if (smccc_dev->func_id != id_table->func_id)
+			continue;
+		if (!!smccc_dev->match_params != !!smccc_drv->match)
+			continue;
+		if (smccc_drv->match && !smccc_drv->match(smccc_dev))
+			continue;
+		return 1;
 	}
 
 	return 0;
@@ -103,7 +108,7 @@ static void arm_smccc_release_device(struct device *dev)
 	kfree(smccc_dev);
 }
 
-static struct device *arm_smccc_device_alloc(u32 func_id)
+static struct device *arm_smccc_device_alloc(u32 func_id, void *match_params)
 {
 	struct arm_smccc_device *smccc_dev;
 
@@ -112,6 +117,7 @@ static struct device *arm_smccc_device_alloc(u32 func_id)
 		return NULL;
 
 	smccc_dev->func_id = func_id;
+	smccc_dev->match_params = match_params;
 	smccc_dev->dev.bus = &arm_smccc_bus_type;
 	smccc_dev->dev.release = arm_smccc_release_device;
 	device_initialize(&smccc_dev->dev);
@@ -119,14 +125,16 @@ static struct device *arm_smccc_device_alloc(u32 func_id)
 	return &smccc_dev->dev;
 }
 
-struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id)
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id,
+						   void *match_params)
 {
 	int ret;
 
 	if (!name)
 		return ERR_PTR(-EINVAL);
 
-	struct device *dev __free(put_device) = arm_smccc_device_alloc(func_id);
+	struct device *dev __free(put_device) = arm_smccc_device_alloc(func_id,
+								       match_params);
 	if (!dev)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/drivers/firmware/smccc/smccc.c b/drivers/firmware/smccc/smccc.c
index 5dc768ac4143a..93658120114d3 100644
--- a/drivers/firmware/smccc/smccc.c
+++ b/drivers/firmware/smccc/smccc.c
@@ -136,7 +136,8 @@ static int __init smccc_devices_init(void)
 		if (!smccc_probe_smccc_device(smccc_dev))
 			continue;
 
-		sdev = arm_smccc_device_register(smccc_dev->device_name, smccc_dev->func_id);
+		sdev = arm_smccc_device_register(smccc_dev->device_name,
+						 smccc_dev->func_id, NULL);
 		if (IS_ERR(sdev))
 			pr_err("%s: could not register device: %pe\n",
 			       smccc_dev->device_name, sdev);
diff --git a/include/linux/arm-smccc-bus.h b/include/linux/arm-smccc-bus.h
index 05c0c850510e0..b7b44c9b67ec3 100644
--- a/include/linux/arm-smccc-bus.h
+++ b/include/linux/arm-smccc-bus.h
@@ -12,6 +12,7 @@
 struct arm_smccc_device {
 	struct device dev;
 	u32 func_id;
+	void *match_params;
 };
 
 #define to_arm_smccc_device(d) container_of_const(d, struct arm_smccc_device, dev)
@@ -22,6 +23,7 @@ struct arm_smccc_driver {
 	const char *name;
 	int (*probe)(struct arm_smccc_device *sdev);
 	void (*remove)(struct arm_smccc_device *sdev);
+	bool (*match)(const struct arm_smccc_device *sdev);
 	const struct arm_smccc_device_id *id_table;
 };
 
@@ -31,7 +33,8 @@ struct arm_smccc_driver {
 int arm_smccc_driver_register(struct arm_smccc_driver *driver,
 		struct module *owner, const char *mod_name);
 void arm_smccc_driver_unregister(struct arm_smccc_driver *driver);
-struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id);
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id,
+						   void *match_param);
 void arm_smccc_device_unregister(struct arm_smccc_device *smcc_dev);
 
 #define arm_smccc_register(driver) \

-- 
2.43.0




More information about the linux-arm-kernel mailing list