2 * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
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 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef _LINUX_MSM_IOMMU_DOMAINS_H
15 #define _LINUX_MSM_IOMMU_DOMAINS_H
17 #include <linux/errno.h>
18 #include <linux/mutex.h>
19 #include <linux/genalloc.h>
20 #include <linux/rbtree.h>
21 #include <linux/dma-buf.h>
23 #define MSM_IOMMU_DOMAIN_SECURE 0x1
42 struct mutex pool_mutex;
43 struct gen_pool *gpool;
50 struct msm_iommu_domain {
51 /* iommu domain to map in */
52 struct iommu_domain *domain;
53 /* total number of allocations from this domain */
54 atomic_t allocation_cnt;
55 /* number of iova pools */
58 * array of gen_pools for allocating iovas.
59 * behavior is undefined if these overlap
61 struct mem_pool *iova_pools;
64 struct msm_iommu_domain_name {
69 struct iommu_domains_pdata {
70 struct msm_iommu_domain *domains;
72 struct msm_iommu_domain_name *domain_names;
74 unsigned int domain_alloc_flags;
77 struct msm_iova_partition {
82 struct msm_iova_layout {
83 struct msm_iova_partition *partitions;
85 const char *client_name;
86 unsigned int domain_flags;
87 unsigned int is_secure;
90 #if defined(CONFIG_QCOM_IOMMU)
91 extern void msm_iommu_set_client_name(struct iommu_domain *domain,
93 extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
94 extern int msm_allocate_iova_address(unsigned int iommu_domain,
95 unsigned int partition_no,
100 extern void msm_free_iova_address(unsigned long iova,
101 unsigned int iommu_domain,
102 unsigned int partition_no,
105 extern int msm_use_iommu(void);
107 extern int msm_iommu_map_extra(struct iommu_domain *domain,
108 unsigned long start_iova,
109 phys_addr_t phys_addr,
111 unsigned long page_size,
114 extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
115 unsigned long start_iova,
117 unsigned long page_size);
119 extern int msm_iommu_map_contig_buffer(phys_addr_t phys,
120 unsigned int domain_no,
121 unsigned int partition_no,
124 unsigned long cached,
125 dma_addr_t *iova_val);
127 extern void msm_iommu_unmap_contig_buffer(dma_addr_t iova,
128 unsigned int domain_no,
129 unsigned int partition_no,
132 extern int msm_register_domain(struct msm_iova_layout *layout);
133 extern int msm_unregister_domain(struct iommu_domain *domain);
135 int msm_map_dma_buf(struct dma_buf *dma_buf, struct sg_table *table,
136 int domain_num, int partition_num, unsigned long align,
137 unsigned long iova_length, unsigned long *iova,
138 unsigned long *buffer_size,
139 unsigned long flags, unsigned long iommu_flags);
141 void msm_unmap_dma_buf(struct sg_table *table, int domain_num,
144 static inline void msm_iommu_set_client_name(struct iommu_domain *domain,
149 static inline struct iommu_domain *msm_get_iommu_domain(int subsys_id)
154 static inline int msm_allocate_iova_address(unsigned int iommu_domain,
155 unsigned int partition_no,
163 static inline void msm_free_iova_address(unsigned long iova,
164 unsigned int iommu_domain,
165 unsigned int partition_no,
166 unsigned long size) { }
168 static inline int msm_use_iommu(void)
173 static inline int msm_iommu_map_extra(struct iommu_domain *domain,
174 unsigned long start_iova,
175 phys_addr_t phys_addr,
177 unsigned long page_size,
183 static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
184 unsigned long start_iova,
186 unsigned long page_size)
190 static inline int msm_iommu_map_contig_buffer(phys_addr_t phys,
191 unsigned int domain_no,
192 unsigned int partition_no,
195 unsigned long cached,
196 dma_addr_t *iova_val)
202 static inline void msm_iommu_unmap_contig_buffer(dma_addr_t iova,
203 unsigned int domain_no,
204 unsigned int partition_no,
209 static inline int msm_register_domain(struct msm_iova_layout *layout)
214 static inline int msm_unregister_domain(struct iommu_domain *domain)
219 static inline int msm_map_dma_buf(struct dma_buf *dma_buf,
220 struct sg_table *table,
221 int domain_num, int partition_num,
223 unsigned long iova_length,
225 unsigned long *buffer_size,
227 unsigned long iommu_flags)
232 static inline void msm_unmap_dma_buf(struct sg_table *table, int domain_num,
238 #endif /* CONFIG_QCOM_IOMMU */
239 #endif /* _LINUX_MSM_IOMMU_DOMAINS_H */