All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers
@ 2018-06-13  7:24 Shawn Lin
  2018-06-13  7:25 ` [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:24 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin


Hi Bjorn and Lorenzo,

PCI host drivers use highly similar code block to allocate IRQ domain which
leads to code duplication than expected. This patchset adds a new helper,
pci_host_alloc_intx_irqd(), to avoid that as much as possible.


Changes in v3:
- rename to pci_host_alloc_intx_irqd and move to probe.c
- fix compile error reported by Kbuild Robot
- rebased

Changes in v2:
- fix typo and move the code to C file.

Shawn Lin (10):
  PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain
  PCI: dra7xx: Use pci_host_alloc_intx_irqd() helper to simplify the
    code
  PCI: keystone-dw: Use pci_host_alloc_intx_irqd() helper to get irq
    domain for INTx
  PCI: aardvark: Use pci_host_alloc_intx_irqd() helper to get irq domain
    for INTx
  PCI: faraday: Use pci_host_alloc_intx_irqd() helper to get irq domain
    for INTx
  PCI: altera: Use pci_host_alloc_intx_irqd() helper to get irq domain
    for INTx
  PCI: mediatek: Use pci_host_alloc_intx_irqd() helper to get irq domain
    for INTx
  PCI: xilinx-nwl: Use pci_host_alloc_intx_irqd() helper to get irq
    domain for INTx
  PCI: xilinx: Use pci_host_alloc_intx_irqd() helper to get irq domain
    for INTx
  PCI: rockchip: Use pci_host_alloc_intx_irqd() helper to get irq domain
    for INTx

 drivers/pci/controller/dwc/pci-dra7xx.c      | 42 ++--------------
 drivers/pci/controller/dwc/pci-keystone-dw.c | 13 ++---
 drivers/pci/controller/pci-aardvark.c        | 24 ++-------
 drivers/pci/controller/pci-ftpci100.c        | 15 ++----
 drivers/pci/controller/pcie-altera.c         | 38 ++------------
 drivers/pci/controller/pcie-mediatek.c       | 30 ++---------
 drivers/pci/controller/pcie-rockchip-host.c  | 38 ++------------
 drivers/pci/controller/pcie-xilinx-nwl.c     | 22 ++-------
 drivers/pci/controller/pcie-xilinx.c         | 44 ++---------------
 drivers/pci/probe.c                          | 74 ++++++++++++++++++++++++++++
 include/linux/pci.h                          | 13 +++++
 11 files changed, 125 insertions(+), 228 deletions(-)

-- 
1.9.1

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

* [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
@ 2018-06-13  7:25 ` Shawn Lin
  2018-06-13 10:03   ` kbuild test robot
  2018-06-13  7:25 ` [PATCH v3 02/10] PCI: dra7xx: Use pci_host_alloc_intx_irqd() helper to simplify the code Shawn Lin
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:25 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

It seems host drivers which allocate IRQ domain for INTx
and the related code block looks highly similar to each other.
Add a new helper, pci_alloc_intx_irqd(), to avoid code duplication
as much as possible.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

---

Changes in v3:
- rename to pci_host_alloc_intx_irqd and move to probe.c
- fix compile error reported by Kbuild Robot

Changes in v2:
- fix typo and move the code to C file.

 drivers/pci/probe.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h | 13 ++++++++++
 2 files changed, 87 insertions(+)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ac876e3..d37b879 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -3139,3 +3139,77 @@ int pci_hp_add_bridge(struct pci_dev *dev)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(pci_hp_add_bridge);
