Deleted Added
full compact
busdma_bounce.c (117691) busdma_bounce.c (118081)
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

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

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
27#include <sys/cdefs.h>
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

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

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
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/i386/i386/busdma_machdep.c 117691 2003-07-17 16:07:46Z scottl $");
28__FBSDID("$FreeBSD: head/sys/i386/i386/busdma_machdep.c 118081 2003-07-27 13:52:10Z mux $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/bus.h>
34#include <sys/interrupt.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>

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

381 * Allocate a piece of memory that can be efficiently mapped into
382 * bus device space based on the constraints lited in the dma tag.
383 * A dmamap to for use with dmamap_load is also allocated.
384 */
385int
386bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
387 bus_dmamap_t *mapp)
388{
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/bus.h>
34#include <sys/interrupt.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>

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

381 * Allocate a piece of memory that can be efficiently mapped into
382 * bus device space based on the constraints lited in the dma tag.
383 * A dmamap to for use with dmamap_load is also allocated.
384 */
385int
386bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
387 bus_dmamap_t *mapp)
388{
389 int mflags;
390
391 if (flags & BUS_DMA_NOWAIT)
392 mflags = M_NOWAIT;
393 else
394 mflags = M_WAITOK;
395 if (flags & BUS_DMA_ZERO)
396 mflags |= M_ZERO;
397
389 /* If we succeed, no mapping/bouncing will be required */
390 *mapp = NULL;
391
392 if ((dmat->maxsize <= PAGE_SIZE) &&
393 dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
398 /* If we succeed, no mapping/bouncing will be required */
399 *mapp = NULL;
400
401 if ((dmat->maxsize <= PAGE_SIZE) &&
402 dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
394 *vaddr = malloc(dmat->maxsize, M_DEVBUF,
395 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
403 *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags);
396 } else {
397 /*
398 * XXX Use Contigmalloc until it is merged into this facility
399 * and handles multi-seg allocations. Nobody is doing
400 * multi-seg allocations yet though.
401 */
404 } else {
405 /*
406 * XXX Use Contigmalloc until it is merged into this facility
407 * and handles multi-seg allocations. Nobody is doing
408 * multi-seg allocations yet though.
409 */
402 mtx_lock(&Giant);
403 *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF,
404 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK,
410 *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags,
405 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
406 dmat->boundary);
411 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
412 dmat->boundary);
407 mtx_unlock(&Giant);
408 }
409 if (*vaddr == NULL)
410 return (ENOMEM);
411 return (0);
412}
413
414/*
415 * Free a piece of memory and it's allociated dmamap, that was allocated

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

800 while (numpages > 0) {
801 struct bounce_page *bpage;
802
803 bpage = (struct bounce_page *)malloc(sizeof(*bpage), M_DEVBUF,
804 M_NOWAIT | M_ZERO);
805
806 if (bpage == NULL)
807 break;
413 }
414 if (*vaddr == NULL)
415 return (ENOMEM);
416 return (0);
417}
418
419/*
420 * Free a piece of memory and it's allociated dmamap, that was allocated

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

805 while (numpages > 0) {
806 struct bounce_page *bpage;
807
808 bpage = (struct bounce_page *)malloc(sizeof(*bpage), M_DEVBUF,
809 M_NOWAIT | M_ZERO);
810
811 if (bpage == NULL)
812 break;
808 mtx_lock(&Giant);
809 bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF,
810 M_NOWAIT, 0ul,
811 dmat->lowaddr,
812 PAGE_SIZE,
813 dmat->boundary);
813 bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF,
814 M_NOWAIT, 0ul,
815 dmat->lowaddr,
816 PAGE_SIZE,
817 dmat->boundary);
814 mtx_unlock(&Giant);
815 if (bpage->vaddr == 0) {
816 free(bpage, M_DEVBUF);
817 break;
818 }
819 bpage->busaddr = pmap_kextract(bpage->vaddr);
820 mtx_lock(&bounce_lock);
821 STAILQ_INSERT_TAIL(&bounce_page_list, bpage, links);
822 total_bpages++;

--- 101 unchanged lines hidden ---
818 if (bpage->vaddr == 0) {
819 free(bpage, M_DEVBUF);
820 break;
821 }
822 bpage->busaddr = pmap_kextract(bpage->vaddr);
823 mtx_lock(&bounce_lock);
824 STAILQ_INSERT_TAIL(&bounce_page_list, bpage, links);
825 total_bpages++;

--- 101 unchanged lines hidden ---