+
+/**
+ * ipi_get_hwirq - get the hwirq associated with an IPI to a cpu
+ * @irq: linux irq number
+ * @cpu: the cpu to find the revmap for
+ *
+ * When dealing with coprocessors IPI, we need to inform it of the hwirq it
+ * needs to use to receive and send IPIs. This function provides the revmap
+ * to get this info to pass on to coprocessor firmware.
+ *
+ * Returns hwirq value on success and INVALID_HWIRQ on failure.
+ */
+irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu)
+{
+ struct irq_data *data = irq_get_irq_data(irq);
+ struct ipi_mask *ipimask = data ? irq_data_get_ipi_mask(data) : NULL;
+ irq_hw_number_t hwirq;
+
+ if (!data || !ipimask)
+ return INVALID_HWIRQ;
+
+ if (cpu > ipimask->nbits)
+ return INVALID_HWIRQ;
+
+ if (!test_bit(cpu, ipimask->cpu_bitmap))
+ return INVALID_HWIRQ;
+
+ if (irq_domain_is_ipi_per_cpu(data->domain)) {
+ data = irq_get_irq_data(irq + cpu - ipimask->offset);
+ hwirq = data ? irqd_to_hwirq(data) : INVALID_HWIRQ;
+ } else {
+ hwirq = irqd_to_hwirq(data) + cpu - ipimask->offset;
+ }
+
+ return hwirq;
+}
+EXPORT_SYMBOL_GPL(ipi_get_hwirq);