All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add qcom hvc/shmem transport
@ 2023-07-18 16:08 ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 16:08 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change introduce a new transport channel for Qualcomm virtual
platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
The difference between the two transports is that a parameter is passed in
the hypervisor call to identify which doorbell to assert. This parameter is
dynamically generated at runtime on the device and insuitable to pass via
the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

Nikunj Kela (2):
  dt-bindings: arm: Add qcom specific hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport

 .../bindings/firmware/arm,scmi.yaml           |  69 +++++
 drivers/firmware/arm_scmi/Kconfig             |  13 +
 drivers/firmware/arm_scmi/Makefile            |   1 +
 drivers/firmware/arm_scmi/common.h            |   3 +
 drivers/firmware/arm_scmi/driver.c            |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c          | 241 ++++++++++++++++++
 6 files changed, 331 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

-- 
2.17.1


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

* [PATCH 0/2] Add qcom hvc/shmem transport
@ 2023-07-18 16:08 ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 16:08 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change introduce a new transport channel for Qualcomm virtual
platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
The difference between the two transports is that a parameter is passed in
the hypervisor call to identify which doorbell to assert. This parameter is
dynamically generated at runtime on the device and insuitable to pass via
the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

Nikunj Kela (2):
  dt-bindings: arm: Add qcom specific hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport

 .../bindings/firmware/arm,scmi.yaml           |  69 +++++
 drivers/firmware/arm_scmi/Kconfig             |  13 +
 drivers/firmware/arm_scmi/Makefile            |   1 +
 drivers/firmware/arm_scmi/common.h            |   3 +
 drivers/firmware/arm_scmi/driver.c            |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c          | 241 ++++++++++++++++++
 6 files changed, 331 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

-- 
2.17.1


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

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

* [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-07-18 16:08   ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 16:08 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..605b1e997a85 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -321,6 +324,16 @@ else:
       required:
         - linaro,optee-channel-id
 
+    else:
+      if:
+        properties:
+          compatible:
+            contains:
+              const: qcom,scmi-hvc-shmem
+      then:
+        required:
+          - shmem
+
 examples:
   - |
     firmware {
@@ -444,6 +457,62 @@ examples:
         };
     };
 
+  - |
+    firmware {
+        scmi_dpu {
+            compatible = "qcom,scmi-hvc-shmem";
+            shmem = <&shmem_dpu>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            scmi_pd_dpu: protocol@11 {
+                reg = <0x11>;
+                #power-domain-cells = <1>;
+            };
+        };
+
+        scmi_gpu {
+            compatible = "qcom,scmi-hvc-shmem";
+            shmem = <&shmem_gpu>;
+
+            interrupts = <GIC_SPI 931 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "a2p";
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            scmi_pd_gpu: protocol@11 {
+                reg = <0x11>;
+                #power-domain-cells = <1>;
+            };
+        };
+    };
+
+    soc {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        sram@95c00000 {
+            compatible = "mmio-sram";
+            reg = <0x95c00000 0x10000>;
+
+            #address-cells = <1>;
+            #size-cells = <1>;
+            ranges;
+
+            shmem_dpu: scmi-sram-dpu@95c00000 {
+                compatible = "arm,scmi-shmem";
+                reg = <0x95c00000 0x3f0>;
+            };
+
+            shmem_gpu: scmi-sram-gpu@95c00400 {
+                compatible = "arm,scmi-shmem";
+                reg = <0x95c00400 0x3f0>;
+            };
+        };
+    };
+
   - |
     firmware {
         scmi {
-- 
2.17.1


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

* [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-07-18 16:08   ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 16:08 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..605b1e997a85 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -321,6 +324,16 @@ else:
       required:
         - linaro,optee-channel-id
 
+    else:
+      if:
+        properties:
+          compatible:
+            contains:
+              const: qcom,scmi-hvc-shmem
+      then:
+        required:
+          - shmem
+
 examples:
   - |
     firmware {
@@ -444,6 +457,62 @@ examples:
         };
     };
 
+  - |
+    firmware {
+        scmi_dpu {
+            compatible = "qcom,scmi-hvc-shmem";
+            shmem = <&shmem_dpu>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            scmi_pd_dpu: protocol@11 {
+                reg = <0x11>;
+                #power-domain-cells = <1>;
+            };
+        };
+
+        scmi_gpu {
+            compatible = "qcom,scmi-hvc-shmem";
+            shmem = <&shmem_gpu>;
+
+            interrupts = <GIC_SPI 931 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "a2p";
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            scmi_pd_gpu: protocol@11 {
+                reg = <0x11>;
+                #power-domain-cells = <1>;
+            };
+        };
+    };
+
+    soc {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        sram@95c00000 {
+            compatible = "mmio-sram";
+            reg = <0x95c00000 0x10000>;
+
+            #address-cells = <1>;
+            #size-cells = <1>;
+            ranges;
+
+            shmem_dpu: scmi-sram-dpu@95c00000 {
+                compatible = "arm,scmi-shmem";
+                reg = <0x95c00000 0x3f0>;
+            };
+
+            shmem_gpu: scmi-sram-gpu@95c00400 {
+                compatible = "arm,scmi-shmem";
+                reg = <0x95c00400 0x3f0>;
+            };
+        };
+    };
+
   - |
     firmware {
         scmi {
-- 
2.17.1


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

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

* [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-07-18 16:08   ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 16:08 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Add a new transport channel to the SCMI firmware interface driver for
SCMI message exchange on Qualcomm virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The qcom hvc doorbell/shared memory transport uses a statically defined
shared memory region that binds with "arm,scmi-shmem" device tree node.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig    |  13 ++
 drivers/firmware/arm_scmi/Makefile   |   1 +
 drivers/firmware/arm_scmi/common.h   |   3 +
 drivers/firmware/arm_scmi/driver.c   |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c | 241 +++++++++++++++++++++++++++
 5 files changed, 262 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..40d07329ebf7 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -99,6 +99,19 @@ config ARM_SCMI_TRANSPORT_OPTEE
 	  If you want the ARM SCMI PROTOCOL stack to include support for a
 	  transport based on OP-TEE SCMI service, answer Y.
 
+config ARM_SCMI_TRANSPORT_QCOM_HVC
+	bool "SCMI transport based on hvc doorbell & shmem for Qualcomm SoCs"
+	depends on ARCH_QCOM
+	select ARM_SCMI_HAVE_TRANSPORT
+	select ARM_SCMI_HAVE_SHMEM
+	default y
+	help
+	  Enable hvc doorbell & shmem based transport for SCMI.
+
+	  If you want the ARM SCMI PROTOCOL stack to include support for a
+	  hvc doorbell and shmem transport on Qualcomm virtual platforms,
+	  answer Y.
+
 config ARM_SCMI_TRANSPORT_SMC
 	bool "SCMI transport based on SMC"
 	depends on HAVE_ARM_SMCCC_DISCOVERY
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index b31d78fa66cc..ba1ff5893ec0 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -10,6 +10,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o
+scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC) += qcom_hvc.o
 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o
 scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
 
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index c46dc5215af7..5c98cbb1278b 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -298,6 +298,9 @@ extern const struct scmi_desc scmi_virtio_desc;
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE
 extern const struct scmi_desc scmi_optee_desc;
 #endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+extern const struct scmi_desc scmi_qcom_hvc_desc;
+#endif
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv);
 
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index b5957cc12fee..c54519596c29 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2918,6 +2918,10 @@ static const struct of_device_id scmi_of_match[] = {
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
+#endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+	{ .compatible = "qcom,scmi-hvc-shmem",
+	  .data = &scmi_qcom_hvc_desc },
 #endif
 	{ /* Sentinel */ },
 };
diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
new file mode 100644
index 000000000000..3b6096d8fe67
--- /dev/null
+++ b/drivers/firmware/arm_scmi/qcom_hvc.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) Message
+ * Qualcomm HVC/shmem Transport driver
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright 2020 NXP
+ *
+ * This is copied from drivers/firmware/arm_scmi/smc.c
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/processor.h>
+#include <linux/slab.h>
+
+#include "common.h"
+
+/**
+ * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
+ *
+ * @cinfo: SCMI channel info
+ * @shmem: Transmit/Receive shared memory area
+ * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
+ * @func_id: hvc call function-id
+ * @cap_id: hvc doorbell's capability id
+ */
+
+struct scmi_qcom_hvc {
+	struct scmi_chan_info *cinfo;
+	struct scmi_shared_mem __iomem *shmem;
+	/* Protect access to shmem area */
+	struct mutex shmem_lock;
+	u32 func_id;
+	unsigned long cap_id;
+};
+
+static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
+{
+	struct scmi_qcom_hvc *scmi_info = data;
+
+	scmi_rx_callback(scmi_info->cinfo,
+			 shmem_read_header(scmi_info->shmem), NULL);
+
+	return IRQ_HANDLED;
+}
+
+static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
+{
+	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
+
+	if (!np)
+		return false;
+
+	of_node_put(np);
+	return true;
+}
+
+static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
+{
+	mutex_init(&scmi_info->shmem_lock);
+}
+
+static inline void
+qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
+			      struct scmi_xfer *xfer __maybe_unused)
+{
+	mutex_lock(&scmi_info->shmem_lock);
+}
+
+static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
+						 *scmi_info)
+{
+	mutex_unlock(&scmi_info->shmem_lock);
+}
+
+static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
+			       struct device *dev, bool tx)
+{
+	struct device *cdev = cinfo->dev;
+	struct scmi_qcom_hvc *scmi_info;
+	resource_size_t size;
+	struct resource res;
+	struct device_node *np;
+	unsigned long cap_id;
+	u32 func_id;
+	int ret, irq;
+
+	if (!tx)
+		return -ENODEV;
+
+	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
+	if (!scmi_info)
+		return -ENOMEM;
+
+	np = of_parse_phandle(cdev->of_node, "shmem", 0);
+	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
+		return -ENXIO;
+
+	ret = of_address_to_resource(np, 0, &res);
+	of_node_put(np);
+	if (ret) {
+		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
+		return ret;
+	}
+
+	size = resource_size(&res);
+
+	/* let's map 2 additional ulong since
+	 * func-id & capability-id are kept after shmem.
+	 *     +-------+
+	 *     |       |
+	 *     | shmem |
+	 *     |       |
+	 *     |       |
+	 *     +-------+ <-- size
+	 *     | funcId|
+	 *     +-------+ <-- size + sizeof(ulong)
+	 *     | capId |
+	 *     +-------+ <-- size + 2*sizeof(ulong)
+	 */
+
+	scmi_info->shmem = devm_ioremap(dev, res.start,
+					size + 2 * sizeof(unsigned long));
+	if (!scmi_info->shmem) {
+		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
+		return -EADDRNOTAVAIL;
+	}
+
+	func_id = readl((void *)(scmi_info->shmem) + size);
+
+#ifdef CONFIG_ARM64
+	cap_id = readq((void *)(scmi_info->shmem) + size +
+		       sizeof(unsigned long));
+#else
+	cap_id = readl((void *)(scmi_info->shmem) + size +
+		       sizeof(unsigned long));
+#endif
+
+	/*
+	 * If there is an interrupt named "a2p", then the service and
+	 * completion of a message is signaled by an interrupt rather than by
+	 * the return of the hvc call.
+	 */
+	irq = of_irq_get_byname(cdev->of_node, "a2p");
+	if (irq > 0) {
+		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
+				       IRQF_NO_SUSPEND,
+				       dev_name(dev), scmi_info);
+		if (ret) {
+			dev_err(dev, "failed to setup SCMI completion irq\n");
+			return ret;
+		}
+	} else {
+		cinfo->no_completion_irq = true;
+	}
+
+	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
+	scmi_info->cinfo = cinfo;
+	qcom_hvc_channel_lock_init(scmi_info);
+	cinfo->transport_info = scmi_info;
+
+	return 0;
+}
+
+static int qcom_hvc_chan_free(int id, void *p, void *data)
+{
+	struct scmi_chan_info *cinfo = p;
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	cinfo->transport_info = NULL;
+	scmi_info->cinfo = NULL;
+
+	return 0;
+}
+
+static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
+				 struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+	struct arm_smccc_res res;
+
+	/*
+	 * Channel will be released only once response has been
+	 * surely fully retrieved, so after .mark_txdone()
+	 */
+	qcom_hvc_channel_lock_acquire(scmi_info, xfer);
+
+	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
+
+	arm_smccc_1_1_hvc(scmi_info->func_id, scmi_info->cap_id,
+			  0, 0, 0, 0, 0, 0, &res);
+
+	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
+	if (res.a0) {
+		qcom_hvc_channel_lock_release(scmi_info);
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
+				    struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	shmem_fetch_response(scmi_info->shmem, xfer);
+}
+
+static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
+				 struct scmi_xfer *__unused)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	qcom_hvc_channel_lock_release(scmi_info);
+}
+
+static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
+	.chan_available = qcom_hvc_chan_available,
+	.chan_setup = qcom_hvc_chan_setup,
+	.chan_free = qcom_hvc_chan_free,
+	.send_message = qcom_hvc_send_message,
+	.mark_txdone = qcom_hvc_mark_txdone,
+	.fetch_response = qcom_hvc_fetch_response,
+};
+
+const struct scmi_desc scmi_qcom_hvc_desc = {
+	.ops = &scmi_qcom_hvc_ops,
+	.max_rx_timeout_ms = 30,
+	.max_msg = 20,
+	.max_msg_size = 128,
+	.sync_cmds_completed_on_ret = true,
+};
-- 
2.17.1


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

* [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 16:08   ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 16:08 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Add a new transport channel to the SCMI firmware interface driver for
SCMI message exchange on Qualcomm virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The qcom hvc doorbell/shared memory transport uses a statically defined
shared memory region that binds with "arm,scmi-shmem" device tree node.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig    |  13 ++
 drivers/firmware/arm_scmi/Makefile   |   1 +
 drivers/firmware/arm_scmi/common.h   |   3 +
 drivers/firmware/arm_scmi/driver.c   |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c | 241 +++++++++++++++++++++++++++
 5 files changed, 262 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..40d07329ebf7 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -99,6 +99,19 @@ config ARM_SCMI_TRANSPORT_OPTEE
 	  If you want the ARM SCMI PROTOCOL stack to include support for a
 	  transport based on OP-TEE SCMI service, answer Y.
 
+config ARM_SCMI_TRANSPORT_QCOM_HVC
+	bool "SCMI transport based on hvc doorbell & shmem for Qualcomm SoCs"
+	depends on ARCH_QCOM
+	select ARM_SCMI_HAVE_TRANSPORT
+	select ARM_SCMI_HAVE_SHMEM
+	default y
+	help
+	  Enable hvc doorbell & shmem based transport for SCMI.
+
+	  If you want the ARM SCMI PROTOCOL stack to include support for a
+	  hvc doorbell and shmem transport on Qualcomm virtual platforms,
+	  answer Y.
+
 config ARM_SCMI_TRANSPORT_SMC
 	bool "SCMI transport based on SMC"
 	depends on HAVE_ARM_SMCCC_DISCOVERY
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index b31d78fa66cc..ba1ff5893ec0 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -10,6 +10,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o
+scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC) += qcom_hvc.o
 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o
 scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
 
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index c46dc5215af7..5c98cbb1278b 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -298,6 +298,9 @@ extern const struct scmi_desc scmi_virtio_desc;
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE
 extern const struct scmi_desc scmi_optee_desc;
 #endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+extern const struct scmi_desc scmi_qcom_hvc_desc;
+#endif
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv);
 
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index b5957cc12fee..c54519596c29 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2918,6 +2918,10 @@ static const struct of_device_id scmi_of_match[] = {
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
+#endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+	{ .compatible = "qcom,scmi-hvc-shmem",
+	  .data = &scmi_qcom_hvc_desc },
 #endif
 	{ /* Sentinel */ },
 };
diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
new file mode 100644
index 000000000000..3b6096d8fe67
--- /dev/null
+++ b/drivers/firmware/arm_scmi/qcom_hvc.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) Message
+ * Qualcomm HVC/shmem Transport driver
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright 2020 NXP
+ *
+ * This is copied from drivers/firmware/arm_scmi/smc.c
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/processor.h>
+#include <linux/slab.h>
+
+#include "common.h"
+
+/**
+ * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
+ *
+ * @cinfo: SCMI channel info
+ * @shmem: Transmit/Receive shared memory area
+ * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
+ * @func_id: hvc call function-id
+ * @cap_id: hvc doorbell's capability id
+ */
+
+struct scmi_qcom_hvc {
+	struct scmi_chan_info *cinfo;
+	struct scmi_shared_mem __iomem *shmem;
+	/* Protect access to shmem area */
+	struct mutex shmem_lock;
+	u32 func_id;
+	unsigned long cap_id;
+};
+
+static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
+{
+	struct scmi_qcom_hvc *scmi_info = data;
+
+	scmi_rx_callback(scmi_info->cinfo,
+			 shmem_read_header(scmi_info->shmem), NULL);
+
+	return IRQ_HANDLED;
+}
+
+static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
+{
+	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
+
+	if (!np)
+		return false;
+
+	of_node_put(np);
+	return true;
+}
+
+static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
+{
+	mutex_init(&scmi_info->shmem_lock);
+}
+
+static inline void
+qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
+			      struct scmi_xfer *xfer __maybe_unused)
+{
+	mutex_lock(&scmi_info->shmem_lock);
+}
+
+static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
+						 *scmi_info)
+{
+	mutex_unlock(&scmi_info->shmem_lock);
+}
+
+static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
+			       struct device *dev, bool tx)
+{
+	struct device *cdev = cinfo->dev;
+	struct scmi_qcom_hvc *scmi_info;
+	resource_size_t size;
+	struct resource res;
+	struct device_node *np;
+	unsigned long cap_id;
+	u32 func_id;
+	int ret, irq;
+
+	if (!tx)
+		return -ENODEV;
+
+	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
+	if (!scmi_info)
+		return -ENOMEM;
+
+	np = of_parse_phandle(cdev->of_node, "shmem", 0);
+	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
+		return -ENXIO;
+
+	ret = of_address_to_resource(np, 0, &res);
+	of_node_put(np);
+	if (ret) {
+		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
+		return ret;
+	}
+
+	size = resource_size(&res);
+
+	/* let's map 2 additional ulong since
+	 * func-id & capability-id are kept after shmem.
+	 *     +-------+
+	 *     |       |
+	 *     | shmem |
+	 *     |       |
+	 *     |       |
+	 *     +-------+ <-- size
+	 *     | funcId|
+	 *     +-------+ <-- size + sizeof(ulong)
+	 *     | capId |
+	 *     +-------+ <-- size + 2*sizeof(ulong)
+	 */
+
+	scmi_info->shmem = devm_ioremap(dev, res.start,
+					size + 2 * sizeof(unsigned long));
+	if (!scmi_info->shmem) {
+		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
+		return -EADDRNOTAVAIL;
+	}
+
+	func_id = readl((void *)(scmi_info->shmem) + size);
+
+#ifdef CONFIG_ARM64
+	cap_id = readq((void *)(scmi_info->shmem) + size +
+		       sizeof(unsigned long));
+#else
+	cap_id = readl((void *)(scmi_info->shmem) + size +
+		       sizeof(unsigned long));
+#endif
+
+	/*
+	 * If there is an interrupt named "a2p", then the service and
+	 * completion of a message is signaled by an interrupt rather than by
+	 * the return of the hvc call.
+	 */
+	irq = of_irq_get_byname(cdev->of_node, "a2p");
+	if (irq > 0) {
+		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
+				       IRQF_NO_SUSPEND,
+				       dev_name(dev), scmi_info);
+		if (ret) {
+			dev_err(dev, "failed to setup SCMI completion irq\n");
+			return ret;
+		}
+	} else {
+		cinfo->no_completion_irq = true;
+	}
+
+	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
+	scmi_info->cinfo = cinfo;
+	qcom_hvc_channel_lock_init(scmi_info);
+	cinfo->transport_info = scmi_info;
+
+	return 0;
+}
+
+static int qcom_hvc_chan_free(int id, void *p, void *data)
+{
+	struct scmi_chan_info *cinfo = p;
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	cinfo->transport_info = NULL;
+	scmi_info->cinfo = NULL;
+
+	return 0;
+}
+
+static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
+				 struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+	struct arm_smccc_res res;
+
+	/*
+	 * Channel will be released only once response has been
+	 * surely fully retrieved, so after .mark_txdone()
+	 */
+	qcom_hvc_channel_lock_acquire(scmi_info, xfer);
+
+	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
+
+	arm_smccc_1_1_hvc(scmi_info->func_id, scmi_info->cap_id,
+			  0, 0, 0, 0, 0, 0, &res);
+
+	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
+	if (res.a0) {
+		qcom_hvc_channel_lock_release(scmi_info);
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
+				    struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	shmem_fetch_response(scmi_info->shmem, xfer);
+}
+
+static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
+				 struct scmi_xfer *__unused)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	qcom_hvc_channel_lock_release(scmi_info);
+}
+
+static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
+	.chan_available = qcom_hvc_chan_available,
+	.chan_setup = qcom_hvc_chan_setup,
+	.chan_free = qcom_hvc_chan_free,
+	.send_message = qcom_hvc_send_message,
+	.mark_txdone = qcom_hvc_mark_txdone,
+	.fetch_response = qcom_hvc_fetch_response,
+};
+
+const struct scmi_desc scmi_qcom_hvc_desc = {
+	.ops = &scmi_qcom_hvc_ops,
+	.max_rx_timeout_ms = 30,
+	.max_msg = 20,
+	.max_msg_size = 128,
+	.sync_cmds_completed_on_ret = true,
+};
-- 
2.17.1


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

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-18 16:08   ` Nikunj Kela
@ 2023-07-18 17:21     ` Rob Herring
  -1 siblings, 0 replies; 186+ messages in thread
From: Rob Herring @ 2023-07-18 17:21 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: linux-arm-kernel, linux-kernel, agross, sudeep.holla, devicetree,
	konrad.dybcio, robh+dt, krzysztof.kozlowski+dt, andersson,
	linux-arm-msm, conor+dt, cristian.marussi


On Tue, 18 Jul 2023 09:08:32 -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/firmware/arm,scmi.example.dts:194.31-32 syntax error
FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.lib:419: Documentation/devicetree/bindings/firmware/arm,scmi.example.dtb] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1500: dt_binding_check] Error 2
make: *** [Makefile:234: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230718160833.36397-2-quic_nkela@quicinc.com

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-07-18 17:21     ` Rob Herring
  0 siblings, 0 replies; 186+ messages in thread
From: Rob Herring @ 2023-07-18 17:21 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: linux-arm-kernel, linux-kernel, agross, sudeep.holla, devicetree,
	konrad.dybcio, robh+dt, krzysztof.kozlowski+dt, andersson,
	linux-arm-msm, conor+dt, cristian.marussi


On Tue, 18 Jul 2023 09:08:32 -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/firmware/arm,scmi.example.dts:194.31-32 syntax error
FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.lib:419: Documentation/devicetree/bindings/firmware/arm,scmi.example.dtb] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1500: dt_binding_check] Error 2
make: *** [Makefile:234: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230718160833.36397-2-quic_nkela@quicinc.com

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


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

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-18 16:08   ` Nikunj Kela
@ 2023-07-18 18:12     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-18 18:12 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 18:08, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> index b138f3d23df8..605b1e997a85 100644
> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> @@ -45,6 +45,9 @@ properties:
>        - description: SCMI compliant firmware with OP-TEE transport
>          items:
>            - const: linaro,scmi-optee
> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> +        items:
> +          - const: qcom,scmi-hvc-shmem
>  
>    interrupts:
>      description:
> @@ -321,6 +324,16 @@ else:
>        required:
>          - linaro,optee-channel-id
>  
> +    else:
> +      if:
> +        properties:
> +          compatible:
> +            contains:
> +              const: qcom,scmi-hvc-shmem
> +      then:
> +        required:
> +          - shmem

Unfortunately this pattern if-else-if-else-if-else does not scale well.
Please convert all entries first to allOf:if:then,if:then,if:then (in
new patch), and then add new if:then:

> +
>  examples:
>    - |
>      firmware {
> @@ -444,6 +457,62 @@ examples:
>          };
>      };
>  
> +  - |
> +    firmware {
> +        scmi_dpu {

No underscores in node names.

Node names should be generic. See also an explanation and list of
examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation



> +            compatible = "qcom,scmi-hvc-shmem";
> +            shmem = <&shmem_dpu>;
> +
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            scmi_pd_dpu: protocol@11 {
> +                reg = <0x11>;
> +                #power-domain-cells = <1>;
> +            };
> +        };
> +

Add only one example, but then only if it differs significantly. I see
no differences - except compatible - so maybe no point of examples.


> +        scmi_gpu {
> +            compatible = "qcom,scmi-hvc-shmem";
> +            shmem = <&shmem_gpu>;

This example for sure is not needed - you duplicate above.

> +
> +            interrupts = <GIC_SPI 931 IRQ_TYPE_EDGE_RISING>;
> +            interrupt-names = "a2p";
> +
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            scmi_pd_gpu: protocol@11 {
> +                reg = <0x11>;
> +                #power-domain-cells = <1>;
> +            };
> +        };
> +    };
> +
> +    soc {
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +
> +        sram@95c00000 {
> +            compatible = "mmio-sram";
> +            reg = <0x95c00000 0x10000>;
> +
> +            #address-cells = <1>;
> +            #size-cells = <1>;
> +            ranges;
> +
> +            shmem_dpu: scmi-sram-dpu@95c00000 {
> +                compatible = "arm,scmi-shmem";
> +                reg = <0x95c00000 0x3f0>;
> +            };

How does these differ from existing example?

Best regards,
Krzysztof


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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-07-18 18:12     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-18 18:12 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 18:08, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> index b138f3d23df8..605b1e997a85 100644
> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> @@ -45,6 +45,9 @@ properties:
>        - description: SCMI compliant firmware with OP-TEE transport
>          items:
>            - const: linaro,scmi-optee
> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> +        items:
> +          - const: qcom,scmi-hvc-shmem
>  
>    interrupts:
>      description:
> @@ -321,6 +324,16 @@ else:
>        required:
>          - linaro,optee-channel-id
>  
> +    else:
> +      if:
> +        properties:
> +          compatible:
> +            contains:
> +              const: qcom,scmi-hvc-shmem
> +      then:
> +        required:
> +          - shmem

Unfortunately this pattern if-else-if-else-if-else does not scale well.
Please convert all entries first to allOf:if:then,if:then,if:then (in
new patch), and then add new if:then:

> +
>  examples:
>    - |
>      firmware {
> @@ -444,6 +457,62 @@ examples:
>          };
>      };
>  
> +  - |
> +    firmware {
> +        scmi_dpu {

No underscores in node names.

Node names should be generic. See also an explanation and list of
examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation



> +            compatible = "qcom,scmi-hvc-shmem";
> +            shmem = <&shmem_dpu>;
> +
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            scmi_pd_dpu: protocol@11 {
> +                reg = <0x11>;
> +                #power-domain-cells = <1>;
> +            };
> +        };
> +

Add only one example, but then only if it differs significantly. I see
no differences - except compatible - so maybe no point of examples.


> +        scmi_gpu {
> +            compatible = "qcom,scmi-hvc-shmem";
> +            shmem = <&shmem_gpu>;

This example for sure is not needed - you duplicate above.

> +
> +            interrupts = <GIC_SPI 931 IRQ_TYPE_EDGE_RISING>;
> +            interrupt-names = "a2p";
> +
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            scmi_pd_gpu: protocol@11 {
> +                reg = <0x11>;
> +                #power-domain-cells = <1>;
> +            };
> +        };
> +    };
> +
> +    soc {
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +
> +        sram@95c00000 {
> +            compatible = "mmio-sram";
> +            reg = <0x95c00000 0x10000>;
> +
> +            #address-cells = <1>;
> +            #size-cells = <1>;
> +            ranges;
> +
> +            shmem_dpu: scmi-sram-dpu@95c00000 {
> +                compatible = "arm,scmi-shmem";
> +                reg = <0x95c00000 0x3f0>;
> +            };

How does these differ from existing example?

Best regards,
Krzysztof


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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 16:08   ` Nikunj Kela
@ 2023-07-18 18:17     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-18 18:17 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 18:08, Nikunj Kela wrote:
> Add a new transport channel to the SCMI firmware interface driver for
> SCMI message exchange on Qualcomm virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 

...

> +
> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
> +{
> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
> +
> +	if (!np)
> +		return false;
> +
> +	of_node_put(np);
> +	return true;
> +}
> +
> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
> +{
> +	mutex_init(&scmi_info->shmem_lock);
> +}
> +
> +static inline void
> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
> +			      struct scmi_xfer *xfer __maybe_unused)

Why do you pass unused arguments?

> +{
> +	mutex_lock(&scmi_info->shmem_lock);

Why do you need these wrappers? Why not using mutexes directly?
If they are needed, then add lock __acquires annotation.


> +}
> +
> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
> +						 *scmi_info)

Same comments.

> +{
> +	mutex_unlock(&scmi_info->shmem_lock);
> +}
> +
> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> +			       struct device *dev, bool tx)
> +{
> +	struct device *cdev = cinfo->dev;
> +	struct scmi_qcom_hvc *scmi_info;
> +	resource_size_t size;
> +	struct resource res;
> +	struct device_node *np;
> +	unsigned long cap_id;
> +	u32 func_id;
> +	int ret, irq;
> +
> +	if (!tx)
> +		return -ENODEV;
> +
> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
> +	if (!scmi_info)
> +		return -ENOMEM;
> +
> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))

You leak here reference.

> +		return -ENXIO;
> +
> +	ret = of_address_to_resource(np, 0, &res);
> +	of_node_put(np);
> +	if (ret) {
> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
> +		return ret;
> +	}
> +
> +	size = resource_size(&res);
> +
> +	/* let's map 2 additional ulong since
> +	 * func-id & capability-id are kept after shmem.
> +	 *     +-------+
> +	 *     |       |
> +	 *     | shmem |
> +	 *     |       |
> +	 *     |       |
> +	 *     +-------+ <-- size
> +	 *     | funcId|
> +	 *     +-------+ <-- size + sizeof(ulong)
> +	 *     | capId |
> +	 *     +-------+ <-- size + 2*sizeof(ulong)
> +	 */
> +
> +	scmi_info->shmem = devm_ioremap(dev, res.start,
> +					size + 2 * sizeof(unsigned long));
> +	if (!scmi_info->shmem) {
> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> +		return -EADDRNOTAVAIL;
> +	}
> +
> +	func_id = readl((void *)(scmi_info->shmem) + size);
> +
> +#ifdef CONFIG_ARM64
> +	cap_id = readq((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#else
> +	cap_id = readl((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#endif
> +
> +	/*
> +	 * If there is an interrupt named "a2p", then the service and
> +	 * completion of a message is signaled by an interrupt rather than by
> +	 * the return of the hvc call.
> +	 */
> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
> +	if (irq > 0) {
> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
> +				       IRQF_NO_SUSPEND,
> +				       dev_name(dev), scmi_info);
> +		if (ret) {
> +			dev_err(dev, "failed to setup SCMI completion irq\n");

return dev_err_probe, unless this is not called in probe... but then
using devm-interface raises questions.

Best regards,
Krzysztof


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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 18:17     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-18 18:17 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 18:08, Nikunj Kela wrote:
> Add a new transport channel to the SCMI firmware interface driver for
> SCMI message exchange on Qualcomm virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 

...

> +
> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
> +{
> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
> +
> +	if (!np)
> +		return false;
> +
> +	of_node_put(np);
> +	return true;
> +}
> +
> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
> +{
> +	mutex_init(&scmi_info->shmem_lock);
> +}
> +
> +static inline void
> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
> +			      struct scmi_xfer *xfer __maybe_unused)

Why do you pass unused arguments?

> +{
> +	mutex_lock(&scmi_info->shmem_lock);

Why do you need these wrappers? Why not using mutexes directly?
If they are needed, then add lock __acquires annotation.


> +}
> +
> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
> +						 *scmi_info)

Same comments.

> +{
> +	mutex_unlock(&scmi_info->shmem_lock);
> +}
> +
> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> +			       struct device *dev, bool tx)
> +{
> +	struct device *cdev = cinfo->dev;
> +	struct scmi_qcom_hvc *scmi_info;
> +	resource_size_t size;
> +	struct resource res;
> +	struct device_node *np;
> +	unsigned long cap_id;
> +	u32 func_id;
> +	int ret, irq;
> +
> +	if (!tx)
> +		return -ENODEV;
> +
> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
> +	if (!scmi_info)
> +		return -ENOMEM;
> +
> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))

You leak here reference.

> +		return -ENXIO;
> +
> +	ret = of_address_to_resource(np, 0, &res);
> +	of_node_put(np);
> +	if (ret) {
> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
> +		return ret;
> +	}
> +
> +	size = resource_size(&res);
> +
> +	/* let's map 2 additional ulong since
> +	 * func-id & capability-id are kept after shmem.
> +	 *     +-------+
> +	 *     |       |
> +	 *     | shmem |
> +	 *     |       |
> +	 *     |       |
> +	 *     +-------+ <-- size
> +	 *     | funcId|
> +	 *     +-------+ <-- size + sizeof(ulong)
> +	 *     | capId |
> +	 *     +-------+ <-- size + 2*sizeof(ulong)
> +	 */
> +
> +	scmi_info->shmem = devm_ioremap(dev, res.start,
> +					size + 2 * sizeof(unsigned long));
> +	if (!scmi_info->shmem) {
> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> +		return -EADDRNOTAVAIL;
> +	}
> +
> +	func_id = readl((void *)(scmi_info->shmem) + size);
> +
> +#ifdef CONFIG_ARM64
> +	cap_id = readq((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#else
> +	cap_id = readl((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#endif
> +
> +	/*
> +	 * If there is an interrupt named "a2p", then the service and
> +	 * completion of a message is signaled by an interrupt rather than by
> +	 * the return of the hvc call.
> +	 */
> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
> +	if (irq > 0) {
> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
> +				       IRQF_NO_SUSPEND,
> +				       dev_name(dev), scmi_info);
> +		if (ret) {
> +			dev_err(dev, "failed to setup SCMI completion irq\n");

return dev_err_probe, unless this is not called in probe... but then
using devm-interface raises questions.

Best regards,
Krzysztof


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

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-18 18:12     ` Krzysztof Kozlowski
@ 2023-07-18 18:18       ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 18:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:12 AM, Krzysztof Kozlowski wrote:
> On 18/07/2023 18:08, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
>> transport channel for Qualcomm virtual platforms.
>> The compatible mandates a shared memory channel.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>>   1 file changed, 69 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> index b138f3d23df8..605b1e997a85 100644
>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> @@ -45,6 +45,9 @@ properties:
>>         - description: SCMI compliant firmware with OP-TEE transport
>>           items:
>>             - const: linaro,scmi-optee
>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>> +        items:
>> +          - const: qcom,scmi-hvc-shmem
>>   
>>     interrupts:
>>       description:
>> @@ -321,6 +324,16 @@ else:
>>         required:
>>           - linaro,optee-channel-id
>>   
>> +    else:
>> +      if:
>> +        properties:
>> +          compatible:
>> +            contains:
>> +              const: qcom,scmi-hvc-shmem
>> +      then:
>> +        required:
>> +          - shmem
> Unfortunately this pattern if-else-if-else-if-else does not scale well.
> Please convert all entries first to allOf:if:then,if:then,if:then (in
> new patch), and then add new if:then:
Ok!
>
>> +
>>   examples:
>>     - |
>>       firmware {
>> @@ -444,6 +457,62 @@ examples:
>>           };
>>       };
>>   
>> +  - |
>> +    firmware {
>> +        scmi_dpu {
> No underscores in node names.
>
> Node names should be generic. See also an explanation and list of
> examples (not exhaustive) in DT specification:
> https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
ACK!
>
>
>
>> +            compatible = "qcom,scmi-hvc-shmem";
>> +            shmem = <&shmem_dpu>;
>> +
>> +            #address-cells = <1>;
>> +            #size-cells = <0>;
>> +
>> +            scmi_pd_dpu: protocol@11 {
>> +                reg = <0x11>;
>> +                #power-domain-cells = <1>;
>> +            };
>> +        };
>> +
> Add only one example, but then only if it differs significantly. I see
> no differences - except compatible - so maybe no point of examples.
Other than the compatible, it also doesn't require smc-id, we read it 
from shmem region.  Will remove examples.
>
>
>> +        scmi_gpu {
>> +            compatible = "qcom,scmi-hvc-shmem";
>> +            shmem = <&shmem_gpu>;
> This example for sure is not needed - you duplicate above.
Right, will remove this example.
>
>> +
>> +            interrupts = <GIC_SPI 931 IRQ_TYPE_EDGE_RISING>;
>> +            interrupt-names = "a2p";
>> +
>> +            #address-cells = <1>;
>> +            #size-cells = <0>;
>> +
>> +            scmi_pd_gpu: protocol@11 {
>> +                reg = <0x11>;
>> +                #power-domain-cells = <1>;
>> +            };
>> +        };
>> +    };
>> +
>> +    soc {
>> +        #address-cells = <1>;
>> +        #size-cells = <1>;
>> +
>> +        sram@95c00000 {
>> +            compatible = "mmio-sram";
>> +            reg = <0x95c00000 0x10000>;
>> +
>> +            #address-cells = <1>;
>> +            #size-cells = <1>;
>> +            ranges;
>> +
>> +            shmem_dpu: scmi-sram-dpu@95c00000 {
>> +                compatible = "arm,scmi-shmem";
>> +                reg = <0x95c00000 0x3f0>;
>> +            };
> How does these differ from existing example?

It doesn't. Will remove the example as suggested. Thanks


>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-07-18 18:18       ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 18:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:12 AM, Krzysztof Kozlowski wrote:
> On 18/07/2023 18:08, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
>> transport channel for Qualcomm virtual platforms.
>> The compatible mandates a shared memory channel.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>>   1 file changed, 69 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> index b138f3d23df8..605b1e997a85 100644
>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> @@ -45,6 +45,9 @@ properties:
>>         - description: SCMI compliant firmware with OP-TEE transport
>>           items:
>>             - const: linaro,scmi-optee
>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>> +        items:
>> +          - const: qcom,scmi-hvc-shmem
>>   
>>     interrupts:
>>       description:
>> @@ -321,6 +324,16 @@ else:
>>         required:
>>           - linaro,optee-channel-id
>>   
>> +    else:
>> +      if:
>> +        properties:
>> +          compatible:
>> +            contains:
>> +              const: qcom,scmi-hvc-shmem
>> +      then:
>> +        required:
>> +          - shmem
> Unfortunately this pattern if-else-if-else-if-else does not scale well.
> Please convert all entries first to allOf:if:then,if:then,if:then (in
> new patch), and then add new if:then:
Ok!
>
>> +
>>   examples:
>>     - |
>>       firmware {
>> @@ -444,6 +457,62 @@ examples:
>>           };
>>       };
>>   
>> +  - |
>> +    firmware {
>> +        scmi_dpu {
> No underscores in node names.
>
> Node names should be generic. See also an explanation and list of
> examples (not exhaustive) in DT specification:
> https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
ACK!
>
>
>
>> +            compatible = "qcom,scmi-hvc-shmem";
>> +            shmem = <&shmem_dpu>;
>> +
>> +            #address-cells = <1>;
>> +            #size-cells = <0>;
>> +
>> +            scmi_pd_dpu: protocol@11 {
>> +                reg = <0x11>;
>> +                #power-domain-cells = <1>;
>> +            };
>> +        };
>> +
> Add only one example, but then only if it differs significantly. I see
> no differences - except compatible - so maybe no point of examples.
Other than the compatible, it also doesn't require smc-id, we read it 
from shmem region.  Will remove examples.
>
>
>> +        scmi_gpu {
>> +            compatible = "qcom,scmi-hvc-shmem";
>> +            shmem = <&shmem_gpu>;
> This example for sure is not needed - you duplicate above.
Right, will remove this example.
>
>> +
>> +            interrupts = <GIC_SPI 931 IRQ_TYPE_EDGE_RISING>;
>> +            interrupt-names = "a2p";
>> +
>> +            #address-cells = <1>;
>> +            #size-cells = <0>;
>> +
>> +            scmi_pd_gpu: protocol@11 {
>> +                reg = <0x11>;
>> +                #power-domain-cells = <1>;
>> +            };
>> +        };
>> +    };
>> +
>> +    soc {
>> +        #address-cells = <1>;
>> +        #size-cells = <1>;
>> +
>> +        sram@95c00000 {
>> +            compatible = "mmio-sram";
>> +            reg = <0x95c00000 0x10000>;
>> +
>> +            #address-cells = <1>;
>> +            #size-cells = <1>;
>> +            ranges;
>> +
>> +            shmem_dpu: scmi-sram-dpu@95c00000 {
>> +                compatible = "arm,scmi-shmem";
>> +                reg = <0x95c00000 0x3f0>;
>> +            };
> How does these differ from existing example?

It doesn't. Will remove the example as suggested. Thanks


>
> Best regards,
> Krzysztof
>

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 18:17     ` Krzysztof Kozlowski
@ 2023-07-18 18:25       ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 18:25 UTC (permalink / raw)
  To: Krzysztof Kozlowski, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:17 AM, Krzysztof Kozlowski wrote:
> On 18/07/2023 18:08, Nikunj Kela wrote:
>> Add a new transport channel to the SCMI firmware interface driver for
>> SCMI message exchange on Qualcomm virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
> ...
>
>> +
>> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
>> +{
>> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
>> +
>> +	if (!np)
>> +		return false;
>> +
>> +	of_node_put(np);
>> +	return true;
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
>> +{
>> +	mutex_init(&scmi_info->shmem_lock);
>> +}
>> +
>> +static inline void
>> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
>> +			      struct scmi_xfer *xfer __maybe_unused)
> Why do you pass unused arguments?
I mimic the same behavior as in smc.c. At the moment, we don't have a 
use case for atomicity but was trying to keep the same skeleton in case 
we need to add the atomic support in future. But you are right, I don't 
need wrapper at the moment.
>
>> +{
>> +	mutex_lock(&scmi_info->shmem_lock);
> Why do you need these wrappers? Why not using mutexes directly?
> If they are needed, then add lock __acquires annotation.
>
Will remove the wrappers.
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
>> +						 *scmi_info)
> Same comments.
>
>> +{
>> +	mutex_unlock(&scmi_info->shmem_lock);
>> +}
>> +
>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>> +			       struct device *dev, bool tx)
>> +{
>> +	struct device *cdev = cinfo->dev;
>> +	struct scmi_qcom_hvc *scmi_info;
>> +	resource_size_t size;
>> +	struct resource res;
>> +	struct device_node *np;
>> +	unsigned long cap_id;
>> +	u32 func_id;
>> +	int ret, irq;
>> +
>> +	if (!tx)
>> +		return -ENODEV;
>> +
>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>> +	if (!scmi_info)
>> +		return -ENOMEM;
>> +
>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
> You leak here reference.
Wouldn't the devm_* API take care of that implicitly? It is same in 
smc.c as well.
>> +		return -ENXIO;
>> +
>> +	ret = of_address_to_resource(np, 0, &res);
>> +	of_node_put(np);
>> +	if (ret) {
>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>> +		return ret;
>> +	}
>> +
>> +	size = resource_size(&res);
>> +
>> +	/* let's map 2 additional ulong since
>> +	 * func-id & capability-id are kept after shmem.
>> +	 *     +-------+
>> +	 *     |       |
>> +	 *     | shmem |
>> +	 *     |       |
>> +	 *     |       |
>> +	 *     +-------+ <-- size
>> +	 *     | funcId|
>> +	 *     +-------+ <-- size + sizeof(ulong)
>> +	 *     | capId |
>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>> +	 */
>> +
>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>> +					size + 2 * sizeof(unsigned long));
>> +	if (!scmi_info->shmem) {
>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>> +		return -EADDRNOTAVAIL;
>> +	}
>> +
>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>> +
>> +#ifdef CONFIG_ARM64
>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#else
>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#endif
>> +
>> +	/*
>> +	 * If there is an interrupt named "a2p", then the service and
>> +	 * completion of a message is signaled by an interrupt rather than by
>> +	 * the return of the hvc call.
>> +	 */
>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>> +	if (irq > 0) {
>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>> +				       IRQF_NO_SUSPEND,
>> +				       dev_name(dev), scmi_info);
>> +		if (ret) {
>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
> return dev_err_probe, unless this is not called in probe... but then
> using devm-interface raises questions.
This is copied as is from existing smc.c
>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 18:25       ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 18:25 UTC (permalink / raw)
  To: Krzysztof Kozlowski, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:17 AM, Krzysztof Kozlowski wrote:
> On 18/07/2023 18:08, Nikunj Kela wrote:
>> Add a new transport channel to the SCMI firmware interface driver for
>> SCMI message exchange on Qualcomm virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
> ...
>
>> +
>> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
>> +{
>> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
>> +
>> +	if (!np)
>> +		return false;
>> +
>> +	of_node_put(np);
>> +	return true;
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
>> +{
>> +	mutex_init(&scmi_info->shmem_lock);
>> +}
>> +
>> +static inline void
>> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
>> +			      struct scmi_xfer *xfer __maybe_unused)
> Why do you pass unused arguments?
I mimic the same behavior as in smc.c. At the moment, we don't have a 
use case for atomicity but was trying to keep the same skeleton in case 
we need to add the atomic support in future. But you are right, I don't 
need wrapper at the moment.
>
>> +{
>> +	mutex_lock(&scmi_info->shmem_lock);
> Why do you need these wrappers? Why not using mutexes directly?
> If they are needed, then add lock __acquires annotation.
>
Will remove the wrappers.
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
>> +						 *scmi_info)
> Same comments.
>
>> +{
>> +	mutex_unlock(&scmi_info->shmem_lock);
>> +}
>> +
>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>> +			       struct device *dev, bool tx)
>> +{
>> +	struct device *cdev = cinfo->dev;
>> +	struct scmi_qcom_hvc *scmi_info;
>> +	resource_size_t size;
>> +	struct resource res;
>> +	struct device_node *np;
>> +	unsigned long cap_id;
>> +	u32 func_id;
>> +	int ret, irq;
>> +
>> +	if (!tx)
>> +		return -ENODEV;
>> +
>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>> +	if (!scmi_info)
>> +		return -ENOMEM;
>> +
>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
> You leak here reference.
Wouldn't the devm_* API take care of that implicitly? It is same in 
smc.c as well.
>> +		return -ENXIO;
>> +
>> +	ret = of_address_to_resource(np, 0, &res);
>> +	of_node_put(np);
>> +	if (ret) {
>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>> +		return ret;
>> +	}
>> +
>> +	size = resource_size(&res);
>> +
>> +	/* let's map 2 additional ulong since
>> +	 * func-id & capability-id are kept after shmem.
>> +	 *     +-------+
>> +	 *     |       |
>> +	 *     | shmem |
>> +	 *     |       |
>> +	 *     |       |
>> +	 *     +-------+ <-- size
>> +	 *     | funcId|
>> +	 *     +-------+ <-- size + sizeof(ulong)
>> +	 *     | capId |
>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>> +	 */
>> +
>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>> +					size + 2 * sizeof(unsigned long));
>> +	if (!scmi_info->shmem) {
>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>> +		return -EADDRNOTAVAIL;
>> +	}
>> +
>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>> +
>> +#ifdef CONFIG_ARM64
>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#else
>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#endif
>> +
>> +	/*
>> +	 * If there is an interrupt named "a2p", then the service and
>> +	 * completion of a message is signaled by an interrupt rather than by
>> +	 * the return of the hvc call.
>> +	 */
>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>> +	if (irq > 0) {
>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>> +				       IRQF_NO_SUSPEND,
>> +				       dev_name(dev), scmi_info);
>> +		if (ret) {
>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
> return dev_err_probe, unless this is not called in probe... but then
> using devm-interface raises questions.
This is copied as is from existing smc.c
>
> Best regards,
> Krzysztof
>

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 16:08   ` Nikunj Kela
@ 2023-07-18 18:29     ` Bjorn Andersson
  -1 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-07-18 18:29 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> new file mode 100644
> index 000000000000..3b6096d8fe67
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
> @@ -0,0 +1,241 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * System Control and Management Interface (SCMI) Message
> + * Qualcomm HVC/shmem Transport driver
> + *
> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
> + * Copyright 2020 NXP
> + *
> + * This is copied from drivers/firmware/arm_scmi/smc.c

s/copied from/based on/

> + */
> +
> +#include <linux/arm-smccc.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/of_irq.h>
> +#include <linux/processor.h>

This is here because the original code uses spin_until_cond().

> +#include <linux/slab.h>
> +
> +#include "common.h"
> +
> +/**
> + * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
> + *
> + * @cinfo: SCMI channel info
> + * @shmem: Transmit/Receive shared memory area
> + * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
> + * @func_id: hvc call function-id
> + * @cap_id: hvc doorbell's capability id
> + */
> +
> +struct scmi_qcom_hvc {
> +	struct scmi_chan_info *cinfo;
> +	struct scmi_shared_mem __iomem *shmem;
> +	/* Protect access to shmem area */
> +	struct mutex shmem_lock;
> +	u32 func_id;
> +	unsigned long cap_id;

One architecture-independent and one architecture-dependent parameter,
see below.

> +};
> +
> +static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
> +{
> +	struct scmi_qcom_hvc *scmi_info = data;
> +
> +	scmi_rx_callback(scmi_info->cinfo,
> +			 shmem_read_header(scmi_info->shmem), NULL);

80-char is a nice guideline, but this would be easier to read if not
line-wrapped.

> +
> +	return IRQ_HANDLED;
> +}
> +
> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
> +{
> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
> +
> +	if (!np)
> +		return false;
> +
> +	of_node_put(np);
> +	return true;
> +}
> +
> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
> +{
> +	mutex_init(&scmi_info->shmem_lock);

Just inline these three lock-related methods, saves the reader from
wondering what is actually locked, what a "channel" is (is a "channel"
the same thing as a "shm region"?) etc.

> +}
> +
> +static inline void
> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
> +			      struct scmi_xfer *xfer __maybe_unused)
> +{

You claim above that you copied smc.c, but you don't mention that you
dropped the support for transfers from atomic mode. Please capture this
in the commit message, so that someone looking at this in the future
knows why you made this choice.

> +	mutex_lock(&scmi_info->shmem_lock);
> +}
> +
> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
> +						 *scmi_info)
> +{
> +	mutex_unlock(&scmi_info->shmem_lock);
> +}
> +
> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> +			       struct device *dev, bool tx)
> +{
> +	struct device *cdev = cinfo->dev;
> +	struct scmi_qcom_hvc *scmi_info;
> +	resource_size_t size;
> +	struct resource res;
> +	struct device_node *np;
> +	unsigned long cap_id;
> +	u32 func_id;
> +	int ret, irq;

Please declare one variable per line, and please sort them by length, in
descending order (i.e. reverse Christmas tree).

> +
> +	if (!tx)
> +		return -ENODEV;
> +
> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
> +	if (!scmi_info)
> +		return -ENOMEM;
> +
> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
> +		return -ENXIO;
> +
> +	ret = of_address_to_resource(np, 0, &res);
> +	of_node_put(np);
> +	if (ret) {
> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
> +		return ret;
> +	}
> +
> +	size = resource_size(&res);
> +
> +	/* let's map 2 additional ulong since
> +	 * func-id & capability-id are kept after shmem.
> +	 *     +-------+
> +	 *     |       |
> +	 *     | shmem |
> +	 *     |       |
> +	 *     |       |
> +	 *     +-------+ <-- size
> +	 *     | funcId|
> +	 *     +-------+ <-- size + sizeof(ulong)
> +	 *     | capId |
> +	 *     +-------+ <-- size + 2*sizeof(ulong)

Relying on an undocumented convention that following the region
specified in DeviceTree are two architecture specifically sized integers
isn't good practice.

This should be covered by the DeviceTree binding, in one way or another.

> +	 */
> +
> +	scmi_info->shmem = devm_ioremap(dev, res.start,
> +					size + 2 * sizeof(unsigned long));

I don't find any code that uses the size of the defined shm, so I don't
think you need to do this dance.

> +	if (!scmi_info->shmem) {
> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> +		return -EADDRNOTAVAIL;
> +	}
> +
> +	func_id = readl((void *)(scmi_info->shmem) + size);
> +
> +#ifdef CONFIG_ARM64
> +	cap_id = readq((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#else
> +	cap_id = readl((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#endif

Please don't make the in-memory representation depend on architecture
specific data types. Quite likely you didn't compile test one of these
variants?

Just define the in-memory representation as u32 + u64.

> +
> +	/*
> +	 * If there is an interrupt named "a2p", then the service and
> +	 * completion of a message is signaled by an interrupt rather than by
> +	 * the return of the hvc call.
> +	 */
> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
> +	if (irq > 0) {
> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
> +				       IRQF_NO_SUSPEND,
> +				       dev_name(dev), scmi_info);
> +		if (ret) {
> +			dev_err(dev, "failed to setup SCMI completion irq\n");
> +			return ret;
> +		}
> +	} else {
> +		cinfo->no_completion_irq = true;
> +	}
> +
> +	scmi_info->func_id = func_id;
> +	scmi_info->cap_id = cap_id;
> +	scmi_info->cinfo = cinfo;
> +	qcom_hvc_channel_lock_init(scmi_info);
> +	cinfo->transport_info = scmi_info;
> +
> +	return 0;
> +}
> +
> +static int qcom_hvc_chan_free(int id, void *p, void *data)
> +{
> +	struct scmi_chan_info *cinfo = p;
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +
> +	cinfo->transport_info = NULL;
> +	scmi_info->cinfo = NULL;

Your a2p interrupt is cleaned up using devres, which will happen at a
later point. So just setting cinfo to NULL here would cause an interrupt
to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
which happily will dereference that NULL.

> +
> +	return 0;
> +}
> +
> +static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
> +				 struct scmi_xfer *xfer)
> +{
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +	struct arm_smccc_res res;
> +
> +	/*
> +	 * Channel will be released only once response has been
> +	 * surely fully retrieved, so after .mark_txdone()
> +	 */
> +	qcom_hvc_channel_lock_acquire(scmi_info, xfer);
> +
> +	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
> +
> +	arm_smccc_1_1_hvc(scmi_info->func_id, scmi_info->cap_id,
> +			  0, 0, 0, 0, 0, 0, &res);
> +
> +	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */

Does this hold for your implementation as well?

> +	if (res.a0) {
> +		qcom_hvc_channel_lock_release(scmi_info);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	return 0;
> +}
> +
> +static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
> +				    struct scmi_xfer *xfer)
> +{
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +
> +	shmem_fetch_response(scmi_info->shmem, xfer);
> +}
> +
> +static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
> +				 struct scmi_xfer *__unused)
> +{
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +
> +	qcom_hvc_channel_lock_release(scmi_info);
> +}
> +
> +static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
> +	.chan_available = qcom_hvc_chan_available,
> +	.chan_setup = qcom_hvc_chan_setup,
> +	.chan_free = qcom_hvc_chan_free,
> +	.send_message = qcom_hvc_send_message,
> +	.mark_txdone = qcom_hvc_mark_txdone,
> +	.fetch_response = qcom_hvc_fetch_response,
> +};
> +
> +const struct scmi_desc scmi_qcom_hvc_desc = {
> +	.ops = &scmi_qcom_hvc_ops,
> +	.max_rx_timeout_ms = 30,
> +	.max_msg = 20,

I'm confused about the purpose of this number, it serves both as a limit
of the number of clients that are currently allowed to prepare messages,
and as a limit for how many outstanding transfers waiting for response.

Making the prior limit too low will result in the client running into an
-ENOMEM which it likely won't recover from - the user experience after
getting -ENOMEM on regulator_enable() will be suboptimal...

The latter limit would relate to resource limitations on the firmware
side. Please make sure that you have accounted for 2.5kB of firmware
memory, per agent, in your design.

> +	.max_msg_size = 128,

Regards,
Bjorn

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 18:29     ` Bjorn Andersson
  0 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-07-18 18:29 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> new file mode 100644
> index 000000000000..3b6096d8fe67
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
> @@ -0,0 +1,241 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * System Control and Management Interface (SCMI) Message
> + * Qualcomm HVC/shmem Transport driver
> + *
> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
> + * Copyright 2020 NXP
> + *
> + * This is copied from drivers/firmware/arm_scmi/smc.c

s/copied from/based on/

> + */
> +
> +#include <linux/arm-smccc.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/of_irq.h>
> +#include <linux/processor.h>

This is here because the original code uses spin_until_cond().

> +#include <linux/slab.h>
> +
> +#include "common.h"
> +
> +/**
> + * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
> + *
> + * @cinfo: SCMI channel info
> + * @shmem: Transmit/Receive shared memory area
> + * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
> + * @func_id: hvc call function-id
> + * @cap_id: hvc doorbell's capability id
> + */
> +
> +struct scmi_qcom_hvc {
> +	struct scmi_chan_info *cinfo;
> +	struct scmi_shared_mem __iomem *shmem;
> +	/* Protect access to shmem area */
> +	struct mutex shmem_lock;
> +	u32 func_id;
> +	unsigned long cap_id;

One architecture-independent and one architecture-dependent parameter,
see below.

> +};
> +
> +static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
> +{
> +	struct scmi_qcom_hvc *scmi_info = data;
> +
> +	scmi_rx_callback(scmi_info->cinfo,
> +			 shmem_read_header(scmi_info->shmem), NULL);

80-char is a nice guideline, but this would be easier to read if not
line-wrapped.

> +
> +	return IRQ_HANDLED;
> +}
> +
> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
> +{
> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
> +
> +	if (!np)
> +		return false;
> +
> +	of_node_put(np);
> +	return true;
> +}
> +
> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
> +{
> +	mutex_init(&scmi_info->shmem_lock);

Just inline these three lock-related methods, saves the reader from
wondering what is actually locked, what a "channel" is (is a "channel"
the same thing as a "shm region"?) etc.

> +}
> +
> +static inline void
> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
> +			      struct scmi_xfer *xfer __maybe_unused)
> +{

You claim above that you copied smc.c, but you don't mention that you
dropped the support for transfers from atomic mode. Please capture this
in the commit message, so that someone looking at this in the future
knows why you made this choice.

> +	mutex_lock(&scmi_info->shmem_lock);
> +}
> +
> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
> +						 *scmi_info)
> +{
> +	mutex_unlock(&scmi_info->shmem_lock);
> +}
> +
> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> +			       struct device *dev, bool tx)
> +{
> +	struct device *cdev = cinfo->dev;
> +	struct scmi_qcom_hvc *scmi_info;
> +	resource_size_t size;
> +	struct resource res;
> +	struct device_node *np;
> +	unsigned long cap_id;
> +	u32 func_id;
> +	int ret, irq;

Please declare one variable per line, and please sort them by length, in
descending order (i.e. reverse Christmas tree).

> +
> +	if (!tx)
> +		return -ENODEV;
> +
> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
> +	if (!scmi_info)
> +		return -ENOMEM;
> +
> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
> +		return -ENXIO;
> +
> +	ret = of_address_to_resource(np, 0, &res);
> +	of_node_put(np);
> +	if (ret) {
> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
> +		return ret;
> +	}
> +
> +	size = resource_size(&res);
> +
> +	/* let's map 2 additional ulong since
> +	 * func-id & capability-id are kept after shmem.
> +	 *     +-------+
> +	 *     |       |
> +	 *     | shmem |
> +	 *     |       |
> +	 *     |       |
> +	 *     +-------+ <-- size
> +	 *     | funcId|
> +	 *     +-------+ <-- size + sizeof(ulong)
> +	 *     | capId |
> +	 *     +-------+ <-- size + 2*sizeof(ulong)

Relying on an undocumented convention that following the region
specified in DeviceTree are two architecture specifically sized integers
isn't good practice.

This should be covered by the DeviceTree binding, in one way or another.

> +	 */
> +
> +	scmi_info->shmem = devm_ioremap(dev, res.start,
> +					size + 2 * sizeof(unsigned long));

I don't find any code that uses the size of the defined shm, so I don't
think you need to do this dance.

> +	if (!scmi_info->shmem) {
> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> +		return -EADDRNOTAVAIL;
> +	}
> +
> +	func_id = readl((void *)(scmi_info->shmem) + size);
> +
> +#ifdef CONFIG_ARM64
> +	cap_id = readq((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#else
> +	cap_id = readl((void *)(scmi_info->shmem) + size +
> +		       sizeof(unsigned long));
> +#endif

Please don't make the in-memory representation depend on architecture
specific data types. Quite likely you didn't compile test one of these
variants?

Just define the in-memory representation as u32 + u64.

> +
> +	/*
> +	 * If there is an interrupt named "a2p", then the service and
> +	 * completion of a message is signaled by an interrupt rather than by
> +	 * the return of the hvc call.
> +	 */
> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
> +	if (irq > 0) {
> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
> +				       IRQF_NO_SUSPEND,
> +				       dev_name(dev), scmi_info);
> +		if (ret) {
> +			dev_err(dev, "failed to setup SCMI completion irq\n");
> +			return ret;
> +		}
> +	} else {
> +		cinfo->no_completion_irq = true;
> +	}
> +
> +	scmi_info->func_id = func_id;
> +	scmi_info->cap_id = cap_id;
> +	scmi_info->cinfo = cinfo;
> +	qcom_hvc_channel_lock_init(scmi_info);
> +	cinfo->transport_info = scmi_info;
> +
> +	return 0;
> +}
> +
> +static int qcom_hvc_chan_free(int id, void *p, void *data)
> +{
> +	struct scmi_chan_info *cinfo = p;
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +
> +	cinfo->transport_info = NULL;
> +	scmi_info->cinfo = NULL;

Your a2p interrupt is cleaned up using devres, which will happen at a
later point. So just setting cinfo to NULL here would cause an interrupt
to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
which happily will dereference that NULL.

> +
> +	return 0;
> +}
> +
> +static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
> +				 struct scmi_xfer *xfer)
> +{
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +	struct arm_smccc_res res;
> +
> +	/*
> +	 * Channel will be released only once response has been
> +	 * surely fully retrieved, so after .mark_txdone()
> +	 */
> +	qcom_hvc_channel_lock_acquire(scmi_info, xfer);
> +
> +	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
> +
> +	arm_smccc_1_1_hvc(scmi_info->func_id, scmi_info->cap_id,
> +			  0, 0, 0, 0, 0, 0, &res);
> +
> +	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */

Does this hold for your implementation as well?

> +	if (res.a0) {
> +		qcom_hvc_channel_lock_release(scmi_info);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	return 0;
> +}
> +
> +static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
> +				    struct scmi_xfer *xfer)
> +{
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +
> +	shmem_fetch_response(scmi_info->shmem, xfer);
> +}
> +
> +static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
> +				 struct scmi_xfer *__unused)
> +{
> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> +
> +	qcom_hvc_channel_lock_release(scmi_info);
> +}
> +
> +static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
> +	.chan_available = qcom_hvc_chan_available,
> +	.chan_setup = qcom_hvc_chan_setup,
> +	.chan_free = qcom_hvc_chan_free,
> +	.send_message = qcom_hvc_send_message,
> +	.mark_txdone = qcom_hvc_mark_txdone,
> +	.fetch_response = qcom_hvc_fetch_response,
> +};
> +
> +const struct scmi_desc scmi_qcom_hvc_desc = {
> +	.ops = &scmi_qcom_hvc_ops,
> +	.max_rx_timeout_ms = 30,
> +	.max_msg = 20,

I'm confused about the purpose of this number, it serves both as a limit
of the number of clients that are currently allowed to prepare messages,
and as a limit for how many outstanding transfers waiting for response.

Making the prior limit too low will result in the client running into an
-ENOMEM which it likely won't recover from - the user experience after
getting -ENOMEM on regulator_enable() will be suboptimal...

The latter limit would relate to resource limitations on the firmware
side. Please make sure that you have accounted for 2.5kB of firmware
memory, per agent, in your design.

> +	.max_msg_size = 128,

Regards,
Bjorn

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 18:25       ` Nikunj Kela
@ 2023-07-18 18:42         ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-18 18:42 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 20:25, Nikunj Kela wrote:
>>> +
>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>> +	if (!scmi_info)
>>> +		return -ENOMEM;
>>> +
>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>> You leak here reference.
> Wouldn't the devm_* API take care of that implicitly? It is same in 
> smc.c as well.

Thanks for bringing my attention to this. I sent a fix for smc.c. Fix
your patch as well, please.

>>> +		return -ENXIO;
>>> +
>>> +	ret = of_address_to_resource(np, 0, &res);
>>> +	of_node_put(np);
>>> +	if (ret) {
>>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>>> +		return ret;
>>> +	}
>>> +
>>> +	size = resource_size(&res);
>>> +
>>> +	/* let's map 2 additional ulong since
>>> +	 * func-id & capability-id are kept after shmem.
>>> +	 *     +-------+
>>> +	 *     |       |
>>> +	 *     | shmem |
>>> +	 *     |       |
>>> +	 *     |       |
>>> +	 *     +-------+ <-- size
>>> +	 *     | funcId|
>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>> +	 *     | capId |
>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>> +	 */
>>> +
>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>> +					size + 2 * sizeof(unsigned long));
>>> +	if (!scmi_info->shmem) {
>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>> +		return -EADDRNOTAVAIL;
>>> +	}
>>> +
>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>> +
>>> +#ifdef CONFIG_ARM64
>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>> +		       sizeof(unsigned long));
>>> +#else
>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>> +		       sizeof(unsigned long));
>>> +#endif
>>> +
>>> +	/*
>>> +	 * If there is an interrupt named "a2p", then the service and
>>> +	 * completion of a message is signaled by an interrupt rather than by
>>> +	 * the return of the hvc call.
>>> +	 */
>>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>>> +	if (irq > 0) {
>>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>>> +				       IRQF_NO_SUSPEND,
>>> +				       dev_name(dev), scmi_info);
>>> +		if (ret) {
>>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>> return dev_err_probe, unless this is not called in probe... but then
>> using devm-interface raises questions.
> This is copied as is from existing smc.c

I understand and I hope you understand the code you copied. If there is
a bug in existing code, please do not copy it to new code (like leaking
OF node reference).

Best regards,
Krzysztof


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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 18:42         ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-18 18:42 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 20:25, Nikunj Kela wrote:
>>> +
>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>> +	if (!scmi_info)
>>> +		return -ENOMEM;
>>> +
>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>> You leak here reference.
> Wouldn't the devm_* API take care of that implicitly? It is same in 
> smc.c as well.

Thanks for bringing my attention to this. I sent a fix for smc.c. Fix
your patch as well, please.

>>> +		return -ENXIO;
>>> +
>>> +	ret = of_address_to_resource(np, 0, &res);
>>> +	of_node_put(np);
>>> +	if (ret) {
>>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>>> +		return ret;
>>> +	}
>>> +
>>> +	size = resource_size(&res);
>>> +
>>> +	/* let's map 2 additional ulong since
>>> +	 * func-id & capability-id are kept after shmem.
>>> +	 *     +-------+
>>> +	 *     |       |
>>> +	 *     | shmem |
>>> +	 *     |       |
>>> +	 *     |       |
>>> +	 *     +-------+ <-- size
>>> +	 *     | funcId|
>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>> +	 *     | capId |
>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>> +	 */
>>> +
>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>> +					size + 2 * sizeof(unsigned long));
>>> +	if (!scmi_info->shmem) {
>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>> +		return -EADDRNOTAVAIL;
>>> +	}
>>> +
>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>> +
>>> +#ifdef CONFIG_ARM64
>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>> +		       sizeof(unsigned long));
>>> +#else
>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>> +		       sizeof(unsigned long));
>>> +#endif
>>> +
>>> +	/*
>>> +	 * If there is an interrupt named "a2p", then the service and
>>> +	 * completion of a message is signaled by an interrupt rather than by
>>> +	 * the return of the hvc call.
>>> +	 */
>>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>>> +	if (irq > 0) {
>>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>>> +				       IRQF_NO_SUSPEND,
>>> +				       dev_name(dev), scmi_info);
>>> +		if (ret) {
>>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>> return dev_err_probe, unless this is not called in probe... but then
>> using devm-interface raises questions.
> This is copied as is from existing smc.c

I understand and I hope you understand the code you copied. If there is
a bug in existing code, please do not copy it to new code (like leaking
OF node reference).

Best regards,
Krzysztof


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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 18:29     ` Bjorn Andersson
@ 2023-07-18 18:53       ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 18:53 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
>> new file mode 100644
>> index 000000000000..3b6096d8fe67
>> --- /dev/null
>> +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
>> @@ -0,0 +1,241 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * System Control and Management Interface (SCMI) Message
>> + * Qualcomm HVC/shmem Transport driver
>> + *
>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
>> + * Copyright 2020 NXP
>> + *
>> + * This is copied from drivers/firmware/arm_scmi/smc.c
> s/copied from/based on/
ok.
>
>> + */
>> +
>> +#include <linux/arm-smccc.h>
>> +#include <linux/device.h>
>> +#include <linux/err.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of.h>
>> +#include <linux/of_address.h>
>> +#include <linux/of_irq.h>
>> +#include <linux/processor.h>
> This is here because the original code uses spin_until_cond().
ok, will remove it.
>
>> +#include <linux/slab.h>
>> +
>> +#include "common.h"
>> +
>> +/**
>> + * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
>> + *
>> + * @cinfo: SCMI channel info
>> + * @shmem: Transmit/Receive shared memory area
>> + * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
>> + * @func_id: hvc call function-id
>> + * @cap_id: hvc doorbell's capability id
>> + */
>> +
>> +struct scmi_qcom_hvc {
>> +	struct scmi_chan_info *cinfo;
>> +	struct scmi_shared_mem __iomem *shmem;
>> +	/* Protect access to shmem area */
>> +	struct mutex shmem_lock;
>> +	u32 func_id;
>> +	unsigned long cap_id;
> One architecture-independent and one architecture-dependent parameter,
> see below.
>
>> +};
>> +
>> +static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = data;
>> +
>> +	scmi_rx_callback(scmi_info->cinfo,
>> +			 shmem_read_header(scmi_info->shmem), NULL);
> 80-char is a nice guideline, but this would be easier to read if not
> line-wrapped.
ok.
>> +
>> +	return IRQ_HANDLED;
>> +}
>> +
>> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
>> +{
>> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
>> +
>> +	if (!np)
>> +		return false;
>> +
>> +	of_node_put(np);
>> +	return true;
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
>> +{
>> +	mutex_init(&scmi_info->shmem_lock);
> Just inline these three lock-related methods, saves the reader from
> wondering what is actually locked, what a "channel" is (is a "channel"
> the same thing as a "shm region"?) etc.
will do.
>
>> +}
>> +
>> +static inline void
>> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
>> +			      struct scmi_xfer *xfer __maybe_unused)
>> +{
> You claim above that you copied smc.c, but you don't mention that you
> dropped the support for transfers from atomic mode. Please capture this
> in the commit message, so that someone looking at this in the future
> knows why you made this choice.

At the moment, we dont have any requirement to support atomicity. Will 
add a comment in the commit message.


>
>> +	mutex_lock(&scmi_info->shmem_lock);
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
>> +						 *scmi_info)
>> +{
>> +	mutex_unlock(&scmi_info->shmem_lock);
>> +}
>> +
>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>> +			       struct device *dev, bool tx)
>> +{
>> +	struct device *cdev = cinfo->dev;
>> +	struct scmi_qcom_hvc *scmi_info;
>> +	resource_size_t size;
>> +	struct resource res;
>> +	struct device_node *np;
>> +	unsigned long cap_id;
>> +	u32 func_id;
>> +	int ret, irq;
> Please declare one variable per line, and please sort them by length, in
> descending order (i.e. reverse Christmas tree).
ok
>
>> +
>> +	if (!tx)
>> +		return -ENODEV;
>> +
>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>> +	if (!scmi_info)
>> +		return -ENOMEM;
>> +
>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>> +		return -ENXIO;
>> +
>> +	ret = of_address_to_resource(np, 0, &res);
>> +	of_node_put(np);
>> +	if (ret) {
>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>> +		return ret;
>> +	}
>> +
>> +	size = resource_size(&res);
>> +
>> +	/* let's map 2 additional ulong since
>> +	 * func-id & capability-id are kept after shmem.
>> +	 *     +-------+
>> +	 *     |       |
>> +	 *     | shmem |
>> +	 *     |       |
>> +	 *     |       |
>> +	 *     +-------+ <-- size
>> +	 *     | funcId|
>> +	 *     +-------+ <-- size + sizeof(ulong)
>> +	 *     | capId |
>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
> Relying on an undocumented convention that following the region
> specified in DeviceTree are two architecture specifically sized integers
> isn't good practice.
>
> This should be covered by the DeviceTree binding, in one way or another.

ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try 
adding a property as cap-id-width if its allowed.


>
>> +	 */
>> +
>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>> +					size + 2 * sizeof(unsigned long));
> I don't find any code that uses the size of the defined shm, so I don't
> think you need to do this dance.
Right! I can remove the addition part.
>
>> +	if (!scmi_info->shmem) {
>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>> +		return -EADDRNOTAVAIL;
>> +	}
>> +
>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>> +
>> +#ifdef CONFIG_ARM64
>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#else
>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#endif
> Please don't make the in-memory representation depend on architecture
> specific data types. Quite likely you didn't compile test one of these
> variants?
>
> Just define the in-memory representation as u32 + u64.
I tested this for ARM64, I didn't test it for 32bit since Hypervisor 
doesn't support it currently. In future, it may add 32 bit support too.
>> +
>> +	/*
>> +	 * If there is an interrupt named "a2p", then the service and
>> +	 * completion of a message is signaled by an interrupt rather than by
>> +	 * the return of the hvc call.
>> +	 */
>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>> +	if (irq > 0) {
>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>> +				       IRQF_NO_SUSPEND,
>> +				       dev_name(dev), scmi_info);
>> +		if (ret) {
>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>> +			return ret;
>> +		}
>> +	} else {
>> +		cinfo->no_completion_irq = true;
>> +	}
>> +
>> +	scmi_info->func_id = func_id;
>> +	scmi_info->cap_id = cap_id;
>> +	scmi_info->cinfo = cinfo;
>> +	qcom_hvc_channel_lock_init(scmi_info);
>> +	cinfo->transport_info = scmi_info;
>> +
>> +	return 0;
>> +}
>> +
>> +static int qcom_hvc_chan_free(int id, void *p, void *data)
>> +{
>> +	struct scmi_chan_info *cinfo = p;
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +
>> +	cinfo->transport_info = NULL;
>> +	scmi_info->cinfo = NULL;
> Your a2p interrupt is cleaned up using devres, which will happen at a
> later point. So just setting cinfo to NULL here would cause an interrupt
> to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
> which happily will dereference that NULL.
Ok, will add a check in ISR.
>
>> +
>> +	return 0;
>> +}
>> +
>> +static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
>> +				 struct scmi_xfer *xfer)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +	struct arm_smccc_res res;
>> +
>> +	/*
>> +	 * Channel will be released only once response has been
>> +	 * surely fully retrieved, so after .mark_txdone()
>> +	 */
>> +	qcom_hvc_channel_lock_acquire(scmi_info, xfer);
>> +
>> +	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>> +
>> +	arm_smccc_1_1_hvc(scmi_info->func_id, scmi_info->cap_id,
>> +			  0, 0, 0, 0, 0, 0, &res);
>> +
>> +	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
> Does this hold for your implementation as well?
We will have different error codes based on the cap-id passed. Will 
remove the above comment.
>
>> +	if (res.a0) {
>> +		qcom_hvc_channel_lock_release(scmi_info);
>> +		return -EOPNOTSUPP;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
>> +				    struct scmi_xfer *xfer)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +
>> +	shmem_fetch_response(scmi_info->shmem, xfer);
>> +}
>> +
>> +static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
>> +				 struct scmi_xfer *__unused)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +
>> +	qcom_hvc_channel_lock_release(scmi_info);
>> +}
>> +
>> +static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
>> +	.chan_available = qcom_hvc_chan_available,
>> +	.chan_setup = qcom_hvc_chan_setup,
>> +	.chan_free = qcom_hvc_chan_free,
>> +	.send_message = qcom_hvc_send_message,
>> +	.mark_txdone = qcom_hvc_mark_txdone,
>> +	.fetch_response = qcom_hvc_fetch_response,
>> +};
>> +
>> +const struct scmi_desc scmi_qcom_hvc_desc = {
>> +	.ops = &scmi_qcom_hvc_ops,
>> +	.max_rx_timeout_ms = 30,
>> +	.max_msg = 20,
> I'm confused about the purpose of this number, it serves both as a limit
> of the number of clients that are currently allowed to prepare messages,
> and as a limit for how many outstanding transfers waiting for response.
>
> Making the prior limit too low will result in the client running into an
> -ENOMEM which it likely won't recover from - the user experience after
> getting -ENOMEM on regulator_enable() will be suboptimal...
>
> The latter limit would relate to resource limitations on the firmware
> side. Please make sure that you have accounted for 2.5kB of firmware
> memory, per agent, in your design.
ok!
>> +	.max_msg_size = 128,
> Regards,
> Bjorn

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 18:53       ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 18:53 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
>> new file mode 100644
>> index 000000000000..3b6096d8fe67
>> --- /dev/null
>> +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
>> @@ -0,0 +1,241 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * System Control and Management Interface (SCMI) Message
>> + * Qualcomm HVC/shmem Transport driver
>> + *
>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
>> + * Copyright 2020 NXP
>> + *
>> + * This is copied from drivers/firmware/arm_scmi/smc.c
> s/copied from/based on/
ok.
>
>> + */
>> +
>> +#include <linux/arm-smccc.h>
>> +#include <linux/device.h>
>> +#include <linux/err.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of.h>
>> +#include <linux/of_address.h>
>> +#include <linux/of_irq.h>
>> +#include <linux/processor.h>
> This is here because the original code uses spin_until_cond().
ok, will remove it.
>
>> +#include <linux/slab.h>
>> +
>> +#include "common.h"
>> +
>> +/**
>> + * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
>> + *
>> + * @cinfo: SCMI channel info
>> + * @shmem: Transmit/Receive shared memory area
>> + * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
>> + * @func_id: hvc call function-id
>> + * @cap_id: hvc doorbell's capability id
>> + */
>> +
>> +struct scmi_qcom_hvc {
>> +	struct scmi_chan_info *cinfo;
>> +	struct scmi_shared_mem __iomem *shmem;
>> +	/* Protect access to shmem area */
>> +	struct mutex shmem_lock;
>> +	u32 func_id;
>> +	unsigned long cap_id;
> One architecture-independent and one architecture-dependent parameter,
> see below.
>
>> +};
>> +
>> +static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = data;
>> +
>> +	scmi_rx_callback(scmi_info->cinfo,
>> +			 shmem_read_header(scmi_info->shmem), NULL);
> 80-char is a nice guideline, but this would be easier to read if not
> line-wrapped.
ok.
>> +
>> +	return IRQ_HANDLED;
>> +}
>> +
>> +static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
>> +{
>> +	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
>> +
>> +	if (!np)
>> +		return false;
>> +
>> +	of_node_put(np);
>> +	return true;
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_init(struct scmi_qcom_hvc *scmi_info)
>> +{
>> +	mutex_init(&scmi_info->shmem_lock);
> Just inline these three lock-related methods, saves the reader from
> wondering what is actually locked, what a "channel" is (is a "channel"
> the same thing as a "shm region"?) etc.
will do.
>
>> +}
>> +
>> +static inline void
>> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
>> +			      struct scmi_xfer *xfer __maybe_unused)
>> +{
> You claim above that you copied smc.c, but you don't mention that you
> dropped the support for transfers from atomic mode. Please capture this
> in the commit message, so that someone looking at this in the future
> knows why you made this choice.

At the moment, we dont have any requirement to support atomicity. Will 
add a comment in the commit message.


>
>> +	mutex_lock(&scmi_info->shmem_lock);
>> +}
>> +
>> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
>> +						 *scmi_info)
>> +{
>> +	mutex_unlock(&scmi_info->shmem_lock);
>> +}
>> +
>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>> +			       struct device *dev, bool tx)
>> +{
>> +	struct device *cdev = cinfo->dev;
>> +	struct scmi_qcom_hvc *scmi_info;
>> +	resource_size_t size;
>> +	struct resource res;
>> +	struct device_node *np;
>> +	unsigned long cap_id;
>> +	u32 func_id;
>> +	int ret, irq;
> Please declare one variable per line, and please sort them by length, in
> descending order (i.e. reverse Christmas tree).
ok
>
>> +
>> +	if (!tx)
>> +		return -ENODEV;
>> +
>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>> +	if (!scmi_info)
>> +		return -ENOMEM;
>> +
>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>> +		return -ENXIO;
>> +
>> +	ret = of_address_to_resource(np, 0, &res);
>> +	of_node_put(np);
>> +	if (ret) {
>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>> +		return ret;
>> +	}
>> +
>> +	size = resource_size(&res);
>> +
>> +	/* let's map 2 additional ulong since
>> +	 * func-id & capability-id are kept after shmem.
>> +	 *     +-------+
>> +	 *     |       |
>> +	 *     | shmem |
>> +	 *     |       |
>> +	 *     |       |
>> +	 *     +-------+ <-- size
>> +	 *     | funcId|
>> +	 *     +-------+ <-- size + sizeof(ulong)
>> +	 *     | capId |
>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
> Relying on an undocumented convention that following the region
> specified in DeviceTree are two architecture specifically sized integers
> isn't good practice.
>
> This should be covered by the DeviceTree binding, in one way or another.

ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try 
adding a property as cap-id-width if its allowed.


>
>> +	 */
>> +
>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>> +					size + 2 * sizeof(unsigned long));
> I don't find any code that uses the size of the defined shm, so I don't
> think you need to do this dance.
Right! I can remove the addition part.
>
>> +	if (!scmi_info->shmem) {
>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>> +		return -EADDRNOTAVAIL;
>> +	}
>> +
>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>> +
>> +#ifdef CONFIG_ARM64
>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#else
>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>> +		       sizeof(unsigned long));
>> +#endif
> Please don't make the in-memory representation depend on architecture
> specific data types. Quite likely you didn't compile test one of these
> variants?
>
> Just define the in-memory representation as u32 + u64.
I tested this for ARM64, I didn't test it for 32bit since Hypervisor 
doesn't support it currently. In future, it may add 32 bit support too.
>> +
>> +	/*
>> +	 * If there is an interrupt named "a2p", then the service and
>> +	 * completion of a message is signaled by an interrupt rather than by
>> +	 * the return of the hvc call.
>> +	 */
>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>> +	if (irq > 0) {
>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>> +				       IRQF_NO_SUSPEND,
>> +				       dev_name(dev), scmi_info);
>> +		if (ret) {
>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>> +			return ret;
>> +		}
>> +	} else {
>> +		cinfo->no_completion_irq = true;
>> +	}
>> +
>> +	scmi_info->func_id = func_id;
>> +	scmi_info->cap_id = cap_id;
>> +	scmi_info->cinfo = cinfo;
>> +	qcom_hvc_channel_lock_init(scmi_info);
>> +	cinfo->transport_info = scmi_info;
>> +
>> +	return 0;
>> +}
>> +
>> +static int qcom_hvc_chan_free(int id, void *p, void *data)
>> +{
>> +	struct scmi_chan_info *cinfo = p;
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +
>> +	cinfo->transport_info = NULL;
>> +	scmi_info->cinfo = NULL;
> Your a2p interrupt is cleaned up using devres, which will happen at a
> later point. So just setting cinfo to NULL here would cause an interrupt
> to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
> which happily will dereference that NULL.
Ok, will add a check in ISR.
>
>> +
>> +	return 0;
>> +}
>> +
>> +static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
>> +				 struct scmi_xfer *xfer)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +	struct arm_smccc_res res;
>> +
>> +	/*
>> +	 * Channel will be released only once response has been
>> +	 * surely fully retrieved, so after .mark_txdone()
>> +	 */
>> +	qcom_hvc_channel_lock_acquire(scmi_info, xfer);
>> +
>> +	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>> +
>> +	arm_smccc_1_1_hvc(scmi_info->func_id, scmi_info->cap_id,
>> +			  0, 0, 0, 0, 0, 0, &res);
>> +
>> +	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
> Does this hold for your implementation as well?
We will have different error codes based on the cap-id passed. Will 
remove the above comment.
>
>> +	if (res.a0) {
>> +		qcom_hvc_channel_lock_release(scmi_info);
>> +		return -EOPNOTSUPP;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
>> +				    struct scmi_xfer *xfer)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +
>> +	shmem_fetch_response(scmi_info->shmem, xfer);
>> +}
>> +
>> +static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
>> +				 struct scmi_xfer *__unused)
>> +{
>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>> +
>> +	qcom_hvc_channel_lock_release(scmi_info);
>> +}
>> +
>> +static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
>> +	.chan_available = qcom_hvc_chan_available,
>> +	.chan_setup = qcom_hvc_chan_setup,
>> +	.chan_free = qcom_hvc_chan_free,
>> +	.send_message = qcom_hvc_send_message,
>> +	.mark_txdone = qcom_hvc_mark_txdone,
>> +	.fetch_response = qcom_hvc_fetch_response,
>> +};
>> +
>> +const struct scmi_desc scmi_qcom_hvc_desc = {
>> +	.ops = &scmi_qcom_hvc_ops,
>> +	.max_rx_timeout_ms = 30,
>> +	.max_msg = 20,
> I'm confused about the purpose of this number, it serves both as a limit
> of the number of clients that are currently allowed to prepare messages,
> and as a limit for how many outstanding transfers waiting for response.
>
> Making the prior limit too low will result in the client running into an
> -ENOMEM which it likely won't recover from - the user experience after
> getting -ENOMEM on regulator_enable() will be suboptimal...
>
> The latter limit would relate to resource limitations on the firmware
> side. Please make sure that you have accounted for 2.5kB of firmware
> memory, per agent, in your design.
ok!
>> +	.max_msg_size = 128,
> Regards,
> Bjorn

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 18:53       ` Nikunj Kela
@ 2023-07-18 19:07         ` Bjorn Andersson
  -1 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-07-18 19:07 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> > On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> > > diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
[..]
> > > +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> > > +			       struct device *dev, bool tx)
> > > +{
[..]
> > > +	/* let's map 2 additional ulong since
> > > +	 * func-id & capability-id are kept after shmem.
> > > +	 *     +-------+
> > > +	 *     |       |
> > > +	 *     | shmem |
> > > +	 *     |       |
> > > +	 *     |       |
> > > +	 *     +-------+ <-- size
> > > +	 *     | funcId|
> > > +	 *     +-------+ <-- size + sizeof(ulong)
> > > +	 *     | capId |
> > > +	 *     +-------+ <-- size + 2*sizeof(ulong)
> > Relying on an undocumented convention that following the region
> > specified in DeviceTree are two architecture specifically sized integers
> > isn't good practice.
> > 
> > This should be covered by the DeviceTree binding, in one way or another.
> 
> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
> a property as cap-id-width if its allowed.
> 

If you remove the additional part, per the next comment, DeviceTree
would be oblivious to these properties. I'll don't know if the
DeviceTree people have any concerns/suggestions about this.

> 
> > 
> > > +	 */
> > > +
> > > +	scmi_info->shmem = devm_ioremap(dev, res.start,
> > > +					size + 2 * sizeof(unsigned long));
> > I don't find any code that uses the size of the defined shm, so I don't
> > think you need to do this dance.
> Right! I can remove the addition part.
> > 
> > > +	if (!scmi_info->shmem) {
> > > +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> > > +		return -EADDRNOTAVAIL;
> > > +	}
> > > +
> > > +	func_id = readl((void *)(scmi_info->shmem) + size);
> > > +
> > > +#ifdef CONFIG_ARM64
> > > +	cap_id = readq((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#else
> > > +	cap_id = readl((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#endif
> > Please don't make the in-memory representation depend on architecture
> > specific data types. Quite likely you didn't compile test one of these
> > variants?
> > 
> > Just define the in-memory representation as u32 + u64.
> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
> support it currently. In future, it may add 32 bit support too.

I'd not be surprised if the capability id is 64 bit on a 32-bit machine
as well, it's not really a property of the architecture.

But regardless, always using 64 bits in your memory representation will
at worst waste a few bytes. But the result is a better defined
interface, and you can avoid the conditional code.

Regards,
Bjorn

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 19:07         ` Bjorn Andersson
  0 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-07-18 19:07 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> > On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> > > diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
[..]
> > > +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> > > +			       struct device *dev, bool tx)
> > > +{
[..]
> > > +	/* let's map 2 additional ulong since
> > > +	 * func-id & capability-id are kept after shmem.
> > > +	 *     +-------+
> > > +	 *     |       |
> > > +	 *     | shmem |
> > > +	 *     |       |
> > > +	 *     |       |
> > > +	 *     +-------+ <-- size
> > > +	 *     | funcId|
> > > +	 *     +-------+ <-- size + sizeof(ulong)
> > > +	 *     | capId |
> > > +	 *     +-------+ <-- size + 2*sizeof(ulong)
> > Relying on an undocumented convention that following the region
> > specified in DeviceTree are two architecture specifically sized integers
> > isn't good practice.
> > 
> > This should be covered by the DeviceTree binding, in one way or another.
> 
> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
> a property as cap-id-width if its allowed.
> 

If you remove the additional part, per the next comment, DeviceTree
would be oblivious to these properties. I'll don't know if the
DeviceTree people have any concerns/suggestions about this.

> 
> > 
> > > +	 */
> > > +
> > > +	scmi_info->shmem = devm_ioremap(dev, res.start,
> > > +					size + 2 * sizeof(unsigned long));
> > I don't find any code that uses the size of the defined shm, so I don't
> > think you need to do this dance.
> Right! I can remove the addition part.
> > 
> > > +	if (!scmi_info->shmem) {
> > > +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> > > +		return -EADDRNOTAVAIL;
> > > +	}
> > > +
> > > +	func_id = readl((void *)(scmi_info->shmem) + size);
> > > +
> > > +#ifdef CONFIG_ARM64
> > > +	cap_id = readq((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#else
> > > +	cap_id = readl((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#endif
> > Please don't make the in-memory representation depend on architecture
> > specific data types. Quite likely you didn't compile test one of these
> > variants?
> > 
> > Just define the in-memory representation as u32 + u64.
> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
> support it currently. In future, it may add 32 bit support too.

I'd not be surprised if the capability id is 64 bit on a 32-bit machine
as well, it's not really a property of the architecture.

But regardless, always using 64 bits in your memory representation will
at worst waste a few bytes. But the result is a better defined
interface, and you can avoid the conditional code.

Regards,
Bjorn

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 19:07         ` Bjorn Andersson
@ 2023-07-18 19:10           ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 19:10 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 12:07 PM, Bjorn Andersson wrote:
> On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
>> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
>>> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>>>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> [..]
>>>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>>>> +			       struct device *dev, bool tx)
>>>> +{
> [..]
>>>> +	/* let's map 2 additional ulong since
>>>> +	 * func-id & capability-id are kept after shmem.
>>>> +	 *     +-------+
>>>> +	 *     |       |
>>>> +	 *     | shmem |
>>>> +	 *     |       |
>>>> +	 *     |       |
>>>> +	 *     +-------+ <-- size
>>>> +	 *     | funcId|
>>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>>> +	 *     | capId |
>>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>> Relying on an undocumented convention that following the region
>>> specified in DeviceTree are two architecture specifically sized integers
>>> isn't good practice.
>>>
>>> This should be covered by the DeviceTree binding, in one way or another.
>> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
>> a property as cap-id-width if its allowed.
>>
> If you remove the additional part, per the next comment, DeviceTree
> would be oblivious to these properties. I'll don't know if the
> DeviceTree people have any concerns/suggestions about this.
ok.
>
>>>> +	 */
>>>> +
>>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>>> +					size + 2 * sizeof(unsigned long));
>>> I don't find any code that uses the size of the defined shm, so I don't
>>> think you need to do this dance.
>> Right! I can remove the addition part.
>>>> +	if (!scmi_info->shmem) {
>>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>>> +		return -EADDRNOTAVAIL;
>>>> +	}
>>>> +
>>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>>> +
>>>> +#ifdef CONFIG_ARM64
>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#else
>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#endif
>>> Please don't make the in-memory representation depend on architecture
>>> specific data types. Quite likely you didn't compile test one of these
>>> variants?
>>>
>>> Just define the in-memory representation as u32 + u64.
>> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
>> support it currently. In future, it may add 32 bit support too.
> I'd not be surprised if the capability id is 64 bit on a 32-bit machine
> as well, it's not really a property of the architecture.

on 32bit machine, you will have to use SMC32 convention. lt will mean 
that the parameters can only be 32 bit long. If you keep cap-id 64 bit 
in 32bit machines, then it has to be passed in two parameters. Are you 
suggesting, I make this driver dependent on ARM64 and only care about 64 
bit for now?

>
> But regardless, always using 64 bits in your memory representation will
> at worst waste a few bytes. But the result is a better defined
> interface, and you can avoid the conditional code.
>
> Regards,
> Bjorn

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 19:10           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 19:10 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 12:07 PM, Bjorn Andersson wrote:
> On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
>> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
>>> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>>>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> [..]
>>>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>>>> +			       struct device *dev, bool tx)
>>>> +{
> [..]
>>>> +	/* let's map 2 additional ulong since
>>>> +	 * func-id & capability-id are kept after shmem.
>>>> +	 *     +-------+
>>>> +	 *     |       |
>>>> +	 *     | shmem |
>>>> +	 *     |       |
>>>> +	 *     |       |
>>>> +	 *     +-------+ <-- size
>>>> +	 *     | funcId|
>>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>>> +	 *     | capId |
>>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>> Relying on an undocumented convention that following the region
>>> specified in DeviceTree are two architecture specifically sized integers
>>> isn't good practice.
>>>
>>> This should be covered by the DeviceTree binding, in one way or another.
>> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
>> a property as cap-id-width if its allowed.
>>
> If you remove the additional part, per the next comment, DeviceTree
> would be oblivious to these properties. I'll don't know if the
> DeviceTree people have any concerns/suggestions about this.
ok.
>
>>>> +	 */
>>>> +
>>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>>> +					size + 2 * sizeof(unsigned long));
>>> I don't find any code that uses the size of the defined shm, so I don't
>>> think you need to do this dance.
>> Right! I can remove the addition part.
>>>> +	if (!scmi_info->shmem) {
>>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>>> +		return -EADDRNOTAVAIL;
>>>> +	}
>>>> +
>>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>>> +
>>>> +#ifdef CONFIG_ARM64
>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#else
>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#endif
>>> Please don't make the in-memory representation depend on architecture
>>> specific data types. Quite likely you didn't compile test one of these
>>> variants?
>>>
>>> Just define the in-memory representation as u32 + u64.
>> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
>> support it currently. In future, it may add 32 bit support too.
> I'd not be surprised if the capability id is 64 bit on a 32-bit machine
> as well, it's not really a property of the architecture.

on 32bit machine, you will have to use SMC32 convention. lt will mean 
that the parameters can only be 32 bit long. If you keep cap-id 64 bit 
in 32bit machines, then it has to be passed in two parameters. Are you 
suggesting, I make this driver dependent on ARM64 and only care about 64 
bit for now?

>
> But regardless, always using 64 bits in your memory representation will
> at worst waste a few bytes. But the result is a better defined
> interface, and you can avoid the conditional code.
>
> Regards,
> Bjorn

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 19:10           ` Nikunj Kela
@ 2023-07-18 19:30             ` Bjorn Andersson
  -1 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-07-18 19:30 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 12:10:16PM -0700, Nikunj Kela wrote:
> 
> On 7/18/2023 12:07 PM, Bjorn Andersson wrote:
> > On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
> > > On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> > > > On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> > > > > diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> > [..]
[..]
> > > > > +#ifdef CONFIG_ARM64
> > > > > +	cap_id = readq((void *)(scmi_info->shmem) + size +
> > > > > +		       sizeof(unsigned long));
> > > > > +#else
> > > > > +	cap_id = readl((void *)(scmi_info->shmem) + size +
> > > > > +		       sizeof(unsigned long));
> > > > > +#endif
> > > > Please don't make the in-memory representation depend on architecture
> > > > specific data types. Quite likely you didn't compile test one of these
> > > > variants?
> > > > 
> > > > Just define the in-memory representation as u32 + u64.
> > > I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
> > > support it currently. In future, it may add 32 bit support too.
> > I'd not be surprised if the capability id is 64 bit on a 32-bit machine
> > as well, it's not really a property of the architecture.
> 
> on 32bit machine, you will have to use SMC32 convention. lt will mean that
> the parameters can only be 32 bit long. If you keep cap-id 64 bit in 32bit
> machines, then it has to be passed in two parameters. Are you suggesting, I
> make this driver dependent on ARM64 and only care about 64 bit for now?
> 

I'm suggesting that the calling convention is one thing and the
in-memory format for passing the information to the driver is a
different thing.

Keep the arguments passed in memory architecture-independent (i.e. make
it u64).

If you're saying that the calling convention would be different on a
32-bit system, then you are also saying that your driver _is_ 64-bit
specific. Please confirm what the size of your capability id would be in
such a system and make sure the Kconfig and/or the code, reflects
reality.

Thanks,
Bjorn

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 19:30             ` Bjorn Andersson
  0 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-07-18 19:30 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 12:10:16PM -0700, Nikunj Kela wrote:
> 
> On 7/18/2023 12:07 PM, Bjorn Andersson wrote:
> > On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
> > > On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> > > > On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> > > > > diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> > [..]
[..]
> > > > > +#ifdef CONFIG_ARM64
> > > > > +	cap_id = readq((void *)(scmi_info->shmem) + size +
> > > > > +		       sizeof(unsigned long));
> > > > > +#else
> > > > > +	cap_id = readl((void *)(scmi_info->shmem) + size +
> > > > > +		       sizeof(unsigned long));
> > > > > +#endif
> > > > Please don't make the in-memory representation depend on architecture
> > > > specific data types. Quite likely you didn't compile test one of these
> > > > variants?
> > > > 
> > > > Just define the in-memory representation as u32 + u64.
> > > I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
> > > support it currently. In future, it may add 32 bit support too.
> > I'd not be surprised if the capability id is 64 bit on a 32-bit machine
> > as well, it's not really a property of the architecture.
> 
> on 32bit machine, you will have to use SMC32 convention. lt will mean that
> the parameters can only be 32 bit long. If you keep cap-id 64 bit in 32bit
> machines, then it has to be passed in two parameters. Are you suggesting, I
> make this driver dependent on ARM64 and only care about 64 bit for now?
> 

I'm suggesting that the calling convention is one thing and the
in-memory format for passing the information to the driver is a
different thing.

Keep the arguments passed in memory architecture-independent (i.e. make
it u64).

If you're saying that the calling convention would be different on a
32-bit system, then you are also saying that your driver _is_ 64-bit
specific. Please confirm what the size of your capability id would be in
such a system and make sure the Kconfig and/or the code, reflects
reality.

Thanks,
Bjorn

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 18:42         ` Krzysztof Kozlowski
@ 2023-07-18 21:16           ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 21:16 UTC (permalink / raw)
  To: Krzysztof Kozlowski, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:42 AM, Krzysztof Kozlowski wrote:
> On 18/07/2023 20:25, Nikunj Kela wrote:
>>>> +
>>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>>> +	if (!scmi_info)
>>>> +		return -ENOMEM;
>>>> +
>>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>>> You leak here reference.
>> Wouldn't the devm_* API take care of that implicitly? It is same in
>> smc.c as well.
> Thanks for bringing my attention to this. I sent a fix for smc.c. Fix
> your patch as well, please.
Thanks, I thought you were referring to kzalloc cleanup. Will include 
this fix. BTW, you may need to fix mailbox.c as well.
>
>>>> +		return -ENXIO;
>>>> +
>>>> +	ret = of_address_to_resource(np, 0, &res);
>>>> +	of_node_put(np);
>>>> +	if (ret) {
>>>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>>>> +		return ret;
>>>> +	}
>>>> +
>>>> +	size = resource_size(&res);
>>>> +
>>>> +	/* let's map 2 additional ulong since
>>>> +	 * func-id & capability-id are kept after shmem.
>>>> +	 *     +-------+
>>>> +	 *     |       |
>>>> +	 *     | shmem |
>>>> +	 *     |       |
>>>> +	 *     |       |
>>>> +	 *     +-------+ <-- size
>>>> +	 *     | funcId|
>>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>>> +	 *     | capId |
>>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>>> +	 */
>>>> +
>>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>>> +					size + 2 * sizeof(unsigned long));
>>>> +	if (!scmi_info->shmem) {
>>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>>> +		return -EADDRNOTAVAIL;
>>>> +	}
>>>> +
>>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>>> +
>>>> +#ifdef CONFIG_ARM64
>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#else
>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#endif
>>>> +
>>>> +	/*
>>>> +	 * If there is an interrupt named "a2p", then the service and
>>>> +	 * completion of a message is signaled by an interrupt rather than by
>>>> +	 * the return of the hvc call.
>>>> +	 */
>>>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>>>> +	if (irq > 0) {
>>>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>>>> +				       IRQF_NO_SUSPEND,
>>>> +				       dev_name(dev), scmi_info);
>>>> +		if (ret) {
>>>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>>> return dev_err_probe, unless this is not called in probe... but then
>>> using devm-interface raises questions.
>> This is copied as is from existing smc.c
> I understand and I hope you understand the code you copied. If there is
> a bug in existing code, please do not copy it to new code (like leaking
> OF node reference).
>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 21:16           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 21:16 UTC (permalink / raw)
  To: Krzysztof Kozlowski, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 11:42 AM, Krzysztof Kozlowski wrote:
> On 18/07/2023 20:25, Nikunj Kela wrote:
>>>> +
>>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>>> +	if (!scmi_info)
>>>> +		return -ENOMEM;
>>>> +
>>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>>> You leak here reference.
>> Wouldn't the devm_* API take care of that implicitly? It is same in
>> smc.c as well.
> Thanks for bringing my attention to this. I sent a fix for smc.c. Fix
> your patch as well, please.
Thanks, I thought you were referring to kzalloc cleanup. Will include 
this fix. BTW, you may need to fix mailbox.c as well.
>
>>>> +		return -ENXIO;
>>>> +
>>>> +	ret = of_address_to_resource(np, 0, &res);
>>>> +	of_node_put(np);
>>>> +	if (ret) {
>>>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>>>> +		return ret;
>>>> +	}
>>>> +
>>>> +	size = resource_size(&res);
>>>> +
>>>> +	/* let's map 2 additional ulong since
>>>> +	 * func-id & capability-id are kept after shmem.
>>>> +	 *     +-------+
>>>> +	 *     |       |
>>>> +	 *     | shmem |
>>>> +	 *     |       |
>>>> +	 *     |       |
>>>> +	 *     +-------+ <-- size
>>>> +	 *     | funcId|
>>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>>> +	 *     | capId |
>>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>>> +	 */
>>>> +
>>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>>> +					size + 2 * sizeof(unsigned long));
>>>> +	if (!scmi_info->shmem) {
>>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>>> +		return -EADDRNOTAVAIL;
>>>> +	}
>>>> +
>>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>>> +
>>>> +#ifdef CONFIG_ARM64
>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#else
>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#endif
>>>> +
>>>> +	/*
>>>> +	 * If there is an interrupt named "a2p", then the service and
>>>> +	 * completion of a message is signaled by an interrupt rather than by
>>>> +	 * the return of the hvc call.
>>>> +	 */
>>>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>>>> +	if (irq > 0) {
>>>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>>>> +				       IRQF_NO_SUSPEND,
>>>> +				       dev_name(dev), scmi_info);
>>>> +		if (ret) {
>>>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>>> return dev_err_probe, unless this is not called in probe... but then
>>> using devm-interface raises questions.
>> This is copied as is from existing smc.c
> I understand and I hope you understand the code you copied. If there is
> a bug in existing code, please do not copy it to new code (like leaking
> OF node reference).
>
> Best regards,
> Krzysztof
>

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 19:30             ` Bjorn Andersson
@ 2023-07-18 22:05               ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 22:05 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 12:30 PM, Bjorn Andersson wrote:
> On Tue, Jul 18, 2023 at 12:10:16PM -0700, Nikunj Kela wrote:
>> On 7/18/2023 12:07 PM, Bjorn Andersson wrote:
>>> On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
>>>> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
>>>>> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>>>>>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
>>> [..]
> [..]
>>>>>> +#ifdef CONFIG_ARM64
>>>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>>>> +		       sizeof(unsigned long));
>>>>>> +#else
>>>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>>>> +		       sizeof(unsigned long));
>>>>>> +#endif
>>>>> Please don't make the in-memory representation depend on architecture
>>>>> specific data types. Quite likely you didn't compile test one of these
>>>>> variants?
>>>>>
>>>>> Just define the in-memory representation as u32 + u64.
>>>> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
>>>> support it currently. In future, it may add 32 bit support too.
>>> I'd not be surprised if the capability id is 64 bit on a 32-bit machine
>>> as well, it's not really a property of the architecture.
>> on 32bit machine, you will have to use SMC32 convention. lt will mean that
>> the parameters can only be 32 bit long. If you keep cap-id 64 bit in 32bit
>> machines, then it has to be passed in two parameters. Are you suggesting, I
>> make this driver dependent on ARM64 and only care about 64 bit for now?
>>
> I'm suggesting that the calling convention is one thing and the
> in-memory format for passing the information to the driver is a
> different thing.
>
> Keep the arguments passed in memory architecture-independent (i.e. make
> it u64).
>
> If you're saying that the calling convention would be different on a
> 32-bit system, then you are also saying that your driver _is_ 64-bit
> specific. Please confirm what the size of your capability id would be in
> such a system and make sure the Kconfig and/or the code, reflects
> reality.
>
> Thanks,
> Bjorn
It is confirmed that cap-id will be 32 bit long on 32bit machines. That 
said, I will make changes to use last 16bytes irrespective of the 
architecture.

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-18 22:05               ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-18 22:05 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/18/2023 12:30 PM, Bjorn Andersson wrote:
> On Tue, Jul 18, 2023 at 12:10:16PM -0700, Nikunj Kela wrote:
>> On 7/18/2023 12:07 PM, Bjorn Andersson wrote:
>>> On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
>>>> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
>>>>> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>>>>>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
>>> [..]
> [..]
>>>>>> +#ifdef CONFIG_ARM64
>>>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>>>> +		       sizeof(unsigned long));
>>>>>> +#else
>>>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>>>> +		       sizeof(unsigned long));
>>>>>> +#endif
>>>>> Please don't make the in-memory representation depend on architecture
>>>>> specific data types. Quite likely you didn't compile test one of these
>>>>> variants?
>>>>>
>>>>> Just define the in-memory representation as u32 + u64.
>>>> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
>>>> support it currently. In future, it may add 32 bit support too.
>>> I'd not be surprised if the capability id is 64 bit on a 32-bit machine
>>> as well, it's not really a property of the architecture.
>> on 32bit machine, you will have to use SMC32 convention. lt will mean that
>> the parameters can only be 32 bit long. If you keep cap-id 64 bit in 32bit
>> machines, then it has to be passed in two parameters. Are you suggesting, I
>> make this driver dependent on ARM64 and only care about 64 bit for now?
>>
> I'm suggesting that the calling convention is one thing and the
> in-memory format for passing the information to the driver is a
> different thing.
>
> Keep the arguments passed in memory architecture-independent (i.e. make
> it u64).
>
> If you're saying that the calling convention would be different on a
> 32-bit system, then you are also saying that your driver _is_ 64-bit
> specific. Please confirm what the size of your capability id would be in
> such a system and make sure the Kconfig and/or the code, reflects
> reality.
>
> Thanks,
> Bjorn
It is confirmed that cap-id will be 32 bit long on 32bit machines. That 
said, I will make changes to use last 16bytes irrespective of the 
architecture.

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 21:16           ` Nikunj Kela
@ 2023-07-19  6:15             ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-19  6:15 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 23:16, Nikunj Kela wrote:
> 
> On 7/18/2023 11:42 AM, Krzysztof Kozlowski wrote:
>> On 18/07/2023 20:25, Nikunj Kela wrote:
>>>>> +
>>>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>>>> +	if (!scmi_info)
>>>>> +		return -ENOMEM;
>>>>> +
>>>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>>>> You leak here reference.
>>> Wouldn't the devm_* API take care of that implicitly? It is same in
>>> smc.c as well.
>> Thanks for bringing my attention to this. I sent a fix for smc.c. Fix
>> your patch as well, please.
> Thanks, I thought you were referring to kzalloc cleanup. Will include 
> this fix. BTW, you may need to fix mailbox.c as well.

Indeed, thanks.

Best regards,
Krzysztof


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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-19  6:15             ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-19  6:15 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/07/2023 23:16, Nikunj Kela wrote:
> 
> On 7/18/2023 11:42 AM, Krzysztof Kozlowski wrote:
>> On 18/07/2023 20:25, Nikunj Kela wrote:
>>>>> +
>>>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>>>> +	if (!scmi_info)
>>>>> +		return -ENOMEM;
>>>>> +
>>>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>>>> You leak here reference.
>>> Wouldn't the devm_* API take care of that implicitly? It is same in
>>> smc.c as well.
>> Thanks for bringing my attention to this. I sent a fix for smc.c. Fix
>> your patch as well, please.
> Thanks, I thought you were referring to kzalloc cleanup. Will include 
> this fix. BTW, you may need to fix mailbox.c as well.

Indeed, thanks.

Best regards,
Krzysztof


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

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-18 16:08   ` Nikunj Kela
@ 2023-07-19 10:39     ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-07-19 10:39 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, agross, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 09:08:32AM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> index b138f3d23df8..605b1e997a85 100644
> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> @@ -45,6 +45,9 @@ properties:
>        - description: SCMI compliant firmware with OP-TEE transport
>          items:
>            - const: linaro,scmi-optee
> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> +        items:
> +          - const: qcom,scmi-hvc-shmem
>  
>    interrupts:
>      description:
> @@ -321,6 +324,16 @@ else:
>        required:
>          - linaro,optee-channel-id
>  
> +    else:
> +      if:
> +        properties:
> +          compatible:
> +            contains:
> +              const: qcom,scmi-hvc-shmem
> +      then:
> +        required:
> +          - shmem
> +

Since this was done after we merged the support recently for extension of
SMC/HVC, I need the reason(s) why this can't be used and based on the response
this is new change so it can't be because there is a product already
supporting this. So for now, NACK until I get the response for these.

-- 
Regards,
Sudeep

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-07-19 10:39     ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-07-19 10:39 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, agross, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 09:08:32AM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>  1 file changed, 69 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> index b138f3d23df8..605b1e997a85 100644
> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> @@ -45,6 +45,9 @@ properties:
>        - description: SCMI compliant firmware with OP-TEE transport
>          items:
>            - const: linaro,scmi-optee
> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> +        items:
> +          - const: qcom,scmi-hvc-shmem
>  
>    interrupts:
>      description:
> @@ -321,6 +324,16 @@ else:
>        required:
>          - linaro,optee-channel-id
>  
> +    else:
> +      if:
> +        properties:
> +          compatible:
> +            contains:
> +              const: qcom,scmi-hvc-shmem
> +      then:
> +        required:
> +          - shmem
> +

Since this was done after we merged the support recently for extension of
SMC/HVC, I need the reason(s) why this can't be used and based on the response
this is new change so it can't be because there is a product already
supporting this. So for now, NACK until I get the response for these.

-- 
Regards,
Sudeep

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 18:53       ` Nikunj Kela
@ 2023-07-19 10:55         ` Cristian Marussi
  -1 siblings, 0 replies; 186+ messages in thread
From: Cristian Marussi @ 2023-07-19 10:55 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Bjorn Andersson, sudeep.holla, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
> 
> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> > On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> > > diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> > > new file mode 100644
> > > index 000000000000..3b6096d8fe67
> > > --- /dev/null
> > > +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
> > > @@ -0,0 +1,241 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * System Control and Management Interface (SCMI) Message
> > > + * Qualcomm HVC/shmem Transport driver
> > > + *
> > > + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
> > > + * Copyright 2020 NXP
> > > + *
> > > + * This is copied from drivers/firmware/arm_scmi/smc.c
> > s/copied from/based on/
> ok.

Hi Nikunj,

> > 
> > > + */
> > > +
> > > +#include <linux/arm-smccc.h>
> > > +#include <linux/device.h>
> > > +#include <linux/err.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/mutex.h>
> > > +#include <linux/of.h>
> > > +#include <linux/of_address.h>

[snip]

> > > +
> > > +static inline void
> > > +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
> > > +			      struct scmi_xfer *xfer __maybe_unused)
> > > +{
> > You claim above that you copied smc.c, but you don't mention that you
> > dropped the support for transfers from atomic mode. Please capture this
> > in the commit message, so that someone looking at this in the future
> > knows why you made this choice.
> 
> At the moment, we dont have any requirement to support atomicity. Will add a
> comment in the commit message.
> 

As said no atomic support no wrappers needed.

> 
> > 
> > > +	mutex_lock(&scmi_info->shmem_lock);
> > > +}
> > > +
> > > +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
> > > +						 *scmi_info)
> > > +{
> > > +	mutex_unlock(&scmi_info->shmem_lock);
> > > +}
> > > +
> > > +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> > > +			       struct device *dev, bool tx)
> > > +{
> > > +	struct device *cdev = cinfo->dev;
> > > +	struct scmi_qcom_hvc *scmi_info;
> > > +	resource_size_t size;
> > > +	struct resource res;
> > > +	struct device_node *np;
> > > +	unsigned long cap_id;
> > > +	u32 func_id;
> > > +	int ret, irq;
> > Please declare one variable per line, and please sort them by length, in
> > descending order (i.e. reverse Christmas tree).
> ok
> > 
> > > +
> > > +	if (!tx)
> > > +		return -ENODEV;
> > > +
> > > +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
> > > +	if (!scmi_info)
> > > +		return -ENOMEM;
> > > +
> > > +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
> > > +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
> > > +		return -ENXIO;
> > > +
> > > +	ret = of_address_to_resource(np, 0, &res);
> > > +	of_node_put(np);
> > > +	if (ret) {
> > > +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
> > > +		return ret;
> > > +	}
> > > +
> > > +	size = resource_size(&res);
> > > +
> > > +	/* let's map 2 additional ulong since
> > > +	 * func-id & capability-id are kept after shmem.
> > > +	 *     +-------+
> > > +	 *     |       |
> > > +	 *     | shmem |
> > > +	 *     |       |
> > > +	 *     |       |
> > > +	 *     +-------+ <-- size
> > > +	 *     | funcId|
> > > +	 *     +-------+ <-- size + sizeof(ulong)
> > > +	 *     | capId |
> > > +	 *     +-------+ <-- size + 2*sizeof(ulong)
> > Relying on an undocumented convention that following the region
> > specified in DeviceTree are two architecture specifically sized integers
> > isn't good practice.
> > 
> > This should be covered by the DeviceTree binding, in one way or another.
> 
> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
> a property as cap-id-width if its allowed.
> 

This is sort of transport configuration so maybe it could be placed on a
shmem on its own, but it seems difficult that the binding can be accepted
since, as you said, is not an HW description BUT indeed configuration.

> 
> > 
> > > +	 */
> > > +
> > > +	scmi_info->shmem = devm_ioremap(dev, res.start,
> > > +					size + 2 * sizeof(unsigned long));
> > I don't find any code that uses the size of the defined shm, so I don't
> > think you need to do this dance.
> Right! I can remove the addition part.
> > 

Mmm...but can you access this trailing config bytes if you dont ioremap it ?

> > > +	if (!scmi_info->shmem) {
> > > +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> > > +		return -EADDRNOTAVAIL;
> > > +	}
> > > +
> > > +	func_id = readl((void *)(scmi_info->shmem) + size);
> > > +
> > > +#ifdef CONFIG_ARM64
> > > +	cap_id = readq((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#else
> > > +	cap_id = readl((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#endif
> > Please don't make the in-memory representation depend on architecture
> > specific data types. Quite likely you didn't compile test one of these
> > variants?
> > 
> > Just define the in-memory representation as u32 + u64.
> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
> support it currently. In future, it may add 32 bit support too.
> > > +
> > > +	/*
> > > +	 * If there is an interrupt named "a2p", then the service and
> > > +	 * completion of a message is signaled by an interrupt rather than by
> > > +	 * the return of the hvc call.
> > > +	 */
> > > +	irq = of_irq_get_byname(cdev->of_node, "a2p");
> > > +	if (irq > 0) {
> > > +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
> > > +				       IRQF_NO_SUSPEND,
> > > +				       dev_name(dev), scmi_info);
> > > +		if (ret) {
> > > +			dev_err(dev, "failed to setup SCMI completion irq\n");
> > > +			return ret;
> > > +		}
> > > +	} else {
> > > +		cinfo->no_completion_irq = true;
> > > +	}
> > > +
> > > +	scmi_info->func_id = func_id;
> > > +	scmi_info->cap_id = cap_id;
> > > +	scmi_info->cinfo = cinfo;
> > > +	qcom_hvc_channel_lock_init(scmi_info);
> > > +	cinfo->transport_info = scmi_info;
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int qcom_hvc_chan_free(int id, void *p, void *data)
> > > +{
> > > +	struct scmi_chan_info *cinfo = p;
> > > +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> > > +
> > > +	cinfo->transport_info = NULL;
> > > +	scmi_info->cinfo = NULL;
> > Your a2p interrupt is cleaned up using devres, which will happen at a
> > later point. So just setting cinfo to NULL here would cause an interrupt
> > to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
> > which happily will dereference that NULL.
> Ok, will add a check in ISR.
> > 

Other transports here takes care to block/inhibit any further possible
message reception with a transport/subsystem dependent method (like masking
the IRQ calling into mbox subsys or breaking the virtio device); I suppose
here you could also unregister the ISR before clearing to NULL.
(and I'll need to post a similar fix for SMC...)

Thanks,
Cristian

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-19 10:55         ` Cristian Marussi
  0 siblings, 0 replies; 186+ messages in thread
From: Cristian Marussi @ 2023-07-19 10:55 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Bjorn Andersson, sudeep.holla, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
> 
> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
> > On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
> > > diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
> > > new file mode 100644
> > > index 000000000000..3b6096d8fe67
> > > --- /dev/null
> > > +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
> > > @@ -0,0 +1,241 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * System Control and Management Interface (SCMI) Message
> > > + * Qualcomm HVC/shmem Transport driver
> > > + *
> > > + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
> > > + * Copyright 2020 NXP
> > > + *
> > > + * This is copied from drivers/firmware/arm_scmi/smc.c
> > s/copied from/based on/
> ok.

Hi Nikunj,

> > 
> > > + */
> > > +
> > > +#include <linux/arm-smccc.h>
> > > +#include <linux/device.h>
> > > +#include <linux/err.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/mutex.h>
> > > +#include <linux/of.h>
> > > +#include <linux/of_address.h>

[snip]

> > > +
> > > +static inline void
> > > +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
> > > +			      struct scmi_xfer *xfer __maybe_unused)
> > > +{
> > You claim above that you copied smc.c, but you don't mention that you
> > dropped the support for transfers from atomic mode. Please capture this
> > in the commit message, so that someone looking at this in the future
> > knows why you made this choice.
> 
> At the moment, we dont have any requirement to support atomicity. Will add a
> comment in the commit message.
> 

As said no atomic support no wrappers needed.

> 
> > 
> > > +	mutex_lock(&scmi_info->shmem_lock);
> > > +}
> > > +
> > > +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
> > > +						 *scmi_info)
> > > +{
> > > +	mutex_unlock(&scmi_info->shmem_lock);
> > > +}
> > > +
> > > +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
> > > +			       struct device *dev, bool tx)
> > > +{
> > > +	struct device *cdev = cinfo->dev;
> > > +	struct scmi_qcom_hvc *scmi_info;
> > > +	resource_size_t size;
> > > +	struct resource res;
> > > +	struct device_node *np;
> > > +	unsigned long cap_id;
> > > +	u32 func_id;
> > > +	int ret, irq;
> > Please declare one variable per line, and please sort them by length, in
> > descending order (i.e. reverse Christmas tree).
> ok
> > 
> > > +
> > > +	if (!tx)
> > > +		return -ENODEV;
> > > +
> > > +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
> > > +	if (!scmi_info)
> > > +		return -ENOMEM;
> > > +
> > > +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
> > > +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
> > > +		return -ENXIO;
> > > +
> > > +	ret = of_address_to_resource(np, 0, &res);
> > > +	of_node_put(np);
> > > +	if (ret) {
> > > +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
> > > +		return ret;
> > > +	}
> > > +
> > > +	size = resource_size(&res);
> > > +
> > > +	/* let's map 2 additional ulong since
> > > +	 * func-id & capability-id are kept after shmem.
> > > +	 *     +-------+
> > > +	 *     |       |
> > > +	 *     | shmem |
> > > +	 *     |       |
> > > +	 *     |       |
> > > +	 *     +-------+ <-- size
> > > +	 *     | funcId|
> > > +	 *     +-------+ <-- size + sizeof(ulong)
> > > +	 *     | capId |
> > > +	 *     +-------+ <-- size + 2*sizeof(ulong)
> > Relying on an undocumented convention that following the region
> > specified in DeviceTree are two architecture specifically sized integers
> > isn't good practice.
> > 
> > This should be covered by the DeviceTree binding, in one way or another.
> 
> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
> a property as cap-id-width if its allowed.
> 

This is sort of transport configuration so maybe it could be placed on a
shmem on its own, but it seems difficult that the binding can be accepted
since, as you said, is not an HW description BUT indeed configuration.

> 
> > 
> > > +	 */
> > > +
> > > +	scmi_info->shmem = devm_ioremap(dev, res.start,
> > > +					size + 2 * sizeof(unsigned long));
> > I don't find any code that uses the size of the defined shm, so I don't
> > think you need to do this dance.
> Right! I can remove the addition part.
> > 

Mmm...but can you access this trailing config bytes if you dont ioremap it ?

> > > +	if (!scmi_info->shmem) {
> > > +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
> > > +		return -EADDRNOTAVAIL;
> > > +	}
> > > +
> > > +	func_id = readl((void *)(scmi_info->shmem) + size);
> > > +
> > > +#ifdef CONFIG_ARM64
> > > +	cap_id = readq((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#else
> > > +	cap_id = readl((void *)(scmi_info->shmem) + size +
> > > +		       sizeof(unsigned long));
> > > +#endif
> > Please don't make the in-memory representation depend on architecture
> > specific data types. Quite likely you didn't compile test one of these
> > variants?
> > 
> > Just define the in-memory representation as u32 + u64.
> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
> support it currently. In future, it may add 32 bit support too.
> > > +
> > > +	/*
> > > +	 * If there is an interrupt named "a2p", then the service and
> > > +	 * completion of a message is signaled by an interrupt rather than by
> > > +	 * the return of the hvc call.
> > > +	 */
> > > +	irq = of_irq_get_byname(cdev->of_node, "a2p");
> > > +	if (irq > 0) {
> > > +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
> > > +				       IRQF_NO_SUSPEND,
> > > +				       dev_name(dev), scmi_info);
> > > +		if (ret) {
> > > +			dev_err(dev, "failed to setup SCMI completion irq\n");
> > > +			return ret;
> > > +		}
> > > +	} else {
> > > +		cinfo->no_completion_irq = true;
> > > +	}
> > > +
> > > +	scmi_info->func_id = func_id;
> > > +	scmi_info->cap_id = cap_id;
> > > +	scmi_info->cinfo = cinfo;
> > > +	qcom_hvc_channel_lock_init(scmi_info);
> > > +	cinfo->transport_info = scmi_info;
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int qcom_hvc_chan_free(int id, void *p, void *data)
> > > +{
> > > +	struct scmi_chan_info *cinfo = p;
> > > +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
> > > +
> > > +	cinfo->transport_info = NULL;
> > > +	scmi_info->cinfo = NULL;
> > Your a2p interrupt is cleaned up using devres, which will happen at a
> > later point. So just setting cinfo to NULL here would cause an interrupt
> > to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
> > which happily will dereference that NULL.
> Ok, will add a check in ISR.
> > 

Other transports here takes care to block/inhibit any further possible
message reception with a transport/subsystem dependent method (like masking
the IRQ calling into mbox subsys or breaking the virtio device); I suppose
here you could also unregister the ISR before clearing to NULL.
(and I'll need to post a similar fix for SMC...)

Thanks,
Cristian

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

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-19 10:39     ` Sudeep Holla
@ 2023-07-19 13:58       ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-19 13:58 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/19/2023 3:39 AM, Sudeep Holla wrote:
> On Tue, Jul 18, 2023 at 09:08:32AM -0700, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
>> transport channel for Qualcomm virtual platforms.
>> The compatible mandates a shared memory channel.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>>   1 file changed, 69 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> index b138f3d23df8..605b1e997a85 100644
>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> @@ -45,6 +45,9 @@ properties:
>>         - description: SCMI compliant firmware with OP-TEE transport
>>           items:
>>             - const: linaro,scmi-optee
>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>> +        items:
>> +          - const: qcom,scmi-hvc-shmem
>>   
>>     interrupts:
>>       description:
>> @@ -321,6 +324,16 @@ else:
>>         required:
>>           - linaro,optee-channel-id
>>   
>> +    else:
>> +      if:
>> +        properties:
>> +          compatible:
>> +            contains:
>> +              const: qcom,scmi-hvc-shmem
>> +      then:
>> +        required:
>> +          - shmem
>> +
> Since this was done after we merged the support recently for extension of
> SMC/HVC, I need the reason(s) why this can't be used and based on the response
> this is new change so it can't be because there is a product already
> supporting this. So for now, NACK until I get the response for these.
Our hypervisor deals with objects and uses object-ids to identify them. 
The hvc doorbell object is independent of the shmem object created by 
hypervisor. Hypervisor treats them independently. With the patch you 
mentioned, hypervisor need to create an association between the doorbell 
object and shmem object which will make it SCMI specific change in 
hypervisor. Hypervisor doesn't really care if doorbell is for SCMI or 
for other purposes hence we are adding this new driver so it can work 
with our hypervisor ABIs specification.

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

* Re: [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-07-19 13:58       ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-19 13:58 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/19/2023 3:39 AM, Sudeep Holla wrote:
> On Tue, Jul 18, 2023 at 09:08:32AM -0700, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
>> transport channel for Qualcomm virtual platforms.
>> The compatible mandates a shared memory channel.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   .../bindings/firmware/arm,scmi.yaml           | 69 +++++++++++++++++++
>>   1 file changed, 69 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> index b138f3d23df8..605b1e997a85 100644
>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> @@ -45,6 +45,9 @@ properties:
>>         - description: SCMI compliant firmware with OP-TEE transport
>>           items:
>>             - const: linaro,scmi-optee
>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>> +        items:
>> +          - const: qcom,scmi-hvc-shmem
>>   
>>     interrupts:
>>       description:
>> @@ -321,6 +324,16 @@ else:
>>         required:
>>           - linaro,optee-channel-id
>>   
>> +    else:
>> +      if:
>> +        properties:
>> +          compatible:
>> +            contains:
>> +              const: qcom,scmi-hvc-shmem
>> +      then:
>> +        required:
>> +          - shmem
>> +
> Since this was done after we merged the support recently for extension of
> SMC/HVC, I need the reason(s) why this can't be used and based on the response
> this is new change so it can't be because there is a product already
> supporting this. So for now, NACK until I get the response for these.
Our hypervisor deals with objects and uses object-ids to identify them. 
The hvc doorbell object is independent of the shmem object created by 
hypervisor. Hypervisor treats them independently. With the patch you 
mentioned, hypervisor need to create an association between the doorbell 
object and shmem object which will make it SCMI specific change in 
hypervisor. Hypervisor doesn't really care if doorbell is for SCMI or 
for other purposes hence we are adding this new driver so it can work 
with our hypervisor ABIs specification.

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-19 10:55         ` Cristian Marussi
@ 2023-07-19 14:02           ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-19 14:02 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: Bjorn Andersson, sudeep.holla, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/19/2023 3:55 AM, Cristian Marussi wrote:
> On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
>> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
>>> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>>>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
>>>> new file mode 100644
>>>> index 000000000000..3b6096d8fe67
>>>> --- /dev/null
>>>> +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
>>>> @@ -0,0 +1,241 @@
>>>> +// SPDX-License-Identifier: GPL-2.0
>>>> +/*
>>>> + * System Control and Management Interface (SCMI) Message
>>>> + * Qualcomm HVC/shmem Transport driver
>>>> + *
>>>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
>>>> + * Copyright 2020 NXP
>>>> + *
>>>> + * This is copied from drivers/firmware/arm_scmi/smc.c
>>> s/copied from/based on/
>> ok.
> Hi Nikunj,
>
>>>> + */
>>>> +
>>>> +#include <linux/arm-smccc.h>
>>>> +#include <linux/device.h>
>>>> +#include <linux/err.h>
>>>> +#include <linux/interrupt.h>
>>>> +#include <linux/mutex.h>
>>>> +#include <linux/of.h>
>>>> +#include <linux/of_address.h>
> [snip]
>
>>>> +
>>>> +static inline void
>>>> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
>>>> +			      struct scmi_xfer *xfer __maybe_unused)
>>>> +{
>>> You claim above that you copied smc.c, but you don't mention that you
>>> dropped the support for transfers from atomic mode. Please capture this
>>> in the commit message, so that someone looking at this in the future
>>> knows why you made this choice.
>> At the moment, we dont have any requirement to support atomicity. Will add a
>> comment in the commit message.
>>
> As said no atomic support no wrappers needed.
ACK!
>
>>>> +	mutex_lock(&scmi_info->shmem_lock);
>>>> +}
>>>> +
>>>> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
>>>> +						 *scmi_info)
>>>> +{
>>>> +	mutex_unlock(&scmi_info->shmem_lock);
>>>> +}
>>>> +
>>>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>>>> +			       struct device *dev, bool tx)
>>>> +{
>>>> +	struct device *cdev = cinfo->dev;
>>>> +	struct scmi_qcom_hvc *scmi_info;
>>>> +	resource_size_t size;
>>>> +	struct resource res;
>>>> +	struct device_node *np;
>>>> +	unsigned long cap_id;
>>>> +	u32 func_id;
>>>> +	int ret, irq;
>>> Please declare one variable per line, and please sort them by length, in
>>> descending order (i.e. reverse Christmas tree).
>> ok
>>>> +
>>>> +	if (!tx)
>>>> +		return -ENODEV;
>>>> +
>>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>>> +	if (!scmi_info)
>>>> +		return -ENOMEM;
>>>> +
>>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>>>> +		return -ENXIO;
>>>> +
>>>> +	ret = of_address_to_resource(np, 0, &res);
>>>> +	of_node_put(np);
>>>> +	if (ret) {
>>>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>>>> +		return ret;
>>>> +	}
>>>> +
>>>> +	size = resource_size(&res);
>>>> +
>>>> +	/* let's map 2 additional ulong since
>>>> +	 * func-id & capability-id are kept after shmem.
>>>> +	 *     +-------+
>>>> +	 *     |       |
>>>> +	 *     | shmem |
>>>> +	 *     |       |
>>>> +	 *     |       |
>>>> +	 *     +-------+ <-- size
>>>> +	 *     | funcId|
>>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>>> +	 *     | capId |
>>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>> Relying on an undocumented convention that following the region
>>> specified in DeviceTree are two architecture specifically sized integers
>>> isn't good practice.
>>>
>>> This should be covered by the DeviceTree binding, in one way or another.
>> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
>> a property as cap-id-width if its allowed.
>>
> This is sort of transport configuration so maybe it could be placed on a
> shmem on its own, but it seems difficult that the binding can be accepted
> since, as you said, is not an HW description BUT indeed configuration.
Ok.
>
>>>> +	 */
>>>> +
>>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>>> +					size + 2 * sizeof(unsigned long));
>>> I don't find any code that uses the size of the defined shm, so I don't
>>> think you need to do this dance.
>> Right! I can remove the addition part.
> Mmm...but can you access this trailing config bytes if you dont ioremap it ?
No, I meant, the last 16 bytes of each channel can be used so we don't 
need to remap 2 extra ulong.
>
>>>> +	if (!scmi_info->shmem) {
>>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>>> +		return -EADDRNOTAVAIL;
>>>> +	}
>>>> +
>>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>>> +
>>>> +#ifdef CONFIG_ARM64
>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#else
>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#endif
>>> Please don't make the in-memory representation depend on architecture
>>> specific data types. Quite likely you didn't compile test one of these
>>> variants?
>>>
>>> Just define the in-memory representation as u32 + u64.
>> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
>> support it currently. In future, it may add 32 bit support too.
>>>> +
>>>> +	/*
>>>> +	 * If there is an interrupt named "a2p", then the service and
>>>> +	 * completion of a message is signaled by an interrupt rather than by
>>>> +	 * the return of the hvc call.
>>>> +	 */
>>>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>>>> +	if (irq > 0) {
>>>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>>>> +				       IRQF_NO_SUSPEND,
>>>> +				       dev_name(dev), scmi_info);
>>>> +		if (ret) {
>>>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>>>> +			return ret;
>>>> +		}
>>>> +	} else {
>>>> +		cinfo->no_completion_irq = true;
>>>> +	}
>>>> +
>>>> +	scmi_info->func_id = func_id;
>>>> +	scmi_info->cap_id = cap_id;
>>>> +	scmi_info->cinfo = cinfo;
>>>> +	qcom_hvc_channel_lock_init(scmi_info);
>>>> +	cinfo->transport_info = scmi_info;
>>>> +
>>>> +	return 0;
>>>> +}
>>>> +
>>>> +static int qcom_hvc_chan_free(int id, void *p, void *data)
>>>> +{
>>>> +	struct scmi_chan_info *cinfo = p;
>>>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>>>> +
>>>> +	cinfo->transport_info = NULL;
>>>> +	scmi_info->cinfo = NULL;
>>> Your a2p interrupt is cleaned up using devres, which will happen at a
>>> later point. So just setting cinfo to NULL here would cause an interrupt
>>> to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
>>> which happily will dereference that NULL.
>> Ok, will add a check in ISR.
> Other transports here takes care to block/inhibit any further possible
> message reception with a transport/subsystem dependent method (like masking
> the IRQ calling into mbox subsys or breaking the virtio device); I suppose
> here you could also unregister the ISR before clearing to NULL.
> (and I'll need to post a similar fix for SMC...)
Thanks, will do!
>
> Thanks,
> Cristian

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-19 14:02           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-19 14:02 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: Bjorn Andersson, sudeep.holla, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/19/2023 3:55 AM, Cristian Marussi wrote:
> On Tue, Jul 18, 2023 at 11:53:24AM -0700, Nikunj Kela wrote:
>> On 7/18/2023 11:29 AM, Bjorn Andersson wrote:
>>> On Tue, Jul 18, 2023 at 09:08:33AM -0700, Nikunj Kela wrote:
>>>> diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
>>>> new file mode 100644
>>>> index 000000000000..3b6096d8fe67
>>>> --- /dev/null
>>>> +++ b/drivers/firmware/arm_scmi/qcom_hvc.c
>>>> @@ -0,0 +1,241 @@
>>>> +// SPDX-License-Identifier: GPL-2.0
>>>> +/*
>>>> + * System Control and Management Interface (SCMI) Message
>>>> + * Qualcomm HVC/shmem Transport driver
>>>> + *
>>>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
>>>> + * Copyright 2020 NXP
>>>> + *
>>>> + * This is copied from drivers/firmware/arm_scmi/smc.c
>>> s/copied from/based on/
>> ok.
> Hi Nikunj,
>
>>>> + */
>>>> +
>>>> +#include <linux/arm-smccc.h>
>>>> +#include <linux/device.h>
>>>> +#include <linux/err.h>
>>>> +#include <linux/interrupt.h>
>>>> +#include <linux/mutex.h>
>>>> +#include <linux/of.h>
>>>> +#include <linux/of_address.h>
> [snip]
>
>>>> +
>>>> +static inline void
>>>> +qcom_hvc_channel_lock_acquire(struct scmi_qcom_hvc *scmi_info,
>>>> +			      struct scmi_xfer *xfer __maybe_unused)
>>>> +{
>>> You claim above that you copied smc.c, but you don't mention that you
>>> dropped the support for transfers from atomic mode. Please capture this
>>> in the commit message, so that someone looking at this in the future
>>> knows why you made this choice.
>> At the moment, we dont have any requirement to support atomicity. Will add a
>> comment in the commit message.
>>
> As said no atomic support no wrappers needed.
ACK!
>
>>>> +	mutex_lock(&scmi_info->shmem_lock);
>>>> +}
>>>> +
>>>> +static inline void qcom_hvc_channel_lock_release(struct scmi_qcom_hvc
>>>> +						 *scmi_info)
>>>> +{
>>>> +	mutex_unlock(&scmi_info->shmem_lock);
>>>> +}
>>>> +
>>>> +static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
>>>> +			       struct device *dev, bool tx)
>>>> +{
>>>> +	struct device *cdev = cinfo->dev;
>>>> +	struct scmi_qcom_hvc *scmi_info;
>>>> +	resource_size_t size;
>>>> +	struct resource res;
>>>> +	struct device_node *np;
>>>> +	unsigned long cap_id;
>>>> +	u32 func_id;
>>>> +	int ret, irq;
>>> Please declare one variable per line, and please sort them by length, in
>>> descending order (i.e. reverse Christmas tree).
>> ok
>>>> +
>>>> +	if (!tx)
>>>> +		return -ENODEV;
>>>> +
>>>> +	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
>>>> +	if (!scmi_info)
>>>> +		return -ENOMEM;
>>>> +
>>>> +	np = of_parse_phandle(cdev->of_node, "shmem", 0);
>>>> +	if (!of_device_is_compatible(np, "arm,scmi-shmem"))
>>>> +		return -ENXIO;
>>>> +
>>>> +	ret = of_address_to_resource(np, 0, &res);
>>>> +	of_node_put(np);
>>>> +	if (ret) {
>>>> +		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
>>>> +		return ret;
>>>> +	}
>>>> +
>>>> +	size = resource_size(&res);
>>>> +
>>>> +	/* let's map 2 additional ulong since
>>>> +	 * func-id & capability-id are kept after shmem.
>>>> +	 *     +-------+
>>>> +	 *     |       |
>>>> +	 *     | shmem |
>>>> +	 *     |       |
>>>> +	 *     |       |
>>>> +	 *     +-------+ <-- size
>>>> +	 *     | funcId|
>>>> +	 *     +-------+ <-- size + sizeof(ulong)
>>>> +	 *     | capId |
>>>> +	 *     +-------+ <-- size + 2*sizeof(ulong)
>>> Relying on an undocumented convention that following the region
>>> specified in DeviceTree are two architecture specifically sized integers
>>> isn't good practice.
>>>
>>> This should be covered by the DeviceTree binding, in one way or another.
>> ok. Usually, DTBs don't allow non-hw properties in the dtb. I can try adding
>> a property as cap-id-width if its allowed.
>>
> This is sort of transport configuration so maybe it could be placed on a
> shmem on its own, but it seems difficult that the binding can be accepted
> since, as you said, is not an HW description BUT indeed configuration.
Ok.
>
>>>> +	 */
>>>> +
>>>> +	scmi_info->shmem = devm_ioremap(dev, res.start,
>>>> +					size + 2 * sizeof(unsigned long));
>>> I don't find any code that uses the size of the defined shm, so I don't
>>> think you need to do this dance.
>> Right! I can remove the addition part.
> Mmm...but can you access this trailing config bytes if you dont ioremap it ?
No, I meant, the last 16 bytes of each channel can be used so we don't 
need to remap 2 extra ulong.
>
>>>> +	if (!scmi_info->shmem) {
>>>> +		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
>>>> +		return -EADDRNOTAVAIL;
>>>> +	}
>>>> +
>>>> +	func_id = readl((void *)(scmi_info->shmem) + size);
>>>> +
>>>> +#ifdef CONFIG_ARM64
>>>> +	cap_id = readq((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#else
>>>> +	cap_id = readl((void *)(scmi_info->shmem) + size +
>>>> +		       sizeof(unsigned long));
>>>> +#endif
>>> Please don't make the in-memory representation depend on architecture
>>> specific data types. Quite likely you didn't compile test one of these
>>> variants?
>>>
>>> Just define the in-memory representation as u32 + u64.
>> I tested this for ARM64, I didn't test it for 32bit since Hypervisor doesn't
>> support it currently. In future, it may add 32 bit support too.
>>>> +
>>>> +	/*
>>>> +	 * If there is an interrupt named "a2p", then the service and
>>>> +	 * completion of a message is signaled by an interrupt rather than by
>>>> +	 * the return of the hvc call.
>>>> +	 */
>>>> +	irq = of_irq_get_byname(cdev->of_node, "a2p");
>>>> +	if (irq > 0) {
>>>> +		ret = devm_request_irq(dev, irq, qcom_hvc_msg_done_isr,
>>>> +				       IRQF_NO_SUSPEND,
>>>> +				       dev_name(dev), scmi_info);
>>>> +		if (ret) {
>>>> +			dev_err(dev, "failed to setup SCMI completion irq\n");
>>>> +			return ret;
>>>> +		}
>>>> +	} else {
>>>> +		cinfo->no_completion_irq = true;
>>>> +	}
>>>> +
>>>> +	scmi_info->func_id = func_id;
>>>> +	scmi_info->cap_id = cap_id;
>>>> +	scmi_info->cinfo = cinfo;
>>>> +	qcom_hvc_channel_lock_init(scmi_info);
>>>> +	cinfo->transport_info = scmi_info;
>>>> +
>>>> +	return 0;
>>>> +}
>>>> +
>>>> +static int qcom_hvc_chan_free(int id, void *p, void *data)
>>>> +{
>>>> +	struct scmi_chan_info *cinfo = p;
>>>> +	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
>>>> +
>>>> +	cinfo->transport_info = NULL;
>>>> +	scmi_info->cinfo = NULL;
>>> Your a2p interrupt is cleaned up using devres, which will happen at a
>>> later point. So just setting cinfo to NULL here would cause an interrupt
>>> to trigger qcom_hvc_msg_done_isr() which will call scmi_rx_callback()
>>> which happily will dereference that NULL.
>> Ok, will add a check in ISR.
> Other transports here takes care to block/inhibit any further possible
> message reception with a transport/subsystem dependent method (like masking
> the IRQ calling into mbox subsys or breaking the virtio device); I suppose
> here you could also unregister the ISR before clearing to NULL.
> (and I'll need to post a similar fix for SMC...)
Thanks, will do!
>
> Thanks,
> Cristian

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

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-18 16:08   ` Nikunj Kela
@ 2023-07-23  2:15     ` kernel test robot
  -1 siblings, 0 replies; 186+ messages in thread
From: kernel test robot @ 2023-07-23  2:15 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: oe-kbuild-all, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm, Nikunj Kela

Hi Nikunj,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.5-rc2 next-20230721]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nikunj-Kela/dt-bindings-arm-Add-qcom-specific-hvc-transport-for-SCMI/20230719-001116
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230718160833.36397-3-quic_nkela%40quicinc.com
patch subject: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
config: arm64-randconfig-r083-20230723 (https://download.01.org/0day-ci/archive/20230723/202307231034.5C5lj4Dv-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230723/202307231034.5C5lj4Dv-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307231034.5C5lj4Dv-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/firmware/arm_scmi/qcom_hvc.c:136:26: sparse: sparse: cast removes address space '__iomem' of expression
>> drivers/firmware/arm_scmi/qcom_hvc.c:136:52: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void * @@
   drivers/firmware/arm_scmi/qcom_hvc.c:136:52: sparse:     expected void const volatile [noderef] __iomem *addr
   drivers/firmware/arm_scmi/qcom_hvc.c:136:52: sparse:     got void *
   drivers/firmware/arm_scmi/qcom_hvc.c:139:25: sparse: sparse: cast removes address space '__iomem' of expression
   drivers/firmware/arm_scmi/qcom_hvc.c:139:58: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void * @@
   drivers/firmware/arm_scmi/qcom_hvc.c:139:58: sparse:     expected void const volatile [noderef] __iomem *addr
   drivers/firmware/arm_scmi/qcom_hvc.c:139:58: sparse:     got void *

vim +/__iomem +136 drivers/firmware/arm_scmi/qcom_hvc.c

    82	
    83	static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
    84				       struct device *dev, bool tx)
    85	{
    86		struct device *cdev = cinfo->dev;
    87		struct scmi_qcom_hvc *scmi_info;
    88		resource_size_t size;
    89		struct resource res;
    90		struct device_node *np;
    91		unsigned long cap_id;
    92		u32 func_id;
    93		int ret, irq;
    94	
    95		if (!tx)
    96			return -ENODEV;
    97	
    98		scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
    99		if (!scmi_info)
   100			return -ENOMEM;
   101	
   102		np = of_parse_phandle(cdev->of_node, "shmem", 0);
   103		if (!of_device_is_compatible(np, "arm,scmi-shmem"))
   104			return -ENXIO;
   105	
   106		ret = of_address_to_resource(np, 0, &res);
   107		of_node_put(np);
   108		if (ret) {
   109			dev_err(cdev, "failed to get SCMI Tx shared memory\n");
   110			return ret;
   111		}
   112	
   113		size = resource_size(&res);
   114	
   115		/* let's map 2 additional ulong since
   116		 * func-id & capability-id are kept after shmem.
   117		 *     +-------+
   118		 *     |       |
   119		 *     | shmem |
   120		 *     |       |
   121		 *     |       |
   122		 *     +-------+ <-- size
   123		 *     | funcId|
   124		 *     +-------+ <-- size + sizeof(ulong)
   125		 *     | capId |
   126		 *     +-------+ <-- size + 2*sizeof(ulong)
   127		 */
   128	
   129		scmi_info->shmem = devm_ioremap(dev, res.start,
   130						size + 2 * sizeof(unsigned long));
   131		if (!scmi_info->shmem) {
   132			dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
   133			return -EADDRNOTAVAIL;
   134		}
   135	
 > 136		func_id = readl((void *)(scmi_info->shmem) + size);
   137	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-23  2:15     ` kernel test robot
  0 siblings, 0 replies; 186+ messages in thread
From: kernel test robot @ 2023-07-23  2:15 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: oe-kbuild-all, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, agross, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm, Nikunj Kela

Hi Nikunj,

kernel test robot noticed the following build warnings:

[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.5-rc2 next-20230721]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nikunj-Kela/dt-bindings-arm-Add-qcom-specific-hvc-transport-for-SCMI/20230719-001116
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230718160833.36397-3-quic_nkela%40quicinc.com
patch subject: [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport
config: arm64-randconfig-r083-20230723 (https://download.01.org/0day-ci/archive/20230723/202307231034.5C5lj4Dv-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230723/202307231034.5C5lj4Dv-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307231034.5C5lj4Dv-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/firmware/arm_scmi/qcom_hvc.c:136:26: sparse: sparse: cast removes address space '__iomem' of expression
>> drivers/firmware/arm_scmi/qcom_hvc.c:136:52: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void * @@
   drivers/firmware/arm_scmi/qcom_hvc.c:136:52: sparse:     expected void const volatile [noderef] __iomem *addr
   drivers/firmware/arm_scmi/qcom_hvc.c:136:52: sparse:     got void *
   drivers/firmware/arm_scmi/qcom_hvc.c:139:25: sparse: sparse: cast removes address space '__iomem' of expression
   drivers/firmware/arm_scmi/qcom_hvc.c:139:58: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const volatile [noderef] __iomem *addr @@     got void * @@
   drivers/firmware/arm_scmi/qcom_hvc.c:139:58: sparse:     expected void const volatile [noderef] __iomem *addr
   drivers/firmware/arm_scmi/qcom_hvc.c:139:58: sparse:     got void *

vim +/__iomem +136 drivers/firmware/arm_scmi/qcom_hvc.c

    82	
    83	static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
    84				       struct device *dev, bool tx)
    85	{
    86		struct device *cdev = cinfo->dev;
    87		struct scmi_qcom_hvc *scmi_info;
    88		resource_size_t size;
    89		struct resource res;
    90		struct device_node *np;
    91		unsigned long cap_id;
    92		u32 func_id;
    93		int ret, irq;
    94	
    95		if (!tx)
    96			return -ENODEV;
    97	
    98		scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
    99		if (!scmi_info)
   100			return -ENOMEM;
   101	
   102		np = of_parse_phandle(cdev->of_node, "shmem", 0);
   103		if (!of_device_is_compatible(np, "arm,scmi-shmem"))
   104			return -ENXIO;
   105	
   106		ret = of_address_to_resource(np, 0, &res);
   107		of_node_put(np);
   108		if (ret) {
   109			dev_err(cdev, "failed to get SCMI Tx shared memory\n");
   110			return ret;
   111		}
   112	
   113		size = resource_size(&res);
   114	
   115		/* let's map 2 additional ulong since
   116		 * func-id & capability-id are kept after shmem.
   117		 *     +-------+
   118		 *     |       |
   119		 *     | shmem |
   120		 *     |       |
   121		 *     |       |
   122		 *     +-------+ <-- size
   123		 *     | funcId|
   124		 *     +-------+ <-- size + sizeof(ulong)
   125		 *     | capId |
   126		 *     +-------+ <-- size + 2*sizeof(ulong)
   127		 */
   128	
   129		scmi_info->shmem = devm_ioremap(dev, res.start,
   130						size + 2 * sizeof(unsigned long));
   131		if (!scmi_info->shmem) {
   132			dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
   133			return -EADDRNOTAVAIL;
   134		}
   135	
 > 136		func_id = readl((void *)(scmi_info->shmem) + size);
   137	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

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

* [PATCH v2 0/3] Add qcom hvc/shmem transport
  2023-07-18 16:08 ` Nikunj Kela
                   ` (2 preceding siblings ...)
  (?)
@ 2023-07-24 16:44 ` Nikunj Kela
  2023-07-24 16:44   ` [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
                     ` (2 more replies)
  -1 siblings, 3 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-24 16:44 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change introduce a new transport channel for Qualcomm virtual
platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
The difference between the two transports is that a parameter is passed in
the hypervisor call to identify which doorbell to assert. This parameter is
dynamically generated at runtime on the device and insuitable to pass via
the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (3):
  dt-bindings: arm: convert nested if-else construct to allOf
  dt-bindings: arm: Add qcom specific hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport

 .../bindings/firmware/arm,scmi.yaml           |  67 +++---
 drivers/firmware/arm_scmi/Kconfig             |  13 +
 drivers/firmware/arm_scmi/Makefile            |   1 +
 drivers/firmware/arm_scmi/common.h            |   3 +
 drivers/firmware/arm_scmi/driver.c            |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c          | 224 ++++++++++++++++++
 6 files changed, 284 insertions(+), 28 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

-- 
2.17.1


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

* [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf
  2023-07-24 16:44 ` [PATCH v2 0/3] " Nikunj Kela
@ 2023-07-24 16:44   ` Nikunj Kela
  2023-07-25  6:01     ` Krzysztof Kozlowski
  2023-07-24 16:44   ` [PATCH v2 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI Nikunj Kela
  2023-07-24 16:44   ` [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
  2 siblings, 1 reply; 186+ messages in thread
From: Nikunj Kela @ 2023-07-24 16:44 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Nested if-else construct is not scalable therefore, convert
it to allOf:if-else.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 .../bindings/firmware/arm,scmi.yaml           | 55 +++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..8d54ea768d38 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -284,35 +284,34 @@ $defs:
 required:
   - compatible
 
-if:
-  properties:
-    compatible:
-      contains:
-        const: arm,scmi
-then:
-  properties:
-    interrupts: false
-    interrupt-names: false
-
-  required:
-    - mboxes
-    - shmem
-
-else:
-  if:
-    properties:
-      compatible:
-        contains:
-          enum:
-            - arm,scmi-smc
-            - arm,scmi-smc-param
-  then:
-    required:
-      - arm,smc-id
-      - shmem
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: arm,scmi
+    then:
+      properties:
+        interrupts: false
+        interrupt-names: false
+
+      required:
+        - mboxes
+        - shmem
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - arm,scmi-smc
+              - arm,scmi-smc-param
+    then:
+      required:
+        - arm,smc-id
+        - shmem
 
-  else:
-    if:
+  - if:
       properties:
         compatible:
           contains:
-- 
2.17.1


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

* [PATCH v2 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-24 16:44 ` [PATCH v2 0/3] " Nikunj Kela
  2023-07-24 16:44   ` [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
@ 2023-07-24 16:44   ` Nikunj Kela
  2023-07-25  6:06     ` Krzysztof Kozlowski
  2023-07-24 16:44   ` [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
  2 siblings, 1 reply; 186+ messages in thread
From: Nikunj Kela @ 2023-07-24 16:44 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 8d54ea768d38..4090240f45b1 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -320,6 +323,15 @@ allOf:
       required:
         - linaro,optee-channel-id
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,scmi-hvc-shmem
+    then:
+      required:
+        - shmem
+
 examples:
   - |
     firmware {
-- 
2.17.1


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

* [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-24 16:44 ` [PATCH v2 0/3] " Nikunj Kela
  2023-07-24 16:44   ` [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
  2023-07-24 16:44   ` [PATCH v2 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI Nikunj Kela
@ 2023-07-24 16:44   ` Nikunj Kela
  2023-07-25 17:03     ` Cristian Marussi
  2023-08-01  7:27       ` kernel test robot
  2 siblings, 2 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-24 16:44 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Add a new transport channel to the SCMI firmware interface driver for
SCMI message exchange on Qualcomm virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The qcom hvc doorbell/shared memory transport uses a statically defined
shared memory region that binds with "arm,scmi-shmem" device tree node.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Currently, there is no usecase for the atomic support therefore this driver
doesn't include the changes for the same.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig    |  13 ++
 drivers/firmware/arm_scmi/Makefile   |   1 +
 drivers/firmware/arm_scmi/common.h   |   3 +
 drivers/firmware/arm_scmi/driver.c   |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c | 224 +++++++++++++++++++++++++++
 5 files changed, 245 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..40d07329ebf7 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -99,6 +99,19 @@ config ARM_SCMI_TRANSPORT_OPTEE
 	  If you want the ARM SCMI PROTOCOL stack to include support for a
 	  transport based on OP-TEE SCMI service, answer Y.
 
+config ARM_SCMI_TRANSPORT_QCOM_HVC
+	bool "SCMI transport based on hvc doorbell & shmem for Qualcomm SoCs"
+	depends on ARCH_QCOM
+	select ARM_SCMI_HAVE_TRANSPORT
+	select ARM_SCMI_HAVE_SHMEM
+	default y
+	help
+	  Enable hvc doorbell & shmem based transport for SCMI.
+
+	  If you want the ARM SCMI PROTOCOL stack to include support for a
+	  hvc doorbell and shmem transport on Qualcomm virtual platforms,
+	  answer Y.
+
 config ARM_SCMI_TRANSPORT_SMC
 	bool "SCMI transport based on SMC"
 	depends on HAVE_ARM_SMCCC_DISCOVERY
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index b31d78fa66cc..ba1ff5893ec0 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -10,6 +10,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o
+scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC) += qcom_hvc.o
 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o
 scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
 
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index c46dc5215af7..5c98cbb1278b 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -298,6 +298,9 @@ extern const struct scmi_desc scmi_virtio_desc;
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE
 extern const struct scmi_desc scmi_optee_desc;
 #endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+extern const struct scmi_desc scmi_qcom_hvc_desc;
+#endif
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv);
 
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index b5957cc12fee..c54519596c29 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2918,6 +2918,10 @@ static const struct of_device_id scmi_of_match[] = {
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
+#endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+	{ .compatible = "qcom,scmi-hvc-shmem",
+	  .data = &scmi_qcom_hvc_desc },
 #endif
 	{ /* Sentinel */ },
 };
diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
new file mode 100644
index 000000000000..9aa60d6bb797
--- /dev/null
+++ b/drivers/firmware/arm_scmi/qcom_hvc.c
@@ -0,0 +1,224 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) Message
+ * Qualcomm HVC/shmem Transport driver
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright 2020 NXP
+ *
+ * This is based on drivers/firmware/arm_scmi/smc.c
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/slab.h>
+
+#include "common.h"
+
+/**
+ * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
+ *
+ * @irq: An optional IRQ for completion
+ * @cinfo: SCMI channel info
+ * @shmem: Transmit/Receive shared memory area
+ * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
+ * @func_id: hvc call function-id
+ * @cap_id: hvc doorbell's capability id
+ */
+
+struct scmi_qcom_hvc {
+	int irq;
+	struct scmi_chan_info *cinfo;
+	struct scmi_shared_mem __iomem *shmem;
+	/* Protect access to shmem area */
+	struct mutex shmem_lock;
+	u32 func_id;
+	u64 cap_id;
+};
+
+static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
+{
+	struct scmi_qcom_hvc *scmi_info = data;
+
+	scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem), NULL);
+
+	return IRQ_HANDLED;
+}
+
+static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
+{
+	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
+
+	if (!np)
+		return false;
+
+	of_node_put(np);
+	return true;
+}
+
+static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
+			       struct device *dev, bool tx)
+{
+	struct device *cdev = cinfo->dev;
+	struct scmi_qcom_hvc *scmi_info;
+	struct device_node *np;
+	resource_size_t size;
+	struct resource res;
+	u32 func_id;
+	u64 cap_id;
+	int ret;
+
+	if (!tx)
+		return -ENODEV;
+
+	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
+	if (!scmi_info)
+		return -ENOMEM;
+
+	np = of_parse_phandle(cdev->of_node, "shmem", 0);
+	if (!of_device_is_compatible(np, "arm,scmi-shmem")) {
+		of_node_put(np);
+		return -ENXIO;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	of_node_put(np);
+	if (ret) {
+		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
+		return ret;
+	}
+
+	size = resource_size(&res);
+
+	/* The func-id & capability-id are kept in last 16 bytes of shmem.
+	 *     +-------+
+	 *     |       |
+	 *     | shmem |
+	 *     |       |
+	 *     |       |
+	 *     +-------+ <-- (size - 16)
+	 *     | funcId|
+	 *     +-------+ <-- (size - 8)
+	 *     | capId |
+	 *     +-------+ <-- size
+	 */
+
+	scmi_info->shmem = devm_ioremap(dev, res.start, size);
+	if (!scmi_info->shmem) {
+		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
+		return -EADDRNOTAVAIL;
+	}
+
+	func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
+
+#ifdef CONFIG_ARM64
+	cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
+#else
+	/* capability-id is 32 bit long on 32bit machines */
+	cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
+#endif
+
+	/*
+	 * If there is an interrupt named "a2p", then the service and
+	 * completion of a message is signaled by an interrupt rather than by
+	 * the return of the hvc call.
+	 */
+	scmi_info->irq = of_irq_get_byname(cdev->of_node, "a2p");
+	if (scmi_info->irq > 0) {
+		ret = request_irq(scmi_info->irq, qcom_hvc_msg_done_isr,
+				  IRQF_NO_SUSPEND, dev_name(dev), scmi_info);
+		if (ret) {
+			dev_err(dev, "failed to setup SCMI completion irq\n");
+			return ret;
+		}
+	} else {
+		cinfo->no_completion_irq = true;
+	}
+
+	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
+	scmi_info->cinfo = cinfo;
+	mutex_init(&scmi_info->shmem_lock);
+	cinfo->transport_info = scmi_info;
+
+	return 0;
+}
+
+static int qcom_hvc_chan_free(int id, void *p, void *data)
+{
+	struct scmi_chan_info *cinfo = p;
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	/* Ignore any possible further reception on the IRQ path */
+	if (scmi_info->irq > 0)
+		free_irq(scmi_info->irq, scmi_info);
+
+	cinfo->transport_info = NULL;
+	scmi_info->cinfo = NULL;
+
+	return 0;
+}
+
+static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
+				 struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+	struct arm_smccc_res res;
+
+	/*
+	 * Channel will be released only once response has been
+	 * surely fully retrieved, so after .mark_txdone()
+	 */
+	mutex_lock(&scmi_info->shmem_lock);
+
+	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
+
+	arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
+			  0, 0, 0, 0, 0, 0, &res);
+
+	if (res.a0) {
+		mutex_unlock(&scmi_info->shmem_lock);
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
+				    struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	shmem_fetch_response(scmi_info->shmem, xfer);
+}
+
+static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
+				 struct scmi_xfer *__unused)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	mutex_unlock(&scmi_info->shmem_lock);
+}
+
+static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
+	.chan_available = qcom_hvc_chan_available,
+	.chan_setup = qcom_hvc_chan_setup,
+	.chan_free = qcom_hvc_chan_free,
+	.send_message = qcom_hvc_send_message,
+	.mark_txdone = qcom_hvc_mark_txdone,
+	.fetch_response = qcom_hvc_fetch_response,
+};
+
+const struct scmi_desc scmi_qcom_hvc_desc = {
+	.ops = &scmi_qcom_hvc_ops,
+	.max_rx_timeout_ms = 30,
+	.max_msg = 20,
+	.max_msg_size = 128,
+	.sync_cmds_completed_on_ret = true,
+};
-- 
2.17.1


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

* Re: [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf
  2023-07-24 16:44   ` [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
@ 2023-07-25  6:01     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-25  6:01 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 24/07/2023 18:44, Nikunj Kela wrote:
> Nested if-else construct is not scalable therefore, convert
> it to allOf:if-else.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  .../bindings/firmware/arm,scmi.yaml           | 55 +++++++++----------
>  1 file changed, 27 insertions(+), 28 deletions(-)
> 


Suggested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


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

* Re: [PATCH v2 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-07-24 16:44   ` [PATCH v2 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI Nikunj Kela
@ 2023-07-25  6:06     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-25  6:06 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 24/07/2023 18:44, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

This looks fine for me, but I did not investigate whether Sudeep's
concerns were solved/answered fully.


Best regards,
Krzysztof


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

* Re: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-24 16:44   ` [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
@ 2023-07-25 17:03     ` Cristian Marussi
  2023-07-25 17:12       ` Nikunj Kela
  2023-08-01  7:27       ` kernel test robot
  1 sibling, 1 reply; 186+ messages in thread
From: Cristian Marussi @ 2023-07-25 17:03 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, robh+dt, krzysztof.kozlowski+dt, conor+dt, agross,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Jul 24, 2023 at 09:44:19AM -0700, Nikunj Kela wrote:
> Add a new transport channel to the SCMI firmware interface driver for
> SCMI message exchange on Qualcomm virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when HVC call is invoked.
> 
> The qcom hvc doorbell/shared memory transport uses a statically defined
> shared memory region that binds with "arm,scmi-shmem" device tree node.
> 
> The function-id & capability-id are allocated by the hypervisor on bootup
> and are stored in the shmem region by the firmware before starting Linux.
> 
> Currently, there is no usecase for the atomic support therefore this driver
> doesn't include the changes for the same.
> 

Hi Nikunj,

so basically this new SCMI transport that you are introducing is just
exactly like the existing SMC transport with the only difference that
you introduced even another new way to configure func_id, a new cap_id
param AND the fact that you use HVC instead of SMC... all of this tied
to a new compatible to identify this new transport mechanism....
..but all in all is just a lot of plain duplicated code to maintain...

...why can't you fit this other smc/hvc transport variant into the
existing SMC transport by properly picking and configuring func_id/cap_id
and "doorbell" method (SMC vs HVC) in the chan_setup() step ?

..I mean ... you can decide where to pick your params based on
compatibles and also you can setup your invokation method (SMC vs HVC)
based on those...while keeping all the other stuff exactly the same...
...including support for atomic exchanges...if not, when you'll need that
too in your QC_HVC transport you'll have to duplicate also that (and my
bugs too probably :P)

(... well maybe in this scenario also the transport itself should be
renamed from SMC to something more general...)

Not sure if I am missing something, or if Sudeep will be horrified by
this unifying proposal of mine, but in this series as it stands now I
just see a lot of brutally duplicated stuff that just differs by naming
and a very minimal change in logic that could be addressed changing and
generalizing the original SMC transport code instead.

Thanks,
Cristian


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

* Re: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-25 17:03     ` Cristian Marussi
@ 2023-07-25 17:12       ` Nikunj Kela
  2023-07-31 14:04           ` Nikunj Kela
  0 siblings, 1 reply; 186+ messages in thread
From: Nikunj Kela @ 2023-07-25 17:12 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: sudeep.holla, robh+dt, krzysztof.kozlowski+dt, conor+dt, agross,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 7/25/2023 10:03 AM, Cristian Marussi wrote:
> On Mon, Jul 24, 2023 at 09:44:19AM -0700, Nikunj Kela wrote:
>> Add a new transport channel to the SCMI firmware interface driver for
>> SCMI message exchange on Qualcomm virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when HVC call is invoked.
>>
>> The qcom hvc doorbell/shared memory transport uses a statically defined
>> shared memory region that binds with "arm,scmi-shmem" device tree node.
>>
>> The function-id & capability-id are allocated by the hypervisor on bootup
>> and are stored in the shmem region by the firmware before starting Linux.
>>
>> Currently, there is no usecase for the atomic support therefore this driver
>> doesn't include the changes for the same.
>>
> Hi Nikunj,
>
> so basically this new SCMI transport that you are introducing is just
> exactly like the existing SMC transport with the only difference that
> you introduced even another new way to configure func_id, a new cap_id
> param AND the fact that you use HVC instead of SMC... all of this tied
> to a new compatible to identify this new transport mechanism....
> ..but all in all is just a lot of plain duplicated code to maintain...
>
> ...why can't you fit this other smc/hvc transport variant into the
> existing SMC transport by properly picking and configuring func_id/cap_id
> and "doorbell" method (SMC vs HVC) in the chan_setup() step ?
>
> ..I mean ... you can decide where to pick your params based on
> compatibles and also you can setup your invokation method (SMC vs HVC)
> based on those...while keeping all the other stuff exactly the same...
> ...including support for atomic exchanges...if not, when you'll need that
> too in your QC_HVC transport you'll have to duplicate also that (and my
> bugs too probably :P)
>
> (... well maybe in this scenario also the transport itself should be
> renamed from SMC to something more general...)
>
> Not sure if I am missing something, or if Sudeep will be horrified by
> this unifying proposal of mine, but in this series as it stands now I
> just see a lot of brutally duplicated stuff that just differs by naming
> and a very minimal change in logic that could be addressed changing and
> generalizing the original SMC transport code instead.
>
> Thanks,
> Cristian

Hi Christian,

I totally agree with you and will be happy to include my changes in 
smc.c if Sudeep agrees with that approach.

Thanks


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

* Re: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-25 17:12       ` Nikunj Kela
@ 2023-07-31 14:04           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-31 14:04 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: sudeep.holla, robh+dt, krzysztof.kozlowski+dt, conor+dt, agross,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 7/25/2023 10:12 AM, Nikunj Kela wrote:
>
> On 7/25/2023 10:03 AM, Cristian Marussi wrote:
>> On Mon, Jul 24, 2023 at 09:44:19AM -0700, Nikunj Kela wrote:
>>> Add a new transport channel to the SCMI firmware interface driver for
>>> SCMI message exchange on Qualcomm virtual platforms.
>>>
>>> The hypervisor associates an object-id also known as capability-id
>>> with each hvc doorbell object. The capability-id is used to identify 
>>> the
>>> doorbell from the VM's capability namespace, similar to a 
>>> file-descriptor.
>>>
>>> The hypervisor, in addition to the function-id, expects the 
>>> capability-id
>>> to be passed in x1 register when HVC call is invoked.
>>>
>>> The qcom hvc doorbell/shared memory transport uses a statically defined
>>> shared memory region that binds with "arm,scmi-shmem" device tree node.
>>>
>>> The function-id & capability-id are allocated by the hypervisor on 
>>> bootup
>>> and are stored in the shmem region by the firmware before starting 
>>> Linux.
>>>
>>> Currently, there is no usecase for the atomic support therefore this 
>>> driver
>>> doesn't include the changes for the same.
>>>
>> Hi Nikunj,
>>
>> so basically this new SCMI transport that you are introducing is just
>> exactly like the existing SMC transport with the only difference that
>> you introduced even another new way to configure func_id, a new cap_id
>> param AND the fact that you use HVC instead of SMC... all of this tied
>> to a new compatible to identify this new transport mechanism....
>> ..but all in all is just a lot of plain duplicated code to maintain...
>>
>> ...why can't you fit this other smc/hvc transport variant into the
>> existing SMC transport by properly picking and configuring 
>> func_id/cap_id
>> and "doorbell" method (SMC vs HVC) in the chan_setup() step ?
>>
>> ..I mean ... you can decide where to pick your params based on
>> compatibles and also you can setup your invokation method (SMC vs HVC)
>> based on those...while keeping all the other stuff exactly the same...
>> ...including support for atomic exchanges...if not, when you'll need 
>> that
>> too in your QC_HVC transport you'll have to duplicate also that (and my
>> bugs too probably :P)
>>
>> (... well maybe in this scenario also the transport itself should be
>> renamed from SMC to something more general...)
>>
>> Not sure if I am missing something, or if Sudeep will be horrified by
>> this unifying proposal of mine, but in this series as it stands now I
>> just see a lot of brutally duplicated stuff that just differs by naming
>> and a very minimal change in logic that could be addressed changing and
>> generalizing the original SMC transport code instead.
>>
>> Thanks,
>> Cristian
>
> Hi Christian,
>
> I totally agree with you and will be happy to include my changes in 
> smc.c if Sudeep agrees with that approach.
>
> Thanks

Hi Sudeep, Could you please provide your feedback on this? Thanks


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

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

* Re: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-07-31 14:04           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-07-31 14:04 UTC (permalink / raw)
  To: Cristian Marussi
  Cc: sudeep.holla, robh+dt, krzysztof.kozlowski+dt, conor+dt, agross,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 7/25/2023 10:12 AM, Nikunj Kela wrote:
>
> On 7/25/2023 10:03 AM, Cristian Marussi wrote:
>> On Mon, Jul 24, 2023 at 09:44:19AM -0700, Nikunj Kela wrote:
>>> Add a new transport channel to the SCMI firmware interface driver for
>>> SCMI message exchange on Qualcomm virtual platforms.
>>>
>>> The hypervisor associates an object-id also known as capability-id
>>> with each hvc doorbell object. The capability-id is used to identify 
>>> the
>>> doorbell from the VM's capability namespace, similar to a 
>>> file-descriptor.
>>>
>>> The hypervisor, in addition to the function-id, expects the 
>>> capability-id
>>> to be passed in x1 register when HVC call is invoked.
>>>
>>> The qcom hvc doorbell/shared memory transport uses a statically defined
>>> shared memory region that binds with "arm,scmi-shmem" device tree node.
>>>
>>> The function-id & capability-id are allocated by the hypervisor on 
>>> bootup
>>> and are stored in the shmem region by the firmware before starting 
>>> Linux.
>>>
>>> Currently, there is no usecase for the atomic support therefore this 
>>> driver
>>> doesn't include the changes for the same.
>>>
>> Hi Nikunj,
>>
>> so basically this new SCMI transport that you are introducing is just
>> exactly like the existing SMC transport with the only difference that
>> you introduced even another new way to configure func_id, a new cap_id
>> param AND the fact that you use HVC instead of SMC... all of this tied
>> to a new compatible to identify this new transport mechanism....
>> ..but all in all is just a lot of plain duplicated code to maintain...
>>
>> ...why can't you fit this other smc/hvc transport variant into the
>> existing SMC transport by properly picking and configuring 
>> func_id/cap_id
>> and "doorbell" method (SMC vs HVC) in the chan_setup() step ?
>>
>> ..I mean ... you can decide where to pick your params based on
>> compatibles and also you can setup your invokation method (SMC vs HVC)
>> based on those...while keeping all the other stuff exactly the same...
>> ...including support for atomic exchanges...if not, when you'll need 
>> that
>> too in your QC_HVC transport you'll have to duplicate also that (and my
>> bugs too probably :P)
>>
>> (... well maybe in this scenario also the transport itself should be
>> renamed from SMC to something more general...)
>>
>> Not sure if I am missing something, or if Sudeep will be horrified by
>> this unifying proposal of mine, but in this series as it stands now I
>> just see a lot of brutally duplicated stuff that just differs by naming
>> and a very minimal change in logic that could be addressed changing and
>> generalizing the original SMC transport code instead.
>>
>> Thanks,
>> Cristian
>
> Hi Christian,
>
> I totally agree with you and will be happy to include my changes in 
> smc.c if Sudeep agrees with that approach.
>
> Thanks

Hi Sudeep, Could you please provide your feedback on this? Thanks


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

* Re: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-07-24 16:44   ` [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
@ 2023-08-01  7:27       ` kernel test robot
  2023-08-01  7:27       ` kernel test robot
  1 sibling, 0 replies; 186+ messages in thread
From: kernel test robot @ 2023-08-01  7:27 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: llvm, oe-kbuild-all, cristian.marussi, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, agross, andersson,
	konrad.dybcio, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm, Nikunj Kela

Hi Nikunj,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.5-rc4 next-20230801]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nikunj-Kela/dt-bindings-arm-convert-nested-if-else-construct-to-allOf/20230725-004613
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230724164419.16092-4-quic_nkela%40quicinc.com
patch subject: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
config: arm-randconfig-r004-20230731 (https://download.01.org/0day-ci/archive/20230801/202308011516.voJRAbHr-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce: (https://download.01.org/0day-ci/archive/20230801/202308011516.voJRAbHr-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308011516.voJRAbHr-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/firmware/arm_scmi/qcom_hvc.c:182:2: error: write to reserved register 'R7'
           arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
           ^
   include/linux/arm-smccc.h:536:48: note: expanded from macro 'arm_smccc_1_1_hvc'
   #define arm_smccc_1_1_hvc(...)  __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__)
                                                   ^
   include/linux/arm-smccc.h:398:24: note: expanded from macro 'SMCCC_HVC_INST'
   #define SMCCC_HVC_INST  __HVC(0)
                           ^
   arch/arm/include/asm/opcodes-virt.h:11:22: note: expanded from macro '__HVC'
   #define __HVC(imm16) __inst_arm_thumb32(                                \
                        ^
   arch/arm/include/asm/opcodes.h:215:2: note: expanded from macro '__inst_arm_thumb32'
           __inst_thumb32(thumb_opcode)
           ^
   arch/arm/include/asm/opcodes.h:205:27: note: expanded from macro '__inst_thumb32'
   #define __inst_thumb32(x) ___inst_thumb32(                              \
                             ^
   arch/arm/include/asm/opcodes.h:230:2: note: expanded from macro '___inst_thumb32'
           ".short " __stringify(first) ", " __stringify(second) "\n\t"
           ^
   1 error generated.


vim +/R7 +182 drivers/firmware/arm_scmi/qcom_hvc.c

   167	
   168	static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
   169					 struct scmi_xfer *xfer)
   170	{
   171		struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
   172		struct arm_smccc_res res;
   173	
   174		/*
   175		 * Channel will be released only once response has been
   176		 * surely fully retrieved, so after .mark_txdone()
   177		 */
   178		mutex_lock(&scmi_info->shmem_lock);
   179	
   180		shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
   181	
 > 182		arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
   183				  0, 0, 0, 0, 0, 0, &res);
   184	
   185		if (res.a0) {
   186			mutex_unlock(&scmi_info->shmem_lock);
   187			return -EOPNOTSUPP;
   188		}
   189	
   190		return 0;
   191	}
   192	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-08-01  7:27       ` kernel test robot
  0 siblings, 0 replies; 186+ messages in thread
From: kernel test robot @ 2023-08-01  7:27 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: llvm, oe-kbuild-all, cristian.marussi, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, agross, andersson,
	konrad.dybcio, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm, Nikunj Kela

Hi Nikunj,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.5-rc4 next-20230801]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nikunj-Kela/dt-bindings-arm-convert-nested-if-else-construct-to-allOf/20230725-004613
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230724164419.16092-4-quic_nkela%40quicinc.com
patch subject: [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
config: arm-randconfig-r004-20230731 (https://download.01.org/0day-ci/archive/20230801/202308011516.voJRAbHr-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce: (https://download.01.org/0day-ci/archive/20230801/202308011516.voJRAbHr-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308011516.voJRAbHr-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/firmware/arm_scmi/qcom_hvc.c:182:2: error: write to reserved register 'R7'
           arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
           ^
   include/linux/arm-smccc.h:536:48: note: expanded from macro 'arm_smccc_1_1_hvc'
   #define arm_smccc_1_1_hvc(...)  __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__)
                                                   ^
   include/linux/arm-smccc.h:398:24: note: expanded from macro 'SMCCC_HVC_INST'
   #define SMCCC_HVC_INST  __HVC(0)
                           ^
   arch/arm/include/asm/opcodes-virt.h:11:22: note: expanded from macro '__HVC'
   #define __HVC(imm16) __inst_arm_thumb32(                                \
                        ^
   arch/arm/include/asm/opcodes.h:215:2: note: expanded from macro '__inst_arm_thumb32'
           __inst_thumb32(thumb_opcode)
           ^
   arch/arm/include/asm/opcodes.h:205:27: note: expanded from macro '__inst_thumb32'
   #define __inst_thumb32(x) ___inst_thumb32(                              \
                             ^
   arch/arm/include/asm/opcodes.h:230:2: note: expanded from macro '___inst_thumb32'
           ".short " __stringify(first) ", " __stringify(second) "\n\t"
           ^
   1 error generated.


vim +/R7 +182 drivers/firmware/arm_scmi/qcom_hvc.c

   167	
   168	static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
   169					 struct scmi_xfer *xfer)
   170	{
   171		struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
   172		struct arm_smccc_res res;
   173	
   174		/*
   175		 * Channel will be released only once response has been
   176		 * surely fully retrieved, so after .mark_txdone()
   177		 */
   178		mutex_lock(&scmi_info->shmem_lock);
   179	
   180		shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
   181	
 > 182		arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
   183				  0, 0, 0, 0, 0, 0, &res);
   184	
   185		if (res.a0) {
   186			mutex_unlock(&scmi_info->shmem_lock);
   187			return -EOPNOTSUPP;
   188		}
   189	
   190		return 0;
   191	}
   192	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

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

* [PATCH v3 0/3] Add qcom hvc/shmem transport
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-08-11 17:57   ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change introduce a new transport channel for Qualcomm virtual
platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
The difference between the two transports is that a parameter is passed in
the hypervisor call to identify which doorbell to assert. This parameter is
dynamically generated at runtime on the device and insuitable to pass via
the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (3):
  dt-bindings: arm: convert nested if-else construct to allOf
  dt-bindings: arm: Add qcom specific hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport

 .../bindings/firmware/arm,scmi.yaml           |  67 ++---
 drivers/firmware/arm_scmi/Kconfig             |  13 +
 drivers/firmware/arm_scmi/Makefile            |   2 +
 drivers/firmware/arm_scmi/common.h            |   3 +
 drivers/firmware/arm_scmi/driver.c            |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
 6 files changed, 293 insertions(+), 28 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

-- 
2.17.1


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

* [PATCH v3 0/3] Add qcom hvc/shmem transport
@ 2023-08-11 17:57   ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change introduce a new transport channel for Qualcomm virtual
platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
The difference between the two transports is that a parameter is passed in
the hypervisor call to identify which doorbell to assert. This parameter is
dynamically generated at runtime on the device and insuitable to pass via
the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (3):
  dt-bindings: arm: convert nested if-else construct to allOf
  dt-bindings: arm: Add qcom specific hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport

 .../bindings/firmware/arm,scmi.yaml           |  67 ++---
 drivers/firmware/arm_scmi/Kconfig             |  13 +
 drivers/firmware/arm_scmi/Makefile            |   2 +
 drivers/firmware/arm_scmi/common.h            |   3 +
 drivers/firmware/arm_scmi/driver.c            |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
 6 files changed, 293 insertions(+), 28 deletions(-)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

-- 
2.17.1


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

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

* [PATCH v3 1/3] dt-bindings: arm: convert nested if-else construct to allOf
  2023-08-11 17:57   ` Nikunj Kela
@ 2023-08-11 17:57     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Nested if-else construct is not scalable therefore, convert
it to allOf:if-else.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Suggested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../bindings/firmware/arm,scmi.yaml           | 55 +++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..8d54ea768d38 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -284,35 +284,34 @@ $defs:
 required:
   - compatible
 
-if:
-  properties:
-    compatible:
-      contains:
-        const: arm,scmi
-then:
-  properties:
-    interrupts: false
-    interrupt-names: false
-
-  required:
-    - mboxes
-    - shmem
-
-else:
-  if:
-    properties:
-      compatible:
-        contains:
-          enum:
-            - arm,scmi-smc
-            - arm,scmi-smc-param
-  then:
-    required:
-      - arm,smc-id
-      - shmem
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: arm,scmi
+    then:
+      properties:
+        interrupts: false
+        interrupt-names: false
+
+      required:
+        - mboxes
+        - shmem
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - arm,scmi-smc
+              - arm,scmi-smc-param
+    then:
+      required:
+        - arm,smc-id
+        - shmem
 
-  else:
-    if:
+  - if:
       properties:
         compatible:
           contains:
-- 
2.17.1


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

* [PATCH v3 1/3] dt-bindings: arm: convert nested if-else construct to allOf
@ 2023-08-11 17:57     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Nested if-else construct is not scalable therefore, convert
it to allOf:if-else.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Suggested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../bindings/firmware/arm,scmi.yaml           | 55 +++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..8d54ea768d38 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -284,35 +284,34 @@ $defs:
 required:
   - compatible
 
-if:
-  properties:
-    compatible:
-      contains:
-        const: arm,scmi
-then:
-  properties:
-    interrupts: false
-    interrupt-names: false
-
-  required:
-    - mboxes
-    - shmem
-
-else:
-  if:
-    properties:
-      compatible:
-        contains:
-          enum:
-            - arm,scmi-smc
-            - arm,scmi-smc-param
-  then:
-    required:
-      - arm,smc-id
-      - shmem
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: arm,scmi
+    then:
+      properties:
+        interrupts: false
+        interrupt-names: false
+
+      required:
+        - mboxes
+        - shmem
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - arm,scmi-smc
+              - arm,scmi-smc-param
+    then:
+      required:
+        - arm,smc-id
+        - shmem
 
-  else:
-    if:
+  - if:
       properties:
         compatible:
           contains:
-- 
2.17.1


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

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

* [PATCH v3 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI
  2023-08-11 17:57   ` Nikunj Kela
@ 2023-08-11 17:57     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 8d54ea768d38..4090240f45b1 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -320,6 +323,15 @@ allOf:
       required:
         - linaro,optee-channel-id
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,scmi-hvc-shmem
+    then:
+      required:
+        - shmem
+
 examples:
   - |
     firmware {
-- 
2.17.1


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

* [PATCH v3 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI
@ 2023-08-11 17:57     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 8d54ea768d38..4090240f45b1 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -320,6 +323,15 @@ allOf:
       required:
         - linaro,optee-channel-id
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,scmi-hvc-shmem
+    then:
+      required:
+        - shmem
+
 examples:
   - |
     firmware {
-- 
2.17.1


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

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

* [PATCH v3 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
  2023-08-11 17:57   ` Nikunj Kela
@ 2023-08-11 17:57     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Add a new transport channel to the SCMI firmware interface driver for
SCMI message exchange on Qualcomm virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The qcom hvc doorbell/shared memory transport uses a statically defined
shared memory region that binds with "arm,scmi-shmem" device tree node.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Currently, there is no usecase for the atomic support therefore this driver
doesn't include the changes for the same.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig    |  13 ++
 drivers/firmware/arm_scmi/Makefile   |   2 +
 drivers/firmware/arm_scmi/common.h   |   3 +
 drivers/firmware/arm_scmi/driver.c   |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c | 232 +++++++++++++++++++++++++++
 5 files changed, 254 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..40d07329ebf7 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -99,6 +99,19 @@ config ARM_SCMI_TRANSPORT_OPTEE
 	  If you want the ARM SCMI PROTOCOL stack to include support for a
 	  transport based on OP-TEE SCMI service, answer Y.
 
+config ARM_SCMI_TRANSPORT_QCOM_HVC
+	bool "SCMI transport based on hvc doorbell & shmem for Qualcomm SoCs"
+	depends on ARCH_QCOM
+	select ARM_SCMI_HAVE_TRANSPORT
+	select ARM_SCMI_HAVE_SHMEM
+	default y
+	help
+	  Enable hvc doorbell & shmem based transport for SCMI.
+
+	  If you want the ARM SCMI PROTOCOL stack to include support for a
+	  hvc doorbell and shmem transport on Qualcomm virtual platforms,
+	  answer Y.
+
 config ARM_SCMI_TRANSPORT_SMC
 	bool "SCMI transport based on SMC"
 	depends on HAVE_ARM_SMCCC_DISCOVERY
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index b31d78fa66cc..aaeba724b5e6 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -10,6 +10,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o
+scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC) += qcom_hvc.o
 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o
 scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
 
@@ -24,4 +25,5 @@ ifeq ($(CONFIG_THUMB2_KERNEL)$(CONFIG_CC_IS_CLANG),yy)
 # pointer in Thumb2 mode, which is forcibly enabled by Clang when profiling
 # hooks are inserted via the -pg switch.
 CFLAGS_REMOVE_smc.o += $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_qcom_hvc.o += $(CC_FLAGS_FTRACE)
 endif
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index c46dc5215af7..5c98cbb1278b 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -298,6 +298,9 @@ extern const struct scmi_desc scmi_virtio_desc;
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE
 extern const struct scmi_desc scmi_optee_desc;
 #endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+extern const struct scmi_desc scmi_qcom_hvc_desc;
+#endif
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv);
 
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index b5957cc12fee..c54519596c29 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2918,6 +2918,10 @@ static const struct of_device_id scmi_of_match[] = {
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
+#endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+	{ .compatible = "qcom,scmi-hvc-shmem",
+	  .data = &scmi_qcom_hvc_desc },
 #endif
 	{ /* Sentinel */ },
 };
diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
new file mode 100644
index 000000000000..87dc36805967
--- /dev/null
+++ b/drivers/firmware/arm_scmi/qcom_hvc.c
@@ -0,0 +1,232 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) Message
+ * Qualcomm HVC/shmem Transport driver
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright 2020 NXP
+ *
+ * This is based on drivers/firmware/arm_scmi/smc.c
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/slab.h>
+
+#include "common.h"
+
+/**
+ * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
+ *
+ * @irq: An optional IRQ for completion
+ * @cinfo: SCMI channel info
+ * @shmem: Transmit/Receive shared memory area
+ * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
+ * @func_id: hvc call function-id
+ * @cap_id: hvc doorbell's capability id
+ */
+
+struct scmi_qcom_hvc {
+	int irq;
+	struct scmi_chan_info *cinfo;
+	struct scmi_shared_mem __iomem *shmem;
+	/* Protect access to shmem area */
+	struct mutex shmem_lock;
+	u32 func_id;
+	u64 cap_id;
+};
+
+static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
+{
+	struct scmi_qcom_hvc *scmi_info = data;
+
+	scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem), NULL);
+
+	return IRQ_HANDLED;
+}
+
+static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
+{
+	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
+
+	if (!np)
+		return false;
+
+	of_node_put(np);
+	return true;
+}
+
+static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
+			       struct device *dev, bool tx)
+{
+	struct device *cdev = cinfo->dev;
+	struct scmi_qcom_hvc *scmi_info;
+	struct device_node *np;
+	resource_size_t size;
+	struct resource res;
+	u32 func_id;
+	u64 cap_id;
+	int ret;
+
+	if (!tx)
+		return -ENODEV;
+
+	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
+	if (!scmi_info)
+		return -ENOMEM;
+
+	np = of_parse_phandle(cdev->of_node, "shmem", 0);
+	if (!of_device_is_compatible(np, "arm,scmi-shmem")) {
+		of_node_put(np);
+		return -ENXIO;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	of_node_put(np);
+	if (ret) {
+		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
+		return ret;
+	}
+
+	size = resource_size(&res);
+
+	/* The func-id & capability-id are kept in last 16 bytes of shmem.
+	 *     +-------+
+	 *     |       |
+	 *     | shmem |
+	 *     |       |
+	 *     |       |
+	 *     +-------+ <-- (size - 16)
+	 *     | funcId|
+	 *     +-------+ <-- (size - 8)
+	 *     | capId |
+	 *     +-------+ <-- size
+	 */
+
+	scmi_info->shmem = devm_ioremap(dev, res.start, size);
+	if (!scmi_info->shmem) {
+		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
+		return -EADDRNOTAVAIL;
+	}
+
+	func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
+
+#ifdef CONFIG_ARM64
+	cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
+#else
+	/* capability-id is 32 bit long on 32bit machines */
+	cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
+#endif
+
+	/*
+	 * If there is an interrupt named "a2p", then the service and
+	 * completion of a message is signaled by an interrupt rather than by
+	 * the return of the hvc call.
+	 */
+	scmi_info->irq = of_irq_get_byname(cdev->of_node, "a2p");
+	if (scmi_info->irq > 0) {
+		ret = request_irq(scmi_info->irq, qcom_hvc_msg_done_isr,
+				  IRQF_NO_SUSPEND, dev_name(dev), scmi_info);
+		if (ret) {
+			dev_err(dev, "failed to setup SCMI completion irq\n");
+			return ret;
+		}
+	} else {
+		cinfo->no_completion_irq = true;
+	}
+
+	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
+	scmi_info->cinfo = cinfo;
+	mutex_init(&scmi_info->shmem_lock);
+	cinfo->transport_info = scmi_info;
+
+	return 0;
+}
+
+static int qcom_hvc_chan_free(int id, void *p, void *data)
+{
+	struct scmi_chan_info *cinfo = p;
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	/* Ignore any possible further reception on the IRQ path */
+	if (scmi_info->irq > 0)
+		free_irq(scmi_info->irq, scmi_info);
+
+	cinfo->transport_info = NULL;
+	scmi_info->cinfo = NULL;
+
+	return 0;
+}
+
+static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
+				 struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+	struct arm_smccc_res res;
+
+	/*
+	 * Channel will be released only once response has been
+	 * surely fully retrieved, so after .mark_txdone()
+	 */
+	mutex_lock(&scmi_info->shmem_lock);
+
+	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
+
+	arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
+			  0, 0, 0, 0, 0, 0, &res);
+
+	if (res.a0) {
+		mutex_unlock(&scmi_info->shmem_lock);
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
+				    struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	shmem_fetch_response(scmi_info->shmem, xfer);
+}
+
+static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
+				 struct scmi_xfer *__unused)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	mutex_unlock(&scmi_info->shmem_lock);
+}
+
+static bool
+qcom_hvc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	return shmem_poll_done(scmi_info->shmem, xfer);
+}
+
+static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
+	.chan_available = qcom_hvc_chan_available,
+	.chan_setup = qcom_hvc_chan_setup,
+	.chan_free = qcom_hvc_chan_free,
+	.send_message = qcom_hvc_send_message,
+	.mark_txdone = qcom_hvc_mark_txdone,
+	.fetch_response = qcom_hvc_fetch_response,
+	.poll_done = qcom_hvc_poll_done,
+};
+
+const struct scmi_desc scmi_qcom_hvc_desc = {
+	.ops = &scmi_qcom_hvc_ops,
+	.max_rx_timeout_ms = 30,
+	.max_msg = 20,
+	.max_msg_size = 128,
+};
-- 
2.17.1


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

* [PATCH v3 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport
@ 2023-08-11 17:57     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-08-11 17:57 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Add a new transport channel to the SCMI firmware interface driver for
SCMI message exchange on Qualcomm virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The qcom hvc doorbell/shared memory transport uses a statically defined
shared memory region that binds with "arm,scmi-shmem" device tree node.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Currently, there is no usecase for the atomic support therefore this driver
doesn't include the changes for the same.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig    |  13 ++
 drivers/firmware/arm_scmi/Makefile   |   2 +
 drivers/firmware/arm_scmi/common.h   |   3 +
 drivers/firmware/arm_scmi/driver.c   |   4 +
 drivers/firmware/arm_scmi/qcom_hvc.c | 232 +++++++++++++++++++++++++++
 5 files changed, 254 insertions(+)
 create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..40d07329ebf7 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -99,6 +99,19 @@ config ARM_SCMI_TRANSPORT_OPTEE
 	  If you want the ARM SCMI PROTOCOL stack to include support for a
 	  transport based on OP-TEE SCMI service, answer Y.
 
+config ARM_SCMI_TRANSPORT_QCOM_HVC
+	bool "SCMI transport based on hvc doorbell & shmem for Qualcomm SoCs"
+	depends on ARCH_QCOM
+	select ARM_SCMI_HAVE_TRANSPORT
+	select ARM_SCMI_HAVE_SHMEM
+	default y
+	help
+	  Enable hvc doorbell & shmem based transport for SCMI.
+
+	  If you want the ARM SCMI PROTOCOL stack to include support for a
+	  hvc doorbell and shmem transport on Qualcomm virtual platforms,
+	  answer Y.
+
 config ARM_SCMI_TRANSPORT_SMC
 	bool "SCMI transport based on SMC"
 	depends on HAVE_ARM_SMCCC_DISCOVERY
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index b31d78fa66cc..aaeba724b5e6 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -10,6 +10,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o
 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o
 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o
+scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC) += qcom_hvc.o
 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o
 scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
 
@@ -24,4 +25,5 @@ ifeq ($(CONFIG_THUMB2_KERNEL)$(CONFIG_CC_IS_CLANG),yy)
 # pointer in Thumb2 mode, which is forcibly enabled by Clang when profiling
 # hooks are inserted via the -pg switch.
 CFLAGS_REMOVE_smc.o += $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_qcom_hvc.o += $(CC_FLAGS_FTRACE)
 endif
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index c46dc5215af7..5c98cbb1278b 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -298,6 +298,9 @@ extern const struct scmi_desc scmi_virtio_desc;
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE
 extern const struct scmi_desc scmi_optee_desc;
 #endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+extern const struct scmi_desc scmi_qcom_hvc_desc;
+#endif
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv);
 
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index b5957cc12fee..c54519596c29 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2918,6 +2918,10 @@ static const struct of_device_id scmi_of_match[] = {
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
+#endif
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_QCOM_HVC
+	{ .compatible = "qcom,scmi-hvc-shmem",
+	  .data = &scmi_qcom_hvc_desc },
 #endif
 	{ /* Sentinel */ },
 };
diff --git a/drivers/firmware/arm_scmi/qcom_hvc.c b/drivers/firmware/arm_scmi/qcom_hvc.c
new file mode 100644
index 000000000000..87dc36805967
--- /dev/null
+++ b/drivers/firmware/arm_scmi/qcom_hvc.c
@@ -0,0 +1,232 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) Message
+ * Qualcomm HVC/shmem Transport driver
+ *
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright 2020 NXP
+ *
+ * This is based on drivers/firmware/arm_scmi/smc.c
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/slab.h>
+
+#include "common.h"
+
+/**
+ * struct scmi_qcom_hvc - Structure representing a SCMI qcom hvc transport
+ *
+ * @irq: An optional IRQ for completion
+ * @cinfo: SCMI channel info
+ * @shmem: Transmit/Receive shared memory area
+ * @shmem_lock: Lock to protect access to Tx/Rx shared memory area.
+ * @func_id: hvc call function-id
+ * @cap_id: hvc doorbell's capability id
+ */
+
+struct scmi_qcom_hvc {
+	int irq;
+	struct scmi_chan_info *cinfo;
+	struct scmi_shared_mem __iomem *shmem;
+	/* Protect access to shmem area */
+	struct mutex shmem_lock;
+	u32 func_id;
+	u64 cap_id;
+};
+
+static irqreturn_t qcom_hvc_msg_done_isr(int irq, void *data)
+{
+	struct scmi_qcom_hvc *scmi_info = data;
+
+	scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem), NULL);
+
+	return IRQ_HANDLED;
+}
+
+static bool qcom_hvc_chan_available(struct device_node *of_node, int idx)
+{
+	struct device_node *np = of_parse_phandle(of_node, "shmem", 0);
+
+	if (!np)
+		return false;
+
+	of_node_put(np);
+	return true;
+}
+
+static int qcom_hvc_chan_setup(struct scmi_chan_info *cinfo,
+			       struct device *dev, bool tx)
+{
+	struct device *cdev = cinfo->dev;
+	struct scmi_qcom_hvc *scmi_info;
+	struct device_node *np;
+	resource_size_t size;
+	struct resource res;
+	u32 func_id;
+	u64 cap_id;
+	int ret;
+
+	if (!tx)
+		return -ENODEV;
+
+	scmi_info = devm_kzalloc(dev, sizeof(*scmi_info), GFP_KERNEL);
+	if (!scmi_info)
+		return -ENOMEM;
+
+	np = of_parse_phandle(cdev->of_node, "shmem", 0);
+	if (!of_device_is_compatible(np, "arm,scmi-shmem")) {
+		of_node_put(np);
+		return -ENXIO;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	of_node_put(np);
+	if (ret) {
+		dev_err(cdev, "failed to get SCMI Tx shared memory\n");
+		return ret;
+	}
+
+	size = resource_size(&res);
+
+	/* The func-id & capability-id are kept in last 16 bytes of shmem.
+	 *     +-------+
+	 *     |       |
+	 *     | shmem |
+	 *     |       |
+	 *     |       |
+	 *     +-------+ <-- (size - 16)
+	 *     | funcId|
+	 *     +-------+ <-- (size - 8)
+	 *     | capId |
+	 *     +-------+ <-- size
+	 */
+
+	scmi_info->shmem = devm_ioremap(dev, res.start, size);
+	if (!scmi_info->shmem) {
+		dev_err(dev, "failed to ioremap SCMI Tx shared memory\n");
+		return -EADDRNOTAVAIL;
+	}
+
+	func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
+
+#ifdef CONFIG_ARM64
+	cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
+#else
+	/* capability-id is 32 bit long on 32bit machines */
+	cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
+#endif
+
+	/*
+	 * If there is an interrupt named "a2p", then the service and
+	 * completion of a message is signaled by an interrupt rather than by
+	 * the return of the hvc call.
+	 */
+	scmi_info->irq = of_irq_get_byname(cdev->of_node, "a2p");
+	if (scmi_info->irq > 0) {
+		ret = request_irq(scmi_info->irq, qcom_hvc_msg_done_isr,
+				  IRQF_NO_SUSPEND, dev_name(dev), scmi_info);
+		if (ret) {
+			dev_err(dev, "failed to setup SCMI completion irq\n");
+			return ret;
+		}
+	} else {
+		cinfo->no_completion_irq = true;
+	}
+
+	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
+	scmi_info->cinfo = cinfo;
+	mutex_init(&scmi_info->shmem_lock);
+	cinfo->transport_info = scmi_info;
+
+	return 0;
+}
+
+static int qcom_hvc_chan_free(int id, void *p, void *data)
+{
+	struct scmi_chan_info *cinfo = p;
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	/* Ignore any possible further reception on the IRQ path */
+	if (scmi_info->irq > 0)
+		free_irq(scmi_info->irq, scmi_info);
+
+	cinfo->transport_info = NULL;
+	scmi_info->cinfo = NULL;
+
+	return 0;
+}
+
+static int qcom_hvc_send_message(struct scmi_chan_info *cinfo,
+				 struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+	struct arm_smccc_res res;
+
+	/*
+	 * Channel will be released only once response has been
+	 * surely fully retrieved, so after .mark_txdone()
+	 */
+	mutex_lock(&scmi_info->shmem_lock);
+
+	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
+
+	arm_smccc_1_1_hvc(scmi_info->func_id, (unsigned long)scmi_info->cap_id,
+			  0, 0, 0, 0, 0, 0, &res);
+
+	if (res.a0) {
+		mutex_unlock(&scmi_info->shmem_lock);
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static void qcom_hvc_fetch_response(struct scmi_chan_info *cinfo,
+				    struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	shmem_fetch_response(scmi_info->shmem, xfer);
+}
+
+static void qcom_hvc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
+				 struct scmi_xfer *__unused)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	mutex_unlock(&scmi_info->shmem_lock);
+}
+
+static bool
+qcom_hvc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
+{
+	struct scmi_qcom_hvc *scmi_info = cinfo->transport_info;
+
+	return shmem_poll_done(scmi_info->shmem, xfer);
+}
+
+static const struct scmi_transport_ops scmi_qcom_hvc_ops = {
+	.chan_available = qcom_hvc_chan_available,
+	.chan_setup = qcom_hvc_chan_setup,
+	.chan_free = qcom_hvc_chan_free,
+	.send_message = qcom_hvc_send_message,
+	.mark_txdone = qcom_hvc_mark_txdone,
+	.fetch_response = qcom_hvc_fetch_response,
+	.poll_done = qcom_hvc_poll_done,
+};
+
+const struct scmi_desc scmi_qcom_hvc_desc = {
+	.ops = &scmi_qcom_hvc_ops,
+	.max_rx_timeout_ms = 30,
+	.max_msg = 20,
+	.max_msg_size = 128,
+};
-- 
2.17.1


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

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
  2023-08-11 17:57   ` Nikunj Kela
@ 2023-09-05 16:06     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-05 16:06 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 8/11/2023 10:57 AM, Nikunj Kela wrote:
> This change introduce a new transport channel for Qualcomm virtual
> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
> The difference between the two transports is that a parameter is passed in
> the hypervisor call to identify which doorbell to assert. This parameter is
> dynamically generated at runtime on the device and insuitable to pass via
> the devicetree.
>
> The function ID and parameter are stored by firmware in the shmem region.
>
> This has been tested on ARM64 virtual Qualcomm platform.
>
> ---
> v3 -> fix the compilation error reported by the test bot,
>        add support for polling based instances
>
> v2 -> use allOf construct in dtb schema,
>        remove wrappers from mutexes,
>        use architecture independent channel layout
>
> v1 -> original patches
>
> Nikunj Kela (3):
>    dt-bindings: arm: convert nested if-else construct to allOf
>    dt-bindings: arm: Add qcom specific hvc transport for SCMI
>    firmware: arm_scmi: Add qcom hvc/shmem transport
>
>   .../bindings/firmware/arm,scmi.yaml           |  67 ++---
>   drivers/firmware/arm_scmi/Kconfig             |  13 +
>   drivers/firmware/arm_scmi/Makefile            |   2 +
>   drivers/firmware/arm_scmi/common.h            |   3 +
>   drivers/firmware/arm_scmi/driver.c            |   4 +
>   drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
>   6 files changed, 293 insertions(+), 28 deletions(-)
>   create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
Gentle Ping!

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

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
@ 2023-09-05 16:06     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-05 16:06 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 8/11/2023 10:57 AM, Nikunj Kela wrote:
> This change introduce a new transport channel for Qualcomm virtual
> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
> The difference between the two transports is that a parameter is passed in
> the hypervisor call to identify which doorbell to assert. This parameter is
> dynamically generated at runtime on the device and insuitable to pass via
> the devicetree.
>
> The function ID and parameter are stored by firmware in the shmem region.
>
> This has been tested on ARM64 virtual Qualcomm platform.
>
> ---
> v3 -> fix the compilation error reported by the test bot,
>        add support for polling based instances
>
> v2 -> use allOf construct in dtb schema,
>        remove wrappers from mutexes,
>        use architecture independent channel layout
>
> v1 -> original patches
>
> Nikunj Kela (3):
>    dt-bindings: arm: convert nested if-else construct to allOf
>    dt-bindings: arm: Add qcom specific hvc transport for SCMI
>    firmware: arm_scmi: Add qcom hvc/shmem transport
>
>   .../bindings/firmware/arm,scmi.yaml           |  67 ++---
>   drivers/firmware/arm_scmi/Kconfig             |  13 +
>   drivers/firmware/arm_scmi/Makefile            |   2 +
>   drivers/firmware/arm_scmi/common.h            |   3 +
>   drivers/firmware/arm_scmi/driver.c            |   4 +
>   drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
>   6 files changed, 293 insertions(+), 28 deletions(-)
>   create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
Gentle Ping!

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
  2023-09-05 16:06     ` Nikunj Kela
@ 2023-09-05 16:37       ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-05 16:37 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 05/09/2023 18:06, Nikunj Kela wrote:
> 
> On 8/11/2023 10:57 AM, Nikunj Kela wrote:
>> This change introduce a new transport channel for Qualcomm virtual
>> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
>> The difference between the two transports is that a parameter is passed in
>> the hypervisor call to identify which doorbell to assert. This parameter is
>> dynamically generated at runtime on the device and insuitable to pass via
>> the devicetree.
>>
>> The function ID and parameter are stored by firmware in the shmem region.
>>
>> This has been tested on ARM64 virtual Qualcomm platform.
>>
>> ---
>> v3 -> fix the compilation error reported by the test bot,
>>        add support for polling based instances
>>
>> v2 -> use allOf construct in dtb schema,
>>        remove wrappers from mutexes,
>>        use architecture independent channel layout
>>
>> v1 -> original patches
>>
>> Nikunj Kela (3):
>>    dt-bindings: arm: convert nested if-else construct to allOf
>>    dt-bindings: arm: Add qcom specific hvc transport for SCMI
>>    firmware: arm_scmi: Add qcom hvc/shmem transport
>>
>>   .../bindings/firmware/arm,scmi.yaml           |  67 ++---
>>   drivers/firmware/arm_scmi/Kconfig             |  13 +
>>   drivers/firmware/arm_scmi/Makefile            |   2 +
>>   drivers/firmware/arm_scmi/common.h            |   3 +
>>   drivers/firmware/arm_scmi/driver.c            |   4 +
>>   drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
>>   6 files changed, 293 insertions(+), 28 deletions(-)
>>   create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
> Gentle Ping!

It's third ping these two weeks from Qualcomm. Folks, it is merge
window. What do you think will happen with your ping during this time?

Best regards,
Krzysztof


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

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
@ 2023-09-05 16:37       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-05 16:37 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 05/09/2023 18:06, Nikunj Kela wrote:
> 
> On 8/11/2023 10:57 AM, Nikunj Kela wrote:
>> This change introduce a new transport channel for Qualcomm virtual
>> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
>> The difference between the two transports is that a parameter is passed in
>> the hypervisor call to identify which doorbell to assert. This parameter is
>> dynamically generated at runtime on the device and insuitable to pass via
>> the devicetree.
>>
>> The function ID and parameter are stored by firmware in the shmem region.
>>
>> This has been tested on ARM64 virtual Qualcomm platform.
>>
>> ---
>> v3 -> fix the compilation error reported by the test bot,
>>        add support for polling based instances
>>
>> v2 -> use allOf construct in dtb schema,
>>        remove wrappers from mutexes,
>>        use architecture independent channel layout
>>
>> v1 -> original patches
>>
>> Nikunj Kela (3):
>>    dt-bindings: arm: convert nested if-else construct to allOf
>>    dt-bindings: arm: Add qcom specific hvc transport for SCMI
>>    firmware: arm_scmi: Add qcom hvc/shmem transport
>>
>>   .../bindings/firmware/arm,scmi.yaml           |  67 ++---
>>   drivers/firmware/arm_scmi/Kconfig             |  13 +
>>   drivers/firmware/arm_scmi/Makefile            |   2 +
>>   drivers/firmware/arm_scmi/common.h            |   3 +
>>   drivers/firmware/arm_scmi/driver.c            |   4 +
>>   drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
>>   6 files changed, 293 insertions(+), 28 deletions(-)
>>   create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
> Gentle Ping!

It's third ping these two weeks from Qualcomm. Folks, it is merge
window. What do you think will happen with your ping during this time?

Best regards,
Krzysztof


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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
  2023-09-05 16:37       ` Krzysztof Kozlowski
@ 2023-09-07 10:36         ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-09-07 10:36 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Krzysztof Kozlowski, cristian.marussi, Sudeep Holla, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, agross, andersson,
	konrad.dybcio, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm

On Tue, Sep 05, 2023 at 06:37:14PM +0200, Krzysztof Kozlowski wrote:
> On 05/09/2023 18:06, Nikunj Kela wrote:
> > 
> > On 8/11/2023 10:57 AM, Nikunj Kela wrote:
> >> This change introduce a new transport channel for Qualcomm virtual
> >> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
> >> The difference between the two transports is that a parameter is passed in
> >> the hypervisor call to identify which doorbell to assert. This parameter is
> >> dynamically generated at runtime on the device and insuitable to pass via
> >> the devicetree.
> >>
> >> The function ID and parameter are stored by firmware in the shmem region.
> >>
> >> This has been tested on ARM64 virtual Qualcomm platform.
> >>
> >> ---
> >> v3 -> fix the compilation error reported by the test bot,
> >>        add support for polling based instances
> >>
> >> v2 -> use allOf construct in dtb schema,
> >>        remove wrappers from mutexes,
> >>        use architecture independent channel layout
> >>
> >> v1 -> original patches
> >>
> >> Nikunj Kela (3):
> >>    dt-bindings: arm: convert nested if-else construct to allOf
> >>    dt-bindings: arm: Add qcom specific hvc transport for SCMI
> >>    firmware: arm_scmi: Add qcom hvc/shmem transport
> >>
> >>   .../bindings/firmware/arm,scmi.yaml           |  67 ++---
> >>   drivers/firmware/arm_scmi/Kconfig             |  13 +
> >>   drivers/firmware/arm_scmi/Makefile            |   2 +
> >>   drivers/firmware/arm_scmi/common.h            |   3 +
> >>   drivers/firmware/arm_scmi/driver.c            |   4 +
> >>   drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
> >>   6 files changed, 293 insertions(+), 28 deletions(-)
> >>   create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
> > Gentle Ping!

Pong !

>
> It's third ping these two weeks from Qualcomm. Folks, it is merge
> window. What do you think will happen with your ping during this time?
>

+1

Okay, here is the deal with this patch set. As you are aware that a previous
merged solution was abandoned by Qcom in a single kernel release cycle. So
I decided to ignore this for one or 2 kernel release cycle to make sure
Qcom makes up their mind on the design and then we can see how to proceed.
Qcom must understand upstream kernel is not a playground to push their
design which they might decided to drop support for in such short period.
Please understand the upstream kernel supports platforms that are more than
few decades old. It is not like the mobile platforms that are hardly supported
for couple of years. And similarly, we push core support if and only if we
know for sure it will be used on some platform. I trusted Qcom with the
previous extension of SMC/HVC transport but I was proven wrong.

Also, I definitely don't like the way you have copied the whole smc.c
and changed it to Qcom's need and made it qcom_hvc.c. Just add the required
changes in smc.c.

--
Regards,
Sudeep

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

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
@ 2023-09-07 10:36         ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-09-07 10:36 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Krzysztof Kozlowski, cristian.marussi, Sudeep Holla, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, agross, andersson,
	konrad.dybcio, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm

On Tue, Sep 05, 2023 at 06:37:14PM +0200, Krzysztof Kozlowski wrote:
> On 05/09/2023 18:06, Nikunj Kela wrote:
> > 
> > On 8/11/2023 10:57 AM, Nikunj Kela wrote:
> >> This change introduce a new transport channel for Qualcomm virtual
> >> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
> >> The difference between the two transports is that a parameter is passed in
> >> the hypervisor call to identify which doorbell to assert. This parameter is
> >> dynamically generated at runtime on the device and insuitable to pass via
> >> the devicetree.
> >>
> >> The function ID and parameter are stored by firmware in the shmem region.
> >>
> >> This has been tested on ARM64 virtual Qualcomm platform.
> >>
> >> ---
> >> v3 -> fix the compilation error reported by the test bot,
> >>        add support for polling based instances
> >>
> >> v2 -> use allOf construct in dtb schema,
> >>        remove wrappers from mutexes,
> >>        use architecture independent channel layout
> >>
> >> v1 -> original patches
> >>
> >> Nikunj Kela (3):
> >>    dt-bindings: arm: convert nested if-else construct to allOf
> >>    dt-bindings: arm: Add qcom specific hvc transport for SCMI
> >>    firmware: arm_scmi: Add qcom hvc/shmem transport
> >>
> >>   .../bindings/firmware/arm,scmi.yaml           |  67 ++---
> >>   drivers/firmware/arm_scmi/Kconfig             |  13 +
> >>   drivers/firmware/arm_scmi/Makefile            |   2 +
> >>   drivers/firmware/arm_scmi/common.h            |   3 +
> >>   drivers/firmware/arm_scmi/driver.c            |   4 +
> >>   drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
> >>   6 files changed, 293 insertions(+), 28 deletions(-)
> >>   create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
> > Gentle Ping!

Pong !

>
> It's third ping these two weeks from Qualcomm. Folks, it is merge
> window. What do you think will happen with your ping during this time?
>

+1

Okay, here is the deal with this patch set. As you are aware that a previous
merged solution was abandoned by Qcom in a single kernel release cycle. So
I decided to ignore this for one or 2 kernel release cycle to make sure
Qcom makes up their mind on the design and then we can see how to proceed.
Qcom must understand upstream kernel is not a playground to push their
design which they might decided to drop support for in such short period.
Please understand the upstream kernel supports platforms that are more than
few decades old. It is not like the mobile platforms that are hardly supported
for couple of years. And similarly, we push core support if and only if we
know for sure it will be used on some platform. I trusted Qcom with the
previous extension of SMC/HVC transport but I was proven wrong.

Also, I definitely don't like the way you have copied the whole smc.c
and changed it to Qcom's need and made it qcom_hvc.c. Just add the required
changes in smc.c.

--
Regards,
Sudeep

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
  2023-09-07 10:36         ` Sudeep Holla
@ 2023-09-07 14:20           ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-07 14:20 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Krzysztof Kozlowski, cristian.marussi, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, agross, andersson,
	konrad.dybcio, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm


On 9/7/2023 3:36 AM, Sudeep Holla wrote:
> On Tue, Sep 05, 2023 at 06:37:14PM +0200, Krzysztof Kozlowski wrote:
>> On 05/09/2023 18:06, Nikunj Kela wrote:
>>> On 8/11/2023 10:57 AM, Nikunj Kela wrote:
>>>> This change introduce a new transport channel for Qualcomm virtual
>>>> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
>>>> The difference between the two transports is that a parameter is passed in
>>>> the hypervisor call to identify which doorbell to assert. This parameter is
>>>> dynamically generated at runtime on the device and insuitable to pass via
>>>> the devicetree.
>>>>
>>>> The function ID and parameter are stored by firmware in the shmem region.
>>>>
>>>> This has been tested on ARM64 virtual Qualcomm platform.
>>>>
>>>> ---
>>>> v3 -> fix the compilation error reported by the test bot,
>>>>         add support for polling based instances
>>>>
>>>> v2 -> use allOf construct in dtb schema,
>>>>         remove wrappers from mutexes,
>>>>         use architecture independent channel layout
>>>>
>>>> v1 -> original patches
>>>>
>>>> Nikunj Kela (3):
>>>>     dt-bindings: arm: convert nested if-else construct to allOf
>>>>     dt-bindings: arm: Add qcom specific hvc transport for SCMI
>>>>     firmware: arm_scmi: Add qcom hvc/shmem transport
>>>>
>>>>    .../bindings/firmware/arm,scmi.yaml           |  67 ++---
>>>>    drivers/firmware/arm_scmi/Kconfig             |  13 +
>>>>    drivers/firmware/arm_scmi/Makefile            |   2 +
>>>>    drivers/firmware/arm_scmi/common.h            |   3 +
>>>>    drivers/firmware/arm_scmi/driver.c            |   4 +
>>>>    drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
>>>>    6 files changed, 293 insertions(+), 28 deletions(-)
>>>>    create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
>>> Gentle Ping!
> Pong !
>
>> It's third ping these two weeks from Qualcomm. Folks, it is merge
>> window. What do you think will happen with your ping during this time?
>>
> +1
>
> Okay, here is the deal with this patch set. As you are aware that a previous
> merged solution was abandoned by Qcom in a single kernel release cycle. So
> I decided to ignore this for one or 2 kernel release cycle to make sure
> Qcom makes up their mind on the design and then we can see how to proceed.
> Qcom must understand upstream kernel is not a playground to push their
> design which they might decided to drop support for in such short period.
> Please understand the upstream kernel supports platforms that are more than
> few decades old. It is not like the mobile platforms that are hardly supported
> for couple of years. And similarly, we push core support if and only if we
> know for sure it will be used on some platform. I trusted Qcom with the
> previous extension of SMC/HVC transport but I was proven wrong.
>
> Also, I definitely don't like the way you have copied the whole smc.c
> and changed it to Qcom's need and made it qcom_hvc.c. Just add the required
> changes in smc.c.
>
> --
> Regards,
> Sudeep

Completely understand your concerns and extending my apologies once 
again on the patch that was abandoned. I will rework the patch to 
include changes in smc.c. Thanks so much for your response!


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

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

* Re: [PATCH v3 0/3] Add qcom hvc/shmem transport
@ 2023-09-07 14:20           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-07 14:20 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Krzysztof Kozlowski, cristian.marussi, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, agross, andersson,
	konrad.dybcio, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm


On 9/7/2023 3:36 AM, Sudeep Holla wrote:
> On Tue, Sep 05, 2023 at 06:37:14PM +0200, Krzysztof Kozlowski wrote:
>> On 05/09/2023 18:06, Nikunj Kela wrote:
>>> On 8/11/2023 10:57 AM, Nikunj Kela wrote:
>>>> This change introduce a new transport channel for Qualcomm virtual
>>>> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
>>>> The difference between the two transports is that a parameter is passed in
>>>> the hypervisor call to identify which doorbell to assert. This parameter is
>>>> dynamically generated at runtime on the device and insuitable to pass via
>>>> the devicetree.
>>>>
>>>> The function ID and parameter are stored by firmware in the shmem region.
>>>>
>>>> This has been tested on ARM64 virtual Qualcomm platform.
>>>>
>>>> ---
>>>> v3 -> fix the compilation error reported by the test bot,
>>>>         add support for polling based instances
>>>>
>>>> v2 -> use allOf construct in dtb schema,
>>>>         remove wrappers from mutexes,
>>>>         use architecture independent channel layout
>>>>
>>>> v1 -> original patches
>>>>
>>>> Nikunj Kela (3):
>>>>     dt-bindings: arm: convert nested if-else construct to allOf
>>>>     dt-bindings: arm: Add qcom specific hvc transport for SCMI
>>>>     firmware: arm_scmi: Add qcom hvc/shmem transport
>>>>
>>>>    .../bindings/firmware/arm,scmi.yaml           |  67 ++---
>>>>    drivers/firmware/arm_scmi/Kconfig             |  13 +
>>>>    drivers/firmware/arm_scmi/Makefile            |   2 +
>>>>    drivers/firmware/arm_scmi/common.h            |   3 +
>>>>    drivers/firmware/arm_scmi/driver.c            |   4 +
>>>>    drivers/firmware/arm_scmi/qcom_hvc.c          | 232 ++++++++++++++++++
>>>>    6 files changed, 293 insertions(+), 28 deletions(-)
>>>>    create mode 100644 drivers/firmware/arm_scmi/qcom_hvc.c
>>> Gentle Ping!
> Pong !
>
>> It's third ping these two weeks from Qualcomm. Folks, it is merge
>> window. What do you think will happen with your ping during this time?
>>
> +1
>
> Okay, here is the deal with this patch set. As you are aware that a previous
> merged solution was abandoned by Qcom in a single kernel release cycle. So
> I decided to ignore this for one or 2 kernel release cycle to make sure
> Qcom makes up their mind on the design and then we can see how to proceed.
> Qcom must understand upstream kernel is not a playground to push their
> design which they might decided to drop support for in such short period.
> Please understand the upstream kernel supports platforms that are more than
> few decades old. It is not like the mobile platforms that are hardly supported
> for couple of years. And similarly, we push core support if and only if we
> know for sure it will be used on some platform. I trusted Qcom with the
> previous extension of SMC/HVC transport but I was proven wrong.
>
> Also, I definitely don't like the way you have copied the whole smc.c
> and changed it to Qcom's need and made it qcom_hvc.c. Just add the required
> changes in smc.c.
>
> --
> Regards,
> Sudeep

Completely understand your concerns and extending my apologies once 
again on the patch that was abandoned. I will rework the patch to 
include changes in smc.c. Thanks so much for your response!


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

* Re: [PATCH 0/2] Add qcom hvc/shmem transport
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-09-07 16:16   ` Konrad Dybcio
  -1 siblings, 0 replies; 186+ messages in thread
From: Konrad Dybcio @ 2023-09-07 16:16 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm

On 18.07.2023 18:08, Nikunj Kela wrote:
> This change introduce a new transport channel for Qualcomm virtual
> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
> The difference between the two transports is that a parameter is passed in
> the hypervisor call to identify which doorbell to assert. This parameter is
> dynamically generated at runtime on the device and insuitable to pass via
> the devicetree.
> 
> The function ID and parameter are stored by firmware in the shmem region.
> 
> This has been tested on ARM64 virtual Qualcomm platform.
What can we test it on?

Konrad

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

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

* Re: [PATCH 0/2] Add qcom hvc/shmem transport
@ 2023-09-07 16:16   ` Konrad Dybcio
  0 siblings, 0 replies; 186+ messages in thread
From: Konrad Dybcio @ 2023-09-07 16:16 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm

On 18.07.2023 18:08, Nikunj Kela wrote:
> This change introduce a new transport channel for Qualcomm virtual
> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
> The difference between the two transports is that a parameter is passed in
> the hypervisor call to identify which doorbell to assert. This parameter is
> dynamically generated at runtime on the device and insuitable to pass via
> the devicetree.
> 
> The function ID and parameter are stored by firmware in the shmem region.
> 
> This has been tested on ARM64 virtual Qualcomm platform.
What can we test it on?

Konrad

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

* Re: [PATCH 0/2] Add qcom hvc/shmem transport
  2023-09-07 16:16   ` Konrad Dybcio
@ 2023-09-07 22:32     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-07 22:32 UTC (permalink / raw)
  To: Konrad Dybcio, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm


On 9/7/2023 9:16 AM, Konrad Dybcio wrote:
> On 18.07.2023 18:08, Nikunj Kela wrote:
>> This change introduce a new transport channel for Qualcomm virtual
>> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
>> The difference between the two transports is that a parameter is passed in
>> the hypervisor call to identify which doorbell to assert. This parameter is
>> dynamically generated at runtime on the device and insuitable to pass via
>> the devicetree.
>>
>> The function ID and parameter are stored by firmware in the shmem region.
>>
>> This has been tested on ARM64 virtual Qualcomm platform.
> What can we test it on?
>
> Konrad
This is being developed for SA8775p platform.

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

* Re: [PATCH 0/2] Add qcom hvc/shmem transport
@ 2023-09-07 22:32     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-07 22:32 UTC (permalink / raw)
  To: Konrad Dybcio, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	agross, andersson, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm


On 9/7/2023 9:16 AM, Konrad Dybcio wrote:
> On 18.07.2023 18:08, Nikunj Kela wrote:
>> This change introduce a new transport channel for Qualcomm virtual
>> platforms. The transport is mechanically similar to ARM_SCMI_TRANSPORT_SMC.
>> The difference between the two transports is that a parameter is passed in
>> the hypervisor call to identify which doorbell to assert. This parameter is
>> dynamically generated at runtime on the device and insuitable to pass via
>> the devicetree.
>>
>> The function ID and parameter are stored by firmware in the shmem region.
>>
>> This has been tested on ARM64 virtual Qualcomm platform.
> What can we test it on?
>
> Konrad
This is being developed for SA8775p platform.

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

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

* [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-09-11 19:43   ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change augments smc transport to include support for Qualcomm virtual
platforms by passing a parameter(capability-id) in the hypervisor call to
identify which doorbell to assert. This parameter is dynamically generated
at runtime on the device and insuitable to pass via the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v4 -> port the changes into smc.c

v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (4):
  firmware: arm_scmi: Add polling support for completion in smc
  dt-bindings: arm: convert nested if-else construct to allOf
  dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport support

 .../bindings/firmware/arm,scmi.yaml           | 67 +++++++++++--------
 drivers/firmware/arm_scmi/Kconfig             | 14 ++++
 drivers/firmware/arm_scmi/driver.c            |  1 +
 drivers/firmware/arm_scmi/smc.c               | 62 +++++++++++++++--
 4 files changed, 110 insertions(+), 34 deletions(-)

-- 
2.17.1


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

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

* [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-09-11 19:43   ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change augments smc transport to include support for Qualcomm virtual
platforms by passing a parameter(capability-id) in the hypervisor call to
identify which doorbell to assert. This parameter is dynamically generated
at runtime on the device and insuitable to pass via the devicetree.

The function ID and parameter are stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v4 -> port the changes into smc.c

v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (4):
  firmware: arm_scmi: Add polling support for completion in smc
  dt-bindings: arm: convert nested if-else construct to allOf
  dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  firmware: arm_scmi: Add qcom hvc/shmem transport support

 .../bindings/firmware/arm,scmi.yaml           | 67 +++++++++++--------
 drivers/firmware/arm_scmi/Kconfig             | 14 ++++
 drivers/firmware/arm_scmi/driver.c            |  1 +
 drivers/firmware/arm_scmi/smc.c               | 62 +++++++++++++++--
 4 files changed, 110 insertions(+), 34 deletions(-)

-- 
2.17.1


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

* [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-09-11 19:43   ` Nikunj Kela
@ 2023-09-11 19:43     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Currently, the return from the smc call assumes the completion of
the scmi request. However this may not be true in virtual platforms
that are using hvc doorbell.

This change adds a Kconfig to enable the polling for the request
completion.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig | 14 ++++++++++++++
 drivers/firmware/arm_scmi/smc.c   | 15 ++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..771d60f8319f 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -125,6 +125,20 @@ config ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE
 	  in atomic context too, at the price of using a number of busy-waiting
 	  primitives all over instead. If unsure say N.
 
+config ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
+	bool "Enable polling support for SCMI SMC transport"
+	depends on ARM_SCMI_TRANSPORT_SMC
+	help
+	  Enable completion polling support for SCMI SMC based transport.
+
+	  If you want the SCMI SMC based transport to poll for the completion,
+	  answer Y.
+	  Enabling completion polling might be desired in the absence of the a2p
+	  irq when the return from smc/hvc call doesn't indicate the completion
+	  of the SCMI requests. This might be useful for instances used in
+	  virtual platforms.
+	  If unsure say N.
+
 config ARM_SCMI_TRANSPORT_VIRTIO
 	bool "SCMI transport based on VirtIO"
 	depends on VIRTIO=y || VIRTIO=ARM_SCMI_PROTOCOL
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index c193516a254d..0a0b7e401159 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -250,6 +250,16 @@ static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
 	smc_channel_lock_release(scmi_info);
 }
 
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
+static bool
+smc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
+{
+	struct scmi_smc *scmi_info = cinfo->transport_info;
+
+	return shmem_poll_done(scmi_info->shmem, xfer);
+}
+#endif
+
 static const struct scmi_transport_ops scmi_smc_ops = {
 	.chan_available = smc_chan_available,
 	.chan_setup = smc_chan_setup,
@@ -257,6 +267,9 @@ static const struct scmi_transport_ops scmi_smc_ops = {
 	.send_message = smc_send_message,
 	.mark_txdone = smc_mark_txdone,
 	.fetch_response = smc_fetch_response,
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
+	.poll_done = smc_poll_done,
+#endif
 };
 
 const struct scmi_desc scmi_smc_desc = {
@@ -272,6 +285,6 @@ const struct scmi_desc scmi_smc_desc = {
 	 * for the issued command will be immmediately ready to be fetched
 	 * from the shared memory area.
 	 */
-	.sync_cmds_completed_on_ret = true,
+	.sync_cmds_completed_on_ret = !IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION),
 	.atomic_enabled = IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE),
 };
-- 
2.17.1


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

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

* [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-09-11 19:43     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Currently, the return from the smc call assumes the completion of
the scmi request. However this may not be true in virtual platforms
that are using hvc doorbell.

This change adds a Kconfig to enable the polling for the request
completion.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/Kconfig | 14 ++++++++++++++
 drivers/firmware/arm_scmi/smc.c   | 15 ++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index ea0f5083ac47..771d60f8319f 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -125,6 +125,20 @@ config ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE
 	  in atomic context too, at the price of using a number of busy-waiting
 	  primitives all over instead. If unsure say N.
 
+config ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
+	bool "Enable polling support for SCMI SMC transport"
+	depends on ARM_SCMI_TRANSPORT_SMC
+	help
+	  Enable completion polling support for SCMI SMC based transport.
+
+	  If you want the SCMI SMC based transport to poll for the completion,
+	  answer Y.
+	  Enabling completion polling might be desired in the absence of the a2p
+	  irq when the return from smc/hvc call doesn't indicate the completion
+	  of the SCMI requests. This might be useful for instances used in
+	  virtual platforms.
+	  If unsure say N.
+
 config ARM_SCMI_TRANSPORT_VIRTIO
 	bool "SCMI transport based on VirtIO"
 	depends on VIRTIO=y || VIRTIO=ARM_SCMI_PROTOCOL
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index c193516a254d..0a0b7e401159 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -250,6 +250,16 @@ static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
 	smc_channel_lock_release(scmi_info);
 }
 
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
+static bool
+smc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
+{
+	struct scmi_smc *scmi_info = cinfo->transport_info;
+
+	return shmem_poll_done(scmi_info->shmem, xfer);
+}
+#endif
+
 static const struct scmi_transport_ops scmi_smc_ops = {
 	.chan_available = smc_chan_available,
 	.chan_setup = smc_chan_setup,
@@ -257,6 +267,9 @@ static const struct scmi_transport_ops scmi_smc_ops = {
 	.send_message = smc_send_message,
 	.mark_txdone = smc_mark_txdone,
 	.fetch_response = smc_fetch_response,
+#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
+	.poll_done = smc_poll_done,
+#endif
 };
 
 const struct scmi_desc scmi_smc_desc = {
@@ -272,6 +285,6 @@ const struct scmi_desc scmi_smc_desc = {
 	 * for the issued command will be immmediately ready to be fetched
 	 * from the shared memory area.
 	 */
-	.sync_cmds_completed_on_ret = true,
+	.sync_cmds_completed_on_ret = !IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION),
 	.atomic_enabled = IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE),
 };
-- 
2.17.1


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

* [PATCH v4 2/4] dt-bindings: arm: convert nested if-else construct to allOf
  2023-09-11 19:43   ` Nikunj Kela
@ 2023-09-11 19:43     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Nested if-else construct is not scalable therefore, convert
it to allOf:if-else.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Suggested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../bindings/firmware/arm,scmi.yaml           | 55 +++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..8d54ea768d38 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -284,35 +284,34 @@ $defs:
 required:
   - compatible
 
-if:
-  properties:
-    compatible:
-      contains:
-        const: arm,scmi
-then:
-  properties:
-    interrupts: false
-    interrupt-names: false
-
-  required:
-    - mboxes
-    - shmem
-
-else:
-  if:
-    properties:
-      compatible:
-        contains:
-          enum:
-            - arm,scmi-smc
-            - arm,scmi-smc-param
-  then:
-    required:
-      - arm,smc-id
-      - shmem
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: arm,scmi
+    then:
+      properties:
+        interrupts: false
+        interrupt-names: false
+
+      required:
+        - mboxes
+        - shmem
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - arm,scmi-smc
+              - arm,scmi-smc-param
+    then:
+      required:
+        - arm,smc-id
+        - shmem
 
-  else:
-    if:
+  - if:
       properties:
         compatible:
           contains:
-- 
2.17.1


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

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

* [PATCH v4 2/4] dt-bindings: arm: convert nested if-else construct to allOf
@ 2023-09-11 19:43     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Nested if-else construct is not scalable therefore, convert
it to allOf:if-else.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Suggested-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../bindings/firmware/arm,scmi.yaml           | 55 +++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index b138f3d23df8..8d54ea768d38 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -284,35 +284,34 @@ $defs:
 required:
   - compatible
 
-if:
-  properties:
-    compatible:
-      contains:
-        const: arm,scmi
-then:
-  properties:
-    interrupts: false
-    interrupt-names: false
-
-  required:
-    - mboxes
-    - shmem
-
-else:
-  if:
-    properties:
-      compatible:
-        contains:
-          enum:
-            - arm,scmi-smc
-            - arm,scmi-smc-param
-  then:
-    required:
-      - arm,smc-id
-      - shmem
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: arm,scmi
+    then:
+      properties:
+        interrupts: false
+        interrupt-names: false
+
+      required:
+        - mboxes
+        - shmem
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - arm,scmi-smc
+              - arm,scmi-smc-param
+    then:
+      required:
+        - arm,smc-id
+        - shmem
 
-  else:
-    if:
+  - if:
       properties:
         compatible:
           contains:
-- 
2.17.1


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

* [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-09-11 19:43   ` Nikunj Kela
@ 2023-09-11 19:43     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 8d54ea768d38..4090240f45b1 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -320,6 +323,15 @@ allOf:
       required:
         - linaro,optee-channel-id
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,scmi-hvc-shmem
+    then:
+      required:
+        - shmem
+
 examples:
   - |
     firmware {
-- 
2.17.1


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

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

* [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-09-11 19:43     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
transport channel for Qualcomm virtual platforms.
The compatible mandates a shared memory channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 8d54ea768d38..4090240f45b1 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -45,6 +45,9 @@ properties:
       - description: SCMI compliant firmware with OP-TEE transport
         items:
           - const: linaro,scmi-optee
+      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
+        items:
+          - const: qcom,scmi-hvc-shmem
 
   interrupts:
     description:
@@ -320,6 +323,15 @@ allOf:
       required:
         - linaro,optee-channel-id
 
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,scmi-hvc-shmem
+    then:
+      required:
+        - shmem
+
 examples:
   - |
     firmware {
-- 
2.17.1


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

* [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-09-11 19:43   ` Nikunj Kela
@ 2023-09-11 19:43     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change adds the support for SCMI message exchange on Qualcomm
virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/driver.c |  1 +
 drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 87383c05424b..ea344bc6ae49 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
 	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
 	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
+	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index 0a0b7e401159..94ec07fdc14a 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -50,6 +50,9 @@
  * @func_id: smc/hvc call function id
  * @param_page: 4K page number of the shmem channel
  * @param_offset: Offset within the 4K page of the shmem channel
+ * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
+ *	    platforms
+ * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
  */
 
 struct scmi_smc {
@@ -63,6 +66,8 @@ struct scmi_smc {
 	u32 func_id;
 	u32 param_page;
 	u32 param_offset;
+	u64 cap_id;
+	bool qcom_xport;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	struct resource res;
 	struct device_node *np;
 	u32 func_id;
+	u64 cap_id;
 	int ret;
 
 	if (!tx)
@@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return -EADDRNOTAVAIL;
 	}
 
-	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
-	if (ret < 0)
-		return ret;
+	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
+		scmi_info->qcom_xport = true;
+
+		/* The func-id & capability-id are kept in last 16 bytes of shmem.
+		 *     +-------+
+		 *     |       |
+		 *     | shmem |
+		 *     |       |
+		 *     |       |
+		 *     +-------+ <-- (size - 16)
+		 *     | funcId|
+		 *     +-------+ <-- (size - 8)
+		 *     | capId |
+		 *     +-------+ <-- size
+		 */
+
+		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
+#ifdef CONFIG_ARM64
+		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
+#else
+		/* capability-id is 32 bit wide on 32bit machines */
+		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
+#endif
+	} else {
+		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
+		if (ret < 0)
+			return ret;
+	}
 
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
 		scmi_info->param_page = SHMEM_PAGE(res.start);
@@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	}
 
 	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
 	scmi_info->cinfo = cinfo;
 	smc_channel_lock_init(scmi_info);
 	cinfo->transport_info = scmi_info;
@@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 	struct arm_smccc_res res;
 	unsigned long page = scmi_info->param_page;
 	unsigned long offset = scmi_info->param_offset;
+	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
 
 	/*
 	 * Channel will be released only once response has been
@@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
-			     &res);
+	if (scmi_info->qcom_xport)
+		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
+				  &res);
+	else
+		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
+				     0, 0, &res);
 
 	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
 	if (res.a0) {
-- 
2.17.1


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

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

* [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-09-11 19:43     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-11 19:43 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change adds the support for SCMI message exchange on Qualcomm
virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each hvc doorbell object. The capability-id is used to identify the
doorbell from the VM's capability namespace, similar to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when HVC call is invoked.

The function-id & capability-id are allocated by the hypervisor on bootup
and are stored in the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/driver.c |  1 +
 drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 87383c05424b..ea344bc6ae49 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
 	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
 	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
+	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index 0a0b7e401159..94ec07fdc14a 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -50,6 +50,9 @@
  * @func_id: smc/hvc call function id
  * @param_page: 4K page number of the shmem channel
  * @param_offset: Offset within the 4K page of the shmem channel
+ * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
+ *	    platforms
+ * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
  */
 
 struct scmi_smc {
@@ -63,6 +66,8 @@ struct scmi_smc {
 	u32 func_id;
 	u32 param_page;
 	u32 param_offset;
+	u64 cap_id;
+	bool qcom_xport;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	struct resource res;
 	struct device_node *np;
 	u32 func_id;
+	u64 cap_id;
 	int ret;
 
 	if (!tx)
@@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return -EADDRNOTAVAIL;
 	}
 
-	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
-	if (ret < 0)
-		return ret;
+	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
+		scmi_info->qcom_xport = true;
+
+		/* The func-id & capability-id are kept in last 16 bytes of shmem.
+		 *     +-------+
+		 *     |       |
+		 *     | shmem |
+		 *     |       |
+		 *     |       |
+		 *     +-------+ <-- (size - 16)
+		 *     | funcId|
+		 *     +-------+ <-- (size - 8)
+		 *     | capId |
+		 *     +-------+ <-- size
+		 */
+
+		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
+#ifdef CONFIG_ARM64
+		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
+#else
+		/* capability-id is 32 bit wide on 32bit machines */
+		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
+#endif
+	} else {
+		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
+		if (ret < 0)
+			return ret;
+	}
 
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
 		scmi_info->param_page = SHMEM_PAGE(res.start);
@@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	}
 
 	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
 	scmi_info->cinfo = cinfo;
 	smc_channel_lock_init(scmi_info);
 	cinfo->transport_info = scmi_info;
@@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 	struct arm_smccc_res res;
 	unsigned long page = scmi_info->param_page;
 	unsigned long offset = scmi_info->param_offset;
+	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
 
 	/*
 	 * Channel will be released only once response has been
@@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
-			     &res);
+	if (scmi_info->qcom_xport)
+		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
+				  &res);
+	else
+		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
+				     0, 0, &res);
 
 	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
 	if (res.a0) {
-- 
2.17.1


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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-09-11 19:43   ` Nikunj Kela
@ 2023-09-18 15:01     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-18 15:01 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

Gentle Ping!

On 9/11/2023 12:43 PM, Nikunj Kela wrote:
> This change augments smc transport to include support for Qualcomm virtual
> platforms by passing a parameter(capability-id) in the hypervisor call to
> identify which doorbell to assert. This parameter is dynamically generated
> at runtime on the device and insuitable to pass via the devicetree.
>
> The function ID and parameter are stored by firmware in the shmem region.
>
> This has been tested on ARM64 virtual Qualcomm platform.
>
> ---
> v4 -> port the changes into smc.c
>
> v3 -> fix the compilation error reported by the test bot,
>        add support for polling based instances
>
> v2 -> use allOf construct in dtb schema,
>        remove wrappers from mutexes,
>        use architecture independent channel layout
>
> v1 -> original patches
>
> Nikunj Kela (4):
>    firmware: arm_scmi: Add polling support for completion in smc
>    dt-bindings: arm: convert nested if-else construct to allOf
>    dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
>    firmware: arm_scmi: Add qcom hvc/shmem transport support
>
>   .../bindings/firmware/arm,scmi.yaml           | 67 +++++++++++--------
>   drivers/firmware/arm_scmi/Kconfig             | 14 ++++
>   drivers/firmware/arm_scmi/driver.c            |  1 +
>   drivers/firmware/arm_scmi/smc.c               | 62 +++++++++++++++--
>   4 files changed, 110 insertions(+), 34 deletions(-)
>

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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-09-18 15:01     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-09-18 15:01 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

Gentle Ping!

On 9/11/2023 12:43 PM, Nikunj Kela wrote:
> This change augments smc transport to include support for Qualcomm virtual
> platforms by passing a parameter(capability-id) in the hypervisor call to
> identify which doorbell to assert. This parameter is dynamically generated
> at runtime on the device and insuitable to pass via the devicetree.
>
> The function ID and parameter are stored by firmware in the shmem region.
>
> This has been tested on ARM64 virtual Qualcomm platform.
>
> ---
> v4 -> port the changes into smc.c
>
> v3 -> fix the compilation error reported by the test bot,
>        add support for polling based instances
>
> v2 -> use allOf construct in dtb schema,
>        remove wrappers from mutexes,
>        use architecture independent channel layout
>
> v1 -> original patches
>
> Nikunj Kela (4):
>    firmware: arm_scmi: Add polling support for completion in smc
>    dt-bindings: arm: convert nested if-else construct to allOf
>    dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
>    firmware: arm_scmi: Add qcom hvc/shmem transport support
>
>   .../bindings/firmware/arm,scmi.yaml           | 67 +++++++++++--------
>   drivers/firmware/arm_scmi/Kconfig             | 14 ++++
>   drivers/firmware/arm_scmi/driver.c            |  1 +
>   drivers/firmware/arm_scmi/smc.c               | 62 +++++++++++++++--
>   4 files changed, 110 insertions(+), 34 deletions(-)
>

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-09-18 15:01     ` Nikunj Kela
@ 2023-09-18 15:15       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-09-18 15:15 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> Gentle Ping!
> 

I will take a look at this later this week. That said, I am unable be
gauge the urgency based on you ping here. You have shown the same urgency
last time for a feature that I queued promptly just to know that it was
abandon within couple of days. So I don't want to rush here simply based
on the number of pings here. I need to understand that it is really that
important. For now, I am thinking of skipping even v6.7 just to allow
some time for Qcom to make up its mind and be absolutely sure this is what
they *really* want this time.

-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-09-18 15:15       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-09-18 15:15 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> Gentle Ping!
> 

I will take a look at this later this week. That said, I am unable be
gauge the urgency based on you ping here. You have shown the same urgency
last time for a feature that I queued promptly just to know that it was
abandon within couple of days. So I don't want to rush here simply based
on the number of pings here. I need to understand that it is really that
important. For now, I am thinking of skipping even v6.7 just to allow
some time for Qcom to make up its mind and be absolutely sure this is what
they *really* want this time.

-- 
Regards,
Sudeep

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-09-18 15:15       ` Sudeep Holla
@ 2023-09-18 15:54         ` Brian Masney
  -1 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-09-18 15:54 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Nikunj Kela, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > Gentle Ping!
> > 
> 
> I will take a look at this later this week. That said, I am unable be
> gauge the urgency based on you ping here. You have shown the same urgency
> last time for a feature that I queued promptly just to know that it was
> abandon within couple of days. So I don't want to rush here simply based
> on the number of pings here. I need to understand that it is really that
> important. For now, I am thinking of skipping even v6.7 just to allow
> some time for Qcom to make up its mind and be absolutely sure this is what
> they *really* want this time.

Hi Sudeep,

Red Hat is interested in this patch set. Qualcomm is moving one of their
automotive platforms over to use SCMI and this will appear in that
product.

Brian


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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-09-18 15:54         ` Brian Masney
  0 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-09-18 15:54 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Nikunj Kela, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > Gentle Ping!
> > 
> 
> I will take a look at this later this week. That said, I am unable be
> gauge the urgency based on you ping here. You have shown the same urgency
> last time for a feature that I queued promptly just to know that it was
> abandon within couple of days. So I don't want to rush here simply based
> on the number of pings here. I need to understand that it is really that
> important. For now, I am thinking of skipping even v6.7 just to allow
> some time for Qcom to make up its mind and be absolutely sure this is what
> they *really* want this time.

Hi Sudeep,

Red Hat is interested in this patch set. Qualcomm is moving one of their
automotive platforms over to use SCMI and this will appear in that
product.

Brian


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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-09-18 15:01     ` Nikunj Kela
@ 2023-09-18 20:32       ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-18 20:32 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/09/2023 17:01, Nikunj Kela wrote:
> Gentle Ping!

Whatever is written with exclamation mark is not really gentle.
Especially for second time... and 7 days after posting. 7 days and you ping.

Please relax, and help out by reviewing other patches on the mailing
lists in order to relieve the burden of maintainers and move your
patches higher up the list.

Best regards,
Krzysztof


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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-09-18 20:32       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 186+ messages in thread
From: Krzysztof Kozlowski @ 2023-09-18 20:32 UTC (permalink / raw)
  To: Nikunj Kela, sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On 18/09/2023 17:01, Nikunj Kela wrote:
> Gentle Ping!

Whatever is written with exclamation mark is not really gentle.
Especially for second time... and 7 days after posting. 7 days and you ping.

Please relax, and help out by reviewing other patches on the mailing
lists in order to relieve the burden of maintainers and move your
patches higher up the list.

Best regards,
Krzysztof


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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-09-18 15:54         ` Brian Masney
@ 2023-09-19  8:56           ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-09-19  8:56 UTC (permalink / raw)
  To: Brian Masney
  Cc: Nikunj Kela, cristian.marussi, Sudeep Holla, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, andersson, konrad.dybcio,
	linux-arm-kernel, devicetree, linux-kernel, linux-arm-msm

On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
> On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> > On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > > Gentle Ping!
> > >
> >
> > I will take a look at this later this week. That said, I am unable be
> > gauge the urgency based on you ping here. You have shown the same urgency
> > last time for a feature that I queued promptly just to know that it was
> > abandon within couple of days. So I don't want to rush here simply based
> > on the number of pings here. I need to understand that it is really that
> > important. For now, I am thinking of skipping even v6.7 just to allow
> > some time for Qcom to make up its mind and be absolutely sure this is what
> > they *really* want this time.
>
> Hi Sudeep,
>
> Red Hat is interested in this patch set. Qualcomm is moving one of their
> automotive platforms over to use SCMI and this will appear in that
> product.
>

Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
progress later this week. We can try to target next merge window.

--
Regards,
Sudeep

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-09-19  8:56           ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-09-19  8:56 UTC (permalink / raw)
  To: Brian Masney
  Cc: Nikunj Kela, cristian.marussi, Sudeep Holla, robh+dt,
	krzysztof.kozlowski+dt, conor+dt, andersson, konrad.dybcio,
	linux-arm-kernel, devicetree, linux-kernel, linux-arm-msm

On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
> On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> > On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > > Gentle Ping!
> > >
> >
> > I will take a look at this later this week. That said, I am unable be
> > gauge the urgency based on you ping here. You have shown the same urgency
> > last time for a feature that I queued promptly just to know that it was
> > abandon within couple of days. So I don't want to rush here simply based
> > on the number of pings here. I need to understand that it is really that
> > important. For now, I am thinking of skipping even v6.7 just to allow
> > some time for Qcom to make up its mind and be absolutely sure this is what
> > they *really* want this time.
>
> Hi Sudeep,
>
> Red Hat is interested in this patch set. Qualcomm is moving one of their
> automotive platforms over to use SCMI and this will appear in that
> product.
>

Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
progress later this week. We can try to target next merge window.

--
Regards,
Sudeep

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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-09-19  8:56           ` Sudeep Holla
@ 2023-10-02 17:31             ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 17:31 UTC (permalink / raw)
  To: Sudeep Holla, Brian Masney
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 9/19/2023 1:56 AM, Sudeep Holla wrote:
> On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
>> On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
>>> On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
>>>> Gentle Ping!
>>>>
>>> I will take a look at this later this week. That said, I am unable be
>>> gauge the urgency based on you ping here. You have shown the same urgency
>>> last time for a feature that I queued promptly just to know that it was
>>> abandon within couple of days. So I don't want to rush here simply based
>>> on the number of pings here. I need to understand that it is really that
>>> important. For now, I am thinking of skipping even v6.7 just to allow
>>> some time for Qcom to make up its mind and be absolutely sure this is what
>>> they *really* want this time.
>> Hi Sudeep,
>>
>> Red Hat is interested in this patch set. Qualcomm is moving one of their
>> automotive platforms over to use SCMI and this will appear in that
>> product.
>>
> Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
> progress later this week. We can try to target next merge window.
>
> --
> Regards,
> Sudeep
Gentle Ping...

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-10-02 17:31             ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 17:31 UTC (permalink / raw)
  To: Sudeep Holla, Brian Masney
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 9/19/2023 1:56 AM, Sudeep Holla wrote:
> On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
>> On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
>>> On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
>>>> Gentle Ping!
>>>>
>>> I will take a look at this later this week. That said, I am unable be
>>> gauge the urgency based on you ping here. You have shown the same urgency
>>> last time for a feature that I queued promptly just to know that it was
>>> abandon within couple of days. So I don't want to rush here simply based
>>> on the number of pings here. I need to understand that it is really that
>>> important. For now, I am thinking of skipping even v6.7 just to allow
>>> some time for Qcom to make up its mind and be absolutely sure this is what
>>> they *really* want this time.
>> Hi Sudeep,
>>
>> Red Hat is interested in this patch set. Qualcomm is moving one of their
>> automotive platforms over to use SCMI and this will appear in that
>> product.
>>
> Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
> progress later this week. We can try to target next merge window.
>
> --
> Regards,
> Sudeep
Gentle Ping...

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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-10-02 17:31             ` Nikunj Kela
@ 2023-10-02 17:58               ` Cristian Marussi
  -1 siblings, 0 replies; 186+ messages in thread
From: Cristian Marussi @ 2023-10-02 17:58 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Sudeep Holla, Brian Masney, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 10:31:27AM -0700, Nikunj Kela wrote:
> 
> On 9/19/2023 1:56 AM, Sudeep Holla wrote:
> > On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
> > > On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> > > > On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > > > > Gentle Ping!
> > > > > 
> > > > I will take a look at this later this week. That said, I am unable be
> > > > gauge the urgency based on you ping here. You have shown the same urgency
> > > > last time for a feature that I queued promptly just to know that it was
> > > > abandon within couple of days. So I don't want to rush here simply based
> > > > on the number of pings here. I need to understand that it is really that
> > > > important. For now, I am thinking of skipping even v6.7 just to allow
> > > > some time for Qcom to make up its mind and be absolutely sure this is what
> > > > they *really* want this time.
> > > Hi Sudeep,
> > > 
> > > Red Hat is interested in this patch set. Qualcomm is moving one of their
> > > automotive platforms over to use SCMI and this will appear in that
> > > product.
> > > 
> > Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
> > progress later this week. We can try to target next merge window.
> > 
> > --
> > Regards,
> > Sudeep
> Gentle Ping...

Looking at this tomorrow.

Thanks,
Cristian

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-10-02 17:58               ` Cristian Marussi
  0 siblings, 0 replies; 186+ messages in thread
From: Cristian Marussi @ 2023-10-02 17:58 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Sudeep Holla, Brian Masney, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 10:31:27AM -0700, Nikunj Kela wrote:
> 
> On 9/19/2023 1:56 AM, Sudeep Holla wrote:
> > On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
> > > On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> > > > On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > > > > Gentle Ping!
> > > > > 
> > > > I will take a look at this later this week. That said, I am unable be
> > > > gauge the urgency based on you ping here. You have shown the same urgency
> > > > last time for a feature that I queued promptly just to know that it was
> > > > abandon within couple of days. So I don't want to rush here simply based
> > > > on the number of pings here. I need to understand that it is really that
> > > > important. For now, I am thinking of skipping even v6.7 just to allow
> > > > some time for Qcom to make up its mind and be absolutely sure this is what
> > > > they *really* want this time.
> > > Hi Sudeep,
> > > 
> > > Red Hat is interested in this patch set. Qualcomm is moving one of their
> > > automotive platforms over to use SCMI and this will appear in that
> > > product.
> > > 
> > Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
> > progress later this week. We can try to target next merge window.
> > 
> > --
> > Regards,
> > Sudeep
> Gentle Ping...

Looking at this tomorrow.

Thanks,
Cristian

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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-09-11 19:43     ` Nikunj Kela
@ 2023-10-02 18:18       ` Brian Masney
  -1 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-02 18:18 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> Currently, the return from the smc call assumes the completion of
> the scmi request. However this may not be true in virtual platforms
> that are using hvc doorbell.
> 
> This change adds a Kconfig to enable the polling for the request
> completion.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  drivers/firmware/arm_scmi/Kconfig | 14 ++++++++++++++
>  drivers/firmware/arm_scmi/smc.c   | 15 ++++++++++++++-
>  2 files changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
> index ea0f5083ac47..771d60f8319f 100644
> --- a/drivers/firmware/arm_scmi/Kconfig
> +++ b/drivers/firmware/arm_scmi/Kconfig
> @@ -125,6 +125,20 @@ config ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE
>  	  in atomic context too, at the price of using a number of busy-waiting
>  	  primitives all over instead. If unsure say N.
>  
> +config ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
> +	bool "Enable polling support for SCMI SMC transport"
> +	depends on ARM_SCMI_TRANSPORT_SMC
> +	help
> +	  Enable completion polling support for SCMI SMC based transport.
> +
> +	  If you want the SCMI SMC based transport to poll for the completion,
> +	  answer Y.
> +	  Enabling completion polling might be desired in the absence of the a2p
> +	  irq when the return from smc/hvc call doesn't indicate the completion
> +	  of the SCMI requests. This might be useful for instances used in
> +	  virtual platforms.
> +	  If unsure say N.
> +
>  config ARM_SCMI_TRANSPORT_VIRTIO
>  	bool "SCMI transport based on VirtIO"
>  	depends on VIRTIO=y || VIRTIO=ARM_SCMI_PROTOCOL
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index c193516a254d..0a0b7e401159 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -250,6 +250,16 @@ static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
>  	smc_channel_lock_release(scmi_info);
>  }
>  
> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
> +static bool
> +smc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
> +{
> +	struct scmi_smc *scmi_info = cinfo->transport_info;
> +
> +	return shmem_poll_done(scmi_info->shmem, xfer);
> +}
> +#endif
> +
>  static const struct scmi_transport_ops scmi_smc_ops = {
>  	.chan_available = smc_chan_available,
>  	.chan_setup = smc_chan_setup,
> @@ -257,6 +267,9 @@ static const struct scmi_transport_ops scmi_smc_ops = {
>  	.send_message = smc_send_message,
>  	.mark_txdone = smc_mark_txdone,
>  	.fetch_response = smc_fetch_response,
> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
> +	.poll_done = smc_poll_done,
> +#endif
>  };
>  
>  const struct scmi_desc scmi_smc_desc = {
> @@ -272,6 +285,6 @@ const struct scmi_desc scmi_smc_desc = {
>  	 * for the issued command will be immmediately ready to be fetched
>  	 * from the shared memory area.
>  	 */
> -	.sync_cmds_completed_on_ret = true,
> +	.sync_cmds_completed_on_ret = !IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION),
>  	.atomic_enabled = IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE),

From a Linux distributor viewpoint, it would be nice if this was
determined at runtime, rather than at compile time. We generate a single
kernel binary that's used on systems from multiple hardware
manufacturers. We'd run into an issue if one company required this, but
another one didn't. We may potentially run into this same type of issue
with the upstream arm64 defconfig.

Brian


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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-02 18:18       ` Brian Masney
  0 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-02 18:18 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> Currently, the return from the smc call assumes the completion of
> the scmi request. However this may not be true in virtual platforms
> that are using hvc doorbell.
> 
> This change adds a Kconfig to enable the polling for the request
> completion.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  drivers/firmware/arm_scmi/Kconfig | 14 ++++++++++++++
>  drivers/firmware/arm_scmi/smc.c   | 15 ++++++++++++++-
>  2 files changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
> index ea0f5083ac47..771d60f8319f 100644
> --- a/drivers/firmware/arm_scmi/Kconfig
> +++ b/drivers/firmware/arm_scmi/Kconfig
> @@ -125,6 +125,20 @@ config ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE
>  	  in atomic context too, at the price of using a number of busy-waiting
>  	  primitives all over instead. If unsure say N.
>  
> +config ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
> +	bool "Enable polling support for SCMI SMC transport"
> +	depends on ARM_SCMI_TRANSPORT_SMC
> +	help
> +	  Enable completion polling support for SCMI SMC based transport.
> +
> +	  If you want the SCMI SMC based transport to poll for the completion,
> +	  answer Y.
> +	  Enabling completion polling might be desired in the absence of the a2p
> +	  irq when the return from smc/hvc call doesn't indicate the completion
> +	  of the SCMI requests. This might be useful for instances used in
> +	  virtual platforms.
> +	  If unsure say N.
> +
>  config ARM_SCMI_TRANSPORT_VIRTIO
>  	bool "SCMI transport based on VirtIO"
>  	depends on VIRTIO=y || VIRTIO=ARM_SCMI_PROTOCOL
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index c193516a254d..0a0b7e401159 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -250,6 +250,16 @@ static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
>  	smc_channel_lock_release(scmi_info);
>  }
>  
> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
> +static bool
> +smc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
> +{
> +	struct scmi_smc *scmi_info = cinfo->transport_info;
> +
> +	return shmem_poll_done(scmi_info->shmem, xfer);
> +}
> +#endif
> +
>  static const struct scmi_transport_ops scmi_smc_ops = {
>  	.chan_available = smc_chan_available,
>  	.chan_setup = smc_chan_setup,
> @@ -257,6 +267,9 @@ static const struct scmi_transport_ops scmi_smc_ops = {
>  	.send_message = smc_send_message,
>  	.mark_txdone = smc_mark_txdone,
>  	.fetch_response = smc_fetch_response,
> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
> +	.poll_done = smc_poll_done,
> +#endif
>  };
>  
>  const struct scmi_desc scmi_smc_desc = {
> @@ -272,6 +285,6 @@ const struct scmi_desc scmi_smc_desc = {
>  	 * for the issued command will be immmediately ready to be fetched
>  	 * from the shared memory area.
>  	 */
> -	.sync_cmds_completed_on_ret = true,
> +	.sync_cmds_completed_on_ret = !IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION),
>  	.atomic_enabled = IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE),

From a Linux distributor viewpoint, it would be nice if this was
determined at runtime, rather than at compile time. We generate a single
kernel binary that's used on systems from multiple hardware
manufacturers. We'd run into an issue if one company required this, but
another one didn't. We may potentially run into this same type of issue
with the upstream arm64 defconfig.

Brian


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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-09-11 19:43     ` Nikunj Kela
@ 2023-10-02 18:34       ` Brian Masney
  -1 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-02 18:34 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when HVC call is invoked.
> 
> The function-id & capability-id are allocated by the hypervisor on bootup
> and are stored in the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  drivers/firmware/arm_scmi/driver.c |  1 +
>  drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>  2 files changed, 43 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 87383c05424b..ea344bc6ae49 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>  	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>  	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>  #endif
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>  	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 0a0b7e401159..94ec07fdc14a 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -50,6 +50,9 @@
>   * @func_id: smc/hvc call function id
>   * @param_page: 4K page number of the shmem channel
>   * @param_offset: Offset within the 4K page of the shmem channel
> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> + *	    platforms
> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>   */
>  
>  struct scmi_smc {
> @@ -63,6 +66,8 @@ struct scmi_smc {
>  	u32 func_id;
>  	u32 param_page;
>  	u32 param_offset;
> +	u64 cap_id;
> +	bool qcom_xport;
>  };

[snip]

>  static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	struct resource res;
>  	struct device_node *np;
>  	u32 func_id;
> +	u64 cap_id;
>  	int ret;

[snip]

> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> +#ifdef CONFIG_ARM64
> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> +#else
> +		/* capability-id is 32 bit wide on 32bit machines */
> +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
> +#endif

The 32 bit case is defined as a u64 in two places above.

> +
> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> +		 *     +-------+
> +		 *     |       |
> +		 *     | shmem |
> +		 *     |       |
> +		 *     |       |
> +		 *     +-------+ <-- (size - 16)
> +		 *     | funcId|
> +		 *     +-------+ <-- (size - 8)
> +		 *     | capId |
> +		 *     +-------+ <-- size
> +		 */

Personally I'd add one more space to the right side of the table after
funcId.

> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
> -			     &res);
> +	if (scmi_info->qcom_xport)
> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
> +				  &res);
> +	else
> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
> +				     0, 0, &res);

Does it make sense to call this variable qcom_xport? Would hvc_xport be
a more appropriate name?

Brian


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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-02 18:34       ` Brian Masney
  0 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-02 18:34 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when HVC call is invoked.
> 
> The function-id & capability-id are allocated by the hypervisor on bootup
> and are stored in the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  drivers/firmware/arm_scmi/driver.c |  1 +
>  drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>  2 files changed, 43 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 87383c05424b..ea344bc6ae49 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>  	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>  	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>  #endif
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>  	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 0a0b7e401159..94ec07fdc14a 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -50,6 +50,9 @@
>   * @func_id: smc/hvc call function id
>   * @param_page: 4K page number of the shmem channel
>   * @param_offset: Offset within the 4K page of the shmem channel
> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> + *	    platforms
> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>   */
>  
>  struct scmi_smc {
> @@ -63,6 +66,8 @@ struct scmi_smc {
>  	u32 func_id;
>  	u32 param_page;
>  	u32 param_offset;
> +	u64 cap_id;
> +	bool qcom_xport;
>  };

[snip]

>  static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	struct resource res;
>  	struct device_node *np;
>  	u32 func_id;
> +	u64 cap_id;
>  	int ret;

[snip]

> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> +#ifdef CONFIG_ARM64
> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> +#else
> +		/* capability-id is 32 bit wide on 32bit machines */
> +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
> +#endif

The 32 bit case is defined as a u64 in two places above.

> +
> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> +		 *     +-------+
> +		 *     |       |
> +		 *     | shmem |
> +		 *     |       |
> +		 *     |       |
> +		 *     +-------+ <-- (size - 16)
> +		 *     | funcId|
> +		 *     +-------+ <-- (size - 8)
> +		 *     | capId |
> +		 *     +-------+ <-- size
> +		 */

Personally I'd add one more space to the right side of the table after
funcId.

> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
> -			     &res);
> +	if (scmi_info->qcom_xport)
> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
> +				  &res);
> +	else
> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
> +				     0, 0, &res);

Does it make sense to call this variable qcom_xport? Would hvc_xport be
a more appropriate name?

Brian


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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-10-02 18:18       ` Brian Masney
@ 2023-10-02 18:36         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 18:36 UTC (permalink / raw)
  To: Brian Masney
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/2/2023 11:18 AM, Brian Masney wrote:
> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
>> Currently, the return from the smc call assumes the completion of
>> the scmi request. However this may not be true in virtual platforms
>> that are using hvc doorbell.
>>
>> This change adds a Kconfig to enable the polling for the request
>> completion.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   drivers/firmware/arm_scmi/Kconfig | 14 ++++++++++++++
>>   drivers/firmware/arm_scmi/smc.c   | 15 ++++++++++++++-
>>   2 files changed, 28 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
>> index ea0f5083ac47..771d60f8319f 100644
>> --- a/drivers/firmware/arm_scmi/Kconfig
>> +++ b/drivers/firmware/arm_scmi/Kconfig
>> @@ -125,6 +125,20 @@ config ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE
>>   	  in atomic context too, at the price of using a number of busy-waiting
>>   	  primitives all over instead. If unsure say N.
>>   
>> +config ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
>> +	bool "Enable polling support for SCMI SMC transport"
>> +	depends on ARM_SCMI_TRANSPORT_SMC
>> +	help
>> +	  Enable completion polling support for SCMI SMC based transport.
>> +
>> +	  If you want the SCMI SMC based transport to poll for the completion,
>> +	  answer Y.
>> +	  Enabling completion polling might be desired in the absence of the a2p
>> +	  irq when the return from smc/hvc call doesn't indicate the completion
>> +	  of the SCMI requests. This might be useful for instances used in
>> +	  virtual platforms.
>> +	  If unsure say N.
>> +
>>   config ARM_SCMI_TRANSPORT_VIRTIO
>>   	bool "SCMI transport based on VirtIO"
>>   	depends on VIRTIO=y || VIRTIO=ARM_SCMI_PROTOCOL
>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>> index c193516a254d..0a0b7e401159 100644
>> --- a/drivers/firmware/arm_scmi/smc.c
>> +++ b/drivers/firmware/arm_scmi/smc.c
>> @@ -250,6 +250,16 @@ static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
>>   	smc_channel_lock_release(scmi_info);
>>   }
>>   
>> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
>> +static bool
>> +smc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
>> +{
>> +	struct scmi_smc *scmi_info = cinfo->transport_info;
>> +
>> +	return shmem_poll_done(scmi_info->shmem, xfer);
>> +}
>> +#endif
>> +
>>   static const struct scmi_transport_ops scmi_smc_ops = {
>>   	.chan_available = smc_chan_available,
>>   	.chan_setup = smc_chan_setup,
>> @@ -257,6 +267,9 @@ static const struct scmi_transport_ops scmi_smc_ops = {
>>   	.send_message = smc_send_message,
>>   	.mark_txdone = smc_mark_txdone,
>>   	.fetch_response = smc_fetch_response,
>> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
>> +	.poll_done = smc_poll_done,
>> +#endif
>>   };
>>   
>>   const struct scmi_desc scmi_smc_desc = {
>> @@ -272,6 +285,6 @@ const struct scmi_desc scmi_smc_desc = {
>>   	 * for the issued command will be immmediately ready to be fetched
>>   	 * from the shared memory area.
>>   	 */
>> -	.sync_cmds_completed_on_ret = true,
>> +	.sync_cmds_completed_on_ret = !IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION),
>>   	.atomic_enabled = IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE),
>  From a Linux distributor viewpoint, it would be nice if this was
> determined at runtime, rather than at compile time. We generate a single
> kernel binary that's used on systems from multiple hardware
> manufacturers. We'd run into an issue if one company required this, but
> another one didn't. We may potentially run into this same type of issue
> with the upstream arm64 defconfig.
>
> Brian
This is a transport dependent property. Either the transport supports 
"completion on return of the smc call" or not. For a given platform, 
this will be fixed for all channels. This is similar to

CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE which is also a Kconfig.


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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-02 18:36         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 18:36 UTC (permalink / raw)
  To: Brian Masney
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/2/2023 11:18 AM, Brian Masney wrote:
> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
>> Currently, the return from the smc call assumes the completion of
>> the scmi request. However this may not be true in virtual platforms
>> that are using hvc doorbell.
>>
>> This change adds a Kconfig to enable the polling for the request
>> completion.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   drivers/firmware/arm_scmi/Kconfig | 14 ++++++++++++++
>>   drivers/firmware/arm_scmi/smc.c   | 15 ++++++++++++++-
>>   2 files changed, 28 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
>> index ea0f5083ac47..771d60f8319f 100644
>> --- a/drivers/firmware/arm_scmi/Kconfig
>> +++ b/drivers/firmware/arm_scmi/Kconfig
>> @@ -125,6 +125,20 @@ config ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE
>>   	  in atomic context too, at the price of using a number of busy-waiting
>>   	  primitives all over instead. If unsure say N.
>>   
>> +config ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
>> +	bool "Enable polling support for SCMI SMC transport"
>> +	depends on ARM_SCMI_TRANSPORT_SMC
>> +	help
>> +	  Enable completion polling support for SCMI SMC based transport.
>> +
>> +	  If you want the SCMI SMC based transport to poll for the completion,
>> +	  answer Y.
>> +	  Enabling completion polling might be desired in the absence of the a2p
>> +	  irq when the return from smc/hvc call doesn't indicate the completion
>> +	  of the SCMI requests. This might be useful for instances used in
>> +	  virtual platforms.
>> +	  If unsure say N.
>> +
>>   config ARM_SCMI_TRANSPORT_VIRTIO
>>   	bool "SCMI transport based on VirtIO"
>>   	depends on VIRTIO=y || VIRTIO=ARM_SCMI_PROTOCOL
>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>> index c193516a254d..0a0b7e401159 100644
>> --- a/drivers/firmware/arm_scmi/smc.c
>> +++ b/drivers/firmware/arm_scmi/smc.c
>> @@ -250,6 +250,16 @@ static void smc_mark_txdone(struct scmi_chan_info *cinfo, int ret,
>>   	smc_channel_lock_release(scmi_info);
>>   }
>>   
>> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
>> +static bool
>> +smc_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
>> +{
>> +	struct scmi_smc *scmi_info = cinfo->transport_info;
>> +
>> +	return shmem_poll_done(scmi_info->shmem, xfer);
>> +}
>> +#endif
>> +
>>   static const struct scmi_transport_ops scmi_smc_ops = {
>>   	.chan_available = smc_chan_available,
>>   	.chan_setup = smc_chan_setup,
>> @@ -257,6 +267,9 @@ static const struct scmi_transport_ops scmi_smc_ops = {
>>   	.send_message = smc_send_message,
>>   	.mark_txdone = smc_mark_txdone,
>>   	.fetch_response = smc_fetch_response,
>> +#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION
>> +	.poll_done = smc_poll_done,
>> +#endif
>>   };
>>   
>>   const struct scmi_desc scmi_smc_desc = {
>> @@ -272,6 +285,6 @@ const struct scmi_desc scmi_smc_desc = {
>>   	 * for the issued command will be immmediately ready to be fetched
>>   	 * from the shared memory area.
>>   	 */
>> -	.sync_cmds_completed_on_ret = true,
>> +	.sync_cmds_completed_on_ret = !IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_POLL_COMPLETION),
>>   	.atomic_enabled = IS_ENABLED(CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE),
>  From a Linux distributor viewpoint, it would be nice if this was
> determined at runtime, rather than at compile time. We generate a single
> kernel binary that's used on systems from multiple hardware
> manufacturers. We'd run into an issue if one company required this, but
> another one didn't. We may potentially run into this same type of issue
> with the upstream arm64 defconfig.
>
> Brian
This is a transport dependent property. Either the transport supports 
"completion on return of the smc call" or not. For a given platform, 
this will be fixed for all channels. This is similar to

CONFIG_ARM_SCMI_TRANSPORT_SMC_ATOMIC_ENABLE which is also a Kconfig.


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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-02 18:34       ` Brian Masney
@ 2023-10-02 18:39         ` Brian Masney
  -1 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-02 18:39 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 02:34:06PM -0400, Brian Masney wrote:
> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> > +#ifdef CONFIG_ARM64
> > +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> > +#else
> > +		/* capability-id is 32 bit wide on 32bit machines */
> > +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
> > +#endif
> 
> The 32 bit case is defined as a u64 in two places above.

Also should the 32 bit case be 'size - 4' instead of 'size - 8'? Sorry
I just noticed that as soon as I pressed send.

Brian


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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-02 18:39         ` Brian Masney
  0 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-02 18:39 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 02:34:06PM -0400, Brian Masney wrote:
> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> > +#ifdef CONFIG_ARM64
> > +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> > +#else
> > +		/* capability-id is 32 bit wide on 32bit machines */
> > +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
> > +#endif
> 
> The 32 bit case is defined as a u64 in two places above.

Also should the 32 bit case be 'size - 4' instead of 'size - 8'? Sorry
I just noticed that as soon as I pressed send.

Brian


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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-02 18:34       ` Brian Masney
@ 2023-10-02 18:42         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 18:42 UTC (permalink / raw)
  To: Brian Masney
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/2/2023 11:34 AM, Brian Masney wrote:
> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>> This change adds the support for SCMI message exchange on Qualcomm
>> virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when HVC call is invoked.
>>
>> The function-id & capability-id are allocated by the hypervisor on bootup
>> and are stored in the shmem region by the firmware before starting Linux.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   drivers/firmware/arm_scmi/driver.c |  1 +
>>   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>>   2 files changed, 43 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
>> index 87383c05424b..ea344bc6ae49 100644
>> --- a/drivers/firmware/arm_scmi/driver.c
>> +++ b/drivers/firmware/arm_scmi/driver.c
>> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>>   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>>   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>>   #endif
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>>   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>> index 0a0b7e401159..94ec07fdc14a 100644
>> --- a/drivers/firmware/arm_scmi/smc.c
>> +++ b/drivers/firmware/arm_scmi/smc.c
>> @@ -50,6 +50,9 @@
>>    * @func_id: smc/hvc call function id
>>    * @param_page: 4K page number of the shmem channel
>>    * @param_offset: Offset within the 4K page of the shmem channel
>> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
>> + *	    platforms
>> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>>    */
>>   
>>   struct scmi_smc {
>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>   	u32 func_id;
>>   	u32 param_page;
>>   	u32 param_offset;
>> +	u64 cap_id;
>> +	bool qcom_xport;
>>   };
> [snip]
>
>>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
>> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   	struct resource res;
>>   	struct device_node *np;
>>   	u32 func_id;
>> +	u64 cap_id;
>>   	int ret;
> [snip]
>
>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
>> +#ifdef CONFIG_ARM64
>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
>> +#else
>> +		/* capability-id is 32 bit wide on 32bit machines */
>> +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
>> +#endif
> The 32 bit case is defined as a u64 in two places above.

That is done to make sure the size of the structure in memory is not 
architecture dependent. This was recommended in one of the previous 
version of this patch.


>
>> +
>> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
>> +		 *     +-------+
>> +		 *     |       |
>> +		 *     | shmem |
>> +		 *     |       |
>> +		 *     |       |
>> +		 *     +-------+ <-- (size - 16)
>> +		 *     | funcId|
>> +		 *     +-------+ <-- (size - 8)
>> +		 *     | capId |
>> +		 *     +-------+ <-- size
>> +		 */
> Personally I'd add one more space to the right side of the table after
> funcId.

I could do that but then in 32bit case, you would want one more space 
right after cap-id since it is 32 bit on 32 bit platform. If it helps, I 
can have two lay out one for 32bit and one for 64 bit.


>> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
>> -			     &res);
>> +	if (scmi_info->qcom_xport)
>> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
>> +				  &res);
>> +	else
>> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
>> +				     0, 0, &res);
> Does it make sense to call this variable qcom_xport? Would hvc_xport be
> a more appropriate name?
>
> Brian

Cap-id is QCOM specific ABI parameter not HVC.

>

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-02 18:42         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 18:42 UTC (permalink / raw)
  To: Brian Masney
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/2/2023 11:34 AM, Brian Masney wrote:
> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>> This change adds the support for SCMI message exchange on Qualcomm
>> virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when HVC call is invoked.
>>
>> The function-id & capability-id are allocated by the hypervisor on bootup
>> and are stored in the shmem region by the firmware before starting Linux.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   drivers/firmware/arm_scmi/driver.c |  1 +
>>   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>>   2 files changed, 43 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
>> index 87383c05424b..ea344bc6ae49 100644
>> --- a/drivers/firmware/arm_scmi/driver.c
>> +++ b/drivers/firmware/arm_scmi/driver.c
>> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>>   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>>   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>>   #endif
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>>   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>> index 0a0b7e401159..94ec07fdc14a 100644
>> --- a/drivers/firmware/arm_scmi/smc.c
>> +++ b/drivers/firmware/arm_scmi/smc.c
>> @@ -50,6 +50,9 @@
>>    * @func_id: smc/hvc call function id
>>    * @param_page: 4K page number of the shmem channel
>>    * @param_offset: Offset within the 4K page of the shmem channel
>> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
>> + *	    platforms
>> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>>    */
>>   
>>   struct scmi_smc {
>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>   	u32 func_id;
>>   	u32 param_page;
>>   	u32 param_offset;
>> +	u64 cap_id;
>> +	bool qcom_xport;
>>   };
> [snip]
>
>>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
>> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   	struct resource res;
>>   	struct device_node *np;
>>   	u32 func_id;
>> +	u64 cap_id;
>>   	int ret;
> [snip]
>
>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
>> +#ifdef CONFIG_ARM64
>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
>> +#else
>> +		/* capability-id is 32 bit wide on 32bit machines */
>> +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
>> +#endif
> The 32 bit case is defined as a u64 in two places above.

That is done to make sure the size of the structure in memory is not 
architecture dependent. This was recommended in one of the previous 
version of this patch.


>
>> +
>> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
>> +		 *     +-------+
>> +		 *     |       |
>> +		 *     | shmem |
>> +		 *     |       |
>> +		 *     |       |
>> +		 *     +-------+ <-- (size - 16)
>> +		 *     | funcId|
>> +		 *     +-------+ <-- (size - 8)
>> +		 *     | capId |
>> +		 *     +-------+ <-- size
>> +		 */
> Personally I'd add one more space to the right side of the table after
> funcId.

I could do that but then in 32bit case, you would want one more space 
right after cap-id since it is 32 bit on 32 bit platform. If it helps, I 
can have two lay out one for 32bit and one for 64 bit.


>> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
>> -			     &res);
>> +	if (scmi_info->qcom_xport)
>> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
>> +				  &res);
>> +	else
>> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
>> +				     0, 0, &res);
> Does it make sense to call this variable qcom_xport? Would hvc_xport be
> a more appropriate name?
>
> Brian

Cap-id is QCOM specific ABI parameter not HVC.

>

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-02 18:39         ` Brian Masney
@ 2023-10-02 18:45           ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 18:45 UTC (permalink / raw)
  To: Brian Masney
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/2/2023 11:39 AM, Brian Masney wrote:
> On Mon, Oct 02, 2023 at 02:34:06PM -0400, Brian Masney wrote:
>> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
>>> +#ifdef CONFIG_ARM64
>>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
>>> +#else
>>> +		/* capability-id is 32 bit wide on 32bit machines */
>>> +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
>>> +#endif
>> The 32 bit case is defined as a u64 in two places above.
> Also should the 32 bit case be 'size - 4' instead of 'size - 8'? Sorry
> I just noticed that as soon as I pressed send.
>
> Brian

I already addressed this in one of your previous comments. We are 
keeping last 16 bytes reserved for these two parameters regardless of 
the architecture.



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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-02 18:45           ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-02 18:45 UTC (permalink / raw)
  To: Brian Masney
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/2/2023 11:39 AM, Brian Masney wrote:
> On Mon, Oct 02, 2023 at 02:34:06PM -0400, Brian Masney wrote:
>> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
>>> +#ifdef CONFIG_ARM64
>>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
>>> +#else
>>> +		/* capability-id is 32 bit wide on 32bit machines */
>>> +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
>>> +#endif
>> The 32 bit case is defined as a u64 in two places above.
> Also should the 32 bit case be 'size - 4' instead of 'size - 8'? Sorry
> I just noticed that as soon as I pressed send.
>
> Brian

I already addressed this in one of your previous comments. We are 
keeping last 16 bytes reserved for these two parameters regardless of 
the architecture.



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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-09-11 19:43     ` Nikunj Kela
@ 2023-10-03 10:33       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:33 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, Brian Masney,
	krzysztof.kozlowski+dt, conor+dt, andersson, konrad.dybcio,
	linux-arm-kernel, devicetree, linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> Currently, the return from the smc call assumes the completion of
> the scmi request. However this may not be true in virtual platforms
> that are using hvc doorbell.
>

Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
not a fast call. AFAIK, only TOS use yielding calls. Are you using them
here ? If not, this must complete when the SMC/HVC returns. We added
support for platforms indicating the same via interrupt.

I would like to avoid adding this build config. Why does it require polling ?
Broken firmware ? I would add a compatible for that. Or if the qcom always
wants to do this way, just make it specific to the qcom compatible.

I would avoid a config flag as it needs to be always enabled for single
image and affects other platforms as well. So please drop this change.
If this is absolutely needed, just add additional property which DT
maintainers may not like as it is more like a policy or just make it
compatible specific.

--
Regards,
Sudeep

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-03 10:33       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:33 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, Brian Masney,
	krzysztof.kozlowski+dt, conor+dt, andersson, konrad.dybcio,
	linux-arm-kernel, devicetree, linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> Currently, the return from the smc call assumes the completion of
> the scmi request. However this may not be true in virtual platforms
> that are using hvc doorbell.
>

Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
not a fast call. AFAIK, only TOS use yielding calls. Are you using them
here ? If not, this must complete when the SMC/HVC returns. We added
support for platforms indicating the same via interrupt.

I would like to avoid adding this build config. Why does it require polling ?
Broken firmware ? I would add a compatible for that. Or if the qcom always
wants to do this way, just make it specific to the qcom compatible.

I would avoid a config flag as it needs to be always enabled for single
image and affects other platforms as well. So please drop this change.
If this is absolutely needed, just add additional property which DT
maintainers may not like as it is more like a policy or just make it
compatible specific.

--
Regards,
Sudeep

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

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
  2023-10-02 17:31             ` Nikunj Kela
@ 2023-10-03 10:34               ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:34 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Brian Masney, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 10:31:27AM -0700, Nikunj Kela wrote:
> 
> On 9/19/2023 1:56 AM, Sudeep Holla wrote:
> > On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
> > > On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> > > > On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > > > > Gentle Ping!
> > > > > 
> > > > I will take a look at this later this week. That said, I am unable be
> > > > gauge the urgency based on you ping here. You have shown the same urgency
> > > > last time for a feature that I queued promptly just to know that it was
> > > > abandon within couple of days. So I don't want to rush here simply based
> > > > on the number of pings here. I need to understand that it is really that
> > > > important. For now, I am thinking of skipping even v6.7 just to allow
> > > > some time for Qcom to make up its mind and be absolutely sure this is what
> > > > they *really* want this time.
> > > Hi Sudeep,
> > > 
> > > Red Hat is interested in this patch set. Qualcomm is moving one of their
> > > automotive platforms over to use SCMI and this will appear in that
> > > product.
> > > 
> > Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
> > progress later this week. We can try to target next merge window.
> > 
> > --
> > Regards,
> > Sudeep
> Gentle Ping...

Sorry for the delay, both me and Cristian looking at this now.

-- 
Regards,
Sudeep

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

* Re: [PATCH v4 0/4] Add qcom hvc/shmem transport support
@ 2023-10-03 10:34               ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:34 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Brian Masney, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 10:31:27AM -0700, Nikunj Kela wrote:
> 
> On 9/19/2023 1:56 AM, Sudeep Holla wrote:
> > On Mon, Sep 18, 2023 at 11:54:25AM -0400, Brian Masney wrote:
> > > On Mon, Sep 18, 2023 at 04:15:52PM +0100, Sudeep Holla wrote:
> > > > On Mon, Sep 18, 2023 at 08:01:26AM -0700, Nikunj Kela wrote:
> > > > > Gentle Ping!
> > > > > 
> > > > I will take a look at this later this week. That said, I am unable be
> > > > gauge the urgency based on you ping here. You have shown the same urgency
> > > > last time for a feature that I queued promptly just to know that it was
> > > > abandon within couple of days. So I don't want to rush here simply based
> > > > on the number of pings here. I need to understand that it is really that
> > > > important. For now, I am thinking of skipping even v6.7 just to allow
> > > > some time for Qcom to make up its mind and be absolutely sure this is what
> > > > they *really* want this time.
> > > Hi Sudeep,
> > > 
> > > Red Hat is interested in this patch set. Qualcomm is moving one of their
> > > automotive platforms over to use SCMI and this will appear in that
> > > product.
> > > 
> > Thanks Brian, I trust Redhat over Qcom 😄. I will try to review and enable
> > progress later this week. We can try to target next merge window.
> > 
> > --
> > Regards,
> > Sudeep
> Gentle Ping...

Sorry for the delay, both me and Cristian looking at this now.

-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-09-11 19:43     ` Nikunj Kela
@ 2023-10-03 10:44       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:44 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> index 8d54ea768d38..4090240f45b1 100644
> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> @@ -45,6 +45,9 @@ properties:
>        - description: SCMI compliant firmware with OP-TEE transport
>          items:
>            - const: linaro,scmi-optee
> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> +        items:
> +          - const: qcom,scmi-hvc-shmem

Can it be simply "qcom,scmi-smc" for 2 reasons ?
1. We don't support SMC/HVC without shmem, so what is your argument to add
   '-shmem' in the compatible here ?
2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
  '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
  that HVC is the conduit chosen here based on the compatible. It can be true
  for other reason but I don't want to mislead here by using HVC.
>
>    interrupts:
>      description:
> @@ -320,6 +323,15 @@ allOf:
>        required:
>          - linaro,optee-channel-id
>  
> +  - if:
> +      properties:
> +        compatible:
> +          contains:
> +            const: qcom,scmi-hvc-shmem
> +    then:
> +      required:
> +        - shmem
> +
>  examples:
>    - |
>      firmware {
> -- 
> 2.17.1
> 

-- 
Regards,
Sudeep

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-03 10:44       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:44 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
> transport channel for Qualcomm virtual platforms.
> The compatible mandates a shared memory channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> index 8d54ea768d38..4090240f45b1 100644
> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> @@ -45,6 +45,9 @@ properties:
>        - description: SCMI compliant firmware with OP-TEE transport
>          items:
>            - const: linaro,scmi-optee
> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> +        items:
> +          - const: qcom,scmi-hvc-shmem

Can it be simply "qcom,scmi-smc" for 2 reasons ?
1. We don't support SMC/HVC without shmem, so what is your argument to add
   '-shmem' in the compatible here ?
2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
  '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
  that HVC is the conduit chosen here based on the compatible. It can be true
  for other reason but I don't want to mislead here by using HVC.
>
>    interrupts:
>      description:
> @@ -320,6 +323,15 @@ allOf:
>        required:
>          - linaro,optee-channel-id
>  
> +  - if:
> +      properties:
> +        compatible:
> +          contains:
> +            const: qcom,scmi-hvc-shmem
> +    then:
> +      required:
> +        - shmem
> +
>  examples:
>    - |
>      firmware {
> -- 
> 2.17.1
> 

-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-02 18:42         ` Nikunj Kela
@ 2023-10-03 10:48           ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:48 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Brian Masney, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 11:42:22AM -0700, Nikunj Kela wrote:
> 
> On 10/2/2023 11:34 AM, Brian Masney wrote:
> > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > This change adds the support for SCMI message exchange on Qualcomm
> > > virtual platforms.
> > > 
> > > The hypervisor associates an object-id also known as capability-id
> > > with each hvc doorbell object. The capability-id is used to identify the
> > > doorbell from the VM's capability namespace, similar to a file-descriptor.
> > > 
> > > The hypervisor, in addition to the function-id, expects the capability-id
> > > to be passed in x1 register when HVC call is invoked.
> > > 
> > > The function-id & capability-id are allocated by the hypervisor on bootup
> > > and are stored in the shmem region by the firmware before starting Linux.
> > > 
> > > Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> > > ---
> > >   drivers/firmware/arm_scmi/driver.c |  1 +
> > >   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
> > >   2 files changed, 43 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> > > index 87383c05424b..ea344bc6ae49 100644
> > > --- a/drivers/firmware/arm_scmi/driver.c
> > > +++ b/drivers/firmware/arm_scmi/driver.c
> > > @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
> > >   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
> > >   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> > > +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
> > >   #endif
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
> > >   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> > > index 0a0b7e401159..94ec07fdc14a 100644
> > > --- a/drivers/firmware/arm_scmi/smc.c
> > > +++ b/drivers/firmware/arm_scmi/smc.c
> > > @@ -50,6 +50,9 @@
> > >    * @func_id: smc/hvc call function id
> > >    * @param_page: 4K page number of the shmem channel
> > >    * @param_offset: Offset within the 4K page of the shmem channel
> > > + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> > > + *	    platforms
> > > + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
> > >    */
> > >   struct scmi_smc {
> > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > >   	u32 func_id;
> > >   	u32 param_page;
> > >   	u32 param_offset;
> > > +	u64 cap_id;
> > > +	bool qcom_xport;
> > >   };
> > [snip]
> > 
> > >   static irqreturn_t smc_msg_done_isr(int irq, void *data)
> > > @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
> > >   	struct resource res;
> > >   	struct device_node *np;
> > >   	u32 func_id;
> > > +	u64 cap_id;
> > >   	int ret;
> > [snip]
> > 
> > > +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> > > +#ifdef CONFIG_ARM64
> > > +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> > > +#else
> > > +		/* capability-id is 32 bit wide on 32bit machines */
> > > +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
> > > +#endif
> > The 32 bit case is defined as a u64 in two places above.
> 
> That is done to make sure the size of the structure in memory is not
> architecture dependent. This was recommended in one of the previous version
> of this patch.
> 
> 
> > 
> > > +
> > > +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> > > +		 *     +-------+
> > > +		 *     |       |
> > > +		 *     | shmem |
> > > +		 *     |       |
> > > +		 *     |       |
> > > +		 *     +-------+ <-- (size - 16)
> > > +		 *     | funcId|
> > > +		 *     +-------+ <-- (size - 8)
> > > +		 *     | capId |
> > > +		 *     +-------+ <-- size
> > > +		 */
> > Personally I'd add one more space to the right side of the table after
> > funcId.
> 
> I could do that but then in 32bit case, you would want one more space right
> after cap-id since it is 32 bit on 32 bit platform. If it helps, I can have
> two lay out one for 32bit and one for 64 bit.
>

IIUC, it was just a cosmetic change requested. Instead of this,

		+-------+ <-- (size - 16)
		| funcId|
		+-------+ <-- (size - 8)

something like this, just a extra space after 'funcId' text.

		+--------+ <-- (size - 16)
		| funcId |
		+--------+ <-- (size - 8)
-- 
Regards,
Sudeep

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-03 10:48           ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 10:48 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Brian Masney, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 02, 2023 at 11:42:22AM -0700, Nikunj Kela wrote:
> 
> On 10/2/2023 11:34 AM, Brian Masney wrote:
> > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > This change adds the support for SCMI message exchange on Qualcomm
> > > virtual platforms.
> > > 
> > > The hypervisor associates an object-id also known as capability-id
> > > with each hvc doorbell object. The capability-id is used to identify the
> > > doorbell from the VM's capability namespace, similar to a file-descriptor.
> > > 
> > > The hypervisor, in addition to the function-id, expects the capability-id
> > > to be passed in x1 register when HVC call is invoked.
> > > 
> > > The function-id & capability-id are allocated by the hypervisor on bootup
> > > and are stored in the shmem region by the firmware before starting Linux.
> > > 
> > > Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> > > ---
> > >   drivers/firmware/arm_scmi/driver.c |  1 +
> > >   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
> > >   2 files changed, 43 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> > > index 87383c05424b..ea344bc6ae49 100644
> > > --- a/drivers/firmware/arm_scmi/driver.c
> > > +++ b/drivers/firmware/arm_scmi/driver.c
> > > @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
> > >   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
> > >   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> > > +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
> > >   #endif
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
> > >   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> > > index 0a0b7e401159..94ec07fdc14a 100644
> > > --- a/drivers/firmware/arm_scmi/smc.c
> > > +++ b/drivers/firmware/arm_scmi/smc.c
> > > @@ -50,6 +50,9 @@
> > >    * @func_id: smc/hvc call function id
> > >    * @param_page: 4K page number of the shmem channel
> > >    * @param_offset: Offset within the 4K page of the shmem channel
> > > + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> > > + *	    platforms
> > > + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
> > >    */
> > >   struct scmi_smc {
> > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > >   	u32 func_id;
> > >   	u32 param_page;
> > >   	u32 param_offset;
> > > +	u64 cap_id;
> > > +	bool qcom_xport;
> > >   };
> > [snip]
> > 
> > >   static irqreturn_t smc_msg_done_isr(int irq, void *data)
> > > @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
> > >   	struct resource res;
> > >   	struct device_node *np;
> > >   	u32 func_id;
> > > +	u64 cap_id;
> > >   	int ret;
> > [snip]
> > 
> > > +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> > > +#ifdef CONFIG_ARM64
> > > +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> > > +#else
> > > +		/* capability-id is 32 bit wide on 32bit machines */
> > > +		cap_id = readl((void __iomem *)(scmi_info->shmem) + size - 8);
> > > +#endif
> > The 32 bit case is defined as a u64 in two places above.
> 
> That is done to make sure the size of the structure in memory is not
> architecture dependent. This was recommended in one of the previous version
> of this patch.
> 
> 
> > 
> > > +
> > > +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> > > +		 *     +-------+
> > > +		 *     |       |
> > > +		 *     | shmem |
> > > +		 *     |       |
> > > +		 *     |       |
> > > +		 *     +-------+ <-- (size - 16)
> > > +		 *     | funcId|
> > > +		 *     +-------+ <-- (size - 8)
> > > +		 *     | capId |
> > > +		 *     +-------+ <-- size
> > > +		 */
> > Personally I'd add one more space to the right side of the table after
> > funcId.
> 
> I could do that but then in 32bit case, you would want one more space right
> after cap-id since it is 32 bit on 32 bit platform. If it helps, I can have
> two lay out one for 32bit and one for 64 bit.
>

IIUC, it was just a cosmetic change requested. Instead of this,

		+-------+ <-- (size - 16)
		| funcId|
		+-------+ <-- (size - 8)

something like this, just a extra space after 'funcId' text.

		+--------+ <-- (size - 16)
		| funcId |
		+--------+ <-- (size - 8)
-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-10-03 10:33       ` Sudeep Holla
@ 2023-10-03 10:50         ` Cristian Marussi
  -1 siblings, 0 replies; 186+ messages in thread
From: Cristian Marussi @ 2023-10-03 10:50 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Nikunj Kela, robh+dt, Brian Masney, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 11:33:17AM +0100, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> > Currently, the return from the smc call assumes the completion of
> > the scmi request. However this may not be true in virtual platforms
> > that are using hvc doorbell.
> >
> 
> Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
> not a fast call. AFAIK, only TOS use yielding calls. Are you using them
> here ? If not, this must complete when the SMC/HVC returns. We added
> support for platforms indicating the same via interrupt.
> 
> I would like to avoid adding this build config. Why does it require polling ?
> Broken firmware ? I would add a compatible for that. Or if the qcom always
> wants to do this way, just make it specific to the qcom compatible.
> 
> I would avoid a config flag as it needs to be always enabled for single
> image and affects other platforms as well. So please drop this change.
> If this is absolutely needed, just add additional property which DT
> maintainers may not like as it is more like a policy or just make it
> compatible specific.
> 

Not sure if it could be acceptable or controversial, BUT if there is the
need somehow to support polling for yielding calls (depending on the location
of the SCMI server), should not we think about doing this by just looking up
dynamically the fast-call bits in the provided FID ?

Why we need another binding, given that the FID is currently already
statically provided by the DT itself (via smc-id) or dynamically by the
hypervisor at setup by the changes in this series and the SMCCC spec
clearly defines how the IDs are supposed to be formed for
fast-atomic-calls ?

This way we could enforce the compliance with the SMCCC spec tooo...
...for sure it would require a bit of work in the core, though, given the
const nature of some of this structures.

Thanks,
Cristian

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-03 10:50         ` Cristian Marussi
  0 siblings, 0 replies; 186+ messages in thread
From: Cristian Marussi @ 2023-10-03 10:50 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Nikunj Kela, robh+dt, Brian Masney, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 11:33:17AM +0100, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> > Currently, the return from the smc call assumes the completion of
> > the scmi request. However this may not be true in virtual platforms
> > that are using hvc doorbell.
> >
> 
> Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
> not a fast call. AFAIK, only TOS use yielding calls. Are you using them
> here ? If not, this must complete when the SMC/HVC returns. We added
> support for platforms indicating the same via interrupt.
> 
> I would like to avoid adding this build config. Why does it require polling ?
> Broken firmware ? I would add a compatible for that. Or if the qcom always
> wants to do this way, just make it specific to the qcom compatible.
> 
> I would avoid a config flag as it needs to be always enabled for single
> image and affects other platforms as well. So please drop this change.
> If this is absolutely needed, just add additional property which DT
> maintainers may not like as it is more like a policy or just make it
> compatible specific.
> 

Not sure if it could be acceptable or controversial, BUT if there is the
need somehow to support polling for yielding calls (depending on the location
of the SCMI server), should not we think about doing this by just looking up
dynamically the fast-call bits in the provided FID ?

Why we need another binding, given that the FID is currently already
statically provided by the DT itself (via smc-id) or dynamically by the
hypervisor at setup by the changes in this series and the SMCCC spec
clearly defines how the IDs are supposed to be formed for
fast-atomic-calls ?

This way we could enforce the compliance with the SMCCC spec tooo...
...for sure it would require a bit of work in the core, though, given the
const nature of some of this structures.

Thanks,
Cristian

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-09-11 19:43     ` Nikunj Kela
@ 2023-10-03 11:19       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 11:19 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when HVC call is invoked.
> 
> The function-id & capability-id are allocated by the hypervisor on bootup
> and are stored in the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  drivers/firmware/arm_scmi/driver.c |  1 +
>  drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>  2 files changed, 43 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 87383c05424b..ea344bc6ae49 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>  	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>  	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>  #endif
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>  	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 0a0b7e401159..94ec07fdc14a 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -50,6 +50,9 @@
>   * @func_id: smc/hvc call function id
>   * @param_page: 4K page number of the shmem channel
>   * @param_offset: Offset within the 4K page of the shmem channel
> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> + *	    platforms
> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>   */
>  
>  struct scmi_smc {
> @@ -63,6 +66,8 @@ struct scmi_smc {
>  	u32 func_id;
>  	u32 param_page;
>  	u32 param_offset;
> +	u64 cap_id;

Can it be unsigned long instead so that it just works for both 32 and 64 bit.

> +	bool qcom_xport;

Do we really need this ?

>  };
>  
>  static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	struct resource res;
>  	struct device_node *np;
>  	u32 func_id;
> +	u64 cap_id;

Ditto..

>  	int ret;
>  
>  	if (!tx)
> @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  		return -EADDRNOTAVAIL;
>  	}
>  
> -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> -	if (ret < 0)
> -		return ret;
> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
> +		scmi_info->qcom_xport = true;
> +
> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> +		 *     +-------+
> +		 *     |       |
> +		 *     | shmem |
> +		 *     |       |
> +		 *     |       |
> +		 *     +-------+ <-- (size - 16)
> +		 *     | funcId|
> +		 *     +-------+ <-- (size - 8)
> +		 *     | capId |
> +		 *     +-------+ <-- size
> +		 */
> +
> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);

So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
particular reason ? Just to get both FID and cap ID from shmem ?

> +#ifdef CONFIG_ARM64

I would rather make this arch agnostic using CONFIG_64BIT

> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);

Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
Also scmi_info->shmem is ioremapped just few steps above and you are using
read* here, is that safe ?

> +#else
> +		/* capability-id is 32 bit wide on 32bit machines */
> +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);

Other thought once you move for u64 to unsigned long you need not have
#ifdeffery, just do copy of sizeof(unsigned long)

> +#endif
> +	} else {
> +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> +		if (ret < 0)
> +			return ret;
> +	}
>  
>  	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>  		scmi_info->param_page = SHMEM_PAGE(res.start);
> @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	}
>  
>  	scmi_info->func_id = func_id;
> +	scmi_info->cap_id = cap_id;
>  	scmi_info->cinfo = cinfo;
>  	smc_channel_lock_init(scmi_info);
>  	cinfo->transport_info = scmi_info;
> @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>  	struct arm_smccc_res res;
>  	unsigned long page = scmi_info->param_page;
>  	unsigned long offset = scmi_info->param_offset;
> +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
>  
>  	/*
>  	 * Channel will be released only once response has been
> @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>  
>  	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>  
> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
> -			     &res);
> +	if (scmi_info->qcom_xport)

Just make sure cap_id is set only for qcom and just use that as your flag.
No point in setting always true scmi_info->qcom_xport and using it here.

> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
> +				  &res);
> +	else
> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
> +				     0, 0, &res);
>  
>  	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>  	if (res.a0) {
> -- 
> 2.17.1
> 

-- 
Regards,
Sudeep

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-03 11:19       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-03 11:19 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each hvc doorbell object. The capability-id is used to identify the
> doorbell from the VM's capability namespace, similar to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when HVC call is invoked.
> 
> The function-id & capability-id are allocated by the hypervisor on bootup
> and are stored in the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> ---
>  drivers/firmware/arm_scmi/driver.c |  1 +
>  drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>  2 files changed, 43 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 87383c05424b..ea344bc6ae49 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>  	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>  	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>  #endif
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>  	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 0a0b7e401159..94ec07fdc14a 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -50,6 +50,9 @@
>   * @func_id: smc/hvc call function id
>   * @param_page: 4K page number of the shmem channel
>   * @param_offset: Offset within the 4K page of the shmem channel
> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> + *	    platforms
> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>   */
>  
>  struct scmi_smc {
> @@ -63,6 +66,8 @@ struct scmi_smc {
>  	u32 func_id;
>  	u32 param_page;
>  	u32 param_offset;
> +	u64 cap_id;

Can it be unsigned long instead so that it just works for both 32 and 64 bit.

> +	bool qcom_xport;

Do we really need this ?

>  };
>  
>  static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	struct resource res;
>  	struct device_node *np;
>  	u32 func_id;
> +	u64 cap_id;

Ditto..

>  	int ret;
>  
>  	if (!tx)
> @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  		return -EADDRNOTAVAIL;
>  	}
>  
> -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> -	if (ret < 0)
> -		return ret;
> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
> +		scmi_info->qcom_xport = true;
> +
> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> +		 *     +-------+
> +		 *     |       |
> +		 *     | shmem |
> +		 *     |       |
> +		 *     |       |
> +		 *     +-------+ <-- (size - 16)
> +		 *     | funcId|
> +		 *     +-------+ <-- (size - 8)
> +		 *     | capId |
> +		 *     +-------+ <-- size
> +		 */
> +
> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);

So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
particular reason ? Just to get both FID and cap ID from shmem ?

> +#ifdef CONFIG_ARM64

I would rather make this arch agnostic using CONFIG_64BIT

> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);

Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
Also scmi_info->shmem is ioremapped just few steps above and you are using
read* here, is that safe ?

> +#else
> +		/* capability-id is 32 bit wide on 32bit machines */
> +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);

Other thought once you move for u64 to unsigned long you need not have
#ifdeffery, just do copy of sizeof(unsigned long)

> +#endif
> +	} else {
> +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> +		if (ret < 0)
> +			return ret;
> +	}
>  
>  	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>  		scmi_info->param_page = SHMEM_PAGE(res.start);
> @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	}
>  
>  	scmi_info->func_id = func_id;
> +	scmi_info->cap_id = cap_id;
>  	scmi_info->cinfo = cinfo;
>  	smc_channel_lock_init(scmi_info);
>  	cinfo->transport_info = scmi_info;
> @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>  	struct arm_smccc_res res;
>  	unsigned long page = scmi_info->param_page;
>  	unsigned long offset = scmi_info->param_offset;
> +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
>  
>  	/*
>  	 * Channel will be released only once response has been
> @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>  
>  	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>  
> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
> -			     &res);
> +	if (scmi_info->qcom_xport)

Just make sure cap_id is set only for qcom and just use that as your flag.
No point in setting always true scmi_info->qcom_xport and using it here.

> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
> +				  &res);
> +	else
> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
> +				     0, 0, &res);
>  
>  	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>  	if (res.a0) {
> -- 
> 2.17.1
> 

-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-10-03 10:33       ` Sudeep Holla
@ 2023-10-03 15:53         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-03 15:53 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, Brian Masney, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/3/2023 3:33 AM, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
>> Currently, the return from the smc call assumes the completion of
>> the scmi request. However this may not be true in virtual platforms
>> that are using hvc doorbell.
>>
> Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
> not a fast call. AFAIK, only TOS use yielding calls. Are you using them
> here ? If not, this must complete when the SMC/HVC returns. We added
> support for platforms indicating the same via interrupt.
>
> I would like to avoid adding this build config. Why does it require polling ?
> Broken firmware ? I would add a compatible for that. Or if the qcom always
> wants to do this way, just make it specific to the qcom compatible.
>
> I would avoid a config flag as it needs to be always enabled for single
> image and affects other platforms as well. So please drop this change.
> If this is absolutely needed, just add additional property which DT
> maintainers may not like as it is more like a policy or just make it
> compatible specific.
>
> --
> Regards,
> Sudeep
We are using Fast call FID. We are using completion IRQ for all the scmi 
instances except one where we need to communicate with the server when 
GIC is in suspended state in HLOS. We will need to poll the channel for 
completion in that use case. I am open to suggestions.

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-03 15:53         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-03 15:53 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, Brian Masney, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/3/2023 3:33 AM, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
>> Currently, the return from the smc call assumes the completion of
>> the scmi request. However this may not be true in virtual platforms
>> that are using hvc doorbell.
>>
> Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
> not a fast call. AFAIK, only TOS use yielding calls. Are you using them
> here ? If not, this must complete when the SMC/HVC returns. We added
> support for platforms indicating the same via interrupt.
>
> I would like to avoid adding this build config. Why does it require polling ?
> Broken firmware ? I would add a compatible for that. Or if the qcom always
> wants to do this way, just make it specific to the qcom compatible.
>
> I would avoid a config flag as it needs to be always enabled for single
> image and affects other platforms as well. So please drop this change.
> If this is absolutely needed, just add additional property which DT
> maintainers may not like as it is more like a policy or just make it
> compatible specific.
>
> --
> Regards,
> Sudeep
We are using Fast call FID. We are using completion IRQ for all the scmi 
instances except one where we need to communicate with the server when 
GIC is in suspended state in HLOS. We will need to poll the channel for 
completion in that use case. I am open to suggestions.

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

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-03 10:44       ` Sudeep Holla
@ 2023-10-03 15:59         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-03 15:59 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/3/2023 3:44 AM, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
>> transport channel for Qualcomm virtual platforms.
>> The compatible mandates a shared memory channel.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> ---
>>   .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> index 8d54ea768d38..4090240f45b1 100644
>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> @@ -45,6 +45,9 @@ properties:
>>         - description: SCMI compliant firmware with OP-TEE transport
>>           items:
>>             - const: linaro,scmi-optee
>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>> +        items:
>> +          - const: qcom,scmi-hvc-shmem
> Can it be simply "qcom,scmi-smc" for 2 reasons ?
> 1. We don't support SMC/HVC without shmem, so what is your argument to add
>     '-shmem' in the compatible here ?

In our platforms, there are multiple ways to allocate memory. One is 
preallocated shmem as used here, another is dynamically by hypervisor 
APIs. shmem was to just to indicate it is preallocated.


> 2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
>    '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
>    that HVC is the conduit chosen here based on the compatible. It can be true
>    for other reason but I don't want to mislead here by using HVC.

IUUC, currently, conduit comes from PSCI dt node. We have been using smc 
for PSCI but want to use hvc here. That being said, I am fine to explore 
if we can change PSCI to use hvc too.


>>     interrupts:
>>       description:
>> @@ -320,6 +323,15 @@ allOf:
>>         required:
>>           - linaro,optee-channel-id
>>   
>> +  - if:
>> +      properties:
>> +        compatible:
>> +          contains:
>> +            const: qcom,scmi-hvc-shmem
>> +    then:
>> +      required:
>> +        - shmem
>> +
>>   examples:
>>     - |
>>       firmware {
>> -- 
>> 2.17.1
>>

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-03 15:59         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-03 15:59 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/3/2023 3:44 AM, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
>> transport channel for Qualcomm virtual platforms.
>> The compatible mandates a shared memory channel.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> ---
>>   .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> index 8d54ea768d38..4090240f45b1 100644
>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>> @@ -45,6 +45,9 @@ properties:
>>         - description: SCMI compliant firmware with OP-TEE transport
>>           items:
>>             - const: linaro,scmi-optee
>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>> +        items:
>> +          - const: qcom,scmi-hvc-shmem
> Can it be simply "qcom,scmi-smc" for 2 reasons ?
> 1. We don't support SMC/HVC without shmem, so what is your argument to add
>     '-shmem' in the compatible here ?

In our platforms, there are multiple ways to allocate memory. One is 
preallocated shmem as used here, another is dynamically by hypervisor 
APIs. shmem was to just to indicate it is preallocated.


> 2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
>    '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
>    that HVC is the conduit chosen here based on the compatible. It can be true
>    for other reason but I don't want to mislead here by using HVC.

IUUC, currently, conduit comes from PSCI dt node. We have been using smc 
for PSCI but want to use hvc here. That being said, I am fine to explore 
if we can change PSCI to use hvc too.


>>     interrupts:
>>       description:
>> @@ -320,6 +323,15 @@ allOf:
>>         required:
>>           - linaro,optee-channel-id
>>   
>> +  - if:
>> +      properties:
>> +        compatible:
>> +          contains:
>> +            const: qcom,scmi-hvc-shmem
>> +    then:
>> +      required:
>> +        - shmem
>> +
>>   examples:
>>     - |
>>       firmware {
>> -- 
>> 2.17.1
>>

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-03 11:19       ` Sudeep Holla
@ 2023-10-03 16:16         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-03 16:16 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>> This change adds the support for SCMI message exchange on Qualcomm
>> virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when HVC call is invoked.
>>
>> The function-id & capability-id are allocated by the hypervisor on bootup
>> and are stored in the shmem region by the firmware before starting Linux.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   drivers/firmware/arm_scmi/driver.c |  1 +
>>   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>>   2 files changed, 43 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
>> index 87383c05424b..ea344bc6ae49 100644
>> --- a/drivers/firmware/arm_scmi/driver.c
>> +++ b/drivers/firmware/arm_scmi/driver.c
>> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>>   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>>   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>>   #endif
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>>   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>> index 0a0b7e401159..94ec07fdc14a 100644
>> --- a/drivers/firmware/arm_scmi/smc.c
>> +++ b/drivers/firmware/arm_scmi/smc.c
>> @@ -50,6 +50,9 @@
>>    * @func_id: smc/hvc call function id
>>    * @param_page: 4K page number of the shmem channel
>>    * @param_offset: Offset within the 4K page of the shmem channel
>> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
>> + *	    platforms
>> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>>    */
>>   
>>   struct scmi_smc {
>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>   	u32 func_id;
>>   	u32 param_page;
>>   	u32 param_offset;
>> +	u64 cap_id;
> Can it be unsigned long instead so that it just works for both 32 and 64 bit.

My first version of this patch was ulong but Bjorn suggested to make 
this structure size fixed i.e. architecture independent. Hence changed 
it to u64. If you are ok with ulong, I can change it back to ulong.


>
>> +	bool qcom_xport;
> Do we really need this ?

Not if we initialize it with a negative value since 0 is a valid value 
for cap-id.


>
>>   };
>>   
>>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
>> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   	struct resource res;
>>   	struct device_node *np;
>>   	u32 func_id;
>> +	u64 cap_id;
> Ditto..

Answered in earlier comment.


>>   	int ret;
>>   
>>   	if (!tx)
>> @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   		return -EADDRNOTAVAIL;
>>   	}
>>   
>> -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>> -	if (ret < 0)
>> -		return ret;
>> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
>> +		scmi_info->qcom_xport = true;
>> +
>> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
>> +		 *     +-------+
>> +		 *     |       |
>> +		 *     | shmem |
>> +		 *     |       |
>> +		 *     |       |
>> +		 *     +-------+ <-- (size - 16)
>> +		 *     | funcId|
>> +		 *     +-------+ <-- (size - 8)
>> +		 *     | capId |
>> +		 *     +-------+ <-- size
>> +		 */
>> +
>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
> particular reason ? Just to get both FID and cap ID from shmem ?

I could use smc-id binding for func-id, it's just two parameters will 
come from two different places so thought of keeping everything at one 
place to maintain consistency.  Since DT can't take cap-id, I decided to 
move func-id. I am fine if you want me to use smc-id binding.


>> +#ifdef CONFIG_ARM64
> I would rather make this arch agnostic using CONFIG_64BIT
ok.
>
>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
> Also scmi_info->shmem is ioremapped just few steps above and you are using
> read* here, is that safe ?

I saw some compilation warnings without __iomem. I will use ioread* API 
instead of read*.


>
>> +#else
>> +		/* capability-id is 32 bit wide on 32bit machines */
>> +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);
> Other thought once you move for u64 to unsigned long you need not have
> #ifdeffery, just do copy of sizeof(unsigned long)
Right, my first version was like that only.
>
>> +#endif
>> +	} else {
>> +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>> +		if (ret < 0)
>> +			return ret;
>> +	}
>>   
>>   	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>>   		scmi_info->param_page = SHMEM_PAGE(res.start);
>> @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   	}
>>   
>>   	scmi_info->func_id = func_id;
>> +	scmi_info->cap_id = cap_id;
>>   	scmi_info->cinfo = cinfo;
>>   	smc_channel_lock_init(scmi_info);
>>   	cinfo->transport_info = scmi_info;
>> @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>   	struct arm_smccc_res res;
>>   	unsigned long page = scmi_info->param_page;
>>   	unsigned long offset = scmi_info->param_offset;
>> +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
>>   
>>   	/*
>>   	 * Channel will be released only once response has been
>> @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>   
>>   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>>   
>> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
>> -			     &res);
>> +	if (scmi_info->qcom_xport)
> Just make sure cap_id is set only for qcom and just use that as your flag.
> No point in setting always true scmi_info->qcom_xport and using it here.
ok, I can remove that. Though 0 is a valid value for cap-id so will have 
to init cap-id with a negative value.
>
>> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
>> +				  &res);
>> +	else
>> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
>> +				     0, 0, &res);
>>   
>>   	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>>   	if (res.a0) {
>> -- 
>> 2.17.1
>>

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-03 16:16         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-03 16:16 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>> This change adds the support for SCMI message exchange on Qualcomm
>> virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each hvc doorbell object. The capability-id is used to identify the
>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when HVC call is invoked.
>>
>> The function-id & capability-id are allocated by the hypervisor on bootup
>> and are stored in the shmem region by the firmware before starting Linux.
>>
>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>> ---
>>   drivers/firmware/arm_scmi/driver.c |  1 +
>>   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>>   2 files changed, 43 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
>> index 87383c05424b..ea344bc6ae49 100644
>> --- a/drivers/firmware/arm_scmi/driver.c
>> +++ b/drivers/firmware/arm_scmi/driver.c
>> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>>   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>>   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>>   #endif
>>   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>>   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>> index 0a0b7e401159..94ec07fdc14a 100644
>> --- a/drivers/firmware/arm_scmi/smc.c
>> +++ b/drivers/firmware/arm_scmi/smc.c
>> @@ -50,6 +50,9 @@
>>    * @func_id: smc/hvc call function id
>>    * @param_page: 4K page number of the shmem channel
>>    * @param_offset: Offset within the 4K page of the shmem channel
>> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
>> + *	    platforms
>> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>>    */
>>   
>>   struct scmi_smc {
>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>   	u32 func_id;
>>   	u32 param_page;
>>   	u32 param_offset;
>> +	u64 cap_id;
> Can it be unsigned long instead so that it just works for both 32 and 64 bit.

My first version of this patch was ulong but Bjorn suggested to make 
this structure size fixed i.e. architecture independent. Hence changed 
it to u64. If you are ok with ulong, I can change it back to ulong.


>
>> +	bool qcom_xport;
> Do we really need this ?

Not if we initialize it with a negative value since 0 is a valid value 
for cap-id.


>
>>   };
>>   
>>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
>> @@ -129,6 +134,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   	struct resource res;
>>   	struct device_node *np;
>>   	u32 func_id;
>> +	u64 cap_id;
> Ditto..

Answered in earlier comment.


>>   	int ret;
>>   
>>   	if (!tx)
>> @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   		return -EADDRNOTAVAIL;
>>   	}
>>   
>> -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>> -	if (ret < 0)
>> -		return ret;
>> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
>> +		scmi_info->qcom_xport = true;
>> +
>> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
>> +		 *     +-------+
>> +		 *     |       |
>> +		 *     | shmem |
>> +		 *     |       |
>> +		 *     |       |
>> +		 *     +-------+ <-- (size - 16)
>> +		 *     | funcId|
>> +		 *     +-------+ <-- (size - 8)
>> +		 *     | capId |
>> +		 *     +-------+ <-- size
>> +		 */
>> +
>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
> particular reason ? Just to get both FID and cap ID from shmem ?

I could use smc-id binding for func-id, it's just two parameters will 
come from two different places so thought of keeping everything at one 
place to maintain consistency.  Since DT can't take cap-id, I decided to 
move func-id. I am fine if you want me to use smc-id binding.


>> +#ifdef CONFIG_ARM64
> I would rather make this arch agnostic using CONFIG_64BIT
ok.
>
>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
> Also scmi_info->shmem is ioremapped just few steps above and you are using
> read* here, is that safe ?

I saw some compilation warnings without __iomem. I will use ioread* API 
instead of read*.


>
>> +#else
>> +		/* capability-id is 32 bit wide on 32bit machines */
>> +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);
> Other thought once you move for u64 to unsigned long you need not have
> #ifdeffery, just do copy of sizeof(unsigned long)
Right, my first version was like that only.
>
>> +#endif
>> +	} else {
>> +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>> +		if (ret < 0)
>> +			return ret;
>> +	}
>>   
>>   	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>>   		scmi_info->param_page = SHMEM_PAGE(res.start);
>> @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>   	}
>>   
>>   	scmi_info->func_id = func_id;
>> +	scmi_info->cap_id = cap_id;
>>   	scmi_info->cinfo = cinfo;
>>   	smc_channel_lock_init(scmi_info);
>>   	cinfo->transport_info = scmi_info;
>> @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>   	struct arm_smccc_res res;
>>   	unsigned long page = scmi_info->param_page;
>>   	unsigned long offset = scmi_info->param_offset;
>> +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
>>   
>>   	/*
>>   	 * Channel will be released only once response has been
>> @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>   
>>   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>>   
>> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
>> -			     &res);
>> +	if (scmi_info->qcom_xport)
> Just make sure cap_id is set only for qcom and just use that as your flag.
> No point in setting always true scmi_info->qcom_xport and using it here.
ok, I can remove that. Though 0 is a valid value for cap-id so will have 
to init cap-id with a negative value.
>
>> +		arm_smccc_1_1_hvc(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0, 0,
>> +				  &res);
>> +	else
>> +		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
>> +				     0, 0, &res);
>>   
>>   	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>>   	if (res.a0) {
>> -- 
>> 2.17.1
>>

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

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-03 15:59         ` Nikunj Kela
@ 2023-10-04 15:53           ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-04 15:53 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	Sudeep Holla, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 08:59:45AM -0700, Nikunj Kela wrote:
> 
> On 10/3/2023 3:44 AM, Sudeep Holla wrote:
> > On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
> > > Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
> > > transport channel for Qualcomm virtual platforms.
> > > The compatible mandates a shared memory channel.
> > > 
> > > Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> > > Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > > ---
> > >   .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
> > >   1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> > > index 8d54ea768d38..4090240f45b1 100644
> > > --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> > > +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> > > @@ -45,6 +45,9 @@ properties:
> > >         - description: SCMI compliant firmware with OP-TEE transport
> > >           items:
> > >             - const: linaro,scmi-optee
> > > +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> > > +        items:
> > > +          - const: qcom,scmi-hvc-shmem
> > Can it be simply "qcom,scmi-smc" for 2 reasons ?
> > 1. We don't support SMC/HVC without shmem, so what is your argument to add
> >     '-shmem' in the compatible here ?
> 
> In our platforms, there are multiple ways to allocate memory. One is
> preallocated shmem as used here, another is dynamically by hypervisor APIs.
> shmem was to just to indicate it is preallocated.
>

Let us keep it without shmem. If it is dynamically allocated, you must not
need another compatible as you can check it at the runtime.

> 
> > 2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
> >    '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
> >    that HVC is the conduit chosen here based on the compatible. It can be true
> >    for other reason but I don't want to mislead here by using HVC.
> 
> IUUC, currently, conduit comes from PSCI dt node. We have been using smc for
> PSCI but want to use hvc here. That being said, I am fine to explore if we
> can change PSCI to use hvc too.
>

I think only OPTEE has explicit conduit other than PSCI and it is continued
for legacy/compatibility reasons IIUC and IIRC. Anything else depends on
the conduit used by PSCI to be consistent. So yes you need to use what the
PSCI conduit is and you don't need the extra information from the DT either
as new property or in the compatible.

-- 
Regards,
Sudeep

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-04 15:53           ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-04 15:53 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	Sudeep Holla, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 08:59:45AM -0700, Nikunj Kela wrote:
> 
> On 10/3/2023 3:44 AM, Sudeep Holla wrote:
> > On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
> > > Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
> > > transport channel for Qualcomm virtual platforms.
> > > The compatible mandates a shared memory channel.
> > > 
> > > Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> > > Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > > ---
> > >   .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
> > >   1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> > > index 8d54ea768d38..4090240f45b1 100644
> > > --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> > > +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
> > > @@ -45,6 +45,9 @@ properties:
> > >         - description: SCMI compliant firmware with OP-TEE transport
> > >           items:
> > >             - const: linaro,scmi-optee
> > > +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
> > > +        items:
> > > +          - const: qcom,scmi-hvc-shmem
> > Can it be simply "qcom,scmi-smc" for 2 reasons ?
> > 1. We don't support SMC/HVC without shmem, so what is your argument to add
> >     '-shmem' in the compatible here ?
> 
> In our platforms, there are multiple ways to allocate memory. One is
> preallocated shmem as used here, another is dynamically by hypervisor APIs.
> shmem was to just to indicate it is preallocated.
>

Let us keep it without shmem. If it is dynamically allocated, you must not
need another compatible as you can check it at the runtime.

> 
> > 2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
> >    '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
> >    that HVC is the conduit chosen here based on the compatible. It can be true
> >    for other reason but I don't want to mislead here by using HVC.
> 
> IUUC, currently, conduit comes from PSCI dt node. We have been using smc for
> PSCI but want to use hvc here. That being said, I am fine to explore if we
> can change PSCI to use hvc too.
>

I think only OPTEE has explicit conduit other than PSCI and it is continued
for legacy/compatibility reasons IIUC and IIRC. Anything else depends on
the conduit used by PSCI to be consistent. So yes you need to use what the
PSCI conduit is and you don't need the extra information from the DT either
as new property or in the compatible.

-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-03 16:16         ` Nikunj Kela
@ 2023-10-04 16:06           ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-04 16:06 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
> 
> On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > This change adds the support for SCMI message exchange on Qualcomm
> > > virtual platforms.
> > > 
> > > The hypervisor associates an object-id also known as capability-id
> > > with each hvc doorbell object. The capability-id is used to identify the
> > > doorbell from the VM's capability namespace, similar to a file-descriptor.
> > > 
> > > The hypervisor, in addition to the function-id, expects the capability-id
> > > to be passed in x1 register when HVC call is invoked.
> > > 
> > > The function-id & capability-id are allocated by the hypervisor on bootup
> > > and are stored in the shmem region by the firmware before starting Linux.
> > > 
> > > Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> > > ---
> > >   drivers/firmware/arm_scmi/driver.c |  1 +
> > >   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
> > >   2 files changed, 43 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> > > index 87383c05424b..ea344bc6ae49 100644
> > > --- a/drivers/firmware/arm_scmi/driver.c
> > > +++ b/drivers/firmware/arm_scmi/driver.c
> > > @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
> > >   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
> > >   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> > > +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
> > >   #endif
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
> > >   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> > > index 0a0b7e401159..94ec07fdc14a 100644
> > > --- a/drivers/firmware/arm_scmi/smc.c
> > > +++ b/drivers/firmware/arm_scmi/smc.c
> > > @@ -50,6 +50,9 @@
> > >    * @func_id: smc/hvc call function id
> > >    * @param_page: 4K page number of the shmem channel
> > >    * @param_offset: Offset within the 4K page of the shmem channel
> > > + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> > > + *	    platforms
> > > + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
> > >    */
> > >   struct scmi_smc {
> > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > >   	u32 func_id;
> > >   	u32 param_page;
> > >   	u32 param_offset;
> > > +	u64 cap_id;
> > Can it be unsigned long instead so that it just works for both 32 and 64 bit.
> 
> My first version of this patch was ulong but Bjorn suggested to make this
> structure size fixed i.e. architecture independent. Hence changed it to u64.
> If you are ok with ulong, I can change it back to ulong.
>

SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
with that. I haven't followed Bjorn suggestions/comments though.

> 
> > 
> > > +	bool qcom_xport;
> > Do we really need this ?
> 
> Not if we initialize it with a negative value since 0 is a valid value for
> cap-id.
>

Fine with negative value(-EINVAL may be).

> > >   	int ret;
> > >   	if (!tx)
> > > @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
> > >   		return -EADDRNOTAVAIL;
> > >   	}
> > > -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> > > -	if (ret < 0)
> > > -		return ret;
> > > +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
> > > +		scmi_info->qcom_xport = true;
> > > +
> > > +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> > > +		 *     +-------+
> > > +		 *     |       |
> > > +		 *     | shmem |
> > > +		 *     |       |
> > > +		 *     |       |
> > > +		 *     +-------+ <-- (size - 16)
> > > +		 *     | funcId|
> > > +		 *     +-------+ <-- (size - 8)
> > > +		 *     | capId |
> > > +		 *     +-------+ <-- size
> > > +		 */
> > > +
> > > +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> > So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
> > particular reason ? Just to get both FID and cap ID from shmem ?
>

I am fine either way. If you use from DT(via arm,smc-id), then "qcom,scmi"
can be just addition compatible that expects you to read cap-id from the
shmem. May need adjustment in the binding as you allow both
"qcom,scmi-smc", "arm,scmi-smc". I will leave the details to you.

> I could use smc-id binding for func-id, it's just two parameters will come
> from two different places so thought of keeping everything at one place to
> maintain consistency.  Since DT can't take cap-id, I decided to move
> func-id. I am fine if you want me to use smc-id binding.
>

Up to you. If you want to make "qcom,scmi-smc" and "arm,scmi-smc"
compatible in way in that way or you can keep it incompatible as you have
proposed in this patch set.

> 
> > > +#ifdef CONFIG_ARM64
> > I would rather make this arch agnostic using CONFIG_64BIT
> ok.
> > 
> > > +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> > Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
> > Also scmi_info->shmem is ioremapped just few steps above and you are using
> > read* here, is that safe ?
> 
> I saw some compilation warnings without __iomem. I will use ioread* API
> instead of read*.
>

That was the clue that you were using __iomem with read* calls IMO.

> 
> > 
> > > +#else
> > > +		/* capability-id is 32 bit wide on 32bit machines */
> > > +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);
> > Other thought once you move for u64 to unsigned long you need not have
> > #ifdeffery, just do copy of sizeof(unsigned long)
> Right, my first version was like that only.

OK

> > 
> > > +#endif
> > > +	} else {
> > > +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> > > +		if (ret < 0)
> > > +			return ret;
> > > +	}
> > >   	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
> > >   		scmi_info->param_page = SHMEM_PAGE(res.start);
> > > @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
> > >   	}
> > >   	scmi_info->func_id = func_id;
> > > +	scmi_info->cap_id = cap_id;
> > >   	scmi_info->cinfo = cinfo;
> > >   	smc_channel_lock_init(scmi_info);
> > >   	cinfo->transport_info = scmi_info;
> > > @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
> > >   	struct arm_smccc_res res;
> > >   	unsigned long page = scmi_info->param_page;
> > >   	unsigned long offset = scmi_info->param_offset;
> > > +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
> > >   	/*
> > >   	 * Channel will be released only once response has been
> > > @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
> > >   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
> > > -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
> > > -			     &res);
> > > +	if (scmi_info->qcom_xport)
> > Just make sure cap_id is set only for qcom and just use that as your flag.
> > No point in setting always true scmi_info->qcom_xport and using it here.
> ok, I can remove that. Though 0 is a valid value for cap-id so will have to
> init cap-id with a negative value.

Yes as mentioned above.

-- 
Regards,
Sudeep

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-04 16:06           ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-04 16:06 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
> 
> On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > This change adds the support for SCMI message exchange on Qualcomm
> > > virtual platforms.
> > > 
> > > The hypervisor associates an object-id also known as capability-id
> > > with each hvc doorbell object. The capability-id is used to identify the
> > > doorbell from the VM's capability namespace, similar to a file-descriptor.
> > > 
> > > The hypervisor, in addition to the function-id, expects the capability-id
> > > to be passed in x1 register when HVC call is invoked.
> > > 
> > > The function-id & capability-id are allocated by the hypervisor on bootup
> > > and are stored in the shmem region by the firmware before starting Linux.
> > > 
> > > Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> > > ---
> > >   drivers/firmware/arm_scmi/driver.c |  1 +
> > >   drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
> > >   2 files changed, 43 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> > > index 87383c05424b..ea344bc6ae49 100644
> > > --- a/drivers/firmware/arm_scmi/driver.c
> > > +++ b/drivers/firmware/arm_scmi/driver.c
> > > @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
> > >   	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
> > >   	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> > > +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
> > >   #endif
> > >   #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
> > >   	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> > > index 0a0b7e401159..94ec07fdc14a 100644
> > > --- a/drivers/firmware/arm_scmi/smc.c
> > > +++ b/drivers/firmware/arm_scmi/smc.c
> > > @@ -50,6 +50,9 @@
> > >    * @func_id: smc/hvc call function id
> > >    * @param_page: 4K page number of the shmem channel
> > >    * @param_offset: Offset within the 4K page of the shmem channel
> > > + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
> > > + *	    platforms
> > > + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
> > >    */
> > >   struct scmi_smc {
> > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > >   	u32 func_id;
> > >   	u32 param_page;
> > >   	u32 param_offset;
> > > +	u64 cap_id;
> > Can it be unsigned long instead so that it just works for both 32 and 64 bit.
> 
> My first version of this patch was ulong but Bjorn suggested to make this
> structure size fixed i.e. architecture independent. Hence changed it to u64.
> If you are ok with ulong, I can change it back to ulong.
>

SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
with that. I haven't followed Bjorn suggestions/comments though.

> 
> > 
> > > +	bool qcom_xport;
> > Do we really need this ?
> 
> Not if we initialize it with a negative value since 0 is a valid value for
> cap-id.
>

Fine with negative value(-EINVAL may be).

> > >   	int ret;
> > >   	if (!tx)
> > > @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
> > >   		return -EADDRNOTAVAIL;
> > >   	}
> > > -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> > > -	if (ret < 0)
> > > -		return ret;
> > > +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
> > > +		scmi_info->qcom_xport = true;
> > > +
> > > +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
> > > +		 *     +-------+
> > > +		 *     |       |
> > > +		 *     | shmem |
> > > +		 *     |       |
> > > +		 *     |       |
> > > +		 *     +-------+ <-- (size - 16)
> > > +		 *     | funcId|
> > > +		 *     +-------+ <-- (size - 8)
> > > +		 *     | capId |
> > > +		 *     +-------+ <-- size
> > > +		 */
> > > +
> > > +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
> > So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
> > particular reason ? Just to get both FID and cap ID from shmem ?
>

I am fine either way. If you use from DT(via arm,smc-id), then "qcom,scmi"
can be just addition compatible that expects you to read cap-id from the
shmem. May need adjustment in the binding as you allow both
"qcom,scmi-smc", "arm,scmi-smc". I will leave the details to you.

> I could use smc-id binding for func-id, it's just two parameters will come
> from two different places so thought of keeping everything at one place to
> maintain consistency.  Since DT can't take cap-id, I decided to move
> func-id. I am fine if you want me to use smc-id binding.
>

Up to you. If you want to make "qcom,scmi-smc" and "arm,scmi-smc"
compatible in way in that way or you can keep it incompatible as you have
proposed in this patch set.

> 
> > > +#ifdef CONFIG_ARM64
> > I would rather make this arch agnostic using CONFIG_64BIT
> ok.
> > 
> > > +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
> > Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
> > Also scmi_info->shmem is ioremapped just few steps above and you are using
> > read* here, is that safe ?
> 
> I saw some compilation warnings without __iomem. I will use ioread* API
> instead of read*.
>

That was the clue that you were using __iomem with read* calls IMO.

> 
> > 
> > > +#else
> > > +		/* capability-id is 32 bit wide on 32bit machines */
> > > +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);
> > Other thought once you move for u64 to unsigned long you need not have
> > #ifdeffery, just do copy of sizeof(unsigned long)
> Right, my first version was like that only.

OK

> > 
> > > +#endif
> > > +	} else {
> > > +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
> > > +		if (ret < 0)
> > > +			return ret;
> > > +	}
> > >   	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
> > >   		scmi_info->param_page = SHMEM_PAGE(res.start);
> > > @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
> > >   	}
> > >   	scmi_info->func_id = func_id;
> > > +	scmi_info->cap_id = cap_id;
> > >   	scmi_info->cinfo = cinfo;
> > >   	smc_channel_lock_init(scmi_info);
> > >   	cinfo->transport_info = scmi_info;
> > > @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
> > >   	struct arm_smccc_res res;
> > >   	unsigned long page = scmi_info->param_page;
> > >   	unsigned long offset = scmi_info->param_offset;
> > > +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
> > >   	/*
> > >   	 * Channel will be released only once response has been
> > > @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
> > >   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
> > > -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
> > > -			     &res);
> > > +	if (scmi_info->qcom_xport)
> > Just make sure cap_id is set only for qcom and just use that as your flag.
> > No point in setting always true scmi_info->qcom_xport and using it here.
> ok, I can remove that. Though 0 is a valid value for cap-id so will have to
> init cap-id with a negative value.

Yes as mentioned above.

-- 
Regards,
Sudeep

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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-10-03 15:53         ` Nikunj Kela
@ 2023-10-04 16:11           ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-04 16:11 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, Brian Masney,
	krzysztof.kozlowski+dt, conor+dt, andersson, konrad.dybcio,
	linux-arm-kernel, devicetree, linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 08:53:20AM -0700, Nikunj Kela wrote:
> 
> On 10/3/2023 3:33 AM, Sudeep Holla wrote:
> > On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> > > Currently, the return from the smc call assumes the completion of
> > > the scmi request. However this may not be true in virtual platforms
> > > that are using hvc doorbell.
> > > 
> > Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
> > not a fast call. AFAIK, only TOS use yielding calls. Are you using them
> > here ? If not, this must complete when the SMC/HVC returns. We added
> > support for platforms indicating the same via interrupt.
> > 
> > I would like to avoid adding this build config. Why does it require polling ?
> > Broken firmware ? I would add a compatible for that. Or if the qcom always
> > wants to do this way, just make it specific to the qcom compatible.
> > 
> > I would avoid a config flag as it needs to be always enabled for single
> > image and affects other platforms as well. So please drop this change.
> > If this is absolutely needed, just add additional property which DT
> > maintainers may not like as it is more like a policy or just make it
> > compatible specific.
> > 
> > --
> > Regards,
> > Sudeep
> We are using Fast call FID. We are using completion IRQ for all the scmi
> instances except one where we need to communicate with the server when GIC
> is in suspended state in HLOS. We will need to poll the channel for
> completion in that use case. I am open to suggestions.

IIUC, for the sake of that one corner case, you have added the polling
Kconfig and will be enabled for all the case and even on other platforms
in a single Image. I think we could be something better, no ?

Please share details on that one corner case.
Is it in the scmi drivers already ? If so, specifics please.
If no, again provide details on how you plan to use. We do have ways
to make a polling call, but haven't mixed it with interrupt based calls
for a reason, but we can revisit if it makes sense.

--
Regards,
Sudeep

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-04 16:11           ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-04 16:11 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, Brian Masney,
	krzysztof.kozlowski+dt, conor+dt, andersson, konrad.dybcio,
	linux-arm-kernel, devicetree, linux-kernel, linux-arm-msm

On Tue, Oct 03, 2023 at 08:53:20AM -0700, Nikunj Kela wrote:
> 
> On 10/3/2023 3:33 AM, Sudeep Holla wrote:
> > On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
> > > Currently, the return from the smc call assumes the completion of
> > > the scmi request. However this may not be true in virtual platforms
> > > that are using hvc doorbell.
> > > 
> > Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
> > not a fast call. AFAIK, only TOS use yielding calls. Are you using them
> > here ? If not, this must complete when the SMC/HVC returns. We added
> > support for platforms indicating the same via interrupt.
> > 
> > I would like to avoid adding this build config. Why does it require polling ?
> > Broken firmware ? I would add a compatible for that. Or if the qcom always
> > wants to do this way, just make it specific to the qcom compatible.
> > 
> > I would avoid a config flag as it needs to be always enabled for single
> > image and affects other platforms as well. So please drop this change.
> > If this is absolutely needed, just add additional property which DT
> > maintainers may not like as it is more like a policy or just make it
> > compatible specific.
> > 
> > --
> > Regards,
> > Sudeep
> We are using Fast call FID. We are using completion IRQ for all the scmi
> instances except one where we need to communicate with the server when GIC
> is in suspended state in HLOS. We will need to poll the channel for
> completion in that use case. I am open to suggestions.

IIUC, for the sake of that one corner case, you have added the polling
Kconfig and will be enabled for all the case and even on other platforms
in a single Image. I think we could be something better, no ?

Please share details on that one corner case.
Is it in the scmi drivers already ? If so, specifics please.
If no, again provide details on how you plan to use. We do have ways
to make a polling call, but haven't mixed it with interrupt based calls
for a reason, but we can revisit if it makes sense.

--
Regards,
Sudeep

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-04 16:06           ` Sudeep Holla
@ 2023-10-04 17:48             ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-04 17:48 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/4/2023 9:06 AM, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
>> On 10/3/2023 4:19 AM, Sudeep Holla wrote:
>>> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>>>> This change adds the support for SCMI message exchange on Qualcomm
>>>> virtual platforms.
>>>>
>>>> The hypervisor associates an object-id also known as capability-id
>>>> with each hvc doorbell object. The capability-id is used to identify the
>>>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>>>
>>>> The hypervisor, in addition to the function-id, expects the capability-id
>>>> to be passed in x1 register when HVC call is invoked.
>>>>
>>>> The function-id & capability-id are allocated by the hypervisor on bootup
>>>> and are stored in the shmem region by the firmware before starting Linux.
>>>>
>>>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>>>> ---
>>>>    drivers/firmware/arm_scmi/driver.c |  1 +
>>>>    drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>>>>    2 files changed, 43 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
>>>> index 87383c05424b..ea344bc6ae49 100644
>>>> --- a/drivers/firmware/arm_scmi/driver.c
>>>> +++ b/drivers/firmware/arm_scmi/driver.c
>>>> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>>>>    #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>>>>    	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>>>>    	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>>>> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>>>>    #endif
>>>>    #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>>>>    	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
>>>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>>>> index 0a0b7e401159..94ec07fdc14a 100644
>>>> --- a/drivers/firmware/arm_scmi/smc.c
>>>> +++ b/drivers/firmware/arm_scmi/smc.c
>>>> @@ -50,6 +50,9 @@
>>>>     * @func_id: smc/hvc call function id
>>>>     * @param_page: 4K page number of the shmem channel
>>>>     * @param_offset: Offset within the 4K page of the shmem channel
>>>> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
>>>> + *	    platforms
>>>> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>>>>     */
>>>>    struct scmi_smc {
>>>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>>>    	u32 func_id;
>>>>    	u32 param_page;
>>>>    	u32 param_offset;
>>>> +	u64 cap_id;
>>> Can it be unsigned long instead so that it just works for both 32 and 64 bit.
>> My first version of this patch was ulong but Bjorn suggested to make this
>> structure size fixed i.e. architecture independent. Hence changed it to u64.
>> If you are ok with ulong, I can change it back to ulong.
>>
> SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
> with that. I haven't followed Bjorn suggestions/comments though.
Ok.
>>>> +	bool qcom_xport;
>>> Do we really need this ?
>> Not if we initialize it with a negative value since 0 is a valid value for
>> cap-id.
>>
> Fine with negative value(-EINVAL may be).
Ok.
>>>>    	int ret;
>>>>    	if (!tx)
>>>> @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>>>    		return -EADDRNOTAVAIL;
>>>>    	}
>>>> -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>>>> -	if (ret < 0)
>>>> -		return ret;
>>>> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
>>>> +		scmi_info->qcom_xport = true;
>>>> +
>>>> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
>>>> +		 *     +-------+
>>>> +		 *     |       |
>>>> +		 *     | shmem |
>>>> +		 *     |       |
>>>> +		 *     |       |
>>>> +		 *     +-------+ <-- (size - 16)
>>>> +		 *     | funcId|
>>>> +		 *     +-------+ <-- (size - 8)
>>>> +		 *     | capId |
>>>> +		 *     +-------+ <-- size
>>>> +		 */
>>>> +
>>>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
>>> So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
>>> particular reason ? Just to get both FID and cap ID from shmem ?
> I am fine either way. If you use from DT(via arm,smc-id), then "qcom,scmi"
> can be just addition compatible that expects you to read cap-id from the
> shmem. May need adjustment in the binding as you allow both
> "qcom,scmi-smc", "arm,scmi-smc". I will leave the details to you.
Ok.
>> I could use smc-id binding for func-id, it's just two parameters will come
>> from two different places so thought of keeping everything at one place to
>> maintain consistency.  Since DT can't take cap-id, I decided to move
>> func-id. I am fine if you want me to use smc-id binding.
>>
> Up to you. If you want to make "qcom,scmi-smc" and "arm,scmi-smc"
> compatible in way in that way or you can keep it incompatible as you have
> proposed in this patch set.
Ok.
>>>> +#ifdef CONFIG_ARM64
>>> I would rather make this arch agnostic using CONFIG_64BIT
>> ok.
>>>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
>>> Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
>>> Also scmi_info->shmem is ioremapped just few steps above and you are using
>>> read* here, is that safe ?
>> I saw some compilation warnings without __iomem. I will use ioread* API
>> instead of read*.
>>
> That was the clue that you were using __iomem with read* calls IMO.
Ok.
>>>> +#else
>>>> +		/* capability-id is 32 bit wide on 32bit machines */
>>>> +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);
>>> Other thought once you move for u64 to unsigned long you need not have
>>> #ifdeffery, just do copy of sizeof(unsigned long)
>> Right, my first version was like that only.
> OK
>
>>>> +#endif
>>>> +	} else {
>>>> +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>>>> +		if (ret < 0)
>>>> +			return ret;
>>>> +	}
>>>>    	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>>>>    		scmi_info->param_page = SHMEM_PAGE(res.start);
>>>> @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>>>    	}
>>>>    	scmi_info->func_id = func_id;
>>>> +	scmi_info->cap_id = cap_id;
>>>>    	scmi_info->cinfo = cinfo;
>>>>    	smc_channel_lock_init(scmi_info);
>>>>    	cinfo->transport_info = scmi_info;
>>>> @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>>>    	struct arm_smccc_res res;
>>>>    	unsigned long page = scmi_info->param_page;
>>>>    	unsigned long offset = scmi_info->param_offset;
>>>> +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
>>>>    	/*
>>>>    	 * Channel will be released only once response has been
>>>> @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>>>    	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>>>> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
>>>> -			     &res);
>>>> +	if (scmi_info->qcom_xport)
>>> Just make sure cap_id is set only for qcom and just use that as your flag.
>>> No point in setting always true scmi_info->qcom_xport and using it here.
>> ok, I can remove that. Though 0 is a valid value for cap-id so will have to
>> init cap-id with a negative value.
> Yes as mentioned above.
Ok.
>

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-04 17:48             ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-04 17:48 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/4/2023 9:06 AM, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
>> On 10/3/2023 4:19 AM, Sudeep Holla wrote:
>>> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>>>> This change adds the support for SCMI message exchange on Qualcomm
>>>> virtual platforms.
>>>>
>>>> The hypervisor associates an object-id also known as capability-id
>>>> with each hvc doorbell object. The capability-id is used to identify the
>>>> doorbell from the VM's capability namespace, similar to a file-descriptor.
>>>>
>>>> The hypervisor, in addition to the function-id, expects the capability-id
>>>> to be passed in x1 register when HVC call is invoked.
>>>>
>>>> The function-id & capability-id are allocated by the hypervisor on bootup
>>>> and are stored in the shmem region by the firmware before starting Linux.
>>>>
>>>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>>>> ---
>>>>    drivers/firmware/arm_scmi/driver.c |  1 +
>>>>    drivers/firmware/arm_scmi/smc.c    | 47 ++++++++++++++++++++++++++----
>>>>    2 files changed, 43 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
>>>> index 87383c05424b..ea344bc6ae49 100644
>>>> --- a/drivers/firmware/arm_scmi/driver.c
>>>> +++ b/drivers/firmware/arm_scmi/driver.c
>>>> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>>>>    #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>>>>    	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>>>>    	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
>>>> +	{ .compatible = "qcom,scmi-hvc-shmem", .data = &scmi_smc_desc},
>>>>    #endif
>>>>    #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>>>>    	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
>>>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
>>>> index 0a0b7e401159..94ec07fdc14a 100644
>>>> --- a/drivers/firmware/arm_scmi/smc.c
>>>> +++ b/drivers/firmware/arm_scmi/smc.c
>>>> @@ -50,6 +50,9 @@
>>>>     * @func_id: smc/hvc call function id
>>>>     * @param_page: 4K page number of the shmem channel
>>>>     * @param_offset: Offset within the 4K page of the shmem channel
>>>> + * @cap_id: hvc doorbell's capability id to be used on Qualcomm virtual
>>>> + *	    platforms
>>>> + * @qcom_xport: Flag to indicate the transport on Qualcomm virtual platforms
>>>>     */
>>>>    struct scmi_smc {
>>>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>>>    	u32 func_id;
>>>>    	u32 param_page;
>>>>    	u32 param_offset;
>>>> +	u64 cap_id;
>>> Can it be unsigned long instead so that it just works for both 32 and 64 bit.
>> My first version of this patch was ulong but Bjorn suggested to make this
>> structure size fixed i.e. architecture independent. Hence changed it to u64.
>> If you are ok with ulong, I can change it back to ulong.
>>
> SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
> with that. I haven't followed Bjorn suggestions/comments though.
Ok.
>>>> +	bool qcom_xport;
>>> Do we really need this ?
>> Not if we initialize it with a negative value since 0 is a valid value for
>> cap-id.
>>
> Fine with negative value(-EINVAL may be).
Ok.
>>>>    	int ret;
>>>>    	if (!tx)
>>>> @@ -158,9 +164,34 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>>>    		return -EADDRNOTAVAIL;
>>>>    	}
>>>> -	ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>>>> -	if (ret < 0)
>>>> -		return ret;
>>>> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-hvc-shmem")) {
>>>> +		scmi_info->qcom_xport = true;
>>>> +
>>>> +		/* The func-id & capability-id are kept in last 16 bytes of shmem.
>>>> +		 *     +-------+
>>>> +		 *     |       |
>>>> +		 *     | shmem |
>>>> +		 *     |       |
>>>> +		 *     |       |
>>>> +		 *     +-------+ <-- (size - 16)
>>>> +		 *     | funcId|
>>>> +		 *     +-------+ <-- (size - 8)
>>>> +		 *     | capId |
>>>> +		 *     +-------+ <-- size
>>>> +		 */
>>>> +
>>>> +		func_id = readl((void __iomem *)(scmi_info->shmem) + size - 16);
>>> So unlike 'arm,scmi-smc', you don't want 'arm,smc-id' in the DT ? Any
>>> particular reason ? Just to get both FID and cap ID from shmem ?
> I am fine either way. If you use from DT(via arm,smc-id), then "qcom,scmi"
> can be just addition compatible that expects you to read cap-id from the
> shmem. May need adjustment in the binding as you allow both
> "qcom,scmi-smc", "arm,scmi-smc". I will leave the details to you.
Ok.
>> I could use smc-id binding for func-id, it's just two parameters will come
>> from two different places so thought of keeping everything at one place to
>> maintain consistency.  Since DT can't take cap-id, I decided to move
>> func-id. I am fine if you want me to use smc-id binding.
>>
> Up to you. If you want to make "qcom,scmi-smc" and "arm,scmi-smc"
> compatible in way in that way or you can keep it incompatible as you have
> proposed in this patch set.
Ok.
>>>> +#ifdef CONFIG_ARM64
>>> I would rather make this arch agnostic using CONFIG_64BIT
>> ok.
>>>> +		cap_id = readq((void __iomem *)(scmi_info->shmem) + size - 8);
>>> Do you need __iomem typecast here ? Is scmi_info->shmem not already __iomem ?
>>> Also scmi_info->shmem is ioremapped just few steps above and you are using
>>> read* here, is that safe ?
>> I saw some compilation warnings without __iomem. I will use ioread* API
>> instead of read*.
>>
> That was the clue that you were using __iomem with read* calls IMO.
Ok.
>>>> +#else
>>>> +		/* capability-id is 32 bit wide on 32bit machines */
>>>> +		cap_id = rieadl((void __iomem *)(scmi_info->shmem) + size - 8);
>>> Other thought once you move for u64 to unsigned long you need not have
>>> #ifdeffery, just do copy of sizeof(unsigned long)
>> Right, my first version was like that only.
> OK
>
>>>> +#endif
>>>> +	} else {
>>>> +		ret = of_property_read_u32(dev->of_node, "arm,smc-id", &func_id);
>>>> +		if (ret < 0)
>>>> +			return ret;
>>>> +	}
>>>>    	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>>>>    		scmi_info->param_page = SHMEM_PAGE(res.start);
>>>> @@ -184,6 +215,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>>>>    	}
>>>>    	scmi_info->func_id = func_id;
>>>> +	scmi_info->cap_id = cap_id;
>>>>    	scmi_info->cinfo = cinfo;
>>>>    	smc_channel_lock_init(scmi_info);
>>>>    	cinfo->transport_info = scmi_info;
>>>> @@ -213,6 +245,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>>>    	struct arm_smccc_res res;
>>>>    	unsigned long page = scmi_info->param_page;
>>>>    	unsigned long offset = scmi_info->param_offset;
>>>> +	unsigned long cap_id = (unsigned long)scmi_info->cap_id;
>>>>    	/*
>>>>    	 * Channel will be released only once response has been
>>>> @@ -222,8 +255,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>>>>    	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>>>> -	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
>>>> -			     &res);
>>>> +	if (scmi_info->qcom_xport)
>>> Just make sure cap_id is set only for qcom and just use that as your flag.
>>> No point in setting always true scmi_info->qcom_xport and using it here.
>> ok, I can remove that. Though 0 is a valid value for cap-id so will have to
>> init cap-id with a negative value.
> Yes as mentioned above.
Ok.
>

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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
  2023-10-04 16:11           ` Sudeep Holla
@ 2023-10-05  3:25             ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-05  3:25 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, Brian Masney, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/4/2023 9:11 AM, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 08:53:20AM -0700, Nikunj Kela wrote:
>> On 10/3/2023 3:33 AM, Sudeep Holla wrote:
>>> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
>>>> Currently, the return from the smc call assumes the completion of
>>>> the scmi request. However this may not be true in virtual platforms
>>>> that are using hvc doorbell.
>>>>
>>> Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
>>> not a fast call. AFAIK, only TOS use yielding calls. Are you using them
>>> here ? If not, this must complete when the SMC/HVC returns. We added
>>> support for platforms indicating the same via interrupt.
>>>
>>> I would like to avoid adding this build config. Why does it require polling ?
>>> Broken firmware ? I would add a compatible for that. Or if the qcom always
>>> wants to do this way, just make it specific to the qcom compatible.
>>>
>>> I would avoid a config flag as it needs to be always enabled for single
>>> image and affects other platforms as well. So please drop this change.
>>> If this is absolutely needed, just add additional property which DT
>>> maintainers may not like as it is more like a policy or just make it
>>> compatible specific.
>>>
>>> --
>>> Regards,
>>> Sudeep
>> We are using Fast call FID. We are using completion IRQ for all the scmi
>> instances except one where we need to communicate with the server when GIC
>> is in suspended state in HLOS. We will need to poll the channel for
>> completion in that use case. I am open to suggestions.
> IIUC, for the sake of that one corner case, you have added the polling
> Kconfig and will be enabled for all the case and even on other platforms
> in a single Image. I think we could be something better, no ?
>
> Please share details on that one corner case.
> Is it in the scmi drivers already ? If so, specifics please.
> If no, again provide details on how you plan to use. We do have ways
> to make a polling call, but haven't mixed it with interrupt based calls
> for a reason, but we can revisit if it makes sense.
>
> --
> Regards,
> Sudeep

Ok. I will discard this patch for now from this series and will explore 
alternative ways instead of polling that might work in our usecase. If 
required, will provide you with more details in a separate patch. Thanks!


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

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

* Re: [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc
@ 2023-10-05  3:25             ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-05  3:25 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, Brian Masney, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/4/2023 9:11 AM, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 08:53:20AM -0700, Nikunj Kela wrote:
>> On 10/3/2023 3:33 AM, Sudeep Holla wrote:
>>> On Mon, Sep 11, 2023 at 12:43:56PM -0700, Nikunj Kela wrote:
>>>> Currently, the return from the smc call assumes the completion of
>>>> the scmi request. However this may not be true in virtual platforms
>>>> that are using hvc doorbell.
>>>>
>>> Hmm, it is expectation from SMCCC for the fast calls. Is you HVC FID
>>> not a fast call. AFAIK, only TOS use yielding calls. Are you using them
>>> here ? If not, this must complete when the SMC/HVC returns. We added
>>> support for platforms indicating the same via interrupt.
>>>
>>> I would like to avoid adding this build config. Why does it require polling ?
>>> Broken firmware ? I would add a compatible for that. Or if the qcom always
>>> wants to do this way, just make it specific to the qcom compatible.
>>>
>>> I would avoid a config flag as it needs to be always enabled for single
>>> image and affects other platforms as well. So please drop this change.
>>> If this is absolutely needed, just add additional property which DT
>>> maintainers may not like as it is more like a policy or just make it
>>> compatible specific.
>>>
>>> --
>>> Regards,
>>> Sudeep
>> We are using Fast call FID. We are using completion IRQ for all the scmi
>> instances except one where we need to communicate with the server when GIC
>> is in suspended state in HLOS. We will need to poll the channel for
>> completion in that use case. I am open to suggestions.
> IIUC, for the sake of that one corner case, you have added the polling
> Kconfig and will be enabled for all the case and even on other platforms
> in a single Image. I think we could be something better, no ?
>
> Please share details on that one corner case.
> Is it in the scmi drivers already ? If so, specifics please.
> If no, again provide details on how you plan to use. We do have ways
> to make a polling call, but haven't mixed it with interrupt based calls
> for a reason, but we can revisit if it makes sense.
>
> --
> Regards,
> Sudeep

Ok. I will discard this patch for now from this series and will explore 
alternative ways instead of polling that might work in our usecase. If 
required, will provide you with more details in a separate patch. Thanks!


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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-04 15:53           ` Sudeep Holla
@ 2023-10-05 21:51             ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-05 21:51 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/4/2023 8:53 AM, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 08:59:45AM -0700, Nikunj Kela wrote:
>> On 10/3/2023 3:44 AM, Sudeep Holla wrote:
>>> On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
>>>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
>>>> transport channel for Qualcomm virtual platforms.
>>>> The compatible mandates a shared memory channel.
>>>>
>>>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>>>> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>> ---
>>>>    .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
>>>>    1 file changed, 12 insertions(+)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>>>> index 8d54ea768d38..4090240f45b1 100644
>>>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>>>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>>>> @@ -45,6 +45,9 @@ properties:
>>>>          - description: SCMI compliant firmware with OP-TEE transport
>>>>            items:
>>>>              - const: linaro,scmi-optee
>>>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>>>> +        items:
>>>> +          - const: qcom,scmi-hvc-shmem
>>> Can it be simply "qcom,scmi-smc" for 2 reasons ?
>>> 1. We don't support SMC/HVC without shmem, so what is your argument to add
>>>      '-shmem' in the compatible here ?
>> In our platforms, there are multiple ways to allocate memory. One is
>> preallocated shmem as used here, another is dynamically by hypervisor APIs.
>> shmem was to just to indicate it is preallocated.
>>
> Let us keep it without shmem. If it is dynamically allocated, you must not
> need another compatible as you can check it at the runtime.
>
>>> 2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
>>>     '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
>>>     that HVC is the conduit chosen here based on the compatible. It can be true
>>>     for other reason but I don't want to mislead here by using HVC.
>> IUUC, currently, conduit comes from PSCI dt node. We have been using smc for
>> PSCI but want to use hvc here. That being said, I am fine to explore if we
>> can change PSCI to use hvc too.
>>
> I think only OPTEE has explicit conduit other than PSCI and it is continued
> for legacy/compatibility reasons IIUC and IIRC. Anything else depends on
> the conduit used by PSCI to be consistent. So yes you need to use what the
> PSCI conduit is and you don't need the extra information from the DT either
> as new property or in the compatible.

Ok, will use conduit then. Thanks!


>

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

* Re: [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-05 21:51             ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-05 21:51 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/4/2023 8:53 AM, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 08:59:45AM -0700, Nikunj Kela wrote:
>> On 10/3/2023 3:44 AM, Sudeep Holla wrote:
>>> On Mon, Sep 11, 2023 at 12:43:58PM -0700, Nikunj Kela wrote:
>>>> Introduce compatible "qcom,scmi-hvc-shmem" for SCMI smc/hvc
>>>> transport channel for Qualcomm virtual platforms.
>>>> The compatible mandates a shared memory channel.
>>>>
>>>> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
>>>> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>> ---
>>>>    .../devicetree/bindings/firmware/arm,scmi.yaml       | 12 ++++++++++++
>>>>    1 file changed, 12 insertions(+)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>>>> index 8d54ea768d38..4090240f45b1 100644
>>>> --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>>>> +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
>>>> @@ -45,6 +45,9 @@ properties:
>>>>          - description: SCMI compliant firmware with OP-TEE transport
>>>>            items:
>>>>              - const: linaro,scmi-optee
>>>> +      - description: SCMI compliant firmware with Qualcomm hvc/shmem transport
>>>> +        items:
>>>> +          - const: qcom,scmi-hvc-shmem
>>> Can it be simply "qcom,scmi-smc" for 2 reasons ?
>>> 1. We don't support SMC/HVC without shmem, so what is your argument to add
>>>      '-shmem' in the compatible here ?
>> In our platforms, there are multiple ways to allocate memory. One is
>> preallocated shmem as used here, another is dynamically by hypervisor APIs.
>> shmem was to just to indicate it is preallocated.
>>
> Let us keep it without shmem. If it is dynamically allocated, you must not
> need another compatible as you can check it at the runtime.
>
>>> 2. The exact conduit(SMC/HVC) used is detected runtime, so I prefer to keep
>>>     '-smc' instead of '-hvc' in the compatible just to avoid giving an illusion
>>>     that HVC is the conduit chosen here based on the compatible. It can be true
>>>     for other reason but I don't want to mislead here by using HVC.
>> IUUC, currently, conduit comes from PSCI dt node. We have been using smc for
>> PSCI but want to use hvc here. That being said, I am fine to explore if we
>> can change PSCI to use hvc too.
>>
> I think only OPTEE has explicit conduit other than PSCI and it is continued
> for legacy/compatibility reasons IIUC and IIRC. Anything else depends on
> the conduit used by PSCI to be consistent. So yes you need to use what the
> PSCI conduit is and you don't need the extra information from the DT either
> as new property or in the compatible.

Ok, will use conduit then. Thanks!


>

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-04 16:06           ` Sudeep Holla
@ 2023-10-05 22:20             ` Bjorn Andersson
  -1 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-10-05 22:20 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Nikunj Kela, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Wed, Oct 04, 2023 at 05:06:30PM +0100, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
> > On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> > > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
[..]
> > > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > > >   	u32 func_id;
> > > >   	u32 param_page;
> > > >   	u32 param_offset;
> > > > +	u64 cap_id;
> > > Can it be unsigned long instead so that it just works for both 32 and 64 bit.
> > 
> > My first version of this patch was ulong but Bjorn suggested to make this
> > structure size fixed i.e. architecture independent. Hence changed it to u64.
> > If you are ok with ulong, I can change it back to ulong.
> >
> 
> SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
> with that. I haven't followed Bjorn suggestions/comments though.
> 

My request was that funcId and capId is an ABI between the firmware and
the OS, so I'd like for that to use well defined, fixed sized, data
types - if nothing else just for documentation purpose.

These values will be truncated when passed to arm_smccc_1_1_invoke()
anyways, so I don't have any opinion against using unsigned long here...


PS. I understand why func_id is u32, but why are param_page and
param_offset u32?

Regards,
Bjorn

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-05 22:20             ` Bjorn Andersson
  0 siblings, 0 replies; 186+ messages in thread
From: Bjorn Andersson @ 2023-10-05 22:20 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Nikunj Kela, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Wed, Oct 04, 2023 at 05:06:30PM +0100, Sudeep Holla wrote:
> On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
> > On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> > > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
[..]
> > > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > > >   	u32 func_id;
> > > >   	u32 param_page;
> > > >   	u32 param_offset;
> > > > +	u64 cap_id;
> > > Can it be unsigned long instead so that it just works for both 32 and 64 bit.
> > 
> > My first version of this patch was ulong but Bjorn suggested to make this
> > structure size fixed i.e. architecture independent. Hence changed it to u64.
> > If you are ok with ulong, I can change it back to ulong.
> >
> 
> SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
> with that. I haven't followed Bjorn suggestions/comments though.
> 

My request was that funcId and capId is an ABI between the firmware and
the OS, so I'd like for that to use well defined, fixed sized, data
types - if nothing else just for documentation purpose.

These values will be truncated when passed to arm_smccc_1_1_invoke()
anyways, so I don't have any opinion against using unsigned long here...


PS. I understand why func_id is u32, but why are param_page and
param_offset u32?

Regards,
Bjorn

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-05 22:20             ` Bjorn Andersson
@ 2023-10-05 22:33               ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-05 22:33 UTC (permalink / raw)
  To: Bjorn Andersson, Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/5/2023 3:20 PM, Bjorn Andersson wrote:
> On Wed, Oct 04, 2023 at 05:06:30PM +0100, Sudeep Holla wrote:
>> On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
>>> On 10/3/2023 4:19 AM, Sudeep Holla wrote:
>>>> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>>>>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> [..]
>>>>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>>>>    	u32 func_id;
>>>>>    	u32 param_page;
>>>>>    	u32 param_offset;
>>>>> +	u64 cap_id;
>>>> Can it be unsigned long instead so that it just works for both 32 and 64 bit.
>>> My first version of this patch was ulong but Bjorn suggested to make this
>>> structure size fixed i.e. architecture independent. Hence changed it to u64.
>>> If you are ok with ulong, I can change it back to ulong.
>>>
>> SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
>> with that. I haven't followed Bjorn suggestions/comments though.
>>
> My request was that funcId and capId is an ABI between the firmware and
> the OS, so I'd like for that to use well defined, fixed sized, data
> types - if nothing else just for documentation purpose.
>
> These values will be truncated when passed to arm_smccc_1_1_invoke()
> anyways, so I don't have any opinion against using unsigned long here...
>
>
> PS. I understand why func_id is u32, but why are param_page and
> param_offset u32?

That was done to keep it uniform across smc32/smc64 conventions.

>
> Regards,
> Bjorn

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-05 22:33               ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-05 22:33 UTC (permalink / raw)
  To: Bjorn Andersson, Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/5/2023 3:20 PM, Bjorn Andersson wrote:
> On Wed, Oct 04, 2023 at 05:06:30PM +0100, Sudeep Holla wrote:
>> On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
>>> On 10/3/2023 4:19 AM, Sudeep Holla wrote:
>>>> On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
>>>>> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> [..]
>>>>> @@ -63,6 +66,8 @@ struct scmi_smc {
>>>>>    	u32 func_id;
>>>>>    	u32 param_page;
>>>>>    	u32 param_offset;
>>>>> +	u64 cap_id;
>>>> Can it be unsigned long instead so that it just works for both 32 and 64 bit.
>>> My first version of this patch was ulong but Bjorn suggested to make this
>>> structure size fixed i.e. architecture independent. Hence changed it to u64.
>>> If you are ok with ulong, I can change it back to ulong.
>>>
>> SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
>> with that. I haven't followed Bjorn suggestions/comments though.
>>
> My request was that funcId and capId is an ABI between the firmware and
> the OS, so I'd like for that to use well defined, fixed sized, data
> types - if nothing else just for documentation purpose.
>
> These values will be truncated when passed to arm_smccc_1_1_invoke()
> anyways, so I don't have any opinion against using unsigned long here...
>
>
> PS. I understand why func_id is u32, but why are param_page and
> param_offset u32?

That was done to keep it uniform across smc32/smc64 conventions.

>
> Regards,
> Bjorn

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

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
  2023-10-05 22:20             ` Bjorn Andersson
@ 2023-10-06  7:26               ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-06  7:26 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Nikunj Kela, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Thu, Oct 05, 2023 at 03:20:16PM -0700, Bjorn Andersson wrote:
> On Wed, Oct 04, 2023 at 05:06:30PM +0100, Sudeep Holla wrote:
> > On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
> > > On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> > > > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> [..]
> > > > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > > > >   	u32 func_id;
> > > > >   	u32 param_page;
> > > > >   	u32 param_offset;
> > > > > +	u64 cap_id;
> > > > Can it be unsigned long instead so that it just works for both 32 and 64 bit.
> > > 
> > > My first version of this patch was ulong but Bjorn suggested to make this
> > > structure size fixed i.e. architecture independent. Hence changed it to u64.
> > > If you are ok with ulong, I can change it back to ulong.
> > >
> > 
> > SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
> > with that. I haven't followed Bjorn suggestions/comments though.
> > 
> 
> My request was that funcId and capId is an ABI between the firmware and
> the OS, so I'd like for that to use well defined, fixed sized, data
> types - if nothing else just for documentation purpose.
> 
> These values will be truncated when passed to arm_smccc_1_1_invoke()
> anyways, so I don't have any opinion against using unsigned long here...
> 
> 
> PS. I understand why func_id is u32, but why are param_page and
> param_offset u32?
> 

Good point. Sorry I somehow missed your original comment, my bad.
Yes, it is good to be consistent. Sorry if I added any confusion by
missing o read your comment and understanding it before I responded.

--
Regards,
Sudeep

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

* Re: [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support
@ 2023-10-06  7:26               ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-06  7:26 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Nikunj Kela, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Thu, Oct 05, 2023 at 03:20:16PM -0700, Bjorn Andersson wrote:
> On Wed, Oct 04, 2023 at 05:06:30PM +0100, Sudeep Holla wrote:
> > On Tue, Oct 03, 2023 at 09:16:27AM -0700, Nikunj Kela wrote:
> > > On 10/3/2023 4:19 AM, Sudeep Holla wrote:
> > > > On Mon, Sep 11, 2023 at 12:43:59PM -0700, Nikunj Kela wrote:
> > > > > diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> [..]
> > > > > @@ -63,6 +66,8 @@ struct scmi_smc {
> > > > >   	u32 func_id;
> > > > >   	u32 param_page;
> > > > >   	u32 param_offset;
> > > > > +	u64 cap_id;
> > > > Can it be unsigned long instead so that it just works for both 32 and 64 bit.
> > > 
> > > My first version of this patch was ulong but Bjorn suggested to make this
> > > structure size fixed i.e. architecture independent. Hence changed it to u64.
> > > If you are ok with ulong, I can change it back to ulong.
> > >
> > 
> > SMCCC pre-v1.2 used the common structure in that way. I don't see any issue
> > with that. I haven't followed Bjorn suggestions/comments though.
> > 
> 
> My request was that funcId and capId is an ABI between the firmware and
> the OS, so I'd like for that to use well defined, fixed sized, data
> types - if nothing else just for documentation purpose.
> 
> These values will be truncated when passed to arm_smccc_1_1_invoke()
> anyways, so I don't have any opinion against using unsigned long here...
> 
> 
> PS. I understand why func_id is u32, but why are param_page and
> param_offset u32?
> 

Good point. Sorry I somehow missed your original comment, my bad.
Yes, it is good to be consistent. Sorry if I added any confusion by
missing o read your comment and understanding it before I responded.

--
Regards,
Sudeep

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

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

* [PATCH v5 0/2] Add qcom smc/hvc transport support
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-10-06 16:42   ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-06 16:42 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change augments smc transport to include support for Qualcomm virtual
platforms by passing a parameter(capability-id) in the hypervisor call to
identify which doorbell to assert. This parameter is dynamically generated
at runtime on the device and insuitable to pass via the devicetree.

The capability-id is stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v5 -> changed compatible, removed polling support patch,
      make use of smc-id binding for function-id

v4 -> port the changes into smc.c

v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (2):
  dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  firmware: arm_scmi: Add qcom smc/hvc transport support

 .../bindings/firmware/arm,scmi.yaml           |  4 +++
 drivers/firmware/arm_scmi/driver.c            |  1 +
 drivers/firmware/arm_scmi/smc.c               | 33 +++++++++++++++++--
 3 files changed, 36 insertions(+), 2 deletions(-)

-- 
2.17.1


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

* [PATCH v5 0/2] Add qcom smc/hvc transport support
@ 2023-10-06 16:42   ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-06 16:42 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change augments smc transport to include support for Qualcomm virtual
platforms by passing a parameter(capability-id) in the hypervisor call to
identify which doorbell to assert. This parameter is dynamically generated
at runtime on the device and insuitable to pass via the devicetree.

The capability-id is stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v5 -> changed compatible, removed polling support patch,
      make use of smc-id binding for function-id

v4 -> port the changes into smc.c

v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (2):
  dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  firmware: arm_scmi: Add qcom smc/hvc transport support

 .../bindings/firmware/arm,scmi.yaml           |  4 +++
 drivers/firmware/arm_scmi/driver.c            |  1 +
 drivers/firmware/arm_scmi/smc.c               | 33 +++++++++++++++++--
 3 files changed, 36 insertions(+), 2 deletions(-)

-- 
2.17.1


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

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

* [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-06 16:42   ` Nikunj Kela
@ 2023-10-06 16:42     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-06 16:42 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
Qualcomm virtual platforms.

This compatible mandates populating an additional parameter 'capability-id'
from the last 8 bytes of the shmem channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 Documentation/devicetree/bindings/firmware/arm,scmi.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 563a87dfb31a..4591523b51a0 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -38,6 +38,9 @@ properties:
                      with shmem address(4KB-page, offset) as parameters
         items:
           - const: arm,scmi-smc-param
+      - description: SCMI compliant firmware with Qualcomm SMC/HVC transport
+        items:
+          - const: qcom,scmi-smc
       - description: SCMI compliant firmware with SCMI Virtio transport.
                      The virtio transport only supports a single device.
         items:
@@ -313,6 +316,7 @@ else:
           enum:
             - arm,scmi-smc
             - arm,scmi-smc-param
+            - qcom,scmi-smc
   then:
     required:
       - arm,smc-id
-- 
2.17.1


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

* [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-06 16:42     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-06 16:42 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
Qualcomm virtual platforms.

This compatible mandates populating an additional parameter 'capability-id'
from the last 8 bytes of the shmem channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 Documentation/devicetree/bindings/firmware/arm,scmi.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 563a87dfb31a..4591523b51a0 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -38,6 +38,9 @@ properties:
                      with shmem address(4KB-page, offset) as parameters
         items:
           - const: arm,scmi-smc-param
+      - description: SCMI compliant firmware with Qualcomm SMC/HVC transport
+        items:
+          - const: qcom,scmi-smc
       - description: SCMI compliant firmware with SCMI Virtio transport.
                      The virtio transport only supports a single device.
         items:
@@ -313,6 +316,7 @@ else:
           enum:
             - arm,scmi-smc
             - arm,scmi-smc-param
+            - qcom,scmi-smc
   then:
     required:
       - arm,smc-id
-- 
2.17.1


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

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

* [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-06 16:42   ` Nikunj Kela
@ 2023-10-06 16:42     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-06 16:42 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change adds the support for SCMI message exchange on Qualcomm
virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each smc/hvc doorbell object. The capability-id is used to
identify the doorbell from the VM's capability namespace, similar
to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when SMC/HVC call is invoked.

The capability-id is allocated by the hypervisor on bootup and is stored in
the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/driver.c |  1 +
 drivers/firmware/arm_scmi/smc.c    | 33 ++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 87383c05424b..09371f40d61f 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
 	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
 	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
+	{ .compatible = "qcom,scmi-smc", .data = &scmi_smc_desc},
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index c193516a254d..3d594d65ab14 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -50,6 +50,8 @@
  * @func_id: smc/hvc call function id
  * @param_page: 4K page number of the shmem channel
  * @param_offset: Offset within the 4K page of the shmem channel
+ * @cap_id: smc/hvc doorbell's capability id to be used on Qualcomm virtual
+ *	    platforms
  */
 
 struct scmi_smc {
@@ -63,6 +65,7 @@ struct scmi_smc {
 	u32 func_id;
 	u32 param_page;
 	u32 param_offset;
+	s64 cap_id;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -128,6 +131,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	resource_size_t size;
 	struct resource res;
 	struct device_node *np;
+	s64 cap_id = -EINVAL;
 	u32 func_id;
 	int ret;
 
@@ -162,6 +166,25 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	if (ret < 0)
 		return ret;
 
+	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
+		/* The capability-id is kept in last 8 bytes of shmem.
+		 *     +-------+
+		 *     |       |
+		 *     | shmem |
+		 *     |       |
+		 *     |       |
+		 *     +-------+ <-- (size - 8)
+		 *     | capId |
+		 *     +-------+ <-- size
+		 */
+
+#ifdef CONFIG_64BIT
+		cap_id = ioread64((void *)scmi_info->shmem + size - 8);
+#else
+		cap_id = ioread32((void *)scmi_info->shmem + size - 8);
+#endif
+	}
+
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
 		scmi_info->param_page = SHMEM_PAGE(res.start);
 		scmi_info->param_offset = SHMEM_OFFSET(res.start);
@@ -184,6 +207,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	}
 
 	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
 	scmi_info->cinfo = cinfo;
 	smc_channel_lock_init(scmi_info);
 	cinfo->transport_info = scmi_info;
@@ -213,6 +237,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 	struct arm_smccc_res res;
 	unsigned long page = scmi_info->param_page;
 	unsigned long offset = scmi_info->param_offset;
+	long cap_id = (long)scmi_info->cap_id;
 
 	/*
 	 * Channel will be released only once response has been
@@ -222,8 +247,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
-			     &res);
+	if (cap_id >= 0)
+		arm_smccc_1_1_invoke(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0,
+				     0, &res);
+	else
+		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
+				     0, 0, &res);
 
 	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
 	if (res.a0) {
-- 
2.17.1


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

* [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-06 16:42     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-06 16:42 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change adds the support for SCMI message exchange on Qualcomm
virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each smc/hvc doorbell object. The capability-id is used to
identify the doorbell from the VM's capability namespace, similar
to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when SMC/HVC call is invoked.

The capability-id is allocated by the hypervisor on bootup and is stored in
the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
---
 drivers/firmware/arm_scmi/driver.c |  1 +
 drivers/firmware/arm_scmi/smc.c    | 33 ++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 87383c05424b..09371f40d61f 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
 	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
 	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
+	{ .compatible = "qcom,scmi-smc", .data = &scmi_smc_desc},
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index c193516a254d..3d594d65ab14 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -50,6 +50,8 @@
  * @func_id: smc/hvc call function id
  * @param_page: 4K page number of the shmem channel
  * @param_offset: Offset within the 4K page of the shmem channel
+ * @cap_id: smc/hvc doorbell's capability id to be used on Qualcomm virtual
+ *	    platforms
  */
 
 struct scmi_smc {
@@ -63,6 +65,7 @@ struct scmi_smc {
 	u32 func_id;
 	u32 param_page;
 	u32 param_offset;
+	s64 cap_id;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -128,6 +131,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	resource_size_t size;
 	struct resource res;
 	struct device_node *np;
+	s64 cap_id = -EINVAL;
 	u32 func_id;
 	int ret;
 
@@ -162,6 +166,25 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	if (ret < 0)
 		return ret;
 
+	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
+		/* The capability-id is kept in last 8 bytes of shmem.
+		 *     +-------+
+		 *     |       |
+		 *     | shmem |
+		 *     |       |
+		 *     |       |
+		 *     +-------+ <-- (size - 8)
+		 *     | capId |
+		 *     +-------+ <-- size
+		 */
+
+#ifdef CONFIG_64BIT
+		cap_id = ioread64((void *)scmi_info->shmem + size - 8);
+#else
+		cap_id = ioread32((void *)scmi_info->shmem + size - 8);
+#endif
+	}
+
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
 		scmi_info->param_page = SHMEM_PAGE(res.start);
 		scmi_info->param_offset = SHMEM_OFFSET(res.start);
@@ -184,6 +207,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	}
 
 	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
 	scmi_info->cinfo = cinfo;
 	smc_channel_lock_init(scmi_info);
 	cinfo->transport_info = scmi_info;
@@ -213,6 +237,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 	struct arm_smccc_res res;
 	unsigned long page = scmi_info->param_page;
 	unsigned long offset = scmi_info->param_offset;
+	long cap_id = (long)scmi_info->cap_id;
 
 	/*
 	 * Channel will be released only once response has been
@@ -222,8 +247,12 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0, 0, 0,
-			     &res);
+	if (cap_id >= 0)
+		arm_smccc_1_1_invoke(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0,
+				     0, &res);
+	else
+		arm_smccc_1_1_invoke(scmi_info->func_id, page, offset, 0, 0, 0,
+				     0, 0, &res);
 
 	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
 	if (res.a0) {
-- 
2.17.1


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

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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-06 16:42     ` Nikunj Kela
@ 2023-10-06 20:08       ` Brian Masney
  -1 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-06 20:08 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
> Qualcomm virtual platforms.
> 
> This compatible mandates populating an additional parameter 'capability-id'
> from the last 8 bytes of the shmem channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>

Reviewed-by: Brian Masney <bmasney@redhat.com>


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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-06 20:08       ` Brian Masney
  0 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-06 20:08 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
> Qualcomm virtual platforms.
> 
> This compatible mandates populating an additional parameter 'capability-id'
> from the last 8 bytes of the shmem channel.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>

Reviewed-by: Brian Masney <bmasney@redhat.com>


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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-06 16:42     ` Nikunj Kela
@ 2023-10-06 20:17       ` Brian Masney
  -1 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-06 20:17 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each smc/hvc doorbell object. The capability-id is used to
> identify the doorbell from the VM's capability namespace, similar
> to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when SMC/HVC call is invoked.
> 
> The capability-id is allocated by the hypervisor on bootup and is stored in
> the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>

Reviewed-by: Brian Masney <bmasney@redhat.com>


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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-06 20:17       ` Brian Masney
  0 siblings, 0 replies; 186+ messages in thread
From: Brian Masney @ 2023-10-06 20:17 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: sudeep.holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each smc/hvc doorbell object. The capability-id is used to
> identify the doorbell from the VM's capability namespace, similar
> to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when SMC/HVC call is invoked.
> 
> The capability-id is allocated by the hypervisor on bootup and is stored in
> the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>

Reviewed-by: Brian Masney <bmasney@redhat.com>


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

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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-06 16:42     ` Nikunj Kela
@ 2023-10-09 14:41       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 14:41 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
> Qualcomm virtual platforms.
>
> This compatible mandates populating an additional parameter 'capability-id'
> from the last 8 bytes of the shmem channel.
>

While I am happy with the simplification here, I am also bit nervous how
long before Qualcomm abandons this. I hope this is adopted as is in all
internal and downstream code without any modifications and this is not
just a push for upstreaming some change to minimise delta with internal/
downstream code.

--
Regards,
Sudeep

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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-09 14:41       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 14:41 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
> Qualcomm virtual platforms.
>
> This compatible mandates populating an additional parameter 'capability-id'
> from the last 8 bytes of the shmem channel.
>

While I am happy with the simplification here, I am also bit nervous how
long before Qualcomm abandons this. I hope this is adopted as is in all
internal and downstream code without any modifications and this is not
just a push for upstreaming some change to minimise delta with internal/
downstream code.

--
Regards,
Sudeep

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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-06 16:42     ` Nikunj Kela
@ 2023-10-09 14:47       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 14:47 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	Sudeep Holla, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each smc/hvc doorbell object. The capability-id is used to
> identify the doorbell from the VM's capability namespace, similar
> to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when SMC/HVC call is invoked.
> 
> The capability-id is allocated by the hypervisor on bootup and is stored in
> the shmem region by the firmware before starting Linux.
>

Since you are happy to move to signed value, I assume you are happy to loose
upper half of the range values ?

Anyways after Bjorn pointed out inconsistency, I am thinking of moving
all the values to unsigned long to work with both 32bit and 64bit.

Does the below delta on top of this patch works for you and makes sense?

--
Regards,
Sudeep

-->8
diff --git c/drivers/firmware/arm_scmi/smc.c i/drivers/firmware/arm_scmi/smc.c
index bf0b7769c7b2..e00c5e81c8d9 100644
--- c/drivers/firmware/arm_scmi/smc.c
+++ i/drivers/firmware/arm_scmi/smc.c
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
+#include <linux/limits.h>
 #include <linux/processor.h>
 #include <linux/slab.h>
 
@@ -65,7 +66,7 @@ struct scmi_smc {
 	unsigned long func_id;
 	unsigned long param_page;
 	unsigned long param_offset;
-	s64 cap_id;
+	unsigned long cap_id;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -127,11 +128,11 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 			  bool tx)
 {
 	struct device *cdev = cinfo->dev;
+	unsigned long cap_id = ULONG_MAX;
 	struct scmi_smc *scmi_info;
 	resource_size_t size;
 	struct resource res;
 	struct device_node *np;
-	s64 cap_id = -EINVAL;
 	u32 func_id;
 	int ret;
 
@@ -167,6 +168,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return ret;
 
 	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
+		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
 		/* The capability-id is kept in last 8 bytes of shmem.
 		 *     +-------+
 		 *     |       |
@@ -177,12 +179,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		 *     | capId |
 		 *     +-------+ <-- size
 		 */
-
-#ifdef CONFIG_64BIT
-		cap_id = ioread64((void *)scmi_info->shmem + size - 8);
-#else
-		cap_id = ioread32((void *)scmi_info->shmem + size - 8);
-#endif
+		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
 	}
 
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
@@ -247,7 +244,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	if (cap_id >= 0)
+	if (cap_id != ULONG_MAX)
 		arm_smccc_1_1_invoke(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0,
 				     0, &res);
 	else


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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 14:47       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 14:47 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	Sudeep Holla, andersson, konrad.dybcio, linux-arm-kernel,
	devicetree, linux-kernel, linux-arm-msm

On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each smc/hvc doorbell object. The capability-id is used to
> identify the doorbell from the VM's capability namespace, similar
> to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when SMC/HVC call is invoked.
> 
> The capability-id is allocated by the hypervisor on bootup and is stored in
> the shmem region by the firmware before starting Linux.
>

Since you are happy to move to signed value, I assume you are happy to loose
upper half of the range values ?

Anyways after Bjorn pointed out inconsistency, I am thinking of moving
all the values to unsigned long to work with both 32bit and 64bit.

Does the below delta on top of this patch works for you and makes sense?

--
Regards,
Sudeep

-->8
diff --git c/drivers/firmware/arm_scmi/smc.c i/drivers/firmware/arm_scmi/smc.c
index bf0b7769c7b2..e00c5e81c8d9 100644
--- c/drivers/firmware/arm_scmi/smc.c
+++ i/drivers/firmware/arm_scmi/smc.c
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
+#include <linux/limits.h>
 #include <linux/processor.h>
 #include <linux/slab.h>
 
@@ -65,7 +66,7 @@ struct scmi_smc {
 	unsigned long func_id;
 	unsigned long param_page;
 	unsigned long param_offset;
-	s64 cap_id;
+	unsigned long cap_id;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -127,11 +128,11 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 			  bool tx)
 {
 	struct device *cdev = cinfo->dev;
+	unsigned long cap_id = ULONG_MAX;
 	struct scmi_smc *scmi_info;
 	resource_size_t size;
 	struct resource res;
 	struct device_node *np;
-	s64 cap_id = -EINVAL;
 	u32 func_id;
 	int ret;
 
@@ -167,6 +168,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		return ret;
 
 	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
+		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
 		/* The capability-id is kept in last 8 bytes of shmem.
 		 *     +-------+
 		 *     |       |
@@ -177,12 +179,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 		 *     | capId |
 		 *     +-------+ <-- size
 		 */
-
-#ifdef CONFIG_64BIT
-		cap_id = ioread64((void *)scmi_info->shmem + size - 8);
-#else
-		cap_id = ioread32((void *)scmi_info->shmem + size - 8);
-#endif
+		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
 	}
 
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
@@ -247,7 +244,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	if (cap_id >= 0)
+	if (cap_id != ULONG_MAX)
 		arm_smccc_1_1_invoke(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0,
 				     0, &res);
 	else


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

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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-09 14:41       ` Sudeep Holla
@ 2023-10-09 14:52         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 14:52 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 7:41 AM, Sudeep Holla wrote:
> On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
>> Qualcomm virtual platforms.
>>
>> This compatible mandates populating an additional parameter 'capability-id'
>> from the last 8 bytes of the shmem channel.
>>
> While I am happy with the simplification here, I am also bit nervous how
> long before Qualcomm abandons this. I hope this is adopted as is in all
> internal and downstream code without any modifications and this is not
> just a push for upstreaming some change to minimise delta with internal/
> downstream code.
>
> --
> Regards,
> Sudeep

Qualcomm is using patch on all the virtual auto platforms using 
shmem/doorbell as scmi channel. This is already being used without any 
modifications in our downstream code. No delta for this patch series. 
Thanks!


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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-09 14:52         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 14:52 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 7:41 AM, Sudeep Holla wrote:
> On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
>> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
>> Qualcomm virtual platforms.
>>
>> This compatible mandates populating an additional parameter 'capability-id'
>> from the last 8 bytes of the shmem channel.
>>
> While I am happy with the simplification here, I am also bit nervous how
> long before Qualcomm abandons this. I hope this is adopted as is in all
> internal and downstream code without any modifications and this is not
> just a push for upstreaming some change to minimise delta with internal/
> downstream code.
>
> --
> Regards,
> Sudeep

Qualcomm is using patch on all the virtual auto platforms using 
shmem/doorbell as scmi channel. This is already being used without any 
modifications in our downstream code. No delta for this patch series. 
Thanks!


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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 14:47       ` Sudeep Holla
@ 2023-10-09 14:59         ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 14:59 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 7:47 AM, Sudeep Holla wrote:
> On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
>> This change adds the support for SCMI message exchange on Qualcomm
>> virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each smc/hvc doorbell object. The capability-id is used to
>> identify the doorbell from the VM's capability namespace, similar
>> to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when SMC/HVC call is invoked.
>>
>> The capability-id is allocated by the hypervisor on bootup and is stored in
>> the shmem region by the firmware before starting Linux.
>>
> Since you are happy to move to signed value, I assume you are happy to loose
> upper half of the range values ?
>
> Anyways after Bjorn pointed out inconsistency, I am thinking of moving
> all the values to unsigned long to work with both 32bit and 64bit.
>
> Does the below delta on top of this patch works for you and makes sense?

This looks good to me. Will do some testing and float v6 with the 
changes you suggested below. Thanks


>
> --
> Regards,
> Sudeep
>
> -->8
> diff --git c/drivers/firmware/arm_scmi/smc.c i/drivers/firmware/arm_scmi/smc.c
> index bf0b7769c7b2..e00c5e81c8d9 100644
> --- c/drivers/firmware/arm_scmi/smc.c
> +++ i/drivers/firmware/arm_scmi/smc.c
> @@ -15,6 +15,7 @@
>   #include <linux/of.h>
>   #include <linux/of_address.h>
>   #include <linux/of_irq.h>
> +#include <linux/limits.h>
>   #include <linux/processor.h>
>   #include <linux/slab.h>
>   
> @@ -65,7 +66,7 @@ struct scmi_smc {
>   	unsigned long func_id;
>   	unsigned long param_page;
>   	unsigned long param_offset;
> -	s64 cap_id;
> +	unsigned long cap_id;
>   };
>   
>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -127,11 +128,11 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   			  bool tx)
>   {
>   	struct device *cdev = cinfo->dev;
> +	unsigned long cap_id = ULONG_MAX;
>   	struct scmi_smc *scmi_info;
>   	resource_size_t size;
>   	struct resource res;
>   	struct device_node *np;
> -	s64 cap_id = -EINVAL;
>   	u32 func_id;
>   	int ret;
>   
> @@ -167,6 +168,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   		return ret;
>   
>   	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
> +		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
>   		/* The capability-id is kept in last 8 bytes of shmem.
>   		 *     +-------+
>   		 *     |       |
> @@ -177,12 +179,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   		 *     | capId |
>   		 *     +-------+ <-- size
>   		 */
> -
> -#ifdef CONFIG_64BIT
> -		cap_id = ioread64((void *)scmi_info->shmem + size - 8);
> -#else
> -		cap_id = ioread32((void *)scmi_info->shmem + size - 8);
> -#endif
> +		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
>   	}
>   
>   	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
> @@ -247,7 +244,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>   
>   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>   
> -	if (cap_id >= 0)
> +	if (cap_id != ULONG_MAX)
>   		arm_smccc_1_1_invoke(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0,
>   				     0, &res);
>   	else
>

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 14:59         ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 14:59 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 7:47 AM, Sudeep Holla wrote:
> On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
>> This change adds the support for SCMI message exchange on Qualcomm
>> virtual platforms.
>>
>> The hypervisor associates an object-id also known as capability-id
>> with each smc/hvc doorbell object. The capability-id is used to
>> identify the doorbell from the VM's capability namespace, similar
>> to a file-descriptor.
>>
>> The hypervisor, in addition to the function-id, expects the capability-id
>> to be passed in x1 register when SMC/HVC call is invoked.
>>
>> The capability-id is allocated by the hypervisor on bootup and is stored in
>> the shmem region by the firmware before starting Linux.
>>
> Since you are happy to move to signed value, I assume you are happy to loose
> upper half of the range values ?
>
> Anyways after Bjorn pointed out inconsistency, I am thinking of moving
> all the values to unsigned long to work with both 32bit and 64bit.
>
> Does the below delta on top of this patch works for you and makes sense?

This looks good to me. Will do some testing and float v6 with the 
changes you suggested below. Thanks


>
> --
> Regards,
> Sudeep
>
> -->8
> diff --git c/drivers/firmware/arm_scmi/smc.c i/drivers/firmware/arm_scmi/smc.c
> index bf0b7769c7b2..e00c5e81c8d9 100644
> --- c/drivers/firmware/arm_scmi/smc.c
> +++ i/drivers/firmware/arm_scmi/smc.c
> @@ -15,6 +15,7 @@
>   #include <linux/of.h>
>   #include <linux/of_address.h>
>   #include <linux/of_irq.h>
> +#include <linux/limits.h>
>   #include <linux/processor.h>
>   #include <linux/slab.h>
>   
> @@ -65,7 +66,7 @@ struct scmi_smc {
>   	unsigned long func_id;
>   	unsigned long param_page;
>   	unsigned long param_offset;
> -	s64 cap_id;
> +	unsigned long cap_id;
>   };
>   
>   static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -127,11 +128,11 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   			  bool tx)
>   {
>   	struct device *cdev = cinfo->dev;
> +	unsigned long cap_id = ULONG_MAX;
>   	struct scmi_smc *scmi_info;
>   	resource_size_t size;
>   	struct resource res;
>   	struct device_node *np;
> -	s64 cap_id = -EINVAL;
>   	u32 func_id;
>   	int ret;
>   
> @@ -167,6 +168,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   		return ret;
>   
>   	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
> +		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
>   		/* The capability-id is kept in last 8 bytes of shmem.
>   		 *     +-------+
>   		 *     |       |
> @@ -177,12 +179,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>   		 *     | capId |
>   		 *     +-------+ <-- size
>   		 */
> -
> -#ifdef CONFIG_64BIT
> -		cap_id = ioread64((void *)scmi_info->shmem + size - 8);
> -#else
> -		cap_id = ioread32((void *)scmi_info->shmem + size - 8);
> -#endif
> +		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
>   	}
>   
>   	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
> @@ -247,7 +244,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>   
>   	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>   
> -	if (cap_id >= 0)
> +	if (cap_id != ULONG_MAX)
>   		arm_smccc_1_1_invoke(scmi_info->func_id, cap_id, 0, 0, 0, 0, 0,
>   				     0, &res);
>   	else
>

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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 14:59         ` Nikunj Kela
@ 2023-10-09 15:29           ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 15:29 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
> 
> On 10/9/2023 7:47 AM, Sudeep Holla wrote:
> > On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> > > This change adds the support for SCMI message exchange on Qualcomm
> > > virtual platforms.
> > > 
> > > The hypervisor associates an object-id also known as capability-id
> > > with each smc/hvc doorbell object. The capability-id is used to
> > > identify the doorbell from the VM's capability namespace, similar
> > > to a file-descriptor.
> > > 
> > > The hypervisor, in addition to the function-id, expects the capability-id
> > > to be passed in x1 register when SMC/HVC call is invoked.
> > > 
> > > The capability-id is allocated by the hypervisor on bootup and is stored in
> > > the shmem region by the firmware before starting Linux.
> > > 
> > Since you are happy to move to signed value, I assume you are happy to loose
> > upper half of the range values ?
> > 
> > Anyways after Bjorn pointed out inconsistency, I am thinking of moving
> > all the values to unsigned long to work with both 32bit and 64bit.
> > 
> > Does the below delta on top of this patch works for you and makes sense?
> 
> This looks good to me. Will do some testing and float v6 with the changes
> you suggested below. Thanks
> 

Please refer or use the patch from [1] when reposting. I rebased on my
patch[2] that I posted few minutes back. I am trying to finalise the branch
and send PR in next couple of days, so please test and post sooner. Sorry
for the rush.

--
Regards,
Sudeep
[1] https://git.kernel.org/sudeep.holla/h/for-next/scmi/updates
[2] https://lore.kernel.org/r/20231009152049.1428872-1-sudeep.holla@arm.com

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 15:29           ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 15:29 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
> 
> On 10/9/2023 7:47 AM, Sudeep Holla wrote:
> > On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> > > This change adds the support for SCMI message exchange on Qualcomm
> > > virtual platforms.
> > > 
> > > The hypervisor associates an object-id also known as capability-id
> > > with each smc/hvc doorbell object. The capability-id is used to
> > > identify the doorbell from the VM's capability namespace, similar
> > > to a file-descriptor.
> > > 
> > > The hypervisor, in addition to the function-id, expects the capability-id
> > > to be passed in x1 register when SMC/HVC call is invoked.
> > > 
> > > The capability-id is allocated by the hypervisor on bootup and is stored in
> > > the shmem region by the firmware before starting Linux.
> > > 
> > Since you are happy to move to signed value, I assume you are happy to loose
> > upper half of the range values ?
> > 
> > Anyways after Bjorn pointed out inconsistency, I am thinking of moving
> > all the values to unsigned long to work with both 32bit and 64bit.
> > 
> > Does the below delta on top of this patch works for you and makes sense?
> 
> This looks good to me. Will do some testing and float v6 with the changes
> you suggested below. Thanks
> 

Please refer or use the patch from [1] when reposting. I rebased on my
patch[2] that I posted few minutes back. I am trying to finalise the branch
and send PR in next couple of days, so please test and post sooner. Sorry
for the rush.

--
Regards,
Sudeep
[1] https://git.kernel.org/sudeep.holla/h/for-next/scmi/updates
[2] https://lore.kernel.org/r/20231009152049.1428872-1-sudeep.holla@arm.com

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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 15:29           ` Sudeep Holla
@ 2023-10-09 17:49             ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 17:49 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 8:29 AM, Sudeep Holla wrote:
> On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
>> On 10/9/2023 7:47 AM, Sudeep Holla wrote:
>>> On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
>>>> This change adds the support for SCMI message exchange on Qualcomm
>>>> virtual platforms.
>>>>
>>>> The hypervisor associates an object-id also known as capability-id
>>>> with each smc/hvc doorbell object. The capability-id is used to
>>>> identify the doorbell from the VM's capability namespace, similar
>>>> to a file-descriptor.
>>>>
>>>> The hypervisor, in addition to the function-id, expects the capability-id
>>>> to be passed in x1 register when SMC/HVC call is invoked.
>>>>
>>>> The capability-id is allocated by the hypervisor on bootup and is stored in
>>>> the shmem region by the firmware before starting Linux.
>>>>
>>> Since you are happy to move to signed value, I assume you are happy to loose
>>> upper half of the range values ?
>>>
>>> Anyways after Bjorn pointed out inconsistency, I am thinking of moving
>>> all the values to unsigned long to work with both 32bit and 64bit.
>>>
>>> Does the below delta on top of this patch works for you and makes sense?
>> This looks good to me. Will do some testing and float v6 with the changes
>> you suggested below. Thanks
>>
> Please refer or use the patch from [1] when reposting. I rebased on my
> patch[2] that I posted few minutes back. I am trying to finalise the branch
> and send PR in next couple of days, so please test and post sooner. Sorry
> for the rush.

Validated the patch from [1] below on Qualcomm ARM64 virtual platform 
using SMC64 convention. Thanks!


>
> --
> Regards,
> Sudeep
> [1] https://git.kernel.org/sudeep.holla/h/for-next/scmi/updates
> [2] https://lore.kernel.org/r/20231009152049.1428872-1-sudeep.holla@arm.com

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 17:49             ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 17:49 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 8:29 AM, Sudeep Holla wrote:
> On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
>> On 10/9/2023 7:47 AM, Sudeep Holla wrote:
>>> On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
>>>> This change adds the support for SCMI message exchange on Qualcomm
>>>> virtual platforms.
>>>>
>>>> The hypervisor associates an object-id also known as capability-id
>>>> with each smc/hvc doorbell object. The capability-id is used to
>>>> identify the doorbell from the VM's capability namespace, similar
>>>> to a file-descriptor.
>>>>
>>>> The hypervisor, in addition to the function-id, expects the capability-id
>>>> to be passed in x1 register when SMC/HVC call is invoked.
>>>>
>>>> The capability-id is allocated by the hypervisor on bootup and is stored in
>>>> the shmem region by the firmware before starting Linux.
>>>>
>>> Since you are happy to move to signed value, I assume you are happy to loose
>>> upper half of the range values ?
>>>
>>> Anyways after Bjorn pointed out inconsistency, I am thinking of moving
>>> all the values to unsigned long to work with both 32bit and 64bit.
>>>
>>> Does the below delta on top of this patch works for you and makes sense?
>> This looks good to me. Will do some testing and float v6 with the changes
>> you suggested below. Thanks
>>
> Please refer or use the patch from [1] when reposting. I rebased on my
> patch[2] that I posted few minutes back. I am trying to finalise the branch
> and send PR in next couple of days, so please test and post sooner. Sorry
> for the rush.

Validated the patch from [1] below on Qualcomm ARM64 virtual platform 
using SMC64 convention. Thanks!


>
> --
> Regards,
> Sudeep
> [1] https://git.kernel.org/sudeep.holla/h/for-next/scmi/updates
> [2] https://lore.kernel.org/r/20231009152049.1428872-1-sudeep.holla@arm.com

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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 17:49             ` Nikunj Kela
@ 2023-10-09 19:08               ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 19:08 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 09, 2023 at 10:49:44AM -0700, Nikunj Kela wrote:
> 
> On 10/9/2023 8:29 AM, Sudeep Holla wrote:
> > On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
> > > On 10/9/2023 7:47 AM, Sudeep Holla wrote:
> > > > On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> > > > > This change adds the support for SCMI message exchange on Qualcomm
> > > > > virtual platforms.
> > > > > 
> > > > > The hypervisor associates an object-id also known as capability-id
> > > > > with each smc/hvc doorbell object. The capability-id is used to
> > > > > identify the doorbell from the VM's capability namespace, similar
> > > > > to a file-descriptor.
> > > > > 
> > > > > The hypervisor, in addition to the function-id, expects the capability-id
> > > > > to be passed in x1 register when SMC/HVC call is invoked.
> > > > > 
> > > > > The capability-id is allocated by the hypervisor on bootup and is stored in
> > > > > the shmem region by the firmware before starting Linux.
> > > > > 
> > > > Since you are happy to move to signed value, I assume you are happy to loose
> > > > upper half of the range values ?
> > > > 
> > > > Anyways after Bjorn pointed out inconsistency, I am thinking of moving
> > > > all the values to unsigned long to work with both 32bit and 64bit.
> > > > 
> > > > Does the below delta on top of this patch works for you and makes sense?
> > > This looks good to me. Will do some testing and float v6 with the changes
> > > you suggested below. Thanks
> > > 
> > Please refer or use the patch from [1] when reposting. I rebased on my
> > patch[2] that I posted few minutes back. I am trying to finalise the branch
> > and send PR in next couple of days, so please test and post sooner. Sorry
> > for the rush.
> 
> Validated the patch from [1] below on Qualcomm ARM64 virtual platform using
> SMC64 convention. Thanks!
>

Thanks, since I have patched a bit, it is better if you post them so that
we have a link for the exact patch on the list. Just pick up the patches
from the branch[1] and post them as v6 with a change log so that all the
details are captured for reference purposes.

-- 
Regards,
Sudeep

[1] https://git.kernel.org/sudeep.holla/h/for-next/scmi/updates
[2] https://lore.kernel.org/r/20231009152049.1428872-1-sudeep.holla@arm.com

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 19:08               ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-09 19:08 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 09, 2023 at 10:49:44AM -0700, Nikunj Kela wrote:
> 
> On 10/9/2023 8:29 AM, Sudeep Holla wrote:
> > On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
> > > On 10/9/2023 7:47 AM, Sudeep Holla wrote:
> > > > On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
> > > > > This change adds the support for SCMI message exchange on Qualcomm
> > > > > virtual platforms.
> > > > > 
> > > > > The hypervisor associates an object-id also known as capability-id
> > > > > with each smc/hvc doorbell object. The capability-id is used to
> > > > > identify the doorbell from the VM's capability namespace, similar
> > > > > to a file-descriptor.
> > > > > 
> > > > > The hypervisor, in addition to the function-id, expects the capability-id
> > > > > to be passed in x1 register when SMC/HVC call is invoked.
> > > > > 
> > > > > The capability-id is allocated by the hypervisor on bootup and is stored in
> > > > > the shmem region by the firmware before starting Linux.
> > > > > 
> > > > Since you are happy to move to signed value, I assume you are happy to loose
> > > > upper half of the range values ?
> > > > 
> > > > Anyways after Bjorn pointed out inconsistency, I am thinking of moving
> > > > all the values to unsigned long to work with both 32bit and 64bit.
> > > > 
> > > > Does the below delta on top of this patch works for you and makes sense?
> > > This looks good to me. Will do some testing and float v6 with the changes
> > > you suggested below. Thanks
> > > 
> > Please refer or use the patch from [1] when reposting. I rebased on my
> > patch[2] that I posted few minutes back. I am trying to finalise the branch
> > and send PR in next couple of days, so please test and post sooner. Sorry
> > for the rush.
> 
> Validated the patch from [1] below on Qualcomm ARM64 virtual platform using
> SMC64 convention. Thanks!
>

Thanks, since I have patched a bit, it is better if you post them so that
we have a link for the exact patch on the list. Just pick up the patches
from the branch[1] and post them as v6 with a change log so that all the
details are captured for reference purposes.

-- 
Regards,
Sudeep

[1] https://git.kernel.org/sudeep.holla/h/for-next/scmi/updates
[2] https://lore.kernel.org/r/20231009152049.1428872-1-sudeep.holla@arm.com

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

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

* [PATCH v6 0/2] Add qcom smc/hvc transport support
  2023-07-18 16:08 ` Nikunj Kela
@ 2023-10-09 19:14   ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:14 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change augments smc transport to include support for Qualcomm virtual
platforms by passing a parameter(capability-id) in the hypervisor call to
identify which doorbell to assert. This parameter is dynamically generated
at runtime on the device and insuitable to pass via the devicetree.

The capability-id is stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v6 -> use unsigned long for cap-id

v5 -> changed compatible, removed polling support patch,
      make use of smc-id binding for function-id

v4 -> port the changes into smc.c

v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (2):
  dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  firmware: arm_scmi: Add qcom smc/hvc transport support

 .../bindings/firmware/arm,scmi.yaml           |  4 +++
 drivers/firmware/arm_scmi/driver.c            |  1 +
 drivers/firmware/arm_scmi/smc.c               | 27 +++++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

-- 
2.17.1


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

* [PATCH v6 0/2] Add qcom smc/hvc transport support
@ 2023-10-09 19:14   ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:14 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change augments smc transport to include support for Qualcomm virtual
platforms by passing a parameter(capability-id) in the hypervisor call to
identify which doorbell to assert. This parameter is dynamically generated
at runtime on the device and insuitable to pass via the devicetree.

The capability-id is stored by firmware in the shmem region.

This has been tested on ARM64 virtual Qualcomm platform.

---
v6 -> use unsigned long for cap-id

v5 -> changed compatible, removed polling support patch,
      make use of smc-id binding for function-id

v4 -> port the changes into smc.c

v3 -> fix the compilation error reported by the test bot,
      add support for polling based instances

v2 -> use allOf construct in dtb schema,
      remove wrappers from mutexes,
      use architecture independent channel layout

v1 -> original patches

Nikunj Kela (2):
  dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  firmware: arm_scmi: Add qcom smc/hvc transport support

 .../bindings/firmware/arm,scmi.yaml           |  4 +++
 drivers/firmware/arm_scmi/driver.c            |  1 +
 drivers/firmware/arm_scmi/smc.c               | 27 +++++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

-- 
2.17.1


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

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

* [PATCH v6 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-09 19:14   ` Nikunj Kela
@ 2023-10-09 19:14     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:14 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
Qualcomm virtual platforms.

This compatible mandates populating an additional parameter 'capability-id'
from the last 8 bytes of the shmem channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 Documentation/devicetree/bindings/firmware/arm,scmi.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 563a87dfb31a..4591523b51a0 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -38,6 +38,9 @@ properties:
                      with shmem address(4KB-page, offset) as parameters
         items:
           - const: arm,scmi-smc-param
+      - description: SCMI compliant firmware with Qualcomm SMC/HVC transport
+        items:
+          - const: qcom,scmi-smc
       - description: SCMI compliant firmware with SCMI Virtio transport.
                      The virtio transport only supports a single device.
         items:
@@ -313,6 +316,7 @@ else:
           enum:
             - arm,scmi-smc
             - arm,scmi-smc-param
+            - qcom,scmi-smc
   then:
     required:
       - arm,smc-id
-- 
2.17.1


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

* [PATCH v6 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-09 19:14     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:14 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport channel for
Qualcomm virtual platforms.

This compatible mandates populating an additional parameter 'capability-id'
from the last 8 bytes of the shmem channel.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 Documentation/devicetree/bindings/firmware/arm,scmi.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
index 563a87dfb31a..4591523b51a0 100644
--- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
+++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml
@@ -38,6 +38,9 @@ properties:
                      with shmem address(4KB-page, offset) as parameters
         items:
           - const: arm,scmi-smc-param
+      - description: SCMI compliant firmware with Qualcomm SMC/HVC transport
+        items:
+          - const: qcom,scmi-smc
       - description: SCMI compliant firmware with SCMI Virtio transport.
                      The virtio transport only supports a single device.
         items:
@@ -313,6 +316,7 @@ else:
           enum:
             - arm,scmi-smc
             - arm,scmi-smc-param
+            - qcom,scmi-smc
   then:
     required:
       - arm,smc-id
-- 
2.17.1


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

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

* [PATCH v6 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 19:14   ` Nikunj Kela
@ 2023-10-09 19:14     ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:14 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change adds the support for SCMI message exchange on Qualcomm
virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each smc/hvc doorbell object. The capability-id is used to
identify the doorbell from the VM's capability namespace, similar
to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when SMC/HVC call is invoked.

The capability-id is allocated by the hypervisor on bootup and is stored in
the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/firmware/arm_scmi/driver.c |  1 +
 drivers/firmware/arm_scmi/smc.c    | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 87383c05424b..09371f40d61f 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
 	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
 	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
+	{ .compatible = "qcom,scmi-smc", .data = &scmi_smc_desc},
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index 8eba60a41975..7611e9665038 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
+#include <linux/limits.h>
 #include <linux/processor.h>
 #include <linux/slab.h>
 
@@ -50,6 +51,8 @@
  * @func_id: smc/hvc call function id
  * @param_page: 4K page number of the shmem channel
  * @param_offset: Offset within the 4K page of the shmem channel
+ * @cap_id: smc/hvc doorbell's capability id to be used on Qualcomm virtual
+ *	    platforms
  */
 
 struct scmi_smc {
@@ -63,6 +66,7 @@ struct scmi_smc {
 	unsigned long func_id;
 	unsigned long param_page;
 	unsigned long param_offset;
+	unsigned long cap_id;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -124,6 +128,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 			  bool tx)
 {
 	struct device *cdev = cinfo->dev;
+	unsigned long cap_id = ULONG_MAX;
 	struct scmi_smc *scmi_info;
 	resource_size_t size;
 	struct resource res;
@@ -162,6 +167,18 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	if (ret < 0)
 		return ret;
 
+	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
+		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
+		/* The capability-id is kept in last 8 bytes of shmem.
+		 *     +-------+ <-- 0
+		 *     | shmem |
+		 *     +-------+ <-- size - 8
+		 *     | capId |
+		 *     +-------+ <-- size
+		 */
+		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
+	}
+
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
 		scmi_info->param_page = SHMEM_PAGE(res.start);
 		scmi_info->param_offset = SHMEM_OFFSET(res.start);
@@ -184,6 +201,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	}
 
 	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
 	scmi_info->cinfo = cinfo;
 	smc_channel_lock_init(scmi_info);
 	cinfo->transport_info = scmi_info;
@@ -220,8 +238,13 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
-			     scmi_info->param_offset, 0, 0, 0, 0, 0, &res);
+	if (scmi_info->cap_id != ULONG_MAX)
+		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->cap_id, 0,
+				     0, 0, 0, 0, 0, &res);
+	else
+		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
+				     scmi_info->param_offset, 0, 0, 0, 0, 0,
+				     &res);
 
 	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
 	if (res.a0) {
-- 
2.17.1


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

* [PATCH v6 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 19:14     ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:14 UTC (permalink / raw)
  To: sudeep.holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm, Nikunj Kela

This change adds the support for SCMI message exchange on Qualcomm
virtual platforms.

The hypervisor associates an object-id also known as capability-id
with each smc/hvc doorbell object. The capability-id is used to
identify the doorbell from the VM's capability namespace, similar
to a file-descriptor.

The hypervisor, in addition to the function-id, expects the capability-id
to be passed in x1 register when SMC/HVC call is invoked.

The capability-id is allocated by the hypervisor on bootup and is stored in
the shmem region by the firmware before starting Linux.

Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/firmware/arm_scmi/driver.c |  1 +
 drivers/firmware/arm_scmi/smc.c    | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 87383c05424b..09371f40d61f 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
 	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
 	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
+	{ .compatible = "qcom,scmi-smc", .data = &scmi_smc_desc},
 #endif
 #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
 	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index 8eba60a41975..7611e9665038 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
+#include <linux/limits.h>
 #include <linux/processor.h>
 #include <linux/slab.h>
 
@@ -50,6 +51,8 @@
  * @func_id: smc/hvc call function id
  * @param_page: 4K page number of the shmem channel
  * @param_offset: Offset within the 4K page of the shmem channel
+ * @cap_id: smc/hvc doorbell's capability id to be used on Qualcomm virtual
+ *	    platforms
  */
 
 struct scmi_smc {
@@ -63,6 +66,7 @@ struct scmi_smc {
 	unsigned long func_id;
 	unsigned long param_page;
 	unsigned long param_offset;
+	unsigned long cap_id;
 };
 
 static irqreturn_t smc_msg_done_isr(int irq, void *data)
@@ -124,6 +128,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 			  bool tx)
 {
 	struct device *cdev = cinfo->dev;
+	unsigned long cap_id = ULONG_MAX;
 	struct scmi_smc *scmi_info;
 	resource_size_t size;
 	struct resource res;
@@ -162,6 +167,18 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	if (ret < 0)
 		return ret;
 
+	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
+		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
+		/* The capability-id is kept in last 8 bytes of shmem.
+		 *     +-------+ <-- 0
+		 *     | shmem |
+		 *     +-------+ <-- size - 8
+		 *     | capId |
+		 *     +-------+ <-- size
+		 */
+		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
+	}
+
 	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
 		scmi_info->param_page = SHMEM_PAGE(res.start);
 		scmi_info->param_offset = SHMEM_OFFSET(res.start);
@@ -184,6 +201,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
 	}
 
 	scmi_info->func_id = func_id;
+	scmi_info->cap_id = cap_id;
 	scmi_info->cinfo = cinfo;
 	smc_channel_lock_init(scmi_info);
 	cinfo->transport_info = scmi_info;
@@ -220,8 +238,13 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
 
 	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
 
-	arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
-			     scmi_info->param_offset, 0, 0, 0, 0, 0, &res);
+	if (scmi_info->cap_id != ULONG_MAX)
+		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->cap_id, 0,
+				     0, 0, 0, 0, 0, &res);
+	else
+		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
+				     scmi_info->param_offset, 0, 0, 0, 0, 0,
+				     &res);
 
 	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
 	if (res.a0) {
-- 
2.17.1


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

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 19:08               ` Sudeep Holla
@ 2023-10-09 19:16                 ` Nikunj Kela
  -1 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:16 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 12:08 PM, Sudeep Holla wrote:
> On Mon, Oct 09, 2023 at 10:49:44AM -0700, Nikunj Kela wrote:
>> On 10/9/2023 8:29 AM, Sudeep Holla wrote:
>>> On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
>>>> On 10/9/2023 7:47 AM, Sudeep Holla wrote:
>>>>> On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
>>>>>> This change adds the support for SCMI message exchange on Qualcomm
>>>>>> virtual platforms.
>>>>>>
>>>>>> The hypervisor associates an object-id also known as capability-id
>>>>>> with each smc/hvc doorbell object. The capability-id is used to
>>>>>> identify the doorbell from the VM's capability namespace, similar
>>>>>> to a file-descriptor.
>>>>>>
>>>>>> The hypervisor, in addition to the function-id, expects the capability-id
>>>>>> to be passed in x1 register when SMC/HVC call is invoked.
>>>>>>
>>>>>> The capability-id is allocated by the hypervisor on bootup and is stored in
>>>>>> the shmem region by the firmware before starting Linux.
>>>>>>
>>>>> Since you are happy to move to signed value, I assume you are happy to loose
>>>>> upper half of the range values ?
>>>>>
>>>>> Anyways after Bjorn pointed out inconsistency, I am thinking of moving
>>>>> all the values to unsigned long to work with both 32bit and 64bit.
>>>>>
>>>>> Does the below delta on top of this patch works for you and makes sense?
>>>> This looks good to me. Will do some testing and float v6 with the changes
>>>> you suggested below. Thanks
>>>>
>>> Please refer or use the patch from [1] when reposting. I rebased on my
>>> patch[2] that I posted few minutes back. I am trying to finalise the branch
>>> and send PR in next couple of days, so please test and post sooner. Sorry
>>> for the rush.
>> Validated the patch from [1] below on Qualcomm ARM64 virtual platform using
>> SMC64 convention. Thanks!
>>
> Thanks, since I have patched a bit, it is better if you post them so that
> we have a link for the exact patch on the list. Just pick up the patches
> from the branch[1] and post them as v6 with a change log so that all the
> details are captured for reference purposes.

v6 on its way, thanks!


>

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

* Re: [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-09 19:16                 ` Nikunj Kela
  0 siblings, 0 replies; 186+ messages in thread
From: Nikunj Kela @ 2023-10-09 19:16 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm


On 10/9/2023 12:08 PM, Sudeep Holla wrote:
> On Mon, Oct 09, 2023 at 10:49:44AM -0700, Nikunj Kela wrote:
>> On 10/9/2023 8:29 AM, Sudeep Holla wrote:
>>> On Mon, Oct 09, 2023 at 07:59:08AM -0700, Nikunj Kela wrote:
>>>> On 10/9/2023 7:47 AM, Sudeep Holla wrote:
>>>>> On Fri, Oct 06, 2023 at 09:42:06AM -0700, Nikunj Kela wrote:
>>>>>> This change adds the support for SCMI message exchange on Qualcomm
>>>>>> virtual platforms.
>>>>>>
>>>>>> The hypervisor associates an object-id also known as capability-id
>>>>>> with each smc/hvc doorbell object. The capability-id is used to
>>>>>> identify the doorbell from the VM's capability namespace, similar
>>>>>> to a file-descriptor.
>>>>>>
>>>>>> The hypervisor, in addition to the function-id, expects the capability-id
>>>>>> to be passed in x1 register when SMC/HVC call is invoked.
>>>>>>
>>>>>> The capability-id is allocated by the hypervisor on bootup and is stored in
>>>>>> the shmem region by the firmware before starting Linux.
>>>>>>
>>>>> Since you are happy to move to signed value, I assume you are happy to loose
>>>>> upper half of the range values ?
>>>>>
>>>>> Anyways after Bjorn pointed out inconsistency, I am thinking of moving
>>>>> all the values to unsigned long to work with both 32bit and 64bit.
>>>>>
>>>>> Does the below delta on top of this patch works for you and makes sense?
>>>> This looks good to me. Will do some testing and float v6 with the changes
>>>> you suggested below. Thanks
>>>>
>>> Please refer or use the patch from [1] when reposting. I rebased on my
>>> patch[2] that I posted few minutes back. I am trying to finalise the branch
>>> and send PR in next couple of days, so please test and post sooner. Sorry
>>> for the rush.
>> Validated the patch from [1] below on Qualcomm ARM64 virtual platform using
>> SMC64 convention. Thanks!
>>
> Thanks, since I have patched a bit, it is better if you post them so that
> we have a link for the exact patch on the list. Just pick up the patches
> from the branch[1] and post them as v6 with a change log so that all the
> details are captured for reference purposes.

v6 on its way, thanks!


>

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

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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
  2023-10-09 14:52         ` Nikunj Kela
@ 2023-10-09 21:03           ` Konrad Dybcio
  -1 siblings, 0 replies; 186+ messages in thread
From: Konrad Dybcio @ 2023-10-09 21:03 UTC (permalink / raw)
  To: Nikunj Kela, Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm



On 10/9/23 16:52, Nikunj Kela wrote:
> 
> On 10/9/2023 7:41 AM, Sudeep Holla wrote:
>> On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
>>> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport 
>>> channel for
>>> Qualcomm virtual platforms.
>>>
>>> This compatible mandates populating an additional parameter 
>>> 'capability-id'
>>> from the last 8 bytes of the shmem channel.
>>>
>> While I am happy with the simplification here, I am also bit nervous how
>> long before Qualcomm abandons this. I hope this is adopted as is in all
>> internal and downstream code without any modifications and this is not
>> just a push for upstreaming some change to minimise delta with internal/
>> downstream code.
>>
>> -- 
>> Regards,
>> Sudeep
> 
> Qualcomm is using patch on all the virtual auto platforms using 
> shmem/doorbell as scmi channel. This is already being used without any 
> modifications in our downstream code. No delta for this patch series. 
> Thanks!
AFAICT Sudeep is looking for a solid guarantee that it will continue to 
be used as-is, on more than one platform and on more than one BSP version.

There have been cases where such firmware interfaces had silent ABI 
breaks (or were replaced altogether) between qc downstream branches and 
this would be unacceptable. Understandably, having a unified means of 
communication for *all* Qualcomm chips (i.e. not only auto) going 
forward would likely be expected..

Konrad

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

* Re: [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
@ 2023-10-09 21:03           ` Konrad Dybcio
  0 siblings, 0 replies; 186+ messages in thread
From: Konrad Dybcio @ 2023-10-09 21:03 UTC (permalink / raw)
  To: Nikunj Kela, Sudeep Holla
  Cc: cristian.marussi, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	andersson, linux-arm-kernel, devicetree, linux-kernel,
	linux-arm-msm



On 10/9/23 16:52, Nikunj Kela wrote:
> 
> On 10/9/2023 7:41 AM, Sudeep Holla wrote:
>> On Fri, Oct 06, 2023 at 09:42:05AM -0700, Nikunj Kela wrote:
>>> Introduce compatible "qcom,scmi-smc" for SCMI smc/hvc transport 
>>> channel for
>>> Qualcomm virtual platforms.
>>>
>>> This compatible mandates populating an additional parameter 
>>> 'capability-id'
>>> from the last 8 bytes of the shmem channel.
>>>
>> While I am happy with the simplification here, I am also bit nervous how
>> long before Qualcomm abandons this. I hope this is adopted as is in all
>> internal and downstream code without any modifications and this is not
>> just a push for upstreaming some change to minimise delta with internal/
>> downstream code.
>>
>> -- 
>> Regards,
>> Sudeep
> 
> Qualcomm is using patch on all the virtual auto platforms using 
> shmem/doorbell as scmi channel. This is already being used without any 
> modifications in our downstream code. No delta for this patch series. 
> Thanks!
AFAICT Sudeep is looking for a solid guarantee that it will continue to 
be used as-is, on more than one platform and on more than one BSP version.

There have been cases where such firmware interfaces had silent ABI 
breaks (or were replaced altogether) between qc downstream branches and 
this would be unacceptable. Understandably, having a unified means of 
communication for *all* Qualcomm chips (i.e. not only auto) going 
forward would likely be expected..

Konrad

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

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

* Re: [PATCH v6 0/2] Add qcom smc/hvc transport support
  2023-10-09 19:14   ` Nikunj Kela
@ 2023-10-10 10:21     ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-10 10:21 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Sudeep Holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, 09 Oct 2023 12:14:35 -0700, Nikunj Kela wrote:
> This change augments smc transport to include support for Qualcomm virtual
> platforms by passing a parameter(capability-id) in the hypervisor call to
> identify which doorbell to assert. This parameter is dynamically generated
> at runtime on the device and insuitable to pass via the devicetree.
>
> The capability-id is stored by firmware in the shmem region.
>
> [...]

Applied to sudeep.holla/linux (for-next/scmi/updates), thanks!

[1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
      https://git.kernel.org/sudeep.holla/c/6979f88f5a8e
[2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
      https://git.kernel.org/sudeep.holla/c/da405477e767
--
Regards,
Sudeep


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

* Re: [PATCH v6 0/2] Add qcom smc/hvc transport support
@ 2023-10-10 10:21     ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-10 10:21 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: Sudeep Holla, cristian.marussi, robh+dt, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, 09 Oct 2023 12:14:35 -0700, Nikunj Kela wrote:
> This change augments smc transport to include support for Qualcomm virtual
> platforms by passing a parameter(capability-id) in the hypervisor call to
> identify which doorbell to assert. This parameter is dynamically generated
> at runtime on the device and insuitable to pass via the devicetree.
>
> The capability-id is stored by firmware in the shmem region.
>
> [...]

Applied to sudeep.holla/linux (for-next/scmi/updates), thanks!

[1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI
      https://git.kernel.org/sudeep.holla/c/6979f88f5a8e
[2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
      https://git.kernel.org/sudeep.holla/c/da405477e767
--
Regards,
Sudeep


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

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

* Re: [PATCH v6 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
  2023-10-09 19:14     ` Nikunj Kela
@ 2023-10-10 10:42       ` Sudeep Holla
  -1 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-10 10:42 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 09, 2023 at 12:14:37PM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each smc/hvc doorbell object. The capability-id is used to
> identify the doorbell from the VM's capability namespace, similar
> to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when SMC/HVC call is invoked.
> 
> The capability-id is allocated by the hypervisor on bootup and is stored in
> the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> Reviewed-by: Brian Masney <bmasney@redhat.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

FYI for the next time. When posting on the list, the senders sign-off must
be the last. The only reason I signed off is because it is needed as part
of committer in the git repo. You should have ideally dropped it in this case.
If there was some other author/co-developer of the patch, then your signoff
will be always at the end as you are sending the patch.

Refer "Sign your work - the Developer's Certificate of Origin" section
in Documentation/process/submitting-patches.rst

> ---
>  drivers/firmware/arm_scmi/driver.c |  1 +
>  drivers/firmware/arm_scmi/smc.c    | 27 +++++++++++++++++++++++++--
>  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 87383c05424b..09371f40d61f 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>  	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>  	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> +	{ .compatible = "qcom,scmi-smc", .data = &scmi_smc_desc},
>  #endif
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>  	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 8eba60a41975..7611e9665038 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -15,6 +15,7 @@
>  #include <linux/of.h>
>  #include <linux/of_address.h>
>  #include <linux/of_irq.h>
> +#include <linux/limits.h>
>  #include <linux/processor.h>
>  #include <linux/slab.h>
>  
> @@ -50,6 +51,8 @@
>   * @func_id: smc/hvc call function id
>   * @param_page: 4K page number of the shmem channel
>   * @param_offset: Offset within the 4K page of the shmem channel
> + * @cap_id: smc/hvc doorbell's capability id to be used on Qualcomm virtual
> + *	    platforms
>   */
>  
>  struct scmi_smc {
> @@ -63,6 +66,7 @@ struct scmi_smc {
>  	unsigned long func_id;
>  	unsigned long param_page;
>  	unsigned long param_offset;
> +	unsigned long cap_id;
>  };
>  
>  static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -124,6 +128,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  			  bool tx)
>  {
>  	struct device *cdev = cinfo->dev;
> +	unsigned long cap_id = ULONG_MAX;
>  	struct scmi_smc *scmi_info;
>  	resource_size_t size;
>  	struct resource res;
> @@ -162,6 +167,18 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	if (ret < 0)
>  		return ret;
>  
> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
> +		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
> +		/* The capability-id is kept in last 8 bytes of shmem.
> +		 *     +-------+ <-- 0
> +		 *     | shmem |
> +		 *     +-------+ <-- size - 8
> +		 *     | capId |
> +		 *     +-------+ <-- size
> +		 */
> +		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
> +	}
> +
>  	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>  		scmi_info->param_page = SHMEM_PAGE(res.start);
>  		scmi_info->param_offset = SHMEM_OFFSET(res.start);
> @@ -184,6 +201,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	}
>  
>  	scmi_info->func_id = func_id;
> +	scmi_info->cap_id = cap_id;
>  	scmi_info->cinfo = cinfo;
>  	smc_channel_lock_init(scmi_info);
>  	cinfo->transport_info = scmi_info;
> @@ -220,8 +238,13 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>  
>  	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>  
> -	arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
> -			     scmi_info->param_offset, 0, 0, 0, 0, 0, &res);
> +	if (scmi_info->cap_id != ULONG_MAX)
> +		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->cap_id, 0,
> +				     0, 0, 0, 0, 0, &res);
> +	else
> +		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
> +				     scmi_info->param_offset, 0, 0, 0, 0, 0,
> +				     &res);
>  
>  	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>  	if (res.a0) {
> -- 
> 2.17.1
> 

-- 
Regards,
Sudeep

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

* Re: [PATCH v6 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support
@ 2023-10-10 10:42       ` Sudeep Holla
  0 siblings, 0 replies; 186+ messages in thread
From: Sudeep Holla @ 2023-10-10 10:42 UTC (permalink / raw)
  To: Nikunj Kela
  Cc: cristian.marussi, robh+dt, Sudeep Holla, krzysztof.kozlowski+dt,
	conor+dt, andersson, konrad.dybcio, linux-arm-kernel, devicetree,
	linux-kernel, linux-arm-msm

On Mon, Oct 09, 2023 at 12:14:37PM -0700, Nikunj Kela wrote:
> This change adds the support for SCMI message exchange on Qualcomm
> virtual platforms.
> 
> The hypervisor associates an object-id also known as capability-id
> with each smc/hvc doorbell object. The capability-id is used to
> identify the doorbell from the VM's capability namespace, similar
> to a file-descriptor.
> 
> The hypervisor, in addition to the function-id, expects the capability-id
> to be passed in x1 register when SMC/HVC call is invoked.
> 
> The capability-id is allocated by the hypervisor on bootup and is stored in
> the shmem region by the firmware before starting Linux.
> 
> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com>
> Reviewed-by: Brian Masney <bmasney@redhat.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

FYI for the next time. When posting on the list, the senders sign-off must
be the last. The only reason I signed off is because it is needed as part
of committer in the git repo. You should have ideally dropped it in this case.
If there was some other author/co-developer of the patch, then your signoff
will be always at the end as you are sending the patch.

Refer "Sign your work - the Developer's Certificate of Origin" section
in Documentation/process/submitting-patches.rst

> ---
>  drivers/firmware/arm_scmi/driver.c |  1 +
>  drivers/firmware/arm_scmi/smc.c    | 27 +++++++++++++++++++++++++--
>  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 87383c05424b..09371f40d61f 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -2915,6 +2915,7 @@ static const struct of_device_id scmi_of_match[] = {
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
>  	{ .compatible = "arm,scmi-smc", .data = &scmi_smc_desc},
>  	{ .compatible = "arm,scmi-smc-param", .data = &scmi_smc_desc},
> +	{ .compatible = "qcom,scmi-smc", .data = &scmi_smc_desc},
>  #endif
>  #ifdef CONFIG_ARM_SCMI_TRANSPORT_VIRTIO
>  	{ .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc},
> diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
> index 8eba60a41975..7611e9665038 100644
> --- a/drivers/firmware/arm_scmi/smc.c
> +++ b/drivers/firmware/arm_scmi/smc.c
> @@ -15,6 +15,7 @@
>  #include <linux/of.h>
>  #include <linux/of_address.h>
>  #include <linux/of_irq.h>
> +#include <linux/limits.h>
>  #include <linux/processor.h>
>  #include <linux/slab.h>
>  
> @@ -50,6 +51,8 @@
>   * @func_id: smc/hvc call function id
>   * @param_page: 4K page number of the shmem channel
>   * @param_offset: Offset within the 4K page of the shmem channel
> + * @cap_id: smc/hvc doorbell's capability id to be used on Qualcomm virtual
> + *	    platforms
>   */
>  
>  struct scmi_smc {
> @@ -63,6 +66,7 @@ struct scmi_smc {
>  	unsigned long func_id;
>  	unsigned long param_page;
>  	unsigned long param_offset;
> +	unsigned long cap_id;
>  };
>  
>  static irqreturn_t smc_msg_done_isr(int irq, void *data)
> @@ -124,6 +128,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  			  bool tx)
>  {
>  	struct device *cdev = cinfo->dev;
> +	unsigned long cap_id = ULONG_MAX;
>  	struct scmi_smc *scmi_info;
>  	resource_size_t size;
>  	struct resource res;
> @@ -162,6 +167,18 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	if (ret < 0)
>  		return ret;
>  
> +	if (of_device_is_compatible(dev->of_node, "qcom,scmi-smc")) {
> +		void __iomem *ptr = (void __iomem *)scmi_info->shmem + size - 8;
> +		/* The capability-id is kept in last 8 bytes of shmem.
> +		 *     +-------+ <-- 0
> +		 *     | shmem |
> +		 *     +-------+ <-- size - 8
> +		 *     | capId |
> +		 *     +-------+ <-- size
> +		 */
> +		memcpy_fromio(&cap_id, ptr, sizeof(cap_id));
> +	}
> +
>  	if (of_device_is_compatible(dev->of_node, "arm,scmi-smc-param")) {
>  		scmi_info->param_page = SHMEM_PAGE(res.start);
>  		scmi_info->param_offset = SHMEM_OFFSET(res.start);
> @@ -184,6 +201,7 @@ static int smc_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
>  	}
>  
>  	scmi_info->func_id = func_id;
> +	scmi_info->cap_id = cap_id;
>  	scmi_info->cinfo = cinfo;
>  	smc_channel_lock_init(scmi_info);
>  	cinfo->transport_info = scmi_info;
> @@ -220,8 +238,13 @@ static int smc_send_message(struct scmi_chan_info *cinfo,
>  
>  	shmem_tx_prepare(scmi_info->shmem, xfer, cinfo);
>  
> -	arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
> -			     scmi_info->param_offset, 0, 0, 0, 0, 0, &res);
> +	if (scmi_info->cap_id != ULONG_MAX)
> +		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->cap_id, 0,
> +				     0, 0, 0, 0, 0, &res);
> +	else
> +		arm_smccc_1_1_invoke(scmi_info->func_id, scmi_info->param_page,
> +				     scmi_info->param_offset, 0, 0, 0, 0, 0,
> +				     &res);
>  
>  	/* Only SMCCC_RET_NOT_SUPPORTED is valid error code */
>  	if (res.a0) {
> -- 
> 2.17.1
> 

-- 
Regards,
Sudeep

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

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

end of thread, other threads:[~2023-10-10 10:43 UTC | newest]

Thread overview: 186+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 16:08 [PATCH 0/2] Add qcom hvc/shmem transport Nikunj Kela
2023-07-18 16:08 ` Nikunj Kela
2023-07-18 16:08 ` [PATCH 1/2] dt-bindings: arm: Add qcom specific hvc transport for SCMI Nikunj Kela
2023-07-18 16:08   ` Nikunj Kela
2023-07-18 17:21   ` Rob Herring
2023-07-18 17:21     ` Rob Herring
2023-07-18 18:12   ` Krzysztof Kozlowski
2023-07-18 18:12     ` Krzysztof Kozlowski
2023-07-18 18:18     ` Nikunj Kela
2023-07-18 18:18       ` Nikunj Kela
2023-07-19 10:39   ` Sudeep Holla
2023-07-19 10:39     ` Sudeep Holla
2023-07-19 13:58     ` Nikunj Kela
2023-07-19 13:58       ` Nikunj Kela
2023-07-18 16:08 ` [PATCH 2/2] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
2023-07-18 16:08   ` Nikunj Kela
2023-07-18 18:17   ` Krzysztof Kozlowski
2023-07-18 18:17     ` Krzysztof Kozlowski
2023-07-18 18:25     ` Nikunj Kela
2023-07-18 18:25       ` Nikunj Kela
2023-07-18 18:42       ` Krzysztof Kozlowski
2023-07-18 18:42         ` Krzysztof Kozlowski
2023-07-18 21:16         ` Nikunj Kela
2023-07-18 21:16           ` Nikunj Kela
2023-07-19  6:15           ` Krzysztof Kozlowski
2023-07-19  6:15             ` Krzysztof Kozlowski
2023-07-18 18:29   ` Bjorn Andersson
2023-07-18 18:29     ` Bjorn Andersson
2023-07-18 18:53     ` Nikunj Kela
2023-07-18 18:53       ` Nikunj Kela
2023-07-18 19:07       ` Bjorn Andersson
2023-07-18 19:07         ` Bjorn Andersson
2023-07-18 19:10         ` Nikunj Kela
2023-07-18 19:10           ` Nikunj Kela
2023-07-18 19:30           ` Bjorn Andersson
2023-07-18 19:30             ` Bjorn Andersson
2023-07-18 22:05             ` Nikunj Kela
2023-07-18 22:05               ` Nikunj Kela
2023-07-19 10:55       ` Cristian Marussi
2023-07-19 10:55         ` Cristian Marussi
2023-07-19 14:02         ` Nikunj Kela
2023-07-19 14:02           ` Nikunj Kela
2023-07-23  2:15   ` kernel test robot
2023-07-23  2:15     ` kernel test robot
2023-07-24 16:44 ` [PATCH v2 0/3] " Nikunj Kela
2023-07-24 16:44   ` [PATCH v2 1/3] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
2023-07-25  6:01     ` Krzysztof Kozlowski
2023-07-24 16:44   ` [PATCH v2 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI Nikunj Kela
2023-07-25  6:06     ` Krzysztof Kozlowski
2023-07-24 16:44   ` [PATCH v2 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
2023-07-25 17:03     ` Cristian Marussi
2023-07-25 17:12       ` Nikunj Kela
2023-07-31 14:04         ` Nikunj Kela
2023-07-31 14:04           ` Nikunj Kela
2023-08-01  7:27     ` kernel test robot
2023-08-01  7:27       ` kernel test robot
2023-08-11 17:57 ` [PATCH v3 0/3] " Nikunj Kela
2023-08-11 17:57   ` Nikunj Kela
2023-08-11 17:57   ` [PATCH v3 1/3] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
2023-08-11 17:57     ` Nikunj Kela
2023-08-11 17:57   ` [PATCH v3 2/3] dt-bindings: arm: Add qcom specific hvc transport for SCMI Nikunj Kela
2023-08-11 17:57     ` Nikunj Kela
2023-08-11 17:57   ` [PATCH v3 3/3] firmware: arm_scmi: Add qcom hvc/shmem transport Nikunj Kela
2023-08-11 17:57     ` Nikunj Kela
2023-09-05 16:06   ` [PATCH v3 0/3] " Nikunj Kela
2023-09-05 16:06     ` Nikunj Kela
2023-09-05 16:37     ` Krzysztof Kozlowski
2023-09-05 16:37       ` Krzysztof Kozlowski
2023-09-07 10:36       ` Sudeep Holla
2023-09-07 10:36         ` Sudeep Holla
2023-09-07 14:20         ` Nikunj Kela
2023-09-07 14:20           ` Nikunj Kela
2023-09-07 16:16 ` [PATCH 0/2] " Konrad Dybcio
2023-09-07 16:16   ` Konrad Dybcio
2023-09-07 22:32   ` Nikunj Kela
2023-09-07 22:32     ` Nikunj Kela
2023-09-11 19:43 ` [PATCH v4 0/4] Add qcom hvc/shmem transport support Nikunj Kela
2023-09-11 19:43   ` Nikunj Kela
2023-09-11 19:43   ` [PATCH v4 1/4] firmware: arm_scmi: Add polling support for completion in smc Nikunj Kela
2023-09-11 19:43     ` Nikunj Kela
2023-10-02 18:18     ` Brian Masney
2023-10-02 18:18       ` Brian Masney
2023-10-02 18:36       ` Nikunj Kela
2023-10-02 18:36         ` Nikunj Kela
2023-10-03 10:33     ` Sudeep Holla
2023-10-03 10:33       ` Sudeep Holla
2023-10-03 10:50       ` Cristian Marussi
2023-10-03 10:50         ` Cristian Marussi
2023-10-03 15:53       ` Nikunj Kela
2023-10-03 15:53         ` Nikunj Kela
2023-10-04 16:11         ` Sudeep Holla
2023-10-04 16:11           ` Sudeep Holla
2023-10-05  3:25           ` Nikunj Kela
2023-10-05  3:25             ` Nikunj Kela
2023-09-11 19:43   ` [PATCH v4 2/4] dt-bindings: arm: convert nested if-else construct to allOf Nikunj Kela
2023-09-11 19:43     ` Nikunj Kela
2023-09-11 19:43   ` [PATCH v4 3/4] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI Nikunj Kela
2023-09-11 19:43     ` Nikunj Kela
2023-10-03 10:44     ` Sudeep Holla
2023-10-03 10:44       ` Sudeep Holla
2023-10-03 15:59       ` Nikunj Kela
2023-10-03 15:59         ` Nikunj Kela
2023-10-04 15:53         ` Sudeep Holla
2023-10-04 15:53           ` Sudeep Holla
2023-10-05 21:51           ` Nikunj Kela
2023-10-05 21:51             ` Nikunj Kela
2023-09-11 19:43   ` [PATCH v4 4/4] firmware: arm_scmi: Add qcom hvc/shmem transport support Nikunj Kela
2023-09-11 19:43     ` Nikunj Kela
2023-10-02 18:34     ` Brian Masney
2023-10-02 18:34       ` Brian Masney
2023-10-02 18:39       ` Brian Masney
2023-10-02 18:39         ` Brian Masney
2023-10-02 18:45         ` Nikunj Kela
2023-10-02 18:45           ` Nikunj Kela
2023-10-02 18:42       ` Nikunj Kela
2023-10-02 18:42         ` Nikunj Kela
2023-10-03 10:48         ` Sudeep Holla
2023-10-03 10:48           ` Sudeep Holla
2023-10-03 11:19     ` Sudeep Holla
2023-10-03 11:19       ` Sudeep Holla
2023-10-03 16:16       ` Nikunj Kela
2023-10-03 16:16         ` Nikunj Kela
2023-10-04 16:06         ` Sudeep Holla
2023-10-04 16:06           ` Sudeep Holla
2023-10-04 17:48           ` Nikunj Kela
2023-10-04 17:48             ` Nikunj Kela
2023-10-05 22:20           ` Bjorn Andersson
2023-10-05 22:20             ` Bjorn Andersson
2023-10-05 22:33             ` Nikunj Kela
2023-10-05 22:33               ` Nikunj Kela
2023-10-06  7:26             ` Sudeep Holla
2023-10-06  7:26               ` Sudeep Holla
2023-09-18 15:01   ` [PATCH v4 0/4] " Nikunj Kela
2023-09-18 15:01     ` Nikunj Kela
2023-09-18 15:15     ` Sudeep Holla
2023-09-18 15:15       ` Sudeep Holla
2023-09-18 15:54       ` Brian Masney
2023-09-18 15:54         ` Brian Masney
2023-09-19  8:56         ` Sudeep Holla
2023-09-19  8:56           ` Sudeep Holla
2023-10-02 17:31           ` Nikunj Kela
2023-10-02 17:31             ` Nikunj Kela
2023-10-02 17:58             ` Cristian Marussi
2023-10-02 17:58               ` Cristian Marussi
2023-10-03 10:34             ` Sudeep Holla
2023-10-03 10:34               ` Sudeep Holla
2023-09-18 20:32     ` Krzysztof Kozlowski
2023-09-18 20:32       ` Krzysztof Kozlowski
2023-10-06 16:42 ` [PATCH v5 0/2] Add qcom smc/hvc " Nikunj Kela
2023-10-06 16:42   ` Nikunj Kela
2023-10-06 16:42   ` [PATCH v5 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI Nikunj Kela
2023-10-06 16:42     ` Nikunj Kela
2023-10-06 20:08     ` Brian Masney
2023-10-06 20:08       ` Brian Masney
2023-10-09 14:41     ` Sudeep Holla
2023-10-09 14:41       ` Sudeep Holla
2023-10-09 14:52       ` Nikunj Kela
2023-10-09 14:52         ` Nikunj Kela
2023-10-09 21:03         ` Konrad Dybcio
2023-10-09 21:03           ` Konrad Dybcio
2023-10-06 16:42   ` [PATCH v5 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support Nikunj Kela
2023-10-06 16:42     ` Nikunj Kela
2023-10-06 20:17     ` Brian Masney
2023-10-06 20:17       ` Brian Masney
2023-10-09 14:47     ` Sudeep Holla
2023-10-09 14:47       ` Sudeep Holla
2023-10-09 14:59       ` Nikunj Kela
2023-10-09 14:59         ` Nikunj Kela
2023-10-09 15:29         ` Sudeep Holla
2023-10-09 15:29           ` Sudeep Holla
2023-10-09 17:49           ` Nikunj Kela
2023-10-09 17:49             ` Nikunj Kela
2023-10-09 19:08             ` Sudeep Holla
2023-10-09 19:08               ` Sudeep Holla
2023-10-09 19:16               ` Nikunj Kela
2023-10-09 19:16                 ` Nikunj Kela
2023-10-09 19:14 ` [PATCH v6 0/2] " Nikunj Kela
2023-10-09 19:14   ` Nikunj Kela
2023-10-09 19:14   ` [PATCH v6 1/2] dt-bindings: arm: Add new compatible for smc/hvc transport for SCMI Nikunj Kela
2023-10-09 19:14     ` Nikunj Kela
2023-10-09 19:14   ` [PATCH v6 2/2] firmware: arm_scmi: Add qcom smc/hvc transport support Nikunj Kela
2023-10-09 19:14     ` Nikunj Kela
2023-10-10 10:42     ` Sudeep Holla
2023-10-10 10:42       ` Sudeep Holla
2023-10-10 10:21   ` [PATCH v6 0/2] " Sudeep Holla
2023-10-10 10:21     ` Sudeep Holla

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.