rk fb:modify iommu interface to match upstream request
[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 HEVC_SYSMMU_COMPATIBLE_NAME "iommu,hevc_mmu"
26 #define VPU_SYSMMU_COMPATIBLE_NAME "iommu,vpu_mmu"
27
28
29 enum rk_sysmmu_inttype {
30         SYSMMU_PAGEFAULT,
31         SYSMMU_BUSERROR,
32         SYSMMU_FAULT_UNKNOWN,
33         SYSMMU_FAULTS_NUM
34 };
35         
36 struct sysmmu_drvdata;
37 /*
38  * @itype: type of fault.
39  * @pgtable_base: the physical address of page table base. This is 0 if @itype
40  *                                is SYSMMU_BUSERROR.
41  * @fault_addr: the device (virtual) address that the System MMU tried to
42  *                         translated. This is 0 if @itype is SYSMMU_BUSERROR.
43  */
44 typedef int (*sysmmu_fault_handler_t)(struct device *dev,
45                                       enum rk_sysmmu_inttype itype,
46                                       unsigned long pgtable_base,
47                                       unsigned long fault_addr,
48                                       unsigned int statu);
49         
50 #ifdef CONFIG_ROCKCHIP_IOMMU
51 /**
52 * rockchip_sysmmu_enable() - enable system mmu
53 * @owner: The device whose System MMU is about to be enabled.
54 * @pgd: Base physical address of the 1st level page table
55 *
56 * This function enable system mmu to transfer address
57 * from virtual address to physical address.
58 * Return non-zero if it fails to enable System MMU.
59 */
60 int rockchip_sysmmu_enable(struct device *owner, unsigned long pgd);
61
62 /**
63 * rockchip_sysmmu_disable() - disable sysmmu mmu of ip
64 * @owner: The device whose System MMU is about to be disabled.
65 *
66 * This function disable system mmu to transfer address
67  * from virtual address to physical address
68  */
69 bool rockchip_sysmmu_disable(struct device *owner);
70
71 /**
72  * rockchip_sysmmu_tlb_invalidate() - flush all TLB entry in system mmu
73  * @owner: The device whose System MMU.
74  *
75  * This function flush all TLB entry in system mmu
76  */
77 void rockchip_sysmmu_tlb_invalidate(struct device *owner);
78
79 /** rockchip_sysmmu_set_fault_handler() - Fault handler for System MMUs
80  * Called when interrupt occurred by the System MMUs
81  * The device drivers of peripheral devices that has a System MMU can implement
82  * a fault handler to resolve address translation fault by System MMU.
83  * The meanings of return value and parameters are described below.
84  *
85  * return value: non-zero if the fault is correctly resolved.
86  *                 zero if the fault is not handled.
87  */
88 void rockchip_sysmmu_set_fault_handler(struct device *dev,sysmmu_fault_handler_t handler);
89
90 /** rockchip_sysmmu_set_prefbuf() - Initialize prefetch buffers of System MMU v3
91  *      @owner: The device which need to set the prefetch buffers
92  *      @base0: The start virtual address of the area of the @owner device that the
93  *                      first prefetch buffer loads translation descriptors
94  *      @size0: The last virtual address of the area of the @owner device that the
95  *                      first prefetch buffer loads translation descriptors.
96  *      @base1: The start virtual address of the area of the @owner device that the
97  *                      second prefetch buffer loads translation descriptors. This will be
98  *                      ignored if @size1 is 0 and this function assigns the 2 prefetch
99  *                      buffers with each half of the area specified by @base0 and @size0
100  *      @size1: The last virtual address of the area of the @owner device that the
101  *                      prefetch buffer loads translation descriptors. This can be 0. See
102  *                      the description of @base1 for more information with @size1 = 0
103  */
104 void rockchip_sysmmu_set_prefbuf(struct device *owner,
105                                 unsigned long base0, unsigned long size0,
106                                 unsigned long base1, unsigned long size1);
107 #else /* CONFIG_ROCKCHIP_IOMMU */
108 static inline int rockchip_sysmmu_enable(struct device *owner, unsigned long pgd)
109 {
110         return -ENOSYS;
111 }
112 static inline bool rockchip_sysmmu_disable(struct device *owner)
113 {
114         return false;
115 }
116 static inline void rockchip_sysmmu_tlb_invalidate(struct device *owner)
117 {
118 }
119 static inline void rockchip_sysmmu_set_fault_handler(struct device *dev,sysmmu_fault_handler_t handler)
120 {
121 }
122 static inline void rockchip_sysmmu_set_prefbuf(struct device *owner,
123                                                unsigned long base0, unsigned long size0,
124                                                unsigned long base1, unsigned long size1)
125 {
126 }
127 #endif
128
129 #ifdef CONFIG_IOMMU_API
130 static inline void platform_set_sysmmu(struct device *sysmmu, struct device *dev)
131 {
132         dev->archdata.iommu = sysmmu;
133 }
134 #else
135 static inline void platform_set_sysmmu(struct device *sysmmu, struct device *dev)
136 {
137 }
138 #endif
139
140 #endif /* _ARM_MACH_RK_SYSMMU_H_ */