Index: head/sys/alpha/isa/isa.c =================================================================== --- head/sys/alpha/isa/isa.c (revision 127145) +++ head/sys/alpha/isa/isa.c (revision 127146) @@ -1,421 +1,419 @@ /*- * Copyright (c) 1998 Doug Rabson * 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 THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct rman isa_irq_rman; static struct rman isa_drq_rman; static void isa_intr_enable(int irq) { if (irq < 8) outb(IO_ICU1+1, inb(IO_ICU1+1) & ~(1 << irq)); else outb(IO_ICU2+1, inb(IO_ICU2+1) & ~(1 << (irq - 8))); } static void isa_intr_disable(int irq) { if (irq < 8) outb(IO_ICU1+1, inb(IO_ICU1+1) | (1 << irq)); else outb(IO_ICU2+1, inb(IO_ICU2+1) | (1 << (irq - 8))); } intrmask_t isa_irq_pending(void) { u_char irr1; u_char irr2; irr1 = inb(IO_ICU1); irr2 = inb(IO_ICU2); return ((irr2 << 8) | irr1); } intrmask_t isa_irq_mask(void) { u_char irr1; u_char irr2; irr1 = inb(IO_ICU1+1); irr2 = inb(IO_ICU2+1); return ((irr2 << 8) | irr1); } void isa_init(device_t dev) { isa_init_intr(); } void isa_init_intr(void) { static int initted = 0; if (initted) return; initted = 1; isa_irq_rman.rm_start = 0; isa_irq_rman.rm_end = 15; isa_irq_rman.rm_type = RMAN_ARRAY; isa_irq_rman.rm_descr = "ISA Interrupt request lines"; if (rman_init(&isa_irq_rman) || rman_manage_region(&isa_irq_rman, 0, 1) || rman_manage_region(&isa_irq_rman, 3, 15)) panic("isa_probe isa_irq_rman"); isa_drq_rman.rm_start = 0; isa_drq_rman.rm_end = 7; isa_drq_rman.rm_type = RMAN_ARRAY; isa_drq_rman.rm_descr = "ISA DMA request lines"; if (rman_init(&isa_drq_rman) || rman_manage_region(&isa_drq_rman, 0, 7)) panic("isa_probe isa_drq_rman"); /* mask all isa interrupts */ outb(IO_ICU1+1, 0xff); outb(IO_ICU2+1, 0xff); /* make sure chaining irq is enabled */ isa_intr_enable(2); } struct resource * isa_alloc_intr(device_t bus, device_t child, int irq) { return rman_reserve_resource(&isa_irq_rman, irq, irq, 1, 0, child); } struct resource * isa_alloc_intrs(device_t bus, device_t child, u_long start, u_long end) { return rman_reserve_resource(&isa_irq_rman, start, end, end - start + 1, 0, child); } int isa_release_intr(device_t bus, device_t child, struct resource *r) { return rman_release_resource(r); } /* * This implementation simply passes the request up to the parent * bus, which in our case is the pci chipset device, substituting any * configured values if the caller defaulted. We can get away with * this because there is no special mapping for ISA resources on this * platform. When porting this code to another architecture, it may be * necessary to interpose a mapping layer here. * * We manage our own interrupt resources since ISA interrupts go through * the ISA PIC, not the PCI interrupt controller. */ struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* - * Consider adding a resource definition. We allow rid 0-1 for - * irq and drq, 0-3 for memory and 0-7 for ports which is - * sufficient for isapnp. + * Consider adding a resource definition. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; struct resource *res; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } if (type != SYS_RES_IRQ && type != SYS_RES_DRQ) return resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags); if (!passthrough) { rl = device_get_ivars(child); rle = resource_list_find(rl, type, *rid); if (!rle) return 0; if (rle->res) panic("isa_alloc_resource: resource entry is busy"); if (isdefault) { start = end = rle->start; count = 1; } } if (type == SYS_RES_IRQ) res = rman_reserve_resource(&isa_irq_rman, start, start, 1, 0, child); else res = rman_reserve_resource(&isa_drq_rman, start, start, 1, 0, child); if (res && !passthrough) { rle = resource_list_find(rl, type, *rid); rle->start = rman_get_start(res); rle->end = rman_get_end(res); rle->count = 1; rle->res = res; } return res; } int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { int passthrough = (device_get_parent(child) != bus); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; int error; if (type != SYS_RES_IRQ) return resource_list_release(rl, bus, child, type, rid, res); error = rman_release_resource(res); if (!passthrough && !error) { rle = resource_list_find(rl, SYS_RES_IRQ, rid); if (rle) rle->res = NULL; else error = ENOENT; } return error; } struct isa_intr { void *ih; driver_intr_t *intr; void *arg; int irq; }; /* * Wrap ISA interrupt routines so that we can feed non-specific * EOI to the PICs. */ static void isa_handle_fast_intr(void *arg) { struct isa_intr *ii = arg; int irq = ii->irq; ii->intr(ii->arg); mtx_lock_spin(&icu_lock); if (irq > 7) outb(IO_ICU2, 0x20 | (irq & 7)); outb(IO_ICU1, 0x20 | (irq > 7 ? 2 : irq)); mtx_unlock_spin(&icu_lock); } static void isa_handle_intr(void *arg) { struct isa_intr *ii = arg; ii->intr(ii->arg); } /* * Send a non-specific EIO early, then disable the source */ static void isa_disable_intr(uintptr_t vector) { int irq; irq = (vector - 0x800) >> 4; mtx_lock_spin(&icu_lock); if (irq > 7) outb(IO_ICU2, 0x20 | (irq & 7)); outb(IO_ICU1, 0x20 | (irq > 7 ? 2 : irq)); isa_intr_disable(irq); mtx_unlock_spin(&icu_lock); } static void isa_enable_intr(uintptr_t vector) { int irq; irq = (vector - 0x800) >> 4; mtx_lock_spin(&icu_lock); isa_intr_enable(irq); mtx_unlock_spin(&icu_lock); } int isa_setup_intr(device_t dev, device_t child, struct resource *irq, int flags, driver_intr_t *intr, void *arg, void **cookiep) { struct isa_intr *ii; int error; if (platform.isa_setup_intr) return platform.isa_setup_intr(dev, child, irq, flags, intr, arg, cookiep); if (irq == NULL) return ENODEV; error = rman_activate_resource(irq); if (error) return error; ii = malloc(sizeof(struct isa_intr), M_DEVBUF, M_NOWAIT); if (!ii) return ENOMEM; ii->intr = intr; ii->arg = arg; ii->irq = irq->r_start; error = alpha_setup_intr( device_get_nameunit(child ? child : dev), 0x800 + (irq->r_start << 4), ((flags & INTR_FAST) ? isa_handle_fast_intr : isa_handle_intr), ii, flags, &ii->ih, &intrcnt[INTRCNT_ISA_IRQ + irq->r_start], isa_disable_intr, isa_enable_intr); if (error) { free(ii, M_DEVBUF); return error; } mtx_lock_spin(&icu_lock); isa_intr_enable(irq->r_start); mtx_unlock_spin(&icu_lock); *cookiep = ii; if (child) device_printf(child, "interrupting at ISA irq %d\n", (int)irq->r_start); return 0; } int isa_teardown_intr(device_t dev, device_t child, struct resource *irq, void *cookie) { struct isa_intr *ii = cookie; struct intrhand *ih, *handler = (struct intrhand *)ii->ih; struct ithd *ithread = handler->ih_ithread; int num_handlers = 0; mtx_lock(&ithread->it_lock); TAILQ_FOREACH(ih, &ithread->it_handlers, ih_next) num_handlers++; mtx_unlock(&ithread->it_lock); /* * Only disable the interrupt in hardware if there are no * other handlers sharing it. */ if (num_handlers == 1) { mtx_lock_spin(&icu_lock); isa_intr_disable(irq->r_start); mtx_unlock_spin(&icu_lock); if (platform.isa_teardown_intr) { platform.isa_teardown_intr(dev, child, irq, cookie); return 0; } } alpha_teardown_intr(ii->ih); return 0; } Index: head/sys/amd64/isa/isa.c =================================================================== --- head/sys/amd64/isa/isa.c (revision 127145) +++ head/sys/amd64/isa/isa.c (revision 127146) @@ -1,161 +1,159 @@ /*- * Copyright (c) 1998 Doug Rabson * 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 THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * Modifications for Intel architecture by Garrett A. Wollman. * Copyright 1998 Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby * granted, provided that both the above copyright notice and this * permission notice appear in all copies, that both the above * copyright notice and this permission notice appear in all * supporting documentation, and that the name of M.I.T. not be used * in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. M.I.T. makes * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include void isa_init(device_t dev) { } /* * This implementation simply passes the request up to the parent * bus, which in our case is the special i386 nexus, substituting any * configured values if the caller defaulted. We can get away with * this because there is no special mapping for ISA resources on an Intel * platform. When porting this code to another architecture, it may be * necessary to interpose a mapping layer here. */ struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* - * Consider adding a resource definition. We allow rid 0-1 for - * irq and drq, 0-3 for memory and 0-7 for ports which is - * sufficient for isapnp. + * Consider adding a resource definition. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } return resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags); } int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; return resource_list_release(rl, bus, child, type, rid, r); } /* * We can't use the bus_generic_* versions of these methods because those * methods always pass the bus param as the requesting device, and we need * to pass the child (the i386 nexus knows about this and is prepared to * deal). */ int isa_setup_intr(device_t bus, device_t child, struct resource *r, int flags, void (*ihand)(void *), void *arg, void **cookiep) { return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags, ihand, arg, cookiep)); } int isa_teardown_intr(device_t bus, device_t child, struct resource *r, void *cookie) { return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie)); } Index: head/sys/ia64/isa/isa.c =================================================================== --- head/sys/ia64/isa/isa.c (revision 127145) +++ head/sys/ia64/isa/isa.c (revision 127146) @@ -1,171 +1,169 @@ /*- * Copyright (c) 1998 Doug Rabson * 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 THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ /* * Modifications for Intel architecture by Garrett A. Wollman. * Copyright 1998 Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby * granted, provided that both the above copyright notice and this * permission notice appear in all copies, that both the above * copyright notice and this permission notice appear in all * supporting documentation, and that the name of M.I.T. not be used * in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. M.I.T. makes * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include void isa_init(device_t dev) { } intrmask_t isa_irq_pending(void) { u_char irr1; u_char irr2; irr1 = inb(IO_ICU1); irr2 = inb(IO_ICU2); return ((irr2 << 8) | irr1); } /* * This implementation simply passes the request up to the parent * bus, which in our case is the special i386 nexus, substituting any * configured values if the caller defaulted. We can get away with * this because there is no special mapping for ISA resources on an Intel * platform. When porting this code to another architecture, it may be * necessary to interpose a mapping layer here. */ struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* - * Consider adding a resource definition. We allow rid 0-1 for - * irq and drq, 0-3 for memory and 0-7 for ports which is - * sufficient for isapnp. + * Consider adding a resource definition. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } return resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags); } int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; return resource_list_release(rl, bus, child, type, rid, r); } /* * We can't use the bus_generic_* versions of these methods because those * methods always pass the bus param as the requesting device, and we need * to pass the child (the i386 nexus knows about this and is prepared to * deal). */ int isa_setup_intr(device_t bus, device_t child, struct resource *r, int flags, void (*ihand)(void *), void *arg, void **cookiep) { return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags, ihand, arg, cookiep)); } int isa_teardown_intr(device_t bus, device_t child, struct resource *r, void *cookie) { return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie)); } Index: head/sys/sparc64/isa/isa.c =================================================================== --- head/sys/sparc64/isa/isa.c (revision 127145) +++ head/sys/sparc64/isa/isa.c (revision 127146) @@ -1,366 +1,364 @@ /*- * Copyright (c) 1998 Doug Rabson * Copyright (c) 2001 Thomas Moestl * 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 THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: FreeBSD: src/sys/alpha/isa/isa.c,v 1.26 2001/07/11 * * $FreeBSD$ */ #include "opt_ofw_pci.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* There can be only one ISA bus, so it is safe to use globals. */ bus_space_tag_t isa_io_bt = NULL; bus_space_handle_t isa_io_hdl; bus_space_tag_t isa_mem_bt = NULL; bus_space_handle_t isa_mem_hdl; u_int64_t isa_io_base; u_int64_t isa_io_limit; u_int64_t isa_mem_base; u_int64_t isa_mem_limit; device_t isa_bus_device; static phandle_t isab_node; static ofw_pci_intr_t isa_ino[8]; #ifdef OFW_NEWPCI struct ofw_bus_iinfo isa_iinfo; #endif /* * XXX: This is really partly partly PCI-specific, but unfortunately is * differently enough to have to duplicate it here... */ #define ISAB_RANGE_PHYS(r) \ (((u_int64_t)(r)->phys_mid << 32) | (u_int64_t)(r)->phys_lo) #define ISAB_RANGE_SPACE(r) (((r)->phys_hi >> 24) & 0x03) #define ISAR_SPACE_IO 0x01 #define ISAR_SPACE_MEM 0x02 #define INRANGE(x, start, end) ((x) >= (start) && (x) <= (end)) static int isa_route_intr_res(device_t, u_long, u_long); intrmask_t isa_irq_pending(void) { intrmask_t pending; int i; /* XXX: Is this correct? */ for (i = 7, pending = 0; i >= 0; i--) { pending <<= 1; if (isa_ino[i] != PCI_INVALID_IRQ) { pending |= (OFW_PCI_INTR_PENDING(isa_bus_device, isa_ino[i]) == 0) ? 0 : 1; } } return (pending); } void isa_init(device_t dev) { device_t bridge; phandle_t node; ofw_isa_intr_t ino; #ifndef OFW_NEWPCI ofw_pci_intr_t rino; #endif struct isa_ranges *br; int nbr, i; /* The parent of the bus must be a PCI-ISA bridge. */ bridge = device_get_parent(dev); #ifdef OFW_NEWPCI isab_node = ofw_pci_get_node(bridge); #else isab_node = ofw_pci_node(bridge); #endif nbr = OF_getprop_alloc(isab_node, "ranges", sizeof(*br), (void **)&br); if (nbr <= 0) panic("isa_init: cannot get bridge range property"); #ifdef OFW_NEWPCI ofw_bus_setup_iinfo(isab_node, &isa_iinfo, sizeof(ofw_isa_intr_t)); #endif /* * This is really a bad kludge; however, it is needed to provide * isa_irq_pending(), which is unfortunately still used by some * drivers. */ for (i = 0; i < 8; i++) isa_ino[i] = PCI_INVALID_IRQ; for (node = OF_child(isab_node); node != 0; node = OF_peer(node)) { if (OF_getprop(node, "interrupts", &ino, sizeof(ino)) == -1) continue; if (ino > 7) panic("isa_init: XXX: ino too large"); #ifdef OFW_NEWPCI isa_ino[ino] = ofw_isa_route_intr(bridge, node, &isa_iinfo, ino); #else rino = ofw_bus_route_intr(node, ino, ofw_pci_orb_callback, dev); isa_ino[ino] = rino == ORIR_NOTFOUND ? PCI_INVALID_IRQ : rino; #endif } for (nbr -= 1; nbr >= 0; nbr--) { switch(ISAB_RANGE_SPACE(br + nbr)) { case ISAR_SPACE_IO: /* This is probably always 0. */ isa_io_base = ISAB_RANGE_PHYS(&br[nbr]); isa_io_limit = br[nbr].size; isa_io_hdl = OFW_PCI_GET_BUS_HANDLE(bridge, SYS_RES_IOPORT, isa_io_base, &isa_io_bt); break; case ISAR_SPACE_MEM: /* This is probably always 0. */ isa_mem_base = ISAB_RANGE_PHYS(&br[nbr]); isa_mem_limit = br[nbr].size; isa_mem_hdl = OFW_PCI_GET_BUS_HANDLE(bridge, SYS_RES_MEMORY, isa_mem_base, &isa_mem_bt); break; } } free(br, M_OFWPROP); } static int isa_route_intr_res(device_t bus, u_long start, u_long end) { int res; if (start != end) { panic("isa_route_intr_res: allocation of interrupt range not " "supported (0x%lx - 0x%lx)", start, end); } if (start > 7) panic("isa_route_intr_res: start out of isa range"); res = isa_ino[start]; if (res == PCI_INVALID_IRQ) device_printf(bus, "could not map interrupt %d\n", res); return (res); } struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* - * Consider adding a resource definition. We allow rid 0-1 for - * irq and drq, 0-3 for memory and 0-7 for ports which is - * sufficient for isapnp. + * Consider adding a resource definition. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; u_long base, limit; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } /* * Add the base, change default allocations to be between base and * limit, and reject allocations if a resource type is not enabled. */ base = limit = 0; switch(type) { case SYS_RES_MEMORY: if (isa_mem_bt == NULL) return (NULL); base = isa_mem_base; limit = base + isa_mem_limit; break; case SYS_RES_IOPORT: if (isa_io_bt == NULL) return (NULL); base = isa_io_base; limit = base + isa_io_limit; break; case SYS_RES_IRQ: if (isdefault && passthrough) panic("isa_alloc_resource: cannot pass through default " "irq allocation"); if (!isdefault) { start = end = isa_route_intr_res(bus, start, end); if (start == PCI_INVALID_IRQ) return (NULL); } break; default: panic("isa_alloc_resource: unsupported resource type %d", type); } if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { start = ulmin(start + base, limit); end = ulmin(end + base, limit); } /* * This inlines a modified resource_list_alloc(); this is needed * because the resources need to have offsets added to them, which * cannot be done beforehand without patching the resource list entries * (which is ugly). */ if (passthrough) { return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type, rid, start, end, count, flags)); } rle = resource_list_find(rl, type, *rid); if (rle == NULL) return (NULL); /* no resource of that type/rid */ if (rle->res != NULL) panic("isa_alloc_resource: resource entry is busy"); if (isdefault) { start = rle->start; count = ulmax(count, rle->count); end = ulmax(rle->end, start + count - 1); switch (type) { case SYS_RES_MEMORY: case SYS_RES_IOPORT: start += base; end += base; if (!INRANGE(start, base, limit) || !INRANGE(end, base, limit)) return (NULL); break; case SYS_RES_IRQ: start = end = isa_route_intr_res(bus, start, end); if (start == PCI_INVALID_IRQ) return (NULL); break; } } rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type, rid, start, end, count, flags); /* * Record the new range. */ if (rle->res != NULL) { rle->start = rman_get_start(rle->res) - base; rle->end = rman_get_end(rle->res) - base; rle->count = count; } return (rle->res); } int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; return (resource_list_release(rl, bus, child, type, rid, res)); } int isa_setup_intr(device_t dev, device_t child, struct resource *irq, int flags, driver_intr_t *intr, void *arg, void **cookiep) { /* * Just pass through. This is going to be handled by either one of * the parent PCI buses or the nexus device. * The interrupt was routed at allocation time. */ return (BUS_SETUP_INTR(device_get_parent(dev), child, irq, flags, intr, arg, cookiep)); } int isa_teardown_intr(device_t dev, device_t child, struct resource *irq, void *cookie) { return (BUS_TEARDOWN_INTR(device_get_parent(dev), child, irq, cookie)); }