Commit 8293ebfc authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[media] s5p-fimc: Use v4l core mutex in ioctl and file operations

Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ef7af59b
This diff is collapsed.
...@@ -741,22 +741,17 @@ int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv, ...@@ -741,22 +741,17 @@ int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv,
struct v4l2_format *f) struct v4l2_format *f)
{ {
struct fimc_ctx *ctx = priv; struct fimc_ctx *ctx = priv;
struct fimc_dev *fimc = ctx->fimc_dev;
struct fimc_frame *frame; struct fimc_frame *frame;
frame = ctx_get_frame(ctx, f->type); frame = ctx_get_frame(ctx, f->type);
if (IS_ERR(frame)) if (IS_ERR(frame))
return PTR_ERR(frame); return PTR_ERR(frame);
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
f->fmt.pix.width = frame->width; f->fmt.pix.width = frame->width;
f->fmt.pix.height = frame->height; f->fmt.pix.height = frame->height;
f->fmt.pix.field = V4L2_FIELD_NONE; f->fmt.pix.field = V4L2_FIELD_NONE;
f->fmt.pix.pixelformat = frame->fmt->fourcc; f->fmt.pix.pixelformat = frame->fmt->fourcc;
mutex_unlock(&fimc->lock);
return 0; return 0;
} }
...@@ -800,7 +795,8 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv, ...@@ -800,7 +795,8 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp; struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
struct fimc_fmt *fmt; struct fimc_fmt *fmt;
u32 max_width, mod_x, mod_y, mask; u32 max_width, mod_x, mod_y, mask;
int ret, i, is_output = 0; int i, is_output = 0;
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
if (ctx->state & FIMC_CTX_CAP) if (ctx->state & FIMC_CTX_CAP)
...@@ -810,8 +806,6 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv, ...@@ -810,8 +806,6 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
return -EINVAL; return -EINVAL;
} }
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
dbg("w: %d, h: %d", pix->width, pix->height); dbg("w: %d, h: %d", pix->width, pix->height);
mask = is_output ? FMT_FLAGS_M2M : FMT_FLAGS_M2M | FMT_FLAGS_CAM; mask = is_output ? FMT_FLAGS_M2M : FMT_FLAGS_M2M | FMT_FLAGS_CAM;
...@@ -819,13 +813,13 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv, ...@@ -819,13 +813,13 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
if (!fmt) { if (!fmt) {
v4l2_err(&fimc->m2m.v4l2_dev, "Fourcc format (0x%X) invalid.\n", v4l2_err(&fimc->m2m.v4l2_dev, "Fourcc format (0x%X) invalid.\n",
pix->pixelformat); pix->pixelformat);
goto tf_out; return -EINVAL;
} }
if (pix->field == V4L2_FIELD_ANY) if (pix->field == V4L2_FIELD_ANY)
pix->field = V4L2_FIELD_NONE; pix->field = V4L2_FIELD_NONE;
else if (V4L2_FIELD_NONE != pix->field) else if (V4L2_FIELD_NONE != pix->field)
goto tf_out; return -EINVAL;
if (is_output) { if (is_output) {
max_width = variant->pix_limit->scaler_dis_w; max_width = variant->pix_limit->scaler_dis_w;
...@@ -871,11 +865,7 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv, ...@@ -871,11 +865,7 @@ int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
pix->plane_fmt[i].sizeimage); pix->plane_fmt[i].sizeimage);
} }
ret = 0; return 0;
tf_out:
mutex_unlock(&fimc->lock);
return ret;
} }
static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv, static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
...@@ -888,45 +878,33 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv, ...@@ -888,45 +878,33 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
struct v4l2_pix_format_mplane *pix; struct v4l2_pix_format_mplane *pix;
unsigned long flags; unsigned long flags;
int i, ret = 0; int i, ret = 0;
u32 tmp;
ret = fimc_vidioc_try_fmt_mplane(file, priv, f); ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
if (ret) if (ret)
return ret; return ret;
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
if (vb2_is_streaming(vq)) { if (vb2_is_streaming(vq)) {
v4l2_err(&fimc->vid_cap.v4l2_dev, "%s: queue (%d) busy\n", v4l2_err(&fimc->m2m.v4l2_dev, "queue (%d) busy\n", f->type);
__func__, f->type); return -EBUSY;
ret = -EBUSY;
goto sf_out;
} }
spin_lock_irqsave(&ctx->slock, flags);
if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
frame = &ctx->s_frame; frame = &ctx->s_frame;
ctx->state |= FIMC_SRC_FMT;
} else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
frame = &ctx->d_frame; frame = &ctx->d_frame;
ctx->state |= FIMC_DST_FMT;
} else { } else {
spin_unlock_irqrestore(&ctx->slock, flags);
v4l2_err(&fimc->m2m.v4l2_dev, v4l2_err(&fimc->m2m.v4l2_dev,
"Wrong buffer/video queue type (%d)\n", f->type); "Wrong buffer/video queue type (%d)\n", f->type);
ret = -EINVAL; return -EINVAL;
goto sf_out;
} }
spin_unlock_irqrestore(&ctx->slock, flags);
pix = &f->fmt.pix_mp; pix = &f->fmt.pix_mp;
frame->fmt = find_format(f, FMT_FLAGS_M2M); frame->fmt = find_format(f, FMT_FLAGS_M2M);
if (!frame->fmt) { if (!frame->fmt)
ret = -EINVAL; return -EINVAL;
goto sf_out;
}
for (i = 0; i < frame->fmt->colplanes; i++) for (i = 0; i < frame->fmt->colplanes; i++)
frame->payload[i] = pix->plane_fmt[i].bytesperline * pix->height; frame->payload[i] = pix->plane_fmt[i].bytesperline * pix->height;
...@@ -942,14 +920,13 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv, ...@@ -942,14 +920,13 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *priv,
frame->offs_v = 0; frame->offs_v = 0;
spin_lock_irqsave(&ctx->slock, flags); spin_lock_irqsave(&ctx->slock, flags);
ctx->state |= FIMC_PARAMS; tmp = (frame == &ctx->d_frame) ? FIMC_DST_FMT : FIMC_SRC_FMT;
ctx->state |= FIMC_PARAMS | tmp;
spin_unlock_irqrestore(&ctx->slock, flags); spin_unlock_irqrestore(&ctx->slock, flags);
dbg("f_w: %d, f_h: %d", frame->f_width, frame->f_height); dbg("f_w: %d, f_h: %d", frame->f_width, frame->f_height);
sf_out: return 0;
mutex_unlock(&fimc->lock);
return ret;
} }
static int fimc_m2m_reqbufs(struct file *file, void *priv, static int fimc_m2m_reqbufs(struct file *file, void *priv,
...@@ -1018,11 +995,8 @@ int fimc_vidioc_queryctrl(struct file *file, void *priv, ...@@ -1018,11 +995,8 @@ int fimc_vidioc_queryctrl(struct file *file, void *priv,
} }
if (ctx->state & FIMC_CTX_CAP) { if (ctx->state & FIMC_CTX_CAP) {
if (mutex_lock_interruptible(&ctx->fimc_dev->lock)) return v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
return -ERESTARTSYS;
ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
core, queryctrl, qc); core, queryctrl, qc);
mutex_unlock(&ctx->fimc_dev->lock);
} }
return ret; return ret;
} }
...@@ -1032,10 +1006,6 @@ int fimc_vidioc_g_ctrl(struct file *file, void *priv, ...@@ -1032,10 +1006,6 @@ int fimc_vidioc_g_ctrl(struct file *file, void *priv,
{ {
struct fimc_ctx *ctx = priv; struct fimc_ctx *ctx = priv;
struct fimc_dev *fimc = ctx->fimc_dev; struct fimc_dev *fimc = ctx->fimc_dev;
int ret = 0;
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_HFLIP: case V4L2_CID_HFLIP:
...@@ -1049,18 +1019,17 @@ int fimc_vidioc_g_ctrl(struct file *file, void *priv, ...@@ -1049,18 +1019,17 @@ int fimc_vidioc_g_ctrl(struct file *file, void *priv,
break; break;
default: default:
if (ctx->state & FIMC_CTX_CAP) { if (ctx->state & FIMC_CTX_CAP) {
ret = v4l2_subdev_call(fimc->vid_cap.sd, core, return v4l2_subdev_call(fimc->vid_cap.sd, core,
g_ctrl, ctrl); g_ctrl, ctrl);
} else { } else {
v4l2_err(&fimc->m2m.v4l2_dev, v4l2_err(&fimc->m2m.v4l2_dev,
"Invalid control\n"); "Invalid control\n");
ret = -EINVAL; return -EINVAL;
} }
} }
dbg("ctrl->value= %d", ctrl->value); dbg("ctrl->value= %d", ctrl->value);
mutex_unlock(&fimc->lock); return 0;
return ret;
} }
int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl) int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl)
...@@ -1151,22 +1120,17 @@ static int fimc_m2m_cropcap(struct file *file, void *fh, ...@@ -1151,22 +1120,17 @@ static int fimc_m2m_cropcap(struct file *file, void *fh,
{ {
struct fimc_frame *frame; struct fimc_frame *frame;
struct fimc_ctx *ctx = fh; struct fimc_ctx *ctx = fh;
struct fimc_dev *fimc = ctx->fimc_dev;
frame = ctx_get_frame(ctx, cr->type); frame = ctx_get_frame(ctx, cr->type);
if (IS_ERR(frame)) if (IS_ERR(frame))
return PTR_ERR(frame); return PTR_ERR(frame);
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
cr->bounds.left = 0; cr->bounds.left = 0;
cr->bounds.top = 0; cr->bounds.top = 0;
cr->bounds.width = frame->f_width; cr->bounds.width = frame->f_width;
cr->bounds.height = frame->f_height; cr->bounds.height = frame->f_height;
cr->defrect = cr->bounds; cr->defrect = cr->bounds;
mutex_unlock(&fimc->lock);
return 0; return 0;
} }
...@@ -1174,21 +1138,16 @@ static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) ...@@ -1174,21 +1138,16 @@ static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
{ {
struct fimc_frame *frame; struct fimc_frame *frame;
struct fimc_ctx *ctx = file->private_data; struct fimc_ctx *ctx = file->private_data;
struct fimc_dev *fimc = ctx->fimc_dev;
frame = ctx_get_frame(ctx, cr->type); frame = ctx_get_frame(ctx, cr->type);
if (IS_ERR(frame)) if (IS_ERR(frame))
return PTR_ERR(frame); return PTR_ERR(frame);
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
cr->c.left = frame->offs_h; cr->c.left = frame->offs_h;
cr->c.top = frame->offs_v; cr->c.top = frame->offs_v;
cr->c.width = frame->width; cr->c.width = frame->width;
cr->c.height = frame->height; cr->c.height = frame->height;
mutex_unlock(&fimc->lock);
return 0; return 0;
} }
...@@ -1268,9 +1227,6 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) ...@@ -1268,9 +1227,6 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ? f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ?
&ctx->s_frame : &ctx->d_frame; &ctx->s_frame : &ctx->d_frame;
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
spin_lock_irqsave(&ctx->slock, flags); spin_lock_irqsave(&ctx->slock, flags);
if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) { if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) {
/* Check to see if scaling ratio is within supported range */ /* Check to see if scaling ratio is within supported range */
...@@ -1280,8 +1236,8 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) ...@@ -1280,8 +1236,8 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame); ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
if (ret) { if (ret) {
v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range"); v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
ret = -EINVAL; spin_unlock_irqrestore(&ctx->slock, flags);
goto scr_unlock; return -EINVAL;
} }
} }
ctx->state |= FIMC_PARAMS; ctx->state |= FIMC_PARAMS;
...@@ -1291,9 +1247,7 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) ...@@ -1291,9 +1247,7 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
f->width = cr->c.width; f->width = cr->c.width;
f->height = cr->c.height; f->height = cr->c.height;
scr_unlock:
spin_unlock_irqrestore(&ctx->slock, flags); spin_unlock_irqrestore(&ctx->slock, flags);
mutex_unlock(&fimc->lock);
return 0; return 0;
} }
...@@ -1364,10 +1318,6 @@ static int fimc_m2m_open(struct file *file) ...@@ -1364,10 +1318,6 @@ static int fimc_m2m_open(struct file *file)
{ {
struct fimc_dev *fimc = video_drvdata(file); struct fimc_dev *fimc = video_drvdata(file);
struct fimc_ctx *ctx = NULL; struct fimc_ctx *ctx = NULL;
int err = 0;
if (mutex_lock_interruptible(&fimc->lock))
return -ERESTARTSYS;
dbg("pid: %d, state: 0x%lx, refcnt: %d", dbg("pid: %d, state: 0x%lx, refcnt: %d",
task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt); task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt);
...@@ -1376,19 +1326,15 @@ static int fimc_m2m_open(struct file *file) ...@@ -1376,19 +1326,15 @@ static int fimc_m2m_open(struct file *file)
* Return if the corresponding video capture node * Return if the corresponding video capture node
* is already opened. * is already opened.
*/ */
if (fimc->vid_cap.refcnt > 0) { if (fimc->vid_cap.refcnt > 0)
err = -EBUSY; return -EBUSY;
goto err_unlock;
}
fimc->m2m.refcnt++; fimc->m2m.refcnt++;
set_bit(ST_OUTDMA_RUN, &fimc->state); set_bit(ST_OUTDMA_RUN, &fimc->state);
ctx = kzalloc(sizeof *ctx, GFP_KERNEL); ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
if (!ctx) { if (!ctx)
err = -ENOMEM; return -ENOMEM;
goto err_unlock;
}
file->private_data = ctx; file->private_data = ctx;
ctx->fimc_dev = fimc; ctx->fimc_dev = fimc;
...@@ -1404,13 +1350,12 @@ static int fimc_m2m_open(struct file *file) ...@@ -1404,13 +1350,12 @@ static int fimc_m2m_open(struct file *file)
ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init); ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init);
if (IS_ERR(ctx->m2m_ctx)) { if (IS_ERR(ctx->m2m_ctx)) {
err = PTR_ERR(ctx->m2m_ctx); int err = PTR_ERR(ctx->m2m_ctx);
kfree(ctx); kfree(ctx);
return err;
} }
err_unlock: return 0;
mutex_unlock(&fimc->lock);
return err;
} }
static int fimc_m2m_release(struct file *file) static int fimc_m2m_release(struct file *file)
...@@ -1418,8 +1363,6 @@ static int fimc_m2m_release(struct file *file) ...@@ -1418,8 +1363,6 @@ static int fimc_m2m_release(struct file *file)
struct fimc_ctx *ctx = file->private_data; struct fimc_ctx *ctx = file->private_data;
struct fimc_dev *fimc = ctx->fimc_dev; struct fimc_dev *fimc = ctx->fimc_dev;
mutex_lock(&fimc->lock);
dbg("pid: %d, state: 0x%lx, refcnt= %d", dbg("pid: %d, state: 0x%lx, refcnt= %d",
task_pid_nr(current), fimc->state, fimc->m2m.refcnt); task_pid_nr(current), fimc->state, fimc->m2m.refcnt);
...@@ -1428,7 +1371,6 @@ static int fimc_m2m_release(struct file *file) ...@@ -1428,7 +1371,6 @@ static int fimc_m2m_release(struct file *file)
if (--fimc->m2m.refcnt <= 0) if (--fimc->m2m.refcnt <= 0)
clear_bit(ST_OUTDMA_RUN, &fimc->state); clear_bit(ST_OUTDMA_RUN, &fimc->state);
mutex_unlock(&fimc->lock);
return 0; return 0;
} }
...@@ -1494,6 +1436,7 @@ static int fimc_register_m2m_device(struct fimc_dev *fimc) ...@@ -1494,6 +1436,7 @@ static int fimc_register_m2m_device(struct fimc_dev *fimc)
vfd->ioctl_ops = &fimc_m2m_ioctl_ops; vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
vfd->minor = -1; vfd->minor = -1;
vfd->release = video_device_release; vfd->release = video_device_release;
vfd->lock = &fimc->lock;
snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev)); snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
......
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