FreeBSD/sys/powerpc/powerpc/busdma_machdep.c
/*
 * Allocate a handle for mapping from kva/uva/physical
 * address space into bus device space.
 */
Allocate a handle for mapping from kva/uva/physical
address space into bus device space.
Allocate a handle for mapping from kva / uva / physical address space into bus device space .
int
bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
{
	int error;
	error = 0;
	*mapp = (bus_dmamap_t)malloc(sizeof(**mapp), M_DEVBUF,
				     M_NOWAIT | M_ZERO);
	if (*mapp == NULL) {
		CTR3(KTR_BUSDMA, "%s: tag %p error %d",
		    __func__, dmat, ENOMEM);
		return (ENOMEM);
	}
	if (dmat->flags & BUS_DMA_COULD_BOUNCE) {
		struct bounce_zone *bz;
		int maxpages;
		if (dmat->bounce_zone == NULL) {
			if ((error = alloc_bounce_zone(dmat)) != 0)
				return (error);
		}
		bz = dmat->bounce_zone;
		STAILQ_INIT(&((*mapp)->bpages));
		if (dmat->alignment > 1)
			maxpages = MAX_BPAGES;
		else
			maxpages = MIN(MAX_BPAGES, Maxmem -atop(dmat->lowaddr));
		if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0
		 || (bz->map_count > 0 && bz->total_bpages < maxpages)) {
			int pages;
			pages = MAX(atop(dmat->maxsize), 1);
			pages = MIN(maxpages - bz->total_bpages, pages);
			pages = MAX(pages, 1);
			if (alloc_bounce_pages(dmat, pages) < pages)
				error = ENOMEM;
			if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0) {
				if (error == 0)
					dmat->flags |= BUS_DMA_MIN_ALLOC_COMP;
			} else {
				error = 0;
			}
		}
		bz->map_count++;
	}
	(*mapp)->nsegs = 0;
	(*mapp)->segments = (bus_dma_segment_t *)malloc(
	    sizeof(bus_dma_segment_t) * dmat->nsegments, M_DEVBUF,
	    M_NOWAIT);
	if ((*mapp)->segments == NULL) {
		CTR3(KTR_BUSDMA, "%s: tag %p error %d",
		    __func__, dmat, ENOMEM);
		return (ENOMEM);
	}
	if (error == 0)
		dmat->map_count++;
	CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
	    __func__, dmat, dmat->flags, error);
	return (error);
}
int bus_dmamap_create ( bus_dma_tag_t dmat , int flags , bus_dmamap_t * mapp ) { int error ; error = 0 ; * mapp = ( bus_dmamap_t ) malloc ( sizeof ( * * mapp ) , M_DEVBUF , M_NOWAIT | M_ZERO ) ; if ( * mapp == NULL ) { CTR3 ( KTR_BUSDMA , " " , __func__ , dmat , ENOMEM ) ; return ( ENOMEM ) ; } if ( dmat -> flags & BUS_DMA_COULD_BOUNCE ) { struct bounce_zone * bz ; int maxpages ; if ( dmat -> bounce_zone == NULL ) { if ( ( error = alloc_bounce_zone ( dmat ) ) != 0 ) return ( error ) ; } bz = dmat -> bounce_zone ; STAILQ_INIT ( & ( ( * mapp ) -> bpages ) ) ; if ( dmat -> alignment > 1 ) maxpages = MAX_BPAGES ; else maxpages = MIN ( MAX_BPAGES , Maxmem - atop ( dmat -> lowaddr ) ) ; if ( ( dmat -> flags & BUS_DMA_MIN_ALLOC_COMP ) == 0 || ( bz -> map_count > 0 && bz -> total_bpages < maxpages ) ) { int pages ; pages = MAX ( atop ( dmat -> maxsize ) , 1 ) ; pages = MIN ( maxpages - bz -> total_bpages , pages ) ; pages = MAX ( pages , 1 ) ; if ( alloc_bounce_pages ( dmat , pages ) < pages ) error = ENOMEM ; if ( ( dmat -> flags & BUS_DMA_MIN_ALLOC_COMP ) == 0 ) { if ( error == 0 ) dmat -> flags |= BUS_DMA_MIN_ALLOC_COMP ; } else { error = 0 ; } } bz -> map_count ++ ; } ( * mapp ) -> nsegs = 0 ; ( * mapp ) -> segments = ( bus_dma_segment_t * ) malloc ( sizeof ( bus_dma_segment_t ) * dmat -> nsegments , M_DEVBUF , M_NOWAIT ) ; if ( ( * mapp ) -> segments == NULL ) { CTR3 ( KTR_BUSDMA , " " , __func__ , dmat , ENOMEM ) ; return ( ENOMEM ) ; } if ( error == 0 ) dmat -> map_count ++ ; CTR4 ( KTR_BUSDMA , " " , __func__ , dmat , dmat -> flags , error ) ; return ( error ) ; }
Allocate a handle for mapping from kva/uva/physical
 address space into bus device space.
Allocate a handle for mapping from kva / uva / physical address space into bus device space .
/*
	 * Bouncing might be required if the driver asks for an active
	 * exclusion region, a data alignment that is stricter than 1, and/or
	 * an active address boundary.
	 */ /* Must bounce */ /* Initialize the new map */ /*
		 * Attempt to add pages to our pool on a per-instance
		 * basis up to a sane limit.
		 */