Merge branch 'intelfb-patches' of master.kernel.org:/pub/scm/linux/kernel/git/airlied...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / powerpc / kernel / dma_64.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/ibmebus.h>
14 #include <asm/scatterlist.h>
15 #include <asm/bug.h>
16
17 static struct dma_mapping_ops *get_dma_ops(struct device *dev)
18 {
19 #ifdef CONFIG_PCI
20 if (dev->bus == &pci_bus_type)
21 return &pci_dma_ops;
22 #endif
23 #ifdef CONFIG_IBMVIO
24 if (dev->bus == &vio_bus_type)
25 return &vio_dma_ops;
26 #endif
27 #ifdef CONFIG_IBMEBUS
28 if (dev->bus == &ibmebus_bus_type)
29 return &ibmebus_dma_ops;
30 #endif
31 return NULL;
32 }
33
34 int dma_supported(struct device *dev, u64 mask)
35 {
36 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
37
38 BUG_ON(!dma_ops);
39
40 return dma_ops->dma_supported(dev, mask);
41 }
42 EXPORT_SYMBOL(dma_supported);
43
44 int dma_set_mask(struct device *dev, u64 dma_mask)
45 {
46 #ifdef CONFIG_PCI
47 if (dev->bus == &pci_bus_type)
48 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
49 #endif
50 #ifdef CONFIG_IBMVIO
51 if (dev->bus == &vio_bus_type)
52 return -EIO;
53 #endif /* CONFIG_IBMVIO */
54 #ifdef CONFIG_IBMEBUS
55 if (dev->bus == &ibmebus_bus_type)
56 return -EIO;
57 #endif
58 BUG();
59 return 0;
60 }
61 EXPORT_SYMBOL(dma_set_mask);
62
63 void *dma_alloc_coherent(struct device *dev, size_t size,
64 dma_addr_t *dma_handle, gfp_t flag)
65 {
66 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
67
68 BUG_ON(!dma_ops);
69
70 return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
71 }
72 EXPORT_SYMBOL(dma_alloc_coherent);
73
74 void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
75 dma_addr_t dma_handle)
76 {
77 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
78
79 BUG_ON(!dma_ops);
80
81 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
82 }
83 EXPORT_SYMBOL(dma_free_coherent);
84
85 dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
86 enum dma_data_direction direction)
87 {
88 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
89
90 BUG_ON(!dma_ops);
91
92 return dma_ops->map_single(dev, cpu_addr, size, direction);
93 }
94 EXPORT_SYMBOL(dma_map_single);
95
96 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
97 enum dma_data_direction direction)
98 {
99 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
100
101 BUG_ON(!dma_ops);
102
103 dma_ops->unmap_single(dev, dma_addr, size, direction);
104 }
105 EXPORT_SYMBOL(dma_unmap_single);
106
107 dma_addr_t dma_map_page(struct device *dev, struct page *page,
108 unsigned long offset, size_t size,
109 enum dma_data_direction direction)
110 {
111 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
112
113 BUG_ON(!dma_ops);
114
115 return dma_ops->map_single(dev, page_address(page) + offset, size,
116 direction);
117 }
118 EXPORT_SYMBOL(dma_map_page);
119
120 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
121 enum dma_data_direction direction)
122 {
123 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
124
125 BUG_ON(!dma_ops);
126
127 dma_ops->unmap_single(dev, dma_address, size, direction);
128 }
129 EXPORT_SYMBOL(dma_unmap_page);
130
131 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
132 enum dma_data_direction direction)
133 {
134 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
135
136 BUG_ON(!dma_ops);
137
138 return dma_ops->map_sg(dev, sg, nents, direction);
139 }
140 EXPORT_SYMBOL(dma_map_sg);
141
142 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
143 enum dma_data_direction direction)
144 {
145 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
146
147 BUG_ON(!dma_ops);
148
149 dma_ops->unmap_sg(dev, sg, nhwentries, direction);
150 }
151 EXPORT_SYMBOL(dma_unmap_sg);