From patchwork Fri Apr 27 08:22:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10367717 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 27C34601D3 for ; Fri, 27 Apr 2018 08:30:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140DB29225 for ; Fri, 27 Apr 2018 08:30:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 073E5292F8; Fri, 27 Apr 2018 08:30:44 +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 7D68D29225 for ; Fri, 27 Apr 2018 08:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757754AbeD0Iam (ORCPT ); Fri, 27 Apr 2018 04:30:42 -0400 Received: from lucky1.263xmail.com ([211.157.147.135]:54433 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757750AbeD0Ial (ORCPT ); Fri, 27 Apr 2018 04:30:41 -0400 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.160]) by lucky1.263xmail.com (Postfix) with ESMTP id B388B6DB2; Fri, 27 Apr 2018 16:30:33 +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 [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 120163BA; Fri, 27 Apr 2018 16:30:31 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: lorenzo.pieralisi@arm.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <42d5919b2cc44127677a20b365483eec> 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 14614DBDO8S; Fri, 27 Apr 2018 16:30:32 +0800 (CST) From: Shawn Lin To: Lorenzo Pieralisi , Bjorn Helgaas Cc: linux-pci@vger.kernel.org, Shawn Lin Subject: [PATCH 1/9] PCI: Add new helper for allocating irq domain for INTx Date: Fri, 27 Apr 2018 16:22:47 +0800 Message-Id: <1524817367-239076-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524817322-239028-1-git-send-email-shawn.lin@rock-chips.com> References: <1524817322-239028-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 --- 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 #include #include +#include +#include #include #include @@ -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 */