blob: dfb100c7f7d53e91589be9b9dbfa44f67551ff3b [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
59#if defined(CONFIG_MSM_IOMMU)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060
Laura Abbott9f4a8e62011-08-29 19:08:07 -070061extern struct iommu_domain *msm_get_iommu_domain(int domain_num);
62
63extern unsigned long msm_allocate_iova_address(unsigned int iommu_domain,
64 unsigned int partition_no,
65 unsigned long size,
66 unsigned long align);
67
68extern void msm_free_iova_address(unsigned long iova,
69 unsigned int iommu_domain,
70 unsigned int partition_no,
71 unsigned long size);
72
Laura Abbott9f4a8e62011-08-29 19:08:07 -070073extern int msm_use_iommu(void);
Laura Abbotte956cce2011-10-25 13:33:20 -070074
75extern int msm_iommu_map_extra(struct iommu_domain *domain,
76 unsigned long start_iova,
77 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -070078 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -070079 int cached);
80
Olav Haugan8726caf2012-05-10 15:11:35 -070081extern void msm_iommu_unmap_extra(struct iommu_domain *domain,
82 unsigned long start_iova,
83 unsigned long size,
84 unsigned long page_size);
85
Laura Abbottd027fdb2012-04-17 16:22:24 -070086extern int msm_iommu_map_contig_buffer(unsigned long phys,
87 unsigned int domain_no,
88 unsigned int partition_no,
89 unsigned long size,
90 unsigned long align,
91 unsigned long cached,
92 unsigned long *iova_val);
93
94
95extern void msm_iommu_unmap_contig_buffer(unsigned long iova,
96 unsigned int domain_no,
97 unsigned int partition_no,
98 unsigned long size);
99
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700100#else
101static inline struct iommu_domain
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700102 *msm_get_iommu_domain(int subsys_id) { return NULL; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700104
105
106static inline unsigned long msm_allocate_iova_address(unsigned int iommu_domain,
107 unsigned int partition_no,
108 unsigned long size,
109 unsigned long align) { return 0; }
110
111static inline void msm_free_iova_address(unsigned long iova,
112 unsigned int iommu_domain,
113 unsigned int partition_no,
114 unsigned long size) { return; }
115
Laura Abbott9f4a8e62011-08-29 19:08:07 -0700116static inline int msm_use_iommu(void)
117{
118 return 0;
119}
Laura Abbotte956cce2011-10-25 13:33:20 -0700120
121static inline int msm_iommu_map_extra(struct iommu_domain *domain,
122 unsigned long start_iova,
123 unsigned long size,
Olav Haugan8726caf2012-05-10 15:11:35 -0700124 unsigned long page_size,
Laura Abbotte956cce2011-10-25 13:33:20 -0700125 int cached)
126{
127 return -ENODEV;
128}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700129
Olav Haugan8726caf2012-05-10 15:11:35 -0700130static inline void msm_iommu_unmap_extra(struct iommu_domain *domain,
131 unsigned long start_iova,
132 unsigned long size,
133 unsigned long page_size)
134{
135}
Laura Abbottd027fdb2012-04-17 16:22:24 -0700136
137static inline int msm_iommu_map_contig_buffer(unsigned long phys,
138 unsigned int domain_no,
139 unsigned int partition_no,
140 unsigned long size,
141 unsigned long align,
142 unsigned long cached,
143 unsigned long *iova_val)
144{
145 *iova_val = phys;
146 return 0;
147}
148
149static inline void msm_iommu_unmap_contig_buffer(unsigned long iova,
150 unsigned int domain_no,
151 unsigned int partition_no,
152 unsigned long size)
153{
154 return;
155}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700156#endif
157
158#endif