Lines Matching refs:ctx
41 static void coda_free_bitstream_buffer(struct coda_ctx *ctx);
64 static void coda_command_async(struct coda_ctx *ctx, int cmd) in coda_command_async() argument
66 struct coda_dev *dev = ctx->dev; in coda_command_async()
72 coda_write(dev, ctx->bit_stream_param, in coda_command_async()
74 coda_write(dev, ctx->frm_dis_flg, in coda_command_async()
75 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_command_async()
76 coda_write(dev, ctx->frame_mem_ctrl, in coda_command_async()
78 coda_write(dev, ctx->workbuf.paddr, CODA_REG_BIT_WORK_BUF_ADDR); in coda_command_async()
88 coda_write(dev, ctx->idx, CODA_REG_BIT_RUN_INDEX); in coda_command_async()
89 coda_write(dev, ctx->params.codec_mode, CODA_REG_BIT_RUN_COD_STD); in coda_command_async()
90 coda_write(dev, ctx->params.codec_mode_aux, CODA7_REG_BIT_RUN_AUX_STD); in coda_command_async()
92 trace_coda_bit_run(ctx, cmd); in coda_command_async()
97 static int coda_command_sync(struct coda_ctx *ctx, int cmd) in coda_command_sync() argument
99 struct coda_dev *dev = ctx->dev; in coda_command_sync()
104 coda_command_async(ctx, cmd); in coda_command_sync()
106 trace_coda_bit_done(ctx); in coda_command_sync()
111 int coda_hw_reset(struct coda_ctx *ctx) in coda_hw_reset() argument
113 struct coda_dev *dev = ctx->dev; in coda_hw_reset()
149 static void coda_kfifo_sync_from_device(struct coda_ctx *ctx) in coda_kfifo_sync_from_device() argument
151 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_from_device()
152 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_from_device()
155 rd_ptr = coda_read(dev, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_kfifo_sync_from_device()
157 (rd_ptr - ctx->bitstream.paddr); in coda_kfifo_sync_from_device()
162 static void coda_kfifo_sync_to_device_full(struct coda_ctx *ctx) in coda_kfifo_sync_to_device_full() argument
164 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_to_device_full()
165 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_to_device_full()
168 rd_ptr = ctx->bitstream.paddr + (kfifo->out & kfifo->mask); in coda_kfifo_sync_to_device_full()
169 coda_write(dev, rd_ptr, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_full()
170 wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); in coda_kfifo_sync_to_device_full()
171 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_full()
174 static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx) in coda_kfifo_sync_to_device_write() argument
176 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_to_device_write()
177 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_to_device_write()
180 wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); in coda_kfifo_sync_to_device_write()
181 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_write()
184 static int coda_h264_bitstream_pad(struct coda_ctx *ctx, u32 size) in coda_h264_bitstream_pad() argument
197 n = kfifo_in(&ctx->bitstream_fifo, buf, size); in coda_h264_bitstream_pad()
203 int coda_bitstream_flush(struct coda_ctx *ctx) in coda_bitstream_flush() argument
207 if (ctx->inst_type != CODA_INST_DECODER || !ctx->use_bit) in coda_bitstream_flush()
210 ret = coda_command_sync(ctx, CODA_COMMAND_DEC_BUF_FLUSH); in coda_bitstream_flush()
212 v4l2_err(&ctx->dev->v4l2_dev, "failed to flush bitstream\n"); in coda_bitstream_flush()
216 kfifo_init(&ctx->bitstream_fifo, ctx->bitstream.vaddr, in coda_bitstream_flush()
217 ctx->bitstream.size); in coda_bitstream_flush()
218 coda_kfifo_sync_to_device_full(ctx); in coda_bitstream_flush()
223 static int coda_bitstream_queue(struct coda_ctx *ctx, const u8 *buf, u32 size) in coda_bitstream_queue() argument
225 u32 n = kfifo_in(&ctx->bitstream_fifo, buf, size); in coda_bitstream_queue()
230 static u32 coda_buffer_parse_headers(struct coda_ctx *ctx, in coda_buffer_parse_headers() argument
237 switch (ctx->codec->src_fourcc) { in coda_buffer_parse_headers()
239 size = coda_mpeg2_parse_headers(ctx, vaddr, payload); in coda_buffer_parse_headers()
242 size = coda_mpeg4_parse_headers(ctx, vaddr, payload); in coda_buffer_parse_headers()
251 static bool coda_bitstream_try_queue(struct coda_ctx *ctx, in coda_bitstream_try_queue() argument
259 if (coda_get_bitstream_payload(ctx) + payload + 512 >= in coda_bitstream_try_queue()
260 ctx->bitstream.size) in coda_bitstream_try_queue()
264 v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n"); in coda_bitstream_try_queue()
268 if (ctx->qsequence == 0 && payload < 512) { in coda_bitstream_try_queue()
276 u32 header_size = coda_buffer_parse_headers(ctx, src_buf, in coda_bitstream_try_queue()
280 coda_dbg(1, ctx, "pad with %u-byte header\n", in coda_bitstream_try_queue()
283 ret = coda_bitstream_queue(ctx, vaddr, in coda_bitstream_try_queue()
286 v4l2_err(&ctx->dev->v4l2_dev, in coda_bitstream_try_queue()
290 if (ctx->dev->devtype->product == CODA_960) in coda_bitstream_try_queue()
294 coda_dbg(1, ctx, in coda_bitstream_try_queue()
299 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264) in coda_bitstream_try_queue()
300 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 lockdep_assert_held(&ctx->bitstream_mutex); in coda_fill_bitstream()
331 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) in coda_fill_bitstream()
334 while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) { in coda_fill_bitstream()
340 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
341 ctx->num_metas > 1) in coda_fill_bitstream()
344 if (ctx->num_internal_frames && in coda_fill_bitstream()
345 ctx->num_metas >= ctx->num_internal_frames) { in coda_fill_bitstream()
346 meta = list_first_entry(&ctx->buffer_meta_list, in coda_fill_bitstream()
357 if (coda_bitstream_can_fetch_past(ctx, meta->end)) in coda_fill_bitstream()
361 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_fill_bitstream()
364 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
365 !coda_jpeg_check_buffer(ctx, &src_buf->vb2_buf)) { in coda_fill_bitstream()
366 v4l2_err(&ctx->dev->v4l2_dev, in coda_fill_bitstream()
368 ctx->qsequence); in coda_fill_bitstream()
369 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
385 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
391 start = ctx->bitstream_fifo.kfifo.in; in coda_fill_bitstream()
393 if (coda_bitstream_try_queue(ctx, src_buf)) { in coda_fill_bitstream()
398 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
406 meta->end = ctx->bitstream_fifo.kfifo.in; in coda_fill_bitstream()
409 coda_dbg(1, ctx, "marking last meta"); in coda_fill_bitstream()
410 spin_lock(&ctx->buffer_meta_lock); in coda_fill_bitstream()
412 &ctx->buffer_meta_list); in coda_fill_bitstream()
413 ctx->num_metas++; in coda_fill_bitstream()
414 spin_unlock(&ctx->buffer_meta_lock); in coda_fill_bitstream()
416 trace_coda_bit_queue(ctx, src_buf, meta); in coda_fill_bitstream()
435 void coda_bit_stream_end_flag(struct coda_ctx *ctx) in coda_bit_stream_end_flag() argument
437 struct coda_dev *dev = ctx->dev; in coda_bit_stream_end_flag()
439 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_bit_stream_end_flag()
444 (ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX))) { in coda_bit_stream_end_flag()
445 coda_write(dev, ctx->bit_stream_param, in coda_bit_stream_end_flag()
450 static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value) in coda_parabuf_write() argument
452 struct coda_dev *dev = ctx->dev; in coda_parabuf_write()
453 u32 *p = ctx->parabuf.vaddr; in coda_parabuf_write()
461 static inline int coda_alloc_context_buf(struct coda_ctx *ctx, in coda_alloc_context_buf() argument
465 return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry); in coda_alloc_context_buf()
469 static void coda_free_framebuffers(struct coda_ctx *ctx) in coda_free_framebuffers() argument
474 coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i].buf); in coda_free_framebuffers()
477 static int coda_alloc_framebuffers(struct coda_ctx *ctx, in coda_alloc_framebuffers() argument
480 struct coda_dev *dev = ctx->dev; in coda_alloc_framebuffers()
485 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
486 ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
487 ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4 || in coda_alloc_framebuffers()
488 ctx->codec->dst_fourcc == V4L2_PIX_FMT_MPEG4) in coda_alloc_framebuffers()
494 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda_alloc_framebuffers()
500 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
506 (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
507 (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4 && i == 0))) in coda_alloc_framebuffers()
511 coda_free_framebuffers(ctx); in coda_alloc_framebuffers()
514 ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i].buf, in coda_alloc_framebuffers()
518 coda_free_framebuffers(ctx); in coda_alloc_framebuffers()
524 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
528 y = ctx->internal_frames[i].buf.paddr; in coda_alloc_framebuffers()
532 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) { in coda_alloc_framebuffers()
541 coda_parabuf_write(ctx, i * 3 + 0, y); in coda_alloc_framebuffers()
542 coda_parabuf_write(ctx, i * 3 + 1, cb); in coda_alloc_framebuffers()
543 coda_parabuf_write(ctx, i * 3 + 2, cr); in coda_alloc_framebuffers()
549 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264) in coda_alloc_framebuffers()
550 coda_parabuf_write(ctx, 96 + i, mvcol); in coda_alloc_framebuffers()
551 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4 && i == 0) in coda_alloc_framebuffers()
552 coda_parabuf_write(ctx, 97, mvcol); in coda_alloc_framebuffers()
558 static void coda_free_context_buffers(struct coda_ctx *ctx) in coda_free_context_buffers() argument
560 struct coda_dev *dev = ctx->dev; in coda_free_context_buffers()
562 coda_free_aux_buf(dev, &ctx->slicebuf); in coda_free_context_buffers()
563 coda_free_aux_buf(dev, &ctx->psbuf); in coda_free_context_buffers()
565 coda_free_aux_buf(dev, &ctx->workbuf); in coda_free_context_buffers()
566 coda_free_aux_buf(dev, &ctx->parabuf); in coda_free_context_buffers()
569 static int coda_alloc_context_buffers(struct coda_ctx *ctx, in coda_alloc_context_buffers() argument
572 struct coda_dev *dev = ctx->dev; in coda_alloc_context_buffers()
576 if (!ctx->parabuf.vaddr) { in coda_alloc_context_buffers()
577 ret = coda_alloc_context_buf(ctx, &ctx->parabuf, in coda_alloc_context_buffers()
586 if (!ctx->slicebuf.vaddr && q_data->fourcc == V4L2_PIX_FMT_H264) { in coda_alloc_context_buffers()
590 ret = coda_alloc_context_buf(ctx, &ctx->slicebuf, size, in coda_alloc_context_buffers()
596 if (!ctx->psbuf.vaddr && (dev->devtype->product == CODA_HX4 || in coda_alloc_context_buffers()
598 ret = coda_alloc_context_buf(ctx, &ctx->psbuf, in coda_alloc_context_buffers()
604 if (!ctx->workbuf.vaddr) { in coda_alloc_context_buffers()
609 ret = coda_alloc_context_buf(ctx, &ctx->workbuf, size, in coda_alloc_context_buffers()
618 coda_free_context_buffers(ctx); in coda_alloc_context_buffers()
622 static int coda_encode_header(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf, in coda_encode_header() argument
626 struct coda_dev *dev = ctx->dev; in coda_encode_header()
643 ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264 && in coda_encode_header()
645 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_encode_header()
660 ret = coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER); in coda_encode_header()
672 *size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)) - in coda_encode_header()
680 static u32 coda_slice_mode(struct coda_ctx *ctx) in coda_slice_mode() argument
684 switch (ctx->params.slice_mode) { in coda_slice_mode()
689 size = ctx->params.slice_max_mb; in coda_slice_mode()
693 size = ctx->params.slice_max_bits; in coda_slice_mode()
703 static int coda_enc_param_change(struct coda_ctx *ctx) in coda_enc_param_change() argument
705 struct coda_dev *dev = ctx->dev; in coda_enc_param_change()
710 if (ctx->params.gop_size_changed) { in coda_enc_param_change()
712 coda_write(dev, ctx->params.gop_size, in coda_enc_param_change()
714 ctx->gopcounter = ctx->params.gop_size - 1; in coda_enc_param_change()
715 ctx->params.gop_size_changed = false; in coda_enc_param_change()
717 if (ctx->params.h264_intra_qp_changed) { in coda_enc_param_change()
718 coda_dbg(1, ctx, "parameter change: intra Qp %u\n", in coda_enc_param_change()
719 ctx->params.h264_intra_qp); in coda_enc_param_change()
721 if (ctx->params.bitrate) { in coda_enc_param_change()
723 coda_write(dev, ctx->params.h264_intra_qp, in coda_enc_param_change()
726 ctx->params.h264_intra_qp_changed = false; in coda_enc_param_change()
728 if (ctx->params.bitrate_changed) { in coda_enc_param_change()
729 coda_dbg(1, ctx, "parameter change: bitrate %u kbit/s\n", in coda_enc_param_change()
730 ctx->params.bitrate); in coda_enc_param_change()
732 coda_write(dev, ctx->params.bitrate, in coda_enc_param_change()
734 ctx->params.bitrate_changed = false; in coda_enc_param_change()
736 if (ctx->params.framerate_changed) { in coda_enc_param_change()
737 coda_dbg(1, ctx, "parameter change: frame rate %u/%u Hz\n", in coda_enc_param_change()
738 ctx->params.framerate & 0xffff, in coda_enc_param_change()
739 (ctx->params.framerate >> 16) + 1); in coda_enc_param_change()
741 coda_write(dev, ctx->params.framerate, in coda_enc_param_change()
743 ctx->params.framerate_changed = false; in coda_enc_param_change()
745 if (ctx->params.intra_refresh_changed) { in coda_enc_param_change()
746 coda_dbg(1, ctx, "parameter change: intra refresh MBs %u\n", in coda_enc_param_change()
747 ctx->params.intra_refresh); in coda_enc_param_change()
749 coda_write(dev, ctx->params.intra_refresh, in coda_enc_param_change()
751 ctx->params.intra_refresh_changed = false; in coda_enc_param_change()
753 if (ctx->params.slice_mode_changed) { in coda_enc_param_change()
755 coda_write(dev, coda_slice_mode(ctx), in coda_enc_param_change()
757 ctx->params.slice_mode_changed = false; in coda_enc_param_change()
765 ret = coda_command_sync(ctx, CODA_COMMAND_RC_CHANGE_PARAMETER); in coda_enc_param_change()
771 coda_dbg(1, ctx, "parameter change failed: %u\n", success); in coda_enc_param_change()
791 static void coda_setup_iram(struct coda_ctx *ctx) in coda_setup_iram() argument
793 struct coda_iram_info *iram_info = &ctx->iram_info; in coda_setup_iram()
794 struct coda_dev *dev = ctx->dev; in coda_setup_iram()
832 if (ctx->inst_type == CODA_INST_ENCODER) { in coda_setup_iram()
835 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_setup_iram()
872 } else if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
875 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_setup_iram()
900 coda_dbg(1, ctx, "IRAM smaller than needed\n"); in coda_setup_iram()
905 if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
1010 static void coda9_set_frame_cache(struct coda_ctx *ctx, u32 fourcc) in coda9_set_frame_cache() argument
1014 if (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) { in coda9_set_frame_cache()
1023 coda_write(ctx->dev, cache_size, CODA9_CMD_SET_FRAME_CACHE_SIZE); in coda9_set_frame_cache()
1033 coda_write(ctx->dev, cache_config, CODA9_CMD_SET_FRAME_CACHE_CONFIG); in coda9_set_frame_cache()
1040 static int coda_encoder_reqbufs(struct coda_ctx *ctx, in coda_encoder_reqbufs() argument
1050 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_encoder_reqbufs()
1051 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_encoder_reqbufs()
1055 coda_free_context_buffers(ctx); in coda_encoder_reqbufs()
1061 static int coda_start_encoding(struct coda_ctx *ctx) in coda_start_encoding() argument
1063 struct coda_dev *dev = ctx->dev; in coda_start_encoding()
1073 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_start_encoding()
1074 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_start_encoding()
1077 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
1087 if (!ctx->params.jpeg_qmat_tab[0]) { in coda_start_encoding()
1088 ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
1089 if (!ctx->params.jpeg_qmat_tab[0]) in coda_start_encoding()
1092 if (!ctx->params.jpeg_qmat_tab[1]) { in coda_start_encoding()
1093 ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
1094 if (!ctx->params.jpeg_qmat_tab[1]) in coda_start_encoding()
1097 coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality); in coda_start_encoding()
1102 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in coda_start_encoding()
1103 coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_start_encoding()
1104 coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_start_encoding()
1120 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in coda_start_encoding()
1123 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in coda_start_encoding()
1124 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda_start_encoding()
1125 ctx->frame_mem_ctrl |= (0x3 << 9) | CODA9_FRAME_TILED2LINEAR; in coda_start_encoding()
1126 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in coda_start_encoding()
1161 ctx->params.framerate = 0; in coda_start_encoding()
1162 coda_write(dev, ctx->params.framerate, in coda_start_encoding()
1165 ctx->params.codec_mode = ctx->codec->mode; in coda_start_encoding()
1183 value = ((ctx->params.h264_disable_deblocking_filter_idc & in coda_start_encoding()
1186 ((ctx->params.h264_slice_alpha_c0_offset_div2 & in coda_start_encoding()
1189 ((ctx->params.h264_slice_beta_offset_div2 & in coda_start_encoding()
1192 (ctx->params.h264_constrained_intra_pred_flag << in coda_start_encoding()
1194 (ctx->params.h264_chroma_qp_index_offset & in coda_start_encoding()
1200 coda_write(dev, ctx->params.jpeg_restart_interval, in coda_start_encoding()
1206 coda_jpeg_write_tables(ctx); in coda_start_encoding()
1220 value = coda_slice_mode(ctx); in coda_start_encoding()
1222 value = ctx->params.gop_size; in coda_start_encoding()
1226 if (ctx->params.bitrate && (ctx->params.frame_rc_enable || in coda_start_encoding()
1227 ctx->params.mb_rc_enable)) { in coda_start_encoding()
1228 ctx->params.bitrate_changed = false; in coda_start_encoding()
1229 ctx->params.h264_intra_qp_changed = false; in coda_start_encoding()
1232 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK) in coda_start_encoding()
1235 value |= (ctx->params.vbv_delay & in coda_start_encoding()
1245 coda_write(dev, ctx->params.vbv_size, CODA_CMD_ENC_SEQ_RC_BUF_SIZE); in coda_start_encoding()
1246 coda_write(dev, ctx->params.intra_refresh, in coda_start_encoding()
1263 if (ctx->params.h264_min_qp || ctx->params.h264_max_qp) { in coda_start_encoding()
1265 ctx->params.h264_min_qp << CODA_QPMIN_OFFSET | in coda_start_encoding()
1266 ctx->params.h264_max_qp << CODA_QPMAX_OFFSET, in coda_start_encoding()
1270 if (ctx->params.h264_max_qp) in coda_start_encoding()
1281 if (ctx->params.h264_min_qp) in coda_start_encoding()
1283 if (ctx->params.h264_max_qp) in coda_start_encoding()
1288 if (ctx->params.frame_rc_enable && !ctx->params.mb_rc_enable) in coda_start_encoding()
1294 coda_setup_iram(ctx); in coda_start_encoding()
1304 coda_write(dev, ctx->iram_info.search_ram_paddr, in coda_start_encoding()
1306 coda_write(dev, ctx->iram_info.search_ram_size, in coda_start_encoding()
1315 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); in coda_start_encoding()
1326 ctx->initialized = 1; in coda_start_encoding()
1330 ctx->num_internal_frames = 4; in coda_start_encoding()
1332 ctx->num_internal_frames = 2; in coda_start_encoding()
1333 ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc); in coda_start_encoding()
1341 ctx->num_internal_frames = 0; in coda_start_encoding()
1354 coda_write(dev, ctx->iram_info.buf_bit_use, in coda_start_encoding()
1356 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in coda_start_encoding()
1358 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in coda_start_encoding()
1360 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in coda_start_encoding()
1362 coda_write(dev, ctx->iram_info.buf_ovl_use, in coda_start_encoding()
1365 coda_write(dev, ctx->iram_info.buf_btp_use, in coda_start_encoding()
1368 coda9_set_frame_cache(ctx, q_data_src->fourcc); in coda_start_encoding()
1371 coda_write(dev, ctx->internal_frames[2].buf.paddr, in coda_start_encoding()
1373 coda_write(dev, ctx->internal_frames[3].buf.paddr, in coda_start_encoding()
1378 ret = coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF); in coda_start_encoding()
1384 coda_dbg(1, ctx, "start encoding %dx%d %4.4s->%4.4s @ %d/%d Hz\n", in coda_start_encoding()
1386 (char *)&ctx->codec->src_fourcc, (char *)&dst_fourcc, in coda_start_encoding()
1387 ctx->params.framerate & 0xffff, in coda_start_encoding()
1388 (ctx->params.framerate >> 16) + 1); in coda_start_encoding()
1391 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
1398 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_SPS, in coda_start_encoding()
1399 &ctx->vpu_header[0][0], in coda_start_encoding()
1400 &ctx->vpu_header_size[0]); in coda_start_encoding()
1413 if (ctx->dev->devtype->product != CODA_960 && in coda_start_encoding()
1416 ret = coda_h264_sps_fixup(ctx, q_data_src->rect.width, in coda_start_encoding()
1418 &ctx->vpu_header[0][0], in coda_start_encoding()
1419 &ctx->vpu_header_size[0], in coda_start_encoding()
1420 sizeof(ctx->vpu_header[0])); in coda_start_encoding()
1429 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_PPS, in coda_start_encoding()
1430 &ctx->vpu_header[1][0], in coda_start_encoding()
1431 &ctx->vpu_header_size[1]); in coda_start_encoding()
1440 ctx->vpu_header_size[2] = coda_h264_padding( in coda_start_encoding()
1441 (ctx->vpu_header_size[0] + in coda_start_encoding()
1442 ctx->vpu_header_size[1]), in coda_start_encoding()
1443 ctx->vpu_header[2]); in coda_start_encoding()
1450 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOS, in coda_start_encoding()
1451 &ctx->vpu_header[0][0], in coda_start_encoding()
1452 &ctx->vpu_header_size[0]); in coda_start_encoding()
1456 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VIS, in coda_start_encoding()
1457 &ctx->vpu_header[1][0], in coda_start_encoding()
1458 &ctx->vpu_header_size[1]); in coda_start_encoding()
1462 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOL, in coda_start_encoding()
1463 &ctx->vpu_header[2][0], in coda_start_encoding()
1464 &ctx->vpu_header_size[2]); in coda_start_encoding()
1478 static int coda_prepare_encode(struct coda_ctx *ctx) in coda_prepare_encode() argument
1482 struct coda_dev *dev = ctx->dev; in coda_prepare_encode()
1491 ret = coda_enc_param_change(ctx); in coda_prepare_encode()
1493 v4l2_warn(&ctx->dev->v4l2_dev, "parameter change failed: %d\n", in coda_prepare_encode()
1497 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1498 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1499 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_prepare_encode()
1500 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_encode()
1503 src_buf->sequence = ctx->osequence; in coda_prepare_encode()
1504 dst_buf->sequence = ctx->osequence; in coda_prepare_encode()
1505 ctx->osequence++; in coda_prepare_encode()
1507 force_ipicture = ctx->params.force_ipicture; in coda_prepare_encode()
1509 ctx->params.force_ipicture = false; in coda_prepare_encode()
1510 else if (ctx->params.gop_size != 0 && in coda_prepare_encode()
1511 (src_buf->sequence % ctx->params.gop_size) == 0) in coda_prepare_encode()
1528 coda_set_gdi_regs(ctx); in coda_prepare_encode()
1537 ctx->vpu_header_size[0] + in coda_prepare_encode()
1538 ctx->vpu_header_size[1] + in coda_prepare_encode()
1539 ctx->vpu_header_size[2]; in coda_prepare_encode()
1541 ctx->vpu_header_size[0] - in coda_prepare_encode()
1542 ctx->vpu_header_size[1] - in coda_prepare_encode()
1543 ctx->vpu_header_size[2]; in coda_prepare_encode()
1545 &ctx->vpu_header[0][0], ctx->vpu_header_size[0]); in coda_prepare_encode()
1547 + ctx->vpu_header_size[0], &ctx->vpu_header[1][0], in coda_prepare_encode()
1548 ctx->vpu_header_size[1]); in coda_prepare_encode()
1550 + ctx->vpu_header_size[0] + ctx->vpu_header_size[1], in coda_prepare_encode()
1551 &ctx->vpu_header[2][0], ctx->vpu_header_size[2]); in coda_prepare_encode()
1561 quant_param = ctx->params.h264_intra_qp; in coda_prepare_encode()
1564 quant_param = ctx->params.mpeg4_intra_qp; in coda_prepare_encode()
1570 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1577 quant_param = ctx->params.h264_inter_qp; in coda_prepare_encode()
1580 quant_param = ctx->params.mpeg4_inter_qp; in coda_prepare_encode()
1583 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1590 if (ctx->params.rot_mode) in coda_prepare_encode()
1591 rot_mode = CODA_ROT_MIR_ENABLE | ctx->params.rot_mode; in coda_prepare_encode()
1605 coda_write_base(ctx, q_data_src, src_buf, reg); in coda_prepare_encode()
1614 if (!ctx->streamon_out) { in coda_prepare_encode()
1616 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_prepare_encode()
1617 coda_write(dev, ctx->bit_stream_param, in coda_prepare_encode()
1622 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_encode()
1625 trace_coda_enc_pic_run(ctx, src_buf); in coda_prepare_encode()
1627 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_encode()
1639 static void coda_finish_encode(struct coda_ctx *ctx) in coda_finish_encode() argument
1642 struct coda_dev *dev = ctx->dev; in coda_finish_encode()
1645 if (ctx->aborting) in coda_finish_encode()
1653 mutex_lock(&ctx->wakeup_mutex); in coda_finish_encode()
1654 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1655 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_finish_encode()
1657 trace_coda_enc_pic_done(ctx, dst_buf); in coda_finish_encode()
1661 wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_finish_encode()
1667 ctx->vpu_header_size[0] + in coda_finish_encode()
1668 ctx->vpu_header_size[1] + in coda_finish_encode()
1669 ctx->vpu_header_size[2]); in coda_finish_encode()
1674 coda_dbg(1, ctx, "frame size = %u\n", wr_ptr - start_ptr); in coda_finish_encode()
1692 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1693 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE); in coda_finish_encode()
1694 mutex_unlock(&ctx->wakeup_mutex); in coda_finish_encode()
1696 ctx->gopcounter--; in coda_finish_encode()
1697 if (ctx->gopcounter < 0) in coda_finish_encode()
1698 ctx->gopcounter = ctx->params.gop_size - 1; in coda_finish_encode()
1700 coda_dbg(1, ctx, "job finished: encoded %c frame (%d)%s\n", in coda_finish_encode()
1707 struct coda_ctx *ctx = container_of(work, struct coda_ctx, seq_end_work); in coda_seq_end_work() local
1708 struct coda_dev *dev = ctx->dev; in coda_seq_end_work()
1710 mutex_lock(&ctx->buffer_mutex); in coda_seq_end_work()
1713 if (ctx->initialized == 0) in coda_seq_end_work()
1716 coda_dbg(1, ctx, "%s: sent command 'SEQ_END' to coda\n", __func__); in coda_seq_end_work()
1717 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) { in coda_seq_end_work()
1728 coda_hw_reset(ctx); in coda_seq_end_work()
1730 kfifo_init(&ctx->bitstream_fifo, in coda_seq_end_work()
1731 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_seq_end_work()
1733 coda_free_framebuffers(ctx); in coda_seq_end_work()
1735 ctx->initialized = 0; in coda_seq_end_work()
1739 mutex_unlock(&ctx->buffer_mutex); in coda_seq_end_work()
1742 static void coda_bit_release(struct coda_ctx *ctx) in coda_bit_release() argument
1744 mutex_lock(&ctx->buffer_mutex); in coda_bit_release()
1745 coda_free_framebuffers(ctx); in coda_bit_release()
1746 coda_free_context_buffers(ctx); in coda_bit_release()
1747 coda_free_bitstream_buffer(ctx); in coda_bit_release()
1748 mutex_unlock(&ctx->buffer_mutex); in coda_bit_release()
1765 static int coda_alloc_bitstream_buffer(struct coda_ctx *ctx, in coda_alloc_bitstream_buffer() argument
1768 if (ctx->bitstream.vaddr) in coda_alloc_bitstream_buffer()
1771 ctx->bitstream.size = roundup_pow_of_two(q_data->sizeimage * 2); in coda_alloc_bitstream_buffer()
1772 ctx->bitstream.vaddr = dma_alloc_wc(ctx->dev->dev, ctx->bitstream.size, in coda_alloc_bitstream_buffer()
1773 &ctx->bitstream.paddr, GFP_KERNEL); in coda_alloc_bitstream_buffer()
1774 if (!ctx->bitstream.vaddr) { in coda_alloc_bitstream_buffer()
1775 v4l2_err(&ctx->dev->v4l2_dev, in coda_alloc_bitstream_buffer()
1779 kfifo_init(&ctx->bitstream_fifo, in coda_alloc_bitstream_buffer()
1780 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_alloc_bitstream_buffer()
1785 static void coda_free_bitstream_buffer(struct coda_ctx *ctx) in coda_free_bitstream_buffer() argument
1787 if (ctx->bitstream.vaddr == NULL) in coda_free_bitstream_buffer()
1790 dma_free_wc(ctx->dev->dev, ctx->bitstream.size, ctx->bitstream.vaddr, in coda_free_bitstream_buffer()
1791 ctx->bitstream.paddr); in coda_free_bitstream_buffer()
1792 ctx->bitstream.vaddr = NULL; in coda_free_bitstream_buffer()
1793 kfifo_init(&ctx->bitstream_fifo, NULL, 0); in coda_free_bitstream_buffer()
1796 static int coda_decoder_reqbufs(struct coda_ctx *ctx, in coda_decoder_reqbufs() argument
1806 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_decoder_reqbufs()
1807 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_decoder_reqbufs()
1810 ret = coda_alloc_bitstream_buffer(ctx, q_data_src); in coda_decoder_reqbufs()
1812 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1816 coda_free_bitstream_buffer(ctx); in coda_decoder_reqbufs()
1817 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1823 static bool coda_reorder_enable(struct coda_ctx *ctx) in coda_reorder_enable() argument
1825 struct coda_dev *dev = ctx->dev; in coda_reorder_enable()
1833 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) in coda_reorder_enable()
1836 if (ctx->codec->src_fourcc != V4L2_PIX_FMT_H264) in coda_reorder_enable()
1839 profile = coda_h264_profile(ctx->params.h264_profile_idc); in coda_reorder_enable()
1842 ctx->params.h264_profile_idc); in coda_reorder_enable()
1848 static void coda_decoder_drop_used_metas(struct coda_ctx *ctx) in coda_decoder_drop_used_metas() argument
1856 spin_lock(&ctx->buffer_meta_lock); in coda_decoder_drop_used_metas()
1857 list_for_each_entry_safe(meta, tmp, &ctx->buffer_meta_list, list) { in coda_decoder_drop_used_metas()
1858 if (ctx->bitstream_fifo.kfifo.out >= meta->end) { in coda_decoder_drop_used_metas()
1859 coda_dbg(2, ctx, "releasing meta: seq=%d start=%d end=%d\n", in coda_decoder_drop_used_metas()
1863 ctx->num_metas--; in coda_decoder_drop_used_metas()
1864 ctx->first_frame_sequence++; in coda_decoder_drop_used_metas()
1868 spin_unlock(&ctx->buffer_meta_lock); in coda_decoder_drop_used_metas()
1871 static int __coda_decoder_seq_init(struct coda_ctx *ctx) in __coda_decoder_seq_init() argument
1875 struct coda_dev *dev = ctx->dev; in __coda_decoder_seq_init()
1883 coda_dbg(1, ctx, "Video Data Order Adapter: %s\n", in __coda_decoder_seq_init()
1884 ctx->use_vdoa ? "Enabled" : "Disabled"); in __coda_decoder_seq_init()
1887 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in __coda_decoder_seq_init()
1888 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in __coda_decoder_seq_init()
1889 bitstream_buf = ctx->bitstream.paddr; in __coda_decoder_seq_init()
1890 bitstream_size = ctx->bitstream.size; in __coda_decoder_seq_init()
1895 coda_kfifo_sync_to_device_full(ctx); in __coda_decoder_seq_init()
1897 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in __coda_decoder_seq_init()
1900 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in __coda_decoder_seq_init()
1901 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in __coda_decoder_seq_init()
1902 ctx->frame_mem_ctrl |= (0x3 << 9) | in __coda_decoder_seq_init()
1903 ((ctx->use_vdoa) ? 0 : CODA9_FRAME_TILED2LINEAR); in __coda_decoder_seq_init()
1904 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in __coda_decoder_seq_init()
1906 ctx->display_idx = -1; in __coda_decoder_seq_init()
1907 ctx->frm_dis_flg = 0; in __coda_decoder_seq_init()
1908 coda_write(dev, 0, CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in __coda_decoder_seq_init()
1913 if (coda_reorder_enable(ctx)) in __coda_decoder_seq_init()
1915 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) in __coda_decoder_seq_init()
1919 ctx->params.codec_mode = ctx->codec->mode; in __coda_decoder_seq_init()
1922 ctx->params.codec_mode_aux = CODA_MP4_AUX_MPEG4; in __coda_decoder_seq_init()
1924 ctx->params.codec_mode_aux = 0; in __coda_decoder_seq_init()
1932 coda_write(dev, ctx->psbuf.paddr, in __coda_decoder_seq_init()
1947 ctx->bit_stream_param = CODA_BIT_DEC_SEQ_INIT_ESCAPE; in __coda_decoder_seq_init()
1948 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); in __coda_decoder_seq_init()
1949 ctx->bit_stream_param = 0; in __coda_decoder_seq_init()
1954 ctx->sequence_offset = ~0U; in __coda_decoder_seq_init()
1955 ctx->initialized = 1; in __coda_decoder_seq_init()
1956 ctx->first_frame_sequence = 0; in __coda_decoder_seq_init()
1959 coda_kfifo_sync_from_device(ctx); in __coda_decoder_seq_init()
1965 coda_decoder_drop_used_metas(ctx); in __coda_decoder_seq_init()
1993 coda_dbg(1, ctx, "start decoding: %dx%d\n", width, height); in __coda_decoder_seq_init()
1995 ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED); in __coda_decoder_seq_init()
2003 if (ctx->use_vdoa) in __coda_decoder_seq_init()
2004 ctx->num_internal_frames += 1; in __coda_decoder_seq_init()
2005 if (ctx->num_internal_frames > CODA_MAX_FRAMEBUFFERS) { in __coda_decoder_seq_init()
2008 CODA_MAX_FRAMEBUFFERS, ctx->num_internal_frames); in __coda_decoder_seq_init()
2035 coda_update_profile_level_ctrls(ctx, profile, level); in __coda_decoder_seq_init()
2043 struct coda_ctx *ctx = container_of(work, in coda_dec_seq_init_work() local
2045 struct coda_dev *dev = ctx->dev; in coda_dec_seq_init_work()
2047 mutex_lock(&ctx->buffer_mutex); in coda_dec_seq_init_work()
2050 if (!ctx->initialized) in coda_dec_seq_init_work()
2051 __coda_decoder_seq_init(ctx); in coda_dec_seq_init_work()
2054 mutex_unlock(&ctx->buffer_mutex); in coda_dec_seq_init_work()
2057 static int __coda_start_decoding(struct coda_ctx *ctx) in __coda_start_decoding() argument
2060 struct coda_dev *dev = ctx->dev; in __coda_start_decoding()
2064 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in __coda_start_decoding()
2065 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in __coda_start_decoding()
2069 if (!ctx->initialized) { in __coda_start_decoding()
2070 ret = __coda_decoder_seq_init(ctx); in __coda_start_decoding()
2074 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in __coda_start_decoding()
2077 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in __coda_start_decoding()
2078 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in __coda_start_decoding()
2079 ctx->frame_mem_ctrl |= (0x3 << 9) | in __coda_start_decoding()
2080 ((ctx->use_vdoa) ? 0 : CODA9_FRAME_TILED2LINEAR); in __coda_start_decoding()
2083 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in __coda_start_decoding()
2085 ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc); in __coda_start_decoding()
2092 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); in __coda_start_decoding()
2098 coda_setup_iram(ctx); in __coda_start_decoding()
2100 coda_write(dev, ctx->iram_info.buf_bit_use, in __coda_start_decoding()
2102 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in __coda_start_decoding()
2104 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in __coda_start_decoding()
2106 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in __coda_start_decoding()
2108 coda_write(dev, ctx->iram_info.buf_ovl_use, in __coda_start_decoding()
2111 coda_write(dev, ctx->iram_info.buf_btp_use, in __coda_start_decoding()
2115 coda9_set_frame_cache(ctx, dst_fourcc); in __coda_start_decoding()
2120 coda_write(dev, ctx->slicebuf.paddr, in __coda_start_decoding()
2122 coda_write(dev, ctx->slicebuf.size / 1024, in __coda_start_decoding()
2143 if (coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF)) { in __coda_start_decoding()
2144 v4l2_err(&ctx->dev->v4l2_dev, in __coda_start_decoding()
2152 static int coda_start_decoding(struct coda_ctx *ctx) in coda_start_decoding() argument
2154 struct coda_dev *dev = ctx->dev; in coda_start_decoding()
2158 ret = __coda_start_decoding(ctx); in coda_start_decoding()
2164 static int coda_prepare_decode(struct coda_ctx *ctx) in coda_prepare_decode() argument
2167 struct coda_dev *dev = ctx->dev; in coda_prepare_decode()
2173 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_decode()
2174 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_decode()
2177 mutex_lock(&ctx->bitstream_mutex); in coda_prepare_decode()
2178 coda_fill_bitstream(ctx, NULL); in coda_prepare_decode()
2179 mutex_unlock(&ctx->bitstream_mutex); in coda_prepare_decode()
2181 if (coda_get_bitstream_payload(ctx) < 512 && in coda_prepare_decode()
2182 (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { in coda_prepare_decode()
2183 coda_dbg(1, ctx, "bitstream payload: %d, skipping\n", in coda_prepare_decode()
2184 coda_get_bitstream_payload(ctx)); in coda_prepare_decode()
2189 if (!ctx->initialized) { in coda_prepare_decode()
2190 int ret = __coda_start_decoding(ctx); in coda_prepare_decode()
2196 ctx->initialized = 1; in coda_prepare_decode()
2201 coda_set_gdi_regs(ctx); in coda_prepare_decode()
2203 if (ctx->use_vdoa && in coda_prepare_decode()
2204 ctx->display_idx >= 0 && in coda_prepare_decode()
2205 ctx->display_idx < ctx->num_internal_frames) { in coda_prepare_decode()
2206 vdoa_device_run(ctx->vdoa, in coda_prepare_decode()
2208 ctx->internal_frames[ctx->display_idx].buf.paddr); in coda_prepare_decode()
2235 coda_write_base(ctx, q_data_dst, dst_buf, reg_addr); in coda_prepare_decode()
2238 rot_mode = CODA_ROT_MIR_ENABLE | ctx->params.rot_mode; in coda_prepare_decode()
2262 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_decode()
2265 spin_lock(&ctx->buffer_meta_lock); in coda_prepare_decode()
2266 meta = list_first_entry_or_null(&ctx->buffer_meta_list, in coda_prepare_decode()
2269 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) { in coda_prepare_decode()
2272 if (meta->end == ctx->bitstream_fifo.kfifo.in) { in coda_prepare_decode()
2281 kfifo_in(&ctx->bitstream_fifo, buf, pad); in coda_prepare_decode()
2284 spin_unlock(&ctx->buffer_meta_lock); in coda_prepare_decode()
2286 coda_kfifo_sync_to_device_full(ctx); in coda_prepare_decode()
2294 trace_coda_dec_pic_run(ctx, meta); in coda_prepare_decode()
2296 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_decode()
2301 static void coda_finish_decode(struct coda_ctx *ctx) in coda_finish_decode() argument
2303 struct coda_dev *dev = ctx->dev; in coda_finish_decode()
2318 if (ctx->aborting) in coda_finish_decode()
2322 coda_kfifo_sync_from_device(ctx); in coda_finish_decode()
2328 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) { in coda_finish_decode()
2329 if (coda_get_bitstream_payload(ctx) >= ctx->bitstream.size - 512) in coda_finish_decode()
2330 kfifo_init(&ctx->bitstream_fifo, in coda_finish_decode()
2331 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_finish_decode()
2334 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_finish_decode()
2349 ctx->psbuf.size); in coda_finish_decode()
2353 ctx->slicebuf.size); in coda_finish_decode()
2360 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_finish_decode()
2389 coda_dbg(1, ctx, "errors in %d macroblocks\n", err_mb); in coda_finish_decode()
2390 v4l2_ctrl_s_ctrl(ctx->mb_err_cnt_ctrl, in coda_finish_decode()
2391 v4l2_ctrl_g_ctrl(ctx->mb_err_cnt_ctrl) + err_mb); in coda_finish_decode()
2399 coda_dbg(1, ctx, "prescan failed: %d\n", val); in coda_finish_decode()
2400 ctx->hold = true; in coda_finish_decode()
2406 if (ctx->use_vdoa && in coda_finish_decode()
2407 ctx->display_idx >= 0 && in coda_finish_decode()
2408 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2409 err_vdoa = vdoa_wait_for_completion(ctx->vdoa); in coda_finish_decode()
2412 ctx->frm_dis_flg = coda_read(dev, in coda_finish_decode()
2413 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
2416 if (ctx->display_idx >= 0 && in coda_finish_decode()
2417 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2418 ctx->frm_dis_flg &= ~(1 << ctx->display_idx); in coda_finish_decode()
2419 coda_write(dev, ctx->frm_dis_flg, in coda_finish_decode()
2420 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
2433 if (display_idx >= 0 && display_idx < ctx->num_internal_frames) in coda_finish_decode()
2434 ctx->sequence_offset++; in coda_finish_decode()
2435 else if (ctx->display_idx < 0) in coda_finish_decode()
2436 ctx->hold = true; in coda_finish_decode()
2438 if (ctx->display_idx >= 0 && in coda_finish_decode()
2439 ctx->display_idx < ctx->num_internal_frames) in coda_finish_decode()
2440 ctx->sequence_offset++; in coda_finish_decode()
2442 } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) { in coda_finish_decode()
2448 decoded_frame = &ctx->internal_frames[decoded_idx]; in coda_finish_decode()
2451 if (ctx->sequence_offset == -1) in coda_finish_decode()
2452 ctx->sequence_offset = val; in coda_finish_decode()
2454 sequence = val + ctx->first_frame_sequence in coda_finish_decode()
2455 - ctx->sequence_offset; in coda_finish_decode()
2456 spin_lock(&ctx->buffer_meta_lock); in coda_finish_decode()
2457 if (!list_empty(&ctx->buffer_meta_list)) { in coda_finish_decode()
2458 meta = list_first_entry(&ctx->buffer_meta_list, in coda_finish_decode()
2461 ctx->num_metas--; in coda_finish_decode()
2462 spin_unlock(&ctx->buffer_meta_lock); in coda_finish_decode()
2473 sequence, ctx->sequence_offset, in coda_finish_decode()
2479 spin_unlock(&ctx->buffer_meta_lock); in coda_finish_decode()
2485 ctx->sequence_offset++; in coda_finish_decode()
2488 trace_coda_dec_pic_done(ctx, &decoded_frame->meta); in coda_finish_decode()
2503 ctx->hold = true; in coda_finish_decode()
2506 } else if (display_idx < 0 || display_idx >= ctx->num_internal_frames) { in coda_finish_decode()
2513 if (ctx->display_idx >= 0 && in coda_finish_decode()
2514 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2517 ready_frame = &ctx->internal_frames[ctx->display_idx]; in coda_finish_decode()
2519 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_decode()
2520 dst_buf->sequence = ctx->osequence++; in coda_finish_decode()
2528 if (meta->last && !coda_reorder_enable(ctx)) { in coda_finish_decode()
2533 coda_dbg(1, ctx, "last meta, marking as last frame\n"); in coda_finish_decode()
2535 } else if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG && in coda_finish_decode()
2541 coda_dbg(1, ctx, in coda_finish_decode()
2548 trace_coda_dec_rot_done(ctx, dst_buf, meta); in coda_finish_decode()
2554 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_ERROR); in coda_finish_decode()
2556 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE); in coda_finish_decode()
2559 coda_dbg(1, ctx, "job finished: decoded %c frame %u, returned %c frame %u (%u/%u)%s\n", in coda_finish_decode()
2564 dst_buf->sequence, ctx->qsequence, in coda_finish_decode()
2568 coda_dbg(1, ctx, "job finished: no frame decoded (%d), returned %c frame %u (%u/%u)%s\n", in coda_finish_decode()
2572 dst_buf->sequence, ctx->qsequence, in coda_finish_decode()
2578 coda_dbg(1, ctx, "job finished: decoded %c frame %u, no frame returned (%d)\n", in coda_finish_decode()
2581 ctx->display_idx); in coda_finish_decode()
2583 coda_dbg(1, ctx, "job finished: no frame decoded (%d) or returned (%d)\n", in coda_finish_decode()
2584 decoded_idx, ctx->display_idx); in coda_finish_decode()
2589 ctx->display_idx = display_idx; in coda_finish_decode()
2598 mutex_lock(&ctx->bitstream_mutex); in coda_finish_decode()
2599 coda_fill_bitstream(ctx, NULL); in coda_finish_decode()
2600 mutex_unlock(&ctx->bitstream_mutex); in coda_finish_decode()
2603 static void coda_decode_timeout(struct coda_ctx *ctx) in coda_decode_timeout() argument
2613 if (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG)) in coda_decode_timeout()
2616 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_decode_timeout()
2617 dst_buf->sequence = ctx->qsequence - 1; in coda_decode_timeout()
2619 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_ERROR); in coda_decode_timeout()
2637 struct coda_ctx *ctx; in coda_irq_handler() local
2645 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); in coda_irq_handler()
2646 if (ctx == NULL) { in coda_irq_handler()
2652 trace_coda_bit_done(ctx); in coda_irq_handler()
2654 if (ctx->aborting) { in coda_irq_handler()
2655 coda_dbg(1, ctx, "task has been aborted\n"); in coda_irq_handler()
2658 if (coda_isbusy(ctx->dev)) { in coda_irq_handler()
2659 coda_dbg(1, ctx, "coda is still busy!!!!\n"); in coda_irq_handler()
2663 complete(&ctx->completion); in coda_irq_handler()