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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
/* Copyright (c) 2012-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.
*
*/
#include <asm/dma-iommu.h>
#include <linux/dma-attrs.h>
#include <linux/dma-buf.h>
#include <linux/dma-direction.h>
#include <linux/iommu.h>
#include <linux/msm_dma_iommu_mapping.h>
#include <linux/msm_ion.h>
#include <linux/slab.h>
#include <linux/types.h>
#include "media/msm_vidc.h"
#include "msm_vidc_debug.h"
#include "msm_vidc_resources.h"
struct smem_client {
int mem_type;
void *clnt;
struct msm_vidc_platform_resources *res;
enum session_type session_type;
};
static int get_device_address(struct smem_client *smem_client,
struct ion_handle *hndl, unsigned long align,
ion_phys_addr_t *iova, unsigned long *buffer_size,
unsigned long flags, enum hal_buffer buffer_type,
struct dma_mapping_info *mapping_info)
{
int rc = 0;
struct ion_client *clnt = NULL;
struct dma_buf *buf = NULL;
struct dma_buf_attachment *attach;
struct sg_table *table = NULL;
struct context_bank_info *cb = NULL;
if (!iova || !buffer_size || !hndl || !smem_client || !mapping_info) {
dprintk(VIDC_ERR, "Invalid params: %pK, %pK, %pK, %pK\n",
smem_client, hndl, iova, buffer_size);
return -EINVAL;
}
clnt = smem_client->clnt;
if (!clnt) {
dprintk(VIDC_ERR, "Invalid client\n");
return -EINVAL;
}
if (is_iommu_present(smem_client->res)) {
cb = msm_smem_get_context_bank(smem_client, flags & SMEM_SECURE,
buffer_type);
if (!cb) {
dprintk(VIDC_ERR,
"%s: Failed to get context bank device\n",
__func__);
rc = -EIO;
goto mem_map_failed;
}
/* Convert an Ion handle to a dma buf */
buf = ion_share_dma_buf(clnt, hndl);
if (IS_ERR_OR_NULL(buf)) {
rc = PTR_ERR(buf) ?: -ENOMEM;
dprintk(VIDC_ERR, "Share ION buf to DMA failed\n");
goto mem_map_failed;
}
/* Check if the dmabuf size matches expected size */
if (buf->size < *buffer_size) {
rc = -EINVAL;
dprintk(VIDC_ERR,
"Size mismatch! Dmabuf size: %zu Expected Size: %lu",
buf->size, *buffer_size);
goto mem_buf_size_mismatch;
}
/* Prepare a dma buf for dma on the given device */
attach = dma_buf_attach(buf, cb->dev);
if (IS_ERR_OR_NULL(attach)) {
rc = PTR_ERR(attach) ?: -ENOMEM;
dprintk(VIDC_ERR, "Failed to attach dmabuf\n");
goto mem_buf_attach_failed;
}
/* Get the scatterlist for the given attachment */
table = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
if (IS_ERR_OR_NULL(table)) {
rc = PTR_ERR(table) ?: -ENOMEM;
dprintk(VIDC_ERR, "Failed to map table\n");
goto mem_map_table_failed;
}
/* debug trace's need to be updated later */
trace_msm_smem_buffer_iommu_op_start("MAP", 0, 0,
align, *iova, *buffer_size);
/* Map a scatterlist into an SMMU */
rc = msm_dma_map_sg_lazy(cb->dev, table->sgl, table->nents,
DMA_BIDIRECTIONAL, buf);
if (rc != table->nents) {
dprintk(VIDC_ERR,
"Mapping failed with rc(%d), expected rc(%d)\n",
rc, table->nents);
rc = -ENOMEM;
goto mem_map_sg_failed;
}
if (table->sgl) {
dprintk(VIDC_DBG,
"%s: CB : %s, DMA buf: %pK, device: %pK, attach: %pK, table: %pK, table sgl: %pK, rc: %d, dma_address: %pa\n",
__func__, cb->name, buf, cb->dev, attach,
table, table->sgl, rc,
&table->sgl->dma_address);
*iova = table->sgl->dma_address;
*buffer_size = table->sgl->dma_length;
} else {
dprintk(VIDC_ERR, "sgl is NULL\n");
rc = -ENOMEM;
goto mem_map_sg_failed;
}
mapping_info->dev = cb->dev;
mapping_info->mapping = cb->mapping;
mapping_info->table = table;
mapping_info->attach = attach;
mapping_info->buf = buf;
trace_msm_smem_buffer_iommu_op_end("MAP", 0, 0,
align, *iova, *buffer_size);
} else {
dprintk(VIDC_DBG, "Using physical memory address\n");
rc = ion_phys(clnt, hndl, iova, (size_t *)buffer_size);
if (rc) {
dprintk(VIDC_ERR, "ion memory map failed - %d\n", rc);
goto mem_map_failed;
}
}
dprintk(VIDC_DBG, "mapped ion handle %pK to %pa\n", hndl, iova);
return 0;
mem_map_sg_failed:
dma_buf_unmap_attachment(attach, table, DMA_BIDIRECTIONAL);
mem_map_table_failed:
dma_buf_detach(buf, attach);
mem_buf_size_mismatch:
mem_buf_attach_failed:
dma_buf_put(buf);
mem_map_failed:
return rc;
}
static void put_device_address(struct smem_client *smem_client,
struct ion_handle *hndl, u32 flags,
struct dma_mapping_info *mapping_info,
enum hal_buffer buffer_type)
{
struct ion_client *clnt = NULL;
if (!hndl || !smem_client || !mapping_info) {
dprintk(VIDC_WARN, "Invalid params: %pK, %pK\n",
smem_client, hndl);
return;
}
if (!mapping_info->dev || !mapping_info->table ||
!mapping_info->buf || !mapping_info->attach) {
dprintk(VIDC_WARN, "Invalid params:\n");
return;
}
clnt = smem_client->clnt;
if (!clnt) {
dprintk(VIDC_WARN, "Invalid client\n");
return;
}
if (is_iommu_present(smem_client->res)) {
dprintk(VIDC_DBG,
"Calling dma_unmap_sg - device: %pK, address: %pa, buf: %pK, table: %pK, attach: %pK\n",
mapping_info->dev,
&mapping_info->table->sgl->dma_address,
mapping_info->buf, mapping_info->table,
mapping_info->attach);
trace_msm_smem_buffer_iommu_op_start("UNMAP", 0, 0, 0, 0, 0);
msm_dma_unmap_sg(mapping_info->dev, mapping_info->table->sgl,
mapping_info->table->nents, DMA_BIDIRECTIONAL,
mapping_info->buf);
dma_buf_unmap_attachment(mapping_info->attach,
mapping_info->table, DMA_BIDIRECTIONAL);
dma_buf_detach(mapping_info->buf, mapping_info->attach);
dma_buf_put(mapping_info->buf);
trace_msm_smem_buffer_iommu_op_end("UNMAP", 0, 0, 0, 0, 0);
}
}
static int ion_user_to_kernel(struct smem_client *client, int fd, u32 size,
struct msm_smem *mem, enum hal_buffer buffer_type)
{
struct ion_handle *hndl;
ion_phys_addr_t iova = 0;
unsigned long buffer_size = size;
int rc = 0;
unsigned long align = SZ_4K;
unsigned long ion_flags = 0;
hndl = ion_import_dma_buf(client->clnt, fd);
dprintk(VIDC_DBG, "%s ion handle: %pK\n", __func__, hndl);
if (IS_ERR_OR_NULL(hndl)) {
dprintk(VIDC_ERR, "Failed to get handle: %pK, %d, %d, %pK\n",
client, fd, size, hndl);
rc = -ENOMEM;
goto fail_import_fd;
}
mem->kvaddr = NULL;
rc = ion_handle_get_flags(client->clnt, hndl, &ion_flags);
if (rc) {
dprintk(VIDC_ERR, "Failed to get ion flags: %d\n", rc);
goto fail_device_address;
}
mem->buffer_type = buffer_type;
if (ion_flags & ION_FLAG_CACHED)
mem->flags |= SMEM_CACHED;
if (ion_flags & ION_FLAG_SECURE)
mem->flags |= SMEM_SECURE;
rc = get_device_address(client, hndl, align, &iova, &buffer_size,
mem->flags, buffer_type, &mem->mapping_info);
if (rc) {
dprintk(VIDC_ERR, "Failed to get device address: %d\n", rc);
goto fail_device_address;
}
mem->mem_type = client->mem_type;
mem->smem_priv = hndl;
mem->device_addr = iova;
mem->size = buffer_size;
if ((u32)mem->device_addr != iova) {
dprintk(VIDC_ERR, "iova(%pa) truncated to %#x",
&iova, (u32)mem->device_addr);
goto fail_device_address;
}
dprintk(VIDC_DBG,
"%s: ion_handle = %pK, fd = %d, device_addr = %pa, size = %zx, kvaddr = %pK, buffer_type = %d, flags = %#lx\n",
__func__, mem->smem_priv, fd, &mem->device_addr, mem->size,
mem->kvaddr, mem->buffer_type, mem->flags);
return rc;
fail_device_address:
ion_free(client->clnt, hndl);
fail_import_fd:
return rc;
}
static int get_secure_flag_for_buffer_type(
struct smem_client *client, enum hal_buffer buffer_type)
{
if (!client) {
dprintk(VIDC_ERR, "%s - invalid params\n", __func__);
return -EINVAL;
}
switch (buffer_type) {
case HAL_BUFFER_INPUT:
if (client->session_type == MSM_VIDC_ENCODER)
return ION_FLAG_CP_PIXEL;
else
return ION_FLAG_CP_BITSTREAM;
case HAL_BUFFER_OUTPUT:
case HAL_BUFFER_OUTPUT2:
if (client->session_type == MSM_VIDC_ENCODER)
return ION_FLAG_CP_BITSTREAM;
else
return ION_FLAG_CP_PIXEL;
case HAL_BUFFER_INTERNAL_SCRATCH:
return ION_FLAG_CP_BITSTREAM;
case HAL_BUFFER_INTERNAL_SCRATCH_1:
return ION_FLAG_CP_NON_PIXEL;
case HAL_BUFFER_INTERNAL_SCRATCH_2:
return ION_FLAG_CP_PIXEL;
case HAL_BUFFER_INTERNAL_PERSIST:
return ION_FLAG_CP_BITSTREAM;
case HAL_BUFFER_INTERNAL_PERSIST_1:
return ION_FLAG_CP_NON_PIXEL;
default:
WARN(1, "No matching secure flag for buffer type : %x\n",
buffer_type);
return -EINVAL;
}
}
static int alloc_ion_mem(struct smem_client *client, size_t size, u32 align,
u32 flags, enum hal_buffer buffer_type, struct msm_smem *mem,
int map_kernel)
{
struct ion_handle *hndl;
ion_phys_addr_t iova = 0;
unsigned long buffer_size = 0;
unsigned long heap_mask = 0;
int rc = 0;
int ion_flags = 0;
align = ALIGN(align, SZ_4K);
size = ALIGN(size, SZ_4K);
if (is_iommu_present(client->res)) {
heap_mask = ION_HEAP(ION_IOMMU_HEAP_ID);
} else {
dprintk(VIDC_DBG,
"allocate shared memory from adsp heap size %zx align %d\n",
size, align);
heap_mask = ION_HEAP(ION_ADSP_HEAP_ID);
}
if (flags & SMEM_CACHED)
ion_flags |= ION_FLAG_CACHED;
if (flags & SMEM_SECURE) {
int secure_flag =
get_secure_flag_for_buffer_type(client, buffer_type);
if (secure_flag < 0) {
rc = secure_flag;
goto fail_shared_mem_alloc;
}
ion_flags |= ION_FLAG_SECURE | secure_flag;
heap_mask = ION_HEAP(ION_SECURE_HEAP_ID);
if (client->res->slave_side_cp) {
heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID);
size = ALIGN(size, SZ_1M);
align = ALIGN(size, SZ_1M);
}
}
trace_msm_smem_buffer_ion_op_start("ALLOC", (u32)buffer_type,
heap_mask, size, align, flags, map_kernel);
hndl = ion_alloc(client->clnt, size, align, heap_mask, ion_flags);
if (IS_ERR_OR_NULL(hndl)) {
dprintk(VIDC_ERR,
"Failed to allocate shared memory = %pK, %zx, %d, %#x\n",
client, size, align, flags);
rc = -ENOMEM;
goto fail_shared_mem_alloc;
}
trace_msm_smem_buffer_ion_op_end("ALLOC", (u32)buffer_type,
heap_mask, size, align, flags, map_kernel);
mem->mem_type = client->mem_type;
mem->smem_priv = hndl;
mem->flags = flags;
mem->buffer_type = buffer_type;
if (map_kernel) {
mem->kvaddr = ion_map_kernel(client->clnt, hndl);
if (IS_ERR_OR_NULL(mem->kvaddr)) {
dprintk(VIDC_ERR,
"Failed to map shared mem in kernel\n");
rc = -EIO;
goto fail_map;
}
} else {
mem->kvaddr = NULL;
}
rc = get_device_address(client, hndl, align, &iova, &buffer_size,
flags, buffer_type, &mem->mapping_info);
if (rc) {
dprintk(VIDC_ERR, "Failed to get device address: %d\n",
rc);
goto fail_device_address;
}
mem->device_addr = iova;
if ((u32)mem->device_addr != iova) {
dprintk(VIDC_ERR, "iova(%pa) truncated to %#x",
&iova, (u32)mem->device_addr);
goto fail_device_address;
}
mem->size = size;
dprintk(VIDC_DBG,
"%s: ion_handle = %pK, device_addr = %pa, size = %#zx, kvaddr = %pK, buffer_type = %#x, flags = %#lx\n",
__func__, mem->smem_priv, &mem->device_addr,
mem->size, mem->kvaddr, mem->buffer_type, mem->flags);
return rc;
fail_device_address:
if (mem->kvaddr)
ion_unmap_kernel(client->clnt, hndl);
fail_map:
ion_free(client->clnt, hndl);
fail_shared_mem_alloc:
return rc;
}
static void free_ion_mem(struct smem_client *client, struct msm_smem *mem)
{
dprintk(VIDC_DBG,
"%s: ion_handle = %pK, device_addr = %pa, size = %#zx, kvaddr = %pK, buffer_type = %#x\n",
__func__, mem->smem_priv, &mem->device_addr,
mem->size, mem->kvaddr, mem->buffer_type);
if (mem->device_addr)
put_device_address(client, mem->smem_priv, mem->flags,
&mem->mapping_info, mem->buffer_type);
if (mem->kvaddr)
ion_unmap_kernel(client->clnt, mem->smem_priv);
if (mem->smem_priv) {
trace_msm_smem_buffer_ion_op_start("FREE",
(u32)mem->buffer_type, -1, mem->size, -1,
mem->flags, -1);
dprintk(VIDC_DBG,
"%s: Freeing handle %pK, client: %pK\n",
__func__, mem->smem_priv, client->clnt);
ion_free(client->clnt, mem->smem_priv);
trace_msm_smem_buffer_ion_op_end("FREE", (u32)mem->buffer_type,
-1, mem->size, -1, mem->flags, -1);
}
}
static void *ion_new_client(void)
{
struct ion_client *client = NULL;
client = msm_ion_client_create("video_client");
if (!client)
dprintk(VIDC_ERR, "Failed to create smem client\n");
return client;
};
static void ion_delete_client(struct smem_client *client)
{
ion_client_destroy(client->clnt);
}
struct msm_smem *msm_smem_user_to_kernel(void *clt, int fd, u32 size,
enum hal_buffer buffer_type)
{
struct smem_client *client = clt;
int rc = 0;
struct msm_smem *mem;
if (fd < 0) {
dprintk(VIDC_ERR, "Invalid fd: %d\n", fd);
return NULL;
}
mem = kzalloc(sizeof(*mem), GFP_KERNEL);
if (!mem) {
dprintk(VIDC_ERR, "Failed to allocte shared mem\n");
return NULL;
}
switch (client->mem_type) {
case SMEM_ION:
rc = ion_user_to_kernel(clt, fd, size, mem, buffer_type);
break;
default:
dprintk(VIDC_ERR, "Mem type not supported\n");
rc = -EINVAL;
break;
}
if (rc) {
dprintk(VIDC_ERR, "Failed to allocate shared memory\n");
kfree(mem);
mem = NULL;
}
return mem;
}
bool msm_smem_compare_buffers(void *clt, int fd, void *priv)
{
struct smem_client *client = clt;
struct ion_handle *handle = NULL;
bool ret = false;
if (!clt || !priv) {
dprintk(VIDC_ERR, "Invalid params: %pK, %pK\n",
clt, priv);
return false;
}
handle = ion_import_dma_buf(client->clnt, fd);
ret = handle == priv;
(!IS_ERR_OR_NULL(handle)) ? ion_free(client->clnt, handle) : 0;
return ret;
}
static int ion_cache_operations(struct smem_client *client,
struct msm_smem *mem, enum smem_cache_ops cache_op,
int size)
{
unsigned long ionflag = 0;
int rc = 0;
int msm_cache_ops = 0;
int op_size = 0;
if (!mem || !client) {
dprintk(VIDC_ERR, "Invalid params: %pK, %pK\n",
mem, client);
return -EINVAL;
}
rc = ion_handle_get_flags(client->clnt, mem->smem_priv,
&ionflag);
if (rc) {
dprintk(VIDC_ERR,
"ion_handle_get_flags failed: %d\n", rc);
goto cache_op_failed;
}
if (ION_IS_CACHED(ionflag)) {
switch (cache_op) {
case SMEM_CACHE_CLEAN:
msm_cache_ops = ION_IOC_CLEAN_CACHES;
break;
case SMEM_CACHE_INVALIDATE:
msm_cache_ops = ION_IOC_INV_CACHES;
break;
case SMEM_CACHE_CLEAN_INVALIDATE:
msm_cache_ops = ION_IOC_CLEAN_INV_CACHES;
break;
default:
dprintk(VIDC_ERR, "cache operation not supported\n");
rc = -EINVAL;
goto cache_op_failed;
}
if (size <= 0)
op_size = mem->size;
else
op_size = mem->size < size ? mem->size : size;
rc = msm_ion_do_cache_offset_op(client->clnt,
(struct ion_handle *)mem->smem_priv,
0, mem->offset,
(unsigned long)op_size, msm_cache_ops);
if (rc) {
dprintk(VIDC_ERR,
"cache operation failed %d\n", rc);
goto cache_op_failed;
}
}
cache_op_failed:
return rc;
}
int msm_smem_cache_operations(void *clt, struct msm_smem *mem,
enum smem_cache_ops cache_op, int size)
{
struct smem_client *client = clt;
int rc = 0;
if (!client) {
dprintk(VIDC_ERR, "Invalid params: %pK\n",
client);
return -EINVAL;
}
switch (client->mem_type) {
case SMEM_ION:
rc = ion_cache_operations(client, mem, cache_op, size);
if (rc)
dprintk(VIDC_ERR,
"Failed cache operations: %d\n", rc);
break;
default:
dprintk(VIDC_ERR, "Mem type not supported\n");
break;
}
return rc;
}
void *msm_smem_new_client(enum smem_type mtype,
void *platform_resources, enum session_type stype)
{
struct smem_client *client = NULL;
void *clnt = NULL;
struct msm_vidc_platform_resources *res = platform_resources;
switch (mtype) {
case SMEM_ION:
clnt = ion_new_client();
break;
default:
dprintk(VIDC_ERR, "Mem type not supported\n");
break;
}
if (clnt) {
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (client) {
client->mem_type = mtype;
client->clnt = clnt;
client->res = res;
client->session_type = stype;
}
} else {
dprintk(VIDC_ERR, "Failed to create new client: mtype = %d\n",
mtype);
}
return client;
}
struct msm_smem *msm_smem_alloc(void *clt, size_t size, u32 align, u32 flags,
enum hal_buffer buffer_type, int map_kernel)
{
struct smem_client *client;
int rc = 0;
struct msm_smem *mem;
client = clt;
if (!client) {
dprintk(VIDC_ERR, "Invalid client passed\n");
return NULL;
}
if (!size) {
dprintk(VIDC_ERR, "No need to allocate memory of size: %zx\n",
size);
return NULL;
}
mem = kzalloc(sizeof(*mem), GFP_KERNEL);
if (!mem) {
dprintk(VIDC_ERR, "Failed to allocate shared mem\n");
return NULL;
}
switch (client->mem_type) {
case SMEM_ION:
rc = alloc_ion_mem(client, size, align, flags, buffer_type,
mem, map_kernel);
break;
default:
dprintk(VIDC_ERR, "Mem type not supported\n");
rc = -EINVAL;
break;
}
if (rc) {
dprintk(VIDC_ERR, "Failed to allocate shared memory\n");
kfree(mem);
mem = NULL;
}
return mem;
}
void msm_smem_free(void *clt, struct msm_smem *mem)
{
struct smem_client *client = clt;
if (!client || !mem) {
dprintk(VIDC_ERR, "Invalid client/handle passed\n");
return;
}
switch (client->mem_type) {
case SMEM_ION:
free_ion_mem(client, mem);
break;
default:
dprintk(VIDC_ERR, "Mem type not supported\n");
break;
}
kfree(mem);
};
void msm_smem_delete_client(void *clt)
{
struct smem_client *client = clt;
if (!client) {
dprintk(VIDC_ERR, "Invalid client passed\n");
return;
}
switch (client->mem_type) {
case SMEM_ION:
ion_delete_client(client);
break;
default:
dprintk(VIDC_ERR, "Mem type not supported\n");
break;
}
kfree(client);
}
struct context_bank_info *msm_smem_get_context_bank(void *clt,
bool is_secure, enum hal_buffer buffer_type)
{
struct smem_client *client = clt;
struct context_bank_info *cb = NULL, *match = NULL;
if (!clt) {
dprintk(VIDC_ERR, "%s - invalid params\n", __func__);
return NULL;
}
/*
* HAL_BUFFER_INPUT is directly mapped to bitstream CB in DT
* as the buffer type structure was initially designed
* just for decoder. For Encoder, input should be mapped to
* pixel CB. So swap the buffer types just in this local scope.
*/
if (is_secure && client->session_type == MSM_VIDC_ENCODER) {
if (buffer_type == HAL_BUFFER_INPUT)
buffer_type = HAL_BUFFER_OUTPUT;
else if (buffer_type == HAL_BUFFER_OUTPUT)
buffer_type = HAL_BUFFER_INPUT;
}
list_for_each_entry(cb, &client->res->context_banks, list) {
if (cb->is_secure == is_secure &&
cb->buffer_type & buffer_type) {
match = cb;
dprintk(VIDC_DBG,
"context bank found for CB : %s, device: %pK mapping: %pK\n",
match->name, match->dev, match->mapping);
break;
}
}
return match;
}
|