mirror of
https://github.com/torvalds/linux.git
synced 2026-06-01 11:03:43 +02:00
media: mtk: vcodec: Access v4l2_fh from file
The v4l2_fh associated with an open file handle is now guaranteed to be available in file->private_data, initialised by v4l2_fh_add(). Access the v4l2_fh, and from there the driver-specific structure, from the file * in all ioctl handlers. While at modify mtk_vcodec_enc_get_chip_name() to accept a ctx instead of a raw void *. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Co-developed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
This commit is contained in:
parent
698c41290e
commit
50363fc1fe
|
|
@ -87,7 +87,7 @@ static int stateful_try_decoder_cmd(struct file *file, void *priv, struct v4l2_d
|
|||
|
||||
static int stateful_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
struct vb2_queue *src_vq, *dst_vq;
|
||||
int ret;
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ static int stateless_try_decoder_cmd(struct file *file, void *priv, struct v4l2_
|
|||
|
||||
static int stateless_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
int ret;
|
||||
|
||||
ret = v4l2_m2m_ioctl_stateless_try_decoder_cmd(file, priv, cmd);
|
||||
|
|
@ -158,7 +158,7 @@ static int stateless_decoder_cmd(struct file *file, void *priv, struct v4l2_deco
|
|||
|
||||
static int vidioc_try_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
|
||||
if (ctx->dev->vdec_pdata->uses_stateless_api)
|
||||
return stateless_try_decoder_cmd(file, priv, cmd);
|
||||
|
|
@ -168,7 +168,7 @@ static int vidioc_try_decoder_cmd(struct file *file, void *priv, struct v4l2_dec
|
|||
|
||||
static int vidioc_decoder_cmd(struct file *file, void *priv, struct v4l2_decoder_cmd *cmd)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
|
||||
if (ctx->dev->vdec_pdata->uses_stateless_api)
|
||||
return stateless_decoder_cmd(file, priv, cmd);
|
||||
|
|
@ -233,7 +233,7 @@ void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_dec_ctx *ctx)
|
|||
static int vidioc_vdec_qbuf(struct file *file, void *priv,
|
||||
struct v4l2_buffer *buf)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
|
||||
if (ctx->state == MTK_STATE_ABORT) {
|
||||
mtk_v4l2_vdec_err(ctx, "[%d] Call on QBUF after unrecoverable error", ctx->id);
|
||||
|
|
@ -246,7 +246,7 @@ static int vidioc_vdec_qbuf(struct file *file, void *priv,
|
|||
static int vidioc_vdec_dqbuf(struct file *file, void *priv,
|
||||
struct v4l2_buffer *buf)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
|
||||
if (ctx->state == MTK_STATE_ABORT) {
|
||||
mtk_v4l2_vdec_err(ctx, "[%d] Call on DQBUF after unrecoverable error", ctx->id);
|
||||
|
|
@ -259,7 +259,7 @@ static int vidioc_vdec_dqbuf(struct file *file, void *priv,
|
|||
static int vidioc_vdec_querycap(struct file *file, void *priv,
|
||||
struct v4l2_capability *cap)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
struct device *dev = &ctx->dev->plat_dev->dev;
|
||||
|
||||
strscpy(cap->driver, dev->driver->name, sizeof(cap->driver));
|
||||
|
|
@ -354,7 +354,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
|
|||
struct v4l2_format *f)
|
||||
{
|
||||
const struct mtk_video_fmt *fmt;
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;
|
||||
|
||||
fmt = mtk_vdec_find_format(f, dec_pdata);
|
||||
|
|
@ -372,7 +372,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
|
|||
{
|
||||
struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
|
||||
const struct mtk_video_fmt *fmt;
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;
|
||||
|
||||
fmt = mtk_vdec_find_format(f, dec_pdata);
|
||||
|
|
@ -393,7 +393,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
|
|||
static int vidioc_vdec_g_selection(struct file *file, void *priv,
|
||||
struct v4l2_selection *s)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
struct mtk_q_data *q_data;
|
||||
|
||||
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
||||
|
|
@ -442,7 +442,7 @@ static int vidioc_vdec_g_selection(struct file *file, void *priv,
|
|||
static int vidioc_vdec_s_selection(struct file *file, void *priv,
|
||||
struct v4l2_selection *s)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
|
||||
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
||||
return -EINVAL;
|
||||
|
|
@ -464,7 +464,7 @@ static int vidioc_vdec_s_selection(struct file *file, void *priv,
|
|||
static int vidioc_vdec_s_fmt(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
struct v4l2_pix_format_mplane *pix_mp;
|
||||
struct mtk_q_data *q_data;
|
||||
int ret = 0;
|
||||
|
|
@ -594,7 +594,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
|
|||
struct v4l2_frmsizeenum *fsize)
|
||||
{
|
||||
int i = 0;
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;
|
||||
|
||||
if (fsize->index != 0)
|
||||
|
|
@ -623,10 +623,10 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, void *priv,
|
||||
static int vidioc_enum_fmt(struct file *file, struct v4l2_fmtdesc *f,
|
||||
bool output_queue)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;
|
||||
const struct mtk_video_fmt *fmt;
|
||||
int i, j = 0;
|
||||
|
|
@ -660,19 +660,19 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, void *priv,
|
|||
static int vidioc_vdec_enum_fmt_vid_cap(struct file *file, void *priv,
|
||||
struct v4l2_fmtdesc *f)
|
||||
{
|
||||
return vidioc_enum_fmt(f, priv, false);
|
||||
return vidioc_enum_fmt(file, f, false);
|
||||
}
|
||||
|
||||
static int vidioc_vdec_enum_fmt_vid_out(struct file *file, void *priv,
|
||||
struct v4l2_fmtdesc *f)
|
||||
{
|
||||
return vidioc_enum_fmt(f, priv, true);
|
||||
return vidioc_enum_fmt(file, f, true);
|
||||
}
|
||||
|
||||
static int vidioc_vdec_g_fmt(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
|
||||
struct mtk_vcodec_dec_ctx *ctx = file_to_dec_ctx(file);
|
||||
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
|
||||
struct vb2_queue *vq;
|
||||
struct mtk_q_data *q_data;
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ static int vidioc_enum_framesizes(struct file *file, void *fh,
|
|||
struct v4l2_frmsizeenum *fsize)
|
||||
{
|
||||
const struct mtk_video_fmt *fmt;
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(fh);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
|
||||
if (fsize->index != 0)
|
||||
return -EINVAL;
|
||||
|
|
@ -183,7 +183,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
|
|||
struct v4l2_fmtdesc *f)
|
||||
{
|
||||
const struct mtk_vcodec_enc_pdata *pdata =
|
||||
fh_to_enc_ctx(priv)->dev->venc_pdata;
|
||||
file_to_enc_ctx(file)->dev->venc_pdata;
|
||||
|
||||
return vidioc_enum_fmt(f, pdata->capture_formats,
|
||||
pdata->num_capture_formats);
|
||||
|
|
@ -193,15 +193,14 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
|
|||
struct v4l2_fmtdesc *f)
|
||||
{
|
||||
const struct mtk_vcodec_enc_pdata *pdata =
|
||||
fh_to_enc_ctx(priv)->dev->venc_pdata;
|
||||
file_to_enc_ctx(file)->dev->venc_pdata;
|
||||
|
||||
return vidioc_enum_fmt(f, pdata->output_formats,
|
||||
pdata->num_output_formats);
|
||||
}
|
||||
|
||||
static int mtk_vcodec_enc_get_chip_name(void *priv)
|
||||
static int mtk_vcodec_enc_get_chip_name(struct mtk_vcodec_enc_ctx *ctx)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct device *dev = &ctx->dev->plat_dev->dev;
|
||||
|
||||
if (of_device_is_compatible(dev->of_node, "mediatek,mt8173-vcodec-enc"))
|
||||
|
|
@ -221,9 +220,9 @@ static int mtk_vcodec_enc_get_chip_name(void *priv)
|
|||
static int vidioc_venc_querycap(struct file *file, void *priv,
|
||||
struct v4l2_capability *cap)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
struct device *dev = &ctx->dev->plat_dev->dev;
|
||||
int platform_name = mtk_vcodec_enc_get_chip_name(priv);
|
||||
int platform_name = mtk_vcodec_enc_get_chip_name(ctx);
|
||||
|
||||
strscpy(cap->driver, dev->driver->name, sizeof(cap->driver));
|
||||
snprintf(cap->card, sizeof(cap->card), "MT%d video encoder", platform_name);
|
||||
|
|
@ -234,7 +233,7 @@ static int vidioc_venc_querycap(struct file *file, void *priv,
|
|||
static int vidioc_venc_s_parm(struct file *file, void *priv,
|
||||
struct v4l2_streamparm *a)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
struct v4l2_fract *timeperframe = &a->parm.output.timeperframe;
|
||||
|
||||
if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
|
||||
|
|
@ -257,7 +256,7 @@ static int vidioc_venc_s_parm(struct file *file, void *priv,
|
|||
static int vidioc_venc_g_parm(struct file *file, void *priv,
|
||||
struct v4l2_streamparm *a)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
|
||||
if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
|
||||
return -EINVAL;
|
||||
|
|
@ -414,7 +413,7 @@ static void mtk_venc_set_param(struct mtk_vcodec_enc_ctx *ctx,
|
|||
static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
|
||||
struct vb2_queue *vq;
|
||||
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, f->type);
|
||||
|
|
@ -469,7 +468,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
|
|||
static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
|
||||
struct vb2_queue *vq;
|
||||
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, f->type);
|
||||
|
|
@ -524,7 +523,7 @@ static int vidioc_venc_g_fmt(struct file *file, void *priv,
|
|||
struct v4l2_format *f)
|
||||
{
|
||||
struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
struct vb2_queue *vq;
|
||||
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, f->type);
|
||||
int i;
|
||||
|
|
@ -557,7 +556,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
|
|||
struct v4l2_format *f)
|
||||
{
|
||||
const struct mtk_video_fmt *fmt;
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
|
||||
|
||||
fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
|
||||
|
|
@ -579,7 +578,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
|
|||
struct v4l2_format *f)
|
||||
{
|
||||
const struct mtk_video_fmt *fmt;
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
|
||||
|
||||
fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
|
||||
|
|
@ -600,7 +599,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
|
|||
static int vidioc_venc_g_selection(struct file *file, void *priv,
|
||||
struct v4l2_selection *s)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, s->type);
|
||||
|
||||
if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
|
||||
|
|
@ -630,7 +629,7 @@ static int vidioc_venc_g_selection(struct file *file, void *priv,
|
|||
static int vidioc_venc_s_selection(struct file *file, void *priv,
|
||||
struct v4l2_selection *s)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, s->type);
|
||||
|
||||
if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
|
||||
|
|
@ -655,7 +654,7 @@ static int vidioc_venc_s_selection(struct file *file, void *priv,
|
|||
static int vidioc_venc_qbuf(struct file *file, void *priv,
|
||||
struct v4l2_buffer *buf)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
|
||||
if (ctx->state == MTK_STATE_ABORT) {
|
||||
mtk_v4l2_venc_err(ctx, "[%d] Call on QBUF after unrecoverable error",
|
||||
|
|
@ -669,7 +668,7 @@ static int vidioc_venc_qbuf(struct file *file, void *priv,
|
|||
static int vidioc_venc_dqbuf(struct file *file, void *priv,
|
||||
struct v4l2_buffer *buf)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
int ret;
|
||||
|
||||
if (ctx->state == MTK_STATE_ABORT) {
|
||||
|
|
@ -707,7 +706,7 @@ static int vidioc_venc_dqbuf(struct file *file, void *priv,
|
|||
static int vidioc_encoder_cmd(struct file *file, void *priv,
|
||||
struct v4l2_encoder_cmd *cmd)
|
||||
{
|
||||
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
|
||||
struct mtk_vcodec_enc_ctx *ctx = file_to_enc_ctx(file);
|
||||
struct vb2_queue *src_vq, *dst_vq;
|
||||
int ret;
|
||||
|
||||
|
|
|
|||
|
|
@ -217,14 +217,9 @@ struct mtk_vcodec_enc_dev {
|
|||
struct mtk_vcodec_dbgfs dbgfs;
|
||||
};
|
||||
|
||||
static inline struct mtk_vcodec_enc_ctx *fh_to_enc_ctx(struct v4l2_fh *fh)
|
||||
{
|
||||
return container_of(fh, struct mtk_vcodec_enc_ctx, fh);
|
||||
}
|
||||
|
||||
static inline struct mtk_vcodec_enc_ctx *file_to_enc_ctx(struct file *filp)
|
||||
{
|
||||
return fh_to_enc_ctx(file_to_v4l2_fh(filp));
|
||||
return container_of(file_to_v4l2_fh(filp), struct mtk_vcodec_enc_ctx, fh);
|
||||
}
|
||||
|
||||
static inline struct mtk_vcodec_enc_ctx *ctrl_to_enc_ctx(struct v4l2_ctrl *ctrl)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user