1 #ifndef ___ASM_SPARC_DMA_MAPPING_H
2 #define ___ASM_SPARC_DMA_MAPPING_H
4 #include <linux/scatterlist.h>
7 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
9 extern int dma_supported(struct device
*dev
, u64 mask
);
10 extern int dma_set_mask(struct device
*dev
, u64 dma_mask
);
12 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
13 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
14 #define dma_is_consistent(d, h) (1)
17 void *(*alloc_coherent
)(struct device
*dev
, size_t size
,
18 dma_addr_t
*dma_handle
, gfp_t flag
);
19 void (*free_coherent
)(struct device
*dev
, size_t size
,
20 void *cpu_addr
, dma_addr_t dma_handle
);
21 dma_addr_t (*map_page
)(struct device
*dev
, struct page
*page
,
22 unsigned long offset
, size_t size
,
23 enum dma_data_direction direction
);
24 void (*unmap_page
)(struct device
*dev
, dma_addr_t dma_addr
,
26 enum dma_data_direction direction
);
27 int (*map_sg
)(struct device
*dev
, struct scatterlist
*sg
, int nents
,
28 enum dma_data_direction direction
);
29 void (*unmap_sg
)(struct device
*dev
, struct scatterlist
*sg
,
31 enum dma_data_direction direction
);
32 void (*sync_single_for_cpu
)(struct device
*dev
,
33 dma_addr_t dma_handle
, size_t size
,
34 enum dma_data_direction direction
);
35 void (*sync_single_for_device
)(struct device
*dev
,
36 dma_addr_t dma_handle
, size_t size
,
37 enum dma_data_direction direction
);
38 void (*sync_sg_for_cpu
)(struct device
*dev
, struct scatterlist
*sg
,
40 enum dma_data_direction direction
);
41 void (*sync_sg_for_device
)(struct device
*dev
,
42 struct scatterlist
*sg
, int nents
,
43 enum dma_data_direction dir
);
45 extern const struct dma_ops
*dma_ops
;
47 static inline void *dma_alloc_coherent(struct device
*dev
, size_t size
,
48 dma_addr_t
*dma_handle
, gfp_t flag
)
50 return dma_ops
->alloc_coherent(dev
, size
, dma_handle
, flag
);
53 static inline void dma_free_coherent(struct device
*dev
, size_t size
,
54 void *cpu_addr
, dma_addr_t dma_handle
)
56 dma_ops
->free_coherent(dev
, size
, cpu_addr
, dma_handle
);
59 static inline dma_addr_t
dma_map_single(struct device
*dev
, void *cpu_addr
,
61 enum dma_data_direction direction
)
63 return dma_ops
->map_page(dev
, virt_to_page(cpu_addr
),
64 (unsigned long)cpu_addr
& ~PAGE_MASK
, size
,
68 static inline void dma_unmap_single(struct device
*dev
, dma_addr_t dma_addr
,
70 enum dma_data_direction direction
)
72 dma_ops
->unmap_page(dev
, dma_addr
, size
, direction
);
75 static inline dma_addr_t
dma_map_page(struct device
*dev
, struct page
*page
,
76 unsigned long offset
, size_t size
,
77 enum dma_data_direction direction
)
79 return dma_ops
->map_page(dev
, page
, offset
, size
, direction
);
82 static inline void dma_unmap_page(struct device
*dev
, dma_addr_t dma_address
,
84 enum dma_data_direction direction
)
86 dma_ops
->unmap_page(dev
, dma_address
, size
, direction
);
89 static inline int dma_map_sg(struct device
*dev
, struct scatterlist
*sg
,
90 int nents
, enum dma_data_direction direction
)
92 return dma_ops
->map_sg(dev
, sg
, nents
, direction
);
95 static inline void dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
,
96 int nents
, enum dma_data_direction direction
)
98 dma_ops
->unmap_sg(dev
, sg
, nents
, direction
);
101 static inline void dma_sync_single_for_cpu(struct device
*dev
,
102 dma_addr_t dma_handle
, size_t size
,
103 enum dma_data_direction direction
)
105 dma_ops
->sync_single_for_cpu(dev
, dma_handle
, size
, direction
);
108 static inline void dma_sync_single_for_device(struct device
*dev
,
109 dma_addr_t dma_handle
,
111 enum dma_data_direction direction
)
113 if (dma_ops
->sync_single_for_device
)
114 dma_ops
->sync_single_for_device(dev
, dma_handle
, size
,
118 static inline void dma_sync_sg_for_cpu(struct device
*dev
,
119 struct scatterlist
*sg
, int nelems
,
120 enum dma_data_direction direction
)
122 dma_ops
->sync_sg_for_cpu(dev
, sg
, nelems
, direction
);
125 static inline void dma_sync_sg_for_device(struct device
*dev
,
126 struct scatterlist
*sg
, int nelems
,
127 enum dma_data_direction direction
)
129 if (dma_ops
->sync_sg_for_device
)
130 dma_ops
->sync_sg_for_device(dev
, sg
, nelems
, direction
);
133 static inline void dma_sync_single_range_for_cpu(struct device
*dev
,
134 dma_addr_t dma_handle
,
135 unsigned long offset
,
137 enum dma_data_direction dir
)
139 dma_sync_single_for_cpu(dev
, dma_handle
+offset
, size
, dir
);
142 static inline void dma_sync_single_range_for_device(struct device
*dev
,
143 dma_addr_t dma_handle
,
144 unsigned long offset
,
146 enum dma_data_direction dir
)
148 dma_sync_single_for_device(dev
, dma_handle
+offset
, size
, dir
);
152 static inline int dma_mapping_error(struct device
*dev
, dma_addr_t dma_addr
)
154 return (dma_addr
== DMA_ERROR_CODE
);
157 static inline int dma_get_cache_alignment(void)
160 * no easy way to get cache size on all processors, so return
161 * the maximum possible, to be safe
163 return (1 << INTERNODE_CACHE_SHIFT
);