Skip to contentSkip to conversation

firmware: arm_scmi: add smc/hvc transports support

PATCH Superseded [email protected] 2 participants 7 messages Feb 13, 2020 – Feb 14, 2020

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover firmware: arm_scmi: add smc/hvc transports support

From: Peng Fan <[email protected]>

V2:
patch 1/2: only add smc-id property
patch 2/2: Parse smc/hvc from psci node
Use prot_id as 2nd arg when issue smc/hvc Differentiate tranports using mboxes or smc-id property

This is to add smc/hvc transports support, based on Viresh's v6. SCMI firmware could be implemented in EL3, S-EL1, NS-EL2 or other A core exception level. Then smc/hvc could be used. And for vendor specific firmware, a wrapper layer could added in EL3, S-EL1, NS-EL2 and etc to translate SCMI calls to vendor specific firmware calls.

A new compatible string arm,scmi-smc is added. arm,scmi is still for mailbox transports.

All protocol share same smc/hvc id, the protocol id will be take as 2nd arg when issue smc/hvc.
Each protocol could use its own shmem or share the same shmem Per smc/hvc, only Tx supported.

Peng Fan (2):
dt-bindings: arm: arm,scmi: add smc/hvc transports
firmware: arm_scmi: add smc/hvc transports

 Documentation/devicetree/bindings/arm/arm,scmi.txt |   1 +
 drivers/firmware/arm_scmi/Makefile                 |   2 +-
 drivers/firmware/arm_scmi/common.h                 |   4 +-
 drivers/firmware/arm_scmi/driver.c                 |  11 +-
 drivers/firmware/arm_scmi/mailbox.c                |   2 +-
 drivers/firmware/arm_scmi/smc.c                    | 222 +++++++++++++++++++++
 6 files changed, 235 insertions(+), 7 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/smc.c
Signature · 1 line
2.16.4
#1 lore raw

PATCH v2 1/2 dt-bindings: arm: arm,scmi: add smc/hvc transports

From: Peng Fan <[email protected]>

SCMI could use SMC/HVC as tranports. Since there is no standardized id, we need to use vendor specific id. So add into devicetree binding doc.

---
 Documentation/devicetree/bindings/arm/arm,scmi.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/arm/arm,scmi.txt +1 -0
index f493d69e6194..dacc62dc248b 100644
@@ -25,6 +25,7 @@ The scmi node with the following properties shall be under the /firmware/ node.
 	  protocol identifier for a given sub-node.
 - #size-cells : should be '0' as 'reg' property doesn't have any size
 	  associated with it.
+- smc-id : SMC id required when using smc or hvc transports
 
 Optional properties:
 
Signature · 1 line
2.16.4
#2 lore raw

Re: [PATCH V2 1/2] dt-bindings: arm: arm,scmi: add smc/hvc transports

Quoted 16 lines · On Thu, Feb 13, 2020 at 11:58:49AM +0800, [email protected] wrote:

From: Peng Fan <[email protected]>

SCMI could use SMC/HVC as tranports. Since there is no standardized id, we need to use vendor specific id. So add into devicetree binding doc.

---
 Documentation/devicetree/bindings/arm/arm,scmi.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/arm/arm,scmi.txt +0 -0
index f493d69e6194..dacc62dc248b 100644

Documentation/devicetree/bindings/arm/arm,scmi.txt The scmi node with the following properties shall be under the /firmware/ node. · line 28

Quoted 4 lines
Documentation/devicetree/bindings/arm/arm,scmi.txt +1 -0
@@ -25,6 +25,7 @@ The scmi node with the following properties shall be under the /firmware/ node.
 	  protocol identifier for a given sub-node.
 - #size-cells : should be '0' as 'reg' property doesn't have any size
 	  associated with it.
+- smc-id : SMC id required when using smc or hvc transports

IIUC, "arm,smc-id" is preferred more.

Why did you drop "arm,scmi-smc" ?

--
Regards,
Sudeep

author
#3 lore raw

RE: [PATCH V2 1/2] dt-bindings: arm: arm,scmi: add smc/hvc transports

Hi Sudeep,

Quoted 22 lines

Subject: Re: [PATCH V2 1/2] dt-bindings: arm: arm,scmi: add smc/hvc transports

