linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benoit Parrot <bparrot@ti.com>
To: <linux-media@vger.kernel.org>, Hans Verkuil <hverkuil@xs4all.nl>
Cc: <linux-kernel@vger.kernel.org>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Jyri Sarha <jsarha@ti.com>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Benoit Parrot <bparrot@ti.com>
Subject: [Patch v2 31/35] media: ti-vpe: vpe: Make sure frame size dont exceed scaler capacity
Date: Fri, 18 Nov 2016 17:20:41 -0600	[thread overview]
Message-ID: <20161118232045.24665-32-bparrot@ti.com> (raw)
In-Reply-To: <20161118232045.24665-1-bparrot@ti.com>

When scaler is to be used we need to make sure that the input and
output frame size do not exceed the maximum frame sizes that the
scaler h/w can handle otherwise streaming stall as the scaler
cannot proceed.

The scaler buffer is limited to 2047 pixels (i.e. 11 bits) when
attempting anything larger (2048 for example) the scaler stalls.

Realistically in an mem2mem device we can only check for this type
of issue when start_streaming is called. We can't do it during the
try_fmt/s_fmt because we do not have all of the info needed at that
point. So instead when start_streaming is called we need to check
that the input and output frames size do not exceed the scaler's
capability. The only time larger frame size are allowed is when
the input frame szie is the same as the output frame size.

Now in the case where we need to fail, start_streaming must return
all previously queued buffer back otherwise the vb2 framework
will issue kernel WARN messages.
In this case we also give an error message.

Signed-off-by: Benoit Parrot <bparrot@ti.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/ti-vpe/sc.h  |  6 ++++
 drivers/media/platform/ti-vpe/vpe.c | 71 ++++++++++++++++++++++++++++---------
 2 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/sc.h b/drivers/media/platform/ti-vpe/sc.h
index d0aab5ef0eca..f1fe80b38c9f 100644
--- a/drivers/media/platform/ti-vpe/sc.h
+++ b/drivers/media/platform/ti-vpe/sc.h
@@ -173,6 +173,12 @@
 /* number of taps expected by the scaler in it's coefficient memory */
 #define SC_NUM_TAPS_MEM_ALIGN		8
 
