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,
f.fainelli@gmail.com, etienne.carriere@linaro.org,
vincent.guittot@linaro.org, Ludvig.Parsson@axis.com,
cristian.marussi@arm.com
Subject: [PATCH 8/9] firmware: arm_scmi: Introduce a new lifecycle for protocol devices
Date: Thu, 22 Dec 2022 18:50:48 +0000 [thread overview]
Message-ID: <20221222185049.737625-9-cristian.marussi@arm.com> (raw)
In-Reply-To: <20221222185049.737625-1-cristian.marussi@arm.com>
Protocol devices are created or destroyed depending on the related device
request/unrequest events emitted on the scmi_requested_devices_nh
notification chain by the SCMI bus and served in the driver by the
scmi_device_request_notifier.
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/firmware/arm_scmi/driver.c | 45 ++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 83a43a5f7bb4..115baaa4aca9 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -14,6 +14,8 @@
* Copyright (C) 2018-2021 ARM Ltd.
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <linux/bitmap.h>
#include <linux/device.h>
#include <linux/export.h>
@@ -140,6 +142,7 @@ struct scmi_protocol_instance {
* @bus_nb: A notifier to listen for device bind/unbind on the scmi bus
* @dev_req_nb: A notifier to listen for device request/unrequest on the scmi
* bus
+ * @devreq_mtx: A mutex to serialize device creation for this SCMI instance
*/
struct scmi_info {
struct device *dev;
@@ -161,6 +164,8 @@ struct scmi_info {
int users;
struct notifier_block bus_nb;
struct notifier_block dev_req_nb;
+ /* Serialize device creation process for this instance */
+ struct mutex devreq_mtx;
};
#define handle_to_scmi_info(h) container_of(h, struct scmi_info, handle)
@@ -255,6 +260,40 @@ void scmi_protocol_unregister(const struct scmi_protocol *proto)
}
EXPORT_SYMBOL_GPL(scmi_protocol_unregister);
+/**
+ * scmi_create_protocol_devices - Create devices for all pending requests for
+ * this SCMI instance.
+ *
+ * @np: The device node describing the protocol
+ * @info: The SCMI instance descriptor
+ * @prot_id: The protocol ID
+ * @name: The optional name of the device to be created: if not provided this
+ * call will lead to the creation of all the devices currently requested
+ * for the specified protocol.
+ */
+static void scmi_create_protocol_devices(struct device_node *np,
+ struct scmi_info *info,
+ int prot_id, const char *name)
+{
+ struct scmi_device *sdev;
+
+ mutex_lock(&info->devreq_mtx);
+ sdev = scmi_device_create(np, info->dev, prot_id, name);
+ if (name && !sdev)
+ dev_err(info->dev,
+ "failed to create device for protocol 0x%X (%s)\n",
+ prot_id, name);
+ mutex_unlock(&info->devreq_mtx);
+}
+
+static void scmi_destroy_protocol_devices(struct scmi_info *info,
+ int prot_id, const char *name)
+{
+ mutex_lock(&info->devreq_mtx);
+ scmi_device_destroy(info->dev, prot_id, name);
+ mutex_unlock(&info->devreq_mtx);
+}
+
void scmi_notification_instance_data_set(const struct scmi_handle *handle,
void *priv)
{
@@ -2283,8 +2322,12 @@ static int scmi_device_request_notifier(struct notifier_block *nb,
switch (action) {
case SCMI_BUS_NOTIFY_DEVICE_REQUEST:
+ scmi_create_protocol_devices(np, info, id_table->protocol_id,
+ id_table->name);
break;
case SCMI_BUS_NOTIFY_DEVICE_UNREQUEST:
+ scmi_destroy_protocol_devices(info, id_table->protocol_id,
+ id_table->name);
break;
default:
return NOTIFY_DONE;
@@ -2318,6 +2361,7 @@ static int scmi_probe(struct platform_device *pdev)
idr_init(&info->protocols);
mutex_init(&info->protocols_mtx);
idr_init(&info->active_protocols);
+ mutex_init(&info->devreq_mtx);
platform_set_drvdata(pdev, info);
idr_init(&info->tx_idr);
@@ -2412,6 +2456,7 @@ static int scmi_probe(struct platform_device *pdev)
}
of_node_get(child);
+ scmi_create_protocol_devices(child, info, prot_id, NULL);
}
return 0;
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-12-22 18:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 18:50 [PATCH 0/9] Rework SCMI initialization and probing sequence Cristian Marussi
2022-12-22 18:50 ` [PATCH 1/9] firmware: arm_scmi: Simplify chan_available transport operation Cristian Marussi
2022-12-22 18:50 ` [PATCH 2/9] firmware: arm_scmi: Use dedicated devices to initialize channels Cristian Marussi
2022-12-22 18:50 ` [PATCH 3/9] firmware: arm_scmi: Move protocol registration helpers Cristian Marussi
2022-12-22 18:50 ` [PATCH 4/9] firmware: arm_scmi: Add common notifier helpers Cristian Marussi
2022-12-22 18:50 ` [PATCH 5/9] firmware: arm_scmi: Refactor protocol device creation Cristian Marussi
2022-12-22 18:50 ` [PATCH 6/9] firmware: arm_scmi: Move handle get/set helpers Cristian Marussi
2022-12-22 18:50 ` [PATCH 7/9] firmware: arm_scmi: Refactor device create/destroy helpers Cristian Marussi
2022-12-22 18:50 ` Cristian Marussi [this message]
2022-12-22 18:50 ` [PATCH 9/9] firmware: arm_scmi: Split bus and driver into distinct modules Cristian Marussi
2022-12-23 5:36 ` [PATCH 0/9] Rework SCMI initialization and probing sequence Sumit Garg
2022-12-23 11:37 ` Cristian Marussi
2022-12-26 13:54 ` Sumit Garg
2023-01-19 19:31 ` Sudeep Holla
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=20221222185049.737625-9-cristian.marussi@arm.com \
--to=cristian.marussi@arm.com \
--cc=Ludvig.Parsson@axis.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=sudeep.holla@arm.com \
--cc=vincent.guittot@linaro.org \
/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