This source file includes following definitions.
- vb2_create_framevec
- vb2_destroy_framevec
- vb2_common_vm_open
- vb2_common_vm_close
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/slab.h>
15 #include <linux/module.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/vmalloc.h>
18 #include <linux/mm.h>
19 #include <linux/sched.h>
20 #include <linux/file.h>
21
22 #include <media/videobuf2-v4l2.h>
23 #include <media/videobuf2-memops.h>
24
25
26
27
28
29
30
31
32
33
34
35
36 struct frame_vector *vb2_create_framevec(unsigned long start,
37 unsigned long length)
38 {
39 int ret;
40 unsigned long first, last;
41 unsigned long nr;
42 struct frame_vector *vec;
43 unsigned int flags = FOLL_FORCE | FOLL_WRITE;
44
45 first = start >> PAGE_SHIFT;
46 last = (start + length - 1) >> PAGE_SHIFT;
47 nr = last - first + 1;
48 vec = frame_vector_create(nr);
49 if (!vec)
50 return ERR_PTR(-ENOMEM);
51 ret = get_vaddr_frames(start & PAGE_MASK, nr, flags, vec);
52 if (ret < 0)
53 goto out_destroy;
54
55 if (ret != nr) {
56 ret = -EFAULT;
57 goto out_release;
58 }
59 return vec;
60 out_release:
61 put_vaddr_frames(vec);
62 out_destroy:
63 frame_vector_destroy(vec);
64 return ERR_PTR(ret);
65 }
66 EXPORT_SYMBOL(vb2_create_framevec);
67
68
69
70
71
72
73
74
75 void vb2_destroy_framevec(struct frame_vector *vec)
76 {
77 put_vaddr_frames(vec);
78 frame_vector_destroy(vec);
79 }
80 EXPORT_SYMBOL(vb2_destroy_framevec);
81
82
83
84
85
86
87
88
89 static void vb2_common_vm_open(struct vm_area_struct *vma)
90 {
91 struct vb2_vmarea_handler *h = vma->vm_private_data;
92
93 pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
94 __func__, h, refcount_read(h->refcount), vma->vm_start,
95 vma->vm_end);
96
97 refcount_inc(h->refcount);
98 }
99
100
101
102
103
104
105
106
107 static void vb2_common_vm_close(struct vm_area_struct *vma)
108 {
109 struct vb2_vmarea_handler *h = vma->vm_private_data;
110
111 pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
112 __func__, h, refcount_read(h->refcount), vma->vm_start,
113 vma->vm_end);
114
115 h->put(h->arg);
116 }
117
118
119
120
121
122 const struct vm_operations_struct vb2_common_vm_ops = {
123 .open = vb2_common_vm_open,
124 .close = vb2_common_vm_close,
125 };
126 EXPORT_SYMBOL_GPL(vb2_common_vm_ops);
127
128 MODULE_DESCRIPTION("common memory handling routines for videobuf2");
129 MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>");
130 MODULE_LICENSE("GPL");