nexus.c revision 157894
1139790Simp/*-
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 157894 2006-04-20 04:18:30Z imp $
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 <vm/vm.h>
5484124Sdfr#include <vm/pmap.h>
5584124Sdfr
56119970Smarcel#include <machine/intr.h>
5784124Sdfr#include <machine/nexusvar.h>
58119970Smarcel#include <machine/pmap.h>
5984124Sdfr#include <machine/resource.h>
60119970Smarcel#include <machine/sapicvar.h>
61119970Smarcel#include <machine/vmparam.h>
6284124Sdfr
6384541Sdfr#include <isa/isareg.h>
6484124Sdfr#include <sys/rtprio.h>
6584124Sdfr
6684124Sdfrstatic MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device");
6784124Sdfrstruct nexus_device {
6884124Sdfr	struct resource_list	nx_resources;
6984124Sdfr	int			nx_pcibus;
7084124Sdfr};
7184124Sdfr
7284124Sdfr#define DEVTONX(dev)	((struct nexus_device *)device_get_ivars(dev))
7384124Sdfr
7484124Sdfrstatic struct rman irq_rman, drq_rman, port_rman, mem_rman;
7584124Sdfr
7684124Sdfrstatic	int nexus_probe(device_t);
7784124Sdfrstatic	int nexus_attach(device_t);
7884124Sdfrstatic	int nexus_print_resources(struct resource_list *rl, const char *name, int type,
7984124Sdfr				  const char *format);
8084124Sdfrstatic	int nexus_print_all_resources(device_t dev);
8184124Sdfrstatic	int nexus_print_child(device_t, device_t);
8284124Sdfrstatic device_t nexus_add_child(device_t bus, int order, const char *name,
8384124Sdfr				int unit);
8484124Sdfrstatic	struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
8584124Sdfr					      u_long, u_long, u_long, u_int);
8684124Sdfrstatic	int nexus_read_ivar(device_t, device_t, int, uintptr_t *);
8784124Sdfrstatic	int nexus_write_ivar(device_t, device_t, int, uintptr_t);
8884124Sdfrstatic	int nexus_activate_resource(device_t, device_t, int, int,
8984124Sdfr				    struct resource *);
9084124Sdfrstatic	int nexus_deactivate_resource(device_t, device_t, int, int,
9184124Sdfr				      struct resource *);
9284124Sdfrstatic	int nexus_release_resource(device_t, device_t, int, int,
9384124Sdfr				   struct resource *);
9484124Sdfrstatic	int nexus_setup_intr(device_t, device_t, struct resource *, int flags,
9584124Sdfr			     void (*)(void *), void *, void **);
9684124Sdfrstatic	int nexus_teardown_intr(device_t, device_t, struct resource *,
9784124Sdfr				void *);
98134263Snjlstatic struct resource_list *nexus_get_reslist(device_t dev, device_t child);
9984124Sdfrstatic	int nexus_set_resource(device_t, device_t, int, int, u_long, u_long);
100119970Smarcelstatic	int nexus_get_resource(device_t, device_t, int, int, u_long *,
101119970Smarcel			       u_long *);
10284124Sdfrstatic void nexus_delete_resource(device_t, device_t, int, int);
103119970Smarcelstatic	int nexus_config_intr(device_t, int, enum intr_trigger,
104119970Smarcel			      enum intr_polarity);
10584124Sdfr
10684124Sdfrstatic device_method_t nexus_methods[] = {
10784124Sdfr	/* Device interface */
10884124Sdfr	DEVMETHOD(device_probe,		nexus_probe),
10984124Sdfr	DEVMETHOD(device_attach,	nexus_attach),
11084124Sdfr	DEVMETHOD(device_detach,	bus_generic_detach),
11184124Sdfr	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
11284124Sdfr	DEVMETHOD(device_suspend,	bus_generic_suspend),
11384124Sdfr	DEVMETHOD(device_resume,	bus_generic_resume),
11484124Sdfr
11584124Sdfr	/* Bus interface */
11684124Sdfr	DEVMETHOD(bus_print_child,	nexus_print_child),
11784124Sdfr	DEVMETHOD(bus_add_child,	nexus_add_child),
11884124Sdfr	DEVMETHOD(bus_read_ivar,	nexus_read_ivar),
11984124Sdfr	DEVMETHOD(bus_write_ivar,	nexus_write_ivar),
12084124Sdfr	DEVMETHOD(bus_alloc_resource,	nexus_alloc_resource),
12184124Sdfr	DEVMETHOD(bus_release_resource,	nexus_release_resource),
12284124Sdfr	DEVMETHOD(bus_activate_resource, nexus_activate_resource),
12384124Sdfr	DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
12484124Sdfr	DEVMETHOD(bus_setup_intr,	nexus_setup_intr),
12584124Sdfr	DEVMETHOD(bus_teardown_intr,	nexus_teardown_intr),
126134263Snjl	DEVMETHOD(bus_get_resource_list, nexus_get_reslist),
12784124Sdfr	DEVMETHOD(bus_set_resource,	nexus_set_resource),
12884124Sdfr	DEVMETHOD(bus_get_resource,	nexus_get_resource),
12984124Sdfr	DEVMETHOD(bus_delete_resource,	nexus_delete_resource),
130119970Smarcel	DEVMETHOD(bus_config_intr,	nexus_config_intr),
13184124Sdfr
13284124Sdfr	{ 0, 0 }
13384124Sdfr};
13484124Sdfr
13584124Sdfrstatic driver_t nexus_driver = {
13684124Sdfr	"nexus",
13784124Sdfr	nexus_methods,
13884124Sdfr	1,			/* no softc */
13984124Sdfr};
14084124Sdfrstatic devclass_t nexus_devclass;
14184124Sdfr
14284124SdfrDRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0);
14384124Sdfr
14484124Sdfrstatic int
14584124Sdfrnexus_probe(device_t dev)
14684124Sdfr{
14784124Sdfr
14884124Sdfr	device_quiet(dev);	/* suppress attach message for neatness */
14984124Sdfr
15084124Sdfr	/*
15184124Sdfr	 * XXX working notes:
15284124Sdfr	 *
15384124Sdfr	 * - IRQ resource creation should be moved to the PIC/APIC driver.
15484124Sdfr	 * - DRQ resource creation should be moved to the DMAC driver.
15584124Sdfr	 * - The above should be sorted to probe earlier than any child busses.
15684124Sdfr	 *
15784124Sdfr	 * - Leave I/O and memory creation here, as child probes may need them.
15884124Sdfr	 *   (especially eg. ACPI)
15984124Sdfr	 */
16084124Sdfr
16184124Sdfr	/*
16284124Sdfr	 * IRQ's are on the mainboard on old systems, but on the ISA part
16384124Sdfr	 * of PCI->ISA bridges.  There would be multiple sets of IRQs on
16484124Sdfr	 * multi-ISA-bus systems.  PCI interrupts are routed to the ISA
16584124Sdfr	 * component, so in a way, PCI can be a partial child of an ISA bus(!).
16684124Sdfr	 * APIC interrupts are global though.
16784124Sdfr	 *
16884124Sdfr	 * XXX We depend on the AT PIC driver correctly claiming IRQ 2
16984124Sdfr	 *     to prevent its reuse elsewhere in the !APIC_IO case.
17084124Sdfr	 */
17184124Sdfr	irq_rman.rm_start = 0;
17284124Sdfr	irq_rman.rm_type = RMAN_ARRAY;
17384124Sdfr	irq_rman.rm_descr = "Interrupt request lines";
174100398Speter	irq_rman.rm_end = 255;
17584124Sdfr	if (rman_init(&irq_rman)
17684124Sdfr	    || rman_manage_region(&irq_rman,
17784124Sdfr				  irq_rman.rm_start, irq_rman.rm_end))
17884124Sdfr		panic("nexus_probe irq_rman");
17984124Sdfr
18084124Sdfr	/*
18184124Sdfr	 * ISA DMA on PCI systems is implemented in the ISA part of each
18284124Sdfr	 * PCI->ISA bridge and the channels can be duplicated if there are
18384124Sdfr	 * multiple bridges.  (eg: laptops with docking stations)
18484124Sdfr	 */
18584124Sdfr	drq_rman.rm_start = 0;
18684124Sdfr	drq_rman.rm_end = 7;
18784124Sdfr	drq_rman.rm_type = RMAN_ARRAY;
18884124Sdfr	drq_rman.rm_descr = "DMA request lines";
18984124Sdfr	/* XXX drq 0 not available on some machines */
19084124Sdfr	if (rman_init(&drq_rman)
19184124Sdfr	    || rman_manage_region(&drq_rman,
19284124Sdfr				  drq_rman.rm_start, drq_rman.rm_end))
19384124Sdfr		panic("nexus_probe drq_rman");
19484124Sdfr
19584124Sdfr	/*
19684124Sdfr	 * However, IO ports and Memory truely are global at this level,
19784124Sdfr	 * as are APIC interrupts (however many IO APICS there turn out
19884124Sdfr	 * to be on large systems..)
19984124Sdfr	 */
20084124Sdfr	port_rman.rm_start = 0;
20184124Sdfr	port_rman.rm_end = 0xffff;
20284124Sdfr	port_rman.rm_type = RMAN_ARRAY;
20384124Sdfr	port_rman.rm_descr = "I/O ports";
20484124Sdfr	if (rman_init(&port_rman)
20584124Sdfr	    || rman_manage_region(&port_rman, 0, 0xffff))
20684124Sdfr		panic("nexus_probe port_rman");
20784124Sdfr
20884124Sdfr	mem_rman.rm_start = 0;
20984124Sdfr	mem_rman.rm_end = ~0u;
21084124Sdfr	mem_rman.rm_type = RMAN_ARRAY;
21184124Sdfr	mem_rman.rm_descr = "I/O memory addresses";
21284124Sdfr	if (rman_init(&mem_rman)
21384124Sdfr	    || rman_manage_region(&mem_rman, 0, ~0))
21484124Sdfr		panic("nexus_probe mem_rman");
21584124Sdfr
21684124Sdfr	return bus_generic_probe(dev);
21784124Sdfr}
21884124Sdfr
21984124Sdfrstatic int
22084124Sdfrnexus_attach(device_t dev)
22184124Sdfr{
22284541Sdfr	/*
22384541Sdfr	 * Mask the legacy PICs - we will use the I/O SAPIC for interrupt.
22484541Sdfr	 */
22584541Sdfr	outb(IO_ICU1+1, 0xff);
22684541Sdfr	outb(IO_ICU2+1, 0xff);
22784541Sdfr
22884124Sdfr	bus_generic_attach(dev);
22984124Sdfr	return 0;
23084124Sdfr}
23184124Sdfr
23284124Sdfrstatic int
23384124Sdfrnexus_print_resources(struct resource_list *rl, const char *name, int type,
23484124Sdfr		      const char *format)
23584124Sdfr{
23684124Sdfr	struct resource_list_entry *rle;
23784124Sdfr	int printed, retval;
23884124Sdfr
23984124Sdfr	printed = 0;
24084124Sdfr	retval = 0;
24184124Sdfr	/* Yes, this is kinda cheating */
242143867Snjl	STAILQ_FOREACH(rle, rl, link) {
24384124Sdfr		if (rle->type == type) {
24484124Sdfr			if (printed == 0)
24584124Sdfr				retval += printf(" %s ", name);
24684124Sdfr			else if (printed > 0)
24784124Sdfr				retval += printf(",");
24884124Sdfr			printed++;
24984124Sdfr			retval += printf(format, rle->start);
25084124Sdfr			if (rle->count > 1) {
25184124Sdfr				retval += printf("-");
25284124Sdfr				retval += printf(format, rle->start +
25384124Sdfr						 rle->count - 1);
25484124Sdfr			}
25584124Sdfr		}
25684124Sdfr	}
25784124Sdfr	return retval;
25884124Sdfr}
25984124Sdfr
26084124Sdfrstatic int
26184124Sdfrnexus_print_all_resources(device_t dev)
26284124Sdfr{
26384124Sdfr	struct	nexus_device *ndev = DEVTONX(dev);
26484124Sdfr	struct resource_list *rl = &ndev->nx_resources;
26584124Sdfr	int retval = 0;
26684124Sdfr
267143867Snjl	if (STAILQ_FIRST(rl) || ndev->nx_pcibus != -1)
26884124Sdfr		retval += printf(" at");
26984124Sdfr
27084124Sdfr	retval += nexus_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
27184124Sdfr	retval += nexus_print_resources(rl, "iomem", SYS_RES_MEMORY, "%#lx");
27284124Sdfr	retval += nexus_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
27384124Sdfr
27484124Sdfr	return retval;
27584124Sdfr}
27684124Sdfr
27784124Sdfrstatic int
27884124Sdfrnexus_print_child(device_t bus, device_t child)
27984124Sdfr{
28084124Sdfr	struct	nexus_device *ndev = DEVTONX(child);
28184124Sdfr	int retval = 0;
28284124Sdfr
28384124Sdfr	retval += bus_print_child_header(bus, child);
28484124Sdfr	retval += nexus_print_all_resources(child);
28584124Sdfr	if (ndev->nx_pcibus != -1)
28684124Sdfr		retval += printf(" pcibus %d", ndev->nx_pcibus);
287136521Snjl	if (device_get_flags(child))
288136521Snjl		retval += printf(" flags %#x", device_get_flags(child));
28984124Sdfr	retval += printf(" on motherboard\n");	/* XXX "motherboard", ick */
29084124Sdfr
29184124Sdfr	return (retval);
29284124Sdfr}
29384124Sdfr
29484124Sdfrstatic device_t
29584124Sdfrnexus_add_child(device_t bus, int order, const char *name, int unit)
29684124Sdfr{
29784124Sdfr	device_t		child;
29884124Sdfr	struct nexus_device	*ndev;
29984124Sdfr
30084124Sdfr	ndev = malloc(sizeof(struct nexus_device), M_NEXUSDEV, M_NOWAIT|M_ZERO);
30184124Sdfr	if (!ndev)
30284124Sdfr		return(0);
30384124Sdfr	resource_list_init(&ndev->nx_resources);
30484124Sdfr	ndev->nx_pcibus = -1;
30584124Sdfr
30684124Sdfr	child = device_add_child_ordered(bus, order, name, unit);
30784124Sdfr
30884124Sdfr	/* should we free this in nexus_child_detached? */
30984124Sdfr	device_set_ivars(child, ndev);
31084124Sdfr
31184124Sdfr	return(child);
31284124Sdfr}
31384124Sdfr
31484124Sdfrstatic int
31584124Sdfrnexus_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
31684124Sdfr{
31784124Sdfr	struct	nexus_device *ndev = DEVTONX(child);
31884124Sdfr
31984124Sdfr	switch (which) {
32084124Sdfr	case NEXUS_IVAR_PCIBUS:
32184124Sdfr		*result = ndev->nx_pcibus;
32284124Sdfr		break;
32384124Sdfr	default:
32484124Sdfr		return ENOENT;
32584124Sdfr	}
32684124Sdfr	return 0;
32784124Sdfr}
32884124Sdfr
32984124Sdfr
33084124Sdfrstatic int
33184124Sdfrnexus_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
33284124Sdfr{
33384124Sdfr	struct	nexus_device *ndev = DEVTONX(child);
33484124Sdfr
33584124Sdfr	switch (which) {
33684124Sdfr	case NEXUS_IVAR_PCIBUS:
33784124Sdfr		ndev->nx_pcibus = value;
33884124Sdfr		break;
33984124Sdfr	default:
34084124Sdfr		return ENOENT;
34184124Sdfr	}
34284124Sdfr	return 0;
34384124Sdfr}
34484124Sdfr
34584124Sdfr
34684124Sdfr/*
34784124Sdfr * Allocate a resource on behalf of child.  NB: child is usually going to be a
34884124Sdfr * child of one of our descendants, not a direct child of nexus0.
34984124Sdfr * (Exceptions include npx.)
35084124Sdfr */
35184124Sdfrstatic struct resource *
35284124Sdfrnexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
35384124Sdfr		     u_long start, u_long end, u_long count, u_int flags)
35484124Sdfr{
35584124Sdfr	struct nexus_device *ndev = DEVTONX(child);
35684124Sdfr	struct	resource *rv;
35784124Sdfr	struct resource_list_entry *rle;
35884124Sdfr	struct	rman *rm;
35984124Sdfr	int needactivate = flags & RF_ACTIVE;
36084124Sdfr
36184124Sdfr	/*
36284124Sdfr	 * If this is an allocation of the "default" range for a given RID, and
36384124Sdfr	 * we know what the resources for this device are (ie. they aren't maintained
36484124Sdfr	 * by a child bus), then work out the start/end values.
36584124Sdfr	 */
36684124Sdfr	if ((start == 0UL) && (end == ~0UL) && (count == 1)) {
36784124Sdfr		if (ndev == NULL)
36884124Sdfr			return(NULL);
36984124Sdfr		rle = resource_list_find(&ndev->nx_resources, type, *rid);
37084124Sdfr		if (rle == NULL)
37184124Sdfr			return(NULL);
37284124Sdfr		start = rle->start;
37384124Sdfr		end = rle->end;
37484124Sdfr		count = rle->count;
37584124Sdfr	}
37684124Sdfr
37784124Sdfr	flags &= ~RF_ACTIVE;
37884124Sdfr
37984124Sdfr	switch (type) {
38084124Sdfr	case SYS_RES_IRQ:
38184124Sdfr		rm = &irq_rman;
38284124Sdfr		break;
38384124Sdfr
38484124Sdfr	case SYS_RES_DRQ:
38584124Sdfr		rm = &drq_rman;
38684124Sdfr		break;
38784124Sdfr
38884124Sdfr	case SYS_RES_IOPORT:
38984124Sdfr		rm = &port_rman;
39084124Sdfr		break;
39184124Sdfr
39284124Sdfr	case SYS_RES_MEMORY:
39384124Sdfr		rm = &mem_rman;
39484124Sdfr		break;
39584124Sdfr
39684124Sdfr	default:
39784124Sdfr		return 0;
39884124Sdfr	}
39984124Sdfr
40084124Sdfr	rv = rman_reserve_resource(rm, start, end, count, flags, child);
40184124Sdfr	if (rv == 0)
40284124Sdfr		return 0;
40384124Sdfr
404157894Simp	rman_set_rid(rv, *rid);
40584124Sdfr	if (type == SYS_RES_MEMORY) {
40684124Sdfr		rman_set_bustag(rv, IA64_BUS_SPACE_MEM);
40784124Sdfr	} else if (type == SYS_RES_IOPORT) {
40884124Sdfr		rman_set_bustag(rv, IA64_BUS_SPACE_IO);
40984124Sdfr		/* IBM-PC: the type of bus_space_handle_t is u_int */
410151006Sphk		rman_set_bushandle(rv, rman_get_start(rv));
41184124Sdfr	}
41284124Sdfr
41384124Sdfr	if (needactivate) {
41484124Sdfr		if (bus_activate_resource(child, type, *rid, rv)) {
41584124Sdfr			rman_release_resource(rv);
41684124Sdfr			return 0;
41784124Sdfr		}
41884124Sdfr	}
41984124Sdfr
42084124Sdfr	return rv;
42184124Sdfr}
42284124Sdfr
42384124Sdfrstatic int
42484124Sdfrnexus_activate_resource(device_t bus, device_t child, int type, int rid,
42584124Sdfr			struct resource *r)
42684124Sdfr{
42784124Sdfr	/*
42884124Sdfr	 * If this is a memory resource, map it into the kernel.
42984124Sdfr	 */
43084124Sdfr	if (rman_get_bustag(r) == IA64_BUS_SPACE_MEM) {
43184124Sdfr		vm_offset_t paddr = rman_get_start(r);
43284124Sdfr		vm_offset_t psize = rman_get_size(r);
43384124Sdfr		caddr_t vaddr = 0;
43484124Sdfr
43584124Sdfr		vaddr = pmap_mapdev(paddr, psize);
43684124Sdfr		rman_set_virtual(r, vaddr);
43784124Sdfr		rman_set_bushandle(r, (bus_space_handle_t) paddr);
43884124Sdfr	}
43984124Sdfr	return (rman_activate_resource(r));
44084124Sdfr}
44184124Sdfr
44284124Sdfrstatic int
44384124Sdfrnexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
44484124Sdfr			  struct resource *r)
44584124Sdfr{
44684124Sdfr
44784124Sdfr	return (rman_deactivate_resource(r));
44884124Sdfr}
44984124Sdfr
45084124Sdfrstatic int
45184124Sdfrnexus_release_resource(device_t bus, device_t child, int type, int rid,
45284124Sdfr		       struct resource *r)
45384124Sdfr{
45484124Sdfr	if (rman_get_flags(r) & RF_ACTIVE) {
45584124Sdfr		int error = bus_deactivate_resource(child, type, rid, r);
45684124Sdfr		if (error)
45784124Sdfr			return error;
45884124Sdfr	}
45984124Sdfr	return (rman_release_resource(r));
46084124Sdfr}
46184124Sdfr
46284124Sdfr/*
46384124Sdfr * Currently this uses the really grody interface from kern/kern_intr.c
46484124Sdfr * (which really doesn't belong in kern/anything.c).  Eventually, all of
46584124Sdfr * the code in kern_intr.c and machdep_intr.c should get moved here, since
46684124Sdfr * this is going to be the official interface.
46784124Sdfr */
46884124Sdfrstatic int
46984124Sdfrnexus_setup_intr(device_t bus, device_t child, struct resource *irq,
47084124Sdfr		 int flags, void (*ihand)(void *), void *arg, void **cookiep)
47184124Sdfr{
47284124Sdfr	driver_t	*driver;
47384124Sdfr	int		error;
47484124Sdfr
47584124Sdfr	/* somebody tried to setup an irq that failed to allocate! */
47684124Sdfr	if (irq == NULL)
47784124Sdfr		panic("nexus_setup_intr: NULL irq resource!");
47884124Sdfr
47984124Sdfr	*cookiep = 0;
480151006Sphk	if ((rman_get_flags(irq) & RF_SHAREABLE) == 0)
48184124Sdfr		flags |= INTR_EXCL;
48284124Sdfr
48384124Sdfr	driver = device_get_driver(child);
48484124Sdfr
48584124Sdfr	/*
48684124Sdfr	 * We depend here on rman_activate_resource() being idempotent.
48784124Sdfr	 */
48884124Sdfr	error = rman_activate_resource(irq);
48984124Sdfr	if (error)
49084124Sdfr		return (error);
49184124Sdfr
492151006Sphk	error = ia64_setup_intr(device_get_nameunit(child),
493151006Sphk	    rman_get_start(irq), ihand, arg, flags, cookiep, 0);
49484124Sdfr
49584124Sdfr	return (error);
49684124Sdfr}
49784124Sdfr
49884124Sdfrstatic int
49984124Sdfrnexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih)
50084124Sdfr{
50184124Sdfr#if 0
50284124Sdfr	return (inthand_remove(ih));
50384124Sdfr#else
50484124Sdfr	return 0;
50584124Sdfr#endif
50684124Sdfr}
50784124Sdfr
508134263Snjlstatic struct resource_list *
509134263Snjlnexus_get_reslist(device_t dev, device_t child)
510134263Snjl{
511134263Snjl	struct nexus_device *ndev = DEVTONX(child);
512134263Snjl
513134263Snjl	return (&ndev->nx_resources);
514134263Snjl}
515134263Snjl
51684124Sdfrstatic int
51784124Sdfrnexus_set_resource(device_t dev, device_t child, int type, int rid, u_long start, u_long count)
51884124Sdfr{
51984124Sdfr	struct nexus_device	*ndev = DEVTONX(child);
52084124Sdfr	struct resource_list	*rl = &ndev->nx_resources;
52184124Sdfr
52284124Sdfr	/* XXX this should return a success/failure indicator */
52384124Sdfr	resource_list_add(rl, type, rid, start, start + count - 1, count);
52484124Sdfr	return(0);
52584124Sdfr}
52684124Sdfr
52784124Sdfrstatic int
52884124Sdfrnexus_get_resource(device_t dev, device_t child, int type, int rid, u_long *startp, u_long *countp)
52984124Sdfr{
53084124Sdfr	struct nexus_device	*ndev = DEVTONX(child);
53184124Sdfr	struct resource_list	*rl = &ndev->nx_resources;
53284124Sdfr	struct resource_list_entry *rle;
53384124Sdfr
53484124Sdfr	rle = resource_list_find(rl, type, rid);
53584124Sdfr	device_printf(child, "type %d  rid %d  startp %p  countp %p - got %p\n",
53684124Sdfr		      type, rid, startp, countp, rle);
53784124Sdfr	if (!rle)
53884124Sdfr		return(ENOENT);
53984124Sdfr	if (startp)
54084124Sdfr		*startp = rle->start;
54184124Sdfr	if (countp)
54284124Sdfr		*countp = rle->count;
54384124Sdfr	return(0);
54484124Sdfr}
54584124Sdfr
54684124Sdfrstatic void
54784124Sdfrnexus_delete_resource(device_t dev, device_t child, int type, int rid)
54884124Sdfr{
54984124Sdfr	struct nexus_device	*ndev = DEVTONX(child);
55084124Sdfr	struct resource_list	*rl = &ndev->nx_resources;
55184124Sdfr
55284124Sdfr	resource_list_delete(rl, type, rid);
55384124Sdfr}
55484124Sdfr
555119970Smarcelstatic int
556119970Smarcelnexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
557119970Smarcel    enum intr_polarity pol)
558119970Smarcel{
559119970Smarcel
560119970Smarcel	return (sapic_config_intr(irq, trig, pol));
561119970Smarcel}
562119970Smarcel
56384124Sdfr#if 0
56484124Sdfr
56584124Sdfr/*
56684124Sdfr * Placeholder which claims PnP 'devices' which describe system
56784124Sdfr * resources.
56884124Sdfr */
56984124Sdfrstatic struct isa_pnp_id sysresource_ids[] = {
57084124Sdfr	{ 0x010cd041 /* PNP0c01 */, "System Memory" },
57184124Sdfr	{ 0x020cd041 /* PNP0c02 */, "System Resource" },
57284124Sdfr	{ 0 }
57384124Sdfr};
57484124Sdfr
57584124Sdfrstatic int
57684124Sdfrsysresource_probe(device_t dev)
57784124Sdfr{
57884124Sdfr	int	result;
57984124Sdfr
58084124Sdfr	if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, sysresource_ids)) <= 0) {
58184124Sdfr		device_quiet(dev);
58284124Sdfr	}
58384124Sdfr	return(result);
58484124Sdfr}
58584124Sdfr
58684124Sdfrstatic int
58784124Sdfrsysresource_attach(device_t dev)
58884124Sdfr{
58984124Sdfr	return(0);
59084124Sdfr}
59184124Sdfr
59284124Sdfrstatic device_method_t sysresource_methods[] = {
59384124Sdfr	/* Device interface */
59484124Sdfr	DEVMETHOD(device_probe,		sysresource_probe),
59584124Sdfr	DEVMETHOD(device_attach,	sysresource_attach),
59684124Sdfr	DEVMETHOD(device_detach,	bus_generic_detach),
59784124Sdfr	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
59884124Sdfr	DEVMETHOD(device_suspend,	bus_generic_suspend),
59984124Sdfr	DEVMETHOD(device_resume,	bus_generic_resume),
60084124Sdfr	{ 0, 0 }
60184124Sdfr};
60284124Sdfr
60384124Sdfrstatic driver_t sysresource_driver = {
60484124Sdfr	"sysresource",
60584124Sdfr	sysresource_methods,
60684124Sdfr	1,		/* no softc */
60784124Sdfr};
60884124Sdfr
60984124Sdfrstatic devclass_t sysresource_devclass;
61084124Sdfr
61184124SdfrDRIVER_MODULE(sysresource, isa, sysresource_driver, sysresource_devclass, 0, 0);
61284124Sdfr
61384124Sdfr#endif
614