Skip to contentSkip to conversation

pinctrl: qcom: use scm_call to route GPIO irq to Apps

PATCH Superseded Ansuel Smith 3 participants 3 messages Mar 13, 2020 – Mar 26, 2020

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: qcom: use scm_call to route GPIO irq to Apps

For IPQ806x targets, TZ protects the registers that are used to configure the routing of interrupts to a target processor. To resolve this, this patch uses scm call to route GPIO interrupts to application processor. Also the scm call interface is changed.

---
 drivers/pinctrl/qcom/pinctrl-msm.c | 36 ++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
drivers/pinctrl/qcom/pinctrl-msm.c +32 -4
index 9a8daa256a32..a83cfd1da219 100644
@@ -22,6 +22,8 @@
 #include <linux/reboot.h>
 #include <linux/pm.h>
 #include <linux/log2.h>
+#include <linux/qcom_scm.h>
+#include <linux/io.h>
 
 #include <linux/soc/qcom/irq.h>
 
@@ -710,6 +712,9 @@ static void msm_gpio_irq_mask(struct irq_data *d)
 	const struct msm_pingroup *g;
 	unsigned long flags;
 	u32 val;
+	u32 addr;
+	int ret;
+	const __be32 *reg;
 
 	if (d->parent_data)
 		irq_chip_mask_parent(d);
@@ -863,6 +868,7 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	const struct msm_pingroup *g;
 	unsigned long flags;
 	u32 val;
+	int ret;
 
 	if (d->parent_data)
 		irq_chip_set_type_parent(d, type);
@@ -882,11 +888,33 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	else
 		clear_bit(d->hwirq, pctrl->dual_edge_irqs);
 
+	ret = of_device_is_compatible(pctrl->dev->of_node,
+					"qcom,ipq8064-pinctrl");
 	/* Route interrupts to application cpu */
-	val = msm_readl_intr_target(pctrl, g);
-	val &= ~(7 << g->intr_target_bit);
-	val |= g->intr_target_kpss_val << g->intr_target_bit;
-	msm_writel_intr_target(val, pctrl, g);
+	if (!ret) {
+		val = msm_readl_intr_target(pctrl, g);
+		val &= ~(7 << g->intr_target_bit);
+		val |= g->intr_target_kpss_val << g->intr_target_bit;
+		msm_writel_intr_target(val, pctrl, g);
+	} else {
+		const __be32 *reg = of_get_property(pctrl->dev->of_node,
+						    "reg", NULL);
+
+		if (reg) {
+			u32 addr = be32_to_cpup(reg) + g->intr_target_reg;
+
+			qcom_scm_io_readl(addr, &val);
+			__iormb();
+
+			val &= ~(7 << g->intr_target_bit);
+			val |= g->intr_target_kpss_val << g->intr_target_bit;
+
+			__iowmb();
+			ret = qcom_scm_io_writel(addr, val);
+			if (ret)
+				pr_err("\n Routing interrupts to Apps proc failed");
+		}
+	}
 
 	/* Update configuration for gpio.
 	 * RAW_STATUS_EN is left on for all gpio irqs. Due to the
Signature · 1 line
2.25.0
#1 lore raw
Quoted 7 lines · Ansuel Smith

For IPQ806x targets, TZ protects the registers that are used to configure the routing of interrupts to a target processor. To resolve this, this patch uses scm call to route GPIO interrupts to application processor. Also the scm call interface is changed.

That's advanced. I'd really like Bjorn's review on this.

drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 894

Quoted 8 lines
drivers/pinctrl/qcom/pinctrl-msm.c +3 -4
+       ret = of_device_is_compatible(pctrl->dev->of_node,
+                                       "qcom,ipq8064-pinctrl");
        /* Route interrupts to application cpu */
