From patchwork Wed Jul 1 13:16:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 11636327 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6784A739 for ; Wed, 1 Jul 2020 13:16:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E11420780 for ; Wed, 1 Jul 2020 13:16:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sUebkVht" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E11420780 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aQSoCiVjtk5geo47Y5LiFhz0KPPiYpHLDHUE0yvhVAw=; b=sUebkVhtw6CukR7aXAtaEen7o y0dp23YKQdhquAICRxX2q34FVavONY+YKTfqi2Jvw3xvjXIBxuNDwvJpmRvC00xnpM+Cfb8aI2I7Q aVHo7SYELmJ2ckasRYYuKwGLoMI74P7IIZ1/ObyQa4TnNDc/UzLkReC0dqUpppKZPNEChYx3tErmy 3IQzONp57rWvhiV/CABhek+DPT1tsOYufJ23TPiG2MqYdQIDiI14jozNSwPGpyry+jS61pDyd6ELE 7dwZ+USZKxPntW2YY1RyMos5/51TUgtfzkjcKoayT11c7JDMQMq4y31S+mZZQshAvh503K57Sly88 yexS8Wopg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqcbI-0005zL-Sb; Wed, 01 Jul 2020 13:16:32 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqcbF-0005yF-Qd for linux-rockchip@lists.infradead.org; Wed, 01 Jul 2020 13:16:31 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 606ED2A56A6 From: Ezequiel Garcia To: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] hantro: Rework how encoder and decoder are identified Date: Wed, 1 Jul 2020 10:16:04 -0300 Message-Id: <20200701131607.121988-4-ezequiel@collabora.com> X-Mailer: git-send-email 2.26.0.rc2 In-Reply-To: <20200701131607.121988-1-ezequiel@collabora.com> References: <20200701131607.121988-1-ezequiel@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200701_091630_248192_2A0B20EB X-CRM114-Status: GOOD ( 15.90 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [46.235.227.227 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Verkuil , kernel@collabora.com, Ezequiel Garcia , Philipp Zabel Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org 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: Ezequiel Garcia --- v2: * Get rid of the helper and simply use the flag, as pointed out by Robin and Philipp. --- drivers/staging/media/hantro/hantro.h | 6 ++--- drivers/staging/media/hantro/hantro_drv.c | 9 +++---- drivers/staging/media/hantro/hantro_v4l2.c | 28 +++++++++++----------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h index 3005207fc6fb..2284e23d8500 100644 --- a/drivers/staging/media/hantro/hantro.h +++ b/drivers/staging/media/hantro/hantro.h @@ -199,6 +199,7 @@ struct hantro_dev { * * @dev: VPU driver data to which the context belongs. * @fh: V4L2 file handler. + * @is_encoder: Decoder or encoder context? * * @sequence_cap: Sequence counter for capture queue * @sequence_out: Sequence counter for output queue @@ -223,6 +224,7 @@ struct hantro_dev { struct hantro_ctx { struct hantro_dev *dev; struct v4l2_fh fh; + bool is_encoder; u32 sequence_cap; u32 sequence_out; @@ -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); } -bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx); - void *hantro_get_ctrl(struct hantro_ctx *ctx, u32 id); dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts); @@ -420,7 +420,7 @@ static inline bool hantro_needs_postproc(const struct hantro_ctx *ctx, 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 diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c index 0db8ad455160..9145d02e5d3c 100644 --- a/drivers/staging/media/hantro/hantro_drv.c +++ b/drivers/staging/media/hantro/hantro_drv.c @@ -195,11 +195,6 @@ static void device_run(void *priv) 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 = { .device_run = device_run, }; @@ -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. */ - if (hantro_is_encoder_ctx(ctx)) { + if (ctx->is_encoder) { dst_vq->mem_ops = &vb2_vmalloc_memops; } else { dst_vq->bidirectional = true; @@ -420,8 +415,10 @@ static int hantro_open(struct file *filp) if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) { allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS; ctx->buf_finish = hantro_enc_buf_finish; + ctx->is_encoder = true; } else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) { allowed_codecs = vpu->variant->codec & HANTRO_DECODERS; + ctx->is_encoder = false; } else { ret = -ENODEV; goto err_ctx_free; diff --git a/drivers/staging/media/hantro/hantro_v4l2.c b/drivers/staging/media/hantro/hantro_v4l2.c index f28a94e2fa93..785d59331d7c 100644 --- a/drivers/staging/media/hantro/hantro_v4l2.c +++ b/drivers/staging/media/hantro/hantro_v4l2.c @@ -40,7 +40,7 @@ hantro_get_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts) { const struct hantro_fmt *formats; - if (hantro_is_encoder_ctx(ctx)) { + if (ctx->is_encoder) { formats = ctx->dev->variant->enc_fmts; *num_fmts = ctx->dev->variant->num_enc_fmts; } else { @@ -55,7 +55,7 @@ static const struct hantro_fmt * hantro_get_postproc_formats(const struct hantro_ctx *ctx, unsigned int *num_fmts) { - if (hantro_is_encoder_ctx(ctx)) { + if (ctx->is_encoder) { *num_fmts = 0; return NULL; } @@ -158,7 +158,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv, * not MODE_NONE. * - 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); for (i = 0; i < num_fmts; i++) { @@ -240,7 +240,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx, bool capture = !V4L2_TYPE_IS_OUTPUT(type); bool coded; - coded = capture == hantro_is_encoder_ctx(ctx); + coded = capture == ctx->is_encoder; vpu_debug(4, "trying format %c%c%c%c\n", (pix_mp->pixelformat & 0x7f), @@ -257,7 +257,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx, if (coded) { pix_mp->num_planes = 1; vpu_fmt = fmt; - } else if (hantro_is_encoder_ctx(ctx)) { + } else if (ctx->is_encoder) { vpu_fmt = ctx->vpu_dst_fmt; } else { vpu_fmt = ctx->vpu_src_fmt; @@ -330,7 +330,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) vpu_fmt = hantro_get_default_fmt(ctx, true); - if (hantro_is_encoder_ctx(ctx)) { + if (ctx->is_encoder) { ctx->vpu_dst_fmt = vpu_fmt; fmt = &ctx->dst_fmt; } else { @@ -341,7 +341,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) hantro_reset_fmt(fmt, vpu_fmt); fmt->width = vpu_fmt->frmsize.min_width; fmt->height = vpu_fmt->frmsize.min_height; - if (hantro_is_encoder_ctx(ctx)) + if (ctx->is_encoder) hantro_set_fmt_cap(ctx, fmt); else hantro_set_fmt_out(ctx, fmt); @@ -355,7 +355,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx) 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; raw_fmt = &ctx->src_fmt; encoded_fmt = &ctx->dst_fmt; @@ -368,7 +368,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx) hantro_reset_fmt(raw_fmt, raw_vpu_fmt); 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); else hantro_set_fmt_cap(ctx, raw_fmt); @@ -409,7 +409,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, if (ret) return ret; - if (!hantro_is_encoder_ctx(ctx)) { + if (!ctx->is_encoder) { struct vb2_queue *peer_vq; /* @@ -450,7 +450,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, * Note that hantro_reset_raw_fmt() also propagates size * changes to the raw format. */ - if (!hantro_is_encoder_ctx(ctx)) + if (!ctx->is_encoder) hantro_reset_raw_fmt(ctx); /* Colorimetry information are always propagated. */ @@ -479,7 +479,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, if (vb2_is_busy(vq)) return -EBUSY; - if (hantro_is_encoder_ctx(ctx)) { + if (ctx->is_encoder) { struct vb2_queue *peer_vq; /* @@ -512,7 +512,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, * Note that hantro_reset_raw_fmt() also propagates size * changes to the raw format. */ - if (hantro_is_encoder_ctx(ctx)) + if (ctx->is_encoder) hantro_reset_raw_fmt(ctx); /* Colorimetry information are always propagated. */ @@ -655,7 +655,7 @@ static bool hantro_vq_is_coded(struct vb2_queue *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)