nvmem: rockchip-efuse: add support for rk3288 secure efuse
[firefly-linux-kernel-4.4.55.git] / drivers / iommu / rk-iommu.h
1 /*
2  * Data structure definition for Rockchip IOMMU driver
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 #ifndef __ASM_PLAT_IOMMU_H
9 #define __ASM_PLAT_IOMMU_H
10
11 #include <linux/kernel.h>
12 #include <linux/spinlock.h>
13 #include <linux/list.h>
14 #include <linux/device.h>
15 #include <linux/platform_device.h>
16 #include <linux/genalloc.h>
17 #include <linux/iommu.h>
18
19 #include <linux/rockchip-iovmm.h>
20
21
22 struct rk_iovmm {
23         struct iommu_domain *domain; /* iommu domain for this iovmm */
24         struct gen_pool *vmm_pool;
25         struct list_head regions_list;  /* list of rk_vm_region */
26         spinlock_t lock; /* lock for updating regions_list */
27 };
28
29 struct iommu_drvdata {
30         struct list_head node; /* entry of rk_iommu_domain.clients */
31         struct device *iommu;   /*  IOMMU's device descriptor */
32         struct device *master; /* IOMMU's master device descriptor */
33         int num_res_mem;
34         int num_res_irq;
35         const char *dbgname;
36         void __iomem **res_bases;
37         int activations;
38         spinlock_t data_lock;
39         struct iommu_domain *domain; /* domain given to iommu_attach_device() */
40         unsigned int pgtable;
41         struct rk_iovmm vmm;
42         rockchip_iommu_fault_handler_t fault_handler;
43 };
44
45 #ifdef CONFIG_RK_IOVMM
46
47 #define IOVA_START 0x10000000
48 #define IOVM_SIZE (SZ_1G - SZ_4K) /* last 4K is for error values */
49
50 struct rk_vm_region {
51         struct list_head node;
52         unsigned int start;
53         unsigned int size;
54 };
55
56 static inline struct rk_iovmm *rockchip_get_iovmm(struct device *dev)
57 {
58         struct iommu_drvdata *data = dev_get_drvdata(dev->archdata.iommu);
59
60         BUG_ON(!dev->archdata.iommu || !data);
61
62         return &data->vmm;
63 }
64
65 int rockchip_init_iovmm(struct device *iommu, struct rk_iovmm *vmm);
66 #else
67 static inline int rockchip_init_iovmm(struct device *iommu,
68                                 struct rk_iovmm *vmm)
69 {
70         return -ENOSYS;
71 }
72 #endif
73
74
75 #ifdef CONFIG_RK_IOMMU
76
77 /**
78  * rockchip_iommu_tlb_invalidate() - flush all TLB entry in iommu
79  * @owner: The device whose IOMMU.
80  *
81  * This function flush all TLB entry in iommu
82  */
83 int rockchip_iommu_tlb_invalidate(struct device *owner);
84 int rockchip_iommu_tlb_invalidate_global(struct device *owner);
85
86 #else /* CONFIG_RK_IOMMU */
87 static inline int rockchip_iommu_tlb_invalidate(struct device *owner)
88 {
89         return -1;
90 }
91 static int rockchip_iommu_tlb_invalidate_global(struct device *owner)
92 {
93         return -1;
94 }
95
96 #endif
97
98 #endif  /*__ASM_PLAT_IOMMU_H*/