{
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_buffer *vb = &cb->vb2;
+ struct vb2_queue *q = vb->vb2_queue;
enum dma_data_direction dma_dir =
V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
void *mem_priv;
@@ -198,7 +199,7 @@ static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
* Allocate memory for all planes in this buffer
* NOTE: mmapped areas should be page aligned
*/
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
@@ -207,16 +208,16 @@ static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
goto free;
/* Associate allocator private data with this plane */
- vb->vb2.planes[plane].mem_priv = mem_priv;
- vb->v4l2_planes[plane].length = q->plane_sizes[plane];
+ vb->planes[plane].mem_priv = mem_priv;
+ cb->v4l2_planes[plane].length = q->plane_sizes[plane];
}
return 0;
free:
/* Free already allocated memory if one of the allocations failed */
for (; plane > 0; --plane) {
- call_void_memop(vb, put, vb->vb2.planes[plane - 1].mem_priv);
- vb->vb2.planes[plane - 1].mem_priv = NULL;
+ call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
+ vb->planes[plane - 1].mem_priv = NULL;
}
return -ENOMEM;
@@ -225,15 +226,16 @@ free:
/**
* __vb2_buf_mem_free() - free memory of the given buffer
*/
-static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
+static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *cb)
{
+ struct vb2_buffer *vb = &cb->vb2;
unsigned int plane;
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- call_void_memop(vb, put, vb->vb2.planes[plane].mem_priv);
- vb->vb2.planes[plane].mem_priv = NULL;
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ call_void_memop(vb, put, vb->planes[plane].mem_priv);
+ vb->planes[plane].mem_priv = NULL;
dprintk(3, "freed plane %d of buffer %d\n", plane,
- vb->v4l2_buf.index);
+ cb->v4l2_buf.index);
}
}
@@ -241,14 +243,15 @@ static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
* __vb2_buf_userptr_put() - release userspace memory associated with
* a USERPTR buffer
*/
-static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
+static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *cb)
{
+ struct vb2_buffer *vb = &cb->vb2;
unsigned int plane;
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- if (vb->vb2.planes[plane].mem_priv)
- call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
- vb->vb2.planes[plane].mem_priv = NULL;
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ if (vb->planes[plane].mem_priv)
+ call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+ vb->planes[plane].mem_priv = NULL;
}
}
@@ -256,8 +259,9 @@ static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
* __vb2_plane_dmabuf_put() - release memory associated with
* a DMABUF shared plane
*/
-static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane *p)
+static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *cb, struct vb2_plane *p)
{
+ struct vb2_buffer *vb = &cb->vb2;
if (!p->mem_priv)
return;
@@ -273,12 +277,13 @@ static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane
* __vb2_buf_dmabuf_put() - release memory associated with
* a DMABUF shared buffer
*/
-static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
+static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *cb)
{
+ struct vb2_buffer *vb = &cb->vb2;
unsigned int plane;
- for (plane = 0; plane < vb->vb2.num_planes; ++plane)
- __vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
+ for (plane = 0; plane < vb->num_planes; ++plane)
+ __vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
}
/**
@@ -288,15 +293,17 @@ static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
static void __setup_lengths(struct vb2_queue *q, unsigned int n)
{
unsigned int buffer, plane;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
vb = q->bufs[buffer];
if (!vb)
continue;
- for (plane = 0; plane < vb->vb2.num_planes; ++plane)
- vb->v4l2_planes[plane].length = q->plane_sizes[plane];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ for (plane = 0; plane < vb->num_planes; ++plane)
+ cb->v4l2_planes[plane].length = q->plane_sizes[plane];
}
}
@@ -307,13 +314,15 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n)
static void __setup_offsets(struct vb2_queue *q, unsigned int n)
{
unsigned int buffer, plane;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
unsigned long off;
if (q->num_buffers) {
struct v4l2_plane *p;
vb = q->bufs[q->num_buffers - 1];
- p = &vb->v4l2_planes[vb->vb2.num_planes - 1];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ p = &cb->v4l2_planes[vb->num_planes - 1];
off = PAGE_ALIGN(p->m.mem_offset + p->length);
} else {
off = 0;
@@ -324,13 +333,14 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
if (!vb)
continue;
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- vb->v4l2_planes[plane].m.mem_offset = off;
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ cb->v4l2_planes[plane].m.mem_offset = off;
dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
buffer, plane, off);
- off += vb->v4l2_planes[plane].length;
+ off += cb->v4l2_planes[plane].length;
off = PAGE_ALIGN(off);
}
}
@@ -347,35 +357,37 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
unsigned int num_buffers, unsigned int num_planes)
{
unsigned int buffer;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
int ret;
for (buffer = 0; buffer < num_buffers; ++buffer) {
/* Allocate videobuf buffer structures */
- vb = kzalloc(q->buf_struct_size, GFP_KERNEL);
- if (!vb) {
+ cb = kzalloc(q->buf_struct_size, GFP_KERNEL);
+ if (!cb) {
dprintk(1, "memory alloc for buffer struct failed\n");
break;
}
+ vb = &cb->vb2;
/* Length stores number of planes for multiplanar buffers */
if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
- vb->v4l2_buf.length = num_planes;
+ cb->v4l2_buf.length = num_planes;
- vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
- vb->vb2.vb2_queue = q;
- vb->vb2.num_planes = num_planes;
- vb->v4l2_buf.index = q->num_buffers + buffer;
- vb->v4l2_buf.type = q->type;
- vb->v4l2_buf.memory = memory;
+ vb->state = VB2_BUF_STATE_DEQUEUED;
+ vb->vb2_queue = q;
+ vb->num_planes = num_planes;
+ cb->v4l2_buf.index = q->num_buffers + buffer;
+ cb->v4l2_buf.type = q->type;
+ cb->v4l2_buf.memory = memory;
/* Allocate video buffer memory for the MMAP type */
if (memory == V4L2_MEMORY_MMAP) {
- ret = __vb2_buf_mem_alloc(vb);
+ ret = __vb2_buf_mem_alloc(cb);
if (ret) {
dprintk(1, "failed allocating memory for "
"buffer %d\n", buffer);
- kfree(vb);
+ kfree(cb);
break;
}
/*
@@ -387,8 +399,8 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
if (ret) {
dprintk(1, "buffer %d %p initialization"
" failed\n", buffer, vb);
- __vb2_buf_mem_free(vb);
- kfree(vb);
+ __vb2_buf_mem_free(cb);
+ kfree(cb);
break;
}
}
@@ -412,21 +424,23 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
{
unsigned int buffer;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
++buffer) {
vb = q->bufs[buffer];
if (!vb)
continue;
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
/* Free MMAP buffers or release USERPTR buffers */
if (q->memory == V4L2_MEMORY_MMAP)
- __vb2_buf_mem_free(vb);
+ __vb2_buf_mem_free(cb);
else if (q->memory == V4L2_MEMORY_DMABUF)
- __vb2_buf_dmabuf_put(vb);
+ __vb2_buf_dmabuf_put(cb);
else
- __vb2_buf_userptr_put(vb);
+ __vb2_buf_userptr_put(cb);
}
}
@@ -438,7 +452,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
{
unsigned int buffer;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_buffer *vb;
/*
* Sanity check: when preparing a buffer the queue lock is released for
@@ -450,11 +464,11 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
*/
for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
++buffer) {
- vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
+ vb = q->bufs[buffer];
if (vb == NULL)
continue;
- if (vb->vb2.state == VB2_BUF_STATE_PREPARING) {
+ if (vb->state == VB2_BUF_STATE_PREPARING) {
dprintk(1, "preparing buffers, cannot free\n");
return -EAGAIN;
}
@@ -463,9 +477,9 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
/* Call driver-provided cleanup function for each buffer, if provided */
for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
++buffer) {
- vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
+ vb = q->bufs[buffer];
- if (vb && vb->vb2.planes[0].mem_priv)
+ if (vb && vb->planes[0].mem_priv)
call_void_vb_qop(vb, buf_cleanup, vb);
}
@@ -498,38 +512,38 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
q->cnt_stop_streaming = 0;
}
for (buffer = 0; buffer < q->num_buffers; ++buffer) {
- struct vb2_v4l2_buffer *vb = q->bufs[buffer];
- bool unbalanced = vb->vb2.cnt_mem_alloc != vb->vb2.cnt_mem_put ||
- vb->vb2.cnt_mem_prepare != vb->vb2.cnt_mem_finish ||
- vb->vb2.cnt_mem_get_userptr != vb->vb2.cnt_mem_put_userptr ||
- vb->vb2.cnt_mem_attach_dmabuf != vb->vb2.cnt_mem_detach_dmabuf ||
- vb->vb2.cnt_mem_map_dmabuf != vb->vb2.cnt_mem_unmap_dmabuf ||
- vb->vb2.cnt_buf_queue != vb->vb2.cnt_buf_done ||
- vb->vb2.cnt_buf_prepare != vb->vb2.cnt_buf_finish ||
- vb->vb2.cnt_buf_init != vb->vb2.cnt_buf_cleanup;
+ struct vb2_buffer *vb = q->bufs[buffer];
+ bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
+ vb->cnt_mem_prepare != vb->cnt_mem_finish ||
+ vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
+ vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
+ vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
+ vb->cnt_buf_queue != vb->cnt_buf_done ||
+ vb->cnt_buf_prepare != vb->cnt_buf_finish ||
+ vb->cnt_buf_init != vb->cnt_buf_cleanup;
if (unbalanced || debug) {
pr_info("vb2: counters for queue %p, buffer %d:%s\n",
q, buffer, unbalanced ? " UNBALANCED!" : "");
pr_info("vb2: buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
- vb->vb2.cnt_buf_init, vb->vb2.cnt_buf_cleanup,
- vb->vb2.cnt_buf_prepare, vb->vb2.cnt_buf_finish);
+ vb->cnt_buf_init, vb->cnt_buf_cleanup,
+ vb->cnt_buf_prepare, vb->cnt_buf_finish);
pr_info("vb2: buf_queue: %u buf_done: %u\n",
- vb->vb2.cnt_buf_queue, vb->vb2.cnt_buf_done);
+ vb->cnt_buf_queue, vb->cnt_buf_done);
pr_info("vb2: alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
- vb->vb2.cnt_mem_alloc, vb->vb2.cnt_mem_put,
- vb->vb2.cnt_mem_prepare, vb->vb2.cnt_mem_finish,
- vb->vb2.cnt_mem_mmap);
+ vb->cnt_mem_alloc, vb->cnt_mem_put,
+ vb->cnt_mem_prepare, vb->cnt_mem_finish,
+ vb->cnt_mem_mmap);
pr_info("vb2: get_userptr: %u put_userptr: %u\n",
- vb->vb2.cnt_mem_get_userptr, vb->vb2.cnt_mem_put_userptr);
+ vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
pr_info("vb2: attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
- vb->vb2.cnt_mem_attach_dmabuf, vb->vb2.cnt_mem_detach_dmabuf,
- vb->vb2.cnt_mem_map_dmabuf, vb->vb2.cnt_mem_unmap_dmabuf);
+ vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
+ vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
pr_info("vb2: get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
- vb->vb2.cnt_mem_get_dmabuf,
- vb->vb2.cnt_mem_num_users,
- vb->vb2.cnt_mem_vaddr,
- vb->vb2.cnt_mem_cookie);
+ vb->cnt_mem_get_dmabuf,
+ vb->cnt_mem_num_users,
+ vb->cnt_mem_vaddr,
+ vb->cnt_mem_cookie);
}
}
#endif
@@ -553,8 +567,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
* __verify_planes_array() - verify that the planes array passed in struct
* v4l2_buffer from userspace can be safely used
*/
-static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
+static int __verify_planes_array(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
{
+ struct vb2_buffer *vb = &cb->vb2;
+
if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
return 0;
@@ -565,9 +581,9 @@ static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_b
return -EINVAL;
}
- if (b->length < vb->vb2.num_planes || b->length > VIDEO_MAX_PLANES) {
+ if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
dprintk(1, "incorrect planes array length, "
- "expected %d, got %d\n", vb->vb2.num_planes, b->length);
+ "expected %d, got %d\n", vb->num_planes, b->length);
return -EINVAL;
}
@@ -578,8 +594,9 @@ static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_b
* __verify_length() - Verify that the bytesused value for each plane fits in
* the plane length and that the data offset doesn't exceed the bytesused value.
*/
-static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
+static int __verify_length(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
{
+ struct vb2_buffer *vb = &cb->vb2;
unsigned int length;
unsigned int bytesused;
unsigned int plane;
@@ -588,11 +605,11 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
return 0;
if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
length = (b->memory == V4L2_MEMORY_USERPTR ||
b->memory == V4L2_MEMORY_DMABUF)
? b->m.planes[plane].length
- : vb->v4l2_planes[plane].length;
+ : cb->v4l2_planes[plane].length;
bytesused = b->m.planes[plane].bytesused
? b->m.planes[plane].bytesused : length;
@@ -605,7 +622,7 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
}
} else {
length = (b->memory == V4L2_MEMORY_USERPTR)
- ? b->length : vb->v4l2_planes[0].length;
+ ? b->length : cb->v4l2_planes[0].length;
bytesused = b->bytesused ? b->bytesused : length;
if (b->bytesused > length)
@@ -619,11 +636,12 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
* __buffer_in_use() - return true if the buffer is in use and
* the queue cannot be freed (by the means of REQBUFS(0)) call
*/
-static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
+static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *cb)
{
+ struct vb2_buffer *vb = &cb->vb2;
unsigned int plane;
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- void *mem_priv = vb->vb2.planes[plane].mem_priv;
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ void *mem_priv = vb->planes[plane].mem_priv;
/*
* If num_users() has not been provided, call_memop
* will return 0, apparently nobody cares about this
@@ -642,9 +660,12 @@ static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
*/
static bool __buffers_in_use(struct vb2_queue *q)
{
+ struct vb2_v4l2_buffer *cb;
unsigned int buffer;
+
for (buffer = 0; buffer < q->num_buffers; ++buffer) {
- if (__buffer_in_use(q, q->bufs[buffer]))
+ cb = container_of(q->bufs[buffer], struct vb2_v4l2_buffer, vb2);
+ if (__buffer_in_use(q, cb))
return true;
}
return false;
@@ -654,36 +675,37 @@ static bool __buffers_in_use(struct vb2_queue *q)
* __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
* returned to userspace
*/
-static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b)
+static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *cb, struct v4l2_buffer *b)
{
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_buffer *vb = &cb->vb2;
+ struct vb2_queue *q = vb->vb2_queue;
/* Copy back data such as timestamp, flags, etc. */
- memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
- b->reserved2 = vb->v4l2_buf.reserved2;
- b->reserved = vb->v4l2_buf.reserved;
+ memcpy(b, &cb->v4l2_buf, offsetof(struct v4l2_buffer, m));
+ b->reserved2 = cb->v4l2_buf.reserved2;
+ b->reserved = cb->v4l2_buf.reserved;
if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
/*
* Fill in plane-related data if userspace provided an array
* for it. The caller has already verified memory and size.
*/
- b->length = vb->vb2.num_planes;
- memcpy(b->m.planes, vb->v4l2_planes,
+ b->length = vb->num_planes;
+ memcpy(b->m.planes, cb->v4l2_planes,
b->length * sizeof(struct v4l2_plane));
} else {
/*
* We use length and offset in v4l2_planes array even for
* single-planar buffers, but userspace does not.
*/
- b->length = vb->v4l2_planes[0].length;
- b->bytesused = vb->v4l2_planes[0].bytesused;
+ b->length = cb->v4l2_planes[0].length;
+ b->bytesused = cb->v4l2_planes[0].bytesused;
if (q->memory == V4L2_MEMORY_MMAP)
- b->m.offset = vb->v4l2_planes[0].m.mem_offset;
+ b->m.offset = cb->v4l2_planes[0].m.mem_offset;
else if (q->memory == V4L2_MEMORY_USERPTR)
- b->m.userptr = vb->v4l2_planes[0].m.userptr;
+ b->m.userptr = cb->v4l2_planes[0].m.userptr;
else if (q->memory == V4L2_MEMORY_DMABUF)
- b->m.fd = vb->v4l2_planes[0].m.fd;
+ b->m.fd = cb->v4l2_planes[0].m.fd;
}
/*
@@ -701,7 +723,7 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
}
- switch (vb->vb2.state) {
+ switch (vb->state) {
case VB2_BUF_STATE_QUEUED:
case VB2_BUF_STATE_ACTIVE:
b->flags |= V4L2_BUF_FLAG_QUEUED;
@@ -721,7 +743,7 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
break;
}
- if (__buffer_in_use(q, vb))
+ if (__buffer_in_use(q, cb))
b->flags |= V4L2_BUF_FLAG_MAPPED;
}
@@ -740,7 +762,8 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
*/
int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
{
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
int ret;
if (b->type != q->type) {
@@ -753,9 +776,10 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
return -EINVAL;
}
vb = q->bufs[b->index];
- ret = __verify_planes_array(vb, b);
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ ret = __verify_planes_array(cb, b);
if (!ret)
- __fill_v4l2_buffer(vb, b);
+ __fill_v4l2_buffer(cb, b);
return ret;
}
EXPORT_SYMBOL(vb2_querybuf);
@@ -1123,12 +1147,13 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
* This function returns a kernel virtual address of a given plane if
* such a mapping exist, NULL otherwise.
*/
-void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
+void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
{
- if (plane_no > vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
+ struct vb2_buffer *vb = &cb->vb2;
+ if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
return NULL;
- return call_ptr_memop(vb, vaddr, vb->vb2.planes[plane_no].mem_priv);
+ return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
}
EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
@@ -1140,16 +1165,17 @@ EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
*
* This function returns an allocator specific cookie for a given plane if
* available, NULL otherwise. The allocator should provide some simple static
- * inline funaction, which would convert this cookie to the allocator specific
+ * inline function, which would convert this cookie to the allocator specific
* type that can be used directly by the driver to access the buffer. This can
* be for example physical address, pointer to scatter list or IOMMU mapping.
*/
-void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
+void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
{
- if (plane_no >= vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
+ struct vb2_buffer *vb = &cb->vb2;
+ if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
return NULL;
- return call_ptr_memop(vb, cookie, vb->vb2.planes[plane_no].mem_priv);
+ return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
}
EXPORT_SYMBOL_GPL(vb2_plane_cookie);
@@ -1172,13 +1198,14 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
* be started for some reason. In that case the buffers should be returned with
* state QUEUED.
*/
-void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
+void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state)
{
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_buffer *vb = &cb->vb2;
+ struct vb2_queue *q = vb->vb2_queue;
unsigned long flags;
unsigned int plane;
- if (WARN_ON(vb->vb2.state != VB2_BUF_STATE_ACTIVE))
+ if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
return;
if (WARN_ON(state != VB2_BUF_STATE_DONE &&
@@ -1191,20 +1218,20 @@ void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
* Although this is not a callback, it still does have to balance
* with the buf_queue op. So update this counter manually.
*/
- vb->vb2.cnt_buf_done++;
+ vb->cnt_buf_done++;
#endif
dprintk(4, "done processing on buffer %d, state: %d\n",
- vb->v4l2_buf.index, state);
+ cb->v4l2_buf.index, state);
/* sync buffers */
- for (plane = 0; plane < vb->vb2.num_planes; ++plane)
- call_void_memop(vb, finish, vb->vb2.planes[plane].mem_priv);
+ for (plane = 0; plane < vb->num_planes; ++plane)
+ call_void_memop(vb, finish, vb->planes[plane].mem_priv);
/* Add the buffer to the done buffers list */
spin_lock_irqsave(&q->done_lock, flags);
- vb->vb2.state = state;
+ vb->state = state;
if (state != VB2_BUF_STATE_QUEUED)
- list_add_tail(&vb->vb2.done_entry, &q->done_list);
+ list_add_tail(&vb->done_entry, &q->done_list);
atomic_dec(&q->owned_by_drv_count);
spin_unlock_irqrestore(&q->done_lock, flags);
@@ -1245,14 +1272,15 @@ EXPORT_SYMBOL_GPL(vb2_discard_done);
* v4l2_buffer by the userspace. The caller has already verified that struct
* v4l2_buffer has a valid number of planes.
*/
-static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b,
+static void __fill_vb2_buffer(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b,
struct v4l2_plane *v4l2_planes)
{
+ struct vb2_buffer *vb = &cb->vb2;
unsigned int plane;
if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
if (b->memory == V4L2_MEMORY_USERPTR) {
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
v4l2_planes[plane].m.userptr =
b->m.planes[plane].m.userptr;
v4l2_planes[plane].length =
@@ -1260,7 +1288,7 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
}
}
if (b->memory == V4L2_MEMORY_DMABUF) {
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
v4l2_planes[plane].m.fd =
b->m.planes[plane].m.fd;
v4l2_planes[plane].length =
@@ -1280,7 +1308,7 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
* it's a safe assumption that they really meant to
* use the full plane sizes.
*/
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
struct v4l2_plane *pdst = &v4l2_planes[plane];
struct v4l2_plane *psrc = &b->m.planes[plane];
@@ -1318,15 +1346,15 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
}
/* Zero flags that the vb2 core handles */
- vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
- if ((vb->vb2.vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
+ cb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
+ if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
/*
* Non-COPY timestamps and non-OUTPUT queues will get
* their timestamp and timestamp source flags from the
* queue.
*/
- vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+ cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
}
if (V4L2_TYPE_IS_OUTPUT(b->type)) {
@@ -1336,46 +1364,48 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
* The 'field' is valid metadata for this output buffer
* and so that needs to be copied here.
*/
- vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
- vb->v4l2_buf.field = b->field;
+ cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
+ cb->v4l2_buf.field = b->field;
} else {
/* Zero any output buffer flags as this is a capture buffer */
- vb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
+ cb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
}
}
/**
* __qbuf_mmap() - handle qbuf of an MMAP buffer
*/
-static int __qbuf_mmap(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_mmap(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
{
- __fill_vb2_buffer(vb, b, vb->v4l2_planes);
+ struct vb2_buffer *vb = &cb->vb2;
+ __fill_vb2_buffer(cb, b, cb->v4l2_planes);
return call_vb_qop(vb, buf_prepare, vb);
}
/**
* __qbuf_userptr() - handle qbuf of a USERPTR buffer
*/
-static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_userptr(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
{
+ struct vb2_buffer *vb = &cb->vb2;
struct v4l2_plane planes[VIDEO_MAX_PLANES];
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_queue *q = vb->vb2_queue;
void *mem_priv;
unsigned int plane;
int ret;
enum dma_data_direction dma_dir =
V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
- bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
+ bool reacquired = vb->planes[0].mem_priv == NULL;
- memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
+ memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
/* Copy relevant information provided by the userspace */
- __fill_vb2_buffer(vb, b, planes);
+ __fill_vb2_buffer(cb, b, planes);
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
/* Skip the plane if already verified */
- if (vb->v4l2_planes[plane].m.userptr &&
- vb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
- && vb->v4l2_planes[plane].length == planes[plane].length)
+ if (cb->v4l2_planes[plane].m.userptr &&
+ cb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
+ && cb->v4l2_planes[plane].length == planes[plane].length)
continue;
dprintk(3, "userspace address for plane %d changed, "
@@ -1392,16 +1422,16 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
}
/* Release previously acquired memory if present */
- if (vb->vb2.planes[plane].mem_priv) {
+ if (vb->planes[plane].mem_priv) {
if (!reacquired) {
reacquired = true;
call_void_vb_qop(vb, buf_cleanup, vb);
}
- call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
+ call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
}
- vb->vb2.planes[plane].mem_priv = NULL;
- memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
+ vb->planes[plane].mem_priv = NULL;
+ memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
/* Acquire each plane's memory */
mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
@@ -1413,15 +1443,15 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
goto err;
}
- vb->vb2.planes[plane].mem_priv = mem_priv;
+ vb->planes[plane].mem_priv = mem_priv;
}
/*
* Now that everything is in order, copy relevant information
* provided by userspace.
*/
- for (plane = 0; plane < vb->vb2.num_planes; ++plane)
- vb->v4l2_planes[plane] = planes[plane];
+ for (plane = 0; plane < vb->num_planes; ++plane)
+ cb->v4l2_planes[plane] = planes[plane];
if (reacquired) {
/*
@@ -1446,12 +1476,12 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
return 0;
err:
/* In case of errors, release planes that were already acquired */
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- if (vb->vb2.planes[plane].mem_priv)
- call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
- vb->vb2.planes[plane].mem_priv = NULL;
- vb->v4l2_planes[plane].m.userptr = 0;
- vb->v4l2_planes[plane].length = 0;
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ if (vb->planes[plane].mem_priv)
+ call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+ vb->planes[plane].mem_priv = NULL;
+ cb->v4l2_planes[plane].m.userptr = 0;
+ cb->v4l2_planes[plane].length = 0;
}
return ret;
@@ -1460,22 +1490,23 @@ err:
/**
* __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
*/
-static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_dmabuf(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
{
+ struct vb2_buffer *vb = &cb->vb2;
struct v4l2_plane planes[VIDEO_MAX_PLANES];
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_queue *q = vb->vb2_queue;
void *mem_priv;
unsigned int plane;
int ret;
enum dma_data_direction dma_dir =
V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
- bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
+ bool reacquired = vb->planes[0].mem_priv == NULL;
- memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
+ memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
/* Copy relevant information provided by the userspace */
- __fill_vb2_buffer(vb, b, planes);
+ __fill_vb2_buffer(cb, b, planes);
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
if (IS_ERR_OR_NULL(dbuf)) {
@@ -1497,8 +1528,8 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
}
/* Skip the plane if already verified */
- if (dbuf == vb->vb2.planes[plane].dbuf &&
- vb->v4l2_planes[plane].length == planes[plane].length) {
+ if (dbuf == vb->planes[plane].dbuf &&
+ cb->v4l2_planes[plane].length == planes[plane].length) {
dma_buf_put(dbuf);
continue;
}
@@ -1511,8 +1542,8 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
}
/* Release previously acquired memory if present */
- __vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
- memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
+ __vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
+ memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
/* Acquire each plane's memory */
mem_priv = call_ptr_memop(vb, attach_dmabuf, q->alloc_ctx[plane],
@@ -1524,30 +1555,30 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
goto err;
}
- vb->vb2.planes[plane].dbuf = dbuf;
- vb->vb2.planes[plane].mem_priv = mem_priv;
+ vb->planes[plane].dbuf = dbuf;
+ vb->planes[plane].mem_priv = mem_priv;
}
/* TODO: This pins the buffer(s) with dma_buf_map_attachment()).. but
* really we want to do this just before the DMA, not while queueing
* the buffer(s)..
*/
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- ret = call_memop(vb, map_dmabuf, vb->vb2.planes[plane].mem_priv);
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
if (ret) {
dprintk(1, "failed to map dmabuf for plane %d\n",
plane);
goto err;
}
- vb->vb2.planes[plane].dbuf_mapped = 1;
+ vb->planes[plane].dbuf_mapped = 1;
}
/*
* Now that everything is in order, copy relevant information
* provided by userspace.
*/
- for (plane = 0; plane < vb->vb2.num_planes; ++plane)
- vb->v4l2_planes[plane] = planes[plane];
+ for (plane = 0; plane < vb->num_planes; ++plane)
+ cb->v4l2_planes[plane] = planes[plane];
if (reacquired) {
/*
@@ -1571,7 +1602,7 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
return 0;
err:
/* In case of errors, release planes that were already acquired */
- __vb2_buf_dmabuf_put(vb);
+ __vb2_buf_dmabuf_put(cb);
return ret;
}
@@ -1581,7 +1612,6 @@ err:
*/
static void __enqueue_in_driver(struct vb2_buffer *vb)
{
- struct vb2_v4l2_buffer *pb = container_of(vb, struct vb2_v4l2_buffer, vb2);
struct vb2_queue *q = vb->vb2_queue;
unsigned int plane;
@@ -1590,17 +1620,18 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
/* sync buffers */
for (plane = 0; plane < vb->num_planes; ++plane)
- call_void_memop(pb, prepare, vb->planes[plane].mem_priv);
+ call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
- call_void_vb_qop(pb, buf_queue, pb);
+ call_void_vb_qop(vb, buf_queue, vb);
}
-static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
+static int __buf_prepare(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
{
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_buffer *vb = &cb->vb2;
+ struct vb2_queue *q = vb->vb2_queue;
int ret;
- ret = __verify_length(vb, b);
+ ret = __verify_length(cb, b);
if (ret < 0) {
dprintk(1, "plane parameters verification failed: %d\n", ret);
return ret;
@@ -1624,22 +1655,22 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
return -EIO;
}
- vb->vb2.state = VB2_BUF_STATE_PREPARING;
- vb->v4l2_buf.timestamp.tv_sec = 0;
- vb->v4l2_buf.timestamp.tv_usec = 0;
- vb->v4l2_buf.sequence = 0;
+ vb->state = VB2_BUF_STATE_PREPARING;
+ cb->v4l2_buf.timestamp.tv_sec = 0;
+ cb->v4l2_buf.timestamp.tv_usec = 0;
+ cb->v4l2_buf.sequence = 0;
switch (q->memory) {
case V4L2_MEMORY_MMAP:
- ret = __qbuf_mmap(vb, b);
+ ret = __qbuf_mmap(cb, b);
break;
case V4L2_MEMORY_USERPTR:
down_read(¤t->mm->mmap_sem);
- ret = __qbuf_userptr(vb, b);
+ ret = __qbuf_userptr(cb, b);
up_read(¤t->mm->mmap_sem);
break;
case V4L2_MEMORY_DMABUF:
- ret = __qbuf_dmabuf(vb, b);
+ ret = __qbuf_dmabuf(cb, b);
break;
default:
WARN(1, "Invalid queue type\n");
@@ -1648,7 +1679,7 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
if (ret)
dprintk(1, "buffer preparation failed: %d\n", ret);
- vb->vb2.state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
+ vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
return ret;
}
@@ -1656,6 +1687,8 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
const char *opname)
{
+ struct vb2_v4l2_buffer *cb;
+
if (b->type != q->type) {
dprintk(1, "%s: invalid buffer type\n", opname);
return -EINVAL;
@@ -1677,7 +1710,9 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
return -EINVAL;
}
- return __verify_planes_array(q->bufs[b->index], b);
+ cb = container_of(q->bufs[b->index], struct vb2_v4l2_buffer, vb2);
+
+ return __verify_planes_array(cb, b);
}
/**
@@ -1697,7 +1732,8 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
*/
int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
{
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
int ret;
if (vb2_fileio_is_active(q)) {
@@ -1710,18 +1746,19 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
return ret;
vb = q->bufs[b->index];
- if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ if (vb->state != VB2_BUF_STATE_DEQUEUED) {
dprintk(1, "invalid buffer state %d\n",
- vb->vb2.state);
+ vb->state);
return -EINVAL;
}
- ret = __buf_prepare(vb, b);
+ ret = __buf_prepare(cb, b);
if (!ret) {
/* Fill buffer information for the userspace */
- __fill_v4l2_buffer(vb, b);
+ __fill_v4l2_buffer(cb, b);
- dprintk(1, "prepare of buffer %d succeeded\n", vb->v4l2_buf.index);
+ dprintk(1, "prepare of buffer %d succeeded\n", cb->v4l2_buf.index);
}
return ret;
}
@@ -1741,7 +1778,7 @@ EXPORT_SYMBOL_GPL(vb2_prepare_buf);
static int vb2_start_streaming(struct vb2_queue *q)
{
struct vb2_buffer *vb;
- struct vb2_v4l2_buffer *pb;
+ struct vb2_v4l2_buffer *cb;
int ret;
/*
@@ -1775,9 +1812,10 @@ static int vb2_start_streaming(struct vb2_queue *q)
* correctly return them to vb2.
*/
for (i = 0; i < q->num_buffers; ++i) {
- pb = q->bufs[i];
- if (pb->vb2.state == VB2_BUF_STATE_ACTIVE)
- vb2_buffer_done(pb, VB2_BUF_STATE_QUEUED);
+ vb = q->bufs[i];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ if (vb->state == VB2_BUF_STATE_ACTIVE)
+ vb2_buffer_done(cb, VB2_BUF_STATE_QUEUED);
}
/* Must be zero now */
WARN_ON(atomic_read(&q->owned_by_drv_count));
@@ -1794,16 +1832,18 @@ static int vb2_start_streaming(struct vb2_queue *q)
static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
{
int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
if (ret)
return ret;
vb = q->bufs[b->index];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
- switch (vb->vb2.state) {
+ switch (vb->state) {
case VB2_BUF_STATE_DEQUEUED:
- ret = __buf_prepare(vb, b);
+ ret = __buf_prepare(cb, b);
if (ret)
return ret;
break;
@@ -1813,7 +1853,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
dprintk(1, "buffer still being prepared\n");
return -EINVAL;
default:
- dprintk(1, "invalid buffer state %d\n", vb->vb2.state);
+ dprintk(1, "invalid buffer state %d\n", vb->state);
return -EINVAL;
}
@@ -1821,10 +1861,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
* Add to the queued buffers list, a buffer will stay on it until
* dequeued in dqbuf.
*/
- list_add_tail(&vb->vb2.queued_entry, &q->queued_list);
+ list_add_tail(&vb->queued_entry, &q->queued_list);
q->queued_count++;
q->waiting_for_buffers = false;
- vb->vb2.state = VB2_BUF_STATE_QUEUED;
+ vb->state = VB2_BUF_STATE_QUEUED;
if (V4L2_TYPE_IS_OUTPUT(q->type)) {
/*
* For output buffers copy the timestamp if needed,
@@ -1832,10 +1872,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
*/
if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
V4L2_BUF_FLAG_TIMESTAMP_COPY)
- vb->v4l2_buf.timestamp = b->timestamp;
- vb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
+ cb->v4l2_buf.timestamp = b->timestamp;
+ cb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
if (b->flags & V4L2_BUF_FLAG_TIMECODE)
- vb->v4l2_buf.timecode = b->timecode;
+ cb->v4l2_buf.timecode = b->timecode;
}
/*
@@ -1843,10 +1883,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
* If not, the buffer will be given to driver on next streamon.
*/
if (q->start_streaming_called)
- __enqueue_in_driver(&vb->vb2);
+ __enqueue_in_driver(vb);
/* Fill buffer information for the userspace */
- __fill_v4l2_buffer(vb, b);
+ __fill_v4l2_buffer(cb, b);
/*
* If streamon has been called, and we haven't yet called
@@ -1861,7 +1901,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
return ret;
}
- dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index);
+ dprintk(1, "qbuf of buffer %d succeeded\n", cb->v4l2_buf.index);
return 0;
}
@@ -1969,12 +2009,12 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
*
* Will sleep if required for nonblocking == false.
*/
-static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
+static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **cb,
struct v4l2_buffer *b, int nonblocking)
{
unsigned long flags;
int ret;
- struct vb2_buffer *vb2 = NULL;
+ struct vb2_buffer *vb = NULL;
/*
* Wait for at least one buffer to become available on the done_list.
@@ -1988,15 +2028,15 @@ static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
* is not empty, so no need for another list_empty(done_list) check.
*/
spin_lock_irqsave(&q->done_lock, flags);
- vb2 = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
- *vb = container_of(vb2, struct vb2_v4l2_buffer, vb2);
+ vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
+ *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
/*
* Only remove the buffer from done_list if v4l2_buffer can handle all
* the planes.
*/
- ret = __verify_planes_array(*vb, b);
+ ret = __verify_planes_array(*cb, b);
if (!ret)
- list_del(&(*vb)->vb2.done_entry);
+ list_del(&vb->done_entry);
spin_unlock_irqrestore(&q->done_lock, flags);
return ret;
@@ -2027,41 +2067,45 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
/**
* __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
*/
-static void __vb2_dqbuf(struct vb2_v4l2_buffer *vb)
+static void __vb2_dqbuf(struct vb2_v4l2_buffer *cb)
{
- struct vb2_queue *q = vb->vb2.vb2_queue;
+ struct vb2_buffer *vb = &cb->vb2;
+ struct vb2_queue *q = vb->vb2_queue;
unsigned int i;
/* nothing to do if the buffer is already dequeued */
- if (vb->vb2.state == VB2_BUF_STATE_DEQUEUED)
+ if (vb->state == VB2_BUF_STATE_DEQUEUED)
return;
- vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
+ vb->state = VB2_BUF_STATE_DEQUEUED;
/* unmap DMABUF buffer */
if (q->memory == V4L2_MEMORY_DMABUF)
- for (i = 0; i < vb->vb2.num_planes; ++i) {
- if (!vb->vb2.planes[i].dbuf_mapped)
+ for (i = 0; i < vb->num_planes; ++i) {
+ if (!vb->planes[i].dbuf_mapped)
continue;
- call_void_memop(vb, unmap_dmabuf, vb->vb2.planes[i].mem_priv);
- vb->vb2.planes[i].dbuf_mapped = 0;
+ call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
+ vb->planes[i].dbuf_mapped = 0;
}
}
static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
{
- struct vb2_v4l2_buffer *vb = NULL;
+ struct vb2_v4l2_buffer *cb = NULL;
+ struct vb2_buffer *vb = NULL;
int ret;
if (b->type != q->type) {
dprintk(1, "invalid buffer type\n");
return -EINVAL;
}
- ret = __vb2_get_done_vb(q, &vb, b, nonblocking);
+ ret = __vb2_get_done_vb(q, &cb, b, nonblocking);
if (ret < 0)
return ret;
- switch (vb->vb2.state) {
+ vb = &cb->vb2;
+
+ switch (vb->state) {
case VB2_BUF_STATE_DONE:
dprintk(3, "returning done buffer\n");
break;
@@ -2076,15 +2120,15 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
call_void_vb_qop(vb, buf_finish, vb);
/* Fill buffer information for the userspace */
- __fill_v4l2_buffer(vb, b);
+ __fill_v4l2_buffer(cb, b);
/* Remove from videobuf queue */
- list_del(&vb->vb2.queued_entry);
+ list_del(&vb->queued_entry);
q->queued_count--;
/* go back to dequeued state */
- __vb2_dqbuf(vb);
+ __vb2_dqbuf(cb);
dprintk(1, "dqbuf of buffer %d, with state %d\n",
- vb->v4l2_buf.index, vb->vb2.state);
+ cb->v4l2_buf.index, vb->state);
return 0;
}
@@ -2128,8 +2172,9 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
*/
static void __vb2_queue_cancel(struct vb2_queue *q)
{
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
unsigned int i;
- struct vb2_v4l2_buffer *vb;
/*
* Tell driver to stop all transactions and release all queued
@@ -2147,9 +2192,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
for (i = 0; i < q->num_buffers; ++i)
{
- vb = (struct vb2_v4l2_buffer *)q->bufs[i];
- if (vb->vb2.state == VB2_BUF_STATE_ACTIVE)
- vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+ vb = q->bufs[i];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+ if (vb->state == VB2_BUF_STATE_ACTIVE)
+ vb2_buffer_done(cb, VB2_BUF_STATE_ERROR);
}
/* Must be zero now */
WARN_ON(atomic_read(&q->owned_by_drv_count));
@@ -2182,13 +2228,14 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
* be changed, so we can't move the buf_finish() to __vb2_dqbuf().
*/
for (i = 0; i < q->num_buffers; ++i) {
- struct vb2_v4l2_buffer *vb = q->bufs[i];
+ struct vb2_buffer *vb = q->bufs[i];
+ struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
- if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
- vb->vb2.state = VB2_BUF_STATE_PREPARED;
+ if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+ vb->state = VB2_BUF_STATE_PREPARED;
call_void_vb_qop(vb, buf_finish, vb);
}
- __vb2_dqbuf(vb);
+ __vb2_dqbuf(cb);
}
}
@@ -2333,7 +2380,8 @@ EXPORT_SYMBOL_GPL(vb2_streamoff);
static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
unsigned int *_buffer, unsigned int *_plane)
{
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
unsigned int buffer, plane;
/*
@@ -2343,9 +2391,10 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
*/
for (buffer = 0; buffer < q->num_buffers; ++buffer) {
vb = q->bufs[buffer];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
- for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
- if (vb->v4l2_planes[plane].m.mem_offset == off) {
+ for (plane = 0; plane < vb->num_planes; ++plane) {
+ if (cb->v4l2_planes[plane].m.mem_offset == off) {
*_buffer = buffer;
*_plane = plane;
return 0;
@@ -2367,7 +2416,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
*/
int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
{
- struct vb2_v4l2_buffer *vb = NULL;
+ struct vb2_buffer *vb = NULL;
struct vb2_plane *vb_plane;
int ret;
struct dma_buf *dbuf;
@@ -2399,7 +2448,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
vb = q->bufs[eb->index];
- if (eb->plane >= vb->vb2.num_planes) {
+ if (eb->plane >= vb->num_planes) {
dprintk(1, "buffer plane out of range\n");
return -EINVAL;
}
@@ -2409,7 +2458,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
return -EBUSY;
}
- vb_plane = &vb->vb2.planes[eb->plane];
+ vb_plane = &vb->planes[eb->plane];
dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
if (IS_ERR_OR_NULL(dbuf)) {
@@ -2456,7 +2505,8 @@ EXPORT_SYMBOL_GPL(vb2_expbuf);
int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
{
unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
unsigned int buffer = 0, plane = 0;
int ret;
unsigned long length;
@@ -2497,13 +2547,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
return ret;
vb = q->bufs[buffer];
-
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
/*
* MMAP requires page_aligned buffers.
* The buffer length was page_aligned at __vb2_buf_mem_alloc(),
* so, we need to do the same here.
*/
- length = PAGE_ALIGN(vb->v4l2_planes[plane].length);
+ length = PAGE_ALIGN(cb->v4l2_planes[plane].length);
if (length < (vma->vm_end - vma->vm_start)) {
dprintk(1,
"MMAP invalid, as it would overflow buffer length\n");
@@ -2511,7 +2561,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
}
mutex_lock(&q->mmap_lock);
- ret = call_memop(vb, mmap, vb->vb2.planes[plane].mem_priv, vma);
+ ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
mutex_unlock(&q->mmap_lock);
if (ret)
return ret;
@@ -2528,8 +2578,9 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
unsigned long pgoff,
unsigned long flags)
{
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
unsigned long off = pgoff << PAGE_SHIFT;
- struct vb2_v4l2_buffer *vb;
unsigned int buffer, plane;
void *vaddr;
int ret;
@@ -2547,8 +2598,9 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
return ret;
vb = q->bufs[buffer];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
- vaddr = vb2_plane_vaddr(vb, plane);
+ vaddr = vb2_plane_vaddr(cb, plane);
return vaddr ? (unsigned long)vaddr : -EINVAL;
}
EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
@@ -2784,7 +2836,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
struct vb2_fileio_data *fileio;
int i, ret;
unsigned int count = 0;
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
/*
* Sanity check
@@ -2835,8 +2888,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
* Check if plane_count is correct
* (multiplane buffers are not supported).
*/
- vb = (struct vb2_v4l2_buffer *)q->bufs[0];
- if (vb->vb2.num_planes != 1) {
+ vb = q->bufs[0];
+ if (vb->num_planes != 1) {
ret = -EBUSY;
goto err_reqbufs;
}
@@ -2845,12 +2898,13 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
* Get kernel address of each buffer.
*/
for (i = 0; i < q->num_buffers; i++) {
- fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
+ cb = container_of(q->bufs[i], struct vb2_v4l2_buffer, vb2);
+ fileio->bufs[i].vaddr = vb2_plane_vaddr(cb, 0);
if (fileio->bufs[i].vaddr == NULL) {
ret = -EINVAL;
goto err_reqbufs;
}
- fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
+ fileio->bufs[i].size = vb2_plane_size(cb, 0);
}
/*
@@ -2937,6 +2991,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
loff_t *ppos, int nonblock, int read)
{
+ struct vb2_v4l2_buffer *cb;
struct vb2_fileio_data *fileio;
struct vb2_fileio_buf *buf;
bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
@@ -2996,10 +3051,11 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
/*
* Get number of bytes filled by the driver
*/
+ cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
buf->pos = 0;
buf->queued = 0;
- buf->size = read ? vb2_get_plane_payload(q->bufs[index], 0)
- : vb2_plane_size(q->bufs[index], 0);
+ buf->size = read ? vb2_get_plane_payload(cb, 0)
+ : vb2_plane_size(cb, 0);
/* Compensate for data_offset on read in the multiplanar case. */
if (is_multiplanar && read &&
fileio->b.m.planes[0].data_offset < buf->size) {
@@ -3076,9 +3132,10 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
/*
* Buffer has been queued, update the status
*/
+ cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
buf->pos = 0;
buf->queued = 1;
- buf->size = vb2_plane_size(q->bufs[index], 0);
+ buf->size = vb2_plane_size(cb, 0);
fileio->q_count += 1;
/*
* If we are queuing up buffers for the first time, then
@@ -3146,7 +3203,8 @@ static int vb2_thread(void *data)
set_freezable();
for (;;) {
- struct vb2_v4l2_buffer *vb;
+ struct vb2_v4l2_buffer *cb;
+ struct vb2_buffer *vb;
/*
* Call vb2_dqbuf to get buffer back.
@@ -3169,8 +3227,9 @@ static int vb2_thread(void *data)
try_to_freeze();
vb = q->bufs[fileio->b.index];
+ cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR))
- if (threadio->fnc(vb, threadio->priv))
+ if (threadio->fnc(cb, threadio->priv))
break;
call_void_qop(q, wait_finish, q);
if (set_timestamp)
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 3b5df66..24c229d 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -227,27 +227,6 @@ struct vb2_buffer {
};
/**
- * struct vb2_v4l2_buffer - represents a video buffer for v4l2
- * @vb2_buf: common video buffer
- * @v4l2_buf: struct v4l2_buffer associated with this buffer; can
- * be read by the driver and relevant entries can be
- * changed by the driver in case of CAPTURE types
- * (such as timestamp)
- * @v4l2_planes: struct v4l2_planes associated with this buffer; can
- * be read by the driver and relevant entries can be
- * changed by the driver in case of CAPTURE types
- * (such as bytesused); NOTE that even for single-planar
- * types, the v4l2_planes[0] struct should be used
- * instead of v4l2_buf for filling bytesused - drivers
- * should use the vb2_set_plane_payload() function for that
- */
-struct vb2_v4l2_buffer {
- struct vb2_buffer vb2;
- struct v4l2_buffer v4l2_buf;
- struct v4l2_plane v4l2_planes[VIDEO_MAX_PLANES];
-};
-
-/**
* struct vb2_ops - driver-specific callbacks
*
* @queue_setup: called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
@@ -327,26 +306,24 @@ struct vb2_v4l2_buffer {
* pre-queued buffers before calling STREAMON.
*/
struct vb2_ops {
- int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
+ int (*queue_setup)(struct vb2_queue *q, void *fmt,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[]);