Commit eaec420f authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] v4l2-ioctl/exynos: fix G/S_SELECTION's type handling

The type field in struct v4l2_selection is supposed to never use the
_MPLANE variants. E.g. if the driver supports V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
then userspace should still pass V4L2_BUF_TYPE_VIDEO_CAPTURE.

The reasons for this are lost in the mists of time, but it is really
annoying. In addition, the exynos drivers didn't follow this rule and
instead expected the _MPLANE type.

To fix that code is added to the v4l2 core that maps the _MPLANE buffer
types to their regular equivalents before calling the driver.

Effectively this allows for userspace to use either _MPLANE or the regular
buffer type. This keeps backwards compatibility while making things easier
for userspace.

Since drivers now never see the _MPLANE buffer types the exynos drivers
had to be adapted as well.
Signed-off-by: default avatarHans Verkuil <hansverk@cisco.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 0e8298e5
...@@ -568,9 +568,9 @@ int gsc_try_crop(struct gsc_ctx *ctx, struct v4l2_crop *cr) ...@@ -568,9 +568,9 @@ int gsc_try_crop(struct gsc_ctx *ctx, struct v4l2_crop *cr)
} }
pr_debug("user put w: %d, h: %d", cr->c.width, cr->c.height); pr_debug("user put w: %d, h: %d", cr->c.width, cr->c.height);
if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
f = &ctx->d_frame; f = &ctx->d_frame;
else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
f = &ctx->s_frame; f = &ctx->s_frame;
else else
return -EINVAL; return -EINVAL;
......
...@@ -460,8 +460,8 @@ static int gsc_m2m_g_selection(struct file *file, void *fh, ...@@ -460,8 +460,8 @@ static int gsc_m2m_g_selection(struct file *file, void *fh,
struct gsc_frame *frame; struct gsc_frame *frame;
struct gsc_ctx *ctx = fh_to_ctx(fh); struct gsc_ctx *ctx = fh_to_ctx(fh);
if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) && if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
(s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)) (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT))
return -EINVAL; return -EINVAL;
frame = ctx_get_frame(ctx, s->type); frame = ctx_get_frame(ctx, s->type);
...@@ -503,8 +503,8 @@ static int gsc_m2m_s_selection(struct file *file, void *fh, ...@@ -503,8 +503,8 @@ static int gsc_m2m_s_selection(struct file *file, void *fh,
cr.type = s->type; cr.type = s->type;
cr.c = s->r; cr.c = s->r;
if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) && if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
(s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)) (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT))
return -EINVAL; return -EINVAL;
ret = gsc_try_crop(ctx, &cr); ret = gsc_try_crop(ctx, &cr);
......
...@@ -1270,7 +1270,7 @@ static int fimc_cap_g_selection(struct file *file, void *fh, ...@@ -1270,7 +1270,7 @@ static int fimc_cap_g_selection(struct file *file, void *fh,
struct fimc_ctx *ctx = fimc->vid_cap.ctx; struct fimc_ctx *ctx = fimc->vid_cap.ctx;
struct fimc_frame *f = &ctx->s_frame; struct fimc_frame *f = &ctx->s_frame;
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
switch (s->target) { switch (s->target) {
...@@ -1322,7 +1322,7 @@ static int fimc_cap_s_selection(struct file *file, void *fh, ...@@ -1322,7 +1322,7 @@ static int fimc_cap_s_selection(struct file *file, void *fh,
struct fimc_frame *f; struct fimc_frame *f;
unsigned long flags; unsigned long flags;
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
if (s->target == V4L2_SEL_TGT_COMPOSE) if (s->target == V4L2_SEL_TGT_COMPOSE)
......
...@@ -901,7 +901,7 @@ static int fimc_lite_g_selection(struct file *file, void *fh, ...@@ -901,7 +901,7 @@ static int fimc_lite_g_selection(struct file *file, void *fh,
struct fimc_lite *fimc = video_drvdata(file); struct fimc_lite *fimc = video_drvdata(file);
struct flite_frame *f = &fimc->out_frame; struct flite_frame *f = &fimc->out_frame;
if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
switch (sel->target) { switch (sel->target) {
...@@ -929,7 +929,7 @@ static int fimc_lite_s_selection(struct file *file, void *fh, ...@@ -929,7 +929,7 @@ static int fimc_lite_s_selection(struct file *file, void *fh,
struct v4l2_rect rect = sel->r; struct v4l2_rect rect = sel->r;
unsigned long flags; unsigned long flags;
if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
sel->target != V4L2_SEL_TGT_COMPOSE) sel->target != V4L2_SEL_TGT_COMPOSE)
return -EINVAL; return -EINVAL;
......
...@@ -2145,6 +2145,47 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, ...@@ -2145,6 +2145,47 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
-EINVAL; -EINVAL;
} }
/*
* The selection API specified originally that the _MPLANE buffer types
* shouldn't be used. The reasons for this are lost in the mists of time
* (or just really crappy memories). Regardless, this is really annoying
* for userspace. So to keep things simple we map _MPLANE buffer types
* to their 'regular' counterparts before calling the driver. And we
* restore it afterwards. This way applications can use either buffer
* type and drivers don't need to check for both.
*/
static int v4l_g_selection(const struct v4l2_ioctl_ops *ops,
struct file *file, void *fh, void *arg)
{
struct v4l2_selection *p = arg;
u32 old_type = p->type;
int ret;
if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
ret = ops->vidioc_g_selection(file, fh, p);
p->type = old_type;
return ret;
}
static int v4l_s_selection(const struct v4l2_ioctl_ops *ops,
struct file *file, void *fh, void *arg)
{
struct v4l2_selection *p = arg;
u32 old_type = p->type;
int ret;
if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
ret = ops->vidioc_s_selection(file, fh, p);
p->type = old_type;
return ret;
}
static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
struct file *file, void *fh, void *arg) struct file *file, void *fh, void *arg)
{ {
...@@ -2164,7 +2205,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, ...@@ -2164,7 +2205,7 @@ static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
else else
s.target = V4L2_SEL_TGT_CROP_ACTIVE; s.target = V4L2_SEL_TGT_CROP_ACTIVE;
ret = ops->vidioc_g_selection(file, fh, &s); ret = v4l_g_selection(ops, file, fh, &s);
/* copying results to old structure on success */ /* copying results to old structure on success */
if (!ret) if (!ret)
...@@ -2191,7 +2232,7 @@ static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, ...@@ -2191,7 +2232,7 @@ static int v4l_s_crop(const struct v4l2_ioctl_ops *ops,
else else
s.target = V4L2_SEL_TGT_CROP_ACTIVE; s.target = V4L2_SEL_TGT_CROP_ACTIVE;
return ops->vidioc_s_selection(file, fh, &s); return v4l_s_selection(ops, file, fh, &s);
} }
static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
...@@ -2233,7 +2274,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, ...@@ -2233,7 +2274,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
else else
s.target = V4L2_SEL_TGT_CROP_BOUNDS; s.target = V4L2_SEL_TGT_CROP_BOUNDS;
ret = ops->vidioc_g_selection(file, fh, &s); ret = v4l_g_selection(ops, file, fh, &s);
if (ret) if (ret)
return ret; return ret;
p->bounds = s.r; p->bounds = s.r;
...@@ -2244,7 +2285,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, ...@@ -2244,7 +2285,7 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
else else
s.target = V4L2_SEL_TGT_CROP_DEFAULT; s.target = V4L2_SEL_TGT_CROP_DEFAULT;
ret = ops->vidioc_g_selection(file, fh, &s); ret = v4l_g_selection(ops, file, fh, &s);
if (ret) if (ret)
return ret; return ret;
p->defrect = s.r; p->defrect = s.r;
...@@ -2556,8 +2597,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = { ...@@ -2556,8 +2597,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)), IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)), IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO), IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, INFO_FL_CLEAR(v4l2_selection, r)), IOCTL_INFO_FNC(VIDIOC_G_SELECTION, v4l_g_selection, v4l_print_selection, INFO_FL_CLEAR(v4l2_selection, r)),
IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_selection, r)), IOCTL_INFO_FNC(VIDIOC_S_SELECTION, v4l_s_selection, v4l_print_selection, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_selection, r)),
IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0), IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0),
IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO), IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO),
IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0), IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment