[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211126232734.708730446@linutronix.de>
Date: Sat, 27 Nov 2021 02:22:38 +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,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-s390@...r.kernel.org, Heiko Carstens <hca@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ibm.com>,
Jon Mason <jdmason@...zu.us>,
Dave Jiang <dave.jiang@...el.com>,
Allen Hubbe <allenbh@...il.com>, linux-ntb@...glegroups.com
Subject: [patch 07/32] genirq/msi: Count the allocated MSI descriptors
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
---
include/linux/msi.h | 3 +++
kernel/irq/msi.c | 18 ++++++++++++++++++
2 files changed, 21 insertions(+)
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -156,6 +156,7 @@ enum msi_desc_filter {
* msi_device_data - MSI per device data
* @lock: Spinlock to protect register access
* @properties: MSI properties which are interesting to drivers
+ * @num_descs: The number of allocated MSI descriptors for the device
* @attrs: Pointer to the sysfs attribute group
* @platform_data: Platform-MSI specific data
* @list: List of MSI descriptors associated to the device
@@ -166,6 +167,7 @@ enum msi_desc_filter {
struct msi_device_data {
raw_spinlock_t lock;
unsigned long properties;
+ unsigned int num_descs;
const struct attribute_group **attrs;
struct platform_msi_priv_data *platform_data;
struct list_head list;
@@ -208,6 +210,7 @@ static inline unsigned int msi_get_virq(
void msi_lock_descs(struct device *dev);
void msi_unlock_descs(struct device *dev);
+unsigned int msi_device_num_descs(struct device *dev);
struct msi_desc *__msi_first_desc(struct device *dev, enum msi_desc_filter filter, unsigned int base_index);
struct msi_desc *msi_next_desc(struct device *dev);
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -82,6 +82,7 @@ int msi_add_msi_desc(struct device *dev,
desc->pci = init_desc->pci;
list_add_tail(&desc->list, &dev->msi.data->list);
+ dev->msi.data->num_descs++;
return 0;
}
@@ -109,6 +110,7 @@ int msi_add_simple_msi_descs(struct devi
list_add_tail(&desc->list, &list);
}
list_splice_tail(&list, &dev->msi.data->list);
+ dev->msi.data->num_descs += ndesc;
return 0;
fail:
@@ -142,6 +144,7 @@ void msi_free_msi_descs_range(struct dev
continue;
list_del(&desc->list);
free_msi_entry(desc);
+ dev->msi.data->num_descs--;
}
}
@@ -157,6 +160,21 @@ bool msi_device_has_property(struct devi
return !!(dev->msi.data->properties & prop);
}
+/**
+ * msi_device_num_descs - Query the number of allocated MSI descriptors of a device
+ * @dev: The device to read from
+ *
+ * Note: This is a lockless snapshot of msi_device_data::num_descs
+ *
+ * Returns the number of MSI descriptors which are allocated for @dev
+ */
+unsigned int msi_device_num_descs(struct device *dev)
+{
+ if (dev->msi.data)
+ return dev->msi.data->num_descs;
+ return 0;
+}
+
void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
{
*msg = entry->msg;
Powered by blists - more mailing lists