blob: 9a895087744d9ab409082bfa58e2120192e501e5 [file] [log] [blame]
Mitchel Humpherysaf3b5222013-01-15 15:38:52 -08001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _ARCH_IOMMU_DOMAINS_H
14#define _ARCH_IOMMU_DOMAINS_H
15
Olav Haugan62a89472013-03-28 08:33:25 -070016#include <linux/errno.h>
Laura Abbott0577d7b2012-04-17 11:14:30 -070017#include <linux/memory_alloc.h>
18
Laura Abbott6a6ca552012-08-30 11:26:31 -070019#define MSM_IOMMU_DOMAIN_SECURE 0x1
20
Laura Abbott9f4a8e62011-08-29 19:08:07 -070021enum {
Olav Hauganab77b1b2012-02-28 09:19:22 -080022 VIDEO_DOMAIN,
Olav Haugan2d191032012-02-28 09:46:31 -080023 CAMERA_DOMAIN,
Olav Hauganef95ae32012-05-15 09:50:30 -070024 DISPLAY_READ_DOMAIN,
25 DISPLAY_WRITE_DOMAIN,
26 ROTATOR_SRC_DOMAIN,
27 ROTATOR_DST_DOMAIN,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070028 MAX_DOMAINS
29};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030
Laura Abbott9f4a8e62011-08-29 19:08:07 -070031enum {
32 VIDEO_FIRMWARE_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080033 VIDEO_MAIN_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080034 GEN_POOL,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070035};
36
Laura Abbott0577d7b2012-04-17 11:14:30 -070037struct msm_iommu_domain_name {
38 char *name;
39 int domain;
40};
41
42struct msm_iommu_domain {
43 /* iommu domain to map in */
44 struct iommu_domain *domain;
45 /* total number of allocations from this domain */
46 atomic_t allocation_cnt;
47 /* number of iova pools */
48 int npools;
49 /*
50 * array of gen_pools for allocating iovas.
51 * behavior is undefined if these overlap
52 */
53 struct mem_pool *iova_pools;
54};
55
56struct iommu_domains_pdata {
57 struct msm_iommu_domain *domains;
58 int ndomains;
59 struct msm_iommu_domain_name *domain_names;
60 int nnames;
61 unsigned int domain_alloc_flags;
62};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070063
Laura Abbottd01221b2012-05-16 17:52:49 -070064
65struct msm_iova_partition {
66 unsigned long start;
67 unsigned long size;
68};
69
70struct msm_iova_layout {
71 struct msm_iova_partition *partitions;
72 int npartitions;
73 const char *client_name;
74 unsigned int domain_flags;
Laura Abbott6a6ca552012-08-30 11:26:31 -070075 unsigned int is_secure;
Laura Abbottd01221b2012-05-16 17:52:49 -070076};
77
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078#if defined(CONFIG_MSM_IOMMU)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070079
Olav Haugana9820ce2013-03-22 14:50:28 -070080extern void msm_iommu_set_client_name(struct iommu_domain *domain,
81 char const *name);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070082extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
Olav Haugan35deadc2012-12-10 18:28:27 -080083extern int msm_find_domain_no(const struct iommu_domain *domain);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070084
Laura Abbottd01221b2012-05-16 17:52:49 -070085extern int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070086 unsigned int partition_no,
87 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -070088 unsigned long align,
89 unsigned long *iova);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070090
91extern void msm_free_iova_address(unsigned long iova,
92 unsigned int iommu_domain,
93 unsigned int partition_no,
94 unsigned long size);
95
Laura Abbott9f4a8e62011-08-29 19:08:07 -070096extern int msm_use_iommu(void);
Laura Abbotte956cce2011-10-25 13:33:20 -070097
98extern int msm_iommu_map_extra(struct iommu_domain *domain,
99 unsigned long start_iova,
Laura Abbott3cfa2e62013-03-13 17:48:26 -0700100 phys_addr_t phys_addr,
Laura Abbotte956cce2011-10-25 13:33:20 -0700101 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -0700102 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -0700103 int cached);
104
Olav Haugan8726caf2012-05-10 15:11:35 -0700105extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
106 unsigned long start_iova,
107 unsigned long size,
108 unsigned long page_size);
109
Laura Abbott3cfa2e62013-03-13 17:48:26 -0700110extern int msm_iommu_map_contig_buffer(phys_addr_t phys,
Laura Abbottd027fdb2012-04-17 16:22:24 -0700111 unsigned int domain_no,
112 unsigned int partition_no,
113 unsigned long size,
114 unsigned long align,
115 unsigned long cached,
116 unsigned long *iova_val);
117
118
119extern void msm_iommu_unmap_contig_buffer(unsigned long iova,
120 unsigned int domain_no,
121 unsigned int partition_no,
122 unsigned long size);
123
Laura Abbottd01221b2012-05-16 17:52:49 -0700124extern int msm_register_domain(struct msm_iova_layout *layout);
125
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126#else
Olav Haugana9820ce2013-03-22 14:50:28 -0700127static inline void msm_iommu_set_client_name(struct iommu_domain *domain,
128 char const *name)
129{
130}
131
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132static inline struct iommu_domain
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700133 *msm_get_iommu_domain(int subsys_id) { return NULL; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700135
Olav Haugan35deadc2012-12-10 18:28:27 -0800136static inline int msm_find_domain_no(const struct iommu_domain *domain)
137{
138 return -EINVAL;
139}
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700140
Laura Abbottd01221b2012-05-16 17:52:49 -0700141static inline int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700142 unsigned int partition_no,
143 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -0700144 unsigned long align,
145 unsigned long *iova) { return -ENOMEM; }
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700146
147static inline void msm_free_iova_address(unsigned long iova,
148 unsigned int iommu_domain,
149 unsigned int partition_no,
150 unsigned long size) { return; }
151
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700152static inline int msm_use_iommu(void)
153{
154 return 0;
155}
Laura Abbotte956cce2011-10-25 13:33:20 -0700156
157static inline int msm_iommu_map_extra(struct iommu_domain *domain,
158 unsigned long start_iova,
Laura Abbott3cfa2e62013-03-13 17:48:26 -0700159 phys_addr_t phys_addr,
Laura Abbotte956cce2011-10-25 13:33:20 -0700160 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -0700161 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -0700162 int cached)
163{
164 return -ENODEV;
165}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700166
Olav Haugan8726caf2012-05-10 15:11:35 -0700167static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
168 unsigned long start_iova,
169 unsigned long size,
170 unsigned long page_size)
171{
172}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700173
Laura Abbott3cfa2e62013-03-13 17:48:26 -0700174static inline int msm_iommu_map_contig_buffer(phys_addr_t phys,
Laura Abbottd027fdb2012-04-17 16:22:24 -0700175 unsigned int domain_no,
176 unsigned int partition_no,
177 unsigned long size,
178 unsigned long align,
179 unsigned long cached,
180 unsigned long *iova_val)
181{
182 *iova_val = phys;
183 return 0;
184}
185
186static inline void msm_iommu_unmap_contig_buffer(unsigned long iova,
187 unsigned int domain_no,
188 unsigned int partition_no,
189 unsigned long size)
190{
191 return;
192}
Laura Abbottd01221b2012-05-16 17:52:49 -0700193
194static inline int msm_register_domain(struct msm_iova_layout *layout)
195{
196 return -ENODEV;
197}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198#endif
199
200#endif