public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com,
	Jonathan.Cameron@Huawei.com, f.fainelli@gmail.com,
	etienne.carriere@linaro.org, vincent.guittot@linaro.org,
	souvik.chakravarty@arm.com, wleavitt@marvell.com,
	peter.hilber@opensynergy.com, nicola.mazzucato@arm.com,
	tarek.el-sherbiny@arm.com, cristian.marussi@arm.com
Subject: [RFC PATCH 2/6] firmware: arm_scmi: Add bus helpers to enter raw mode
Date: Tue, 16 Aug 2022 08:24:46 +0100	[thread overview]
Message-ID: <20220816072450.3120959-3-cristian.marussi@arm.com> (raw)
In-Reply-To: <20220816072450.3120959-1-cristian.marussi@arm.com>

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(-)

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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-08-16  7:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  7:24 [RFC PATCH 0/6] Introduce a unified API for SCMI Server testing Cristian Marussi
2022-08-16  7:24 ` [RFC PATCH 1/6] firmware: arm_scmi: Refactor xfer in-flight registration routines Cristian Marussi
2022-08-16  7:24 ` Cristian Marussi [this message]
2022-08-16  7:24 ` [RFC PATCH 3/6] firmware: arm_scmi: Add xfer raw helpers Cristian Marussi
2022-08-16  7:24 ` [RFC PATCH 4/6] firmware: arm_scmi: Move errors defs and code to common.h Cristian Marussi
2022-08-16  7:24 ` [RFC PATCH 5/6] firmware: arm_scmi: Add raw transmission support Cristian Marussi
2022-08-16 18:03   ` Mark Brown
2022-08-17  8:38     ` Cristian Marussi
2022-08-17 13:42       ` Mark Brown
2022-08-17 14:21         ` Cristian Marussi
2022-08-16  7:24 ` [RFC PATCH 6/6] firmware: arm_scmi: Call Raw mode hooks from the core stack Cristian Marussi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220816072450.3120959-3-cristian.marussi@arm.com \
    --to=cristian.marussi@arm.com \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=etienne.carriere@linaro.org \
    --cc=f.fainelli@gmail.com \
    --cc=james.quinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicola.mazzucato@arm.com \
    --cc=peter.hilber@opensynergy.com \
    --cc=souvik.chakravarty@arm.com \
    --cc=sudeep.holla@arm.com \
    --cc=tarek.el-sherbiny@arm.com \
    --cc=vincent.guittot@linaro.org \
    --cc=wleavitt@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox