From: Shawn Lin <shawn.lin@rock-chips.com>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, Shawn Lin <shawn.lin@rock-chips.com>
Subject: [PATCH 1/9] PCI: Add new helper for allocating irq domain for INTx
Date: Fri, 27 Apr 2018 16:22:47 +0800 [thread overview]
Message-ID: <1524817367-239076-1-git-send-email-shawn.lin@rock-chips.com> (raw)
In-Reply-To: <1524817322-239028-1-git-send-email-shawn.lin@rock-chips.com>
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>
---
include/linux/pci.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 73178a2..68a1994 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,74 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
return 0;
}
+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() - PCI helper for allocating 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 defalut. 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.
+ */
+static __maybe_unused 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;
+}
+
#ifdef CONFIG_PCIEPORTBUS
extern bool pcie_ports_disabled;
#else
@@ -1683,6 +1753,10 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
unsigned long *out_hwirq,
unsigned int *out_type)
{ return -EINVAL; }
+
+static __maybe_unused struct irq_domain *pci_alloc_intx_irqd(struct device *dev,
+ void *host, bool general_xlate, const struct irq_domain_ops *ops)
+{ return ERR_PTR(-EINVAL); }
#endif /* CONFIG_PCI */
/* Include architecture-dependent settings and functions */
--
1.9.1
next prev parent reply other threads:[~2018-04-27 8:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-27 8:22 [PATCH 0/9] Add new helper to allocate irq domain for hosts Shawn Lin
2018-04-27 8:22 ` Shawn Lin [this message]
2018-04-27 17:18 ` [PATCH 1/9] PCI: Add new helper for allocating irq domain for INTx Bjorn Helgaas
2018-04-28 0:44 ` Shawn Lin
2018-04-28 22:52 ` kbuild test robot
2018-04-28 23:08 ` kbuild test robot
2018-04-27 8:22 ` [PATCH 2/9] PCI: dra7xx: Use pci_alloc_intx_irqd() helper to simplify the code Shawn Lin
2018-04-27 8:23 ` [PATCH 3/9] PCI: keystone-dw: Use pci_alloc_intx_irqd() helper to get irq domain for INTx Shawn Lin
2018-04-27 8:23 ` [PATCH 4/9] PCI: aardvark: " Shawn Lin
2018-04-27 8:23 ` [PATCH 5/9] PCI: faraday: " Shawn Lin
2018-04-28 23:32 ` kbuild test robot
2018-04-27 8:24 ` [PATCH 6/9] PCI: altera: " Shawn Lin
2018-04-27 8:24 ` [PATCH 7/9] PCI: mediatek: " Shawn Lin
2018-04-27 8:24 ` [PATCH 8/9] PCI: xilinx-nwl: " Shawn Lin
2018-04-27 8:25 ` [PATCH 9/9] PCI: xilinx: " Shawn Lin
2018-04-30 10:19 ` [PATCH 0/9] Add new helper to allocate irq domain for hosts Lorenzo Pieralisi
2018-05-02 0:59 ` Shawn Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524817367-239076-1-git-send-email-shawn.lin@rock-chips.com \
--to=shawn.lin@rock-chips.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).