All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/21] CODA fixes and vmalloc input
@ 2015-01-23 16:51 Philipp Zabel
  2015-01-23 16:51 ` [PATCH 01/21] [media] coda: fix encoder rate control parameter masks Philipp Zabel
                   ` (20 more replies)
  0 siblings, 21 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Hi,

this is a series of various fixes that should increase stability
in the face of broken streams and just general use of the CODA driver.
They range from crash fixes to issues uncovered by v4l2-compliance.
The CODA9 subsampling buffers patch fixes encoder image corruption.

Also, the BIT decoder input queue is switched to vmalloc memory, and the
bitstream buffer and sequence end work are made optional for future
CODA9 JPEG support.

regards
Philipp

Lucas Stach (1):
  [media] coda: adjust sequence offset after unexpected decoded frame

Markus Pargmann (1):
  [media] coda: fix width validity check when starting to decode

Philipp Zabel (19):
  [media] coda: fix encoder rate control parameter masks
  [media] coda: bitrate can only be set in kbps steps
  [media] coda: remove context debugfs entry last
  [media] coda: move meta out of padding
  [media] coda: fix job_ready debug reporting for bitstream decoding
  [media] coda: fix try_fmt_vid_out colorspace setting
  [media] coda: properly clear f_cap in coda_s_fmt_vid_out
  [media] coda: initialize SRAM on probe
  [media] coda: clear RET_DEC_PIC_SUCCESS flag in prepare_decode
  [media] coda: remove unused isequence, reset qsequence in
    stop_streaming
  [media] coda: issue seq_end_work during stop_streaming
  [media] coda: don't ever use subsampling ping-pong buffers as
    reconstructed reference buffers
  [media] coda: add coda_estimate_sizeimage and use it in set_defaults
  [media] coda: switch BIT decoder source queue to vmalloc
  [media] coda: make seq_end_work optional
  [media] coda: free context buffers under buffer mutex
  [media] coda: add support for contexts that do not use the BIT
    processor
  [media] coda: allocate bitstream ringbuffer only for BIT decoder
  [media] coda: simplify check in coda_buf_queue

 drivers/media/platform/Kconfig            |   1 +
 drivers/media/platform/coda/coda-bit.c    |  25 +++--
 drivers/media/platform/coda/coda-common.c | 161 ++++++++++++++++++++----------
 drivers/media/platform/coda/coda.h        |   2 +-
 drivers/media/platform/coda/coda_regs.h   |   4 +-
 5 files changed, 130 insertions(+), 63 deletions(-)

-- 
2.1.4


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

* [PATCH 01/21] [media] coda: fix encoder rate control parameter masks
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps Philipp Zabel
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

This patch fixes the ENC_SEQ_RC_PARA initial delay and bitrate masks.
These bit fields are 15 bit wide, not 7 bit.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda_regs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda_regs.h b/drivers/media/platform/coda/coda_regs.h
index 8e015b8..7d02624 100644
--- a/drivers/media/platform/coda/coda_regs.h
+++ b/drivers/media/platform/coda/coda_regs.h
@@ -304,9 +304,9 @@
 #define		CODA_RATECONTROL_AUTOSKIP_OFFSET		31
 #define		CODA_RATECONTROL_AUTOSKIP_MASK			0x01
 #define		CODA_RATECONTROL_INITIALDELAY_OFFSET		16
-#define		CODA_RATECONTROL_INITIALDELAY_MASK		0x7f
+#define		CODA_RATECONTROL_INITIALDELAY_MASK		0x7fff
 #define		CODA_RATECONTROL_BITRATE_OFFSET		1
-#define		CODA_RATECONTROL_BITRATE_MASK			0x7f
+#define		CODA_RATECONTROL_BITRATE_MASK			0x7fff
 #define		CODA_RATECONTROL_ENABLE_OFFSET			0
 #define		CODA_RATECONTROL_ENABLE_MASK			0x01
 #define CODA_CMD_ENC_SEQ_RC_BUF_SIZE				0x1b0
-- 
2.1.4


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

