All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers
@ 2018-04-28  1:48 Shawn Lin
  2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:48 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +Cc: linux-pci, Shawn Lin


Hi Bjorn and Lorenzo,

PCI drivers use highly similar code block to allocate IRQ domain which
leads to code duplication than expected. This patchset adds a new helper,
pci_alloc_intx_irqd(), to avoid that as much as possible. Just leave
pcie-rockchip out now as it's under re-construct and will add incremental
patch for it if this series looks ok and the pcie-rockchip ongoing patches
got merge.


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

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

 drivers/pci/dwc/pci-dra7xx.c       | 41 ++---------------------
 drivers/pci/dwc/pci-keystone-dw.c  | 12 +++----
 drivers/pci/host/pci-aardvark.c    | 24 +++-----------
 drivers/pci/host/pci-ftpci100.c    | 15 +++------
 drivers/pci/host/pcie-altera.c     | 38 +++------------------
 drivers/pci/host/pcie-mediatek.c   | 29 ++--------------
 drivers/pci/host/pcie-xilinx-nwl.c | 21 +++---------
 drivers/pci/host/pcie-xilinx.c     | 43 ++----------------------
 drivers/pci/irq.c                  | 68 ++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h                | 10 ++++++
 10 files changed, 108 insertions(+), 193 deletions(-)

-- 
1.9.1

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

* [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
@ 2018-04-28  1:48 ` Shawn Lin
  2018-04-28 17:59   ` Christoph Hellwig
                     ` (2 more replies)
  2018-04-28  1:49 ` [PATCH v2 2/9] PCI: dra7xx: Use pci_alloc_intx_irqd() helper to simplify the code Shawn Lin
                   ` (7 subsequent siblings)
  8 siblings, 3 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:48 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +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 v2:
- fix typo and move the code to C file.

 drivers/pci/irq.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h | 10 ++++++++
 2 files changed, 78 insertions(+)

diff --git a/drivers/pci/irq.c b/drivers/pci/irq.c
index 2a808e1..57fe0f4 100644
--- a/drivers/pci/irq.c
+++ b/drivers/pci/irq.c
@@ -118,3 +118,71 @@ void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id)
 	kfree(free_irq(pci_irq_vector(dev, nr), dev_id));
 }
 EXPORT_SYMBOL(pci_free_irq);
+
+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;
+}
+
+static struct irq_domain_ops pci_intx_domain_ops = {
+	.map = pcie_intx_map,
+};
+
+/**
+ * pci_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_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;
+	const struct irq_domain_ops *irqd_ops;
+	bool need_put = false;
+
+	if (!intc) {
+		intc = of_get_next_child(dev->of_node, NULL);
+		if (!intc) {
+			dev_err(dev, "missing child interrupt-controller node\n");
+			return ERR_PTR(-EINVAL);
+		}
+		need_put = true;
+	}
+
+	if (intx_domain_ops) {
+		irqd_ops = intx_domain_ops;
+	} else {
+		if (general_xlate)
+			pci_intx_domain_ops.xlate = &pci_irqd_intx_xlate;
+		irqd_ops = &pci_intx_domain_ops;
+	}
+
+	domain = irq_domain_add_linear(intc, PCI_NUM_INTX,
+				       irqd_ops, host);
+	if (!domain) {
+		dev_err(dev, "failed to get a INTx IRQ domain\n");
+		if (need_put)
+			of_node_put(intc);
+		return ERR_PTR(-EINVAL);
+	}
+
+	return domain;
+}
+EXPORT_SYMBOL_GPL(pci_alloc_intx_irqd);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 73178a2..18cc39f 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -31,6 +31,8 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/of_irq.h>
 #include <linux/resource_ext.h>
 #include <uapi/linux/pci.h>
 
@@ -1449,6 +1451,9 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
 	return 0;
 }
 
+extern struct irq_domain *pci_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;
 #else
@@ -1683,6 +1688,11 @@ 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_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] 13+ messages in thread

* [PATCH v2 2/9] PCI: dra7xx: Use pci_alloc_intx_irqd() helper to simplify the code
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
  2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
@ 2018-04-28  1:49 ` Shawn Lin
  2018-04-28  1:49 ` [PATCH v2 3/9] PCI: keystone-dw: Use pci_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:49 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, Shawn Lin, Kishon Vijay Abraham I

Just avoid code duplication, but no functional change intended.

Cc: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v2: None

 drivers/pci/dwc/pci-dra7xx.c | 41 ++---------------------------------------
 1 file changed, 2 insertions(+), 39 deletions(-)

diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index ed8558d..45f6456 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -212,43 +212,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;
@@ -454,8 +417,8 @@ 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_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] 13+ messages in thread

* [PATCH v2 3/9] PCI: keystone-dw: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
  2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
  2018-04-28  1:49 ` [PATCH v2 2/9] PCI: dra7xx: Use pci_alloc_intx_irqd() helper to simplify the code Shawn Lin
@ 2018-04-28  1:49 ` Shawn Lin
  2018-04-28  1:49 ` [PATCH v2 4/9] PCI: aardvark: " Shawn Lin
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:49 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, Shawn Lin, Kishon Vijay Abraham I

Just avoid code duplication, but no functional change intended.

Cc: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v2: None

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

diff --git a/drivers/pci/dwc/pci-keystone-dw.c b/drivers/pci/dwc/pci-keystone-dw.c
index 0682213..171198a 100644
--- a/drivers/pci/dwc/pci-keystone-dw.c
+++ b/drivers/pci/dwc/pci-keystone-dw.c
@@ -470,15 +470,11 @@ 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_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] 13+ messages in thread

