forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
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;
....@@ -670,7 +852,7 @@
670852 /* Only H.264BP and H.263P3 are considered */
671853 iram_info->buf_dbk_y_use = coda_iram_alloc(iram_info, w64);
672854 iram_info->buf_dbk_c_use = coda_iram_alloc(iram_info, w64);
673
- if (!iram_info->buf_dbk_c_use)
855
+ if (!iram_info->buf_dbk_y_use || !iram_info->buf_dbk_c_use)
674856 goto out;
675857 iram_info->axi_sram_use |= dbk_bits;
676858
....@@ -694,7 +876,7 @@
694876
695877 iram_info->buf_dbk_y_use = coda_iram_alloc(iram_info, w128);
696878 iram_info->buf_dbk_c_use = coda_iram_alloc(iram_info, w128);
697
- if (!iram_info->buf_dbk_c_use)
879
+ if (!iram_info->buf_dbk_y_use || !iram_info->buf_dbk_c_use)
698880 goto out;
699881 iram_info->axi_sram_use |= dbk_bits;
700882
....@@ -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) {
....@@ -901,10 +1082,16 @@
9011082 }
9021083
9031084 if (dst_fourcc == V4L2_PIX_FMT_JPEG) {
904
- if (!ctx->params.jpeg_qmat_tab[0])
1085
+ if (!ctx->params.jpeg_qmat_tab[0]) {
9051086 ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL);
906
- if (!ctx->params.jpeg_qmat_tab[1])
1087
+ if (!ctx->params.jpeg_qmat_tab[0])
1088
+ return -ENOMEM;
1089
+ }
1090
+ if (!ctx->params.jpeg_qmat_tab[1]) {
9071091 ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL);
1092
+ if (!ctx->params.jpeg_qmat_tab[1])
1093
+ return -ENOMEM;
1094
+ }
9081095 coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality);
9091096 }
9101097
....@@ -920,7 +1107,7 @@
9201107 break;
9211108 case CODA_960:
9221109 coda_write(dev, 0, CODA9_GDI_WPROT_RGN_EN);
923
- /* fallthrough */
1110
+ fallthrough;
9241111 case CODA_HX4:
9251112 case CODA_7541:
9261113 coda_write(dev, CODA7_STREAM_BUF_DYNALLOC_EN |
....@@ -960,7 +1147,7 @@
9601147 CODA7_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET;
9611148 break;
9621149 }
963
- /* fallthrough */
1150
+ fallthrough;
9641151 case CODA_960:
9651152 value = (q_data_src->rect.width & CODA7_PICWIDTH_MASK)
9661153 << CODA7_PICWIDTH_OFFSET;
....@@ -999,7 +1186,11 @@
9991186 CODA_264PARAM_DEBLKFILTEROFFSETALPHA_OFFSET) |
10001187 ((ctx->params.h264_slice_beta_offset_div2 &
10011188 CODA_264PARAM_DEBLKFILTEROFFSETBETA_MASK) <<
1002
- CODA_264PARAM_DEBLKFILTEROFFSETBETA_OFFSET);
1189
+ CODA_264PARAM_DEBLKFILTEROFFSETBETA_OFFSET) |
1190
+ (ctx->params.h264_constrained_intra_pred_flag <<
1191
+ CODA_264PARAM_CONSTRAINEDINTRAPREDFLAG_OFFSET) |
1192
+ (ctx->params.h264_chroma_qp_index_offset &
1193
+ CODA_264PARAM_CHROMAQPOFFSET_MASK);
10031194 coda_write(dev, value, CODA_CMD_ENC_SEQ_264_PARA);
10041195 break;
10051196 case V4L2_PIX_FMT_JPEG:
....@@ -1024,33 +1215,17 @@
10241215 * in JPEG mode
10251216 */
10261217 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
- }
1218
+ value = coda_slice_mode(ctx);
10481219 coda_write(dev, value, CODA_CMD_ENC_SEQ_SLICE_MODE);
10491220 value = ctx->params.gop_size;
10501221 coda_write(dev, value, CODA_CMD_ENC_SEQ_GOP_SIZE);
10511222 }
10521223
1053
- if (ctx->params.bitrate) {
1224
+ if (ctx->params.bitrate && (ctx->params.frame_rc_enable ||
1225
+ ctx->params.mb_rc_enable)) {
1226
+ ctx->params.bitrate_changed = false;
1227
+ ctx->params.h264_intra_qp_changed = false;
1228
+
10541229 /* Rate control enabled */
10551230 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK)
10561231 << CODA_RATECONTROL_BITRATE_OFFSET;
....@@ -1108,7 +1283,11 @@
11081283 }
11091284 coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION);
11101285
1111
- coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE);
1286
+ if (ctx->params.frame_rc_enable && !ctx->params.mb_rc_enable)
1287
+ value = 1;
1288
+ else
1289
+ value = 0;
1290
+ coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE);
11121291
11131292 coda_setup_iram(ctx);
11141293
....@@ -1187,9 +1366,9 @@
11871366 coda9_set_frame_cache(ctx, q_data_src->fourcc);
11881367
11891368 /* FIXME */
1190
- coda_write(dev, ctx->internal_frames[2].paddr,
1369
+ coda_write(dev, ctx->internal_frames[2].buf.paddr,
11911370 CODA9_CMD_SET_FRAME_SUBSAMP_A);
1192
- coda_write(dev, ctx->internal_frames[3].paddr,
1371
+ coda_write(dev, ctx->internal_frames[3].buf.paddr,
11931372 CODA9_CMD_SET_FRAME_SUBSAMP_B);
11941373 }
11951374 }
....@@ -1199,6 +1378,12 @@
11991378 v4l2_err(v4l2_dev, "CODA_COMMAND_SET_FRAME_BUF timeout\n");
12001379 goto out;
12011380 }
1381
+
1382
+ coda_dbg(1, ctx, "start encoding %dx%d %4.4s->%4.4s @ %d/%d Hz\n",
1383
+ q_data_src->rect.width, q_data_src->rect.height,
1384
+ (char *)&ctx->codec->src_fourcc, (char *)&dst_fourcc,
1385
+ ctx->params.framerate & 0xffff,
1386
+ (ctx->params.framerate >> 16) + 1);
12021387
12031388 /* Save stream headers */
12041389 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
....@@ -1299,6 +1484,13 @@
12991484 u32 rot_mode = 0;
13001485 u32 dst_fourcc;
13011486 u32 reg;
1487
+ int ret;
1488
+
1489
+ ret = coda_enc_param_change(ctx);
1490
+ if (ret < 0) {
1491
+ v4l2_warn(&ctx->dev->v4l2_dev, "parameter change failed: %d\n",
1492
+ ret);
1493
+ }
13021494
13031495 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
13041496 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
....@@ -1435,12 +1627,28 @@
14351627 return 0;
14361628 }
14371629
1630
+static char coda_frame_type_char(u32 flags)
1631
+{
1632
+ return (flags & V4L2_BUF_FLAG_KEYFRAME) ? 'I' :
1633
+ (flags & V4L2_BUF_FLAG_PFRAME) ? 'P' :
1634
+ (flags & V4L2_BUF_FLAG_BFRAME) ? 'B' : '?';
1635
+}
1636
+
14381637 static void coda_finish_encode(struct coda_ctx *ctx)
14391638 {
14401639 struct vb2_v4l2_buffer *src_buf, *dst_buf;
14411640 struct coda_dev *dev = ctx->dev;
14421641 u32 wr_ptr, start_ptr;
14431642
1643
+ if (ctx->aborting)
1644
+ return;
1645
+
1646
+ /*
1647
+ * Lock to make sure that an encoder stop command running in parallel
1648
+ * will either already have marked src_buf as last, or it will wake up
1649
+ * the capture queue after the buffers are returned.
1650
+ */
1651
+ mutex_lock(&ctx->wakeup_mutex);
14441652 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
14451653 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
14461654
....@@ -1461,41 +1669,35 @@
14611669 vb2_set_plane_payload(&dst_buf->vb2_buf, 0, wr_ptr - start_ptr);
14621670 }
14631671
1464
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "frame size = %u\n",
1465
- wr_ptr - start_ptr);
1672
+ coda_dbg(1, ctx, "frame size = %u\n", wr_ptr - start_ptr);
14661673
14671674 coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM);
14681675 coda_read(dev, CODA_RET_ENC_PIC_FLAG);
14691676
1470
- if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0) {
1677
+ dst_buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
1678
+ V4L2_BUF_FLAG_PFRAME |
1679
+ V4L2_BUF_FLAG_LAST);
1680
+ if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0)
14711681 dst_buf->flags |= V4L2_BUF_FLAG_KEYFRAME;
1472
- dst_buf->flags &= ~V4L2_BUF_FLAG_PFRAME;
1473
- } else {
1682
+ else
14741683 dst_buf->flags |= V4L2_BUF_FLAG_PFRAME;
1475
- dst_buf->flags &= ~V4L2_BUF_FLAG_KEYFRAME;
1476
- }
1684
+ dst_buf->flags |= src_buf->flags & V4L2_BUF_FLAG_LAST;
14771685
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;
1686
+ v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, false);
14841687
14851688 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
14861689
14871690 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
14881691 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE);
1692
+ mutex_unlock(&ctx->wakeup_mutex);
14891693
14901694 ctx->gopcounter--;
14911695 if (ctx->gopcounter < 0)
14921696 ctx->gopcounter = ctx->params.gop_size - 1;
14931697
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");
1698
+ coda_dbg(1, ctx, "job finished: encoded %c frame (%d)%s\n",
1699
+ coda_frame_type_char(dst_buf->flags), dst_buf->sequence,
1700
+ (dst_buf->flags & V4L2_BUF_FLAG_LAST) ? " (last)" : "");
14991701 }
15001702
15011703 static void coda_seq_end_work(struct work_struct *work)
....@@ -1509,9 +1711,7 @@
15091711 if (ctx->initialized == 0)
15101712 goto out;
15111713
1512
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1513
- "%d: %s: sent command 'SEQ_END' to coda\n", ctx->idx,
1514
- __func__);
1714
+ coda_dbg(1, ctx, "%s: sent command 'SEQ_END' to coda\n", __func__);
15151715 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) {
15161716 v4l2_err(&dev->v4l2_dev,
15171717 "CODA_COMMAND_SEQ_END failed\n");
....@@ -1567,8 +1767,7 @@
15671767 return 0;
15681768
15691769 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,
1770
+ ctx->bitstream.vaddr = dma_alloc_wc(ctx->dev->dev, ctx->bitstream.size,
15721771 &ctx->bitstream.paddr, GFP_KERNEL);
15731772 if (!ctx->bitstream.vaddr) {
15741773 v4l2_err(&ctx->dev->v4l2_dev,
....@@ -1586,8 +1785,8 @@
15861785 if (ctx->bitstream.vaddr == NULL)
15871786 return;
15881787
1589
- dma_free_wc(&ctx->dev->plat_dev->dev, ctx->bitstream.size,
1590
- ctx->bitstream.vaddr, ctx->bitstream.paddr);
1788
+ dma_free_wc(ctx->dev->dev, ctx->bitstream.size, ctx->bitstream.vaddr,
1789
+ ctx->bitstream.paddr);
15911790 ctx->bitstream.vaddr = NULL;
15921791 kfifo_init(&ctx->bitstream_fifo, NULL, 0);
15931792 }
....@@ -1644,7 +1843,7 @@
16441843 return profile > V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE;
16451844 }
16461845
1647
-static int __coda_start_decoding(struct coda_ctx *ctx)
1846
+static int __coda_decoder_seq_init(struct coda_ctx *ctx)
16481847 {
16491848 struct coda_q_data *q_data_src, *q_data_dst;
16501849 u32 bitstream_buf, bitstream_size;
....@@ -1654,8 +1853,9 @@
16541853 u32 val;
16551854 int ret;
16561855
1657
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1658
- "Video Data Order Adapter: %s\n",
1856
+ lockdep_assert_held(&dev->coda_mutex);
1857
+
1858
+ coda_dbg(1, ctx, "Video Data Order Adapter: %s\n",
16591859 ctx->use_vdoa ? "Enabled" : "Disabled");
16601860
16611861 /* Start decoding */
....@@ -1665,8 +1865,6 @@
16651865 bitstream_size = ctx->bitstream.size;
16661866 src_fourcc = q_data_src->fourcc;
16671867 dst_fourcc = q_data_dst->fourcc;
1668
-
1669
- coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR);
16701868
16711869 /* Update coda bitstream read and write pointers from kfifo */
16721870 coda_kfifo_sync_to_device_full(ctx);
....@@ -1736,7 +1934,7 @@
17361934
17371935 if (coda_read(dev, CODA_RET_DEC_SEQ_SUCCESS) == 0) {
17381936 v4l2_err(&dev->v4l2_dev,
1739
- "CODA_COMMAND_SEQ_INIT failed, error code = %d\n",
1937
+ "CODA_COMMAND_SEQ_INIT failed, error code = 0x%x\n",
17401938 coda_read(dev, CODA_RET_DEC_SEQ_ERR_REASON));
17411939 return -EAGAIN;
17421940 }
....@@ -1760,8 +1958,7 @@
17601958 width = round_up(width, 16);
17611959 height = round_up(height, 16);
17621960
1763
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "%s instance %d now: %dx%d\n",
1764
- __func__, ctx->idx, width, height);
1961
+ coda_dbg(1, ctx, "start decoding: %dx%d\n", width, height);
17651962
17661963 ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED);
17671964 /*
....@@ -1795,6 +1992,72 @@
17951992 (top_bottom & 0x3ff);
17961993 }
17971994
1995
+ if (dev->devtype->product != CODA_DX6) {
1996
+ u8 profile, level;
1997
+
1998
+ val = coda_read(dev, CODA7_RET_DEC_SEQ_HEADER_REPORT);
1999
+ profile = val & 0xff;
2000
+ level = (val >> 8) & 0x7f;
2001
+
2002
+ if (profile || level)
2003
+ coda_update_profile_level_ctrls(ctx, profile, level);
2004
+ }
2005
+
2006
+ return 0;
2007
+}
2008
+
2009
+static void coda_dec_seq_init_work(struct work_struct *work)
2010
+{
2011
+ struct coda_ctx *ctx = container_of(work,
2012
+ struct coda_ctx, seq_init_work);
2013
+ struct coda_dev *dev = ctx->dev;
2014
+ int ret;
2015
+
2016
+ mutex_lock(&ctx->buffer_mutex);
2017
+ mutex_lock(&dev->coda_mutex);
2018
+
2019
+ if (ctx->initialized == 1)
2020
+ goto out;
2021
+
2022
+ ret = __coda_decoder_seq_init(ctx);
2023
+ if (ret < 0)
2024
+ goto out;
2025
+
2026
+ ctx->initialized = 1;
2027
+
2028
+out:
2029
+ mutex_unlock(&dev->coda_mutex);
2030
+ mutex_unlock(&ctx->buffer_mutex);
2031
+}
2032
+
2033
+static int __coda_start_decoding(struct coda_ctx *ctx)
2034
+{
2035
+ struct coda_q_data *q_data_src, *q_data_dst;
2036
+ struct coda_dev *dev = ctx->dev;
2037
+ u32 src_fourcc, dst_fourcc;
2038
+ int ret;
2039
+
2040
+ q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
2041
+ q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
2042
+ src_fourcc = q_data_src->fourcc;
2043
+ dst_fourcc = q_data_dst->fourcc;
2044
+
2045
+ if (!ctx->initialized) {
2046
+ ret = __coda_decoder_seq_init(ctx);
2047
+ if (ret < 0)
2048
+ return ret;
2049
+ } else {
2050
+ ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) |
2051
+ CODA9_FRAME_TILED2LINEAR);
2052
+ if (dst_fourcc == V4L2_PIX_FMT_NV12 || dst_fourcc == V4L2_PIX_FMT_YUYV)
2053
+ ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE;
2054
+ if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP)
2055
+ ctx->frame_mem_ctrl |= (0x3 << 9) |
2056
+ ((ctx->use_vdoa) ? 0 : CODA9_FRAME_TILED2LINEAR);
2057
+ }
2058
+
2059
+ coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR);
2060
+
17982061 ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc);
17992062 if (ret < 0) {
18002063 v4l2_err(&dev->v4l2_dev, "failed to allocate framebuffers\n");
....@@ -1803,7 +2066,8 @@
18032066
18042067 /* Tell the decoder how many frame buffers we allocated. */
18052068 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM);
1806
- coda_write(dev, width, CODA_CMD_SET_FRAME_BUF_STRIDE);
2069
+ coda_write(dev, round_up(q_data_dst->rect.width, 16),
2070
+ CODA_CMD_SET_FRAME_BUF_STRIDE);
18072071
18082072 if (dev->devtype->product != CODA_DX6) {
18092073 /* Set secondary AXI IRAM */
....@@ -1879,7 +2143,6 @@
18792143 struct coda_dev *dev = ctx->dev;
18802144 struct coda_q_data *q_data_dst;
18812145 struct coda_buffer_meta *meta;
1882
- unsigned long flags;
18832146 u32 rot_mode = 0;
18842147 u32 reg_addr, reg_stride;
18852148
....@@ -1893,8 +2156,7 @@
18932156
18942157 if (coda_get_bitstream_payload(ctx) < 512 &&
18952158 (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) {
1896
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1897
- "bitstream payload: %d, skipping\n",
2159
+ coda_dbg(1, ctx, "bitstream payload: %d, skipping\n",
18982160 coda_get_bitstream_payload(ctx));
18992161 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx);
19002162 return -EAGAIN;
....@@ -1921,20 +2183,25 @@
19212183 ctx->display_idx < ctx->num_internal_frames) {
19222184 vdoa_device_run(ctx->vdoa,
19232185 vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0),
1924
- ctx->internal_frames[ctx->display_idx].paddr);
2186
+ ctx->internal_frames[ctx->display_idx].buf.paddr);
19252187 } else {
19262188 if (dev->devtype->product == CODA_960) {
19272189 /*
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.
2190
+ * It was previously assumed that the CODA960 has an
2191
+ * internal list of 64 buffer entries that contains
2192
+ * both the registered internal frame buffers as well
2193
+ * as the rotator buffer output, and that the ROT_INDEX
2194
+ * register must be set to a value between the last
2195
+ * internal frame buffers' index and 64.
2196
+ * At least on firmware version 3.1.1 it turns out that
2197
+ * setting ROT_INDEX to any value >= 32 causes CODA
2198
+ * hangups that it can not recover from with the SRC VPU
2199
+ * reset.
2200
+ * It does appear to work however, to just set it to a
2201
+ * fixed value in the [ctx->num_internal_frames, 31]
2202
+ * range, for example CODA_MAX_FRAMEBUFFERS.
19352203 */
1936
- coda_write(dev,
1937
- CODA_MAX_FRAMEBUFFERS + dst_buf->vb2_buf.index,
2204
+ coda_write(dev, CODA_MAX_FRAMEBUFFERS,
19382205 CODA9_CMD_DEC_PIC_ROT_INDEX);
19392206
19402207 reg_addr = CODA9_CMD_DEC_PIC_ROT_ADDR_Y;
....@@ -1973,15 +2240,14 @@
19732240 coda_write(dev, ctx->iram_info.axi_sram_use,
19742241 CODA7_REG_BIT_AXI_SRAM_USE);
19752242
1976
- spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
2243
+ spin_lock(&ctx->buffer_meta_lock);
19772244 meta = list_first_entry_or_null(&ctx->buffer_meta_list,
19782245 struct coda_buffer_meta, list);
19792246
19802247 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) {
19812248
19822249 /* 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)) {
2250
+ if (meta->end == ctx->bitstream_fifo.kfifo.in) {
19852251 static unsigned char buf[512];
19862252 unsigned int pad;
19872253
....@@ -1993,7 +2259,7 @@
19932259 kfifo_in(&ctx->bitstream_fifo, buf, pad);
19942260 }
19952261 }
1996
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2262
+ spin_unlock(&ctx->buffer_meta_lock);
19972263
19982264 coda_kfifo_sync_to_device_full(ctx);
19992265
....@@ -2017,16 +2283,18 @@
20172283 struct coda_q_data *q_data_dst;
20182284 struct vb2_v4l2_buffer *dst_buf;
20192285 struct coda_buffer_meta *meta;
2020
- unsigned long payload;
2021
- unsigned long flags;
20222286 int width, height;
20232287 int decoded_idx;
20242288 int display_idx;
2289
+ struct coda_internal_frame *decoded_frame = NULL;
20252290 u32 src_fourcc;
20262291 int success;
20272292 u32 err_mb;
20282293 int err_vdoa = 0;
20292294 u32 val;
2295
+
2296
+ if (ctx->aborting)
2297
+ return;
20302298
20312299 /* Update kfifo out pointer from coda bitstream read pointer */
20322300 coda_kfifo_sync_from_device(ctx);
....@@ -2103,8 +2371,7 @@
21032371 val = coda_read(dev, CODA_RET_DEC_PIC_OPTION);
21042372 if (val == 0) {
21052373 /* not enough bitstream data */
2106
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
2107
- "prescan failed: %d\n", val);
2374
+ coda_dbg(1, ctx, "prescan failed: %d\n", val);
21082375 ctx->hold = true;
21092376 return;
21102377 }
....@@ -2151,17 +2418,19 @@
21512418 v4l2_err(&dev->v4l2_dev,
21522419 "decoded frame index out of range: %d\n", decoded_idx);
21532420 } else {
2421
+ decoded_frame = &ctx->internal_frames[decoded_idx];
2422
+
21542423 val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM);
21552424 if (ctx->sequence_offset == -1)
21562425 ctx->sequence_offset = val;
21572426 val -= ctx->sequence_offset;
2158
- spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
2427
+ spin_lock(&ctx->buffer_meta_lock);
21592428 if (!list_empty(&ctx->buffer_meta_list)) {
21602429 meta = list_first_entry(&ctx->buffer_meta_list,
21612430 struct coda_buffer_meta, list);
21622431 list_del(&meta->list);
21632432 ctx->num_metas--;
2164
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2433
+ spin_unlock(&ctx->buffer_meta_lock);
21652434 /*
21662435 * Clamp counters to 16 bits for comparison, as the HW
21672436 * counter rolls over at this point for h.264. This
....@@ -2175,28 +2444,26 @@
21752444 val, ctx->sequence_offset,
21762445 meta->sequence);
21772446 }
2178
- ctx->frame_metas[decoded_idx] = *meta;
2447
+ decoded_frame->meta = *meta;
21792448 kfree(meta);
21802449 } else {
2181
- spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags);
2450
+ spin_unlock(&ctx->buffer_meta_lock);
21822451 v4l2_err(&dev->v4l2_dev, "empty timestamp list!\n");
2183
- memset(&ctx->frame_metas[decoded_idx], 0,
2452
+ memset(&decoded_frame->meta, 0,
21842453 sizeof(struct coda_buffer_meta));
2185
- ctx->frame_metas[decoded_idx].sequence = val;
2454
+ decoded_frame->meta.sequence = val;
2455
+ decoded_frame->meta.last = false;
21862456 ctx->sequence_offset++;
21872457 }
21882458
2189
- trace_coda_dec_pic_done(ctx, &ctx->frame_metas[decoded_idx]);
2459
+ trace_coda_dec_pic_done(ctx, &decoded_frame->meta);
21902460
21912461 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;
2462
+ decoded_frame->type = (val == 0) ? V4L2_BUF_FLAG_KEYFRAME :
2463
+ (val == 1) ? V4L2_BUF_FLAG_PFRAME :
2464
+ V4L2_BUF_FLAG_BFRAME;
21982465
2199
- ctx->frame_errors[decoded_idx] = err_mb;
2466
+ decoded_frame->error = err_mb;
22002467 }
22012468
22022469 if (display_idx == -1) {
....@@ -2216,6 +2483,10 @@
22162483 /* If a frame was copied out, return it */
22172484 if (ctx->display_idx >= 0 &&
22182485 ctx->display_idx < ctx->num_internal_frames) {
2486
+ struct coda_internal_frame *ready_frame;
2487
+
2488
+ ready_frame = &ctx->internal_frames[ctx->display_idx];
2489
+
22192490 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
22202491 dst_buf->sequence = ctx->osequence++;
22212492
....@@ -2223,46 +2494,81 @@
22232494 dst_buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
22242495 V4L2_BUF_FLAG_PFRAME |
22252496 V4L2_BUF_FLAG_BFRAME);
2226
- dst_buf->flags |= ctx->frame_types[ctx->display_idx];
2227
- meta = &ctx->frame_metas[ctx->display_idx];
2497
+ dst_buf->flags |= ready_frame->type;
2498
+ meta = &ready_frame->meta;
2499
+ if (meta->last && !coda_reorder_enable(ctx)) {
2500
+ /*
2501
+ * If this was the last decoded frame, and reordering
2502
+ * is disabled, this will be the last display frame.
2503
+ */
2504
+ coda_dbg(1, ctx, "last meta, marking as last frame\n");
2505
+ dst_buf->flags |= V4L2_BUF_FLAG_LAST;
2506
+ } else if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG &&
2507
+ display_idx == -1) {
2508
+ /*
2509
+ * If there is no designated presentation frame anymore,
2510
+ * this frame has to be the last one.
2511
+ */
2512
+ coda_dbg(1, ctx,
2513
+ "no more frames to return, marking as last frame\n");
2514
+ dst_buf->flags |= V4L2_BUF_FLAG_LAST;
2515
+ }
22282516 dst_buf->timecode = meta->timecode;
22292517 dst_buf->vb2_buf.timestamp = meta->timestamp;
22302518
22312519 trace_coda_dec_rot_done(ctx, dst_buf, meta);
22322520
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);
2521
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
2522
+ q_data_dst->sizeimage);
22482523
2249
- if (ctx->frame_errors[ctx->display_idx] || err_vdoa)
2524
+ if (ready_frame->error || err_vdoa)
22502525 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_ERROR);
22512526 else
22522527 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE);
22532528
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");
2529
+ if (decoded_frame) {
2530
+ coda_dbg(1, ctx, "job finished: decoded %c frame %u, returned %c frame %u (%u/%u)%s\n",
2531
+ coda_frame_type_char(decoded_frame->type),
2532
+ decoded_frame->meta.sequence,
2533
+ coda_frame_type_char(dst_buf->flags),
2534
+ ready_frame->meta.sequence,
2535
+ dst_buf->sequence, ctx->qsequence,
2536
+ (dst_buf->flags & V4L2_BUF_FLAG_LAST) ?
2537
+ " (last)" : "");
2538
+ } else {
2539
+ coda_dbg(1, ctx, "job finished: no frame decoded (%d), returned %c frame %u (%u/%u)%s\n",
2540
+ decoded_idx,
2541
+ coda_frame_type_char(dst_buf->flags),
2542
+ ready_frame->meta.sequence,
2543
+ dst_buf->sequence, ctx->qsequence,
2544
+ (dst_buf->flags & V4L2_BUF_FLAG_LAST) ?
2545
+ " (last)" : "");
2546
+ }
22592547 } else {
2260
- v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
2261
- "job finished: no frame decoded\n");
2548
+ if (decoded_frame) {
2549
+ coda_dbg(1, ctx, "job finished: decoded %c frame %u, no frame returned (%d)\n",
2550
+ coda_frame_type_char(decoded_frame->type),
2551
+ decoded_frame->meta.sequence,
2552
+ ctx->display_idx);
2553
+ } else {
2554
+ coda_dbg(1, ctx, "job finished: no frame decoded (%d) or returned (%d)\n",
2555
+ decoded_idx, ctx->display_idx);
2556
+ }
22622557 }
22632558
22642559 /* The rotator will copy the current display frame next time */
22652560 ctx->display_idx = display_idx;
2561
+
2562
+ /*
2563
+ * The current decode run might have brought the bitstream fill level
2564
+ * below the size where we can start the next decode run. As userspace
2565
+ * might have filled the output queue completely and might thus be
2566
+ * blocked, we can't rely on the next qbuf to trigger the bitstream
2567
+ * refill. Check if we have data to refill the bitstream now.
2568
+ */
2569
+ mutex_lock(&ctx->bitstream_mutex);
2570
+ coda_fill_bitstream(ctx, NULL);
2571
+ mutex_unlock(&ctx->bitstream_mutex);
22662572 }
22672573
22682574 static void coda_decode_timeout(struct coda_ctx *ctx)
....@@ -2291,6 +2597,7 @@
22912597 .prepare_run = coda_prepare_decode,
22922598 .finish_run = coda_finish_decode,
22932599 .run_timeout = coda_decode_timeout,
2600
+ .seq_init_work = coda_dec_seq_init_work,
22942601 .seq_end_work = coda_seq_end_work,
22952602 .release = coda_bit_release,
22962603 };
....@@ -2302,6 +2609,7 @@
23022609
23032610 /* read status register to attend the IRQ */
23042611 coda_read(dev, CODA_REG_BIT_INT_STATUS);
2612
+ coda_write(dev, 0, CODA_REG_BIT_INT_REASON);
23052613 coda_write(dev, CODA_REG_BIT_INT_CLEAR_SET,
23062614 CODA_REG_BIT_INT_CLEAR);
23072615
....@@ -2315,13 +2623,11 @@
23152623 trace_coda_bit_done(ctx);
23162624
23172625 if (ctx->aborting) {
2318
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
2319
- "task has been aborted\n");
2626
+ coda_dbg(1, ctx, "task has been aborted\n");
23202627 }
23212628
23222629 if (coda_isbusy(ctx->dev)) {
2323
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
2324
- "coda is still busy!!!!\n");
2630
+ coda_dbg(1, ctx, "coda is still busy!!!!\n");
23252631 return IRQ_NONE;
23262632 }
23272633