Re: [PATCHv17 20/34] videodev2.h: Add request_fd field to v4l2_buffer

2018-08-13 Thread Mauro Carvalho Chehab
Em Sat,  4 Aug 2018 14:45:12 +0200
Hans Verkuil  escreveu:

> From: Hans Verkuil 
> 
> When queuing buffers allow for passing the request that should
> be associated with this buffer.
> 
> If V4L2_BUF_FLAG_REQUEST_FD is set, then request_fd is used as
> the file descriptor.
> 
> If a buffer is stored in a request, but not yet queued to the
> driver, then V4L2_BUF_FLAG_IN_REQUEST is set.
> 
> Signed-off-by: Hans Verkuil 
Reviewed-by: Mauro Carvalho Chehab 

> ---
>  drivers/media/common/videobuf2/videobuf2-v4l2.c |  2 +-
>  drivers/media/usb/cpia2/cpia2_v4l.c |  2 +-
>  drivers/media/v4l2-core/v4l2-compat-ioctl32.c   |  9 ++---
>  drivers/media/v4l2-core/v4l2-ioctl.c|  4 ++--
>  include/uapi/linux/videodev2.h  | 10 +-
>  5 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c 
> b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> index a677e2c26247..64905d87465c 100644
> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> @@ -384,7 +384,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, 
> void *pb)
>   b->timecode = vbuf->timecode;
>   b->sequence = vbuf->sequence;
>   b->reserved2 = 0;
> - b->reserved = 0;
> + b->request_fd = 0;
>  
>   if (q->is_multiplanar) {
>   /*
> diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c 
> b/drivers/media/usb/cpia2/cpia2_v4l.c
> index 99f106b13280..13aee9f67d05 100644
> --- a/drivers/media/usb/cpia2/cpia2_v4l.c
> +++ b/drivers/media/usb/cpia2/cpia2_v4l.c
> @@ -949,7 +949,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, 
> struct v4l2_buffer *buf)
>   buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
>   buf->length = cam->frame_size;
>   buf->reserved2 = 0;
> - buf->reserved = 0;
> + buf->request_fd = 0;
>   memset(>timecode, 0, sizeof(buf->timecode));
>  
>   DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
> diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
> b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
> index dcce86c1fe40..633465d21d04 100644
> --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
> +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
> @@ -482,7 +482,7 @@ struct v4l2_buffer32 {
>   } m;
>   __u32   length;
>   __u32   reserved2;
> - __u32   reserved;
> + __s32   request_fd;
>  };
>  
>  static int get_v4l2_plane32(struct v4l2_plane __user *p64,
> @@ -581,6 +581,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user 
> *p64,
>  {
>   u32 type;
>   u32 length;
> + s32 request_fd;
>   enum v4l2_memory memory;
>   struct v4l2_plane32 __user *uplane32;
>   struct v4l2_plane __user *uplane;
> @@ -595,7 +596,9 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user 
> *p64,
>   get_user(memory, >memory) ||
>   put_user(memory, >memory) ||
>   get_user(length, >length) ||
> - put_user(length, >length))
> + put_user(length, >length) ||
> + get_user(request_fd, >request_fd) ||
> + put_user(request_fd, >request_fd))
>   return -EFAULT;
>  
>   if (V4L2_TYPE_IS_OUTPUT(type))
> @@ -699,7 +702,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer __user 
> *p64,
>   copy_in_user(>timecode, >timecode, sizeof(p64->timecode)) 
> ||
>   assign_in_user(>sequence, >sequence) ||
>   assign_in_user(>reserved2, >reserved2) ||
> - assign_in_user(>reserved, >reserved) ||
> + assign_in_user(>request_fd, >request_fd) ||
>   get_user(length, >length) ||
>   put_user(length, >length))
>   return -EFAULT;
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
> b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 20b5145a5254..2a84ca9e328a 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -474,13 +474,13 @@ static void v4l_print_buffer(const void *arg, bool 
> write_only)
>   const struct v4l2_plane *plane;
>   int i;
>  
> - pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, flags=0x%08x, 
> field=%s, sequence=%d, memory=%s",
> + pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, request_fd=%d, 
> flags=0x%08x, field=%s, sequence=%d, memory=%s",
>   p->timestamp.tv_sec / 3600,
>   (int)(p->timestamp.tv_sec / 60) % 60,
>   (int)(p->timestamp.tv_sec % 60),
>   (long)p->timestamp.tv_usec,
>   p->index,
> - prt_names(p->type, v4l2_type_names),
> + prt_names(p->type, v4l2_type_names), p->request_fd,
>   p->flags, prt_names(p->field, v4l2_field_names),
>   p->sequence, prt_names(p->memory, v4l2_memory_names));
>  
> diff 

[PATCHv17 20/34] videodev2.h: Add request_fd field to v4l2_buffer

2018-08-04 Thread Hans Verkuil
From: Hans Verkuil 

When queuing buffers allow for passing the request that should
be associated with this buffer.

If V4L2_BUF_FLAG_REQUEST_FD is set, then request_fd is used as
the file descriptor.

If a buffer is stored in a request, but not yet queued to the
driver, then V4L2_BUF_FLAG_IN_REQUEST is set.

Signed-off-by: Hans Verkuil 
---
 drivers/media/common/videobuf2/videobuf2-v4l2.c |  2 +-
 drivers/media/usb/cpia2/cpia2_v4l.c |  2 +-
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c   |  9 ++---
 drivers/media/v4l2-core/v4l2-ioctl.c|  4 ++--
 include/uapi/linux/videodev2.h  | 10 +-
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c 
b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index a677e2c26247..64905d87465c 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -384,7 +384,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void 
*pb)
b->timecode = vbuf->timecode;
b->sequence = vbuf->sequence;
b->reserved2 = 0;
-   b->reserved = 0;
+   b->request_fd = 0;
 
if (q->is_multiplanar) {
/*
diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c 
b/drivers/media/usb/cpia2/cpia2_v4l.c
index 99f106b13280..13aee9f67d05 100644
--- a/drivers/media/usb/cpia2/cpia2_v4l.c
+++ b/drivers/media/usb/cpia2/cpia2_v4l.c
@@ -949,7 +949,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct 
v4l2_buffer *buf)
buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
buf->length = cam->frame_size;
buf->reserved2 = 0;
-   buf->reserved = 0;
+   buf->request_fd = 0;
memset(>timecode, 0, sizeof(buf->timecode));
 
DBG("DQBUF #%d status:%d seq:%d length:%d\n", buf->index,
diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index dcce86c1fe40..633465d21d04 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -482,7 +482,7 @@ struct v4l2_buffer32 {
} m;
__u32   length;
__u32   reserved2;
-   __u32   reserved;
+   __s32   request_fd;
 };
 
 static int get_v4l2_plane32(struct v4l2_plane __user *p64,
@@ -581,6 +581,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *p64,
 {
u32 type;
u32 length;
+   s32 request_fd;
enum v4l2_memory memory;
struct v4l2_plane32 __user *uplane32;
struct v4l2_plane __user *uplane;
@@ -595,7 +596,9 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *p64,
get_user(memory, >memory) ||
put_user(memory, >memory) ||
get_user(length, >length) ||
-   put_user(length, >length))
+   put_user(length, >length) ||
+   get_user(request_fd, >request_fd) ||
+   put_user(request_fd, >request_fd))
return -EFAULT;
 
if (V4L2_TYPE_IS_OUTPUT(type))
@@ -699,7 +702,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer __user *p64,
copy_in_user(>timecode, >timecode, sizeof(p64->timecode)) 
||
assign_in_user(>sequence, >sequence) ||
assign_in_user(>reserved2, >reserved2) ||
-   assign_in_user(>reserved, >reserved) ||
+   assign_in_user(>request_fd, >request_fd) ||
get_user(length, >length) ||
put_user(length, >length))
return -EFAULT;
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 20b5145a5254..2a84ca9e328a 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -474,13 +474,13 @@ static void v4l_print_buffer(const void *arg, bool 
write_only)
const struct v4l2_plane *plane;
int i;
 
-   pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, flags=0x%08x, 
field=%s, sequence=%d, memory=%s",
+   pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, request_fd=%d, 
flags=0x%08x, field=%s, sequence=%d, memory=%s",
p->timestamp.tv_sec / 3600,
(int)(p->timestamp.tv_sec / 60) % 60,
(int)(p->timestamp.tv_sec % 60),
(long)p->timestamp.tv_usec,
p->index,
-   prt_names(p->type, v4l2_type_names),
+   prt_names(p->type, v4l2_type_names), p->request_fd,
p->flags, prt_names(p->field, v4l2_field_names),
p->sequence, prt_names(p->memory, v4l2_memory_names));
 
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 1df0fa983db6..91126b7312f8 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -917,6 +917,7 @@ struct v4l2_plane {
  *