Index: head/sys/powerpc/powermac/grackle.c =================================================================== --- head/sys/powerpc/powermac/grackle.c (revision 133520) +++ head/sys/powerpc/powermac/grackle.c (revision 133521) @@ -1,554 +1,553 @@ /* * Copyright 2003 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * * $FreeBSD$ */ -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pcib_if.h" int badaddr(void *, size_t); /* XXX */ /* * Device interface. */ static int grackle_probe(device_t); static int grackle_attach(device_t); /* * Bus interface. */ static int grackle_read_ivar(device_t, device_t, int, uintptr_t *); static struct resource * grackle_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags); static int grackle_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res); static int grackle_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res); static int grackle_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res); /* * pcib interface. */ static int grackle_maxslots(device_t); static u_int32_t grackle_read_config(device_t, u_int, u_int, u_int, u_int, int); static void grackle_write_config(device_t, u_int, u_int, u_int, u_int, u_int32_t, int); static int grackle_route_interrupt(device_t, device_t, int); /* * Local routines. */ static int grackle_enable_config(struct grackle_softc *, u_int, u_int, u_int, u_int); static void grackle_disable_config(struct grackle_softc *); /* * Driver methods. */ static device_method_t grackle_methods[] = { /* Device interface */ DEVMETHOD(device_probe, grackle_probe), DEVMETHOD(device_attach, grackle_attach), /* Bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), DEVMETHOD(bus_read_ivar, grackle_read_ivar), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), DEVMETHOD(bus_alloc_resource, grackle_alloc_resource), DEVMETHOD(bus_release_resource, grackle_release_resource), DEVMETHOD(bus_activate_resource, grackle_activate_resource), DEVMETHOD(bus_deactivate_resource, grackle_deactivate_resource), /* pcib interface */ DEVMETHOD(pcib_maxslots, grackle_maxslots), DEVMETHOD(pcib_read_config, grackle_read_config), DEVMETHOD(pcib_write_config, grackle_write_config), DEVMETHOD(pcib_route_interrupt, grackle_route_interrupt), { 0, 0 } }; static driver_t grackle_driver = { "pcib", grackle_methods, sizeof(struct grackle_softc) }; static devclass_t grackle_devclass; DRIVER_MODULE(grackle, nexus, grackle_driver, grackle_devclass, 0, 0); static int grackle_probe(device_t dev) { char *type, *compatible; type = nexus_get_device_type(dev); compatible = nexus_get_compatible(dev); if (type == NULL || compatible == NULL) return (ENXIO); if (strcmp(type, "pci") != 0 || strcmp(compatible, "grackle") != 0) return (ENXIO); device_set_desc(dev, "MPC106 (Grackle) Host-PCI bridge"); return (0); } static int grackle_attach(device_t dev) { struct grackle_softc *sc; phandle_t node; u_int32_t busrange[2]; struct grackle_range *rp, *io, *mem[2]; int nmem, i; node = nexus_get_node(dev); sc = device_get_softc(dev); if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8) return (ENXIO); sc->sc_dev = dev; sc->sc_node = node; sc->sc_bus = busrange[0]; /* * The Grackle PCI config addr/data registers are actually in * PCI space, but since they are needed to actually probe the * PCI bus, use the fact that they are also available directly * on the processor bus and map them */ sc->sc_addr = (vm_offset_t)pmap_mapdev(GRACKLE_ADDR, PAGE_SIZE); sc->sc_data = (vm_offset_t)pmap_mapdev(GRACKLE_DATA, PAGE_SIZE); bzero(sc->sc_range, sizeof(sc->sc_range)); sc->sc_nrange = OF_getprop(node, "ranges", sc->sc_range, sizeof(sc->sc_range)); if (sc->sc_nrange == -1) { device_printf(dev, "could not get ranges\n"); return (ENXIO); } sc->sc_range[6].pci_hi = 0; io = NULL; nmem = 0; for (rp = sc->sc_range; rp->pci_hi != 0; rp++) { switch (rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) { case OFW_PCI_PHYS_HI_SPACE_CONFIG: break; case OFW_PCI_PHYS_HI_SPACE_IO: io = rp; break; case OFW_PCI_PHYS_HI_SPACE_MEM32: mem[nmem] = rp; nmem++; break; case OFW_PCI_PHYS_HI_SPACE_MEM64: break; } } if (io == NULL) { device_printf(dev, "can't find io range\n"); return (ENXIO); } sc->sc_io_rman.rm_type = RMAN_ARRAY; sc->sc_io_rman.rm_descr = "Grackle PCI I/O Ports"; sc->sc_iostart = io->pci_iospace; if (rman_init(&sc->sc_io_rman) != 0 || rman_manage_region(&sc->sc_io_rman, io->pci_lo, io->pci_lo + io->size_lo) != 0) { device_printf(dev, "failed to set up io range management\n"); return (ENXIO); } if (nmem == 0) { device_printf(dev, "can't find mem ranges\n"); return (ENXIO); } sc->sc_mem_rman.rm_type = RMAN_ARRAY; sc->sc_mem_rman.rm_descr = "Grackle PCI Memory"; if (rman_init(&sc->sc_mem_rman) != 0) { device_printf(dev, "failed to init mem range resources\n"); return (ENXIO); } for (i = 0; i < nmem; i++) { if (rman_manage_region(&sc->sc_mem_rman, mem[i]->pci_lo, mem[i]->pci_lo + mem[i]->size_lo) != 0) { device_printf(dev, "failed to set up memory range management\n"); return (ENXIO); } } /* * Write out the correct PIC interrupt values to config space * of all devices on the bus. */ ofw_pci_fixup(dev, sc->sc_bus, sc->sc_node); device_add_child(dev, "pci", device_get_unit(dev)); return (bus_generic_attach(dev)); } static int grackle_maxslots(device_t dev) { return (PCI_SLOTMAX); } static u_int32_t grackle_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int width) { struct grackle_softc *sc; vm_offset_t caoff; u_int32_t retval = 0xffffffff; sc = device_get_softc(dev); caoff = sc->sc_data + (reg & 0x03); if (grackle_enable_config(sc, bus, slot, func, reg) != 0) { /* * Config probes to non-existent devices on the * secondary bus generates machine checks. Be sure * to catch these. */ if (bus > 0) { if (badaddr((void *)sc->sc_data, 4)) { return (retval); } } switch (width) { case 1: retval = (in8rb(caoff)); break; case 2: retval = (in16rb(caoff)); break; case 4: retval = (in32rb(caoff)); break; } } grackle_disable_config(sc); return (retval); } static void grackle_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, u_int32_t val, int width) { struct grackle_softc *sc; vm_offset_t caoff; sc = device_get_softc(dev); caoff = sc->sc_data + (reg & 0x03); if (grackle_enable_config(sc, bus, slot, func, reg)) { switch (width) { case 1: out8rb(caoff, val); (void)in8rb(caoff); break; case 2: out16rb(caoff, val); (void)in16rb(caoff); break; case 4: out32rb(caoff, val); (void)in32rb(caoff); break; } } grackle_disable_config(sc); } static int grackle_route_interrupt(device_t bus, device_t dev, int pin) { return (0); } static int grackle_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct grackle_softc *sc; sc = device_get_softc(dev); switch (which) { case PCIB_IVAR_BUS: *result = sc->sc_bus; return (0); break; } return (ENOENT); } static struct resource * grackle_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct grackle_softc *sc; struct resource *rv; struct rman *rm; bus_space_tag_t bt; int needactivate; needactivate = flags & RF_ACTIVE; flags &= ~RF_ACTIVE; sc = device_get_softc(bus); switch (type) { case SYS_RES_MEMORY: rm = &sc->sc_mem_rman; bt = PPC_BUS_SPACE_MEM; break; case SYS_RES_IOPORT: rm = &sc->sc_io_rman; bt = PPC_BUS_SPACE_IO; break; case SYS_RES_IRQ: return (bus_alloc_resource(bus, type, rid, start, end, count, flags)); break; default: device_printf(bus, "unknown resource request from %s\n", device_get_nameunit(child)); return (NULL); } rv = rman_reserve_resource(rm, start, end, count, flags, child); if (rv == NULL) { device_printf(bus, "failed to reserve resource for %s\n", device_get_nameunit(child)); return (NULL); } rman_set_bustag(rv, bt); rman_set_bushandle(rv, rman_get_start(rv)); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv) != 0) { device_printf(bus, "failed to activate resource for %s\n", device_get_nameunit(child)); rman_release_resource(rv); return (NULL); } } return (rv); } static int grackle_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { if (rman_get_flags(res) & RF_ACTIVE) { int error = bus_deactivate_resource(child, type, rid, res); if (error) return error; } return (rman_release_resource(res)); } static int grackle_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { struct grackle_softc *sc; void *p; sc = device_get_softc(bus); if (type == SYS_RES_IRQ) { return (bus_activate_resource(bus, type, rid, res)); } if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { vm_offset_t start; start = (vm_offset_t)rman_get_start(res); /* * For i/o-ports, convert the start address to the * MPC106 PCI i/o window */ if (type == SYS_RES_IOPORT) start += sc->sc_iostart; if (bootverbose) printf("grackle mapdev: start %x, len %ld\n", start, rman_get_size(res)); p = pmap_mapdev(start, (vm_size_t)rman_get_size(res)); if (p == NULL) return (ENOMEM); rman_set_virtual(res, p); rman_set_bushandle(res, (u_long)p); } return (rman_activate_resource(res)); } static int grackle_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { /* * If this is a memory resource, unmap it. */ if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { u_int32_t psize; psize = rman_get_size(res); pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize); } return (rman_deactivate_resource(res)); } static int grackle_enable_config(struct grackle_softc *sc, u_int bus, u_int slot, u_int func, u_int reg) { u_int32_t cfgval; /* * Unlike UniNorth, the format of the config word is the same * for local (0) and remote busses. */ cfgval = (bus << 16) | (slot << 11) | (func << 8) | (reg & 0xFC) | GRACKLE_CFG_ENABLE; out32rb(sc->sc_addr, cfgval); (void) in32rb(sc->sc_addr); return (1); } static void grackle_disable_config(struct grackle_softc *sc) { /* * Clear the GRACKLE_CFG_ENABLE bit to prevent stray * accesses from causing config cycles */ out32rb(sc->sc_addr, 0); } /* * Driver to swallow Grackle host bridges from the PCI bus side. */ static int grackle_hb_probe(device_t dev) { if (pci_get_devid(dev) == 0x00021057) { device_set_desc(dev, "Grackle Host to PCI bridge"); device_quiet(dev); return (0); } return (ENXIO); } static int grackle_hb_attach(device_t dev) { return (0); } static device_method_t grackle_hb_methods[] = { /* Device interface */ DEVMETHOD(device_probe, grackle_hb_probe), DEVMETHOD(device_attach, grackle_hb_attach), { 0, 0 } }; static driver_t grackle_hb_driver = { "grackle_hb", grackle_hb_methods, 1, }; static devclass_t grackle_hb_devclass; DRIVER_MODULE(grackle_hb, pci, grackle_hb_driver, grackle_hb_devclass, 0, 0); Index: head/sys/powerpc/powermac/hrowpic.c =================================================================== --- head/sys/powerpc/powermac/hrowpic.c (revision 133520) +++ head/sys/powerpc/powermac/hrowpic.c (revision 133521) @@ -1,488 +1,489 @@ /* * Copyright 2003 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * * $FreeBSD$ */ /* * A driver for the PIC found in the Heathrow/Paddington MacIO chips. * This was superseded by an OpenPIC in the Keylargo and beyond * MacIO versions. * * The device is initially located in the OpenFirmware device tree * in the earliest stage of the nexus probe. However, no device registers * are touched until the actual h/w is probed later on during the * MacIO probe. At that point, any interrupt sources that were allocated * prior to this are activated. */ -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pic_if.h" /* * Device interface. */ static void hrowpic_identify(driver_t *, device_t); static int hrowpic_probe(device_t); static int hrowpic_attach(device_t); /* * PIC interface. */ static struct resource *hrowpic_allocate_intr(device_t, device_t, int *, u_long, u_int); static int hrowpic_setup_intr(device_t, device_t, struct resource *, int, driver_intr_t, void *, void **); static int hrowpic_teardown_intr(device_t, device_t, struct resource *, void *); static int hrowpic_release_intr(device_t dev, device_t, int, struct resource *res); /* * MacIO interface */ static int hrowpic_macio_probe(device_t); static int hrowpic_macio_attach(device_t); /* * Local routines */ static void hrowpic_intr(void); static void hrowpic_ext_enable_irq(uintptr_t); static void hrowpic_ext_disable_irq(uintptr_t); static void hrowpic_toggle_irq(struct hrowpic_softc *sc, int, int); /* * Interrupt controller softc. There should only be one. */ static struct hrowpic_softc *hpicsoftc; /* * Driver methods. */ static device_method_t hrowpic_methods[] = { /* Device interface */ DEVMETHOD(device_identify, hrowpic_identify), DEVMETHOD(device_probe, hrowpic_probe), DEVMETHOD(device_attach, hrowpic_attach), /* PIC interface */ DEVMETHOD(pic_allocate_intr, hrowpic_allocate_intr), DEVMETHOD(pic_setup_intr, hrowpic_setup_intr), DEVMETHOD(pic_teardown_intr, hrowpic_teardown_intr), DEVMETHOD(pic_release_intr, hrowpic_release_intr), { 0, 0 } }; static driver_t hrowpic_driver = { "hrowpic", hrowpic_methods, sizeof(struct hrowpic_softc) }; static devclass_t hrowpic_devclass; DRIVER_MODULE(hrowpic, nexus, hrowpic_driver, hrowpic_devclass, 0, 0); static void hrowpic_identify(driver_t *driver, device_t parent) { phandle_t chosen, pic; char type[40]; chosen = OF_finddevice("/chosen"); if (chosen == -1) return; if (OF_getprop(chosen, "interrupt-controller", &pic, 4) != 4) return; OF_getprop(pic, "compatible", type, sizeof(type)); if (strcmp(type, "heathrow")) return; BUS_ADD_CHILD(parent, 0, "hrowpic", 0); } static int hrowpic_probe(device_t dev) { char *name; name = nexus_get_name(dev); if (strcmp(name, "hrowpic")) return (ENXIO); device_set_desc(dev, "Heathrow interrupt controller"); return (0); } static int hrowpic_attach(device_t dev) { struct hrowpic_softc *sc; sc = device_get_softc(dev); sc->sc_rman.rm_type = RMAN_ARRAY; sc->sc_rman.rm_descr = device_get_nameunit(dev); if (rman_init(&sc->sc_rman) != 0 || rman_manage_region(&sc->sc_rman, 0, HROWPIC_IRQMAX-1) != 0) { device_printf(dev, "could not set up resource management"); return (ENXIO); } nexus_install_intcntlr(dev); intr_init(hrowpic_intr, HROWPIC_IRQMAX, hrowpic_ext_enable_irq, hrowpic_ext_disable_irq); KASSERT(hpicsoftc == NULL, ("hrowpic: h/w already probed")); hpicsoftc = sc; return (0); } /* * PIC interface */ static struct resource * hrowpic_allocate_intr(device_t picdev, device_t child, int *rid, u_long intr, u_int flags) { struct hrowpic_softc *sc; struct resource *rv; int needactivate; sc = device_get_softc(picdev); needactivate = flags & RF_ACTIVE; flags &= ~RF_ACTIVE; rv = rman_reserve_resource(&sc->sc_rman, intr, intr, 1, flags, child); if (rv == NULL) { device_printf(picdev, "interrupt reservation failed for %s\n", device_get_nameunit(child)); return (NULL); } return (rv); } static int hrowpic_setup_intr(device_t picdev, device_t child, struct resource *res, int flags, driver_intr_t *intr, void *arg, void **cookiep) { struct hrowpic_softc *sc; + u_long start; int error; sc = device_get_softc(picdev); + start = rman_get_start(res); - if ((res->r_flags & RF_SHAREABLE) == 0) + if ((rman_get_flags(res) & RF_SHAREABLE) == 0) flags |= INTR_EXCL; /* * We depend here on rman_activate_resource() being idempotent. */ error = rman_activate_resource(res); if (error) return (error); - error = inthand_add(device_get_nameunit(child), res->r_start, intr, - arg, flags, cookiep); + error = inthand_add(device_get_nameunit(child), start, intr, arg, + flags, cookiep); if (!error) { /* * Record irq request, and enable if h/w has been probed */ - sc->sc_irq[res->r_start] = 1; + sc->sc_irq[start] = 1; if (sc->sc_memr) { - hrowpic_toggle_irq(sc, res->r_start, 1); + hrowpic_toggle_irq(sc, start, 1); } } return (error); } static int hrowpic_teardown_intr(device_t picdev, device_t child, struct resource *res, void *ih) { int error; error = rman_deactivate_resource(res); if (error) return (error); - error = inthand_remove(res->r_start, ih); + error = inthand_remove(rman_get_start(res), ih); return (error); } static int hrowpic_release_intr(device_t picdev, device_t child, int rid, struct resource *res) { int error; if (rman_get_flags(res) & RF_ACTIVE) { error = bus_deactivate_resource(child, SYS_RES_IRQ, rid, res); if (error) return (error); } return (rman_release_resource(res)); } /* * Interrupt interface */ static void hrowpic_write_reg(struct hrowpic_softc *sc, u_int reg, u_int bank, u_int32_t val) { if (bank == HPIC_PRIMARY) reg += HPIC_1ST_OFFSET; bus_space_write_4(sc->sc_bt, sc->sc_bh, reg, val); /* * XXX Issue a read to force the write to complete */ bus_space_read_4(sc->sc_bt, sc->sc_bh, reg); } static u_int32_t hrowpic_read_reg(struct hrowpic_softc *sc, u_int reg, u_int bank) { if (bank == HPIC_PRIMARY) reg += HPIC_1ST_OFFSET; return (bus_space_read_4(sc->sc_bt, sc->sc_bh, reg)); } static void hrowpic_clear_all(struct hrowpic_softc *sc) { /* * Disable all interrupt sources and clear outstanding interrupts */ hrowpic_write_reg(sc, HPIC_ENABLE, HPIC_PRIMARY, 0); hrowpic_write_reg(sc, HPIC_CLEAR, HPIC_PRIMARY, 0xffffffff); hrowpic_write_reg(sc, HPIC_ENABLE, HPIC_SECONDARY, 0); hrowpic_write_reg(sc, HPIC_CLEAR, HPIC_SECONDARY, 0xffffffff); } static void hrowpic_toggle_irq(struct hrowpic_softc *sc, int irq, int enable) { u_int roffset; u_int rbit; KASSERT((irq > 0) && (irq < HROWPIC_IRQMAX), ("en irq out of range")); /* * Calculate prim/sec register bank for the IRQ, update soft copy, * and enable the IRQ as an interrupt source */ roffset = HPIC_INT_TO_BANK(irq); rbit = HPIC_INT_TO_REGBIT(irq); if (enable) sc->sc_softreg[roffset] |= (1 << rbit); else sc->sc_softreg[roffset] &= ~(1 << rbit); hrowpic_write_reg(sc, HPIC_ENABLE, roffset, sc->sc_softreg[roffset]); } static void hrowpic_intr(void) { int irq_lo, irq_hi; int i; struct hrowpic_softc *sc; sc = hpicsoftc; /* * Loop through both interrupt sources until they are empty. * XXX simplistic code, far from optimal. */ do { irq_lo = hrowpic_read_reg(sc, HPIC_STATUS, HPIC_PRIMARY); if (irq_lo) { hrowpic_write_reg(sc, HPIC_CLEAR, HPIC_PRIMARY, irq_lo); for (i = 0; i < HROWPIC_IRQ_REGNUM; i++) { if (irq_lo & (1 << i)) { /* * Disable IRQ and call handler */ hrowpic_toggle_irq(sc, i, 0); intr_handle(i); } } } irq_hi = hrowpic_read_reg(sc, HPIC_STATUS, HPIC_SECONDARY); if (irq_hi) { hrowpic_write_reg(sc, HPIC_CLEAR, HPIC_SECONDARY, irq_hi); for (i = 0; i < HROWPIC_IRQ_REGNUM; i++) { if (irq_hi & (1 << i)) { /* * Disable IRQ and call handler */ hrowpic_toggle_irq(sc, i + HROWPIC_IRQ_REGNUM, 0); intr_handle(i + HROWPIC_IRQ_REGNUM); } } } } while (irq_lo && irq_hi); } static void hrowpic_ext_enable_irq(uintptr_t irq) { hrowpic_toggle_irq(hpicsoftc, irq, 1); } static void hrowpic_ext_disable_irq(uintptr_t irq) { hrowpic_toggle_irq(hpicsoftc, irq, 0); } /* * MacIO interface */ static device_method_t hrowpic_macio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, hrowpic_macio_probe), DEVMETHOD(device_attach, hrowpic_macio_attach), { 0, 0 }, }; static driver_t hrowpic_macio_driver = { "hrowpicmacio", hrowpic_macio_methods, 0 }; static devclass_t hrowpic_macio_devclass; DRIVER_MODULE(hrowpicmacio, macio, hrowpic_macio_driver, hrowpic_macio_devclass, 0, 0); static int hrowpic_macio_probe(device_t dev) { char *type = macio_get_devtype(dev); /* * OpenPIC cells have a type of "open-pic", so this * is sufficient to identify a Heathrow cell */ if (strcmp(type, "interrupt-controller") != 0) return (ENXIO); /* * The description was already printed out in the nexus * probe, so don't do it again here */ device_set_desc(dev, "Heathrow MacIO interrupt cell"); device_quiet(dev); return (0); } static int hrowpic_macio_attach(device_t dev) { struct hrowpic_softc *sc = hpicsoftc; int rid; int i; KASSERT(sc != NULL, ("pic not nexus-probed\n")); sc->sc_maciodev = dev; rid = 0; sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_memr == NULL) { device_printf(dev, "Could not alloc mem resource!\n"); return (ENXIO); } sc->sc_bt = rman_get_bustag(sc->sc_memr); sc->sc_bh = rman_get_bushandle(sc->sc_memr); hrowpic_clear_all(sc); /* * Enable all IRQs that were requested before the h/w * was probed */ for (i = 0; i < HROWPIC_IRQMAX; i++) if (sc->sc_irq[i]) { hrowpic_toggle_irq(sc, i, 1); } return (0); } Index: head/sys/powerpc/powermac/macio.c =================================================================== --- head/sys/powerpc/powermac/macio.c (revision 133520) +++ head/sys/powerpc/powermac/macio.c (revision 133521) @@ -1,575 +1,574 @@ /* * Copyright 2002 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * * $FreeBSD$ */ /* * Driver for KeyLargo/Pangea, the MacPPC south bridge ASIC. */ -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * Macio softc */ struct macio_softc { phandle_t sc_node; vm_offset_t sc_base; vm_offset_t sc_size; struct rman sc_mem_rman; }; static MALLOC_DEFINE(M_MACIO, "macio", "macio device information"); static int macio_probe(device_t); static int macio_attach(device_t); static int macio_print_child(device_t dev, device_t child); static void macio_probe_nomatch(device_t, device_t); static int macio_read_ivar(device_t, device_t, int, uintptr_t *); static int macio_write_ivar(device_t, device_t, int, uintptr_t); static struct resource *macio_alloc_resource(device_t, device_t, int, int *, u_long, u_long, u_long, u_int); static int macio_activate_resource(device_t, device_t, int, int, struct resource *); static int macio_deactivate_resource(device_t, device_t, int, int, struct resource *); static int macio_release_resource(device_t, device_t, int, int, struct resource *); static struct resource_list *macio_get_resource_list (device_t, device_t); /* * Bus interface definition */ static device_method_t macio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, macio_probe), DEVMETHOD(device_attach, macio_attach), DEVMETHOD(device_detach, bus_generic_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), /* Bus interface */ DEVMETHOD(bus_print_child, macio_print_child), DEVMETHOD(bus_probe_nomatch, macio_probe_nomatch), DEVMETHOD(bus_read_ivar, macio_read_ivar), DEVMETHOD(bus_write_ivar, macio_write_ivar), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), DEVMETHOD(bus_alloc_resource, macio_alloc_resource), DEVMETHOD(bus_release_resource, macio_release_resource), DEVMETHOD(bus_activate_resource, macio_activate_resource), DEVMETHOD(bus_deactivate_resource, macio_deactivate_resource), DEVMETHOD(bus_get_resource_list, macio_get_resource_list), { 0, 0 } }; static driver_t macio_pci_driver = { "macio", macio_methods, sizeof(struct macio_softc) }; devclass_t macio_devclass; DRIVER_MODULE(macio, pci, macio_pci_driver, macio_devclass, 0, 0); /* * PCI ID search table */ static struct macio_pci_dev { u_int32_t mpd_devid; char *mpd_desc; } macio_pci_devlist[] = { { 0x0017106b, "Paddington I/O Controller" }, { 0x0022106b, "KeyLargo I/O Controller" }, { 0x0025106b, "Pangea I/O Controller" }, { 0x003e106b, "Intrepid I/O Controller" }, { 0, NULL } }; /* * Devices to exclude from the probe * XXX some of these may be required in the future... */ #define MACIO_QUIRK_IGNORE 0x00000001 #define MACIO_QUIRK_CHILD_HAS_INTR 0x00000002 struct macio_quirk_entry { const char *mq_name; int mq_quirks; }; static struct macio_quirk_entry macio_quirks[] = { { "escc-legacy", MACIO_QUIRK_IGNORE }, { "timer", MACIO_QUIRK_IGNORE }, { "escc", MACIO_QUIRK_CHILD_HAS_INTR }, { NULL, 0 } }; static int macio_get_quirks(const char *name) { struct macio_quirk_entry *mqe; for (mqe = macio_quirks; mqe->mq_name != NULL; mqe++) if (strcmp(name, mqe->mq_name) == 0) return (mqe->mq_quirks); return (0); } /* * Add an interrupt to the dev's resource list if present */ static void macio_add_intr(phandle_t devnode, struct macio_devinfo *dinfo) { int intr; if (dinfo->mdi_ninterrupts >= 5) { printf("macio: device has more than 5 interrupts\n"); return; } if (OF_getprop(devnode, "interrupts", &intr, sizeof(intr)) == -1) { if (OF_getprop(devnode, "AAPL,interrupts", &intr, sizeof(intr)) == -1) return; } if (intr == -1) return; resource_list_add(&dinfo->mdi_resources, SYS_RES_IRQ, dinfo->mdi_ninterrupts, intr, intr, 1); dinfo->mdi_interrupts[dinfo->mdi_ninterrupts] = intr; dinfo->mdi_ninterrupts++; } static void macio_add_reg(phandle_t devnode, struct macio_devinfo *dinfo) { struct macio_reg *reg; int i, nreg; nreg = OF_getprop_alloc(devnode, "reg", sizeof(*reg), (void **)®); if (nreg == -1) return; dinfo->mdi_nregs = nreg; dinfo->mdi_regs = reg; for (i = 0; i < nreg; i++) { resource_list_add(&dinfo->mdi_resources, SYS_RES_MEMORY, i, reg[i].mr_base, reg[i].mr_base + reg[i].mr_size, reg[i].mr_size); } } /* * PCI probe */ static int macio_probe(device_t dev) { int i; u_int32_t devid; devid = pci_get_devid(dev); for (i = 0; macio_pci_devlist[i].mpd_desc != NULL; i++) { if (devid == macio_pci_devlist[i].mpd_devid) { device_set_desc(dev, macio_pci_devlist[i].mpd_desc); return (0); } } return (ENXIO); } /* * PCI attach: scan OpenFirmware child nodes, and attach these as children * of the macio bus */ static int macio_attach(device_t dev) { struct macio_softc *sc; struct macio_devinfo *dinfo; phandle_t root; phandle_t child; phandle_t subchild; device_t cdev; u_int reg[3]; char *name, *type; int quirks; sc = device_get_softc(dev); root = sc->sc_node = OF_finddevice("mac-io"); /* * Locate the device node and it's base address */ if (OF_getprop(root, "assigned-addresses", reg, sizeof(reg)) < sizeof(reg)) { return (ENXIO); } sc->sc_base = reg[2]; sc->sc_size = MACIO_REG_SIZE; sc->sc_mem_rman.rm_type = RMAN_ARRAY; sc->sc_mem_rman.rm_descr = "MacIO Device Memory"; if (rman_init(&sc->sc_mem_rman) != 0) { device_printf(dev, "failed to init mem range resources\n"); return (ENXIO); } rman_manage_region(&sc->sc_mem_rman, 0, sc->sc_size); /* * Iterate through the sub-devices */ for (child = OF_child(root); child != 0; child = OF_peer(child)) { OF_getprop_alloc(child, "name", 1, (void **)&name); OF_getprop_alloc(child, "device_type", 1, (void **)&type); quirks = macio_get_quirks(name); if ((quirks & MACIO_QUIRK_IGNORE) != 0) { free(name, M_OFWPROP); free(type, M_OFWPROP); continue; } cdev = device_add_child(dev, NULL, -1); if (cdev != NULL) { dinfo = malloc(sizeof(*dinfo), M_MACIO, M_WAITOK); memset(dinfo, 0, sizeof(*dinfo)); resource_list_init(&dinfo->mdi_resources); dinfo->mdi_node = child; dinfo->mdi_name = name; dinfo->mdi_device_type = type; dinfo->mdi_ninterrupts = 0; macio_add_intr(child, dinfo); macio_add_reg(child, dinfo); if ((quirks & MACIO_QUIRK_CHILD_HAS_INTR) != 0) { for (subchild = OF_child(child); subchild != 0; subchild = OF_peer(subchild)) { macio_add_intr(subchild, dinfo); } } device_set_ivars(cdev, dinfo); } else { free(name, M_OFWPROP); free(type, M_OFWPROP); } } return (bus_generic_attach(dev)); } static int macio_print_child(device_t dev, device_t child) { struct macio_devinfo *dinfo; struct resource_list *rl; int retval = 0; dinfo = device_get_ivars(child); rl = &dinfo->mdi_resources; retval += bus_print_child_header(dev, child); retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx"); retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld"); retval += bus_print_child_footer(dev, child); return (retval); } static void macio_probe_nomatch(device_t dev, device_t child) { struct macio_devinfo *dinfo; struct resource_list *rl; if (bootverbose) { dinfo = device_get_ivars(child); rl = &dinfo->mdi_resources; device_printf(dev, "<%s, %s>", macio_get_devtype(child), macio_get_name(child)); resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx"); resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld"); printf(" (no driver attached)\n"); } } static int macio_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct macio_devinfo *dinfo; if ((dinfo = device_get_ivars(child)) == 0) return (ENOENT); switch (which) { case MACIO_IVAR_NODE: *result = dinfo->mdi_node; break; case MACIO_IVAR_NAME: *result = (uintptr_t)dinfo->mdi_name; break; case MACIO_IVAR_DEVTYPE: *result = (uintptr_t)dinfo->mdi_device_type; break; case MACIO_IVAR_NREGS: *result = dinfo->mdi_nregs; break; case MACIO_IVAR_REGS: *result = (uintptr_t)dinfo->mdi_regs; break; default: return (ENOENT); } return (0); } static int macio_write_ivar(device_t dev, device_t child, int which, uintptr_t value) { return (EINVAL); } static struct resource * macio_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct macio_softc *sc; int needactivate; struct resource *rv; struct rman *rm; bus_space_tag_t tagval; u_long adjstart, adjend, adjcount; struct macio_devinfo *dinfo; struct resource_list_entry *rle; sc = device_get_softc(bus); dinfo = device_get_ivars(child); needactivate = flags & RF_ACTIVE; flags &= ~RF_ACTIVE; switch (type) { case SYS_RES_MEMORY: case SYS_RES_IOPORT: rle = resource_list_find(&dinfo->mdi_resources, SYS_RES_MEMORY, *rid); if (rle == NULL) { device_printf(bus, "no rle for %s memory %d\n", device_get_nameunit(child), *rid); return (NULL); } if (start < rle->start) adjstart = rle->start; else if (start > rle->end) adjstart = rle->end; else adjstart = start; if (end < rle->start) adjend = rle->start; else if (end > rle->end) adjend = rle->end; else adjend = end; adjcount = adjend - adjstart; rm = &sc->sc_mem_rman; tagval = PPC_BUS_SPACE_MEM; break; case SYS_RES_IRQ: rle = resource_list_find(&dinfo->mdi_resources, SYS_RES_IRQ, *rid); if (rle == NULL) { if (dinfo->mdi_ninterrupts >= 5) { device_printf(bus, "%s has more than 5 interrupts\n", device_get_nameunit(child)); return (NULL); } resource_list_add(&dinfo->mdi_resources, SYS_RES_IRQ, dinfo->mdi_ninterrupts, start, start, 1); dinfo->mdi_interrupts[dinfo->mdi_ninterrupts] = start; dinfo->mdi_ninterrupts++; } return (resource_list_alloc(&dinfo->mdi_resources, bus, child, type, rid, start, end, count, flags)); break; default: device_printf(bus, "unknown resource request from %s\n", device_get_nameunit(child)); return (NULL); } rv = rman_reserve_resource(rm, adjstart, adjend, adjcount, flags, child); if (rv == NULL) { device_printf(bus, "failed to reserve resource %#lx - %#lx (%#lx) for %s\n", adjstart, adjend, adjcount, device_get_nameunit(child)); return (NULL); } rman_set_bustag(rv, tagval); rman_set_bushandle(rv, rman_get_start(rv)); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv) != 0) { device_printf(bus, "failed to activate resource for %s\n", device_get_nameunit(child)); rman_release_resource(rv); return (NULL); } } return (rv); } static int macio_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { if (rman_get_flags(res) & RF_ACTIVE) { int error = bus_deactivate_resource(child, type, rid, res); if (error) return error; } return (rman_release_resource(res)); } static int macio_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { struct macio_softc *sc; void *p; sc = device_get_softc(bus); if (type == SYS_RES_IRQ) return (bus_activate_resource(bus, type, rid, res)); if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { p = pmap_mapdev((vm_offset_t)rman_get_start(res) + sc->sc_base, (vm_size_t)rman_get_size(res)); if (p == NULL) return (ENOMEM); rman_set_virtual(res, p); rman_set_bushandle(res, (u_long)p); } return (rman_activate_resource(res)); } static int macio_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { /* * If this is a memory resource, unmap it. */ if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { u_int32_t psize; psize = rman_get_size(res); pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize); } return (rman_deactivate_resource(res)); } static struct resource_list * macio_get_resource_list (device_t dev, device_t child) { struct macio_devinfo *dinfo = device_get_ivars(child); struct resource_list *rl = &dinfo->mdi_resources; if (!rl) return (NULL); return (rl); } Index: head/sys/powerpc/powermac/openpic_macio.c =================================================================== --- head/sys/powerpc/powermac/openpic_macio.c (revision 133520) +++ head/sys/powerpc/powermac/openpic_macio.c (revision 133521) @@ -1,230 +1,229 @@ /* * Copyright 2003 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * */ /* * The macio attachment for the OpenPIC interrupt controller. * A nexus driver is defined so the number of interrupts can be * determined early in the boot sequence before the hardware * is accessed - the interrupt i/f is installed at this time, * and when h/w is finally accessed, interrupt sources allocated * prior to this are activated */ #include __FBSDID("$FreeBSD$"); -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pic_if.h" struct openpic_ofw_softc { struct openpic_softc osc; struct resource *sc_memr; /* macio bus resource */ device_t sc_ndev; /* nexus device */ }; static struct openpic_ofw_softc *ofwpicsoftc; /* * MacIO interface */ static void openpic_ofw_identify(driver_t *, device_t); static int openpic_ofw_probe(device_t); static int openpic_ofw_attach(device_t); static int openpic_macio_probe(device_t); static int openpic_macio_attach(device_t); /* * Nexus attachment */ static device_method_t openpic_ofw_methods[] = { /* Device interface */ DEVMETHOD(device_identify, openpic_ofw_identify), DEVMETHOD(device_probe, openpic_ofw_probe), DEVMETHOD(device_attach, openpic_ofw_attach), /* PIC interface */ DEVMETHOD(pic_allocate_intr, openpic_allocate_intr), DEVMETHOD(pic_setup_intr, openpic_setup_intr), DEVMETHOD(pic_teardown_intr, openpic_teardown_intr), DEVMETHOD(pic_release_intr, openpic_release_intr), { 0, 0 } }; static driver_t openpic_ofw_driver = { "openpic", openpic_ofw_methods, sizeof(struct openpic_ofw_softc) }; static devclass_t openpic_ofw_devclass; DRIVER_MODULE(openpic_ofw, nexus, openpic_ofw_driver, openpic_ofw_devclass, 0, 0); static void openpic_ofw_identify(driver_t *driver, device_t parent) { device_t child; phandle_t pic; char type[40]; pic = OF_finddevice("mpic"); if (pic == -1) return; OF_getprop(pic, "device_type", type, sizeof(type)); if (strcmp(type, "open-pic") != 0) return; child = BUS_ADD_CHILD(parent, 0, "openpic", 0); if (child != NULL) nexus_set_device_type(child, "macio"); } static int openpic_ofw_probe(device_t dev) { char *name; char *type; name = nexus_get_name(dev); type = nexus_get_device_type(dev); if (strcmp(name, "openpic") != 0 || strcmp(type, "macio") != 0) return (ENXIO); device_set_desc(dev, OPENPIC_DEVSTR); return (0); } static int openpic_ofw_attach(device_t dev) { KASSERT(ofwpicsoftc == NULL, ("ofw openpic: already probed")); ofwpicsoftc = device_get_softc(dev); ofwpicsoftc->sc_ndev = dev; nexus_install_intcntlr(dev); openpic_early_attach(dev); return (0); } /* * MacIO attachment */ static device_method_t openpic_macio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, openpic_macio_probe), DEVMETHOD(device_attach, openpic_macio_attach), { 0, 0 }, }; static driver_t openpic_macio_driver = { "openpicmacio", openpic_macio_methods, 0 }; static devclass_t openpic_macio_devclass; DRIVER_MODULE(openpicmacio, macio, openpic_macio_driver, openpic_macio_devclass, 0, 0); static int openpic_macio_probe(device_t dev) { char *type = macio_get_devtype(dev); if (strcmp(type, "open-pic") != 0) return (ENXIO); /* * The description was already printed out in the nexus * probe, so don't do it again here */ device_set_desc(dev, "OpenPIC MacIO interrupt cell"); if (!bootverbose) device_quiet(dev); return (0); } static int openpic_macio_attach(device_t dev) { struct openpic_ofw_softc *sc; int rid; sc = ofwpicsoftc; KASSERT(sc != NULL, ("pic not nexus-probed\n")); rid = 0; sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_memr == NULL) { device_printf(dev, "Could not alloc mem resource!\n"); return (ENXIO); } sc->osc.sc_bt = rman_get_bustag(sc->sc_memr); sc->osc.sc_bh = rman_get_bushandle(sc->sc_memr); sc->osc.sc_altdev = dev; return (openpic_attach(sc->sc_ndev)); } Index: head/sys/powerpc/powermac/uninorth.c =================================================================== --- head/sys/powerpc/powermac/uninorth.c (revision 133520) +++ head/sys/powerpc/powermac/uninorth.c (revision 133521) @@ -1,571 +1,570 @@ /* * Copyright (C) 2002 Benno Rice. * All rights reserved. * * 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 Benno Rice ``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 TOOLS GMBH 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. * * $FreeBSD$ */ -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pcib_if.h" #define UNINORTH_DEBUG 0 /* * Device interface. */ static int uninorth_probe(device_t); static int uninorth_attach(device_t); /* * Bus interface. */ static int uninorth_read_ivar(device_t, device_t, int, uintptr_t *); static struct resource * uninorth_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags); static int uninorth_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res); /* * pcib interface. */ static int uninorth_maxslots(device_t); static u_int32_t uninorth_read_config(device_t, u_int, u_int, u_int, u_int, int); static void uninorth_write_config(device_t, u_int, u_int, u_int, u_int, u_int32_t, int); static int uninorth_route_interrupt(device_t, device_t, int); /* * Local routines. */ static int uninorth_enable_config(struct uninorth_softc *, u_int, u_int, u_int, u_int); static void unin_enable_gmac(void); /* * Driver methods. */ static device_method_t uninorth_methods[] = { /* Device interface */ DEVMETHOD(device_probe, uninorth_probe), DEVMETHOD(device_attach, uninorth_attach), /* Bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), DEVMETHOD(bus_read_ivar, uninorth_read_ivar), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), DEVMETHOD(bus_alloc_resource, uninorth_alloc_resource), DEVMETHOD(bus_activate_resource, uninorth_activate_resource), /* pcib interface */ DEVMETHOD(pcib_maxslots, uninorth_maxslots), DEVMETHOD(pcib_read_config, uninorth_read_config), DEVMETHOD(pcib_write_config, uninorth_write_config), DEVMETHOD(pcib_route_interrupt, uninorth_route_interrupt), { 0, 0 } }; static driver_t uninorth_driver = { "pcib", uninorth_methods, sizeof(struct uninorth_softc) }; static devclass_t uninorth_devclass; DRIVER_MODULE(uninorth, nexus, uninorth_driver, uninorth_devclass, 0, 0); static int uninorth_probe(device_t dev) { char *type, *compatible; type = nexus_get_device_type(dev); compatible = nexus_get_compatible(dev); if (type == NULL || compatible == NULL) return (ENXIO); if (strcmp(type, "pci") != 0 || strcmp(compatible, "uni-north") != 0) return (ENXIO); device_set_desc(dev, "Apple UniNorth Host-PCI bridge"); return (0); } static int uninorth_attach(device_t dev) { struct uninorth_softc *sc; phandle_t node; phandle_t child; u_int32_t reg[2], busrange[2]; struct uninorth_range *rp, *io, *mem[2]; int nmem, i; node = nexus_get_node(dev); sc = device_get_softc(dev); if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8) return (ENXIO); if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8) return (ENXIO); sc->sc_dev = dev; sc->sc_node = node; sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE); sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE); sc->sc_bus = busrange[0]; bzero(sc->sc_range, sizeof(sc->sc_range)); sc->sc_nrange = OF_getprop(node, "ranges", sc->sc_range, sizeof(sc->sc_range)); if (sc->sc_nrange == -1) { device_printf(dev, "could not get ranges\n"); return (ENXIO); } sc->sc_range[6].pci_hi = 0; io = NULL; nmem = 0; for (rp = sc->sc_range; rp->pci_hi != 0; rp++) { switch (rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) { case OFW_PCI_PHYS_HI_SPACE_CONFIG: break; case OFW_PCI_PHYS_HI_SPACE_IO: io = rp; break; case OFW_PCI_PHYS_HI_SPACE_MEM32: mem[nmem] = rp; nmem++; break; case OFW_PCI_PHYS_HI_SPACE_MEM64: break; } } if (io == NULL) { device_printf(dev, "can't find io range\n"); return (ENXIO); } sc->sc_io_rman.rm_type = RMAN_ARRAY; sc->sc_io_rman.rm_descr = "UniNorth PCI I/O Ports"; if (rman_init(&sc->sc_io_rman) != 0 || rman_manage_region(&sc->sc_io_rman, io->pci_lo, io->pci_lo + io->size_lo) != 0) { device_printf(dev, "failed to set up io range management\n"); return (ENXIO); } if (nmem == 0) { device_printf(dev, "can't find mem ranges\n"); return (ENXIO); } sc->sc_mem_rman.rm_type = RMAN_ARRAY; sc->sc_mem_rman.rm_descr = "UniNorth PCI Memory"; if (rman_init(&sc->sc_mem_rman) != 0) { device_printf(dev, "failed to init mem range resources\n"); return (ENXIO); } for (i = 0; i < nmem; i++) { if (rman_manage_region(&sc->sc_mem_rman, mem[i]->pci_lo, mem[i]->pci_lo + mem[i]->size_lo) != 0) { device_printf(dev, "failed to set up memory range management\n"); return (ENXIO); } } /* * Enable the GMAC ethernet cell if OpenFirmware says it is * used */ for (child = OF_child(node); child; child = OF_peer(child)) { char compat[32]; memset(compat, 0, sizeof(compat)); OF_getprop(child, "compatible", compat, sizeof(compat)); if (strcmp(compat, "gmac") == 0) { unin_enable_gmac(); } } /* * Write out the correct PIC interrupt values to config space * of all devices on the bus. This has to be done after the GEM * cell is enabled above. */ ofw_pci_fixup(dev, sc->sc_bus, node); device_add_child(dev, "pci", device_get_unit(dev)); return (bus_generic_attach(dev)); } static int uninorth_maxslots(device_t dev) { return (PCI_SLOTMAX); } static u_int32_t uninorth_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int width) { struct uninorth_softc *sc; vm_offset_t caoff; sc = device_get_softc(dev); caoff = sc->sc_data + (reg & 0x07); if (uninorth_enable_config(sc, bus, slot, func, reg) != 0) { switch (width) { case 1: return (in8rb(caoff)); break; case 2: return (in16rb(caoff)); break; case 4: return (in32rb(caoff)); break; } } return (0xffffffff); } static void uninorth_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, u_int32_t val, int width) { struct uninorth_softc *sc; vm_offset_t caoff; sc = device_get_softc(dev); caoff = sc->sc_data + (reg & 0x07); if (uninorth_enable_config(sc, bus, slot, func, reg)) { switch (width) { case 1: out8rb(caoff, val); (void)in8rb(caoff); break; case 2: out16rb(caoff, val); (void)in16rb(caoff); break; case 4: out32rb(caoff, val); (void)in32rb(caoff); break; } } } static int uninorth_route_interrupt(device_t bus, device_t dev, int pin) { return (0); } static int uninorth_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct uninorth_softc *sc; sc = device_get_softc(dev); switch (which) { case PCIB_IVAR_BUS: *result = sc->sc_bus; return (0); break; } return (ENOENT); } static struct resource * uninorth_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct uninorth_softc *sc; struct resource *rv; struct rman *rm; bus_space_tag_t bt; int needactivate; needactivate = flags & RF_ACTIVE; flags &= ~RF_ACTIVE; sc = device_get_softc(bus); switch (type) { case SYS_RES_MEMORY: rm = &sc->sc_mem_rman; bt = PPC_BUS_SPACE_MEM; break; case SYS_RES_IRQ: return (bus_alloc_resource(bus, type, rid, start, end, count, flags)); break; default: device_printf(bus, "unknown resource request from %s\n", device_get_nameunit(child)); return (NULL); } rv = rman_reserve_resource(rm, start, end, count, flags, child); if (rv == NULL) { device_printf(bus, "failed to reserve resource for %s\n", device_get_nameunit(child)); return (NULL); } rman_set_bustag(rv, bt); rman_set_bushandle(rv, rman_get_start(rv)); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv) != 0) { device_printf(bus, "failed to activate resource for %s\n", device_get_nameunit(child)); rman_release_resource(rv); return (NULL); } } return (rv); } static int uninorth_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { void *p; if (type == SYS_RES_IRQ) return (bus_activate_resource(bus, type, rid, res)); if (type == SYS_RES_MEMORY) { p = pmap_mapdev((vm_offset_t)rman_get_start(res), (vm_size_t)rman_get_size(res)); if (p == NULL) return (ENOMEM); rman_set_virtual(res, p); rman_set_bushandle(res, (u_long)p); } return (rman_activate_resource(res)); } static int uninorth_enable_config(struct uninorth_softc *sc, u_int bus, u_int slot, u_int func, u_int reg) { u_int32_t cfgval; if (sc->sc_bus == bus) { /* * No slots less than 11 on the primary bus */ if (slot < 11) return (0); cfgval = (1 << slot) | (func << 8) | (reg & 0xfc); } else { cfgval = (bus << 16) | (slot << 11) | (func << 8) | (reg & 0xfc) | 1; } do { out32rb(sc->sc_addr, cfgval); } while (in32rb(sc->sc_addr) != cfgval); return (1); } /* * Driver to swallow UniNorth host bridges from the PCI bus side. */ static int unhb_probe(device_t dev) { if (pci_get_class(dev) == PCIC_BRIDGE && pci_get_subclass(dev) == PCIS_BRIDGE_HOST) { device_set_desc(dev, "Host to PCI bridge"); device_quiet(dev); return (-10000); } return (ENXIO); } static int unhb_attach(device_t dev) { return (0); } static device_method_t unhb_methods[] = { /* Device interface */ DEVMETHOD(device_probe, unhb_probe), DEVMETHOD(device_attach, unhb_attach), { 0, 0 } }; static driver_t unhb_driver = { "unhb", unhb_methods, 1, }; static devclass_t unhb_devclass; DRIVER_MODULE(unhb, pci, unhb_driver, unhb_devclass, 0, 0); /* * Small stub driver for the Uninorth chip itself, to allow setting * of various parameters and cell enables */ static struct unin_chip_softc *uncsc; static void unin_enable_gmac(void) { volatile u_int *clkreg; u_int32_t tmpl; if (uncsc == NULL) panic("unin_enable_gmac: device not found"); clkreg = (void *)(uncsc->sc_addr + UNIN_CLOCKCNTL); tmpl = inl(clkreg); tmpl |= UNIN_CLOCKCNTL_GMAC; outl(clkreg, tmpl); } static int unin_chip_probe(device_t dev) { char *name; name = nexus_get_name(dev); if (name == NULL) return (ENXIO); if (strcmp(name, "uni-n") != 0) return (ENXIO); device_set_desc(dev, "Apple UniNorth System Controller"); return (0); } static int unin_chip_attach(device_t dev) { phandle_t node; u_int reg[2]; uncsc = device_get_softc(dev); node = nexus_get_node(dev); if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8) return (ENXIO); uncsc->sc_physaddr = reg[0]; uncsc->sc_size = reg[1]; /* * Only map the first page, since that is where the registers * of interest lie. */ uncsc->sc_addr = (vm_offset_t) pmap_mapdev(reg[0], PAGE_SIZE); uncsc->sc_version = *(u_int *)uncsc->sc_addr; device_printf(dev, "Version %d\n", uncsc->sc_version); return (0); } static device_method_t unin_chip_methods[] = { /* Device interface */ DEVMETHOD(device_probe, unin_chip_probe), DEVMETHOD(device_attach, unin_chip_attach), { 0, 0 } }; static driver_t unin_chip_driver = { "unin", unin_chip_methods, sizeof(struct unin_chip_softc) }; static devclass_t unin_chip_devclass; DRIVER_MODULE(unin, nexus, unin_chip_driver, unin_chip_devclass, 0, 0); Index: head/sys/powerpc/powerpc/openpic.c =================================================================== --- head/sys/powerpc/powerpc/openpic.c (revision 133520) +++ head/sys/powerpc/powerpc/openpic.c (revision 133521) @@ -1,406 +1,407 @@ /* * Copyright (C) 2002 Benno Rice. * All rights reserved. * * 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 Benno Rice ``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 TOOLS GMBH 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. * * $FreeBSD$ */ -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pic_if.h" /* * Local routines */ static u_int openpic_read(struct openpic_softc *, int); static void openpic_write(struct openpic_softc *, int, u_int); static int openpic_read_irq(struct openpic_softc *, int); static void openpic_eoi(struct openpic_softc *, int); static void openpic_enable_irq(struct openpic_softc *, int, int); static void openpic_disable_irq(struct openpic_softc *, int); static void openpic_set_priority(struct openpic_softc *, int, int); static void openpic_intr(void); static void openpic_ext_enable_irq(uintptr_t); static void openpic_ext_disable_irq(uintptr_t); /* XXX This limits us to one openpic */ static struct openpic_softc *openpic_softc; /* * Called at nexus-probe time to allow interrupts to be enabled by * devices that are probed before the OpenPIC h/w is probed. */ int openpic_early_attach(device_t dev) { struct openpic_softc *sc; sc = device_get_softc(dev); openpic_softc = sc; sc->sc_rman.rm_type = RMAN_ARRAY; sc->sc_rman.rm_descr = device_get_nameunit(dev); if (rman_init(&sc->sc_rman) != 0 || rman_manage_region(&sc->sc_rman, 0, OPENPIC_IRQMAX-1) != 0) { device_printf(dev, "could not set up resource management"); return (ENXIO); } intr_init(openpic_intr, OPENPIC_IRQMAX, openpic_ext_enable_irq, openpic_ext_disable_irq); sc->sc_early_done = 1; return (0); } int openpic_attach(device_t dev) { struct openpic_softc *sc; u_int irq; u_int32_t x; sc = device_get_softc(dev); sc->sc_hwprobed = 1; if (!sc->sc_early_done) openpic_early_attach(dev); x = openpic_read(sc, OPENPIC_FEATURE); switch (x & OPENPIC_FEATURE_VERSION_MASK) { case 1: sc->sc_version = "1.0"; break; case 2: sc->sc_version = "1.2"; break; case 3: sc->sc_version = "1.3"; break; default: sc->sc_version = "unknown"; break; } sc->sc_ncpu = ((x & OPENPIC_FEATURE_LAST_CPU_MASK) >> OPENPIC_FEATURE_LAST_CPU_SHIFT) + 1; sc->sc_nirq = ((x & OPENPIC_FEATURE_LAST_IRQ_MASK) >> OPENPIC_FEATURE_LAST_IRQ_SHIFT) + 1; /* * PSIM seems to report 1 too many IRQs */ if (sc->sc_psim) sc->sc_nirq--; if (bootverbose) device_printf(dev, "Version %s, supports %d CPUs and %d irqs\n", sc->sc_version, sc->sc_ncpu, sc->sc_nirq); /* disable all interrupts */ for (irq = 0; irq < sc->sc_nirq; irq++) openpic_write(sc, OPENPIC_SRC_VECTOR(irq), OPENPIC_IMASK); openpic_set_priority(sc, 0, 15); /* we don't need 8259 passthrough mode */ x = openpic_read(sc, OPENPIC_CONFIG); x |= OPENPIC_CONFIG_8259_PASSTHRU_DISABLE; openpic_write(sc, OPENPIC_CONFIG, x); /* send all interrupts to cpu 0 */ for (irq = 0; irq < sc->sc_nirq; irq++) openpic_write(sc, OPENPIC_IDEST(irq), 1 << 0); for (irq = 0; irq < sc->sc_nirq; irq++) { x = irq; x |= OPENPIC_IMASK; x |= OPENPIC_POLARITY_POSITIVE; x |= OPENPIC_SENSE_LEVEL; x |= 8 << OPENPIC_PRIORITY_SHIFT; openpic_write(sc, OPENPIC_SRC_VECTOR(irq), x); } /* XXX IPI */ /* XXX set spurious intr vector */ openpic_set_priority(sc, 0, 0); /* clear all pending interrupts */ for (irq = 0; irq < sc->sc_nirq; irq++) { openpic_read_irq(sc, 0); openpic_eoi(sc, 0); } /* enable pre-h/w reserved irqs, disable all others */ for (irq = 0; irq < sc->sc_nirq; irq++) if (sc->sc_irqrsv[irq]) openpic_enable_irq(sc, irq, IST_LEVEL); else openpic_disable_irq(sc, irq); return (0); } /* * PIC interface */ struct resource * openpic_allocate_intr(device_t dev, device_t child, int *rid, u_long intr, u_int flags) { struct openpic_softc *sc; struct resource *rv; int needactivate; sc = device_get_softc(dev); needactivate = flags & RF_ACTIVE; flags &= ~RF_ACTIVE; if (sc->sc_hwprobed && (intr > sc->sc_nirq)) { device_printf(dev, "interrupt reservation %ld out of range\n", intr); return (NULL); } rv = rman_reserve_resource(&sc->sc_rman, intr, intr, 1, flags, child); if (rv == NULL) { device_printf(dev, "interrupt reservation failed for %s\n", device_get_nameunit(child)); return (NULL); } if (needactivate) { if (bus_activate_resource(child, SYS_RES_IRQ, *rid, rv) != 0) { device_printf(dev, "resource activation failed for %s\n", device_get_nameunit(child)); rman_release_resource(rv); return (NULL); } } return (rv); } int openpic_setup_intr(device_t dev, device_t child, struct resource *res, int flags, driver_intr_t *intr, void *arg, void **cookiep) { struct openpic_softc *sc; + u_long start; int error; sc = device_get_softc(dev); + start = rman_get_start(res); if (res == NULL) { device_printf(dev, "null interrupt resource from %s\n", device_get_nameunit(child)); return (EINVAL); } - if ((res->r_flags & RF_SHAREABLE) == 0) + if ((rman_get_flags(res) & RF_SHAREABLE) == 0) flags |= INTR_EXCL; /* * We depend here on rman_activate_resource() being idempotent. */ error = rman_activate_resource(res); if (error) return (error); - error = inthand_add(device_get_nameunit(child), res->r_start, intr, - arg, flags, cookiep); + error = inthand_add(device_get_nameunit(child), start, intr, arg, + flags, cookiep); if (sc->sc_hwprobed) - openpic_enable_irq(sc, res->r_start, IST_LEVEL); + openpic_enable_irq(sc, start, IST_LEVEL); else - sc->sc_irqrsv[res->r_start] = 1; + sc->sc_irqrsv[start] = 1; return (error); } int openpic_teardown_intr(device_t dev, device_t child, struct resource *res, void *ih) { int error; error = rman_deactivate_resource(res); if (error) return (error); - error = inthand_remove(res->r_start, ih); + error = inthand_remove(rman_get_start(res), ih); return (error); } int openpic_release_intr(device_t dev, device_t child, int rid, struct resource *res) { int error; if (rman_get_flags(res) & RF_ACTIVE) { error = bus_deactivate_resource(child, SYS_RES_IRQ, rid, res); if (error) return (error); } return (rman_release_resource(res)); } /* * Local routines */ static u_int openpic_read(struct openpic_softc *sc, int reg) { return (bus_space_read_4(sc->sc_bt, sc->sc_bh, reg)); } static void openpic_write(struct openpic_softc *sc, int reg, u_int val) { bus_space_write_4(sc->sc_bt, sc->sc_bh, reg, val); } static int openpic_read_irq(struct openpic_softc *sc, int cpu) { return openpic_read(sc, OPENPIC_IACK(cpu)) & OPENPIC_VECTOR_MASK; } static void openpic_eoi(struct openpic_softc *sc, int cpu) { openpic_write(sc, OPENPIC_EOI(cpu), 0); } static void openpic_enable_irq(struct openpic_softc *sc, int irq, int type) { u_int x; x = openpic_read(sc, OPENPIC_SRC_VECTOR(irq)); x &= ~(OPENPIC_IMASK | OPENPIC_SENSE_LEVEL | OPENPIC_SENSE_EDGE); if (type == IST_LEVEL) x |= OPENPIC_SENSE_LEVEL; else x |= OPENPIC_SENSE_EDGE; openpic_write(sc, OPENPIC_SRC_VECTOR(irq), x); } static void openpic_disable_irq(struct openpic_softc *sc, int irq) { u_int x; x = openpic_read(sc, OPENPIC_SRC_VECTOR(irq)); x |= OPENPIC_IMASK; openpic_write(sc, OPENPIC_SRC_VECTOR(irq), x); } static void openpic_set_priority(struct openpic_softc *sc, int cpu, int pri) { u_int x; x = openpic_read(sc, OPENPIC_CPU_PRIORITY(cpu)); x &= ~OPENPIC_CPU_PRIORITY_MASK; x |= pri; openpic_write(sc, OPENPIC_CPU_PRIORITY(cpu), x); } static void openpic_intr(void) { struct openpic_softc *sc; int irq; u_int32_t msr; sc = openpic_softc; msr = mfmsr(); irq = openpic_read_irq(sc, 0); if (irq == 255) { return; } start: openpic_disable_irq(sc, irq); /*mtmsr(msr | PSL_EE);*/ /* do the interrupt thang */ intr_handle(irq); mtmsr(msr); openpic_eoi(sc, 0); irq = openpic_read_irq(sc, 0); if (irq != 255) goto start; } static void openpic_ext_enable_irq(uintptr_t irq) { if (!openpic_softc->sc_hwprobed) return; openpic_enable_irq(openpic_softc, irq, IST_LEVEL); } static void openpic_ext_disable_irq(uintptr_t irq) { if (!openpic_softc->sc_hwprobed) return; openpic_disable_irq(openpic_softc, irq); } Index: head/sys/powerpc/psim/iobus.c =================================================================== --- head/sys/powerpc/psim/iobus.c (revision 133520) +++ head/sys/powerpc/psim/iobus.c (revision 133521) @@ -1,416 +1,415 @@ /* * Copyright 2002 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * * $FreeBSD$ */ /* * PSIM 'iobus' local bus. Should be set up in the device tree like: * * /iobus@0x80000000/name psim-iobus * * Code borrowed from various nexus.c and uninorth.c :-) */ -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct iobus_softc { phandle_t sc_node; vm_offset_t sc_addr; vm_offset_t sc_size; struct rman sc_mem_rman; }; static MALLOC_DEFINE(M_IOBUS, "iobus", "iobus device information"); static int iobus_probe(device_t); static int iobus_attach(device_t); static int iobus_print_child(device_t dev, device_t child); static void iobus_probe_nomatch(device_t, device_t); static int iobus_read_ivar(device_t, device_t, int, uintptr_t *); static int iobus_write_ivar(device_t, device_t, int, uintptr_t); static struct resource *iobus_alloc_resource(device_t, device_t, int, int *, u_long, u_long, u_long, u_int); static int iobus_activate_resource(device_t, device_t, int, int, struct resource *); static int iobus_deactivate_resource(device_t, device_t, int, int, struct resource *); static int iobus_release_resource(device_t, device_t, int, int, struct resource *); /* * Bus interface definition */ static device_method_t iobus_methods[] = { /* Device interface */ DEVMETHOD(device_probe, iobus_probe), DEVMETHOD(device_attach, iobus_attach), DEVMETHOD(device_detach, bus_generic_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), /* Bus interface */ DEVMETHOD(bus_print_child, iobus_print_child), DEVMETHOD(bus_probe_nomatch, iobus_probe_nomatch), DEVMETHOD(bus_read_ivar, iobus_read_ivar), DEVMETHOD(bus_write_ivar, iobus_write_ivar), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), DEVMETHOD(bus_alloc_resource, iobus_alloc_resource), DEVMETHOD(bus_release_resource, iobus_release_resource), DEVMETHOD(bus_activate_resource, iobus_activate_resource), DEVMETHOD(bus_deactivate_resource, iobus_deactivate_resource), { 0, 0 } }; static driver_t iobus_driver = { "iobus", iobus_methods, sizeof(struct iobus_softc) }; devclass_t iobus_devclass; DRIVER_MODULE(iobus, nexus, iobus_driver, iobus_devclass, 0, 0); static int iobus_probe(device_t dev) { char *type = nexus_get_name(dev); if (strcmp(type, "psim-iobus") != 0) return (ENXIO); device_set_desc(dev, "PSIM local bus"); return (0); } /* * Add interrupt/addr range to the dev's resource list if present */ static void iobus_add_intr(phandle_t devnode, struct iobus_devinfo *dinfo) { u_int intr = -1; if (OF_getprop(devnode, "interrupt", &intr, sizeof(intr)) != -1) { resource_list_add(&dinfo->id_resources, SYS_RES_IRQ, 0, intr, intr, 1); } dinfo->id_interrupt = intr; } static void iobus_add_reg(phandle_t devnode, struct iobus_devinfo *dinfo, vm_offset_t iobus_off) { u_int size; int i; size = OF_getprop(devnode, "reg", dinfo->id_reg,sizeof(dinfo->id_reg)); if (size != -1) { dinfo->id_nregs = size / (sizeof(dinfo->id_reg[0])); for (i = 0; i < dinfo->id_nregs; i+= 3) { /* * Scale the absolute addresses back to iobus * relative offsets. This is to better simulate * macio */ dinfo->id_reg[i+1] -= iobus_off; resource_list_add(&dinfo->id_resources, SYS_RES_MEMORY, 0, dinfo->id_reg[i+1], dinfo->id_reg[i+1] + dinfo->id_reg[i+2], dinfo->id_reg[i+2]); } } } static int iobus_attach(device_t dev) { struct iobus_softc *sc; struct iobus_devinfo *dinfo; phandle_t root; phandle_t child; device_t cdev; char *name; u_int reg[2]; int size; sc = device_get_softc(dev); sc->sc_node = nexus_get_node(dev); /* * Find the base addr/size of the iobus, and initialize the * resource manager */ size = OF_getprop(sc->sc_node, "reg", reg, sizeof(reg)); if (size == sizeof(reg)) { sc->sc_addr = reg[0]; sc->sc_size = reg[1]; } else { return (ENXIO); } sc->sc_mem_rman.rm_type = RMAN_ARRAY; sc->sc_mem_rman.rm_descr = "IOBus Device Memory"; if (rman_init(&sc->sc_mem_rman) != 0) { device_printf(dev, "failed to init mem range resources\n"); return (ENXIO); } rman_manage_region(&sc->sc_mem_rman, 0, sc->sc_size); /* * Iterate through the sub-devices */ root = sc->sc_node; for (child = OF_child(root); child != 0; child = OF_peer(child)) { OF_getprop_alloc(child, "name", 1, (void **)&name); cdev = device_add_child(dev, NULL, -1); if (cdev != NULL) { dinfo = malloc(sizeof(*dinfo), M_IOBUS, M_WAITOK); memset(dinfo, 0, sizeof(*dinfo)); resource_list_init(&dinfo->id_resources); dinfo->id_node = child; dinfo->id_name = name; iobus_add_intr(child, dinfo); iobus_add_reg(child, dinfo, sc->sc_addr); device_set_ivars(cdev, dinfo); } else { free(name, M_OFWPROP); } } return (bus_generic_attach(dev)); } static int iobus_print_child(device_t dev, device_t child) { struct iobus_devinfo *dinfo; struct resource_list *rl; int retval = 0; dinfo = device_get_ivars(child); rl = &dinfo->id_resources; retval += bus_print_child_header(dev, child); retval += printf(" offset 0x%x", dinfo->id_reg[1]); retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld"); retval += bus_print_child_footer(dev, child); return (retval); } static void iobus_probe_nomatch(device_t dev, device_t child) { } static int iobus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct iobus_devinfo *dinfo; if ((dinfo = device_get_ivars(child)) == 0) return (ENOENT); switch (which) { case IOBUS_IVAR_NODE: *result = dinfo->id_node; break; case IOBUS_IVAR_NAME: *result = (uintptr_t)dinfo->id_name; break; case IOBUS_IVAR_NREGS: *result = dinfo->id_nregs; break; case IOBUS_IVAR_REGS: *result = (uintptr_t)dinfo->id_reg; break; default: return (ENOENT); } return (0); } static int iobus_write_ivar(device_t dev, device_t child, int which, uintptr_t value) { return (EINVAL); } static struct resource * iobus_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct iobus_softc *sc; int needactivate; struct resource *rv; struct rman *rm; bus_space_tag_t tagval; sc = device_get_softc(bus); needactivate = flags & RF_ACTIVE; flags &= ~RF_ACTIVE; switch (type) { case SYS_RES_MEMORY: case SYS_RES_IOPORT: rm = &sc->sc_mem_rman; tagval = PPC_BUS_SPACE_MEM; break; case SYS_RES_IRQ: return (bus_alloc_resource(bus, type, rid, start, end, count, flags)); break; default: device_printf(bus, "unknown resource request from %s\n", device_get_nameunit(child)); return (NULL); } rv = rman_reserve_resource(rm, start, end, count, flags, child); if (rv == NULL) { device_printf(bus, "failed to reserve resource for %s\n", device_get_nameunit(child)); return (NULL); } rman_set_bustag(rv, tagval); rman_set_bushandle(rv, rman_get_start(rv)); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv) != 0) { device_printf(bus, "failed to activate resource for %s\n", device_get_nameunit(child)); rman_release_resource(rv); return (NULL); } } return (rv); } static int iobus_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { if (rman_get_flags(res) & RF_ACTIVE) { int error = bus_deactivate_resource(child, type, rid, res); if (error) return error; } return (rman_release_resource(res)); } static int iobus_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { struct iobus_softc *sc; void *p; sc = device_get_softc(bus); if (type == SYS_RES_IRQ) return (bus_activate_resource(bus, type, rid, res)); if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { p = pmap_mapdev((vm_offset_t)rman_get_start(res) + sc->sc_addr, (vm_size_t)rman_get_size(res)); if (p == NULL) return (ENOMEM); rman_set_virtual(res, p); rman_set_bushandle(res, (u_long)p); } return (rman_activate_resource(res)); } static int iobus_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { /* * If this is a memory resource, unmap it. */ if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) { u_int32_t psize; psize = rman_get_size(res); pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize); } return (rman_deactivate_resource(res)); } Index: head/sys/powerpc/psim/openpic_iobus.c =================================================================== --- head/sys/powerpc/psim/openpic_iobus.c (revision 133520) +++ head/sys/powerpc/psim/openpic_iobus.c (revision 133521) @@ -1,221 +1,220 @@ /* * Copyright 2003 by Peter Grehan. All rights reserved. * * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. * */ /* * The psim iobus attachment for the OpenPIC interrupt controller. */ #include __FBSDID("$FreeBSD$"); -#define __RMAN_RESOURCE_VISIBLE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pic_if.h" struct openpic_iobus_softc { struct openpic_softc osc; struct resource *sc_memr; /* iobus mem resource */ device_t sc_ndev; /* nexus device */ }; static struct openpic_iobus_softc *ppicsoftc; /* * MacIO interface */ static void openpic_psim_identify(driver_t *, device_t); static int openpic_psim_probe(device_t); static int openpic_psim_attach(device_t); static int openpic_iobus_probe(device_t); static int openpic_iobus_attach(device_t); /* * Nexus attachment */ static device_method_t openpic_psim_methods[] = { /* Device interface */ DEVMETHOD(device_identify, openpic_psim_identify), DEVMETHOD(device_probe, openpic_psim_probe), DEVMETHOD(device_attach, openpic_psim_attach), /* PIC interface */ DEVMETHOD(pic_allocate_intr, openpic_allocate_intr), DEVMETHOD(pic_setup_intr, openpic_setup_intr), DEVMETHOD(pic_teardown_intr, openpic_teardown_intr), DEVMETHOD(pic_release_intr, openpic_release_intr), { 0, 0 } }; static driver_t openpic_psim_driver = { "openpic", openpic_psim_methods, sizeof(struct openpic_iobus_softc) }; static devclass_t openpic_psim_devclass; DRIVER_MODULE(openpic_psim, nexus, openpic_psim_driver, openpic_psim_devclass, 0, 0); static void openpic_psim_identify(driver_t *driver, device_t parent) { device_t child; phandle_t pic; pic = OF_finddevice("/iobus/opic"); if (pic == -1) return; child = BUS_ADD_CHILD(parent, 0, "openpic", 0); if (child != NULL) nexus_set_device_type(child, "psim"); } static int openpic_psim_probe(device_t dev) { char *name; char *type; name = nexus_get_name(dev); type = nexus_get_device_type(dev); if (strcmp(name, "openpic") != 0 || strcmp(type, "psim") != 0) return (ENXIO); device_set_desc(dev, OPENPIC_DEVSTR); return (0); } static int openpic_psim_attach(device_t dev) { KASSERT(ppicsoftc == NULL, ("iobus openpic: already probed")); ppicsoftc = device_get_softc(dev); ppicsoftc->sc_ndev = dev; nexus_install_intcntlr(dev); openpic_early_attach(dev); return (0); } /* * PSIM IOBus attachment */ static device_method_t openpic_iobus_methods[] = { /* Device interface */ DEVMETHOD(device_probe, openpic_iobus_probe), DEVMETHOD(device_attach, openpic_iobus_attach), { 0, 0 }, }; static driver_t openpic_iobus_driver = { "openpiciobus", openpic_iobus_methods, 0 }; static devclass_t openpic_iobus_devclass; DRIVER_MODULE(openpiciobus, iobus, openpic_iobus_driver, openpic_iobus_devclass, 0, 0); static int openpic_iobus_probe(device_t dev) { char *name; name = iobus_get_name(dev); if (strcmp(name, "interrupt-controller") != 0) return (ENXIO); /* * The description was already printed out in the nexus * probe, so don't do it again here */ device_set_desc(dev, "OpenPIC IOBus interrupt cell"); if (!bootverbose) device_quiet(dev); return (0); } static int openpic_iobus_attach(device_t dev) { struct openpic_iobus_softc *sc; int rid; sc = ppicsoftc; KASSERT(sc != NULL, ("pic not nexus-probed\n")); rid = 0; sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_memr == NULL) { device_printf(dev, "Could not alloc mem resource!\n"); return (ENXIO); } sc->osc.sc_psim = 1; sc->osc.sc_bt = rman_get_bustag(sc->sc_memr); sc->osc.sc_bh = rman_get_bushandle(sc->sc_memr); sc->osc.sc_altdev = dev; return (openpic_attach(sc->sc_ndev)); }