1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/* Copyright (c) 2007-2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef MDSS_SMMU_H
#define MDSS_SMMU_H
#include <linux/msm_ion.h>
#include <linux/msm_mdp.h>
#include <linux/mdss_io_util.h>
#include "mdss.h"
#include "mdss_mdp.h"
#include "mdss_debug.h"
#define MDSS_SMMU_COMPATIBLE "qcom,smmu"
#define SMMU_CBN_FSYNR1 0x6c
struct mdss_iommu_map_type {
char *client_name;
char *ctx_name;
unsigned long start;
unsigned long size;
};
struct mdss_smmu_domain {
char *ctx_name;
int domain;
unsigned long start;
unsigned long size;
};
struct mdss_smmu_private {
struct device_node *pdev;
struct list_head smmu_device_list;
struct list_head user_list;
struct mutex smmu_reg_lock;
};
void mdss_smmu_register(struct device *dev);
int mdss_smmu_init(struct mdss_data_type *mdata, struct device *dev);
int mdss_smmu_set_attribute(int domain, int flag, int val);
enum smmu_attributes {
EARLY_MAP
};
static inline int mdss_smmu_dma_data_direction(int dir)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
return (mdss_has_quirk(mdata, MDSS_QUIRK_DMA_BI_DIR)) ?
DMA_BIDIRECTIONAL : dir;
}
static inline bool is_mdss_smmu_compatible_device(const char *str)
{
/* check the prefix */
return (!strncmp(str, MDSS_SMMU_COMPATIBLE,
strlen(MDSS_SMMU_COMPATIBLE))) ? true : false;
}
/*
* mdss_smmu_is_valid_domain_type()
*
* Used to check if rotator smmu domain is defined or not by checking if
* vbif base is defined. As those are associated.
*/
static inline bool mdss_smmu_is_valid_domain_type(struct mdss_data_type *mdata,
int domain_type)
{
if ((domain_type == MDSS_IOMMU_DOMAIN_ROT_UNSECURE ||
domain_type == MDSS_IOMMU_DOMAIN_ROT_SECURE) &&
!mdss_mdp_is_nrt_vbif_base_defined(mdata))
return false;
return true;
}
static inline bool mdss_smmu_is_valid_domain_condition(
struct mdss_data_type *mdata,
int domain_type,
bool is_attach)
{
if (is_attach) {
if (test_bit(MDSS_CAPS_SEC_DETACH_SMMU,
mdata->mdss_caps_map) &&
(mdata->sec_disp_en ||
(mdata->sec_cam_en &&
domain_type == MDSS_IOMMU_DOMAIN_SECURE))) {
pr_debug("SMMU attach not attempted, sd:%d, sc:%d\n",
mdata->sec_disp_en, mdata->sec_cam_en);
return false;
} else {
return true;
}
} else {
if (test_bit(MDSS_CAPS_SEC_DETACH_SMMU,
mdata->mdss_caps_map) &&
(mdata->sec_disp_en ||
(mdata->sec_cam_en &&
domain_type == MDSS_IOMMU_DOMAIN_SECURE))) {
pr_debug("SMMU detach attempted, sd:%d, sc:%d\n",
mdata->sec_disp_en, mdata->sec_cam_en);
return true;
} else {
return false;
}
}
}
static inline struct mdss_smmu_client *mdss_smmu_get_cb(u32 domain)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdss_smmu_is_valid_domain_type(mdata, domain))
return NULL;
return (domain >= MDSS_IOMMU_MAX_DOMAIN) ? NULL :
&mdata->mdss_smmu[domain];
}
static inline struct ion_client *mdss_get_ionclient(void)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
return mdata ? mdata->iclient : NULL;
}
static inline int is_mdss_iommu_attached(void)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
return mdata ? mdata->iommu_attached : false;
}
static inline int mdss_smmu_get_domain_type(u64 flags, bool rotator)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
int type;
if (flags & MDP_SECURE_OVERLAY_SESSION) {
type = (rotator &&
mdata->mdss_smmu[MDSS_IOMMU_DOMAIN_ROT_SECURE].base.dev) ?
MDSS_IOMMU_DOMAIN_ROT_SECURE : MDSS_IOMMU_DOMAIN_SECURE;
} else {
type = (rotator &&
mdata->mdss_smmu[MDSS_IOMMU_DOMAIN_ROT_UNSECURE].base.dev) ?
MDSS_IOMMU_DOMAIN_ROT_UNSECURE : MDSS_IOMMU_DOMAIN_UNSECURE;
}
return type;
}
static inline int mdss_smmu_attach(struct mdss_data_type *mdata)
{
int rc;
mdata->mdss_util->iommu_lock();
MDSS_XLOG(mdata->iommu_attached);
if (mdata->iommu_attached) {
pr_debug("mdp iommu already attached\n");
rc = 0;
goto end;
}
if (!mdata->smmu_ops.smmu_attach) {
rc = -ENODEV;
goto end;
}
rc = mdata->smmu_ops.smmu_attach(mdata);
if (!rc)
mdata->iommu_attached = true;
end:
mdata->mdss_util->iommu_unlock();
return rc;
}
static inline int mdss_smmu_detach(struct mdss_data_type *mdata)
{
int rc;
mdata->mdss_util->iommu_lock();
MDSS_XLOG(mdata->iommu_attached);
if (!mdata->iommu_attached) {
pr_debug("mdp iommu already dettached\n");
rc = 0;
goto end;
}
if (!mdata->smmu_ops.smmu_detach) {
rc = -ENODEV;
goto end;
}
rc = mdata->smmu_ops.smmu_detach(mdata);
if (!rc)
mdata->iommu_attached = false;
end:
mdata->mdss_util->iommu_unlock();
return rc;
}
static inline int mdss_smmu_get_domain_id(u32 type)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdss_smmu_is_valid_domain_type(mdata, type))
return -ENODEV;
if (!mdata || !mdata->smmu_ops.smmu_get_domain_id
|| type >= MDSS_IOMMU_MAX_DOMAIN)
return -ENODEV;
return mdata->smmu_ops.smmu_get_domain_id(type);
}
static inline struct dma_buf_attachment *mdss_smmu_dma_buf_attach(
struct dma_buf *dma_buf, struct device *dev, int domain)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdata || !mdata->smmu_ops.smmu_dma_buf_attach)
return NULL;
return mdata->smmu_ops.smmu_dma_buf_attach(dma_buf, dev, domain);
}
static inline int mdss_smmu_map_dma_buf(struct dma_buf *dma_buf,
struct sg_table *table, int domain, dma_addr_t *iova,
unsigned long *size, int dir)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdata->smmu_ops.smmu_map_dma_buf)
return -ENOSYS;
return mdata->smmu_ops.smmu_map_dma_buf(dma_buf, table,
domain, iova, size,
mdss_smmu_dma_data_direction(dir));
}
static inline void mdss_smmu_unmap_dma_buf(struct sg_table *table, int domain,
int dir, struct dma_buf *dma_buf)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (mdata->smmu_ops.smmu_unmap_dma_buf)
mdata->smmu_ops.smmu_unmap_dma_buf(table, domain,
mdss_smmu_dma_data_direction(dir), dma_buf);
}
static inline int mdss_smmu_dma_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *phys, dma_addr_t *iova, void **cpu_addr,
gfp_t gfp, int domain)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdata || !mdata->smmu_ops.smmu_dma_alloc_coherent)
return -ENOSYS;
return mdata->smmu_ops.smmu_dma_alloc_coherent(dev, size,
phys, iova, cpu_addr, gfp, domain);
}
static inline void mdss_smmu_dma_free_coherent(struct device *dev, size_t size,
void *cpu_addr, dma_addr_t phys, dma_addr_t iova, int domain)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (mdata && mdata->smmu_ops.smmu_dma_free_coherent)
mdata->smmu_ops.smmu_dma_free_coherent(dev, size, cpu_addr,
phys, iova, domain);
}
static inline int mdss_smmu_map(int domain, phys_addr_t iova, phys_addr_t phys,
int gfp_order, int prot)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdata->smmu_ops.smmu_map)
return -ENOSYS;
return mdata->smmu_ops.smmu_map(domain, iova, phys, gfp_order, prot);
}
static inline void mdss_smmu_unmap(int domain, unsigned long iova,
int gfp_order)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (mdata->smmu_ops.smmu_unmap)
mdata->smmu_ops.smmu_unmap(domain, iova, gfp_order);
}
static inline char *mdss_smmu_dsi_alloc_buf(struct device *dev, int size,
dma_addr_t *dmap, gfp_t gfp)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdata->smmu_ops.smmu_dsi_alloc_buf)
return NULL;
return mdata->smmu_ops.smmu_dsi_alloc_buf(dev, size, dmap, gfp);
}
static inline int mdss_smmu_dsi_map_buffer(phys_addr_t phys,
unsigned int domain, unsigned long size, dma_addr_t *dma_addr,
void *cpu_addr, int dir)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (!mdata->smmu_ops.smmu_dsi_map_buffer)
return -ENOSYS;
return mdata->smmu_ops.smmu_dsi_map_buffer(phys, domain, size,
dma_addr, cpu_addr,
mdss_smmu_dma_data_direction(dir));
}
static inline void mdss_smmu_dsi_unmap_buffer(dma_addr_t dma_addr, int domain,
unsigned long size, int dir)
{
struct mdss_data_type *mdata = mdss_mdp_get_mdata();
if (mdata->smmu_ops.smmu_dsi_unmap_buffer)
mdata->smmu_ops.smmu_dsi_unmap_buffer(dma_addr, domain,
size, mdss_smmu_dma_data_direction(dir));
}
static inline void mdss_smmu_deinit(struct mdss_data_type *mdata)
{
if (mdata->smmu_ops.smmu_deinit)
mdata->smmu_ops.smmu_deinit(mdata);
}
#endif /* MDSS_SMMU_H */
|