dma-mapping: consolidate dma_supported
[pandora-kernel.git] / arch / microblaze / include / asm / dma-mapping.h
1 /*
2  * Implements the generic device dma API for microblaze and the pci
3  *
4  * Copyright (C) 2009-2010 Michal Simek <monstr@monstr.eu>
5  * Copyright (C) 2009-2010 PetaLogix
6  *
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.
10  *
11  * This file is base on powerpc and x86 dma-mapping.h versions
12  * Copyright (C) 2004 IBM
13  */
14
15 #ifndef _ASM_MICROBLAZE_DMA_MAPPING_H
16 #define _ASM_MICROBLAZE_DMA_MAPPING_H
17
18 /*
19  * See Documentation/DMA-API-HOWTO.txt and
20  * Documentation/DMA-API.txt for documentation.
21  */
22
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/cacheflush.h>
31
32 #define DMA_ERROR_CODE          (~(dma_addr_t)0x0)
33
34 #define __dma_alloc_coherent(dev, gfp, size, handle)    NULL
35 #define __dma_free_coherent(size, addr)         ((void)0)
36
37 /*
38  * Available generic sets of operations
39  */
40 extern struct dma_map_ops dma_direct_ops;
41
42 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
43 {
44         return &dma_direct_ops;
45 }
46
47 #include <asm-generic/dma-mapping-common.h>
48
49 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
50 {
51         struct dma_map_ops *ops = get_dma_ops(dev);
52
53         if (unlikely(ops == NULL))
54                 return -EIO;
55         if (ops->set_dma_mask)
56                 return ops->set_dma_mask(dev, dma_mask);
57         if (!dev->dma_mask || !dma_supported(dev, dma_mask))
58                 return -EIO;
59         *dev->dma_mask = dma_mask;
60         return 0;
61 }
62
63 static inline void __dma_sync(unsigned long paddr,
64                               size_t size, enum dma_data_direction direction)
65 {
66         switch (direction) {
67         case DMA_TO_DEVICE:
68         case DMA_BIDIRECTIONAL:
69                 flush_dcache_range(paddr, paddr + size);
70                 break;
71         case DMA_FROM_DEVICE:
72                 invalidate_dcache_range(paddr, paddr + size);
73                 break;
74         default:
75                 BUG();
76         }
77 }
78
79 static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
80                 enum dma_data_direction direction)
81 {
82         BUG_ON(direction == DMA_NONE);
83         __dma_sync(virt_to_phys(vaddr), size, (int)direction);
84 }
85
86 #endif  /* _ASM_MICROBLAZE_DMA_MAPPING_H */