+/* Maximum frame width the scaler can handle (in pixels) */
+#define SC_MAX_PIXEL_WIDTH		2047
+
+/* Maximum frame height the scaler can handle (in lines) */
+#define SC_MAX_PIXEL_HEIGHT		2047
+
 /*
  * coefficient memory size in bytes:
  * num phases x num sets(luma and chroma) x num taps(aligned) x coeff size
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index ebde4f4586e6..32489d6369ca 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2025,28 +2025,33 @@ static void vpe_buf_queue(struct vb2_buffer *vb)
 	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
-static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
+static int check_srcdst_sizes(struct vpe_ctx *ctx)
 {
-	struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+	struct vpe_q_data *s_q_data =  &ctx->q_data[Q_DATA_SRC];
+	struct vpe_q_data *d_q_data =  &ctx->q_data[Q_DATA_DST];
+	unsigned int src_w = s_q_data->c_rect.width;
+	unsigned int src_h = s_q_data->c_rect.height;
+	unsigned int dst_w = d_q_data->c_rect.width;
+	unsigned int dst_h = d_q_data->c_rect.height;
 
-	if (ctx->deinterlacing)
-		config_edi_input_mode(ctx, 0x0);
+	if (src_w == dst_w && src_h == dst_h)
+		return 0;
 
-	if (ctx->sequence != 0)
-		set_srcdst_params(ctx);
+	if (src_h <= SC_MAX_PIXEL_HEIGHT &&
+	    src_w <= SC_MAX_PIXEL_WIDTH &&
+	    dst_h <= SC_MAX_PIXEL_HEIGHT &&
+	    dst_w <= SC_MAX_PIXEL_WIDTH)
+		return 0;
 
-	return 0;
+	return -1;
 }
 
-static void vpe_stop_streaming(struct vb2_queue *q)
+static void vpe_return_all_buffers(struct vpe_ctx *ctx,  struct vb2_queue *q,
+				   enum vb2_buffer_state state)
 {
-	struct vpe_ctx *ctx = vb2_get_drv_priv(q);
 	struct vb2_v4l2_buffer *vb;
 	unsigned long flags;
 
-	vpe_dump_regs(ctx->dev);
-	vpdma_dump_regs(ctx->dev->vpdma);
-
 	for (;;) {
 		if (V4L2_TYPE_IS_OUTPUT(q->type))
 			vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
@@ -2055,7 +2060,7 @@ static void vpe_stop_streaming(struct vb2_queue *q)
 		if (!vb)
 			break;
 		spin_lock_irqsave(&ctx->dev->lock, flags);
-		v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+		v4l2_m2m_buf_done(vb, state);
 		spin_unlock_irqrestore(&ctx->dev->lock, flags);
 	}
 
@@ -2068,15 +2073,15 @@ static void vpe_stop_streaming(struct vb2_queue *q)
 		spin_lock_irqsave(&ctx->dev->lock, flags);
 
 		if (ctx->src_vbs[2])
-			v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_ERROR);
+			v4l2_m2m_buf_done(ctx->src_vbs[2], state);
 
 		if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
-			v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_ERROR);
+			v4l2_m2m_buf_done(ctx->src_vbs[1], state);
 
 		if (ctx->src_vbs[0] &&
 		    (ctx->src_vbs[0] != ctx->src_vbs[1]) &&
 		    (ctx->src_vbs[0] != ctx->src_vbs[2]))
-			v4l2_m2m_buf_done(ctx->src_vbs[0], VB2_BUF_STATE_ERROR);
+			v4l2_m2m_buf_done(ctx->src_vbs[0], state);
 
 		ctx->src_vbs[2] = NULL;
 		ctx->src_vbs[1] = NULL;
@@ -2087,13 +2092,45 @@ static void vpe_stop_streaming(struct vb2_queue *q)
 		if (ctx->dst_vb) {
 			spin_lock_irqsave(&ctx->dev->lock, flags);
 
-			v4l2_m2m_buf_done(ctx->dst_vb, VB2_BUF_STATE_ERROR);
+			v4l2_m2m_buf_done(ctx->dst_vb, state);
 			ctx->dst_vb = NULL;
 			spin_unlock_irqrestore(&ctx->dev->lock, flags);
 		}
 	}
 }
 
+static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
+{
+	struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+
+	/* Check any of the size exceed maximum scaling sizes */
+	if (check_srcdst_sizes(ctx)) {
+		vpe_err(ctx->dev,
+			"Conversion setup failed, check source and destination parameters\n"
+			);
+		vpe_return_all_buffers(ctx, q, VB2_BUF_STATE_QUEUED);
+		return -EINVAL;
+	}
+
+	if (ctx->deinterlacing)
+		config_edi_input_mode(ctx, 0x0);
+
+	if (ctx->sequence != 0)
+		set_srcdst_params(ctx);
+
+	return 0;
+}
+
+static void vpe_stop_streaming(struct vb2_queue *q)
+{
+	struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+
+	vpe_dump_regs(ctx->dev);
+	vpdma_dump_regs(ctx->dev->vpdma);
+
+	vpe_return_all_buffers(ctx, q, VB2_BUF_STATE_ERROR);
+}
+
 static const struct vb2_ops vpe_qops = {
 	.queue_setup	 = vpe_queue_setup,
 	.buf_prepare	 = vpe_buf_prepare,
-- 
2.9.0


  parent reply	other threads:[~2016-11-18 23:21 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 23:20 [Patch v2 00/35] media: ti-vpe: fixes and enhancements Benoit Parrot
2016-11-18 23:20 ` [Patch v2 01/35] media: ti-vpe: vpdma: Make vpdma library into its own module Benoit Parrot
2016-11-18 23:20 ` [Patch v2 02/35] media: ti-vpe: vpdma: Add multi-instance and multi-client support Benoit Parrot
2016-11-18 23:20 ` [Patch v2 03/35] media: ti-vpe: vpdma: Add helper to set a background color Benoit Parrot
2016-11-18 23:20 ` [Patch v2 04/35] media: ti-vpe: vpdma: Fix bus error when vpdma is writing a descriptor Benoit Parrot
2016-11-18 23:20 ` [Patch v2 05/35] media: ti-vpe: Use line average de-interlacing for first 2 frames Benoit Parrot
2016-11-18 23:20 ` [Patch v2 06/35] media: ti-vpe: vpe: Do not perform job transaction atomically Benoit Parrot
2016-11-18 23:20 ` [Patch v2 07/35] media: ti-vpe: Add support for SEQ_TB buffers Benoit Parrot
2016-11-18 23:20 ` [Patch v2 08/35] media: ti-vpe: Increasing max buffer height and width Benoit Parrot
2016-11-18 23:20 ` [Patch v2 09/35] media: ti-vpe: vpe: Return NULL for invalid buffer type Benoit Parrot
2016-11-18 23:20 ` [Patch v2 10/35] media: ti-vpe: Free vpdma buffers in vpe_release Benoit Parrot
2016-11-18 23:20 ` [Patch v2 11/35] media: ti-vpe: vpdma: Add support for setting max width height Benoit Parrot
2016-11-18 23:20 ` [Patch v2 12/35] media: ti-vpe: vpdma: Add abort channel desc and cleanup APIs Benoit Parrot
2016-11-18 23:20 ` [Patch v2 13/35] media: ti-vpe: vpdma: Make list post atomic operation Benoit Parrot
2016-11-18 23:20 ` [Patch v2 14/35] media: ti-vpe: vpdma: Clear IRQs for individual lists Benoit Parrot
2016-11-18 23:20 ` [Patch v2 15/35] media: ti-vpe: vpe: configure line mode separately Benoit Parrot
2016-11-18 23:20 ` [Patch v2 16/35] media: ti-vpe: vpe: Setup srcdst parameters in start_streaming Benoit Parrot
2016-11-18 23:20 ` [Patch v2 17/35] media: ti-vpe: vpe: Post next descriptor only for list complete IRQ Benoit Parrot
2016-11-18 23:20 ` [Patch v2 18/35] media: ti-vpe: vpe: Add RGB565 and RGB5551 support Benoit Parrot
2016-11-18 23:20 ` [Patch v2 19/35] media: ti-vpe: vpdma: allocate and maintain hwlist Benoit Parrot
2016-11-18 23:20 ` [Patch v2 20/35] media: ti-vpe: vpe: Added MODULE_DEVICE_TABLE hint Benoit Parrot
2016-11-18 23:20 ` [Patch v2 21/35] media: ti-vpe: vpdma: Corrected YUV422 data type label Benoit Parrot
2016-11-18 23:20 ` [Patch v2 22/35] media: ti-vpe: vpdma: RGB data type yield inverted data Benoit Parrot
2016-11-18 23:20 ` [Patch v2 23/35] media: ti-vpe: sc: Fix incorrect optimization Benoit Parrot
2016-11-18 23:20 ` [Patch v2 24/35] media: ti-vpe: vpe: Fix vb2 buffer cleanup Benoit Parrot
2016-11-18 23:20 ` [Patch v2 25/35] media: ti-vpe: vpdma: Fix race condition for firmware loading Benoit Parrot
2016-11-18 23:20 ` [Patch v2 26/35] media: ti-vpe: vpdma: Use bidirectional cached buffers Benoit Parrot
2016-11-18 23:20 ` [Patch v2 27/35] media: ti-vpe: vpe: Fix line stride for output motion vector Benoit Parrot
2016-11-18 23:20 ` [Patch v2 28/35] media: ti-vpe: vpe: Enable DMABUF export Benoit Parrot
2016-11-18 23:20 ` [Patch v2 29/35] media: ti-vpe: Make scaler library into its own module Benoit Parrot
2016-11-18 23:20 ` [Patch v2 30/35] media: ti-vpe: scaler: Add debug support for multi-instance Benoit Parrot
2016-11-18 23:20 ` Benoit Parrot [this message]
2016-11-18 23:20 ` [Patch v2 32/35] media: ti-vpe: vpdma: Add RAW8 and RAW16 data types Benoit Parrot
2016-11-18 23:20 ` [Patch v2 33/35] media: ti-vpe: Make colorspace converter library into its own module Benoit Parrot
2016-11-18 23:20 ` [Patch v2 34/35] media: ti-vpe: csc: Add debug support for multi-instance Benoit Parrot
2016-11-18 23:20 ` [Patch v2 35/35] media: ti-vpe: vpe: Add proper support single and multi-plane buffer Benoit Parrot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161118232045.24665-32-bparrot@ti.com \
    --to=bparrot@ti.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jsarha@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).