2 * Copyright 2003 by Peter Grehan. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * The macio attachment for the OpenPIC interrupt controller.
31 * A nexus driver is defined so the number of interrupts can be
32 * determined early in the boot sequence before the hardware
33 * is accessed - the interrupt i/f is installed at this time,
34 * and when h/w is finally accessed, interrupt sources allocated
35 * prior to this are activated
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/module.h>
46 #include <sys/kernel.h>
48 #include <dev/ofw/ofw_bus.h>
49 #include <dev/ofw/openfirm.h>
51 #include <machine/bus.h>
52 #include <machine/intr.h>
53 #include <machine/intr_machdep.h>
54 #include <machine/md_var.h>
55 #include <machine/nexusvar.h>
56 #include <machine/pio.h>
57 #include <machine/resource.h>
64 #include <machine/openpicvar.h>
68 struct openpic_ofw_softc {
69 struct openpic_softc osc;
70 struct resource *sc_memr; /* macio bus resource */
71 device_t sc_ndev; /* nexus device */
74 static struct openpic_ofw_softc *ofwpicsoftc;
79 static void openpic_ofw_identify(driver_t *, device_t);
80 static int openpic_ofw_probe(device_t);
81 static int openpic_ofw_attach(device_t);
82 static int openpic_macio_probe(device_t);
83 static int openpic_macio_attach(device_t);
88 static device_method_t openpic_ofw_methods[] = {
89 /* Device interface */
90 DEVMETHOD(device_identify, openpic_ofw_identify),
91 DEVMETHOD(device_probe, openpic_ofw_probe),
92 DEVMETHOD(device_attach, openpic_ofw_attach),
95 DEVMETHOD(pic_allocate_intr, openpic_allocate_intr),
96 DEVMETHOD(pic_setup_intr, openpic_setup_intr),
97 DEVMETHOD(pic_teardown_intr, openpic_teardown_intr),
98 DEVMETHOD(pic_release_intr, openpic_release_intr),
103 static driver_t openpic_ofw_driver = {
106 sizeof(struct openpic_ofw_softc)
109 static devclass_t openpic_ofw_devclass;
111 DRIVER_MODULE(openpic_ofw, nexus, openpic_ofw_driver, openpic_ofw_devclass,
115 openpic_ofw_identify(driver_t *driver, device_t parent)
121 pic = OF_finddevice("mpic");
125 OF_getprop(pic, "device_type", type, sizeof(type));
127 if (strcmp(type, "open-pic") != 0)
130 child = BUS_ADD_CHILD(parent, 0, "openpic", 0);
132 nexus_set_device_type(child, "macio");
136 openpic_ofw_probe(device_t dev)
141 name = nexus_get_name(dev);
142 type = nexus_get_device_type(dev);
144 if (strcmp(name, "openpic") != 0 ||
145 strcmp(type, "macio") != 0)
148 device_set_desc(dev, OPENPIC_DEVSTR);
153 openpic_ofw_attach(device_t dev)
155 KASSERT(ofwpicsoftc == NULL, ("ofw openpic: already probed"));
156 ofwpicsoftc = device_get_softc(dev);
157 ofwpicsoftc->sc_ndev = dev;
159 nexus_install_intcntlr(dev);
160 openpic_early_attach(dev);
167 static device_method_t openpic_macio_methods[] = {
168 /* Device interface */
169 DEVMETHOD(device_probe, openpic_macio_probe),
170 DEVMETHOD(device_attach, openpic_macio_attach),
175 static driver_t openpic_macio_driver = {
177 openpic_macio_methods,
181 static devclass_t openpic_macio_devclass;
183 DRIVER_MODULE(openpicmacio, macio, openpic_macio_driver,
184 openpic_macio_devclass, 0, 0);
187 openpic_macio_probe(device_t dev)
189 const char *type = ofw_bus_get_type(dev);
191 if (strcmp(type, "open-pic") != 0)
195 * The description was already printed out in the nexus
196 * probe, so don't do it again here
198 device_set_desc(dev, "OpenPIC MacIO interrupt cell");
205 openpic_macio_attach(device_t dev)
207 struct openpic_ofw_softc *sc;
211 KASSERT(sc != NULL, ("pic not nexus-probed\n"));
214 sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
217 if (sc->sc_memr == NULL) {
218 device_printf(dev, "Could not alloc mem resource!\n");
222 sc->osc.sc_bt = rman_get_bustag(sc->sc_memr);
223 sc->osc.sc_bh = rman_get_bushandle(sc->sc_memr);
224 sc->osc.sc_altdev = dev;
226 return (openpic_attach(sc->sc_ndev));