1 /* Copyright (C) 2002 by James.Bottomley@HansenPartnership.com
3 * Implements the generic device dma API via the existing pci_ one
4 * for unconverted architectures
7 #ifndef _ASM_GENERIC_DMA_MAPPING_H
8 #define _ASM_GENERIC_DMA_MAPPING_H
13 /* we implement the API below in terms of the existing PCI one,
15 #include <linux/pci.h>
16 /* need struct page definitions */
20 dma_supported(struct device
*dev
, u64 mask
)
22 BUG_ON(dev
->bus
!= &pci_bus_type
);
24 return pci_dma_supported(to_pci_dev(dev
), mask
);
28 dma_set_mask(struct device
*dev
, u64 dma_mask
)
30 BUG_ON(dev
->bus
!= &pci_bus_type
);
32 return pci_set_dma_mask(to_pci_dev(dev
), dma_mask
);
36 dma_alloc_coherent(struct device
*dev
, size_t size
, dma_addr_t
*dma_handle
,
39 BUG_ON(dev
->bus
!= &pci_bus_type
);
41 return pci_alloc_consistent(to_pci_dev(dev
), size
, dma_handle
);
45 dma_free_coherent(struct device
*dev
, size_t size
, void *cpu_addr
,
46 dma_addr_t dma_handle
)
48 BUG_ON(dev
->bus
!= &pci_bus_type
);
50 pci_free_consistent(to_pci_dev(dev
), size
, cpu_addr
, dma_handle
);
53 static inline dma_addr_t
54 dma_map_single(struct device
*dev
, void *cpu_addr
, size_t size
,
55 enum dma_data_direction direction
)
57 BUG_ON(dev
->bus
!= &pci_bus_type
);
59 return pci_map_single(to_pci_dev(dev
), cpu_addr
, size
, (int)direction
);
63 dma_unmap_single(struct device
*dev
, dma_addr_t dma_addr
, size_t size
,
64 enum dma_data_direction direction
)
66 BUG_ON(dev
->bus
!= &pci_bus_type
);
68 pci_unmap_single(to_pci_dev(dev
), dma_addr
, size
, (int)direction
);
71 static inline dma_addr_t
72 dma_map_page(struct device
*dev
, struct page
*page
,
73 unsigned long offset
, size_t size
,
74 enum dma_data_direction direction
)
76 BUG_ON(dev
->bus
!= &pci_bus_type
);
78 return pci_map_page(to_pci_dev(dev
), page
, offset
, size
, (int)direction
);
82 dma_unmap_page(struct device
*dev
, dma_addr_t dma_address
, size_t size
,
83 enum dma_data_direction direction
)
85 BUG_ON(dev
->bus
!= &pci_bus_type
);
87 pci_unmap_page(to_pci_dev(dev
), dma_address
, size
, (int)direction
);
91 dma_map_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
92 enum dma_data_direction direction
)
94 BUG_ON(dev
->bus
!= &pci_bus_type
);
96 return pci_map_sg(to_pci_dev(dev
), sg
, nents
, (int)direction
);
100 dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nhwentries
,
101 enum dma_data_direction direction
)
103 BUG_ON(dev
->bus
!= &pci_bus_type
);
105 pci_unmap_sg(to_pci_dev(dev
), sg
, nhwentries
, (int)direction
);
109 dma_sync_single_for_cpu(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
110 enum dma_data_direction direction
)
112 BUG_ON(dev
->bus
!= &pci_bus_type
);
114 pci_dma_sync_single_for_cpu(to_pci_dev(dev
), dma_handle
,
115 size
, (int)direction
);
119 dma_sync_single_for_device(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
120 enum dma_data_direction direction
)
122 BUG_ON(dev
->bus
!= &pci_bus_type
);
124 pci_dma_sync_single_for_device(to_pci_dev(dev
), dma_handle
,
125 size
, (int)direction
);
129 dma_sync_sg_for_cpu(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
130 enum dma_data_direction direction
)
132 BUG_ON(dev
->bus
!= &pci_bus_type
);
134 pci_dma_sync_sg_for_cpu(to_pci_dev(dev
), sg
, nelems
, (int)direction
);
138 dma_sync_sg_for_device(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
139 enum dma_data_direction direction
)
141 BUG_ON(dev
->bus
!= &pci_bus_type
);
143 pci_dma_sync_sg_for_device(to_pci_dev(dev
), sg
, nelems
, (int)direction
);
147 dma_mapping_error(dma_addr_t dma_addr
)
149 return pci_dma_mapping_error(dma_addr
);
156 dma_supported(struct device
*dev
, u64 mask
)
162 dma_set_mask(struct device
*dev
, u64 dma_mask
)
169 dma_alloc_coherent(struct device
*dev
, size_t size
, dma_addr_t
*dma_handle
,
177 dma_free_coherent(struct device
*dev
, size_t size
, void *cpu_addr
,
178 dma_addr_t dma_handle
)
183 static inline dma_addr_t
184 dma_map_single(struct device
*dev
, void *cpu_addr
, size_t size
,
185 enum dma_data_direction direction
)
192 dma_unmap_single(struct device
*dev
, dma_addr_t dma_addr
, size_t size
,
193 enum dma_data_direction direction
)
198 static inline dma_addr_t
199 dma_map_page(struct device
*dev
, struct page
*page
,
200 unsigned long offset
, size_t size
,
201 enum dma_data_direction direction
)
208 dma_unmap_page(struct device
*dev
, dma_addr_t dma_address
, size_t size
,
209 enum dma_data_direction direction
)
215 dma_map_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
216 enum dma_data_direction direction
)
223 dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nhwentries
,
224 enum dma_data_direction direction
)
230 dma_sync_single_for_cpu(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
231 enum dma_data_direction direction
)
237 dma_sync_single_for_device(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
238 enum dma_data_direction direction
)
244 dma_sync_sg_for_cpu(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
245 enum dma_data_direction direction
)
251 dma_sync_sg_for_device(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
252 enum dma_data_direction direction
)
258 dma_error(dma_addr_t dma_addr
)
265 /* Now for the API extensions over the pci_ one */
267 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
268 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
269 #define dma_is_consistent(d) (1)
272 dma_get_cache_alignment(void)
274 /* no easy way to get cache size on all processors, so return
275 * the maximum possible, to be safe */
276 return (1 << INTERNODE_CACHE_SHIFT
);
280 dma_sync_single_range_for_cpu(struct device
*dev
, dma_addr_t dma_handle
,
281 unsigned long offset
, size_t size
,
282 enum dma_data_direction direction
)
284 /* just sync everything, that's all the pci API can do */
285 dma_sync_single_for_cpu(dev
, dma_handle
, offset
+size
, direction
);
289 dma_sync_single_range_for_device(struct device
*dev
, dma_addr_t dma_handle
,
290 unsigned long offset
, size_t size
,
291 enum dma_data_direction direction
)
293 /* just sync everything, that's all the pci API can do */
294 dma_sync_single_for_device(dev
, dma_handle
, offset
+size
, direction
);
298 dma_cache_sync(void *vaddr
, size_t size
,
299 enum dma_data_direction direction
)
301 /* could define this in terms of the dma_cache ... operations,
302 * but if you get this on a platform, you should convert the platform
303 * to using the generic device DMA API */