From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [PATCHv18 15/35] v4l2-ctrls: support g/s_ext_ctrls for requests
Date: Tue, 14 Aug 2018 16:33:44 -0300 [thread overview]
Message-ID: <20180814163344.2b59d941@coco.lan> (raw)
In-Reply-To: <20180814142047.93856-16-hverkuil@xs4all.nl>
Em Tue, 14 Aug 2018 16:20:27 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> From: Hans Verkuil <hans.verkuil@cisco.com>
>
> The v4l2_g/s_ext_ctrls functions now support control handlers that
> represent requests.
>
> The v4l2_ctrls_find_req_obj() function is responsible for finding the
> request from the fd.
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> ---
> drivers/media/platform/omap3isp/ispvideo.c | 2 +-
> drivers/media/v4l2-core/v4l2-ctrls.c | 138 +++++++++++++++++++--
> drivers/media/v4l2-core/v4l2-ioctl.c | 12 +-
> drivers/media/v4l2-core/v4l2-subdev.c | 9 +-
> include/media/v4l2-ctrls.h | 7 +-
> 5 files changed, 149 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 9d228eac24ea..674e7fd3ad99 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -1028,7 +1028,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
> ctrls.count = 1;
> ctrls.controls = &ctrl;
>
> - ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, &ctrls);
> + ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, NULL, &ctrls);
> if (ret < 0) {
> dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
> pipe->external->name);
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 89e7bfee108f..6d34d7a6f235 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -3140,7 +3140,8 @@ static int class_check(struct v4l2_ctrl_handler *hdl, u32 which)
> }
>
> /* Get extended controls. Allocates the helpers array if needed. */
> -int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
> +static int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl,
> + struct v4l2_ext_controls *cs)
> {
> struct v4l2_ctrl_helper helper[4];
> struct v4l2_ctrl_helper *helpers = helper;
> @@ -3220,6 +3221,83 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
> kvfree(helpers);
> return ret;
> }
> +
> +static struct media_request_object *
> +v4l2_ctrls_find_req_obj(struct v4l2_ctrl_handler *hdl,
> + struct media_request *req, bool set)
> +{
> + struct media_request_object *obj;
> + struct v4l2_ctrl_handler *new_hdl;
> + int ret;
> +
> + if (IS_ERR(req))
> + return ERR_CAST(req);
> +
> + if (set && WARN_ON(req->state != MEDIA_REQUEST_STATE_UPDATING))
> + return ERR_PTR(-EBUSY);
> +
> + obj = media_request_object_find(req, &req_ops, hdl);
> + if (obj)
> + return obj;
> + if (!set)
> + return ERR_PTR(-ENOENT);
> +
> + new_hdl = kzalloc(sizeof(*new_hdl), GFP_KERNEL);
> + if (!new_hdl)
> + return ERR_PTR(-ENOMEM);
> +
> + obj = &new_hdl->req_obj;
> + ret = v4l2_ctrl_handler_init(new_hdl, (hdl->nr_of_buckets - 1) * 8);
> + if (!ret)
> + ret = v4l2_ctrl_request_bind(req, new_hdl, hdl);
> + if (ret) {
> + kfree(new_hdl);
> +
> + return ERR_PTR(ret);
> + }
> +
> + media_request_object_get(obj);
> + return obj;
> +}
> +
> +int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct media_device *mdev,
> + struct v4l2_ext_controls *cs)
> +{
> + struct media_request_object *obj = NULL;
> + int ret;
> +
> + if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
> + struct media_request *req;
> +
> + if (!mdev || cs->request_fd < 0)
> + return -EINVAL;
> +
> + req = media_request_get_by_fd(mdev, cs->request_fd);
> + if (IS_ERR(req))
> + return PTR_ERR(req);
> +
> + if (req->state != MEDIA_REQUEST_STATE_IDLE &&
> + req->state != MEDIA_REQUEST_STATE_COMPLETE) {
> + media_request_put(req);
> + return -EBUSY;
> + }
> +
> + obj = v4l2_ctrls_find_req_obj(hdl, req, false);
> + /* Reference to the request held through obj */
> + media_request_put(req);
> + if (IS_ERR(obj))
> + return PTR_ERR(obj);
> +
> + hdl = container_of(obj, struct v4l2_ctrl_handler,
> + req_obj);
> + }
> +
> + ret = v4l2_g_ext_ctrls_common(hdl, cs);
> +
> + if (obj)
> + media_request_object_put(obj);
> + return ret;
> +}
> EXPORT_SYMBOL(v4l2_g_ext_ctrls);
>
> /* Helper function to get a single control */
> @@ -3408,9 +3486,9 @@ static void update_from_auto_cluster(struct v4l2_ctrl *master)
> }
>
> /* Try or try-and-set controls */
> -static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
> - struct v4l2_ext_controls *cs,
> - bool set)
> +static int try_set_ext_ctrls_common(struct v4l2_fh *fh,
> + struct v4l2_ctrl_handler *hdl,
> + struct v4l2_ext_controls *cs, bool set)
> {
> struct v4l2_ctrl_helper helper[4];
> struct v4l2_ctrl_helper *helpers = helper;
> @@ -3523,16 +3601,60 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
> return ret;
> }
>
> -int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
> +static int try_set_ext_ctrls(struct v4l2_fh *fh,
> + struct v4l2_ctrl_handler *hdl, struct media_device *mdev,
> + struct v4l2_ext_controls *cs, bool set)
> +{
> + struct media_request_object *obj = NULL;
> + struct media_request *req = NULL;
> + int ret;
> +
> + if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
> + if (!mdev || cs->request_fd < 0)
> + return -EINVAL;
> +
> + req = media_request_get_by_fd(mdev, cs->request_fd);
> + if (IS_ERR(req))
> + return PTR_ERR(req);
> +
> + ret = media_request_lock_for_update(req);
> + if (ret) {
> + media_request_put(req);
> + return ret;
> + }
> +
> + obj = v4l2_ctrls_find_req_obj(hdl, req, set);
> + /* Reference to the request held through obj */
> + media_request_put(req);
> + if (IS_ERR(obj)) {
> + media_request_unlock_for_update(req);
> + return PTR_ERR(obj);
> + }
> + hdl = container_of(obj, struct v4l2_ctrl_handler,
> + req_obj);
> + }
> +
> + ret = try_set_ext_ctrls_common(fh, hdl, cs, set);
> +
> + if (obj) {
> + media_request_unlock_for_update(obj->req);
> + media_request_object_put(obj);
> + }
> +
> + return ret;
> +}
> +
> +int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct media_device *mdev,
> + struct v4l2_ext_controls *cs)
> {
> - return try_set_ext_ctrls(NULL, hdl, cs, false);
> + return try_set_ext_ctrls(NULL, hdl, mdev, cs, false);
> }
> EXPORT_SYMBOL(v4l2_try_ext_ctrls);
>
> int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
> - struct v4l2_ext_controls *cs)
> + struct media_device *mdev, struct v4l2_ext_controls *cs)
> {
> - return try_set_ext_ctrls(fh, hdl, cs, true);
> + return try_set_ext_ctrls(fh, hdl, mdev, cs, true);
> }
> EXPORT_SYMBOL(v4l2_s_ext_ctrls);
>
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 03241d6b7ef8..20b5145a5254 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -2109,9 +2109,9 @@ static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
>
> p->error_idx = p->count;
> if (vfh && vfh->ctrl_handler)
> - return v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
> + return v4l2_g_ext_ctrls(vfh->ctrl_handler, vfd->v4l2_dev->mdev, p);
> if (vfd->ctrl_handler)
> - return v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
> + return v4l2_g_ext_ctrls(vfd->ctrl_handler, vfd->v4l2_dev->mdev, p);
> if (ops->vidioc_g_ext_ctrls == NULL)
> return -ENOTTY;
> return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
> @@ -2128,9 +2128,9 @@ static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
>
> p->error_idx = p->count;
> if (vfh && vfh->ctrl_handler)
> - return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
> + return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, vfd->v4l2_dev->mdev, p);
> if (vfd->ctrl_handler)
> - return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
> + return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, vfd->v4l2_dev->mdev, p);
> if (ops->vidioc_s_ext_ctrls == NULL)
> return -ENOTTY;
> return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
> @@ -2147,9 +2147,9 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
>
> p->error_idx = p->count;
> if (vfh && vfh->ctrl_handler)
> - return v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
> + return v4l2_try_ext_ctrls(vfh->ctrl_handler, vfd->v4l2_dev->mdev, p);
> if (vfd->ctrl_handler)
> - return v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
> + return v4l2_try_ext_ctrls(vfd->ctrl_handler, vfd->v4l2_dev->mdev, p);
> if (ops->vidioc_try_ext_ctrls == NULL)
> return -ENOTTY;
> return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index 2b63fa6b6fc9..0fdbd85532dd 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -222,17 +222,20 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
> case VIDIOC_G_EXT_CTRLS:
> if (!vfh->ctrl_handler)
> return -ENOTTY;
> - return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg);
> + return v4l2_g_ext_ctrls(vfh->ctrl_handler,
> + sd->v4l2_dev->mdev, arg);
>
> case VIDIOC_S_EXT_CTRLS:
> if (!vfh->ctrl_handler)
> return -ENOTTY;
> - return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg);
> + return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler,
> + sd->v4l2_dev->mdev, arg);
>
> case VIDIOC_TRY_EXT_CTRLS:
> if (!vfh->ctrl_handler)
> return -ENOTTY;
> - return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg);
> + return v4l2_try_ext_ctrls(vfh->ctrl_handler,
> + sd->v4l2_dev->mdev, arg);
>
> case VIDIOC_DQEVENT:
> if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index ed784e98c293..f4156544150b 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -1179,11 +1179,12 @@ int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
> * :ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
> *
> * @hdl: pointer to &struct v4l2_ctrl_handler
> + * @mdev: pointer to &struct media_device
> * @c: pointer to &struct v4l2_ext_controls
> *
> * If hdl == NULL then they will all return -EINVAL.
> */
> -int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl,
> +int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct media_device *mdev,
> struct v4l2_ext_controls *c);
>
> /**
> @@ -1191,11 +1192,13 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl,
> * :ref:`VIDIOC_TRY_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
> *
> * @hdl: pointer to &struct v4l2_ctrl_handler
> + * @mdev: pointer to &struct media_device
> * @c: pointer to &struct v4l2_ext_controls
> *
> * If hdl == NULL then they will all return -EINVAL.
> */
> int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
> + struct media_device *mdev,
> struct v4l2_ext_controls *c);
>
> /**
> @@ -1204,11 +1207,13 @@ int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl,
> *
> * @fh: pointer to &struct v4l2_fh
> * @hdl: pointer to &struct v4l2_ctrl_handler
> + * @mdev: pointer to &struct media_device
> * @c: pointer to &struct v4l2_ext_controls
> *
> * If hdl == NULL then they will all return -EINVAL.
> */
> int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
> + struct media_device *mdev,
> struct v4l2_ext_controls *c);
>
> /**
Thanks,
Mauro
next prev parent reply other threads:[~2018-08-14 22:22 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 14:20 [PATCHv18 00/35] Request API Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 01/35] Documentation: v4l: document request API Hans Verkuil
2018-08-14 19:16 ` Mauro Carvalho Chehab
2018-08-15 16:14 ` Laurent Pinchart
2018-08-16 9:58 ` Hans Verkuil
2018-08-16 10:16 ` Hans Verkuil
2018-08-16 10:28 ` Mauro Carvalho Chehab
2018-11-12 19:06 ` Thomas Gleixner
2018-11-18 13:52 ` Mauro Carvalho Chehab
2018-11-23 9:51 ` Mauro Carvalho Chehab
2018-11-23 10:38 ` Thomas Gleixner
2018-11-23 12:29 ` Mauro Carvalho Chehab
2018-11-23 12:44 ` Thomas Gleixner
2018-11-27 18:54 ` Mauro Carvalho Chehab
2018-11-26 3:27 ` Tomasz Figa
2018-08-14 14:20 ` [PATCHv18 02/35] uapi/linux/media.h: add " Hans Verkuil
2018-08-14 19:17 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 03/35] media-request: implement media requests Hans Verkuil
2018-08-14 19:20 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 04/35] media: doc: Add media-request.h header to documentation build Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 05/35] media-request: add media_request_get_by_fd Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 06/35] media-request: add media_request_object_find Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 07/35] v4l2-device.h: add v4l2_device_supports_requests() helper Hans Verkuil
2018-08-24 10:21 ` Sakari Ailus
2018-08-14 14:20 ` [PATCHv18 08/35] v4l2-dev: lock req_queue_mutex Hans Verkuil
2018-08-14 19:22 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 09/35] videodev2.h: add request_fd field to v4l2_ext_controls Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 10/35] v4l2-ctrls: v4l2_ctrl_add_handler: add from_other_dev Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 11/35] v4l2-ctrls: prepare internal structs for request API Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 12/35] v4l2-ctrls: alloc memory for p_req Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 13/35] v4l2-ctrls: use ref in helper instead of ctrl Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 14/35] v4l2-ctrls: add core request support Hans Verkuil
2018-08-14 19:27 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 15/35] v4l2-ctrls: support g/s_ext_ctrls for requests Hans Verkuil
2018-08-14 19:33 ` Mauro Carvalho Chehab [this message]
2018-08-14 14:20 ` [PATCHv18 16/35] v4l2-ctrls: add v4l2_ctrl_request_hdl_find/put/ctrl_find functions Hans Verkuil
2018-08-14 19:34 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 17/35] videobuf2-v4l2: move __fill_v4l2_buffer() function Hans Verkuil
2018-08-14 19:36 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 18/35] videobuf2-v4l2: replace if by switch in __fill_vb2_buffer() Hans Verkuil
2018-08-15 11:51 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 19/35] vb2: store userspace data in vb2_v4l2_buffer Hans Verkuil
2018-08-14 19:47 ` Mauro Carvalho Chehab
2018-08-15 11:54 ` Hans Verkuil
2018-08-15 12:28 ` Mauro Carvalho Chehab
2018-08-15 12:33 ` Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 20/35] davinci_vpfe: remove bogus vb2->state check Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 21/35] vb2: drop VB2_BUF_STATE_PREPARED, use bool prepared/synced instead Hans Verkuil
2018-08-14 19:50 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 22/35] videodev2.h: Add request_fd field to v4l2_buffer Hans Verkuil
2018-08-25 12:58 ` Sakari Ailus
2018-08-14 14:20 ` [PATCHv18 23/35] vb2: add init_buffer buffer op Hans Verkuil
2018-08-25 12:58 ` Sakari Ailus
2018-08-14 14:20 ` [PATCHv18 24/35] videobuf2-core: embed media_request_object Hans Verkuil
2018-08-14 19:53 ` Mauro Carvalho Chehab
2018-08-25 13:01 ` Sakari Ailus
2018-08-14 14:20 ` [PATCHv18 25/35] videobuf2-core: integrate with media requests Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 26/35] videobuf2-v4l2: " Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 27/35] videobuf2-core: add request helper functions Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 28/35] videobuf2-v4l2: add vb2_request_queue/validate helpers Hans Verkuil
2018-08-14 19:54 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 29/35] videobuf2-core: add uses_requests/qbuf flags Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 30/35] videobuf2-v4l2: refuse qbuf if queue uses requests or vv Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 31/35] v4l2-mem2mem: add vb2_m2m_request_queue Hans Verkuil
2018-08-14 19:56 ` Mauro Carvalho Chehab
2018-08-14 14:20 ` [PATCHv18 32/35] vim2m: use workqueue Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 33/35] vim2m: support requests Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 34/35] vivid: add mc Hans Verkuil
2018-08-14 14:20 ` [PATCHv18 35/35] vivid: add request support Hans Verkuil
2018-08-14 20:01 ` [PATCHv18 00/35] Request API Mauro Carvalho Chehab
2018-08-14 20:04 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180814163344.2b59d941@coco.lan \
--to=mchehab+samsung@kernel.org \
--cc=hans.verkuil@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.