ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-ppc64 / dma-mapping.h
1 /* Copyright (C) 2004 IBM
2  *
3  * Implements the generic device dma API for ppc64. Handles
4  * the pci and vio busses
5  */
6
7 #ifndef _ASM_DMA_MAPPING_H
8 #define _ASM_DMA_MAPPING_H
9
10 #include <linux/types.h>
11 #include <linux/device.h>
12 #include <linux/cache.h>
13 /* need struct page definitions */
14 #include <linux/mm.h>
15 #include <asm/scatterlist.h>
16 #include <asm/bug.h>
17
18 #define DMA_ERROR_CODE          (~(dma_addr_t)0x0)
19
20 extern int dma_supported(struct device *dev, u64 mask);
21 extern int dma_set_mask(struct device *dev, u64 dma_mask);
22 extern void *dma_alloc_coherent(struct device *dev, size_t size,
23                 dma_addr_t *dma_handle, int flag);
24 extern void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
25                 dma_addr_t dma_handle);
26 extern dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
27                 size_t size, enum dma_data_direction direction);
28 extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
29                 size_t size, enum dma_data_direction direction);
30 extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
31                 unsigned long offset, size_t size,
32                 enum dma_data_direction direction);
33 extern void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
34                 size_t size, enum dma_data_direction direction);
35 extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
36                 enum dma_data_direction direction);
37 extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
38                 int nhwentries, enum dma_data_direction direction);
39
40 static inline void
41 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
42                         enum dma_data_direction direction)
43 {
44         BUG_ON(direction == DMA_NONE);
45         /* nothing to do */
46 }
47
48 static inline void
49 dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
50                            enum dma_data_direction direction)
51 {
52         BUG_ON(direction == DMA_NONE);
53         /* nothing to do */
54 }
55
56 static inline void
57 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
58                     enum dma_data_direction direction)
59 {
60         BUG_ON(direction == DMA_NONE);
61         /* nothing to do */
62 }
63
64 static inline void
65 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
66                        enum dma_data_direction direction)
67 {
68         BUG_ON(direction == DMA_NONE);
69         /* nothing to do */
70 }
71
72 static inline int dma_mapping_error(dma_addr_t dma_addr)
73 {
74         return (dma_addr == DMA_ERROR_CODE);
75 }
76
77 /* Now for the API extensions over the pci_ one */
78
79 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
80 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
81 #define dma_is_consistent(d)    (1)
82
83 static inline int
84 dma_get_cache_alignment(void)
85 {
86         /* no easy way to get cache size on all processors, so return
87          * the maximum possible, to be safe */
88         return (1 << L1_CACHE_SHIFT_MAX);
89 }
90
91 static inline void
92 dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
93                               unsigned long offset, size_t size,
94                               enum dma_data_direction direction)
95 {
96         BUG_ON(direction == DMA_NONE);
97         /* nothing to do */
98 }
99
100 static inline void
101 dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
102                                  unsigned long offset, size_t size,
103                                  enum dma_data_direction direction)
104 {
105         BUG_ON(direction == DMA_NONE);
106         /* nothing to do */
107 }
108
109 static inline void
110 dma_cache_sync(void *vaddr, size_t size,
111                enum dma_data_direction direction)
112 {
113         BUG_ON(direction == DMA_NONE);
114         /* nothing to do */
115 }
116
117 #endif  /* _ASM_DMA_MAPPING_H */