@@ -195,6 +195,8 @@ static inline unsigned int irq_linear_revmap(struct irq_domain *domain,
extern unsigned int irq_find_mapping(struct irq_domain *host,
irq_hw_number_t hwirq);
extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
+extern unsigned int irq_alloc_mapping(struct irq_domain *host,
+ irq_hw_number_t *hwirq);
extern int irq_create_strict_mappings(struct irq_domain *domain,
unsigned int irq_base,
irq_hw_number_t hwirq_base, int count);
@@ -375,6 +375,42 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain)
EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
/**
+ * irq_alloc_mapping() - Allocate an irq for mapping
+ * @domain: domain to allocate the irq for or NULL for default domain
+ * @hwirq: reference to the returned hwirq
+ *
+ * This routine are used for irq controllers which can choose the
+ * hardware interrupt number from a range [ 0 ; domain size ], such as
+ * is often the case with PCI MSI controllers. The function will
+ * returned the allocated hwirq number in the hwirq pointer, and the
+ * corresponding virq number as the return value.
+ */
+unsigned int irq_alloc_mapping(struct irq_domain *domain,
+ irq_hw_number_t *out_hwirq)
+{
+ irq_hw_number_t hwirq;
+ int rc;
+
+ pr_debug("irq_alloc_mapping(0x%p)\n", domain);
+
+ for (hwirq = 0; hwirq < domain->revmap_size; hwirq++)
+ if (domain->linear_revmap[hwirq] == 0)
+ break;
+
+ if (hwirq == domain->hwirq_max) {
+ pr_debug("-> no available hwirq found\n");
+ return 0;
+ }
+
+ rc = irq_create_mapping(domain, hwirq);
+ if (rc)
+ *out_hwirq = hwirq;
+
+ return rc;
+}
+EXPORT_SYMBOL_GPL(irq_alloc_mapping);
+
+/**
* irq_create_mapping() - Map a hardware interrupt into linux irq space
* @domain: domain owning this hardware interrupt or NULL for default domain
* @hwirq: hardware irq number in that domain space