All of lore.kernel.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, lukasz.luba@arm.com,
	james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com,
	cristian.marussi@arm.com, arnd@arndb.de,
	gregkh@linuxfoundation.org, robh@kernel.org
Subject: [PATCH v5 1/3] firmware: arm_scmi: support only one single SystemPower device
Date: Thu,  4 Feb 2021 16:59:11 +0000	[thread overview]
Message-ID: <20210204165913.42582-2-cristian.marussi@arm.com> (raw)
In-Reply-To: <20210204165913.42582-1-cristian.marussi@arm.com>

In order to minimize SCMI platform fw-side complexity, only one platform
should be in charge of SCMI SystemPower protocol communications with the
OSPM: enforce the existence of one single unique device associated with
SystemPower protocol across any possible number of SCMI platforms, and
warn if a system tries to register different SystemPower devices from
multiple platforms.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/bus.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index 88149a46e6d9..e8542a7e8862 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -19,6 +19,9 @@ static DEFINE_IDA(scmi_bus_id);
 static DEFINE_IDR(scmi_available_protocols);
 static DEFINE_SPINLOCK(protocol_lock);
 
+/* Track globally the creation of SCMI SystemPower related devices */
+static bool scmi_syspower_registered;
+
 static const struct scmi_device_id *
 scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv)
 {
@@ -175,6 +178,23 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 	int id, retval;
 	struct scmi_device *scmi_dev;
 
+	/*
+	 * Check if any SCMI SystemPower device was already created.
+	 *
+	 * Note that, shared global @scmi_syspower_registered is not protected
+	 * by a mutex since:
+	 *  - scmi_device_create() is not concurrently invoked by the SCMI core
+	 *  - scmi_device_destroy() is effectively called only upon SCMI core
+	 *    unloading/unbinding, so no race is either possible between create
+	 *    and destroy.
+	 */
+	if (protocol == SCMI_PROTOCOL_SYSTEM && scmi_syspower_registered) {
+		dev_warn(parent,
+			 "SCMI SystemPower protocol device must be unique !\n");
+		dump_stack();
+		return NULL;
+	}
+
 	scmi_dev = kzalloc(sizeof(*scmi_dev), GFP_KERNEL);
 	if (!scmi_dev)
 		return NULL;
@@ -204,6 +224,9 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 	if (retval)
 		goto put_dev;
 
+	if (protocol == SCMI_PROTOCOL_SYSTEM)
+		scmi_syspower_registered = true;
+
 	return scmi_dev;
 put_dev:
 	kfree_const(scmi_dev->name);
@@ -218,6 +241,8 @@ void scmi_device_destroy(struct scmi_device *scmi_dev)
 	scmi_handle_put(scmi_dev->handle);
 	ida_simple_remove(&scmi_bus_id, scmi_dev->id);
 	device_unregister(&scmi_dev->dev);
+	if (scmi_dev->protocol_id == SCMI_PROTOCOL_SYSTEM)
+		scmi_syspower_registered = false;
 }
 
 void scmi_set_handle(struct scmi_device *scmi_dev)
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: robh@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org,
	sudeep.holla@arm.com, lukasz.luba@arm.com,
	james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com,
	cristian.marussi@arm.com
Subject: [PATCH v5 1/3] firmware: arm_scmi: support only one single SystemPower device
Date: Thu,  4 Feb 2021 16:59:11 +0000	[thread overview]
Message-ID: <20210204165913.42582-2-cristian.marussi@arm.com> (raw)
In-Reply-To: <20210204165913.42582-1-cristian.marussi@arm.com>

In order to minimize SCMI platform fw-side complexity, only one platform
should be in charge of SCMI SystemPower protocol communications with the
OSPM: enforce the existence of one single unique device associated with
SystemPower protocol across any possible number of SCMI platforms, and
warn if a system tries to register different SystemPower devices from
multiple platforms.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/bus.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index 88149a46e6d9..e8542a7e8862 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -19,6 +19,9 @@ static DEFINE_IDA(scmi_bus_id);
 static DEFINE_IDR(scmi_available_protocols);
 static DEFINE_SPINLOCK(protocol_lock);
 
+/* Track globally the creation of SCMI SystemPower related devices */
+static bool scmi_syspower_registered;
+
 static const struct scmi_device_id *
 scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv)
 {
@@ -175,6 +178,23 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 	int id, retval;
 	struct scmi_device *scmi_dev;
 
+	/*
+	 * Check if any SCMI SystemPower device was already created.
+	 *
+	 * Note that, shared global @scmi_syspower_registered is not protected
+	 * by a mutex since:
+	 *  - scmi_device_create() is not concurrently invoked by the SCMI core
+	 *  - scmi_device_destroy() is effectively called only upon SCMI core
+	 *    unloading/unbinding, so no race is either possible between create
+	 *    and destroy.
+	 */
+	if (protocol == SCMI_PROTOCOL_SYSTEM && scmi_syspower_registered) {
+		dev_warn(parent,
+			 "SCMI SystemPower protocol device must be unique !\n");
+		dump_stack();
+		return NULL;
+	}
+
 	scmi_dev = kzalloc(sizeof(*scmi_dev), GFP_KERNEL);
 	if (!scmi_dev)
 		return NULL;
@@ -204,6 +224,9 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 	if (retval)
 		goto put_dev;
 
+	if (protocol == SCMI_PROTOCOL_SYSTEM)
+		scmi_syspower_registered = true;
+
 	return scmi_dev;
 put_dev:
 	kfree_const(scmi_dev->name);
@@ -218,6 +241,8 @@ void scmi_device_destroy(struct scmi_device *scmi_dev)
 	scmi_handle_put(scmi_dev->handle);
 	ida_simple_remove(&scmi_bus_id, scmi_dev->id);
 	device_unregister(&scmi_dev->dev);
+	if (scmi_dev->protocol_id == SCMI_PROTOCOL_SYSTEM)
+		scmi_syspower_registered = false;
 }
 
 void scmi_set_handle(struct scmi_device *scmi_dev)
-- 
2.17.1


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

  reply	other threads:[~2021-02-04 17:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-04 16:59 [PATCH v5 0/3] Introduce SCMI System Power Control driver Cristian Marussi
2021-02-04 16:59 ` Cristian Marussi
2021-02-04 16:59 ` Cristian Marussi [this message]
2021-02-04 16:59   ` [PATCH v5 1/3] firmware: arm_scmi: support only one single SystemPower device Cristian Marussi
2021-02-04 16:59 ` [PATCH v5 2/3] firmware: arm_scmi: add System Power utility macro Cristian Marussi
2021-02-04 16:59   ` Cristian Marussi
2021-02-04 16:59 ` [PATCH v5 3/3] firmware: arm_scmi: add SCMI System Power Control driver Cristian Marussi
2021-02-04 16:59   ` 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=20210204165913.42582-2-cristian.marussi@arm.com \
    --to=cristian.marussi@arm.com \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.quinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=robh@kernel.org \
    --cc=sudeep.holla@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.