ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / x86_64 / kernel / pci-dma.c
1 /*
2  * Dynamic DMA mapping support. Common code
3  */
4
5 #include <linux/types.h>
6 #include <linux/mm.h>
7 #include <linux/string.h>
8 #include <linux/pci.h>
9 #include <linux/module.h>
10 #include <asm/io.h>
11
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).
17  *
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.
23  *
24  * Device ownership issues as mentioned above for pci_map_single are
25  * the same here.
26  */
27 int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
28                              int nents, int direction)
29 {
30         int i;
31
32         BUG_ON(direction == PCI_DMA_NONE);
33         for (i = 0; i < nents; i++ ) {
34                 struct scatterlist *s = &sg[i];
35                 BUG_ON(!s->page); 
36                         s->dma_address = pci_map_page(hwdev, s->page, s->offset, 
37                                                       s->length, direction); 
38                 s->dma_length = s->length;
39         }
40         return nents;
41 }
42
43 EXPORT_SYMBOL(pci_map_sg);
44
45 /* Unmap a set of streaming mode DMA translations.
46  * Again, cpu read rules concerning calls here are the same as for
47  * pci_unmap_single() above.
48  */
49 void pci_unmap_sg(struct pci_dev *dev, struct scatterlist *sg, 
50                                   int nents, int dir)
51 {
52         int i;
53         for (i = 0; i < nents; i++) { 
54                 struct scatterlist *s = &sg[i];
55                 BUG_ON(s->page == NULL); 
56                 BUG_ON(s->dma_address == 0); 
57                 pci_unmap_single(dev, s->dma_address, s->dma_length, dir); 
58         } 
59 }
60
61 EXPORT_SYMBOL(pci_unmap_sg);