+
+static int pcie_intx_map(struct irq_domain *domain, unsigned int irq,
+			 irq_hw_number_t hwirq)
+{
+	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
+	irq_set_chip_data(irq, domain->host_data);
+
+	return 0;
+}
+
+/**
+ * pci_host_alloc_intx_irqd() - Allocate INTx IRQ domain
+ * @dev: device associated with the PCI controller.
+ * @host: pointer to host specific data struct
+ * @general_xlate: flag for whether use pci_irqd_intx_xlate() helper
+ * @intx_domain_ops: pointer to driver specific struct irq_domain_ops
+ * @local_intc: pointer to driver specific interrupt controller node
+ *
+ * A simple helper for drivers to allocate IRQ domain for INTx. If
+ * intx_domain_ops is NULL, use pci_intx_domain_ops by default. And if
+ * local_intc is present, then use it firstly, otherwise, fallback to get
+ * interrupt controller node from @dev.
+ *
+ * Returns valid pointer of struct irq_domain on success, or PTR_ERR(-EINVAL)
+ * if failure occurred.
+ */
+struct irq_domain *pci_host_alloc_intx_irqd(struct device *dev, void *host,
+	bool general_xlate, const struct irq_domain_ops *intx_domain_ops,
+	struct device_node *local_intc)
+{
+	struct device_node *intc = local_intc;
+	struct irq_domain *domain = NULL;
+	struct irq_domain_ops *irqd_ops;
+	bool need_put = false;
+	int err = -EINVAL;
+
+	if (!intc) {
+		intc = of_get_next_child(dev->of_node, NULL);
+		if (!intc) {
+			dev_err(dev, "missing child interrupt-controller node\n");
+			goto err_out;
+		}
+		need_put = true;
+	}
+
+	if (!intx_domain_ops) {
+		irqd_ops = (struct irq_domain_ops *)devm_kmalloc(dev,
+				sizeof(struct irq_domain_ops), GFP_KERNEL);
+		if (!irqd_ops) {
+			err = -ENOMEM;
+			goto err_out;
+		}
+
+		irqd_ops->map = &pcie_intx_map;
+		if (general_xlate)
+			irqd_ops->xlate = &pci_irqd_intx_xlate;
+		intx_domain_ops = irqd_ops;
+	}
+#ifdef CONFIG_IRQ_DOMAIN
+	domain = irq_domain_add_linear(intc, PCI_NUM_INTX,
+				       intx_domain_ops, host);
+#endif
+	if (!domain) {
+		dev_err(dev, "failed to get a INTx IRQ domain\n");
+		goto err_out;
+	}
+
+	return domain;
+err_out:
+	if (need_put)
+		of_node_put(intc);
+	return ERR_PTR(err);
+}
+EXPORT_SYMBOL_GPL(pci_host_alloc_intx_irqd);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 340029b..06ed80d 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -31,6 +31,9 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
+#include <linux/of_irq.h>
 #include <linux/resource_ext.h>
 #include <uapi/linux/pci.h>
 
@@ -1453,6 +1456,10 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
 	return 0;
 }
 
+extern struct irq_domain *pci_host_alloc_intx_irqd(struct device *dev,
+				void *host, bool general_xlate,
+				const struct irq_domain_ops *intx_domain_ops,
+				struct device_node *local_intc);
 #ifdef CONFIG_PCIEPORTBUS
 extern bool pcie_ports_disabled;
 extern bool pcie_ports_native;
@@ -1688,6 +1695,12 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
 				      unsigned long *out_hwirq,
 				      unsigned int *out_type)
 { return -EINVAL; }
+
+static struct irq_domain *pci_host_alloc_intx_irqd(struct device *dev,
+				void *host, bool general_xlate,
+				const struct irq_domain_ops *intx_domain_ops,
+				struct device_node *local_intc)
+{ return ERR_PTR(-EINVAL); }
 #endif /* CONFIG_PCI */
 
 /* Include architecture-dependent settings and functions */
-- 
1.9.1

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

* [PATCH v3 02/10] PCI: dra7xx: Use pci_host_alloc_intx_irqd() helper to simplify the code
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
  2018-06-13  7:25 ` [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
@ 2018-06-13  7:25 ` Shawn Lin
  2018-06-13  7:25 ` [PATCH v3 03/10] PCI: keystone-dw: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:25 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/dwc/pci-dra7xx.c | 42 +++------------------------------
 1 file changed, 3 insertions(+), 39 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c
index cfaeef8..a281924 100644
--- a/drivers/pci/controller/dwc/pci-dra7xx.c
+++ b/drivers/pci/controller/dwc/pci-dra7xx.c
@@ -213,43 +213,6 @@ static int dra7xx_pcie_host_init(struct pcie_port *pp)
 	.host_init = dra7xx_pcie_host_init,
 };
 
-static int dra7xx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
-				irq_hw_number_t hwirq)
-{
-	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
-	irq_set_chip_data(irq, domain->host_data);
-
-	return 0;
-}
-
-static const struct irq_domain_ops intx_domain_ops = {
-	.map = dra7xx_pcie_intx_map,
-	.xlate = pci_irqd_intx_xlate,
-};
-
-static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)
-{
-	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
-	struct device *dev = pci->dev;
-	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
-	struct device_node *node = dev->of_node;
-	struct device_node *pcie_intc_node =  of_get_next_child(node, NULL);
-
-	if (!pcie_intc_node) {
-		dev_err(dev, "No PCIe Intc node found\n");
-		return -ENODEV;
-	}
-
-	dra7xx->irq_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
-						   &intx_domain_ops, pp);
-	if (!dra7xx->irq_domain) {
-		dev_err(dev, "Failed to get a INTx IRQ domain\n");
-		return -ENODEV;
-	}
-
-	return 0;
-}
-
 static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)
 {
 	struct dra7xx_pcie *dra7xx = arg;
@@ -455,8 +418,9 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
 		return ret;
 	}
 
-	ret = dra7xx_pcie_init_irq_domain(pp);
-	if (ret < 0)
+	dra7xx->irq_domain = pci_host_alloc_intx_irqd(dev, dra7xx, true, NULL,
+						      NULL);
+	if (IS_ERR(dra7xx->irq_domain))
 		return ret;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbics");
-- 
1.9.1

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

* [PATCH v3 03/10] PCI: keystone-dw: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
  2018-06-13  7:25 ` [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
  2018-06-13  7:25 ` [PATCH v3 02/10] PCI: dra7xx: Use pci_host_alloc_intx_irqd() helper to simplify the code Shawn Lin
@ 2018-06-13  7:25 ` Shawn Lin
  2018-06-13  7:26 ` [PATCH v3 04/10] PCI: aardvark: " Shawn Lin
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:25 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/dwc/pci-keystone-dw.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-keystone-dw.c b/drivers/pci/controller/dwc/pci-keystone-dw.c
index 0682213..a45809d 100644
--- a/drivers/pci/controller/dwc/pci-keystone-dw.c
+++ b/drivers/pci/controller/dwc/pci-keystone-dw.c
@@ -470,15 +470,12 @@ int __init ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie,
 	ks_pcie->app = *res;
 
 	/* Create legacy IRQ domain */
-	ks_pcie->legacy_irq_domain =
-			irq_domain_add_linear(ks_pcie->legacy_intc_np,
-					PCI_NUM_INTX,
+	ks_pcie->legacy_irq_domain = pci_host_alloc_intx_irqd(dev, ks_pcie,
+					false,
 					&ks_dw_pcie_legacy_irq_domain_ops,
-					NULL);
-	if (!ks_pcie->legacy_irq_domain) {
-		dev_err(dev, "Failed to add irq domain for legacy irqs\n");
-		return -EINVAL;
-	}
+					ks_pcie->legacy_intc_np);
+	if (IS_ERR(ks_pcie->legacy_irq_domain))
+		return PTR_ERR(ks_pcie->legacy_irq_domain);
 
 	return dw_pcie_host_init(pp);
 }
-- 
1.9.1

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

* [PATCH v3 04/10] PCI: aardvark: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (2 preceding siblings ...)
  2018-06-13  7:25 ` [PATCH v3 03/10] PCI: keystone-dw: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
@ 2018-06-13  7:26 ` Shawn Lin
  2018-06-13  7:26 ` [PATCH v3 05/10] PCI: faraday: " Shawn Lin
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pci-aardvark.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index d3172d5..4c31582 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -704,37 +704,23 @@ static void advk_pcie_remove_msi_irq_domain(struct advk_pcie *pcie)
 static int advk_pcie_init_irq_domain(struct advk_pcie *pcie)
 {
 	struct device *dev = &pcie->pdev->dev;
-	struct device_node *node = dev->of_node;
-	struct device_node *pcie_intc_node;
 	struct irq_chip *irq_chip;
 
-	pcie_intc_node =  of_get_next_child(node, NULL);
-	if (!pcie_intc_node) {
-		dev_err(dev, "No PCIe Intc node found\n");
-		return -ENODEV;
-	}
-
 	irq_chip = &pcie->irq_chip;
 
 	irq_chip->name = devm_kasprintf(dev, GFP_KERNEL, "%s-irq",
 					dev_name(dev));
-	if (!irq_chip->name) {
-		of_node_put(pcie_intc_node);
+	if (!irq_chip->name)
 		return -ENOMEM;
-	}
 
 	irq_chip->irq_mask = advk_pcie_irq_mask;
 	irq_chip->irq_mask_ack = advk_pcie_irq_mask;
 	irq_chip->irq_unmask = advk_pcie_irq_unmask;
 
-	pcie->irq_domain =
-		irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
-				      &advk_pcie_irq_domain_ops, pcie);
-	if (!pcie->irq_domain) {
-		dev_err(dev, "Failed to get a INTx IRQ domain\n");
-		of_node_put(pcie_intc_node);
-		return -ENOMEM;
-	}
+	pcie->irq_domain = pci_host_alloc_intx_irqd(dev, pcie, false,
+				&advk_pcie_irq_domain_ops, NULL);
+	if (IS_ERR(pcie->irq_domain))
+		return PTR_ERR(pcie->irq_domain);
 
 	return 0;
 }
