From patchwork Mon Dec 6 22:51:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 12660313 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 646E8C43217 for ; Mon, 6 Dec 2021 22:51:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.240129.416576 (Exim 4.92) (envelope-from ) id 1muMpF-0001Cy-14; Mon, 06 Dec 2021 22:51:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 240129.416576; Mon, 06 Dec 2021 22:51:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muMpE-0001B6-Ri; Mon, 06 Dec 2021 22:51:12 +0000 Received: by outflank-mailman (input) for mailman id 240129; Mon, 06 Dec 2021 22:51:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muMpD-0000Tb-Rn for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 22:51:11 +0000 Received: from galois.linutronix.de (galois.linutronix.de [193.142.43.55]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 01efee6d-56e7-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 23:51:11 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 01efee6d-56e7-11ec-8a4d-196798b21f7b Message-ID: <20211206210747.873833567@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1638831071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=UXWSPGXq5vnQLUJp9/NNC9VtOj7oZ//oTBntFTDlckE=; b=PgswJKO7WjEq/yzSlO8H3r2ZY7wjGa6pUk3EvaNcKuMrsgVGzpecG5DceC1CGnwjJDfFrd NEIcwffhXM1Dh8hkAJqoaBetLrFmrWaiobLhBPB3Si54snueZHcItXS4lJu61yhklX8gL9 vDjkPpzxc7w5tGUe71tIur9OcFBylBX/nVwXuDYVc4/D/njZPwu1dfzRZIDTvKazX1ctqQ qfboBuUucOEcJo4C9YNpUXDsL6irdm9ZTWhNvyVPa3FV7PH/JPmsWkGxQxeoLk+YcMZswH LUhmEcQ2lFEnBNmvg7mPfElXx9sYkYIvbB/0MVj3vFz9c+772JnNAXwn11Yomw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1638831071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=UXWSPGXq5vnQLUJp9/NNC9VtOj7oZ//oTBntFTDlckE=; b=t+DO982LnLzdozDveVemoQFAxPU8VVJP7+1gBgv3k94/pKvOyQo4khceqch0cyJeFbU1xs cy6hN4KbQT/tk+DA== From: Thomas Gleixner To: LKML Cc: Bjorn Helgaas , Marc Zygnier , Alex Williamson , Kevin Tian , Jason Gunthorpe , Megha Dey , Ashok Raj , linux-pci@vger.kernel.org, Cedric Le Goater , xen-devel@lists.xenproject.org, Juergen Gross , Greg Kroah-Hartman , Niklas Schnelle , linux-s390@vger.kernel.org, Heiko Carstens , Christian Borntraeger , Logan Gunthorpe , Jon Mason , Dave Jiang , Allen Hubbe , linux-ntb@googlegroups.com Subject: [patch V2 05/31] genirq/msi: Provide msi_alloc_msi_desc() and a simple allocator References: <20211206210600.123171746@linutronix.de> MIME-Version: 1.0 Date: Mon, 6 Dec 2021 23:51:10 +0100 (CET) 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 --- include/linux/msi.h | 2 + kernel/irq/msi.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -264,6 +264,8 @@ static inline void pci_write_msi_msg(uns } #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); --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -61,6 +61,65 @@ void free_msi_entry(struct msi_desc *ent } /** + * 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; +} + +/** * msi_device_set_properties - Set device specific MSI properties * @dev: Pointer to the device which is queried * @prop: Properties to set