blob: 0a1006692bb253a601ae7e6e2187e8a983e37767 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_SPARC64_DMA_MAPPING_H
2#define _ASM_SPARC64_DMA_MAPPING_H
3
David S. Millerad7ad572007-07-27 22:39:14 -07004#include <linux/scatterlist.h>
David S. Miller42f14232006-05-23 02:07:22 -07005#include <linux/mm.h>
6
David S. Millerad7ad572007-07-27 22:39:14 -07007#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
David S. Miller9ac6d4a2007-05-14 02:56:03 -07008
David S. Millerad7ad572007-07-27 22:39:14 -07009struct dma_ops {
10 void *(*alloc_coherent)(struct device *dev, size_t size,
11 dma_addr_t *dma_handle, gfp_t flag);
12 void (*free_coherent)(struct device *dev, size_t size,
13 void *cpu_addr, dma_addr_t dma_handle);
14 dma_addr_t (*map_single)(struct device *dev, void *cpu_addr,
15 size_t size,
16 enum dma_data_direction direction);
17 void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
18 size_t size,
19 enum dma_data_direction direction);
20 int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
21 enum dma_data_direction direction);
22 void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
23 int nhwentries,
24 enum dma_data_direction direction);
25 void (*sync_single_for_cpu)(struct device *dev,
26 dma_addr_t dma_handle, size_t size,
27 enum dma_data_direction direction);
28 void (*sync_single_for_device)(struct device *dev,
29 dma_addr_t dma_handle, size_t size,
30 enum dma_data_direction direction);
31 void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
32 int nelems,
33 enum dma_data_direction direction);
34 void (*sync_sg_for_device)(struct device *dev, struct scatterlist *sg,
35 int nelems,
36 enum dma_data_direction direction);
37};
38extern const struct dma_ops *dma_ops;
David S. Miller42f14232006-05-23 02:07:22 -070039
David S. Millerad7ad572007-07-27 22:39:14 -070040extern int dma_supported(struct device *dev, u64 mask);
41extern int dma_set_mask(struct device *dev, u64 dma_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43static inline void *dma_alloc_coherent(struct device *dev, size_t size,
David S. Millerad7ad572007-07-27 22:39:14 -070044 dma_addr_t *dma_handle, gfp_t flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
David S. Millerad7ad572007-07-27 22:39:14 -070046 return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
49static inline void dma_free_coherent(struct device *dev, size_t size,
David S. Millerad7ad572007-07-27 22:39:14 -070050 void *cpu_addr, dma_addr_t dma_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
David S. Millerad7ad572007-07-27 22:39:14 -070052 dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
David S. Millerad7ad572007-07-27 22:39:14 -070055static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
56 size_t size,
57 enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -070058{
David S. Millerad7ad572007-07-27 22:39:14 -070059 return dma_ops->map_single(dev, cpu_addr, size, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -070060}
61
David S. Millerad7ad572007-07-27 22:39:14 -070062static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
63 size_t size,
64 enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -070065{
David S. Millerad7ad572007-07-27 22:39:14 -070066 dma_ops->unmap_single(dev, dma_addr, size, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -070067}
68
David S. Millerad7ad572007-07-27 22:39:14 -070069static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
70 unsigned long offset, size_t size,
71 enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -070072{
David S. Millerad7ad572007-07-27 22:39:14 -070073 return dma_ops->map_single(dev, page_address(page) + offset,
74 size, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -070075}
76
David S. Millerad7ad572007-07-27 22:39:14 -070077static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
78 size_t size,
79 enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -070080{
David S. Millerad7ad572007-07-27 22:39:14 -070081 dma_ops->unmap_single(dev, dma_address, size, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -070082}
83
David S. Millerad7ad572007-07-27 22:39:14 -070084static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
85 int nents, enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -070086{
David S. Millerad7ad572007-07-27 22:39:14 -070087 return dma_ops->map_sg(dev, sg, nents, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -070088}
89
David S. Millerad7ad572007-07-27 22:39:14 -070090static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
91 int nents, enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -070092{
David S. Millerad7ad572007-07-27 22:39:14 -070093 dma_ops->unmap_sg(dev, sg, nents, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -070094}
95
David S. Millerad7ad572007-07-27 22:39:14 -070096static inline void dma_sync_single_for_cpu(struct device *dev,
97 dma_addr_t dma_handle, size_t size,
98 enum dma_data_direction direction)
Randy Dunlap72335892006-07-05 20:18:39 -070099{
David S. Millerad7ad572007-07-27 22:39:14 -0700100 dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction);
Randy Dunlap72335892006-07-05 20:18:39 -0700101}
102
David S. Millerad7ad572007-07-27 22:39:14 -0700103static inline void dma_sync_single_for_device(struct device *dev,
104 dma_addr_t dma_handle,
105 size_t size,
106 enum dma_data_direction direction)
Randy Dunlap72335892006-07-05 20:18:39 -0700107{
David S. Millerad7ad572007-07-27 22:39:14 -0700108 dma_ops->sync_single_for_device(dev, dma_handle, size, direction);
Randy Dunlap72335892006-07-05 20:18:39 -0700109}
110
David S. Millerad7ad572007-07-27 22:39:14 -0700111static inline void dma_sync_sg_for_cpu(struct device *dev,
112 struct scatterlist *sg, int nelems,
113 enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -0700114{
David S. Millerad7ad572007-07-27 22:39:14 -0700115 dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -0700116}
117
David S. Millerad7ad572007-07-27 22:39:14 -0700118static inline void dma_sync_sg_for_device(struct device *dev,
119 struct scatterlist *sg, int nelems,
120 enum dma_data_direction direction)
David S. Millerf04dbac2007-06-04 23:32:23 -0700121{
David S. Millerad7ad572007-07-27 22:39:14 -0700122 dma_ops->sync_sg_for_device(dev, sg, nelems, direction);
David S. Millerf04dbac2007-06-04 23:32:23 -0700123}
124
David S. Millerad7ad572007-07-27 22:39:14 -0700125static inline int dma_mapping_error(dma_addr_t dma_addr)
David S. Millerf04dbac2007-06-04 23:32:23 -0700126{
David S. Millerad7ad572007-07-27 22:39:14 -0700127 return (dma_addr == DMA_ERROR_CODE);
David S. Millerf04dbac2007-06-04 23:32:23 -0700128}
129
David S. Miller36321422006-06-25 02:07:52 -0700130#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
131#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
Ralf Baechlef67637e2006-12-06 20:38:54 -0800132#define dma_is_consistent(d, h) (1)
David S. Miller36321422006-06-25 02:07:52 -0700133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif /* _ASM_SPARC64_DMA_MAPPING_H */