Index: sparc64/pci/schizo.c =================================================================== --- sparc64/pci/schizo.c (revision 197980) +++ sparc64/pci/schizo.c (working copy) @@ -989,7 +989,8 @@ sc = device_get_softc(bridge); pintr = pin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, ®, - sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf)) + sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), NULL, + maskbuf)) return (mintr); device_printf(bridge, "could not route pin %d for device %d.%d\n", Index: sparc64/pci/ofw_pcib_subr.c =================================================================== --- sparc64/pci/ofw_pcib_subr.c (revision 197980) +++ sparc64/pci/ofw_pcib_subr.c (working copy) @@ -77,7 +77,7 @@ pintr = intpin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), ii, ®, sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), - maskbuf)) { + NULL, maskbuf)) { /* * If we've found a mapping, return it and don't map * it again on higher levels - that causes problems Index: sparc64/pci/psycho.c =================================================================== --- sparc64/pci/psycho.c (revision 197980) +++ sparc64/pci/psycho.c (working copy) @@ -1030,7 +1030,8 @@ sc = device_get_softc(bridge); pintr = pin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, ®, - sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf)) + sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), NULL, + maskbuf)) return (mintr); /* * If this is outside of the range for an intpin, it's likely a full Index: sparc64/isa/ofw_isa.c =================================================================== --- sparc64/isa/ofw_isa.c (revision 197980) +++ sparc64/isa/ofw_isa.c (working copy) @@ -113,7 +113,7 @@ * fully specified, so we may not continue to map. */ if (!ofw_bus_lookup_imap(node, ii, ®, sizeof(reg), - &intr, sizeof(intr), &mintr, sizeof(mintr), maskbuf)) { + &intr, sizeof(intr), &mintr, sizeof(mintr), NULL, maskbuf)) { /* Try routing at the parent bridge. */ mintr = PCIB_ROUTE_INTERRUPT(pbridge, bridge, intr); } Index: dev/ofw/ofw_bus_subr.c =================================================================== --- dev/ofw/ofw_bus_subr.c (revision 197980) +++ dev/ofw/ofw_bus_subr.c (working copy) @@ -174,7 +174,7 @@ int ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg, int regsz, void *pintr, int pintrsz, void *mintr, int mintrsz, - void *maskbuf) + phandle_t *iparent, void *maskbuf) { int rv; @@ -188,7 +188,7 @@ panic("ofw_bus_lookup_imap: could not get reg property"); return (ofw_bus_search_intrmap(pintr, pintrsz, reg, ii->opi_addrc, ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr, - mintrsz)); + mintrsz, iparent)); } /* @@ -211,7 +211,7 @@ int ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, void *imap, int imapsz, void *imapmsk, void *maskbuf, void *result, - int rintrsz) + int rintrsz, phandle_t *iparent) { phandle_t parent; uint8_t *ref = maskbuf; @@ -255,6 +255,9 @@ if (bcmp(ref, mptr, physsz + intrsz) == 0) { bcopy(mptr + physsz + intrsz + sizeof(parent), result, rintrsz); + + if (iparent != NULL) + *iparent = parent; return (1); } mptr += tsz; Index: dev/ofw/ofw_bus_subr.h =================================================================== --- dev/ofw/ofw_bus_subr.h (revision 197980) +++ dev/ofw/ofw_bus_subr.h (working copy) @@ -63,8 +63,11 @@ /* Routines for processing firmware interrupt maps */ void ofw_bus_setup_iinfo(phandle_t, struct ofw_bus_iinfo *, int); int ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int, - void *, int, void *, int, void *); + void *, int, void *, int, phandle_t *, void *); int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *, - void *, void *, int); + void *, void *, int, phandle_t *); +/* Helper to get node's interrupt parent */ +void ofw_bus_find_iparent(phandle_t); + #endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */ Index: powerpc/booke/interrupt.c =================================================================== --- powerpc/booke/interrupt.c (revision 197980) +++ powerpc/booke/interrupt.c (working copy) @@ -133,6 +133,6 @@ td = PCPU_GET(curthread); atomic_add_int(&td->td_intr_nesting_level, 1); - PIC_DISPATCH(pic, framep); + PIC_DISPATCH(root_pic, framep); atomic_subtract_int(&td->td_intr_nesting_level, 1); } Index: powerpc/powerpc/pic_if.m =================================================================== --- powerpc/powerpc/pic_if.m (revision 197980) +++ powerpc/powerpc/pic_if.m (working copy) @@ -60,6 +60,10 @@ u_int cpu; }; +METHOD uint32_t id { + device_t dev; +}; + METHOD void mask { device_t dev; u_int irq; Index: powerpc/powerpc/openpic.c =================================================================== --- powerpc/powerpc/openpic.c (revision 197980) +++ powerpc/powerpc/openpic.c (working copy) @@ -52,6 +52,7 @@ /* * Local routines */ +static void openpic_intr(void *arg); static __inline uint32_t openpic_read(struct openpic_softc *sc, u_int reg) @@ -100,6 +101,19 @@ sc->sc_bt = rman_get_bustag(sc->sc_memr); sc->sc_bh = rman_get_bushandle(sc->sc_memr); + /* Check if this is a cascaded PIC */ + sc->sc_irq = 0; + sc->sc_intr = NULL; + if (resource_list_find(BUS_GET_RESOURCE_LIST(device_get_parent(dev), + dev), SYS_RES_IRQ, 0) != NULL) { + sc->sc_intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, + &sc->sc_irq, RF_ACTIVE); + + /* XXX Cascaded PICs pass NULL trapframes! */ + bus_setup_intr(dev, sc->sc_intr, INTR_TYPE_MISC | INTR_MPSAFE, + NULL, openpic_intr, dev, &sc->sc_icookie); + } + x = openpic_read(sc, OPENPIC_FEATURE); switch (x & OPENPIC_FEATURE_VERSION_MASK) { case 1: @@ -175,6 +189,10 @@ powerpc_register_pic(dev, sc->sc_nirq); + /* If this is not a cascaded PIC, it must be the root PIC */ + if (sc->sc_intr == NULL) + root_pic = dev; + return (0); } @@ -202,6 +220,15 @@ openpic_write(sc, OPENPIC_SRC_VECTOR(irq), x); } +static void +openpic_intr(void *arg) +{ + device_t dev = (device_t)(arg); + + /* XXX Cascaded PICs do not pass non-NULL trapframes! */ + openpic_dispatch(dev, NULL); +} + void openpic_dispatch(device_t dev, struct trapframe *tf) { Index: powerpc/powerpc/intr_machdep.c =================================================================== --- powerpc/powerpc/intr_machdep.c (revision 197980) +++ powerpc/powerpc/intr_machdep.c (working copy) @@ -85,14 +85,6 @@ #include "pic_if.h" -#ifdef MPC85XX -#define ISA_IRQ_COUNT 16 -#endif - -#ifndef ISA_IRQ_COUNT -#define ISA_IRQ_COUNT 0 -#endif - #define MAX_STRAY_LOG 5 MALLOC_DEFINE(M_INTR, "intr", "interrupt handler data"); @@ -108,20 +100,25 @@ enum intr_polarity pol; }; +struct pic { + device_t pic; + uint32_t pic_id; + int ipi_irq; +}; + static struct mtx intr_table_lock; static struct powerpc_intr *powerpc_intrs[INTR_VECTORS]; +static struct pic piclist[MAX_PICS]; static u_int nvectors; /* Allocated vectors */ +static u_int npics; /* PICs registered */ static u_int stray_count; +device_t root_pic; + #ifdef SMP static void *ipi_cookie; #endif -static u_int ipi_irq; - -device_t pic; -device_t pic8259; - static void intr_init(void *dummy __unused) { @@ -197,21 +194,13 @@ powerpc_map_irq(struct powerpc_intr *i) { -#if ISA_IRQ_COUNT > 0 - if (i->irq < ISA_IRQ_COUNT) { - if (pic8259 == NULL) { - i->pic = pic; - i->intline = 0; - return (ENXIO); - } - i->pic = pic8259; - i->intline = i->irq; - return (0); - } -#endif + i->intline = INTR_INTLINE(i->irq); + i->pic = piclist[INTR_IGN(i->irq)].pic; - i->pic = pic; - i->intline = i->irq - ISA_IRQ_COUNT; + /* Try a best guess if that failed */ + if (i->pic == NULL) + i->pic = root_pic; + return (0); } @@ -242,16 +231,44 @@ void powerpc_register_pic(device_t dev, u_int ipi) { + int i; - pic = dev; - ipi_irq = ipi + ISA_IRQ_COUNT; + mtx_lock(&intr_table_lock); + + for (i = 0; i < npics; i++) { + if (piclist[i].pic_id == PIC_ID(dev)) + break; + } + piclist[i].pic = dev; + piclist[i].pic_id = PIC_ID(dev); + piclist[i].ipi_irq = ipi; + if (i == npics) + npics++; + + mtx_unlock(&intr_table_lock); } -void -powerpc_register_8259(device_t dev) +int +powerpc_ign_lookup(uint32_t pic_id) { + int i; - pic8259 = dev; + mtx_lock(&intr_table_lock); + + for (i = 0; i < npics; i++) { + if (piclist[i].pic_id == pic_id) { + mtx_unlock(&intr_table_lock); + return (i); + } + } + piclist[i].pic = NULL; + piclist[i].pic_id = pic_id; + piclist[i].ipi_irq = 0; + npics++; + + mtx_unlock(&intr_table_lock); + + return (i); } int @@ -260,7 +277,7 @@ struct powerpc_intr *i; int error, vector; - if (pic == NULL) + if (npics == 0) panic("no PIC detected\n"); #ifdef SMP @@ -294,7 +311,7 @@ } int -powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter, +powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter, driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep) { struct powerpc_intr *i; Index: powerpc/include/intr_machdep.h =================================================================== --- powerpc/include/intr_machdep.h (revision 197980) +++ powerpc/include/intr_machdep.h (working copy) @@ -29,21 +29,27 @@ #define _MACHINE_INTR_MACHDEP_H_ #define INTR_VECTORS 256 +#define MAX_PICS 5 -extern device_t pic; -extern device_t pic8259; +#define IGN_SHIFT 8 +#define INTR_INTLINE(irq) (irq & ((1 << IGN_SHIFT) - 1)) +#define INTR_IGN(irq) (irq >> IGN_SHIFT) +#define INTR_VEC(pic_id, irq) ((powerpc_ign_lookup(pic_id) << IGN_SHIFT) | irq) + +extern device_t root_pic; + struct trapframe; driver_filter_t powerpc_ipi_handler; void powerpc_register_pic(device_t, u_int); -void powerpc_register_8259(device_t); +int powerpc_ign_lookup(uint32_t pic_id); void powerpc_dispatch_intr(u_int, struct trapframe *); int powerpc_enable_intr(void); -int powerpc_setup_intr(const char *, u_int, driver_filter_t, - driver_intr_t, void *, enum intr_type, void **); +int powerpc_setup_intr(const char *, u_int, driver_filter_t, driver_intr_t, + void *, enum intr_type, void **); int powerpc_teardown_intr(void *); int powerpc_config_intr(int, enum intr_trigger, enum intr_polarity); Index: powerpc/include/openpicvar.h =================================================================== --- powerpc/include/openpicvar.h (revision 197980) +++ powerpc/include/openpicvar.h (working copy) @@ -35,10 +35,13 @@ struct openpic_softc { device_t sc_dev; struct resource *sc_memr; + struct resource *sc_intr; bus_space_tag_t sc_bt; bus_space_handle_t sc_bh; char *sc_version; int sc_rid; + int sc_irq; + void *sc_icookie; u_int sc_ncpu; u_int sc_nirq; int sc_psim; Index: powerpc/aim/interrupt.c =================================================================== --- powerpc/aim/interrupt.c (revision 197980) +++ powerpc/aim/interrupt.c (working copy) @@ -81,7 +81,7 @@ switch (framep->exc) { case EXC_EXI: atomic_add_int(&td->td_intr_nesting_level, 1); - PIC_DISPATCH(pic, framep); + PIC_DISPATCH(root_pic, framep); atomic_subtract_int(&td->td_intr_nesting_level, 1); break; Index: powerpc/ofw/ofw_pcib_pci.c =================================================================== --- powerpc/ofw/ofw_pcib_pci.c (revision 197980) +++ powerpc/ofw/ofw_pcib_pci.c (working copy) @@ -42,6 +42,8 @@ #include #include +#include + #include "pcib_if.h" static int ofw_pcib_pci_probe(device_t bus); @@ -149,6 +151,7 @@ struct ofw_bus_iinfo *ii; struct ofw_pci_register reg; cell_t pintr, mintr; + phandle_t iparent; uint8_t maskbuf[sizeof(reg) + sizeof(pintr)]; sc = device_get_softc(bridge); @@ -157,13 +160,13 @@ pintr = intpin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), ii, ®, sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), - maskbuf)) { + &iparent, maskbuf)) { /* * If we've found a mapping, return it and don't map * it again on higher levels - that causes problems * in some cases, and never seems to be required. */ - return (mintr); + return (INTR_VEC(iparent, mintr)); } } else if (intpin >= 1 && intpin <= 4) { /* Index: powerpc/powermac/cpcht.c =================================================================== --- powerpc/powermac/cpcht.c (revision 197980) +++ powerpc/powermac/cpcht.c (working copy) @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -606,13 +607,15 @@ struct cpcpci_softc *sc; struct ofw_pci_register reg; uint32_t pintr, mintr; + phandle_t iparent; uint8_t maskbuf[sizeof(reg) + sizeof(pintr)]; sc = device_get_softc(bus); pintr = pin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, ®, - sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf)) - return (mintr); + sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), + &iparent, maskbuf)) + return (INTR_VEC(iparent, mintr)); /* Maybe it's a real interrupt, not an intpin */ if (pin > 4) Index: powerpc/powermac/openpic_macio.c =================================================================== --- powerpc/powermac/openpic_macio.c (revision 197980) +++ powerpc/powermac/openpic_macio.c (working copy) @@ -59,6 +59,7 @@ * MacIO interface */ static int openpic_macio_probe(device_t); +static uint32_t openpic_macio_id(device_t); static device_method_t openpic_macio_methods[] = { /* Device interface */ @@ -73,6 +74,7 @@ DEVMETHOD(pic_ipi, openpic_ipi), DEVMETHOD(pic_mask, openpic_mask), DEVMETHOD(pic_unmask, openpic_unmask), + DEVMETHOD(pic_id, openpic_macio_id), { 0, 0 }, }; @@ -96,3 +98,10 @@ device_set_desc(dev, OPENPIC_DEVSTR); return (0); } + +static uint32_t +openpic_macio_id(device_t dev) +{ + return (ofw_bus_get_node(dev)); +} + Index: powerpc/powermac/uninorth.c =================================================================== --- powerpc/powermac/uninorth.c (revision 197980) +++ powerpc/powermac/uninorth.c (working copy) @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -365,13 +366,15 @@ struct uninorth_softc *sc; struct ofw_pci_register reg; uint32_t pintr, mintr; + phandle_t iparent; uint8_t maskbuf[sizeof(reg) + sizeof(pintr)]; sc = device_get_softc(bus); pintr = pin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, ®, - sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf)) - return (mintr); + sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), + &iparent, maskbuf)) + return (INTR_VEC(iparent, mintr)); /* Maybe it's a real interrupt, not an intpin */ if (pin > 4) Index: powerpc/powermac/grackle.c =================================================================== --- powerpc/powermac/grackle.c (revision 197980) +++ powerpc/powermac/grackle.c (working copy) @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -341,13 +342,15 @@ struct grackle_softc *sc; struct ofw_pci_register reg; uint32_t pintr, mintr; + phandle_t iparent; uint8_t maskbuf[sizeof(reg) + sizeof(pintr)]; sc = device_get_softc(bus); pintr = pin; if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, ®, - sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf)) - return (mintr); + sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), + &iparent, maskbuf)) + return (INTR_VEC(iparent, mintr)); /* Maybe it's a real interrupt, not an intpin */ if (pin > 4) Index: powerpc/powermac/hrowpic.c =================================================================== --- powerpc/powermac/hrowpic.c (revision 197980) +++ powerpc/powermac/hrowpic.c (working copy) @@ -70,6 +70,7 @@ static void hrowpic_ipi(device_t, u_int); static void hrowpic_mask(device_t, u_int); static void hrowpic_unmask(device_t, u_int); +static uint32_t hrowpic_id(device_t dev); static device_method_t hrowpic_methods[] = { /* Device interface */ @@ -80,6 +81,7 @@ DEVMETHOD(pic_dispatch, hrowpic_dispatch), DEVMETHOD(pic_enable, hrowpic_enable), DEVMETHOD(pic_eoi, hrowpic_eoi), + DEVMETHOD(pic_id, hrowpic_id), DEVMETHOD(pic_ipi, hrowpic_ipi), DEVMETHOD(pic_mask, hrowpic_mask), DEVMETHOD(pic_unmask, hrowpic_unmask), @@ -169,6 +171,8 @@ hrowpic_write_reg(sc, HPIC_CLEAR, HPIC_SECONDARY, 0xffffffff); powerpc_register_pic(dev, 64); + root_pic = dev; /* Heathrow systems have only one PIC */ + return (0); } @@ -276,3 +280,10 @@ sc = device_get_softc(dev); hrowpic_toggle_irq(sc, irq, 1); } + +static uint32_t +hrowpic_id(device_t dev) +{ + return (ofw_bus_get_node(dev)); +} + Index: powerpc/powermac/macgpio.c =================================================================== --- powerpc/powermac/macgpio.c (revision 197980) +++ powerpc/powermac/macgpio.c (working copy) @@ -35,15 +35,16 @@ #include #include #include -#include #include -#include #include #include + +#include +#include #include - #include +#include #include #include @@ -148,8 +149,7 @@ { struct macgpio_softc *sc; struct macgpio_devinfo *dinfo; - phandle_t root; - phandle_t child; + phandle_t root, child, iparent; device_t cdev; uint32_t irq; @@ -184,10 +184,13 @@ resource_list_init(&dinfo->mdi_resources); - if (OF_getprop(child,"interrupts",&irq, sizeof(irq)) == + if (OF_getprop(child, "interrupts", &irq, sizeof(irq)) == sizeof(irq)) { + OF_searchprop(child, "interrupt-parent", &iparent, + sizeof(iparent)); resource_list_add(&dinfo->mdi_resources, SYS_RES_IRQ, - 0, irq, irq, 1); + 0, INTR_VEC(iparent, irq), INTR_VEC(iparent, irq), + 1); } /* Fix messed-up offsets */ Index: powerpc/powermac/macio.c =================================================================== --- powerpc/powermac/macio.c (revision 197980) +++ powerpc/powermac/macio.c (working copy) @@ -37,15 +37,16 @@ #include #include #include -#include #include -#include #include #include + +#include +#include #include - #include +#include #include #include @@ -186,6 +187,7 @@ static void macio_add_intr(phandle_t devnode, struct macio_devinfo *dinfo) { + phandle_t iparent; int *intr; int i, nintr; int icells; @@ -211,11 +213,17 @@ if (intr[0] == -1) return; + if (OF_getprop(devnode, "interrupt-parent", &iparent, sizeof(iparent)) + <= 0) + panic("Interrupt but no interrupt parent!\n"); + for (i = 0; i < nintr; i+=icells) { resource_list_add(&dinfo->mdi_resources, SYS_RES_IRQ, - dinfo->mdi_ninterrupts, intr[i], intr[i], 1); + dinfo->mdi_ninterrupts, INTR_VEC(iparent, intr[i]), + INTR_VEC(iparent, intr[i]), 1); - dinfo->mdi_interrupts[dinfo->mdi_ninterrupts] = intr[i]; + dinfo->mdi_interrupts[dinfo->mdi_ninterrupts] = + INTR_VEC(iparent, intr[i]); dinfo->mdi_ninterrupts++; } }