blob: 07f82eccdfb07a652609eddb3349045a2dece56c [file] [log] [blame]
Olav Haugan35deadc2012-12-10 18:28:27 -08001/* Copyright (c) 2011-2012, 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
Laura Abbott0577d7b2012-04-17 11:14:30 -070016#include <linux/memory_alloc.h>
17
Laura Abbott6a6ca552012-08-30 11:26:31 -070018#define MSM_IOMMU_DOMAIN_SECURE 0x1
19
Laura Abbott9f4a8e62011-08-29 19:08:07 -070020enum {
Olav Hauganab77b1b2012-02-28 09:19:22 -080021 VIDEO_DOMAIN,
Olav Haugan2d191032012-02-28 09:46:31 -080022 CAMERA_DOMAIN,
Olav Hauganef95ae32012-05-15 09:50:30 -070023 DISPLAY_READ_DOMAIN,
24 DISPLAY_WRITE_DOMAIN,
25 ROTATOR_SRC_DOMAIN,
26 ROTATOR_DST_DOMAIN,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070027 MAX_DOMAINS
28};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029
Laura Abbott9f4a8e62011-08-29 19:08:07 -070030enum {
31 VIDEO_FIRMWARE_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080032 VIDEO_MAIN_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080033 GEN_POOL,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070034};
35
Laura Abbott0577d7b2012-04-17 11:14:30 -070036struct msm_iommu_domain_name {
37 char *name;
38 int domain;
39};
40
41struct msm_iommu_domain {
42 /* iommu domain to map in */
43 struct iommu_domain *domain;
44 /* total number of allocations from this domain */
45 atomic_t allocation_cnt;
46 /* number of iova pools */
47 int npools;
48 /*
49 * array of gen_pools for allocating iovas.
50 * behavior is undefined if these overlap
51 */
52 struct mem_pool *iova_pools;
53};
54
55struct iommu_domains_pdata {
56 struct msm_iommu_domain *domains;
57 int ndomains;
58 struct msm_iommu_domain_name *domain_names;
59 int nnames;
60 unsigned int domain_alloc_flags;
61};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062
Laura Abbottd01221b2012-05-16 17:52:49 -070063
64struct msm_iova_partition {
65 unsigned long start;
66 unsigned long size;
67};
68
69struct msm_iova_layout {
70 struct msm_iova_partition *partitions;
71 int npartitions;
72 const char *client_name;
73 unsigned int domain_flags;
Laura Abbott6a6ca552012-08-30 11:26:31 -070074 unsigned int is_secure;
Laura Abbottd01221b2012-05-16 17:52:49 -070075};
76
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077#if defined(CONFIG_MSM_IOMMU)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078
Laura Abbott9f4a8e62011-08-29 19:08:07 -070079extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
Olav Haugan35deadc2012-12-10 18:28:27 -080080extern int msm_find_domain_no(const struct iommu_domain *domain);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070081
Laura Abbottd01221b2012-05-16 17:52:49 -070082extern int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070083 unsigned int partition_no,
84 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -070085 unsigned long align,
86 unsigned long *iova);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070087
88extern void msm_free_iova_address(unsigned long iova,
89 unsigned int iommu_domain,
90 unsigned int partition_no,
91 unsigned long size);
92
Laura Abbott9f4a8e62011-08-29 19:08:07 -070093extern int msm_use_iommu(void);
Laura Abbotte956cce2011-10-25 13:33:20 -070094
95extern int msm_iommu_map_extra(struct iommu_domain *domain,
96 unsigned long start_iova,
97 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -070098 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -070099 int cached);
100
Olav Haugan8726caf2012-05-10 15:11:35 -0700101extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
102 unsigned long start_iova,
103 unsigned long size,
104 unsigned long page_size);
105
Laura Abbottd027fdb2012-04-17 16:22:24 -0700106extern int msm_iommu_map_contig_buffer(unsigned long phys,
107 unsigned int domain_no,
108 unsigned int partition_no,
109 unsigned long size,
110 unsigned long align,
111 unsigned long cached,
112 unsigned long *iova_val);
113
114
115extern void msm_iommu_unmap_contig_buffer(unsigned long iova,
116 unsigned int domain_no,
117 unsigned int partition_no,
118 unsigned long size);
119
Laura Abbottd01221b2012-05-16 17:52:49 -0700120extern int msm_register_domain(struct msm_iova_layout *layout);
121
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122#else
123static inline struct iommu_domain
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700124 *msm_get_iommu_domain(int subsys_id) { return NULL; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700126
Olav Haugan35deadc2012-12-10 18:28:27 -0800127static inline int msm_find_domain_no(const struct iommu_domain *domain)
128{
129 return -EINVAL;
130}
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700131
Laura Abbottd01221b2012-05-16 17:52:49 -0700132static inline int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700133 unsigned int partition_no,
134 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -0700135 unsigned long align,
136 unsigned long *iova) { return -ENOMEM; }
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700137
138static inline void msm_free_iova_address(unsigned long iova,
139 unsigned int iommu_domain,
140 unsigned int partition_no,
141 unsigned long size) { return; }
142
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700143static inline int msm_use_iommu(void)
144{
145 return 0;
146}
Laura Abbotte956cce2011-10-25 13:33:20 -0700147
148static inline int msm_iommu_map_extra(struct iommu_domain *domain,
149 unsigned long start_iova,
150 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -0700151 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -0700152 int cached)
153{
154 return -ENODEV;
155}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700156
Olav Haugan8726caf2012-05-10 15:11:35 -0700157static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
158 unsigned long start_iova,
159 unsigned long size,
160 unsigned long page_size)
161{
162}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700163
164static inline int msm_iommu_map_contig_buffer(unsigned long phys,
165 unsigned int domain_no,
166 unsigned int partition_no,
167 unsigned long size,
168 unsigned long align,
169 unsigned long cached,
170 unsigned long *iova_val)
171{
172 *iova_val = phys;
173 return 0;
174}
175
176static inline void msm_iommu_unmap_contig_buffer(unsigned long iova,
177 unsigned int domain_no,
178 unsigned int partition_no,
179 unsigned long size)
180{
181 return;
182}
Laura Abbottd01221b2012-05-16 17:52:49 -0700183
184static inline int msm_register_domain(struct msm_iova_layout *layout)
185{
186 return -ENODEV;
187}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188#endif
189
190#endif