1 #ifndef _ASM_SPARC64_DMA_MAPPING_H
2 #define _ASM_SPARC64_DMA_MAPPING_H
7 /* we implement the API below in terms of the existing PCI one,
10 /* need struct page definitions */
13 #include <asm/of_device.h>
16 dma_supported(struct device
*dev
, u64 mask
)
18 BUG_ON(dev
->bus
!= &pci_bus_type
);
20 return pci_dma_supported(to_pci_dev(dev
), mask
);
24 dma_set_mask(struct device
*dev
, u64 dma_mask
)
26 BUG_ON(dev
->bus
!= &pci_bus_type
);
28 return pci_set_dma_mask(to_pci_dev(dev
), dma_mask
);
32 dma_alloc_coherent(struct device
*dev
, size_t size
, dma_addr_t
*dma_handle
,
35 BUG_ON(dev
->bus
!= &pci_bus_type
);
37 return pci_iommu_ops
->alloc_consistent(to_pci_dev(dev
), size
, dma_handle
, flag
);
41 dma_free_coherent(struct device
*dev
, size_t size
, void *cpu_addr
,
42 dma_addr_t dma_handle
)
44 BUG_ON(dev
->bus
!= &pci_bus_type
);
46 pci_free_consistent(to_pci_dev(dev
), size
, cpu_addr
, dma_handle
);
49 static inline dma_addr_t
50 dma_map_single(struct device
*dev
, void *cpu_addr
, size_t size
,
51 enum dma_data_direction direction
)
53 BUG_ON(dev
->bus
!= &pci_bus_type
);
55 return pci_map_single(to_pci_dev(dev
), cpu_addr
, size
, (int)direction
);
59 dma_unmap_single(struct device
*dev
, dma_addr_t dma_addr
, size_t size
,
60 enum dma_data_direction direction
)
62 BUG_ON(dev
->bus
!= &pci_bus_type
);
64 pci_unmap_single(to_pci_dev(dev
), dma_addr
, size
, (int)direction
);
67 static inline dma_addr_t
68 dma_map_page(struct device
*dev
, struct page
*page
,
69 unsigned long offset
, size_t size
,
70 enum dma_data_direction direction
)
72 BUG_ON(dev
->bus
!= &pci_bus_type
);
74 return pci_map_page(to_pci_dev(dev
), page
, offset
, size
, (int)direction
);
78 dma_unmap_page(struct device
*dev
, dma_addr_t dma_address
, size_t size
,
79 enum dma_data_direction direction
)
81 BUG_ON(dev
->bus
!= &pci_bus_type
);
83 pci_unmap_page(to_pci_dev(dev
), dma_address
, size
, (int)direction
);
87 dma_map_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
88 enum dma_data_direction direction
)
90 BUG_ON(dev
->bus
!= &pci_bus_type
);
92 return pci_map_sg(to_pci_dev(dev
), sg
, nents
, (int)direction
);
96 dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nhwentries
,
97 enum dma_data_direction direction
)
99 BUG_ON(dev
->bus
!= &pci_bus_type
);
101 pci_unmap_sg(to_pci_dev(dev
), sg
, nhwentries
, (int)direction
);
105 dma_sync_single_for_cpu(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
106 enum dma_data_direction direction
)
108 BUG_ON(dev
->bus
!= &pci_bus_type
);
110 pci_dma_sync_single_for_cpu(to_pci_dev(dev
), dma_handle
,
111 size
, (int)direction
);
115 dma_sync_single_for_device(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
116 enum dma_data_direction direction
)
118 BUG_ON(dev
->bus
!= &pci_bus_type
);
120 pci_dma_sync_single_for_device(to_pci_dev(dev
), dma_handle
,
121 size
, (int)direction
);
125 dma_sync_sg_for_cpu(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
126 enum dma_data_direction direction
)
128 BUG_ON(dev
->bus
!= &pci_bus_type
);
130 pci_dma_sync_sg_for_cpu(to_pci_dev(dev
), sg
, nelems
, (int)direction
);
134 dma_sync_sg_for_device(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
135 enum dma_data_direction direction
)
137 BUG_ON(dev
->bus
!= &pci_bus_type
);
139 pci_dma_sync_sg_for_device(to_pci_dev(dev
), sg
, nelems
, (int)direction
);
143 dma_mapping_error(dma_addr_t dma_addr
)
145 return pci_dma_mapping_error(dma_addr
);
155 dma_supported(struct device
*dev
, u64 mask
)
162 dma_set_mask(struct device
*dev
, u64 dma_mask
)
168 static inline void *dma_alloc_coherent(struct device
*dev
, size_t size
,
169 dma_addr_t
*dma_handle
, gfp_t flag
)
175 static inline void dma_free_coherent(struct device
*dev
, size_t size
,
176 void *vaddr
, dma_addr_t dma_handle
)
181 static inline dma_addr_t
182 dma_map_single(struct device
*dev
, void *cpu_addr
, size_t size
,
183 enum dma_data_direction direction
)
190 dma_unmap_single(struct device
*dev
, dma_addr_t dma_addr
, size_t size
,
191 enum dma_data_direction direction
)
196 static inline dma_addr_t
197 dma_map_page(struct device
*dev
, struct page
*page
,
198 unsigned long offset
, size_t size
,
199 enum dma_data_direction direction
)
206 dma_unmap_page(struct device
*dev
, dma_addr_t dma_address
, size_t size
,
207 enum dma_data_direction direction
)
213 dma_map_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
214 enum dma_data_direction direction
)
221 dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nhwentries
,
222 enum dma_data_direction direction
)
228 dma_sync_single_for_cpu(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
229 enum dma_data_direction direction
)
235 dma_sync_single_for_device(struct device
*dev
, dma_addr_t dma_handle
, size_t size
,
236 enum dma_data_direction direction
)
242 dma_sync_sg_for_cpu(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
243 enum dma_data_direction direction
)
249 dma_sync_sg_for_device(struct device
*dev
, struct scatterlist
*sg
, int nelems
,
250 enum dma_data_direction direction
)
256 dma_mapping_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, h) (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(struct device
*dev
, 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 */
307 #endif /* _ASM_SPARC64_DMA_MAPPING_H */