Home | History | Annotate | Line # | Download | only in xscale
iopaau.c revision 1.7
      1 /*	$NetBSD: iopaau.c,v 1.7 2002/08/04 02:26:18 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2002 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Common code for XScale-based I/O Processor Application Accelerator
     40  * Unit support.
     41  *
     42  * The AAU provides a back-end for the dmover(9) facility.
     43  */
     44 
     45 #include <sys/cdefs.h>
     46 __KERNEL_RCSID(0, "$NetBSD: iopaau.c,v 1.7 2002/08/04 02:26:18 thorpej Exp $");
     47 
     48 #include <sys/param.h>
     49 #include <sys/pool.h>
     50 #include <sys/lock.h>
     51 #include <sys/systm.h>
     52 #include <sys/device.h>
     53 #include <sys/uio.h>
     54 
     55 #include <uvm/uvm.h>
     56 
     57 #include <machine/bus.h>
     58 
     59 #include <arm/xscale/iopaaureg.h>
     60 #include <arm/xscale/iopaauvar.h>
     61 
     62 #ifdef AAU_DEBUG
     63 #define	DPRINTF(x)	printf x
     64 #else
     65 #define	DPRINTF(x)	/* nothing */
     66 #endif
     67 
     68 static struct pool aau_desc_4_pool;
     69 static struct pool aau_desc_8_pool;
     70 
     71 struct pool_cache iopaau_desc_4_cache;
     72 struct pool_cache iopaau_desc_8_cache;
     73 
     74 /*
     75  * iopaau_desc_ctor:
     76  *
     77  *	Constructor for all types of descriptors.
     78  */
     79 static int
     80 iopaau_desc_ctor(void *arg, void *object, int flags)
     81 {
     82 	struct aau_desc_4 *d = object;
     83 
     84 	/*
     85 	 * Cache the physical address of the hardware portion of
     86 	 * the descriptor in the software portion of the descriptor
     87 	 * for quick reference later.
     88 	 */
     89 	d->d_pa = vtophys(d) + SYNC_DESC_4_OFFSET;
     90 	KASSERT((d->d_pa & 31) == 0);
     91 	return (0);
     92 }
     93 
     94 /*
     95  * iopaau_desc_free:
     96  *
     97  *	Free a chain of AAU descriptors.
     98  */
     99 void
    100 iopaau_desc_free(struct pool_cache *dc, void *firstdesc)
    101 {
    102 	struct aau_desc_4 *d, *next;
    103 
    104 	for (d = firstdesc; d != NULL; d = next) {
    105 		next = d->d_next;
    106 		pool_cache_put(dc, d);
    107 	}
    108 }
    109 
    110 /*
    111  * iopaau_start:
    112  *
    113  *	Start an AAU request.  Must be called at splbio().
    114  */
    115 static void
    116 iopaau_start(struct iopaau_softc *sc)
    117 {
    118 	struct dmover_backend *dmb = &sc->sc_dmb;
    119 	struct dmover_request *dreq;
    120 	struct iopaau_function *af;
    121 	int error;
    122 
    123 	for (;;) {
    124 
    125 		KASSERT(sc->sc_running == NULL);
    126 
    127 		dreq = TAILQ_FIRST(&dmb->dmb_pendreqs);
    128 		if (dreq == NULL)
    129 			return;
    130 
    131 		dmover_backend_remque(dmb, dreq);
    132 		dreq->dreq_flags |= DMOVER_REQ_RUNNING;
    133 
    134 		sc->sc_running = dreq;
    135 
    136 		/* XXXUNLOCK */
    137 
    138 		af = dreq->dreq_assignment->das_algdesc->dad_data;
    139 		error = (*af->af_setup)(sc, dreq);
    140 
    141 		/* XXXLOCK */
    142 
    143 		if (error) {
    144 			dreq->dreq_flags |= DMOVER_REQ_ERROR;
    145 			dreq->dreq_error = error;
    146 			sc->sc_running = NULL;
    147 			/* XXXUNLOCK */
    148 			dmover_done(dreq);
    149 			/* XXXLOCK */
    150 			continue;
    151 		}
    152 
    153 #ifdef DIAGNOSTIC
    154 		if (bus_space_read_4(sc->sc_st, sc->sc_sh, AAU_ASR) &
    155 		    AAU_ASR_AAF)
    156 			panic("iopaau_start: AAU already active");
    157 #endif
    158 
    159 		DPRINTF(("%s: starting dreq %p\n", sc->sc_dev.dv_xname,
    160 		    dreq));
    161 
    162 		bus_space_write_4(sc->sc_st, sc->sc_sh, AAU_ANDAR,
    163 		    sc->sc_firstdesc_pa);
    164 		bus_space_write_4(sc->sc_st, sc->sc_sh, AAU_ACR,
    165 		    AAU_ACR_AAE);
    166 
    167 		break;
    168 	}
    169 }
    170 
    171 /*
    172  * iopaau_finish:
    173  *
    174  *	Finish the current operation.  AAU must be stopped.
    175  */
    176 static void
    177 iopaau_finish(struct iopaau_softc *sc)
    178 {
    179 	struct dmover_request *dreq = sc->sc_running;
    180 	struct iopaau_function *af =
    181 	    dreq->dreq_assignment->das_algdesc->dad_data;
    182 	void *firstdesc = sc->sc_firstdesc;
    183 	int i, ninputs = dreq->dreq_assignment->das_algdesc->dad_ninputs;
    184 
    185 	sc->sc_running = NULL;
    186 
    187 	/* If the function has inputs, unmap them. */
    188 	for (i = 0; i < ninputs; i++) {
    189 		bus_dmamap_sync(sc->sc_dmat, sc->sc_map_in[i], 0,
    190 		    sc->sc_map_in[i]->dm_mapsize, BUS_DMASYNC_POSTWRITE);
    191 		bus_dmamap_unload(sc->sc_dmat, sc->sc_map_in[i]);
    192 	}
    193 
    194 	/* Unload the output buffer DMA map. */
    195 	bus_dmamap_sync(sc->sc_dmat, sc->sc_map_out, 0,
    196 	    sc->sc_map_out->dm_mapsize, BUS_DMASYNC_POSTREAD);
    197 	bus_dmamap_unload(sc->sc_dmat, sc->sc_map_out);
    198 
    199 	/* Get the next transfer started. */
    200 	iopaau_start(sc);
    201 
    202 	/* Now free descriptors for last transfer. */
    203 	iopaau_desc_free(af->af_desc_cache, firstdesc);
    204 
    205 	dmover_done(dreq);
    206 }
    207 
    208 /*
    209  * iopaau_process:
    210  *
    211  *	Dmover back-end entry point.
    212  */
    213 void
    214 iopaau_process(struct dmover_backend *dmb)
    215 {
    216 	struct iopaau_softc *sc = dmb->dmb_cookie;
    217 	int s;
    218 
    219 	s = splbio();
    220 	/* XXXLOCK */
    221 
    222 	if (sc->sc_running == NULL)
    223 		iopaau_start(sc);
    224 
    225 	/* XXXUNLOCK */
    226 	splx(s);
    227 }
    228 
    229 /*
    230  * iopaau_func_fill_immed_setup:
    231  *
    232  *	Common code shared by the zero and fillN setup routines.
    233  */
    234 static int
    235 iopaau_func_fill_immed_setup(struct iopaau_softc *sc,
    236     struct dmover_request *dreq, uint32_t immed)
    237 {
    238 	struct iopaau_function *af =
    239 	    dreq->dreq_assignment->das_algdesc->dad_data;
    240 	struct pool_cache *dc = af->af_desc_cache;
    241 	bus_dmamap_t dmamap = sc->sc_map_out;
    242 	uint32_t *prevpa;
    243 	struct aau_desc_4 **prevp, *cur;
    244 	int error, seg;
    245 
    246 	switch (dreq->dreq_outbuf_type) {
    247 	case DMOVER_BUF_LINEAR:
    248 		error = bus_dmamap_load(sc->sc_dmat, dmamap,
    249 		    dreq->dreq_outbuf.dmbuf_linear.l_addr,
    250 		    dreq->dreq_outbuf.dmbuf_linear.l_len, NULL,
    251 		    BUS_DMA_NOWAIT|BUS_DMA_READ|BUS_DMA_STREAMING);
    252 		break;
    253 
    254 	case DMOVER_BUF_UIO:
    255 	    {
    256 		struct uio *uio = dreq->dreq_outbuf.dmbuf_uio;
    257 
    258 		if (uio->uio_rw != UIO_READ)
    259 			return (EINVAL);
    260 
    261 		error = bus_dmamap_load_uio(sc->sc_dmat, dmamap,
    262 		    uio, BUS_DMA_NOWAIT|BUS_DMA_READ|BUS_DMA_STREAMING);
    263 		break;
    264 	    }
    265 	}
    266 
    267 	if (__predict_false(error != 0))
    268 		return (error);
    269 
    270 	bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
    271 	    BUS_DMASYNC_PREREAD);
    272 
    273 	prevp = (struct aau_desc_4 **) &sc->sc_firstdesc;
    274 	prevpa = &sc->sc_firstdesc_pa;
    275 
    276 	for (seg = 0; seg < dmamap->dm_nsegs; seg++) {
    277 		cur = pool_cache_get(dc, PR_NOWAIT);
    278 		if (cur == NULL) {
    279 			*prevp = NULL;
    280 			error = ENOMEM;
    281 			goto bad;
    282 		}
    283 
    284 		*prevp = cur;
    285 		*prevpa = cur->d_pa;
    286 
    287 		prevp = &cur->d_next;
    288 		prevpa = &cur->d_nda;
    289 
    290 		/*
    291 		 * We don't actually enforce the page alignment
    292 		 * constraint, here, because there is only one
    293 		 * data stream to worry about.
    294 		 */
    295 
    296 		cur->d_sar[0] = immed;
    297 		cur->d_dar = dmamap->dm_segs[seg].ds_addr;
    298 		cur->d_bc = dmamap->dm_segs[seg].ds_len;
    299 		cur->d_dc = AAU_DC_B1_CC(AAU_DC_CC_FILL) | AAU_DC_DWE;
    300 		SYNC_DESC(cur, sizeof(struct aau_desc_4));
    301 	}
    302 
    303 	*prevp = NULL;
    304 	*prevpa = 0;
    305 
    306 	cur->d_dc |= AAU_DC_IE;
    307 	SYNC_DESC(cur, sizeof(struct aau_desc_4));
    308 
    309 	sc->sc_lastdesc = cur;
    310 
    311 	return (0);
    312 
    313  bad:
    314 	iopaau_desc_free(dc, sc->sc_firstdesc);
    315 	bus_dmamap_unload(sc->sc_dmat, sc->sc_map_out);
    316 	sc->sc_firstdesc = NULL;
    317 
    318 	return (error);
    319 }
    320 
    321 /*
    322  * iopaau_func_zero_setup:
    323  *
    324  *	Setup routine for the "zero" function.
    325  */
    326 int
    327 iopaau_func_zero_setup(struct iopaau_softc *sc, struct dmover_request *dreq)
    328 {
    329 
    330 	return (iopaau_func_fill_immed_setup(sc, dreq, 0));
    331 }
    332 
    333 /*
    334  * iopaau_func_fill8_setup:
    335  *
    336  *	Setup routine for the "fill8" function.
    337  */
    338 int
    339 iopaau_func_fill8_setup(struct iopaau_softc *sc, struct dmover_request *dreq)
    340 {
    341 
    342 	return (iopaau_func_fill_immed_setup(sc, dreq,
    343 	    dreq->dreq_immediate[0] |
    344 	    (dreq->dreq_immediate[0] << 8) |
    345 	    (dreq->dreq_immediate[0] << 16) |
    346 	    (dreq->dreq_immediate[0] << 24)));
    347 }
    348 
    349 /*
    350  * Descriptor command words for varying numbers of inputs.  For 1 input,
    351  * this does a copy.  For multiple inputs, we're doing an XOR.  In this
    352  * case, the first block is a "direct fill" to load the store queue, and
    353  * the remaining blocks are XOR'd to the store queue.
    354  */
    355 static const uint32_t iopaau_dc_inputs[] = {
    356 	0,						/* 0 */
    357 
    358 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL),		/* 1 */
    359 
    360 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|		/* 2 */
    361 	AAU_DC_B2_CC(AAU_DC_CC_XOR),
    362 
    363 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|		/* 3 */
    364 	AAU_DC_B2_CC(AAU_DC_CC_XOR)|
    365 	AAU_DC_B3_CC(AAU_DC_CC_XOR),
    366 
    367 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|		/* 4 */
    368 	AAU_DC_B2_CC(AAU_DC_CC_XOR)|
    369 	AAU_DC_B3_CC(AAU_DC_CC_XOR)|
    370 	AAU_DC_B4_CC(AAU_DC_CC_XOR),
    371 
    372 	AAU_DC_SBCI_5_8|				/* 5 */
    373 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|
    374 	AAU_DC_B2_CC(AAU_DC_CC_XOR)|
    375 	AAU_DC_B3_CC(AAU_DC_CC_XOR)|
    376 	AAU_DC_B4_CC(AAU_DC_CC_XOR)|
    377 	AAU_DC_B5_CC(AAU_DC_CC_XOR),
    378 
    379 	AAU_DC_SBCI_5_8|				/* 6 */
    380 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|
    381 	AAU_DC_B2_CC(AAU_DC_CC_XOR)|
    382 	AAU_DC_B3_CC(AAU_DC_CC_XOR)|
    383 	AAU_DC_B4_CC(AAU_DC_CC_XOR)|
    384 	AAU_DC_B5_CC(AAU_DC_CC_XOR)|
    385 	AAU_DC_B6_CC(AAU_DC_CC_XOR),
    386 
    387 	AAU_DC_SBCI_5_8|				/* 7 */
    388 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|
    389 	AAU_DC_B2_CC(AAU_DC_CC_XOR)|
    390 	AAU_DC_B3_CC(AAU_DC_CC_XOR)|
    391 	AAU_DC_B4_CC(AAU_DC_CC_XOR)|
    392 	AAU_DC_B5_CC(AAU_DC_CC_XOR)|
    393 	AAU_DC_B6_CC(AAU_DC_CC_XOR)|
    394 	AAU_DC_B7_CC(AAU_DC_CC_XOR),
    395 
    396 	AAU_DC_SBCI_5_8|				/* 8 */
    397 	AAU_DC_B1_CC(AAU_DC_CC_DIRECT_FILL)|
    398 	AAU_DC_B2_CC(AAU_DC_CC_XOR)|
    399 	AAU_DC_B3_CC(AAU_DC_CC_XOR)|
    400 	AAU_DC_B4_CC(AAU_DC_CC_XOR)|
    401 	AAU_DC_B5_CC(AAU_DC_CC_XOR)|
    402 	AAU_DC_B6_CC(AAU_DC_CC_XOR)|
    403 	AAU_DC_B7_CC(AAU_DC_CC_XOR)|
    404 	AAU_DC_B8_CC(AAU_DC_CC_XOR),
    405 };
    406 
    407 /*
    408  * iopaau_func_xor_setup:
    409  *
    410  *	Setup routine for the "copy", "xor2".."xor8" functions.
    411  */
    412 int
    413 iopaau_func_xor_setup(struct iopaau_softc *sc, struct dmover_request *dreq)
    414 {
    415 	struct iopaau_function *af =
    416 	    dreq->dreq_assignment->das_algdesc->dad_data;
    417 	struct pool_cache *dc = af->af_desc_cache;
    418 	bus_dmamap_t dmamap = sc->sc_map_out;
    419 	bus_dmamap_t *inmap = sc->sc_map_in;
    420 	uint32_t *prevpa;
    421 	struct aau_desc_8 **prevp, *cur;
    422 	int ninputs = dreq->dreq_assignment->das_algdesc->dad_ninputs;
    423 	int i, error, seg;
    424 	size_t descsz = AAU_DESC_SIZE(ninputs);
    425 
    426 	KASSERT(ninputs <= AAU_MAX_INPUTS);
    427 
    428 	switch (dreq->dreq_outbuf_type) {
    429 	case DMOVER_BUF_LINEAR:
    430 		error = bus_dmamap_load(sc->sc_dmat, dmamap,
    431 		    dreq->dreq_outbuf.dmbuf_linear.l_addr,
    432 		    dreq->dreq_outbuf.dmbuf_linear.l_len, NULL,
    433 		    BUS_DMA_NOWAIT|BUS_DMA_READ|BUS_DMA_STREAMING);
    434 		break;
    435 
    436 	case DMOVER_BUF_UIO:
    437 	    {
    438 		struct uio *uio = dreq->dreq_outbuf.dmbuf_uio;
    439 
    440 		if (uio->uio_rw != UIO_READ)
    441 			return (EINVAL);
    442 
    443 		error = bus_dmamap_load_uio(sc->sc_dmat, dmamap,
    444 		    uio, BUS_DMA_NOWAIT|BUS_DMA_READ|BUS_DMA_STREAMING);
    445 		break;
    446 	    }
    447 	}
    448 
    449 	if (__predict_false(error != 0))
    450 		return (error);
    451 
    452 	switch (dreq->dreq_inbuf_type) {
    453 	case DMOVER_BUF_LINEAR:
    454 		for (i = 0; i < ninputs; i++) {
    455 			error = bus_dmamap_load(sc->sc_dmat, inmap[i],
    456 			    dreq->dreq_inbuf[i].dmbuf_linear.l_addr,
    457 			    dreq->dreq_inbuf[i].dmbuf_linear.l_len, NULL,
    458 			    BUS_DMA_NOWAIT|BUS_DMA_WRITE|BUS_DMA_STREAMING);
    459 			if (__predict_false(error != 0))
    460 				break;
    461 			if (dmamap->dm_nsegs != inmap[i]->dm_nsegs) {
    462 				error = EFAULT;	/* "address error", sort of. */
    463 				bus_dmamap_unload(sc->sc_dmat, inmap[i]);
    464 				break;
    465 			}
    466 		}
    467 		break;
    468 
    469 	 case DMOVER_BUF_UIO:
    470 	     {
    471 		struct uio *uio;
    472 
    473 		for (i = 0; i < ninputs; i++) {
    474 			uio = dreq->dreq_inbuf[i].dmbuf_uio;
    475 
    476 			if (uio->uio_rw != UIO_WRITE) {
    477 				error = EINVAL;
    478 				break;
    479 			}
    480 
    481 			error = bus_dmamap_load_uio(sc->sc_dmat, inmap[i], uio,
    482 			    BUS_DMA_NOWAIT|BUS_DMA_WRITE|BUS_DMA_STREAMING);
    483 			if (__predict_false(error != 0)) {
    484 				break;
    485 			}
    486 			if (dmamap->dm_nsegs != inmap[i]->dm_nsegs) {
    487 				error = EFAULT;	/* "address error", sort of. */
    488 				bus_dmamap_unload(sc->sc_dmat, inmap[i]);
    489 				break;
    490 			}
    491 		}
    492 		break;
    493 	    }
    494 	}
    495 
    496 	if (__predict_false(error != 0)) {
    497 		for (--i; i >= 0; i--)
    498 			bus_dmamap_unload(sc->sc_dmat, inmap[i]);
    499 		bus_dmamap_unload(sc->sc_dmat, dmamap);
    500 		return (error);
    501 	}
    502 
    503 	bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
    504 	    BUS_DMASYNC_PREREAD);
    505 	for (i = 0; i < ninputs; i++) {
    506 		bus_dmamap_sync(sc->sc_dmat, inmap[i], 0, inmap[i]->dm_mapsize,
    507 		    BUS_DMASYNC_PREWRITE);
    508 	}
    509 
    510 	prevp = (struct aau_desc_8 **) &sc->sc_firstdesc;
    511 	prevpa = &sc->sc_firstdesc_pa;
    512 
    513 	for (seg = 0; seg < dmamap->dm_nsegs; seg++) {
    514 		cur = pool_cache_get(dc, PR_NOWAIT);
    515 		if (cur == NULL) {
    516 			*prevp = NULL;
    517 			error = ENOMEM;
    518 			goto bad;
    519 		}
    520 
    521 		*prevp = cur;
    522 		*prevpa = cur->d_pa;
    523 
    524 		prevp = &cur->d_next;
    525 		prevpa = &cur->d_nda;
    526 
    527 		for (i = 0; i < ninputs; i++) {
    528 			if (dmamap->dm_segs[seg].ds_len !=
    529 			    inmap[i]->dm_segs[seg].ds_len) {
    530 				*prevp = NULL;
    531 				error = EFAULT;	/* "address" error, sort of. */
    532 				goto bad;
    533 			}
    534 			if (i < 4) {
    535 				cur->d_sar[i] =
    536 				    inmap[i]->dm_segs[seg].ds_addr;
    537 			} else if (i < 8) {
    538 				cur->d_sar5_8[i - 4] =
    539 				    inmap[i]->dm_segs[seg].ds_addr;
    540 			}
    541 		}
    542 		cur->d_dar = dmamap->dm_segs[seg].ds_addr;
    543 		cur->d_bc = dmamap->dm_segs[seg].ds_len;
    544 		cur->d_dc = iopaau_dc_inputs[ninputs] | AAU_DC_DWE;
    545 		SYNC_DESC(cur, descsz);
    546 	}
    547 
    548 	*prevp = NULL;
    549 	*prevpa = 0;
    550 
    551 	cur->d_dc |= AAU_DC_IE;
    552 	SYNC_DESC(cur, descsz);
    553 
    554 	sc->sc_lastdesc = cur;
    555 
    556 	return (0);
    557 
    558  bad:
    559 	iopaau_desc_free(dc, sc->sc_firstdesc);
    560 	bus_dmamap_unload(sc->sc_dmat, sc->sc_map_out);
    561 	for (i = 0; i < ninputs; i++)
    562 		bus_dmamap_unload(sc->sc_dmat, sc->sc_map_in[i]);
    563 	sc->sc_firstdesc = NULL;
    564 
    565 	return (error);
    566 }
    567 
    568 int
    569 iopaau_intr(void *arg)
    570 {
    571 	struct iopaau_softc *sc = arg;
    572 	struct dmover_request *dreq;
    573 	uint32_t asr;
    574 
    575 	/* Clear the interrupt. */
    576 	asr = bus_space_read_4(sc->sc_st, sc->sc_sh, AAU_ASR);
    577 	if (asr == 0)
    578 		return (0);
    579 	bus_space_write_4(sc->sc_st, sc->sc_sh, AAU_ASR, asr);
    580 
    581 	/* XXX -- why does this happen? */
    582 	if (sc->sc_running == NULL) {
    583 		printf("%s: unexpected interrupt, ASR = 0x%08x\n",
    584 		    sc->sc_dev.dv_xname, asr);
    585 		return (1);
    586 	}
    587 	dreq = sc->sc_running;
    588 
    589 	/* Stop the AAU. */
    590 	bus_space_write_4(sc->sc_st, sc->sc_sh, AAU_ACR, 0);
    591 
    592 	DPRINTF(("%s: got interrupt for dreq %p\n", sc->sc_dev.dv_xname,
    593 	    dreq));
    594 
    595 	if (__predict_false((asr & AAU_ASR_ETIF) != 0)) {
    596 		/*
    597 		 * We expect to get end-of-chain interrupts, not
    598 		 * end-of-transfer interrupts, so panic if we get
    599 		 * one of these.
    600 		 */
    601 		panic("aau_intr: got EOT interrupt");
    602 	}
    603 
    604 	if (__predict_false((asr & AAU_ASR_MA) != 0)) {
    605 		printf("%s: WARNING: got master abort\n", sc->sc_dev.dv_xname);
    606 		dreq->dreq_flags |= DMOVER_REQ_ERROR;
    607 		dreq->dreq_error = EFAULT;
    608 	}
    609 
    610 	/* Finish this transfer, start next one. */
    611 	iopaau_finish(sc);
    612 
    613 	return (1);
    614 }
    615 
    616 void
    617 iopaau_attach(struct iopaau_softc *sc)
    618 {
    619 	int error, i;
    620 
    621 	error = bus_dmamap_create(sc->sc_dmat, AAU_MAX_XFER, AAU_MAX_SEGS,
    622 	    AAU_MAX_XFER, AAU_IO_BOUNDARY, 0, &sc->sc_map_out);
    623 	if (error) {
    624 		printf("%s: unable to create output DMA map, error = %d\n",
    625 		    sc->sc_dev.dv_xname, error);
    626 		return;
    627 	}
    628 
    629 	for (i = 0; i < AAU_MAX_INPUTS; i++) {
    630 		error = bus_dmamap_create(sc->sc_dmat, AAU_MAX_XFER,
    631 		    AAU_MAX_SEGS, AAU_MAX_XFER, AAU_IO_BOUNDARY, 0,
    632 		    &sc->sc_map_in[i]);
    633 		if (error) {
    634 			printf("%s: unable to create input %d DMA map, "
    635 			    "error = %d\n", sc->sc_dev.dv_xname, i, error);
    636 			return;
    637 		}
    638 	}
    639 
    640 	/*
    641 	 * Initialize global resources.  Ok to do here, since there's
    642 	 * only one AAU.
    643 	 */
    644 	pool_init(&aau_desc_4_pool, sizeof(struct aau_desc_4),
    645 	    8 * 4, offsetof(struct aau_desc_4, d_nda), 0, "aaud4pl",
    646 	    NULL);
    647 	pool_init(&aau_desc_8_pool, sizeof(struct aau_desc_8),
    648 	    8 * 4, offsetof(struct aau_desc_8, d_nda), 0, "aaud8pl",
    649 	    NULL);
    650 
    651 	pool_cache_init(&iopaau_desc_4_cache, &aau_desc_4_pool,
    652 	    iopaau_desc_ctor, NULL, NULL);
    653 	pool_cache_init(&iopaau_desc_8_cache, &aau_desc_8_pool,
    654 	    iopaau_desc_ctor, NULL, NULL);
    655 
    656 	/* Register us with dmover. */
    657 	dmover_backend_register(&sc->sc_dmb);
    658 }
    659