dma_sbus.c revision 1.31 1 /* $NetBSD: dma_sbus.c,v 1.31 2008/04/13 04:55:53 tsutsui 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.31 2008/04/13 04:55:53 tsutsui 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 <sys/bus.h>
79 #include <sys/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 struct dma_softc {
88 struct lsi64854_softc sc_lsi64854; /* base device */
89 struct sbusdev sc_sd; /* sbus device */
90 };
91
92 int dmamatch_sbus(device_t, cfdata_t, void *);
93 void dmaattach_sbus(device_t, device_t, void *);
94
95 int dmaprint_sbus(void *, const char *);
96
97 void *dmabus_intr_establish(
98 bus_space_tag_t,
99 int, /*bus interrupt priority*/
100 int, /*`device class' level*/
101 int (*)(void *), /*handler*/
102 void *, /*handler arg*/
103 void (*) (void)); /*optional fast trap handler*/
104
105 CFATTACH_DECL_NEW(dma_sbus, sizeof(struct dma_softc),
106 dmamatch_sbus, dmaattach_sbus, NULL, NULL);
107
108 CFATTACH_DECL_NEW(ledma, sizeof(struct dma_softc),
109 dmamatch_sbus, dmaattach_sbus, NULL, NULL);
110
111 int
112 dmaprint_sbus(void *aux, const char *busname)
113 {
114 struct sbus_attach_args *sa = aux;
115 bus_space_tag_t t = sa->sa_bustag;
116 struct dma_softc *sc = t->cookie;
117
118 sa->sa_bustag = sc->sc_lsi64854.sc_bustag; /* XXX */
119 sbus_print(aux, busname); /* XXX */
120 sa->sa_bustag = t; /* XXX */
121 return UNCONF;
122 }
123
124 int
125 dmamatch_sbus(struct device *parent, struct cfdata *cf, void *aux)
126 {
127 struct sbus_attach_args *sa = aux;
128
129 return strcmp(cf->cf_name, sa->sa_name) == 0 ||
130 strcmp("espdma", sa->sa_name) == 0;
131 }
132
133 void
134 dmaattach_sbus(device_t parent, device_t self, void *aux)
135 {
136 struct dma_softc *dsc = device_private(self);
137 struct lsi64854_softc *sc = &dsc->sc_lsi64854;
138 struct sbus_attach_args *sa = aux;
139 struct sbus_softc *sbsc = device_private(parent);
140 bus_space_tag_t sbt;
141 int sbusburst, burst;
142 int node;
143
144 node = sa->sa_node;
145
146 sc->sc_dev = self;
147 sc->sc_bustag = sa->sa_bustag;
148 sc->sc_dmatag = sa->sa_dmatag;
149
150 /* Map registers */
151 if (sa->sa_npromvaddrs) {
152 sbus_promaddr_to_handle(sa->sa_bustag,
153 sa->sa_promvaddrs[0], &sc->sc_regs);
154 } else {
155 if (sbus_bus_map(sa->sa_bustag,
156 sa->sa_slot, sa->sa_offset, sa->sa_size,
157 0, &sc->sc_regs) != 0) {
158 aprint_error(": cannot map registers\n");
159 return;
160 }
161 }
162
163 /*
164 * Get transfer burst size from PROM and plug it into the
165 * controller registers. This is needed on the Sun4m; do
166 * others need it too?
167 */
168 sbusburst = sbsc->sc_burst;
169 if (sbusburst == 0)
170 sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
171
172 burst = prom_getpropint(node,"burst-sizes", -1);
173 if (burst == -1)
174 /* take SBus burst sizes */
175 burst = sbusburst;
176
177 /* Clamp at parent's burst sizes */
178 burst &= sbusburst;
179 sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
180 (burst & SBUS_BURST_16) ? 16 : 0;
181
182 if (device_is_a(self, "ledma")) {
183 char *cabletype;
184 uint32_t csr;
185 /*
186 * Check to see which cable type is currently active and
187 * set the appropriate bit in the ledma csr so that it
188 * gets used. If we didn't netboot, the PROM won't have
189 * the "cable-selection" property; default to TP and then
190 * the user can change it via a "media" option to ifconfig.
191 */
192 cabletype = prom_getpropstring(node, "cable-selection");
193 csr = L64854_GCSR(sc);
194 if (strcmp(cabletype, "tpe") == 0) {
195 csr |= E_TP_AUI;
196 } else if (strcmp(cabletype, "aui") == 0) {
197 csr &= ~E_TP_AUI;
198 } else {
199 /* assume TP if nothing there */
200 csr |= E_TP_AUI;
201 }
202 L64854_SCSR(sc, csr);
203 delay(20000); /* manual says we need a 20ms delay */
204 sc->sc_channel = L64854_CHANNEL_ENET;
205 } else {
206 sc->sc_channel = L64854_CHANNEL_SCSI;
207 }
208
209 sbus_establish(&dsc->sc_sd, self);
210 if ((sbt = bus_space_tag_alloc(sc->sc_bustag, dsc)) == NULL) {
211 aprint_error(": out of memory\n");
212 return;
213 }
214 sbt->sparc_intr_establish = dmabus_intr_establish;
215 lsi64854_attach(sc);
216
217 /* Attach children */
218 for (node = firstchild(sa->sa_node); node; node = nextsibling(node)) {
219 struct sbus_attach_args sax;
220 sbus_setup_attach_args(sbsc, sbt, sc->sc_dmatag, node, &sax);
221 (void)config_found(self, (void *)&sax, dmaprint_sbus);
222 sbus_destroy_attach_args(&sax);
223 }
224 }
225
226 void *
227 dmabus_intr_establish(bus_space_tag_t t, int pri, int level,
228 int (*handler)(void *), void *arg, void (*fastvec)(void))
229 {
230 struct lsi64854_softc *sc = t->cookie;
231
232 /* XXX - for now only le; do esp later */
233 if (sc->sc_channel == L64854_CHANNEL_ENET) {
234 sc->sc_intrchain = handler;
235 sc->sc_intrchainarg = arg;
236 handler = lsi64854_enet_intr;
237 arg = sc;
238 }
239 return bus_intr_establish(sc->sc_bustag, pri, level, handler, arg);
240 }
241