• Home
  • Raw
  • Download

Lines Matching refs:ctx

40 static void coda_free_bitstream_buffer(struct coda_ctx *ctx);
63 static void coda_command_async(struct coda_ctx *ctx, int cmd) in coda_command_async() argument
65 struct coda_dev *dev = ctx->dev; in coda_command_async()
71 coda_write(dev, ctx->bit_stream_param, in coda_command_async()
73 coda_write(dev, ctx->frm_dis_flg, in coda_command_async()
74 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_command_async()
75 coda_write(dev, ctx->frame_mem_ctrl, in coda_command_async()
77 coda_write(dev, ctx->workbuf.paddr, CODA_REG_BIT_WORK_BUF_ADDR); in coda_command_async()
87 coda_write(dev, ctx->idx, CODA_REG_BIT_RUN_INDEX); in coda_command_async()
88 coda_write(dev, ctx->params.codec_mode, CODA_REG_BIT_RUN_COD_STD); in coda_command_async()
89 coda_write(dev, ctx->params.codec_mode_aux, CODA7_REG_BIT_RUN_AUX_STD); in coda_command_async()
91 trace_coda_bit_run(ctx, cmd); in coda_command_async()
96 static int coda_command_sync(struct coda_ctx *ctx, int cmd) in coda_command_sync() argument
98 struct coda_dev *dev = ctx->dev; in coda_command_sync()
103 coda_command_async(ctx, cmd); in coda_command_sync()
105 trace_coda_bit_done(ctx); in coda_command_sync()
110 int coda_hw_reset(struct coda_ctx *ctx) in coda_hw_reset() argument
112 struct coda_dev *dev = ctx->dev; in coda_hw_reset()
148 static void coda_kfifo_sync_from_device(struct coda_ctx *ctx) in coda_kfifo_sync_from_device() argument
150 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_from_device()
151 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_from_device()
154 rd_ptr = coda_read(dev, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_kfifo_sync_from_device()
156 (rd_ptr - ctx->bitstream.paddr); in coda_kfifo_sync_from_device()
161 static void coda_kfifo_sync_to_device_full(struct coda_ctx *ctx) in coda_kfifo_sync_to_device_full() argument
163 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_to_device_full()
164 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_to_device_full()
167 rd_ptr = ctx->bitstream.paddr + (kfifo->out & kfifo->mask); in coda_kfifo_sync_to_device_full()
168 coda_write(dev, rd_ptr, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_full()
169 wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); in coda_kfifo_sync_to_device_full()
170 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_full()
173 static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx) in coda_kfifo_sync_to_device_write() argument
175 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_to_device_write()
176 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_to_device_write()
179 wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); in coda_kfifo_sync_to_device_write()
180 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_write()
183 static int coda_h264_bitstream_pad(struct coda_ctx *ctx, u32 size) in coda_h264_bitstream_pad() argument
196 n = kfifo_in(&ctx->bitstream_fifo, buf, size); in coda_h264_bitstream_pad()
202 int coda_bitstream_flush(struct coda_ctx *ctx) in coda_bitstream_flush() argument
206 if (ctx->inst_type != CODA_INST_DECODER || !ctx->use_bit) in coda_bitstream_flush()
209 ret = coda_command_sync(ctx, CODA_COMMAND_DEC_BUF_FLUSH); in coda_bitstream_flush()
211 v4l2_err(&ctx->dev->v4l2_dev, "failed to flush bitstream\n"); in coda_bitstream_flush()
215 kfifo_init(&ctx->bitstream_fifo, ctx->bitstream.vaddr, in coda_bitstream_flush()
216 ctx->bitstream.size); in coda_bitstream_flush()
217 coda_kfifo_sync_to_device_full(ctx); in coda_bitstream_flush()
222 static int coda_bitstream_queue(struct coda_ctx *ctx, const u8 *buf, u32 size) in coda_bitstream_queue() argument
224 u32 n = kfifo_in(&ctx->bitstream_fifo, buf, size); in coda_bitstream_queue()
229 static u32 coda_buffer_parse_headers(struct coda_ctx *ctx, in coda_buffer_parse_headers() argument
236 switch (ctx->codec->src_fourcc) { in coda_buffer_parse_headers()
238 size = coda_mpeg2_parse_headers(ctx, vaddr, payload); in coda_buffer_parse_headers()
241 size = coda_mpeg4_parse_headers(ctx, vaddr, payload); in coda_buffer_parse_headers()
250 static bool coda_bitstream_try_queue(struct coda_ctx *ctx, in coda_bitstream_try_queue() argument
258 if (coda_get_bitstream_payload(ctx) + payload + 512 >= in coda_bitstream_try_queue()
259 ctx->bitstream.size) in coda_bitstream_try_queue()
263 v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n"); in coda_bitstream_try_queue()
267 if (ctx->qsequence == 0 && payload < 512) { in coda_bitstream_try_queue()
275 u32 header_size = coda_buffer_parse_headers(ctx, src_buf, in coda_bitstream_try_queue()
279 coda_dbg(1, ctx, "pad with %u-byte header\n", in coda_bitstream_try_queue()
282 ret = coda_bitstream_queue(ctx, vaddr, in coda_bitstream_try_queue()
285 v4l2_err(&ctx->dev->v4l2_dev, in coda_bitstream_try_queue()
289 if (ctx->dev->devtype->product == CODA_960) in coda_bitstream_try_queue()
293 coda_dbg(1, ctx, in coda_bitstream_try_queue()
299 if (ctx->qsequence == 0 && payload < 512 && in coda_bitstream_try_queue()
300 ctx->codec->src_fourcc == V4L2_PIX_FMT_H264) in coda_bitstream_try_queue()
301 coda_h264_bitstream_pad(ctx, 512 - payload); in coda_bitstream_try_queue()
303 ret = coda_bitstream_queue(ctx, vaddr, payload); in coda_bitstream_try_queue()
305 v4l2_err(&ctx->dev->v4l2_dev, "bitstream buffer overflow\n"); in coda_bitstream_try_queue()
309 src_buf->sequence = ctx->qsequence++; in coda_bitstream_try_queue()
312 if (ctx == v4l2_m2m_get_curr_priv(ctx->dev->m2m_dev)) in coda_bitstream_try_queue()
313 coda_kfifo_sync_to_device_write(ctx); in coda_bitstream_try_queue()
317 coda_bit_stream_end_flag(ctx); in coda_bitstream_try_queue()
318 ctx->hold = false; in coda_bitstream_try_queue()
323 void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list) in coda_fill_bitstream() argument
329 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) in coda_fill_bitstream()
332 while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) { in coda_fill_bitstream()
338 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
339 ctx->num_metas > 1) in coda_fill_bitstream()
342 if (ctx->num_internal_frames && in coda_fill_bitstream()
343 ctx->num_metas >= ctx->num_internal_frames) { in coda_fill_bitstream()
344 meta = list_first_entry(&ctx->buffer_meta_list, in coda_fill_bitstream()
355 if (coda_bitstream_can_fetch_past(ctx, meta->end)) in coda_fill_bitstream()
359 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_fill_bitstream()
362 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
363 !coda_jpeg_check_buffer(ctx, &src_buf->vb2_buf)) { in coda_fill_bitstream()
364 v4l2_err(&ctx->dev->v4l2_dev, in coda_fill_bitstream()
366 ctx->qsequence); in coda_fill_bitstream()
367 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
383 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
389 start = ctx->bitstream_fifo.kfifo.in; in coda_fill_bitstream()
391 if (coda_bitstream_try_queue(ctx, src_buf)) { in coda_fill_bitstream()
396 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
404 meta->end = ctx->bitstream_fifo.kfifo.in; in coda_fill_bitstream()
407 coda_dbg(1, ctx, "marking last meta"); in coda_fill_bitstream()
408 spin_lock(&ctx->buffer_meta_lock); in coda_fill_bitstream()
410 &ctx->buffer_meta_list); in coda_fill_bitstream()
411 ctx->num_metas++; in coda_fill_bitstream()
412 spin_unlock(&ctx->buffer_meta_lock); in coda_fill_bitstream()
414 trace_coda_bit_queue(ctx, src_buf, meta); in coda_fill_bitstream()
433 void coda_bit_stream_end_flag(struct coda_ctx *ctx) in coda_bit_stream_end_flag() argument
435 struct coda_dev *dev = ctx->dev; in coda_bit_stream_end_flag()
437 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_bit_stream_end_flag()
442 (ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX))) { in coda_bit_stream_end_flag()
443 coda_write(dev, ctx->bit_stream_param, in coda_bit_stream_end_flag()
448 static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value) in coda_parabuf_write() argument
450 struct coda_dev *dev = ctx->dev; in coda_parabuf_write()
451 u32 *p = ctx->parabuf.vaddr; in coda_parabuf_write()
459 static inline int coda_alloc_context_buf(struct coda_ctx *ctx, in coda_alloc_context_buf() argument
463 return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry); in coda_alloc_context_buf()
467 static void coda_free_framebuffers(struct coda_ctx *ctx) in coda_free_framebuffers() argument
472 coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i].buf); in coda_free_framebuffers()
475 static int coda_alloc_framebuffers(struct coda_ctx *ctx, in coda_alloc_framebuffers() argument
478 struct coda_dev *dev = ctx->dev; in coda_alloc_framebuffers()
483 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
484 ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
485 ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4 || in coda_alloc_framebuffers()
486 ctx->codec->dst_fourcc == V4L2_PIX_FMT_MPEG4) in coda_alloc_framebuffers()
492 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda_alloc_framebuffers()
498 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
504 (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
505 (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4 && i == 0))) in coda_alloc_framebuffers()
509 coda_free_framebuffers(ctx); in coda_alloc_framebuffers()
512 ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i].buf, in coda_alloc_framebuffers()
516 coda_free_framebuffers(ctx); in coda_alloc_framebuffers()
522 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
526 y = ctx->internal_frames[i].buf.paddr; in coda_alloc_framebuffers()
530 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) { in coda_alloc_framebuffers()
539 coda_parabuf_write(ctx, i * 3 + 0, y); in coda_alloc_framebuffers()
540 coda_parabuf_write(ctx, i * 3 + 1, cb); in coda_alloc_framebuffers()
541 coda_parabuf_write(ctx, i * 3 + 2, cr); in coda_alloc_framebuffers()
547 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264) in coda_alloc_framebuffers()
548 coda_parabuf_write(ctx, 96 + i, mvcol); in coda_alloc_framebuffers()
549 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4 && i == 0) in coda_alloc_framebuffers()
550 coda_parabuf_write(ctx, 97, mvcol); in coda_alloc_framebuffers()
556 static void coda_free_context_buffers(struct coda_ctx *ctx) in coda_free_context_buffers() argument
558 struct coda_dev *dev = ctx->dev; in coda_free_context_buffers()
560 coda_free_aux_buf(dev, &ctx->slicebuf); in coda_free_context_buffers()
561 coda_free_aux_buf(dev, &ctx->psbuf); in coda_free_context_buffers()
563 coda_free_aux_buf(dev, &ctx->workbuf); in coda_free_context_buffers()
564 coda_free_aux_buf(dev, &ctx->parabuf); in coda_free_context_buffers()
567 static int coda_alloc_context_buffers(struct coda_ctx *ctx, in coda_alloc_context_buffers() argument
570 struct coda_dev *dev = ctx->dev; in coda_alloc_context_buffers()
574 if (!ctx->parabuf.vaddr) { in coda_alloc_context_buffers()
575 ret = coda_alloc_context_buf(ctx, &ctx->parabuf, in coda_alloc_context_buffers()
584 if (!ctx->slicebuf.vaddr && q_data->fourcc == V4L2_PIX_FMT_H264) { in coda_alloc_context_buffers()
588 ret = coda_alloc_context_buf(ctx, &ctx->slicebuf, size, in coda_alloc_context_buffers()
594 if (!ctx->psbuf.vaddr && (dev->devtype->product == CODA_HX4 || in coda_alloc_context_buffers()
596 ret = coda_alloc_context_buf(ctx, &ctx->psbuf, in coda_alloc_context_buffers()
602 if (!ctx->workbuf.vaddr) { in coda_alloc_context_buffers()
607 ret = coda_alloc_context_buf(ctx, &ctx->workbuf, size, in coda_alloc_context_buffers()
616 coda_free_context_buffers(ctx); in coda_alloc_context_buffers()
620 static int coda_encode_header(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf, in coda_encode_header() argument
624 struct coda_dev *dev = ctx->dev; in coda_encode_header()
641 ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264 && in coda_encode_header()
643 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_encode_header()
658 ret = coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER); in coda_encode_header()
670 *size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)) - in coda_encode_header()
678 static u32 coda_slice_mode(struct coda_ctx *ctx) in coda_slice_mode() argument
682 switch (ctx->params.slice_mode) { in coda_slice_mode()
687 size = ctx->params.slice_max_mb; in coda_slice_mode()
691 size = ctx->params.slice_max_bits; in coda_slice_mode()
701 static int coda_enc_param_change(struct coda_ctx *ctx) in coda_enc_param_change() argument
703 struct coda_dev *dev = ctx->dev; in coda_enc_param_change()
708 if (ctx->params.gop_size_changed) { in coda_enc_param_change()
710 coda_write(dev, ctx->params.gop_size, in coda_enc_param_change()
712 ctx->gopcounter = ctx->params.gop_size - 1; in coda_enc_param_change()
713 ctx->params.gop_size_changed = false; in coda_enc_param_change()
715 if (ctx->params.h264_intra_qp_changed) { in coda_enc_param_change()
716 coda_dbg(1, ctx, "parameter change: intra Qp %u\n", in coda_enc_param_change()
717 ctx->params.h264_intra_qp); in coda_enc_param_change()
719 if (ctx->params.bitrate) { in coda_enc_param_change()
721 coda_write(dev, ctx->params.h264_intra_qp, in coda_enc_param_change()
724 ctx->params.h264_intra_qp_changed = false; in coda_enc_param_change()
726 if (ctx->params.bitrate_changed) { in coda_enc_param_change()
727 coda_dbg(1, ctx, "parameter change: bitrate %u kbit/s\n", in coda_enc_param_change()
728 ctx->params.bitrate); in coda_enc_param_change()
730 coda_write(dev, ctx->params.bitrate, in coda_enc_param_change()
732 ctx->params.bitrate_changed = false; in coda_enc_param_change()
734 if (ctx->params.framerate_changed) { in coda_enc_param_change()
735 coda_dbg(1, ctx, "parameter change: frame rate %u/%u Hz\n", in coda_enc_param_change()
736 ctx->params.framerate & 0xffff, in coda_enc_param_change()
737 (ctx->params.framerate >> 16) + 1); in coda_enc_param_change()
739 coda_write(dev, ctx->params.framerate, in coda_enc_param_change()
741 ctx->params.framerate_changed = false; in coda_enc_param_change()
743 if (ctx->params.intra_refresh_changed) { in coda_enc_param_change()
744 coda_dbg(1, ctx, "parameter change: intra refresh MBs %u\n", in coda_enc_param_change()
745 ctx->params.intra_refresh); in coda_enc_param_change()
747 coda_write(dev, ctx->params.intra_refresh, in coda_enc_param_change()
749 ctx->params.intra_refresh_changed = false; in coda_enc_param_change()
751 if (ctx->params.slice_mode_changed) { in coda_enc_param_change()
753 coda_write(dev, coda_slice_mode(ctx), in coda_enc_param_change()
755 ctx->params.slice_mode_changed = false; in coda_enc_param_change()
763 ret = coda_command_sync(ctx, CODA_COMMAND_RC_CHANGE_PARAMETER); in coda_enc_param_change()
769 coda_dbg(1, ctx, "parameter change failed: %u\n", success); in coda_enc_param_change()
789 static void coda_setup_iram(struct coda_ctx *ctx) in coda_setup_iram() argument
791 struct coda_iram_info *iram_info = &ctx->iram_info; in coda_setup_iram()
792 struct coda_dev *dev = ctx->dev; in coda_setup_iram()
830 if (ctx->inst_type == CODA_INST_ENCODER) { in coda_setup_iram()
833 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_setup_iram()
870 } else if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
873 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_setup_iram()
898 coda_dbg(1, ctx, "IRAM smaller than needed\n"); in coda_setup_iram()
903 if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
1008 static void coda9_set_frame_cache(struct coda_ctx *ctx, u32 fourcc) in coda9_set_frame_cache() argument
1012 if (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) { in coda9_set_frame_cache()
1021 coda_write(ctx->dev, cache_size, CODA9_CMD_SET_FRAME_CACHE_SIZE); in coda9_set_frame_cache()
1031 coda_write(ctx->dev, cache_config, CODA9_CMD_SET_FRAME_CACHE_CONFIG); in coda9_set_frame_cache()
1038 static int coda_encoder_reqbufs(struct coda_ctx *ctx, in coda_encoder_reqbufs() argument
1048 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_encoder_reqbufs()
1049 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_encoder_reqbufs()
1053 coda_free_context_buffers(ctx); in coda_encoder_reqbufs()
1059 static int coda_start_encoding(struct coda_ctx *ctx) in coda_start_encoding() argument
1061 struct coda_dev *dev = ctx->dev; in coda_start_encoding()
1071 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_start_encoding()
1072 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_start_encoding()
1075 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
1085 if (!ctx->params.jpeg_qmat_tab[0]) in coda_start_encoding()
1086 ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
1087 if (!ctx->params.jpeg_qmat_tab[1]) in coda_start_encoding()
1088 ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
1089 coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality); in coda_start_encoding()
1094 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in coda_start_encoding()
1095 coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_start_encoding()
1096 coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_start_encoding()
1112 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in coda_start_encoding()
1115 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in coda_start_encoding()
1116 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda_start_encoding()
1117 ctx->frame_mem_ctrl |= (0x3 << 9) | CODA9_FRAME_TILED2LINEAR; in coda_start_encoding()
1118 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in coda_start_encoding()
1153 ctx->params.framerate = 0; in coda_start_encoding()
1154 coda_write(dev, ctx->params.framerate, in coda_start_encoding()
1157 ctx->params.codec_mode = ctx->codec->mode; in coda_start_encoding()
1175 value = ((ctx->params.h264_disable_deblocking_filter_idc & in coda_start_encoding()
1178 ((ctx->params.h264_slice_alpha_c0_offset_div2 & in coda_start_encoding()
1181 ((ctx->params.h264_slice_beta_offset_div2 & in coda_start_encoding()
1184 (ctx->params.h264_constrained_intra_pred_flag << in coda_start_encoding()
1186 (ctx->params.h264_chroma_qp_index_offset & in coda_start_encoding()
1192 coda_write(dev, ctx->params.jpeg_restart_interval, in coda_start_encoding()
1198 coda_jpeg_write_tables(ctx); in coda_start_encoding()
1212 value = coda_slice_mode(ctx); in coda_start_encoding()
1214 value = ctx->params.gop_size; in coda_start_encoding()
1218 if (ctx->params.bitrate && (ctx->params.frame_rc_enable || in coda_start_encoding()
1219 ctx->params.mb_rc_enable)) { in coda_start_encoding()
1220 ctx->params.bitrate_changed = false; in coda_start_encoding()
1221 ctx->params.h264_intra_qp_changed = false; in coda_start_encoding()
1224 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK) in coda_start_encoding()
1227 value |= (ctx->params.vbv_delay & in coda_start_encoding()
1237 coda_write(dev, ctx->params.vbv_size, CODA_CMD_ENC_SEQ_RC_BUF_SIZE); in coda_start_encoding()
1238 coda_write(dev, ctx->params.intra_refresh, in coda_start_encoding()
1255 if (ctx->params.h264_min_qp || ctx->params.h264_max_qp) { in coda_start_encoding()
1257 ctx->params.h264_min_qp << CODA_QPMIN_OFFSET | in coda_start_encoding()
1258 ctx->params.h264_max_qp << CODA_QPMAX_OFFSET, in coda_start_encoding()
1262 if (ctx->params.h264_max_qp) in coda_start_encoding()
1273 if (ctx->params.h264_min_qp) in coda_start_encoding()
1275 if (ctx->params.h264_max_qp) in coda_start_encoding()
1280 if (ctx->params.frame_rc_enable && !ctx->params.mb_rc_enable) in coda_start_encoding()
1286 coda_setup_iram(ctx); in coda_start_encoding()
1296 coda_write(dev, ctx->iram_info.search_ram_paddr, in coda_start_encoding()
1298 coda_write(dev, ctx->iram_info.search_ram_size, in coda_start_encoding()
1307 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); in coda_start_encoding()
1318 ctx->initialized = 1; in coda_start_encoding()
1322 ctx->num_internal_frames = 4; in coda_start_encoding()
1324 ctx->num_internal_frames = 2; in coda_start_encoding()
1325 ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc); in coda_start_encoding()
1333 ctx->num_internal_frames = 0; in coda_start_encoding()
1346 coda_write(dev, ctx->iram_info.buf_bit_use, in coda_start_encoding()
1348 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in coda_start_encoding()
1350 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in coda_start_encoding()
1352 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in coda_start_encoding()
1354 coda_write(dev, ctx->iram_info.buf_ovl_use, in coda_start_encoding()
1357 coda_write(dev, ctx->iram_info.buf_btp_use, in coda_start_encoding()
1360 coda9_set_frame_cache(ctx, q_data_src->fourcc); in coda_start_encoding()
1363 coda_write(dev, ctx->internal_frames[2].buf.paddr, in coda_start_encoding()
1365 coda_write(dev, ctx->internal_frames[3].buf.paddr, in coda_start_encoding()
1370 ret = coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF); in coda_start_encoding()
1376 coda_dbg(1, ctx, "start encoding %dx%d %4.4s->%4.4s @ %d/%d Hz\n", in coda_start_encoding()
1378 (char *)&ctx->codec->src_fourcc, (char *)&dst_fourcc, in coda_start_encoding()
1379 ctx->params.framerate & 0xffff, in coda_start_encoding()
1380 (ctx->params.framerate >> 16) + 1); in coda_start_encoding()
1383 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
1390 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_SPS, in coda_start_encoding()
1391 &ctx->vpu_header[0][0], in coda_start_encoding()
1392 &ctx->vpu_header_size[0]); in coda_start_encoding()
1405 if (ctx->dev->devtype->product != CODA_960 && in coda_start_encoding()
1408 ret = coda_h264_sps_fixup(ctx, q_data_src->rect.width, in coda_start_encoding()
1410 &ctx->vpu_header[0][0], in coda_start_encoding()
1411 &ctx->vpu_header_size[0], in coda_start_encoding()
1412 sizeof(ctx->vpu_header[0])); in coda_start_encoding()
1421 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_PPS, in coda_start_encoding()
1422 &ctx->vpu_header[1][0], in coda_start_encoding()
1423 &ctx->vpu_header_size[1]); in coda_start_encoding()
1432 ctx->vpu_header_size[2] = coda_h264_padding( in coda_start_encoding()
1433 (ctx->vpu_header_size[0] + in coda_start_encoding()
1434 ctx->vpu_header_size[1]), in coda_start_encoding()
1435 ctx->vpu_header[2]); in coda_start_encoding()
1442 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOS, in coda_start_encoding()
1443 &ctx->vpu_header[0][0], in coda_start_encoding()
1444 &ctx->vpu_header_size[0]); in coda_start_encoding()
1448 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VIS, in coda_start_encoding()
1449 &ctx->vpu_header[1][0], in coda_start_encoding()
1450 &ctx->vpu_header_size[1]); in coda_start_encoding()
1454 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOL, in coda_start_encoding()
1455 &ctx->vpu_header[2][0], in coda_start_encoding()
1456 &ctx->vpu_header_size[2]); in coda_start_encoding()
1470 static int coda_prepare_encode(struct coda_ctx *ctx) in coda_prepare_encode() argument
1474 struct coda_dev *dev = ctx->dev; in coda_prepare_encode()
1483 ret = coda_enc_param_change(ctx); in coda_prepare_encode()
1485 v4l2_warn(&ctx->dev->v4l2_dev, "parameter change failed: %d\n", in coda_prepare_encode()
1489 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1490 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1491 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_prepare_encode()
1492 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_encode()
1495 src_buf->sequence = ctx->osequence; in coda_prepare_encode()
1496 dst_buf->sequence = ctx->osequence; in coda_prepare_encode()
1497 ctx->osequence++; in coda_prepare_encode()
1499 force_ipicture = ctx->params.force_ipicture; in coda_prepare_encode()
1501 ctx->params.force_ipicture = false; in coda_prepare_encode()
1502 else if (ctx->params.gop_size != 0 && in coda_prepare_encode()
1503 (src_buf->sequence % ctx->params.gop_size) == 0) in coda_prepare_encode()
1520 coda_set_gdi_regs(ctx); in coda_prepare_encode()
1529 ctx->vpu_header_size[0] + in coda_prepare_encode()
1530 ctx->vpu_header_size[1] + in coda_prepare_encode()
1531 ctx->vpu_header_size[2]; in coda_prepare_encode()
1533 ctx->vpu_header_size[0] - in coda_prepare_encode()
1534 ctx->vpu_header_size[1] - in coda_prepare_encode()
1535 ctx->vpu_header_size[2]; in coda_prepare_encode()
1537 &ctx->vpu_header[0][0], ctx->vpu_header_size[0]); in coda_prepare_encode()
1539 + ctx->vpu_header_size[0], &ctx->vpu_header[1][0], in coda_prepare_encode()
1540 ctx->vpu_header_size[1]); in coda_prepare_encode()
1542 + ctx->vpu_header_size[0] + ctx->vpu_header_size[1], in coda_prepare_encode()
1543 &ctx->vpu_header[2][0], ctx->vpu_header_size[2]); in coda_prepare_encode()
1553 quant_param = ctx->params.h264_intra_qp; in coda_prepare_encode()
1556 quant_param = ctx->params.mpeg4_intra_qp; in coda_prepare_encode()
1562 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1569 quant_param = ctx->params.h264_inter_qp; in coda_prepare_encode()
1572 quant_param = ctx->params.mpeg4_inter_qp; in coda_prepare_encode()
1575 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1582 if (ctx->params.rot_mode) in coda_prepare_encode()
1583 rot_mode = CODA_ROT_MIR_ENABLE | ctx->params.rot_mode; in coda_prepare_encode()
1597 coda_write_base(ctx, q_data_src, src_buf, reg); in coda_prepare_encode()
1606 if (!ctx->streamon_out) { in coda_prepare_encode()
1608 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_prepare_encode()
1609 coda_write(dev, ctx->bit_stream_param, in coda_prepare_encode()
1614 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_encode()
1617 trace_coda_enc_pic_run(ctx, src_buf); in coda_prepare_encode()
1619 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_encode()
1631 static void coda_finish_encode(struct coda_ctx *ctx) in coda_finish_encode() argument
1634 struct coda_dev *dev = ctx->dev; in coda_finish_encode()
1637 if (ctx->aborting) in coda_finish_encode()
1645 mutex_lock(&ctx->wakeup_mutex); in coda_finish_encode()
1646 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1647 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_finish_encode()
1649 trace_coda_enc_pic_done(ctx, dst_buf); in coda_finish_encode()
1653 wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_finish_encode()
1659 ctx->vpu_header_size[0] + in coda_finish_encode()
1660 ctx->vpu_header_size[1] + in coda_finish_encode()
1661 ctx->vpu_header_size[2]); in coda_finish_encode()
1666 coda_dbg(1, ctx, "frame size = %u\n", wr_ptr - start_ptr); in coda_finish_encode()
1684 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1685 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE); in coda_finish_encode()
1686 mutex_unlock(&ctx->wakeup_mutex); in coda_finish_encode()
1688 ctx->gopcounter--; in coda_finish_encode()
1689 if (ctx->gopcounter < 0) in coda_finish_encode()
1690 ctx->gopcounter = ctx->params.gop_size - 1; in coda_finish_encode()
1692 coda_dbg(1, ctx, "job finished: encoded %c frame (%d)%s\n", in coda_finish_encode()
1699 struct coda_ctx *ctx = container_of(work, struct coda_ctx, seq_end_work); in coda_seq_end_work() local
1700 struct coda_dev *dev = ctx->dev; in coda_seq_end_work()
1702 mutex_lock(&ctx->buffer_mutex); in coda_seq_end_work()
1705 if (ctx->initialized == 0) in coda_seq_end_work()
1708 coda_dbg(1, ctx, "%s: sent command 'SEQ_END' to coda\n", __func__); in coda_seq_end_work()
1709 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) { in coda_seq_end_work()
1720 coda_hw_reset(ctx); in coda_seq_end_work()
1722 kfifo_init(&ctx->bitstream_fifo, in coda_seq_end_work()
1723 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_seq_end_work()
1725 coda_free_framebuffers(ctx); in coda_seq_end_work()
1727 ctx->initialized = 0; in coda_seq_end_work()
1731 mutex_unlock(&ctx->buffer_mutex); in coda_seq_end_work()
1734 static void coda_bit_release(struct coda_ctx *ctx) in coda_bit_release() argument
1736 mutex_lock(&ctx->buffer_mutex); in coda_bit_release()
1737 coda_free_framebuffers(ctx); in coda_bit_release()
1738 coda_free_context_buffers(ctx); in coda_bit_release()
1739 coda_free_bitstream_buffer(ctx); in coda_bit_release()
1740 mutex_unlock(&ctx->buffer_mutex); in coda_bit_release()
1757 static int coda_alloc_bitstream_buffer(struct coda_ctx *ctx, in coda_alloc_bitstream_buffer() argument
1760 if (ctx->bitstream.vaddr) in coda_alloc_bitstream_buffer()
1763 ctx->bitstream.size = roundup_pow_of_two(q_data->sizeimage * 2); in coda_alloc_bitstream_buffer()
1764 ctx->bitstream.vaddr = dma_alloc_wc(ctx->dev->dev, ctx->bitstream.size, in coda_alloc_bitstream_buffer()
1765 &ctx->bitstream.paddr, GFP_KERNEL); in coda_alloc_bitstream_buffer()
1766 if (!ctx->bitstream.vaddr) { in coda_alloc_bitstream_buffer()
1767 v4l2_err(&ctx->dev->v4l2_dev, in coda_alloc_bitstream_buffer()
1771 kfifo_init(&ctx->bitstream_fifo, in coda_alloc_bitstream_buffer()
1772 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_alloc_bitstream_buffer()
1777 static void coda_free_bitstream_buffer(struct coda_ctx *ctx) in coda_free_bitstream_buffer() argument
1779 if (ctx->bitstream.vaddr == NULL) in coda_free_bitstream_buffer()
1782 dma_free_wc(ctx->dev->dev, ctx->bitstream.size, ctx->bitstream.vaddr, in coda_free_bitstream_buffer()
1783 ctx->bitstream.paddr); in coda_free_bitstream_buffer()
1784 ctx->bitstream.vaddr = NULL; in coda_free_bitstream_buffer()
1785 kfifo_init(&ctx->bitstream_fifo, NULL, 0); in coda_free_bitstream_buffer()
1788 static int coda_decoder_reqbufs(struct coda_ctx *ctx, in coda_decoder_reqbufs() argument
1798 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_decoder_reqbufs()
1799 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_decoder_reqbufs()
1802 ret = coda_alloc_bitstream_buffer(ctx, q_data_src); in coda_decoder_reqbufs()
1804 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1808 coda_free_bitstream_buffer(ctx); in coda_decoder_reqbufs()
1809 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1815 static bool coda_reorder_enable(struct coda_ctx *ctx) in coda_reorder_enable() argument
1817 struct coda_dev *dev = ctx->dev; in coda_reorder_enable()
1825 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) in coda_reorder_enable()
1828 if (ctx->codec->src_fourcc != V4L2_PIX_FMT_H264) in coda_reorder_enable()
1831 profile = coda_h264_profile(ctx->params.h264_profile_idc); in coda_reorder_enable()
1834 ctx->params.h264_profile_idc); in coda_reorder_enable()
1840 static int __coda_decoder_seq_init(struct coda_ctx *ctx) in __coda_decoder_seq_init() argument
1844 struct coda_dev *dev = ctx->dev; in __coda_decoder_seq_init()
1852 coda_dbg(1, ctx, "Video Data Order Adapter: %s\n", in __coda_decoder_seq_init()
1853 ctx->use_vdoa ? "Enabled" : "Disabled"); in __coda_decoder_seq_init()
1856 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in __coda_decoder_seq_init()
1857 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in __coda_decoder_seq_init()
1858 bitstream_buf = ctx->bitstream.paddr; in __coda_decoder_seq_init()
1859 bitstream_size = ctx->bitstream.size; in __coda_decoder_seq_init()
1864 coda_kfifo_sync_to_device_full(ctx); in __coda_decoder_seq_init()
1866 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in __coda_decoder_seq_init()
1869 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in __coda_decoder_seq_init()
1870 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in __coda_decoder_seq_init()
1871 ctx->frame_mem_ctrl |= (0x3 << 9) | in __coda_decoder_seq_init()
1872 ((ctx->use_vdoa) ? 0 : CODA9_FRAME_TILED2LINEAR); in __coda_decoder_seq_init()
1873 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in __coda_decoder_seq_init()
1875 ctx->display_idx = -1; in __coda_decoder_seq_init()
1876 ctx->frm_dis_flg = 0; in __coda_decoder_seq_init()
1877 coda_write(dev, 0, CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in __coda_decoder_seq_init()
1882 if (coda_reorder_enable(ctx)) in __coda_decoder_seq_init()
1884 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) in __coda_decoder_seq_init()
1888 ctx->params.codec_mode = ctx->codec->mode; in __coda_decoder_seq_init()
1891 ctx->params.codec_mode_aux = CODA_MP4_AUX_MPEG4; in __coda_decoder_seq_init()
1893 ctx->params.codec_mode_aux = 0; in __coda_decoder_seq_init()
1901 coda_write(dev, ctx->psbuf.paddr, in __coda_decoder_seq_init()
1916 ctx->bit_stream_param = CODA_BIT_DEC_SEQ_INIT_ESCAPE; in __coda_decoder_seq_init()
1917 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); in __coda_decoder_seq_init()
1918 ctx->bit_stream_param = 0; in __coda_decoder_seq_init()
1923 ctx->sequence_offset = ~0U; in __coda_decoder_seq_init()
1924 ctx->initialized = 1; in __coda_decoder_seq_init()
1927 coda_kfifo_sync_from_device(ctx); in __coda_decoder_seq_init()
1955 coda_dbg(1, ctx, "start decoding: %dx%d\n", width, height); in __coda_decoder_seq_init()
1957 ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED); in __coda_decoder_seq_init()
1965 if (ctx->use_vdoa) in __coda_decoder_seq_init()
1966 ctx->num_internal_frames += 1; in __coda_decoder_seq_init()
1967 if (ctx->num_internal_frames > CODA_MAX_FRAMEBUFFERS) { in __coda_decoder_seq_init()
1970 CODA_MAX_FRAMEBUFFERS, ctx->num_internal_frames); in __coda_decoder_seq_init()
1997 coda_update_profile_level_ctrls(ctx, profile, level); in __coda_decoder_seq_init()
2005 struct coda_ctx *ctx = container_of(work, in coda_dec_seq_init_work() local
2007 struct coda_dev *dev = ctx->dev; in coda_dec_seq_init_work()
2010 mutex_lock(&ctx->buffer_mutex); in coda_dec_seq_init_work()
2013 if (ctx->initialized == 1) in coda_dec_seq_init_work()
2016 ret = __coda_decoder_seq_init(ctx); in coda_dec_seq_init_work()
2020 ctx->initialized = 1; in coda_dec_seq_init_work()
2024 mutex_unlock(&ctx->buffer_mutex); in coda_dec_seq_init_work()
2027 static int __coda_start_decoding(struct coda_ctx *ctx) in __coda_start_decoding() argument
2030 struct coda_dev *dev = ctx->dev; in __coda_start_decoding()
2034 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in __coda_start_decoding()
2035 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in __coda_start_decoding()
2039 if (!ctx->initialized) { in __coda_start_decoding()
2040 ret = __coda_decoder_seq_init(ctx); in __coda_start_decoding()
2044 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in __coda_start_decoding()
2047 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in __coda_start_decoding()
2048 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in __coda_start_decoding()
2049 ctx->frame_mem_ctrl |= (0x3 << 9) | in __coda_start_decoding()
2050 ((ctx->use_vdoa) ? 0 : CODA9_FRAME_TILED2LINEAR); in __coda_start_decoding()
2053 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in __coda_start_decoding()
2055 ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc); in __coda_start_decoding()
2062 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); in __coda_start_decoding()
2068 coda_setup_iram(ctx); in __coda_start_decoding()
2070 coda_write(dev, ctx->iram_info.buf_bit_use, in __coda_start_decoding()
2072 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in __coda_start_decoding()
2074 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in __coda_start_decoding()
2076 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in __coda_start_decoding()
2078 coda_write(dev, ctx->iram_info.buf_ovl_use, in __coda_start_decoding()
2081 coda_write(dev, ctx->iram_info.buf_btp_use, in __coda_start_decoding()
2085 coda9_set_frame_cache(ctx, dst_fourcc); in __coda_start_decoding()
2090 coda_write(dev, ctx->slicebuf.paddr, in __coda_start_decoding()
2092 coda_write(dev, ctx->slicebuf.size / 1024, in __coda_start_decoding()
2113 if (coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF)) { in __coda_start_decoding()
2114 v4l2_err(&ctx->dev->v4l2_dev, in __coda_start_decoding()
2122 static int coda_start_decoding(struct coda_ctx *ctx) in coda_start_decoding() argument
2124 struct coda_dev *dev = ctx->dev; in coda_start_decoding()
2128 ret = __coda_start_decoding(ctx); in coda_start_decoding()
2134 static int coda_prepare_decode(struct coda_ctx *ctx) in coda_prepare_decode() argument
2137 struct coda_dev *dev = ctx->dev; in coda_prepare_decode()
2143 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_decode()
2144 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_decode()
2147 mutex_lock(&ctx->bitstream_mutex); in coda_prepare_decode()
2148 coda_fill_bitstream(ctx, NULL); in coda_prepare_decode()
2149 mutex_unlock(&ctx->bitstream_mutex); in coda_prepare_decode()
2151 if (coda_get_bitstream_payload(ctx) < 512 && in coda_prepare_decode()
2152 (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { in coda_prepare_decode()
2153 coda_dbg(1, ctx, "bitstream payload: %d, skipping\n", in coda_prepare_decode()
2154 coda_get_bitstream_payload(ctx)); in coda_prepare_decode()
2155 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); in coda_prepare_decode()
2160 if (!ctx->initialized) { in coda_prepare_decode()
2161 int ret = __coda_start_decoding(ctx); in coda_prepare_decode()
2165 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); in coda_prepare_decode()
2168 ctx->initialized = 1; in coda_prepare_decode()
2173 coda_set_gdi_regs(ctx); in coda_prepare_decode()
2175 if (ctx->use_vdoa && in coda_prepare_decode()
2176 ctx->display_idx >= 0 && in coda_prepare_decode()
2177 ctx->display_idx < ctx->num_internal_frames) { in coda_prepare_decode()
2178 vdoa_device_run(ctx->vdoa, in coda_prepare_decode()
2180 ctx->internal_frames[ctx->display_idx].buf.paddr); in coda_prepare_decode()
2207 coda_write_base(ctx, q_data_dst, dst_buf, reg_addr); in coda_prepare_decode()
2210 rot_mode = CODA_ROT_MIR_ENABLE | ctx->params.rot_mode; in coda_prepare_decode()
2234 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_decode()
2237 spin_lock(&ctx->buffer_meta_lock); in coda_prepare_decode()
2238 meta = list_first_entry_or_null(&ctx->buffer_meta_list, in coda_prepare_decode()
2241 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) { in coda_prepare_decode()
2244 if (meta->end == ctx->bitstream_fifo.kfifo.in) { in coda_prepare_decode()
2253 kfifo_in(&ctx->bitstream_fifo, buf, pad); in coda_prepare_decode()
2256 spin_unlock(&ctx->buffer_meta_lock); in coda_prepare_decode()
2258 coda_kfifo_sync_to_device_full(ctx); in coda_prepare_decode()
2266 trace_coda_dec_pic_run(ctx, meta); in coda_prepare_decode()
2268 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_decode()
2273 static void coda_finish_decode(struct coda_ctx *ctx) in coda_finish_decode() argument
2275 struct coda_dev *dev = ctx->dev; in coda_finish_decode()
2290 if (ctx->aborting) in coda_finish_decode()
2294 coda_kfifo_sync_from_device(ctx); in coda_finish_decode()
2300 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) { in coda_finish_decode()
2301 if (coda_get_bitstream_payload(ctx) >= ctx->bitstream.size - 512) in coda_finish_decode()
2302 kfifo_init(&ctx->bitstream_fifo, in coda_finish_decode()
2303 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_finish_decode()
2306 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_finish_decode()
2321 ctx->psbuf.size); in coda_finish_decode()
2325 ctx->slicebuf.size); in coda_finish_decode()
2332 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_finish_decode()
2368 coda_dbg(1, ctx, "prescan failed: %d\n", val); in coda_finish_decode()
2369 ctx->hold = true; in coda_finish_decode()
2375 if (ctx->use_vdoa && in coda_finish_decode()
2376 ctx->display_idx >= 0 && in coda_finish_decode()
2377 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2378 err_vdoa = vdoa_wait_for_completion(ctx->vdoa); in coda_finish_decode()
2381 ctx->frm_dis_flg = coda_read(dev, in coda_finish_decode()
2382 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
2385 if (ctx->display_idx >= 0 && in coda_finish_decode()
2386 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2387 ctx->frm_dis_flg &= ~(1 << ctx->display_idx); in coda_finish_decode()
2388 coda_write(dev, ctx->frm_dis_flg, in coda_finish_decode()
2389 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
2402 if (display_idx >= 0 && display_idx < ctx->num_internal_frames) in coda_finish_decode()
2403 ctx->sequence_offset++; in coda_finish_decode()
2404 else if (ctx->display_idx < 0) in coda_finish_decode()
2405 ctx->hold = true; in coda_finish_decode()
2407 if (ctx->display_idx >= 0 && in coda_finish_decode()
2408 ctx->display_idx < ctx->num_internal_frames) in coda_finish_decode()
2409 ctx->sequence_offset++; in coda_finish_decode()
2411 } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) { in coda_finish_decode()
2415 decoded_frame = &ctx->internal_frames[decoded_idx]; in coda_finish_decode()
2418 if (ctx->sequence_offset == -1) in coda_finish_decode()
2419 ctx->sequence_offset = val; in coda_finish_decode()
2420 val -= ctx->sequence_offset; in coda_finish_decode()
2421 spin_lock(&ctx->buffer_meta_lock); in coda_finish_decode()
2422 if (!list_empty(&ctx->buffer_meta_list)) { in coda_finish_decode()
2423 meta = list_first_entry(&ctx->buffer_meta_list, in coda_finish_decode()
2426 ctx->num_metas--; in coda_finish_decode()
2427 spin_unlock(&ctx->buffer_meta_lock); in coda_finish_decode()
2438 val, ctx->sequence_offset, in coda_finish_decode()
2444 spin_unlock(&ctx->buffer_meta_lock); in coda_finish_decode()
2450 ctx->sequence_offset++; in coda_finish_decode()
2453 trace_coda_dec_pic_done(ctx, &decoded_frame->meta); in coda_finish_decode()
2468 ctx->hold = true; in coda_finish_decode()
2471 } else if (display_idx < 0 || display_idx >= ctx->num_internal_frames) { in coda_finish_decode()
2478 if (ctx->display_idx >= 0 && in coda_finish_decode()
2479 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2482 ready_frame = &ctx->internal_frames[ctx->display_idx]; in coda_finish_decode()
2484 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_decode()
2485 dst_buf->sequence = ctx->osequence++; in coda_finish_decode()
2493 if (meta->last && !coda_reorder_enable(ctx)) { in coda_finish_decode()
2498 coda_dbg(1, ctx, "last meta, marking as last frame\n"); in coda_finish_decode()
2500 } else if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG && in coda_finish_decode()
2506 coda_dbg(1, ctx, in coda_finish_decode()
2513 trace_coda_dec_rot_done(ctx, dst_buf, meta); in coda_finish_decode()
2519 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_ERROR); in coda_finish_decode()
2521 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE); in coda_finish_decode()
2524 coda_dbg(1, ctx, "job finished: decoded %c frame %u, returned %c frame %u (%u/%u)%s\n", in coda_finish_decode()
2529 dst_buf->sequence, ctx->qsequence, in coda_finish_decode()
2533 coda_dbg(1, ctx, "job finished: no frame decoded (%d), returned %c frame %u (%u/%u)%s\n", in coda_finish_decode()
2537 dst_buf->sequence, ctx->qsequence, in coda_finish_decode()
2543 coda_dbg(1, ctx, "job finished: decoded %c frame %u, no frame returned (%d)\n", in coda_finish_decode()
2546 ctx->display_idx); in coda_finish_decode()
2548 coda_dbg(1, ctx, "job finished: no frame decoded (%d) or returned (%d)\n", in coda_finish_decode()
2549 decoded_idx, ctx->display_idx); in coda_finish_decode()
2554 ctx->display_idx = display_idx; in coda_finish_decode()
2563 mutex_lock(&ctx->bitstream_mutex); in coda_finish_decode()
2564 coda_fill_bitstream(ctx, NULL); in coda_finish_decode()
2565 mutex_unlock(&ctx->bitstream_mutex); in coda_finish_decode()
2568 static void coda_decode_timeout(struct coda_ctx *ctx) in coda_decode_timeout() argument
2578 if (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG)) in coda_decode_timeout()
2581 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_decode_timeout()
2582 dst_buf->sequence = ctx->qsequence - 1; in coda_decode_timeout()
2584 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_ERROR); in coda_decode_timeout()
2602 struct coda_ctx *ctx; in coda_irq_handler() local
2610 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); in coda_irq_handler()
2611 if (ctx == NULL) { in coda_irq_handler()
2617 trace_coda_bit_done(ctx); in coda_irq_handler()
2619 if (ctx->aborting) { in coda_irq_handler()
2620 coda_dbg(1, ctx, "task has been aborted\n"); in coda_irq_handler()
2623 if (coda_isbusy(ctx->dev)) { in coda_irq_handler()
2624 coda_dbg(1, ctx, "coda is still busy!!!!\n"); in coda_irq_handler()
2628 complete(&ctx->completion); in coda_irq_handler()