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