-- 
1.9.1

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

* [PATCH v3 05/10] PCI: faraday: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (3 preceding siblings ...)
  2018-06-13  7:26 ` [PATCH v3 04/10] PCI: aardvark: " Shawn Lin
@ 2018-06-13  7:26 ` Shawn Lin
  2018-06-13  7:26 ` [PATCH v3 06/10] PCI: altera: " Shawn Lin
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pci-ftpci100.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index a1ebe9e..8ace724 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -346,24 +346,19 @@ static int faraday_pci_setup_cascaded_irq(struct faraday_pci *p)
 	int irq;
 	int i;
 
-	if (!intc) {
-		dev_err(p->dev, "missing child interrupt-controller node\n");
-		return -EINVAL;
-	}
+	p->irqdomain = pci_host_alloc_intx_irqd(p->dev, p, false,
+					   &faraday_pci_irqdomain_ops, intc);
+	if (IS_ERR(p->irqdomain))
+		return PTR_ERR(p->irqdomain);
 
 	/* All PCI IRQs cascade off this one */
 	irq = of_irq_get(intc, 0);
 	if (irq <= 0) {
 		dev_err(p->dev, "failed to get parent IRQ\n");
+		irq_domain_remove(p->irqdomain);
 		return irq ?: -EINVAL;
 	}
 
-	p->irqdomain = irq_domain_add_linear(intc, PCI_NUM_INTX,
-					     &faraday_pci_irqdomain_ops, p);
-	if (!p->irqdomain) {
-		dev_err(p->dev, "failed to create Gemini PCI IRQ domain\n");
-		return -EINVAL;
-	}
 
 	irq_set_chained_handler_and_data(irq, faraday_pci_irq_handler, p);
 
-- 
1.9.1

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

* [PATCH v3 06/10] PCI: altera: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (4 preceding siblings ...)
  2018-06-13  7:26 ` [PATCH v3 05/10] PCI: faraday: " Shawn Lin
@ 2018-06-13  7:26 ` Shawn Lin
  2018-06-13  7:26 ` [PATCH v3 07/10] PCI: mediatek: " Shawn Lin
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pcie-altera.c | 38 ++++--------------------------------
 1 file changed, 4 insertions(+), 34 deletions(-)

diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c
index 7d05e51..0915c8b 100644
--- a/drivers/pci/controller/pcie-altera.c
+++ b/drivers/pci/controller/pcie-altera.c
@@ -443,19 +443,6 @@ static void altera_pcie_retrain(struct altera_pcie *pcie)
 	}
 }
 
-static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
-				irq_hw_number_t hwirq)
-{
-	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
-	irq_set_chip_data(irq, domain->host_data);
-	return 0;
-}
-
-static const struct irq_domain_ops intx_domain_ops = {
-	.map = altera_pcie_intx_map,
-	.xlate = pci_irqd_intx_xlate,
-};
-
 static void altera_pcie_isr(struct irq_desc *desc)
 {
 	struct irq_chip *chip = irq_desc_get_chip(desc);
@@ -519,22 +506,6 @@ static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
 	return err;
 }
 
