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