ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ppc64 / kernel / dma.c
1 /*
2  * Copyright (C) 2004 IBM Corporation
3  *
4  * Implements the generic device dma API for ppc64. Handles
5  * the pci and vio busses
6  */
7
8 #include <linux/device.h>
9 #include <linux/dma-mapping.h>
10 /* Include the busses we support */
11 #include <linux/pci.h>
12 #include <asm/vio.h>
13 #include <asm/scatterlist.h>
14 #include <asm/bug.h>
15
16 int dma_supported(struct device *dev, u64 mask)
17 {
18         if (dev->bus == &pci_bus_type)
19                 return pci_dma_supported(to_pci_dev(dev), mask);
20         if (dev->bus == &vio_bus_type)
21                 return vio_dma_supported(to_vio_dev(dev), mask);
22         BUG();
23         return 0;
24 }
25 EXPORT_SYMBOL(dma_supported);
26
27 int dma_set_mask(struct device *dev, u64 dma_mask)
28 {
29         if (dev->bus == &pci_bus_type)
30                 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
31         if (dev->bus == &vio_bus_type)
32                 return vio_set_dma_mask(to_vio_dev(dev), dma_mask);
33         BUG();
34         return 0;
35 }
36 EXPORT_SYMBOL(dma_set_mask);
37
38 void *dma_alloc_coherent(struct device *dev, size_t size,
39                 dma_addr_t *dma_handle, int flag)
40 {
41         if (dev->bus == &pci_bus_type)
42                 return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
43         if (dev->bus == &vio_bus_type)
44                 return vio_alloc_consistent(to_vio_dev(dev), size, dma_handle);
45         BUG();
46         return 0;
47 }
48 EXPORT_SYMBOL(dma_alloc_coherent);
49
50 void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
51                 dma_addr_t dma_handle)
52 {
53         if (dev->bus == &pci_bus_type)
54                 pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
55         else if (dev->bus == &vio_bus_type)
56                 vio_free_consistent(to_vio_dev(dev), size, cpu_addr, dma_handle);
57         else
58                 BUG();
59 }
60 EXPORT_SYMBOL(dma_free_coherent);
61
62 dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
63                 enum dma_data_direction direction)
64 {
65         if (dev->bus == &pci_bus_type)
66                 return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
67         if (dev->bus == &vio_bus_type)
68                 return vio_map_single(to_vio_dev(dev), cpu_addr, size, direction);
69         BUG();
70         return (dma_addr_t)0;
71 }
72 EXPORT_SYMBOL(dma_map_single);
73
74 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
75                 enum dma_data_direction direction)
76 {
77         if (dev->bus == &pci_bus_type)
78                 pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
79         else if (dev->bus == &vio_bus_type)
80                 vio_unmap_single(to_vio_dev(dev), dma_addr, size, direction);
81         else
82                 BUG();
83 }
84 EXPORT_SYMBOL(dma_unmap_single);
85
86 dma_addr_t dma_map_page(struct device *dev, struct page *page,
87                 unsigned long offset, size_t size,
88                 enum dma_data_direction direction)
89 {
90         if (dev->bus == &pci_bus_type)
91                 return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
92         if (dev->bus == &vio_bus_type)
93                 return vio_map_page(to_vio_dev(dev), page, offset, size, direction);
94         BUG();
95         return (dma_addr_t)0;
96 }
97 EXPORT_SYMBOL(dma_map_page);
98
99 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
100                 enum dma_data_direction direction)
101 {
102         if (dev->bus == &pci_bus_type)
103                 pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
104         else if (dev->bus == &vio_bus_type)
105                 vio_unmap_page(to_vio_dev(dev), dma_address, size, direction);
106         else
107                 BUG();
108 }
109 EXPORT_SYMBOL(dma_unmap_page);
110
111 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
112                 enum dma_data_direction direction)
113 {
114         if (dev->bus == &pci_bus_type)
115                 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
116         if (dev->bus == &vio_bus_type)
117                 return vio_map_sg(to_vio_dev(dev), sg, nents, direction);
118         BUG();
119         return 0;
120 }
121 EXPORT_SYMBOL(dma_map_sg);
122
123 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
124                 enum dma_data_direction direction)
125 {
126         if (dev->bus == &pci_bus_type)
127                 pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
128         else if (dev->bus == &vio_bus_type)
129                 vio_unmap_sg(to_vio_dev(dev), sg, nhwentries, direction);
130         else
131                 BUG();
132 }
133 EXPORT_SYMBOL(dma_unmap_sg);