[PATCH 0/3] amba: Properly handle device probe without IRQ domain

STALE1446d

Revision v1 of 2 in this series.

18 messages, 5 authors, 2021-08-26 · open the first message on its own page

[PATCH 0/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-16 07:43:23

Patch 1 and 2 make some cleanup, and patch 3 use of_irq_get() instead of 
irq_of_parse_and_map() to get irq number, return -EPROBE_DEFER if the irq
domain is not yet created, amba_device_add() will properly to handle the
no IRQ domain issue via deferred probe.

Kefeng Wang (3):
  amba: Drop unused functions about APB/AHB devices add
  Revert "ARM: amba: make use of -1 IRQs warn"
  amba: Properly handle device probe without IRQ domain

 drivers/amba/bus.c       | 100 ++++++++++-----------------------------
 drivers/of/platform.c    |   6 +--
 include/linux/amba/bus.h |  18 -------
 3 files changed, 27 insertions(+), 97 deletions(-)

-- 
2.26.2


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

[PATCH 2/3] Revert "ARM: amba: make use of -1 IRQs warn"

From: Kefeng Wang <hidden>
Date: 2021-08-16 07:43:19

After commit 77a7300abad7 ("of/irq: Get rid of NO_IRQ usage"),
no irq case has been removed, irq_of_parse_and_map() will return
0 in all cases when get error from parse and map an interrupt into
linux virq space.

amba_device_register() is only used on no-DT initialization, see
  s3c64xx_pl080_init()		arch/arm/mach-s3c/pl080.c
  ep93xx_init_devices()		arch/arm/mach-ep93xx/core.c

They won't set -1 to irq[0], so no need the warn.

This reverts commit 2eac58d5026e4ec8b17ff8b62877fea9e1d2f1b3.

Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kefeng Wang <redacted>
---
 drivers/amba/bus.c | 3 ---
 1 file changed, 3 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 2f2137518be0..36f2f42c8014 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -377,9 +377,6 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 	void __iomem *tmp;
 	int i, ret;
 
-	WARN_ON(dev->irq[0] == (unsigned int)-1);
-	WARN_ON(dev->irq[1] == (unsigned int)-1);
-
 	ret = request_resource(parent, &dev->res);
 	if (ret)
 		goto err_out;
-- 
2.26.2


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

[PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-16 07:43:25

of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
  "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
 drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
 drivers/of/platform.c |  6 +-----
 2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
 #include <linux/clk/clk-conf.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/of_irq.h>
 
 #include <asm/irq.h>
 
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
 	kfree(d);
 }
 
+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+	struct device_node *node = dev->dev.of_node;
+	int i, irq = 0;
+
+	if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+		/* Decode the IRQs and address ranges */
+		for (i = 0; i < AMBA_NR_IRQS; i++) {
+			irq = of_irq_get(node, i);
+			if (irq < 0) {
+				if (irq == -EPROBE_DEFER)
+					return irq;
+				irq = 0;
+			}
+
+			dev->irq[i] = irq;
+		}
+	}
+
+	return 0;
+}
+
 static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 {
 	u32 size;
 	void __iomem *tmp;
 	int i, ret;
 
+	ret = of_amba_device_decode_irq(dev);
+	if (ret)
+		goto err_out;
+
 	ret = request_resource(parent, &dev->res);
 	if (ret)
 		goto err_out;
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 74afbb7a4f5e..32d5ff8df747 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -222,7 +222,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 {
 	struct amba_device *dev;
 	const void *prop;
-	int i, ret;
+	int ret;
 
 	pr_debug("Creating amba device %pOF\n", node);
 
@@ -253,10 +253,6 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 	if (prop)
 		dev->periphid = of_read_ulong(prop, 1);
 
-	/* Decode the IRQs and address ranges */
-	for (i = 0; i < AMBA_NR_IRQS; i++)
-		dev->irq[i] = irq_of_parse_and_map(node, i);
-
 	ret = of_address_to_resource(node, 0, &dev->res);
 	if (ret) {
 		pr_err("amba: of_address_to_resource() failed (%d) for %pOF\n",
-- 
2.26.2


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

[PATCH 1/3] amba: Drop unused functions about APB/AHB devices add

From: Kefeng Wang <hidden>
Date: 2021-08-16 07:43:32

No one use the following functions, kill them.

  amba_aphb_device_add()
  amba_apb_device_add()
  amba_apb_device_add_res()
  amba_ahb_device_add()
  amba_ahb_device_add_res()

Cc: Linus Walleij <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
 drivers/amba/bus.c       | 72 ----------------------------------------
 include/linux/amba/bus.h | 18 ----------
 2 files changed, 90 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 962041148482..2f2137518be0 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -579,78 +579,6 @@ int amba_device_add(struct amba_device *dev, struct resource *parent)
 }
 EXPORT_SYMBOL_GPL(amba_device_add);
 
-static struct amba_device *
-amba_aphb_device_add(struct device *parent, const char *name,
-		     resource_size_t base, size_t size, int irq1, int irq2,
-		     void *pdata, unsigned int periphid, u64 dma_mask,
-		     struct resource *resbase)
-{
-	struct amba_device *dev;
-	int ret;
-
-	dev = amba_device_alloc(name, base, size);
-	if (!dev)
-		return ERR_PTR(-ENOMEM);
-
-	dev->dev.coherent_dma_mask = dma_mask;
-	dev->irq[0] = irq1;
-	dev->irq[1] = irq2;
-	dev->periphid = periphid;
-	dev->dev.platform_data = pdata;
-	dev->dev.parent = parent;
-
-	ret = amba_device_add(dev, resbase);
-	if (ret) {
-		amba_device_put(dev);
-		return ERR_PTR(ret);
-	}
-
-	return dev;
-}
-
-struct amba_device *
-amba_apb_device_add(struct device *parent, const char *name,
-		    resource_size_t base, size_t size, int irq1, int irq2,
-		    void *pdata, unsigned int periphid)
-{
-	return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
-				    periphid, 0, &iomem_resource);
-}
-EXPORT_SYMBOL_GPL(amba_apb_device_add);
-
-struct amba_device *
-amba_ahb_device_add(struct device *parent, const char *name,
-		    resource_size_t base, size_t size, int irq1, int irq2,
-		    void *pdata, unsigned int periphid)
-{
-	return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
-				    periphid, ~0ULL, &iomem_resource);
-}
-EXPORT_SYMBOL_GPL(amba_ahb_device_add);
-
-struct amba_device *
-amba_apb_device_add_res(struct device *parent, const char *name,
-			resource_size_t base, size_t size, int irq1,
-			int irq2, void *pdata, unsigned int periphid,
-			struct resource *resbase)
-{
-	return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
-				    periphid, 0, resbase);
-}
-EXPORT_SYMBOL_GPL(amba_apb_device_add_res);
-
-struct amba_device *
-amba_ahb_device_add_res(struct device *parent, const char *name,
-			resource_size_t base, size_t size, int irq1,
-			int irq2, void *pdata, unsigned int periphid,
-			struct resource *resbase)
-{
-	return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
-				    periphid, ~0ULL, resbase);
-}
-EXPORT_SYMBOL_GPL(amba_ahb_device_add_res);
-
-
 static void amba_device_initialize(struct amba_device *dev, const char *name)
 {
 	device_initialize(&dev->dev);
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index c68d87b87283..edfcf7a14dcd 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -122,24 +122,6 @@ struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
 void amba_device_put(struct amba_device *);
 int amba_device_add(struct amba_device *, struct resource *);
 int amba_device_register(struct amba_device *, struct resource *);
-struct amba_device *amba_apb_device_add(struct device *parent, const char *name,
-					resource_size_t base, size_t size,
-					int irq1, int irq2, void *pdata,
-					unsigned int periphid);
-struct amba_device *amba_ahb_device_add(struct device *parent, const char *name,
-					resource_size_t base, size_t size,
-					int irq1, int irq2, void *pdata,
-					unsigned int periphid);
-struct amba_device *
-amba_apb_device_add_res(struct device *parent, const char *name,
-			resource_size_t base, size_t size, int irq1,
-			int irq2, void *pdata, unsigned int periphid,
-			struct resource *resbase);
-struct amba_device *
-amba_ahb_device_add_res(struct device *parent, const char *name,
-			resource_size_t base, size_t size, int irq1,
-			int irq2, void *pdata, unsigned int periphid,
-			struct resource *resbase);
 void amba_device_unregister(struct amba_device *);
 struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
 int amba_request_regions(struct amba_device *, const char *);
-- 
2.26.2


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

Re: [PATCH 0/3] amba: Properly handle device probe without IRQ domain

From: Rob Herring <robh@kernel.org>
Date: 2021-08-17 22:27:42

On Mon, Aug 16, 2021 at 03:46:16PM +0800, Kefeng Wang wrote:
Patch 1 and 2 make some cleanup, and patch 3 use of_irq_get() instead of 
irq_of_parse_and_map() to get irq number, return -EPROBE_DEFER if the irq
domain is not yet created, amba_device_add() will properly to handle the
no IRQ domain issue via deferred probe.

Kefeng Wang (3):
  amba: Drop unused functions about APB/AHB devices add
  Revert "ARM: amba: make use of -1 IRQs warn"
  amba: Properly handle device probe without IRQ domain

 drivers/amba/bus.c       | 100 ++++++++++-----------------------------
 drivers/of/platform.c    |   6 +--
 include/linux/amba/bus.h |  18 -------
 3 files changed, 27 insertions(+), 97 deletions(-)
Reviewed-by: Rob Herring <robh@kernel.org>

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

Re: [PATCH 0/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-23 02:19:36

On 2021/8/18 6:27, Rob Herring wrote:
On Mon, Aug 16, 2021 at 03:46:16PM +0800, Kefeng Wang wrote:
quoted
Patch 1 and 2 make some cleanup, and patch 3 use of_irq_get() instead of
irq_of_parse_and_map() to get irq number, return -EPROBE_DEFER if the irq
domain is not yet created, amba_device_add() will properly to handle the
no IRQ domain issue via deferred probe.

Kefeng Wang (3):
   amba: Drop unused functions about APB/AHB devices add
   Revert "ARM: amba: make use of -1 IRQs warn"
   amba: Properly handle device probe without IRQ domain

  drivers/amba/bus.c       | 100 ++++++++++-----------------------------
  drivers/of/platform.c    |   6 +--
  include/linux/amba/bus.h |  18 -------
  3 files changed, 27 insertions(+), 97 deletions(-)
Reviewed-by: Rob Herring <robh@kernel.org>
Thanks Rob.

Hi Russell, should I send the patches to the ARM patch system?
.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 0/3] amba: Properly handle device probe without IRQ domain

From: "Russell King (Oracle)" <linux@armlinux.org.uk>
Date: 2021-08-23 09:05:32

On Mon, Aug 23, 2021 at 10:19:23AM +0800, Kefeng Wang wrote:
On 2021/8/18 6:27, Rob Herring wrote:
quoted
On Mon, Aug 16, 2021 at 03:46:16PM +0800, Kefeng Wang wrote:
quoted
Patch 1 and 2 make some cleanup, and patch 3 use of_irq_get() instead of
irq_of_parse_and_map() to get irq number, return -EPROBE_DEFER if the irq
domain is not yet created, amba_device_add() will properly to handle the
no IRQ domain issue via deferred probe.

Kefeng Wang (3):
   amba: Drop unused functions about APB/AHB devices add
   Revert "ARM: amba: make use of -1 IRQs warn"
   amba: Properly handle device probe without IRQ domain

  drivers/amba/bus.c       | 100 ++++++++++-----------------------------
  drivers/of/platform.c    |   6 +--
  include/linux/amba/bus.h |  18 -------
  3 files changed, 27 insertions(+), 97 deletions(-)
Reviewed-by: Rob Herring <robh@kernel.org>
Thanks Rob.

Hi Russell, should I send the patches to the ARM patch system?
Yes please - I'll try to squeeze it in for this cycle but it's getting
a tad late for that. Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

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

Re: [PATCH 0/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-23 10:57:48

On 2021/8/23 17:05, Russell King (Oracle) wrote:
On Mon, Aug 23, 2021 at 10:19:23AM +0800, Kefeng Wang wrote:
quoted
On 2021/8/18 6:27, Rob Herring wrote:
quoted
On Mon, Aug 16, 2021 at 03:46:16PM +0800, Kefeng Wang wrote:
quoted
Patch 1 and 2 make some cleanup, and patch 3 use of_irq_get() instead of
irq_of_parse_and_map() to get irq number, return -EPROBE_DEFER if the irq
domain is not yet created, amba_device_add() will properly to handle the
no IRQ domain issue via deferred probe.

Kefeng Wang (3):
    amba: Drop unused functions about APB/AHB devices add
    Revert "ARM: amba: make use of -1 IRQs warn"
    amba: Properly handle device probe without IRQ domain

   drivers/amba/bus.c       | 100 ++++++++++-----------------------------
   drivers/of/platform.c    |   6 +--
   include/linux/amba/bus.h |  18 -------
   3 files changed, 27 insertions(+), 97 deletions(-)
Reviewed-by: Rob Herring <robh@kernel.org>
Thanks Rob.

Hi Russell, should I send the patches to the ARM patch system?
Yes please - I'll try to squeeze it in for this cycle but it's getting
a tad late for that. Thanks.
Done, but the sequence of patches is reordered at ARM patch system, 
(using git send-email

and deliver patch1/2/3 in order).

BTW,  could you give me some direction the following patchset[1] too if 
you have time, I have

addressed your comments and resend, but there's been no new feedback for 
a long time.

If it is too late for this cycle, I could resend them after 5.15-rc1.

Many thanks.

[1] 
https://lore.kernel.org/linux-arm-kernel/20210610123556.171328-1-wangkefeng.wang@huawei.com/


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

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Rob Herring <robh+dt@kernel.org>
Date: 2021-08-24 20:05:39

+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted hunk
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
  "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
 drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
 drivers/of/platform.c |  6 +-----
 2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
 #include <linux/clk/clk-conf.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/of_irq.h>

 #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
        kfree(d);
 }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
 static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 {
        u32 size;
        void __iomem *tmp;
        int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
        ret = request_resource(parent, &dev->res);
        if (ret)
                goto err_out;
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 74afbb7a4f5e..32d5ff8df747 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -222,7 +222,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 {
        struct amba_device *dev;
        const void *prop;
-       int i, ret;
+       int ret;

        pr_debug("Creating amba device %pOF\n", node);
@@ -253,10 +253,6 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
        if (prop)
                dev->periphid = of_read_ulong(prop, 1);

-       /* Decode the IRQs and address ranges */
-       for (i = 0; i < AMBA_NR_IRQS; i++)
-               dev->irq[i] = irq_of_parse_and_map(node, i);
-
        ret = of_address_to_resource(node, 0, &dev->res);
        if (ret) {
                pr_err("amba: of_address_to_resource() failed (%d) for %pOF\n",
--
2.26.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Saravana Kannan <hidden>
Date: 2021-08-24 20:08:59

On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
  "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
 drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
 drivers/of/platform.c |  6 +-----
 2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
 #include <linux/clk/clk-conf.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/of_irq.h>

 #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
        kfree(d);
 }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
 static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
 {
        u32 size;
        void __iomem *tmp;
        int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.

-Saravana
quoted
        ret = request_resource(parent, &dev->res);
        if (ret)
                goto err_out;
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 74afbb7a4f5e..32d5ff8df747 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -222,7 +222,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
 {
        struct amba_device *dev;
        const void *prop;
-       int i, ret;
+       int ret;

        pr_debug("Creating amba device %pOF\n", node);
@@ -253,10 +253,6 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
        if (prop)
                dev->periphid = of_read_ulong(prop, 1);

-       /* Decode the IRQs and address ranges */
-       for (i = 0; i < AMBA_NR_IRQS; i++)
-               dev->irq[i] = irq_of_parse_and_map(node, i);
-
        ret = of_address_to_resource(node, 0, &dev->res);
        if (ret) {
                pr_err("amba: of_address_to_resource() failed (%d) for %pOF\n",
--
2.26.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-25 04:05:20

On 2021/8/25 4:08, Saravana Kannan wrote:
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
   "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
  drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
  drivers/of/platform.c |  6 +-----
  2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
  #include <linux/clk/clk-conf.h>
  #include <linux/platform_device.h>
  #include <linux/reset.h>
+#include <linux/of_irq.h>

  #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
         kfree(d);
  }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
  static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
  {
         u32 size;
         void __iomem *tmp;
         int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;

of_amba_device_decode_irq() in amba_device_try_add() won't lead to issue,
only delay the device add, right?

If make it into amba_probe(), the above code should be moved too, could we
make a new patch to move both of them, or don't move them?


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

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Saravana Kannan <hidden>
Date: 2021-08-25 08:05:28

On Tue, Aug 24, 2021 at 9:05 PM Kefeng Wang [off-list ref] wrote:

On 2021/8/25 4:08, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
   "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
  drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
  drivers/of/platform.c |  6 +-----
  2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
  #include <linux/clk/clk-conf.h>
  #include <linux/platform_device.h>
  #include <linux/reset.h>
+#include <linux/of_irq.h>

  #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
         kfree(d);
  }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
  static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
  {
         u32 size;
         void __iomem *tmp;
         int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;

of_amba_device_decode_irq() in amba_device_try_add() won't lead to issue,
only delay the device add, right?
But delaying the device add is the issue. For example, adding a device
could trigger the loading of the corresponding module using uevents.
But now this change would delay that step. That can have other
unintended consequences -- slowing down boot, what if the driver was
working fine without the IRQ, etc.
If make it into amba_probe(), the above code should be moved too, could we
make a new patch to move both of them, or don't move them?
I'd say move them both. If Russell hasn't already picked this up, then
I'd say redo your Patch 3/3.

Btw, I've been working on [1] cleaning up the one-off deferred probe
solution that we have for amba devices. That causes a bunch of other
headaches. Your patch 3/3 takes us further in the wrong direction by
adding more reasons for delaying the addition of the device.

-Saravana

[1] - https://lore.kernel.org/lkml/CAGETcx8b228nDUho3cX9AAQ-pXOfZTMv8cj2vhdx9yc_pk8q+A@mail.gmail.com/

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

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-25 08:40:01

On 2021/8/25 16:04, Saravana Kannan wrote:
On Tue, Aug 24, 2021 at 9:05 PM Kefeng Wang [off-list ref] wrote:
quoted
On 2021/8/25 4:08, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
    "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
   drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
   drivers/of/platform.c |  6 +-----
   2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
   #include <linux/clk/clk-conf.h>
   #include <linux/platform_device.h>
   #include <linux/reset.h>
+#include <linux/of_irq.h>

   #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
          kfree(d);
   }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
   static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
   {
          u32 size;
          void __iomem *tmp;
          int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;

of_amba_device_decode_irq() in amba_device_try_add() won't lead to issue,
only delay the device add, right?
But delaying the device add is the issue. For example, adding a device
could trigger the loading of the corresponding module using uevents.
But now this change would delay that step. That can have other
unintended consequences -- slowing down boot, what if the driver was
working fine without the IRQ, etc.
quoted
If make it into amba_probe(), the above code should be moved too, could we
make a new patch to move both of them, or don't move them?
I'd say move them both. If Russell hasn't already picked this up, then
I'd say redo your Patch 3/3.

Sure,I will update it and resend.
Btw, I've been working on [1] cleaning up the one-off deferred probe
solution that we have for amba devices. That causes a bunch of other
headaches. Your patch 3/3 takes us further in the wrong direction by
adding more reasons for delaying the addition of the device.
Thanks for your explanation.
-Saravana

[1] - https://lore.kernel.org/lkml/CAGETcx8b228nDUho3cX9AAQ-pXOfZTMv8cj2vhdx9yc_pk8q+A@mail.gmail.com/
.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Rob Herring <robh+dt@kernel.org>
Date: 2021-08-25 12:33:56

On Tue, Aug 24, 2021 at 11:05 PM Kefeng Wang [off-list ref] wrote:

On 2021/8/25 4:08, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
   "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
  drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
  drivers/of/platform.c |  6 +-----
  2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
  #include <linux/clk/clk-conf.h>
  #include <linux/platform_device.h>
  #include <linux/reset.h>
+#include <linux/of_irq.h>

  #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
         kfree(d);
  }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
  static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
  {
         u32 size;
         void __iomem *tmp;
         int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;
I wonder if we could just remove these. Why does userspace need them
in the first place? It's only an ABI if someone notices. Looking at
the history, AMBA bus was added in 2003 with just 'irq' and then
changed (ABI break) in 2004 to 'irq0' and 'irq1'.

Rob

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/log/arch/arm/common/amba.c

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

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-25 14:41:32

On 2021/8/25 20:33, Rob Herring wrote:
On Tue, Aug 24, 2021 at 11:05 PM Kefeng Wang [off-list ref] wrote:
...
quoted
quoted
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;
I wonder if we could just remove these. Why does userspace need them
in the first place? It's only an ABI if someone notices. Looking at
the history, AMBA bus was added in 2003 with just 'irq' and then
changed (ABI break) in 2004 to 'irq0' and 'irq1'.

Rob
Ok, I will kill all irq parts,
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 962041148482..c08e8b30e02c 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -20,8 +20,6 @@
  #include <linux/platform_device.h>
  #include <linux/reset.h>

-#include <asm/irq.h>
-
  #define to_amba_driver(d)      container_of(d, struct amba_driver, drv)

  /* called on periphid match and class 0x9 coresight device. */
@@ -135,8 +133,6 @@ static ssize_t name##_show(struct device 
*_dev,                             \
  static DEVICE_ATTR_RO(name)

  amba_attr_func(id, "%08x\n", dev->periphid);
-amba_attr_func(irq0, "%u\n", dev->irq[0]);
-amba_attr_func(irq1, "%u\n", dev->irq[1]);
  amba_attr_func(resource, "\t%016llx\t%016llx\t%016lx\n",
          (unsigned long long)dev->res.start, (unsigned long 
long)dev->res.end,
          dev->res.flags);
@@ -467,10 +463,6 @@ static int amba_device_try_add(struct amba_device 
*dev, struct resource *parent)
         if (ret)
                 goto err_release;

-       if (dev->irq[0])
-               ret = device_create_file(&dev->dev, &dev_attr_irq0);
-       if (ret == 0 && dev->irq[1])
-               ret = device_create_file(&dev->dev, &dev_attr_irq1);

and do some cleanup about error handling in the next version.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/log/arch/arm/common/amba.c
.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-26 02:45:28

On 2021/8/25 16:04, Saravana Kannan wrote:
On Tue, Aug 24, 2021 at 9:05 PM Kefeng Wang [off-list ref] wrote:
quoted
On 2021/8/25 4:08, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
    "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
   drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
   drivers/of/platform.c |  6 +-----
   2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
   #include <linux/clk/clk-conf.h>
   #include <linux/platform_device.h>
   #include <linux/reset.h>
+#include <linux/of_irq.h>

   #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
          kfree(d);
   }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
   static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
   {
          u32 size;
          void __iomem *tmp;
          int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;

of_amba_device_decode_irq() in amba_device_try_add() won't lead to issue,
only delay the device add, right?
But delaying the device add is the issue. For example, adding a device
could trigger the loading of the corresponding module using uevents.
But now this change would delay that step. That can have other
unintended consequences -- slowing down boot, what if the driver was
working fine without the IRQ, etc.
quoted
If make it into amba_probe(), the above code should be moved too, could we
make a new patch to move both of them, or don't move them?
I'd say move them both. If Russell hasn't already picked this up, then
I'd say redo your Patch 3/3.
I will resend with put it into amba_probe.
Btw, I've been working on [1] cleaning up the one-off deferred probe
solution that we have for amba devices. That causes a bunch of other
headaches. Your patch 3/3 takes us further in the wrong direction by
adding more reasons for delaying the addition of the device.
Got it,  and I could resend all combine your patch(due to context conflict

when changing same function) if you no object.

-Saravana

[1] - https://lore.kernel.org/lkml/CAGETcx8b228nDUho3cX9AAQ-pXOfZTMv8cj2vhdx9yc_pk8q+A@mail.gmail.com/
.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Saravana Kannan <hidden>
Date: 2021-08-26 04:46:23

On Wed, Aug 25, 2021 at 7:45 PM Kefeng Wang [off-list ref] wrote:

On 2021/8/25 16:04, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 9:05 PM Kefeng Wang [off-list ref] wrote:
quoted
On 2021/8/25 4:08, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
    "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
   drivers/amba/bus.c    | 27 +++++++++++++++++++++++++++
   drivers/of/platform.c |  6 +-----
   2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36f2f42c8014..720aa6cdd402 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
   #include <linux/clk/clk-conf.h>
   #include <linux/platform_device.h>
   #include <linux/reset.h>
+#include <linux/of_irq.h>

   #include <asm/irq.h>
@@ -371,12 +372,38 @@ static void amba_device_release(struct device *dev)
          kfree(d);
   }

+static int of_amba_device_decode_irq(struct amba_device *dev)
+{
+       struct device_node *node = dev->dev.of_node;
+       int i, irq = 0;
+
+       if (IS_ENABLED(CONFIG_OF_IRQ) && node) {
+               /* Decode the IRQs and address ranges */
+               for (i = 0; i < AMBA_NR_IRQS; i++) {
+                       irq = of_irq_get(node, i);
+                       if (irq < 0) {
+                               if (irq == -EPROBE_DEFER)
+                                       return irq;
+                               irq = 0;
+                       }
+
+                       dev->irq[i] = irq;
+               }
+       }
+
+       return 0;
+}
+
   static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
   {
          u32 size;
          void __iomem *tmp;
          int i, ret;

+       ret = of_amba_device_decode_irq(dev);
+       if (ret)
+               goto err_out;
+
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;

of_amba_device_decode_irq() in amba_device_try_add() won't lead to issue,
only delay the device add, right?
But delaying the device add is the issue. For example, adding a device
could trigger the loading of the corresponding module using uevents.
But now this change would delay that step. That can have other
unintended consequences -- slowing down boot, what if the driver was
working fine without the IRQ, etc.
quoted
If make it into amba_probe(), the above code should be moved too, could we
make a new patch to move both of them, or don't move them?
I'd say move them both. If Russell hasn't already picked this up, then
I'd say redo your Patch 3/3.
I will resend with put it into amba_probe.
quoted
Btw, I've been working on [1] cleaning up the one-off deferred probe
solution that we have for amba devices. That causes a bunch of other
headaches. Your patch 3/3 takes us further in the wrong direction by
adding more reasons for delaying the addition of the device.
Got it,  and I could resend all combine your patch(due to context conflict

when changing same function) if you no object.
If you want to resolve the conflict with my patch and resend it while
keeping me as the author, I would definitely appreciate it.

-Saravana
quoted
-Saravana

[1] - https://lore.kernel.org/lkml/CAGETcx8b228nDUho3cX9AAQ-pXOfZTMv8cj2vhdx9yc_pk8q+A@mail.gmail.com/
.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH 3/3] amba: Properly handle device probe without IRQ domain

From: Kefeng Wang <hidden>
Date: 2021-08-26 06:22:30

On 2021/8/26 12:45, Saravana Kannan wrote:
On Wed, Aug 25, 2021 at 7:45 PM Kefeng Wang [off-list ref] wrote:
quoted
On 2021/8/25 16:04, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 9:05 PM Kefeng Wang [off-list ref] wrote:
quoted
On 2021/8/25 4:08, Saravana Kannan wrote:
quoted
On Tue, Aug 24, 2021 at 1:05 PM Rob Herring [off-list ref] wrote:
quoted
+Saravana

Saravana mentioned to me there may be some issues with this one...


On Mon, Aug 16, 2021 at 2:43 AM Kefeng Wang [off-list ref] wrote:
quoted
of_amba_device_create() uses irq_of_parse_and_map() to translate
a DT interrupt specification into a Linux virtual interrupt number.

But it doesn't properly handle the case where the interrupt controller
is not yet available, eg, when pl011 interrupt is connected to MBIGEN
interrupt controller, because the mbigen initialization is too late,
which will lead to no IRQ due to no IRQ domain found, log is shown below,
     "irq: no irq domain found for uart0 !"

use of_irq_get() to return -EPROBE_DEFER as above, and in the function
amba_device_try_add()/amba_device_add(), it will properly handle in such
case, also return 0 in other fail cases to be consistent as before.

Cc: Russell King <linux@armlinux.org.uk>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <redacted>
Reported-by: Ruizhe Lin <redacted>
Signed-off-by: Kefeng Wang <redacted>
---
...
quoted
quoted
quoted
quoted
Similar to other resources the AMBA bus "gets" for the device, I think
this should be moved into amba_probe() and not here. There's no reason
to delay the addition of the device (and loading its module) because
the IRQ isn't ready yet.
The following code in the amba_device_try_add() will be called, it uses irq[0]
and irq[1], so I put of_amba_device_decode_irq() into amba_device_try_add().

470         if (dev->irq[0])
471                 ret = device_create_file(&dev->dev, &dev_attr_irq0);
472         if (ret == 0 && dev->irq[1])
473                 ret = device_create_file(&dev->dev, &dev_attr_irq1);
474         if (ret == 0)
475                 return ret;

of_amba_device_decode_irq() in amba_device_try_add() won't lead to issue,
only delay the device add, right?
But delaying the device add is the issue. For example, adding a device
could trigger the loading of the corresponding module using uevents.
But now this change would delay that step. That can have other
unintended consequences -- slowing down boot, what if the driver was
working fine without the IRQ, etc.
quoted
If make it into amba_probe(), the above code should be moved too, could we
make a new patch to move both of them, or don't move them?
I'd say move them both. If Russell hasn't already picked this up, then
I'd say redo your Patch 3/3.
I will resend with put it into amba_probe.
quoted
Btw, I've been working on [1] cleaning up the one-off deferred probe
solution that we have for amba devices. That causes a bunch of other
headaches. Your patch 3/3 takes us further in the wrong direction by
adding more reasons for delaying the addition of the device.
Got it,  and I could resend all combine your patch(due to context conflict

when changing same function) if you no object.
If you want to resolve the conflict with my patch and resend it while
keeping me as the author, I would definitely appreciate it.
Yes, I will keep it, and rebase my patch based on it.
-Saravana
quoted
quoted
-Saravana

[1] - https://lore.kernel.org/lkml/CAGETcx8b228nDUho3cX9AAQ-pXOfZTMv8cj2vhdx9yc_pk8q+A@mail.gmail.com/
.
.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help