Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE43BC433EF for ; Thu, 16 Dec 2021 21:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241981AbhLPVmP (ORCPT ); Thu, 16 Dec 2021 16:42:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242035AbhLPVlE (ORCPT ); Thu, 16 Dec 2021 16:41:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38732C061761; Thu, 16 Dec 2021 13:40:44 -0800 (PST) Date: Thu, 16 Dec 2021 21:40:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1639690842; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L7yglx4v0aChpbYxWtPHIpo6AN6tPhntRM6VS1F0rzM=; b=C8rF7cS9X9K1xsKM7xhWIWb0KjMvXGCukiZnieUz3E4cwbCKJz0he1NPuRI1dgd7QDw+Dp XdToNu01j99uHgeXtij/627nUebG14oSrOirr3yud4qF8ylfBAWaexipoheX9lVSGkoBEN MW1Ye+iXAQv5NiknmLCMGoI/LtAxb76NvIgZfRZSoekiJBPo2fyV8gbeqczogwBWWptlPc FYK7cATmuy7kztDl+ImSi/Z2DIQWNfZSbjQONZHicCPCbFztlkKp+Cde4Hj/IT6kO12QZb vPu1XiZ4/1c5zveIEmr9MfEjdCd0q8+4jtqGv4wIYxKgA1KCSvk/IFnXTSuZpg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1639690842; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L7yglx4v0aChpbYxWtPHIpo6AN6tPhntRM6VS1F0rzM=; b=qtjDaVVC3tMBvPKfM9SXUAL1pyiSownqLpruFXKpmE8t7IM4NatTPakTyz6hO25hkowdYr 5HCa76H19RnUfIBQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/msi] genirq/msi: Provide msi_alloc_msi_desc() and a simple allocator Cc: Thomas Gleixner , Michael Kelley , Nishanth Menon , Jason Gunthorpe , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20211206210747.873833567@linutronix.de> References: <20211206210747.873833567@linutronix.de> MIME-Version: 1.0 Message-ID: <163969084132.23020.1296539833556787837.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the irq/msi branch of tip: Commit-ID: 602905253607ba892336f7bba8bb45b5be819d87 Gitweb: https://git.kernel.org/tip/602905253607ba892336f7bba8bb45b5be819d87 Author: Thomas Gleixner AuthorDate: Mon, 06 Dec 2021 23:51:10 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 16 Dec 2021 22:22:17 +01:00 genirq/msi: Provide msi_alloc_msi_desc() and a simple allocator Provide msi_alloc_msi_desc() which takes a template MSI descriptor for initializing a newly allocated descriptor. This allows to simplify various usage sites of alloc_msi_entry() and moves the storage handling into the core code. For simple cases where only a linear vector space is required provide msi_add_simple_msi_descs() which just allocates a linear range of MSI descriptors and fills msi_desc::msi_index accordingly. Signed-off-by: Thomas Gleixner Tested-by: Michael Kelley Tested-by: Nishanth Menon Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20211206210747.873833567@linutronix.de --- include/linux/msi.h | 2 +- kernel/irq/msi.c | 59 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+) diff --git a/include/linux/msi.h b/include/linux/msi.h index 703221f..bbb8c1e 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -247,6 +247,8 @@ static inline void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) } #endif /* CONFIG_PCI_MSI */ +int msi_add_msi_desc(struct device *dev, struct msi_desc *init_desc); + struct msi_desc *alloc_msi_entry(struct device *dev, int nvec, const struct irq_affinity_desc *affinity); void free_msi_entry(struct msi_desc *entry); diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index bc67b2c..6ffe75e 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -60,6 +60,65 @@ void free_msi_entry(struct msi_desc *entry) kfree(entry); } +/** + * msi_add_msi_desc - Allocate and initialize a MSI descriptor + * @dev: Pointer to the device for which the descriptor is allocated + * @init_desc: Pointer to an MSI descriptor to initialize the new descriptor + * + * Return: 0 on success or an appropriate failure code. + */ +int msi_add_msi_desc(struct device *dev, struct msi_desc *init_desc) +{ + struct msi_desc *desc; + + lockdep_assert_held(&dev->msi.data->mutex); + + desc = alloc_msi_entry(dev, init_desc->nvec_used, init_desc->affinity); + if (!desc) + return -ENOMEM; + + /* Copy the MSI index and type specific data to the new descriptor. */ + desc->msi_index = init_desc->msi_index; + desc->pci = init_desc->pci; + + list_add_tail(&desc->list, &dev->msi.data->list); + return 0; +} + +/** + * msi_add_simple_msi_descs - Allocate and initialize MSI descriptors + * @dev: Pointer to the device for which the descriptors are allocated + * @index: Index for the first MSI descriptor + * @ndesc: Number of descriptors to allocate + * + * Return: 0 on success or an appropriate failure code. + */ +static int msi_add_simple_msi_descs(struct device *dev, unsigned int index, unsigned int ndesc) +{ + struct msi_desc *desc, *tmp; + LIST_HEAD(list); + unsigned int i; + + lockdep_assert_held(&dev->msi.data->mutex); + + for (i = 0; i < ndesc; i++) { + desc = alloc_msi_entry(dev, 1, NULL); + if (!desc) + goto fail; + desc->msi_index = index + i; + list_add_tail(&desc->list, &list); + } + list_splice_tail(&list, &dev->msi.data->list); + return 0; + +fail: + list_for_each_entry_safe(desc, tmp, &list, list) { + list_del(&desc->list); + free_msi_entry(desc); + } + return -ENOMEM; +} + void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg) { *msg = entry->msg;