Index: sys/arm/arm/pmu.h =================================================================== --- /dev/null +++ sys/arm/arm/pmu.h @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _ARM_PMU_H_ +#define _ARM_PMU_H_ + +#ifdef notyet +#define MAX_RLEN 8 +#else +#define MAX_RLEN 1 +#endif + +struct pmu_softc { + struct resource *res[MAX_RLEN]; + device_t dev; + void *ih[MAX_RLEN]; +}; + +int pmu_attach(device_t dev); + +#endif Index: sys/arm/arm/pmu.c =================================================================== --- sys/arm/arm/pmu.c +++ sys/arm/arm/pmu.c @@ -60,17 +60,7 @@ #include #include -#ifdef notyet -#define MAX_RLEN 8 -#else -#define MAX_RLEN 1 -#endif - -struct pmu_softc { - struct resource *res[MAX_RLEN]; - device_t dev; - void *ih[MAX_RLEN]; -}; +#include "pmu.h" static struct resource_spec pmu_spec[] = { { SYS_RES_IRQ, 0, RF_ACTIVE }, @@ -130,7 +120,7 @@ return (FILTER_HANDLED); } -static int +int pmu_attach(device_t dev) { struct pmu_softc *sc; @@ -181,6 +171,10 @@ #ifdef FDT static struct ofw_compat_data compat_data[] = { {"arm,armv8-pmuv3", 1}, + {"arm,cortex-a73-pmu", 1}, + {"arm,cortex-a72-pmu", 1}, + {"arm,cortex-a57-pmu", 1}, + {"arm,cortex-a53-pmu", 1}, {"arm,cortex-a17-pmu", 1}, {"arm,cortex-a15-pmu", 1}, {"arm,cortex-a12-pmu", 1}, Index: sys/arm/arm/pmu_acpi.c =================================================================== --- /dev/null +++ sys/arm/arm/pmu_acpi.c @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 2019 Greg V + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include + +#include "pmu.h" + +struct madt_ctx { + device_t parent; + device_t dev; +}; + +static void +madt_handler(ACPI_SUBTABLE_HEADER *entry, void *arg) +{ + ACPI_MADT_GENERIC_INTERRUPT *intr; + struct madt_ctx *ctx = arg; + + if (entry->Type != ACPI_MADT_TYPE_GENERIC_INTERRUPT) + return; + + intr = (ACPI_MADT_GENERIC_INTERRUPT *)entry; + + /* NOTE: when adding support for multiple CPUs, handle the case of one IRQ + * for all CPUs (e.g. on the Ampere eMAG) */ + if (intr->CpuInterfaceNumber > 0) + return; + + if (bootverbose) + device_printf(ctx->dev, "MADT entry: CPU/RID %d IRQ %d edge-triggered %d\n", + intr->CpuInterfaceNumber, + intr->PerformanceInterrupt, + (intr->Flags & ACPI_MADT_PERFORMANCE_IRQ_MODE)); + + BUS_SET_RESOURCE(ctx->parent, ctx->dev, SYS_RES_IRQ, + intr->CpuInterfaceNumber, intr->PerformanceInterrupt, 1); + BUS_CONFIG_INTR(ctx->parent, intr->PerformanceInterrupt, + (intr->Flags & ACPI_MADT_PERFORMANCE_IRQ_MODE) ? + INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, + INTR_POLARITY_CONFORM); +} + +static void +pmu_acpi_identify(driver_t *driver, device_t parent) +{ + ACPI_TABLE_MADT *madt; + vm_paddr_t physaddr; + device_t dev; + struct madt_ctx ctx; + + physaddr = acpi_find_table(ACPI_SIG_MADT); + if (physaddr == 0) + return; + + madt = acpi_map_table(physaddr, ACPI_SIG_MADT); + if (madt == NULL) { + device_printf(parent, "pmu: Unable to map the MADT\n"); + return; + } + + dev = BUS_ADD_CHILD(parent, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_LAST, + "pmu", -1); + if (dev == NULL) { + device_printf(parent, "add pmu child failed\n"); + goto out; + } + + ctx.parent = parent; + ctx.dev = dev; + acpi_walk_subtables(madt + 1, (char *)madt + madt->Header.Length, + madt_handler, &ctx); + +out: + acpi_unmap_table(madt); +} + +static int +pmu_acpi_probe(device_t dev) +{ + + device_set_desc(dev, "Performance Monitoring Unit"); + return (BUS_PROBE_NOWILDCARD); +} + +static device_method_t pmu_acpi_methods[] = { + DEVMETHOD(device_identify, pmu_acpi_identify), + DEVMETHOD(device_probe, pmu_acpi_probe), + DEVMETHOD(device_attach, pmu_attach), + DEVMETHOD_END, +}; + +static driver_t pmu_acpi_driver = { + "pmu", + pmu_acpi_methods, + sizeof(struct pmu_softc), +}; + +static devclass_t pmu_acpi_devclass; + +DRIVER_MODULE(pmu, acpi, pmu_acpi_driver, pmu_acpi_devclass, 0, 0); Index: sys/conf/files.arm64 =================================================================== --- sys/conf/files.arm64 +++ sys/conf/files.arm64 @@ -85,6 +85,7 @@ arm/arm/gic_acpi.c optional acpi arm/arm/gic_fdt.c optional fdt arm/arm/pmu.c standard +arm/arm/pmu_acpi.c optional acpi arm/arm/physmem.c standard arm/broadcom/bcm2835/bcm2835_audio.c optional sound vchiq fdt \ compile-with "${NORMAL_C} -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -I$S/contrib/vchiq"