All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/14] SCMI multi-channel and optee shm
@ 2022-05-31 16:09 Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages Etienne Carriere
                   ` (13 more replies)
  0 siblings, 14 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Dear all,

This series implements 2 features in driver/firmware/scmi.

First, a single change adds support for SCMI OP-TEE transport to
use OP-TEE native shared memory. See the 1st patch in this series:
"firmware: scmi: optee: use TEE shared memory for SCMI messages".

Then come changes for supporting multi-channel in the SCMI drivers.
I've split the implementation in 11 several small incremental changes
in the hope it helps the review. Few minor fixup commits are also
inserted in the series. 

Changes since v1:
- Update scmi_clk.c, scmi_reset.c and scmi_regulator.c to store
  SCMI channel reference in private data rather than using private
  data reference as an opaque reference to the target SCMI channel.

Etienne Carriere (14):
  firmware: scmi: optee: use TEE shared memory for SCMI messages
  firmware: scmi: optee: fix inline description of
    PTA_SCMI_CMD_GET_CHANNEL
  firmware: scmi: prepare scmi uclass API to multi-channel
  firmware: scmi: prepare uclass to pass channel reference
  firmware: scmi: factorize scmi transport look up
  firmware: scmi: add multi-channel support
  firmware: scmi: mailbox transport: implement multi-channel
  firmware: scmi: smccc transport: implement multi-channel
  firmware: scmi: optee transport: implement multi-channel
  clk: scmi: support SCMI multi-channel
  reset: scmi: support SCMI multi-channel
  power: regulator: scmi: support SCMI multi-channel
  power: regulator: scmi: simplify scmi_voltd_set_enable()
  firmware: scmi: use multi channel in mailbox, optee and smccc agents

 drivers/clk/clk_scmi.c                     |  33 ++++-
 drivers/firmware/scmi/mailbox_agent.c      |  65 +++++++--
 drivers/firmware/scmi/optee_agent.c        | 147 ++++++++++++++++-----
 drivers/firmware/scmi/sandbox-scmi_agent.c |   1 +
 drivers/firmware/scmi/scmi_agent-uclass.c  |  48 +++++--
 drivers/firmware/scmi/smccc_agent.c        |  56 +++++++-
 drivers/firmware/scmi/smt.c                |  53 +++++++-
 drivers/firmware/scmi/smt.h                |  45 ++++++-
 drivers/power/regulator/scmi_regulator.c   |  36 +++--
 drivers/reset/reset-scmi.c                 |  25 +++-
 include/scmi_agent-uclass.h                |  15 ++-
 include/scmi_agent.h                       |  14 +-
 12 files changed, 458 insertions(+), 80 deletions(-)

-- 
2.25.1


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

* [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-06-23 18:32   ` Tom Rini
  2022-05-31 16:09 ` [PATCH v2 02/14] firmware: scmi: optee: fix inline description of PTA_SCMI_CMD_GET_CHANNEL Etienne Carriere
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Changes implementation when using TEE dynamically allocated shared
memory to synchronize with the Linux implementation where the legacy
SMT protocol cannot be used with such memory since it is expected from
device mapped memory whereas OP-TEE shared memory is cached and
hence should not be accessed using memcpy_toio()/memcpy_fromio().

This change implements the MSG shared memory protocol introduced
in Linux [1]. The protocol uses a simplified SMT header of 32bit
named MSG_SMT to carry SCMI protocol information and uses side channel
means to carry exchanged buffer size information, as TEE invocation API
parameters when used in the SCMI OP-TEE transport.

Link: [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f301bba0ca7392d16a6ea4f1d264a91f1fadea1a
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/optee_agent.c | 68 ++++++++++++++++++++++-------
 drivers/firmware/scmi/smt.c         | 53 +++++++++++++++++++++-
 drivers/firmware/scmi/smt.h         | 45 ++++++++++++++++++-
 3 files changed, 149 insertions(+), 17 deletions(-)

diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c
index 1f265922343..e76f738bbaf 100644
--- a/drivers/firmware/scmi/optee_agent.c
+++ b/drivers/firmware/scmi/optee_agent.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2020-2021 Linaro Limited.
+ * Copyright (C) 2020-2022 Linaro Limited.
  */
 
 #define LOG_CATEGORY UCLASS_SCMI_AGENT
@@ -98,6 +98,22 @@ enum optee_smci_pta_cmd {
 	 * [in]     value[0].b: Requested capabilities mask (enum pta_scmi_caps)
 	 */
 	PTA_SCMI_CMD_GET_CHANNEL = 3,
+
+	/*
+	 * PTA_SCMI_CMD_PROCESS_MSG_CHANNEL - Process SCMI message in MSG
+	 * buffers pointed by memref parameters
+	 *
+	 * [in]     value[0].a: Channel handle
+	 * [in]     memref[1]: Message buffer (MSG header and SCMI payload)
+	 * [out]    memref[2]: Response buffer (MSG header and SCMI payload)
+	 *
+	 * Shared memories used for SCMI message/response are MSG buffers
+	 * referenced by param[1] and param[2]. MSG transport protocol
+	 * uses a 32bit header to carry SCMI meta-data (protocol ID and
+	 * protocol message ID) followed by the effective SCMI message
+	 * payload.
+	 */
+	PTA_SCMI_CMD_PROCESS_MSG_CHANNEL = 4,
 };
 
 /*
@@ -106,9 +122,17 @@ enum optee_smci_pta_cmd {
  * PTA_SCMI_CAPS_SMT_HEADER
  * When set, OP-TEE supports command using SMT header protocol (SCMI shmem) in
  * shared memory buffers to carry SCMI protocol synchronisation information.
+ *
+ * PTA_SCMI_CAPS_MSG_HEADER
+ * When set, OP-TEE supports command using MSG header protocol in an OP-TEE
+ * shared memory to carry SCMI protocol synchronisation information and SCMI
+ * message payload.
  */
 #define PTA_SCMI_CAPS_NONE		0
 #define PTA_SCMI_CAPS_SMT_HEADER	BIT(0)
+#define PTA_SCMI_CAPS_MSG_HEADER	BIT(1)
+#define PTA_SCMI_CAPS_MASK		(PTA_SCMI_CAPS_SMT_HEADER | \
+					 PTA_SCMI_CAPS_MSG_HEADER)
 
 static int open_channel(struct udevice *dev, struct channel_session *sess)
 {
@@ -139,7 +163,10 @@ static int open_channel(struct udevice *dev, struct channel_session *sess)
 
 	param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INOUT;
 	param[0].u.value.a = chan->channel_id;
-	param[0].u.value.b = PTA_SCMI_CAPS_SMT_HEADER;
+	if (chan->dyn_shm)
+		param[0].u.value.b = PTA_SCMI_CAPS_MSG_HEADER;
+	else
+		param[0].u.value.b = PTA_SCMI_CAPS_SMT_HEADER;
 
 	ret = tee_invoke_func(sess->tee, &cmd_arg, ARRAY_SIZE(param), param);
 	if (ret || cmd_arg.ret) {
@@ -167,34 +194,48 @@ static int invoke_cmd(struct udevice *dev, struct channel_session *sess,
 {
 	struct scmi_optee_channel *chan = dev_get_plat(dev);
 	struct tee_invoke_arg arg = { };
-	struct tee_param param[2] = { };
+	struct tee_param param[3] = { };
 	int ret;
 
-	scmi_write_msg_to_smt(dev, &chan->smt, msg);
-
 	arg.session = sess->tee_session;
 	param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
 	param[0].u.value.a = sess->channel_hdl;
 
-	if (chan->dyn_shm) {
-		arg.func = PTA_SCMI_CMD_PROCESS_SMT_CHANNEL_MESSAGE;
-		param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT;
+	if (sess->tee_shm) {
+		size_t in_size;
+
+		ret = scmi_msg_to_smt_msg(dev, &chan->smt, msg, &in_size);
+		if (ret < 0)
+			return ret;
+
+		arg.func = PTA_SCMI_CMD_PROCESS_MSG_CHANNEL;
+		param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT;
 		param[1].u.memref.shm = sess->tee_shm;
-		param[1].u.memref.size = SCMI_SHM_SIZE;
+		param[1].u.memref.size = in_size;
+		param[2].attr = TEE_PARAM_ATTR_TYPE_MEMREF_OUTPUT;
+		param[2].u.memref.shm = sess->tee_shm;
+		param[2].u.memref.size = sess->tee_shm->size;
 	} else {
 		arg.func = PTA_SCMI_CMD_PROCESS_SMT_CHANNEL;
+		scmi_write_msg_to_smt(dev, &chan->smt, msg);
 	}
 
 	ret = tee_invoke_func(sess->tee, &arg, ARRAY_SIZE(param), param);
 	if (ret || arg.ret) {
 		if (!ret)
 			ret = -EPROTO;
+
+		return ret;
+	}
+
+	if (sess->tee_shm) {
+		ret = scmi_msg_from_smt_msg(dev, &chan->smt, msg,
+					    param[2].u.memref.size);
 	} else {
 		ret = scmi_read_resp_from_smt(dev, &chan->smt, msg);
+		scmi_clear_smt_channel(&chan->smt);
 	}
 
-	scmi_clear_smt_channel(&chan->smt);
-
 	return ret;
 }
 
@@ -217,9 +258,6 @@ static int prepare_shm(struct udevice *dev, struct channel_session *sess)
 
 	chan->smt.buf = sess->tee_shm->addr;
 
-	/* Initialize shm buffer for message exchanges */
-	scmi_clear_smt_channel(&chan->smt);
-
 	return 0;
 }
 
@@ -233,7 +271,7 @@ static void release_shm(struct udevice *dev, struct channel_session *sess)
 
 static int scmi_optee_process_msg(struct udevice *dev, struct scmi_msg *msg)
 {
-	struct channel_session sess;
+	struct channel_session sess = { };
 	int ret;
 
 	ret = open_channel(dev, &sess);
diff --git a/drivers/firmware/scmi/smt.c b/drivers/firmware/scmi/smt.c
index e60c2aebc89..509ed618a99 100644
--- a/drivers/firmware/scmi/smt.c
+++ b/drivers/firmware/scmi/smt.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
- * Copyright (C) 2019-2020 Linaro Limited.
+ * Copyright (C) 2019-2022 Linaro Limited.
  */
 
 #define LOG_CATEGORY UCLASS_SCMI_AGENT
@@ -137,3 +137,54 @@ void scmi_clear_smt_channel(struct scmi_smt *smt)
 
 	hdr->channel_status &= ~SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR;
 }
+
+/**
+ * Write SCMI message @msg into a SMT_MSG shared buffer @smt.
+ * Return 0 on success and with a negative errno in case of error.
+ */
+int scmi_msg_to_smt_msg(struct udevice *dev, struct scmi_smt *smt,
+			struct scmi_msg *msg, size_t *buf_size)
+{
+	struct scmi_smt_msg_header *hdr = (void *)smt->buf;
+
+	if ((!msg->in_msg && msg->in_msg_sz) ||
+	    (!msg->out_msg && msg->out_msg_sz))
+		return -EINVAL;
+
+	if (smt->size < (sizeof(*hdr) + msg->in_msg_sz) ||
+	    smt->size < (sizeof(*hdr) + msg->out_msg_sz)) {
+		dev_dbg(dev, "Buffer too small\n");
+		return -ETOOSMALL;
+	}
+
+	*buf_size = msg->in_msg_sz + sizeof(hdr->msg_header);
+
+	hdr->msg_header = SMT_HEADER_TOKEN(0) |
+			  SMT_HEADER_MESSAGE_TYPE(0) |
+			  SMT_HEADER_PROTOCOL_ID(msg->protocol_id) |
+			  SMT_HEADER_MESSAGE_ID(msg->message_id);
+
+	memcpy(hdr->msg_payload, msg->in_msg, msg->in_msg_sz);
+
+	return 0;
+}
+
+/**
+ * Read SCMI message from a SMT shared buffer @smt and copy it into @msg.
+ * Return 0 on success and with a negative errno in case of error.
+ */
+int scmi_msg_from_smt_msg(struct udevice *dev, struct scmi_smt *smt,
+			  struct scmi_msg *msg, size_t buf_size)
+{
+	struct scmi_smt_msg_header *hdr = (void *)smt->buf;
+
+	if (buf_size > msg->out_msg_sz + sizeof(hdr->msg_header)) {
+		dev_err(dev, "Buffer to small\n");
+		return -ETOOSMALL;
+	}
+
+	msg->out_msg_sz = buf_size - sizeof(hdr->msg_header);
+	memcpy(msg->out_msg, hdr->msg_payload, msg->out_msg_sz);
+
+	return 0;
+}
diff --git a/drivers/firmware/scmi/smt.h b/drivers/firmware/scmi/smt.h
index a8c0987bd30..9d669a6c922 100644
--- a/drivers/firmware/scmi/smt.h
+++ b/drivers/firmware/scmi/smt.h
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
- * Copyright (C) 2019-2020 Linaro Limited.
+ * Copyright (C) 2019-2022 Linaro Limited.
  */
 #ifndef SCMI_SMT_H
 #define SCMI_SMT_H
@@ -29,6 +29,17 @@ struct scmi_smt_header {
 	u8 msg_payload[0];
 };
 
+/**
+ * struct scmi_msg_header - Description of a MSG shared memory message buffer
+ *
+ * MSG communication protocol uses a 32bit header memory cell to store SCMI
+ * protocol data followed by the exchange SCMI message payload.
+ */
+struct scmi_smt_msg_header {
+	__le32 msg_header;
+	u8 msg_payload[0];
+};
+
 #define SMT_HEADER_TOKEN(token)		(((token) << 18) & GENMASK(31, 18))
 #define SMT_HEADER_PROTOCOL_ID(proto)	(((proto) << 10) & GENMASK(17, 10))
 #define SMT_HEADER_MESSAGE_TYPE(type)	(((type) << 18) & GENMASK(9, 8))
@@ -75,12 +86,44 @@ static inline void scmi_smt_put_channel(struct scmi_smt *smt)
 
 int scmi_dt_get_smt_buffer(struct udevice *dev, struct scmi_smt *smt);
 
+/*
+ * Write SCMI message to a SMT shared memory
+ * @dev: SCMI device
+ * @smt: Reference to shared memory using SMT header
+ * @msg: Input SCMI message transmitted
+ */
 int scmi_write_msg_to_smt(struct udevice *dev, struct scmi_smt *smt,
 			  struct scmi_msg *msg);
 
+/*
+ * Read SCMI message from a SMT shared memory
+ * @dev: SCMI device
+ * @smt: Reference to shared memory using SMT header
+ * @msg: Output SCMI message received
+ */
 int scmi_read_resp_from_smt(struct udevice *dev, struct scmi_smt *smt,
 			    struct scmi_msg *msg);
 
 void scmi_clear_smt_channel(struct scmi_smt *smt);
 
+/*
+ * Write SCMI message to SMT_MSG shared memory
+ * @dev: SCMI device
+ * @smt: Reference to shared memory using SMT_MSG header
+ * @msg: Input SCMI message transmitted
+ * @buf_size: Size of the full SMT_MSG buffer transmitted
+ */
+int scmi_msg_to_smt_msg(struct udevice *dev, struct scmi_smt *smt,
+			struct scmi_msg *msg, size_t *buf_size);
+
+/*
+ * Read SCMI message from SMT_MSG shared memory
+ * @dev: SCMI device
+ * @smt: Reference to shared memory using SMT_MSG header
+ * @msg: Output SCMI message received
+ * @buf_size: Size of the full SMT_MSG buffer received
+ */
+int scmi_msg_from_smt_msg(struct udevice *dev, struct scmi_smt *smt,
+			  struct scmi_msg *msg, size_t buf_size);
+
 #endif /* SCMI_SMT_H */
-- 
2.25.1


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

* [PATCH v2 02/14] firmware: scmi: optee: fix inline description of PTA_SCMI_CMD_GET_CHANNEL
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 03/14] firmware: scmi: prepare scmi uclass API to multi-channel Etienne Carriere
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Removes inaccurate inline description of OP-TEE SCMI PTA command
PTA_SCMI_CMD_GET_CHANNEL.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/optee_agent.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c
index e76f738bbaf..bf0647bafd1 100644
--- a/drivers/firmware/scmi/optee_agent.c
+++ b/drivers/firmware/scmi/optee_agent.c
@@ -91,8 +91,6 @@ enum optee_smci_pta_cmd {
 	/*
 	 * PTA_SCMI_CMD_GET_CHANNEL - Get channel handle
 	 *
-	 * SCMI shm information are 0 if agent expects to use OP-TEE regular SHM
-	 *
 	 * [in]     value[0].a: Channel identifier
 	 * [out]    value[0].a: Returned channel handle
 	 * [in]     value[0].b: Requested capabilities mask (enum pta_scmi_caps)
-- 
2.25.1


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

* [PATCH v2 03/14] firmware: scmi: prepare scmi uclass API to multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 02/14] firmware: scmi: optee: fix inline description of PTA_SCMI_CMD_GET_CHANNEL Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 04/14] firmware: scmi: prepare uclass to pass channel reference Etienne Carriere
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot
  Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere,
	Lukasz Majewski, Sean Anderson, Jaehoon Chung

Changes SCMI driver API function devm_scmi_process_msg() to add
an SCMI channel reference argument for when SCMI agent supports
SCMI protocol specific channels. First argument of devm_scmi_process_msg()
is also change to point to the caller SCMI protocol device rather
than its parent device (the SCMI agent device).

The argument is a pointer to opaque struct scmi_channel known from
the SCMI transport drivers. It is currently unused and caller a pass
NULL value. A later change will enable such support once SCMI protocol
drivers have means to get the channel reference during initialization.

Cc: Lukasz Majewski <lukma@denx.de>
Cc: Sean Anderson <seanga2@gmail.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/clk/clk_scmi.c                    | 10 +++++-----
 drivers/firmware/scmi/scmi_agent-uclass.c |  3 ++-
 drivers/power/regulator/scmi_regulator.c  | 10 +++++-----
 drivers/reset/reset-scmi.c                |  4 ++--
 include/scmi_agent-uclass.h               |  2 +-
 include/scmi_agent.h                      |  5 ++++-
 6 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index 5aaabcf0b44..0d0bb72eaf7 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -24,7 +24,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
 	};
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, &msg);
+	ret = devm_scmi_process_msg(dev, NULL, &msg);
 	if (ret)
 		return ret;
 
@@ -49,7 +49,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
 	};
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, &msg);
+	ret = devm_scmi_process_msg(dev, NULL, &msg);
 	if (ret)
 		return ret;
 
@@ -70,7 +70,7 @@ static int scmi_clk_gate(struct clk *clk, int enable)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(clk->dev, &msg);
+	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
 	if (ret)
 		return ret;
 
@@ -98,7 +98,7 @@ static ulong scmi_clk_get_rate(struct clk *clk)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(clk->dev, &msg);
+	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -123,7 +123,7 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(clk->dev, &msg);
+	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index 3819f2fa993..93cfc9c395b 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -114,7 +114,8 @@ static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev)
 	return (const struct scmi_agent_ops *)dev->driver->ops;
 }
 
-int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg)
+int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
+			  struct scmi_msg *msg)
 {
 	const struct scmi_agent_ops *ops;
 	struct udevice *parent = dev;
diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c
index 2966bdcf830..3325ddaf23b 100644
--- a/drivers/power/regulator/scmi_regulator.c
+++ b/drivers/power/regulator/scmi_regulator.c
@@ -38,7 +38,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, &msg);
+	ret = devm_scmi_process_msg(dev, NULL, &msg);
 	if (ret)
 		return ret;
 
@@ -61,7 +61,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, &msg);
+	ret = devm_scmi_process_msg(dev, NULL, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -85,7 +85,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, &msg);
+	ret = devm_scmi_process_msg(dev, NULL, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -104,7 +104,7 @@ static int scmi_voltd_get_voltage_level(struct udevice *dev)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, &msg);
+	ret = devm_scmi_process_msg(dev, NULL, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -147,7 +147,7 @@ static int scmi_regulator_probe(struct udevice *dev)
 	/* Check voltage domain is known from SCMI server */
 	in.domain_id = pdata->domain_id;
 
-	ret = devm_scmi_process_msg(dev, &scmi_msg);
+	ret = devm_scmi_process_msg(dev, NULL, &scmi_msg);
 	if (ret) {
 		dev_err(dev, "Failed to query voltage domain %u: %d\n",
 			pdata->domain_id, ret);
diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c
index 81d195a06a9..30b26ec9d31 100644
--- a/drivers/reset/reset-scmi.c
+++ b/drivers/reset/reset-scmi.c
@@ -26,7 +26,7 @@ static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(rst->dev, &msg);
+	ret = devm_scmi_process_msg(rst->dev, NULL, &msg);
 	if (ret)
 		return ret;
 
@@ -58,7 +58,7 @@ static int scmi_reset_request(struct reset_ctl *rst)
 	 * We don't really care about the attribute, just check
 	 * the reset domain exists.
 	 */
-	ret = devm_scmi_process_msg(rst->dev, &msg);
+	ret = devm_scmi_process_msg(rst->dev, NULL, &msg);
 	if (ret)
 		return ret;
 
diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h
index a501d1b4825..861ac6d1100 100644
--- a/include/scmi_agent-uclass.h
+++ b/include/scmi_agent-uclass.h
@@ -15,7 +15,7 @@ struct scmi_agent_ops {
 	/*
 	 * process_msg - Request transport to get the SCMI message processed
 	 *
-	 * @agent:		Agent using the transport
+	 * @dev:		SCMI protocol device using the transport
 	 * @msg:		SCMI message to be transmitted
 	 */
 	int (*process_msg)(struct udevice *dev, struct scmi_msg *msg);
diff --git a/include/scmi_agent.h b/include/scmi_agent.h
index 18bcd48a9d4..f4d85cae773 100644
--- a/include/scmi_agent.h
+++ b/include/scmi_agent.h
@@ -13,6 +13,7 @@
 #include <asm/types.h>
 
 struct udevice;
+struct scmi_channel;
 
 /*
  * struct scmi_msg - Context of a SCMI message sent and the response received
@@ -52,10 +53,12 @@ struct scmi_msg {
  * On return, scmi_msg::out_msg_sz stores the response payload size.
  *
  * @dev:	SCMI device
+ * @channel:	Communication channel for the device
  * @msg:	Message structure reference
  * Return: 0 on success and a negative errno on failure
  */
-int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg);
+int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
+			  struct scmi_msg *msg);
 
 /**
  * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code
-- 
2.25.1


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

* [PATCH v2 04/14] firmware: scmi: prepare uclass to pass channel reference
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (2 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 03/14] firmware: scmi: prepare scmi uclass API to multi-channel Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 05/14] firmware: scmi: factorize scmi transport look up Etienne Carriere
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Changes SCMI transport operator ::process_msg to pass the SCMI channel
reference provided by caller SCMI protocol device.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/mailbox_agent.c      | 4 +++-
 drivers/firmware/scmi/optee_agent.c        | 4 +++-
 drivers/firmware/scmi/sandbox-scmi_agent.c | 1 +
 drivers/firmware/scmi/scmi_agent-uclass.c  | 2 +-
 drivers/firmware/scmi/smccc_agent.c        | 4 +++-
 include/scmi_agent-uclass.h                | 4 +++-
 6 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/scmi/mailbox_agent.c b/drivers/firmware/scmi/mailbox_agent.c
index 8e4af0c8faf..aa4929aafae 100644
--- a/drivers/firmware/scmi/mailbox_agent.c
+++ b/drivers/firmware/scmi/mailbox_agent.c
@@ -31,7 +31,9 @@ struct scmi_mbox_channel {
 	ulong timeout_us;
 };
 
-static int scmi_mbox_process_msg(struct udevice *dev, struct scmi_msg *msg)
+static int scmi_mbox_process_msg(struct udevice *dev,
+				 struct scmi_channel *channel,
+				 struct scmi_msg *msg)
 {
 	struct scmi_mbox_channel *chan = dev_get_plat(dev);
 	int ret;
diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c
index bf0647bafd1..771fa25e989 100644
--- a/drivers/firmware/scmi/optee_agent.c
+++ b/drivers/firmware/scmi/optee_agent.c
@@ -267,7 +267,9 @@ static void release_shm(struct udevice *dev, struct channel_session *sess)
 		tee_shm_free(sess->tee_shm);
 }
 
-static int scmi_optee_process_msg(struct udevice *dev, struct scmi_msg *msg)
+static int scmi_optee_process_msg(struct udevice *dev,
+				  struct scmi_channel *channel,
+				  struct scmi_msg *msg)
 {
 	struct channel_session sess = { };
 	int ret;
diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c b/drivers/firmware/scmi/sandbox-scmi_agent.c
index c555164d196..031882998df 100644
--- a/drivers/firmware/scmi/sandbox-scmi_agent.c
+++ b/drivers/firmware/scmi/sandbox-scmi_agent.c
@@ -471,6 +471,7 @@ static int sandbox_scmi_voltd_level_get(struct udevice *dev,
 }
 
 static int sandbox_scmi_test_process_msg(struct udevice *dev,
+					 struct scmi_channel *channel,
 					 struct scmi_msg *msg)
 {
 	switch (msg->protocol_id) {
diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index 93cfc9c395b..c9c9c00384a 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -133,7 +133,7 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
 	ops = transport_dev_ops(parent);
 
 	if (ops->process_msg)
-		return ops->process_msg(parent, msg);
+		return ops->process_msg(parent, NULL, msg);
 
 	return -EPROTONOSUPPORT;
 }
diff --git a/drivers/firmware/scmi/smccc_agent.c b/drivers/firmware/scmi/smccc_agent.c
index 5e166ca93ee..b7a930b24df 100644
--- a/drivers/firmware/scmi/smccc_agent.c
+++ b/drivers/firmware/scmi/smccc_agent.c
@@ -30,7 +30,9 @@ struct scmi_smccc_channel {
 	struct scmi_smt smt;
 };
 
-static int scmi_smccc_process_msg(struct udevice *dev, struct scmi_msg *msg)
+static int scmi_smccc_process_msg(struct udevice *dev,
+				  struct scmi_channel *channel,
+				  struct scmi_msg *msg)
 {
 	struct scmi_smccc_channel *chan = dev_get_plat(dev);
 	struct arm_smccc_res res;
diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h
index 861ac6d1100..562a4cc99af 100644
--- a/include/scmi_agent-uclass.h
+++ b/include/scmi_agent-uclass.h
@@ -7,6 +7,7 @@
 
 struct udevice;
 struct scmi_msg;
+struct scmi_channel;
 
 /**
  * struct scmi_transport_ops - The functions that a SCMI transport layer must implement.
@@ -18,7 +19,8 @@ struct scmi_agent_ops {
 	 * @dev:		SCMI protocol device using the transport
 	 * @msg:		SCMI message to be transmitted
 	 */
-	int (*process_msg)(struct udevice *dev, struct scmi_msg *msg);
+	int (*process_msg)(struct udevice *dev, struct scmi_channel *channel,
+			   struct scmi_msg *msg);
 };
 
 #endif /* _SCMI_TRANSPORT_UCLASS_H */
-- 
2.25.1


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

* [PATCH v2 05/14] firmware: scmi: factorize scmi transport look up
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (3 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 04/14] firmware: scmi: prepare uclass to pass channel reference Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 06/14] firmware: scmi: add multi-channel support Etienne Carriere
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Defines local helper function find_scmi_transport_device() with the
instructions to find the SCMI transport device from a SCMI protocol
device.

Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/scmi_agent-uclass.c | 26 +++++++++++++++--------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index c9c9c00384a..f7fa5df214c 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -109,6 +109,20 @@ static int scmi_bind_protocols(struct udevice *dev)
 	return ret;
 }
 
+static struct udevice *find_scmi_transport_device(struct udevice *dev)
+{
+	struct udevice *parent = dev;
+
+	do {
+		parent = dev_get_parent(parent);
+	} while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT);
+
+	if (!parent)
+		dev_err(dev, "Invalid SCMI device, agent not found\n");
+
+	return parent;
+}
+
 static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev)
 {
 	return (const struct scmi_agent_ops *)dev->driver->ops;
@@ -118,17 +132,11 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
 			  struct scmi_msg *msg)
 {
 	const struct scmi_agent_ops *ops;
-	struct udevice *parent = dev;
+	struct udevice *parent;
 
-	/* Find related SCMI agent device */
-	do {
-		parent = dev_get_parent(parent);
-	} while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT);
-
-	if (!parent) {
-		dev_err(dev, "Invalid SCMI device, agent not found\n");
+	parent = find_scmi_transport_device(dev);
+	if (!parent)
 		return -ENODEV;
-	}
 
 	ops = transport_dev_ops(parent);
 
-- 
2.25.1


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

* [PATCH v2 06/14] firmware: scmi: add multi-channel support
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (4 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 05/14] firmware: scmi: factorize scmi transport look up Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 07/14] firmware: scmi: mailbox transport: implement multi-channel Etienne Carriere
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Adds resources for SCMI protocols to possibly use a dedicated SCMI
channel instead of the default channel allocated by the SCMI agent
during initialization. As per DT binding documentation, some SCMI
transports can define a specific SCMI communication channel for
given SCMI protocols. It allows SCMI protocols to pass messages
concurrently each other.

This change introduces new scmi agent uclass API function
devm_scmi_of_get_channel() for SCMI drivers probe sequences to get
a reference to the SCMI channel assigned to its related SCMI protocol.
The function queries the channel reference to its SCMI transport driver
through new scmi agent uclass operator .of_get_channel that uses Device
Tree information from related SCMI agent node.

Operator .of_get_channel returns a reference to the SCMI channel
assigned to SCMI protocol used by the caller device. SCMI transport
drivers that do not support multi-channel are not mandated to register
this operator. When so, API function devm_scmi_of_get_channel() returns
NULL and SCMI transport driver are expected to retrieve by their own
means the reference to the unique SCMI channel, for example using
platform data as these drivers currently do in U-Boot source tree.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/scmi_agent-uclass.c | 19 ++++++++++++++++++-
 include/scmi_agent-uclass.h               |  9 +++++++++
 include/scmi_agent.h                      |  9 +++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index f7fa5df214c..2b6211c4e6a 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -128,6 +128,23 @@ static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev)
 	return (const struct scmi_agent_ops *)dev->driver->ops;
 }
 
+int devm_scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel)
+{
+	struct udevice *parent;
+
+	parent = find_scmi_transport_device(dev);
+	if (!parent)
+		return -ENODEV;
+
+	if (transport_dev_ops(parent)->of_get_channel)
+		return transport_dev_ops(parent)->of_get_channel(dev, channel);
+
+	/* Drivers without a get_channel operator don't need a channel ref */
+	*channel = NULL;
+
+	return 0;
+}
+
 int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
 			  struct scmi_msg *msg)
 {
@@ -141,7 +158,7 @@ int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
 	ops = transport_dev_ops(parent);
 
 	if (ops->process_msg)
-		return ops->process_msg(parent, NULL, msg);
+		return ops->process_msg(parent, channel, msg);
 
 	return -EPROTONOSUPPORT;
 }
diff --git a/include/scmi_agent-uclass.h b/include/scmi_agent-uclass.h
index 562a4cc99af..b1c93532c0e 100644
--- a/include/scmi_agent-uclass.h
+++ b/include/scmi_agent-uclass.h
@@ -13,6 +13,15 @@ struct scmi_channel;
  * struct scmi_transport_ops - The functions that a SCMI transport layer must implement.
  */
 struct scmi_agent_ops {
+	/*
+	 * of_get_channel - Get SCMI channel from SCMI agent device tree node
+	 *
+	 * @dev:		SCMI protocol device using the transport
+	 * @channel:		Output reference to SCMI channel upon success
+	 * Return 0 upon success and a negative errno on failure
+	 */
+	int (*of_get_channel)(struct udevice *dev, struct scmi_channel **channel);
+
 	/*
 	 * process_msg - Request transport to get the SCMI message processed
 	 *
diff --git a/include/scmi_agent.h b/include/scmi_agent.h
index f4d85cae773..ee6286366df 100644
--- a/include/scmi_agent.h
+++ b/include/scmi_agent.h
@@ -45,6 +45,15 @@ struct scmi_msg {
 		.out_msg_sz = sizeof(_out_array),	\
 	}
 
+/**
+ * devm_scmi_of_get_channel() - Get SCMI channel handle from SCMI agent DT node
+ *
+ * @dev:	Device requesting a channel
+ * @channel:	Output reference to the SCMI channel upon success
+ * @return 0 on success and a negative errno on failure
+ */
+int devm_scmi_of_get_channel(struct udevice *dev, struct scmi_channel **channel);
+
 /**
  * devm_scmi_process_msg() - Send and process an SCMI message
  *
-- 
2.25.1


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

* [PATCH v2 07/14] firmware: scmi: mailbox transport: implement multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (5 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 06/14] firmware: scmi: add multi-channel support Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 08/14] firmware: scmi: smccc " Etienne Carriere
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Updates SCMI mailbox transport driver to get SCMI channel reference
at initialization and use when posting SCMI messages.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/mailbox_agent.c | 63 ++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/scmi/mailbox_agent.c b/drivers/firmware/scmi/mailbox_agent.c
index aa4929aafae..e63b67c5ee8 100644
--- a/drivers/firmware/scmi/mailbox_agent.c
+++ b/drivers/firmware/scmi/mailbox_agent.c
@@ -31,6 +31,14 @@ struct scmi_mbox_channel {
 	ulong timeout_us;
 };
 
+/**
+ * struct scmi_channel - Channel instance referenced in SCMI drivers
+ * @ref: Reference to local channel instance
+ **/
+struct scmi_channel {
+	struct scmi_mbox_channel ref;
+};
+
 static int scmi_mbox_process_msg(struct udevice *dev,
 				 struct scmi_channel *channel,
 				 struct scmi_msg *msg)
@@ -38,6 +46,10 @@ static int scmi_mbox_process_msg(struct udevice *dev,
 	struct scmi_mbox_channel *chan = dev_get_plat(dev);
 	int ret;
 
+	/* Support SCMI drivers upgraded to of_get_channel operator */
+	if (channel)
+		chan = &channel->ref;
+
 	ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
 	if (ret)
 		return ret;
@@ -64,13 +76,10 @@ out:
 	return ret;
 }
 
-int scmi_mbox_of_to_plat(struct udevice *dev)
+static int setup_channel(struct udevice *dev, struct scmi_mbox_channel *chan)
 {
-	struct scmi_mbox_channel *chan = dev_get_plat(dev);
 	int ret;
 
-	chan->timeout_us = TIMEOUT_US_10MS;
-
 	ret = mbox_get_by_index(dev, 0, &chan->mbox);
 	if (ret) {
 		dev_err(dev, "Failed to find mailbox: %d\n", ret);
@@ -78,10 +87,51 @@ int scmi_mbox_of_to_plat(struct udevice *dev)
 	}
 
 	ret = scmi_dt_get_smt_buffer(dev, &chan->smt);
-	if (ret)
+	if (ret) {
 		dev_err(dev, "Failed to get shm resources: %d\n", ret);
+		return ret;
+	}
 
-	return ret;
+	chan->timeout_us = TIMEOUT_US_10MS;
+
+	return 0;
+}
+
+static int scmi_mbox_get_channel(struct udevice *dev,
+				 struct scmi_channel **channel)
+{
+	struct scmi_mbox_channel *base_chan = dev_get_plat(dev->parent);
+	struct scmi_mbox_channel *chan;
+	int ret;
+
+	if (!dev_read_prop(dev, "shmem", NULL)) {
+		/* Uses agent base channel */
+		*channel = container_of(base_chan, struct scmi_channel, ref);
+
+		return 0;
+	}
+
+	chan = calloc(1, sizeof(*chan));
+	if (!chan)
+		return -ENOMEM;
+
+	/* Setup a dedicated channel for the protocol */
+	ret = setup_channel(dev, chan);
+	if (ret) {
+		free(chan);
+		return ret;
+	}
+
+	*channel = (void *)chan;
+
+	return 0;
+}
+
+int scmi_mbox_of_to_plat(struct udevice *dev)
+{
+	struct scmi_mbox_channel *chan = dev_get_plat(dev);
+
+	return setup_channel(dev, chan);
 }
 
 static const struct udevice_id scmi_mbox_ids[] = {
@@ -90,6 +140,7 @@ static const struct udevice_id scmi_mbox_ids[] = {
 };
 
 static const struct scmi_agent_ops scmi_mbox_ops = {
+	.of_get_channel = scmi_mbox_get_channel,
 	.process_msg = scmi_mbox_process_msg,
 };
 
-- 
2.25.1


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

* [PATCH v2 08/14] firmware: scmi: smccc transport: implement multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (6 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 07/14] firmware: scmi: mailbox transport: implement multi-channel Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 09/14] firmware: scmi: optee " Etienne Carriere
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Updates SCMI SMCCC transport driver to get SCMI channel reference
at initialization and use when posting SCMI messages.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/smccc_agent.c | 54 +++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/scmi/smccc_agent.c b/drivers/firmware/scmi/smccc_agent.c
index b7a930b24df..73a7e0a844a 100644
--- a/drivers/firmware/scmi/smccc_agent.c
+++ b/drivers/firmware/scmi/smccc_agent.c
@@ -30,6 +30,14 @@ struct scmi_smccc_channel {
 	struct scmi_smt smt;
 };
 
+/**
+ * struct scmi_channel - Channel instance referenced in SCMI drivers
+ * @ref: Reference to local channel instance
+ **/
+struct scmi_channel {
+	struct scmi_smccc_channel ref;
+};
+
 static int scmi_smccc_process_msg(struct udevice *dev,
 				  struct scmi_channel *channel,
 				  struct scmi_msg *msg)
@@ -38,6 +46,10 @@ static int scmi_smccc_process_msg(struct udevice *dev,
 	struct arm_smccc_res res;
 	int ret;
 
+	/* Support SCMI drivers upgraded to of_get_channel operator */
+	if (channel)
+		chan = &channel->ref;
+
 	ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
 	if (ret)
 		return ret;
@@ -53,9 +65,8 @@ static int scmi_smccc_process_msg(struct udevice *dev,
 	return ret;
 }
 
-static int scmi_smccc_of_to_plat(struct udevice *dev)
+static int setup_channel(struct udevice *dev, struct scmi_smccc_channel *chan)
 {
-	struct scmi_smccc_channel *chan = dev_get_plat(dev);
 	u32 func_id;
 	int ret;
 
@@ -73,12 +84,51 @@ static int scmi_smccc_of_to_plat(struct udevice *dev)
 	return ret;
 }
 
+static int scmi_smccc_get_channel(struct udevice *dev,
+				  struct scmi_channel **channel)
+{
+	struct scmi_smccc_channel *base_chan = dev_get_plat(dev->parent);
+	struct scmi_smccc_channel *chan;
+	u32 func_id;
+	int ret;
+
+	if (dev_read_u32(dev, "arm,smc-id", &func_id)) {
+		/* Uses agent base channel */
+		*channel = container_of(base_chan, struct scmi_channel, ref);
+
+		return 0;
+	}
+
+	/* Setup a dedicated channel */
+	chan = calloc(1, sizeof(*chan));
+	if (!chan)
+		return -ENOMEM;
+
+	ret = setup_channel(dev, chan);
+	if (ret) {
+		free(chan);
+		return ret;
+	}
+
+	*channel = container_of(chan, struct scmi_channel, ref);
+
+	return 0;
+}
+
+static int scmi_smccc_of_to_plat(struct udevice *dev)
+{
+	struct scmi_smccc_channel *chan = dev_get_plat(dev);
+
+	return setup_channel(dev, chan);
+}
+
 static const struct udevice_id scmi_smccc_ids[] = {
 	{ .compatible = "arm,scmi-smc" },
 	{ }
 };
 
 static const struct scmi_agent_ops scmi_smccc_ops = {
+	.of_get_channel = scmi_smccc_get_channel,
 	.process_msg = scmi_smccc_process_msg,
 };
 
-- 
2.25.1


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

* [PATCH v2 09/14] firmware: scmi: optee transport: implement multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (7 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 08/14] firmware: scmi: smccc " Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 10/14] clk: scmi: support SCMI multi-channel Etienne Carriere
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Implements multi SCMI channel support in OP-TEE SCMI transport. An
SCMI protocol may use a dedicated channel, specified by the DT.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/optee_agent.c | 76 ++++++++++++++++++++++++-----
 1 file changed, 63 insertions(+), 13 deletions(-)

diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c
index 771fa25e989..da5c2ec9754 100644
--- a/drivers/firmware/scmi/optee_agent.c
+++ b/drivers/firmware/scmi/optee_agent.c
@@ -35,6 +35,14 @@ struct scmi_optee_channel {
 	bool dyn_shm;
 };
 
+/**
+ * struct scmi_channel - Channel instance referenced in SCMI drivers
+ * @ref: Reference to local channel instance
+ **/
+struct scmi_channel {
+	struct scmi_optee_channel ref;
+};
+
 /**
  * struct channel_session - Aggreates SCMI service session context references
  * @tee:		OP-TEE device to invoke
@@ -132,10 +140,10 @@ enum optee_smci_pta_cmd {
 #define PTA_SCMI_CAPS_MASK		(PTA_SCMI_CAPS_SMT_HEADER | \
 					 PTA_SCMI_CAPS_MSG_HEADER)
 
-static int open_channel(struct udevice *dev, struct channel_session *sess)
+static int open_channel(struct udevice *dev, struct scmi_optee_channel *chan,
+			struct channel_session *sess)
 {
 	const struct tee_optee_ta_uuid uuid = TA_SCMI_UUID;
-	struct scmi_optee_channel *chan = dev_get_plat(dev);
 	struct tee_open_session_arg sess_arg = { };
 	struct tee_invoke_arg cmd_arg = { };
 	struct tee_param param[1] = { };
@@ -187,10 +195,9 @@ static void close_channel(struct channel_session *sess)
 	tee_close_session(sess->tee, sess->tee_session);
 }
 
-static int invoke_cmd(struct udevice *dev, struct channel_session *sess,
-		      struct scmi_msg *msg)
+static int invoke_cmd(struct udevice *dev, struct scmi_optee_channel *chan,
+		      struct channel_session *sess, struct scmi_msg *msg)
 {
-	struct scmi_optee_channel *chan = dev_get_plat(dev);
 	struct tee_invoke_arg arg = { };
 	struct tee_param param[3] = { };
 	int ret;
@@ -237,9 +244,9 @@ static int invoke_cmd(struct udevice *dev, struct channel_session *sess,
 	return ret;
 }
 
-static int prepare_shm(struct udevice *dev, struct channel_session *sess)
+static int prepare_shm(struct udevice *dev, struct scmi_optee_channel *chan,
+		       struct channel_session *sess)
 {
-	struct scmi_optee_channel *chan = dev_get_plat(dev);
 	int ret;
 
 	/* Static shm is already prepared by the firmware: nothing to do */
@@ -274,15 +281,19 @@ static int scmi_optee_process_msg(struct udevice *dev,
 	struct channel_session sess = { };
 	int ret;
 
-	ret = open_channel(dev, &sess);
+	/* Support SCMI drivers upgraded to of_get_channel operator */
+	if (channel)
+		chan = &channel->ref;
+
+	ret = open_channel(dev, chan, &sess);
 	if (ret)
 		return ret;
 
-	ret = prepare_shm(dev, &sess);
+	ret = prepare_shm(dev, chan, &sess);
 	if (ret)
 		goto out;
 
-	ret = invoke_cmd(dev, &sess, msg);
+	ret = invoke_cmd(dev, chan, &sess, msg);
 
 	release_shm(dev, &sess);
 
@@ -292,9 +303,8 @@ out:
 	return ret;
 }
 
-static int scmi_optee_of_to_plat(struct udevice *dev)
+static int setup_channel(struct udevice *dev, struct scmi_optee_channel *chan)
 {
-	struct scmi_optee_channel *chan = dev_get_plat(dev);
 	int ret;
 
 	if (dev_read_u32(dev, "linaro,optee-channel-id", &chan->channel_id)) {
@@ -316,13 +326,52 @@ static int scmi_optee_of_to_plat(struct udevice *dev)
 	return 0;
 }
 
+static int scmi_optee_get_channel(struct udevice *dev,
+				  struct scmi_channel **channel)
+{
+	struct scmi_optee_channel *base_chan = dev_get_plat(dev->parent);
+	struct scmi_optee_channel *chan;
+	u32 channel_id;
+	int ret;
+
+	if (dev_read_u32(dev, "linaro,optee-channel-id", &channel_id)) {
+		/* Uses agent base channel */
+		*channel = container_of(base_chan, struct scmi_channel, ref);
+
+		return 0;
+	}
+
+	/* Setup a dedicated channel */
+	chan = calloc(1, sizeof(*chan));
+	if (!chan)
+		return -ENOMEM;
+
+	ret = setup_channel(dev, chan);
+	if (ret) {
+		free(chan);
+		return ret;
+	}
+
+	*channel = container_of(chan, struct scmi_channel, ref);
+
+	return 0;
+}
+
+static int scmi_optee_of_to_plat(struct udevice *dev)
+{
+	struct scmi_optee_channel *chan = dev_get_plat(dev);
+
+	return setup_channel(dev, chan);
+}
+
 static int scmi_optee_probe(struct udevice *dev)
 {
+	struct scmi_optee_channel *chan = dev_get_plat(dev);
 	struct channel_session sess;
 	int ret;
 
 	/* Check OP-TEE service acknowledges the SCMI channel */
-	ret = open_channel(dev, &sess);
+	ret = open_channel(dev, chan, &sess);
 	if (!ret)
 		close_channel(&sess);
 
@@ -335,6 +384,7 @@ static const struct udevice_id scmi_optee_ids[] = {
 };
 
 static const struct scmi_agent_ops scmi_optee_ops = {
+	.of_get_channel = scmi_optee_get_channel,
 	.process_msg = scmi_optee_process_msg,
 };
 
-- 
2.25.1


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

* [PATCH v2 10/14] clk: scmi: support SCMI multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (8 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 09/14] firmware: scmi: optee " Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-09-28 17:29   ` Sean Anderson
  2022-05-31 16:09 ` [PATCH v2 11/14] reset: " Etienne Carriere
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot
  Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere,
	Lukasz Majewski, Sean Anderson

Update SCMI clock driver to get its assigned SCMI channel during
initialization. This change allows SCMI clock protocol to use a
dedicated channel when defined in the DT. The reference is saved
in SCMI clock driver private data.

Cc: Lukasz Majewski <lukma@denx.de>
Cc: Sean Anderson <seanga2@gmail.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
Changes since v1:
- Define a private struct to hold channel reference rather than using
  device private data reference as opaque channel reference.

---
 drivers/clk/clk_scmi.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index 0d0bb72eaf7..d172fed24c9 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2019-2020 Linaro Limited
+ * Copyright (C) 2019-2022 Linaro Limited
  */
 
 #define LOG_CATEGORY UCLASS_CLK
@@ -13,8 +13,17 @@
 #include <asm/types.h>
 #include <linux/clk-provider.h>
 
+/**
+ * struct scmi_clk_priv - Private data for SCMI clocks
+ * @channel: Reference to the SCMI channel to use
+ */
+struct scmi_clk_priv {
+	struct scmi_channel *channel;
+};
+
 static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
 {
+	struct scmi_clk_priv *priv = dev_get_priv(dev);
 	struct scmi_clk_protocol_attr_out out;
 	struct scmi_msg msg = {
 		.protocol_id = SCMI_PROTOCOL_ID_CLOCK,
@@ -24,7 +33,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
 	};
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, NULL, &msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
 	if (ret)
 		return ret;
 
@@ -35,6 +44,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
 
 static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
 {
+	struct scmi_clk_priv *priv = dev_get_priv(dev);
 	struct scmi_clk_attribute_in in = {
 		.clock_id = clkid,
 	};
@@ -49,7 +59,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
 	};
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, NULL, &msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
 	if (ret)
 		return ret;
 
@@ -60,6 +70,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
 
 static int scmi_clk_gate(struct clk *clk, int enable)
 {
+	struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
 	struct scmi_clk_state_in in = {
 		.clock_id = clk->id,
 		.attributes = enable,
@@ -70,7 +81,7 @@ static int scmi_clk_gate(struct clk *clk, int enable)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
+	ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg);
 	if (ret)
 		return ret;
 
@@ -89,6 +100,7 @@ static int scmi_clk_disable(struct clk *clk)
 
 static ulong scmi_clk_get_rate(struct clk *clk)
 {
+	struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
 	struct scmi_clk_rate_get_in in = {
 		.clock_id = clk->id,
 	};
@@ -98,7 +110,7 @@ static ulong scmi_clk_get_rate(struct clk *clk)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
+	ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -111,6 +123,7 @@ static ulong scmi_clk_get_rate(struct clk *clk)
 
 static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
 {
+	struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
 	struct scmi_clk_rate_set_in in = {
 		.clock_id = clk->id,
 		.flags = SCMI_CLK_RATE_ROUND_CLOSEST,
@@ -123,7 +136,7 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
+	ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -136,10 +149,15 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
 
 static int scmi_clk_probe(struct udevice *dev)
 {
+	struct scmi_clk_priv *priv = dev_get_priv(dev);
 	struct clk *clk;
 	size_t num_clocks, i;
 	int ret;
 
+	ret = devm_scmi_of_get_channel(dev, &priv->channel);
+	if (ret)
+		return ret;
+
 	if (!CONFIG_IS_ENABLED(CLK_CCF))
 		return 0;
 
@@ -186,5 +204,6 @@ U_BOOT_DRIVER(scmi_clock) = {
 	.name = "scmi_clk",
 	.id = UCLASS_CLK,
 	.ops = &scmi_clk_ops,
-	.probe = &scmi_clk_probe,
+	.probe = scmi_clk_probe,
+	.priv_auto = sizeof(struct scmi_clk_priv *),
 };
-- 
2.25.1


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

* [PATCH v2 11/14] reset: scmi: support SCMI multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (9 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 10/14] clk: scmi: support SCMI multi-channel Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 12/14] power: regulator: " Etienne Carriere
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Update SCMI reset controller driver to get its assigned SCMI channel
during initialization. This change allows SCMI reset domain protocol
to use a dedicated channel when defined in the DT. The reference is
saved in SCMI reset controller driver private data.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
Changes since v1:
- Define a private struct to hold channel reference rather than using
  device private data reference as opaque channel reference.

---
 drivers/reset/reset-scmi.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c
index 30b26ec9d31..122556162ec 100644
--- a/drivers/reset/reset-scmi.c
+++ b/drivers/reset/reset-scmi.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2019-2020 Linaro Limited
+ * Copyright (C) 2019-2022 Linaro Limited
  */
 
 #define LOG_CATEGORY UCLASS_RESET
@@ -13,8 +13,17 @@
 #include <scmi_protocols.h>
 #include <asm/types.h>
 
+/**
+ * struct scmi_reset_priv - Private data for SCMI reset controller
+ * @channel: Reference to the SCMI channel to use
+ */
+struct scmi_reset_priv {
+	struct scmi_channel *channel;
+};
+
 static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
 {
+	struct scmi_reset_priv *priv = dev_get_priv(rst->dev);
 	struct scmi_rd_reset_in in = {
 		.domain_id = rst->id,
 		.flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT : 0,
@@ -26,7 +35,7 @@ static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(rst->dev, NULL, &msg);
+	ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg);
 	if (ret)
 		return ret;
 
@@ -45,6 +54,7 @@ static int scmi_reset_deassert(struct reset_ctl *rst)
 
 static int scmi_reset_request(struct reset_ctl *rst)
 {
+	struct scmi_reset_priv *priv = dev_get_priv(rst->dev);
 	struct scmi_rd_attr_in in = {
 		.domain_id = rst->id,
 	};
@@ -58,7 +68,7 @@ static int scmi_reset_request(struct reset_ctl *rst)
 	 * We don't really care about the attribute, just check
 	 * the reset domain exists.
 	 */
-	ret = devm_scmi_process_msg(rst->dev, NULL, &msg);
+	ret = devm_scmi_process_msg(rst->dev, priv->channel, &msg);
 	if (ret)
 		return ret;
 
@@ -71,8 +81,17 @@ static const struct reset_ops scmi_reset_domain_ops = {
 	.rst_deassert	= scmi_reset_deassert,
 };
 
+static int scmi_reset_probe(struct udevice *dev)
+{
+	struct scmi_reset_priv *priv = dev_get_priv(dev);
+
+	return devm_scmi_of_get_channel(dev, &priv->channel);
+}
+
 U_BOOT_DRIVER(scmi_reset_domain) = {
 	.name = "scmi_reset_domain",
 	.id = UCLASS_RESET,
 	.ops = &scmi_reset_domain_ops,
+	.probe = scmi_reset_probe,
+	.priv_auto = sizeof(struct scmi_reset_priv *),
 };
-- 
2.25.1


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

* [PATCH v2 12/14] power: regulator: scmi: support SCMI multi-channel
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (10 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 11/14] reset: " Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-06-14  2:13   ` Jaehoon Chung
  2022-05-31 16:09 ` [PATCH v2 13/14] power: regulator: scmi: simplify scmi_voltd_set_enable() Etienne Carriere
  2022-05-31 16:09 ` [PATCH v2 14/14] firmware: scmi: use multi channel in mailbox, optee and smccc agents Etienne Carriere
  13 siblings, 1 reply; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere, Jaehoon Chung

