vserver 1.9.5.x5
[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 #ifdef CONFIG_IBMVIO
21         if (dev->bus == &vio_bus_type)
22                 return vio_dma_supported(to_vio_dev(dev), mask);
23 #endif /* CONFIG_IBMVIO */
24         BUG();
25         return 0;
26 }
27 EXPORT_SYMBOL(dma_supported);
28
29 int dma_set_mask(struct device *dev, u64 dma_mask)
30 {
31         if (dev->bus == &pci_bus_type)
32                 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
33 #ifdef CONFIG_IBMVIO
34         if (dev->bus == &vio_bus_type)
35                 return vio_set_dma_mask(to_vio_dev(dev), dma_mask);
36 #endif /* CONFIG_IBMVIO */
37         BUG();
38         return 0;
39 }
40 EXPORT_SYMBOL(dma_set_mask);
41
42 void *dma_alloc_coherent(struct device *dev, size_t size,
43                 dma_addr_t *dma_handle, int flag)
44 {
45         if (dev->bus == &pci_bus_type)
46                 return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
47 #ifdef CONFIG_IBMVIO
48         if (dev->bus == &vio_bus_type)
49                 return vio_alloc_consistent(to_vio_dev(dev), size, dma_handle);
50 #endif /* CONFIG_IBMVIO */
51         BUG();
52         return NULL;
53 }
54 EXPORT_SYMBOL(dma_alloc_coherent);
55
56 void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
57                 dma_addr_t dma_handle)
58 {
59         if (dev->bus == &pci_bus_type)
60                 pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
61 #ifdef CONFIG_IBMVIO
62         else if (dev->bus == &vio_bus_type)
63                 vio_free_consistent(to_vio_dev(dev), size, cpu_addr, dma_handle);
64 #endif /* CONFIG_IBMVIO */
65         else
66                 BUG();
67 }
68 EXPORT_SYMBOL(dma_free_coherent);
69
70 dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
71                 enum dma_data_direction direction)
72 {
73         if (dev->bus == &pci_bus_type)
74                 return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
75 #ifdef CONFIG_IBMVIO
76         if (dev->bus == &vio_bus_type)
77                 return vio_map_single(to_vio_dev(dev), cpu_addr, size, direction);
78 #endif /* CONFIG_IBMVIO */
79         BUG();
80         return (dma_addr_t)0;
81 }
82 EXPORT_SYMBOL(dma_map_single);
83
84 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
85                 enum dma_data_direction direction)
86 {
87         if (dev->bus == &pci_bus_type)
88                 pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
89 #ifdef CONFIG_IBMVIO
90         else if (dev->bus == &vio_bus_type)
91                 vio_unmap_single(to_vio_dev(dev), dma_addr, size, direction);
92 #endif /* CONFIG_IBMVIO */
93         else
94                 BUG();
95 }
96 EXPORT_SYMBOL(dma_unmap_single);
97
98 dma_addr_t dma_map_page(struct device *dev, struct page *page,
99                 unsigned long offset, size_t size,
100                 enum dma_data_direction direction)
101 {
102         if (dev->bus == &pci_bus_type)
103                 return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
104 #ifdef CONFIG_IBMVIO
105         if (dev->bus == &vio_bus_type)
106                 return vio_map_page(to_vio_dev(dev), page, offset, size, direction);
107 #endif /* CONFIG_IBMVIO */
108         BUG();
109         return (dma_addr_t)0;
110 }
111 EXPORT_SYMBOL(dma_map_page);
112
113 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
114                 enum dma_data_direction direction)
115 {
116         if (dev->bus == &pci_bus_type)
117                 pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
118 #ifdef CONFIG_IBMVIO
119         else if (dev->bus == &vio_bus_type)
120                 vio_unmap_page(to_vio_dev(dev), dma_address, size, direction);
121 #endif /* CONFIG_IBMVIO */
122         else
123                 BUG();
124 }
125 EXPORT_SYMBOL(dma_unmap_page);
126
127 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
128                 enum dma_data_direction direction)
129 {
130         if (dev->bus == &pci_bus_type)
131                 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
132 #ifdef CONFIG_IBMVIO
133         if (dev->bus == &vio_bus_type)
134                 return vio_map_sg(to_vio_dev(dev), sg, nents, direction);
135 #endif /* CONFIG_IBMVIO */
136         BUG();
137         return 0;
138 }
139 EXPORT_SYMBOL(dma_map_sg);
140
141 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
142                 enum dma_data_direction direction)
143 {
144         if (dev->bus == &pci_bus_type)
145                 pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
146 #ifdef CONFIG_IBMVIO
147         else if (dev->bus == &vio_bus_type)
148                 vio_unmap_sg(to_vio_dev(dev), sg, nhwentries, direction);
149 #endif /* CONFIG_IBMVIO */
150         else
151                 BUG();
152 }
153 EXPORT_SYMBOL(dma_unmap_sg);