-static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
-{
-	struct device *dev = &pcie->pdev->dev;
-	struct device_node *node = dev->of_node;
-
-	/* Setup INTx */
-	pcie->irq_domain = irq_domain_add_linear(node, PCI_NUM_INTX,
-					&intx_domain_ops, pcie);
-	if (!pcie->irq_domain) {
-		dev_err(dev, "Failed to get a INTx IRQ domain\n");
-		return -ENOMEM;
-	}
-
-	return 0;
-}
-
 static int altera_pcie_parse_dt(struct altera_pcie *pcie)
 {
 	struct device *dev = &pcie->pdev->dev;
@@ -592,11 +563,10 @@ static int altera_pcie_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = altera_pcie_init_irq_domain(pcie);
-	if (ret) {
-		dev_err(dev, "Failed creating IRQ Domain\n");
-		return ret;
-	}
+	pcie->irq_domain = pci_host_alloc_intx_irqd(dev, pcie, true, NULL,
+						    dev->of_node);
+	if (IS_ERR(pcie->irq_domain))
+		return PTR_ERR(pcie->irq_domain);
 
 	/* clear all interrupts */
 	cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);
-- 
1.9.1

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

* [PATCH v3 07/10] PCI: mediatek: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (5 preceding siblings ...)
  2018-06-13  7:26 ` [PATCH v3 06/10] PCI: altera: " Shawn Lin
@ 2018-06-13  7:26 ` Shawn Lin
  2018-06-13  7:26 ` [PATCH v3 08/10] PCI: xilinx-nwl: " Shawn Lin
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pcie-mediatek.c | 30 ++++--------------------------
 1 file changed, 4 insertions(+), 26 deletions(-)

diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 0baabe3..b35a8ce 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -590,39 +590,17 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)
 	writel(val, port->base + PCIE_INT_MASK);
 }
 
-static int mtk_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
-			     irq_hw_number_t hwirq)
-{
-	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
-	irq_set_chip_data(irq, domain->host_data);
-
-	return 0;
-}
-
-static const struct irq_domain_ops intx_domain_ops = {
-	.map = mtk_pcie_intx_map,
-};
-
 static int mtk_pcie_init_irq_domain(struct mtk_pcie_port *port,
 				    struct device_node *node)
 {
 	struct device *dev = port->pcie->dev;
-	struct device_node *pcie_intc_node;
 	int ret;
 
-	/* Setup INTx */
-	pcie_intc_node = of_get_next_child(node, NULL);
-	if (!pcie_intc_node) {
-		dev_err(dev, "no PCIe Intc node found\n");
-		return -ENODEV;
-	}
+	port->irq_domain = pci_host_alloc_intx_irqd(dev, port, false,
+						    NULL, NULL);
+	if (IS_ERR(port->irq_domain))
+		return PTR_ERR(port->irq_domain);
 
-	port->irq_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
-						 &intx_domain_ops, port);
-	if (!port->irq_domain) {
-		dev_err(dev, "failed to get INTx IRQ domain\n");
-		return -ENODEV;
-	}
 
 	if (IS_ENABLED(CONFIG_PCI_MSI)) {
 		ret = mtk_pcie_allocate_msi_domains(port);
-- 
1.9.1

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

* [PATCH v3 08/10] PCI: xilinx-nwl: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (6 preceding siblings ...)
  2018-06-13  7:26 ` [PATCH v3 07/10] PCI: mediatek: " Shawn Lin
@ 2018-06-13  7:26 ` Shawn Lin
  2018-06-13  7:27 ` [PATCH v3 09/10] PCI: xilinx: " Shawn Lin
  2018-06-13  7:27 ` [PATCH v3 10/10] PCI: rockchip: " Shawn Lin
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pcie-xilinx-nwl.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c
index 6a4bbb5..b0d13bb 100644
--- a/drivers/pci/controller/pcie-xilinx-nwl.c
+++ b/drivers/pci/controller/pcie-xilinx-nwl.c
@@ -546,24 +546,12 @@ static int nwl_pcie_init_msi_irq_domain(struct nwl_pcie *pcie)
 static int nwl_pcie_init_irq_domain(struct nwl_pcie *pcie)
 {
 	struct device *dev = pcie->dev;
-	struct device_node *node = dev->of_node;
-	struct device_node *legacy_intc_node;
-
-	legacy_intc_node = of_get_next_child(node, NULL);
-	if (!legacy_intc_node) {
-		dev_err(dev, "No legacy intc node found\n");
-		return -EINVAL;
-	}
 
-	pcie->legacy_irq_domain = irq_domain_add_linear(legacy_intc_node,
-							PCI_NUM_INTX,
-							&legacy_domain_ops,
-							pcie);
-
-	if (!pcie->legacy_irq_domain) {
-		dev_err(dev, "failed to create IRQ domain\n");
-		return -ENOMEM;
-	}
+	pcie->legacy_irq_domain = pci_host_alloc_intx_irqd(dev, pcie, false,
+							   &legacy_domain_ops,
+							   NULL);
+	if (IS_ERR(pcie->legacy_irq_domain))
+		return PTR_ERR(pcie->legacy_irq_domain);
 
 	raw_spin_lock_init(&pcie->leg_mask_lock);
 	nwl_pcie_init_msi_irq_domain(pcie);
-- 
1.9.1

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

* [PATCH v3 09/10] PCI: xilinx: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (7 preceding siblings ...)
  2018-06-13  7:26 ` [PATCH v3 08/10] PCI: xilinx-nwl: " Shawn Lin
@ 2018-06-13  7:27 ` Shawn Lin
  2018-06-13  7:27 ` [PATCH v3 10/10] PCI: rockchip: " Shawn Lin
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:27 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pcie-xilinx.c | 44 ++++--------------------------------
 1 file changed, 4 insertions(+), 40 deletions(-)

diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index b110a3a..8dbfc76 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -346,31 +346,6 @@ static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
 	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
 }
 
-/* INTx Functions */
-
-/**
- * xilinx_pcie_intx_map - Set the handler for the INTx and mark IRQ as valid
- * @domain: IRQ domain
- * @irq: Virtual IRQ number
- * @hwirq: HW interrupt number
- *
- * Return: Always returns 0.
- */
-static int xilinx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
-				irq_hw_number_t hwirq)
-{
-	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
-	irq_set_chip_data(irq, domain->host_data);
-
-	return 0;
-}
-
-/* INTx IRQ Domain operations */
-static const struct irq_domain_ops intx_domain_ops = {
-	.map = xilinx_pcie_intx_map,
-	.xlate = pci_irqd_intx_xlate,
-};
-
 /* PCIe HW Functions */
 
 /**
@@ -497,22 +472,11 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 {
 	struct device *dev = port->dev;
 	struct device_node *node = dev->of_node;
-	struct device_node *pcie_intc_node;
 
-	/* Setup INTx */
-	pcie_intc_node = of_get_next_child(node, NULL);
-	if (!pcie_intc_node) {
-		dev_err(dev, "No PCIe Intc node found\n");
-		return -ENODEV;
-	}
-
-	port->leg_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
-						 &intx_domain_ops,
-						 port);
-	if (!port->leg_domain) {
-		dev_err(dev, "Failed to get a INTx IRQ domain\n");
-		return -ENODEV;
-	}
+	port->leg_domain = pci_host_alloc_intx_irqd(dev, port, true, NULL,
+						    NULL);
+	if (IS_ERR(port->leg_domain))
+		return PTR_ERR(port->leg_domain);
 
 	/* Setup MSI */
 	if (IS_ENABLED(CONFIG_PCI_MSI)) {
-- 
1.9.1

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

* [PATCH v3 10/10] PCI: rockchip: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx
  2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (8 preceding siblings ...)
  2018-06-13  7:27 ` [PATCH v3 09/10] PCI: xilinx: " Shawn Lin
@ 2018-06-13  7:27 ` Shawn Lin
  9 siblings, 0 replies; 12+ messages in thread
From: Shawn Lin @ 2018-06-13  7:27 UTC (permalink / raw)
  To: Bjorn Helgaas, Lorenzo Pieralisi; +Cc: linux-pci, Shawn Lin

Just avoid code duplication, but no functional change intended.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v3: None
Changes in v2: None

 drivers/pci/controller/pcie-rockchip-host.c | 38 +++--------------------------
 1 file changed, 3 insertions(+), 35 deletions(-)

diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 1372d27..eb62ba4 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -699,39 +699,6 @@ static void rockchip_pcie_enable_interrupts(struct rockchip_pcie *rockchip)
 	rockchip_pcie_enable_bw_int(rockchip);
 }
 