* [PATCH v2 4/9] PCI: aardvark: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (2 preceding siblings ...)
  2018-04-28  1:49 ` [PATCH v2 3/9] PCI: keystone-dw: Use pci_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
@ 2018-04-28  1:49 ` Shawn Lin
  2018-04-28  1:49 ` [PATCH v2 5/9] PCI: faraday: " Shawn Lin
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:49 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +Cc: linux-pci, Shawn Lin, Thomas Petazzoni

Just avoid code duplication, but no functional change intended.

Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v2: None

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

diff --git a/drivers/pci/host/pci-aardvark.c b/drivers/pci/host/pci-aardvark.c
index 9abf549..df02b9a 100644
--- a/drivers/pci/host/pci-aardvark.c
+++ b/drivers/pci/host/pci-aardvark.c
@@ -702,37 +702,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_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] 13+ messages in thread

* [PATCH v2 5/9] PCI: faraday: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (3 preceding siblings ...)
  2018-04-28  1:49 ` [PATCH v2 4/9] PCI: aardvark: " Shawn Lin
@ 2018-04-28  1:49 ` Shawn Lin
  2018-04-28  1:50 ` [PATCH v2 6/9] PCI: altera: " Shawn Lin
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:49 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +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 v2: None

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

diff --git a/drivers/pci/host/pci-ftpci100.c b/drivers/pci/host/pci-ftpci100.c
index 5008fd8..018e4f4 100644
--- a/drivers/pci/host/pci-ftpci100.c
+++ b/drivers/pci/host/pci-ftpci100.c
@@ -344,24 +344,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_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] 13+ messages in thread

* [PATCH v2 6/9] PCI: altera: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (4 preceding siblings ...)
  2018-04-28  1:49 ` [PATCH v2 5/9] PCI: faraday: " Shawn Lin
@ 2018-04-28  1:50 ` Shawn Lin
  2018-04-28  1:50 ` [PATCH v2 7/9] PCI: mediatek: " Shawn Lin
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:50 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +Cc: linux-pci, Shawn Lin, Ley Foon Tan

Just avoid code duplication, but no functional change intended.

Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v2: None

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

diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c
index a6af62e..a0fcf0f 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -441,19 +441,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);
@@ -518,22 +505,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;
@@ -591,11 +562,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_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] 13+ messages in thread

* [PATCH v2 7/9] PCI: mediatek: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (5 preceding siblings ...)
  2018-04-28  1:50 ` [PATCH v2 6/9] PCI: altera: " Shawn Lin