* [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
  2015-01-23 16:51 ` [PATCH 01/21] [media] coda: fix encoder rate control parameter masks Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-29 15:34   ` Kamil Debski
  2015-01-23 16:51 ` [PATCH 03/21] [media] coda: remove context debugfs entry last Philipp Zabel
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 39330a7..1cc4e90 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1407,7 +1407,7 @@ static const struct v4l2_ctrl_ops coda_ctrl_ops = {
 static void coda_encode_ctrls(struct coda_ctx *ctx)
 {
 	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
-		V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1, 0);
+		V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1000, 0);
 	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
 		V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16);
 	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
-- 
2.1.4


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

* [PATCH 03/21] [media] coda: remove context debugfs entry last
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
  2015-01-23 16:51 ` [PATCH 01/21] [media] coda: fix encoder rate control parameter masks Philipp Zabel
  2015-01-23 16:51 ` [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 04/21] [media] coda: move meta out of padding Philipp Zabel
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Do not remove the per-context debugfs directory before the
per-buffer debugfs entries contained therein.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 1cc4e90..9a0ee11 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1693,8 +1693,6 @@ static int coda_release(struct file *file)
 	v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n",
 		 ctx);
 
-	debugfs_remove_recursive(ctx->debugfs_entry);
-
 	if (ctx->inst_type == CODA_INST_DECODER)
 		coda_bit_stream_end_flag(ctx);
 
@@ -1728,6 +1726,7 @@ static int coda_release(struct file *file)
 	clear_bit(ctx->idx, &dev->instance_mask);
 	if (ctx->ops->release)
 		ctx->ops->release(ctx);
+	debugfs_remove_recursive(ctx->debugfs_entry);
 	kfree(ctx);
 
 	return 0;
-- 
2.1.4


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

* [PATCH 04/21] [media] coda: move meta out of padding
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (2 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 03/21] [media] coda: remove context debugfs entry last Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 05/21] [media] coda: adjust sequence offset after unexpected decoded frame Philipp Zabel
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Handle an empty buffer metadata list without crashing. This can happen
if the decoder is fed a broken stream, or multiple compressed frames in
a single queued buffer.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index b4029ae..f6cf337 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1565,6 +1565,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
 	struct vb2_buffer *dst_buf;
 	struct coda_dev *dev = ctx->dev;
 	struct coda_q_data *q_data_dst;
+	struct coda_buffer_meta *meta;
 	u32 reg_addr, reg_stride;
 
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
@@ -1643,12 +1644,12 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
 		coda_write(dev, ctx->iram_info.axi_sram_use,
 				CODA7_REG_BIT_AXI_SRAM_USE);
 
-	if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) {
-		struct coda_buffer_meta *meta;
+	meta = list_first_entry_or_null(&ctx->buffer_meta_list,
+					struct coda_buffer_meta, list);
+
+	if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) {
 
 		/* If this is the last buffer in the bitstream, add padding */
-		meta = list_first_entry(&ctx->buffer_meta_list,
-				      struct coda_buffer_meta, list);
 		if (meta->end == (ctx->bitstream_fifo.kfifo.in &
 				  ctx->bitstream_fifo.kfifo.mask)) {
 			static unsigned char buf[512];
-- 
2.1.4


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

* [PATCH 05/21] [media] coda: adjust sequence offset after unexpected decoded frame
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (3 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 04/21] [media] coda: move meta out of padding Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 06/21] [media] coda: fix job_ready debug reporting for bitstream decoding Philipp Zabel
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Lucas Stach

From: Lucas Stach <l.stach@pengutronix.de>

If userspace doesn't properly separate the bitstream input into
individual frames (which may happen for example on slightly
corrupted streams) the CODA hardware may decode more frames
than we expect. We already log an error in this case, but it's
also necessary to adjust the sequence offset. Otherwise we
spam the log with a sequence number mismatch on every frame
frame after the unexpected one.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index f6cf337..6b00a45 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1822,6 +1822,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 			memset(&ctx->frame_metas[decoded_idx], 0,
 			       sizeof(struct coda_buffer_meta));
 			ctx->frame_metas[decoded_idx].sequence = val;
+			ctx->sequence_offset++;
 		}
 		mutex_unlock(&ctx->bitstream_mutex);
 
-- 
2.1.4


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

* [PATCH 06/21] [media] coda: fix job_ready debug reporting for bitstream decoding
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (4 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 05/21] [media] coda: adjust sequence offset after unexpected decoded frame Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 07/21] [media] coda: fix try_fmt_vid_out colorspace setting Philipp Zabel
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Clarify whether job_ready returns false because the context is on hold, waiting
for new input buffers, whether there are not enough input buffers to fill two
into the bitstream, or whether there is not enough data in the bitstream buffer
for the bitstream reader hardware to read a whole frame.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 46 +++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 9a0ee11..ea54337 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -939,15 +939,43 @@ static int coda_job_ready(void *m2m_priv)
 		return 0;
 	}
 
-	if (ctx->hold ||
-	    ((ctx->inst_type == CODA_INST_DECODER) &&
-	     !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
-	     (coda_get_bitstream_payload(ctx) < 512) &&
-	     !(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) {
-		v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
-			 "%d: not ready: not enough bitstream data.\n",
-			 ctx->idx);
-		return 0;
+	if (ctx->inst_type == CODA_INST_DECODER) {
+		struct list_head *meta;
+		bool stream_end;
+		int num_metas;
+		int src_bufs;
+
+		if (ctx->hold && !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) {
+			v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
+				 "%d: not ready: on hold for more buffers.\n",
+				 ctx->idx);
+			return 0;
+		}
+
+		stream_end = ctx->bit_stream_param &
+			     CODA_BIT_STREAM_END_FLAG;
+
+		num_metas = 0;
+		list_for_each(meta, &ctx->buffer_meta_list)
+			num_metas++;
+
+		src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx);
+
+		if (!stream_end && (num_metas + src_bufs) < 2) {
+			v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
+				 "%d: not ready: need 2 buffers available (%d, %d)\n",
+				 ctx->idx, num_metas, src_bufs);
+			return 0;
+		}
+
+
+		if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
+		    !stream_end && (coda_get_bitstream_payload(ctx) < 512)) {
+			v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
+				 "%d: not ready: not enough bitstream data (%d).\n",
+				 ctx->idx, coda_get_bitstream_payload(ctx));
+			return 0;
+		}
 	}
 
 	if (ctx->aborting) {
-- 
2.1.4


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

* [PATCH 07/21] [media] coda: fix try_fmt_vid_out colorspace setting
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (5 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 06/21] [media] coda: fix job_ready debug reporting for bitstream decoding Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 08/21] [media] coda: properly clear f_cap in coda_s_fmt_vid_out Philipp Zabel
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

v4l2-compliance complains about invalid colorspace settings being accepted
on the output side. This patch only allows REC709 and JPEG.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index ea54337..af8a4d6 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -592,7 +592,11 @@ static int coda_try_fmt_vid_out(struct file *file, void *priv,
 	if (ret < 0)
 		return ret;
 
-	if (!f->fmt.pix.colorspace) {
+	switch (f->fmt.pix.colorspace) {
+	case V4L2_COLORSPACE_REC709:
+	case V4L2_COLORSPACE_JPEG:
+		break;
+	default:
 		if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
 			f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
 		else
-- 
2.1.4


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

* [PATCH 08/21] [media] coda: properly clear f_cap in coda_s_fmt_vid_out
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (6 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 07/21] [media] coda: fix try_fmt_vid_out colorspace setting Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 09/21] [media] coda: initialize SRAM on probe Philipp Zabel
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Properly zero the structure on the stack before using it.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index af8a4d6..7a6cb08 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -674,6 +674,7 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv,
 
 	ctx->colorspace = f->fmt.pix.colorspace;
 
+	memset(&f_cap, 0, sizeof(f_cap));
 	f_cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	coda_g_fmt(file, priv, &f_cap);
 	f_cap.fmt.pix.width = f->fmt.pix.width;
-- 
2.1.4


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

* [PATCH 09/21] [media] coda: initialize SRAM on probe
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (7 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 08/21] [media] coda: properly clear f_cap in coda_s_fmt_vid_out Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 10/21] [media] coda: clear RET_DEC_PIC_SUCCESS flag in prepare_decode Philipp Zabel
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Zeroing the SRAM on probe helps with debugging SRAM contents.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 7a6cb08..5386b2c 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -2174,6 +2174,7 @@ static int coda_probe(struct platform_device *pdev)
 	if (!dev->iram.vaddr) {
 		dev_warn(&pdev->dev, "unable to alloc iram\n");
 	} else {
+		memset(dev->iram.vaddr, 0, dev->iram.size);
 		dev->iram.blob.data = dev->iram.vaddr;
 		dev->iram.blob.size = dev->iram.size;
 		dev->iram.dentry = debugfs_create_blob("iram", 0644,
-- 
2.1.4


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

* [PATCH 10/21] [media] coda: clear RET_DEC_PIC_SUCCESS flag in prepare_decode
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (8 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 09/21] [media] coda: initialize SRAM on probe Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 11/21] [media] coda: fix width validity check when starting to decode Philipp Zabel
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

To make sure a set RET_DEC_PIC_SUCCESS flag is not a leftover from
a previous successful run, clear it in prepare_decode.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 6b00a45..d81635d 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1666,6 +1666,9 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
 
 	coda_kfifo_sync_to_device_full(ctx);
 
+	/* Clear decode success flag */
+	coda_write(dev, 0, CODA_RET_DEC_PIC_SUCCESS);
+
 	coda_command_async(ctx, CODA_COMMAND_PIC_RUN);
 
 	return 0;
-- 
2.1.4


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

* [PATCH 11/21] [media] coda: fix width validity check when starting to decode
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (9 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 10/21] [media] coda: clear RET_DEC_PIC_SUCCESS flag in prepare_decode Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 12/21] [media] coda: remove unused isequence, reset qsequence in stop_streaming Philipp Zabel
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Markus Pargmann, Philipp Zabel

From: Markus Pargmann <mpa@pengutronix.de>

Compare rounded up width to fit into bytesperline.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index d81635d..6ecfd29 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1431,9 +1431,10 @@ static int __coda_start_decoding(struct coda_ctx *ctx)
 		height = val & CODA7_PICHEIGHT_MASK;
 	}
 
-	if (width > q_data_dst->width || height > q_data_dst->height) {
+	if (width > q_data_dst->bytesperline || height > q_data_dst->height) {
 		v4l2_err(&dev->v4l2_dev, "stream is %dx%d, not %dx%d\n",
-			 width, height, q_data_dst->width, q_data_dst->height);
+			 width, height, q_data_dst->bytesperline,
+			 q_data_dst->height);
 		return -EINVAL;
 	}
 
-- 
2.1.4


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

* [PATCH 12/21] [media] coda: remove unused isequence, reset qsequence in stop_streaming
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (10 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 11/21] [media] coda: fix width validity check when starting to decode Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 13/21] [media] coda: issue seq_end_work during stop_streaming Philipp Zabel
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

The isequence counter is never used, qsequence counts the buffers queued into
the bit decoder bitstream ringbuffer. It needs to be reset in stop_streaming.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 2 +-
 drivers/media/platform/coda/coda.h        | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 5386b2c..611d737 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1304,7 +1304,7 @@ static void coda_stop_streaming(struct vb2_queue *q)
 
 		coda_bit_stream_end_flag(ctx);
 
-		ctx->isequence = 0;
+		ctx->qsequence = 0;
 
 		while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
 			v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 5dd47e5..2ddfe51 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -198,7 +198,6 @@ struct coda_ctx {
 	int				initialized;
 	int				streamon_out;
 	int				streamon_cap;
-	u32				isequence;
 	u32				qsequence;
 	u32				osequence;
 	u32				sequence_offset;
-- 
2.1.4


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

* [PATCH 13/21] [media] coda: issue seq_end_work during stop_streaming
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (11 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 12/21] [media] coda: remove unused isequence, reset qsequence in stop_streaming Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 14/21] [media] coda: don't ever use subsampling ping-pong buffers as reconstructed reference buffers Philipp Zabel
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

This patch queues seq_end_work and flushes the queue during stop_streaming
and clears the ctx->initialized flag. This allows to start streaming again
after stopping streaming without releasing the context.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 611d737..6ea7e0a 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1323,6 +1323,10 @@ static void coda_stop_streaming(struct vb2_queue *q)
 	if (!ctx->streamon_out && !ctx->streamon_cap) {
 		struct coda_buffer_meta *meta;
 
+		if (ctx->ops->seq_end_work) {
+			queue_work(dev->workqueue, &ctx->seq_end_work);
+			flush_work(&ctx->seq_end_work);
+		}
 		mutex_lock(&ctx->bitstream_mutex);
 		while (!list_empty(&ctx->buffer_meta_list)) {
 			meta = list_first_entry(&ctx->buffer_meta_list,
@@ -1333,6 +1337,7 @@ static void coda_stop_streaming(struct vb2_queue *q)
 		mutex_unlock(&ctx->bitstream_mutex);
 		kfifo_init(&ctx->bitstream_fifo,
 			ctx->bitstream.vaddr, ctx->bitstream.size);
+		ctx->initialized = 0;
 		ctx->runcounter = 0;
 		ctx->aborting = 0;
 	}
-- 
2.1.4


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

* [PATCH 14/21] [media] coda: don't ever use subsampling ping-pong buffers as reconstructed reference buffers
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (12 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 13/21] [media] coda: issue seq_end_work during stop_streaming Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 15/21] [media] coda: add coda_estimate_sizeimage and use it in set_defaults Philipp Zabel
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

On i.MX6, two subsampling ping-pong buffers are used for motion estimation and
deblocking They should not be counted as framebuffers, or they will be also used
to store reconstructed frames, causing visible artifacts in P-frames.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 6ecfd29..7cdddd5 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -718,6 +718,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 	struct vb2_buffer *buf;
 	int gamma, ret, value;
 	u32 dst_fourcc;
+	int num_fb;
 	u32 stride;
 
 	q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
@@ -983,12 +984,14 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 			v4l2_err(v4l2_dev, "failed to allocate framebuffers\n");
 			goto out;
 		}
+		num_fb = 2;
 		stride = q_data_src->bytesperline;
 	} else {
 		ctx->num_internal_frames = 0;
+		num_fb = 0;
 		stride = 0;
 	}
-	coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM);
+	coda_write(dev, num_fb, CODA_CMD_SET_FRAME_BUF_NUM);
 	coda_write(dev, stride, CODA_CMD_SET_FRAME_BUF_STRIDE);
 
 	if (dev->devtype->product == CODA_7541) {
-- 
2.1.4


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

* [PATCH 15/21] [media] coda: add coda_estimate_sizeimage and use it in set_defaults
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (13 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 14/21] [media] coda: don't ever use subsampling ping-pong buffers as reconstructed reference buffers Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 16/21] [media] coda: switch BIT decoder source queue to vmalloc Philipp Zabel
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Call coda_estimate_sizeimage from both try_fmt and set_defaults to
avoid this v4l2-compliance warning on the h.264 decoder video device:

    G_FMT:     1920x1088, 32315559, 1, 1920, 1048576, 3, 0, 0, feedcafe
    TRY/S_FMT: 1920x1088, 32315559, 1, 1920, 3133440, 3, 0, 0, feedcafe
    fail: v4l2-test-formats.cpp(948): Video Capture: S_FMT(G_FMT) != G_FMT

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 38 +++++++++++++++++++------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 6ea7e0a..f7fc355 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -468,6 +468,18 @@ static int coda_try_pixelformat(struct coda_ctx *ctx, struct v4l2_format *f)
 	return 0;
 }
 
+static unsigned int coda_estimate_sizeimage(struct coda_ctx *ctx, u32 sizeimage,
+					    u32 width, u32 height)
+{
+	/*
+	 * This is a rough estimate for sensible compressed buffer
+	 * sizes (between 1 and 16 bits per pixel). This could be
+	 * improved by better format specific worst case estimates.
+	 */
+	return round_up(clamp(sizeimage, width * height / 8,
+					 width * height * 2), PAGE_SIZE);
+}
+
 static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
 			struct v4l2_format *f)
 {
@@ -513,15 +525,10 @@ static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
 	case V4L2_PIX_FMT_H264:
 	case V4L2_PIX_FMT_MPEG4:
 		f->fmt.pix.bytesperline = 0;
-		/*
-		 * This is a rough estimate for sensible compressed buffer
-		 * sizes (between 1 and 16 bits per pixel). This could be
-		 * improved by better format specific worst case estimates.
-		 */
-		f->fmt.pix.sizeimage = round_up(clamp(f->fmt.pix.sizeimage,
-				f->fmt.pix.width * f->fmt.pix.height / 8,
-				f->fmt.pix.width * f->fmt.pix.height * 2),
-				PAGE_SIZE);
+		f->fmt.pix.sizeimage = coda_estimate_sizeimage(ctx,
+							f->fmt.pix.sizeimage,
+							f->fmt.pix.width,
+							f->fmt.pix.height);
 		break;
 	default:
 		BUG();
@@ -1056,13 +1063,14 @@ static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type)
 
 static void set_default_params(struct coda_ctx *ctx)
 {
-	unsigned int max_w, max_h, size;
+	unsigned int max_w, max_h, usize, csize;
 
 	ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0],
 				     ctx->cvd->dst_formats[0]);
 	max_w = min(ctx->codec->max_w, 1920U);
 	max_h = min(ctx->codec->max_h, 1088U);
-	size = max_w * max_h * 3 / 2;
+	usize = max_w * max_h * 3 / 2;
+	csize = coda_estimate_sizeimage(ctx, usize, max_w, max_h);
 
 	ctx->params.codec_mode = ctx->codec->mode;
 	ctx->colorspace = V4L2_COLORSPACE_REC709;
@@ -1077,14 +1085,14 @@ static void set_default_params(struct coda_ctx *ctx)
 	ctx->q_data[V4L2_M2M_DST].height = max_h;
 	if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) {
 		ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w;
-		ctx->q_data[V4L2_M2M_SRC].sizeimage = size;
+		ctx->q_data[V4L2_M2M_SRC].sizeimage = usize;
 		ctx->q_data[V4L2_M2M_DST].bytesperline = 0;
-		ctx->q_data[V4L2_M2M_DST].sizeimage = round_up(size, PAGE_SIZE);
+		ctx->q_data[V4L2_M2M_DST].sizeimage = csize;
 	} else {
 		ctx->q_data[V4L2_M2M_SRC].bytesperline = 0;
-		ctx->q_data[V4L2_M2M_SRC].sizeimage = round_up(size, PAGE_SIZE);
+		ctx->q_data[V4L2_M2M_SRC].sizeimage = csize;
 		ctx->q_data[V4L2_M2M_DST].bytesperline = max_w;
-		ctx->q_data[V4L2_M2M_DST].sizeimage = size;
+		ctx->q_data[V4L2_M2M_DST].sizeimage = usize;
 	}
 	ctx->q_data[V4L2_M2M_SRC].rect.width = max_w;
 	ctx->q_data[V4L2_M2M_SRC].rect.height = max_h;
-- 
2.1.4


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

* [PATCH 16/21] [media] coda: switch BIT decoder source queue to vmalloc
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (14 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 15/21] [media] coda: add coda_estimate_sizeimage and use it in set_defaults Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 17/21] [media] coda: make seq_end_work optional Philipp Zabel
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Since we have to copy from input buffers into the bitstream ringbuffer
with the CPU, there is no need for contiguous DMA buffers on the decoder
input side.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/Kconfig            | 1 +
 drivers/media/platform/coda/coda-common.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 765bffb..74c2101 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -140,6 +140,7 @@ config VIDEO_CODA
 	depends on HAS_DMA
 	select SRAM
 	select VIDEOBUF2_DMA_CONTIG
+	select VIDEOBUF2_VMALLOC
 	select V4L2_MEM2MEM_DEV
 	select GENERIC_ALLOCATOR
 	---help---
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index f7fc355..24d9f8a 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -37,6 +37,7 @@
 #include <media/v4l2-mem2mem.h>
 #include <media/videobuf2-core.h>
 #include <media/videobuf2-dma-contig.h>
+#include <media/videobuf2-vmalloc.h>
 
 #include "coda.h"
 
@@ -1121,6 +1122,7 @@ static int coda_queue_setup(struct vb2_queue *vq,
 	*nplanes = 1;
 	sizes[0] = size;
 
+	/* Set to vb2-dma-contig allocator context, ignored by vb2-vmalloc */
 	alloc_ctxs[0] = ctx->dev->alloc_ctx;
 
 	v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
@@ -1567,8 +1569,8 @@ int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
 	int ret;
 
 	src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-	src_vq->io_modes = VB2_DMABUF | VB2_MMAP;
-	src_vq->mem_ops = &vb2_dma_contig_memops;
+	src_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR;
+	src_vq->mem_ops = &vb2_vmalloc_memops;
 
 	ret = coda_queue_init(priv, src_vq);
 	if (ret)
-- 
2.1.4


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

* [PATCH 17/21] [media] coda: make seq_end_work optional
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (15 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 16/21] [media] coda: switch BIT decoder source queue to vmalloc Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 18/21] [media] coda: free context buffers under buffer mutex Philipp Zabel
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

In preparation for CODA9 JPEG support, which doesn't have to call
SEQ_END on the BIT processor.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 24d9f8a..40074fa 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -921,7 +921,8 @@ static void coda_pic_run_work(struct work_struct *work)
 		ctx->ops->finish_run(ctx);
 	}
 
-	if (ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out))
+	if ((ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out)) &&
+	    ctx->ops->seq_end_work)
 		queue_work(dev->workqueue, &ctx->seq_end_work);
 
 	mutex_unlock(&dev->coda_mutex);
@@ -1627,7 +1628,8 @@ static int coda_open(struct file *file)
 	ctx->ops = ctx->cvd->ops;
 	init_completion(&ctx->completion);
 	INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
-	INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work);
+	if (ctx->ops->seq_end_work)
+		INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work);
 	v4l2_fh_init(&ctx->fh, video_devdata(file));
 	file->private_data = &ctx->fh;
 	v4l2_fh_add(&ctx->fh);
@@ -1748,7 +1750,7 @@ static int coda_release(struct file *file)
 	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
 
 	/* In case the instance was not running, we still need to call SEQ_END */
-	if (ctx->initialized) {
+	if (ctx->initialized && ctx->ops->seq_end_work) {
 		queue_work(dev->workqueue, &ctx->seq_end_work);
 		flush_work(&ctx->seq_end_work);
 	}
-- 
2.1.4


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

* [PATCH 18/21] [media] coda: free context buffers under buffer mutex
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (16 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 17/21] [media] coda: make seq_end_work optional Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 19/21] [media] coda: add support for contexts that do not use the BIT processor Philipp Zabel
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Make sure the buffer_mutex lock is taken in coda_bit_release
while coda_free_framebuffers and coda_free_context_buffers
are called.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 7cdddd5..856b542 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1319,8 +1319,10 @@ static void coda_seq_end_work(struct work_struct *work)
 
 static void coda_bit_release(struct coda_ctx *ctx)
 {
+	mutex_lock(&ctx->buffer_mutex);
 	coda_free_framebuffers(ctx);
 	coda_free_context_buffers(ctx);
+	mutex_unlock(&ctx->buffer_mutex);
 }
 
 const struct coda_context_ops coda_bit_encode_ops = {
-- 
2.1.4


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

* [PATCH 19/21] [media] coda: add support for contexts that do not use the BIT processor
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (17 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 18/21] [media] coda: free context buffers under buffer mutex Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 20/21] [media] coda: allocate bitstream ringbuffer only for BIT decoder Philipp Zabel
  2015-01-23 16:51 ` [PATCH 21/21] [media] coda: simplify check in coda_buf_queue Philipp Zabel
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

In preparation for CODA9 JPEG support, allow contexts that
control hardware units directly, without the BIT processor.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 42 +++++++++++++++++--------------
 drivers/media/platform/coda/coda.h        |  1 +
 2 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 40074fa..2defa4b 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -181,6 +181,7 @@ struct coda_video_device {
 	const char *name;
 	enum coda_inst_type type;
 	const struct coda_context_ops *ops;
+	bool direct;
 	u32 src_formats[CODA_MAX_FORMATS];
 	u32 dst_formats[CODA_MAX_FORMATS];
 };
@@ -953,7 +954,7 @@ static int coda_job_ready(void *m2m_priv)
 		return 0;
 	}
 
