Re: [PATCHv17 24/34] videobuf2-v4l2: integrate with media requests
Em Sat, 4 Aug 2018 14:45:16 +0200 Hans Verkuil escreveu: > From: Hans Verkuil > > This implements the V4L2 part of the request support. The main > change is that vb2_qbuf and vb2_prepare_buf now have a new > media_device pointer. This required changes to several drivers > that did not use the vb2_ioctl_qbuf/prepare_buf helper functions. > > Signed-off-by: Hans Verkuil Reviewed-by: Mauro Carvalho Chehab > --- > .../media/common/videobuf2/videobuf2-core.c | 13 +- > .../media/common/videobuf2/videobuf2-v4l2.c | 112 -- > drivers/media/platform/omap3isp/ispvideo.c| 2 +- > .../media/platform/s3c-camif/camif-capture.c | 4 +- > drivers/media/platform/s5p-mfc/s5p_mfc_dec.c | 4 +- > drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 4 +- > .../media/platform/soc_camera/soc_camera.c| 4 +- > drivers/media/usb/uvc/uvc_queue.c | 5 +- > drivers/media/usb/uvc/uvc_v4l2.c | 3 +- > drivers/media/usb/uvc/uvcvideo.h | 1 + > drivers/media/v4l2-core/v4l2-mem2mem.c| 6 +- > .../staging/media/davinci_vpfe/vpfe_video.c | 3 +- > drivers/staging/media/omap4iss/iss_video.c| 3 +- > drivers/usb/gadget/function/uvc_queue.c | 2 +- > include/media/videobuf2-v4l2.h| 14 ++- > 15 files changed, 148 insertions(+), 32 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c > b/drivers/media/common/videobuf2/videobuf2-core.c > index 1efb9c8b359d..3e6db7d30989 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -1338,6 +1338,14 @@ static void vb2_req_queue(struct media_request_object > *obj) > mutex_unlock(vb->vb2_queue->lock); > } > > +static void vb2_req_unbind(struct media_request_object *obj) > +{ > + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); > + > + if (vb->state == VB2_BUF_STATE_IN_REQUEST) > + call_void_bufop(vb->vb2_queue, init_buffer, vb); > +} > + > static void vb2_req_release(struct media_request_object *obj) > { > struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); > @@ -1350,6 +1358,7 @@ static const struct media_request_object_ops > vb2_core_req_ops = { > .prepare = vb2_req_prepare, > .unprepare = vb2_req_unprepare, > .queue = vb2_req_queue, > + .unbind = vb2_req_unbind, > .release = vb2_req_release, > }; > > @@ -1481,8 +1490,10 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int > index, void *pb, > > vb->state = VB2_BUF_STATE_IN_REQUEST; > /* Fill buffer information for the userspace */ > - if (pb) > + if (pb) { > + call_void_bufop(q, copy_timestamp, vb, pb); > call_void_bufop(q, fill_user_buffer, vb, pb); > + } > > dprintk(2, "qbuf of buffer %d succeeded\n", vb->index); > return 0; > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c > b/drivers/media/common/videobuf2/videobuf2-v4l2.c > index ea9db4b3f59a..9c652afa62ab 100644 > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > @@ -25,6 +25,7 @@ > #include > > #include > +#include > #include > #include > #include > @@ -40,10 +41,12 @@ module_param(debug, int, 0644); > pr_info("vb2-v4l2: %s: " fmt, __func__, ## arg); \ > } while (0) > > -/* Flags that are set by the vb2 core */ > +/* Flags that are set by us */ > #define V4L2_BUFFER_MASK_FLAGS (V4L2_BUF_FLAG_MAPPED | > V4L2_BUF_FLAG_QUEUED | \ >V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \ >V4L2_BUF_FLAG_PREPARED | \ > + V4L2_BUF_FLAG_IN_REQUEST | \ > + V4L2_BUF_FLAG_REQUEST_FD | \ >V4L2_BUF_FLAG_TIMESTAMP_MASK) > /* Output buffer flags that should be passed on to the driver */ > #define V4L2_BUFFER_OUT_FLAGS(V4L2_BUF_FLAG_PFRAME | > V4L2_BUF_FLAG_BFRAME | \ > @@ -118,6 +121,16 @@ static int __verify_length(struct vb2_buffer *vb, const > struct v4l2_buffer *b) > return 0; > } > > +/* > + * __init_v4l2_vb2_buffer() - initialize the v4l2_vb2_buffer struct > + */ > +static void __init_v4l2_vb2_buffer(struct vb2_buffer *vb) > +{ > + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); > + > + vbuf->request_fd = -1; > +} > + > static void __copy_timestamp(struct vb2_buffer *vb, const void *pb) > { > const struct v4l2_buffer *b = pb; > @@ -181,6 +194,7 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer > *vb, struct v4l2_buffer *b > return -EINVAL; > } > vbuf->sequence = 0; > + vbuf->request_fd = -1; > > if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { > switch (b->memory) { >
[PATCHv17 24/34] videobuf2-v4l2: integrate with media requests
From: Hans Verkuil This implements the V4L2 part of the request support. The main change is that vb2_qbuf and vb2_prepare_buf now have a new media_device pointer. This required changes to several drivers that did not use the vb2_ioctl_qbuf/prepare_buf helper functions. Signed-off-by: Hans Verkuil --- .../media/common/videobuf2/videobuf2-core.c | 13 +- .../media/common/videobuf2/videobuf2-v4l2.c | 112 -- drivers/media/platform/omap3isp/ispvideo.c| 2 +- .../media/platform/s3c-camif/camif-capture.c | 4 +- drivers/media/platform/s5p-mfc/s5p_mfc_dec.c | 4 +- drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 4 +- .../media/platform/soc_camera/soc_camera.c| 4 +- drivers/media/usb/uvc/uvc_queue.c | 5 +- drivers/media/usb/uvc/uvc_v4l2.c | 3 +- drivers/media/usb/uvc/uvcvideo.h | 1 + drivers/media/v4l2-core/v4l2-mem2mem.c| 6 +- .../staging/media/davinci_vpfe/vpfe_video.c | 3 +- drivers/staging/media/omap4iss/iss_video.c| 3 +- drivers/usb/gadget/function/uvc_queue.c | 2 +- include/media/videobuf2-v4l2.h| 14 ++- 15 files changed, 148 insertions(+), 32 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 1efb9c8b359d..3e6db7d30989 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1338,6 +1338,14 @@ static void vb2_req_queue(struct media_request_object *obj) mutex_unlock(vb->vb2_queue->lock); } +static void vb2_req_unbind(struct media_request_object *obj) +{ + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); + + if (vb->state == VB2_BUF_STATE_IN_REQUEST) + call_void_bufop(vb->vb2_queue, init_buffer, vb); +} + static void vb2_req_release(struct media_request_object *obj) { struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); @@ -1350,6 +1358,7 @@ static const struct media_request_object_ops vb2_core_req_ops = { .prepare = vb2_req_prepare, .unprepare = vb2_req_unprepare, .queue = vb2_req_queue, + .unbind = vb2_req_unbind, .release = vb2_req_release, }; @@ -1481,8 +1490,10 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, vb->state = VB2_BUF_STATE_IN_REQUEST; /* Fill buffer information for the userspace */ - if (pb) + if (pb) { + call_void_bufop(q, copy_timestamp, vb, pb); call_void_bufop(q, fill_user_buffer, vb, pb); + } dprintk(2, "qbuf of buffer %d succeeded\n", vb->index); return 0; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index ea9db4b3f59a..9c652afa62ab 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -40,10 +41,12 @@ module_param(debug, int, 0644); pr_info("vb2-v4l2: %s: " fmt, __func__, ## arg); \ } while (0) -/* Flags that are set by the vb2 core */ +/* Flags that are set by us */ #define V4L2_BUFFER_MASK_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \ V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \ V4L2_BUF_FLAG_PREPARED | \ +V4L2_BUF_FLAG_IN_REQUEST | \ +V4L2_BUF_FLAG_REQUEST_FD | \ V4L2_BUF_FLAG_TIMESTAMP_MASK) /* Output buffer flags that should be passed on to the driver */ #define V4L2_BUFFER_OUT_FLAGS (V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME | \ @@ -118,6 +121,16 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b) return 0; } +/* + * __init_v4l2_vb2_buffer() - initialize the v4l2_vb2_buffer struct + */ +static void __init_v4l2_vb2_buffer(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + + vbuf->request_fd = -1; +} + static void __copy_timestamp(struct vb2_buffer *vb, const void *pb) { const struct v4l2_buffer *b = pb; @@ -181,6 +194,7 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b return -EINVAL; } vbuf->sequence = 0; + vbuf->request_fd = -1; if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { switch (b->memory) { @@ -318,9 +332,12 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b return 0; } -static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, - const char *opname) +static int