linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Introduce SCMI System Power Control driver
@ 2022-06-23 12:47 Cristian Marussi
  2022-06-23 12:47 ` [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls Cristian Marussi
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Cristian Marussi @ 2022-06-23 12:47 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sudeep.holla, vincent.guittot, f.fainelli, Cristian Marussi

Hi,

This series is a respin of an old series[0] parked for a while waiting for
a required SCMI specification change to be published.

The series, building on top of the SCMI System Power Protocol, adds a new 
SCMI driver which, registering for SystemPower notifications, takes care to
satisfy SCMI plaform system-transitions graceful requests like shutdown or
reboot involving userspace interactions as needed.

Interaction with userspace boils down to the same orderly_ Kernel methods
used by ACPI to handle similar shutdown requests.

The latest SCMI v3.1 specification [1], which adds a new timeout field to
the graceful notifications payload, let the platform advertise for how long
it will possibly wait for the requested system state transition to happen
before forcibly enforcing it.

As a part of the series, patch 2/3 enforces, at the SCMI core level, the
creation of one single SCMI SystemPower device, to avoid promoting the
design of systems in which multiple SCMI platforms can advertise the
concurrent support of SystemPower protocol: when multiple SCMI platform
are defined, only one of them should be in charge of SystemPower comms
with the OSPM, so only one such SystemPower device across all platforms
is allowed to be created.

Thanks,
Cristian

[0]:https://lore.kernel.org/linux-arm-kernel/20210204165913.42582-1-cristian.marussi@arm.com/
[1]:https://developer.arm.com/documentation/den0056/d/?lang=en

Cristian Marussi (5):
  firmware: arm_scmi: Remove deprecated ida_simple_ calls
  firmware: arm_scmi: Support only one single SystemPower device
  firmware: arm_scmi: Add SCMIv3.1 SystemPower extensions
  firmware: arm_scmi: Add devm_protocol_acquire helper
  firmware: arm_scmi: Add SCMI System Power Control driver

 drivers/firmware/arm_scmi/Kconfig             |  12 +
 drivers/firmware/arm_scmi/Makefile            |   1 +
 drivers/firmware/arm_scmi/bus.c               |  37 +-
 drivers/firmware/arm_scmi/driver.c            |  70 +++-
 .../firmware/arm_scmi/scmi_power_control.c    | 362 ++++++++++++++++++
 drivers/firmware/arm_scmi/system.c            |  17 +-
 include/linux/scmi_protocol.h                 |   7 +
 7 files changed, 486 insertions(+), 20 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/scmi_power_control.c

-- 
2.32.0


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls
  2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
@ 2022-06-23 12:47 ` Cristian Marussi
  2022-07-01 13:46   ` Sudeep Holla
  2022-06-23 12:47 ` [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device Cristian Marussi
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Cristian Marussi @ 2022-06-23 12:47 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sudeep.holla, vincent.guittot, f.fainelli, Cristian Marussi

Remove deprecated calls to ida_simple_get/ida_simple_remove.

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

diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index e95085a66bc4..a7cbf4d09081 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -192,7 +192,7 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 		return NULL;
 	}
 
-	id = ida_simple_get(&scmi_bus_id, 1, 0, GFP_KERNEL);
+	id = ida_alloc(&scmi_bus_id, GFP_KERNEL);
 	if (id < 0) {
 		kfree_const(scmi_dev->name);
 		kfree(scmi_dev);
@@ -215,7 +215,7 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 put_dev:
 	kfree_const(scmi_dev->name);
 	put_device(&scmi_dev->dev);
-	ida_simple_remove(&scmi_bus_id, id);
+	ida_free(&scmi_bus_id, id);
 	return NULL;
 }
 
@@ -223,7 +223,7 @@ void scmi_device_destroy(struct scmi_device *scmi_dev)
 {
 	kfree_const(scmi_dev->name);
 	scmi_handle_put(scmi_dev->handle);
-	ida_simple_remove(&scmi_bus_id, scmi_dev->id);
+	ida_free(&scmi_bus_id, scmi_dev->id);
 	device_unregister(&scmi_dev->dev);
 }
 
-- 
2.32.0


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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device
  2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
  2022-06-23 12:47 ` [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls Cristian Marussi
@ 2022-06-23 12:47 ` Cristian Marussi
  2022-07-01 13:45   ` Sudeep Holla
  2022-06-23 12:47 ` [PATCH 3/5] firmware: arm_scmi: Add SCMIv3.1 SystemPower extensions Cristian Marussi
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Cristian Marussi @ 2022-06-23 12:47 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sudeep.holla, vincent.guittot, f.fainelli, Cristian Marussi

In order to minimize SCMI platform fw-side complexity, only one single SCMI
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 | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index a7cbf4d09081..476855d3dccb 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -19,6 +19,11 @@ static DEFINE_IDA(scmi_bus_id);
 static DEFINE_IDR(scmi_protocols);
 static DEFINE_SPINLOCK(protocol_lock);
 
