Home | History | Annotate | Line # | Download | only in isa
isadma_bounce.c revision 1.4.16.1
      1 /*	$NetBSD: isadma_bounce.c,v 1.4.16.1 2007/09/03 14:24:15 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 1998, 2000, 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.4.16.1 2007/09/03 14:24:15 yamt Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/syslog.h>
     46 #include <sys/device.h>
     47 #include <sys/malloc.h>
     48 #include <sys/proc.h>
     49 #include <sys/mbuf.h>
     50 
     51 #include <mips/cache.h>
     52 #define _MIPS_BUS_DMA_PRIVATE
     53 #include <machine/bus.h>
     54 #include <machine/locore.h>
     55 
     56 #include <dev/isa/isareg.h>
     57 #include <dev/isa/isavar.h>
     58 
     59 #include <uvm/uvm_extern.h>
     60 
     61 extern	paddr_t avail_end;
     62 
     63 /*
     64  * Cookie used by bouncing ISA DMA.  A pointer to one of these is stashed
     65  * in the DMA map.
     66  */
     67 struct isadma_bounce_cookie {
     68 	int	id_flags;		/* flags; see below */
     69 
     70 	/*
     71 	 * Information about the original buffer used during
     72 	 * DMA map syncs.  Note that origbuflen is only used
     73 	 * for ID_BUFTYPE_LINEAR.
     74 	 */
     75 	void	*id_origbuf;		/* pointer to orig buffer if
     76 					   bouncing */
     77 	bus_size_t id_origbuflen;	/* ...and size */
     78 	int	id_buftype;		/* type of buffer */
     79 
     80 	void	*id_bouncebuf;		/* pointer to the bounce buffer */
     81 	bus_size_t id_bouncebuflen;	/* ...and size */
     82 	int	id_nbouncesegs;		/* number of valid bounce segs */
     83 	bus_dma_segment_t id_bouncesegs[1]; /* array of bounce buffer
     84 					       physical memory segments */
     85 };
     86 
     87 /* id_flags */
     88 #define	ID_MIGHT_NEED_BOUNCE	0x01	/* map could need bounce buffers */
     89 #define	ID_HAS_BOUNCE		0x02	/* map currently has bounce buffers */
     90 #define	ID_IS_BOUNCING		0x04	/* map is bouncing current xfer */
     91 
     92 /* id_buftype */
     93 #define	ID_BUFTYPE_INVALID	0
     94 #define	ID_BUFTYPE_LINEAR	1
     95 #define	ID_BUFTYPE_MBUF		2
     96 #define	ID_BUFTYPE_UIO		3
     97 #define	ID_BUFTYPE_RAW		4
     98 
     99 int	isadma_bounce_alloc_bouncebuf(bus_dma_tag_t, bus_dmamap_t,
    100 	    bus_size_t, int);
    101 void	isadma_bounce_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t);
    102 
    103 /*
    104  * Create an ISA DMA map.
    105  */
    106 int
    107 isadma_bounce_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
    108     bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
    109 {
    110 	struct isadma_bounce_cookie *cookie;
    111 	bus_dmamap_t map;
    112 	int error, cookieflags;
    113 	void *cookiestore;
    114 	size_t cookiesize;
    115 
    116 	/* Call common function to create the basic map. */
    117 	error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
    118 	    flags, dmamp);
    119 	if (error)
    120 		return (error);
    121 
    122 	map = *dmamp;
    123 	map->_dm_cookie = NULL;
    124 
    125 	cookiesize = sizeof(*cookie);
    126 
    127 	/*
    128 	 * ISA only has 24-bits of address space.  This means
    129 	 * we can't DMA to pages over 16M.  In order to DMA to
    130 	 * arbitrary buffers, we use "bounce buffers" - pages
    131 	 * in memory below the 16M boundary.  On DMA reads,
    132 	 * DMA happens to the bounce buffers, and is copied into
    133 	 * the caller's buffer.  On writes, data is copied into
    134 	 * but bounce buffer, and the DMA happens from those
    135 	 * pages.  To software using the DMA mapping interface,
    136 	 * this looks simply like a data cache.
    137 	 *
    138 	 * If we have more than 16M of RAM in the system, we may
    139 	 * need bounce buffers.  We check and remember that here.
    140 	 *
    141 	 * ...or, there is an opposite case.  The most segments
    142 	 * a transfer will require is (maxxfer / PAGE_SIZE) + 1.  If
    143 	 * the caller can't handle that many segments (e.g. the
    144 	 * ISA DMA controller), we may have to bounce it as well.
    145 	 */
    146 	cookieflags = 0;
    147 	if (avail_end > (t->_wbase + t->_wsize) ||
    148 	    ((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
    149 		cookieflags |= ID_MIGHT_NEED_BOUNCE;
    150 		cookiesize += (sizeof(bus_dma_segment_t) *
    151 		    (map->_dm_segcnt - 1));
    152 	}
    153 
    154 	/*
    155 	 * Allocate our cookie.
    156 	 */
    157 	if ((cookiestore = malloc(cookiesize, M_DMAMAP,
    158 	    (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
    159 		error = ENOMEM;
    160 		goto out;
    161 	}
    162 	memset(cookiestore, 0, cookiesize);
    163 	cookie = (struct isadma_bounce_cookie *)cookiestore;
    164 	cookie->id_flags = cookieflags;
    165 	map->_dm_cookie = cookie;
    166 
    167 	if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
    168 		/*
    169 		 * Allocate the bounce pages now if the caller
    170 		 * wishes us to do so.
    171 		 */
    172 		if ((flags & BUS_DMA_ALLOCNOW) == 0)
    173 			goto out;
    174 
    175 		error = isadma_bounce_alloc_bouncebuf(t, map, size, flags);
    176 	}
    177 
    178  out:
    179 	if (error) {
    180 		if (map->_dm_cookie != NULL)
    181 			free(map->_dm_cookie, M_DMAMAP);
    182 		_bus_dmamap_destroy(t, map);
    183 	}
    184 	return (error);
    185 }
    186 
    187 /*
    188  * Destroy an ISA DMA map.
    189  */
    190 void
    191 isadma_bounce_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
    192 {
    193 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    194 
    195 	/*
    196 	 * Free any bounce pages this map might hold.
    197 	 */
    198 	if (cookie->id_flags & ID_HAS_BOUNCE)
    199 		isadma_bounce_free_bouncebuf(t, map);
    200 
    201 	free(cookie, M_DMAMAP);
    202 	_bus_dmamap_destroy(t, map);
    203 }
    204 
    205 /*
    206  * Load an ISA DMA map with a linear buffer.
    207  */
    208 int
    209 isadma_bounce_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
    210     bus_size_t buflen, struct proc *p, int flags)
    211 {
    212 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    213 	int error;
    214 
    215 	/*
    216 	 * Make sure that on error condition we return "no valid mappings."
    217 	 */
    218 	map->dm_mapsize = 0;
    219 	map->dm_nsegs = 0;
    220 
    221 	/*
    222 	 * Try to load the map the normal way.  If this errors out,
    223 	 * and we can bounce, we will.
    224 	 */
    225 	error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
    226 	if (error == 0 ||
    227 	    (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0))
    228 		return (error);
    229 
    230 	/*
    231 	 * First attempt failed; bounce it.
    232 	 */
    233 
    234 	/*
    235 	 * Allocate bounce pages, if necessary.
    236 	 */
    237 	if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) {
    238 		error = isadma_bounce_alloc_bouncebuf(t, map, buflen, flags);
    239 		if (error)
    240 			return (error);
    241 	}
    242 
    243 	/*
    244 	 * Cache a pointer to the caller's buffer and load the DMA map
    245 	 * with the bounce buffer.
    246 	 */
    247 	cookie->id_origbuf = buf;
    248 	cookie->id_origbuflen = buflen;
    249 	cookie->id_buftype = ID_BUFTYPE_LINEAR;
    250 	error = _bus_dmamap_load(t, map, cookie->id_bouncebuf, buflen,
    251 	    p, flags);
    252 	if (error) {
    253 		/*
    254 		 * Free the bounce pages, unless our resources
    255 		 * are reserved for our exclusive use.
    256 		 */
    257 		if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
    258 			isadma_bounce_free_bouncebuf(t, map);
    259 		return (error);
    260 	}
    261 
    262 	/* ...so isadma_bounce_dmamap_sync() knows we're bouncing */
    263 	cookie->id_flags |= ID_IS_BOUNCING;
    264 	return (0);
    265 }
    266 
    267 /*
    268  * Like isadma_bounce_dmamap_load(), but for mbufs.
    269  */
    270 int
    271 isadma_bounce_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t map,
    272     struct mbuf *m0, int flags)
    273 {
    274 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    275 	int error;
    276 
    277 	/*
    278 	 * Make sure on error condition we return "no valid mappings."
    279 	 */
    280 	map->dm_mapsize = 0;
    281 	map->dm_nsegs = 0;
    282 
    283 #ifdef DIAGNOSTIC
    284 	if ((m0->m_flags & M_PKTHDR) == 0)
    285 		panic("isadma_bounce_dmamap_load_mbuf: no packet header");
    286 #endif
    287 
    288 	if (m0->m_pkthdr.len > map->_dm_size)
    289 		return (EINVAL);
    290 
    291 	/*
    292 	 * Try to load the map the normal way.  If this errors out,
    293 	 * and we can bounce, we will.
    294 	 */
    295 	error = _bus_dmamap_load_mbuf(t, map, m0, flags);
    296 	if (error == 0 ||
    297 	    (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0))
    298 		return (error);
    299 
    300 	/*
    301 	 * First attempt failed; bounce it.
    302 	 */
    303 
    304 	/*
    305 	 * Allocate bounce pages, if necessary.
    306 	 */
    307 	if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) {
    308 		error = isadma_bounce_alloc_bouncebuf(t, map, m0->m_pkthdr.len,
    309 		    flags);
    310 		if (error)
    311 			return (error);
    312 	}
    313 
    314 	/*
    315 	 * Cache a pointer to the caller's buffer and load the DMA map
    316 	 * with the bounce buffer.
    317 	 */
    318 	cookie->id_origbuf = m0;
    319 	cookie->id_origbuflen = m0->m_pkthdr.len;	/* not really used */
    320 	cookie->id_buftype = ID_BUFTYPE_MBUF;
    321 	error = _bus_dmamap_load(t, map, cookie->id_bouncebuf,
    322 	    m0->m_pkthdr.len, NULL, flags);
    323 	if (error) {
    324 		/*
    325 		 * Free the bounce pages, unless our resources
    326 		 * are reserved for our exclusive use.
    327 		 */
    328 		if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
    329 			isadma_bounce_free_bouncebuf(t, map);
    330 		return (error);
    331 	}
    332 
    333 	/* ...so isadma_bounce_dmamap_sync() knows we're bouncing */
    334 	cookie->id_flags |= ID_IS_BOUNCING;
    335 	return (0);
    336 }
    337 
    338 /*
    339  * Like isadma_bounce_dmamap_load(), but for uios.
    340  */
    341 int
    342 isadma_bounce_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t map,
    343     struct uio *uio, int flags)
    344 {
    345 
    346 	panic("isadma_bounce_dmamap_load_uio: not implemented");
    347 }
    348 
    349 /*
    350  * Like isadma_bounce_dmamap_load(), but for raw memory allocated with
    351  * bus_dmamem_alloc().
    352  */
    353 int
    354 isadma_bounce_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map,
    355     bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
    356 {
    357 
    358 	panic("isadma_bounce_dmamap_load_raw: not implemented");
    359 }
    360 
    361 /*
    362  * Unload an ISA DMA map.
    363  */
    364 void
    365 isadma_bounce_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map)
    366 {
    367 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    368 
    369 	/*
    370 	 * If we have bounce pages, free them, unless they're
    371 	 * reserved for our exclusive use.
    372 	 */
    373 	if ((cookie->id_flags & ID_HAS_BOUNCE) &&
    374 	    (map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
    375 		isadma_bounce_free_bouncebuf(t, map);
    376 
    377 	cookie->id_flags &= ~ID_IS_BOUNCING;
    378 	cookie->id_buftype = ID_BUFTYPE_INVALID;
    379 
    380 	/*
    381 	 * Do the generic bits of the unload.
    382 	 */
    383 	_bus_dmamap_unload(t, map);
    384 }
    385 
    386 /*
    387  * Synchronize an ISA DMA map.
    388  */
    389 void
    390 isadma_bounce_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset,
    391     bus_size_t len, int ops)
    392 {
    393 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    394 
    395 	/*
    396 	 * Mixing PRE and POST operations is not allowed.
    397 	 */
    398 	if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 &&
    399 	    (ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0)
    400 		panic("isadma_bounce_dmamap_sync: mix PRE and POST");
    401 
    402 #ifdef DIAGNOSTIC
    403 	if ((ops & (BUS_DMASYNC_PREWRITE|BUS_DMASYNC_POSTREAD)) != 0) {
    404 		if (offset >= map->dm_mapsize)
    405 			panic("isadma_bounce_dmamap_sync: bad offset");
    406 		if (len == 0 || (offset + len) > map->dm_mapsize)
    407 			panic("isadma_bounce_dmamap_sync: bad length");
    408 	}
    409 #endif
    410 
    411 	/*
    412 	 * If we're not bouncing, just do the normal sync operation
    413 	 * and return.
    414 	 */
    415 	if ((cookie->id_flags & ID_IS_BOUNCING) == 0) {
    416 		_bus_dmamap_sync(t, map, offset, len, ops);
    417 		return;
    418 	}
    419 
    420 	/*
    421 	 * Flush data cache for PREREAD.  This has the side-effect
    422 	 * of invalidating the cache.  Done at PREREAD since it
    423 	 * causes the cache line(s) to be written back to memory.
    424 	 *
    425 	 * Copy the original buffer to the bounce buffer and flush
    426 	 * the data cache for PREWRITE, so that the contents
    427 	 * of the data buffer in memory reflect reality.
    428 	 *
    429 	 * Copy the bounce buffer to the original buffer in POSTREAD.
    430 	 */
    431 
    432 	switch (cookie->id_buftype) {
    433 	case ID_BUFTYPE_LINEAR:
    434 		/*
    435 		 * Nothing to do for pre-read.
    436 		 */
    437 
    438 		if (ops & BUS_DMASYNC_PREWRITE) {
    439 			/*
    440 			 * Copy the caller's buffer to the bounce buffer.
    441 			 */
    442 			memcpy((char *)cookie->id_bouncebuf + offset,
    443 			    (char *)cookie->id_origbuf + offset, len);
    444 			wbflush();
    445 		}
    446 
    447 		if (ops & BUS_DMASYNC_POSTREAD) {
    448 			/*
    449 			 * Copy the bounce buffer to the caller's buffer.
    450 			 */
    451 			memcpy((char *)cookie->id_origbuf + offset,
    452 			    (char *)cookie->id_bouncebuf + offset, len);
    453 		}
    454 
    455 		/*
    456 		 * Nothing to do for post-write.
    457 		 */
    458 		break;
    459 
    460 	case ID_BUFTYPE_MBUF:
    461 	    {
    462 		struct mbuf *m, *m0 = cookie->id_origbuf;
    463 		bus_size_t minlen, moff;
    464 
    465 		/*
    466 		 * Nothing to do for pre-read.
    467 		 */
    468 
    469 		if (ops & BUS_DMASYNC_PREWRITE) {
    470 			/*
    471 			 * Copy the caller's buffer to the bounce buffer.
    472 			 */
    473 			m_copydata(m0, offset, len,
    474 			    (char *)cookie->id_bouncebuf + offset);
    475 		}
    476 
    477 		if (ops & BUS_DMASYNC_POSTREAD) {
    478 			/*
    479 			 * Copy the bounce buffer to the caller's buffer.
    480 			 */
    481 			for (moff = offset, m = m0; m != NULL && len != 0;
    482 			     m = m->m_next) {
    483 				/* Find the beginning mbuf. */
    484 				if (moff >= m->m_len) {
    485 					moff -= m->m_len;
    486 					continue;
    487 				}
    488 
    489 				/*
    490 				 * Now at the first mbuf to sync; nail
    491 				 * each one until we have exhausted the
    492 				 * length.
    493 				 */
    494 				minlen = len < m->m_len - moff ?
    495 				    len : m->m_len - moff;
    496 
    497 				memcpy(mtod(m, char *) + moff,
    498 				    (char *)cookie->id_bouncebuf + offset,
    499 				    minlen);
    500 
    501 				moff = 0;
    502 				len -= minlen;
    503 				offset += minlen;
    504 			}
    505 		}
    506 
    507 		/*
    508 		 * Nothing to do for post-write.
    509 		 */
    510 		break;
    511 	    }
    512 
    513 	case ID_BUFTYPE_UIO:
    514 		panic("isadma_bounce_dmamap_sync: ID_BUFTYPE_UIO");
    515 		break;
    516 
    517 	case ID_BUFTYPE_RAW:
    518 		panic("isadma_bounce_dmamap_sync: ID_BUFTYPE_RAW");
    519 		break;
    520 
    521 	case ID_BUFTYPE_INVALID:
    522 		panic("isadma_bounce_dmamap_sync: ID_BUFTYPE_INVALID");
    523 		break;
    524 
    525 	default:
    526 		printf("unknown buffer type %d\n", cookie->id_buftype);
    527 		panic("isadma_bounce_dmamap_sync");
    528 	}
    529 
    530 	/* Drain the write buffer. */
    531 	wbflush();
    532 
    533 	/* XXXJRT */
    534 	if (ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE))
    535 		mips_dcache_wbinv_range((vaddr_t)cookie->id_bouncebuf + offset,
    536 		    len);
    537 }
    538 
    539 /*
    540  * Allocate memory safe for ISA DMA.
    541  */
    542 int
    543 isadma_bounce_dmamem_alloc(bus_dma_tag_t t, bus_size_t size,
    544     bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs,
    545     int nsegs, int *rsegs, int flags)
    546 {
    547 	paddr_t high;
    548 
    549 	if (avail_end > ISA_DMA_BOUNCE_THRESHOLD)
    550 		high = trunc_page(ISA_DMA_BOUNCE_THRESHOLD);
    551 	else
    552 		high = trunc_page(avail_end);
    553 
    554 	return (_bus_dmamem_alloc_range(t, size, alignment, boundary,
    555 	    segs, nsegs, rsegs, flags, 0, high));
    556 }
    557 
    558 /**********************************************************************
    559  * ISA DMA utility functions
    560  **********************************************************************/
    561 
    562 int
    563 isadma_bounce_alloc_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map,
    564     bus_size_t size, int flags)
    565 {
    566 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    567 	int error = 0;
    568 
    569 	cookie->id_bouncebuflen = round_page(size);
    570 	error = isadma_bounce_dmamem_alloc(t, cookie->id_bouncebuflen,
    571 	    PAGE_SIZE, map->_dm_boundary, cookie->id_bouncesegs,
    572 	    map->_dm_segcnt, &cookie->id_nbouncesegs, flags);
    573 	if (error)
    574 		goto out;
    575 	error = _bus_dmamem_map(t, cookie->id_bouncesegs,
    576 	    cookie->id_nbouncesegs, cookie->id_bouncebuflen,
    577 	    (void **)&cookie->id_bouncebuf, flags);
    578 
    579  out:
    580 	if (error) {
    581 		_bus_dmamem_free(t, cookie->id_bouncesegs,
    582 		    cookie->id_nbouncesegs);
    583 		cookie->id_bouncebuflen = 0;
    584 		cookie->id_nbouncesegs = 0;
    585 	} else
    586 		cookie->id_flags |= ID_HAS_BOUNCE;
    587 
    588 	return (error);
    589 }
    590 
    591 void
    592 isadma_bounce_free_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map)
    593 {
    594 	struct isadma_bounce_cookie *cookie = map->_dm_cookie;
    595 
    596 	_bus_dmamem_unmap(t, cookie->id_bouncebuf,
    597 	    cookie->id_bouncebuflen);
    598 	_bus_dmamem_free(t, cookie->id_bouncesegs,
    599 	    cookie->id_nbouncesegs);
    600 	cookie->id_bouncebuflen = 0;
    601 	cookie->id_nbouncesegs = 0;
    602 	cookie->id_flags &= ~ID_HAS_BOUNCE;
    603 }
    604