[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211210221814.780824745@linutronix.de>
Date: Fri, 10 Dec 2021 23:19:23 +0100 (CET)
From: Thomas Gleixner <tglx@...utronix.de>
To: LKML <linux-kernel@...r.kernel.org>
Cc: Bjorn Helgaas <helgaas@...nel.org>, Marc Zygnier <maz@...nel.org>,
Alex Williamson <alex.williamson@...hat.com>,
Kevin Tian <kevin.tian@...el.com>,
Jason Gunthorpe <jgg@...dia.com>,
Megha Dey <megha.dey@...el.com>,
Ashok Raj <ashok.raj@...el.com>, linux-pci@...r.kernel.org,
Cedric Le Goater <clg@...d.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Juergen Gross <jgross@...e.com>,
xen-devel@...ts.xenproject.org, Arnd Bergmann <arnd@...db.de>,
Michael Ellerman <mpe@...erman.id.au>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
linuxppc-dev@...ts.ozlabs.org, Bjorn Helgaas <bhelgaas@...gle.com>,
Stuart Yoder <stuyoder@...il.com>,
Laurentiu Tudor <laurentiu.tudor@....com>,
Nishanth Menon <nm@...com>, Tero Kristo <kristo@...nel.org>,
Santosh Shilimkar <ssantosh@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
Vinod Koul <vkoul@...nel.org>, dmaengine@...r.kernel.org,
Mark Rutland <mark.rutland@....com>,
Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Joerg Roedel <joro@...tes.org>,
iommu@...ts.linux-foundation.org,
Jassi Brar <jassisinghbrar@...il.com>,
Peter Ujfalusi <peter.ujfalusi@...il.com>,
Sinan Kaya <okaya@...nel.org>
Subject: [patch V3 26/35] genirq/msi: Provide interface to retrieve Linux
interrupt number
From: Thomas Gleixner <tglx@...utronix.de>
This allows drivers to retrieve the Linux interrupt number instead of
fiddling with MSI descriptors.
msi_get_virq() returns the Linux interrupt number or 0 in case that there
is no entry for the given MSI index.
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
V2: Simplify the implementation and let PCI deal with the PCI specialities - Marc
---
include/linux/msi.h | 2 ++
kernel/irq/msi.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -153,6 +153,8 @@ struct msi_device_data {
int msi_setup_device_data(struct device *dev);
+unsigned int msi_get_virq(struct device *dev, unsigned int index);
+
/* Helpers to hide struct msi_desc implementation details */
#define msi_desc_to_dev(desc) ((desc)->dev)
#define dev_to_msi_list(dev) (&(dev)->msi_list)
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -105,6 +105,42 @@ int msi_setup_device_data(struct device
return 0;
}
+/**
+ * msi_get_virq - Return Linux interrupt number of a MSI interrupt
+ * @dev: Device to operate on
+ * @index: MSI interrupt index to look for (0-based)
+ *
+ * Return: The Linux interrupt number on success (> 0), 0 if not found
+ */
+unsigned int msi_get_virq(struct device *dev, unsigned int index)
+{
+ struct msi_desc *desc;
+ bool pcimsi;
+
+ if (!dev->msi.data)
+ return 0;
+
+ pcimsi = dev_is_pci(dev) ? to_pci_dev(dev)->msi_enabled : false;
+
+ for_each_msi_entry(desc, dev) {
+ /* PCI-MSI has only one descriptor for multiple interrupts. */
+ if (pcimsi) {
+ if (desc->irq && index < desc->nvec_used)
+ return desc->irq + index;
+ break;
+ }
+
+ /*
+ * PCI-MSIX and platform MSI use a descriptor per
+ * interrupt.
+ */
+ if (desc->msi_index == index)
+ return desc->irq;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(msi_get_virq);
+
#ifdef CONFIG_SYSFS
static ssize_t msi_mode_show(struct device *dev, struct device_attribute *attr,
char *buf)
Powered by blists - more mailing lists