-	if (ctx->inst_type == CODA_INST_DECODER) {
+	if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) {
 		struct list_head *meta;
 		bool stream_end;
 		int num_metas;
@@ -1161,7 +1162,7 @@ static void coda_buf_queue(struct vb2_buffer *vb)
 	 * In the decoder case, immediately try to copy the buffer into the
 	 * bitstream ringbuffer and mark it as ready to be dequeued.
 	 */
-	if (ctx->inst_type == CODA_INST_DECODER &&
+	if (ctx->use_bit && ctx->inst_type == CODA_INST_DECODER &&
 	    vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
 		/*
 		 * For backwards compatibility, queuing an empty buffer marks
@@ -1262,7 +1263,7 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
 		return 0;
 
 	/* Allow BIT decoder device_run with no new buffers queued */
-	if (ctx->inst_type == CODA_INST_DECODER)
+	if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
 		v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true);
 
 	ctx->gopcounter = ctx->params.gop_size - 1;
@@ -1626,6 +1627,7 @@ static int coda_open(struct file *file)
 	ctx->cvd = to_coda_video_device(vdev);
 	ctx->inst_type = ctx->cvd->type;
 	ctx->ops = ctx->cvd->ops;
+	ctx->use_bit = !ctx->cvd->direct;
 	init_completion(&ctx->completion);
 	INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
 	if (ctx->ops->seq_end_work)
@@ -1680,22 +1682,24 @@ static int coda_open(struct file *file)
 
 	ctx->fh.ctrl_handler = &ctx->ctrls;
 
-	ret = coda_alloc_context_buf(ctx, &ctx->parabuf,
-				     CODA_PARA_BUF_SIZE, "parabuf");
-	if (ret < 0) {
-		v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
-		goto err_dma_alloc;
-	}
+	if (ctx->use_bit) {
+		ret = coda_alloc_context_buf(ctx, &ctx->parabuf,
+					     CODA_PARA_BUF_SIZE, "parabuf");
+		if (ret < 0) {
+			v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
+			goto err_dma_alloc;
+		}
 
-	ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
-	ctx->bitstream.vaddr = dma_alloc_writecombine(
-			&dev->plat_dev->dev, ctx->bitstream.size,
-			&ctx->bitstream.paddr, GFP_KERNEL);
-	if (!ctx->bitstream.vaddr) {
-		v4l2_err(&dev->v4l2_dev,
-			 "failed to allocate bitstream ringbuffer");
-		ret = -ENOMEM;
-		goto err_dma_writecombine;
+		ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
+		ctx->bitstream.vaddr = dma_alloc_writecombine(
+				&dev->plat_dev->dev, ctx->bitstream.size,
+				&ctx->bitstream.paddr, GFP_KERNEL);
+		if (!ctx->bitstream.vaddr) {
+			v4l2_err(&dev->v4l2_dev,
+				 "failed to allocate bitstream ringbuffer");
+			ret = -ENOMEM;
+			goto err_dma_writecombine;
+		}
 	}
 	kfifo_init(&ctx->bitstream_fifo,
 		ctx->bitstream.vaddr, ctx->bitstream.size);
@@ -1743,7 +1747,7 @@ static int coda_release(struct file *file)
 	v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n",
 		 ctx);
 
-	if (ctx->inst_type == CODA_INST_DECODER)
+	if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
 		coda_bit_stream_end_flag(ctx);
 
 	/* If this instance is running, call .job_abort and wait for it to end */
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 2ddfe51..0c35cd5 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -235,6 +235,7 @@ struct coda_ctx {
 	u32				frame_mem_ctrl;
 	int				display_idx;
 	struct dentry			*debugfs_entry;
+	bool				use_bit;
 };
 
 extern int coda_debug;
-- 
2.1.4


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

* [PATCH 20/21] [media] coda: allocate bitstream ringbuffer only for BIT decoder
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (18 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 19/21] [media] coda: add support for contexts that do not use the BIT processor Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  2015-01-23 16:51 ` [PATCH 21/21] [media] coda: simplify check in coda_buf_queue Philipp Zabel
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

The BIT encoder does not use a per-context bitstream ringbuffer as it encodes
directly into the videobuf2 capture queue's buffers. Avoid allocation of the
bitstream ringbuffer for encoder contexts.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 2defa4b..c19f4b7 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1689,7 +1689,8 @@ static int coda_open(struct file *file)
 			v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
 			goto err_dma_alloc;
 		}
-
+	}
+	if (ctx->use_bit && ctx->inst_type == CODA_INST_DECODER) {
 		ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
 		ctx->bitstream.vaddr = dma_alloc_writecombine(
 				&dev->plat_dev->dev, ctx->bitstream.size,
-- 
2.1.4


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

* [PATCH 21/21] [media] coda: simplify check in coda_buf_queue
  2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
                   ` (19 preceding siblings ...)
  2015-01-23 16:51 ` [PATCH 20/21] [media] coda: allocate bitstream ringbuffer only for BIT decoder Philipp Zabel
@ 2015-01-23 16:51 ` Philipp Zabel
  20 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-23 16:51 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media, Philipp Zabel

Now that the bitstream buffer is only allocated for the BIT decoder
case, we can use bitstream.size to check for bitstream ringbuffer
operation.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index c19f4b7..3118076 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1154,6 +1154,7 @@ static int coda_buf_prepare(struct vb2_buffer *vb)
 static void coda_buf_queue(struct vb2_buffer *vb)
 {
 	struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vb2_queue *vq = vb->vb2_queue;
 	struct coda_q_data *q_data;
 
 	q_data = get_q_data(ctx, vb->vb2_queue->type);
@@ -1162,8 +1163,7 @@ static void coda_buf_queue(struct vb2_buffer *vb)
 	 * In the decoder case, immediately try to copy the buffer into the
 	 * bitstream ringbuffer and mark it as ready to be dequeued.
 	 */
-	if (ctx->use_bit && ctx->inst_type == CODA_INST_DECODER &&
-	    vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
+	if (ctx->bitstream.size && vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
 		/*
 		 * For backwards compatibility, queuing an empty buffer marks
 		 * the stream end
-- 
2.1.4


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

* RE: [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps
  2015-01-23 16:51 ` [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps Philipp Zabel
@ 2015-01-29 15:34   ` Kamil Debski
  2015-01-29 19:03     ` Philipp Zabel
  0 siblings, 1 reply; 24+ messages in thread
From: Kamil Debski @ 2015-01-29 15:34 UTC (permalink / raw)
  To: 'Philipp Zabel'; +Cc: linux-media

Hi Philipp,

Could you add a one sentence description for this patch?
I know that it is really simple, but still the description is still
necessary.

Best wishes,
-- 
Kamil Debski
Samsung R&D Institute Poland


> -----Original Message-----
> From: Philipp Zabel [mailto:p.zabel@pengutronix.de]
> Sent: Friday, January 23, 2015 5:51 PM
> To: Kamil Debski
> Cc: linux-media@vger.kernel.org; Philipp Zabel
> Subject: [PATCH 02/21] [media] coda: bitrate can only be set in kbps
> steps
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/media/platform/coda/coda-common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/coda/coda-common.c
> b/drivers/media/platform/coda/coda-common.c
> index 39330a7..1cc4e90 100644
> --- a/drivers/media/platform/coda/coda-common.c
> +++ b/drivers/media/platform/coda/coda-common.c
> @@ -1407,7 +1407,7 @@ static const struct v4l2_ctrl_ops coda_ctrl_ops =
> {  static void coda_encode_ctrls(struct coda_ctx *ctx)  {
>  	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
> -		V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1, 0);
> +		V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1000, 0);
>  	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
>  		V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16);
>  	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
> --
> 2.1.4


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

* Re: [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps
  2015-01-29 15:34   ` Kamil Debski
@ 2015-01-29 19:03     ` Philipp Zabel
  0 siblings, 0 replies; 24+ messages in thread
From: Philipp Zabel @ 2015-01-29 19:03 UTC (permalink / raw)
  To: Kamil Debski; +Cc: linux-media

Am Donnerstag, den 29.01.2015, 16:34 +0100 schrieb Kamil Debski:
> Hi Philipp,
> 
> Could you add a one sentence description for this patch?
> I know that it is really simple, but still the description is still
> necessary.
> 
> Best wishes,

Will do, thanks.

regards
Philipp


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

end of thread, other threads:[~2015-01-29 19:04 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23 16:51 [PATCH 00/21] CODA fixes and vmalloc input Philipp Zabel
2015-01-23 16:51 ` [PATCH 01/21] [media] coda: fix encoder rate control parameter masks Philipp Zabel
2015-01-23 16:51 ` [PATCH 02/21] [media] coda: bitrate can only be set in kbps steps Philipp Zabel
2015-01-29 15:34   ` Kamil Debski
2015-01-29 19:03     ` Philipp Zabel
2015-01-23 16:51 ` [PATCH 03/21] [media] coda: remove context debugfs entry last Philipp Zabel
2015-01-23 16:51 ` [PATCH 04/21] [media] coda: move meta out of padding Philipp Zabel
2015-01-23 16:51 ` [PATCH 05/21] [media] coda: adjust sequence offset after unexpected decoded frame Philipp Zabel
2015-01-23 16:51 ` [PATCH 06/21] [media] coda: fix job_ready debug reporting for bitstream decoding Philipp Zabel
2015-01-23 16:51 ` [PATCH 07/21] [media] coda: fix try_fmt_vid_out colorspace setting Philipp Zabel
2015-01-23 16:51 ` [PATCH 08/21] [media] coda: properly clear f_cap in coda_s_fmt_vid_out Philipp Zabel
2015-01-23 16:51 ` [PATCH 09/21] [media] coda: initialize SRAM on probe Philipp Zabel
2015-01-23 16:51 ` [PATCH 10/21] [media] coda: clear RET_DEC_PIC_SUCCESS flag in prepare_decode Philipp Zabel
2015-01-23 16:51 ` [PATCH 11/21] [media] coda: fix width validity check when starting to decode Philipp Zabel
2015-01-23 16:51 ` [PATCH 12/21] [media] coda: remove unused isequence, reset qsequence in stop_streaming Philipp Zabel
2015-01-23 16:51 ` [PATCH 13/21] [media] coda: issue seq_end_work during stop_streaming Philipp Zabel
2015-01-23 16:51 ` [PATCH 14/21] [media] coda: don't ever use subsampling ping-pong buffers as reconstructed reference buffers Philipp Zabel
2015-01-23 16:51 ` [PATCH 15/21] [media] coda: add coda_estimate_sizeimage and use it in set_defaults Philipp Zabel
2015-01-23 16:51 ` [PATCH 16/21] [media] coda: switch BIT decoder source queue to vmalloc Philipp Zabel
2015-01-23 16:51 ` [PATCH 17/21] [media] coda: make seq_end_work optional Philipp Zabel
2015-01-23 16:51 ` [PATCH 18/21] [media] coda: free context buffers under buffer mutex Philipp Zabel
2015-01-23 16:51 ` [PATCH 19/21] [media] coda: add support for contexts that do not use the BIT processor Philipp Zabel
2015-01-23 16:51 ` [PATCH 20/21] [media] coda: allocate bitstream ringbuffer only for BIT decoder Philipp Zabel
2015-01-23 16:51 ` [PATCH 21/21] [media] coda: simplify check in coda_buf_queue Philipp Zabel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.