Documentation/devicetree/bindings/arm/arm,scmi.txt The scmi node with the following properties shall be

Quoted 17 lines · On Thu, Feb 13, 2020 at 11:58:49AM +0800, [email protected] wrote:

From: Peng Fan <[email protected]>

SCMI could use SMC/HVC as tranports. Since there is no standardized id, we need to use vendor specific id. So add into devicetree binding doc.

---
 Documentation/devicetree/bindings/arm/arm,scmi.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/arm/arm,scmi.txt +0 -0
index f493d69e6194..dacc62dc248b 100644
@@ -25,6 +25,7 @@ The scmi node with the following properties shall be

under the /firmware/ node.

Quoted 6 lines

Documentation/devicetree/bindings/arm/arm,scmi.txt The scmi node with the following properties shall be under the /firmware/ node. · line 28

Quoted 4 lines
Documentation/devicetree/bindings/arm/arm,scmi.txt +1 -0
 	  protocol identifier for a given sub-node.
 - #size-cells : should be '0' as 'reg' property doesn't have any size
 	  associated with it.
+- smc-id : SMC id required when using smc or hvc transports

IIUC, "arm,smc-id" is preferred more.

ok. Fix in v3.

Quoted 2 lines

Why did you drop "arm,scmi-smc" ?

Per our discuss in v1 patchset, mailbox/smc-id could be used to differentiate mailbox and smc transports.

https://lkml.org/lkml/2020/2/11/226

So I still use "arm,scmi" for smc tranports.

Thanks,
Peng.

Quoted 4 lines

--
Regards,
Sudeep

#4 lore raw

PATCH v2 2/2 firmware: arm_scmi: add smc/hvc transports

In reply to [email protected]

From: Peng Fan <[email protected]>

Add SCMI smc/hvc transports support.

Take smc-id as the 2nd arg, and protocol id as the 2nd arg when invokding SMC/HVC. Since we need protocol id, so add this parrameter to chan_setup, then smc transport driver could directly use it. There is no Rx, only Tx because of smc/hvc not support Rx.

---
 drivers/firmware/arm_scmi/Makefile  |   2 +-
 drivers/firmware/arm_scmi/common.h  |   4 +-
 drivers/firmware/arm_scmi/driver.c  |  11 +-
 drivers/firmware/arm_scmi/mailbox.c |   2 +-
 drivers/firmware/arm_scmi/smc.c     | 222 ++++++++++++++++++++++++++++++++++++
 5 files changed, 234 insertions(+), 7 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/smc.c
drivers/firmware/arm_scmi/Makefile +1 -1
index 6694d0d908d6..6b1b0d6c6d0e 100644
@@ -2,6 +2,6 @@
 obj-y	= scmi-bus.o scmi-driver.o scmi-protocols.o scmi-transport.o
 scmi-bus-y = bus.o
 scmi-driver-y = driver.o
-scmi-transport-y = mailbox.o shmem.o
+scmi-transport-y = mailbox.o shmem.o smc.o
 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o
 obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o
drivers/firmware/arm_scmi/common.h +3 -1
index fd091a4ccbff..b8cd33be8272 100644
@@ -182,7 +182,8 @@ struct scmi_chan_info {
  */
 struct scmi_transport_ops {
 	bool (*chan_available)(struct device *dev, int idx);
-	int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, bool tx);
+	int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev,
+			  int prot_id, bool tx);
 	int (*chan_free)(int id, void *p, void *data);
 	int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer);
 	void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret);
@@ -207,6 +208,7 @@ struct scmi_desc {
 };
 
 extern const struct scmi_desc scmi_mailbox_desc;
+extern const struct scmi_desc scmi_smc_desc;
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr);
 void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id);
