2 * Dynamic DMA mapping support.
5 #include <linux/types.h>
7 #include <linux/string.h>
9 #include <linux/module.h>
12 /* Map a set of buffers described by scatterlist in streaming
13 * mode for DMA. This is the scatter-gather version of the
14 * above pci_map_single interface. Here the scatter gather list
15 * elements are each tagged with the appropriate dma address
16 * and length. They are obtained via sg_dma_{address,length}(SG).
18 * NOTE: An implementation may be able to use a smaller number of
19 * DMA address/length pairs than there are SG table elements.
20 * (for example via virtual mapping capabilities)
21 * The routine returns the number of addr/length pairs actually
22 * used, at most nents.
24 * Device ownership issues as mentioned above for pci_map_single are
27 int dma_map_sg(struct device *hwdev, struct scatterlist *sg,
28 int nents, int direction)
32 BUG_ON(direction == DMA_NONE);
33 for (i = 0; i < nents; i++ ) {
34 struct scatterlist *s = &sg[i];
36 s->dma_address = virt_to_bus(page_address(s->page) +s->offset);
37 s->dma_length = s->length;
42 EXPORT_SYMBOL(dma_map_sg);
44 /* Unmap a set of streaming mode DMA translations.
45 * Again, cpu read rules concerning calls here are the same as for
46 * pci_unmap_single() above.
48 void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
52 for (i = 0; i < nents; i++) {
53 struct scatterlist *s = &sg[i];
54 BUG_ON(s->page == NULL);
55 BUG_ON(s->dma_address == 0);
56 dma_unmap_single(dev, s->dma_address, s->dma_length, dir);
60 EXPORT_SYMBOL(dma_unmap_sg);