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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
|
/* linux/drivers/media/video/videobuf2-ion.c *
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*
* Implementation of Android ION memory allocator for videobuf2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/file.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/highmem.h>
#include <linux/dma-buf.h>
#include <linux/fs.h>
#include <linux/mutex.h>
#include <linux/vmalloc.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-memops.h>
#include <media/videobuf2-ion.h>
#include <linux/exynos_iovmm.h>
#include <linux/dmabuf_container.h>
#include <asm/cacheflush.h>
#define vb2ion_err(dev, fmt, ...) \
dev_err(dev, "VB2ION: " pr_fmt(fmt), ##__VA_ARGS__)
struct vb2_ion_buf {
struct device *dev;
struct vb2_vmarea_handler handler;
struct vm_area_struct *vma;
struct ion_handle *handle;
struct dma_buf *dma_buf;
struct dma_buf_attachment *attachment;
enum dma_data_direction direction;
void *kva;
unsigned long size;
atomic_t ref;
bool cached;
bool ion;
struct vb2_ion_cookie cookie;
};
#define CACHE_FLUSH_ALL_SIZE (SZ_8M + SZ_2M)
#define DMA_SYNC_SIZE SZ_512K
#define OUTER_FLUSH_ALL_SIZE SZ_1M
static bool vb2_ion_dma_is_coherent(struct device *dev,
enum dma_data_direction dir)
{
if (!(device_get_dma_attr(dev) == DEV_DMA_COHERENT))
return false;
/* TODO: condition for VB2ION_CTX_UNCACHED_READ_DMA */
return (dir != DMA_TO_DEVICE);
}
static int get_iommu_prot(struct device *dev,
enum dma_data_direction dir)
{
int prot;
if (dir == DMA_TO_DEVICE)
prot = IOMMU_READ;
else if (dir == DMA_FROM_DEVICE)
prot = IOMMU_WRITE;
else
prot = IOMMU_READ | IOMMU_WRITE;
if (vb2_ion_dma_is_coherent(dev, dir))
prot |= IOMMU_CACHE;
return prot;
}
/**
* vb2_get_vma() - acquire and lock the virtual memory area
* @vma: given virtual memory area
*
* This function attempts to acquire an area mapped in the userspace for
* the duration of a hardware operation. The area is "locked" by performing
* the same set of operation that are done when process calls fork() and
* memory areas are duplicated.
*
* Returns a copy of a virtual memory region on success or NULL.
*/
static struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma)
{
struct vm_area_struct *vma_copy;
vma_copy = kmalloc(sizeof(*vma_copy), GFP_KERNEL);
if (vma_copy == NULL)
return NULL;
if (vma->vm_ops && vma->vm_ops->open)
vma->vm_ops->open(vma);
if (vma->vm_file)
get_file(vma->vm_file);
memcpy(vma_copy, vma, sizeof(*vma));
vma_copy->vm_mm = NULL;
vma_copy->vm_next = NULL;
vma_copy->vm_prev = NULL;
return vma_copy;
}
/**
* vb2_put_userptr() - release a userspace virtual memory area
* @vma: virtual memory region associated with the area to be released
*
* This function releases the previously acquired memory area after a hardware
* operation.
*/
static void vb2_put_vma(struct vm_area_struct *vma)
{
if (!vma)
return;
if (vma->vm_ops && vma->vm_ops->close)
vma->vm_ops->close(vma);
if (vma->vm_file)
fput(vma->vm_file);
kfree(vma);
}
void vb2_ion_set_noncoherent_dma_read(struct device *dev, bool noncoherent)
{
/* TODO: store information into dev */
}
EXPORT_SYMBOL(vb2_ion_set_noncoherent_dma_read);
static void vb2_ion_put(void *buf_priv)
{
/* TODO */
}
static void *vb2_ion_alloc(struct device *dev, unsigned long attrs,
unsigned long size,
enum dma_data_direction dma_dir, gfp_t gfp_flags)
{
/* TODO */
return NULL;
}
static void *vb2_ion_cookie(void *buf_priv)
{
struct vb2_ion_buf *buf = buf_priv;
if (WARN_ON(!buf))
return NULL;
return (void *)&buf->cookie;
}
static void *vb2_ion_vaddr(void *buf_priv)
{
struct vb2_ion_buf *buf = buf_priv;
if (WARN_ON(!buf))
return NULL;
if (buf->kva != NULL)
return buf->kva;
if (dma_buf_begin_cpu_access(buf->dma_buf, buf->direction))
return NULL;
buf->kva = dma_buf_kmap(buf->dma_buf, buf->cookie.offset / PAGE_SIZE);
if (buf->kva == NULL)
dma_buf_end_cpu_access(buf->dma_buf, buf->direction);
else
buf->kva += buf->cookie.offset & ~PAGE_MASK;
return buf->kva;
}
static unsigned int vb2_ion_num_users(void *buf_priv)
{
struct vb2_ion_buf *buf = buf_priv;
if (WARN_ON(!buf))
return 0;
return atomic_read(&buf->ref);
}
static int vb2_ion_mmap(void *buf_priv, struct vm_area_struct *vma)
{
struct vb2_ion_buf *buf = buf_priv;
unsigned long vm_start = vma->vm_start;
unsigned long vm_end = vma->vm_end;
struct scatterlist *sg = buf->cookie.sgt->sgl;
unsigned long size;
int ret = -EINVAL;
if (buf->size < (vm_end - vm_start))
return ret;
if (!buf->cached)
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
size = min_t(size_t, vm_end - vm_start, sg_dma_len(sg));
ret = remap_pfn_range(vma, vm_start, page_to_pfn(sg_page(sg)),
size, vma->vm_page_prot);
for (sg = sg_next(sg), vm_start += size;
!ret && sg && (vm_start < vm_end);
vm_start += size, sg = sg_next(sg)) {
size = min_t(size_t, vm_end - vm_start, sg_dma_len(sg));
ret = remap_pfn_range(vma, vm_start, page_to_pfn(sg_page(sg)),
size, vma->vm_page_prot);
}
if (ret)
return ret;
if (vm_start < vm_end)
return -EINVAL;
vma->vm_flags |= VM_DONTEXPAND;
vma->vm_private_data = &buf->handler;
vma->vm_ops = &vb2_common_vm_ops;
vma->vm_ops->open(vma);
return ret;
}
static int vb2_ion_map_dmabuf(void *mem_priv)
{
struct vb2_ion_buf *buf = mem_priv;
if (WARN_ON(!buf->attachment)) {
pr_err("trying to pin a non attached buffer\n");
return -EINVAL;
}
if (WARN_ON(buf->cookie.sgt)) {
pr_err("dmabuf buffer is already pinned\n");
return 0;
}
/* get the associated scatterlist for this buffer */
buf->cookie.sgt = dma_buf_map_attachment(buf->attachment,
buf->direction);
if (IS_ERR_OR_NULL(buf->cookie.sgt)) {
pr_err("Error getting dmabuf scatterlist\n");
return -EINVAL;
}
/*
* A dmabuf container itself is also a dmabuf. It is capable of attach
* and map but the buffer in it is not accessible because it just has
* metadata of dma-buf array.
*/
if (dmabuf_container_get_count(buf->dma_buf) > 0)
return 0;
buf->cookie.offset = 0;
buf->cookie.paddr = sg_phys(buf->cookie.sgt->sgl) + buf->cookie.offset;
if (buf->cookie.ioaddr == 0) {
buf->cookie.ioaddr = ion_iovmm_map(buf->attachment, 0,
buf->size, buf->direction,
get_iommu_prot(buf->dev, buf->direction));
if (IS_ERR_VALUE(buf->cookie.ioaddr)) {
pr_err("buf->cookie.ioaddr is error: %pa\n",
&buf->cookie.ioaddr);
dma_buf_unmap_attachment(buf->attachment,
buf->cookie.sgt, buf->direction);
return (int)buf->cookie.ioaddr;
}
}
return 0;
}
static void vb2_ion_unmap_dmabuf(void *mem_priv)
{
struct vb2_ion_buf *buf = mem_priv;
if (WARN_ON(!buf->attachment)) {
pr_err("trying to unpin a not attached buffer\n");
return;
}
if (WARN_ON(!buf->cookie.sgt)) {
pr_err("dmabuf buffer is already unpinned\n");
return;
}
dma_buf_unmap_attachment(buf->attachment,
buf->cookie.sgt, buf->direction);
buf->cookie.sgt = NULL;
}
static void vb2_ion_detach_dmabuf(void *mem_priv)
{
struct vb2_ion_buf *buf = mem_priv;
if (buf->cookie.ioaddr) {
ion_iovmm_unmap(buf->attachment, buf->cookie.ioaddr);
buf->cookie.ioaddr = 0;
}
if (buf->kva != NULL) {
dma_buf_kunmap(buf->dma_buf, 0, buf->kva);
dma_buf_end_cpu_access(buf->dma_buf, 0);
}
/* detach this attachment */
dma_buf_detach(buf->dma_buf, buf->attachment);
kfree(buf);
}
static void *vb2_ion_attach_dmabuf(struct device *dev, struct dma_buf *dbuf,
unsigned long size, enum dma_data_direction dma_dir)
{
struct vb2_ion_buf *buf;
struct dma_buf_attachment *attachment;
if (dbuf->size < size) {
WARN(1, "dbuf->size(%zd) is smaller than size(%ld)\n",
dbuf->size, size);
return ERR_PTR(-EFAULT);
}
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf) {
pr_err("out of memory\n");
return ERR_PTR(-ENOMEM);
}
buf->dev = dev;
/* create attachment for the dmabuf with the user device */
attachment = dma_buf_attach(dbuf, buf->dev);
if (IS_ERR(attachment)) {
pr_err("failed to attach dmabuf\n");
kfree(buf);
return attachment;
}
buf->direction = dma_dir;
buf->size = size;
buf->dma_buf = dbuf;
buf->ion = true;
buf->attachment = attachment;
return buf;
}
static void vb2_ion_put_vma(struct vm_area_struct *vma)
{
while (vma) {
struct vm_area_struct *tmp;
tmp = vma;
vma = vma->vm_prev;
vb2_put_vma(tmp);
}
}
/*
* Verify the user's input and
* obtain the reference to the vma against the user's area
* Returns the last node of doubly linked list of replicated vma.
*/
static struct vm_area_struct *vb2_ion_get_vma(struct device *dev,
unsigned long vaddr, unsigned long size)
{
struct vm_area_struct *new_vma = NULL;
struct vm_area_struct *vma;
unsigned long addr = vaddr;
unsigned long len = size;
if ((vaddr + size) <= vaddr) {
vb2ion_err(dev, "size overflow in user area, [%#lx, %#lx)\n",
vaddr, size);
return NULL;
}
for (vma = find_vma(current->mm, addr);
vma && len && (addr >= vma->vm_start); vma = vma->vm_next) {
struct vm_area_struct *cur_vma;
cur_vma = vb2_get_vma(vma);
if (new_vma) {
if ((cur_vma->vm_file != new_vma->vm_file) ||
(cur_vma->vm_ops != new_vma->vm_ops)) {
vb2ion_err(dev,
"[%#lx, %#lx) crosses disparate vmas\n",
vaddr, size);
vb2_put_vma(cur_vma);
break;
}
new_vma->vm_next = cur_vma;
}
cur_vma->vm_prev = new_vma;
new_vma = cur_vma;
if ((addr + len) <= vma->vm_end) {
addr = addr + len;
len = 0;
} else {
len -= vma->vm_end - addr;
addr = vma->vm_end;
}
}
if (len) { /* error detected */
vb2ion_err(dev, "Invalid user area [%#lx, %#lx)\n",
vaddr, size);
vb2_ion_put_vma(new_vma);
return NULL;
}
while (new_vma && new_vma->vm_prev)
new_vma = new_vma->vm_prev;
return new_vma;
}
static void vb2_ion_put_userptr_dmabuf(struct vb2_ion_buf *buf)
{
ion_iovmm_unmap(buf->attachment,
buf->cookie.ioaddr - buf->cookie.offset);
dma_buf_unmap_attachment(buf->attachment,
buf->cookie.sgt, buf->direction);
dma_buf_detach(buf->dma_buf, buf->attachment);
}
static void *vb2_ion_get_userptr_dmabuf(struct vb2_ion_buf *buf,
unsigned long vaddr)
{
void *ret;
buf->attachment = dma_buf_attach(buf->dma_buf, buf->dev);
if (IS_ERR(buf->attachment)) {
dev_err(buf->dev,
"%s: Failed to pin user buffer @ %#lx/%#lx\n",
__func__, vaddr, buf->size);
return ERR_CAST(buf->attachment);
}
buf->cookie.sgt = dma_buf_map_attachment(buf->attachment,
buf->direction);
if (IS_ERR(buf->cookie.sgt)) {
dev_err(buf->dev,
"%s: Failed to get sgt of user buffer @ %#lx/%#lx\n",
__func__, vaddr, buf->size);
ret = ERR_CAST(buf->cookie.sgt);
goto err_map;
}
buf->cookie.ioaddr = ion_iovmm_map(buf->attachment, 0,
buf->size, buf->direction,
get_iommu_prot(buf->dev, buf->direction));
if (IS_ERR_VALUE(buf->cookie.ioaddr)) {
ret = ERR_PTR(buf->cookie.ioaddr);
goto err_iovmm;
}
buf->cookie.ioaddr += buf->cookie.offset;
return NULL;
err_iovmm:
dma_buf_unmap_attachment(buf->attachment,
buf->cookie.sgt, buf->direction);
err_map:
dma_buf_detach(buf->dma_buf, buf->attachment);
return ret;
}
static void *vb2_ion_get_userptr(struct device *dev, unsigned long vaddr,
unsigned long size, enum dma_data_direction dma_dir)
{
struct vb2_ion_buf *buf = NULL;
struct vm_area_struct *vma;
void *p_ret = ERR_PTR(-ENOMEM);;
vma = vb2_ion_get_vma(dev, vaddr, size);
if (!vma) {
dev_err(dev,
"%s: Failed to holding user buffer @ %#lx/%#lx\n",
__func__, vaddr, size);
return ERR_PTR(-EINVAL);
}
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf) {
dev_err(dev, "%s: Not enough memory\n", __func__);
p_ret = ERR_PTR(-ENOMEM);
goto err_alloc;
}
if (vma->vm_file) {
get_file(vma->vm_file);
buf->dma_buf = get_dma_buf_file(vma->vm_file);
}
buf->dev = dev;
buf->direction = dma_dir;
buf->size = size;
buf->vma = vma;
if (buf->dma_buf) {
buf->ion = true;
buf->cookie.offset = vaddr - vma->vm_start;
p_ret = vb2_ion_get_userptr_dmabuf(buf, vaddr);
if (IS_ERR(p_ret))
goto err_map;
} else {
buf->cookie.ioaddr = exynos_iovmm_map_userptr(buf->dev, vaddr,
size, get_iommu_prot(buf->dev, buf->direction));
if (IS_ERR_VALUE(buf->cookie.ioaddr)) {
p_ret = ERR_PTR(buf->cookie.ioaddr);
goto err_map;
}
}
if ((pgprot_val(pgprot_noncached(buf->vma->vm_page_prot))
== pgprot_val(buf->vma->vm_page_prot))
|| (pgprot_val(pgprot_writecombine(buf->vma->vm_page_prot))
== pgprot_val(buf->vma->vm_page_prot)))
buf->cached = false;
else
buf->cached = true;
return buf;
err_map:
if (buf->dma_buf)
dma_buf_put(buf->dma_buf);
if (vma->vm_file)
fput(vma->vm_file);
kfree(buf);
err_alloc:
vb2_ion_put_vma(vma);
return p_ret;
}
static void vb2_ion_put_userptr(void *mem_priv)
{
struct vb2_ion_buf *buf = mem_priv;
if (buf->kva) {
dma_buf_kunmap(buf->dma_buf, buf->cookie.offset / PAGE_SIZE,
buf->kva - (buf->cookie.offset & ~PAGE_SIZE));
dma_buf_end_cpu_access(buf->dma_buf, DMA_FROM_DEVICE);
}
if (buf->dma_buf)
vb2_ion_put_userptr_dmabuf(buf);
else
exynos_iovmm_unmap_userptr(buf->dev, buf->cookie.ioaddr);
if (buf->dma_buf)
dma_buf_put(buf->dma_buf);
if (buf->vma->vm_file)
fput(buf->vma->vm_file);
vb2_ion_put_vma(buf->vma);
kfree(buf);
}
const struct vb2_mem_ops vb2_ion_memops = {
.alloc = vb2_ion_alloc,
.put = vb2_ion_put,
.cookie = vb2_ion_cookie,
.vaddr = vb2_ion_vaddr,
.mmap = vb2_ion_mmap,
.map_dmabuf = vb2_ion_map_dmabuf,
.unmap_dmabuf = vb2_ion_unmap_dmabuf,
.attach_dmabuf = vb2_ion_attach_dmabuf,
.detach_dmabuf = vb2_ion_detach_dmabuf,
.get_userptr = vb2_ion_get_userptr,
.put_userptr = vb2_ion_put_userptr,
.num_users = vb2_ion_num_users,
};
EXPORT_SYMBOL_GPL(vb2_ion_memops);
void vb2_ion_sync_for_device(void *cookie, off_t offset, size_t size,
enum dma_data_direction dir)
{
struct vb2_ion_buf *buf = container_of(cookie,
struct vb2_ion_buf, cookie);
if (vb2_ion_dma_is_coherent(buf->dev, dir))
return;
dev_dbg(buf->dev, "syncing for device, dmabuf: %p, kva: %p, "
"size: %zd, dir: %d\n", buf->dma_buf, buf->kva, size, dir);
if (buf->kva) {
BUG_ON((offset < 0) || (offset > buf->size));
BUG_ON((offset + size) < size);
BUG_ON((size > buf->size) || ((offset + size) > buf->size));
exynos_ion_sync_vaddr_for_device(buf->dev,
buf->dma_buf, buf->kva, size, offset, dir);
} else if (buf->dma_buf) {
exynos_ion_sync_dmabuf_for_device(buf->dev,
buf->dma_buf, size, dir);
} else if (buf->vma && buf->cached) {
exynos_iommu_sync_for_device(buf->dev,
buf->cookie.ioaddr, size, dir);
}
}
EXPORT_SYMBOL_GPL(vb2_ion_sync_for_device);
void vb2_ion_sync_for_cpu(void *cookie, off_t offset, size_t size,
enum dma_data_direction dir)
{
struct vb2_ion_buf *buf = container_of(cookie,
struct vb2_ion_buf, cookie);
if (vb2_ion_dma_is_coherent(buf->dev, dir))
return;
dev_dbg(buf->dev, "syncing for cpu, dmabuf: %p, kva: %p, "
"size: %zd, dir: %d\n", buf->dma_buf, buf->kva, size, dir);
if (buf->kva) {
BUG_ON((offset < 0) || (offset > buf->size));
BUG_ON((offset + size) < size);
BUG_ON((size > buf->size) || ((offset + size) > buf->size));
exynos_ion_sync_vaddr_for_cpu(buf->dev,
buf->dma_buf, buf->kva, size, offset, dir);
} else if (buf->dma_buf) {
exynos_ion_sync_dmabuf_for_cpu(buf->dev,
buf->dma_buf, size, dir);
} else if (buf->vma && buf->cached) {
exynos_iommu_sync_for_cpu(buf->dev,
buf->cookie.ioaddr, size, dir);
}
}
EXPORT_SYMBOL_GPL(vb2_ion_sync_for_cpu);
int vb2_ion_buf_prepare(struct vb2_buffer *vb)
{
int i;
enum dma_data_direction dir;
dir = V4L2_TYPE_IS_OUTPUT(vb->type) ?
DMA_TO_DEVICE : DMA_FROM_DEVICE;
for (i = 0; i < vb->num_planes; i++) {
struct vb2_ion_buf *buf = vb->planes[i].mem_priv;
vb2_ion_sync_for_device((void *) &buf->cookie, 0,
buf->size, dir);
}
return 0;
}
EXPORT_SYMBOL_GPL(vb2_ion_buf_prepare);
void vb2_ion_buf_finish(struct vb2_buffer *vb)
{
int i;
enum dma_data_direction dir;
dir = V4L2_TYPE_IS_OUTPUT(vb->type) ?
DMA_TO_DEVICE : DMA_FROM_DEVICE;
for (i = 0; i < vb->num_planes; i++) {
struct vb2_ion_buf *buf = vb->planes[i].mem_priv;
vb2_ion_sync_for_cpu((void *) &buf->cookie, 0,
buf->size, dir);
}
}
EXPORT_SYMBOL_GPL(vb2_ion_buf_finish);
int vb2_ion_buf_prepare_exact(struct vb2_buffer *vb)
{
int i;
enum dma_data_direction dir;
dir = V4L2_TYPE_IS_OUTPUT(vb->type) ?
DMA_TO_DEVICE : DMA_FROM_DEVICE;
for (i = 0; i < vb->num_planes; i++) {
struct vb2_ion_buf *buf = vb->planes[i].mem_priv;
vb2_ion_sync_for_device((void *) &buf->cookie, 0,
vb2_get_plane_payload(vb, i), dir);
}
return 0;
}
EXPORT_SYMBOL_GPL(vb2_ion_buf_prepare_exact);
int vb2_ion_buf_finish_exact(struct vb2_buffer *vb)
{
int i;
enum dma_data_direction dir;
dir = V4L2_TYPE_IS_OUTPUT(vb->type) ?
DMA_TO_DEVICE : DMA_FROM_DEVICE;
for (i = 0; i < vb->num_planes; i++) {
struct vb2_ion_buf *buf = vb->planes[i].mem_priv;
vb2_ion_sync_for_cpu((void *) &buf->cookie, 0,
vb2_get_plane_payload(vb, i), dir);
}
return 0;
}
EXPORT_SYMBOL_GPL(vb2_ion_buf_finish_exact);
struct dma_buf *vb2_ion_get_dmabuf(void *cookie)
{
struct vb2_ion_buf *buf = container_of(cookie,
struct vb2_ion_buf, cookie);
if (buf->dma_buf)
get_dma_buf(buf->dma_buf);
return buf->dma_buf;
}
MODULE_AUTHOR("Cho KyongHo <pullip.cho@samsung.com>");
MODULE_AUTHOR("Jinsung Yang <jsgood.yang@samsung.com>");
MODULE_DESCRIPTION("Android ION allocator handling routines for videobuf2");
MODULE_LICENSE("GPL");
|