summaryrefslogtreecommitdiffstats
path: root/kernel/irq
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2021-12-06 23:51:08 +0100
committerThomas Gleixner <tglx@linutronix.de>2021-12-16 22:22:17 +0100
commit1046f71d7268b1680d7b044dea83c664403f6302 (patch)
tree62eda7a479602d007d6e3d12d4d9ba39e3e07b72 /kernel/irq
parent0f62d941acf9ac3b6025692ce649b1f282b89e7f (diff)
downloadlinux-stable-1046f71d7268b1680d7b044dea83c664403f6302.tar.gz
linux-stable-1046f71d7268b1680d7b044dea83c664403f6302.tar.bz2
linux-stable-1046f71d7268b1680d7b044dea83c664403f6302.zip
genirq/msi: Provide a set of advanced MSI accessors and iterators
In preparation for dynamic handling of MSI-X interrupts provide a new set of MSI descriptor accessor functions and iterators. They are benefitial per se as they allow to cleanup quite some code in various MSI domain implementations. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Michael Kelley <mikelley@microsoft.com> Tested-by: Nishanth Menon <nm@ti.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20211206210747.818635078@linutronix.de
Diffstat (limited to 'kernel/irq')
-rw-r--r--kernel/irq/msi.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index 3b21e99bb793..bc67b2cafc9d 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -125,10 +125,106 @@ EXPORT_SYMBOL_GPL(msi_lock_descs);
*/
void msi_unlock_descs(struct device *dev)
{
+ /* Clear the next pointer which was cached by the iterator */
+ dev->msi.data->__next = NULL;
mutex_unlock(&dev->msi.data->mutex);
}
EXPORT_SYMBOL_GPL(msi_unlock_descs);
+static bool msi_desc_match(struct msi_desc *desc, enum msi_desc_filter filter)
+{
+ switch (filter) {
+ case MSI_DESC_ALL:
+ return true;
+ case MSI_DESC_NOTASSOCIATED:
+ return !desc->irq;
+ case MSI_DESC_ASSOCIATED:
+ return !!desc->irq;
+ }
+ WARN_ON_ONCE(1);
+ return false;
+}
+
+static struct msi_desc *msi_find_first_desc(struct device *dev, enum msi_desc_filter filter)
+{
+ struct msi_desc *desc;
+
+ list_for_each_entry(desc, dev_to_msi_list(dev), list) {
+ if (msi_desc_match(desc, filter))
+ return desc;
+ }
+ return NULL;
+}
+
+/**
+ * msi_first_desc - Get the first MSI descriptor of a device
+ * @dev: Device to operate on
+ * @filter: Descriptor state filter
+ *
+ * Must be called with the MSI descriptor mutex held, i.e. msi_lock_descs()
+ * must be invoked before the call.
+ *
+ * Return: Pointer to the first MSI descriptor matching the search
+ * criteria, NULL if none found.
+ */
+struct msi_desc *msi_first_desc(struct device *dev, enum msi_desc_filter filter)
+{
+ struct msi_desc *desc;
+
+ if (WARN_ON_ONCE(!dev->msi.data))
+ return NULL;
+
+ lockdep_assert_held(&dev->msi.data->mutex);
+
+ desc = msi_find_first_desc(dev, filter);
+ dev->msi.data->__next = desc ? list_next_entry(desc, list) : NULL;
+ return desc;
+}
+EXPORT_SYMBOL_GPL(msi_first_desc);
+
+static struct msi_desc *__msi_next_desc(struct device *dev, enum msi_desc_filter filter,
+ struct msi_desc *from)
+{
+ struct msi_desc *desc = from;
+
+ list_for_each_entry_from(desc, dev_to_msi_list(dev), list) {
+ if (msi_desc_match(desc, filter))
+ return desc;
+ }
+ return NULL;
+}
+
+/**
+ * msi_next_desc - Get the next MSI descriptor of a device
+ * @dev: Device to operate on
+ *
+ * The first invocation of msi_next_desc() has to be preceeded by a
+ * successful incovation of __msi_first_desc(). Consecutive invocations are
+ * only valid if the previous one was successful. All these operations have
+ * to be done within the same MSI mutex held region.
+ *
+ * Return: Pointer to the next MSI descriptor matching the search
+ * criteria, NULL if none found.
+ */
+struct msi_desc *msi_next_desc(struct device *dev, enum msi_desc_filter filter)
+{
+ struct msi_device_data *data = dev->msi.data;
+ struct msi_desc *desc;
+
+ if (WARN_ON_ONCE(!data))
+ return NULL;
+
+ lockdep_assert_held(&data->mutex);
+
+ if (!data->__next)
+ return NULL;
+
+ desc = __msi_next_desc(dev, filter, data->__next);
+ dev->msi.data->__next = desc ? list_next_entry(desc, list) : NULL;
+ return desc;
+}
+EXPORT_SYMBOL_GPL(msi_next_desc);
+
/**
* msi_get_virq - Return Linux interrupt number of a MSI interrupt
* @dev: Device to operate on