support rockcihp iommu
[firefly-linux-kernel-4.4.55.git] / drivers / iommu / rockchip-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 #include <linux/kernel.h>
9 #include <linux/spinlock.h>
10 #include <linux/list.h>
11 #include <linux/device.h>
12 #include <linux/platform_device.h>
13 #include <linux/genalloc.h>
14 #include <linux/iommu.h>
15
16 #include <linux/rockchip/sysmmu.h>
17
18 #ifdef CONFIG_ROCKCHIP_IOVMM
19
20 #define IOVA_START 0x10000000
21 #define IOVM_SIZE (SZ_1G - SZ_4K) /* last 4K is for error values */
22
23 struct rk_vm_region {
24         struct list_head node;
25         dma_addr_t start;
26         size_t size;
27 };
28
29 struct rk_iovmm {
30         struct iommu_domain *domain; /* iommu domain for this iovmm */
31         struct gen_pool *vmm_pool;
32         struct list_head regions_list;  /* list of rk_vm_region */
33         spinlock_t lock; /* lock for updating regions_list */
34 };
35 #endif
36
37
38 struct sysmmu_drvdata {
39         struct list_head node; /* entry of rk_iommu_domain.clients */
40         struct device *sysmmu;  /* System MMU's device descriptor */
41         struct device *dev;     /* Owner of system MMU */
42         int num_res_mem;
43         int num_res_irq;        
44         const char *dbgname;
45         void __iomem **res_bases;
46         int activations;
47         rwlock_t lock;
48         struct iommu_domain *domain; /* domain given to iommu_attach_device() */
49         sysmmu_fault_handler_t fault_handler;
50         unsigned long pgtable;
51 #ifdef CONFIG_ROCKCHIP_IOVMM
52         struct rk_iovmm vmm;
53 #endif
54 };
55
56 #ifdef CONFIG_ROCKCHIP_IOVMM
57 static inline struct rk_iovmm *rockchip_get_iovmm(struct device *dev)
58 {
59         struct sysmmu_drvdata *data = dev_get_drvdata(dev->archdata.iommu);
60
61         BUG_ON(!dev->archdata.iommu || !data);
62
63         return &data->vmm;
64 }
65
66 int rockchip_init_iovmm(struct device *sysmmu, struct rk_iovmm *vmm);
67 #else
68 #define rockchip_init_iovmm(sysmmu, vmm) 0
69 #endif