2 * Copyright 2008 by Nathan Whitehorn. 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.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
20 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/module.h>
35 #include <sys/kernel.h>
37 #include <dev/ofw/ofw_bus.h>
38 #include <dev/ofw/openfirm.h>
40 #include <machine/bus.h>
41 #include <machine/intr_machdep.h>
42 #include <machine/md_var.h>
43 #include <machine/pio.h>
44 #include <machine/resource.h>
51 #include <machine/openpicvar.h>
58 static int openpic_mambo_probe(device_t);
59 static int openpic_mambo_attach(device_t);
60 static int openpicbus_mambo_probe(device_t dev);
61 static int openpicbus_mambo_attach(device_t dev);
62 static struct resource *openpicbus_alloc_resource(device_t bus, device_t dev,
63 int type, int *rid, u_long start, u_long end, u_long count, u_int flags);
65 static device_method_t openpicbus_mambo_methods[] = {
66 /* Device interface */
67 DEVMETHOD(device_probe, openpicbus_mambo_probe),
68 DEVMETHOD(device_attach, openpicbus_mambo_attach),
71 DEVMETHOD(bus_alloc_resource, openpicbus_alloc_resource),
76 struct openpicbus_softc {
80 static driver_t openpicbus_mambo_driver = {
82 openpicbus_mambo_methods,
83 sizeof(struct openpicbus_softc),
86 static device_method_t openpic_mambo_methods[] = {
87 /* Device interface */
88 DEVMETHOD(device_probe, openpic_mambo_probe),
89 DEVMETHOD(device_attach, openpic_mambo_attach),
92 DEVMETHOD(pic_config, openpic_config),
93 DEVMETHOD(pic_dispatch, openpic_dispatch),
94 DEVMETHOD(pic_enable, openpic_enable),
95 DEVMETHOD(pic_eoi, openpic_eoi),
96 DEVMETHOD(pic_ipi, openpic_ipi),
97 DEVMETHOD(pic_mask, openpic_mask),
98 DEVMETHOD(pic_unmask, openpic_unmask),
103 static driver_t openpic_mambo_driver = {
105 openpic_mambo_methods,
106 sizeof(struct openpic_softc),
109 static devclass_t openpicbus_devclass;
111 DRIVER_MODULE(openpicbus, nexus, openpicbus_mambo_driver,
112 openpicbus_devclass, 0, 0);
113 DRIVER_MODULE(openpic, openpicbus, openpic_mambo_driver,
114 openpic_devclass, 0, 0);
117 openpicbus_mambo_probe(device_t dev)
119 const char *type = ofw_bus_get_type(dev);
121 if (type == NULL || strcmp(type, "open-pic") != 0)
124 device_set_desc(dev, "Mambo OpenPIC Container");
130 openpicbus_mambo_attach(device_t dev)
134 struct openpicbus_softc *sc;
136 sc = device_get_softc(dev);
138 nexus = OF_parent(ofw_bus_get_node(dev));
140 OF_getprop(nexus,"platform-open-pic",
141 &picaddr,sizeof(picaddr));
143 sc->picaddr = picaddr;
145 device_add_child(dev,"openpic",-1);
147 return (bus_generic_attach(dev));
150 static struct resource *
151 openpicbus_alloc_resource(device_t bus, device_t dev, int type, int *rid,
152 u_long start, u_long end, u_long count, u_int flags)
154 struct openpicbus_softc *sc;
156 sc = device_get_softc(bus);
162 return (bus_alloc_resource(bus, type, rid, start, end, count, flags));
166 openpic_mambo_probe(device_t dev)
169 device_set_desc(dev, OPENPIC_DEVSTR);
174 openpic_mambo_attach(device_t dev)
177 return (openpic_common_attach(dev,
178 ofw_bus_get_node(device_get_parent(dev))));