Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver
@ 2024-06-06 19:18 Luca Weiss
  2024-06-06 19:18 ` [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc Luca Weiss
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Luca Weiss @ 2024-06-06 19:18 UTC (permalink / raw)
  To: ~postmarketos/upstreaming, phone-devel, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Andy Gross
  Cc: Krzysztof Kozlowski, linux-arm-msm, devicetree, linux-kernel,
	Luca Weiss

Take a shot at converting the last driver that requires direct
"qcom,ipc*" syscon references in devicetree by allowing the smsm driver
to use the mailbox interface to achieve the same effect.

Still not sure if the devicetree bindings are the prettiest but they're
functional.

One alternative I'm thinking of is to use mbox-names to not have <0>
elements in dt, and reference the items by name from the driver?

e.g. this change for msm8226 could be represented differently.

-		qcom,ipc-1 = <&apcs 8 13>;
-		qcom,ipc-2 = <&apcs 8 9>;
-		qcom,ipc-3 = <&apcs 8 19>;
+		mboxes = <0>, <&apcs 13>, <&apcs 9>, <&apcs 19>;

vs. for example:

-		qcom,ipc-1 = <&apcs 8 13>;
-		qcom,ipc-2 = <&apcs 8 9>;
-		qcom,ipc-3 = <&apcs 8 19>;
+		mboxes = <&apcs 13>, <&apcs 9>, <&apcs 19>;
+		mbox-names = "ipc-1", "ipc-2", "ipc-3";

But also here the name with 'ipc-N' is probably not particularly
fitting?

Please let me know your thoughts and any suggestions.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
Changes in v2:
- Mark qcom,ipc-N as deprecated
- Update & expand description for mboxes property
- Don't duplicate example, just update existing one since qcom,ipc-N is
  deprecated now anyways
- Pick up tags
- Link to v1: https://lore.kernel.org/r/20240424-smsm-mbox-v1-0-555f3f442841@z3ntu.xyz

---
Luca Weiss (2):
      dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc
      soc: qcom: smsm: Support using mailbox interface

 .../devicetree/bindings/soc/qcom/qcom,smsm.yaml    | 30 +++++++++----
 drivers/soc/qcom/smsm.c                            | 51 +++++++++++++++++++++-
 2 files changed, 71 insertions(+), 10 deletions(-)
---
base-commit: ee78a17615ad0cfdbbc27182b1047cd36c9d4d5f
change-id: 20240424-smsm-mbox-0666f35eae44

Best regards,
-- 
Luca Weiss <luca@z3ntu.xyz>


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

* [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc
  2024-06-06 19:18 [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Luca Weiss
@ 2024-06-06 19:18 ` Luca Weiss
  2024-06-07  7:24   ` Krzysztof Kozlowski
  2024-06-06 19:18 ` [PATCH v2 2/2] soc: qcom: smsm: Support using mailbox interface Luca Weiss
  2024-06-14 22:48 ` [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Bjorn Andersson
  2 siblings, 1 reply; 5+ messages in thread
From: Luca Weiss @ 2024-06-06 19:18 UTC (permalink / raw)
  To: ~postmarketos/upstreaming, phone-devel, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Andy Gross
  Cc: Krzysztof Kozlowski, linux-arm-msm, devicetree, linux-kernel,
	Luca Weiss

The qcom,ipc-N properties are essentially providing a reference to a
mailbox, so allow using the mboxes property to do the same in a more
structured way.

Since multiple SMSM hosts are supported, we need to be able to provide
the correct mailbox for each host. The old qcom,ipc-N properties map to
the mboxes property by index, starting at 0 since that's a valid SMSM
host also.

Mark the older qcom,ipc-N as deprecated and update the example with
mboxes.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
 .../devicetree/bindings/soc/qcom/qcom,smsm.yaml    | 30 +++++++++++++++-------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,smsm.yaml b/Documentation/devicetree/bindings/soc/qcom/qcom,smsm.yaml
index db67cf043256..4900215f26af 100644
--- a/Documentation/devicetree/bindings/soc/qcom/qcom,smsm.yaml
+++ b/Documentation/devicetree/bindings/soc/qcom/qcom,smsm.yaml
@@ -33,6 +33,14 @@ properties:
       specifier of the column in the subscription matrix representing the local
       processor.
 
+  mboxes:
+    minItems: 1
+    maxItems: 5
+    description:
+      Reference to the mailbox representing the outgoing doorbell in APCS for
+      this client. Each entry represents the N:th remote processor by index
+      (0-indexed).
+
   '#size-cells':
     const: 0
 
@@ -47,6 +55,7 @@ patternProperties:
     description:
       Three entries specifying the outgoing ipc bit used for signaling the N:th
       remote processor.
+    deprecated: true
 
   "@[0-9a-f]$":
     type: object
@@ -98,15 +107,18 @@ required:
   - '#address-cells'
   - '#size-cells'
 
-anyOf:
+oneOf:
   - required:
-      - qcom,ipc-1
-  - required:
-      - qcom,ipc-2
-  - required:
-      - qcom,ipc-3
-  - required:
-      - qcom,ipc-4
+      - mboxes
+  - anyOf:
+      - required:
+          - qcom,ipc-1
+      - required:
+          - qcom,ipc-2
+      - required:
+          - qcom,ipc-3
+      - required:
+          - qcom,ipc-4
 
 additionalProperties: false
 
@@ -122,7 +134,7 @@ examples:
         compatible = "qcom,smsm";
         #address-cells = <1>;
         #size-cells = <0>;
-        qcom,ipc-3 = <&apcs 8 19>;
+        mboxes = <0>, <0>, <0>, <&apcs 19>;
 
         apps_smsm: apps@0 {
             reg = <0>;

-- 
2.45.2


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

* [PATCH v2 2/2] soc: qcom: smsm: Support using mailbox interface
  2024-06-06 19:18 [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Luca Weiss
  2024-06-06 19:18 ` [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc Luca Weiss
@ 2024-06-06 19:18 ` Luca Weiss
  2024-06-14 22:48 ` [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Bjorn Andersson
  2 siblings, 0 replies; 5+ messages in thread
From: Luca Weiss @ 2024-06-06 19:18 UTC (permalink / raw)
  To: ~postmarketos/upstreaming, phone-devel, Bjorn Andersson,
	Konrad Dybcio, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Andy Gross
  Cc: Krzysztof Kozlowski, linux-arm-msm, devicetree, linux-kernel,
	Luca Weiss

Add support for using the mbox interface instead of manually writing to
the syscon. With this change the driver will attempt to get the mailbox
first, and if that fails it will fall back to the existing way of using
qcom,ipc-* properties and converting to syscon.

Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
 drivers/soc/qcom/smsm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/smsm.c b/drivers/soc/qcom/smsm.c
index e7c7e9a640a6..ffe78ae34386 100644
--- a/drivers/soc/qcom/smsm.c
+++ b/drivers/soc/qcom/smsm.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/mailbox_client.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of_irq.h>
@@ -71,6 +72,7 @@ struct smsm_host;
  * @lock:	spinlock for read-modify-write of the outgoing state
  * @entries:	context for each of the entries
  * @hosts:	context for each of the hosts
+ * @mbox_client: mailbox client handle
  */
 struct qcom_smsm {
 	struct device *dev;
@@ -88,6 +90,8 @@ struct qcom_smsm {
 
 	struct smsm_entry *entries;
 	struct smsm_host *hosts;
+
+	struct mbox_client mbox_client;
 };
 
 /**
@@ -120,11 +124,14 @@ struct smsm_entry {
  * @ipc_regmap:	regmap for outgoing interrupt
  * @ipc_offset:	offset in @ipc_regmap for outgoing interrupt
  * @ipc_bit:	bit in @ipc_regmap + @ipc_offset for outgoing interrupt
+ * @mbox_chan:	apcs ipc mailbox channel handle
  */
 struct smsm_host {
 	struct regmap *ipc_regmap;
 	int ipc_offset;
 	int ipc_bit;
+
+	struct mbox_chan *mbox_chan;
 };
 
 /**
@@ -172,7 +179,13 @@ static int smsm_update_bits(void *data, u32 mask, u32 value)
 		hostp = &smsm->hosts[host];
 
 		val = readl(smsm->subscription + host);
-		if (val & changes && hostp->ipc_regmap) {
+		if (!(val & changes))
+			continue;
+
+		if (hostp->mbox_chan) {
+			mbox_send_message(hostp->mbox_chan, NULL);
+			mbox_client_txdone(hostp->mbox_chan, 0);
+		} else if (hostp->ipc_regmap) {
 			regmap_write(hostp->ipc_regmap,
 				     hostp->ipc_offset,
 				     BIT(hostp->ipc_bit));
@@ -352,6 +365,28 @@ static const struct irq_domain_ops smsm_irq_ops = {
 	.xlate = irq_domain_xlate_twocell,
 };
 
+/**
+ * smsm_parse_mbox() - requests an mbox channel
+ * @smsm:	smsm driver context
+ * @host_id:	index of the remote host to be resolved
+ *
+ * Requests the desired channel using the mbox interface which is needed for
+ * sending the outgoing interrupts to a remove hosts - identified by @host_id.
+ */
+static int smsm_parse_mbox(struct qcom_smsm *smsm, unsigned int host_id)
+{
+	struct smsm_host *host = &smsm->hosts[host_id];
+	int ret = 0;
+
+	host->mbox_chan = mbox_request_channel(&smsm->mbox_client, host_id);
+	if (IS_ERR(host->mbox_chan)) {
+		ret = PTR_ERR(host->mbox_chan);
+		host->mbox_chan = NULL;
+	}
+
+	return ret;
+}
+
 /**
  * smsm_parse_ipc() - parses a qcom,ipc-%d device tree property
  * @smsm:	smsm driver context
@@ -521,8 +556,16 @@ static int qcom_smsm_probe(struct platform_device *pdev)
 			     "qcom,local-host",
 			     &smsm->local_host);
 
+	smsm->mbox_client.dev = &pdev->dev;
+	smsm->mbox_client.knows_txdone = true;
+
 	/* Parse the host properties */
 	for (id = 0; id < smsm->num_hosts; id++) {
+		/* Try using mbox interface first, otherwise fall back to syscon */
+		ret = smsm_parse_mbox(smsm, id);
+		if (!ret)
+			continue;
+
 		ret = smsm_parse_ipc(smsm, id);
 		if (ret < 0)
 			goto out_put;
@@ -609,6 +652,9 @@ static int qcom_smsm_probe(struct platform_device *pdev)
 
 	qcom_smem_state_unregister(smsm->state);
 out_put:
+	for (id = 0; id < smsm->num_hosts; id++)
+		mbox_free_channel(smsm->hosts[id].mbox_chan);
+
 	of_node_put(local_node);
 	return ret;
 }
@@ -622,6 +668,9 @@ static void qcom_smsm_remove(struct platform_device *pdev)
 		if (smsm->entries[id].domain)
 			irq_domain_remove(smsm->entries[id].domain);
 
+	for (id = 0; id < smsm->num_hosts; id++)
+		mbox_free_channel(smsm->hosts[id].mbox_chan);
+
 	qcom_smem_state_unregister(smsm->state);
 }
 

-- 
2.45.2


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

* Re: [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc
  2024-06-06 19:18 ` [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc Luca Weiss
@ 2024-06-07  7:24   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2024-06-07  7:24 UTC (permalink / raw)
  To: Luca Weiss, ~postmarketos/upstreaming, phone-devel,
	Bjorn Andersson, Konrad Dybcio, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Andy Gross
  Cc: Krzysztof Kozlowski, linux-arm-msm, devicetree, linux-kernel

On 06/06/2024 21:18, Luca Weiss wrote:
> The qcom,ipc-N properties are essentially providing a reference to a
> mailbox, so allow using the mboxes property to do the same in a more
> structured way.
> 
> Since multiple SMSM hosts are supported, we need to be able to provide
> the correct mailbox for each host. The old qcom,ipc-N properties map to
> the mboxes property by index, starting at 0 since that's a valid SMSM
> host also.
> 
> Mark the older qcom,ipc-N as deprecated and update the example with
> mboxes.
> 
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
> ---

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

Best regards,
Krzysztof


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

* Re: [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver
  2024-06-06 19:18 [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Luca Weiss
  2024-06-06 19:18 ` [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc Luca Weiss
  2024-06-06 19:18 ` [PATCH v2 2/2] soc: qcom: smsm: Support using mailbox interface Luca Weiss
@ 2024-06-14 22:48 ` Bjorn Andersson
  2 siblings, 0 replies; 5+ messages in thread
From: Bjorn Andersson @ 2024-06-14 22:48 UTC (permalink / raw)
  To: ~postmarketos/upstreaming, phone-devel, Konrad Dybcio,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andy Gross,
	Luca Weiss
  Cc: Krzysztof Kozlowski, linux-arm-msm, devicetree, linux-kernel


On Thu, 06 Jun 2024 21:18:31 +0200, Luca Weiss wrote:
> Take a shot at converting the last driver that requires direct
> "qcom,ipc*" syscon references in devicetree by allowing the smsm driver
> to use the mailbox interface to achieve the same effect.
> 
> Still not sure if the devicetree bindings are the prettiest but they're
> functional.
> 
> [...]

Applied, thanks!

[1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc
      commit: 5e66abcf1e250f032ecb18a7ecfac5287298ed8e
[2/2] soc: qcom: smsm: Support using mailbox interface
      commit: 75287992f58a74271a083fef0356bc81d629f671

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

end of thread, other threads:[~2024-06-14 22:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-06 19:18 [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Luca Weiss
2024-06-06 19:18 ` [PATCH v2 1/2] dt-bindings: soc: qcom,smsm: Allow specifying mboxes instead of qcom,ipc Luca Weiss
2024-06-07  7:24   ` Krzysztof Kozlowski
2024-06-06 19:18 ` [PATCH v2 2/2] soc: qcom: smsm: Support using mailbox interface Luca Weiss
2024-06-14 22:48 ` [PATCH v2 0/2] Support mailbox interface in qcom,smsm driver Bjorn Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox