linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] Hantro low-hanging cleanups
@ 2020-06-25 16:35 Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 1/6] hantro: h264: Remove unused macro definition Ezequiel Garcia
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

Tackle some low hanging items. There's not much to say here,
see the patches for details.

We'll be soon posting more interesting changes :)

Thanks,
Ezequiel

Ezequiel Garcia (6):
  hantro: h264: Remove unused macro definition
  hantro: h264: Rename scaling list handling function
  hantro: Rework how encoder and decoder are identified
  hantro: Move hantro_enc_buf_finish to JPEG codec_ops.done
  hantro: Remove unused bytesused argument
  hantro: Make sure we don't use post-processor on an encoder

 drivers/staging/media/hantro/hantro.h         |  9 +--
 drivers/staging/media/hantro/hantro_drv.c     | 60 ++++++-------------
 .../staging/media/hantro/hantro_h1_jpeg_enc.c | 17 ++++++
 drivers/staging/media/hantro/hantro_h264.c    |  6 +-
 drivers/staging/media/hantro/hantro_hw.h      |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   |  2 +-
 drivers/staging/media/hantro/rk3288_vpu_hw.c  |  8 +--
 drivers/staging/media/hantro/rk3399_vpu_hw.c  |  7 +--
 8 files changed, 49 insertions(+), 65 deletions(-)

-- 
2.26.0.rc2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/6] hantro: h264: Remove unused macro definition
  2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
@ 2020-06-25 16:35 ` Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 2/6] hantro: h264: Rename scaling list handling function Ezequiel Garcia
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

The generic H264 reference list builder moved all
the users of this macro, but left the macro.

Remove it.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/hantro/hantro_h264.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_h264.c b/drivers/staging/media/hantro/hantro_h264.c
index d561f125085a..dd935d7009bf 100644
--- a/drivers/staging/media/hantro/hantro_h264.c
+++ b/drivers/staging/media/hantro/hantro_h264.c
@@ -22,8 +22,6 @@
 #define POC_BUFFER_SIZE			34
 #define SCALING_LIST_SIZE		(6 * 16 + 2 * 64)
 
-#define HANTRO_CMP(a, b) ((a) < (b) ? -1 : 1)
-
 /* Data structure describing auxiliary buffer format. */
 struct hantro_h264_dec_priv_tbl {
 	u32 cabac_table[CABAC_INIT_BUFFER_SIZE];
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/6] hantro: h264: Rename scaling list handling function
  2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 1/6] hantro: h264: Remove unused macro definition Ezequiel Garcia
@ 2020-06-25 16:35 ` Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 3/6] hantro: Rework how encoder and decoder are identified Ezequiel Garcia
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

Commit e17f08e3166 ("media: hantro: Do not reorder
H264 scaling list") removed the scaling list reordering,
which was wrong and not needed.

However, the name of the function stayed, which is
confusing for anyone reading the code. Rename
from "reorder" to "assemble" which is cleaner.

This is just a cosmetic cleanup.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/hantro/hantro_h264.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_h264.c b/drivers/staging/media/hantro/hantro_h264.c
index dd935d7009bf..194d05848077 100644
--- a/drivers/staging/media/hantro/hantro_h264.c
+++ b/drivers/staging/media/hantro/hantro_h264.c
@@ -193,7 +193,7 @@ static const u32 h264_cabac_table[] = {
 };
 
 static void
-reorder_scaling_list(struct hantro_ctx *ctx)
+assemble_scaling_list(struct hantro_ctx *ctx)
 {
 	const struct hantro_h264_dec_ctrls *ctrls = &ctx->h264_dec.ctrls;
 	const struct v4l2_ctrl_h264_scaling_matrix *scaling = ctrls->scaling;
@@ -235,7 +235,7 @@ static void prepare_table(struct hantro_ctx *ctx)
 	tbl->poc[32] = dec_param->top_field_order_cnt;
 	tbl->poc[33] = dec_param->bottom_field_order_cnt;
 
-	reorder_scaling_list(ctx);
+	assemble_scaling_list(ctx);
 }
 
 static bool dpb_entry_match(const struct v4l2_h264_dpb_entry *a,
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/6] hantro: Rework how encoder and decoder are identified
  2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 1/6] hantro: h264: Remove unused macro definition Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 2/6] hantro: h264: Rename scaling list handling function Ezequiel Garcia
@ 2020-06-25 16:35 ` Ezequiel Garcia
  2020-06-26  7:58   ` Philipp Zabel
  2020-06-26  9:52   ` Robin Murphy
  2020-06-25 16:35 ` [PATCH 4/6] hantro: Move hantro_enc_buf_finish to JPEG codec_ops.done Ezequiel Garcia
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

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 <ezequiel@collabora.com>
---
 drivers/staging/media/hantro/hantro.h     | 2 ++
 drivers/staging/media/hantro/hantro_drv.c | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
index 3005207fc6fb..028b788ad50f 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;
diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 0db8ad455160..112ed556eb90 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -197,7 +197,7 @@ static void device_run(void *priv)
 
 bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
 {
-	return ctx->buf_finish == hantro_enc_buf_finish;
+	return ctx->is_encoder;
 }
 
 static struct v4l2_m2m_ops vpu_m2m_ops = {
@@ -420,8 +420,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;
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/6] hantro: Move hantro_enc_buf_finish to JPEG codec_ops.done
  2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
                   ` (2 preceding siblings ...)
  2020-06-25 16:35 ` [PATCH 3/6] hantro: Rework how encoder and decoder are identified Ezequiel Garcia
@ 2020-06-25 16:35 ` Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 5/6] hantro: Remove unused bytesused argument Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 6/6] hantro: Make sure we don't use post-processor on an encoder Ezequiel Garcia
  5 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

hantro_enc_buf_finish is used only for JPEG, and so should
be moved to JPEG codec_ops.done.

This cleanup is also taking care of addressing
a subtle issue: checking the non-NULL bounce buffer
using ctx->jpeg_enc, which is a member of a union is
confusing and error-prone.

Note that the issue is currently innocuous because an
encoder context only supports JPEG.

The codec_ops.done has an argument that codec-specific code
shouldn't need, so drop that as well.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/hantro/hantro.h         |  7 ----
 drivers/staging/media/hantro/hantro_drv.c     | 37 ++-----------------
 .../staging/media/hantro/hantro_h1_jpeg_enc.c | 17 +++++++++
 drivers/staging/media/hantro/hantro_hw.h      |  3 +-
 drivers/staging/media/hantro/rk3288_vpu_hw.c  |  1 +
 5 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
index 028b788ad50f..0cba5fc3fa1f 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -212,9 +212,6 @@ struct hantro_dev {
  * @ctrl_handler:	Control handler used to register controls.
  * @jpeg_quality:	User-specified JPEG compression quality.
  *
- * @buf_finish:		Buffer finish. This depends on encoder or decoder
- *			context, and it's called right before
- *			calling v4l2_m2m_job_finish.
  * @codec_ops:		Set of operations related to codec mode.
  * @postproc:		Post-processing context.
  * @jpeg_enc:		JPEG-encoding context.
@@ -237,10 +234,6 @@ struct hantro_ctx {
 	struct v4l2_ctrl_handler ctrl_handler;
 	int jpeg_quality;
 
-	int (*buf_finish)(struct hantro_ctx *ctx,
-			  struct vb2_buffer *buf,
-			  unsigned int bytesused);
-
 	const struct hantro_codec_ops *codec_ops;
 	struct hantro_postproc_ctx postproc;
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 112ed556eb90..d1fcf41023f9 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -56,37 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
 	return hantro_get_dec_buf_addr(ctx, buf);
 }
 
-static int
-hantro_enc_buf_finish(struct hantro_ctx *ctx, struct vb2_buffer *buf,
-		      unsigned int bytesused)
-{
-	size_t avail_size;
-
-	avail_size = vb2_plane_size(buf, 0) - ctx->vpu_dst_fmt->header_size;
-	if (bytesused > avail_size)
-		return -EINVAL;
-	/*
-	 * The bounce buffer is only for the JPEG encoder.
-	 * TODO: Rework the JPEG encoder to eliminate the need
-	 * for a bounce buffer.
-	 */
-	if (ctx->jpeg_enc.bounce_buffer.cpu) {
-		memcpy(vb2_plane_vaddr(buf, 0) +
-		       ctx->vpu_dst_fmt->header_size,
-		       ctx->jpeg_enc.bounce_buffer.cpu, bytesused);
-	}
-	buf->planes[0].bytesused =
-		ctx->vpu_dst_fmt->header_size + bytesused;
-	return 0;
-}
-
 static void hantro_job_finish(struct hantro_dev *vpu,
 			      struct hantro_ctx *ctx,
 			      unsigned int bytesused,
 			      enum vb2_buffer_state result)
 {
 	struct vb2_v4l2_buffer *src, *dst;
-	int ret;
 
 	pm_runtime_mark_last_busy(vpu->dev);
 	pm_runtime_put_autosuspend(vpu->dev);
@@ -103,12 +78,6 @@ static void hantro_job_finish(struct hantro_dev *vpu,
 	src->sequence = ctx->sequence_out++;
 	dst->sequence = ctx->sequence_cap++;
 
-	if (ctx->buf_finish) {
-		ret = ctx->buf_finish(ctx, &dst->vb2_buf, bytesused);
-		if (ret)
-			result = VB2_BUF_STATE_ERROR;
-	}
-
 	v4l2_m2m_buf_done_and_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx,
 					 result);
 }
@@ -124,8 +93,11 @@ void hantro_irq_done(struct hantro_dev *vpu, unsigned int bytesused,
 	 * the timeout expired. The watchdog is running,
 	 * and will take care of finishing the job.
 	 */
-	if (cancel_delayed_work(&vpu->watchdog_work))
+	if (cancel_delayed_work(&vpu->watchdog_work)) {
+		if (result == VB2_BUF_STATE_DONE && ctx->codec_ops->done)
+			ctx->codec_ops->done(ctx);
 		hantro_job_finish(vpu, ctx, bytesused, result);
+	}
 }
 
 void hantro_watchdog(struct work_struct *work)
@@ -419,7 +391,6 @@ static int hantro_open(struct file *filp)
 	ctx->dev = vpu;
 	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;
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b22418436823..b88dc4ed06db 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -137,3 +137,20 @@ void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 
 	vepu_write(vpu, reg, H1_REG_ENC_CTRL);
 }
+
+void hantro_jpeg_enc_done(struct hantro_ctx *ctx)
+{
+	struct hantro_dev *vpu = ctx->dev;
+	u32 bytesused = vepu_read(vpu, H1_REG_STR_BUF_LIMIT) / 8;
+	struct vb2_v4l2_buffer *dst_buf = hantro_get_dst_buf(ctx);
+
+	/*
+	 * TODO: Rework the JPEG encoder to eliminate the need
+	 * for a bounce buffer.
+	 */
+	memcpy(vb2_plane_vaddr(&dst_buf->vb2_buf, 0) +
+	       ctx->vpu_dst_fmt->header_size,
+	       ctx->jpeg_enc.bounce_buffer.cpu, bytesused);
+	vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+			      ctx->vpu_dst_fmt->header_size + bytesused);
+}
diff --git a/drivers/staging/media/hantro/hantro_hw.h b/drivers/staging/media/hantro/hantro_hw.h
index 4053d8710e04..2d6323cd6732 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -138,7 +138,7 @@ struct hantro_codec_ops {
 	int (*init)(struct hantro_ctx *ctx);
 	void (*exit)(struct hantro_ctx *ctx);
 	void (*run)(struct hantro_ctx *ctx);
-	void (*done)(struct hantro_ctx *ctx, enum vb2_buffer_state);
+	void (*done)(struct hantro_ctx *ctx);
 	void (*reset)(struct hantro_ctx *ctx);
 };
 
@@ -172,6 +172,7 @@ void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
 void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx);
 int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
 void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
+void hantro_jpeg_enc_done(struct hantro_ctx *ctx);
 
 dma_addr_t hantro_h264_get_ref_buf(struct hantro_ctx *ctx,
 				   unsigned int dpb_idx);
diff --git a/drivers/staging/media/hantro/rk3288_vpu_hw.c b/drivers/staging/media/hantro/rk3288_vpu_hw.c
index 2f914b37b9e5..b1cf2abb972f 100644
--- a/drivers/staging/media/hantro/rk3288_vpu_hw.c
+++ b/drivers/staging/media/hantro/rk3288_vpu_hw.c
@@ -180,6 +180,7 @@ static const struct hantro_codec_ops rk3288_vpu_codec_ops[] = {
 		.run = hantro_h1_jpeg_enc_run,
 		.reset = rk3288_vpu_enc_reset,
 		.init = hantro_jpeg_enc_init,
+		.done = hantro_jpeg_enc_done,
 		.exit = hantro_jpeg_enc_exit,
 	},
 	[HANTRO_MODE_H264_DEC] = {
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/6] hantro: Remove unused bytesused argument
  2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
                   ` (3 preceding siblings ...)
  2020-06-25 16:35 ` [PATCH 4/6] hantro: Move hantro_enc_buf_finish to JPEG codec_ops.done Ezequiel Garcia
@ 2020-06-25 16:35 ` Ezequiel Garcia
  2020-06-25 16:35 ` [PATCH 6/6] hantro: Make sure we don't use post-processor on an encoder Ezequiel Garcia
  5 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

The driver doesn't need the bytesused argument.

For decoders, the plane bytesused is known and therefore,
buf_prepare is used to set it. For encoders, it's
handled by the codec_ops.done hook.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/hantro/hantro_drv.c    | 9 ++++-----
 drivers/staging/media/hantro/hantro_hw.h     | 2 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c  | 2 +-
 drivers/staging/media/hantro/rk3288_vpu_hw.c | 7 +++----
 drivers/staging/media/hantro/rk3399_vpu_hw.c | 7 +++----
 5 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index d1fcf41023f9..0936f0c41af9 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -58,7 +58,6 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
 
 static void hantro_job_finish(struct hantro_dev *vpu,
 			      struct hantro_ctx *ctx,
-			      unsigned int bytesused,
 			      enum vb2_buffer_state result)
 {
 	struct vb2_v4l2_buffer *src, *dst;
@@ -82,7 +81,7 @@ static void hantro_job_finish(struct hantro_dev *vpu,
 					 result);
 }
 
-void hantro_irq_done(struct hantro_dev *vpu, unsigned int bytesused,
+void hantro_irq_done(struct hantro_dev *vpu,
 		     enum vb2_buffer_state result)
 {
 	struct hantro_ctx *ctx =
@@ -96,7 +95,7 @@ void hantro_irq_done(struct hantro_dev *vpu, unsigned int bytesused,
 	if (cancel_delayed_work(&vpu->watchdog_work)) {
 		if (result == VB2_BUF_STATE_DONE && ctx->codec_ops->done)
 			ctx->codec_ops->done(ctx);
-		hantro_job_finish(vpu, ctx, bytesused, result);
+		hantro_job_finish(vpu, ctx, result);
 	}
 }
 
@@ -111,7 +110,7 @@ void hantro_watchdog(struct work_struct *work)
 	if (ctx) {
 		vpu_err("frame processing timed out!\n");
 		ctx->codec_ops->reset(ctx);
-		hantro_job_finish(vpu, ctx, 0, VB2_BUF_STATE_ERROR);
+		hantro_job_finish(vpu, ctx, VB2_BUF_STATE_ERROR);
 	}
 }
 
@@ -164,7 +163,7 @@ static void device_run(void *priv)
 	return;
 
 err_cancel_job:
-	hantro_job_finish(ctx->dev, ctx, 0, VB2_BUF_STATE_ERROR);
+	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
 }
 
 bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
diff --git a/drivers/staging/media/hantro/hantro_hw.h b/drivers/staging/media/hantro/hantro_hw.h
index 2d6323cd6732..f066de6b592d 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -163,7 +163,7 @@ extern const u32 hantro_vp8_dec_mc_filter[8][6];
 
 void hantro_watchdog(struct work_struct *work);
 void hantro_run(struct hantro_ctx *ctx);
-void hantro_irq_done(struct hantro_dev *vpu, unsigned int bytesused,
+void hantro_irq_done(struct hantro_dev *vpu,
 		     enum vb2_buffer_state result);
 void hantro_start_prepare_run(struct hantro_ctx *ctx);
 void hantro_end_prepare_run(struct hantro_ctx *ctx);
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index cb2420c5526e..c222de075ef4 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -143,7 +143,7 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 	vdpu_write(vpu, 0, G1_REG_INTERRUPT);
 	vdpu_write(vpu, G1_REG_CONFIG_DEC_CLK_GATE_E, G1_REG_CONFIG);
 
-	hantro_irq_done(vpu, 0, state);
+	hantro_irq_done(vpu, state);
 
 	return IRQ_HANDLED;
 }
diff --git a/drivers/staging/media/hantro/rk3288_vpu_hw.c b/drivers/staging/media/hantro/rk3288_vpu_hw.c
index b1cf2abb972f..7b299ee3e93d 100644
--- a/drivers/staging/media/hantro/rk3288_vpu_hw.c
+++ b/drivers/staging/media/hantro/rk3288_vpu_hw.c
@@ -113,17 +113,16 @@ static irqreturn_t rk3288_vepu_irq(int irq, void *dev_id)
 {
 	struct hantro_dev *vpu = dev_id;
 	enum vb2_buffer_state state;
-	u32 status, bytesused;
+	u32 status;
 
 	status = vepu_read(vpu, H1_REG_INTERRUPT);
-	bytesused = vepu_read(vpu, H1_REG_STR_BUF_LIMIT) / 8;
 	state = (status & H1_REG_INTERRUPT_FRAME_RDY) ?
 		VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
 
 	vepu_write(vpu, 0, H1_REG_INTERRUPT);
 	vepu_write(vpu, 0, H1_REG_AXI_CTRL);
 
-	hantro_irq_done(vpu, bytesused, state);
+	hantro_irq_done(vpu, state);
 
 	return IRQ_HANDLED;
 }
@@ -141,7 +140,7 @@ static irqreturn_t rk3288_vdpu_irq(int irq, void *dev_id)
 	vdpu_write(vpu, 0, G1_REG_INTERRUPT);
 	vdpu_write(vpu, G1_REG_CONFIG_DEC_CLK_GATE_E, G1_REG_CONFIG);
 
-	hantro_irq_done(vpu, 0, state);
+	hantro_irq_done(vpu, state);
 
 	return IRQ_HANDLED;
 }
diff --git a/drivers/staging/media/hantro/rk3399_vpu_hw.c b/drivers/staging/media/hantro/rk3399_vpu_hw.c
index 9ac1f2cb6a16..7a7962cf771e 100644
--- a/drivers/staging/media/hantro/rk3399_vpu_hw.c
+++ b/drivers/staging/media/hantro/rk3399_vpu_hw.c
@@ -92,17 +92,16 @@ static irqreturn_t rk3399_vepu_irq(int irq, void *dev_id)
 {
 	struct hantro_dev *vpu = dev_id;
 	enum vb2_buffer_state state;
-	u32 status, bytesused;
+	u32 status;
 
 	status = vepu_read(vpu, VEPU_REG_INTERRUPT);
-	bytesused = vepu_read(vpu, VEPU_REG_STR_BUF_LIMIT) / 8;
 	state = (status & VEPU_REG_INTERRUPT_FRAME_READY) ?
 		VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
 
 	vepu_write(vpu, 0, VEPU_REG_INTERRUPT);
 	vepu_write(vpu, 0, VEPU_REG_AXI_CTRL);
 
-	hantro_irq_done(vpu, bytesused, state);
+	hantro_irq_done(vpu, state);
 
 	return IRQ_HANDLED;
 }
@@ -120,7 +119,7 @@ static irqreturn_t rk3399_vdpu_irq(int irq, void *dev_id)
 	vdpu_write(vpu, 0, VDPU_REG_INTERRUPT);
 	vdpu_write(vpu, 0, VDPU_REG_AXI_CTRL);
 
-	hantro_irq_done(vpu, 0, state);
+	hantro_irq_done(vpu, state);
 
 	return IRQ_HANDLED;
 }
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/6] hantro: Make sure we don't use post-processor on an encoder
  2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
                   ` (4 preceding siblings ...)
  2020-06-25 16:35 ` [PATCH 5/6] hantro: Remove unused bytesused argument Ezequiel Garcia
@ 2020-06-25 16:35 ` Ezequiel Garcia
  5 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-25 16:35 UTC (permalink / raw)
  To: linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil, Philipp Zabel, Ezequiel Garcia

Commit 986eee3a5234f fixed hantro_needs_postproc condition,
but missed one case. Encoders don't have any post-processor
hardware block, so also can't be disabled.

Fix it.

Fixes: 986eee3a5234f ("media: hantro: Prevent encoders from using post-processing")
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/hantro/hantro_drv.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 0936f0c41af9..b622bbe181c1 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -122,10 +122,12 @@ void hantro_start_prepare_run(struct hantro_ctx *ctx)
 	v4l2_ctrl_request_setup(src_buf->vb2_buf.req_obj.req,
 				&ctx->ctrl_handler);
 
-	if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
-		hantro_postproc_enable(ctx);
-	else
-		hantro_postproc_disable(ctx);
+	if (!hantro_is_encoder_ctx(ctx)) {
+		if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+			hantro_postproc_enable(ctx);
+		else
+			hantro_postproc_disable(ctx);
+	}
 }
 
 void hantro_end_prepare_run(struct hantro_ctx *ctx)
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/6] hantro: Rework how encoder and decoder are identified
  2020-06-25 16:35 ` [PATCH 3/6] hantro: Rework how encoder and decoder are identified Ezequiel Garcia
@ 2020-06-26  7:58   ` Philipp Zabel
  2020-06-26 18:30     ` Ezequiel Garcia
  2020-06-26  9:52   ` Robin Murphy
  1 sibling, 1 reply; 11+ messages in thread
From: Philipp Zabel @ 2020-06-26  7:58 UTC (permalink / raw)
  To: Ezequiel Garcia, linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil

Hi Ezequiel,

On Thu, 2020-06-25 at 13:35 -0300, Ezequiel Garcia wrote:
> 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 <ezequiel@collabora.com>
> ---
>  drivers/staging/media/hantro/hantro.h     | 2 ++
>  drivers/staging/media/hantro/hantro_drv.c | 4 +++-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
> index 3005207fc6fb..028b788ad50f 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;
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 0db8ad455160..112ed556eb90 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -197,7 +197,7 @@ static void device_run(void *priv)
>  
>  bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
>  {
> -	return ctx->buf_finish == hantro_enc_buf_finish;
> +	return ctx->is_encoder;
>  }

Now this function feels a little superfluous. Why not replace
  hantro_is_encoder_ctx(ctx)
with
  ctx->is_encoder
everywhere?

regards
Philipp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/6] hantro: Rework how encoder and decoder are identified
  2020-06-25 16:35 ` [PATCH 3/6] hantro: Rework how encoder and decoder are identified Ezequiel Garcia
  2020-06-26  7:58   ` Philipp Zabel
@ 2020-06-26  9:52   ` Robin Murphy
  2020-06-26 18:31     ` Ezequiel Garcia
  1 sibling, 1 reply; 11+ messages in thread
