From patchwork Wed Jun 13 07:25:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10461725 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E32A7603B4 for ; Wed, 13 Jun 2018 07:25:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D47B328AD3 for ; Wed, 13 Jun 2018 07:25:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C773728AF9; Wed, 13 Jun 2018 07:25:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F35528AAA for ; Wed, 13 Jun 2018 07:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933618AbeFMHZk (ORCPT ); Wed, 13 Jun 2018 03:25:40 -0400 Received: from lucky1.263xmail.com ([211.157.147.133]:40363 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754452AbeFMHZk (ORCPT ); Wed, 13 Jun 2018 03:25:40 -0400 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.105]) by lucky1.263xmail.com (Postfix) with ESMTP id 2053D95788; Wed, 13 Jun 2018 15:25:37 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id D11CA39B; Wed, 13 Jun 2018 15:25:36 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: bhelgaas@google.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 3389I1XQKA; Wed, 13 Jun 2018 15:25:37 +0800 (CST) From: Shawn Lin To: Bjorn Helgaas , Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, Shawn Lin Subject: [PATCH v3 01/10] PCI: Add pci_host_alloc_intx_irqd() for allocating IRQ domain Date: Wed, 13 Jun 2018 15:25:20 +0800 Message-Id: <1528874720-7575-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1528874696-7524-1-git-send-email-shawn.lin@rock-chips.com> References: <1528874696-7524-1-git-send-email-shawn.lin@rock-chips.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include #include +#include +#include +#include #include #include @@ -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 */