From 818f49fc98b179fdcdcdda84c11ff6f1eabeaee6 Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Sat, 4 Jan 2014 20:59:03 +0000 Subject: [PATCH] Implement OFW_BUS_MAP_INTR() in terms of the FDT PIC table, which will become an ARM-specific quirk. --- sys/arm/arm/nexus.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 94f3c379361..5c02e2aa3c7 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -64,7 +64,9 @@ __FBSDID("$FreeBSD$"); #ifdef FDT #include +#include #include +#include "ofw_bus_if.h" #else static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); @@ -94,6 +96,11 @@ static int nexus_setup_intr(device_t dev, device_t child, struct resource *res, int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, void **cookiep); static int nexus_teardown_intr(device_t, device_t, struct resource *, void *); +#ifdef FDT +static int nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, + int irq); +#endif + static device_method_t nexus_methods[] = { #ifndef FDT /* Device interface */ @@ -109,6 +116,9 @@ static device_method_t nexus_methods[] = { DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), DEVMETHOD(bus_setup_intr, nexus_setup_intr), DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), +#ifdef FDT + DEVMETHOD(ofw_bus_map_intr, nexus_ofw_map_intr), +#endif { 0, 0 } }; @@ -300,3 +310,33 @@ nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, return (rman_deactivate_resource(res)); } +#ifdef FDT +static int +nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int irq) +{ + pcell_t intr[2]; + fdt_pic_decode_t intr_decode; + phandle_t intr_offset; + int i, rv, interrupt, trig, pol; + + intr_offset = OF_xref_phandle(iparent); + intr[0] = cpu_to_fdt32(irq); + + for (i = 0; fdt_pic_table[i] != NULL; i++) { + intr_decode = fdt_pic_table[i]; + rv = intr_decode(intr_offset, intr, &interrupt, &trig, &pol); + + if (rv == 0) { + /* This was recognized as our PIC and decoded. */ + interrupt = FDT_MAP_IRQ(intr_parent, interrupt); + return (interrupt); + } + } + + /* Not in table, so guess */ + interrupt = FDT_MAP_IRQ(intr_parent, fdt32_to_cpu(*intr)); + + return (interrupt); +} +#endif +