+/* Track globally the creation of SCMI SystemPower related devices */
+static bool scmi_syspower_registered;
+/* Protect access to scmi_syspower_registered */
+static DEFINE_MUTEX(scmi_syspower_mtx);
+
 static const struct scmi_device_id *
 scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv)
 {
@@ -207,11 +212,31 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 	scmi_dev->dev.release = scmi_device_release;
 	dev_set_name(&scmi_dev->dev, "scmi_dev.%d", id);
 
+	mutex_lock(&scmi_syspower_mtx);
+	if (protocol == SCMI_PROTOCOL_SYSTEM && scmi_syspower_registered) {
+		dev_warn(parent,
+			 "SCMI SystemPower protocol device must be unique !\n");
+
+		mutex_unlock(&scmi_syspower_mtx);
+		ida_free(&scmi_bus_id, id);
+		kfree_const(scmi_dev->name);
+		kfree(scmi_dev);
+		return NULL;
+	}
+
 	retval = device_register(&scmi_dev->dev);
-	if (retval)
+	if (retval) {
+		mutex_unlock(&scmi_syspower_mtx);
 		goto put_dev;
+	}
+
+	if (protocol == SCMI_PROTOCOL_SYSTEM)
+		scmi_syspower_registered = true;
+
+	mutex_unlock(&scmi_syspower_mtx);
 
 	return scmi_dev;
+
 put_dev:
 	kfree_const(scmi_dev->name);
 	put_device(&scmi_dev->dev);
@@ -221,6 +246,10 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol,
 
 void scmi_device_destroy(struct scmi_device *scmi_dev)
 {
+	mutex_lock(&scmi_syspower_mtx);
+	if (scmi_dev->protocol_id == SCMI_PROTOCOL_SYSTEM)
+		scmi_syspower_registered = false;
+	mutex_unlock(&scmi_syspower_mtx);
 	kfree_const(scmi_dev->name);
 	scmi_handle_put(scmi_dev->handle);
 	ida_free(&scmi_bus_id, scmi_dev->id);
-- 
2.32.0


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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/5] firmware: arm_scmi: Add SCMIv3.1 SystemPower extensions
  2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
  2022-06-23 12:47 ` [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls Cristian Marussi
  2022-06-23 12:47 ` [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device Cristian Marussi
@ 2022-06-23 12:47 ` Cristian Marussi
  2022-06-23 12:47 ` [PATCH 4/5] firmware: arm_scmi: Add devm_protocol_acquire helper Cristian Marussi
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Cristian Marussi @ 2022-06-23 12:47 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sudeep.holla, vincent.guittot, f.fainelli, Cristian Marussi

Add support for SCMIv3.1 SystemPower optional timeout field while
dispatching SYSTEM_POWER_STATE_NOTIFIER notification.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/system.c | 17 ++++++++++++++++-
 include/linux/scmi_protocol.h      |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_scmi/system.c b/drivers/firmware/arm_scmi/system.c
index 220e399118ad..9383d7584539 100644
--- a/drivers/firmware/arm_scmi/system.c
+++ b/drivers/firmware/arm_scmi/system.c
@@ -27,10 +27,12 @@ struct scmi_system_power_state_notifier_payld {
 	__le32 agent_id;
 	__le32 flags;
 	__le32 system_state;
+	__le32 timeout;
 };
 
 struct scmi_system_info {
 	u32 version;
+	bool graceful_timeout_supported;
 };
 
 static int scmi_system_request_notify(const struct scmi_protocol_handle *ph,
@@ -72,17 +74,27 @@ scmi_system_fill_custom_report(const struct scmi_protocol_handle *ph,
 			       const void *payld, size_t payld_sz,
 			       void *report, u32 *src_id)
 {
+	size_t expected_sz;
 	const struct scmi_system_power_state_notifier_payld *p = payld;
 	struct scmi_system_power_state_notifier_report *r = report;
+	struct scmi_system_info *pinfo = ph->get_priv(ph);
 
+	expected_sz = pinfo->graceful_timeout_supported ?
+			sizeof(*p) : sizeof(*p) - sizeof(__le32);
 	if (evt_id != SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER ||
-	    sizeof(*p) != payld_sz)
+	    payld_sz != expected_sz)
 		return NULL;
 
 	r->timestamp = timestamp;
 	r->agent_id = le32_to_cpu(p->agent_id);
 	r->flags = le32_to_cpu(p->flags);
 	r->system_state = le32_to_cpu(p->system_state);
+	if (pinfo->graceful_timeout_supported &&
+	    r->system_state == SCMI_SYSTEM_SHUTDOWN &&
+	    SCMI_SYSPOWER_IS_REQUEST_GRACEFUL(r->flags))
+		r->timeout = le32_to_cpu(p->timeout);
+	else
+		r->timeout = 0x00;
 	*src_id = 0;
 
 	return r;
@@ -129,6 +141,9 @@ static int scmi_system_protocol_init(const struct scmi_protocol_handle *ph)
 		return -ENOMEM;
 
 	pinfo->version = version;
+	if (PROTOCOL_REV_MAJOR(pinfo->version) >= 0x2)
+		pinfo->graceful_timeout_supported = true;
+
 	return ph->set_priv(ph, pinfo);
 }
 
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index a922707bdfe8..37d8603816c2 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -896,8 +896,10 @@ struct scmi_clock_rate_notif_report {
 struct scmi_system_power_state_notifier_report {
 	ktime_t		timestamp;
 	unsigned int	agent_id;
+#define SCMI_SYSPOWER_IS_REQUEST_GRACEFUL(flags)	((flags) & BIT(0))
 	unsigned int	flags;
 	unsigned int	system_state;
+	unsigned int	timeout;
 };
 
 struct scmi_perf_limits_report {
-- 
2.32.0


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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/5] firmware: arm_scmi: Add devm_protocol_acquire helper
  2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
                   ` (2 preceding siblings ...)
  2022-06-23 12:47 ` [PATCH 3/5] firmware: arm_scmi: Add SCMIv3.1 SystemPower extensions Cristian Marussi
@ 2022-06-23 12:47 ` Cristian Marussi
  2022-06-23 12:47 ` [PATCH 5/5] firmware: arm_scmi: Add SCMI System Power Control driver Cristian Marussi
  2022-07-01 13:49 ` [PATCH 0/5] Introduce " Sudeep Holla
  5 siblings, 0 replies; 12+ messages in thread
From: Cristian Marussi @ 2022-06-23 12:47 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sudeep.holla, vincent.guittot, f.fainelli, Cristian Marussi

Add a method to get hold of a protocol, causing it to be initialized and
its resource accounting updated, without getting access to its operations
and handle.

Some protocols, like SCMI SystemPower, do not expose any protocol ops to
the Kernel OSPM agent but still need to be at least initialized: this
helper avoids the need to invoke a full devm_get_protocol() only to get
the protocol initialized while throwing away unused the protocol ops and
handle.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/driver.c | 70 +++++++++++++++++++++++-------
 include/linux/scmi_protocol.h      |  5 +++
 2 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 00b7f2aff4ec..7c91fd44baf5 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -1662,6 +1662,30 @@ static void scmi_devm_release_protocol(struct device *dev, void *res)
 	scmi_protocol_release(dres->handle, dres->protocol_id);
 }
 
+static struct scmi_protocol_instance __must_check *
+scmi_devres_protocol_instance_get(struct scmi_device *sdev, u8 protocol_id)
+{
+	struct scmi_protocol_instance *pi;
+	struct scmi_protocol_devres *dres;
+
+	dres = devres_alloc(scmi_devm_release_protocol,
+			    sizeof(*dres), GFP_KERNEL);
+	if (!dres)
+		return ERR_PTR(-ENOMEM);
+
+	pi = scmi_get_protocol_instance(sdev->handle, protocol_id);
+	if (IS_ERR(pi)) {
+		devres_free(dres);
+		return pi;
+	}
+
+	dres->handle = sdev->handle;
+	dres->protocol_id = protocol_id;
+	devres_add(&sdev->dev, dres);
+
+	return pi;
+}
+
 /**
  * scmi_devm_protocol_get  - Devres managed get protocol operations and handle
  * @sdev: A reference to an scmi_device whose embedded struct device is to
@@ -1685,32 +1709,47 @@ scmi_devm_protocol_get(struct scmi_device *sdev, u8 protocol_id,
 		       struct scmi_protocol_handle **ph)
 {
 	struct scmi_protocol_instance *pi;
-	struct scmi_protocol_devres *dres;
-	struct scmi_handle *handle = sdev->handle;
 
 	if (!ph)
 		return ERR_PTR(-EINVAL);
 
-	dres = devres_alloc(scmi_devm_release_protocol,
-			    sizeof(*dres), GFP_KERNEL);
-	if (!dres)
-		return ERR_PTR(-ENOMEM);
-
-	pi = scmi_get_protocol_instance(handle, protocol_id);
-	if (IS_ERR(pi)) {
-		devres_free(dres);
+	pi = scmi_devres_protocol_instance_get(sdev, protocol_id);
+	if (IS_ERR(pi))
 		return pi;
-	}
-
-	dres->handle = handle;
-	dres->protocol_id = protocol_id;
-	devres_add(&sdev->dev, dres);
 
 	*ph = &pi->ph;
 
 	return pi->proto->ops;
 }
 
+/**
+ * scmi_devm_protocol_acquire  - Devres managed helper to get hold of a protocol
+ * @sdev: A reference to an scmi_device whose embedded struct device is to
+ *	  be used for devres accounting.
+ * @protocol_id: The protocol being requested.
+ *
+ * Get hold of a protocol accounting for its usage, possibly triggering its
+ * initialization but without getting access to its protocol specific operations
+ * and handle.
+ *
+ * Being a devres based managed method, protocol hold will be automatically
+ * released, and possibly de-initialized on last user, once the SCMI driver
+ * owning the scmi_device is unbound from it.
+ *
+ * Return: 0 on SUCCESS
+ */
+static int __must_check scmi_devm_protocol_acquire(struct scmi_device *sdev,
+						   u8 protocol_id)
+{
+	struct scmi_protocol_instance *pi;
+
+	pi = scmi_devres_protocol_instance_get(sdev, protocol_id);
+	if (IS_ERR(pi))
+		return PTR_ERR(pi);
+
+	return 0;
+}
+
 static int scmi_devm_protocol_match(struct device *dev, void *res, void *data)
 {
 	struct scmi_protocol_devres *dres = res;
@@ -2297,6 +2336,7 @@ static int scmi_probe(struct platform_device *pdev)
 	handle = &info->handle;
 	handle->dev = info->dev;
 	handle->version = &info->version;
+	handle->devm_protocol_acquire = scmi_devm_protocol_acquire;
 	handle->devm_protocol_get = scmi_devm_protocol_get;
 	handle->devm_protocol_put = scmi_devm_protocol_put;
 
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index 37d8603816c2..1846b4a870cf 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -734,6 +734,9 @@ struct scmi_notify_ops {
  *
  * @dev: pointer to the SCMI device
  * @version: pointer to the structure containing SCMI version information
+ * @devm_protocol_acquire: devres managed method to get hold of a protocol,
+ *			   causing its initialization and related resource
+ *			   accounting
  * @devm_protocol_get: devres managed method to acquire a protocol and get specific
  *		       operations and a dedicated protocol handler
  * @devm_protocol_put: devres managed method to release a protocol
@@ -752,6 +755,8 @@ struct scmi_handle {
 	struct device *dev;
 	struct scmi_revision_info *version;
 
+	int __must_check (*devm_protocol_acquire)(struct scmi_device *sdev,
+						  u8 proto);
 	const void __must_check *
 		(*devm_protocol_get)(struct scmi_device *sdev, u8 proto,
 				     struct scmi_protocol_handle **ph);
-- 
2.32.0


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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/5] firmware: arm_scmi: Add SCMI System Power Control driver
  2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
                   ` (3 preceding siblings ...)
  2022-06-23 12:47 ` [PATCH 4/5] firmware: arm_scmi: Add devm_protocol_acquire helper Cristian Marussi
@ 2022-06-23 12:47 ` Cristian Marussi
  2022-06-27 13:54   ` Greg Kroah-Hartman
  2022-07-01 13:49 ` [PATCH 0/5] Introduce " Sudeep Holla
  5 siblings, 1 reply; 12+ messages in thread
From: Cristian Marussi @ 2022-06-23 12:47 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sudeep.holla, vincent.guittot, f.fainelli, Cristian Marussi,
	Greg Kroah-Hartman

Add an SCMI System Power control driver to handle platform's requests
carried by SYSTEM_POWER_STATE_NOTIFIER notifications: such platform
requested system-wide power state transitions are handled accordingly,
gracefully or forcefully, depending on the notifications' message flags.

Graceful requests are relayed to userspace using the same Kernel API used
to handle ACPI Shutdown bus events.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/Kconfig             |  12 +
 drivers/firmware/arm_scmi/Makefile            |   1 +
 .../firmware/arm_scmi/scmi_power_control.c    | 362 ++++++++++++++++++
 3 files changed, 375 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/scmi_power_control.c

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index cb5d97c2d8bc..c9bcfab00b76 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -162,4 +162,16 @@ config ARM_SCMI_POWER_DOMAIN
 	  will be called scmi_pm_domain. Note this may needed early in boot
 	  before rootfs may be available.
 
+config ARM_SCMI_POWER_CONTROL
+	tristate "SCMI system power control driver"
+	depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF)
+	help
+	  This enables System Power control logic which binds system shutdown or
+	  reboot actions to SCMI System Power notifications generated by SCP
+	  firmware.
+
+	  This driver can also be built as a module.  If so, the module will be
+	  called scmi_power_control. Note this may needed early in boot to catch
+	  early shutdown/reboot SCMI requests.
+
 endmenu
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index a02dc8ce5a7f..9ea86f8cc8f7 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -12,6 +12,7 @@ scmi-module-objs := $(scmi-bus-y) $(scmi-driver-y) $(scmi-protocols-y) \
 		    $(scmi-transport-y)
 obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
 obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o
+obj-$(CONFIG_ARM_SCMI_POWER_CONTROL) += scmi_power_control.o
 
 ifeq ($(CONFIG_THUMB2_KERNEL)$(CONFIG_CC_IS_CLANG),yy)
 # The use of R7 in the SMCCC conflicts with the compiler's use of R7 as a frame
diff --git a/drivers/firmware/arm_scmi/scmi_power_control.c b/drivers/firmware/arm_scmi/scmi_power_control.c
new file mode 100644
index 000000000000..6eb7d2a4b6b1
--- /dev/null
+++ b/drivers/firmware/arm_scmi/scmi_power_control.c
@@ -0,0 +1,362 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SCMI Generic SystemPower Control driver.
+ *
+ * Copyright (C) 2020-2022 ARM Ltd.
+ */
+/*
+ * In order to handle platform originated SCMI SystemPower requests (like
+ * shutdowns or cold/warm resets) we register an SCMI Notification notifier
+ * block to react when such SCMI SystemPower events are emitted by platform.
+ *
+ * Once such a notification is received we act accordingly to perform the
+ * required system transition depending on the kind of request.
+ *
+ * Graceful requests are routed to userspace through the same API methods
+ * (orderly_poweroff/reboot()) used by ACPI when handling ACPI Shutdown bus
+ * events.
+ *
+ * Direct forceful requests are not supported since are not meant to be sent
+ * by the SCMI platform to an OSPM like Linux.
+ *
+ * Additionally, graceful request notifications can carry an optional timeout
+ * field stating the maximum amount of time allowed by the platform for
+ * completion after which they are converted to forceful ones: the assumption
+ * here is that even graceful requests can be upper-bound by a maximum final
+ * timeout strictly enforced by the platform itself which can ultimately cut
+ * the power off at will anytime; in order to avoid such extreme scenario, we
+ * track progress of graceful requests through the means of a reboot notifier
+ * converting timed-out graceful requests to forceful ones, so at least we
+ * try to perform a clean sync and shutdown/restart before the power is cut.
+ *
+ * Given the peculiar nature of SCMI SystemPower protocol, that is being in
+ * charge of triggering system wide shutdown/reboot events, there should be
+ * only one SCMI platform actively emitting SystemPower events.
+ * For this reason the SCMI core takes care to enforce the creation of one
+ * single unique device associated to the SCMI System Power protocol; no matter
+ * how many SCMI platforms are defined on the system, only one can be designated
+ * to support System Power: as a consequence this driver will never be probed
+ * more than once.
+ *
+ * For similar reasons as soon as the first valid SystemPower is received by
+ * this driver and the shutdown/reboot is started, any further notification
+ * possibly emitted by the platform will be ignored.
+ */
+
+#include <linux/math.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/printk.h>
+#include <linux/reboot.h>
+#include <linux/scmi_protocol.h>
+#include <linux/slab.h>
+#include <linux/time64.h>
+#include <linux/timer.h>
+#include <linux/types.h>
+#include <linux/workqueue.h>
+
+#ifndef MODULE
+#include <linux/fs.h>
+#endif
+
+enum scmi_syspower_state {
+	SCMI_SYSPOWER_IDLE,
+	SCMI_SYSPOWER_IN_PROGRESS,
+	SCMI_SYSPOWER_REBOOTING
+};
+
+/**
+ * struct scmi_syspower_conf  -  Common configuration
+ *
+ * @dev: A reference device
+ * @state: Current SystemPower state
+ * @state_mtx: @state related mutex
+ * @required_transition: The requested transition as decribed in the received
+ *			 SCMI SystemPower notification
+ * @userspace_nb: The notifier_block registered against the SCMI SystemPower
+ *		  notification to start the needed userspace interactions.
+ * @reboot_nb: A notifier_block optionally used to track reboot progress
+ * @forceful_work: A worker used to trigger a forceful transition once a
+ *		   graceful has timed out.
+ */
+struct scmi_syspower_conf {
+	struct device *dev;
+	enum scmi_syspower_state state;
+	/* Protect access to state */
+	struct mutex state_mtx;
+	enum scmi_system_events required_transition;
+
+	struct notifier_block userspace_nb;
+	struct notifier_block reboot_nb;
+
+	struct delayed_work forceful_work;
+};
+
+#define userspace_nb_to_sconf(x)	\
+	container_of(x, struct scmi_syspower_conf, userspace_nb)
+
+#define reboot_nb_to_sconf(x)		\
+	container_of(x, struct scmi_syspower_conf, reboot_nb)
+
+#define dwork_to_sconf(x)		\
+	container_of(x, struct scmi_syspower_conf, forceful_work)
+
+/**
+ * scmi_reboot_notifier  - A reboot notifier to catch an ongoing successful
+ * system transition
+ * @nb: Reference to the related notifier block
+ * @reason: The reason for the ongoing reboot
+ * @__unused: The cmd being executed on a restart request (unused)
+ *
+ * When an ongoing system transition is detected, compatible with the one
+ * requested by SCMI, cancel the delayed work.
+ *
+ * Return: NOTIFY_OK in any case
+ */
+static int scmi_reboot_notifier(struct notifier_block *nb,
+				unsigned long reason, void *__unused)
+{
+	struct scmi_syspower_conf *sc = reboot_nb_to_sconf(nb);
+
+	mutex_lock(&sc->state_mtx);
+	switch (reason) {
+	case SYS_HALT:
+	case SYS_POWER_OFF:
+		if (sc->required_transition == SCMI_SYSTEM_SHUTDOWN)
+			sc->state = SCMI_SYSPOWER_REBOOTING;
+		break;
+	case SYS_RESTART:
+		if (sc->required_transition == SCMI_SYSTEM_COLDRESET ||
+		    sc->required_transition == SCMI_SYSTEM_WARMRESET)
+			sc->state = SCMI_SYSPOWER_REBOOTING;
+		break;
+	default:
+		break;
+	}
+
+	if (sc->state == SCMI_SYSPOWER_REBOOTING) {
+		dev_dbg(sc->dev, "Reboot in progress...cancel delayed work.\n");
+		cancel_delayed_work_sync(&sc->forceful_work);
+	}
+	mutex_unlock(&sc->state_mtx);
+
+	return NOTIFY_OK;
+}
+
+/**
+ * scmi_request_forceful_transition  - Request forceful SystemPower transition
+ * @sc: A reference to the configuration data
+ *
+ * Initiates the required SystemPower transition without involving userspace:
+ * just trigger the action at the kernel level after issuing an emergency
+ * sync. (if possible at all)
+ */
+static inline void
+scmi_request_forceful_transition(struct scmi_syspower_conf *sc)
+{
+	dev_dbg(sc->dev, "Serving forceful request:%d\n",
+		sc->required_transition);
+
+#ifndef MODULE
+	emergency_sync();
+#endif
+	switch (sc->required_transition) {
+	case SCMI_SYSTEM_SHUTDOWN:
+		kernel_power_off();
+		break;
+	case SCMI_SYSTEM_COLDRESET:
+	case SCMI_SYSTEM_WARMRESET:
+		kernel_restart(NULL);
+		break;
+	default:
+		break;
+	}
+}
+
+static void scmi_forceful_work_func(struct work_struct *work)
+{
+	struct scmi_syspower_conf *sc;
+	struct delayed_work *dwork;
+
+	if (system_state > SYSTEM_RUNNING)
+		return;
+
+	dwork = to_delayed_work(work);
+	sc = dwork_to_sconf(dwork);
+
+	dev_dbg(sc->dev, "Graceful request timed out...forcing !\n");
+	mutex_lock(&sc->state_mtx);
+	/* avoid deadlock by unregistering reboot notifier first */
+	unregister_reboot_notifier(&sc->reboot_nb);
+	if (sc->state == SCMI_SYSPOWER_IN_PROGRESS)
+		scmi_request_forceful_transition(sc);
+	mutex_unlock(&sc->state_mtx);
+}
+
+/**
+ * scmi_request_graceful_transition  - Request graceful SystemPower transition
+ * @sc: A reference to the configuration data
+ * @timeout_ms: The desired timeout to wait for the shutdown to complete before
+ *		system is forcibly shutdown.
+ *
+ * Initiates the required SystemPower transition, requesting userspace
+ * co-operation: it uses the same orderly_ methods used by ACPI Shutdown event
+ * processing.
+ *
+ * Takes care also to register a reboot notifier and to schedule a delayed work
+ * in order to detect if userspace actions are taking too long and in such a
+ * case to trigger a forceful transition.
+ */
+static void scmi_request_graceful_transition(struct scmi_syspower_conf *sc,
+					     unsigned int timeout_ms)
+{
+	unsigned int adj_timeout_ms = 0;
+
+	if (timeout_ms) {
+		int ret;
+
+		sc->reboot_nb.notifier_call = &scmi_reboot_notifier;
+		ret = register_reboot_notifier(&sc->reboot_nb);
+		if (!ret) {
+			/* Wait only up to 75% of the advertised timeout */
+			adj_timeout_ms = mult_frac(timeout_ms, 3, 4);
+			INIT_DELAYED_WORK(&sc->forceful_work,
+					  scmi_forceful_work_func);
+			schedule_delayed_work(&sc->forceful_work,
+					      msecs_to_jiffies(adj_timeout_ms));
+		} else {
+			/* Carry on best effort even without a reboot notifier */
+			dev_warn(sc->dev,
+				 "Cannot register reboot notifier !\n");
+		}
+	}
+
+	dev_dbg(sc->dev,
+		"Serving graceful req:%d (timeout_ms:%u  adj_timeout_ms:%u)\n",
+		sc->required_transition, timeout_ms, adj_timeout_ms);
+
+	switch (sc->required_transition) {
+	case SCMI_SYSTEM_SHUTDOWN:
+		/*
+		 * When triggered early at boot-time the 'orderly' call will
+		 * partially fail due to the lack of userspace itself, but
+		 * the force=true argument will start anyway a successful
+		 * forced shutdown.
+		 */
+		orderly_poweroff(true);
+		break;
+	case SCMI_SYSTEM_COLDRESET:
+	case SCMI_SYSTEM_WARMRESET:
+		orderly_reboot();
+		break;
+	default:
+		break;
+	}
+}
+
+/**
+ * scmi_userspace_notifier  - Notifier callback to act on SystemPower
+ * Notifications
+ * @nb: Reference to the related notifier block
+ * @event: The SystemPower notification event id
+ * @data: The SystemPower event report
+ *
+ * This callback is in charge of decoding the received SystemPower report
+ * and act accordingly triggering a graceful or forceful system transition.
+ *
+ * Note that once a valid SCMI SystemPower event starts being served, any
+ * other following SystemPower notification received from the same SCMI
+ * instance (handle) will be ignored.
+ *
+ * Return: NOTIFY_OK once a valid SystemPower event has been successfully
+ * processed.
+ */
+static int scmi_userspace_notifier(struct notifier_block *nb,
+				   unsigned long event, void *data)
+{
+	struct scmi_system_power_state_notifier_report *er = data;
+	struct scmi_syspower_conf *sc = userspace_nb_to_sconf(nb);
+
+	if (er->system_state >= SCMI_SYSTEM_POWERUP) {
+		dev_err(sc->dev, "Ignoring unsupported system_state: 0x%X\n",
+			er->system_state);
+		return NOTIFY_DONE;
+	}
+
+	if (!SCMI_SYSPOWER_IS_REQUEST_GRACEFUL(er->flags)) {
+		dev_err(sc->dev, "Ignoring forceful notification.\n");
+		return NOTIFY_DONE;
+	}
+
+	/*
+	 * Bail out if system is already shutting down or an SCMI SystemPower
+	 * requested is already being served.
+	 */
+	if (system_state > SYSTEM_RUNNING)
+		return NOTIFY_DONE;
+	mutex_lock(&sc->state_mtx);
+	if (sc->state != SCMI_SYSPOWER_IDLE) {
+		dev_dbg(sc->dev,
+			"Transition already in progress...ignore.\n");
+		mutex_unlock(&sc->state_mtx);
+		return NOTIFY_DONE;
+	}
+	sc->state = SCMI_SYSPOWER_IN_PROGRESS;
+	mutex_unlock(&sc->state_mtx);
+
+	sc->required_transition = er->system_state;
+
+	/* Leaving a trace in logs of who triggered the shutdown/reboot. */
+	dev_info(sc->dev, "Serving shutdown/reboot request: %d\n",
+		 sc->required_transition);
+
+	scmi_request_graceful_transition(sc, er->timeout);
+
+	return NOTIFY_OK;
+}
+
+static int scmi_syspower_probe(struct scmi_device *sdev)
+{
+	int ret;
+	struct scmi_syspower_conf *sc;
+	struct scmi_handle *handle = sdev->handle;
+
+	if (!handle)
+		return -ENODEV;
+
+	ret = handle->devm_protocol_acquire(sdev, SCMI_PROTOCOL_SYSTEM);
+	if (ret)
+		return ret;
+
+	sc = devm_kzalloc(&sdev->dev, sizeof(*sc), GFP_KERNEL);
+	if (!sc)
+		return -ENOMEM;
+
+	sc->state = SCMI_SYSPOWER_IDLE;
+	mutex_init(&sc->state_mtx);
+	sc->required_transition = SCMI_SYSTEM_MAX;
+	sc->userspace_nb.notifier_call = &scmi_userspace_notifier;
+	sc->dev = &sdev->dev;
+
+	return handle->notify_ops->devm_event_notifier_register(sdev,
+							   SCMI_PROTOCOL_SYSTEM,
+					 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER,
+						       NULL, &sc->userspace_nb);
+}
+
+static const struct scmi_device_id scmi_id_table[] = {
+	{ SCMI_PROTOCOL_SYSTEM, "syspower" },
+	{ },
+};
+MODULE_DEVICE_TABLE(scmi, scmi_id_table);
+
+static struct scmi_driver scmi_system_power_driver = {
+	.name = "scmi-system-power",
+	.probe = scmi_syspower_probe,
+	.id_table = scmi_id_table,
+};
+module_scmi_driver(scmi_system_power_driver);
+
+MODULE_AUTHOR("Cristian Marussi <cristian.marussi@arm.com>");
+MODULE_DESCRIPTION("ARM SCMI SystemPower Control driver");
+MODULE_LICENSE("GPL");
-- 
2.32.0


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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 5/5] firmware: arm_scmi: Add SCMI System Power Control driver
  2022-06-23 12:47 ` [PATCH 5/5] firmware: arm_scmi: Add SCMI System Power Control driver Cristian Marussi
@ 2022-06-27 13:54   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 12+ messages in thread
From: Greg Kroah-Hartman @ 2022-06-27 13:54 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: linux-kernel, linux-arm-kernel, sudeep.holla, vincent.guittot,
	f.fainelli

On Thu, Jun 23, 2022 at 01:47:42PM +0100, Cristian Marussi wrote:
> Add an SCMI System Power control driver to handle platform's requests
> carried by SYSTEM_POWER_STATE_NOTIFIER notifications: such platform
> requested system-wide power state transitions are handled accordingly,
> gracefully or forcefully, depending on the notifications' message flags.
> 
> Graceful requests are relayed to userspace using the same Kernel API used
> to handle ACPI Shutdown bus events.
> 
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device
  2022-06-23 12:47 ` [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device Cristian Marussi
@ 2022-07-01 13:45   ` Sudeep Holla
  2022-07-01 14:31     ` Cristian Marussi
  0 siblings, 1 reply; 12+ messages in thread
From: Sudeep Holla @ 2022-07-01 13:45 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: linux-kernel, linux-arm-kernel, vincent.guittot, f.fainelli,
	Sudeep Holla

On Thu, Jun 23, 2022 at 01:47:39PM +0100, Cristian Marussi wrote:
> In order to minimize SCMI platform fw-side complexity, only one single SCMI
> 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 | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
> index a7cbf4d09081..476855d3dccb 100644
> --- a/drivers/firmware/arm_scmi/bus.c
> +++ b/drivers/firmware/arm_scmi/bus.c
> @@ -19,6 +19,11 @@ static DEFINE_IDA(scmi_bus_id);
>  static DEFINE_IDR(scmi_protocols);
>  static DEFINE_SPINLOCK(protocol_lock);
>  
> +/* Track globally the creation of SCMI SystemPower related devices */
> +static bool scmi_syspower_registered;
> +/* Protect access to scmi_syspower_registered */
> +static DEFINE_MUTEX(scmi_syspower_mtx);
> +

Since we create device from the driver, can't we do this from there
and keep the bus code free from handling all these special conditions
which are checked for each device creation.

Yes scmi_device_create can be called outside the exiting code but since it
is not exported(yet), we can assume all users are in kernel and we can
catch that if anyone attempts to add. And probably we don't need the lock
as well if it is taken care in the single loop creating the device.

-- 
Regards,
Sudeep

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls
  2022-06-23 12:47 ` [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls Cristian Marussi
@ 2022-07-01 13:46   ` Sudeep Holla
  0 siblings, 0 replies; 12+ messages in thread
From: Sudeep Holla @ 2022-07-01 13:46 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: linux-kernel, linux-arm-kernel, vincent.guittot, f.fainelli,
	Sudeep Holla

On Thu, Jun 23, 2022 at 01:47:38PM +0100, Cristian Marussi wrote:
> Remove deprecated calls to ida_simple_get/ida_simple_remove.
> 
 
As you are aware, similar patch is already merged [1].

-- 
Regards,
Sudeep

[1] https://git.kernel.org/sudeep.holla/c/4ce7e51dc7

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/5] Introduce SCMI System Power Control driver
  2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
                   ` (4 preceding siblings ...)
  2022-06-23 12:47 ` [PATCH 5/5] firmware: arm_scmi: Add SCMI System Power Control driver Cristian Marussi
@ 2022-07-01 13:49 ` Sudeep Holla
  5 siblings, 0 replies; 12+ messages in thread
From: Sudeep Holla @ 2022-07-01 13:49 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: linux-kernel, linux-arm-kernel, vincent.guittot, f.fainelli,
	Sudeep Holla

On Thu, Jun 23, 2022 at 01:47:37PM +0100, Cristian Marussi wrote:
> Hi,
> 
> This series is a respin of an old series[0] parked for a while waiting for
> a required SCMI specification change to be published.
> 
> The series, building on top of the SCMI System Power Protocol, adds a new 
> SCMI driver which, registering for SystemPower notifications, takes care to
> satisfy SCMI plaform system-transitions graceful requests like shutdown or
> reboot involving userspace interactions as needed.
> 
> Interaction with userspace boils down to the same orderly_ Kernel methods
> used by ACPI to handle similar shutdown requests.
> 
> The latest SCMI v3.1 specification [1], which adds a new timeout field to
> the graceful notifications payload, let the platform advertise for how long
> it will possibly wait for the requested system state transition to happen
> before forcibly enforcing it.
> 
> As a part of the series, patch 2/3 enforces, at the SCMI core level, the
> creation of one single SCMI SystemPower device, to avoid promoting the
> design of systems in which multiple SCMI platforms can advertise the
> concurrent support of SystemPower protocol: when multiple SCMI platform
> are defined, only one of them should be in charge of SystemPower comms
> with the OSPM, so only one such SystemPower device across all platforms
> is allowed to be created.
> 

Other than the comment in 2/5, I am happy with the other changes.

-- 
Regards,
Sudeep

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device
  2022-07-01 13:45   ` Sudeep Holla
@ 2022-07-01 14:31     ` Cristian Marussi
  2022-07-01 15:00       ` Sudeep Holla
  0 siblings, 1 reply; 12+ messages in thread
From: Cristian Marussi @ 2022-07-01 14:31 UTC (permalink / raw)
  To: Sudeep Holla; +Cc: linux-kernel, linux-arm-kernel, vincent.guittot, f.fainelli

On Fri, Jul 01, 2022 at 02:45:09PM +0100, Sudeep Holla wrote:
> On Thu, Jun 23, 2022 at 01:47:39PM +0100, Cristian Marussi wrote:
> > In order to minimize SCMI platform fw-side complexity, only one single SCMI
> > 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 | 31 ++++++++++++++++++++++++++++++-
> >  1 file changed, 30 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
> > index a7cbf4d09081..476855d3dccb 100644
> > --- a/drivers/firmware/arm_scmi/bus.c
> > +++ b/drivers/firmware/arm_scmi/bus.c
> > @@ -19,6 +19,11 @@ static DEFINE_IDA(scmi_bus_id);
> >  static DEFINE_IDR(scmi_protocols);
> >  static DEFINE_SPINLOCK(protocol_lock);
> >  
> > +/* Track globally the creation of SCMI SystemPower related devices */
> > +static bool scmi_syspower_registered;
> > +/* Protect access to scmi_syspower_registered */
> > +static DEFINE_MUTEX(scmi_syspower_mtx);
> > +
> 

Hi Sudeep,

thanks for the review first of all.

> Since we create device from the driver, can't we do this from there
> and keep the bus code free from handling all these special conditions
> which are checked for each device creation.
> 
> Yes scmi_device_create can be called outside the exiting code but since it
> is not exported(yet), we can assume all users are in kernel and we can
> catch that if anyone attempts to add. And probably we don't need the lock
> as well if it is taken care in the single loop creating the device.
> 

Do you mean to move the check inside driver.c common routines like in
scmi_get_protocol_device() right before calling scmi_device_create() ?

If this is what you meant, yes I can do that to avoid polluting the
bus code...indeed it would be easier than dealing with all the internals
in scmi_device_create() like it is now, BUT regarding the mutex I'm not so
sure I can avoid it since the device creation is triggered at the end of
main platform probe (driver:scmi_probe()) BUT potentially also whenever a
new SCMI driver is (lately) loaded and asks for the device creation after
(or worst concurrently to) the main probe loop.

Beside that, there is the case of definitions of multiple SCMI platforms,
which is not officially supported I know but that is, in my understanding,
one of the most possible cause of having multiple instances of an SCMI
SystemPower driver trying to register. (i.e. multiple scmi DT nodes ALL
defining a SystemPower protocol with potentially multiple underlying FWs
advertising SystemPower support which was the thing we wanted to avoid
promoting ... AFAIU...but I could be missing something..)

Thanks,
Cristian


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device
  2022-07-01 14:31     ` Cristian Marussi
@ 2022-07-01 15:00       ` Sudeep Holla
  0 siblings, 0 replies; 12+ messages in thread
From: Sudeep Holla @ 2022-07-01 15:00 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: linux-kernel, linux-arm-kernel, vincent.guittot, f.fainelli,
	Sudeep Holla

On Fri, Jul 01, 2022 at 03:31:18PM +0100, Cristian Marussi wrote:
> On Fri, Jul 01, 2022 at 02:45:09PM +0100, Sudeep Holla wrote:
> > On Thu, Jun 23, 2022 at 01:47:39PM +0100, Cristian Marussi wrote:
> > > In order to minimize SCMI platform fw-side complexity, only one single SCMI
> > > 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 | 31 ++++++++++++++++++++++++++++++-
> > >  1 file changed, 30 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
> > > index a7cbf4d09081..476855d3dccb 100644
> > > --- a/drivers/firmware/arm_scmi/bus.c
> > > +++ b/drivers/firmware/arm_scmi/bus.c
> > > @@ -19,6 +19,11 @@ static DEFINE_IDA(scmi_bus_id);
> > >  static DEFINE_IDR(scmi_protocols);
> > >  static DEFINE_SPINLOCK(protocol_lock);
> > >  
> > > +/* Track globally the creation of SCMI SystemPower related devices */
> > > +static bool scmi_syspower_registered;
> > > +/* Protect access to scmi_syspower_registered */
> > > +static DEFINE_MUTEX(scmi_syspower_mtx);
> > > +
> > 
> 
> Hi Sudeep,
> 
> thanks for the review first of all.
> 
> > Since we create device from the driver, can't we do this from there
> > and keep the bus code free from handling all these special conditions
> > which are checked for each device creation.
> > 
> > Yes scmi_device_create can be called outside the exiting code but since it
> > is not exported(yet), we can assume all users are in kernel and we can
> > catch that if anyone attempts to add. And probably we don't need the lock
> > as well if it is taken care in the single loop creating the device.
> > 
> 
> Do you mean to move the check inside driver.c common routines like in
> scmi_get_protocol_device() right before calling scmi_device_create() ?
> 
> If this is what you meant, yes I can do that to avoid polluting the
> bus code...indeed it would be easier than dealing with all the internals
> in scmi_device_create() like it is now, BUT regarding the mutex I'm not so
> sure I can avoid it since the device creation is triggered at the end of
> main platform probe (driver:scmi_probe()) BUT potentially also whenever a
> new SCMI driver is (lately) loaded and asks for the device creation after
> (or worst concurrently to) the main probe loop.
>

You got it right, I meant exactly that.

Agreed and that's why I mentioned we don't export that and hence it is not
possible. I don't want to make bus code complex checking for this. We may
have to do that if that is the only way in the future, but let us defer
until we have to.

> Beside that, there is the case of definitions of multiple SCMI platforms,
> which is not officially supported I know but that is, in my understanding,
> one of the most possible cause of having multiple instances of an SCMI
> SystemPower driver trying to register. (i.e. multiple scmi DT nodes ALL
> defining a SystemPower protocol with potentially multiple underlying FWs
> advertising SystemPower support which was the thing we wanted to avoid
> promoting ... AFAIU...but I could be missing something..)
>

Agreed, I am not questioning the addition of this change, just how and where
:).

-- 
Regards,
Sudeep

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-07-01 15:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 12:47 [PATCH 0/5] Introduce SCMI System Power Control driver Cristian Marussi
2022-06-23 12:47 ` [PATCH 1/5] firmware: arm_scmi: Remove deprecated ida_simple_ calls Cristian Marussi
2022-07-01 13:46   ` Sudeep Holla
2022-06-23 12:47 ` [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device Cristian Marussi
2022-07-01 13:45   ` Sudeep Holla
2022-07-01 14:31     ` Cristian Marussi
2022-07-01 15:00       ` Sudeep Holla
2022-06-23 12:47 ` [PATCH 3/5] firmware: arm_scmi: Add SCMIv3.1 SystemPower extensions Cristian Marussi
2022-06-23 12:47 ` [PATCH 4/5] firmware: arm_scmi: Add devm_protocol_acquire helper Cristian Marussi
2022-06-23 12:47 ` [PATCH 5/5] firmware: arm_scmi: Add SCMI System Power Control driver Cristian Marussi
2022-06-27 13:54   ` Greg Kroah-Hartman
2022-07-01 13:49 ` [PATCH 0/5] Introduce " Sudeep Holla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).