blob: 1d538f2ef0bde87b4b1c0ff19dfd0c683c8835d3 [file] [log] [blame]
Olav Hauganab77b1b2012-02-28 09:19:22 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. 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 Abbott9f4a8e62011-08-29 19:08:07 -070018enum {
Olav Hauganab77b1b2012-02-28 09:19:22 -080019 VIDEO_DOMAIN,
Olav Haugan2d191032012-02-28 09:46:31 -080020 CAMERA_DOMAIN,
Olav Hauganef95ae32012-05-15 09:50:30 -070021 DISPLAY_READ_DOMAIN,
22 DISPLAY_WRITE_DOMAIN,
23 ROTATOR_SRC_DOMAIN,
24 ROTATOR_DST_DOMAIN,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070025 MAX_DOMAINS
26};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027
Laura Abbott9f4a8e62011-08-29 19:08:07 -070028enum {
29 VIDEO_FIRMWARE_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080030 VIDEO_MAIN_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080031 GEN_POOL,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070032};
33
Laura Abbott0577d7b2012-04-17 11:14:30 -070034struct msm_iommu_domain_name {
35 char *name;
36 int domain;
37};
38
39struct msm_iommu_domain {
40 /* iommu domain to map in */
41 struct iommu_domain *domain;
42 /* total number of allocations from this domain */
43 atomic_t allocation_cnt;
44 /* number of iova pools */
45 int npools;
46 /*
47 * array of gen_pools for allocating iovas.
48 * behavior is undefined if these overlap
49 */
50 struct mem_pool *iova_pools;
51};
52
53struct iommu_domains_pdata {
54 struct msm_iommu_domain *domains;
55 int ndomains;
56 struct msm_iommu_domain_name *domain_names;
57 int nnames;
58 unsigned int domain_alloc_flags;
59};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060
Laura Abbottd01221b2012-05-16 17:52:49 -070061
62struct msm_iova_partition {
63 unsigned long start;
64 unsigned long size;
65};
66
67struct msm_iova_layout {
68 struct msm_iova_partition *partitions;
69 int npartitions;
70 const char *client_name;
71 unsigned int domain_flags;
72};
73
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074#if defined(CONFIG_MSM_IOMMU)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075
Laura Abbott9f4a8e62011-08-29 19:08:07 -070076extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
77
Laura Abbottd01221b2012-05-16 17:52:49 -070078extern int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070079 unsigned int partition_no,
80 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -070081 unsigned long align,
82 unsigned long *iova);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070083
84extern void msm_free_iova_address(unsigned long iova,
85 unsigned int iommu_domain,
86 unsigned int partition_no,
87 unsigned long size);
88
Laura Abbott9f4a8e62011-08-29 19:08:07 -070089extern int msm_use_iommu(void);
Laura Abbotte956cce2011-10-25 13:33:20 -070090
91extern int msm_iommu_map_extra(struct iommu_domain *domain,
92 unsigned long start_iova,
93 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -070094 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -070095 int cached);
96
Olav Haugan8726caf2012-05-10 15:11:35 -070097extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
98 unsigned long start_iova,
99 unsigned long size,
100 unsigned long page_size);
101
Laura Abbottd027fdb2012-04-17 16:22:24 -0700102extern int msm_iommu_map_contig_buffer(unsigned long phys,
103 unsigned int domain_no,
104 unsigned int partition_no,
105 unsigned long size,
106 unsigned long align,
107 unsigned long cached,
108 unsigned long *iova_val);
109
110
111extern void msm_iommu_unmap_contig_buffer(unsigned long iova,
112 unsigned int domain_no,
113 unsigned int partition_no,
114 unsigned long size);
115
Laura Abbottd01221b2012-05-16 17:52:49 -0700116extern int msm_register_domain(struct msm_iova_layout *layout);
117
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118#else
119static inline struct iommu_domain
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700120 *msm_get_iommu_domain(int subsys_id) { return NULL; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700122
123
Laura Abbottd01221b2012-05-16 17:52:49 -0700124static inline int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700125 unsigned int partition_no,
126 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -0700127 unsigned long align,
128 unsigned long *iova) { return -ENOMEM; }
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700129
130static inline void msm_free_iova_address(unsigned long iova,
131 unsigned int iommu_domain,
132 unsigned int partition_no,
133 unsigned long size) { return; }
134
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700135static inline int msm_use_iommu(void)
136{
137 return 0;
138}
Laura Abbotte956cce2011-10-25 13:33:20 -0700139
140static inline int msm_iommu_map_extra(struct iommu_domain *domain,
141 unsigned long start_iova,
142 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -0700143 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -0700144 int cached)
145{
146 return -ENODEV;
147}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700148
Olav Haugan8726caf2012-05-10 15:11:35 -0700149static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
150 unsigned long start_iova,
151 unsigned long size,
152 unsigned long page_size)
153{
154}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700155
156static inline int msm_iommu_map_contig_buffer(unsigned long phys,
157 unsigned int domain_no,
158 unsigned int partition_no,
159 unsigned long size,
160 unsigned long align,
161 unsigned long cached,
162 unsigned long *iova_val)
163{
164 *iova_val = phys;
165 return 0;
166}
167
168static inline void msm_iommu_unmap_contig_buffer(unsigned long iova,
169 unsigned int domain_no,
170 unsigned int partition_no,
171 unsigned long size)
172{
173 return;
174}
Laura Abbottd01221b2012-05-16 17:52:49 -0700175
176static inline int msm_register_domain(struct msm_iova_layout *layout)
177{
178 return -ENODEV;
179}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180#endif
181
182#endif