8f2dd07474841947c8c3a6a0a83030d6ff3f0ba1
[firefly-linux-kernel-4.4.55.git] / include / linux / rockchip-iovmm.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation.
5  */
6
7 #ifndef __ASM_PLAT_IOVMM_H
8 #define __ASM_PLAT_IOVMM_H
9
10 #include <linux/list.h>
11 #include <linux/atomic.h>
12 #include <linux/spinlock.h>
13
14 #define IEP_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
15 #define VIP_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
16 #define ISP_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
17 #define VOPB_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
18 #define VOPL_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
19 #define VOP_IOMMU_COMPATIBLE_NAME       "rockchip,iommu"
20 #define HEVC_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
21 #define VPU_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
22 #define VDEC_IOMMU_COMPATIBLE_NAME "rockchip,iommu"
23
24 enum rk_iommu_inttype {
25         IOMMU_PAGEFAULT,
26         IOMMU_BUSERROR,
27         IOMMU_FAULT_UNKNOWN,
28         IOMMU_FAULTS_NUM
29 };
30
31 struct iommu_drvdata;
32
33 /*
34  * @itype: type of fault.
35  * @pgtable_base: the physical address of page table base. This is 0 if @itype
36  *                                is IOMMU_BUSERROR.
37  * @fault_addr: the device (virtual) address that the System MMU tried to
38  *                         translated. This is 0 if @itype is IOMMU_BUSERROR.
39  */
40 typedef int (*rockchip_iommu_fault_handler_t)(struct device *dev,
41                                           enum rk_iommu_inttype itype,
42                                           unsigned long pgtable_base,
43                                           unsigned long fault_addr,
44                                           unsigned int statu
45                                           );
46
47
48 struct scatterlist;
49 struct device;
50
51 #ifdef CONFIG_RK_IOVMM
52
53 int rockchip_iovmm_activate(struct device *dev);
54 void rockchip_iovmm_deactivate(struct device *dev);
55
56 /* rockchip_iovmm_map() - Maps a list of physical memory chunks
57  * @dev: the owner of the IO address space where the mapping is created
58  * @sg: list of physical memory chunks to map
59  * @offset: length in bytes where the mapping starts
60  * @size: how much memory to map in bytes. @offset + @size must not exceed
61  *        total size of @sg
62  *
63  * This function returns mapped IO address in the address space of @dev.
64  * Returns minus error number if mapping fails.
65  * Caller must check its return code with IS_ERROR_VALUE() if the function
66  * succeeded.
67  *
68  * The caller of this function must ensure that iovmm_cleanup() is not called
69  * while this function is called.
70  *
71  */
72 dma_addr_t rockchip_iovmm_map(struct device *dev, struct scatterlist *sg,
73                      off_t offset, size_t size);
74
75 /* rockchip_iovmm_unmap() - unmaps the given IO address
76  * @dev: the owner of the IO address space where @iova belongs
77  * @iova: IO address that needs to be unmapped and freed.
78  *
79  * The caller of this function must ensure that iovmm_cleanup() is not called
80  * while this function is called.
81  */
82 void rockchip_iovmm_unmap(struct device *dev, dma_addr_t iova);
83
84 /* rockchip_iovmm_map_oto - create one to one mapping for the given physical address
85  * @dev: the owner of the IO address space to map
86  * @phys: physical address to map
87  * @size: size of the mapping to create
88  *
89  * This function return 0 if mapping is successful. Otherwise, minus error
90  * value.
91  */
92 int rockchip_iovmm_map_oto(struct device *dev, phys_addr_t phys, size_t size);
93
94 /* rockchip_iovmm_unmap_oto - remove one to one mapping
95  * @dev: the owner ofthe IO address space
96  * @phys: physical address to remove mapping
97  */
98 void rockchip_iovmm_unmap_oto(struct device *dev, phys_addr_t phys);
99
100 void rockchip_iovmm_set_fault_handler(struct device *dev,
101                                        rockchip_iommu_fault_handler_t handler);
102 /** rockchip_iovmm_set_fault_handler() - Fault handler for IOMMUs
103  * Called when interrupt occurred by the IOMMUs
104  * The device drivers of peripheral devices that has a IOMMU can implement
105  * a fault handler to resolve address translation fault by IOMMU.
106  * The meanings of return value and parameters are described below.
107  *
108  * return value: non-zero if the fault is correctly resolved.
109  *                 zero if the fault is not handled.
110  */
111
112 int rockchip_iovmm_invalidate_tlb(struct device *dev);
113 #else
114 static inline int rockchip_iovmm_activate(struct device *dev)
115 {
116         return -ENOSYS;
117 }
118
119 static inline void rockchip_iovmm_deactivate(struct device *dev)
120 {
121 }
122
123 static inline dma_addr_t rockchip_iovmm_map(struct device *dev,
124                         struct scatterlist *sg, off_t offset, size_t size)
125 {
126         return -ENOSYS;
127 }
128
129 static inline void rockchip_iovmm_unmap(struct device *dev, dma_addr_t iova)
130 {
131 }
132
133 static inline int rockchip_iovmm_map_oto(struct device *dev, phys_addr_t phys,
134                                 size_t size)
135 {
136         return -ENOSYS;
137 }
138
139 static inline void rockchip_iovmm_unmap_oto(struct device *dev, phys_addr_t phys)
140 {
141 }
142
143 static inline void rockchip_iovmm_set_fault_handler(struct device *dev,
144                                        rockchip_iommu_fault_handler_t handler)
145 {
146 }
147 static inline int rockchip_iovmm_invalidate_tlb(struct device *dev)
148 {
149         return -ENOSYS;
150 }
151
152 #endif /* CONFIG_RK_IOVMM */
153
154 #endif /*__ASM_PLAT_IOVMM_H*/