Skip to content

Commit de337ee

Browse files
author
Marc Zyngier
committed
irqchip/gic-v2m: Add PCI Multi-MSI support
We'd never implemented Multi-MSI support with GICv2m, because it is weird and clunky, and you'd think people would rather use MSI-X. Turns out there is still plenty of devices out there that rely on Multi-MSI. Oh well, let's teach that trick to the v2m widget, it is not a big deal anyway. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 95a2562 commit de337ee

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

drivers/irqchip/irq-gic-v2m.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static struct irq_chip gicv2m_msi_irq_chip = {
9494

9595
static struct msi_domain_info gicv2m_msi_domain_info = {
9696
.flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
97-
MSI_FLAG_PCI_MSIX),
97+
MSI_FLAG_PCI_MSIX | MSI_FLAG_MULTI_PCI_MSI),
9898
.chip = &gicv2m_msi_irq_chip,
9999
};
100100

@@ -155,32 +155,26 @@ static int gicv2m_irq_gic_domain_alloc(struct irq_domain *domain,
155155
return 0;
156156
}
157157

158-
static void gicv2m_unalloc_msi(struct v2m_data *v2m, unsigned int hwirq)
158+
static void gicv2m_unalloc_msi(struct v2m_data *v2m, unsigned int hwirq,
159+
int nr_irqs)
159160
{
160-
int pos;
161-
162-
pos = hwirq - v2m->spi_start;
163-
if (pos < 0 || pos >= v2m->nr_spis) {
164-
pr_err("Failed to teardown msi. Invalid hwirq %d\n", hwirq);
165-
return;
166-
}
167-
168161
spin_lock(&v2m_lock);
169-
__clear_bit(pos, v2m->bm);
162+
bitmap_release_region(v2m->bm, hwirq - v2m->spi_start,
163+
get_count_order(nr_irqs));
170164
spin_unlock(&v2m_lock);
171165
}
172166

173167
static int gicv2m_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
174168
unsigned int nr_irqs, void *args)
175169
{
176170
struct v2m_data *v2m = NULL, *tmp;
177-
int hwirq, offset, err = 0;
171+
int hwirq, offset, i, err = 0;
178172

179173
spin_lock(&v2m_lock);
180174
list_for_each_entry(tmp, &v2m_nodes, entry) {
181-
offset = find_first_zero_bit(tmp->bm, tmp->nr_spis);
182-
if (offset < tmp->nr_spis) {
183-
__set_bit(offset, tmp->bm);
175+
offset = bitmap_find_free_region(tmp->bm, tmp->nr_spis,
176+
get_count_order(nr_irqs));
177+
if (offset >= 0) {
184178
v2m = tmp;
185179
break;
186180
}
@@ -192,16 +186,21 @@ static int gicv2m_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
192186

193187
hwirq = v2m->spi_start + offset;
194188

195-
err = gicv2m_irq_gic_domain_alloc(domain, virq, hwirq);
196-
if (err) {
197-
gicv2m_unalloc_msi(v2m, hwirq);
198-
return err;
199-
}
189+
for (i = 0; i < nr_irqs; i++) {
190+
err = gicv2m_irq_gic_domain_alloc(domain, virq + i, hwirq + i);
191+
if (err)
192+
goto fail;
200193

201-
irq_domain_set_hwirq_and_chip(domain, virq, hwirq,
202-
&gicv2m_irq_chip, v2m);
194+
irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
195+
&gicv2m_irq_chip, v2m);
196+
}
203197

204198
return 0;
199+
200+
fail:
201+
irq_domain_free_irqs_parent(domain, virq, nr_irqs);
202+
gicv2m_unalloc_msi(v2m, hwirq, get_count_order(nr_irqs));
203+
return err;
205204
}
206205

207206
static void gicv2m_irq_domain_free(struct irq_domain *domain,
@@ -210,8 +209,7 @@ static void gicv2m_irq_domain_free(struct irq_domain *domain,
210209
struct irq_data *d = irq_domain_get_irq_data(domain, virq);
211210
struct v2m_data *v2m = irq_data_get_irq_chip_data(d);
212211

213-
BUG_ON(nr_irqs != 1);
214-
gicv2m_unalloc_msi(v2m, d->hwirq);
212+
gicv2m_unalloc_msi(v2m, d->hwirq, nr_irqs);
215213
irq_domain_free_irqs_parent(domain, virq, nr_irqs);
216214
}
217215

0 commit comments

Comments
 (0)