From patchwork Wed Aug 9 22:51:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 800021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=CAVIUMNETWORKS.onmicrosoft.com header.i=@CAVIUMNETWORKS.onmicrosoft.com header.b="X+a7l1rz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xSRP356RBz9sNc for ; Thu, 10 Aug 2017 08:52:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752665AbdHIWwi (ORCPT ); Wed, 9 Aug 2017 18:52:38 -0400 Received: from mail-sn1nam01on0060.outbound.protection.outlook.com ([104.47.32.60]:33216 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752199AbdHIWvv (ORCPT ); Wed, 9 Aug 2017 18:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=NJLPsaAG+cYiIIvM8+TCs6e7j4/Vig2Dz/zrGd6XpNQ=; b=X+a7l1rz0WvXfqkcXz/pyCD0eGeqYKA6KK2jv9z00xbtkG8qEtENWll0LOy3hFC53HrAdrKQU/Qiozkw0GaWX2r8BPyeBBaZBTPHXK7D8cHawM/uyWuJQDhTjJgSFfOrOCNnrJfc9mB0lnpOMYShemA3TALiRzKeZ6ZeGfM2TSA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Daney@cavium.com; Received: from ubuntu.caveonetworks.com (50.233.148.156) by MWHPR07MB3503.namprd07.prod.outlook.com (10.164.192.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Wed, 9 Aug 2017 22:51:47 +0000 From: David Daney To: Linus Walleij , Alexandre Courbot , Mark Rutland , Marc Zyngier , Thomas Gleixner , linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, David Daney Subject: [PATCH v7 3/5] irqdomain: Add irq_domain_{push, pop}_irq() functions. Date: Wed, 9 Aug 2017 15:51:37 -0700 Message-Id: <1502319099-2782-4-git-send-email-david.daney@cavium.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1502319099-2782-1-git-send-email-david.daney@cavium.com> References: <1502319099-2782-1-git-send-email-david.daney@cavium.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: CO2PR07CA0057.namprd07.prod.outlook.com (10.174.192.25) To MWHPR07MB3503.namprd07.prod.outlook.com (10.164.192.30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f931febc-03e1-468a-f7dd-08d4df793711 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:MWHPR07MB3503; X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3503; 3:3DZDBe7n2sFp8Nl0Qk+xWeFJFXrNSPDv+QnNYuavmEodhuFUgFFxl2dm5qoW5+4dDz/mF8fnSDqbeAuhDExYFmKmxj4lED1VfVtF36kb0h7lu5eEGoo21LFf8ryo4SsHNBG13UCqJXiF7m+YlNpyvGNmoKtp6nSiGAm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x1KcTW22pQzZw09lAifCOT0wNe3JEknJnf7ah9/qdi4J1cumoYtEGc/imTCYT8Pqe7DC2MHEkqDprMHoynLQdlWP/XdI+odJyxnKCT1HwWqpG9JDihmjlKUMsYZzoC20OOXan9kZPL9L9N03DV33gyxlmwyCmgKYBOPeXGlvAwtZ/Ai19xCK7lW5g8d2; 4:cWq9XJBAqoXyJuirvNWeZ+2G/SAKeyewSc79ejJ0HYn+DXzT1/3Y/RFLownXgQjbHqbNxkJIhYBBGK3RoBao0YgKwSozei8rY0es2wx375KLumCimYpZG50oQqF5OaJ/g2E+lLpGSoQZjJpcgs94vX12O1jQNyWwOkflfsKz0UMiWguLVC0znWW7tpGho6uKcQp0QB+AyXTe0FyXFvszOzksbNopNP+7BZUuOgIZLKl4rJtz2tL72uHCgbxUoVCX X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6041248)(20161123558100)(20161123555025)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR07MB3503; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR07MB3503; X-Forefront-PRVS: 0394259C80 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(39400400002)(39410400002)(39850400002)(39840400002)(39450400003)(189002)(199003)(4720700003)(69596002)(4326008)(478600001)(6512007)(53936002)(107886003)(38730400002)(66066001)(72206003)(47776003)(81166006)(86362001)(5660300001)(2950100002)(105586002)(53416004)(33646002)(68736007)(50226002)(42186005)(25786009)(2906002)(81156014)(106356001)(50466002)(305945005)(189998001)(48376002)(5003940100001)(7736002)(97736004)(6116002)(36756003)(3846002)(50986999)(6666003)(101416001)(8676002)(7350300001)(76176999)(6486002)(6506006)(142933001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR07MB3503; H:ubuntu.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR07MB3503; 23:6D7V9YVdDY4davUY1+n6jnK/nTpjiO+Kr4bVSCqs+?= =?us-ascii?Q?uRbX+HS2mZVsOZCkHcctFppRSoIBbUGt7La2boVJUFbgY7m/2AxrZ+NsYzF1?= =?us-ascii?Q?Oew7f2rZ8vZg+kKsQDlFaLyNM+9wPTePyfdjotb1bK6ybjTSKg8QwIlmnH0c?= =?us-ascii?Q?vf0rhvf1DnsdZef1SP8lhkhY0ELWunLMnVf206y26WofaIHZyxfSQqtIATKN?= =?us-ascii?Q?Goiw3wN09nKXIlLp0FqHSyUdyZAWTapDgoq1nVQDVMVJqvMW5qOzPRW6u/3i?= =?us-ascii?Q?HZpVXJGcd4aVPVXVAQRudIpyvIy7QZiskjNP+5lQzwDliC3ifm5LQD6N5buQ?= =?us-ascii?Q?PMwicwEcFSwQSpESBwXw1tyDTfURUwzshf3Xsf58HtWARgW5/fCsPK+K93kd?= =?us-ascii?Q?gVhxUo9FSlmx9paphWJTCSPMFq1hrzp8XSvb9+hFYlj77fVcLQh3zdwmodPo?= =?us-ascii?Q?BfYDwUIzHVgu/FgkvqKeePpsnqd7fOQ4wOVsjX8QoM7CNFkxsLPAL+EFzVcx?= =?us-ascii?Q?mAtXWfUESTnJfLiTn1LFZfC8AXRGl/kQlUsfrSbeQ2JluWvgKNmmTK8h0msq?= =?us-ascii?Q?GVkW6/O2BY+bhHnGUoSAFodz0AoSeJwN8Piwlk6DbW9rUm7Mhj4Yu2IXhDta?= =?us-ascii?Q?4jCh/174Jcgi1WV1yswWU29+0wp7BnSvPspeTIrKcaffviLx55KJ5HPcdyUM?= =?us-ascii?Q?/qfsOVK7Ah49C16CSthAMncxIb/JHounIb4iWr3ehMOGHKu3UAQjWW0uplOV?= =?us-ascii?Q?ct17xaraN7aVCvtHu6IGqA95GMd1bXWrNSe+kRYnEkNLtClofCq1qXaFDOhD?= =?us-ascii?Q?yOS3R7ehhyUZPL2iHMFLhQ0RTNQiFocrM4wno2gvZd93B6ZgHNh/5a/kwgSs?= =?us-ascii?Q?YMQme2PgWT1SWbV2gyYNTjPgcVSzSxvdQ9mie41ixoZmcdN76xOrXi0k2HJl?= =?us-ascii?Q?H/5QAfKes0ZEYqHr7ZVd47u7Zq2HJsmeTNDS+pjxY7ZeY+q6M6tfnXwgkMDv?= =?us-ascii?Q?uyhZbBm8MrTqoImJMi8vEbhPLAkucG8aZe1O+dh0Uifpih3PpizDhelzv5aA?= =?us-ascii?Q?3gutqan4NLVaX5MXODIDCIonSv74fBEk3AyIqwSvMrWgQ1NDLeEamEFhsKLL?= =?us-ascii?Q?9o8AFi17P920as2c6PcnTScitq2qtmDMOUToNz/J/yE7c6u60cQUQEhEhg2B?= =?us-ascii?Q?5rlrf7CJzVFnmv+6R8mAQq45gNswHx7ogkaODqS4GkChbKG28iN0fNmgpqPU?= =?us-ascii?Q?EtfTwI8ozvTv6ecK/HHLxAryv8sgxj5F7+QCCbN/NzrNyh9BCdl5Fz104nkE?= =?us-ascii?Q?pHZ0wEBv9g/Qe4RUHC6Pc+x+ddMwsLI8p0CeW4odQc0?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3503; 6:60ipZEtwuY4eaci1dZJrarTetHHZNUquyAlTCR7IntDtGd6vBoPC+9UsdG/zExuHYPDFLNqb4qU13eSTLeYVtnRiJmkAH+jwQ+v6qmvY6t2kMcyFgjh4onGiEEpe/Ghcgv8rjCX+KE+KvYykkt4U/BRo4tGnz8c6OeWlndoevFDB7oMZ5Hf75uRzyZPW2S7OKl9R6CQz76UT/CztTOHfPB+5YUnJOcgDWAeNg6fbyHjDJq5hU7FcQFND9LDtStYjM6UIBBpz3ztBvQdfizunSzDeCHAPVngy5/MxHYUEWxWcwjUjLeUN7d7+EBc4Uxf1gupO/9LOy+NlcSt3Yv3D9A==; 5:E1SFkQ1pLUjo5N9mh/9iUD/sY5I9UNLrtkFG7piXgOJmw/7wvpY8ZKQNFZ/tUmpAAm+CRChRYdqnU3jyetuGlmq4SaxqPQIUceUYf9HGFPH/5rnUBXxbqjXEsIzejBXwp2DxPzKLkEtUzXd38USDkw==; 24:684v0tRzTF9oj79PWpNg7yy3L91+JJlIqIMcgIk8ETgXEsvzrwYrAAKYMHJHjav8avZJ7y18A6bXzhVMvgUBOQIsZfMGy5LM6qA3CBgdfHI=; 7:QMfpAJ4p/ZIGJnfkNjdV5u+JAjDQNC6XN6AosRVQSa3wfhkdasYnj3LrIsDR1DEu7+QlHIM6wbz8CuTO7eFNwcCRPX0T+FoBlI+j7+7t1jFOXtQmfFRka+rE7exR4MDs1RIW+lykJOwoD/M0BCNcVdfES/LcBinT3bF7aT540INAhz7fvV5IkrrA326vAc8zGW2owzwMYsiqpSi9NuGhMTUbRa8k6U3chf/p/ej/uPk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2017 22:51:47.1075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3503 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org For an already existing irqdomain hierarchy, as might be obtained via a call to pci_enable_msix_range(), a PCI driver wishing to add an additional irqdomain to the hierarchy needs to be able to insert the irqdomain to that already initialized hierarchy. Calling irq_domain_create_hierarchy() allows the new irqdomain to be created, but no existing code allows for initializing the associated irq_data. Add a couple of helper functions (irq_domain_push_irq() and irq_domain_pop_irq()) to initialize the irq_data for the new irqdomain added to an existing hierarchy. Signed-off-by: David Daney --- include/linux/irqdomain.h | 3 + kernel/irq/irqdomain.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index cac77a5..2318f29 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -460,6 +460,9 @@ extern void irq_domain_free_irqs_common(struct irq_domain *domain, extern void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs); +extern int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg); +extern int irq_domain_pop_irq(struct irq_domain *domain, int virq); + extern int irq_domain_alloc_irqs_parent(struct irq_domain *domain, unsigned int irq_base, unsigned int nr_irqs, void *arg); diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index f1f2514..629f770 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1448,6 +1448,184 @@ int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, return ret; } +/* The irq_data was moved, fix the revmap to refer to the new location */ +static void irq_domain_fix_revmap(struct irq_data *d) +{ + void **slot; + + if (d->hwirq < d->domain->revmap_size) + return; /* Not using radix tree. */ + + /* Fix up the revmap. */ + mutex_lock(&revmap_trees_mutex); + slot = radix_tree_lookup_slot(&d->domain->revmap_tree, d->hwirq); + if (slot) + radix_tree_replace_slot(&d->domain->revmap_tree, slot, d); + mutex_unlock(&revmap_trees_mutex); +} + +/** + * irq_domain_push_irq() - Push a domain in to the top of a hierarchy. + * @domain: Domain to push. + * @virq: Irq to push the domain in to. + * @arg: Passed to the irq_domain_ops alloc() function. + * + * For an already existing irqdomain hierarchy, as might be obtained + * via a call to pci_enable_msix(), add an additional domain to the + * head of the processing chain. Must be called before request_irq() + * has been called. + */ +int irq_domain_push_irq(struct irq_domain *domain, int virq, void *arg) +{ + struct irq_data *child_irq_data; + struct irq_data *root_irq_data = irq_get_irq_data(virq); + struct irq_desc *desc; + int rv = 0; + + /* + * Check that no action has been set, which indicates the virq + * is in a state where this function doesn't have to deal with + * races between interrupt handling and maintaining the + * hierarchy. This will catch gross misuse. Attempting to + * make the check race free would require holding locks across + * calls to struct irq_domain_ops->alloc(), which could lead + * to deadlock, so we just do a simple check before starting. + */ + desc = irq_to_desc(virq); + if (!desc) + return -EINVAL; + if (WARN_ON(desc->action)) + return -EBUSY; + + if (domain == NULL) + return -EINVAL; + + if (WARN_ON(!domain->ops->alloc)) + return -EINVAL; + + if (!root_irq_data) + return -EINVAL; + + child_irq_data = kzalloc_node(sizeof(*child_irq_data), GFP_KERNEL, + irq_data_get_node(root_irq_data)); + if (!child_irq_data) + return -ENOMEM; + + mutex_lock(&irq_domain_mutex); + + /* Copy the original irq_data. */ + *child_irq_data = *root_irq_data; + + irq_domain_fix_revmap(child_irq_data); + + /* + * Overwrite the root_irq_data, which is embedded in struct + * irq_desc, with values for this domain. + */ + root_irq_data->parent_data = child_irq_data; + root_irq_data->domain = domain; + root_irq_data->mask = 0; + root_irq_data->hwirq = 0; + root_irq_data->chip = NULL; + root_irq_data->chip_data = NULL; + rv = domain->ops->alloc(domain, virq, 1, arg); + if (rv) { + /* Restore the original irq_data. */ + *root_irq_data = *child_irq_data; + irq_domain_fix_revmap(root_irq_data); + goto error; + } + + if (root_irq_data->hwirq < domain->revmap_size) { + domain->linear_revmap[root_irq_data->hwirq] = virq; + } else { + mutex_lock(&revmap_trees_mutex); + radix_tree_insert(&domain->revmap_tree, + root_irq_data->hwirq, root_irq_data); + mutex_unlock(&revmap_trees_mutex); + } +error: + mutex_unlock(&irq_domain_mutex); + + return rv; +} +EXPORT_SYMBOL_GPL(irq_domain_push_irq); + +/** + * irq_domain_pop_irq() - Remove a domain from the top of a hierarchy. + * @domain: Domain to remove. + * @virq: Irq to remove the domain from. + * + * Undo the effects of a call to irq_domain_push_irq(). Must be + * called either before request_irq() or after free_irq(). + */ +int irq_domain_pop_irq(struct irq_domain *domain, int virq) +{ + struct irq_data *root_irq_data = irq_get_irq_data(virq); + struct irq_data *child_irq_data; + struct irq_data *tmp_irq_data; + struct irq_desc *desc; + + /* + * Check that no action is set, which indicates the virq is in + * a state where this function doesn't have to deal with races + * between interrupt handling and maintaining the hierarchy. + * This will catch gross misuse. Attempting to make the check + * race free would require holding locks across calls to + * struct irq_domain_ops->free(), which could lead to + * deadlock, so we just do a simple check before starting. + */ + desc = irq_to_desc(virq); + if (!desc) + return -EINVAL; + if (WARN_ON(desc->action)) + return -EBUSY; + + if (domain == NULL) + return -EINVAL; + + if (!root_irq_data) + return -EINVAL; + + tmp_irq_data = irq_domain_get_irq_data(domain, virq); + + /* We can only "pop" if this domain is at the top of the list */ + if (WARN_ON(root_irq_data != tmp_irq_data)) + return -EINVAL; + + if (WARN_ON(root_irq_data->domain != domain)) + return -EINVAL; + + child_irq_data = root_irq_data->parent_data; + if (WARN_ON(!child_irq_data)) + return -EINVAL; + + mutex_lock(&irq_domain_mutex); + + root_irq_data->parent_data = NULL; + + if (root_irq_data->hwirq >= domain->revmap_size) { + mutex_lock(&revmap_trees_mutex); + radix_tree_delete(&domain->revmap_tree, root_irq_data->hwirq); + mutex_unlock(&revmap_trees_mutex); + } + + if (domain->ops->free) + domain->ops->free(domain, virq, 1); + + /* Restore the original irq_data. */ + *root_irq_data = *child_irq_data; + + irq_domain_fix_revmap(root_irq_data); + + mutex_unlock(&irq_domain_mutex); + + kfree(child_irq_data); + + return 0; +} +EXPORT_SYMBOL_GPL(irq_domain_pop_irq); + /** * irq_domain_free_irqs - Free IRQ number and associated data structures * @virq: base IRQ number