-       val = msm_readl_intr_target(pctrl, g);
-       val &= ~(7 << g->intr_target_bit);
-       val |= g->intr_target_kpss_val << g->intr_target_bit;
-       msm_writel_intr_target(val, pctrl, g);
+       if (!ret) {

Can't you just:

if (!of_device_is_compatible(pctrl->dev->of_node, "qcom,ipq8064-pinctrl")) {

OK maybe nitpicky.

Quoted 12 lines
drivers/pinctrl/qcom/pinctrl-msm.c +12 -0
+               val = msm_readl_intr_target(pctrl, g);
+               val &= ~(7 << g->intr_target_bit);
+               val |= g->intr_target_kpss_val << g->intr_target_bit;
+               msm_writel_intr_target(val, pctrl, g);
+       } else {
+               const __be32 *reg = of_get_property(pctrl->dev->of_node,
+                                                   "reg", NULL);
+
+               if (reg) {
+                       u32 addr = be32_to_cpup(reg) + g->intr_target_reg;
+
+                       qcom_scm_io_readl(addr, &val);

drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 916

Quoted 10 lines
drivers/pinctrl/qcom/pinctrl-msm.c +10 -0
+                       __iormb();
+
+                       val &= ~(7 << g->intr_target_bit);
+                       val |= g->intr_target_kpss_val << g->intr_target_bit;
+
+                       __iowmb();
+                       ret = qcom_scm_io_writel(addr, val);
+                       if (ret)
+                               pr_err("\n Routing interrupts to Apps proc failed");
+               }

Can we at least put a little comment on top here and explain what is going on?

Yours,
Linus Walleij

#2 lore raw
In reply to Ansuel Smith
Quoted 5 lines · Ansuel Smith

For IPQ806x targets, TZ protects the registers that are used to configure the routing of interrupts to a target processor. To resolve this, this patch uses scm call to route GPIO interrupts to application processor. Also the scm call interface is changed.

Oh no...but this does look pretty reasonable after all, some comments and suggestions below.

Quoted 1 line

With this --author should be Ajay.

Quoted 37 lines
---
 drivers/pinctrl/qcom/pinctrl-msm.c | 36 ++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
drivers/pinctrl/qcom/pinctrl-msm.c +6 -0
index 9a8daa256a32..a83cfd1da219 100644
@@ -22,6 +22,8 @@
 #include <linux/reboot.h>
 #include <linux/pm.h>
 #include <linux/log2.h>
+#include <linux/qcom_scm.h>
+#include <linux/io.h>
 
 #include <linux/soc/qcom/irq.h>
 
@@ -710,6 +712,9 @@ static void msm_gpio_irq_mask(struct irq_data *d)
 	const struct msm_pingroup *g;
 	unsigned long flags;
 	u32 val;
+	u32 addr;
+	int ret;
+	const __be32 *reg;
 
 	if (d->parent_data)
 		irq_chip_mask_parent(d);
@@ -863,6 +868,7 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	const struct msm_pingroup *g;
 	unsigned long flags;
 	u32 val;
+	int ret;
 
 	if (d->parent_data)
 		irq_chip_set_type_parent(d, type);

drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 892

Quoted 5 lines
drivers/pinctrl/qcom/pinctrl-msm.c +2 -0
@@ -882,11 +888,33 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 	else
 		clear_bit(d->hwirq, pctrl->dual_edge_irqs);
 
+	ret = of_device_is_compatible(pctrl->dev->of_node,
+					"qcom,ipq8064-pinctrl");

This won't change in runtime, so I would like for you to query this during probe and then carry the result in msm_pinctrl.

drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 901

Quoted 13 lines
drivers/pinctrl/qcom/pinctrl-msm.c +8 -4
 	/* Route interrupts to application cpu */
-	val = msm_readl_intr_target(pctrl, g);
-	val &= ~(7 << g->intr_target_bit);
-	val |= g->intr_target_kpss_val << g->intr_target_bit;
-	msm_writel_intr_target(val, pctrl, g);
+	if (!ret) {
+		val = msm_readl_intr_target(pctrl, g);
+		val &= ~(7 << g->intr_target_bit);
+		val |= g->intr_target_kpss_val << g->intr_target_bit;
+		msm_writel_intr_target(val, pctrl, g);
+	} else {
+		const __be32 *reg = of_get_property(pctrl->dev->of_node,
+						    "reg", NULL);

This too will be static, and we already resolve this, properly, with address translation etc during probe.

So if you do a partial rollback of '4b024225c4a8 ("pinctrl: use devm_platform_ioremap_resource() to simplify code")' you can stash the base address of the resource in msm_pinctrl, and then make your change conditional on this being NULL or not.

drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 907

Quoted 6 lines
drivers/pinctrl/qcom/pinctrl-msm.c +6 -0
+
+		if (reg) {
+			u32 addr = be32_to_cpup(reg) + g->intr_target_reg;
+
+			qcom_scm_io_readl(addr, &val);
+			__iormb();

Why do you need this and below barriers?

drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 915

Quoted 8 lines
drivers/pinctrl/qcom/pinctrl-msm.c +8 -0
+
+			val &= ~(7 << g->intr_target_bit);
+			val |= g->intr_target_kpss_val << g->intr_target_bit;
+
+			__iowmb();
+			ret = qcom_scm_io_writel(addr, val);
+			if (ret)
+				pr_err("\n Routing interrupts to Apps proc failed");

You have msm_pinctrl->dev, so use dev_err(). And the \n goes at the end in Linux - and perhaps make it include d->hwirq to make it a little bit informative?

Regards,
Bjorn

Quoted 8 lines
drivers/pinctrl/qcom/pinctrl-msm.c +2 -0
+		}
+	}
 
 	/* Update configuration for gpio.
 	 * RAW_STATUS_EN is left on for all gpio irqs. Due to the
Signature · 1 line
2.25.0