Commit | Line | Data |
---|---|---|
10c9c10c G |
1 | /* |
2 | * linux/arch/unicore32/include/asm/dma-mapping.h | |
3 | * | |
4 | * Code specific to PKUnity SoC and UniCore ISA | |
5 | * | |
6 | * Copyright (C) 2001-2010 GUAN Xue-tao | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | */ | |
12 | #ifndef __UNICORE_DMA_MAPPING_H__ | |
13 | #define __UNICORE_DMA_MAPPING_H__ | |
14 | ||
15 | #ifdef __KERNEL__ | |
16 | ||
17 | #include <linux/mm_types.h> | |
18 | #include <linux/scatterlist.h> | |
19 | #include <linux/swiotlb.h> | |
20 | ||
21 | #include <asm-generic/dma-coherent.h> | |
22 | ||
23 | #include <asm/memory.h> | |
24 | #include <asm/cacheflush.h> | |
25 | ||
26 | extern struct dma_map_ops swiotlb_dma_map_ops; | |
27 | ||
28 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) | |
29 | { | |
30 | return &swiotlb_dma_map_ops; | |
31 | } | |
32 | ||
33 | static inline int dma_supported(struct device *dev, u64 mask) | |
34 | { | |
35 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | |
36 | ||
37 | if (unlikely(dma_ops == NULL)) | |
38 | return 0; | |
39 | ||
40 | return dma_ops->dma_supported(dev, mask); | |
41 | } | |
42 | ||
43 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | |
44 | { | |
45 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | |
46 | ||
47 | if (dma_ops->mapping_error) | |
48 | return dma_ops->mapping_error(dev, dma_addr); | |
49 | ||
50 | return 0; | |
51 | } | |
52 | ||
53 | #include <asm-generic/dma-mapping-common.h> | |
54 | ||
55 | static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) | |
56 | { | |
57 | if (dev && dev->dma_mask) | |
58 | return addr + size - 1 <= *dev->dma_mask; | |
59 | ||
60 | return 1; | |
61 | } | |
62 | ||
63 | static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) | |
64 | { | |
65 | return paddr; | |
66 | } | |
67 | ||
68 | static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr) | |
69 | { | |
70 | return daddr; | |
71 | } | |
72 | ||
73 | static inline void dma_mark_clean(void *addr, size_t size) {} | |
74 | ||
75 | static inline int dma_set_mask(struct device *dev, u64 dma_mask) | |
76 | { | |
77 | if (!dev->dma_mask || !dma_supported(dev, dma_mask)) | |
78 | return -EIO; | |
79 | ||
80 | *dev->dma_mask = dma_mask; | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
ffc4a3fa AP |
85 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) |
86 | ||
87 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, | |
88 | dma_addr_t *dma_handle, gfp_t flag, | |
89 | struct dma_attrs *attrs) | |
10c9c10c G |
90 | { |
91 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | |
92 | ||
ffc4a3fa | 93 | return dma_ops->alloc(dev, size, dma_handle, flag, attrs); |
10c9c10c G |
94 | } |
95 | ||
ffc4a3fa AP |
96 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) |
97 | ||
98 | static inline void dma_free_attrs(struct device *dev, size_t size, | |
99 | void *cpu_addr, dma_addr_t dma_handle, | |
100 | struct dma_attrs *attrs) | |
10c9c10c G |
101 | { |
102 | struct dma_map_ops *dma_ops = get_dma_ops(dev); | |
103 | ||
ffc4a3fa | 104 | dma_ops->free(dev, size, cpu_addr, dma_handle, attrs); |
10c9c10c G |
105 | } |
106 | ||
107 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) | |
108 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) | |
109 | ||
110 | static inline void dma_cache_sync(struct device *dev, void *vaddr, | |
111 | size_t size, enum dma_data_direction direction) | |
112 | { | |
113 | unsigned long start = (unsigned long)vaddr; | |
114 | unsigned long end = start + size; | |
115 | ||
116 | switch (direction) { | |
117 | case DMA_NONE: | |
118 | BUG(); | |
119 | case DMA_FROM_DEVICE: | |
120 | case DMA_BIDIRECTIONAL: /* writeback and invalidate */ | |
121 | __cpuc_dma_flush_range(start, end); | |
122 | break; | |
123 | case DMA_TO_DEVICE: /* writeback only */ | |
124 | __cpuc_dma_clean_range(start, end); | |
125 | break; | |
126 | } | |
127 | } | |
128 | ||
129 | #endif /* __KERNEL__ */ | |
130 | #endif |