blob: 0ebfafbd338ca56fc89f781c2848a9c16b81cb6d [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
16#define DMA_64BIT_MASK 0xffffffffffffffffULL
Francois Romieu4c1b4622006-05-10 12:48:57 -070017#define DMA_48BIT_MASK 0x0000ffffffffffffULL
Lee Revellb8112df2005-06-15 14:19:03 -040018#define DMA_40BIT_MASK 0x000000ffffffffffULL
19#define DMA_39BIT_MASK 0x0000007fffffffffULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define DMA_32BIT_MASK 0x00000000ffffffffULL
Lee Revellb8112df2005-06-15 14:19:03 -040021#define DMA_31BIT_MASK 0x000000007fffffffULL
22#define DMA_30BIT_MASK 0x000000003fffffffULL
23#define DMA_29BIT_MASK 0x000000001fffffffULL
Tobias Klauser9d2f9282006-03-22 10:53:19 +010024#define DMA_28BIT_MASK 0x000000000fffffffULL
Tobias Klauser56b146d2006-04-10 22:54:21 -070025#define DMA_24BIT_MASK 0x0000000000ffffffULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
James Bottomley32e8f702007-10-16 01:23:55 -070027#define DMA_MASK_NONE 0x0ULL
28
Rolf Eike Beerd6bd3a32006-09-29 01:59:48 -070029static inline int valid_dma_direction(int dma_direction)
30{
31 return ((dma_direction == DMA_BIDIRECTIONAL) ||
32 (dma_direction == DMA_TO_DEVICE) ||
33 (dma_direction == DMA_FROM_DEVICE));
34}
35
James Bottomley32e8f702007-10-16 01:23:55 -070036static inline int is_device_dma_capable(struct device *dev)
37{
38 return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE;
39}
40
Dan Williams1b0fac42007-07-15 23:40:26 -070041#ifdef CONFIG_HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/dma-mapping.h>
Dan Williams1b0fac42007-07-15 23:40:26 -070043#else
44#include <asm-generic/dma-mapping-broken.h>
45#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47/* Backwards compat, remove in 2.7.x */
48#define dma_sync_single dma_sync_single_for_cpu
49#define dma_sync_sg dma_sync_sg_for_cpu
50
51extern u64 dma_get_required_mask(struct device *dev);
52
53/* flags for the coherent memory api */
54#define DMA_MEMORY_MAP 0x01
55#define DMA_MEMORY_IO 0x02
56#define DMA_MEMORY_INCLUDES_CHILDREN 0x04
57#define DMA_MEMORY_EXCLUSIVE 0x08
58
59#ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
60static inline int
61dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
62 dma_addr_t device_addr, size_t size, int flags)
63{
64 return 0;
65}
66
67static inline void
68dma_release_declared_memory(struct device *dev)
69{
70}
71
72static inline void *
73dma_mark_declared_memory_occupied(struct device *dev,
74 dma_addr_t device_addr, size_t size)
75{
76 return ERR_PTR(-EBUSY);
77}
78#endif
79
Tejun Heo9ac78492007-01-20 16:00:26 +090080/*
81 * Managed DMA API
82 */
83extern void *dmam_alloc_coherent(struct device *dev, size_t size,
84 dma_addr_t *dma_handle, gfp_t gfp);
85extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
86 dma_addr_t dma_handle);
87extern void *dmam_alloc_noncoherent(struct device *dev, size_t size,
88 dma_addr_t *dma_handle, gfp_t gfp);
89extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
90 dma_addr_t dma_handle);
91#ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
92extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
93 dma_addr_t device_addr, size_t size,
94 int flags);
95extern void dmam_release_declared_memory(struct device *dev);
96#else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
97static inline int dmam_declare_coherent_memory(struct device *dev,
98 dma_addr_t bus_addr, dma_addr_t device_addr,
99 size_t size, gfp_t gfp)
100{
101 return 0;
102}
103
104static inline void dmam_release_declared_memory(struct device *dev)
105{
106}
107#endif /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#endif