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