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