1 /* $Id: at91pdc.c,v 1.2 2008/07/03 01:15:38 matt Exp $ */
4 #include <machine/bus.h>
5 #include <arm/at91/at91pdcvar.h>
7 int at91pdc_alloc_fifo(bus_dma_tag_t dmat
, at91pdc_fifo_t
*fifo
, int size
,
10 bus_dma_segment_t segs
;
15 memset(fifo
, 0, sizeof(*fifo
));
18 f
= flags
& (BUS_DMA_BUS1
| BUS_DMA_BUS2
| BUS_DMA_BUS3
| BUS_DMA_BUS4
);
19 err
= bus_dmamap_create(dmat
, size
, 1, size
, 0,
25 /* allocate DMA safe memory: */
26 f
|= flags
& BUS_DMA_STREAMING
;
27 err
= bus_dmamem_alloc(dmat
, size
, 0, size
, &segs
, 1, &rsegs
,
32 /* allocate virtual memory: */
33 f
|= flags
& (BUS_DMA_COHERENT
| BUS_DMA_NOCACHE
);
34 err
= bus_dmamem_map(dmat
, &segs
, 1, size
, &fifo
->f_buf
,
39 /* connect physical to virtual memory: */
40 f
|= flags
& (BUS_DMA_READ
| BUS_DMA_WRITE
);
41 f
&= ~(BUS_DMA_COHERENT
| BUS_DMA_NOCACHE
);
42 err
= bus_dmamap_load(dmat
, fifo
->f_dmamap
, fifo
->f_buf
, size
, NULL
,
47 /* initialize rest of the structure: */
48 fifo
->f_buf_size
= size
;
49 fifo
->f_ndx
= fifo
->f_length
= 0;
51 fifo
->f_buf_addr
= fifo
->f_dmamap
->dm_segs
[0].ds_addr
;
52 fifo
->f_pdc_rd_ndx
= fifo
->f_pdc_wr_ndx
= 0;
53 fifo
->f_pdc_space
= fifo
->f_buf_size
;
57 bus_dmamem_unmap(dmat
, fifo
->f_buf
, size
);
59 bus_dmamem_free(dmat
, &segs
, rsegs
);
61 bus_dmamap_destroy(dmat
, fifo
->f_dmamap
);