Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp9656800rwb; Thu, 24 Nov 2022 16:47:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf4iXAvHvH0OUrzXJm2MTwitXqdLslrPT3cMfTY2ckiwe8+UTjOXJE5x148+Wazvk9foyjXc X-Received: by 2002:a63:4b24:0:b0:476:e640:d016 with SMTP id y36-20020a634b24000000b00476e640d016mr31888696pga.205.1669337267408; Thu, 24 Nov 2022 16:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669337267; cv=none; d=google.com; s=arc-20160816; b=Il90y5DFETbeSzwJdHUU+udKLeH47VpwQCSpwsAiR/gZwLsDn40pf+5Y8Z9utfbjCL sasquYdXtxJxKlXpelXr4RoTUynFyeDgFfiPLBz/kHoISMofTuv0XkKsv0xpEoZw+lv7 CFTwUmbNKL5F7qoqL7jfM7ZhBUnYkH2H9whxdv3s4IzNNz7N8JM0lezip/fe59hL/S8+ //JogzLQaTFKCBsdAfb5ZzDtUOL7Zxo+Ler+zojg6p13D5RPoJ72lR0Th2LSbWgHgB0B //e05M8l18yVKagM6sUK1ZWhihabvI4TWmZyyCvBeEF/D+2Gd/h5c7ny97OSNPxpk1Bl 4NWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=5RTULcrzALXI6kqcCTFqzHeG98y1iAErZ2LN9kOhvOw=; b=qL6IAu6EOP0S3wIUUIT5qDA+oNClYwzhuUCp/4FSnWx2V31tWqmbhboKT6jejkq/Rw ZOoUT2Xiq5pLhenPYOk005WT1sZ6WMMGKyoFzTcF26iI9kNSf9ig6NEztZ2cSe/B0r6r neNkKZsVq/ci6UY2fuhUy5DGGk8CfkP3EYKr9V7xYK9VYP9CtY/uWwJ4vjWLIFXELUto i/f17k5zpjqL3qiju8tpc18iZ8+kf5VrSWGhKl7ASB53usc2Gsqag6qyIi5cQ2iIQz1z mkhg3rzmMWb5p3PEXFqgZAvlPhg8MXWRJjRYrYV2al01wvjL0PVdsUO8d5zGmgdiWCh0 81XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=z4DbH4XI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=lu6X+IMJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f12-20020a65400c000000b00439ae523fd2si2566103pgp.289.2022.11.24.16.47.36; Thu, 24 Nov 2022 16:47:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=z4DbH4XI; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=lu6X+IMJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbiKXXal (ORCPT + 87 others); Thu, 24 Nov 2022 18:30:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229972AbiKXX35 (ORCPT ); Thu, 24 Nov 2022 18:29:57 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A8EA59856; Thu, 24 Nov 2022 15:27:58 -0800 (PST) Message-ID: <20221124232326.961711347@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669332391; 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=5RTULcrzALXI6kqcCTFqzHeG98y1iAErZ2LN9kOhvOw=; b=z4DbH4XIv1kmxippL2hPCp96iWQYpvohT0sVRs5PG25Df35z6ugkXIfB7ahEPFJDmqmTG8 d+ztRHLzC6WuX9awOb1syNuT1Gwlk5hXRUPg9I8cxvNlYjP7+ARyMHQgLdf0Fj6a9LpvSh ungaxTUr3kpRsxm9k0OrPtpQErNPJ0W9CitB7HN8OksxBa+eJhm9F9CzTix/QI7/2enWmG 9biQXQElJUVHE9wwSCjT1Q9F+qMpaqdlPo/D+ykmdBRAeRs8v3kTjWcW/8NSyQtp3UjwRl jLS6X0EssAFpy97oIDN6b1cLAzXnJm9XOEoI4Jxxt414qNeKpZT7ySuguLS4pw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669332391; 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=5RTULcrzALXI6kqcCTFqzHeG98y1iAErZ2LN9kOhvOw=; b=lu6X+IMJmfOSIvBVNI1TXB/n/jyz7pQkN3zGH7jqRBV8dTnepVR3Op1rS8fkLO0RNNiDI5 HpAX+FhR+yvzvXCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe Subject: [patch V3 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq() References: <20221124230505.073418677@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Fri, 25 Nov 2022 00:26:31 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Single vector allocation which allocates the next free index in the IMS space. The free function releases. All allocated vectors are released also via pci_free_vectors() which is also releasing MSI/MSI-X vectors. Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas --- V3: s/cookie/icookie/ (Kevin) --- drivers/pci/msi/api.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 53 insertions(+) --- a/drivers/pci/msi/api.c +++ b/drivers/pci/msi/api.c @@ -361,6 +361,56 @@ const struct cpumask *pci_irq_get_affini EXPORT_SYMBOL(pci_irq_get_affinity); /** + * pci_ims_alloc_irq - Allocate an interrupt on a PCI/IMS interrupt domain + * @dev: The PCI device to operate on + * @icookie: Pointer to an IMS implementation specific cookie for this + * IMS instance (PASID, queue ID, pointer...). + * The cookie content is copied into the MSI descriptor for the + * interrupt chip callbacks or domain specific setup functions. + * @affdesc: Optional pointer to an interrupt affinity descriptor + * + * There is no index for IMS allocations as IMS is an implementation + * specific storage and does not have any direct associations between + * index, which might be a pure software construct, and device + * functionality. This association is established by the driver either via + * the index - if there is a hardware table - or in case of purely software + * managed IMS implementation the association happens via the + * irq_write_msi_msg() callback of the implementation specific interrupt + * chip, which utilizes the provided @icookie to store the MSI message in + * the appropriate place. + * + * Return: A struct msi_map + * + * On success msi_map::index contains the allocated index (>= 0) and + * msi_map::virq the allocated Linux interrupt number (> 0). + * + * On fail msi_map::index contains the error code and msi_map::virq + * is set to 0. + */ +struct msi_map pci_ims_alloc_irq(struct pci_dev *dev, union msi_instance_cookie *icookie, + const struct irq_affinity_desc *affdesc) +{ + return msi_domain_alloc_irq_at(&dev->dev, MSI_SECONDARY_DOMAIN, MSI_ANY_INDEX, + affdesc, icookie); +} +EXPORT_SYMBOL_GPL(pci_ims_alloc_irq); + +/** + * pci_ims_free_irq - Allocate an interrupt on a PCI/IMS interrupt domain + * which was allocated via pci_ims_alloc_irq() + * @dev: The PCI device to operate on + * @map: A struct msi_map describing the interrupt to free as + * returned from pci_ims_alloc_irq() + */ +void pci_ims_free_irq(struct pci_dev *dev, struct msi_map map) +{ + if (WARN_ON_ONCE(map.index < 0 || !map.virq)) + return; + msi_domain_free_irqs_range(&dev->dev, MSI_SECONDARY_DOMAIN, map.index, map.index); +} +EXPORT_SYMBOL_GPL(pci_ims_free_irq); + +/** * pci_free_irq_vectors() - Free previously allocated IRQs for a device * @dev: the PCI device to operate on * --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2491,6 +2491,9 @@ struct msi_domain_template; bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template, unsigned int hwsize, void *data); +struct msi_map pci_ims_alloc_irq(struct pci_dev *pdev, union msi_instance_cookie *icookie, + const struct irq_affinity_desc *affdesc); +void pci_ims_free_irq(struct pci_dev *pdev, struct msi_map map); #include