Commit 21f0315b authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Mauro Carvalho Chehab

hantro: Rework how encoder and decoder are identified

So far we've been using the .buf_finish hook to distinguish
decoder from encoder. This is unnecessarily obfuscated.

Moreover, we want to move the buf_finish, so use a cleaner
scheme to distinguish the driver decoder/encoder type.
Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Reviewed-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 4df3a47e
...@@ -199,6 +199,7 @@ struct hantro_dev { ...@@ -199,6 +199,7 @@ struct hantro_dev {
* *
* @dev: VPU driver data to which the context belongs. * @dev: VPU driver data to which the context belongs.
* @fh: V4L2 file handler. * @fh: V4L2 file handler.
* @is_encoder: Decoder or encoder context?
* *
* @sequence_cap: Sequence counter for capture queue * @sequence_cap: Sequence counter for capture queue
* @sequence_out: Sequence counter for output queue * @sequence_out: Sequence counter for output queue
...@@ -223,6 +224,7 @@ struct hantro_dev { ...@@ -223,6 +224,7 @@ struct hantro_dev {
struct hantro_ctx { struct hantro_ctx {
struct hantro_dev *dev; struct hantro_dev *dev;
struct v4l2_fh fh; struct v4l2_fh fh;
bool is_encoder;
u32 sequence_cap; u32 sequence_cap;
u32 sequence_out; u32 sequence_out;
...@@ -399,8 +401,6 @@ static inline void hantro_reg_write_s(struct hantro_dev *vpu, ...@@ -399,8 +401,6 @@ static inline void hantro_reg_write_s(struct hantro_dev *vpu,
vdpu_write(vpu, vdpu_read_mask(vpu, reg, val), reg->base); vdpu_write(vpu, vdpu_read_mask(vpu, reg, val), reg->base);
} }
bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx);
void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id); void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id);
dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts); dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts);
...@@ -420,7 +420,7 @@ static inline bool ...@@ -420,7 +420,7 @@ static inline bool
hantro_needs_postproc(const struct hantro_ctx *ctx, hantro_needs_postproc(const struct hantro_ctx *ctx,
const struct hantro_fmt *fmt) const struct hantro_fmt *fmt)
{ {
return !hantro_is_encoder_ctx(ctx) && fmt->fourcc != V4L2_PIX_FMT_NV12; return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
} }
static inline dma_addr_t static inline dma_addr_t
......
...@@ -195,11 +195,6 @@ static void device_run(void *priv) ...@@ -195,11 +195,6 @@ static void device_run(void *priv)
hantro_job_finish(ctx->dev, ctx, 0, VB2_BUF_STATE_ERROR); hantro_job_finish(ctx->dev, ctx, 0, VB2_BUF_STATE_ERROR);
} }
bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
{
return ctx->buf_finish == hantro_enc_buf_finish;
}
static struct v4l2_m2m_ops vpu_m2m_ops = { static struct v4l2_m2m_ops vpu_m2m_ops = {
.device_run = device_run, .device_run = device_run,
}; };
...@@ -240,7 +235,7 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) ...@@ -240,7 +235,7 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
* *
* For the DMA destination buffer, we use a bounce buffer. * For the DMA destination buffer, we use a bounce buffer.
*/ */
if (hantro_is_encoder_ctx(ctx)) { if (ctx->is_encoder) {
dst_vq->mem_ops = &vb2_vmalloc_memops; dst_vq->mem_ops = &vb2_vmalloc_memops;
} else { } else {
dst_vq->bidirectional = true; dst_vq->bidirectional = true;
...@@ -420,8 +415,10 @@ static int hantro_open(struct file *filp) ...@@ -420,8 +415,10 @@ static int hantro_open(struct file *filp)
if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) { if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS; allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS;
ctx->buf_finish = hantro_enc_buf_finish; ctx->buf_finish = hantro_enc_buf_finish;
ctx->is_encoder = true;
} else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) { } else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) {
allowed_codecs = vpu->variant->codec & HANTRO_DECODERS; allowed_codecs = vpu->variant->codec & HANTRO_DECODERS;
ctx->is_encoder = false;
} else { } else {
ret = -ENODEV; ret = -ENODEV;
goto err_ctx_free; goto err_ctx_free;
......
...@@ -40,7 +40,7 @@ hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts) ...@@ -40,7 +40,7 @@ hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts)
{ {
const struct hantro_fmt *formats; const struct hantro_fmt *formats;
if (hantro_is_encoder_ctx(ctx)) { if (ctx->is_encoder) {
formats = ctx->dev->variant->enc_fmts; formats = ctx->dev->variant->enc_fmts;
*num_fmts = ctx->dev->variant->num_enc_fmts; *num_fmts = ctx->dev->variant->num_enc_fmts;
} else { } else {
...@@ -55,7 +55,7 @@ static const struct hantro_fmt * ...@@ -55,7 +55,7 @@ static const struct hantro_fmt *
hantro_get_postproc_formats(const struct hantro_ctx *ctx, hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts) unsigned int *num_fmts)
{ {
if (hantro_is_encoder_ctx(ctx)) { if (ctx->is_encoder) {
*num_fmts = 0; *num_fmts = 0;
return NULL; return NULL;
} }
...@@ -158,7 +158,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv, ...@@ -158,7 +158,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
* not MODE_NONE. * not MODE_NONE.
* - on the output side we want to filter out all MODE_NONE formats. * - on the output side we want to filter out all MODE_NONE formats.
*/ */
skip_mode_none = capture == hantro_is_encoder_ctx(ctx); skip_mode_none = capture == ctx->is_encoder;
formats = hantro_get_formats(ctx, &num_fmts); formats = hantro_get_formats(ctx, &num_fmts);
for (i = 0; i < num_fmts; i++) { for (i = 0; i < num_fmts; i++) {
...@@ -240,7 +240,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx, ...@@ -240,7 +240,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
bool capture = V4L2_TYPE_IS_CAPTURE(type); bool capture = V4L2_TYPE_IS_CAPTURE(type);
bool coded; bool coded;
coded = capture == hantro_is_encoder_ctx(ctx); coded = capture == ctx->is_encoder;
vpu_debug(4, "trying format %c%c%c%c\n", vpu_debug(4, "trying format %c%c%c%c\n",
(pix_mp->pixelformat & 0x7f), (pix_mp->pixelformat & 0x7f),
...@@ -257,7 +257,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx, ...@@ -257,7 +257,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
if (coded) { if (coded) {
pix_mp->num_planes = 1; pix_mp->num_planes = 1;
vpu_fmt = fmt; vpu_fmt = fmt;
} else if (hantro_is_encoder_ctx(ctx)) { } else if (ctx->is_encoder) {
vpu_fmt = ctx->vpu_dst_fmt; vpu_fmt = ctx->vpu_dst_fmt;
} else { } else {
vpu_fmt = ctx->vpu_src_fmt; vpu_fmt = ctx->vpu_src_fmt;
...@@ -330,7 +330,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) ...@@ -330,7 +330,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
vpu_fmt = hantro_get_default_fmt(ctx, true); vpu_fmt = hantro_get_default_fmt(ctx, true);
if (hantro_is_encoder_ctx(ctx)) { if (ctx->is_encoder) {
ctx->vpu_dst_fmt = vpu_fmt; ctx->vpu_dst_fmt = vpu_fmt;
fmt = &ctx->dst_fmt; fmt = &ctx->dst_fmt;
} else { } else {
...@@ -341,7 +341,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) ...@@ -341,7 +341,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
hantro_reset_fmt(fmt, vpu_fmt); hantro_reset_fmt(fmt, vpu_fmt);
fmt->width = vpu_fmt->frmsize.min_width; fmt->width = vpu_fmt->frmsize.min_width;
fmt->height = vpu_fmt->frmsize.min_height; fmt->height = vpu_fmt->frmsize.min_height;
if (hantro_is_encoder_ctx(ctx)) if (ctx->is_encoder)
hantro_set_fmt_cap(ctx, fmt); hantro_set_fmt_cap(ctx, fmt);
else else
hantro_set_fmt_out(ctx, fmt); hantro_set_fmt_out(ctx, fmt);
...@@ -355,7 +355,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx) ...@@ -355,7 +355,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx)
raw_vpu_fmt = hantro_get_default_fmt(ctx, false); raw_vpu_fmt = hantro_get_default_fmt(ctx, false);
if (hantro_is_encoder_ctx(ctx)) { if (ctx->is_encoder) {
ctx->vpu_src_fmt = raw_vpu_fmt; ctx->vpu_src_fmt = raw_vpu_fmt;
raw_fmt = &ctx->src_fmt; raw_fmt = &ctx->src_fmt;
encoded_fmt = &ctx->dst_fmt; encoded_fmt = &ctx->dst_fmt;
...@@ -368,7 +368,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx) ...@@ -368,7 +368,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx)
hantro_reset_fmt(raw_fmt, raw_vpu_fmt); hantro_reset_fmt(raw_fmt, raw_vpu_fmt);
raw_fmt->width = encoded_fmt->width; raw_fmt->width = encoded_fmt->width;
raw_fmt->width = encoded_fmt->width; raw_fmt->width = encoded_fmt->width;
if (hantro_is_encoder_ctx(ctx)) if (ctx->is_encoder)
hantro_set_fmt_out(ctx, raw_fmt); hantro_set_fmt_out(ctx, raw_fmt);
else else
hantro_set_fmt_cap(ctx, raw_fmt); hantro_set_fmt_cap(ctx, raw_fmt);
...@@ -409,7 +409,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, ...@@ -409,7 +409,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,
if (ret) if (ret)
return ret; return ret;
if (!hantro_is_encoder_ctx(ctx)) { if (!ctx->is_encoder) {
struct vb2_queue *peer_vq; struct vb2_queue *peer_vq;
/* /*
...@@ -450,7 +450,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, ...@@ -450,7 +450,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,
* Note that hantro_reset_raw_fmt() also propagates size * Note that hantro_reset_raw_fmt() also propagates size
* changes to the raw format. * changes to the raw format.
*/ */
if (!hantro_is_encoder_ctx(ctx)) if (!ctx->is_encoder)
hantro_reset_raw_fmt(ctx); hantro_reset_raw_fmt(ctx);
/* Colorimetry information are always propagated. */ /* Colorimetry information are always propagated. */
...@@ -479,7 +479,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, ...@@ -479,7 +479,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
if (vb2_is_busy(vq)) if (vb2_is_busy(vq))
return -EBUSY; return -EBUSY;
if (hantro_is_encoder_ctx(ctx)) { if (ctx->is_encoder) {
struct vb2_queue *peer_vq; struct vb2_queue *peer_vq;
/* /*
...@@ -512,7 +512,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, ...@@ -512,7 +512,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx,
* Note that hantro_reset_raw_fmt() also propagates size * Note that hantro_reset_raw_fmt() also propagates size
* changes to the raw format. * changes to the raw format.
*/ */
if (hantro_is_encoder_ctx(ctx)) if (ctx->is_encoder)
hantro_reset_raw_fmt(ctx); hantro_reset_raw_fmt(ctx);
/* Colorimetry information are always propagated. */ /* Colorimetry information are always propagated. */
...@@ -655,7 +655,7 @@ static bool hantro_vq_is_coded(struct vb2_queue *q) ...@@ -655,7 +655,7 @@ static bool hantro_vq_is_coded(struct vb2_queue *q)
{ {
struct hantro_ctx *ctx = vb2_get_drv_priv(q); struct hantro_ctx *ctx = vb2_get_drv_priv(q);
return hantro_is_encoder_ctx(ctx) != V4L2_TYPE_IS_OUTPUT(q->type); return ctx->is_encoder != V4L2_TYPE_IS_OUTPUT(q->type);
} }
static int hantro_start_streaming(struct vb2_queue *q, unsigned int count) static int hantro_start_streaming(struct vb2_queue *q, unsigned int count)
......
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