ARM: rockchip: fix broken build
[linux/fpc-iii.git] / arch / arm64 / include / asm / dma-mapping.h
blobf0d6d0bfe55ceceba3339bc9044bed31a159a9cf
1 /*
2 * Copyright (C) 2012 ARM Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #ifndef __ASM_DMA_MAPPING_H
17 #define __ASM_DMA_MAPPING_H
19 #ifdef __KERNEL__
21 #include <linux/acpi.h>
22 #include <linux/types.h>
23 #include <linux/vmalloc.h>
25 #include <asm-generic/dma-coherent.h>
27 #include <xen/xen.h>
28 #include <asm/xen/hypervisor.h>
30 #define DMA_ERROR_CODE (~(dma_addr_t)0)
31 extern struct dma_map_ops *dma_ops;
32 extern struct dma_map_ops dummy_dma_ops;
34 static inline struct dma_map_ops *__generic_dma_ops(struct device *dev)
36 if (unlikely(!dev))
37 return dma_ops;
38 else if (dev->archdata.dma_ops)
39 return dev->archdata.dma_ops;
40 else if (acpi_disabled)
41 return dma_ops;
44 * When ACPI is enabled, if arch_set_dma_ops is not called,
45 * we will disable device DMA capability by setting it
46 * to dummy_dma_ops.
48 return &dummy_dma_ops;
51 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
53 if (xen_initial_domain())
54 return xen_dma_ops;
55 else
56 return __generic_dma_ops(dev);
59 static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
60 struct iommu_ops *iommu, bool coherent)
62 if (!acpi_disabled && !dev->archdata.dma_ops)
63 dev->archdata.dma_ops = dma_ops;
65 dev->archdata.dma_coherent = coherent;
67 #define arch_setup_dma_ops arch_setup_dma_ops
69 /* do not use this function in a driver */
70 static inline bool is_device_dma_coherent(struct device *dev)
72 if (!dev)
73 return false;
74 return dev->archdata.dma_coherent;
77 #include <asm-generic/dma-mapping-common.h>
79 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
81 return (dma_addr_t)paddr;
84 static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
86 return (phys_addr_t)dev_addr;
89 static inline int dma_mapping_error(struct device *dev, dma_addr_t dev_addr)
91 struct dma_map_ops *ops = get_dma_ops(dev);
92 debug_dma_mapping_error(dev, dev_addr);
93 return ops->mapping_error(dev, dev_addr);
96 static inline int dma_supported(struct device *dev, u64 mask)
98 struct dma_map_ops *ops = get_dma_ops(dev);
99 return ops->dma_supported(dev, mask);
102 static inline int dma_set_mask(struct device *dev, u64 mask)
104 if (!dev->dma_mask || !dma_supported(dev, mask))
105 return -EIO;
106 *dev->dma_mask = mask;
108 return 0;
111 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
113 if (!dev->dma_mask)
114 return false;
116 return addr + size - 1 <= *dev->dma_mask;
119 static inline void dma_mark_clean(void *addr, size_t size)
123 #define dma_alloc_coherent(d, s, h, f) dma_alloc_attrs(d, s, h, f, NULL)
124 #define dma_free_coherent(d, s, h, f) dma_free_attrs(d, s, h, f, NULL)
126 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
127 dma_addr_t *dma_handle, gfp_t flags,
128 struct dma_attrs *attrs)
130 struct dma_map_ops *ops = get_dma_ops(dev);
131 void *vaddr;
133 if (dma_alloc_from_coherent(dev, size, dma_handle, &vaddr))
134 return vaddr;
136 vaddr = ops->alloc(dev, size, dma_handle, flags, attrs);
137 debug_dma_alloc_coherent(dev, size, *dma_handle, vaddr);
138 return vaddr;
141 static inline void dma_free_attrs(struct device *dev, size_t size,
142 void *vaddr, dma_addr_t dev_addr,
143 struct dma_attrs *attrs)
145 struct dma_map_ops *ops = get_dma_ops(dev);
147 if (dma_release_from_coherent(dev, get_order(size), vaddr))
148 return;
150 debug_dma_free_coherent(dev, size, vaddr, dev_addr);
151 ops->free(dev, size, vaddr, dev_addr, attrs);
155 * There is no dma_cache_sync() implementation, so just return NULL here.
157 static inline void *dma_alloc_noncoherent(struct device *dev, size_t size,
158 dma_addr_t *handle, gfp_t flags)
160 return NULL;
163 static inline void dma_free_noncoherent(struct device *dev, size_t size,
164 void *cpu_addr, dma_addr_t handle)
168 #endif /* __KERNEL__ */
169 #endif /* __ASM_DMA_MAPPING_H */