-static int rockchip_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
-				  irq_hw_number_t hwirq)
-{
-	irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
-	irq_set_chip_data(irq, domain->host_data);
-
-	return 0;
-}
-
-static const struct irq_domain_ops intx_domain_ops = {
-	.map = rockchip_pcie_intx_map,
-};
-
-static int rockchip_pcie_init_irq_domain(struct rockchip_pcie *rockchip)
-{
-	struct device *dev = rockchip->dev;
-	struct device_node *intc = of_get_next_child(dev->of_node, NULL);
-
-	if (!intc) {
-		dev_err(dev, "missing child interrupt-controller node\n");
-		return -EINVAL;
-	}
-
-	rockchip->irq_domain = irq_domain_add_linear(intc, PCI_NUM_INTX,
-						    &intx_domain_ops, rockchip);
-	if (!rockchip->irq_domain) {
-		dev_err(dev, "failed to get a INTx IRQ domain\n");
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static int rockchip_pcie_prog_ob_atu(struct rockchip_pcie *rockchip,
 				     int region_no, int type, u8 num_pass_bits,
 				     u32 lower_addr, u32 upper_addr)
@@ -990,8 +957,9 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 
 	rockchip_pcie_enable_interrupts(rockchip);
 
-	err = rockchip_pcie_init_irq_domain(rockchip);
-	if (err < 0)
+	rockchip->irq_domain = pci_host_alloc_intx_irqd(dev, rockchip, false,
+							NULL, NULL);
+	if (IS_ERR(rockchip->irq_domain))
 		goto err_deinit_port;
 
 	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
-- 
1.9.1

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

* Re: [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain
  2018-06-13  7:25 ` [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
@ 2018-06-13 10:03   ` kbuild test robot
  0 siblings, 0 replies; 12+ messages in thread
From: kbuild test robot @ 2018-06-13 10:03 UTC (permalink / raw)
  To: Shawn Lin
  Cc: kbuild-all, Bjorn Helgaas, Lorenzo Pieralisi, linux-pci, Shawn Lin

[-- Attachment #1: Type: text/plain, Size: 1706 bytes --]

Hi Shawn,

I love your patch! Yet something to improve:

[auto build test ERROR on pci/next]
[also build test ERROR on v4.17 next-20180613]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Shawn-Lin/Add-new-helper-to-allocate-IRQ-domain-for-host-drivers/20180613-153030
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: sh-rsk7269_defconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=sh 

All errors (new ones prefixed by >>):

   In file included from arch/sh/kernel/io.c:12:0:
>> include/linux/pci.h:1699:27: error: 'pci_host_alloc_intx_irqd' defined but not used [-Werror=unused-function]
    static struct irq_domain *pci_host_alloc_intx_irqd(struct device *dev,
                              ^~~~~~~~~~~~~~~~~~~~~~~~
   cc1: all warnings being treated as errors

vim +/pci_host_alloc_intx_irqd +1699 include/linux/pci.h

  1698	
> 1699	static struct irq_domain *pci_host_alloc_intx_irqd(struct device *dev,
  1700					void *host, bool general_xlate,
  1701					const struct irq_domain_ops *intx_domain_ops,
  1702					struct device_node *local_intc)
  1703	{ return ERR_PTR(-EINVAL); }
  1704	#endif /* CONFIG_PCI */
  1705	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 10590 bytes --]

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

end of thread, other threads:[~2018-06-13 10:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-13  7:24 [PATCH v3 0/10] Add new helper to allocate IRQ domain for host drivers Shawn Lin
2018-06-13  7:25 ` [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
2018-06-13 10:03   ` kbuild test robot
2018-06-13  7:25 ` [PATCH v3 02/10] PCI: dra7xx: Use pci_host_alloc_intx_irqd() helper to simplify the code Shawn Lin
2018-06-13  7:25 ` [PATCH v3 03/10] PCI: keystone-dw: Use pci_host_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
2018-06-13  7:26 ` [PATCH v3 04/10] PCI: aardvark: " Shawn Lin
2018-06-13  7:26 ` [PATCH v3 05/10] PCI: faraday: " Shawn Lin
2018-06-13  7:26 ` [PATCH v3 06/10] PCI: altera: " Shawn Lin
2018-06-13  7:26 ` [PATCH v3 07/10] PCI: mediatek: " Shawn Lin
2018-06-13  7:26 ` [PATCH v3 08/10] PCI: xilinx-nwl: " Shawn Lin
2018-06-13  7:27 ` [PATCH v3 09/10] PCI: xilinx: " Shawn Lin
2018-06-13  7:27 ` [PATCH v3 10/10] PCI: rockchip: " Shawn Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.