]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/sys/powerpc/psim/openpic_iobus.c
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / 6 / sys / powerpc / psim / openpic_iobus.c
1 /*-
2  * Copyright 2003 by Peter Grehan. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
27  */
28
29 /*
30  * The psim iobus attachment for the OpenPIC interrupt controller.
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/module.h>
39 #include <sys/bus.h>
40 #include <sys/conf.h>
41 #include <sys/kernel.h>
42
43 #include <dev/ofw/openfirm.h>
44
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47 #include <machine/intr_machdep.h>
48 #include <machine/md_var.h>
49 #include <machine/nexusvar.h>
50 #include <machine/pio.h>
51 #include <machine/resource.h>
52
53 #include <vm/vm.h>
54 #include <vm/pmap.h>
55
56 #include <sys/rman.h>
57
58 #include <machine/openpicvar.h>
59 #include <powerpc/psim/iobusvar.h>
60
61 #include "pic_if.h"
62
63 struct openpic_iobus_softc {
64         struct openpic_softc osc;
65         struct resource *sc_memr;       /* iobus mem resource */
66         device_t        sc_ndev;        /* nexus device */
67 };
68
69 static struct openpic_iobus_softc *ppicsoftc;
70
71 /*
72  * MacIO interface
73  */
74 static void     openpic_psim_identify(driver_t *, device_t);
75 static int      openpic_psim_probe(device_t);
76 static int      openpic_psim_attach(device_t);
77 static int      openpic_iobus_probe(device_t);
78 static int      openpic_iobus_attach(device_t);
79
80 /*
81  * Nexus attachment
82  */
83 static device_method_t  openpic_psim_methods[] = {
84         /* Device interface */
85         DEVMETHOD(device_identify,      openpic_psim_identify),
86         DEVMETHOD(device_probe,         openpic_psim_probe),
87         DEVMETHOD(device_attach,        openpic_psim_attach),
88
89         /* PIC interface */
90         DEVMETHOD(pic_allocate_intr,    openpic_allocate_intr),
91         DEVMETHOD(pic_setup_intr,       openpic_setup_intr),
92         DEVMETHOD(pic_teardown_intr,    openpic_teardown_intr),
93         DEVMETHOD(pic_release_intr,     openpic_release_intr),
94
95         { 0, 0 }
96 };
97
98 static driver_t openpic_psim_driver = {
99         "openpic",
100         openpic_psim_methods,
101         sizeof(struct openpic_iobus_softc)
102 };
103
104 static devclass_t openpic_psim_devclass;
105
106 DRIVER_MODULE(openpic_psim, nexus, openpic_psim_driver, openpic_psim_devclass, 
107     0, 0);
108
109 static void
110 openpic_psim_identify(driver_t *driver, device_t parent)
111 {
112         device_t child;
113         phandle_t pic;
114
115         pic = OF_finddevice("/iobus/opic");
116         if (pic == -1)
117                 return;
118
119         child = BUS_ADD_CHILD(parent, 0, "openpic", 0);
120         if (child != NULL)
121                 nexus_set_device_type(child, "psim");           
122 }
123
124 static int
125 openpic_psim_probe(device_t dev)
126 {
127         char    *name;
128         char    *type;
129
130         name = nexus_get_name(dev);
131         type = nexus_get_device_type(dev);
132
133         if (strcmp(name, "openpic") != 0 ||
134             strcmp(type, "psim") != 0)
135                 return (ENXIO);
136         
137         device_set_desc(dev, OPENPIC_DEVSTR);
138         return (0);     
139 }
140
141 static int
142 openpic_psim_attach(device_t dev)
143 {
144         KASSERT(ppicsoftc == NULL, ("iobus openpic: already probed"));
145         ppicsoftc = device_get_softc(dev);
146         ppicsoftc->sc_ndev = dev;
147
148         nexus_install_intcntlr(dev);
149         openpic_early_attach(dev);
150         return (0);
151 }
152
153 /*
154  * PSIM IOBus attachment
155  */
156 static device_method_t  openpic_iobus_methods[] = {
157         /* Device interface */
158         DEVMETHOD(device_probe,         openpic_iobus_probe),
159         DEVMETHOD(device_attach,        openpic_iobus_attach),
160
161         { 0, 0 },
162 };
163
164 static driver_t openpic_iobus_driver = {
165         "openpiciobus",
166         openpic_iobus_methods,
167         0
168 };
169
170 static devclass_t openpic_iobus_devclass;
171
172 DRIVER_MODULE(openpiciobus, iobus, openpic_iobus_driver, 
173     openpic_iobus_devclass, 0, 0);
174
175 static int
176 openpic_iobus_probe(device_t dev)
177 {
178         char *name;
179
180         name = iobus_get_name(dev);
181         if (strcmp(name, "interrupt-controller") != 0)
182                 return (ENXIO);
183
184         /*
185          * The description was already printed out in the nexus
186          * probe, so don't do it again here
187          */
188         device_set_desc(dev, "OpenPIC IOBus interrupt cell");
189         if (!bootverbose)
190                 device_quiet(dev);
191         return (0);
192 }
193
194 static int
195 openpic_iobus_attach(device_t dev)
196 {
197         struct openpic_iobus_softc *sc;
198         int rid;
199
200         sc = ppicsoftc;
201         KASSERT(sc != NULL, ("pic not nexus-probed\n"));
202
203         rid = 0;
204         sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
205              RF_ACTIVE);
206
207         if (sc->sc_memr == NULL) {
208                 device_printf(dev, "Could not alloc mem resource!\n");
209                 return (ENXIO);
210         }
211
212         sc->osc.sc_psim = 1;
213         sc->osc.sc_bt = rman_get_bustag(sc->sc_memr);
214         sc->osc.sc_bh = rman_get_bushandle(sc->sc_memr);
215         sc->osc.sc_altdev = dev;
216
217         return (openpic_attach(sc->sc_ndev));
218 }
219
220