From: Robin Murphy @ 2020-06-26  9:52 UTC (permalink / raw)
  To: Ezequiel Garcia, linux-media, linux-rockchip, linux-kernel
  Cc: Hans Verkuil, kernel, Philipp Zabel

Hi Ezequiel,

On 2020-06-25 17:35, Ezequiel Garcia wrote:
> 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 <ezequiel@collabora.com>
> ---
>   drivers/staging/media/hantro/hantro.h     | 2 ++
>   drivers/staging/media/hantro/hantro_drv.c | 4 +++-
>   2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
> index 3005207fc6fb..028b788ad50f 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;
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 0db8ad455160..112ed556eb90 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -197,7 +197,7 @@ static void device_run(void *priv)
>   
>   bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
>   {
> -	return ctx->buf_finish == hantro_enc_buf_finish;
> +	return ctx->is_encoder;

FWIW I'd suggest removing the wrapper function entirely now - it makes 
sense when the check itself is implemented in a weird and non-obvious 
way, but a simple boolean flag named exactly what it means is already 
about as clear as it can get.

Robin.

>   }
>   
>   static struct v4l2_m2m_ops vpu_m2m_ops = {
> @@ -420,8 +420,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;
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/6] hantro: Rework how encoder and decoder are identified
  2020-06-26  7:58   ` Philipp Zabel
@ 2020-06-26 18:30     ` Ezequiel Garcia
  0 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-26 18:30 UTC (permalink / raw)
  To: Philipp Zabel, linux-media, linux-rockchip, linux-kernel
  Cc: kernel, Hans Verkuil

