hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/platform/coda/coda-bit.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Coda multi-standard codec IP - BIT processor functions
34 *
....@@ -5,11 +6,6 @@
56 * Javier Martin, <javier.martin@vista-silicon.com>
67 * Xavier Duret
78 * Copyright (C) 2012-2014 Philipp Zabel, Pengutronix
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
139 */
1410
1511 #include <linux/clk.h>
....@@ -102,6 +98,8 @@
10298 struct coda_dev *dev = ctx->dev;
10399 int ret;
104100
101
+ lockdep_assert_held(&dev->coda_mutex);
102
+
105103 coda_command_async(ctx, cmd);
106104 ret = coda_wait_timeout(dev);
107105 trace_coda_bit_done(ctx);
....@@ -115,6 +113,8 @@
115113 unsigned long timeout;
116114 unsigned int idx;
117115 int ret;
116
+
117
+ lockdep_assert_held(&dev->coda_mutex);
118118
119119 if (!dev->rstc)
120120 return -ENOENT;
....@@ -180,7 +180,7 @@
180180 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx));
181181 }
182182
183
-static int coda_bitstream_pad(struct coda_ctx *ctx, u32 size)
183
+static int coda_h264_bitstream_pad(struct coda_ctx *ctx, u32 size)
184184 {
185185 unsigned char *buf;
186186 u32 n;
....@@ -199,51 +199,122 @@
199199 return (n < size) ? -ENOSPC : 0;
200200 }
201201
202
-static int coda_bitstream_queue(struct coda_ctx *ctx,
203
- struct vb2_v4l2_buffer *src_buf)
202
+int coda_bitstream_flush(struct coda_ctx *ctx)
204203 {
205
- u32 src_size = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
206
- u32 n;
204
+ int ret;
207205
208
- n = kfifo_in(&ctx->bitstream_fifo,
209
- vb2_plane_vaddr(&src_buf->vb2_buf, 0), src_size);
210
- if (n < src_size)
211
- return -ENOSPC;
206
+ if (ctx->inst_type != CODA_INST_DECODER || !ctx->use_bit)
207
+ return 0;
212208
213
- src_buf->sequence = ctx->qsequence++;
209
+ ret = coda_command_sync(ctx, CODA_COMMAND_DEC_BUF_FLUSH);
210
+ if (ret < 0) {
211
+ v4l2_err(&ctx->dev->v4l2_dev, "failed to flush bitstream\n");
212
+ return ret;
213
+ }
214
+
215
+ kfifo_init(&ctx->bitstream_fifo, ctx->bitstream.vaddr,
216
+ ctx->bitstream.size);
217
+ coda_kfifo_sync_to_device_full(ctx);
214218
215219 return 0;
220
+}
221
+
222
+static int coda_bitstream_queue(struct coda_ctx *ctx, const u8 *buf, u32 size)
223
+{
224
+ u32 n = kfifo_in(&ctx->bitstream_fifo, buf, size);
225
+
226
+ return (n < size) ? -ENOSPC : 0;
227
+}
228
+
229
+static u32 coda_buffer_parse_headers(struct coda_ctx *ctx,
230
+ struct vb2_v4l2_buffer *src_buf,
231
+ u32 payload)
232
+{
233
+ u8 *vaddr = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
234
+ u32 size = 0;
235
+
236
+ switch (ctx->codec->src_fourcc) {
237
+ case V4L2_PIX_FMT_MPEG2:
238
+ size = coda_mpeg2_parse_headers(ctx, vaddr, payload);
239
+ break;
240
+ case V4L2_PIX_FMT_MPEG4:
241
+ size = coda_mpeg4_parse_headers(ctx, vaddr, payload);
242
+ break;
243
+ default:
244
+ break;
245
+ }
246
+
247
+ return size;
216248 }
217249
218250 static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
219251 struct vb2_v4l2_buffer *src_buf)
220252 {
221253 unsigned long payload = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
254
+ u8 *vaddr = vb2_plane_vaddr(&src_buf->vb2_buf, 0);
222255 int ret;
256
+ int i;
223257
224258 if (coda_get_bitstream_payload(ctx) + payload + 512 >=
225259 ctx->bitstream.size)
226260 return false;
227261
228
- if (vb2_plane_vaddr(&src_buf->vb2_buf, 0) == NULL) {
262
+ if (!vaddr) {
229263 v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n");
230264 return true;
231265 }
232266
233
- /* Add zero padding before the first H.264 buffer, if it is too small */
267
+ if (ctx->qsequence == 0 && payload < 512) {
268
+ /*
269
+ * Add padding after the first buffer, if it is too small to be
270
+ * fetched by the CODA, by repeating the headers. Without
271
+ * repeated headers, or the first frame already queued, decoder
272
+ * sequence initialization fails with error code 0x2000 on i.MX6
273
+ * or error code 0x1 on i.MX51.
274
+ */
275
+ u32 header_size = coda_buffer_parse_headers(ctx, src_buf,
276
+ payload);
277
+
278
+ if (header_size) {
279
+ coda_dbg(1, ctx, "pad with %u-byte header\n",
280
+ header_size);
281
+ for (i = payload; i < 512; i += header_size) {
282
+ ret = coda_bitstream_queue(ctx, vaddr,
283
+ header_size);
284
+ if (ret < 0) {
285
+ v4l2_err(&ctx->dev->v4l2_dev,
286
+ "bitstream buffer overflow\n");
287
+ return false;
288
+ }
289
+ if (ctx->dev->devtype->product == CODA_960)
290
+ break;
291
+ }
292
+ } else {
293
+ coda_dbg(1, ctx,
294
+ "could not parse header, sequence initialization might fail\n");
295
+ }
296
+ }
297
+
298
+ /* Add padding before the first buffer, if it is too small */
234299 if (ctx->qsequence == 0 && payload < 512 &&
235300 ctx->codec->src_fourcc == V4L2_PIX_FMT_H264)
236
- coda_bitstream_pad(ctx, 512 - payload);
301
+ coda_h264_bitstream_pad(ctx, 512 - payload);
237302
238
- ret = coda_bitstream_queue(ctx, src_buf);
303
+ ret = coda_bitstream_queue(ctx, vaddr, payload);
239304 if (ret < 0) {
240305 v4l2_err(&ctx->dev->v4l2_dev, "bitstream buffer overflow\n");
241306 return false;
242307 }
308
+
309
+ src_buf->sequence = ctx->qsequence++;
310
+
243311 /* Sync read pointer to device */
244312 if (ctx == v4l2_m2m_get_curr_priv(ctx->dev->m2m_dev))
245313 coda_kfifo_sync_to_device_write(ctx);
246314
315
+ /* Set the stream-end flag after the last buffer is queued */
316
+ if (src_buf->flags & V4L2_BUF_FLAG_LAST)
317
+ coda_bit_stream_end_flag(ctx);
247318 ctx->hold = false;
248319
249320 return true;
....@@ -253,7 +324,6 @@
253324 {
254325 struct vb2_v4l2_buffer *src_buf;
255326 struct coda_buffer_meta *meta;
256
- unsigned long flags;
257327 u32 start;
258328
259329 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG)
....@@ -268,6 +338,23 @@
268338 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG &&
269339 ctx->num_metas > 1)
270340 break;
341
+
342
+ if (ctx->num_internal_frames &&
343
+ ctx->num_metas >= ctx->num_internal_frames) {
344
+ meta = list_first_entry(&ctx->buffer_meta_list,
345
+ struct coda_buffer_meta, list);
346
+
347
+ /*
348
+ * If we managed to fill in at least a full reorder
349
+ * window of buffers (num_internal_frames is a
350
+ * conservative estimate for this) and the bitstream
351
+ * prefetcher has at least 2 256 bytes periods beyond
352
+ * the first buffer to fetch, we can safely stop queuing
353
+ * in order to limit the decoder drain latency.
354
+ */
355
+ if (coda_bitstream_can_fetch_past(ctx, meta->end))
356
+ break;
357
+ }
271358
272359 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
273360
....@@ -299,8 +386,7 @@
299386 }
300387
301388 /* Buffer start position */
302
- start = ctx->bitstream_fifo.kfifo.in &
303
- ctx->bitstream_fifo.kfifo.mask;
389
+ start = ctx->bitstream_fifo.kfifo.in;
304390
305391 if (coda_bitstream_try_queue(ctx, src_buf)) {
306392 /*
....@@ -315,15 +401,15 @@
315401 meta->timecode = src_buf->timecode;
316402 meta->timestamp = src_buf->vb2_buf.timestamp;
317403 meta->start = start;
318
- meta->end = ctx->bitstream_fifo.kfifo.in &
319
- ctx->bitstream_fifo.kfifo.mask;
320
- spin_lock_irqsave(&ctx->buffer_meta_lock,
321
- flags);
404
+ meta->end = ctx->bitstream_fifo.kfifo.in;
405
+ meta->last = src_buf->flags & V4L2_BUF_FLAG_LAST;
406
+ if (meta->last)
407
+ coda_dbg(1, ctx, "marking last meta");
408
+ spin_lock(&ctx->buffer_meta_lock);
322409 list_add_tail(&meta->list,
323410 &ctx->buffer_meta_list);
324411 ctx->num_metas++;
325
- spin_unlock_irqrestore(&ctx->buffer_meta_lock,
326
- flags);
412
+ spin_unlock(&ctx->buffer_meta_lock);
327413
328414 trace_coda_bit_queue(ctx, src_buf, meta);
329415 }
....@@ -383,7 +469,7 @@
383469 int i;
384470
385471 for (i = 0; i < CODA_MAX_FRAMEBUFFERS; i++)
386
- coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i]);
472
+ coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i].buf);
387473 }
388474
389475 static int coda_alloc_framebuffers(struct coda_ctx *ctx,
....@@ -423,7 +509,7 @@
423509 coda_free_framebuffers(ctx);
424510 return -ENOMEM;
425511 }
426
- ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i],
512
+ ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i].buf,
427513 size, name);
428514 kfree(name);
429515 if (ret < 0) {
....@@ -437,7 +523,7 @@
437523 u32 y, cb, cr, mvcol;
438524
439525 /* Start addresses of Y, Cb, Cr planes */
440
- y = ctx->internal_frames[i].paddr;
526
+ y = ctx->internal_frames[i].buf.paddr;
441527 cb = y + ysize;
442528 cr = y + ysize + ysize/4;
443529 mvcol = y + ysize + ysize/4 + ysize/4;
....@@ -589,6 +675,102 @@
589675 return 0;
590676 }
591677
678
+static u32 coda_slice_mode(struct coda_ctx *ctx)
679
+{
680
+ int size, unit;
681
+
682
+ switch (ctx->params.slice_mode) {
683
+ case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE:
684
+ default:
685
+ return 0;
686
+ case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB:
687
+ size = ctx->params.slice_max_mb;
688
+ unit = 1;
689
+ break;
690
+ case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES:
691
+ size = ctx->params.slice_max_bits;
692
+ unit = 0;
693
+ break;
694
+ }
695
+
696
+ return ((size & CODA_SLICING_SIZE_MASK) << CODA_SLICING_SIZE_OFFSET) |
697
+ ((unit & CODA_SLICING_UNIT_MASK) << CODA_SLICING_UNIT_OFFSET) |
698
+ ((1 & CODA_SLICING_MODE_MASK) << CODA_SLICING_MODE_OFFSET);
699
+}
700
+
701
+static int coda_enc_param_change(struct coda_ctx *ctx)
702
+{
703
+ struct coda_dev *dev = ctx->dev;
704
+ u32 change_enable = 0;
705
+ u32 success;
706
+ int ret;
707
+
708
+ if (ctx->params.gop_size_changed) {
709
+ change_enable |= CODA_PARAM_CHANGE_RC_GOP;
710
+ coda_write(dev, ctx->params.gop_size,
711
+ CODA_CMD_ENC_PARAM_RC_GOP);
712
+ ctx->gopcounter = ctx->params.gop_size - 1;
713
+ ctx->params.gop_size_changed = false;
714
+ }
715
+ if (ctx->params.h264_intra_qp_changed) {
716
+ coda_dbg(1, ctx, "parameter change: intra Qp %u\n",
717
+ ctx->params.h264_intra_qp);
718
+
719
+ if (ctx->params.bitrate) {
720
+ change_enable |= CODA_PARAM_CHANGE_RC_INTRA_QP;
721
+ coda_write(dev, ctx->params.h264_intra_qp,
722
+ CODA_CMD_ENC_PARAM_RC_INTRA_QP);
723
+ }
724
+ ctx->params.h264_intra_qp_changed = false;
725
+ }
726
+ if (ctx->params.bitrate_changed) {
727
+ coda_dbg(1, ctx, "parameter change: bitrate %u kbit/s\n",
728
+ ctx->params.bitrate);
729
+ change_enable |= CODA_PARAM_CHANGE_RC_BITRATE;
730
+ coda_write(dev, ctx->params.bitrate,
731
+ CODA_CMD_ENC_PARAM_RC_BITRATE);
732
+ ctx->params.bitrate_changed = false;
733
+ }
734
+ if (ctx->params.framerate_changed) {
735
+ coda_dbg(1, ctx, "parameter change: frame rate %u/%u Hz\n",
736
+ ctx->params.framerate & 0xffff,
737
+ (ctx->params.framerate >> 16) + 1);
738
+ change_enable |= CODA_PARAM_CHANGE_RC_FRAME_RATE;
739
+ coda_write(dev, ctx->params.framerate,
740
+ CODA_CMD_ENC_PARAM_RC_FRAME_RATE);
741
+ ctx->params.framerate_changed = false;
742
+ }
743
+ if (ctx->params.intra_refresh_changed) {
744
+ coda_dbg(1, ctx, "parameter change: intra refresh MBs %u\n",
745
+ ctx->params.intra_refresh);
746
+ change_enable |= CODA_PARAM_CHANGE_INTRA_MB_NUM;
747
+ coda_write(dev, ctx->params.intra_refresh,
748
+ CODA_CMD_ENC_PARAM_INTRA_MB_NUM);
749
+ ctx->params.intra_refresh_changed = false;
750
+ }
751
+ if (ctx->params.slice_mode_changed) {
752
+ change_enable |= CODA_PARAM_CHANGE_SLICE_MODE;
753
+ coda_write(dev, coda_slice_mode(ctx),
754
+ CODA_CMD_ENC_PARAM_SLICE_MODE);
755
+ ctx->params.slice_mode_changed = false;
756
+ }
757
+
758
+ if (!change_enable)
759
+ return 0;
760
+
761
+ coda_write(dev, change_enable, CODA_CMD_ENC_PARAM_CHANGE_ENABLE);
762
+
763
+ ret = coda_command_sync(ctx, CODA_COMMAND_RC_CHANGE_PARAMETER);
764
+ if (ret < 0)
765
+ return ret;
766
+
767
+ success = coda_read(dev, CODA_RET_ENC_PARAM_CHANGE_SUCCESS);
768
+ if (success != 1)
769
+ coda_dbg(1, ctx, "parameter change failed: %u\n", success);
770
+
771
+ return 0;
772
+}
773
+
592774 static phys_addr_t coda_iram_alloc(struct coda_iram_info *iram, size_t size)
593775 {
594776 phys_addr_t ret;
....@@ -713,8 +895,7 @@
713895
714896 out:
715897 if (!(iram_info->axi_sram_use & CODA7_USE_HOST_IP_ENABLE))
716
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
717
- "IRAM smaller than needed\n");
898
+ coda_dbg(1, ctx, "IRAM smaller than needed\n");
718899
719900 if (dev->devtype->product == CODA_HX4 ||
720901 dev->devtype->product == CODA_7541) {
....@@ -920,7 +1101,7 @@
9201101 break;
9211102 case CODA_960:
9221103 coda_write(dev, 0, CODA9_GDI_WPROT_RGN_EN);
923
- /* fallthrough */
1104
+ fallthrough;
9241105 case CODA_HX4:
9251106 case CODA_7541:
9261107 coda_write(dev, CODA7_STREAM_BUF_DYNALLOC_EN |
....@@ -960,7 +1141,7 @@
9601141 CODA7_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET;
9611142 break;
9621143 }
963
- /* fallthrough */
1144
+ fallthrough;
9641145 case CODA_960:
9651146 value = (q_data_src->rect.width & CODA7_PICWIDTH_MASK)
9661147 << CODA7_PICWIDTH_OFFSET;
....@@ -999,7 +1180,11 @@
9991180 CODA_264PARAM_DEBLKFILTEROFFSETALPHA_OFFSET) |
10001181 ((ctx->params.h264_slice_beta_offset_div2 &
10011182 CODA_264PARAM_DEBLKFILTEROFFSETBETA_MASK) <<
1002
- CODA_264PARAM_DEBLKFILTEROFFSETBETA_OFFSET);
1183
+ CODA_264PARAM_DEBLKFILTEROFFSETBETA_OFFSET) |
1184
+ (ctx->params.h264_constrained_intra_pred_flag <<
1185
+ CODA_264PARAM_CONSTRAINEDINTRAPREDFLAG_OFFSET) |
1186
+ (ctx->params.h264_chroma_qp_index_offset &
1187
+ CODA_264PARAM_CHROMAQPOFFSET_MASK);
10031188 coda_write(dev, value, CODA_CMD_ENC_SEQ_264_PARA);
10041189 break;
10051190 case V4L2_PIX_FMT_JPEG:
....@@ -1024,33 +1209,17 @@
10241209 * in JPEG mode
10251210 */
10261211 if (dst_fourcc != V4L2_PIX_FMT_JPEG) {
1027
- switch (ctx->params.slice_mode) {
1028
- case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE:
1029
- value = 0;
1030
- break;
1031
- case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB:
1032
- value = (ctx->params.slice_max_mb &
1033
- CODA_SLICING_SIZE_MASK)
1034
- << CODA_SLICING_SIZE_OFFSET;
1035
- value |= (1 & CODA_SLICING_UNIT_MASK)
1036
- << CODA_SLICING_UNIT_OFFSET;
1037
- value |= 1 & CODA_SLICING_MODE_MASK;
1038
- break;
1039
- case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES:
1040
- value = (ctx->params.slice_max_bits &
1041
- CODA_SLICING_SIZE_MASK)
1042
- << CODA_SLICING_SIZE_OFFSET;
1043
- value |= (0 & CODA_SLICING_UNIT_MASK)
1044
- << CODA_SLICING_UNIT_OFFSET;
1045
- value |= 1 & CODA_SLICING_MODE_MASK;
1046
- break;
1047
- }
1212
+ value = coda_slice_mode(ctx);
10481213 coda_write(dev, value, CODA_CMD_ENC_SEQ_SLICE_MODE);
10491214 value = ctx->params.gop_size;
10501215 coda_write(dev, value, CODA_CMD_ENC_SEQ_GOP_SIZE);
10511216 }
10521217
1053
- if (ctx->params.bitrate) {
1218
+ if (ctx->params.bitrate && (ctx->params.frame_rc_enable ||
1219
+ ctx->params.mb_rc_enable)) {
1220
+ ctx->params.bitrate_changed = false;
1221
+ ctx->params.h264_intra_qp_changed = false;
1222
+
10541223 /* Rate control enabled */
10551224 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK)
10561225 << CODA_RATECONTROL_BITRATE_OFFSET;
....@@ -1108,7 +1277,11 @@
11081277 }
11091278 coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION);
11101279
1111
- coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE);
1280
+ if (ctx->params.frame_rc_enable && !ctx->params.mb_rc_enable)
1281
+ value = 1;
1282
+ else
1283
+ value = 0;
1284
+ coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE);
11121285
11131286 coda_setup_iram(ctx);
11141287
....@@ -1187,9 +1360,9 @@
11871360 coda9_set_frame_cache(ctx, q_data_src->fourcc);
11881361
11891362 /* FIXME */
1190
- coda_write(dev, ctx->internal_frames[2].paddr,
1363
+ coda_write(dev, ctx->internal_frames[2].buf.paddr,
11911364 CODA9_CMD_SET_FRAME_SUBSAMP_A);
1192
- coda_write(dev, ctx->internal_frames[3].paddr,
1365
+ coda_write(dev, ctx->internal_frames[3].buf.paddr,
11931366 CODA9_CMD_SET_FRAME_SUBSAMP_B);
11941367 }
11951368 }
....@@ -1199,6 +1372,12 @@
11991372 v4l2_err(v4l2_dev, "CODA_COMMAND_SET_FRAME_BUF timeout\n");
12001373 goto out;
12011374 }
1375
+
1376
+ coda_dbg(1, ctx, "start encoding %dx%d %4.4s->%4.4s @ %d/%d Hz\n",
1377
+ q_data_src->rect.width, q_data_src->rect.height,
1378
+ (char *)&ctx->codec->src_fourcc, (char *)&dst_fourcc,
1379
+ ctx->params.framerate & 0xffff,
1380
+ (ctx->params.framerate >> 16) + 1);
12021381
12031382 /* Save stream headers */
12041383 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
....@@ -1299,6 +1478,13 @@
12991478 u32 rot_mode = 0;
13001479 u32 dst_fourcc;
13011480 u32 reg;
1481
+ int ret;
1482
+
1483
+ ret = coda_enc_param_change(ctx);
1484
+ if (ret < 0) {
1485
+ v4l2_warn(&ctx->dev->v4l2_dev, "parameter change failed: %d\n",
1486
+ ret);
1487
+ }
13021488
13031489 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
13041490 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
....@@ -1435,12 +1621,28 @@
14351621 return 0;
14361622 }
14371623
1624
+static char coda_frame_type_char(u32 flags)
1625
+{
1626
+ return (flags & V4L2_BUF_FLAG_KEYFRAME) ? 'I' :
1627
+ (flags & V4L2_BUF_FLAG_PFRAME) ? 'P' :
1628
+ (flags & V4L2_BUF_FLAG_BFRAME) ? 'B' : '?';
1629
+}
1630
+
14381631 static void coda_finish_encode(struct coda_ctx *ctx)
14391632 {
14401633 struct vb2_v4l2_buffer *src_buf, *dst_buf;
14411634 struct coda_dev *dev = ctx->dev;
14421635 u32 wr_ptr, start_ptr;
14431636
1637
+ if (ctx->aborting)
1638
+ return;
1639
+
1640
+ /*
1641
+ * Lock to make sure that an encoder stop command running in parallel
1642
+ * will either already have marked src_buf as last, or it will wake up
1643
+ * the capture queue after the buffers are returned.
1644
+ */
1645
+ mutex_lock(&ctx->wakeup_mutex);
14441646 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
14451647 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
14461648
....@@ -1461,41 +1663,35 @@
14611663 vb2_set_plane_payload(&dst_buf->vb2_buf, 0, wr_ptr - start_ptr);
14621664 }
14631665
1464
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "frame size = %u\n",
1465
- wr_ptr - start_ptr);
1666
+ coda_dbg(1, ctx, "frame size = %u\n", wr_ptr - start_ptr);
14661667
14671668 coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM);
14681669 coda_read(dev, CODA_RET_ENC_PIC_FLAG);
14691670
1470
- if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0) {
1671
+ dst_buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
1672
+ V4L2_BUF_FLAG_PFRAME |
1673
+ V4L2_BUF_FLAG_LAST);
1674
+ if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0)
14711675 dst_buf->flags |= V4L2_BUF_FLAG_KEYFRAME;
1472
- dst_buf->flags &= ~V4L2_BUF_FLAG_PFRAME;
1473
- } else {
1676
+ else
14741677 dst_buf->flags |= V4L2_BUF_FLAG_PFRAME;
1475
- dst_buf->flags &= ~V4L2_BUF_FLAG_KEYFRAME;
1476
- }
1678
+ dst_buf->flags |= src_buf->flags & V4L2_BUF_FLAG_LAST;
14771679
1478
- dst_buf->vb2_buf.timestamp = src_buf->vb2_buf.timestamp;
1479
- dst_buf->field = src_buf->field;
1480
- dst_buf->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
1481
- dst_buf->flags |=
1482
- src_buf->flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
1483
- dst_buf->timecode = src_buf->timecode;
1680
+ v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, false);
14841681
14851682 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
14861683
14871684 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
14881685 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE);
1686
+ mutex_unlock(&ctx->wakeup_mutex);
14891687
14901688 ctx->gopcounter--;
14911689 if (ctx->gopcounter < 0)
14921690 ctx->gopcounter = ctx->params.gop_size - 1;
14931691
1494
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1495
- "job finished: encoding frame (%d) (%s)\n",
1496
- dst_buf->sequence,
1497
- (dst_buf->flags & V4L2_BUF_FLAG_KEYFRAME) ?
1498
- "KEYFRAME" : "PFRAME");
1692
+ coda_dbg(1, ctx, "job finished: encoded %c frame (%d)%s\n",
1693
+ coda_frame_type_char(dst_buf->flags), dst_buf->sequence,
1694
+ (dst_buf->flags & V4L2_BUF_FLAG_LAST) ? " (last)" : "");
14991695 }
15001696
15011697 static void coda_seq_end_work(struct work_struct *work)
....@@ -1509,9 +1705,7 @@
15091705 if (ctx->initialized == 0)
15101706 goto out;
15111707
1512
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1513
- "%d: %s: sent command 'SEQ_END' to coda\n", ctx->idx,
1514
- __func__);
1708
+ coda_dbg(1, ctx, "%s: sent command 'SEQ_END' to coda\n", __func__);
15151709 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) {
15161710 v4l2_err(&dev->v4l2_dev,
15171711 "CODA_COMMAND_SEQ_END failed\n");
....@@ -1567,8 +1761,7 @@
15671761 return 0;
15681762
15691763 ctx->bitstream.size = roundup_pow_of_two(q_data->sizeimage * 2);
1570
- ctx->bitstream.vaddr = dma_alloc_wc(&ctx->dev->plat_dev->dev,
1571
- ctx->bitstream.size,
1764
+ ctx->bitstream.vaddr = dma_alloc_wc(ctx->dev->dev, ctx->bitstream.size,
15721765 &ctx->bitstream.paddr, GFP_KERNEL);
15731766 if (!ctx->bitstream.vaddr) {
15741767 v4l2_err(&ctx->dev->v4l2_dev,
....@@ -1586,8 +1779,8 @@
15861779 if (ctx->bitstream.vaddr == NULL)
15871780 return;
15881781
1589
- dma_free_wc(&ctx->dev->plat_dev->dev, ctx->bitstream.size,
1590
- ctx->bitstream.vaddr, ctx->bitstream.paddr);
1782
+ dma_free_wc(ctx->dev->dev, ctx->bitstream.size, ctx->bitstream.vaddr,
1783
+ ctx->bitstream.paddr);
15911784 ctx->bitstream.vaddr = NULL;
15921785 kfifo_init(&ctx->bitstream_fifo, NULL, 0);
15931786 }
....@@ -1644,7 +1837,7 @@
16441837 return profile > V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE;
16451838 }
16461839
1647
-static int __coda_start_decoding(struct coda_ctx *ctx)
1840
+static int __coda_decoder_seq_init(struct coda_ctx *ctx)
16481841 {
16491842 struct coda_q_data *q_data_src, *q_data_dst;
16501843 u32 bitstream_buf, bitstream_size;
....@@ -1654,8 +1847,9 @@
16541847 u32 val;
16551848 int ret;
16561849
1657
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1658
- "Video Data Order Adapter: %s\n",
1850
+ lockdep_assert_held(&dev->coda_mutex);
1851
+
1852
+ coda_dbg(1, ctx, "Video Data Order Adapter: %s\n",
16591853 ctx->use_vdoa ? "Enabled" : "Disabled");
16601854
16611855 /* Start decoding */
....@@ -1665,8 +1859,6 @@
16651859 bitstream_size = ctx->bitstream.size;
16661860 src_fourcc = q_data_src->fourcc;
16671861 dst_fourcc = q_data_dst->fourcc;
1668
-
1669
- coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR);
16701862
16711863 /* Update coda bitstream read and write pointers from kfifo */
16721864 coda_kfifo_sync_to_device_full(ctx);
....@@ -1736,7 +1928,7 @@
17361928
17371929 if (coda_read(dev, CODA_RET_DEC_SEQ_SUCCESS) == 0) {
17381930 v4l2_err(&dev->v4l2_dev,
1739
- "CODA_COMMAND_SEQ_INIT failed, error code = %d\n",
1931
+ "CODA_COMMAND_SEQ_INIT failed, error code = 0x%x\n",
17401932 coda_read(dev, CODA_RET_DEC_SEQ_ERR_REASON));
17411933 return -EAGAIN;
17421934 }
....@@ -1760,8 +1952,7 @@
17601952 width = round_up(width, 16);
17611953 height = round_up(height, 16);
17621954
1763
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "%s instance %d now: %dx%d\n",
1764
- __func__, ctx->idx, width, height);
1955
+ coda_dbg(1, ctx, "start decoding: %dx%d\n", width, height);
17651956
17661957 ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED);
17671958 /*
....@@ -1795,6 +1986,72 @@
17951986 (top_bottom & 0x3ff);
17961987 }
17971988
1989
+ if (dev->devtype->product != CODA_DX6) {
1990
+ u8 profile, level;
1991
+
1992
+ val = coda_read(dev, CODA7_RET_DEC_SEQ_HEADER_REPORT);
1993
+ profile = val & 0xff;
1994
+ level = (val >> 8) & 0x7f;
1995
+
1996
+ if (profile || level)
1997
+ coda_update_profile_level_ctrls(ctx, profile, level);
1998
+ }
1999
+
2000
+ return 0;
2001
+}
2002
+
2003
+static void coda_dec_seq_init_work(struct work_struct *work)
2004
+{
2005
+ struct coda_ctx *ctx = container_of(work,
2006
+ struct coda_ctx, seq_init_work);
2007
+ struct coda_dev *dev = ctx->dev;
2008
+ int ret;
2009
+
2010
+ mutex_lock(&ctx->buffer_mutex);
2011
+ mutex_lock(&dev->coda_mutex);
2012
+
2013
+ if (ctx->initialized == 1)
2014
+ goto out;
2015
+
2016
+ ret = __coda_decoder_seq_init(ctx);
2017
+ if (ret < 0)
2018
+ goto out;
2019
+
2020
+ ctx->initialized = 1;
2021
+
2022
+out:
2023
+ mutex_unlock(&dev->coda_mutex);
2024
+ mutex_unlock(&ctx->buffer_mutex);
2025
+}
2026
+
2027
+static int __coda_start_decoding(struct coda_ctx *ctx)
2028
+{
2029
+ struct coda_q_data *q_data_src, *q_data_dst;
2030
+ struct coda_dev *dev = ctx->dev;
2031
+ u32 src_fourcc, dst_fourcc;
2032
+ int ret;
2033
+
2034
+ q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
2035
+ q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
2036
+ src_fourcc = q_data_src->fourcc;
2037
+ dst_fourcc = q_data_dst->fourcc;
2038
+
2039
+ if (!ctx->initialized) {
2040
+ ret = __coda_decoder_seq_init(ctx);
2041
+ if (ret < 0)
2042
+ return ret;
2043
+ } else {
2044
+ ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) |
2045
+ CODA9_FRAME_TILED2LINEAR);
2046
+ if (dst_fourcc == V4L2_PIX_FMT_NV12 || dst_fourcc == V4L2_PIX_FMT_YUYV)
2047
+ ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE;
2048
+ if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP)
2049
+ ctx->frame_mem_ctrl |= (0x3 << 9) |
2050
+ ((ctx->use_vdoa) ? 0 : CODA9_FRAME_TILED2LINEAR);
2051
+ }
2052
+
2053
+ coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR);
2054
+
17982055 ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc);
17992056 if (ret < 0) {
18002057 v4l2_err(&dev->v4l2_dev, "failed to allocate framebuffers\n");
....@@ -1803,7 +2060,8 @@
18032060
18042061 /* Tell the decoder how many frame buffers we allocated. */
18052062 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM);
1806
- coda_write(dev, width, CODA_CMD_SET_FRAME_BUF_STRIDE);
2063
+ coda_write(dev, round_up(q_data_dst->rect.width, 16),
2064
+ CODA_CMD_SET_FRAME_BUF_STRIDE);
18072065
18082066 if (dev->devtype->product != CODA_DX6) {
18092067 /* Set secondary AXI IRAM */
....@@ -1879,7 +2137,6 @@
18792137 struct coda_dev *dev = ctx->dev;
18802138 struct coda_q_data *q_data_dst;
18812139 struct coda_buffer_meta *meta;
1882
- unsigned long flags;
18832140 u32 rot_mode = 0;
18842141 u32 reg_addr, reg_stride;
18852142
....@@ -1893,8 +2150,7 @@
18932150
18942151 if (coda_get_bitstream_payload(ctx) < 512 &&
18952152 (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) {
1896
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1897
- "bitstream payload: %d, skipping\n",
2153
+ coda_dbg(1, ctx, "bitstream payload: %d, skipping\n",
18982154 coda_get_bitstream_payload(ctx));
18992155 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx);
19002156 return -EAGAIN;
....@@ -1921,20 +2177,25 @@
19212177 ctx->display_idx < ctx->num_internal_frames) {
19222178 vdoa_device_run(ctx->vdoa,
19232179 vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0),
1924
- ctx->internal_frames[ctx->display_idx].paddr);
2180
+ ctx->internal_frames[ctx->display_idx].buf.paddr);
19252181 } else {
19262182 if (dev->devtype->product == CODA_960) {
19272183 /*
1928
- * The CODA960 seems to have an internal list of
1929
- * buffers with 64 entries that includes the
1930
- * registered frame buffers as well as the rotator
1931
- * buffer output.
1932
- *
1933
- * ROT_INDEX needs to be < 0x40, but >
1934
- * ctx->num_internal_frames.
2184
+ * It was previously assumed that the CODA960 has an
2185
+ * internal list of 64 buffer entries that contains
2186
+ * both the registered internal frame buffers as well
2187
+ * as the rotator buffer output, and that the ROT_INDEX
2188
+ * register must be set to a value between the last
2189
+ * internal frame buffers' index and 64.
2190
+ * At least on firmware version 3.1.1 it turns out that
2191
+ * setting ROT_INDEX to any value >= 32 causes CODA
2192
+ * hangups that it can not recover from with the SRC VPU
2193
+ * reset.
2194
+ * It does appear to work however, to just set it to a
2195
+ * fixed value in the [ctx->num_internal_frames, 31]
2196
+ * range, for example CODA_MAX_FRAMEBUFFERS.
19352197 */
1936
- coda_write(dev,
1937
- CODA_MAX_FRAMEBUFFERS + dst_buf->vb2_buf.index,
2198
+ coda_write(dev, CODA_MAX_FRAMEBUFFERS,
19382199 CODA9_CMD_DEC_PIC_ROT_INDEX);
19392200
19402201 reg_addr = CODA9_CMD_DEC_PIC_ROT_ADDR_Y;
....@@ -1973,15 +2234,14 @@
19732234 coda_write(dev, ctx->iram_info.axi_sram_use,
19742235 CODA7_REG_BIT_AXI_SRAM_USE);
19752236
1976
- spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
2237
+ spin_lock(&ctx->buffer_meta_lock);
19772238 meta = list_first_entry_or_null(&ctx->buffer_meta_list,
19782239 struct coda_buffer_meta, list);
19792240
19802241 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) {
19812242
19822243 /* If this is the last buffer in the bitstream, add padding */
1983
- if (meta->end == (ctx->bitstream_fifo.kfifo.in &
1984
- ctx->bitstream_fifo.kfifo.mask)) {
2244
+ if (meta->end == ctx->bitstream_fifo.kfifo.in) {
19852245 static unsigned char buf[512];
19862246 unsigned int pad;
19872247
....@@ -1993,7 +2253,7 @@
19932253 kfifo_in(&ctx->bitstream_fifo, buf, pad);
19942254 }
19952255 }
1996
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2256
+ spin_unlock(&ctx->buffer_meta_lock);
19972257
19982258 coda_kfifo_sync_to_device_full(ctx);
19992259
....@@ -2017,16 +2277,18 @@
20172277 struct coda_q_data *q_data_dst;
20182278 struct vb2_v4l2_buffer *dst_buf;
20192279 struct coda_buffer_meta *meta;
2020
- unsigned long payload;
2021
- unsigned long flags;
20222280 int width, height;
20232281 int decoded_idx;
20242282 int display_idx;
2283
+ struct coda_internal_frame *decoded_frame = NULL;
20252284 u32 src_fourcc;
20262285 int success;
20272286 u32 err_mb;
20282287 int err_vdoa = 0;
20292288 u32 val;
2289
+
2290
+ if (ctx->aborting)
2291
+ return;
20302292
20312293 /* Update kfifo out pointer from coda bitstream read pointer */
20322294 coda_kfifo_sync_from_device(ctx);
....@@ -2103,8 +2365,7 @@
21032365 val = coda_read(dev, CODA_RET_DEC_PIC_OPTION);
21042366 if (val == 0) {
21052367 /* not enough bitstream data */
2106
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
2107
- "prescan failed: %d\n", val);
2368
+ coda_dbg(1, ctx, "prescan failed: %d\n", val);
21082369 ctx->hold = true;
21092370 return;
21102371 }
....@@ -2151,17 +2412,19 @@
21512412 v4l2_err(&dev->v4l2_dev,
21522413 "decoded frame index out of range: %d\n", decoded_idx);
21532414 } else {
2415
+ decoded_frame = &ctx->internal_frames[decoded_idx];
2416
+
21542417 val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM);
21552418 if (ctx->sequence_offset == -1)
21562419 ctx->sequence_offset = val;
21572420 val -= ctx->sequence_offset;
2158
- spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
2421
+ spin_lock(&ctx->buffer_meta_lock);
21592422 if (!list_empty(&ctx->buffer_meta_list)) {
21602423 meta = list_first_entry(&ctx->buffer_meta_list,
21612424 struct coda_buffer_meta, list);
21622425 list_del(&meta->list);
21632426 ctx->num_metas--;
2164
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2427
+ spin_unlock(&ctx->buffer_meta_lock);
21652428 /*
21662429 * Clamp counters to 16 bits for comparison, as the HW
21672430 * counter rolls over at this point for h.264. This
....@@ -2175,28 +2438,26 @@
21752438 val, ctx->sequence_offset,
21762439 meta->sequence);
21772440 }
2178
- ctx->frame_metas[decoded_idx] = *meta;
2441
+ decoded_frame->meta = *meta;
21792442 kfree(meta);
21802443 } else {
2181
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2444
+ spin_unlock(&ctx->buffer_meta_lock);
21822445 v4l2_err(&dev->v4l2_dev, "empty timestamp list!\n");
2183
- memset(&ctx->frame_metas[decoded_idx], 0,
2446
+ memset(&decoded_frame->meta, 0,
21842447 sizeof(struct coda_buffer_meta));
2185
- ctx->frame_metas[decoded_idx].sequence = val;
2448
+ decoded_frame->meta.sequence = val;
2449
+ decoded_frame->meta.last = false;
21862450 ctx->sequence_offset++;
21872451 }
21882452
2189
- trace_coda_dec_pic_done(ctx, &ctx->frame_metas[decoded_idx]);
2453
+ trace_coda_dec_pic_done(ctx, &decoded_frame->meta);
21902454
21912455 val = coda_read(dev, CODA_RET_DEC_PIC_TYPE) & 0x7;
2192
- if (val == 0)
2193
- ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_KEYFRAME;
2194
- else if (val == 1)
2195
- ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_PFRAME;
2196
- else
2197
- ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_BFRAME;
2456
+ decoded_frame->type = (val == 0) ? V4L2_BUF_FLAG_KEYFRAME :
2457
+ (val == 1) ? V4L2_BUF_FLAG_PFRAME :
2458
+ V4L2_BUF_FLAG_BFRAME;
21982459
2199
- ctx->frame_errors[decoded_idx] = err_mb;
2460
+ decoded_frame->error = err_mb;
22002461 }
22012462
22022463 if (display_idx == -1) {
....@@ -2216,6 +2477,10 @@
22162477 /* If a frame was copied out, return it */
22172478 if (ctx->display_idx >= 0 &&
22182479 ctx->display_idx < ctx->num_internal_frames) {
2480
+ struct coda_internal_frame *ready_frame;
2481
+
2482
+ ready_frame = &ctx->internal_frames[ctx->display_idx];
2483
+
22192484 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
22202485 dst_buf->sequence = ctx->osequence++;
22212486
....@@ -2223,46 +2488,81 @@
22232488 dst_buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
22242489 V4L2_BUF_FLAG_PFRAME |
22252490 V4L2_BUF_FLAG_BFRAME);
2226
- dst_buf->flags |= ctx->frame_types[ctx->display_idx];
2227
- meta = &ctx->frame_metas[ctx->display_idx];
2491
+ dst_buf->flags |= ready_frame->type;
2492
+ meta = &ready_frame->meta;
2493
+ if (meta->last && !coda_reorder_enable(ctx)) {
2494
+ /*
2495
+ * If this was the last decoded frame, and reordering
2496
+ * is disabled, this will be the last display frame.
2497
+ */
2498
+ coda_dbg(1, ctx, "last meta, marking as last frame\n");
2499
+ dst_buf->flags |= V4L2_BUF_FLAG_LAST;
2500
+ } else if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG &&
2501
+ display_idx == -1) {
2502
+ /*
2503
+ * If there is no designated presentation frame anymore,
2504
+ * this frame has to be the last one.
2505
+ */
2506
+ coda_dbg(1, ctx,
2507
+ "no more frames to return, marking as last frame\n");
2508
+ dst_buf->flags |= V4L2_BUF_FLAG_LAST;
2509
+ }
22282510 dst_buf->timecode = meta->timecode;
22292511 dst_buf->vb2_buf.timestamp = meta->timestamp;
22302512
22312513 trace_coda_dec_rot_done(ctx, dst_buf, meta);
22322514
2233
- switch (q_data_dst->fourcc) {
2234
- case V4L2_PIX_FMT_YUYV:
2235
- payload = width * height * 2;
2236
- break;
2237
- case V4L2_PIX_FMT_YUV420:
2238
- case V4L2_PIX_FMT_YVU420:
2239
- case V4L2_PIX_FMT_NV12:
2240
- default:
2241
- payload = width * height * 3 / 2;
2242
- break;
2243
- case V4L2_PIX_FMT_YUV422P:
2244
- payload = width * height * 2;
2245
- break;
2246
- }
2247
- vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload);
2515
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
2516
+ q_data_dst->sizeimage);
22482517
2249
- if (ctx->frame_errors[ctx->display_idx] || err_vdoa)
2518
+ if (ready_frame->error || err_vdoa)
22502519 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_ERROR);
22512520 else
22522521 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE);
22532522
2254
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
2255
- "job finished: decoding frame (%d) (%s)\n",
2256
- dst_buf->sequence,
2257
- (dst_buf->flags & V4L2_BUF_FLAG_KEYFRAME) ?
2258
- "KEYFRAME" : "PFRAME");
2523
+ if (decoded_frame) {
2524
+ coda_dbg(1, ctx, "job finished: decoded %c frame %u, returned %c frame %u (%u/%u)%s\n",
2525
+ coda_frame_type_char(decoded_frame->type),
2526
+ decoded_frame->meta.sequence,
2527
+ coda_frame_type_char(dst_buf->flags),
2528
+ ready_frame->meta.sequence,
2529
+ dst_buf->sequence, ctx->qsequence,
2530
+ (dst_buf->flags & V4L2_BUF_FLAG_LAST) ?
2531
+ " (last)" : "");
2532
+ } else {
2533
+ coda_dbg(1, ctx, "job finished: no frame decoded (%d), returned %c frame %u (%u/%u)%s\n",
2534
+ decoded_idx,
2535
+ coda_frame_type_char(dst_buf->flags),
2536
+ ready_frame->meta.sequence,
2537
+ dst_buf->sequence, ctx->qsequence,
2538
+ (dst_buf->flags & V4L2_BUF_FLAG_LAST) ?
2539
+ " (last)" : "");
2540
+ }
22592541 } else {
2260
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
2261
- "job finished: no frame decoded\n");
2542
+ if (decoded_frame) {
2543
+ coda_dbg(1, ctx, "job finished: decoded %c frame %u, no frame returned (%d)\n",
2544
+ coda_frame_type_char(decoded_frame->type),
2545
+ decoded_frame->meta.sequence,
2546
+ ctx->display_idx);
2547
+ } else {
2548
+ coda_dbg(1, ctx, "job finished: no frame decoded (%d) or returned (%d)\n",
2549
+ decoded_idx, ctx->display_idx);
2550
+ }
22622551 }
22632552
22642553 /* The rotator will copy the current display frame next time */
22652554 ctx->display_idx = display_idx;
2555
+
2556
+ /*
2557
+ * The current decode run might have brought the bitstream fill level
2558
+ * below the size where we can start the next decode run. As userspace
2559
+ * might have filled the output queue completely and might thus be
2560
+ * blocked, we can't rely on the next qbuf to trigger the bitstream
2561
+ * refill. Check if we have data to refill the bitstream now.
2562
+ */
2563
+ mutex_lock(&ctx->bitstream_mutex);
2564
+ coda_fill_bitstream(ctx, NULL);
2565
+ mutex_unlock(&ctx->bitstream_mutex);
22662566 }
22672567
22682568 static void coda_decode_timeout(struct coda_ctx *ctx)
....@@ -2291,6 +2591,7 @@
22912591 .prepare_run = coda_prepare_decode,
22922592 .finish_run = coda_finish_decode,
22932593 .run_timeout = coda_decode_timeout,
2594
+ .seq_init_work = coda_dec_seq_init_work,
22942595 .seq_end_work = coda_seq_end_work,
22952596 .release = coda_bit_release,
22962597 };
....@@ -2302,6 +2603,7 @@
23022603
23032604 /* read status register to attend the IRQ */
23042605 coda_read(dev, CODA_REG_BIT_INT_STATUS);
2606
+ coda_write(dev, 0, CODA_REG_BIT_INT_REASON);
23052607 coda_write(dev, CODA_REG_BIT_INT_CLEAR_SET,
23062608 CODA_REG_BIT_INT_CLEAR);
23072609
....@@ -2315,13 +2617,11 @@
23152617 trace_coda_bit_done(ctx);
23162618
23172619 if (ctx->aborting) {
2318
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
2319
- "task has been aborted\n");
2620
+ coda_dbg(1, ctx, "task has been aborted\n");
23202621 }
23212622
23222623 if (coda_isbusy(ctx->dev)) {
2323
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
2324
- "coda is still busy!!!!\n");
2624
+ coda_dbg(1, ctx, "coda is still busy!!!!\n");
23252625 return IRQ_NONE;
23262626 }
23272627