3036: fix iomap base addr error
[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 ISP_SYSMMU_COMPATIBLE_NAME "iommu,isp_mmu"
20
21 #define VOPB_SYSMMU_COMPATIBLE_NAME "iommu,vopb_mmu"
22 #define VOPL_SYSMMU_COMPATIBLE_NAME "iommu,vopl_mmu"
23
24 #define VOP_SYSMMU_COMPATIBLE_NAME "iommu,vop_mmu"
25
26 #define HEVC_SYSMMU_COMPATIBLE_NAME "iommu,hevc_mmu"
27 #define VPU_SYSMMU_COMPATIBLE_NAME "iommu,vpu_mmu"
28
29
30 enum rk_sysmmu_inttype {
31         SYSMMU_PAGEFAULT,
32         SYSMMU_BUSERROR,
33         SYSMMU_FAULT_UNKNOWN,
34         SYSMMU_FAULTS_NUM
35 };
36         
37 struct sysmmu_drvdata;
38 /*
39  * @itype: type of fault.
40  * @pgtable_base: the physical address of page table base. This is 0 if @itype
41  *                                is SYSMMU_BUSERROR.
42  * @fault_addr: the device (virtual) address that the System MMU tried to
43  *                         translated. This is 0 if @itype is SYSMMU_BUSERROR.
44  */
45 typedef int (*sysmmu_fault_handler_t)(struct device *dev,
46                                           enum rk_sysmmu_inttype itype,
47                                           unsigned long pgtable_base,
48                                           unsigned long fault_addr,
49                                           unsigned int statu
50                                           );
51         
52 #ifdef CONFIG_ROCKCHIP_IOMMU
53 /**
54 * rockchip_sysmmu_enable() - enable system mmu
55 * @owner: The device whose System MMU is about to be enabled.
56 * @pgd: Base physical address of the 1st level page table
57 *
58 * This function enable system mmu to transfer address
59 * from virtual address to physical address.
60 * Return non-zero if it fails to enable System MMU.
61 */
62 int rockchip_sysmmu_enable(struct device *owner, unsigned long pgd);
63
64 /**
65 * rockchip_sysmmu_disable() - disable sysmmu mmu of ip
66 * @owner: The device whose System MMU is about to be disabled.
67 *
68 * This function disable system mmu to transfer address
69  * from virtual address to physical address
70  */
71 bool rockchip_sysmmu_disable(struct device *owner);
72
73 /**
74  * rockchip_sysmmu_tlb_invalidate() - flush all TLB entry in system mmu
75  * @owner: The device whose System MMU.
76  *
77  * This function flush all TLB entry in system mmu
78  */
79 void rockchip_sysmmu_tlb_invalidate(struct device *owner);
80
81 /** rockchip_sysmmu_set_fault_handler() - Fault handler for System MMUs
82  * Called when interrupt occurred by the System MMUs
83  * The device drivers of peripheral devices that has a System MMU can implement
84  * a fault handler to resolve address translation fault by System MMU.
85  * The meanings of return value and parameters are described below.
86  *
87  * return value: non-zero if the fault is correctly resolved.
88  *                 zero if the fault is not handled.
89  */
90 void rockchip_sysmmu_set_fault_handler(struct device *dev,sysmmu_fault_handler_t handler);
91
92 #else /* CONFIG_ROCKCHIP_IOMMU */
93 #define rockchip_sysmmu_enable(owner, pgd) do { } while (0)
94 #define rockchip_sysmmu_disable(owner) do { } while (0)
95 #define rockchip_sysmmu_tlb_invalidate(owner) do { } while (0)
96 #define rockchip_sysmmu_set_fault_handler(sysmmu, handler) do { } while (0)
97 #endif
98
99 #ifdef CONFIG_IOMMU_API
100 #include <linux/device.h>
101 static inline void platform_set_sysmmu(struct device *sysmmu, struct device *dev)
102 {
103         dev->archdata.iommu = sysmmu;
104 }
105 #else
106 #define platform_set_sysmmu(dev, sysmmu) do { } while (0)
107 #endif
108
109 #endif /* _ARM_MACH_RK_SYSMMU_H_ */