From ec7d251e09845cca95abe7088b4ffb62849395ff Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Sun, 21 Dec 2014 21:27:12 +0000 Subject: [PATCH] Pull out the fdt mapping code into intr.c. The arm_intrng branch also defines this function allowing the mapping method to change when we move to it. --- sys/arm/arm/intr.c | 39 +++++++++++++++++++++++++++++++++++++++ sys/arm/arm/nexus.c | 28 +++------------------------- sys/arm/include/intr.h | 8 ++++++++ 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/sys/arm/arm/intr.c b/sys/arm/arm/intr.c index 83eca0777826..030407a6ddc4 100644 --- a/sys/arm/arm/intr.c +++ b/sys/arm/arm/intr.c @@ -36,8 +36,11 @@ * Soft interrupt and other generic interrupt functions. */ +#include "opt_platform.h" + #include __FBSDID("$FreeBSD$"); + #include #include #include @@ -47,10 +50,16 @@ __FBSDID("$FreeBSD$"); #include #include #include + #include #include #include +#ifdef FDT +#include +#include +#endif + #define INTRNAME_LEN (MAXCOMLEN + 1) typedef void (*mask_fn)(void *); @@ -89,6 +98,36 @@ intr_init(void *unused) SYSINIT(intr_init, SI_SUB_INTR, SI_ORDER_FIRST, intr_init, NULL); +#ifdef FDT +int +arm_fdt_map_irq(phandle_t iparent, pcell_t *intr, int icells) +{ + fdt_pic_decode_t intr_decode; + phandle_t intr_parent; + int i, rv, interrupt, trig, pol; + + intr_parent = OF_node_from_xref(iparent); + for (i = 0; i < icells; i++) + intr[i] = cpu_to_fdt32(intr[i]); + + for (i = 0; fdt_pic_table[i] != NULL; i++) { + intr_decode = fdt_pic_table[i]; + rv = intr_decode(intr_parent, 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[0])); + + return (interrupt); +} +#endif + void arm_setup_irqhandler(const char *name, driver_filter_t *filt, void (*hand)(void*), void *arg, int irq, int flags, void **cookiep) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 6678d5db9b8f..06f2d6ff454f 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -39,6 +39,8 @@ * and I/O memory address space. */ +#include "opt_platform.h" + #include __FBSDID("$FreeBSD$"); @@ -60,10 +62,7 @@ __FBSDID("$FreeBSD$"); #include #include -#include "opt_platform.h" - #ifdef FDT -#include #include #include "ofw_bus_if.h" #endif @@ -351,28 +350,7 @@ static int nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int icells, pcell_t *intr) { - fdt_pic_decode_t intr_decode; - phandle_t intr_parent; - int i, rv, interrupt, trig, pol; - intr_parent = OF_node_from_xref(iparent); - for (i = 0; i < icells; i++) - intr[i] = cpu_to_fdt32(intr[i]); - - for (i = 0; fdt_pic_table[i] != NULL; i++) { - intr_decode = fdt_pic_table[i]; - rv = intr_decode(intr_parent, 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[0])); - - return (interrupt); + return (arm_fdt_map_irq(iparent, intr, icells)); } #endif diff --git a/sys/arm/include/intr.h b/sys/arm/include/intr.h index 35097725b71a..9ee86f342ce6 100644 --- a/sys/arm/include/intr.h +++ b/sys/arm/include/intr.h @@ -39,6 +39,10 @@ #ifndef _MACHINE_INTR_H_ #define _MACHINE_INTR_H_ +#ifdef FDT +#include +#endif + /* XXX move to std.* files? */ #ifdef CPU_XSCALE_81342 #define NIRQ 128 @@ -85,4 +89,8 @@ void gic_init_secondary(void); int gic_decode_fdt(uint32_t iparentnode, uint32_t *intrcells, int *interrupt, int *trig, int *pol); +#ifdef FDT +int arm_fdt_map_irq(phandle_t, pcell_t *, int); +#endif + #endif /* _MACHINE_INTR_H */