Lines Matching +full:msi +full:- +full:num +full:- +full:spis
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ARM GIC v2m MSI(-X) support
21 #include <linux/msi.h>
26 #include <linux/irqchip/arm-gic.h>
27 #include <linux/irqchip/arm-gic-common.h>
29 #include "irq-msi-lib.h"
34 * [25:16] lowest SPI assigned to MSI
36 * [9:0] Numer of SPIs assigned to MSI
52 /* APM X-Gene with GICv2m MSI_IIDR register value */
71 u32 nr_spis; /* The number of SPIs for MSIs */
73 unsigned long *bm; /* MSI vector bitmap */
79 if (v2m->flags & GICV2M_GRAVITON_ADDRESS_ONLY) in gicv2m_get_msi_addr()
80 return v2m->res.start | ((hwirq - 32) << 3); in gicv2m_get_msi_addr()
82 return v2m->res.start + V2M_MSI_SETSPI_NS; in gicv2m_get_msi_addr()
88 phys_addr_t addr = gicv2m_get_msi_addr(v2m, data->hwirq); in gicv2m_compose_msi_msg()
90 msg->address_hi = upper_32_bits(addr); in gicv2m_compose_msi_msg()
91 msg->address_lo = lower_32_bits(addr); in gicv2m_compose_msi_msg()
93 if (v2m->flags & GICV2M_GRAVITON_ADDRESS_ONLY) in gicv2m_compose_msi_msg()
94 msg->data = 0; in gicv2m_compose_msi_msg()
96 msg->data = data->hwirq; in gicv2m_compose_msi_msg()
97 if (v2m->flags & GICV2M_NEEDS_SPI_OFFSET) in gicv2m_compose_msi_msg()
98 msg->data -= v2m->spi_offset; in gicv2m_compose_msi_msg()
120 if (is_of_node(domain->parent->fwnode)) { in gicv2m_irq_gic_domain_alloc()
121 fwspec.fwnode = domain->parent->fwnode; in gicv2m_irq_gic_domain_alloc()
124 fwspec.param[1] = hwirq - 32; in gicv2m_irq_gic_domain_alloc()
126 } else if (is_fwnode_irqchip(domain->parent->fwnode)) { in gicv2m_irq_gic_domain_alloc()
127 fwspec.fwnode = domain->parent->fwnode; in gicv2m_irq_gic_domain_alloc()
132 return -EINVAL; in gicv2m_irq_gic_domain_alloc()
140 d = irq_domain_get_irq_data(domain->parent, virq); in gicv2m_irq_gic_domain_alloc()
141 d->chip->irq_set_type(d, IRQ_TYPE_EDGE_RISING); in gicv2m_irq_gic_domain_alloc()
149 bitmap_release_region(v2m->bm, hwirq - v2m->spi_start, in gicv2m_unalloc_msi()
163 offset = bitmap_find_free_region(tmp->bm, tmp->nr_spis, in gicv2m_irq_domain_alloc()
173 return -ENOSPC; in gicv2m_irq_domain_alloc()
175 hwirq = v2m->spi_start + offset; in gicv2m_irq_domain_alloc()
177 err = iommu_dma_prepare_msi(info->desc, in gicv2m_irq_domain_alloc()
205 gicv2m_unalloc_msi(v2m, d->hwirq, nr_irqs); in gicv2m_irq_domain_free()
215 static bool is_msi_spi_valid(u32 base, u32 num) in is_msi_spi_valid() argument
218 pr_err("Invalid MSI base SPI (base:%u)\n", base); in is_msi_spi_valid()
222 if ((num == 0) || (base + num > V2M_MAX_SPI)) { in is_msi_spi_valid()
223 pr_err("Number of SPIs (%u) exceed maximum (%u)\n", in is_msi_spi_valid()
224 num, V2M_MAX_SPI - V2M_MIN_SPI + 1); in is_msi_spi_valid()
236 list_del(&v2m->entry); in gicv2m_teardown()
237 bitmap_free(v2m->bm); in gicv2m_teardown()
238 iounmap(v2m->base); in gicv2m_teardown()
239 of_node_put(to_of_node(v2m->fwnode)); in gicv2m_teardown()
240 if (is_fwnode_irqchip(v2m->fwnode)) in gicv2m_teardown()
241 irq_domain_free_fwnode(v2m->fwnode); in gicv2m_teardown()
260 .prefix = "GICv2m-",
273 inner_domain = irq_domain_create_hierarchy(parent, 0, 0, v2m->fwnode, in gicv2m_allocate_domains()
277 return -ENOMEM; in gicv2m_allocate_domains()
281 inner_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT; in gicv2m_allocate_domains()
282 inner_domain->msi_parent_ops = &gicv2m_msi_parent_ops; in gicv2m_allocate_domains()
295 return -ENOMEM; in gicv2m_init_one()
297 INIT_LIST_HEAD(&v2m->entry); in gicv2m_init_one()
298 v2m->fwnode = fwnode; in gicv2m_init_one()
299 v2m->flags = flags; in gicv2m_init_one()
301 memcpy(&v2m->res, res, sizeof(struct resource)); in gicv2m_init_one()
303 v2m->base = ioremap(v2m->res.start, resource_size(&v2m->res)); in gicv2m_init_one()
304 if (!v2m->base) { in gicv2m_init_one()
306 ret = -ENOMEM; in gicv2m_init_one()
311 v2m->spi_start = spi_start; in gicv2m_init_one()
312 v2m->nr_spis = nr_spis; in gicv2m_init_one()
317 if (v2m->flags & GICV2M_GRAVITON_ADDRESS_ONLY) { in gicv2m_init_one()
318 ret = -EINVAL; in gicv2m_init_one()
321 typer = readl_relaxed(v2m->base + V2M_MSI_TYPER); in gicv2m_init_one()
323 v2m->spi_start = V2M_MSI_TYPER_BASE_SPI(typer); in gicv2m_init_one()
324 v2m->nr_spis = V2M_MSI_TYPER_NUM_SPI(typer); in gicv2m_init_one()
327 if (!is_msi_spi_valid(v2m->spi_start, v2m->nr_spis)) { in gicv2m_init_one()
328 ret = -EINVAL; in gicv2m_init_one()
333 * APM X-Gene GICv2m implementation has an erratum where in gicv2m_init_one()
334 * the MSI data needs to be the offset from the spi_start in gicv2m_init_one()
335 * in order to trigger the correct MSI interrupt. This is in gicv2m_init_one()
337 * the MSI data is the absolute value within the range from in gicv2m_init_one()
340 * Broadcom NS2 GICv2m implementation has an erratum where the MSI data in gicv2m_init_one()
341 * is 'spi_number - 32' in gicv2m_init_one()
345 if (!(v2m->flags & GICV2M_GRAVITON_ADDRESS_ONLY)) { in gicv2m_init_one()
346 switch (readl_relaxed(v2m->base + V2M_MSI_IIDR)) { in gicv2m_init_one()
348 v2m->flags |= GICV2M_NEEDS_SPI_OFFSET; in gicv2m_init_one()
349 v2m->spi_offset = v2m->spi_start; in gicv2m_init_one()
352 v2m->flags |= GICV2M_NEEDS_SPI_OFFSET; in gicv2m_init_one()
353 v2m->spi_offset = 32; in gicv2m_init_one()
357 v2m->bm = bitmap_zalloc(v2m->nr_spis, GFP_KERNEL); in gicv2m_init_one()
358 if (!v2m->bm) { in gicv2m_init_one()
359 ret = -ENOMEM; in gicv2m_init_one()
363 list_add_tail(&v2m->entry, &v2m_nodes); in gicv2m_init_one()
366 v2m->spi_start, (v2m->spi_start + v2m->nr_spis - 1)); in gicv2m_init_one()
370 iounmap(v2m->base); in gicv2m_init_one()
377 { .compatible = "arm,gic-v2m-frame", },
393 if (!of_property_read_bool(child, "msi-controller")) in gicv2m_of_init()
402 if (!of_property_read_u32(child, "arm,msi-base-spi", in gicv2m_of_init()
404 !of_property_read_u32(child, "arm,msi-num-spis", &nr_spis)) in gicv2m_of_init()
405 pr_info("DT overriding V2M MSI_TYPER (base:%u, num:%u)\n", in gicv2m_of_init()
408 ret = gicv2m_init_one(&child->fwnode, spi_start, nr_spis, in gicv2m_of_init()
433 /* We only return the fwnode of the first MSI frame. */ in gicv2m_get_fwnode()
438 return data->fwnode; in gicv2m_get_fwnode()
454 rc = !memcmp(madt->header.oem_id, ACPI_AMZN_OEM_ID, ACPI_OEM_ID_SIZE); in acpi_check_amazon_graviton_quirks()
473 return -EINVAL; in acpi_parse_madt_msi()
475 res.start = m->base_address; in acpi_parse_madt_msi()
476 res.end = m->base_address + SZ_4K - 1; in acpi_parse_madt_msi()
481 res.end = res.start + SZ_8K - 1; in acpi_parse_madt_msi()
486 if (m->flags & ACPI_MADT_OVERRIDE_SPI_VALUES) { in acpi_parse_madt_msi()
487 spi_start = m->spi_base; in acpi_parse_madt_msi()
488 nr_spis = m->spi_count; in acpi_parse_madt_msi()
490 pr_info("ACPI overriding V2M MSI_TYPER (base:%u, num:%u)\n", in acpi_parse_madt_msi()
497 return -EINVAL; in acpi_parse_madt_msi()
530 return -EINVAL; in gicv2m_acpi_init()
535 return -EINVAL; in gicv2m_acpi_init()