x86: a P4 is a P6 not an i486
[linux-2.6/openmoko-kernel/knife-kernel.git] / include / linux / dma-mapping.h
blob3320307096237a61495d785d751e897bc54a0102
1 #ifndef _LINUX_DMA_MAPPING_H
2 #define _LINUX_DMA_MAPPING_H
4 #include <linux/device.h>
5 #include <linux/err.h>
7 /* These definitions mirror those in pci.h, so they can be used
8 * interchangeably with their PCI_ counterparts */
9 enum dma_data_direction {
10 DMA_BIDIRECTIONAL = 0,
11 DMA_TO_DEVICE = 1,
12 DMA_FROM_DEVICE = 2,
13 DMA_NONE = 3,
16 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
19 * NOTE: do not use the below macros in new code and do not add new definitions
20 * here.
22 * Instead, just open-code DMA_BIT_MASK(n) within your driver
24 #define DMA_64BIT_MASK DMA_BIT_MASK(64)
25 #define DMA_48BIT_MASK DMA_BIT_MASK(48)
26 #define DMA_47BIT_MASK DMA_BIT_MASK(47)
27 #define DMA_40BIT_MASK DMA_BIT_MASK(40)
28 #define DMA_39BIT_MASK DMA_BIT_MASK(39)
29 #define DMA_35BIT_MASK DMA_BIT_MASK(35)
30 #define DMA_32BIT_MASK DMA_BIT_MASK(32)
31 #define DMA_31BIT_MASK DMA_BIT_MASK(31)
32 #define DMA_30BIT_MASK DMA_BIT_MASK(30)
33 #define DMA_29BIT_MASK DMA_BIT_MASK(29)
34 #define DMA_28BIT_MASK DMA_BIT_MASK(28)
35 #define DMA_24BIT_MASK DMA_BIT_MASK(24)
37 #define DMA_MASK_NONE 0x0ULL
39 static inline int valid_dma_direction(int dma_direction)
41 return ((dma_direction == DMA_BIDIRECTIONAL) ||
42 (dma_direction == DMA_TO_DEVICE) ||
43 (dma_direction == DMA_FROM_DEVICE));
46 static inline int is_device_dma_capable(struct device *dev)
48 return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE;
51 #ifdef CONFIG_HAS_DMA
52 #include <asm/dma-mapping.h>
53 #else
54 #include <asm-generic/dma-mapping-broken.h>
55 #endif
57 /* Backwards compat, remove in 2.7.x */
58 #define dma_sync_single dma_sync_single_for_cpu
59 #define dma_sync_sg dma_sync_sg_for_cpu
61 extern u64 dma_get_required_mask(struct device *dev);
63 static inline unsigned int dma_get_max_seg_size(struct device *dev)
65 return dev->dma_parms ? dev->dma_parms->max_segment_size : 65536;
68 static inline unsigned int dma_set_max_seg_size(struct device *dev,
69 unsigned int size)
71 if (dev->dma_parms) {
72 dev->dma_parms->max_segment_size = size;
73 return 0;
74 } else
75 return -EIO;
78 static inline unsigned long dma_get_seg_boundary(struct device *dev)
80 return dev->dma_parms ?
81 dev->dma_parms->segment_boundary_mask : 0xffffffff;
84 static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
86 if (dev->dma_parms) {
87 dev->dma_parms->segment_boundary_mask = mask;
88 return 0;
89 } else
90 return -EIO;
93 /* flags for the coherent memory api */
94 #define DMA_MEMORY_MAP 0x01
95 #define DMA_MEMORY_IO 0x02
96 #define DMA_MEMORY_INCLUDES_CHILDREN 0x04
97 #define DMA_MEMORY_EXCLUSIVE 0x08
99 #ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
100 static inline int
101 dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
102 dma_addr_t device_addr, size_t size, int flags)
104 return 0;
107 static inline void
108 dma_release_declared_memory(struct device *dev)
112 static inline void *
113 dma_mark_declared_memory_occupied(struct device *dev,
114 dma_addr_t device_addr, size_t size)
116 return ERR_PTR(-EBUSY);
118 #endif
121 * Managed DMA API
123 extern void *dmam_alloc_coherent(struct device *dev, size_t size,
124 dma_addr_t *dma_handle, gfp_t gfp);
125 extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
126 dma_addr_t dma_handle);
127 extern void *dmam_alloc_noncoherent(struct device *dev, size_t size,
128 dma_addr_t *dma_handle, gfp_t gfp);
129 extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
130 dma_addr_t dma_handle);
131 #ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
132 extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
133 dma_addr_t device_addr, size_t size,
134 int flags);
135 extern void dmam_release_declared_memory(struct device *dev);
136 #else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
137 static inline int dmam_declare_coherent_memory(struct device *dev,
138 dma_addr_t bus_addr, dma_addr_t device_addr,
139 size_t size, gfp_t gfp)
141 return 0;
144 static inline void dmam_release_declared_memory(struct device *dev)
147 #endif /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
149 #endif