drivers/firmware/arm_scmi/driver.c +7 -4
index dbec767222e9..65c56328e6d8 100644
@@ -595,7 +595,7 @@ static int scmi_chan_setup(struct scmi_info *info, struct device *dev,
 
 	cinfo->dev = dev;
 
-	ret = info->desc->ops->chan_setup(cinfo, info->dev, tx);
+	ret = info->desc->ops->chan_setup(cinfo, info->dev, prot_id, tx);
 	if (ret)
 		return ret;
 
@@ -687,8 +687,11 @@ static int scmi_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *child, *np = dev->of_node;
 
-	desc = of_device_get_match_data(dev);
-	if (!desc)
+	if (of_get_property(np, "mboxes", NULL))
+		desc = &scmi_mailbox_desc;
+	else if (of_get_property(np, "smc-id", NULL))
+		desc = &scmi_smc_desc;
+	else
 		return -EINVAL;
 
 	info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
@@ -826,7 +829,7 @@ ATTRIBUTE_GROUPS(versions);
 
 /* Each compatible listed below must have descriptor associated with it */
 static const struct of_device_id scmi_of_match[] = {
-	{ .compatible = "arm,scmi", .data = &scmi_mailbox_desc },
+	{ .compatible = "arm,scmi",  },
 	{ /* Sentinel */ },
 };
 
drivers/firmware/arm_scmi/mailbox.c +1 -1
index 73077bbc4ad9..b06d5d30fe90 100644
@@ -53,7 +53,7 @@ static bool mailbox_chan_available(struct device *dev, int idx)
 }
 
 static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