@ 2018-04-28  1:50 ` Shawn Lin
  2018-04-28  1:50 ` [PATCH v2 8/9] PCI: xilinx-nwl: " Shawn Lin
  2018-04-28  1:50 ` [PATCH v2 9/9] PCI: xilinx: " Shawn Lin
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:50 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +Cc: linux-pci, Shawn Lin, Ryder Lee

Just avoid code duplication, but no functional change intended.

Cc: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

Changes in v2: None

 drivers/pci/host/pcie-mediatek.c | 29 +++--------------------------
 1 file changed, 3 insertions(+), 26 deletions(-)

diff --git a/drivers/pci/host/pcie-mediatek.c b/drivers/pci/host/pcie-mediatek.c
index a8b20c5..e977a43 100644
--- a/drivers/pci/host/pcie-mediatek.c
+++ b/drivers/pci/host/pcie-mediatek.c
@@ -541,38 +541,15 @@ 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;
 
-	/* 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_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)) {
 		port->msi_domain = irq_domain_add_linear(node, MTK_MSI_IRQS_NUM,
-- 
1.9.1

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

* [PATCH v2 8/9] PCI: xilinx-nwl: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (6 preceding siblings ...)
  2018-04-28  1:50 ` [PATCH v2 7/9] PCI: mediatek: " Shawn Lin
@ 2018-04-28  1:50 ` Shawn Lin
  2018-04-28  1:50 ` [PATCH v2 9/9] PCI: xilinx: " Shawn Lin
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:50 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +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 v2: None

 drivers/pci/host/pcie-xilinx-nwl.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/host/pcie-xilinx-nwl.c b/drivers/pci/host/pcie-xilinx-nwl.c
index 4839ae5..1bb77c0 100644
--- a/drivers/pci/host/pcie-xilinx-nwl.c
+++ b/drivers/pci/host/pcie-xilinx-nwl.c
@@ -544,24 +544,11 @@ 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_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] 13+ messages in thread

* [PATCH v2 9/9] PCI: xilinx: Use pci_alloc_intx_irqd() helper to get irq domain for INTx
  2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
                   ` (7 preceding siblings ...)
  2018-04-28  1:50 ` [PATCH v2 8/9] PCI: xilinx-nwl: " Shawn Lin
@ 2018-04-28  1:50 ` Shawn Lin
  8 siblings, 0 replies; 13+ messages in thread
From: Shawn Lin @ 2018-04-28  1:50 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Bjorn Helgaas; +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 v2: None

 drivers/pci/host/pcie-xilinx.c | 43 +++---------------------------------------
 1 file changed, 3 insertions(+), 40 deletions(-)

diff --git a/drivers/pci/host/pcie-xilinx.c b/drivers/pci/host/pcie-xilinx.c
index 0ad188e..905668a 100644
--- a/drivers/pci/host/pcie-xilinx.c
+++ b/drivers/pci/host/pcie-xilinx.c
@@ -344,31 +344,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 */
 
 /**
@@ -495,22 +470,10 @@ 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_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] 13+ messages in thread

* Re: [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain
  2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
@ 2018-04-28 17:59   ` Christoph Hellwig
  2018-04-29 21:56   ` kbuild test robot
  2018-04-30  0:23   ` kbuild test robot
  2 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2018-04-28 17:59 UTC (permalink / raw)
  To: Shawn Lin; +Cc: Lorenzo Pieralisi, Bjorn Helgaas, linux-pci

On Sat, Apr 28, 2018 at 09:48:52AM +0800, Shawn Lin wrote:
> 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>

Maybe add a _host to the name as in pci_host_alloc_intx_irqdomain,
and potentially move it to a different file than irq.c, as that contains
helpers for drivers.

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

