]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/powerpc/mpc85xx/nexus.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / powerpc / mpc85xx / nexus.c
1 /*-
2  * Copyright 1998 Massachusetts Institute of Technology
3  *
4  * Permission to use, copy, modify, and distribute this software and
5  * its documentation for any purpose and without fee is hereby
6  * granted, provided that both the above copyright notice and this
7  * permission notice appear in all copies, that both the above
8  * copyright notice and this permission notice appear in all
9  * supporting documentation, and that the name of M.I.T. not be used
10  * in advertising or publicity pertaining to distribution of the
11  * software without specific, written prior permission.  M.I.T. makes
12  * no representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied
14  * warranty.
15  *
16  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
17  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 /*-
30  * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>.  All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions
34  * are met:
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  * 2. Redistributions in binary form must reproduce the above copyright
38  *    notice, this list of conditions and the following disclaimer in the
39  *    documentation and/or other materials provided with the distribution.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  *
53  *      from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09
54  */
55
56 #include <sys/cdefs.h>
57 __FBSDID("$FreeBSD$");
58
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/module.h>
62 #include <sys/bus.h>
63 #include <sys/cons.h>
64 #include <sys/kernel.h>
65 #include <sys/malloc.h>
66 #include <sys/rman.h>
67
68 #include <machine/intr_machdep.h>
69
70 /*
71  * Device interface
72  */
73 static int      nexus_probe(device_t);
74 static int      nexus_attach(device_t);
75 static int      nexus_activate_resource(device_t, device_t, int, int,
76     struct resource *);
77 static int      nexus_deactivate_resource(device_t, device_t, int, int,
78     struct resource *);
79
80 static int      nexus_config_intr(device_t, int, enum intr_trigger,
81     enum intr_polarity);
82 static int      nexus_setup_intr(device_t, device_t, struct resource *, int,
83     driver_filter_t *, driver_intr_t *, void *, void **);
84 static int      nexus_teardown_intr(device_t, device_t, struct resource *,
85     void *);
86
87 static device_method_t nexus_methods[] = {
88         /* Device interface */
89         DEVMETHOD(device_probe,         nexus_probe),
90         DEVMETHOD(device_attach,        nexus_attach),
91         DEVMETHOD(device_detach,        bus_generic_detach),
92         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
93         DEVMETHOD(device_suspend,       bus_generic_suspend),
94         DEVMETHOD(device_resume,        bus_generic_resume),
95
96         /* Bus interface. Resource management is business of the children... */
97         DEVMETHOD(bus_add_child,        bus_generic_add_child),
98         DEVMETHOD(bus_probe_nomatch,    NULL),
99         DEVMETHOD(bus_read_ivar,        NULL),
100         DEVMETHOD(bus_write_ivar,       NULL),
101         DEVMETHOD(bus_config_intr,      nexus_config_intr),
102         DEVMETHOD(bus_setup_intr,       nexus_setup_intr),
103         DEVMETHOD(bus_teardown_intr,    nexus_teardown_intr),
104         DEVMETHOD(bus_alloc_resource,   NULL),
105         DEVMETHOD(bus_activate_resource,        nexus_activate_resource),
106         DEVMETHOD(bus_deactivate_resource,      nexus_deactivate_resource),
107         DEVMETHOD(bus_release_resource, NULL),
108
109         DEVMETHOD_END
110 };
111
112 static driver_t nexus_driver = {
113         "nexus",
114         nexus_methods
115 };
116
117 static devclass_t nexus_devclass;
118
119 DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0);
120
121 static int
122 nexus_probe(device_t dev)
123 {
124
125         if (!bootverbose)
126                 device_quiet(dev);
127         return (BUS_PROBE_DEFAULT);
128 }
129
130 static int
131 nexus_attach(device_t dev)
132 {
133
134         bus_generic_probe(dev);
135         bus_generic_attach(dev);
136         return (0);
137 }
138
139 static int
140 nexus_activate_resource(device_t bus, device_t child, int type, int rid,
141     struct resource *res)
142 {
143
144         /* Not much to be done yet... */
145         return (rman_activate_resource(res));
146 }
147
148 static int
149 nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
150     struct resource *res)
151 {
152
153         /* Not much to be done yet... */
154         return (rman_deactivate_resource(res));
155 }
156
157 static int
158 nexus_config_intr(device_t bus, int irq, enum intr_trigger trig,
159     enum intr_polarity pol)
160 {
161
162         return (powerpc_config_intr(irq, trig, pol));
163 }
164
165 static int
166 nexus_setup_intr(device_t bus, device_t child, struct resource *res, int flags,
167     driver_filter_t *ifilt, driver_intr_t *ihand, void *arg, void **cookiep)
168 {
169         int error;
170
171         *cookiep = NULL;
172
173         /* somebody tried to setup an irq that failed to allocate! */
174         if (res == NULL)
175                 return (EINVAL);
176
177         if ((rman_get_flags(res) & RF_SHAREABLE) == 0)
178                 flags |= INTR_EXCL;
179
180         /* We depend on rman_activate_resource() being idempotent. */
181         error = rman_activate_resource(res);
182         if (error)
183                 return (error);
184
185         error = powerpc_setup_intr(device_get_nameunit(child),
186             rman_get_start(res), ifilt, ihand, arg, flags, cookiep);
187         return (error);
188 }
189
190 static int
191 nexus_teardown_intr(device_t bus, device_t child, struct resource *res,
192     void *cookie)
193 {
194         int error;
195
196         if (res == NULL)
197                 return (EINVAL);
198
199         error = powerpc_teardown_intr(cookie);
200         return (error);
201 }