rockchip:iommu:1,fix build error 2,disable invalid tlb when iovmm_unmap
[firefly-linux-kernel-4.4.55.git] / include / linux / rockchip / sysmmu.h
1 /*
2  * Rockchip - System MMU support
3  *
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.
7  */
8
9 #ifndef _ARM_MACH_RK_SYSMMU_H_
10 #define _ARM_MACH_RK_SYSMMU_H_
11
12 #include <linux/list.h>
13 #include <linux/atomic.h>
14 #include <linux/spinlock.h>
15 #include <linux/device.h>
16
17 #define IEP_SYSMMU_COMPATIBLE_NAME "iommu,iep_mmu"
18 #define VIP_SYSMMU_COMPATIBLE_NAME "iommu,vip_mmu"
19
20 #define ISP_SYSMMU_COMPATIBLE_NAME "iommu,isp_mmu"
21
22 #define VOPB_SYSMMU_COMPATIBLE_NAME "iommu,vopb_mmu"
23 #define VOPL_SYSMMU_COMPATIBLE_NAME "iommu,vopl_mmu"
24
25 #define VOP_SYSMMU_COMPATIBLE_NAME "iommu,vop_mmu"
26
27 #define HEVC_SYSMMU_COMPATIBLE_NAME "iommu,hevc_mmu"
28 #define VPU_SYSMMU_COMPATIBLE_NAME "iommu,vpu_mmu"
29
30
31 enum rk_sysmmu_inttype {
32         SYSMMU_PAGEFAULT,
33         SYSMMU_BUSERROR,
34         SYSMMU_FAULT_UNKNOWN,
35         SYSMMU_FAULTS_NUM
36 };
37         
38 struct sysmmu_drvdata;
39 /*
40  * @itype: type of fault.
41  * @pgtable_base: the physical address of page table base. This is 0 if @itype
42  *                                is SYSMMU_BUSERROR.
43  * @fault_addr: the device (virtual) address that the System MMU tried to
44  *                         translated. This is 0 if @itype is SYSMMU_BUSERROR.
45  */
46 typedef int (*sysmmu_fault_handler_t)(struct device *dev,
47                                           enum rk_sysmmu_inttype itype,
48                                           unsigned long pgtable_base,
49                                           unsigned long fault_addr,
50                                           unsigned int statu
51                                           );
52         
53 #ifdef CONFIG_ROCKCHIP_IOMMU
54 /**
55 * rockchip_sysmmu_enable() - enable system mmu
56 * @owner: The device whose System MMU is about to be enabled.
57 * @pgd: Base physical address of the 1st level page table
58 *
59 * This function enable system mmu to transfer address
60 * from virtual address to physical address.
61 * Return non-zero if it fails to enable System MMU.
62 */
63 int rockchip_sysmmu_enable(struct device *owner, unsigned long pgd);
64
65 /**
66 * rockchip_sysmmu_disable() - disable sysmmu mmu of ip
67 * @owner: The device whose System MMU is about to be disabled.
68 *
69 * This function disable system mmu to transfer address
70  * from virtual address to physical address
71  */
72 bool rockchip_sysmmu_disable(struct device *owner);
73
74 /**
75  * rockchip_sysmmu_tlb_invalidate() - flush all TLB entry in system mmu
76  * @owner: The device whose System MMU.
77  *
78  * This function flush all TLB entry in system mmu
79  */
80 void rockchip_sysmmu_tlb_invalidate(struct device *owner);
81
82 /** rockchip_sysmmu_set_fault_handler() - Fault handler for System MMUs
83  * Called when interrupt occurred by the System MMUs
84  * The device drivers of peripheral devices that has a System MMU can implement
85  * a fault handler to resolve address translation fault by System MMU.
86  * The meanings of return value and parameters are described below.
87  *
88  * return value: non-zero if the fault is correctly resolved.
89  *                 zero if the fault is not handled.
90  */
91 void rockchip_sysmmu_set_fault_handler(struct device *dev,sysmmu_fault_handler_t handler);
92
93 #else /* CONFIG_ROCKCHIP_IOMMU */
94 static inline int rockchip_sysmmu_enable(struct device *owner, unsigned long pgd)
95 {
96         return -ENOSYS;
97 }
98 static inline bool rockchip_sysmmu_disable(struct device *owner)
99 {
100         return false;
101 }
102 static inline void rockchip_sysmmu_tlb_invalidate(struct device *owner)
103 {
104 }
105 static inline void rockchip_sysmmu_set_fault_handler(struct device *dev,sysmmu_fault_handler_t handler)
106 {
107 }
108 static inline void rockchip_sysmmu_set_prefbuf(struct device *owner,
109                                                unsigned long base0, unsigned long size0,
110                                                unsigned long base1, unsigned long size1)
111 {
112 }
113 #endif
114
115 #ifdef CONFIG_IOMMU_API
116 static inline void platform_set_sysmmu(struct device *sysmmu, struct device *dev)
117 {
118         dev->archdata.iommu = sysmmu;
119 }
120 #else
121 static inline void platform_set_sysmmu(struct device *sysmmu, struct device *dev)
122 {
123 }
124 #endif
125
126 #endif /* _ARM_MACH_RK_SYSMMU_H_ */