Update SCMI regulator controller driver to get its assigned SCMI channel
during initialization. This change allows SCMI voltage domain protocol
to use a dedicated channel when defined in the DT. The reference is
saved in SCMI regulator controller driver private data.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
Changes since v1:
- Define a private struct to hold channel reference rather than using
  device private data reference as opaque channel reference.

---
 drivers/power/regulator/scmi_regulator.c | 30 +++++++++++++++++++-----
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c
index 3325ddaf23b..352daa9bbc9 100644
--- a/drivers/power/regulator/scmi_regulator.c
+++ b/drivers/power/regulator/scmi_regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2020-2021 Linaro Limited
+ * Copyright (C) 2020-2022 Linaro Limited
  */
 
 #define LOG_CATEGORY UCLASS_REGULATOR
@@ -25,9 +25,18 @@ struct scmi_regulator_platdata {
 	u32 domain_id;
 };
 
+/**
+ * struct scmi_regulator_priv - Private data for SCMI voltage regulator
+ * @channel: Reference to the SCMI channel to use
+ */
+struct scmi_regulator_priv {
+	struct scmi_channel *channel;
+};
+
 static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 {
 	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
+	struct scmi_regulator_priv *priv = dev_get_priv(dev);
 	struct scmi_voltd_config_set_in in = {
 		.domain_id = pdata->domain_id,
 		.config = enable ? SCMI_VOLTD_CONFIG_ON : SCMI_VOLTD_CONFIG_OFF,
@@ -38,7 +47,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, NULL, &msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
 	if (ret)
 		return ret;
 
@@ -52,6 +61,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 static int scmi_voltd_get_enable(struct udevice *dev)
 {
 	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
+	struct scmi_regulator_priv *priv = dev_get_priv(dev);
 	struct scmi_voltd_config_get_in in = {
 		.domain_id = pdata->domain_id,
 	};
@@ -61,7 +71,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, NULL, &msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -74,6 +84,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
 
 static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
 {
+	struct scmi_regulator_priv *priv = dev_get_priv(dev);
 	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
 	struct scmi_voltd_level_set_in in = {
 		.domain_id = pdata->domain_id,
@@ -85,7 +96,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, NULL, &msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -94,6 +105,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
 
 static int scmi_voltd_get_voltage_level(struct udevice *dev)
 {
+	struct scmi_regulator_priv *priv = dev_get_priv(dev);
 	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
 	struct scmi_voltd_level_get_in in = {
 		.domain_id = pdata->domain_id,
@@ -104,7 +116,7 @@ static int scmi_voltd_get_voltage_level(struct udevice *dev)
 					  in, out);
 	int ret;
 
-	ret = devm_scmi_process_msg(dev, NULL, &msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
 	if (ret < 0)
 		return ret;
 
@@ -132,6 +144,7 @@ static int scmi_regulator_of_to_plat(struct udevice *dev)
 static int scmi_regulator_probe(struct udevice *dev)
 {
 	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
+	struct scmi_regulator_priv *priv = dev_get_priv(dev);
 	struct scmi_voltd_attr_in in = { 0 };
 	struct scmi_voltd_attr_out out = { 0 };
 	struct scmi_msg scmi_msg = {
@@ -144,10 +157,14 @@ static int scmi_regulator_probe(struct udevice *dev)
 	};
 	int ret;
 
+	ret = devm_scmi_of_get_channel(dev->parent, &priv->channel);
+	if (ret)
+		return ret;
+
 	/* Check voltage domain is known from SCMI server */
 	in.domain_id = pdata->domain_id;
 
-	ret = devm_scmi_process_msg(dev, NULL, &scmi_msg);
+	ret = devm_scmi_process_msg(dev, priv->channel, &scmi_msg);
 	if (ret) {
 		dev_err(dev, "Failed to query voltage domain %u: %d\n",
 			pdata->domain_id, ret);
@@ -171,6 +188,7 @@ U_BOOT_DRIVER(scmi_regulator) = {
 	.probe = scmi_regulator_probe,
 	.of_to_plat = scmi_regulator_of_to_plat,
 	.plat_auto = sizeof(struct scmi_regulator_platdata),
+	.priv_auto = sizeof(struct scmi_regulator_priv *),
 };
 
 static int scmi_regulator_bind(struct udevice *dev)
-- 
2.25.1


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

* [PATCH v2 13/14] power: regulator: scmi: simplify scmi_voltd_set_enable()
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (11 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 12/14] power: regulator: " Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  2022-06-14  2:13   ` Jaehoon Chung
  2022-05-31 16:09 ` [PATCH v2 14/14] firmware: scmi: use multi channel in mailbox, optee and smccc agents Etienne Carriere
  13 siblings, 1 reply; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere, Jaehoon Chung

Simplify scmi_voltd_set_enable() exit sequence.

Cc: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/power/regulator/scmi_regulator.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c
index 352daa9bbc9..801148036ff 100644
--- a/drivers/power/regulator/scmi_regulator.c
+++ b/drivers/power/regulator/scmi_regulator.c
@@ -51,11 +51,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
 	if (ret)
 		return ret;
 
-	ret = scmi_to_linux_errno(out.status);
-	if (ret)
-		return ret;
-
-	return ret;
+	return scmi_to_linux_errno(out.status);
 }
 
 static int scmi_voltd_get_enable(struct udevice *dev)
-- 
2.25.1


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

* [PATCH v2 14/14] firmware: scmi: use multi channel in mailbox, optee and smccc agents
  2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
                   ` (12 preceding siblings ...)
  2022-05-31 16:09 ` [PATCH v2 13/14] power: regulator: scmi: simplify scmi_voltd_set_enable() Etienne Carriere
@ 2022-05-31 16:09 ` Etienne Carriere
  13 siblings, 0 replies; 19+ messages in thread
From: Etienne Carriere @ 2022-05-31 16:09 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Patrice Chotard, etienne.carriere

Updates .process_msg operators of the SCMI transport drivers that
supports multi-channel to use it now that drivers do provide
the reference through channel argument. These are the mailbox
agent, the optee agent and the smccc agent.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
No change since v1.

---
 drivers/firmware/scmi/mailbox_agent.c | 6 +-----
 drivers/firmware/scmi/optee_agent.c   | 5 +----
 drivers/firmware/scmi/smccc_agent.c   | 6 +-----
 3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/firmware/scmi/mailbox_agent.c b/drivers/firmware/scmi/mailbox_agent.c
index e63b67c5ee8..3efdab9e723 100644
--- a/drivers/firmware/scmi/mailbox_agent.c
+++ b/drivers/firmware/scmi/mailbox_agent.c
@@ -43,13 +43,9 @@ static int scmi_mbox_process_msg(struct udevice *dev,
 				 struct scmi_channel *channel,
 				 struct scmi_msg *msg)
 {
-	struct scmi_mbox_channel *chan = dev_get_plat(dev);
+	struct scmi_mbox_channel *chan = &channel->ref;
 	int ret;
 
-	/* Support SCMI drivers upgraded to of_get_channel operator */
-	if (channel)
-		chan = &channel->ref;
-
 	ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
 	if (ret)
 		return ret;
diff --git a/drivers/firmware/scmi/optee_agent.c b/drivers/firmware/scmi/optee_agent.c
index da5c2ec9754..2b2b8c1670a 100644
--- a/drivers/firmware/scmi/optee_agent.c
+++ b/drivers/firmware/scmi/optee_agent.c
@@ -278,13 +278,10 @@ static int scmi_optee_process_msg(struct udevice *dev,
 				  struct scmi_channel *channel,
 				  struct scmi_msg *msg)
 {
+	struct scmi_optee_channel *chan = &channel->ref;
 	struct channel_session sess = { };
 	int ret;
 
-	/* Support SCMI drivers upgraded to of_get_channel operator */
-	if (channel)
-		chan = &channel->ref;
-
 	ret = open_channel(dev, chan, &sess);
 	if (ret)
 		return ret;
diff --git a/drivers/firmware/scmi/smccc_agent.c b/drivers/firmware/scmi/smccc_agent.c
index 73a7e0a844a..bc2eb67335b 100644
--- a/drivers/firmware/scmi/smccc_agent.c
+++ b/drivers/firmware/scmi/smccc_agent.c
@@ -42,14 +42,10 @@ static int scmi_smccc_process_msg(struct udevice *dev,
 				  struct scmi_channel *channel,
 				  struct scmi_msg *msg)
 {
-	struct scmi_smccc_channel *chan = dev_get_plat(dev);
+	struct scmi_smccc_channel *chan = &channel->ref;
 	struct arm_smccc_res res;
 	int ret;
 
-	/* Support SCMI drivers upgraded to of_get_channel operator */
-	if (channel)
-		chan = &channel->ref;
-
 	ret = scmi_write_msg_to_smt(dev, &chan->smt, msg);
 	if (ret)
 		return ret;
-- 
2.25.1


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

* Re: [PATCH v2 12/14] power: regulator: scmi: support SCMI multi-channel
  2022-05-31 16:09 ` [PATCH v2 12/14] power: regulator: " Etienne Carriere
@ 2022-06-14  2:13   ` Jaehoon Chung
  0 siblings, 0 replies; 19+ messages in thread
From: Jaehoon Chung @ 2022-06-14  2:13 UTC (permalink / raw)
  To: Etienne Carriere, u-boot; +Cc: Patrick Delaunay, Patrice Chotard

On 6/1/22 01:09, Etienne Carriere wrote:
> Update SCMI regulator controller driver to get its assigned SCMI channel
> during initialization. This change allows SCMI voltage domain protocol
> to use a dedicated channel when defined in the DT. The reference is
> saved in SCMI regulator controller driver private data.
> 
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Best Regards,
Jaehoon Chung

> ---
> Changes since v1:
> - Define a private struct to hold channel reference rather than using
>   device private data reference as opaque channel reference.
> 
> ---
>  drivers/power/regulator/scmi_regulator.c | 30 +++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c
> index 3325ddaf23b..352daa9bbc9 100644
> --- a/drivers/power/regulator/scmi_regulator.c
> +++ b/drivers/power/regulator/scmi_regulator.c
> @@ -1,6 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0+
>  /*
> - * Copyright (C) 2020-2021 Linaro Limited
> + * Copyright (C) 2020-2022 Linaro Limited
>   */
>  
>  #define LOG_CATEGORY UCLASS_REGULATOR
> @@ -25,9 +25,18 @@ struct scmi_regulator_platdata {
>  	u32 domain_id;
>  };
>  
> +/**
> + * struct scmi_regulator_priv - Private data for SCMI voltage regulator
> + * @channel: Reference to the SCMI channel to use
> + */
> +struct scmi_regulator_priv {
> +	struct scmi_channel *channel;
> +};
> +
>  static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
>  {
>  	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
> +	struct scmi_regulator_priv *priv = dev_get_priv(dev);
>  	struct scmi_voltd_config_set_in in = {
>  		.domain_id = pdata->domain_id,
>  		.config = enable ? SCMI_VOLTD_CONFIG_ON : SCMI_VOLTD_CONFIG_OFF,
> @@ -38,7 +47,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
>  					  in, out);
>  	int ret;
>  
> -	ret = devm_scmi_process_msg(dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
>  	if (ret)
>  		return ret;
>  
> @@ -52,6 +61,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
>  static int scmi_voltd_get_enable(struct udevice *dev)
>  {
>  	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
> +	struct scmi_regulator_priv *priv = dev_get_priv(dev);
>  	struct scmi_voltd_config_get_in in = {
>  		.domain_id = pdata->domain_id,
>  	};
> @@ -61,7 +71,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
>  					  in, out);
>  	int ret;
>  
> -	ret = devm_scmi_process_msg(dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -74,6 +84,7 @@ static int scmi_voltd_get_enable(struct udevice *dev)
>  
>  static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
>  {
> +	struct scmi_regulator_priv *priv = dev_get_priv(dev);
>  	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
>  	struct scmi_voltd_level_set_in in = {
>  		.domain_id = pdata->domain_id,
> @@ -85,7 +96,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
>  					  in, out);
>  	int ret;
>  
> -	ret = devm_scmi_process_msg(dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -94,6 +105,7 @@ static int scmi_voltd_set_voltage_level(struct udevice *dev, int uV)
>  
>  static int scmi_voltd_get_voltage_level(struct udevice *dev)
>  {
> +	struct scmi_regulator_priv *priv = dev_get_priv(dev);
>  	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
>  	struct scmi_voltd_level_get_in in = {
>  		.domain_id = pdata->domain_id,
> @@ -104,7 +116,7 @@ static int scmi_voltd_get_voltage_level(struct udevice *dev)
>  					  in, out);
>  	int ret;
>  
> -	ret = devm_scmi_process_msg(dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -132,6 +144,7 @@ static int scmi_regulator_of_to_plat(struct udevice *dev)
>  static int scmi_regulator_probe(struct udevice *dev)
>  {
>  	struct scmi_regulator_platdata *pdata = dev_get_plat(dev);
> +	struct scmi_regulator_priv *priv = dev_get_priv(dev);
>  	struct scmi_voltd_attr_in in = { 0 };
>  	struct scmi_voltd_attr_out out = { 0 };
>  	struct scmi_msg scmi_msg = {
> @@ -144,10 +157,14 @@ static int scmi_regulator_probe(struct udevice *dev)
>  	};
>  	int ret;
>  
> +	ret = devm_scmi_of_get_channel(dev->parent, &priv->channel);
> +	if (ret)
> +		return ret;
> +
>  	/* Check voltage domain is known from SCMI server */
>  	in.domain_id = pdata->domain_id;
>  
> -	ret = devm_scmi_process_msg(dev, NULL, &scmi_msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &scmi_msg);
>  	if (ret) {
>  		dev_err(dev, "Failed to query voltage domain %u: %d\n",
>  			pdata->domain_id, ret);
> @@ -171,6 +188,7 @@ U_BOOT_DRIVER(scmi_regulator) = {
>  	.probe = scmi_regulator_probe,
>  	.of_to_plat = scmi_regulator_of_to_plat,
>  	.plat_auto = sizeof(struct scmi_regulator_platdata),
> +	.priv_auto = sizeof(struct scmi_regulator_priv *),
>  };
>  
>  static int scmi_regulator_bind(struct udevice *dev)


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

* Re: [PATCH v2 13/14] power: regulator: scmi: simplify scmi_voltd_set_enable()
  2022-05-31 16:09 ` [PATCH v2 13/14] power: regulator: scmi: simplify scmi_voltd_set_enable() Etienne Carriere
@ 2022-06-14  2:13   ` Jaehoon Chung
  0 siblings, 0 replies; 19+ messages in thread
From: Jaehoon Chung @ 2022-06-14  2:13 UTC (permalink / raw)
  To: Etienne Carriere, u-boot; +Cc: Patrick Delaunay, Patrice Chotard

On 6/1/22 01:09, Etienne Carriere wrote:
> Simplify scmi_voltd_set_enable() exit sequence.
> 
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Best Regards,
Jaehoon Chung

> ---
> No change since v1.
> 
> ---
>  drivers/power/regulator/scmi_regulator.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/power/regulator/scmi_regulator.c b/drivers/power/regulator/scmi_regulator.c
> index 352daa9bbc9..801148036ff 100644
> --- a/drivers/power/regulator/scmi_regulator.c
> +++ b/drivers/power/regulator/scmi_regulator.c
> @@ -51,11 +51,7 @@ static int scmi_voltd_set_enable(struct udevice *dev, bool enable)
>  	if (ret)
>  		return ret;
>  
> -	ret = scmi_to_linux_errno(out.status);
> -	if (ret)
> -		return ret;
> -
> -	return ret;
> +	return scmi_to_linux_errno(out.status);
>  }
>  
>  static int scmi_voltd_get_enable(struct udevice *dev)


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

* Re: [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages
  2022-05-31 16:09 ` [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages Etienne Carriere
@ 2022-06-23 18:32   ` Tom Rini
  0 siblings, 0 replies; 19+ messages in thread
From: Tom Rini @ 2022-06-23 18:32 UTC (permalink / raw)
  To: Etienne Carriere; +Cc: u-boot, Patrick Delaunay, Patrice Chotard

[-- Attachment #1: Type: text/plain, Size: 1028 bytes --]

On Tue, May 31, 2022 at 06:09:16PM +0200, Etienne Carriere wrote:

> Changes implementation when using TEE dynamically allocated shared
> memory to synchronize with the Linux implementation where the legacy
> SMT protocol cannot be used with such memory since it is expected from
> device mapped memory whereas OP-TEE shared memory is cached and
> hence should not be accessed using memcpy_toio()/memcpy_fromio().
> 
> This change implements the MSG shared memory protocol introduced
> in Linux [1]. The protocol uses a simplified SMT header of 32bit
> named MSG_SMT to carry SCMI protocol information and uses side channel
> means to carry exchanged buffer size information, as TEE invocation API
> parameters when used in the SCMI OP-TEE transport.
> 
> Link: [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f301bba0ca7392d16a6ea4f1d264a91f1fadea1a
> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>

For the series, applied to u-boot/next, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

* Re: [PATCH v2 10/14] clk: scmi: support SCMI multi-channel
  2022-05-31 16:09 ` [PATCH v2 10/14] clk: scmi: support SCMI multi-channel Etienne Carriere
@ 2022-09-28 17:29   ` Sean Anderson
  0 siblings, 0 replies; 19+ messages in thread
From: Sean Anderson @ 2022-09-28 17:29 UTC (permalink / raw)
  To: Etienne Carriere, u-boot
  Cc: Patrick Delaunay, Patrice Chotard, Lukasz Majewski

On 5/31/22 12:09, Etienne Carriere wrote:
> Update SCMI clock driver to get its assigned SCMI channel during
> initialization. This change allows SCMI clock protocol to use a
> dedicated channel when defined in the DT. The reference is saved
> in SCMI clock driver private data.
> 
> Cc: Lukasz Majewski <lukma@denx.de>
> Cc: Sean Anderson <seanga2@gmail.com>
> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
> ---
> Changes since v1:
> - Define a private struct to hold channel reference rather than using
>    device private data reference as opaque channel reference.
> 
> ---
>   drivers/clk/clk_scmi.c | 33 ++++++++++++++++++++++++++-------
>   1 file changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
> index 0d0bb72eaf7..d172fed24c9 100644
> --- a/drivers/clk/clk_scmi.c
> +++ b/drivers/clk/clk_scmi.c
> @@ -1,6 +1,6 @@
>   // SPDX-License-Identifier: GPL-2.0+
>   /*
> - * Copyright (C) 2019-2020 Linaro Limited
> + * Copyright (C) 2019-2022 Linaro Limited
>    */
>   
>   #define LOG_CATEGORY UCLASS_CLK
> @@ -13,8 +13,17 @@
>   #include <asm/types.h>
>   #include <linux/clk-provider.h>
>   
> +/**
> + * struct scmi_clk_priv - Private data for SCMI clocks
> + * @channel: Reference to the SCMI channel to use
> + */
> +struct scmi_clk_priv {
> +	struct scmi_channel *channel;
> +};
> +
>   static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
>   {
> +	struct scmi_clk_priv *priv = dev_get_priv(dev);
>   	struct scmi_clk_protocol_attr_out out;
>   	struct scmi_msg msg = {
>   		.protocol_id = SCMI_PROTOCOL_ID_CLOCK,
> @@ -24,7 +33,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
>   	};
>   	int ret;
>   
> -	ret = devm_scmi_process_msg(dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
>   	if (ret)
>   		return ret;
>   
> @@ -35,6 +44,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
>   
>   static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
>   {
> +	struct scmi_clk_priv *priv = dev_get_priv(dev);
>   	struct scmi_clk_attribute_in in = {
>   		.clock_id = clkid,
>   	};
> @@ -49,7 +59,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
>   	};
>   	int ret;
>   
> -	ret = devm_scmi_process_msg(dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(dev, priv->channel, &msg);
>   	if (ret)
>   		return ret;
>   
> @@ -60,6 +70,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
>   
>   static int scmi_clk_gate(struct clk *clk, int enable)
>   {
> +	struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
>   	struct scmi_clk_state_in in = {
>   		.clock_id = clk->id,
>   		.attributes = enable,
> @@ -70,7 +81,7 @@ static int scmi_clk_gate(struct clk *clk, int enable)
>   					  in, out);
>   	int ret;
>   
> -	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg);
>   	if (ret)
>   		return ret;
>   
> @@ -89,6 +100,7 @@ static int scmi_clk_disable(struct clk *clk)
>   
>   static ulong scmi_clk_get_rate(struct clk *clk)
>   {
> +	struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
>   	struct scmi_clk_rate_get_in in = {
>   		.clock_id = clk->id,
>   	};
> @@ -98,7 +110,7 @@ static ulong scmi_clk_get_rate(struct clk *clk)
>   					  in, out);
>   	int ret;
>   
> -	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg);
>   	if (ret < 0)
>   		return ret;
>   
> @@ -111,6 +123,7 @@ static ulong scmi_clk_get_rate(struct clk *clk)
>   
>   static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
>   {
> +	struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
>   	struct scmi_clk_rate_set_in in = {
>   		.clock_id = clk->id,
>   		.flags = SCMI_CLK_RATE_ROUND_CLOSEST,
> @@ -123,7 +136,7 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
>   					  in, out);
>   	int ret;
>   
> -	ret = devm_scmi_process_msg(clk->dev, NULL, &msg);
> +	ret = devm_scmi_process_msg(clk->dev, priv->channel, &msg);
>   	if (ret < 0)
>   		return ret;
>   
> @@ -136,10 +149,15 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
>   
>   static int scmi_clk_probe(struct udevice *dev)
>   {
> +	struct scmi_clk_priv *priv = dev_get_priv(dev);
>   	struct clk *clk;
>   	size_t num_clocks, i;
>   	int ret;
>   
> +	ret = devm_scmi_of_get_channel(dev, &priv->channel);
> +	if (ret)
> +		return ret;
> +
>   	if (!CONFIG_IS_ENABLED(CLK_CCF))
>   		return 0;
>   
> @@ -186,5 +204,6 @@ U_BOOT_DRIVER(scmi_clock) = {
>   	.name = "scmi_clk",
>   	.id = UCLASS_CLK,
>   	.ops = &scmi_clk_ops,
> -	.probe = &scmi_clk_probe,
> +	.probe = scmi_clk_probe,
> +	.priv_auto = sizeof(struct scmi_clk_priv *),
>   };

Reviewed-by: Sean Anderson <seanga2@gmail.com>

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

end of thread, other threads:[~2022-09-28 17:29 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 16:09 [PATCH v2 00/14] SCMI multi-channel and optee shm Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 01/14] firmware: scmi: optee: use TEE shared memory for SCMI messages Etienne Carriere
2022-06-23 18:32   ` Tom Rini
2022-05-31 16:09 ` [PATCH v2 02/14] firmware: scmi: optee: fix inline description of PTA_SCMI_CMD_GET_CHANNEL Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 03/14] firmware: scmi: prepare scmi uclass API to multi-channel Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 04/14] firmware: scmi: prepare uclass to pass channel reference Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 05/14] firmware: scmi: factorize scmi transport look up Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 06/14] firmware: scmi: add multi-channel support Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 07/14] firmware: scmi: mailbox transport: implement multi-channel Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 08/14] firmware: scmi: smccc " Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 09/14] firmware: scmi: optee " Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 10/14] clk: scmi: support SCMI multi-channel Etienne Carriere
2022-09-28 17:29   ` Sean Anderson
2022-05-31 16:09 ` [PATCH v2 11/14] reset: " Etienne Carriere
2022-05-31 16:09 ` [PATCH v2 12/14] power: regulator: " Etienne Carriere
2022-06-14  2:13   ` Jaehoon Chung
2022-05-31 16:09 ` [PATCH v2 13/14] power: regulator: scmi: simplify scmi_voltd_set_enable() Etienne Carriere
2022-06-14  2:13   ` Jaehoon Chung
2022-05-31 16:09 ` [PATCH v2 14/14] firmware: scmi: use multi channel in mailbox, optee and smccc agents Etienne Carriere

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.