Use dentry_path() to create full path to inode object
[pohmelfs.git] / arch / microblaze / include / asm / dma-mapping.h
blob3a3e5b8868544718c7b9b9c0af796f2aed4a6625
1 /*
2 * Implements the generic device dma API for microblaze and the pci
4 * Copyright (C) 2009-2010 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2009-2010 PetaLogix
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
11 * This file is base on powerpc and x86 dma-mapping.h versions
12 * Copyright (C) 2004 IBM
15 #ifndef _ASM_MICROBLAZE_DMA_MAPPING_H
16 #define _ASM_MICROBLAZE_DMA_MAPPING_H
19 * See Documentation/DMA-API-HOWTO.txt and
20 * Documentation/DMA-API.txt for documentation.
23 #include <linux/types.h>
24 #include <linux/cache.h>
25 #include <linux/mm.h>
26 #include <linux/scatterlist.h>
27 #include <linux/dma-debug.h>
28 #include <linux/dma-attrs.h>
29 #include <asm/io.h>
30 #include <asm-generic/dma-coherent.h>
31 #include <asm/cacheflush.h>
33 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
35 #define __dma_alloc_coherent(dev, gfp, size, handle) NULL
36 #define __dma_free_coherent(size, addr) ((void)0)
38 static inline unsigned long device_to_mask(struct device *dev)
40 if (dev->dma_mask && *dev->dma_mask)
41 return *dev->dma_mask;
42 /* Assume devices without mask can take 32 bit addresses */
43 return 0xfffffffful;
46 extern struct dma_map_ops *dma_ops;
49 * Available generic sets of operations
51 extern struct dma_map_ops dma_direct_ops;
53 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
55 /* We don't handle the NULL dev case for ISA for now. We could
56 * do it via an out of line call but it is not needed for now. The
57 * only ISA DMA device we support is the floppy and we have a hack
58 * in the floppy driver directly to get a device for us.
60 if (unlikely(!dev) || !dev->archdata.dma_ops)
61 return NULL;
63 return dev->archdata.dma_ops;
66 static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
68 dev->archdata.dma_ops = ops;
71 static inline int dma_supported(struct device *dev, u64 mask)
73 struct dma_map_ops *ops = get_dma_ops(dev);
75 if (unlikely(!ops))
76 return 0;
77 if (!ops->dma_supported)
78 return 1;
79 return ops->dma_supported(dev, mask);
82 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
84 struct dma_map_ops *ops = get_dma_ops(dev);
86 if (unlikely(ops == NULL))
87 return -EIO;
88 if (ops->set_dma_mask)
89 return ops->set_dma_mask(dev, dma_mask);
90 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
91 return -EIO;
92 *dev->dma_mask = dma_mask;
93 return 0;
96 #include <asm-generic/dma-mapping-common.h>
98 static inline void __dma_sync(unsigned long paddr,
99 size_t size, enum dma_data_direction direction)
101 switch (direction) {
102 case DMA_TO_DEVICE:
103 case DMA_BIDIRECTIONAL:
104 flush_dcache_range(paddr, paddr + size);
105 break;
106 case DMA_FROM_DEVICE:
107 invalidate_dcache_range(paddr, paddr + size);
108 break;
109 default:
110 BUG();
114 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
116 struct dma_map_ops *ops = get_dma_ops(dev);
117 if (ops->mapping_error)
118 return ops->mapping_error(dev, dma_addr);
120 return (dma_addr == DMA_ERROR_CODE);
123 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
124 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
126 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
127 dma_addr_t *dma_handle, gfp_t flag)
129 struct dma_map_ops *ops = get_dma_ops(dev);
130 void *memory;
132 BUG_ON(!ops);
134 memory = ops->alloc_coherent(dev, size, dma_handle, flag);
136 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
137 return memory;
140 static inline void dma_free_coherent(struct device *dev, size_t size,
141 void *cpu_addr, dma_addr_t dma_handle)
143 struct dma_map_ops *ops = get_dma_ops(dev);
145 BUG_ON(!ops);
146 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
147 ops->free_coherent(dev, size, cpu_addr, dma_handle);
150 static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
151 enum dma_data_direction direction)
153 BUG_ON(direction == DMA_NONE);
154 __dma_sync(virt_to_phys(vaddr), size, (int)direction);
157 #endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */