@@ -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;
@@ -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
@@ -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;
};
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@arm.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(-)