On Fri, 2020-06-26 at 09:58 +0200, Philipp Zabel wrote:
> Hi Ezequiel,
> 
> On Thu, 2020-06-25 at 13:35 -0300, Ezequiel Garcia wrote:
> > 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 <ezequiel@collabora.com>
> > ---
> >  drivers/staging/media/hantro/hantro.h     | 2 ++
> >  drivers/staging/media/hantro/hantro_drv.c | 4 +++-
> >  2 files changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
> > index 3005207fc6fb..028b788ad50f 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;
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> > index 0db8ad455160..112ed556eb90 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -197,7 +197,7 @@ static void device_run(void *priv)
> >  
> >  bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
> >  {
> > -	return ctx->buf_finish == hantro_enc_buf_finish;
> > +	return ctx->is_encoder;
> >  }
> 
> Now this function feels a little superfluous. Why not replace
>   hantro_is_encoder_ctx(ctx)
> with
>   ctx->is_encoder
> everywhere?
> 

Absolutely.

Thanks for reviewing,
Ezequiel


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/6] hantro: Rework how encoder and decoder are identified
  2020-06-26  9:52   ` Robin Murphy
@ 2020-06-26 18:31     ` Ezequiel Garcia
  0 siblings, 0 replies; 11+ messages in thread
From: Ezequiel Garcia @ 2020-06-26 18:31 UTC (permalink / raw)
  To: Robin Murphy, linux-media, linux-rockchip, linux-kernel
  Cc: Hans Verkuil, kernel, Philipp Zabel

On Fri, 2020-06-26 at 10:52 +0100, Robin Murphy wrote:
> Hi Ezequiel,
> 
> On 2020-06-25 17:35, Ezequiel Garcia wrote:
> > 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 <ezequiel@collabora.com>
> > ---
> >   drivers/staging/media/hantro/hantro.h     | 2 ++
> >   drivers/staging/media/hantro/hantro_drv.c | 4 +++-
> >   2 files changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
> > index 3005207fc6fb..028b788ad50f 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;
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> > index 0db8ad455160..112ed556eb90 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -197,7 +197,7 @@ static void device_run(void *priv)
> >   
> >   bool hantro_is_encoder_ctx(const struct hantro_ctx *ctx)
> >   {
> > -	return ctx->buf_finish == hantro_enc_buf_finish;
> > +	return ctx->is_encoder;
> 
> FWIW I'd suggest removing the wrapper function entirely now - it makes 
> sense when the check itself is implemented in a weird and non-obvious 
> way, but a simple boolean flag named exactly what it means is already 
> about as clear as it can get.
> 

Indeed, Philipp pointed out the same thing.

Makes perfect sense, and thanks a lot for reviewing.

Ezequiel


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-06-26 18:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25 16:35 [PATCH 0/6] Hantro low-hanging cleanups Ezequiel Garcia
2020-06-25 16:35 ` [PATCH 1/6] hantro: h264: Remove unused macro definition Ezequiel Garcia
2020-06-25 16:35 ` [PATCH 2/6] hantro: h264: Rename scaling list handling function Ezequiel Garcia
2020-06-25 16:35 ` [PATCH 3/6] hantro: Rework how encoder and decoder are identified Ezequiel Garcia
2020-06-26  7:58   ` Philipp Zabel
2020-06-26 18:30     ` Ezequiel Garcia
2020-06-26  9:52   ` Robin Murphy
2020-06-26 18:31     ` Ezequiel Garcia
2020-06-25 16:35 ` [PATCH 4/6] hantro: Move hantro_enc_buf_finish to JPEG codec_ops.done Ezequiel Garcia
2020-06-25 16:35 ` [PATCH 5/6] hantro: Remove unused bytesused argument Ezequiel Garcia
2020-06-25 16:35 ` [PATCH 6/6] hantro: Make sure we don't use post-processor on an encoder Ezequiel Garcia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).