From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751759AbdCACB0 (ORCPT ); Tue, 28 Feb 2017 21:01:26 -0500 Received: from mail-sn1nam02on0051.outbound.protection.outlook.com ([104.47.36.51]:58688 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751497AbdCACBJ (ORCPT ); Tue, 28 Feb 2017 21:01:09 -0500 Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=cavium.com; From: David Daney To: Linus Walleij , Alexandre Courbot , Rob Herring , Mark Rutland , Marc Zyngier , Thomas Gleixner , linux-gpio@vger.kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, David Daney Subject: [PATCH v5 3/6] irqdomain: Add irq_domain_{push,pop}_irq() functions. Date: Tue, 28 Feb 2017 17:48:49 -0800 Message-Id: <1488332932-2691-4-git-send-email-david.daney@cavium.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1488332932-2691-1-git-send-email-david.daney@cavium.com> References: <1488332932-2691-1-git-send-email-david.daney@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: SN1PR0701CA0071.namprd07.prod.outlook.com (10.163.126.39) To SN1PR07MB2432.namprd07.prod.outlook.com (10.169.127.144) X-MS-Office365-Filtering-Correlation-Id: 85ceb9db-5966-4a97-d9ac-08d460452330 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:SN1PR07MB2432; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2432;3:x/8Sme922MwRlV0c1R4arZ6uLRlirZoJ3y/1GiMaD694XWQn7iQVCeUItf1wfNZmyR0voEYdTg7sCdD70xOHOBBUDv0Y4MWd0K1YRNPSGXnxgIkDLmUjX9T8SG/fkhm+e7aCbd6sSmOCRTDKS7/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Q8C6br6O7XYlWZRZvucrTY1TfKtlfm1VX5BV322cwWXj+zIG2BJVOWOpHdBBgRaakArSLAcnN9m+rO4i318bDJbCstesFqnJsEh9XB8sAl/LGdo/1O6m9px0UUCL9aYxlohJuW6GzKQTGx2mA5DaPUgtSfGm8muvE5uA8yCFtZ1vmiuBv50BTknKrsR9l0v+4dMak0iM0i9k5tcK2v1pBg7d+O4jAOooz/dKRWilp86u7tPLEqxK0sCiQIpKhtoQm/GV2MpVHTdPKi4xVXNjTv9cIFbA8+w7e0XlAb0tV3CREQLX5Qj/+zy2Rsy8Qwz X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123558025)(20161123562025)(6072148);SRVR:SN1PR07MB2432;BCL:0;PCL:0;RULEID:;SRVR:SN1PR07MB2432; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2432;4:YAKovWcuBNyshwnQOwkFFAciEvsva1YrF4Bsg0iftKloTrVlOk9vmJobv84TOV0bDdGRoTUHqu6UF11qQq6AoXO7bxKT9bp6Woxx9gzuWK/1qXQgr/twcz8OtPQrzMNBzS60myhdxWKfNISgrF433WeLnP6BFzTZj4TNq7KDkuxWn7ApyWsjHs4cHiLFybVSgEiiCkF13jN90huhGFt2mCkcUslxg9Aua637Q46t5KBpYZaP+6lvGE507Y903aEBQVL9FCXzlrQd7cEFTosTHYeZX2XrQBuawLs0hTdMP7ItHhHFs9fl6iNrZEF0IhVopliHX5KU/iEh6SxURBUQ09gdYNX5eL0B+l3xPOKxMrxMVNiOohnkJsTJdSaCSGbnD1xW/xS1gOLkyUOcMwtG48Hnm1KCX8LYi9qdjxNE90Dfs8q4D053+3OAvAFwj6tQca8WDRvcgujSx9o5Mow1jqCklpvlATd7mTihxw+2/SjnpZABW04my5u+QrrOktBmlx1Bnuwa66cl9Maxi3QpJ4BAIQ4em7jf5hFr7zONsyPdHM9alGCvCqInAaFyhAVFlZD0bKGoX+gobxSwIlLJ7vb1tkBZK6125DJN/SaV/sE= X-Forefront-PRVS: 0233768B38 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(39450400003)(48376002)(53936002)(86362001)(6486002)(50466002)(25786008)(5003940100001)(6506006)(36756003)(81166006)(50226002)(4326008)(50986999)(8676002)(76176999)(92566002)(7736002)(53416004)(5660300001)(6116002)(6512007)(76506005)(4720700003)(2950100002)(42186005)(33646002)(2906002)(66066001)(47776003)(189998001)(305945005)(107886003)(38730400002)(6666003)(142933001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB2432;H:localhost.caveonetworks.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR07MB2432;23:sXkYypAEfLtI9apjR8M4oy+X3QR+w6F0prJzLTx8s?= =?us-ascii?Q?iKHMJc8ecG9wPqnLLtLXwhj0m3hBDhL089beiH9M2JugKNR4j4ZCpNhAmKoU?= =?us-ascii?Q?fVhlpt7rDVz//HCIfCm5HhYlFHbIVsROvNCGO+CYbW3p5zQCmMVBMDPsJS4M?= =?us-ascii?Q?7vx/66wdNW8vw3ShjNI5EZxhZwSCYGRnM+OteclAxQNey+bhl8Nv0nerlm2c?= =?us-ascii?Q?/U9mz0uBKEbve3BOZf7t05X8CblRBAtmcg5/iebElMqlaPeBEXQp4jJDIHCP?= =?us-ascii?Q?SkgAEsUVUQ0WwbgxYs+UReuBABCz6x876yeeZ8X2PwkhVIp7thqQk+cSB7Ws?= =?us-ascii?Q?6+7ESyNhMF3SiQxEthx1WfvFhKjW4LA8Zav3doFi60tY1kQFVVpVxfwggoFl?= =?us-ascii?Q?+eMypJnWJjcYFYYQ5CqfNFCPYtwdXAdsjewvXJNBOGaXWhlzEti34ftSoc6X?= =?us-ascii?Q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wmqrrahXkl1ahVAr26T43s5OE6uiidBrZD3p/B76Iz+h4zsw4xjlqHo88T4E9Tw==;5:zTcGEXRAUrlzcmjlt8JoA7pG4EDRD0cNCaXwIGZPY7KDbRaFVrdjE/i0sY/ub3fihxATSAHw093acdDoFW/JlQtLbmbBVEB0N2ckHuV1DNH/twZwblf1371X/Y+k7G2OgRrBO8PVAgsxJx8RxWbdMg==;24:/NOcR044LyDYwTX/TpFQDh2zzM/uWxd0/YKxNQQj87co1tDaGPCzgtXo9yFrp7dcdwyMFrFO+cOql+PCaWjDf9z2HLUnFLiDSl2VDz6ThuE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2432;7:ARAkD2rUlmoVBJMNU92eaL1ApCy3tzbtxmeVpf+GeXdUqa1sz4Z8fRpSHW4Xdcmzc0I4CzvrJZ5rNb5cIPRTFHKdVmcREPfUgp6tcwCPNDApl8SJUAItMafnEUAakNS9ozZK9xqrthLPG4hUs6ubVqfJCAbxcV5JYo0PKk6xTJDY441n1H/8MxtRvvRCxQ1fnZYS4mdKlEs690AiRgFbYWz4Riqr5gTKcAbz5mgU0toz6+rYWkHE56q1bhXbNUVe4LCdyPVrpjk4VMNcdffz8WPD7jbqgAG7ZxmENCX7n2Kq5JNSEU+5Pe9GZcmi32Xmu2c8FO3mXfvkefEAoWXcig==;23:kd+fWnnCmw7ghD/8aVPjGO8nyCMdTsFXzMh8+R/IEhc5GRUqRGAsSqo7rYCGndzIDfQ0Fu8U1UXCFkRpqHPzTAm70Hb//6TqaVgKTeZ2+46Hdhp2CwriO3PMEXqRPspMGVSZHNMIZPAIP2lyOQa4Iw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2017 01:49:02.0027 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2432 X-OriginatorOrg: cavium.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For an already existing irqdomain hierarchy, as might be obtained via a call to pci_enable_msix(), 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() irq_domain_pop_irq()) to initialize the irq_data for the new irqdomain. Signed-off-by: David Daney --- include/linux/irqdomain.h | 3 + kernel/irq/irqdomain.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index 188eced..a7a16b7 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -425,6 +425,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 31805f2..d5d1c01 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1304,6 +1304,143 @@ 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. + */ +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); + + 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; + domain->ops->alloc(domain, virq, 1, arg); + + 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); + } + + mutex_unlock(&irq_domain_mutex); + + return 0; +} +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(). + */ +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; + + 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 -- 1.8.3.1