-			      bool tx)
+			      int prot_id, bool tx)
 {
 	const char *desc = tx ? "Tx" : "Rx";
 	struct device *cdev = cinfo->dev;
drivers/firmware/arm_scmi/smc.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.16.4
#5 lore raw

Re: [PATCH V2 2/2] firmware: arm_scmi: add smc/hvc transports

Quoted 18 lines · On Thu, Feb 13, 2020 at 11:58:50AM +0800, [email protected] wrote:

From: Peng Fan <[email protected]>

Add SCMI smc/hvc transports support.

Take smc-id as the 2nd arg, and protocol id as the 2nd arg when invokding SMC/HVC. Since we need protocol id, so add this parrameter to chan_setup, then smc transport driver could directly use it. There is no Rx, only Tx because of smc/hvc not support Rx.

---
 drivers/firmware/arm_scmi/Makefile  |   2 +-
 drivers/firmware/arm_scmi/common.h  |   4 +-
 drivers/firmware/arm_scmi/driver.c  |  11 +-
 drivers/firmware/arm_scmi/mailbox.c |   2 +-
 drivers/firmware/arm_scmi/smc.c     | 222 ++++++++++++++++++++++++++++++++++++
 5 files changed, 234 insertions(+), 7 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/smc.c

[...]

drivers/firmware/arm_scmi/driver.c static int scmi_chan_setup(struct scmi_info *info, struct device *dev, · line 598

Quoted 11 lines
drivers/firmware/arm_scmi/driver.c +1 -1
index dbec767222e9..65c56328e6d8 100644
@@ -595,7 +595,7 @@ static int scmi_chan_setup(struct scmi_info *info, struct device *dev,
 
 	cinfo->dev = dev;
 
-	ret = info->desc->ops->chan_setup(cinfo, info->dev, tx);
+	ret = info->desc->ops->chan_setup(cinfo, info->dev, prot_id, tx);

Why do you need this ?

drivers/firmware/arm_scmi/driver.c ATTRIBUTE_GROUPS(versions); · line 832

Quoted 9 lines
drivers/firmware/arm_scmi/driver.c +1 -1
 	if (ret)
 		return ret;
 
@@ -826,7 +829,7 @@ ATTRIBUTE_GROUPS(versions);
 
 /* Each compatible listed below must have descriptor associated with it */
 static const struct of_device_id scmi_of_match[] = {
-	{ .compatible = "arm,scmi", .data = &scmi_mailbox_desc },
+	{ .compatible = "arm,scmi",  },

Don't do this, get "arm,scmi-smc"

Quoted 3 lines
drivers/firmware/arm_scmi/driver.c +0 -0
 	{ /* Sentinel */ },
 };
 

[...]

Quoted 40 lines
drivers/firmware/arm_scmi/driver.c +40 -0
+static unsigned long
+__invoke_scmi_fn_hvc(unsigned long function_id, unsigned long arg0,
+		     unsigned long arg1, unsigned long arg2,
+		     unsigned long arg3, unsigned long arg4,
+		     unsigned long arg5, unsigned long arg6)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, arg5,
+		      arg6, &res);
+
+	return res.a0;
+}
+
+static unsigned long
+__invoke_scmi_fn_smc(unsigned long function_id, unsigned long arg0,
+		     unsigned long arg1, unsigned long arg2,
+		     unsigned long arg3, unsigned long arg4,
+		     unsigned long arg5, unsigned long arg6)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(function_id, arg0, arg1, arg2, arg3, arg4, arg5,
+		      arg6, &res);
+
+	return res.a0;
+}
+
+static int scmi_smc_conduit_method(struct device_node *np)
+{
+	const char *method;
+
+	if (invoke_scmi_smc_fn)
+		return 0;
+
+	if (of_property_read_string(np, "method", &method))
+		return -ENXIO;
+
+	if (!strcmp("hvc", method)) {
+		invoke_scmi_smc_fn = __invoke_scmi_fn_hvc;

drivers/firmware/arm_scmi/driver.c

Quoted 10 lines
drivers/firmware/arm_scmi/driver.c +10 -0
+	} else if (!strcmp("smc", method)) {
+		invoke_scmi_smc_fn = __invoke_scmi_fn_smc;
+	} else {
+		pr_warn("invalid \"method\" property: %s\n", method);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+

You don't the above functions

[...]

drivers/firmware/arm_scmi/driver.c

Quoted 6 lines
drivers/firmware/arm_scmi/driver.c +6 -0
+
+	np = of_find_node_by_path("/psci");
+	if (!np) {
+		dev_err(dev, "Not able to find /psci node\n");
+		return -ENODEV;
+	}

No need for this as mentioned below.

drivers/firmware/arm_scmi/driver.c

Quoted 2 lines
drivers/firmware/arm_scmi/driver.c +2 -0
+
+	ret = scmi_smc_conduit_method(np);

Just use arm_smccc_1_1_get_conduit if you want to get the conduit which I don't think you need. You can just use arm_smccc_1_1_invoke() directly.

--
Regards,
Sudeep

author
#6 lore raw

RE: [PATCH V2 2/2] firmware: arm_scmi: add smc/hvc transports

Hi Sudeep,

Quoted 34 lines

Subject: Re: [PATCH V2 2/2] firmware: arm_scmi: add smc/hvc transports

Quoted 9 lines · On Thu, Feb 13, 2020 at 11:58:50AM +0800, [email protected] wrote:

From: Peng Fan <[email protected]>

Add SCMI smc/hvc transports support.

Take smc-id as the 2nd arg, and protocol id as the 2nd arg when invokding SMC/HVC. Since we need protocol id, so add this parrameter to chan_setup, then smc transport driver could directly use it. There is no Rx, only Tx because of smc/hvc not support Rx.

Quoted 7 lines
---
 drivers/firmware/arm_scmi/Makefile  |   2 +-
 drivers/firmware/arm_scmi/common.h  |   4 +-
 drivers/firmware/arm_scmi/driver.c  |  11 +-
 drivers/firmware/arm_scmi/mailbox.c |   2 +-
 drivers/firmware/arm_scmi/smc.c     | 222

++++++++++++++++++++++++++++++++++++

Quoted 2 lines
 5 files changed, 234 insertions(+), 7 deletions(-)  create mode

100644 drivers/firmware/arm_scmi/smc.c

[...]

Quoted 9 lines
drivers/firmware/arm_scmi/driver.c +0 -0
index dbec767222e9..65c56328e6d8 100644
@@ -595,7 +595,7 @@ static int scmi_chan_setup(struct scmi_info *info,
 struct device *dev,
 
Quoted 6 lines

drivers/firmware/arm_scmi/driver.c static int scmi_chan_setup(struct scmi_info *info, struct device *dev, · line 598

Quoted 4 lines
drivers/firmware/arm_scmi/driver.c +1 -1
 	cinfo->dev = dev;
 
-	ret = info->desc->ops->chan_setup(cinfo, info->dev, tx);
+	ret = info->desc->ops->chan_setup(cinfo, info->dev, prot_id, tx);

Why do you need this ?

For smc tranports, all protocols share same smd-id, but if protocols not share the same shmem, we need let firmare know which protocol issues the smc call. So I take prot_id as an arguments of smc call.

Quoted 4 lines
Quoted 4 lines
drivers/firmware/arm_scmi/driver.c +0 -0
 	if (ret)
 		return ret;
Quoted 8 lines

drivers/firmware/arm_scmi/driver.c ATTRIBUTE_GROUPS(versions); · line 832

Quoted 6 lines
drivers/firmware/arm_scmi/driver.c +1 -1
@@ -826,7 +829,7 @@ ATTRIBUTE_GROUPS(versions);
 
 /* Each compatible listed below must have descriptor associated with
 it */  static const struct of_device_id scmi_of_match[] = {
-	{ .compatible = "arm,scmi", .data = &scmi_mailbox_desc },
+	{ .compatible = "arm,scmi",  },

Don't do this, get "arm,scmi-smc"

You mean code as below?
/* Each compatible listed below must have descriptor associated with it */

static const struct of_device_id scmi_of_match[] = {
         { .compatible = "arm,scmi", .data = &scmi_mailbox_desc },
         { .compatible = "arm,scmi-smc", .data = &scmi_smc_desc },
         { /* Sentinel */ },
};

But since we could use mboxes and smc-id to know the tranports type, do we really need arm,scmi-smc?

Quoted 48 lines
Quoted 4 lines
drivers/firmware/arm_scmi/driver.c +0 -0
 	{ /* Sentinel */ },
 };
 

[...]

Quoted 41 lines
drivers/firmware/arm_scmi/driver.c +41 -0
+static unsigned long
+__invoke_scmi_fn_hvc(unsigned long function_id, unsigned long arg0,
+		     unsigned long arg1, unsigned long arg2,
+		     unsigned long arg3, unsigned long arg4,
+		     unsigned long arg5, unsigned long arg6) {
+	struct arm_smccc_res res;
+
+	arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, arg5,
+		      arg6, &res);
+
+	return res.a0;
+}
+
+static unsigned long
+__invoke_scmi_fn_smc(unsigned long function_id, unsigned long arg0,
+		     unsigned long arg1, unsigned long arg2,
+		     unsigned long arg3, unsigned long arg4,
+		     unsigned long arg5, unsigned long arg6) {
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(function_id, arg0, arg1, arg2, arg3, arg4, arg5,
+		      arg6, &res);
+
+	return res.a0;
+}
+
+static int scmi_smc_conduit_method(struct device_node *np) {
+	const char *method;
+
+	if (invoke_scmi_smc_fn)
+		return 0;
+
+	if (of_property_read_string(np, "method", &method))
+		return -ENXIO;
+
+	if (!strcmp("hvc", method)) {
+		invoke_scmi_smc_fn = __invoke_scmi_fn_hvc;
+	} else if (!strcmp("smc", method)) {
+		invoke_scmi_smc_fn = __invoke_scmi_fn_smc;
+	} else {
+		pr_warn("invalid \"method\" property: %s\n", method);
Quoted 8 lines

drivers/firmware/arm_scmi/driver.c

Quoted 6 lines
drivers/firmware/arm_scmi/driver.c +6 -0
+		return -EINVAL;
+	}
+
+	return 0;
+}
+

You don't the above functions

ok

Quoted 11 lines

[...]

drivers/firmware/arm_scmi/driver.c

Quoted 6 lines
drivers/firmware/arm_scmi/driver.c +6 -0
+
+	np = of_find_node_by_path("/psci");
+	if (!np) {
+		dev_err(dev, "Not able to find /psci node\n");
+		return -ENODEV;
+	}

No need for this as mentioned below.

ok

Quoted 6 lines

drivers/firmware/arm_scmi/driver.c

Quoted 3 lines
drivers/firmware/arm_scmi/driver.c +2 -0
+
+	ret = scmi_smc_conduit_method(np);

Just use arm_smccc_1_1_get_conduit if you want to get the conduit which I don't think you need. You can just use arm_smccc_1_1_invoke() directly.

Fix in v3.

I'll post v3 after we have an agreement on whether we need a new compatible string arm,scmi-smc and the prot_id introduced in chan_setup.

Thanks,
Peng.

Quoted 4 lines

--
Regards,
Sudeep