[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220816072450.3120959-3-cristian.marussi@arm.com>
Date: Tue, 16 Aug 2022 08:24:46 +0100
From: Cristian Marussi <cristian.marussi@....com>
To: linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Cc: sudeep.holla@....com, james.quinlan@...adcom.com,
Jonathan.Cameron@...wei.com, f.fainelli@...il.com,
etienne.carriere@...aro.org, vincent.guittot@...aro.org,
souvik.chakravarty@....com, wleavitt@...vell.com,
peter.hilber@...nsynergy.com, nicola.mazzucato@....com,
tarek.el-sherbiny@....com, cristian.marussi@....com
Subject: [RFC PATCH 2/6] firmware: arm_scmi: Add bus helpers to enter raw mode
Add a couple of helpers to be able to trigger the un-registration and the
re-registration of the whole stack of SCMI drivers from/to the SCMI bus.
Once this mode is enabled any new SCMI driver registration is inhibited
and delayed till the this new mode is disabled.
Signed-off-by: Cristian Marussi <cristian.marussi@....com>
---
drivers/firmware/arm_scmi/bus.c | 69 +++++++++++++++++++++++++++++-
drivers/firmware/arm_scmi/common.h | 2 +
include/linux/scmi_protocol.h | 1 +
3 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index d4e23101448a..c4b3371dcb1b 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -19,6 +19,10 @@ static DEFINE_IDA(scmi_bus_id);
static DEFINE_IDR(scmi_protocols);
static DEFINE_SPINLOCK(protocol_lock);
+static bool scmi_raw_mode_enabled;
+static LIST_HEAD(scmi_registered_drivers);
+static DEFINE_MUTEX(scmi_raw_mode_mtx);
+
static const struct scmi_device_id *
scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv)
{
@@ -144,6 +148,18 @@ int scmi_driver_register(struct scmi_driver *driver, struct module *owner,
driver->driver.owner = owner;
driver->driver.mod_name = mod_name;
+ mutex_lock(&scmi_raw_mode_mtx);
+ list_add_tail(&driver->node, &scmi_registered_drivers);
+ /*
+ * If RAW mode is enabled here, the driver will be registered fully
+ * only later, when RAW will be (if ever) disabled.
+ */
+ if (scmi_raw_mode_enabled) {
+ mutex_unlock(&scmi_raw_mode_mtx);
+ return 0;
+ }
+ mutex_unlock(&scmi_raw_mode_mtx);
+
retval = driver_register(&driver->driver);
if (!retval)
pr_debug("registered new scmi driver %s\n", driver->name);
@@ -154,7 +170,18 @@ EXPORT_SYMBOL_GPL(scmi_driver_register);
void scmi_driver_unregister(struct scmi_driver *driver)
{
- driver_unregister(&driver->driver);
+ mutex_lock(&scmi_raw_mode_mtx);
+ list_del_init(&driver->node);
+ /*
+ * No need to unregister a driver when RAW mode is enabled, it would
+ * have been already unregistered when RAW was enabled.
+ */
+ if (!scmi_raw_mode_enabled) {
+ mutex_unlock(&scmi_raw_mode_mtx);
+ driver_unregister(&driver->driver);
+ mutex_lock(&scmi_raw_mode_mtx);
+ }
+ mutex_unlock(&scmi_raw_mode_mtx);
scmi_protocol_device_unrequest(driver->id_table);
}
EXPORT_SYMBOL_GPL(scmi_driver_unregister);
@@ -276,6 +303,46 @@ static void scmi_devices_unregister(void)
bus_for_each_dev(&scmi_bus_type, NULL, NULL, __scmi_devices_unregister);
}
+void scmi_bus_raw_mode_enable(void)
+{
+ struct scmi_driver *driver;
+
+ /* On enable any known SCMI driver is unregistered */
+ mutex_lock(&scmi_raw_mode_mtx);
+ list_for_each_entry_reverse(driver, &scmi_registered_drivers, node) {
+ mutex_unlock(&scmi_raw_mode_mtx);
+
+ driver_unregister(&driver->driver);
+
+ mutex_lock(&scmi_raw_mode_mtx);
+ }
+ scmi_raw_mode_enabled = true;
+ mutex_unlock(&scmi_raw_mode_mtx);
+}
+
+void scmi_bus_raw_mode_disable(void)
+{
+ int retval;
+ struct scmi_driver *driver;
+
+ /*
+ * On disable any known SCMI driver is registered again unless it was
+ * removed already as a module.
+ */
+ mutex_lock(&scmi_raw_mode_mtx);
+ list_for_each_entry(driver, &scmi_registered_drivers, node) {
+ mutex_unlock(&scmi_raw_mode_mtx);
+
+ retval = driver_register(&driver->driver);
+ if (retval)
+ pr_warn("Failed to rebind driver %s\n", driver->name);
+
+ mutex_lock(&scmi_raw_mode_mtx);
+ }
+ scmi_raw_mode_enabled = false;
+ mutex_unlock(&scmi_raw_mode_mtx);
+}
+
int __init scmi_bus_init(void)
{
int retval;
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index 61aba7447c32..bbaac20544a5 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -171,6 +171,8 @@ int scmi_protocol_device_request(const struct scmi_device_id *id_table);
void scmi_protocol_device_unrequest(const struct scmi_device_id *id_table);
struct scmi_device *scmi_child_dev_find(struct device *parent,
int prot_id, const char *name);
+void scmi_bus_raw_mode_enable(void);
+void scmi_bus_raw_mode_disable(void);
/**
* struct scmi_desc - Description of SoC integration
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index 4f765bc788ff..39e64ec72984 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -820,6 +820,7 @@ struct scmi_driver {
void (*remove)(struct scmi_device *sdev);
const struct scmi_device_id *id_table;
+ struct list_head node;
struct device_driver driver;
};
--
2.32.0
Powered by blists - more mailing lists