nexus.c revision 84541
184124Sdfr/* 284124Sdfr * Copyright 1998 Massachusetts Institute of Technology 384124Sdfr * 484124Sdfr * Permission to use, copy, modify, and distribute this software and 584124Sdfr * its documentation for any purpose and without fee is hereby 684124Sdfr * granted, provided that both the above copyright notice and this 784124Sdfr * permission notice appear in all copies, that both the above 884124Sdfr * copyright notice and this permission notice appear in all 984124Sdfr * supporting documentation, and that the name of M.I.T. not be used 1084124Sdfr * in advertising or publicity pertaining to distribution of the 1184124Sdfr * software without specific, written prior permission. M.I.T. makes 1284124Sdfr * no representations about the suitability of this software for any 1384124Sdfr * purpose. It is provided "as is" without express or implied 1484124Sdfr * warranty. 1584124Sdfr * 1684124Sdfr * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 1784124Sdfr * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 1884124Sdfr * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1984124Sdfr * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 2084124Sdfr * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2184124Sdfr * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2284124Sdfr * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2384124Sdfr * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 2484124Sdfr * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2584124Sdfr * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2684124Sdfr * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2784124Sdfr * SUCH DAMAGE. 2884124Sdfr * 2984124Sdfr * $FreeBSD: head/sys/ia64/ia64/nexus.c 84541 2001-10-05 10:30:09Z dfr $ 3084124Sdfr */ 3184124Sdfr 3284124Sdfr/* 3384124Sdfr * This code implements a `root nexus' for Intel Architecture 3484124Sdfr * machines. The function of the root nexus is to serve as an 3584124Sdfr * attachment point for both processors and buses, and to manage 3684124Sdfr * resources which are common to all of them. In particular, 3784124Sdfr * this code implements the core resource managers for interrupt 3884124Sdfr * requests, DMA requests (which rightfully should be a part of the 3984124Sdfr * ISA code but it's easier to do it here for now), I/O port addresses, 4084124Sdfr * and I/O memory address space. 4184124Sdfr */ 4284124Sdfr 4384124Sdfr#include <sys/param.h> 4484124Sdfr#include <sys/systm.h> 4584124Sdfr#include <sys/bus.h> 4684124Sdfr#include <sys/kernel.h> 4784124Sdfr#include <sys/malloc.h> 4884124Sdfr#include <sys/module.h> 4984124Sdfr#include <machine/bus.h> 5084124Sdfr#include <sys/rman.h> 5184124Sdfr#include <sys/interrupt.h> 5284124Sdfr 5384124Sdfr#include <machine/vmparam.h> 5484124Sdfr#include <vm/vm.h> 5584124Sdfr#include <vm/pmap.h> 5684124Sdfr#include <machine/pmap.h> 5784124Sdfr 5884124Sdfr#include <machine/nexusvar.h> 5984124Sdfr#include <machine/resource.h> 6084124Sdfr 6184124Sdfr#include <isa/isavar.h> 6284541Sdfr#include <isa/isareg.h> 6384124Sdfr#include <sys/rtprio.h> 6484124Sdfr 6584124Sdfrstatic MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device"); 6684124Sdfrstruct nexus_device { 6784124Sdfr struct resource_list nx_resources; 6884124Sdfr int nx_pcibus; 6984124Sdfr}; 7084124Sdfr 7184124Sdfr#define DEVTONX(dev) ((struct nexus_device *)device_get_ivars(dev)) 7284124Sdfr 7384124Sdfrstatic struct rman irq_rman, drq_rman, port_rman, mem_rman; 7484124Sdfr 7584124Sdfrstatic int nexus_probe(device_t); 7684124Sdfrstatic int nexus_attach(device_t); 7784124Sdfrstatic int nexus_print_resources(struct resource_list *rl, const char *name, int type, 7884124Sdfr const char *format); 7984124Sdfrstatic int nexus_print_all_resources(device_t dev); 8084124Sdfrstatic int nexus_print_child(device_t, device_t); 8184124Sdfrstatic device_t nexus_add_child(device_t bus, int order, const char *name, 8284124Sdfr int unit); 8384124Sdfrstatic struct resource *nexus_alloc_resource(device_t, device_t, int, int *, 8484124Sdfr u_long, u_long, u_long, u_int); 8584124Sdfrstatic int nexus_read_ivar(device_t, device_t, int, uintptr_t *); 8684124Sdfrstatic int nexus_write_ivar(device_t, device_t, int, uintptr_t); 8784124Sdfrstatic int nexus_activate_resource(device_t, device_t, int, int, 8884124Sdfr struct resource *); 8984124Sdfrstatic int nexus_deactivate_resource(device_t, device_t, int, int, 9084124Sdfr struct resource *); 9184124Sdfrstatic int nexus_release_resource(device_t, device_t, int, int, 9284124Sdfr struct resource *); 9384124Sdfrstatic int nexus_setup_intr(device_t, device_t, struct resource *, int flags, 9484124Sdfr void (*)(void *), void *, void **); 9584124Sdfrstatic int nexus_teardown_intr(device_t, device_t, struct resource *, 9684124Sdfr void *); 9784124Sdfrstatic int nexus_set_resource(device_t, device_t, int, int, u_long, u_long); 9884124Sdfrstatic int nexus_get_resource(device_t, device_t, int, int, u_long *, u_long *); 9984124Sdfrstatic void nexus_delete_resource(device_t, device_t, int, int); 10084124Sdfr 10184124Sdfrstatic device_method_t nexus_methods[] = { 10284124Sdfr /* Device interface */ 10384124Sdfr DEVMETHOD(device_probe, nexus_probe), 10484124Sdfr DEVMETHOD(device_attach, nexus_attach), 10584124Sdfr DEVMETHOD(device_detach, bus_generic_detach), 10684124Sdfr DEVMETHOD(device_shutdown, bus_generic_shutdown), 10784124Sdfr DEVMETHOD(device_suspend, bus_generic_suspend), 10884124Sdfr DEVMETHOD(device_resume, bus_generic_resume), 10984124Sdfr 11084124Sdfr /* Bus interface */ 11184124Sdfr DEVMETHOD(bus_print_child, nexus_print_child), 11284124Sdfr DEVMETHOD(bus_add_child, nexus_add_child), 11384124Sdfr DEVMETHOD(bus_read_ivar, nexus_read_ivar), 11484124Sdfr DEVMETHOD(bus_write_ivar, nexus_write_ivar), 11584124Sdfr DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), 11684124Sdfr DEVMETHOD(bus_release_resource, nexus_release_resource), 11784124Sdfr DEVMETHOD(bus_activate_resource, nexus_activate_resource), 11884124Sdfr DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), 11984124Sdfr DEVMETHOD(bus_setup_intr, nexus_setup_intr), 12084124Sdfr DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), 12184124Sdfr DEVMETHOD(bus_set_resource, nexus_set_resource), 12284124Sdfr DEVMETHOD(bus_get_resource, nexus_get_resource), 12384124Sdfr DEVMETHOD(bus_delete_resource, nexus_delete_resource), 12484124Sdfr 12584124Sdfr { 0, 0 } 12684124Sdfr}; 12784124Sdfr 12884124Sdfrstatic driver_t nexus_driver = { 12984124Sdfr "nexus", 13084124Sdfr nexus_methods, 13184124Sdfr 1, /* no softc */ 13284124Sdfr}; 13384124Sdfrstatic devclass_t nexus_devclass; 13484124Sdfr 13584124SdfrDRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0); 13684124Sdfr 13784124Sdfrstatic int 13884124Sdfrnexus_probe(device_t dev) 13984124Sdfr{ 14084124Sdfr 14184124Sdfr device_quiet(dev); /* suppress attach message for neatness */ 14284124Sdfr 14384124Sdfr /* 14484124Sdfr * XXX working notes: 14584124Sdfr * 14684124Sdfr * - IRQ resource creation should be moved to the PIC/APIC driver. 14784124Sdfr * - DRQ resource creation should be moved to the DMAC driver. 14884124Sdfr * - The above should be sorted to probe earlier than any child busses. 14984124Sdfr * 15084124Sdfr * - Leave I/O and memory creation here, as child probes may need them. 15184124Sdfr * (especially eg. ACPI) 15284124Sdfr */ 15384124Sdfr 15484124Sdfr /* 15584124Sdfr * IRQ's are on the mainboard on old systems, but on the ISA part 15684124Sdfr * of PCI->ISA bridges. There would be multiple sets of IRQs on 15784124Sdfr * multi-ISA-bus systems. PCI interrupts are routed to the ISA 15884124Sdfr * component, so in a way, PCI can be a partial child of an ISA bus(!). 15984124Sdfr * APIC interrupts are global though. 16084124Sdfr * 16184124Sdfr * XXX We depend on the AT PIC driver correctly claiming IRQ 2 16284124Sdfr * to prevent its reuse elsewhere in the !APIC_IO case. 16384124Sdfr */ 16484124Sdfr irq_rman.rm_start = 0; 16584124Sdfr irq_rman.rm_type = RMAN_ARRAY; 16684124Sdfr irq_rman.rm_descr = "Interrupt request lines"; 16784541Sdfr irq_rman.rm_end = 63; 16884124Sdfr if (rman_init(&irq_rman) 16984124Sdfr || rman_manage_region(&irq_rman, 17084124Sdfr irq_rman.rm_start, irq_rman.rm_end)) 17184124Sdfr panic("nexus_probe irq_rman"); 17284124Sdfr 17384124Sdfr /* 17484124Sdfr * ISA DMA on PCI systems is implemented in the ISA part of each 17584124Sdfr * PCI->ISA bridge and the channels can be duplicated if there are 17684124Sdfr * multiple bridges. (eg: laptops with docking stations) 17784124Sdfr */ 17884124Sdfr drq_rman.rm_start = 0; 17984124Sdfr drq_rman.rm_end = 7; 18084124Sdfr drq_rman.rm_type = RMAN_ARRAY; 18184124Sdfr drq_rman.rm_descr = "DMA request lines"; 18284124Sdfr /* XXX drq 0 not available on some machines */ 18384124Sdfr if (rman_init(&drq_rman) 18484124Sdfr || rman_manage_region(&drq_rman, 18584124Sdfr drq_rman.rm_start, drq_rman.rm_end)) 18684124Sdfr panic("nexus_probe drq_rman"); 18784124Sdfr 18884124Sdfr /* 18984124Sdfr * However, IO ports and Memory truely are global at this level, 19084124Sdfr * as are APIC interrupts (however many IO APICS there turn out 19184124Sdfr * to be on large systems..) 19284124Sdfr */ 19384124Sdfr port_rman.rm_start = 0; 19484124Sdfr port_rman.rm_end = 0xffff; 19584124Sdfr port_rman.rm_type = RMAN_ARRAY; 19684124Sdfr port_rman.rm_descr = "I/O ports"; 19784124Sdfr if (rman_init(&port_rman) 19884124Sdfr || rman_manage_region(&port_rman, 0, 0xffff)) 19984124Sdfr panic("nexus_probe port_rman"); 20084124Sdfr 20184124Sdfr mem_rman.rm_start = 0; 20284124Sdfr mem_rman.rm_end = ~0u; 20384124Sdfr mem_rman.rm_type = RMAN_ARRAY; 20484124Sdfr mem_rman.rm_descr = "I/O memory addresses"; 20584124Sdfr if (rman_init(&mem_rman) 20684124Sdfr || rman_manage_region(&mem_rman, 0, ~0)) 20784124Sdfr panic("nexus_probe mem_rman"); 20884124Sdfr 20984124Sdfr return bus_generic_probe(dev); 21084124Sdfr} 21184124Sdfr 21284124Sdfrstatic int 21384124Sdfrnexus_attach(device_t dev) 21484124Sdfr{ 21584541Sdfr /* 21684541Sdfr * Mask the legacy PICs - we will use the I/O SAPIC for interrupt. 21784541Sdfr */ 21884541Sdfr outb(IO_ICU1+1, 0xff); 21984541Sdfr outb(IO_ICU2+1, 0xff); 22084541Sdfr 22184124Sdfr bus_generic_attach(dev); 22284124Sdfr return 0; 22384124Sdfr} 22484124Sdfr 22584124Sdfrstatic int 22684124Sdfrnexus_print_resources(struct resource_list *rl, const char *name, int type, 22784124Sdfr const char *format) 22884124Sdfr{ 22984124Sdfr struct resource_list_entry *rle; 23084124Sdfr int printed, retval; 23184124Sdfr 23284124Sdfr printed = 0; 23384124Sdfr retval = 0; 23484124Sdfr /* Yes, this is kinda cheating */ 23584124Sdfr SLIST_FOREACH(rle, rl, link) { 23684124Sdfr if (rle->type == type) { 23784124Sdfr if (printed == 0) 23884124Sdfr retval += printf(" %s ", name); 23984124Sdfr else if (printed > 0) 24084124Sdfr retval += printf(","); 24184124Sdfr printed++; 24284124Sdfr retval += printf(format, rle->start); 24384124Sdfr if (rle->count > 1) { 24484124Sdfr retval += printf("-"); 24584124Sdfr retval += printf(format, rle->start + 24684124Sdfr rle->count - 1); 24784124Sdfr } 24884124Sdfr } 24984124Sdfr } 25084124Sdfr return retval; 25184124Sdfr} 25284124Sdfr 25384124Sdfrstatic int 25484124Sdfrnexus_print_all_resources(device_t dev) 25584124Sdfr{ 25684124Sdfr struct nexus_device *ndev = DEVTONX(dev); 25784124Sdfr struct resource_list *rl = &ndev->nx_resources; 25884124Sdfr int retval = 0; 25984124Sdfr 26084124Sdfr if (SLIST_FIRST(rl) || ndev->nx_pcibus != -1) 26184124Sdfr retval += printf(" at"); 26284124Sdfr 26384124Sdfr retval += nexus_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx"); 26484124Sdfr retval += nexus_print_resources(rl, "iomem", SYS_RES_MEMORY, "%#lx"); 26584124Sdfr retval += nexus_print_resources(rl, "irq", SYS_RES_IRQ, "%ld"); 26684124Sdfr 26784124Sdfr return retval; 26884124Sdfr} 26984124Sdfr 27084124Sdfrstatic int 27184124Sdfrnexus_print_child(device_t bus, device_t child) 27284124Sdfr{ 27384124Sdfr struct nexus_device *ndev = DEVTONX(child); 27484124Sdfr int retval = 0; 27584124Sdfr 27684124Sdfr retval += bus_print_child_header(bus, child); 27784124Sdfr retval += nexus_print_all_resources(child); 27884124Sdfr if (ndev->nx_pcibus != -1) 27984124Sdfr retval += printf(" pcibus %d", ndev->nx_pcibus); 28084124Sdfr retval += printf(" on motherboard\n"); /* XXX "motherboard", ick */ 28184124Sdfr 28284124Sdfr return (retval); 28384124Sdfr} 28484124Sdfr 28584124Sdfrstatic device_t 28684124Sdfrnexus_add_child(device_t bus, int order, const char *name, int unit) 28784124Sdfr{ 28884124Sdfr device_t child; 28984124Sdfr struct nexus_device *ndev; 29084124Sdfr 29184124Sdfr ndev = malloc(sizeof(struct nexus_device), M_NEXUSDEV, M_NOWAIT|M_ZERO); 29284124Sdfr if (!ndev) 29384124Sdfr return(0); 29484124Sdfr resource_list_init(&ndev->nx_resources); 29584124Sdfr ndev->nx_pcibus = -1; 29684124Sdfr 29784124Sdfr child = device_add_child_ordered(bus, order, name, unit); 29884124Sdfr 29984124Sdfr /* should we free this in nexus_child_detached? */ 30084124Sdfr device_set_ivars(child, ndev); 30184124Sdfr 30284124Sdfr return(child); 30384124Sdfr} 30484124Sdfr 30584124Sdfrstatic int 30684124Sdfrnexus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 30784124Sdfr{ 30884124Sdfr struct nexus_device *ndev = DEVTONX(child); 30984124Sdfr 31084124Sdfr switch (which) { 31184124Sdfr case NEXUS_IVAR_PCIBUS: 31284124Sdfr *result = ndev->nx_pcibus; 31384124Sdfr break; 31484124Sdfr default: 31584124Sdfr return ENOENT; 31684124Sdfr } 31784124Sdfr return 0; 31884124Sdfr} 31984124Sdfr 32084124Sdfr 32184124Sdfrstatic int 32284124Sdfrnexus_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 32384124Sdfr{ 32484124Sdfr struct nexus_device *ndev = DEVTONX(child); 32584124Sdfr 32684124Sdfr switch (which) { 32784124Sdfr case NEXUS_IVAR_PCIBUS: 32884124Sdfr ndev->nx_pcibus = value; 32984124Sdfr break; 33084124Sdfr default: 33184124Sdfr return ENOENT; 33284124Sdfr } 33384124Sdfr return 0; 33484124Sdfr} 33584124Sdfr 33684124Sdfr 33784124Sdfr/* 33884124Sdfr * Allocate a resource on behalf of child. NB: child is usually going to be a 33984124Sdfr * child of one of our descendants, not a direct child of nexus0. 34084124Sdfr * (Exceptions include npx.) 34184124Sdfr */ 34284124Sdfrstatic struct resource * 34384124Sdfrnexus_alloc_resource(device_t bus, device_t child, int type, int *rid, 34484124Sdfr u_long start, u_long end, u_long count, u_int flags) 34584124Sdfr{ 34684124Sdfr struct nexus_device *ndev = DEVTONX(child); 34784124Sdfr struct resource *rv; 34884124Sdfr struct resource_list_entry *rle; 34984124Sdfr struct rman *rm; 35084124Sdfr int needactivate = flags & RF_ACTIVE; 35184124Sdfr 35284124Sdfr /* 35384124Sdfr * If this is an allocation of the "default" range for a given RID, and 35484124Sdfr * we know what the resources for this device are (ie. they aren't maintained 35584124Sdfr * by a child bus), then work out the start/end values. 35684124Sdfr */ 35784124Sdfr if ((start == 0UL) && (end == ~0UL) && (count == 1)) { 35884124Sdfr if (ndev == NULL) 35984124Sdfr return(NULL); 36084124Sdfr rle = resource_list_find(&ndev->nx_resources, type, *rid); 36184124Sdfr if (rle == NULL) 36284124Sdfr return(NULL); 36384124Sdfr start = rle->start; 36484124Sdfr end = rle->end; 36584124Sdfr count = rle->count; 36684124Sdfr } 36784124Sdfr 36884124Sdfr flags &= ~RF_ACTIVE; 36984124Sdfr 37084124Sdfr switch (type) { 37184124Sdfr case SYS_RES_IRQ: 37284124Sdfr rm = &irq_rman; 37384124Sdfr break; 37484124Sdfr 37584124Sdfr case SYS_RES_DRQ: 37684124Sdfr rm = &drq_rman; 37784124Sdfr break; 37884124Sdfr 37984124Sdfr case SYS_RES_IOPORT: 38084124Sdfr rm = &port_rman; 38184124Sdfr break; 38284124Sdfr 38384124Sdfr case SYS_RES_MEMORY: 38484124Sdfr rm = &mem_rman; 38584124Sdfr break; 38684124Sdfr 38784124Sdfr default: 38884124Sdfr return 0; 38984124Sdfr } 39084124Sdfr 39184124Sdfr rv = rman_reserve_resource(rm, start, end, count, flags, child); 39284124Sdfr if (rv == 0) 39384124Sdfr return 0; 39484124Sdfr 39584124Sdfr if (type == SYS_RES_MEMORY) { 39684124Sdfr rman_set_bustag(rv, IA64_BUS_SPACE_MEM); 39784124Sdfr } else if (type == SYS_RES_IOPORT) { 39884124Sdfr rman_set_bustag(rv, IA64_BUS_SPACE_IO); 39984124Sdfr /* IBM-PC: the type of bus_space_handle_t is u_int */ 40084124Sdfr rman_set_bushandle(rv, rv->r_start); 40184124Sdfr } 40284124Sdfr 40384124Sdfr if (needactivate) { 40484124Sdfr if (bus_activate_resource(child, type, *rid, rv)) { 40584124Sdfr rman_release_resource(rv); 40684124Sdfr return 0; 40784124Sdfr } 40884124Sdfr } 40984124Sdfr 41084124Sdfr return rv; 41184124Sdfr} 41284124Sdfr 41384124Sdfrstatic int 41484124Sdfrnexus_activate_resource(device_t bus, device_t child, int type, int rid, 41584124Sdfr struct resource *r) 41684124Sdfr{ 41784124Sdfr /* 41884124Sdfr * If this is a memory resource, map it into the kernel. 41984124Sdfr */ 42084124Sdfr if (rman_get_bustag(r) == IA64_BUS_SPACE_MEM) { 42184124Sdfr vm_offset_t paddr = rman_get_start(r); 42284124Sdfr vm_offset_t psize = rman_get_size(r); 42384124Sdfr caddr_t vaddr = 0; 42484124Sdfr 42584124Sdfr vaddr = pmap_mapdev(paddr, psize); 42684124Sdfr rman_set_virtual(r, vaddr); 42784124Sdfr rman_set_bushandle(r, (bus_space_handle_t) paddr); 42884124Sdfr } 42984124Sdfr return (rman_activate_resource(r)); 43084124Sdfr} 43184124Sdfr 43284124Sdfrstatic int 43384124Sdfrnexus_deactivate_resource(device_t bus, device_t child, int type, int rid, 43484124Sdfr struct resource *r) 43584124Sdfr{ 43684124Sdfr 43784124Sdfr return (rman_deactivate_resource(r)); 43884124Sdfr} 43984124Sdfr 44084124Sdfrstatic int 44184124Sdfrnexus_release_resource(device_t bus, device_t child, int type, int rid, 44284124Sdfr struct resource *r) 44384124Sdfr{ 44484124Sdfr if (rman_get_flags(r) & RF_ACTIVE) { 44584124Sdfr int error = bus_deactivate_resource(child, type, rid, r); 44684124Sdfr if (error) 44784124Sdfr return error; 44884124Sdfr } 44984124Sdfr return (rman_release_resource(r)); 45084124Sdfr} 45184124Sdfr 45284124Sdfr/* 45384124Sdfr * Currently this uses the really grody interface from kern/kern_intr.c 45484124Sdfr * (which really doesn't belong in kern/anything.c). Eventually, all of 45584124Sdfr * the code in kern_intr.c and machdep_intr.c should get moved here, since 45684124Sdfr * this is going to be the official interface. 45784124Sdfr */ 45884124Sdfrstatic int 45984124Sdfrnexus_setup_intr(device_t bus, device_t child, struct resource *irq, 46084124Sdfr int flags, void (*ihand)(void *), void *arg, void **cookiep) 46184124Sdfr{ 46284124Sdfr driver_t *driver; 46384124Sdfr int error; 46484124Sdfr 46584124Sdfr /* somebody tried to setup an irq that failed to allocate! */ 46684124Sdfr if (irq == NULL) 46784124Sdfr panic("nexus_setup_intr: NULL irq resource!"); 46884124Sdfr 46984124Sdfr *cookiep = 0; 47084124Sdfr if ((irq->r_flags & RF_SHAREABLE) == 0) 47184124Sdfr flags |= INTR_EXCL; 47284124Sdfr 47384124Sdfr driver = device_get_driver(child); 47484124Sdfr 47584124Sdfr /* 47684124Sdfr * We depend here on rman_activate_resource() being idempotent. 47784124Sdfr */ 47884124Sdfr error = rman_activate_resource(irq); 47984124Sdfr if (error) 48084124Sdfr return (error); 48184124Sdfr 48284541Sdfr error = ia64_setup_intr(device_get_nameunit(child), irq->r_start, 48384541Sdfr ihand, arg, flags, cookiep, 0); 48484124Sdfr 48584124Sdfr return (error); 48684124Sdfr} 48784124Sdfr 48884124Sdfrstatic int 48984124Sdfrnexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih) 49084124Sdfr{ 49184124Sdfr#if 0 49284124Sdfr return (inthand_remove(ih)); 49384124Sdfr#else 49484124Sdfr return 0; 49584124Sdfr#endif 49684124Sdfr} 49784124Sdfr 49884124Sdfrstatic int 49984124Sdfrnexus_set_resource(device_t dev, device_t child, int type, int rid, u_long start, u_long count) 50084124Sdfr{ 50184124Sdfr struct nexus_device *ndev = DEVTONX(child); 50284124Sdfr struct resource_list *rl = &ndev->nx_resources; 50384124Sdfr 50484124Sdfr /* XXX this should return a success/failure indicator */ 50584124Sdfr resource_list_add(rl, type, rid, start, start + count - 1, count); 50684124Sdfr return(0); 50784124Sdfr} 50884124Sdfr 50984124Sdfrstatic int 51084124Sdfrnexus_get_resource(device_t dev, device_t child, int type, int rid, u_long *startp, u_long *countp) 51184124Sdfr{ 51284124Sdfr struct nexus_device *ndev = DEVTONX(child); 51384124Sdfr struct resource_list *rl = &ndev->nx_resources; 51484124Sdfr struct resource_list_entry *rle; 51584124Sdfr 51684124Sdfr rle = resource_list_find(rl, type, rid); 51784124Sdfr device_printf(child, "type %d rid %d startp %p countp %p - got %p\n", 51884124Sdfr type, rid, startp, countp, rle); 51984124Sdfr if (!rle) 52084124Sdfr return(ENOENT); 52184124Sdfr if (startp) 52284124Sdfr *startp = rle->start; 52384124Sdfr if (countp) 52484124Sdfr *countp = rle->count; 52584124Sdfr return(0); 52684124Sdfr} 52784124Sdfr 52884124Sdfrstatic void 52984124Sdfrnexus_delete_resource(device_t dev, device_t child, int type, int rid) 53084124Sdfr{ 53184124Sdfr struct nexus_device *ndev = DEVTONX(child); 53284124Sdfr struct resource_list *rl = &ndev->nx_resources; 53384124Sdfr 53484124Sdfr resource_list_delete(rl, type, rid); 53584124Sdfr} 53684124Sdfr 53784124Sdfr#if 0 53884124Sdfr 53984124Sdfr/* 54084124Sdfr * Placeholder which claims PnP 'devices' which describe system 54184124Sdfr * resources. 54284124Sdfr */ 54384124Sdfrstatic struct isa_pnp_id sysresource_ids[] = { 54484124Sdfr { 0x010cd041 /* PNP0c01 */, "System Memory" }, 54584124Sdfr { 0x020cd041 /* PNP0c02 */, "System Resource" }, 54684124Sdfr { 0 } 54784124Sdfr}; 54884124Sdfr 54984124Sdfrstatic int 55084124Sdfrsysresource_probe(device_t dev) 55184124Sdfr{ 55284124Sdfr int result; 55384124Sdfr 55484124Sdfr if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, sysresource_ids)) <= 0) { 55584124Sdfr device_quiet(dev); 55684124Sdfr } 55784124Sdfr return(result); 55884124Sdfr} 55984124Sdfr 56084124Sdfrstatic int 56184124Sdfrsysresource_attach(device_t dev) 56284124Sdfr{ 56384124Sdfr return(0); 56484124Sdfr} 56584124Sdfr 56684124Sdfrstatic device_method_t sysresource_methods[] = { 56784124Sdfr /* Device interface */ 56884124Sdfr DEVMETHOD(device_probe, sysresource_probe), 56984124Sdfr DEVMETHOD(device_attach, sysresource_attach), 57084124Sdfr DEVMETHOD(device_detach, bus_generic_detach), 57184124Sdfr DEVMETHOD(device_shutdown, bus_generic_shutdown), 57284124Sdfr DEVMETHOD(device_suspend, bus_generic_suspend), 57384124Sdfr DEVMETHOD(device_resume, bus_generic_resume), 57484124Sdfr { 0, 0 } 57584124Sdfr}; 57684124Sdfr 57784124Sdfrstatic driver_t sysresource_driver = { 57884124Sdfr "sysresource", 57984124Sdfr sysresource_methods, 58084124Sdfr 1, /* no softc */ 58184124Sdfr}; 58284124Sdfr 58384124Sdfrstatic devclass_t sysresource_devclass; 58484124Sdfr 58584124SdfrDRIVER_MODULE(sysresource, isa, sysresource_driver, sysresource_devclass, 0, 0); 58684124Sdfr 58784124Sdfr#endif 588