dma_sbus.c revision 1.21 1 1.21 pk /* $NetBSD: dma_sbus.c,v 1.21 2004/03/17 17:04:58 pk Exp $ */
2 1.3 pk
3 1.3 pk /*-
4 1.3 pk * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.3 pk * All rights reserved.
6 1.3 pk *
7 1.3 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.3 pk * by Paul Kranenburg.
9 1.3 pk *
10 1.3 pk * Redistribution and use in source and binary forms, with or without
11 1.3 pk * modification, are permitted provided that the following conditions
12 1.3 pk * are met:
13 1.3 pk * 1. Redistributions of source code must retain the above copyright
14 1.3 pk * notice, this list of conditions and the following disclaimer.
15 1.3 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.3 pk * notice, this list of conditions and the following disclaimer in the
17 1.3 pk * documentation and/or other materials provided with the distribution.
18 1.3 pk * 3. All advertising materials mentioning features or use of this software
19 1.3 pk * must display the following acknowledgement:
20 1.3 pk * This product includes software developed by the NetBSD
21 1.3 pk * Foundation, Inc. and its contributors.
22 1.3 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3 pk * contributors may be used to endorse or promote products derived
24 1.3 pk * from this software without specific prior written permission.
25 1.3 pk *
26 1.3 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.3 pk */
38 1.1 pk
39 1.1 pk /*
40 1.1 pk * Copyright (c) 1994 Peter Galbavy. All rights reserved.
41 1.1 pk *
42 1.1 pk * Redistribution and use in source and binary forms, with or without
43 1.1 pk * modification, are permitted provided that the following conditions
44 1.1 pk * are met:
45 1.1 pk * 1. Redistributions of source code must retain the above copyright
46 1.1 pk * notice, this list of conditions and the following disclaimer.
47 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
48 1.1 pk * notice, this list of conditions and the following disclaimer in the
49 1.1 pk * documentation and/or other materials provided with the distribution.
50 1.1 pk * 3. All advertising materials mentioning features or use of this software
51 1.1 pk * must display the following acknowledgement:
52 1.1 pk * This product includes software developed by Peter Galbavy.
53 1.1 pk * 4. The name of the author may not be used to endorse or promote products
54 1.1 pk * derived from this software without specific prior written permission.
55 1.1 pk *
56 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 1.1 pk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 1.1 pk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 1.1 pk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 1.1 pk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 1.1 pk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 1.1 pk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 1.1 pk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 1.1 pk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 1.1 pk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 1.1 pk */
67 1.7 lukem
68 1.7 lukem #include <sys/cdefs.h>
69 1.21 pk __KERNEL_RCSID(0, "$NetBSD: dma_sbus.c,v 1.21 2004/03/17 17:04:58 pk Exp $");
70 1.1 pk
71 1.1 pk #include <sys/param.h>
72 1.1 pk #include <sys/systm.h>
73 1.1 pk #include <sys/kernel.h>
74 1.1 pk #include <sys/errno.h>
75 1.1 pk #include <sys/device.h>
76 1.1 pk #include <sys/malloc.h>
77 1.1 pk
78 1.1 pk #include <machine/bus.h>
79 1.5 pk #include <machine/intr.h>
80 1.1 pk #include <machine/autoconf.h>
81 1.1 pk
82 1.1 pk #include <dev/sbus/sbusvar.h>
83 1.1 pk
84 1.1 pk #include <dev/ic/lsi64854reg.h>
85 1.1 pk #include <dev/ic/lsi64854var.h>
86 1.1 pk
87 1.1 pk struct dma_softc {
88 1.1 pk struct lsi64854_softc sc_lsi64854; /* base device */
89 1.1 pk struct sbusdev sc_sd; /* sbus device */
90 1.1 pk };
91 1.1 pk
92 1.1 pk int dmamatch_sbus __P((struct device *, struct cfdata *, void *));
93 1.1 pk void dmaattach_sbus __P((struct device *, struct device *, void *));
94 1.1 pk
95 1.1 pk int dmaprint_sbus __P((void *, const char *));
96 1.1 pk
97 1.1 pk void *dmabus_intr_establish __P((
98 1.1 pk bus_space_tag_t,
99 1.5 pk int, /*bus interrupt priority*/
100 1.5 pk int, /*`device class' level*/
101 1.1 pk int (*) __P((void *)), /*handler*/
102 1.17 pk void *, /*handler arg*/
103 1.17 pk void (*) __P((void)))); /*optional fast trap handler*/
104 1.1 pk
105 1.1 pk static bus_space_tag_t dma_alloc_bustag __P((struct dma_softc *sc));
106 1.1 pk
107 1.15 thorpej CFATTACH_DECL(dma_sbus, sizeof(struct dma_softc),
108 1.16 thorpej dmamatch_sbus, dmaattach_sbus, NULL, NULL);
109 1.1 pk
110 1.15 thorpej CFATTACH_DECL(ledma, sizeof(struct dma_softc),
111 1.16 thorpej dmamatch_sbus, dmaattach_sbus, NULL, NULL);
112 1.1 pk
113 1.1 pk int
114 1.1 pk dmaprint_sbus(aux, busname)
115 1.1 pk void *aux;
116 1.1 pk const char *busname;
117 1.1 pk {
118 1.1 pk struct sbus_attach_args *sa = aux;
119 1.1 pk bus_space_tag_t t = sa->sa_bustag;
120 1.1 pk struct dma_softc *sc = t->cookie;
121 1.1 pk
122 1.1 pk sa->sa_bustag = sc->sc_lsi64854.sc_bustag; /* XXX */
123 1.1 pk sbus_print(aux, busname); /* XXX */
124 1.1 pk sa->sa_bustag = t; /* XXX */
125 1.1 pk return (UNCONF);
126 1.1 pk }
127 1.1 pk
128 1.1 pk int
129 1.1 pk dmamatch_sbus(parent, cf, aux)
130 1.1 pk struct device *parent;
131 1.1 pk struct cfdata *cf;
132 1.1 pk void *aux;
133 1.1 pk {
134 1.1 pk struct sbus_attach_args *sa = aux;
135 1.1 pk
136 1.12 thorpej return (strcmp(cf->cf_name, sa->sa_name) == 0 ||
137 1.1 pk strcmp("espdma", sa->sa_name) == 0);
138 1.1 pk }
139 1.1 pk
140 1.1 pk void
141 1.1 pk dmaattach_sbus(parent, self, aux)
142 1.1 pk struct device *parent, *self;
143 1.1 pk void *aux;
144 1.1 pk {
145 1.1 pk struct sbus_attach_args *sa = aux;
146 1.1 pk struct dma_softc *dsc = (void *)self;
147 1.1 pk struct lsi64854_softc *sc = &dsc->sc_lsi64854;
148 1.1 pk bus_space_tag_t sbt;
149 1.1 pk int sbusburst, burst;
150 1.1 pk int node;
151 1.1 pk
152 1.1 pk node = sa->sa_node;
153 1.1 pk
154 1.1 pk sc->sc_bustag = sa->sa_bustag;
155 1.1 pk sc->sc_dmatag = sa->sa_dmatag;
156 1.1 pk
157 1.1 pk /* Map registers */
158 1.11 eeh if (sa->sa_npromvaddrs) {
159 1.11 eeh sbus_promaddr_to_handle(sa->sa_bustag,
160 1.11 eeh sa->sa_promvaddrs[0], &sc->sc_regs);
161 1.11 eeh } else {
162 1.10 pk if (sbus_bus_map(sa->sa_bustag,
163 1.11 eeh sa->sa_slot, sa->sa_offset, sa->sa_size,
164 1.11 eeh 0, &sc->sc_regs) != 0) {
165 1.1 pk printf("%s: cannot map registers\n", self->dv_xname);
166 1.1 pk return;
167 1.1 pk }
168 1.1 pk }
169 1.1 pk
170 1.1 pk /*
171 1.1 pk * Get transfer burst size from PROM and plug it into the
172 1.1 pk * controller registers. This is needed on the Sun4m; do
173 1.1 pk * others need it too?
174 1.1 pk */
175 1.1 pk sbusburst = ((struct sbus_softc *)parent)->sc_burst;
176 1.1 pk if (sbusburst == 0)
177 1.1 pk sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
178 1.1 pk
179 1.21 pk burst = prom_getpropint(node,"burst-sizes", -1);
180 1.1 pk if (burst == -1)
181 1.1 pk /* take SBus burst sizes */
182 1.1 pk burst = sbusburst;
183 1.1 pk
184 1.1 pk /* Clamp at parent's burst sizes */
185 1.1 pk burst &= sbusburst;
186 1.1 pk sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
187 1.1 pk (burst & SBUS_BURST_16) ? 16 : 0;
188 1.1 pk
189 1.13 thorpej if (strcmp(sc->sc_dev.dv_cfdata->cf_name, "ledma") == 0) {
190 1.1 pk char *cabletype;
191 1.1 pk u_int32_t csr;
192 1.1 pk /*
193 1.2 pk * Check to see which cable type is currently active and
194 1.2 pk * set the appropriate bit in the ledma csr so that it
195 1.2 pk * gets used. If we didn't netboot, the PROM won't have
196 1.2 pk * the "cable-selection" property; default to TP and then
197 1.2 pk * the user can change it via a "media" option to ifconfig.
198 1.1 pk */
199 1.21 pk cabletype = prom_getpropstring(node, "cable-selection");
200 1.1 pk csr = L64854_GCSR(sc);
201 1.1 pk if (strcmp(cabletype, "tpe") == 0) {
202 1.1 pk csr |= E_TP_AUI;
203 1.1 pk } else if (strcmp(cabletype, "aui") == 0) {
204 1.1 pk csr &= ~E_TP_AUI;
205 1.1 pk } else {
206 1.1 pk /* assume TP if nothing there */
207 1.1 pk csr |= E_TP_AUI;
208 1.1 pk }
209 1.1 pk L64854_SCSR(sc, csr);
210 1.2 pk delay(20000); /* manual says we need a 20ms delay */
211 1.2 pk sc->sc_channel = L64854_CHANNEL_ENET;
212 1.1 pk } else {
213 1.2 pk sc->sc_channel = L64854_CHANNEL_SCSI;
214 1.1 pk }
215 1.1 pk
216 1.1 pk sbus_establish(&dsc->sc_sd, &sc->sc_dev);
217 1.1 pk sbt = dma_alloc_bustag(dsc);
218 1.1 pk lsi64854_attach(sc);
219 1.1 pk
220 1.1 pk /* Attach children */
221 1.1 pk for (node = firstchild(sa->sa_node); node; node = nextsibling(node)) {
222 1.1 pk struct sbus_attach_args sa;
223 1.1 pk sbus_setup_attach_args((struct sbus_softc *)parent,
224 1.4 pk sbt, sc->sc_dmatag, node, &sa);
225 1.1 pk (void) config_found(&sc->sc_dev, (void *)&sa, dmaprint_sbus);
226 1.1 pk sbus_destroy_attach_args(&sa);
227 1.1 pk }
228 1.1 pk }
229 1.1 pk
230 1.1 pk void *
231 1.18 pk dmabus_intr_establish(t, pri, level, handler, arg, fastvec)
232 1.1 pk bus_space_tag_t t;
233 1.5 pk int pri;
234 1.1 pk int level;
235 1.1 pk int (*handler) __P((void *));
236 1.1 pk void *arg;
237 1.17 pk void (*fastvec) __P((void)); /* ignored */
238 1.1 pk {
239 1.1 pk struct lsi64854_softc *sc = t->cookie;
240 1.1 pk
241 1.2 pk /* XXX - for now only le; do esp later */
242 1.2 pk if (sc->sc_channel == L64854_CHANNEL_ENET) {
243 1.1 pk sc->sc_intrchain = handler;
244 1.1 pk sc->sc_intrchainarg = arg;
245 1.1 pk handler = lsi64854_enet_intr;
246 1.1 pk arg = sc;
247 1.1 pk }
248 1.18 pk return (bus_intr_establish(sc->sc_bustag, pri, level,
249 1.5 pk handler, arg));
250 1.1 pk }
251 1.1 pk
252 1.1 pk bus_space_tag_t
253 1.1 pk dma_alloc_bustag(sc)
254 1.1 pk struct dma_softc *sc;
255 1.1 pk {
256 1.1 pk bus_space_tag_t sbt;
257 1.1 pk
258 1.9 tsutsui sbt = (bus_space_tag_t) malloc(sizeof(struct sparc_bus_space_tag),
259 1.9 tsutsui M_DEVBUF, M_NOWAIT|M_ZERO);
260 1.1 pk if (sbt == NULL)
261 1.1 pk return (NULL);
262 1.1 pk
263 1.1 pk sbt->cookie = sc;
264 1.1 pk sbt->parent = sc->sc_lsi64854.sc_bustag;
265 1.1 pk sbt->sparc_intr_establish = dmabus_intr_establish;
266 1.1 pk return (sbt);
267 1.1 pk }
268