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