From cf0afdaab6c385be40c95a079dc2f0de670d40ea Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Wed, 28 Feb 2018 15:25:47 +0000 Subject: [PATCH] Count the number of GIC redistributors in the ACPI tables. The GICv3 driver needs this to allocate memory, and connect the CPUs to the interrupt controller. Sponsored by: DARPA, AFRL Sponsored by: Cavium (Hardware) --- sys/arm64/arm64/gic_v3_acpi.c | 40 +++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/sys/arm64/arm64/gic_v3_acpi.c b/sys/arm64/arm64/gic_v3_acpi.c index 8235bd33919..00a5e371208 100644 --- a/sys/arm64/arm64/gic_v3_acpi.c +++ b/sys/arm64/arm64/gic_v3_acpi.c @@ -206,6 +206,41 @@ gic_v3_acpi_probe(device_t dev) return (BUS_PROBE_NOWILDCARD); } +static void +madt_count_redistrib(ACPI_SUBTABLE_HEADER *entry, void *arg) +{ + struct gic_v3_softc *sc = arg; + + if (entry->Type == ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR) + sc->gic_redists.nregions++; +} + +static int +gic_v3_acpi_count_regions(device_t dev) +{ + struct gic_v3_softc *sc; + ACPI_TABLE_MADT *madt; + vm_paddr_t physaddr; + + sc = device_get_softc(dev); + + physaddr = acpi_find_table(ACPI_SIG_MADT); + if (physaddr == 0) + return (ENXIO); + + madt = acpi_map_table(physaddr, ACPI_SIG_MADT); + if (madt == NULL) { + device_printf(dev, "Unable to map the MADT\n"); + return (ENXIO); + } + + acpi_walk_subtables(madt + 1, (char *)madt + madt->Header.Length, + madt_count_redistrib, sc); + acpi_unmap_table(madt); + + return (sc->gic_redists.nregions > 0 ? 0 : ENXIO); +} + static int gic_v3_acpi_attach(device_t dev) { @@ -216,8 +251,9 @@ gic_v3_acpi_attach(device_t dev) sc->dev = dev; sc->gic_bus = GIC_BUS_ACPI; - /* TODO: Count these correctly */ - sc->gic_redists.nregions = 1; + err = gic_v3_acpi_count_regions(dev); + if (err != 0) + goto error; err = gic_v3_attach(dev); if (err != 0)