blob: 101a2d4636befbd1248b7642c38a87ff77243f07 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_LINUX_DMA_MAPPING_H
2#define _ASM_LINUX_DMA_MAPPING_H
3
4#include <linux/device.h>
5#include <linux/err.h>
6
7/* These definitions mirror those in pci.h, so they can be used
8 * interchangeably with their PCI_ counterparts */
9enum dma_data_direction {
10 DMA_BIDIRECTIONAL = 0,
11 DMA_TO_DEVICE = 1,
12 DMA_FROM_DEVICE = 2,
13 DMA_NONE = 3,
14};
15
Andrew Morton8f286c32007-10-18 03:05:07 -070016#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
Borislav Petkov34c65382007-10-18 03:05:06 -070017
Andrew Morton8f286c32007-10-18 03:05:07 -070018/*
19 * NOTE: do not use the below macros in new code and do not add new definitions
20 * here.
21 *
22 * Instead, just open-code DMA_BIT_MASK(n) within your driver
23 */
24#define DMA_64BIT_MASK DMA_BIT_MASK(64)
Borislav Petkov34c65382007-10-18 03:05:06 -070025#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
James Bottomley32e8f702007-10-16 01:23:55 -070037#define DMA_MASK_NONE 0x0ULL
38
Rolf Eike Beerd6bd3a32006-09-29 01:59:48 -070039static inline int valid_dma_direction(int dma_direction)
40{
41 return ((dma_direction == DMA_BIDIRECTIONAL) ||
42 (dma_direction == DMA_TO_DEVICE) ||
43 (dma_direction == DMA_FROM_DEVICE));
44}
45
James Bottomley32e8f702007-10-16 01:23:55 -070046static inline int is_device_dma_capable(struct device *dev)
47{
48 return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE;
49}
50
Dan Williams1b0fac42007-07-15 23:40:26 -070051#ifdef CONFIG_HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/dma-mapping.h>
Dan Williams1b0fac42007-07-15 23:40:26 -070053#else
54#include <asm-generic/dma-mapping-broken.h>
55#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
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
60
61extern u64 dma_get_required_mask(struct device *dev);
62
63/* flags for the coherent memory api */
64#define DMA_MEMORY_MAP 0x01
65#define DMA_MEMORY_IO 0x02
66#define DMA_MEMORY_INCLUDES_CHILDREN 0x04
67#define DMA_MEMORY_EXCLUSIVE 0x08
68
69#ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
70static inline int
71dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
72 dma_addr_t device_addr, size_t size, int flags)
73{
74 return 0;
75}
76
77static inline void
78dma_release_declared_memory(struct device *dev)
79{
80}
81
82static inline void *
83dma_mark_declared_memory_occupied(struct device *dev,
84 dma_addr_t device_addr, size_t size)
85{
86 return ERR_PTR(-EBUSY);
87}
88#endif
89
Tejun Heo9ac78492007-01-20 16:00:26 +090090/*
91 * Managed DMA API
92 */
93extern void *dmam_alloc_coherent(struct device *dev, size_t size,
94 dma_addr_t *dma_handle, gfp_t gfp);
95extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
96 dma_addr_t dma_handle);
97extern void *dmam_alloc_noncoherent(struct device *dev, size_t size,
98 dma_addr_t *dma_handle, gfp_t gfp);
99extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
100 dma_addr_t dma_handle);
101#ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
102extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
103 dma_addr_t device_addr, size_t size,
104 int flags);
105extern void dmam_release_declared_memory(struct device *dev);
106#else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
107static inline int dmam_declare_coherent_memory(struct device *dev,
108 dma_addr_t bus_addr, dma_addr_t device_addr,
109 size_t size, gfp_t gfp)
110{
111 return 0;
112}
113
114static inline void dmam_release_declared_memory(struct device *dev)
115{
116}
117#endif /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif