nextdma.c revision 1.30 1 1.30 christos /* $NetBSD: nextdma.c,v 1.30 2002/07/11 16:03:12 christos Exp $ */
2 1.1 dbj /*
3 1.1 dbj * Copyright (c) 1998 Darrin B. Jewell
4 1.1 dbj * All rights reserved.
5 1.1 dbj *
6 1.1 dbj * Redistribution and use in source and binary forms, with or without
7 1.1 dbj * modification, are permitted provided that the following conditions
8 1.1 dbj * are met:
9 1.1 dbj * 1. Redistributions of source code must retain the above copyright
10 1.1 dbj * notice, this list of conditions and the following disclaimer.
11 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 dbj * notice, this list of conditions and the following disclaimer in the
13 1.1 dbj * documentation and/or other materials provided with the distribution.
14 1.1 dbj * 3. All advertising materials mentioning features or use of this software
15 1.1 dbj * must display the following acknowledgement:
16 1.1 dbj * This product includes software developed by Darrin B. Jewell
17 1.1 dbj * 4. The name of the author may not be used to endorse or promote products
18 1.1 dbj * derived from this software without specific prior written permission
19 1.1 dbj *
20 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 dbj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 dbj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 dbj * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 dbj * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 dbj * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 dbj * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 dbj * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 dbj * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 dbj * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 dbj */
31 1.1 dbj
32 1.1 dbj #include <sys/param.h>
33 1.1 dbj #include <sys/systm.h>
34 1.1 dbj #include <sys/mbuf.h>
35 1.1 dbj #include <sys/syslog.h>
36 1.1 dbj #include <sys/socket.h>
37 1.1 dbj #include <sys/device.h>
38 1.1 dbj #include <sys/malloc.h>
39 1.1 dbj #include <sys/ioctl.h>
40 1.1 dbj #include <sys/errno.h>
41 1.1 dbj
42 1.1 dbj #include <machine/autoconf.h>
43 1.1 dbj #include <machine/cpu.h>
44 1.1 dbj #include <machine/intr.h>
45 1.5 dbj
46 1.5 dbj #include <m68k/cacheops.h>
47 1.1 dbj
48 1.1 dbj #include <next68k/next68k/isr.h>
49 1.1 dbj
50 1.16 dbj #define _NEXT68K_BUS_DMA_PRIVATE
51 1.1 dbj #include <machine/bus.h>
52 1.1 dbj
53 1.1 dbj #include "nextdmareg.h"
54 1.1 dbj #include "nextdmavar.h"
55 1.1 dbj
56 1.8 dbj #if 1
57 1.1 dbj #define ND_DEBUG
58 1.1 dbj #endif
59 1.1 dbj
60 1.30 christos /* #define panic __asm __volatile("trap #15"); printf */
61 1.30 christos
62 1.30 christos #define NEXTDMA_DEBUG nd->nd_continue_cb == esp_dmacb_continue && nextdma_debug
63 1.1 dbj #if defined(ND_DEBUG)
64 1.8 dbj int nextdma_debug = 0;
65 1.30 christos bus_dmamap_t esp_dmacb_continue __P((void *));
66 1.30 christos #define DPRINTF(x) if (NEXTDMA_DEBUG) printf x;
67 1.1 dbj #else
68 1.1 dbj #define DPRINTF(x)
69 1.1 dbj #endif
70 1.30 christos #define PRINTF printf
71 1.30 christos extern char *esplogp, *esplog;
72 1.30 christos #define ESPLOGIF (10 && nd->nd_intr == NEXT_I_SCSI_DMA && esplogp < (esplog + 8192))
73 1.1 dbj
74 1.26 dbj #if defined(ND_DEBUG)
75 1.26 dbj int nextdma_debug_enetr_idx = 0;
76 1.26 dbj unsigned int nextdma_debug_enetr_state[100] = { 0 };
77 1.26 dbj int nextdma_debug_scsi_idx = 0;
78 1.26 dbj unsigned int nextdma_debug_scsi_state[100] = { 0 };
79 1.26 dbj
80 1.26 dbj void nextdma_debug_initstate(struct nextdma_config *nd);
81 1.26 dbj void nextdma_debug_savestate(struct nextdma_config *nd, unsigned int state);
82 1.26 dbj void nextdma_debug_scsi_dumpstate(void);
83 1.26 dbj void nextdma_debug_enetr_dumpstate(void);
84 1.26 dbj
85 1.26 dbj void
86 1.26 dbj nextdma_debug_initstate(struct nextdma_config *nd)
87 1.26 dbj {
88 1.26 dbj switch(nd->nd_intr) {
89 1.26 dbj case NEXT_I_ENETR_DMA:
90 1.26 dbj memset(nextdma_debug_enetr_state,0,sizeof(nextdma_debug_enetr_state));
91 1.26 dbj break;
92 1.26 dbj case NEXT_I_SCSI_DMA:
93 1.26 dbj memset(nextdma_debug_scsi_state,0,sizeof(nextdma_debug_scsi_state));
94 1.26 dbj break;
95 1.26 dbj }
96 1.26 dbj }
97 1.26 dbj
98 1.26 dbj void
99 1.26 dbj nextdma_debug_savestate(struct nextdma_config *nd, unsigned int state)
100 1.26 dbj {
101 1.26 dbj switch(nd->nd_intr) {
102 1.26 dbj case NEXT_I_ENETR_DMA:
103 1.26 dbj nextdma_debug_enetr_state[nextdma_debug_enetr_idx++] = state;
104 1.26 dbj nextdma_debug_enetr_idx %= (sizeof(nextdma_debug_enetr_state)/sizeof(unsigned int));
105 1.26 dbj break;
106 1.26 dbj case NEXT_I_SCSI_DMA:
107 1.26 dbj nextdma_debug_scsi_state[nextdma_debug_scsi_idx++] = state;
108 1.26 dbj nextdma_debug_scsi_idx %= (sizeof(nextdma_debug_scsi_state)/sizeof(unsigned int));
109 1.26 dbj break;
110 1.26 dbj }
111 1.26 dbj }
112 1.26 dbj
113 1.26 dbj void
114 1.26 dbj nextdma_debug_enetr_dumpstate(void)
115 1.26 dbj {
116 1.26 dbj int i;
117 1.26 dbj int s;
118 1.26 dbj s = spldma();
119 1.26 dbj i = nextdma_debug_enetr_idx;
120 1.26 dbj do {
121 1.26 dbj char sbuf[256];
122 1.26 dbj if (nextdma_debug_enetr_state[i]) {
123 1.26 dbj bitmask_snprintf(nextdma_debug_enetr_state[i], DMACSR_BITS, sbuf, sizeof(sbuf));
124 1.26 dbj printf("DMA: 0x%02x state 0x%s\n",i,sbuf);
125 1.26 dbj }
126 1.26 dbj i++;
127 1.26 dbj i %= (sizeof(nextdma_debug_enetr_state)/sizeof(unsigned int));
128 1.26 dbj } while (i != nextdma_debug_enetr_idx);
129 1.26 dbj splx(s);
130 1.26 dbj }
131 1.26 dbj
132 1.26 dbj void
133 1.26 dbj nextdma_debug_scsi_dumpstate(void)
134 1.26 dbj {
135 1.26 dbj int i;
136 1.26 dbj int s;
137 1.26 dbj s = spldma();
138 1.26 dbj i = nextdma_debug_scsi_idx;
139 1.26 dbj do {
140 1.26 dbj char sbuf[256];
141 1.26 dbj if (nextdma_debug_scsi_state[i]) {
142 1.26 dbj bitmask_snprintf(nextdma_debug_scsi_state[i], DMACSR_BITS, sbuf, sizeof(sbuf));
143 1.26 dbj printf("DMA: 0x%02x state 0x%s\n",i,sbuf);
144 1.26 dbj }
145 1.26 dbj i++;
146 1.26 dbj i %= (sizeof(nextdma_debug_scsi_state)/sizeof(unsigned int));
147 1.26 dbj } while (i != nextdma_debug_scsi_idx);
148 1.26 dbj splx(s);
149 1.26 dbj }
150 1.26 dbj #endif
151 1.26 dbj
152 1.26 dbj
153 1.1 dbj void next_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
154 1.1 dbj bus_size_t, int));
155 1.1 dbj int next_dma_continue __P((struct nextdma_config *));
156 1.1 dbj void next_dma_rotate __P((struct nextdma_config *));
157 1.1 dbj
158 1.1 dbj void next_dma_setup_cont_regs __P((struct nextdma_config *));
159 1.1 dbj void next_dma_setup_curr_regs __P((struct nextdma_config *));
160 1.1 dbj
161 1.1 dbj void
162 1.1 dbj nextdma_config(nd)
163 1.1 dbj struct nextdma_config *nd;
164 1.1 dbj {
165 1.1 dbj /* Initialize the dma_tag. As a hack, we currently
166 1.1 dbj * put the dma tag in the structure itself. It shouldn't be there.
167 1.1 dbj */
168 1.1 dbj
169 1.1 dbj {
170 1.1 dbj bus_dma_tag_t t;
171 1.1 dbj t = &nd->_nd_dmat;
172 1.1 dbj t->_cookie = nd;
173 1.1 dbj t->_dmamap_create = _bus_dmamap_create;
174 1.1 dbj t->_dmamap_destroy = _bus_dmamap_destroy;
175 1.1 dbj t->_dmamap_load = _bus_dmamap_load_direct;
176 1.1 dbj t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
177 1.1 dbj t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
178 1.1 dbj t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
179 1.1 dbj t->_dmamap_unload = _bus_dmamap_unload;
180 1.16 dbj t->_dmamap_sync = _bus_dmamap_sync;
181 1.1 dbj
182 1.1 dbj t->_dmamem_alloc = _bus_dmamem_alloc;
183 1.1 dbj t->_dmamem_free = _bus_dmamem_free;
184 1.1 dbj t->_dmamem_map = _bus_dmamem_map;
185 1.1 dbj t->_dmamem_unmap = _bus_dmamem_unmap;
186 1.1 dbj t->_dmamem_mmap = _bus_dmamem_mmap;
187 1.1 dbj
188 1.1 dbj nd->nd_dmat = t;
189 1.1 dbj }
190 1.1 dbj
191 1.30 christos isrlink_autovec(nextdma_intr, nd, NEXT_I_IPL(nd->nd_intr), 10);
192 1.30 christos INTR_ENABLE(nd->nd_intr);
193 1.30 christos
194 1.1 dbj nextdma_init(nd);
195 1.1 dbj
196 1.1 dbj }
197 1.1 dbj
198 1.1 dbj void
199 1.1 dbj nextdma_init(nd)
200 1.1 dbj struct nextdma_config *nd;
201 1.1 dbj {
202 1.22 tv #ifdef ND_DEBUG
203 1.30 christos if (NEXTDMA_DEBUG) {
204 1.22 tv char sbuf[256];
205 1.22 tv
206 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
207 1.22 tv sbuf, sizeof(sbuf));
208 1.22 tv printf("DMA init ipl (%ld) intr(0x%s)\n",
209 1.22 tv NEXT_I_IPL(nd->nd_intr), sbuf);
210 1.22 tv }
211 1.22 tv #endif
212 1.1 dbj
213 1.1 dbj nd->_nd_map = NULL;
214 1.1 dbj nd->_nd_idx = 0;
215 1.1 dbj nd->_nd_map_cont = NULL;
216 1.1 dbj nd->_nd_idx_cont = 0;
217 1.1 dbj
218 1.1 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, 0);
219 1.1 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
220 1.20 dbj DMACSR_RESET | DMACSR_INITBUF);
221 1.1 dbj
222 1.1 dbj next_dma_setup_curr_regs(nd);
223 1.1 dbj next_dma_setup_cont_regs(nd);
224 1.1 dbj
225 1.20 dbj #if defined(DIAGNOSTIC)
226 1.1 dbj {
227 1.1 dbj u_long state;
228 1.1 dbj state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
229 1.20 dbj
230 1.20 dbj #if 1
231 1.20 dbj /* mourning (a 25Mhz 68040 mono slab) appears to set BUSEXC
232 1.20 dbj * milo (a 25Mhz 68040 mono cube) didn't have this problem
233 1.20 dbj * Darrin B. Jewell <jewell (at) mit.edu> Mon May 25 07:53:05 1998
234 1.20 dbj */
235 1.20 dbj state &= (DMACSR_COMPLETE | DMACSR_SUPDATE | DMACSR_ENABLE);
236 1.20 dbj #else
237 1.1 dbj state &= (DMACSR_BUSEXC | DMACSR_COMPLETE |
238 1.1 dbj DMACSR_SUPDATE | DMACSR_ENABLE);
239 1.20 dbj #endif
240 1.1 dbj if (state) {
241 1.1 dbj next_dma_print(nd);
242 1.20 dbj panic("DMA did not reset");
243 1.1 dbj }
244 1.1 dbj }
245 1.1 dbj #endif
246 1.1 dbj }
247 1.1 dbj
248 1.4 dbj
249 1.1 dbj void
250 1.1 dbj nextdma_reset(nd)
251 1.1 dbj struct nextdma_config *nd;
252 1.1 dbj {
253 1.1 dbj int s;
254 1.18 dbj s = spldma();
255 1.8 dbj
256 1.8 dbj DPRINTF(("DMA reset\n"));
257 1.8 dbj
258 1.8 dbj #if (defined(ND_DEBUG))
259 1.30 christos if (NEXTDMA_DEBUG) next_dma_print(nd);
260 1.8 dbj #endif
261 1.8 dbj
262 1.30 christos bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
263 1.26 dbj if ((nd->_nd_map) || (nd->_nd_map_cont)) {
264 1.26 dbj /* @@@ clean up dma maps */
265 1.30 christos /* panic("DMA abort not implemented\n"); */
266 1.30 christos if (nd->_nd_map_cont) {
267 1.30 christos DPRINTF(("DMA: resetting with non null continue map\n"));
268 1.30 christos if (nd->nd_completed_cb)
269 1.30 christos (*nd->nd_completed_cb)(nd->_nd_map_cont, nd->nd_cb_arg);
270 1.30 christos
271 1.30 christos nd->_nd_map_cont = 0;
272 1.30 christos nd->_nd_idx_cont = 0;
273 1.30 christos }
274 1.30 christos if (nd->nd_shutdown_cb) (*nd->nd_shutdown_cb)(nd->nd_cb_arg);
275 1.30 christos nd->_nd_map = 0;
276 1.30 christos nd->_nd_idx = 0;
277 1.26 dbj }
278 1.20 dbj
279 1.30 christos /* nextdma_init(nd); */
280 1.1 dbj splx(s);
281 1.1 dbj }
282 1.1 dbj
283 1.1 dbj /****************************************************************/
284 1.1 dbj
285 1.1 dbj
286 1.1 dbj /* Call the completed and continue callbacks to try to fill
287 1.1 dbj * in the dma continue buffers.
288 1.1 dbj */
289 1.1 dbj void
290 1.1 dbj next_dma_rotate(nd)
291 1.1 dbj struct nextdma_config *nd;
292 1.1 dbj {
293 1.1 dbj
294 1.30 christos if (ESPLOGIF) *esplogp++ = 'r';
295 1.1 dbj DPRINTF(("DMA next_dma_rotate()\n"));
296 1.1 dbj
297 1.1 dbj /* Rotate the continue map into the current map */
298 1.1 dbj nd->_nd_map = nd->_nd_map_cont;
299 1.1 dbj nd->_nd_idx = nd->_nd_idx_cont;
300 1.1 dbj
301 1.1 dbj if ((!nd->_nd_map_cont) ||
302 1.1 dbj ((nd->_nd_map_cont) &&
303 1.1 dbj (++nd->_nd_idx_cont >= nd->_nd_map_cont->dm_nsegs))) {
304 1.1 dbj if (nd->nd_continue_cb) {
305 1.1 dbj nd->_nd_map_cont = (*nd->nd_continue_cb)(nd->nd_cb_arg);
306 1.26 dbj if (nd->_nd_map_cont) {
307 1.26 dbj nd->_nd_map_cont->dm_xfer_len = 0;
308 1.26 dbj }
309 1.1 dbj } else {
310 1.1 dbj nd->_nd_map_cont = 0;
311 1.1 dbj }
312 1.1 dbj nd->_nd_idx_cont = 0;
313 1.1 dbj }
314 1.7 dbj
315 1.29 dbj #if defined(DIAGNOSTIC) && 0
316 1.24 dbj if (nd->_nd_map_cont) {
317 1.12 dbj if (!DMA_BEGINALIGNED(nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr)) {
318 1.12 dbj next_dma_print(nd);
319 1.7 dbj panic("DMA request unaligned at start\n");
320 1.7 dbj }
321 1.12 dbj if (!DMA_ENDALIGNED(nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
322 1.12 dbj nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len)) {
323 1.12 dbj next_dma_print(nd);
324 1.7 dbj panic("DMA request unaligned at end\n");
325 1.7 dbj }
326 1.7 dbj }
327 1.7 dbj #endif
328 1.7 dbj
329 1.1 dbj }
330 1.1 dbj
331 1.1 dbj void
332 1.1 dbj next_dma_setup_cont_regs(nd)
333 1.1 dbj struct nextdma_config *nd;
334 1.1 dbj {
335 1.20 dbj bus_addr_t dd_start;
336 1.20 dbj bus_addr_t dd_stop;
337 1.20 dbj bus_addr_t dd_saved_start;
338 1.20 dbj bus_addr_t dd_saved_stop;
339 1.20 dbj
340 1.30 christos if (ESPLOGIF) *esplogp++ = 'c';
341 1.1 dbj DPRINTF(("DMA next_dma_setup_regs()\n"));
342 1.1 dbj
343 1.1 dbj if (nd->_nd_map_cont) {
344 1.20 dbj dd_start = nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr;
345 1.20 dbj dd_stop = (nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
346 1.20 dbj nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
347 1.1 dbj
348 1.1 dbj if (nd->nd_intr == NEXT_I_ENETX_DMA) {
349 1.20 dbj dd_stop |= 0x80000000; /* Ethernet transmit needs secret magic */
350 1.29 dbj dd_stop += 15;
351 1.20 dbj }
352 1.20 dbj } else {
353 1.20 dbj dd_start = 0xdeadbeef;
354 1.20 dbj dd_stop = 0xdeadbeef;
355 1.20 dbj }
356 1.1 dbj
357 1.20 dbj dd_saved_start = dd_start;
358 1.20 dbj dd_saved_stop = dd_stop;
359 1.15 dbj
360 1.30 christos if (nd->_nd_map_cont && ESPLOGIF) {
361 1.30 christos sprintf (esplogp, "%ld", nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
362 1.30 christos esplogp += strlen (esplogp);
363 1.30 christos }
364 1.30 christos
365 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START, dd_start);
366 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP, dd_stop);
367 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_START, dd_saved_start);
368 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_STOP, dd_saved_stop);
369 1.1 dbj
370 1.20 dbj #ifdef DIAGNOSTIC
371 1.24 dbj if ( (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_START) != dd_start)
372 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP) != dd_stop)
373 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_START) != dd_saved_start)
374 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_STOP) != dd_saved_stop)
375 1.24 dbj ) {
376 1.20 dbj next_dma_print(nd);
377 1.20 dbj panic("DMA failure writing to continue regs");
378 1.1 dbj }
379 1.7 dbj #endif
380 1.1 dbj }
381 1.1 dbj
382 1.1 dbj void
383 1.1 dbj next_dma_setup_curr_regs(nd)
384 1.1 dbj struct nextdma_config *nd;
385 1.1 dbj {
386 1.20 dbj bus_addr_t dd_next;
387 1.20 dbj bus_addr_t dd_limit;
388 1.20 dbj bus_addr_t dd_saved_next;
389 1.20 dbj bus_addr_t dd_saved_limit;
390 1.20 dbj
391 1.30 christos if (ESPLOGIF) *esplogp++ = 'C';
392 1.1 dbj DPRINTF(("DMA next_dma_setup_curr_regs()\n"));
393 1.1 dbj
394 1.15 dbj
395 1.15 dbj if (nd->_nd_map) {
396 1.20 dbj dd_next = nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr;
397 1.20 dbj dd_limit = (nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
398 1.20 dbj nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
399 1.24 dbj
400 1.15 dbj if (nd->nd_intr == NEXT_I_ENETX_DMA) {
401 1.20 dbj dd_limit |= 0x80000000; /* Ethernet transmit needs secret magic */
402 1.29 dbj dd_limit += 15;
403 1.20 dbj }
404 1.20 dbj } else {
405 1.20 dbj dd_next = 0xdeadbeef;
406 1.20 dbj dd_limit = 0xdeadbeef;
407 1.20 dbj }
408 1.1 dbj
409 1.20 dbj dd_saved_next = dd_next;
410 1.20 dbj dd_saved_limit = dd_limit;
411 1.1 dbj
412 1.30 christos if (nd->_nd_map && ESPLOGIF) {
413 1.30 christos sprintf (esplogp, "%ld", nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
414 1.30 christos esplogp += strlen (esplogp);
415 1.30 christos }
416 1.30 christos
417 1.20 dbj if (nd->nd_intr == NEXT_I_ENETX_DMA) {
418 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF, dd_next);
419 1.15 dbj } else {
420 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT, dd_next);
421 1.15 dbj }
422 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT, dd_limit);
423 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT, dd_saved_next);
424 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT, dd_saved_limit);
425 1.1 dbj
426 1.20 dbj #ifdef DIAGNOSTIC
427 1.24 dbj if ( (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF) != dd_next)
428 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT) != dd_next)
429 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT) != dd_limit)
430 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT) != dd_saved_next)
431 1.24 dbj || (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT) != dd_saved_limit)
432 1.24 dbj ) {
433 1.20 dbj next_dma_print(nd);
434 1.20 dbj panic("DMA failure writing to current regs");
435 1.20 dbj }
436 1.7 dbj #endif
437 1.1 dbj }
438 1.1 dbj
439 1.1 dbj
440 1.1 dbj /* This routine is used for debugging */
441 1.1 dbj
442 1.1 dbj void
443 1.1 dbj next_dma_print(nd)
444 1.1 dbj struct nextdma_config *nd;
445 1.1 dbj {
446 1.1 dbj u_long dd_csr;
447 1.1 dbj u_long dd_next;
448 1.1 dbj u_long dd_next_initbuf;
449 1.1 dbj u_long dd_limit;
450 1.1 dbj u_long dd_start;
451 1.1 dbj u_long dd_stop;
452 1.1 dbj u_long dd_saved_next;
453 1.1 dbj u_long dd_saved_limit;
454 1.1 dbj u_long dd_saved_start;
455 1.1 dbj u_long dd_saved_stop;
456 1.22 tv char sbuf[256];
457 1.1 dbj
458 1.22 tv /* Read all of the registers before we print anything out,
459 1.1 dbj * in case something changes
460 1.1 dbj */
461 1.1 dbj dd_csr = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
462 1.1 dbj dd_next = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT);
463 1.1 dbj dd_next_initbuf = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF);
464 1.1 dbj dd_limit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT);
465 1.1 dbj dd_start = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_START);
466 1.1 dbj dd_stop = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP);
467 1.1 dbj dd_saved_next = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT);
468 1.1 dbj dd_saved_limit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT);
469 1.1 dbj dd_saved_start = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_START);
470 1.1 dbj dd_saved_stop = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_STOP);
471 1.1 dbj
472 1.22 tv bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRSTAT)),
473 1.22 tv NEXT_INTR_BITS, sbuf, sizeof(sbuf));
474 1.22 tv printf("NDMAP: *intrstat = 0x%s\n", sbuf);
475 1.22 tv
476 1.22 tv bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRMASK)),
477 1.22 tv NEXT_INTR_BITS, sbuf, sizeof(sbuf));
478 1.22 tv printf("NDMAP: *intrmask = 0x%s\n", sbuf);
479 1.20 dbj
480 1.12 dbj /* NDMAP is Next DMA Print (really!) */
481 1.12 dbj
482 1.1 dbj if (nd->_nd_map) {
483 1.28 chs printf("NDMAP: nd->_nd_map->dm_mapsize = %ld\n",
484 1.11 dbj nd->_nd_map->dm_mapsize);
485 1.11 dbj printf("NDMAP: nd->_nd_map->dm_nsegs = %d\n",
486 1.11 dbj nd->_nd_map->dm_nsegs);
487 1.28 chs printf("NDMAP: nd->_nd_map->dm_xfer_len = %ld\n",
488 1.26 dbj nd->_nd_map->dm_xfer_len);
489 1.1 dbj printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_addr = 0x%08lx\n",
490 1.1 dbj nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
491 1.28 chs printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_len = %ld\n",
492 1.1 dbj nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
493 1.24 dbj {
494 1.24 dbj int i;
495 1.24 dbj printf("NDMAP: Entire map;\n");
496 1.24 dbj for(i=0;i<nd->_nd_map->dm_nsegs;i++) {
497 1.24 dbj printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_addr = 0x%08lx\n",
498 1.24 dbj i,nd->_nd_map->dm_segs[i].ds_addr);
499 1.28 chs printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_len = %ld\n",
500 1.24 dbj i,nd->_nd_map->dm_segs[i].ds_len);
501 1.24 dbj }
502 1.24 dbj }
503 1.1 dbj } else {
504 1.1 dbj printf("NDMAP: nd->_nd_map = NULL\n");
505 1.1 dbj }
506 1.1 dbj if (nd->_nd_map_cont) {
507 1.28 chs printf("NDMAP: nd->_nd_map_cont->dm_mapsize = %ld\n",
508 1.11 dbj nd->_nd_map_cont->dm_mapsize);
509 1.11 dbj printf("NDMAP: nd->_nd_map_cont->dm_nsegs = %d\n",
510 1.11 dbj nd->_nd_map_cont->dm_nsegs);
511 1.28 chs printf("NDMAP: nd->_nd_map_cont->dm_xfer_len = %ld\n",
512 1.26 dbj nd->_nd_map_cont->dm_xfer_len);
513 1.1 dbj printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_addr = 0x%08lx\n",
514 1.1 dbj nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
515 1.28 chs printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_len = %ld\n",
516 1.1 dbj nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
517 1.24 dbj if (nd->_nd_map_cont != nd->_nd_map) {
518 1.24 dbj int i;
519 1.24 dbj printf("NDMAP: Entire map;\n");
520 1.24 dbj for(i=0;i<nd->_nd_map_cont->dm_nsegs;i++) {
521 1.24 dbj printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_addr = 0x%08lx\n",
522 1.24 dbj i,nd->_nd_map_cont->dm_segs[i].ds_addr);
523 1.28 chs printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_len = %ld\n",
524 1.24 dbj i,nd->_nd_map_cont->dm_segs[i].ds_len);
525 1.24 dbj }
526 1.24 dbj }
527 1.1 dbj } else {
528 1.1 dbj printf("NDMAP: nd->_nd_map_cont = NULL\n");
529 1.1 dbj }
530 1.1 dbj
531 1.22 tv bitmask_snprintf(dd_csr, DMACSR_BITS, sbuf, sizeof(sbuf));
532 1.22 tv printf("NDMAP: dd->dd_csr = 0x%s\n", sbuf);
533 1.22 tv
534 1.28 chs printf("NDMAP: dd->dd_saved_next = 0x%08lx\n", dd_saved_next);
535 1.28 chs printf("NDMAP: dd->dd_saved_limit = 0x%08lx\n", dd_saved_limit);
536 1.28 chs printf("NDMAP: dd->dd_saved_start = 0x%08lx\n", dd_saved_start);
537 1.28 chs printf("NDMAP: dd->dd_saved_stop = 0x%08lx\n", dd_saved_stop);
538 1.28 chs printf("NDMAP: dd->dd_next = 0x%08lx\n", dd_next);
539 1.28 chs printf("NDMAP: dd->dd_next_initbuf = 0x%08lx\n", dd_next_initbuf);
540 1.28 chs printf("NDMAP: dd->dd_limit = 0x%08lx\n", dd_limit);
541 1.28 chs printf("NDMAP: dd->dd_start = 0x%08lx\n", dd_start);
542 1.28 chs printf("NDMAP: dd->dd_stop = 0x%08lx\n", dd_stop);
543 1.1 dbj
544 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
545 1.22 tv sbuf, sizeof(sbuf));
546 1.22 tv printf("NDMAP: interrupt ipl (%ld) intr(0x%s)\n",
547 1.22 tv NEXT_I_IPL(nd->nd_intr), sbuf);
548 1.1 dbj }
549 1.1 dbj
550 1.1 dbj /****************************************************************/
551 1.1 dbj
552 1.1 dbj int
553 1.1 dbj nextdma_intr(arg)
554 1.1 dbj void *arg;
555 1.1 dbj {
556 1.1 dbj /* @@@ This is bogus, we can't be certain of arg's type
557 1.18 dbj * unless the interrupt is for us. For now we successfully
558 1.18 dbj * cheat because DMA interrupts are the only things invoked
559 1.18 dbj * at this interrupt level.
560 1.1 dbj */
561 1.18 dbj struct nextdma_config *nd = arg;
562 1.1 dbj
563 1.1 dbj if (!INTR_OCCURRED(nd->nd_intr)) return 0;
564 1.1 dbj /* Handle dma interrupts */
565 1.1 dbj
566 1.30 christos #if 01
567 1.30 christos if (nd->nd_intr == NEXT_I_SCSI_DMA) {
568 1.30 christos int esp_dma_int __P((void *));
569 1.30 christos return esp_dma_int (nd->nd_cb_arg);
570 1.30 christos }
571 1.30 christos #endif
572 1.30 christos
573 1.30 christos if (ESPLOGIF) *esplogp++ = 'D';
574 1.22 tv #ifdef ND_DEBUG
575 1.30 christos if (NEXTDMA_DEBUG) {
576 1.22 tv char sbuf[256];
577 1.22 tv
578 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
579 1.22 tv sbuf, sizeof(sbuf));
580 1.22 tv printf("DMA interrupt ipl (%ld) intr(0x%s)\n",
581 1.22 tv NEXT_I_IPL(nd->nd_intr), sbuf);
582 1.22 tv }
583 1.22 tv #endif
584 1.1 dbj
585 1.7 dbj #ifdef DIAGNOSTIC
586 1.7 dbj if (!nd->_nd_map) {
587 1.7 dbj next_dma_print(nd);
588 1.7 dbj panic("DMA missing current map in interrupt!\n");
589 1.7 dbj }
590 1.7 dbj #endif
591 1.7 dbj
592 1.1 dbj {
593 1.24 dbj unsigned int state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
594 1.26 dbj
595 1.26 dbj #if defined(ND_DEBUG)
596 1.26 dbj nextdma_debug_savestate(nd,state);
597 1.26 dbj #endif
598 1.26 dbj
599 1.26 dbj #ifdef DIAGNOSTIC
600 1.26 dbj if (!(state & DMACSR_COMPLETE)) {
601 1.26 dbj char sbuf[256];
602 1.26 dbj next_dma_print(nd);
603 1.26 dbj bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
604 1.26 dbj printf("DMA: state 0x%s\n",sbuf);
605 1.26 dbj panic("DMA complete not set in interrupt\n");
606 1.26 dbj }
607 1.26 dbj #endif
608 1.26 dbj
609 1.26 dbj {
610 1.23 dbj bus_addr_t onext;
611 1.23 dbj bus_addr_t olimit;
612 1.23 dbj bus_addr_t slimit;
613 1.1 dbj
614 1.23 dbj DPRINTF(("DMA: finishing xfer\n"));
615 1.23 dbj
616 1.23 dbj onext = nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr;
617 1.23 dbj olimit = onext + nd->_nd_map->dm_segs[nd->_nd_idx].ds_len;
618 1.23 dbj
619 1.24 dbj {
620 1.24 dbj int result = 0;
621 1.24 dbj if (state & DMACSR_ENABLE) {
622 1.24 dbj /* enable bit was set */
623 1.24 dbj result |= 0x01;
624 1.24 dbj }
625 1.23 dbj if (state & DMACSR_SUPDATE) {
626 1.24 dbj /* supdate bit was set */
627 1.24 dbj result |= 0x02;
628 1.24 dbj }
629 1.26 dbj if (nd->_nd_map_cont == NULL) {
630 1.27 dbj KASSERT(nd->_nd_idx+1 == nd->_nd_map->dm_nsegs);
631 1.24 dbj /* Expecting a shutdown, didn't SETSUPDATE last turn */
632 1.24 dbj result |= 0x04;
633 1.24 dbj }
634 1.24 dbj if (state & DMACSR_BUSEXC) {
635 1.24 dbj /* bus exception bit was set */
636 1.24 dbj result |= 0x08;
637 1.24 dbj }
638 1.24 dbj switch (result) {
639 1.24 dbj case 0x00: /* !BUSEXC && !expecting && !SUPDATE && !ENABLE */
640 1.24 dbj case 0x08: /* BUSEXC && !expecting && !SUPDATE && !ENABLE */
641 1.27 dbj if (nd->nd_intr == NEXT_I_SCSI_DMA) {
642 1.27 dbj slimit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT);
643 1.27 dbj } else {
644 1.27 dbj slimit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT);
645 1.27 dbj }
646 1.24 dbj break;
647 1.24 dbj case 0x01: /* !BUSEXC && !expecting && !SUPDATE && ENABLE */
648 1.24 dbj case 0x09: /* BUSEXC && !expecting && !SUPDATE && ENABLE */
649 1.26 dbj if (nd->nd_intr == NEXT_I_SCSI_DMA) {
650 1.26 dbj bus_addr_t snext;
651 1.26 dbj snext = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT);
652 1.26 dbj if (snext != onext) {
653 1.26 dbj slimit = olimit;
654 1.26 dbj } else {
655 1.26 dbj slimit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT);
656 1.26 dbj }
657 1.26 dbj } else {
658 1.26 dbj slimit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT);
659 1.24 dbj }
660 1.24 dbj break;
661 1.24 dbj case 0x02: /* !BUSEXC && !expecting && SUPDATE && !ENABLE */
662 1.24 dbj case 0x0a: /* BUSEXC && !expecting && SUPDATE && !ENABLE */
663 1.24 dbj slimit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT);
664 1.24 dbj break;
665 1.24 dbj case 0x04: /* !BUSEXC && expecting && !SUPDATE && !ENABLE */
666 1.24 dbj case 0x0c: /* BUSEXC && expecting && !SUPDATE && !ENABLE */
667 1.24 dbj slimit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT);
668 1.24 dbj break;
669 1.24 dbj default:
670 1.7 dbj #ifdef DIAGNOSTIC
671 1.26 dbj {
672 1.26 dbj char sbuf[256];
673 1.26 dbj printf("DMA: please send this output to port-next68k-maintainer (at) netbsd.org:\n");
674 1.26 dbj bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
675 1.26 dbj printf("DMA: state 0x%s\n",sbuf);
676 1.26 dbj next_dma_print(nd);
677 1.26 dbj panic("DMA: condition 0x%02x not yet documented to occur\n",result);
678 1.26 dbj }
679 1.23 dbj #endif
680 1.24 dbj slimit = olimit;
681 1.24 dbj break;
682 1.23 dbj }
683 1.23 dbj }
684 1.22 tv
685 1.23 dbj if (nd->nd_intr == NEXT_I_ENETX_DMA) {
686 1.23 dbj slimit &= ~0x80000000;
687 1.29 dbj slimit -= 15;
688 1.23 dbj }
689 1.22 tv
690 1.23 dbj #ifdef DIAGNOSTIC
691 1.23 dbj if ((slimit < onext) || (slimit > olimit)) {
692 1.26 dbj char sbuf[256];
693 1.26 dbj bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
694 1.26 dbj printf("DMA: state 0x%s\n",sbuf);
695 1.23 dbj next_dma_print(nd);
696 1.28 chs panic("DMA: Unexpected limit register (0x%08lx) in finish_xfer\n",slimit);
697 1.23 dbj }
698 1.1 dbj #endif
699 1.1 dbj
700 1.26 dbj #ifdef DIAGNOSTIC
701 1.26 dbj if ((state & DMACSR_ENABLE) && ((nd->_nd_idx+1) != nd->_nd_map->dm_nsegs)) {
702 1.26 dbj if (slimit != olimit) {
703 1.26 dbj char sbuf[256];
704 1.26 dbj bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
705 1.26 dbj printf("DMA: state 0x%s\n",sbuf);
706 1.26 dbj next_dma_print(nd);
707 1.28 chs panic("DMA: short limit register (0x%08lx) w/o finishing map.\n",slimit);
708 1.26 dbj }
709 1.26 dbj }
710 1.26 dbj #endif
711 1.26 dbj
712 1.23 dbj #if (defined(ND_DEBUG))
713 1.30 christos if (NEXTDMA_DEBUG > 2) next_dma_print(nd);
714 1.23 dbj #endif
715 1.7 dbj
716 1.26 dbj nd->_nd_map->dm_xfer_len += slimit-onext;
717 1.12 dbj
718 1.23 dbj /* If we've reached the end of the current map, then inform
719 1.23 dbj * that we've completed that map.
720 1.23 dbj */
721 1.26 dbj if ((nd->_nd_idx+1) == nd->_nd_map->dm_nsegs) {
722 1.23 dbj if (nd->nd_completed_cb)
723 1.23 dbj (*nd->nd_completed_cb)(nd->_nd_map, nd->nd_cb_arg);
724 1.27 dbj } else {
725 1.27 dbj KASSERT(nd->_nd_map == nd->_nd_map_cont);
726 1.27 dbj KASSERT(nd->_nd_idx+1 == nd->_nd_idx_cont);
727 1.23 dbj }
728 1.23 dbj nd->_nd_map = 0;
729 1.23 dbj nd->_nd_idx = 0;
730 1.23 dbj }
731 1.23 dbj
732 1.30 christos if (NEXTDMA_DEBUG) {
733 1.30 christos char sbuf[256];
734 1.30 christos bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
735 1.30 christos printf("CLNDMAP: dd->dd_csr = 0x%s\n", sbuf);
736 1.30 christos }
737 1.23 dbj if (state & DMACSR_ENABLE) {
738 1.22 tv
739 1.23 dbj next_dma_rotate(nd);
740 1.23 dbj next_dma_setup_cont_regs(nd);
741 1.22 tv
742 1.23 dbj {
743 1.23 dbj u_long dmadir; /* DMACSR_SETREAD or DMACSR_SETWRITE */
744 1.23 dbj
745 1.23 dbj if (state & DMACSR_READ) {
746 1.23 dbj dmadir = DMACSR_SETREAD;
747 1.23 dbj } else {
748 1.23 dbj dmadir = DMACSR_SETWRITE;
749 1.23 dbj }
750 1.23 dbj
751 1.26 dbj if (nd->_nd_map_cont == NULL) {
752 1.27 dbj KASSERT(nd->_nd_idx+1 == nd->_nd_map->dm_nsegs);
753 1.23 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
754 1.23 dbj DMACSR_CLRCOMPLETE | dmadir);
755 1.30 christos if (ESPLOGIF) *esplogp++ = 'g';
756 1.23 dbj } else {
757 1.23 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
758 1.23 dbj DMACSR_CLRCOMPLETE | dmadir | DMACSR_SETSUPDATE);
759 1.30 christos if (ESPLOGIF) *esplogp++ = 'G';
760 1.23 dbj }
761 1.7 dbj }
762 1.7 dbj
763 1.23 dbj } else {
764 1.7 dbj
765 1.25 dbj DPRINTF(("DMA: a shutdown occurred\n"));
766 1.25 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
767 1.25 dbj
768 1.23 dbj /* Cleanup more incomplete transfers */
769 1.26 dbj #if 1
770 1.26 dbj /* cleanup continue map */
771 1.23 dbj if (nd->_nd_map_cont) {
772 1.23 dbj DPRINTF(("DMA: shutting down with non null continue map\n"));
773 1.23 dbj if (nd->nd_completed_cb)
774 1.23 dbj (*nd->nd_completed_cb)(nd->_nd_map_cont, nd->nd_cb_arg);
775 1.23 dbj
776 1.23 dbj nd->_nd_map_cont = 0;
777 1.23 dbj nd->_nd_idx_cont = 0;
778 1.20 dbj }
779 1.25 dbj #else
780 1.26 dbj /* Do an automatic dma restart */
781 1.26 dbj if (nd->_nd_map_cont) {
782 1.26 dbj u_long dmadir; /* DMACSR_SETREAD or DMACSR_SETWRITE */
783 1.26 dbj
784 1.25 dbj next_dma_rotate(nd);
785 1.27 dbj
786 1.25 dbj if (state & DMACSR_READ) {
787 1.25 dbj dmadir = DMACSR_SETREAD;
788 1.25 dbj } else {
789 1.25 dbj dmadir = DMACSR_SETWRITE;
790 1.25 dbj }
791 1.25 dbj
792 1.25 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, 0);
793 1.25 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
794 1.25 dbj DMACSR_INITBUF | DMACSR_RESET | dmadir);
795 1.25 dbj
796 1.25 dbj next_dma_setup_curr_regs(nd);
797 1.25 dbj next_dma_setup_cont_regs(nd);
798 1.25 dbj
799 1.26 dbj if (nd->_nd_map_cont == NULL) {
800 1.27 dbj KASSERT(nd->_nd_idx+1 == nd->_nd_map->dm_nsegs);
801 1.25 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
802 1.25 dbj DMACSR_SETENABLE | dmadir);
803 1.25 dbj } else {
804 1.25 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
805 1.25 dbj DMACSR_SETSUPDATE | DMACSR_SETENABLE | dmadir);
806 1.25 dbj }
807 1.25 dbj return 1;
808 1.25 dbj }
809 1.25 dbj #endif
810 1.23 dbj if (nd->nd_shutdown_cb) (*nd->nd_shutdown_cb)(nd->nd_cb_arg);
811 1.1 dbj }
812 1.1 dbj }
813 1.30 christos
814 1.22 tv #ifdef ND_DEBUG
815 1.30 christos if (NEXTDMA_DEBUG) {
816 1.22 tv char sbuf[256];
817 1.22 tv
818 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
819 1.22 tv sbuf, sizeof(sbuf));
820 1.22 tv printf("DMA exiting interrupt ipl (%ld) intr(0x%s)\n",
821 1.22 tv NEXT_I_IPL(nd->nd_intr), sbuf);
822 1.22 tv }
823 1.22 tv #endif
824 1.1 dbj
825 1.1 dbj return(1);
826 1.1 dbj }
827 1.1 dbj
828 1.1 dbj /*
829 1.1 dbj * Check to see if dma has finished for a channel */
830 1.1 dbj int
831 1.1 dbj nextdma_finished(nd)
832 1.1 dbj struct nextdma_config *nd;
833 1.1 dbj {
834 1.1 dbj int r;
835 1.1 dbj int s;
836 1.1 dbj s = spldma(); /* @@@ should this be splimp()? */
837 1.1 dbj r = (nd->_nd_map == NULL) && (nd->_nd_map_cont == NULL);
838 1.1 dbj splx(s);
839 1.1 dbj return(r);
840 1.1 dbj }
841 1.1 dbj
842 1.1 dbj void
843 1.1 dbj nextdma_start(nd, dmadir)
844 1.1 dbj struct nextdma_config *nd;
845 1.19 dbj u_long dmadir; /* DMACSR_SETREAD or DMACSR_SETWRITE */
846 1.1 dbj {
847 1.1 dbj
848 1.30 christos if (ESPLOGIF) *esplogp++ = 'n';
849 1.1 dbj #ifdef DIAGNOSTIC
850 1.1 dbj if (!nextdma_finished(nd)) {
851 1.22 tv char sbuf[256];
852 1.22 tv
853 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
854 1.22 tv sbuf, sizeof(sbuf));
855 1.22 tv panic("DMA trying to start before previous finished on intr(0x%s)\n", sbuf);
856 1.1 dbj }
857 1.1 dbj #endif
858 1.1 dbj
859 1.22 tv #ifdef ND_DEBUG
860 1.30 christos if (NEXTDMA_DEBUG) {
861 1.22 tv char sbuf[256];
862 1.22 tv
863 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
864 1.22 tv sbuf, sizeof(sbuf));
865 1.22 tv printf("DMA start (%ld) intr(0x%s)\n",
866 1.22 tv NEXT_I_IPL(nd->nd_intr), sbuf);
867 1.22 tv }
868 1.22 tv #endif
869 1.1 dbj
870 1.1 dbj #ifdef DIAGNOSTIC
871 1.1 dbj if (nd->_nd_map) {
872 1.1 dbj next_dma_print(nd);
873 1.1 dbj panic("DMA: nextdma_start() with non null map\n");
874 1.1 dbj }
875 1.1 dbj if (nd->_nd_map_cont) {
876 1.1 dbj next_dma_print(nd);
877 1.1 dbj panic("DMA: nextdma_start() with non null continue map\n");
878 1.1 dbj }
879 1.1 dbj #endif
880 1.1 dbj
881 1.9 dbj #ifdef DIAGNOSTIC
882 1.19 dbj if ((dmadir != DMACSR_SETREAD) && (dmadir != DMACSR_SETWRITE)) {
883 1.19 dbj panic("DMA: nextdma_start(), dmadir arg must be DMACSR_SETREAD or DMACSR_SETWRITE\n");
884 1.9 dbj }
885 1.9 dbj #endif
886 1.9 dbj
887 1.26 dbj #if defined(ND_DEBUG)
888 1.26 dbj nextdma_debug_initstate(nd);
889 1.26 dbj #endif
890 1.26 dbj
891 1.7 dbj /* preload both the current and the continue maps */
892 1.1 dbj next_dma_rotate(nd);
893 1.1 dbj
894 1.1 dbj #ifdef DIAGNOSTIC
895 1.1 dbj if (!nd->_nd_map_cont) {
896 1.1 dbj panic("No map available in nextdma_start()");
897 1.1 dbj }
898 1.1 dbj #endif
899 1.1 dbj
900 1.7 dbj next_dma_rotate(nd);
901 1.7 dbj
902 1.22 tv #ifdef ND_DEBUG
903 1.30 christos if (NEXTDMA_DEBUG) {
904 1.22 tv char sbuf[256];
905 1.22 tv
906 1.22 tv bitmask_snprintf(NEXT_I_BIT(nd->nd_intr), NEXT_INTR_BITS,
907 1.22 tv sbuf, sizeof(sbuf));
908 1.22 tv printf("DMA initiating DMA %s of %d segments on intr(0x%s)\n",
909 1.22 tv (dmadir == DMACSR_SETREAD ? "read" : "write"), nd->_nd_map->dm_nsegs, sbuf);
910 1.22 tv }
911 1.22 tv #endif
912 1.1 dbj
913 1.1 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, 0);
914 1.1 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
915 1.20 dbj DMACSR_INITBUF | DMACSR_RESET | dmadir);
916 1.1 dbj
917 1.7 dbj next_dma_setup_curr_regs(nd);
918 1.1 dbj next_dma_setup_cont_regs(nd);
919 1.1 dbj
920 1.4 dbj #if (defined(ND_DEBUG))
921 1.30 christos if (NEXTDMA_DEBUG > 2) next_dma_print(nd);
922 1.4 dbj #endif
923 1.1 dbj
924 1.26 dbj if (nd->_nd_map_cont == NULL) {
925 1.20 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
926 1.20 dbj DMACSR_SETENABLE | dmadir);
927 1.20 dbj } else {
928 1.1 dbj bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
929 1.20 dbj DMACSR_SETSUPDATE | DMACSR_SETENABLE | dmadir);
930 1.1 dbj }
931 1.1 dbj }
932