Skip to contentSkip to conversation

PCI: exynos: add support for MSI

PATCH Superseded Jingoo Han 4 participants 7 messages Aug 23, 2013 – Aug 29, 2013

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH v2 1/1 PCI: exynos: add support for MSI

This patch adds support for Message Signaled Interrupt in the Exynos PCIe diver using Synopsys designware PCIe core IP.

---
Changes since v1:
- removed unnecessary exynos_pcie_clear_irq_level()
- updated the bindings documentation
- used new msi_chip infrastructure
- removed ARCH_SUPPORTS_MSI
- replaced #ifdef guards with IS_ENABLED(CONFIG_PCI_MSI)

 .../devicetree/bindings/pci/designware-pcie.txt    |    2 +
 arch/arm/boot/dts/exynos5440.dtsi                  |    2 +
 drivers/pci/host/pci-exynos.c                      |   47 ++++
 drivers/pci/host/pcie-designware.c                 |  225 ++++++++++++++++++++
 drivers/pci/host/pcie-designware.h                 |    4 +
 5 files changed, 280 insertions(+)
Documentation/devicetree/bindings/pci/designware-pcie.txt +2 -0
index eabcb4b..00bb935 100644
@@ -43,6 +43,7 @@ SoC specific DT Entry:
 		interrupt-map-mask = <0 0 0 0>;
 		interrupt-map = <0x0 0 &gic 53>;
 		num-lanes = <4>;
+		msi-base = <200>;
 	};
 
 	pcie@2a0000 {
@@ -63,6 +64,7 @@ SoC specific DT Entry:
 		interrupt-map-mask = <0 0 0 0>;
 		interrupt-map = <0x0 0 &gic 56>;
 		num-lanes = <4>;
+		msi-base = <232>;
 	};
 
 Board specific DT Entry:
arch/arm/boot/dts/exynos5440.dtsi +2 -0
index 5d6cf49..17549b9 100644
@@ -276,6 +276,7 @@
 		interrupt-map-mask = <0 0 0 0>;
 		interrupt-map = <0x0 0 &gic 53>;
 		num-lanes = <4>;
+		msi-base = <200>;
 	};
 
 	pcie@2a0000 {
@@ -296,5 +297,6 @@
 		interrupt-map-mask = <0 0 0 0>;
 		interrupt-map = <0x0 0 &gic 56>;
 		num-lanes = <4>;
+		msi-base = <232>;
 	};
 };
drivers/pci/host/pci-exynos.c +47 -0

68 lines not on this page · raw message

drivers/pci/host/pcie-designware.c +225 -0

261 lines not on this page · raw message

drivers/pci/host/pcie-designware.h +4 -0
index 133820f..3c01935 100644
@@ -38,6 +38,8 @@ struct pcie_port {
 	int			irq;
 	u32			lanes;
 	struct pcie_host_ops	*ops;
+	int			msi_irq;
+	int			msi_irq_start;
 };
 
 struct pcie_host_ops {
@@ -57,6 +59,8 @@ int cfg_read(void __iomem *addr, int where, int size, u32 *val);
 int cfg_write(void __iomem *addr, int where, int size, u32 val);
 int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, u32 val);
 int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, u32 *val);
+void dw_handle_msi_irq(struct pcie_port *pp);
+void dw_pcie_msi_init(struct pcie_port *pp);
 int dw_pcie_link_up(struct pcie_port *pp);
 void dw_pcie_setup_rc(struct pcie_port *pp);
 int dw_pcie_host_init(struct pcie_port *pp);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 25 lines · Jingoo Han

This patch adds support for Message Signaled Interrupt in the Exynos PCIe diver using Synopsys designware PCIe core IP.

---
Changes since v1:
- removed unnecessary exynos_pcie_clear_irq_level()
- updated the bindings documentation
- used new msi_chip infrastructure
- removed ARCH_SUPPORTS_MSI
- replaced #ifdef guards with IS_ENABLED(CONFIG_PCI_MSI)

 .../devicetree/bindings/pci/designware-pcie.txt    |    2 +
 arch/arm/boot/dts/exynos5440.dtsi                  |    2 +
 drivers/pci/host/pci-exynos.c                      |   47 ++++
 drivers/pci/host/pcie-designware.c                 |  225 ++++++++++++++++++++
 drivers/pci/host/pcie-designware.h                 |    4 +
 5 files changed, 280 insertions(+)
Documentation/devicetree/bindings/pci/designware-pcie.txt +0 -0
index eabcb4b..00bb935 100644

[...]

Quoted 16 lines
drivers/pci/host/pcie-designware.c +2 -0
index 77b0c25..a4fed11 100644
@@ -11,8 +11,10 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/msi.h>
 #include <linux/of_address.h>
 #include <linux/pci.h>
 #include <linux/pci_regs.h>

drivers/pci/host/pcie-designware.c line 67

Quoted 4 lines
drivers/pci/host/pcie-designware.c +1 -0
@@ -62,6 +64,12 @@
 #define PCIE_ATU_FUNC(x)               (((x) & 0x7) << 16)
 #define PCIE_ATU_UPPER_TARGET          0x91C
 
+#define MAX_MSI_IRQS                   32

DW MSI controller can support upto 256. However, 32 seems a practical choice, as there might not be any system which may use more than 32. But a comment like as follows can be put here:

/*
* Maximum number of MSI IRQs can be 256 per controller. But keep
* it 32 as of now. Probably we will never need more than 32. If needed,
* then increment it in multiple of 32.
*/

drivers/pci/host/pcie-designware.c line 68

Quoted 1 line
drivers/pci/host/pcie-designware.c +1 -0
+#define MAX_MSI_CTRLS                  8

Why to waste cpu cycles when MAX_MSI_IRQS is 32 only.
#define MAX_MSI_CTRLS (MAX_MSI_IRQS / 32)

drivers/pci/host/pcie-designware.c line 71

Quoted 3 lines
drivers/pci/host/pcie-designware.c +3 -0
+
+static unsigned int msi_data;
+static DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);

What if one has more than one RC.
There are SOCs which support 3 RCs.
So something like this:

#define MAX_PCIE_PORT_SUPPORTED 3
static DECLARE_BITMAP(msi_irq_in_use[MAX_PCIE_PORT_SUPPORTED],

                  NUM_MSI_IRQS);

static unsigned int *msi_data[MAX_PCIE_PORT_SUPPORTED];

Allocate msi_data using __get_free_pages(GFP_KERNEL, 0)) as Thierry suggested.

Quoted 8 lines
drivers/pci/host/pcie-designware.c +1 -0
+
 static struct hw_pci dw_pci;
 
 unsigned long global_io_offset;
@@ -144,6 +152,205 @@ int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size,
        return ret;
 }
 

[...]

Quoted 4 lines

int dw_pcie_link_up(struct pcie_port *pp)

 {
        if (pp->ops->link_up)

drivers/pci/host/pcie-designware.c int __init dw_pcie_host_init(struct pcie_port *pp) · line 441

Quoted 10 lines
drivers/pci/host/pcie-designware.c +7 -0
@@ -225,6 +432,13 @@ int __init dw_pcie_host_init(struct pcie_port *pp)
                return -EINVAL;
        }
 
+       if (IS_ENABLED(CONFIG_PCI_MSI)) {
+               if (of_property_read_u32(np, "msi-base", &pp->msi_irq_start)) {
+                       dev_err(pp->dev, "Failed to parse the number of lanes\n");
+                       return -EINVAL;
+               }
+       }
+

What if an implementor want to use irq_domain method for msi_irq_start allocation? Is it fine to return error if msi-base is not passed from dt?

Also, with the limited knowledge of dt I do not understand one thing, how would dt understand that you have used 32 msi irqs (MAX_MSI_IRQS)?

Regards
Pratyush

#2 lore raw
Quoted 1 line · Pratyush Anand

On Fri, Aug 23, 2013 at 02:04:20PM +0800, Jingoo Han wrote:

[...]

Quoted 18 lines
Quoted 8 lines
drivers/pci/host/pcie-designware.c +1 -0
+
 static struct hw_pci dw_pci;
 
 unsigned long global_io_offset;
@@ -144,6 +152,205 @@ int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size,
        return ret;
 }
 

[...]

Quoted 7 lines

int dw_pcie_link_up(struct pcie_port *pp)

 {
        if (pp->ops->link_up)
drivers/pci/host/pcie-designware.c +0 -0
@@ -225,6 +432,13 @@ int __init dw_pcie_host_init(struct pcie_port *pp)
                return -EINVAL;
        }
 
Quoted 11 lines

drivers/pci/host/pcie-designware.c int __init dw_pcie_host_init(struct pcie_port *pp) · line 441

Quoted 7 lines
drivers/pci/host/pcie-designware.c +7 -0
+       if (IS_ENABLED(CONFIG_PCI_MSI)) {
+               if (of_property_read_u32(np, "msi-base", &pp->msi_irq_start)) {
+                       dev_err(pp->dev, "Failed to parse the number of lanes\n");
+                       return -EINVAL;
+               }
+       }
+

What if an implementor want to use irq_domain method for msi_irq_start allocation? Is it fine to return error if msi-base is not passed from dt?

I agree. This should be using an IRQ domain to represent the MSI controller. Both Tegra and Marvell drivers do that already and if Exynos can follow that same path it will increase the chances of refactoring common bits.

Also the error message doesn't quite match up with what the code is doing. =)

Thierry

#3 lore raw
Quoted 12 lines · Thierry Reding
Quoted 11 lines

drivers/pci/host/pcie-designware.c int __init dw_pcie_host_init(struct pcie_port *pp) · line 441

Quoted 7 lines
drivers/pci/host/pcie-designware.c +7 -0
+       if (IS_ENABLED(CONFIG_PCI_MSI)) {
+               if (of_property_read_u32(np, "msi-base", &pp->msi_irq_start)) {
+                       dev_err(pp->dev, "Failed to parse the number of lanes\n");
+                       return -EINVAL;
+               }
+       }
+

What if an implementor want to use irq_domain method for msi_irq_start allocation? Is it fine to return error if msi-base is not passed from dt?

Quoted 7 lines

I agree. This should be using an IRQ domain to represent the MSI controller. Both Tegra and Marvell drivers do that already and if Exynos can follow that same path it will increase the chances of refactoring common bits.

Also the error message doesn't quite match up with what the code is doing. =)

Agreed. Besides the encoding of "base" irq values in the device tree is always wrong, since the numbers are not at all a hardware property but an implementation detail of how Linux currently uses interrupt numbers. When using DT probing, you *have* to use IRQ domains, and the rest of Exynos does that.

Arnd

author
#4 lore raw
In reply to Pratyush Anand
Quoted 1 line · Pratyush Anand

On Fri, Aug 23, 2013 at 02:04:20PM +0800, Jingoo Han wrote:

[.....]

Quoted 11 lines
Quoted 1 line

+#define MAX_MSI_IRQS 32

DW MSI controller can support upto 256. However, 32 seems a practical choice, as there might not be any system which may use more than 32. But a comment like as follows can be put here:

/*
* Maximum number of MSI IRQs can be 256 per controller. But keep
* it 32 as of now. Probably we will never need more than 32. If needed,
* then increment it in multiple of 32.
*/

OK.
I will add this comment.

Quoted 5 lines
Quoted 2 lines

+#define MAX_MSI_CTRLS 8

Why to waste cpu cycles when MAX_MSI_IRQS is 32 only.
#define MAX_MSI_CTRLS (MAX_MSI_IRQS / 32)

OK.
I will fix it as you guide.

Quoted 9 lines

drivers/pci/host/pcie-designware.c line 71

Quoted 4 lines
drivers/pci/host/pcie-designware.c +3 -0
+
+static unsigned int msi_data;
+static DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);

What if one has more than one RC.
There are SOCs which support 3 RCs.
So something like this:

Quoted 4 lines

#define MAX_PCIE_PORT_SUPPORTED 3
static DECLARE_BITMAP(msi_irq_in_use[MAX_PCIE_PORT_SUPPORTED],

                  NUM_MSI_IRQS);

static unsigned int *msi_data[MAX_PCIE_PORT_SUPPORTED];

No, there is no need to do it.
Without this, we can use 3 RCs by adding a node of 3rd RC to dt file.

Quoted 3 lines

Allocate msi_data using __get_free_pages(GFP_KERNEL, 0)) as Thierry suggested.

OK.
I will use '__get_free_pages(GFP_KERNEL, 0))' as Thierry guide.

Quoted 7 lines
Quoted 7 lines

int dw_pcie_link_up(struct pcie_port *pp)

 {
        if (pp->ops->link_up)
drivers/pci/host/pcie-designware.c +0 -0
@@ -225,6 +432,13 @@ int __init dw_pcie_host_init(struct pcie_port *pp)
                return -EINVAL;
        }
 
Quoted 11 lines

drivers/pci/host/pcie-designware.c int __init dw_pcie_host_init(struct pcie_port *pp) · line 441

Quoted 7 lines
drivers/pci/host/pcie-designware.c +7 -0
+       if (IS_ENABLED(CONFIG_PCI_MSI)) {
+               if (of_property_read_u32(np, "msi-base", &pp->msi_irq_start)) {
+                       dev_err(pp->dev, "Failed to parse the number of lanes\n");
+                       return -EINVAL;
+               }
+       }
+

What if an implementor want to use irq_domain method for msi_irq_start allocation? Is it fine to return error if msi-base is not passed from dt?

Sure, I will consider using irq_domain method.

Quoted 3 lines

Also, with the limited knowledge of dt I do not understand one thing, how would dt understand that you have used 32 msi irqs (MAX_MSI_IRQS)?

Sorry, I cannot understand exactly. :-(
I will look into it.

I really appreciate your comments. :-)

Best regards,
Jingoo Han

#5 lore raw
Quoted 3 lines · Jingoo Han
Quoted 1 line · Pratyush Anand

On Fri, Aug 23, 2013 at 02:04:20PM +0800, Jingoo Han wrote:

[...]

Quoted 8 lines
Quoted 4 lines

#define MAX_PCIE_PORT_SUPPORTED 3
static DECLARE_BITMAP(msi_irq_in_use[MAX_PCIE_PORT_SUPPORTED],

                  NUM_MSI_IRQS);

static unsigned int *msi_data[MAX_PCIE_PORT_SUPPORTED];

No, there is no need to do it.
Without this, we can use 3 RCs by adding a node of 3rd RC to dt file.

Yes, you can use RCs by adding nodes to dt file. But you will need one msi_irq_in_use and one msi_data per RC (ie per port in this driver), isn't it?

Regards
Pratyush

author
#6 lore raw
Quoted 12 lines · Pratyush Anand
Quoted 3 lines · Jingoo Han
Quoted 1 line · Pratyush Anand

On Fri, Aug 23, 2013 at 02:04:20PM +0800, Jingoo Han wrote:

[...]

Quoted 5 lines
Quoted 4 lines

#define MAX_PCIE_PORT_SUPPORTED 3
static DECLARE_BITMAP(msi_irq_in_use[MAX_PCIE_PORT_SUPPORTED],

                  NUM_MSI_IRQS);

static unsigned int *msi_data[MAX_PCIE_PORT_SUPPORTED];

Quoted 6 lines
Quoted 3 lines

No, there is no need to do it.
Without this, we can use 3 RCs by adding a node of 3rd RC to dt file.

Yes, you can use RCs by adding nodes to dt file. But you will need one msi_irq_in_use and one msi_data per RC (ie per port in this driver), isn't it?

Aha, you're right.

A few minutes ago, I found the same value of msi_data is used for 2 different RCs. It is my fault.

As you mentioned, one msi_data per RC should be used. I will modify it in order to use one msi_data per RC.

Thank you for your kind description. :-)

Best regards,
Jingoo Han