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>
26 #include <linux/scatterlist.h>
27 #include <linux/dma-debug.h>
28 #include <linux/dma-attrs.h>
30 #include <asm/cacheflush.h>
32 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
34 #define __dma_alloc_coherent(dev, gfp, size, handle) NULL
35 #define __dma_free_coherent(size, addr) ((void)0)
38 * Available generic sets of operations
40 extern struct dma_map_ops dma_direct_ops;
42 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
44 return &dma_direct_ops;
47 static inline int dma_supported(struct device *dev, u64 mask)
49 struct dma_map_ops *ops = get_dma_ops(dev);
53 if (!ops->dma_supported)
55 return ops->dma_supported(dev, mask);
58 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
60 struct dma_map_ops *ops = get_dma_ops(dev);
62 if (unlikely(ops == NULL))
64 if (ops->set_dma_mask)
65 return ops->set_dma_mask(dev, dma_mask);
66 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
68 *dev->dma_mask = dma_mask;
72 #include <asm-generic/dma-mapping-common.h>
74 static inline void __dma_sync(unsigned long paddr,
75 size_t size, enum dma_data_direction direction)
79 case DMA_BIDIRECTIONAL:
80 flush_dcache_range(paddr, paddr + size);
83 invalidate_dcache_range(paddr, paddr + size);
90 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
92 struct dma_map_ops *ops = get_dma_ops(dev);
94 debug_dma_mapping_error(dev, dma_addr);
95 if (ops->mapping_error)
96 return ops->mapping_error(dev, dma_addr);
98 return (dma_addr == DMA_ERROR_CODE);
101 static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
102 enum dma_data_direction direction)
104 BUG_ON(direction == DMA_NONE);
105 __dma_sync(virt_to_phys(vaddr), size, (int)direction);
108 #endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */