Deleted Added
full compact
busdma_bounce.c (113492) busdma_bounce.c (115316)
1/*
2 * Copyright (c) 1997, 1998 Justin T. Gibbs.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*
2 * Copyright (c) 1997, 1998 Justin T. Gibbs.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/i386/i386/busdma_machdep.c 113492 2003-04-15 03:11:03Z mux $
26 * $FreeBSD: head/sys/i386/i386/busdma_machdep.c 115316 2003-05-26 04:00:52Z scottl $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/malloc.h>
32#include <sys/bus.h>
33#include <sys/interrupt.h>
34#include <sys/kernel.h>

--- 298 unchanged lines hidden (view full) ---

333
334
335/*
336 * Allocate a piece of memory that can be efficiently mapped into
337 * bus device space based on the constraints lited in the dma tag.
338 * A dmamap to for use with dmamap_load is also allocated.
339 */
340int
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/malloc.h>
32#include <sys/bus.h>
33#include <sys/interrupt.h>
34#include <sys/kernel.h>

--- 298 unchanged lines hidden (view full) ---

333
334
335/*
336 * Allocate a piece of memory that can be efficiently mapped into
337 * bus device space based on the constraints lited in the dma tag.
338 * A dmamap to for use with dmamap_load is also allocated.
339 */
340int
341bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
342 bus_dmamap_t *mapp, bus_size_t size)
341bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
342 bus_dmamap_t *mapp)
343{
343{
344
345 if (size > dmat->maxsize)
346 return (ENOMEM);
347
348 /* If we succeed, no mapping/bouncing will be required */
349 *mapp = NULL;
350
344 /* If we succeed, no mapping/bouncing will be required */
345 *mapp = NULL;
346
351 if ((size <= PAGE_SIZE) &&
347 if ((dmat->maxsize <= PAGE_SIZE) &&
352 dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
348 dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
353 *vaddr = malloc(size, M_DEVBUF,
349 *vaddr = malloc(dmat->maxsize, M_DEVBUF,
354 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
355 } else {
356 /*
357 * XXX Use Contigmalloc until it is merged into this facility
358 * and handles multi-seg allocations. Nobody is doing
359 * multi-seg allocations yet though.
360 */
361 mtx_lock(&Giant);
350 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
351 } else {
352 /*
353 * XXX Use Contigmalloc until it is merged into this facility
354 * and handles multi-seg allocations. Nobody is doing
355 * multi-seg allocations yet though.
356 */
357 mtx_lock(&Giant);
362 *vaddr = contigmalloc(size, M_DEVBUF,
358 *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF,
363 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK,
364 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
365 dmat->boundary);
366 mtx_unlock(&Giant);
367 }
368 if (*vaddr == NULL)
369 return (ENOMEM);
370 return (0);
371}
372
359 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK,
360 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
361 dmat->boundary);
362 mtx_unlock(&Giant);
363 }
364 if (*vaddr == NULL)
365 return (ENOMEM);
366 return (0);
367}
368
373int
374bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
375 bus_dmamap_t *mapp)
376{
377 return (bus_dmamem_alloc_size(dmat, vaddr, flags, mapp, dmat->maxsize));
378}
379
380/*
381 * Free a piece of memory and it's allociated dmamap, that was allocated
382 * via bus_dmamem_alloc. Make the same choice for free/contigfree.
383 */
384void
369/*
370 * Free a piece of memory and it's allociated dmamap, that was allocated
371 * via bus_dmamem_alloc. Make the same choice for free/contigfree.
372 */
373void
385bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
386 bus_size_t size)
374bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
387{
388 /*
389 * dmamem does not need to be bounced, so the map should be
390 * NULL
391 */
392 if (map != NULL)
393 panic("bus_dmamem_free: Invalid map freed\n");
375{
376 /*
377 * dmamem does not need to be bounced, so the map should be
378 * NULL
379 */
380 if (map != NULL)
381 panic("bus_dmamem_free: Invalid map freed\n");
394 if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem))
382 if ((dmat->maxsize <= PAGE_SIZE)
383 && dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem))
395 free(vaddr, M_DEVBUF);
396 else {
397 mtx_lock(&Giant);
384 free(vaddr, M_DEVBUF);
385 else {
386 mtx_lock(&Giant);
398 contigfree(vaddr, size, M_DEVBUF);
387 contigfree(vaddr, dmat->maxsize, M_DEVBUF);
399 mtx_unlock(&Giant);
400 }
401}
402
388 mtx_unlock(&Giant);
389 }
390}
391
403void
404bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
405{
406 bus_dmamem_free_size(dmat, vaddr, map, dmat->maxsize);
407}
408
409/*
410 * Utility function to load a linear buffer. lastaddrp holds state
411 * between invocations (for multiple-buffer loads). segp contains
412 * the starting segment on entrace, and the ending segment on exit.
413 * first indicates if this is the first invocation of this function.
414 */
415static int
416_bus_dmamap_load_buffer(bus_dma_tag_t dmat,

--- 476 unchanged lines hidden ---
392/*
393 * Utility function to load a linear buffer. lastaddrp holds state
394 * between invocations (for multiple-buffer loads). segp contains
395 * the starting segment on entrace, and the ending segment on exit.
396 * first indicates if this is the first invocation of this function.
397 */
398static int
399_bus_dmamap_load_buffer(bus_dma_tag_t dmat,

--- 476 unchanged lines hidden ---