summaryrefslogtreecommitdiff
path: root/include/linux/msi.h
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2021-12-07 01:51:08 +0300
committerThomas Gleixner <tglx@linutronix.de>2021-12-17 00:22:17 +0300
commit1046f71d7268b1680d7b044dea83c664403f6302 (patch)
tree62eda7a479602d007d6e3d12d4d9ba39e3e07b72 /include/linux/msi.h
parent0f62d941acf9ac3b6025692ce649b1f282b89e7f (diff)
downloadlinux-1046f71d7268b1680d7b044dea83c664403f6302.tar.xz
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 'include/linux/msi.h')
-rw-r--r--include/linux/msi.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/include/linux/msi.h b/include/linux/msi.h
index 69c588efe85b..703221f7e9ea 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -140,6 +140,18 @@ struct msi_desc {
struct pci_msi_desc pci;
};
+/*
+ * Filter values for the MSI descriptor iterators and accessor functions.
+ */
+enum msi_desc_filter {
+ /* All descriptors */
+ MSI_DESC_ALL,
+ /* Descriptors which have no interrupt associated */
+ MSI_DESC_NOTASSOCIATED,
+ /* Descriptors which have an interrupt associated */
+ MSI_DESC_ASSOCIATED,
+};
+
/**
* msi_device_data - MSI per device data
* @properties: MSI properties which are interesting to drivers
@@ -147,6 +159,7 @@ struct msi_desc {
* @platform_data: Platform-MSI specific data
* @list: List of MSI descriptors associated to the device
* @mutex: Mutex protecting the MSI list
+ * @__next: Cached pointer to the next entry for iterators
*/
struct msi_device_data {
unsigned long properties;
@@ -154,6 +167,7 @@ struct msi_device_data {
struct platform_msi_priv_data *platform_data;
struct list_head list;
struct mutex mutex;
+ struct msi_desc *__next;
};
int msi_setup_device_data(struct device *dev);
@@ -162,6 +176,25 @@ unsigned int msi_get_virq(struct device *dev, unsigned int index);
void msi_lock_descs(struct device *dev);
void msi_unlock_descs(struct device *dev);
+struct msi_desc *msi_first_desc(struct device *dev, enum msi_desc_filter filter);
+struct msi_desc *msi_next_desc(struct device *dev, enum msi_desc_filter filter);
+
+/**
+ * msi_for_each_desc - Iterate the MSI descriptors
+ *
+ * @desc: struct msi_desc pointer used as iterator
+ * @dev: struct device pointer - device to iterate
+ * @filter: Filter for descriptor selection
+ *
+ * Notes:
+ * - The loop must be protected with a msi_lock_descs()/msi_unlock_descs()
+ * pair.
+ * - It is safe to remove a retrieved MSI descriptor in the loop.
+ */
+#define msi_for_each_desc(desc, dev, filter) \
+ for ((desc) = msi_first_desc((dev), (filter)); (desc); \
+ (desc) = msi_next_desc((dev), (filter)))
+
/* Helpers to hide struct msi_desc implementation details */
#define msi_desc_to_dev(desc) ((desc)->dev)
#define dev_to_msi_list(dev) (&(dev)->msi.data->list)