@@ -269,6 +269,64 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
}
EXPORT_SYMBOL_GPL(platform_get_irq);
+/**
+ * platform_get_irqs_affinity - get all IRQs for a device using an affinity
+ * descriptor
+ * @dev: platform device pointer
+ * @affd: affinity descriptor, must be set
+ * @count: pointer to count of IRQS
+ * @irqs: pointer holder for IRQ numbers
+ *
+ * Gets a full set of IRQs for a platform device, and updates IRQ afffinty
+ * according to the passed affinity descriptor
+ *
+ * Return: 0 on success, negative error number on failure.
+ */
+int platform_get_irqs_affinity(struct platform_device *dev,
+ struct irq_affinity *affd,
+ unsigned int *count,
+ int **irqs)
+{
+ struct irq_affinity_desc *desc;
+ int i, *pirqs;
+
+ if (!affd)
+ return -EPERM;
+
+ *count = platform_irq_count(dev);
+
+ if (*count <= affd->pre_vectors + affd->post_vectors)
+ return -EIO;
+
+ pirqs = kcalloc(*count, sizeof(int), GFP_KERNEL);
+ if (!pirqs)
+ return -ENOMEM;
+
+ for (i = 0; i < *count; i++) {
+ int irq = platform_get_irq(dev, i);
+ if (irq < 0) {
+ kfree(pirqs);
+ return irq;
+ }
+ pirqs[i] = irq;
+ }
+
+ desc = irq_create_affinity_masks(*count, affd);
+ if (!desc) {
+ kfree(pirqs);
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < *count; i++)
+ irq_update_affinity_desc(pirqs[i], &desc[i]);
+
+ kfree(desc);
+ *irqs = pirqs;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(platform_get_irqs_affinity);
+
/**
* platform_irq_count - Count the number of IRQs a platform device uses
* @dev: platform device
@@ -11,6 +11,7 @@
#define _PLATFORM_DEVICE_H_
#include <linux/device.h>
+#include <linux/interrupt.h>
#define PLATFORM_DEVID_NONE (-1)
#define PLATFORM_DEVID_AUTO (-2)
@@ -70,6 +71,10 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev,
extern int platform_get_irq(struct platform_device *, unsigned int);
extern int platform_get_irq_optional(struct platform_device *, unsigned int);
extern int platform_irq_count(struct platform_device *);
+extern int platform_get_irqs_affinity(struct platform_device *dev,
+ struct irq_affinity *affd,
+ unsigned int *count,
+ int **irqs);
extern struct resource *platform_get_resource_byname(struct platform_device *,
unsigned int,
const char *);
Drivers for multi-queue platform devices may also want managed interrupts for handling HW queue completion interrupts, so add support. The function accepts an affinity descriptor pointer, which covers all IRQs expected for the device. The platform device driver is expected to hold all the IRQ numbers, as there is no point in holding these in the common platform_device structure. Signed-off-by: John Garry <john.garry@huawei.com> --- drivers/base/platform.c | 58 +++++++++++++++++++++++++++++++++ include/linux/platform_device.h | 5 +++ 2 files changed, 63 insertions(+) -- 2.26.2