* Re: [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain
  2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
  2018-04-28 17:59   ` Christoph Hellwig
@ 2018-04-29 21:56   ` kbuild test robot
  2018-04-30  0:23   ` kbuild test robot
  2 siblings, 0 replies; 13+ messages in thread
From: kbuild test robot @ 2018-04-29 21:56 UTC (permalink / raw)
  To: Shawn Lin
  Cc: kbuild-all, Lorenzo Pieralisi, Bjorn Helgaas, linux-pci, Shawn Lin

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

Hi Shawn,

I love your patch! Perhaps something to improve:

[auto build test WARNING on pci/next]
[also build test WARNING on v4.17-rc2 next-20180426]
[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/20180430-025537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: s390-allmodconfig (attached as .config)
compiler: s390x-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
        make.cross ARCH=s390 

All warnings (new ones prefixed by >>):

   In file included from arch/s390/include/asm/hw_irq.h:6:0,
                    from include/linux/irq.h:522,
                    from include/linux/of_irq.h:7,
                    from drivers/dma/mv_xor.c:26:
>> include/linux/pci.h:1455:35: warning: 'struct irq_domain_ops' declared inside parameter list will not be visible outside of this definition or declaration
     bool general_xlate, const struct irq_domain_ops *intx_domain_ops,
                                      ^~~~~~~~~~~~~~

vim +1455 include/linux/pci.h

  1453	
  1454	extern struct irq_domain *pci_alloc_intx_irqd(struct device *dev, void *host,
> 1455		bool general_xlate, const struct irq_domain_ops *intx_domain_ops,
  1456		struct device_node *local_intc);
  1457	#ifdef CONFIG_PCIEPORTBUS
  1458	extern bool pcie_ports_disabled;
  1459	#else
  1460	#define pcie_ports_disabled	true
  1461	#endif
  1462	

---
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: 49268 bytes --]

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

* Re: [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain
  2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
  2018-04-28 17:59   ` Christoph Hellwig
  2018-04-29 21:56   ` kbuild test robot
@ 2018-04-30  0:23   ` kbuild test robot
  2 siblings, 0 replies; 13+ messages in thread
From: kbuild test robot @ 2018-04-30  0:23 UTC (permalink / raw)
  To: Shawn Lin
  Cc: kbuild-all, Lorenzo Pieralisi, Bjorn Helgaas, linux-pci, Shawn Lin

[-- Attachment #1: Type: text/plain, Size: 1657 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-rc3 next-20180426]
[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/20180430-025537
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: sh-allmodconfig (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
        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:1692:27: error: 'pci_alloc_intx_irqd' defined but not used [-Werror=unused-function]
    static struct irq_domain *pci_alloc_intx_irqd(struct device *dev, void *host,
                              ^~~~~~~~~~~~~~~~~~~
   cc1: all warnings being treated as errors

vim +/pci_alloc_intx_irqd +1692 include/linux/pci.h

  1691	
> 1692	static struct irq_domain *pci_alloc_intx_irqd(struct device *dev, void *host,
  1693		bool general_xlate, const struct irq_domain_ops *intx_domain_ops,
  1694		struct device_node *local_intc)
  1695	{ return ERR_PTR(-EINVAL); }
  1696	#endif /* CONFIG_PCI */
  1697	

---
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: 47750 bytes --]

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

end of thread, other threads:[~2018-04-30  0:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28  1:48 [PATCH v2 0/9] Add new helper to allocate IRQ domain for host drivers Shawn Lin
2018-04-28  1:48 ` [PATCH v2 1/9] PCI: Add pci_alloc_intx_irqd() for allocating IRQ domain Shawn Lin
2018-04-28 17:59   ` Christoph Hellwig
2018-04-29 21:56   ` kbuild test robot
2018-04-30  0:23   ` kbuild test robot
2018-04-28  1:49 ` [PATCH v2 2/9] PCI: dra7xx: Use pci_alloc_intx_irqd() helper to simplify the code Shawn Lin
2018-04-28  1:49 ` [PATCH v2 3/9] PCI: keystone-dw: Use pci_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
2018-04-28  1:49 ` [PATCH v2 4/9] PCI: aardvark: " Shawn Lin
2018-04-28  1:49 ` [PATCH v2 5/9] PCI: faraday: " Shawn Lin
2018-04-28  1:50 ` [PATCH v2 6/9] PCI: altera: " Shawn Lin
2018-04-28  1:50 ` [PATCH v2 7/9] PCI: mediatek: " Shawn Lin
2018-04-28  1:50 ` [PATCH v2 8/9] PCI: xilinx-nwl: " Shawn Lin
2018-04-28  1:50 ` [PATCH v2 9/9] PCI: xilinx: " 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.