2 * Copyright 1998 Massachusetts Institute of Technology
3 * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>.
4 * Copyright 2006 by Marius Strobl <marius@FreeBSD.org>.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby
9 * granted, provided that both the above copyright notice and this
10 * permission notice appear in all copies, that both the above
11 * copyright notice and this permission notice appear in all
12 * supporting documentation, and that the name of M.I.T. not be used
13 * in advertising or publicity pertaining to distribution of the
14 * software without specific, written prior permission. M.I.T. makes
15 * no representations about the suitability of this software for any
16 * purpose. It is provided "as is" without express or implied
19 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
20 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
23 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
50 #include <dev/ofw/ofw_bus.h>
51 #include <dev/ofw/ofw_bus_subr.h>
52 #include <dev/ofw/openfirm.h>
54 #include <machine/bus.h>
55 #include <machine/intr_machdep.h>
56 #include <machine/resource.h>
59 * The nexus handles root-level resource allocation requests and interrupt
60 * mapping. All direct subdevices of nexus are attached by DEVICE_IDENTIFY().
63 static device_probe_t nexus_probe;
64 static device_attach_t nexus_attach;
65 static bus_setup_intr_t nexus_setup_intr;
66 static bus_teardown_intr_t nexus_teardown_intr;
67 static bus_activate_resource_t nexus_activate_resource;
68 static bus_deactivate_resource_t nexus_deactivate_resource;
69 static bus_space_tag_t nexus_get_bus_tag(device_t, device_t);
71 static bus_bind_intr_t nexus_bind_intr;
73 static bus_config_intr_t nexus_config_intr;
74 static ofw_bus_map_intr_t nexus_ofw_map_intr;
76 static device_method_t nexus_methods[] = {
77 /* Device interface */
78 DEVMETHOD(device_probe, nexus_probe),
79 DEVMETHOD(device_attach, nexus_attach),
82 DEVMETHOD(bus_add_child, bus_generic_add_child),
83 DEVMETHOD(bus_activate_resource, nexus_activate_resource),
84 DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
85 DEVMETHOD(bus_setup_intr, nexus_setup_intr),
86 DEVMETHOD(bus_teardown_intr, nexus_teardown_intr),
88 DEVMETHOD(bus_bind_intr, nexus_bind_intr),
90 DEVMETHOD(bus_config_intr, nexus_config_intr),
91 DEVMETHOD(bus_get_bus_tag, nexus_get_bus_tag),
93 /* ofw_bus interface */
94 DEVMETHOD(ofw_bus_map_intr, nexus_ofw_map_intr),
99 static devclass_t nexus_devclass;
101 DEFINE_CLASS_0(nexus, nexus_driver, nexus_methods, 1);
102 EARLY_DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0,
104 MODULE_VERSION(nexus, 1);
107 nexus_probe(device_t dev)
110 device_quiet(dev); /* suppress attach message for neatness */
112 return (BUS_PROBE_DEFAULT);
116 nexus_attach(device_t dev)
119 bus_generic_probe(dev);
120 bus_generic_attach(dev);
126 nexus_setup_intr(device_t bus __unused, device_t child, struct resource *r,
127 int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
133 panic("%s: NULL interrupt resource!", __func__);
135 if ((rman_get_flags(r) & RF_SHAREABLE) == 0)
138 /* We depend here on rman_activate_resource() being idempotent. */
139 error = rman_activate_resource(r);
143 error = powerpc_setup_intr(device_get_nameunit(child),
144 rman_get_start(r), filt, intr, arg, flags, cookiep);
150 nexus_teardown_intr(device_t bus __unused, device_t child __unused,
151 struct resource *r, void *ih)
157 return (powerpc_teardown_intr(ih));
160 static bus_space_tag_t
161 nexus_get_bus_tag(device_t bus __unused, device_t child __unused)
169 nexus_bind_intr(device_t bus __unused, device_t child __unused,
170 struct resource *r, int cpu)
173 return (powerpc_bind_intr(rman_get_start(r), cpu));
178 nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
179 enum intr_polarity pol)
182 return (powerpc_config_intr(irq, trig, pol));
186 nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int icells,
189 u_int intr = MAP_IRQ(iparent, irq[0]);
191 powerpc_fw_config_intr(intr, irq[1]);
196 nexus_activate_resource(device_t bus __unused, device_t child __unused,
197 int type, int rid __unused, struct resource *r)
200 if (type == SYS_RES_MEMORY) {
204 start = (vm_paddr_t) rman_get_start(r);
206 printf("nexus mapdev: start %jx, len %jd\n",
207 (uintmax_t)start, rman_get_size(r));
209 p = pmap_mapdev(start, (vm_size_t) rman_get_size(r));
212 rman_set_virtual(r, p);
213 rman_set_bustag(r, &bs_be_tag);
214 rman_set_bushandle(r, (u_long)p);
216 return (rman_activate_resource(r));
220 nexus_deactivate_resource(device_t bus __unused, device_t child __unused,
221 int type __unused, int rid __unused, struct resource *r)
225 * If this is a memory resource, unmap it.
227 if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) {
230 psize = rman_get_size(r);
231 pmap_unmapdev((vm_offset_t)rman_get_virtual(r), psize);
234 return (rman_deactivate_resource(r));