FreeBSD/sys/x86/x86/busdma_bounce.c
/*
 * Add a single contiguous physical range to the segment list.
 */
Add a single contiguous physical range to the segment list.
Add a single contiguous physical range to the segment list .
static int
_bus_dmamap_addseg(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t curaddr,
    bus_size_t sgsize, bus_dma_segment_t *segs, int *segp)
{
	bus_addr_t baddr, bmask;
	int seg;
	bmask = ~(dmat->common.boundary - 1);
	if (dmat->common.boundary > 0) {
		baddr = (curaddr + dmat->common.boundary) & bmask;
		if (sgsize > (baddr - curaddr))
			sgsize = (baddr - curaddr);
	}
	seg = *segp;
	if (seg == -1) {
		seg = 0;
		segs[seg].ds_addr = curaddr;
		segs[seg].ds_len = sgsize;
	} else {
		if (curaddr == segs[seg].ds_addr + segs[seg].ds_len &&
		    (segs[seg].ds_len + sgsize) <= dmat->common.maxsegsz &&
		    (dmat->common.boundary == 0 ||
		     (segs[seg].ds_addr & bmask) == (curaddr & bmask)))
			segs[seg].ds_len += sgsize;
		else {
			if (++seg >= dmat->common.nsegments)
				return (0);
			segs[seg].ds_addr = curaddr;
			segs[seg].ds_len = sgsize;
		}
	}
	*segp = seg;
	return (sgsize);
}
static int _bus_dmamap_addseg ( bus_dma_tag_t dmat , bus_dmamap_t map , bus_addr_t curaddr , bus_size_t sgsize , bus_dma_segment_t * segs , int * segp ) { bus_addr_t baddr , bmask ; int seg ; bmask = ~ ( dmat -> common . boundary - 1 ) ; if ( dmat -> common . boundary > 0 ) { baddr = ( curaddr + dmat -> common . boundary ) & bmask ; if ( sgsize > ( baddr - curaddr ) ) sgsize = ( baddr - curaddr ) ; } seg = * segp ; if ( seg == -1 ) { seg = 0 ; segs [ seg ] . ds_addr = curaddr ; segs [ seg ] . ds_len = sgsize ; } else { if ( curaddr == segs [ seg ] . ds_addr + segs [ seg ] . ds_len && ( segs [ seg ] . ds_len + sgsize ) <= dmat -> common . maxsegsz && ( dmat -> common . boundary == 0 || ( segs [ seg ] . ds_addr & bmask ) == ( curaddr & bmask ) ) ) segs [ seg ] . ds_len += sgsize ; else { if ( ++ seg >= dmat -> common . nsegments ) return ( 0 ) ; segs [ seg ] . ds_addr = curaddr ; segs [ seg ] . ds_len = sgsize ; } } * segp = seg ; return ( sgsize ) ; }
Add a single contiguous physical range to the segment list.
Add a single contiguous physical range to the segment list .
/*
	 * Make sure we don't cross any boundaries.
	 */ /*
	 * Insert chunk into a segment, coalescing with
	 * previous segment if possible.
	 */