blob: 1a3a0225262a468337148b1fc6c4a6b435cb5877 [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,
21 DISPLAY_DOMAIN,
22 ROTATOR_DOMAIN,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070023 MAX_DOMAINS
24};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025
Laura Abbott9f4a8e62011-08-29 19:08:07 -070026enum {
27 VIDEO_FIRMWARE_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080028 VIDEO_MAIN_POOL,
Olav Hauganee365362012-02-16 09:31:37 -080029 GEN_POOL,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070030};
31
Laura Abbott0577d7b2012-04-17 11:14:30 -070032struct msm_iommu_domain_name {
33 char *name;
34 int domain;
35};
36
37struct msm_iommu_domain {
38 /* iommu domain to map in */
39 struct iommu_domain *domain;
40 /* total number of allocations from this domain */
41 atomic_t allocation_cnt;
42 /* number of iova pools */
43 int npools;
44 /*
45 * array of gen_pools for allocating iovas.
46 * behavior is undefined if these overlap
47 */
48 struct mem_pool *iova_pools;
49};
50
51struct iommu_domains_pdata {
52 struct msm_iommu_domain *domains;
53 int ndomains;
54 struct msm_iommu_domain_name *domain_names;
55 int nnames;
56 unsigned int domain_alloc_flags;
57};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058
Laura Abbottd01221b2012-05-16 17:52:49 -070059
60struct msm_iova_partition {
61 unsigned long start;
62 unsigned long size;
63};
64
65struct msm_iova_layout {
66 struct msm_iova_partition *partitions;
67 int npartitions;
68 const char *client_name;
69 unsigned int domain_flags;
70};
71
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072#if defined(CONFIG_MSM_IOMMU)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073
Laura Abbott9f4a8e62011-08-29 19:08:07 -070074extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
75
Laura Abbottd01221b2012-05-16 17:52:49 -070076extern int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -070077 unsigned int partition_no,
78 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -070079 unsigned long align,
80 unsigned long *iova);
Laura Abbott9f4a8e62011-08-29 19:08:07 -070081
82extern void msm_free_iova_address(unsigned long iova,
83 unsigned int iommu_domain,
84 unsigned int partition_no,
85 unsigned long size);
86
Laura Abbott9f4a8e62011-08-29 19:08:07 -070087extern int msm_use_iommu(void);
Laura Abbotte956cce2011-10-25 13:33:20 -070088
89extern int msm_iommu_map_extra(struct iommu_domain *domain,
90 unsigned long start_iova,
91 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -070092 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -070093 int cached);
94
Olav Haugan8726caf2012-05-10 15:11:35 -070095extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
96 unsigned long start_iova,
97 unsigned long size,
98 unsigned long page_size);
99
Laura Abbottd027fdb2012-04-17 16:22:24 -0700100extern int msm_iommu_map_contig_buffer(unsigned long phys,
101 unsigned int domain_no,
102 unsigned int partition_no,
103 unsigned long size,
104 unsigned long align,
105 unsigned long cached,
106 unsigned long *iova_val);
107
108
109extern void msm_iommu_unmap_contig_buffer(unsigned long iova,
110 unsigned int domain_no,
111 unsigned int partition_no,
112 unsigned long size);
113
Laura Abbottd01221b2012-05-16 17:52:49 -0700114extern int msm_register_domain(struct msm_iova_layout *layout);
115
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116#else
117static inline struct iommu_domain
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700118 *msm_get_iommu_domain(int subsys_id) { return NULL; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700120
121
Laura Abbottd01221b2012-05-16 17:52:49 -0700122static inline int msm_allocate_iova_address(unsigned int iommu_domain,
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700123 unsigned int partition_no,
124 unsigned long size,
Laura Abbottd01221b2012-05-16 17:52:49 -0700125 unsigned long align,
126 unsigned long *iova) { return -ENOMEM; }
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700127
128static inline void msm_free_iova_address(unsigned long iova,
129 unsigned int iommu_domain,
130 unsigned int partition_no,
131 unsigned long size) { return; }
132
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700133static inline int msm_use_iommu(void)
134{
135 return 0;
136}
Laura Abbotte956cce2011-10-25 13:33:20 -0700137
138static inline int msm_iommu_map_extra(struct iommu_domain *domain,
139 unsigned long start_iova,
140 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -0700141 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -0700142 int cached)
143{
144 return -ENODEV;
145}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700146
Olav Haugan8726caf2012-05-10 15:11:35 -0700147static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
148 unsigned long start_iova,
149 unsigned long size,
150 unsigned long page_size)
151{
152}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700153
154static inline int msm_iommu_map_contig_buffer(unsigned long phys,
155 unsigned int domain_no,
156 unsigned int partition_no,
157 unsigned long size,
158 unsigned long align,
159 unsigned long cached,
160 unsigned long *iova_val)
161{
162 *iova_val = phys;
163 return 0;
164}
165
166static inline void msm_iommu_unmap_contig_buffer(unsigned long iova,
167 unsigned int domain_no,
168 unsigned int partition_no,
169 unsigned long size)
170{
171 return;
172}
Laura Abbottd01221b2012-05-16 17:52:49 -0700173
174static inline int msm_register_domain(struct msm_iova_layout *layout)
175{
176 return -ENODEV;
177}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178#endif
179
180#endif