0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/slab.h>
0015 #include <linux/module.h>
0016 #include <linux/dma-mapping.h>
0017 #include <linux/vmalloc.h>
0018 #include <linux/mm.h>
0019 #include <linux/sched.h>
0020 #include <linux/file.h>
0021
0022 #include <media/videobuf2-v4l2.h>
0023 #include <media/videobuf2-memops.h>
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 struct frame_vector *vb2_create_framevec(unsigned long start,
0037 unsigned long length)
0038 {
0039 int ret;
0040 unsigned long first, last;
0041 unsigned long nr;
0042 struct frame_vector *vec;
0043
0044 first = start >> PAGE_SHIFT;
0045 last = (start + length - 1) >> PAGE_SHIFT;
0046 nr = last - first + 1;
0047 vec = frame_vector_create(nr);
0048 if (!vec)
0049 return ERR_PTR(-ENOMEM);
0050 ret = get_vaddr_frames(start & PAGE_MASK, nr, vec);
0051 if (ret < 0)
0052 goto out_destroy;
0053
0054 if (ret != nr) {
0055 ret = -EFAULT;
0056 goto out_release;
0057 }
0058 return vec;
0059 out_release:
0060 put_vaddr_frames(vec);
0061 out_destroy:
0062 frame_vector_destroy(vec);
0063 return ERR_PTR(ret);
0064 }
0065 EXPORT_SYMBOL(vb2_create_framevec);
0066
0067
0068
0069
0070
0071
0072
0073
0074 void vb2_destroy_framevec(struct frame_vector *vec)
0075 {
0076 put_vaddr_frames(vec);
0077 frame_vector_destroy(vec);
0078 }
0079 EXPORT_SYMBOL(vb2_destroy_framevec);
0080
0081
0082
0083
0084
0085
0086
0087
0088 static void vb2_common_vm_open(struct vm_area_struct *vma)
0089 {
0090 struct vb2_vmarea_handler *h = vma->vm_private_data;
0091
0092 pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
0093 __func__, h, refcount_read(h->refcount), vma->vm_start,
0094 vma->vm_end);
0095
0096 refcount_inc(h->refcount);
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106 static void vb2_common_vm_close(struct vm_area_struct *vma)
0107 {
0108 struct vb2_vmarea_handler *h = vma->vm_private_data;
0109
0110 pr_debug("%s: %p, refcount: %d, vma: %08lx-%08lx\n",
0111 __func__, h, refcount_read(h->refcount), vma->vm_start,
0112 vma->vm_end);
0113
0114 h->put(h->arg);
0115 }
0116
0117
0118
0119
0120
0121 const struct vm_operations_struct vb2_common_vm_ops = {
0122 .open = vb2_common_vm_open,
0123 .close = vb2_common_vm_close,
0124 };
0125 EXPORT_SYMBOL_GPL(vb2_common_vm_ops);
0126
0127 MODULE_DESCRIPTION("common memory handling routines for videobuf2");
0128 MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>");
0129 MODULE_LICENSE("GPL");