DMA Map Management Routines, Part 2

This section describes an alternative set of functions used to manage DMA maps.

#include <machine/bus.h>

int
bus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags,
    bus_dmamap_t *mapp);

void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);

The bus_dmamem_alloc function creates a DMA map based on the DMA tag dmat and stores the result in mapp. This function also allocates maxsize bytes of contiguous memory (where maxsize is defined by dmat). The address of this memory is returned in vaddr. As you’ll soon see, this contiguous memory will eventually become your DMA buffer. The flags argument modifies bus_dmamem_alloc’s behavior. Valid values for this argument are shown in Table 12-4.

Table 12-4. bus_dmamem_alloc Symbolic Constants

Constant

Description

BUS_DMA_ZERO

Causes the allocated memory to be set to zero

BUS_DMA_NOWAIT

Causes bus_dmamem_alloc to return ENOMEM if the allocation cannot be immediately fulfilled due to resource shortage

BUS_DMA_WAITOK

Indicates that it is okay to wait for resources; if the allocation cannot be immediately fulfilled, the current process is put to sleep to wait for resources to become available.

BUS_DMA_COHERENT

Causes cache synchronization operations to be as cheap as possible for your DMA buffer; this flag is implemented only on arm and sparc64.

BUS_DMA_NOCACHE

Prevents caching the DMA buffer, thereby causing all DMA transactions to be executed without reordering; this flag is implemented only on amd64 and i386.

Note

bus_dmamem_alloc is used when you require a physically contiguous DMA buffer.

The bus_dmamem_free function releases the memory at vaddr that was previously allocated by bus_dmamem_alloc. Then it tears down the DMA map map.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.208.183