nextdma.c revision 1.1 1 /* $NetBSD: nextdma.c,v 1.1 1998/06/09 07:53:05 dbj Exp $ */
2 /*
3 * Copyright (c) 1998 Darrin B. Jewell
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Darrin B. Jewell
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/mbuf.h>
35 #include <sys/syslog.h>
36 #include <sys/socket.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
39 #include <sys/ioctl.h>
40 #include <sys/errno.h>
41
42 #include <machine/autoconf.h>
43 #include <machine/cpu.h>
44 #include <machine/intr.h>
45
46 #include <next68k/next68k/isr.h>
47
48 #define _GENERIC_BUS_DMA_PRIVATE
49 #include <machine/bus.h>
50
51 #include "nextdmareg.h"
52 #include "nextdmavar.h"
53
54 #if 0
55 #define ND_DEBUG
56 #endif
57
58 #if defined(ND_DEBUG)
59 #define DPRINTF(x) printf x;
60 #else
61 #define DPRINTF(x)
62 #endif
63
64 /* @@@ for debugging */
65 struct nextdma_config *debugernd;
66 struct nextdma_config *debugexnd;
67
68 int nextdma_intr __P((void *));
69 void next_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
70 bus_size_t, int));
71 int next_dma_continue __P((struct nextdma_config *));
72 void next_dma_rotate __P((struct nextdma_config *));
73
74 void next_dma_setup_cont_regs __P((struct nextdma_config *));
75 void next_dma_setup_curr_regs __P((struct nextdma_config *));
76
77 void next_dma_print __P((struct nextdma_config *));
78
79 void
80 nextdma_config(nd)
81 struct nextdma_config *nd;
82 {
83 /* Initialize the dma_tag. As a hack, we currently
84 * put the dma tag in the structure itself. It shouldn't be there.
85 */
86
87 {
88 bus_dma_tag_t t;
89 t = &nd->_nd_dmat;
90 t->_cookie = nd;
91 t->_get_tag = NULL; /* lose */
92 t->_dmamap_create = _bus_dmamap_create;
93 t->_dmamap_destroy = _bus_dmamap_destroy;
94 t->_dmamap_load = _bus_dmamap_load_direct;
95 t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
96 t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
97 t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
98 t->_dmamap_unload = _bus_dmamap_unload;
99 t->_dmamap_sync = next_dmamap_sync;
100
101 t->_dmamem_alloc = _bus_dmamem_alloc;
102 t->_dmamem_free = _bus_dmamem_free;
103 t->_dmamem_map = _bus_dmamem_map;
104 t->_dmamem_unmap = _bus_dmamem_unmap;
105 t->_dmamem_mmap = _bus_dmamem_mmap;
106
107 nd->nd_dmat = t;
108 }
109
110 /* @@@ for debugging */
111 if (nd->nd_intr == NEXT_I_ENETR_DMA) {
112 debugernd = nd;
113 }
114 if (nd->nd_intr == NEXT_I_ENETX_DMA) {
115 debugexnd = nd;
116 }
117
118 nextdma_init(nd);
119
120 isrlink_autovec(nextdma_intr, nd, NEXT_I_IPL(nd->nd_intr), 10);
121 INTR_ENABLE(nd->nd_intr);
122 }
123
124 void
125 nextdma_init(nd)
126 struct nextdma_config *nd;
127 {
128 DPRINTF(("DMA init ipl (%ld) intr(0x%b)\n",
129 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS));
130
131 /* @@@ should probably check and free these maps */
132 nd->_nd_map = NULL;
133 nd->_nd_idx = 0;
134 nd->_nd_map_cont = NULL;
135 nd->_nd_idx_cont = 0;
136
137 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, 0);
138 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
139 DMACSR_INITBUF | DMACSR_CLRCOMPLETE | DMACSR_RESET);
140
141 next_dma_setup_curr_regs(nd);
142 next_dma_setup_cont_regs(nd);
143
144 #if 0 && defined(DIAGNOSTIC)
145 /* Today, my computer (mourning) appears to fail this test.
146 * yesterday, another NeXT (milo) didn't have this problem
147 * Darrin B. Jewell <jewell (at) mit.edu> Mon May 25 07:53:05 1998
148 */
149 {
150 u_long state;
151 state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
152 state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
153 state &= (DMACSR_BUSEXC | DMACSR_COMPLETE |
154 DMACSR_SUPDATE | DMACSR_ENABLE);
155
156 if (state) {
157 next_dma_print(nd);
158 panic("DMA did not reset\n");
159 }
160 }
161 #endif
162 }
163
164 void
165 nextdma_reset(nd)
166 struct nextdma_config *nd;
167 {
168 int s;
169 s = spldma(); /* @@@ should this be splimp()? */
170 nextdma_init(nd);
171 splx(s);
172 }
173
174 /****************************************************************/
175
176 /* If the next had multiple busses, this should probably
177 * go elsewhere, but it is here anyway */
178 void
179 next_dmamap_sync(t, map, offset, len, ops)
180 bus_dma_tag_t t;
181 bus_dmamap_t map;
182 bus_addr_t offset;
183 bus_size_t len;
184 int ops;
185 {
186 /* flush/purge the cache.
187 * assumes pointers are aligned
188 * should probably be fixed to use offset and len
189 */
190 if (ops & BUS_DMASYNC_PREWRITE) {
191 int i;
192 for(i=0;i<map->dm_nsegs;i++) {
193 bus_addr_t p = map->dm_segs[i].ds_addr;
194 bus_addr_t e = p+map->dm_segs[i].ds_len;
195 while(p<e) {
196 DCFL(p); /* flush */
197 p += 16; /* cache line length */
198 }
199 }
200 }
201
202 if (ops & BUS_DMASYNC_POSTREAD) {
203 int i;
204 for(i=0;i<map->dm_nsegs;i++) {
205 bus_addr_t p = map->dm_segs[i].ds_addr;
206 bus_addr_t e = p+map->dm_segs[i].ds_len;
207 while(p<e) {
208 DCPL(p); /* purge */
209 p += 16; /* cache line length */
210 }
211 }
212 }
213 }
214
215 /****************************************************************/
216
217
218 /* Call the completed and continue callbacks to try to fill
219 * in the dma continue buffers.
220 */
221 void
222 next_dma_rotate(nd)
223 struct nextdma_config *nd;
224 {
225
226 DPRINTF(("DMA next_dma_rotate()\n"));
227
228 /* If we've reached the end of the current map, then inform
229 * that we've completed that map.
230 */
231 if (nd->_nd_map && ((nd->_nd_idx+1) == nd->_nd_map->dm_nsegs)) {
232 if (nd->nd_completed_cb)
233 (*nd->nd_completed_cb)(nd->_nd_map, nd->nd_cb_arg);
234 }
235
236 /* Rotate the continue map into the current map */
237 nd->_nd_map = nd->_nd_map_cont;
238 nd->_nd_idx = nd->_nd_idx_cont;
239
240 if ((!nd->_nd_map_cont) ||
241 ((nd->_nd_map_cont) &&
242 (++nd->_nd_idx_cont >= nd->_nd_map_cont->dm_nsegs))) {
243 if (nd->nd_continue_cb) {
244 nd->_nd_map_cont = (*nd->nd_continue_cb)(nd->nd_cb_arg);
245 } else {
246 nd->_nd_map_cont = 0;
247 }
248 nd->_nd_idx_cont = 0;
249 }
250 }
251
252 void
253 next_dma_setup_cont_regs(nd)
254 struct nextdma_config *nd;
255 {
256 DPRINTF(("DMA next_dma_setup_regs()\n"));
257
258 if (nd->_nd_map_cont) {
259
260 if (nd->nd_intr == NEXT_I_ENETX_DMA) {
261 /* Ethernet transmit needs secret magic */
262
263 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START,
264 nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
265 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP,
266 ((nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
267 nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len)
268 + 0x0) | 0x80000000);
269 } else {
270 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START,
271 nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
272 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP,
273 nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
274 nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
275 }
276
277 } else {
278
279 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START,0);
280 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP, 0);
281 }
282
283 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_START,
284 bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_START));
285 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_STOP,
286 bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP));
287
288 }
289
290 void
291 next_dma_setup_curr_regs(nd)
292 struct nextdma_config *nd;
293 {
294 DPRINTF(("DMA next_dma_setup_curr_regs()\n"));
295
296 if (nd->nd_intr == NEXT_I_ENETX_DMA) {
297 /* Ethernet transmit needs secret magic */
298
299 if (nd->_nd_map) {
300
301 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF,
302 nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
303 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT,
304 ((nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
305 nd->_nd_map->dm_segs[nd->_nd_idx].ds_len)
306 + 0x0) | 0x80000000);
307 } else {
308 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF,0);
309 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT, 0);
310
311 }
312
313 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT,
314 bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF));
315 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT,
316 bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT));
317
318 } else {
319
320 if (nd->_nd_map) {
321
322 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT,
323 nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
324 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT,
325 nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
326 nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
327 } else {
328 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT,0);
329 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT, 0);
330
331 }
332
333 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT,
334 bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT));
335 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT,
336 bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT));
337
338 }
339
340 }
341
342
343 /* This routine is used for debugging */
344
345 void
346 next_dma_print(nd)
347 struct nextdma_config *nd;
348 {
349 u_long dd_csr;
350 u_long dd_next;
351 u_long dd_next_initbuf;
352 u_long dd_limit;
353 u_long dd_start;
354 u_long dd_stop;
355 u_long dd_saved_next;
356 u_long dd_saved_limit;
357 u_long dd_saved_start;
358 u_long dd_saved_stop;
359
360 /* Read all of the registers before we print anything out,
361 * in case something changes
362 */
363 dd_csr = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
364 dd_next = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT);
365 dd_next_initbuf = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT_INITBUF);
366 dd_limit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT);
367 dd_start = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_START);
368 dd_stop = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP);
369 dd_saved_next = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT);
370 dd_saved_limit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT);
371 dd_saved_start = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_START);
372 dd_saved_stop = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_STOP);
373
374 if (nd->_nd_map) {
375 printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_addr = 0x%08lx\n",
376 nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
377 printf("NDMAP: nd->_nd_map->dm_segs[%d].ds_len = %d\n",
378 nd->_nd_idx,nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
379 } else {
380 printf("NDMAP: nd->_nd_map = NULL\n");
381 }
382 if (nd->_nd_map_cont) {
383 printf("NDMAP: nd->_nd_map_cont->dm_segs[%d].ds_addr = 0x%08lx\n",
384 nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
385 printf("NDMAP: nd->_nd_map_cont->dm_segs[%d] = %d\n",
386 nd->_nd_idx_cont,nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
387 } else {
388 printf("NDMAP: nd->_nd_map_cont = NULL\n");
389 }
390
391 printf("NDMAP: dd->dd_csr = 0x%b\n", dd_csr, DMACSR_BITS);
392 printf("NDMAP: dd->dd_saved_next = 0x%08x\n", dd_saved_next);
393 printf("NDMAP: dd->dd_saved_limit = 0x%08x\n", dd_saved_limit);
394 printf("NDMAP: dd->dd_saved_start = 0x%08x\n", dd_saved_start);
395 printf("NDMAP: dd->dd_saved_stop = 0x%08x\n", dd_saved_stop);
396 printf("NDMAP: dd->dd_next = 0x%08x\n", dd_next);
397 printf("NDMAP: dd->dd_next_initbuf = 0x%08x\n", dd_next_initbuf);
398 printf("NDMAP: dd->dd_limit = 0x%08x\n", dd_limit);
399 printf("NDMAP: dd->dd_start = 0x%08x\n", dd_start);
400 printf("NDMAP: dd->dd_stop = 0x%08x\n", dd_stop);
401
402 printf("NDMAP: interrupt ipl (%ld) intr(0x%b)\n",
403 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS);
404 }
405
406 /****************************************************************/
407
408 int
409 nextdma_intr(arg)
410 void *arg;
411 {
412 struct nextdma_config *nd = arg;
413
414 /* @@@ This is bogus, we can't be certain of arg's type
415 * unless the interrupt is for us
416 */
417
418 if (!INTR_OCCURRED(nd->nd_intr)) return 0;
419 /* Handle dma interrupts */
420
421 #ifdef DIAGNOSTIC
422 if (nd->nd_intr == NEXT_I_ENETR_DMA) {
423 if (debugernd != nd) {
424 panic("DMA incorrect handling of rx nd->nd_intr");
425 }
426 }
427 if (nd->nd_intr == NEXT_I_ENETX_DMA) {
428 if (debugexnd != nd) {
429 panic("DMA incorrect handling of tx nd->nd_intr");
430 }
431 }
432 #endif
433
434 DPRINTF(("DMA interrupt ipl (%ld) intr(0x%b)\n",
435 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS));
436
437 {
438 int state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
439
440 state &= (DMACSR_BUSEXC | DMACSR_COMPLETE |
441 DMACSR_SUPDATE | DMACSR_ENABLE);
442
443 if (state & DMACSR_BUSEXC) {
444 #if 0 /* This bit seems to get set periodically and I don't know why */
445 next_dma_print(nd);
446 panic("Bus exception in DMA ipl (%ld) intr(0x%b)\n",
447 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS);
448 #endif
449 }
450
451 #ifdef DIAGNOSTIC
452 if (!(state & DMACSR_COMPLETE)) {
453 next_dma_print(nd);
454 printf("DEBUG: state = 0x%b\n", state,DMACSR_BITS);
455 panic("DMA ipl (%ld) intr(0x%b), DMACSR_COMPLETE not set in intr\n",
456 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS);
457 }
458 #endif
459
460 /* Set the length of the segment to match actual length.
461 * @@@ is it okay to resize dma segments here?
462 * i should probably ask jason about this.
463 */
464 if (nd->_nd_map) {
465
466 bus_addr_t next;
467 bus_addr_t limit;
468
469 #if 0
470 if (state & DMACSR_ENABLE) {
471 next = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_NEXT);
472 } else {
473 next = nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr;
474 }
475 #else
476 next = nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr;
477 #endif
478 limit = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_SAVED_LIMIT);
479
480 if (nd->nd_intr == NEXT_I_ENETX_DMA) {
481 limit &= ~0x80000000;
482 }
483
484 #ifdef DIAGNOSTIC
485 if (next != nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr) {
486 next_dma_print(nd);
487 printf("DEBUG: state = 0x%b\n", state,DMACSR_BITS);
488
489 panic("DMA ipl (%ld) intr(0x%b), unexpected completed address\n",
490 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS);
491 }
492 #endif
493
494 /* @@@ I observed a case where DMACSR_ENABLE wasn't set and
495 * DD_SAVED_LIMIT didn't contain the expected limit value. This
496 * should be tested, fixed, and removed. */
497
498 if (((limit-next) > nd->_nd_map->dm_segs[nd->_nd_idx].ds_len)
499 || (limit-next < 0)) {
500 #if 0
501 next_dma_print(nd);
502 printf("DEBUG: state = 0x%b\n", state,DMACSR_BITS);
503 panic("DMA packlen: next = 0x%08x limit = 0x%08x\n",next,limit);
504 #else
505 DPRINTF(("DMA packlen: next = 0x%08x limit = 0x%08x",next,limit));
506 #endif
507
508 } else {
509 nd->_nd_map->dm_segs[nd->_nd_idx].ds_len = limit - next;
510 }
511 }
512
513
514 if ((state & DMACSR_ENABLE) == 0) {
515
516 /* Non chaining interrupts shutdown immediately */
517 if (!nd->nd_chaining_flag) {
518 nd->_nd_map = nd->_nd_map_cont;
519 nd->_nd_idx = nd->_nd_idx_cont;
520 nd->_nd_map_cont = 0;
521 nd->_nd_idx_cont = 0;
522 }
523
524 /* Call the completed callback for the last packet */
525 if (nd->_nd_map && ((nd->_nd_idx+1) == nd->_nd_map->dm_nsegs)) {
526 if (nd->nd_completed_cb)
527 (*nd->nd_completed_cb)(nd->_nd_map, nd->nd_cb_arg);
528 }
529 nd->_nd_map = 0;
530 nd->_nd_idx = 0;
531
532 if (nd->_nd_map_cont) {
533 DPRINTF(("DMA ipl (%ld) intr(0x%b), restarting\n",
534 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS));
535
536 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
537 DMACSR_SETSUPDATE | DMACSR_SETENABLE);
538
539 } else {
540 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
541 DMACSR_CLRCOMPLETE | DMACSR_RESET);
542 DPRINTF(("DMA: enable not set w/o continue map, shutting down dma\n"));
543 if (nd->nd_shutdown_cb) (*nd->nd_shutdown_cb)(nd->nd_cb_arg);
544 }
545
546 } else {
547 next_dma_rotate(nd);
548 next_dma_setup_cont_regs(nd);
549
550 if (nd->_nd_map_cont) {
551 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
552 DMACSR_SETSUPDATE | DMACSR_CLRCOMPLETE);
553 } else {
554 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
555 DMACSR_CLRCOMPLETE);
556 }
557
558 }
559
560 }
561
562 DPRINTF(("DMA exiting interrupt ipl (%ld) intr(0x%b)\n",
563 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS));
564
565 return(1);
566 }
567
568 /*
569 * Check to see if dma has finished for a channel */
570 int
571 nextdma_finished(nd)
572 struct nextdma_config *nd;
573 {
574 int r;
575 int s;
576 s = spldma(); /* @@@ should this be splimp()? */
577 r = (nd->_nd_map == NULL) && (nd->_nd_map_cont == NULL);
578 splx(s);
579 return(r);
580 }
581
582 void
583 nextdma_start(nd, dmadir)
584 struct nextdma_config *nd;
585 u_long dmadir; /* DMACSR_READ or DMACSR_WRITE */
586 {
587
588 #ifdef DIAGNOSTIC
589 if (!nextdma_finished(nd)) {
590 panic("DMA trying to start before previous finished on intr(0x%b)\n",
591 NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS);
592 }
593 #endif
594
595
596 DPRINTF(("DMA start (%ld) intr(0x%b)\n",
597 NEXT_I_IPL(nd->nd_intr), NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS));
598
599 #ifdef DIAGNOSTIC
600 if (nd->_nd_map) {
601 next_dma_print(nd);
602 panic("DMA: nextdma_start() with non null map\n");
603 }
604 if (nd->_nd_map_cont) {
605 next_dma_print(nd);
606 panic("DMA: nextdma_start() with non null continue map\n");
607 }
608 #endif
609
610 next_dma_rotate(nd);
611
612 #ifdef DIAGNOSTIC
613 if (!nd->_nd_map_cont) {
614 panic("No map available in nextdma_start()");
615 }
616 if (!DMA_BEGINALIGNED(nd->_nd_map_cont->dm_segs[nd->_nd_idx].ds_addr)) {
617 panic("unaligned begin dma at start\n");
618 }
619 if (!DMA_ENDALIGNED(nd->_nd_map_cont->dm_segs[nd->_nd_idx].ds_addr +
620 nd->_nd_map_cont->dm_segs[nd->_nd_idx].ds_len)) {
621 panic("unaligned end dma at start\n");
622 }
623 #endif
624
625 DPRINTF(("DMA initiating DMA %s of %d segments on intr(0x%b)\n",
626 (dmadir == DMACSR_READ ? "read" : "write"), nd->_nd_map_cont->dm_nsegs,
627 NEXT_I_BIT(nd->nd_intr),NEXT_INTR_BITS));
628
629 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, 0);
630 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
631 DMACSR_INITBUF | DMACSR_RESET | dmadir);
632
633 next_dma_setup_cont_regs(nd);
634
635 /* When starting DMA, we must put the continue map
636 * into the current register. We reset the nd->_nd_map
637 * pointer here to avoid duplicated completed callbacks
638 * for the first buffer.
639 */
640 nd->_nd_map = nd->_nd_map_cont;
641 nd->_nd_idx = nd->_nd_idx_cont;
642 next_dma_setup_curr_regs(nd);
643 nd->_nd_map = 0;
644 nd->_nd_idx = 0;
645
646 if (nd->nd_chaining_flag) {
647 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
648 DMACSR_SETSUPDATE | DMACSR_SETENABLE);
649 } else {
650 bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
651 DMACSR_SETENABLE);
652 }
653
654 }
655