Lines Matching refs:ctx

43 static void coda_free_bitstream_buffer(struct coda_ctx *ctx);
66 static void coda_command_async(struct coda_ctx *ctx, int cmd) in coda_command_async() argument
68 struct coda_dev *dev = ctx->dev; in coda_command_async()
73 coda_write(dev, ctx->bit_stream_param, in coda_command_async()
75 coda_write(dev, ctx->frm_dis_flg, in coda_command_async()
76 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_command_async()
77 coda_write(dev, ctx->frame_mem_ctrl, in coda_command_async()
79 coda_write(dev, ctx->workbuf.paddr, CODA_REG_BIT_WORK_BUF_ADDR); in coda_command_async()
89 coda_write(dev, ctx->idx, CODA_REG_BIT_RUN_INDEX); in coda_command_async()
90 coda_write(dev, ctx->params.codec_mode, CODA_REG_BIT_RUN_COD_STD); in coda_command_async()
91 coda_write(dev, ctx->params.codec_mode_aux, CODA7_REG_BIT_RUN_AUX_STD); in coda_command_async()
93 trace_coda_bit_run(ctx, cmd); in coda_command_async()
98 static int coda_command_sync(struct coda_ctx *ctx, int cmd) in coda_command_sync() argument
100 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()
146 static void coda_kfifo_sync_from_device(struct coda_ctx *ctx) in coda_kfifo_sync_from_device() argument
148 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_from_device()
149 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_from_device()
152 rd_ptr = coda_read(dev, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_kfifo_sync_from_device()
154 (rd_ptr - ctx->bitstream.paddr); in coda_kfifo_sync_from_device()
159 static void coda_kfifo_sync_to_device_full(struct coda_ctx *ctx) in coda_kfifo_sync_to_device_full() argument
161 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_to_device_full()
162 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_to_device_full()
165 rd_ptr = ctx->bitstream.paddr + (kfifo->out & kfifo->mask); in coda_kfifo_sync_to_device_full()
166 coda_write(dev, rd_ptr, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_full()
167 wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); in coda_kfifo_sync_to_device_full()
168 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_full()
171 static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx) in coda_kfifo_sync_to_device_write() argument
173 struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; in coda_kfifo_sync_to_device_write()
174 struct coda_dev *dev = ctx->dev; in coda_kfifo_sync_to_device_write()
177 wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); in coda_kfifo_sync_to_device_write()
178 coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_kfifo_sync_to_device_write()
181 static int coda_bitstream_queue(struct coda_ctx *ctx, in coda_bitstream_queue() argument
187 n = kfifo_in(&ctx->bitstream_fifo, vb2_plane_vaddr(src_buf, 0), in coda_bitstream_queue()
192 src_buf->v4l2_buf.sequence = ctx->qsequence++; in coda_bitstream_queue()
197 static bool coda_bitstream_try_queue(struct coda_ctx *ctx, in coda_bitstream_try_queue() argument
202 if (coda_get_bitstream_payload(ctx) + in coda_bitstream_try_queue()
203 vb2_get_plane_payload(src_buf, 0) + 512 >= ctx->bitstream.size) in coda_bitstream_try_queue()
207 v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n"); in coda_bitstream_try_queue()
211 ret = coda_bitstream_queue(ctx, src_buf); in coda_bitstream_try_queue()
213 v4l2_err(&ctx->dev->v4l2_dev, "bitstream buffer overflow\n"); in coda_bitstream_try_queue()
217 if (ctx == v4l2_m2m_get_curr_priv(ctx->dev->m2m_dev)) in coda_bitstream_try_queue()
218 coda_kfifo_sync_to_device_write(ctx); in coda_bitstream_try_queue()
220 ctx->hold = false; in coda_bitstream_try_queue()
225 void coda_fill_bitstream(struct coda_ctx *ctx, bool streaming) in coda_fill_bitstream() argument
231 while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) { in coda_fill_bitstream()
236 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
237 (coda_get_bitstream_payload(ctx) >= 512) && !ctx->hold) in coda_fill_bitstream()
240 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_fill_bitstream()
243 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
244 !coda_jpeg_check_buffer(ctx, src_buf)) { in coda_fill_bitstream()
245 v4l2_err(&ctx->dev->v4l2_dev, in coda_fill_bitstream()
247 ctx->qsequence); in coda_fill_bitstream()
248 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
256 start = ctx->bitstream_fifo.kfifo.in & in coda_fill_bitstream()
257 ctx->bitstream_fifo.kfifo.mask; in coda_fill_bitstream()
259 if (coda_bitstream_try_queue(ctx, src_buf)) { in coda_fill_bitstream()
264 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
272 meta->end = ctx->bitstream_fifo.kfifo.in & in coda_fill_bitstream()
273 ctx->bitstream_fifo.kfifo.mask; in coda_fill_bitstream()
275 &ctx->buffer_meta_list); in coda_fill_bitstream()
277 trace_coda_bit_queue(ctx, src_buf, meta); in coda_fill_bitstream()
287 void coda_bit_stream_end_flag(struct coda_ctx *ctx) in coda_bit_stream_end_flag() argument
289 struct coda_dev *dev = ctx->dev; in coda_bit_stream_end_flag()
291 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_bit_stream_end_flag()
296 (ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX))) { in coda_bit_stream_end_flag()
297 coda_write(dev, ctx->bit_stream_param, in coda_bit_stream_end_flag()
302 static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value) in coda_parabuf_write() argument
304 struct coda_dev *dev = ctx->dev; in coda_parabuf_write()
305 u32 *p = ctx->parabuf.vaddr; in coda_parabuf_write()
313 static inline int coda_alloc_context_buf(struct coda_ctx *ctx, in coda_alloc_context_buf() argument
317 return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry); in coda_alloc_context_buf()
321 static void coda_free_framebuffers(struct coda_ctx *ctx) in coda_free_framebuffers() argument
326 coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i]); in coda_free_framebuffers()
329 static int coda_alloc_framebuffers(struct coda_ctx *ctx, in coda_alloc_framebuffers() argument
332 struct coda_dev *dev = ctx->dev; in coda_alloc_framebuffers()
339 if (ctx->codec && (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
340 ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264)) { in coda_alloc_framebuffers()
350 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
355 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && in coda_alloc_framebuffers()
359 ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i], in coda_alloc_framebuffers()
363 coda_free_framebuffers(ctx); in coda_alloc_framebuffers()
369 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
370 paddr = ctx->internal_frames[i].paddr; in coda_alloc_framebuffers()
372 coda_parabuf_write(ctx, i * 3 + 0, paddr); in coda_alloc_framebuffers()
373 coda_parabuf_write(ctx, i * 3 + 1, paddr + ysize); in coda_alloc_framebuffers()
374 coda_parabuf_write(ctx, i * 3 + 2, paddr + ysize + ysize / 4); in coda_alloc_framebuffers()
377 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && in coda_alloc_framebuffers()
379 coda_parabuf_write(ctx, 96 + i, in coda_alloc_framebuffers()
380 ctx->internal_frames[i].paddr + in coda_alloc_framebuffers()
386 (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4)) in coda_alloc_framebuffers()
387 coda_parabuf_write(ctx, 97, ctx->internal_frames[i].paddr + in coda_alloc_framebuffers()
393 static void coda_free_context_buffers(struct coda_ctx *ctx) in coda_free_context_buffers() argument
395 struct coda_dev *dev = ctx->dev; in coda_free_context_buffers()
397 coda_free_aux_buf(dev, &ctx->slicebuf); in coda_free_context_buffers()
398 coda_free_aux_buf(dev, &ctx->psbuf); in coda_free_context_buffers()
400 coda_free_aux_buf(dev, &ctx->workbuf); in coda_free_context_buffers()
401 coda_free_aux_buf(dev, &ctx->parabuf); in coda_free_context_buffers()
404 static int coda_alloc_context_buffers(struct coda_ctx *ctx, in coda_alloc_context_buffers() argument
407 struct coda_dev *dev = ctx->dev; in coda_alloc_context_buffers()
411 if (!ctx->parabuf.vaddr) { in coda_alloc_context_buffers()
412 ret = coda_alloc_context_buf(ctx, &ctx->parabuf, in coda_alloc_context_buffers()
421 if (!ctx->slicebuf.vaddr && q_data->fourcc == V4L2_PIX_FMT_H264) { in coda_alloc_context_buffers()
425 ret = coda_alloc_context_buf(ctx, &ctx->slicebuf, size, in coda_alloc_context_buffers()
431 if (!ctx->psbuf.vaddr && dev->devtype->product == CODA_7541) { in coda_alloc_context_buffers()
432 ret = coda_alloc_context_buf(ctx, &ctx->psbuf, in coda_alloc_context_buffers()
438 if (!ctx->workbuf.vaddr) { in coda_alloc_context_buffers()
443 ret = coda_alloc_context_buf(ctx, &ctx->workbuf, size, in coda_alloc_context_buffers()
452 coda_free_context_buffers(ctx); in coda_alloc_context_buffers()
456 static int coda_encode_header(struct coda_ctx *ctx, struct vb2_buffer *buf, in coda_encode_header() argument
459 struct coda_dev *dev = ctx->dev; in coda_encode_header()
474 ret = coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER); in coda_encode_header()
486 *size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)) - in coda_encode_header()
509 static void coda_setup_iram(struct coda_ctx *ctx) in coda_setup_iram() argument
511 struct coda_iram_info *iram_info = &ctx->iram_info; in coda_setup_iram()
512 struct coda_dev *dev = ctx->dev; in coda_setup_iram()
541 if (ctx->inst_type == CODA_INST_ENCODER) { in coda_setup_iram()
544 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_setup_iram()
581 } else if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
584 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_setup_iram()
609 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, in coda_setup_iram()
614 if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
719 static int coda_encoder_reqbufs(struct coda_ctx *ctx, in coda_encoder_reqbufs() argument
729 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_encoder_reqbufs()
730 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_encoder_reqbufs()
734 coda_free_context_buffers(ctx); in coda_encoder_reqbufs()
740 static int coda_start_encoding(struct coda_ctx *ctx) in coda_start_encoding() argument
742 struct coda_dev *dev = ctx->dev; in coda_start_encoding()
752 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_start_encoding()
753 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_start_encoding()
756 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
766 if (!ctx->params.jpeg_qmat_tab[0]) in coda_start_encoding()
767 ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
768 if (!ctx->params.jpeg_qmat_tab[1]) in coda_start_encoding()
769 ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
770 coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality); in coda_start_encoding()
775 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in coda_start_encoding()
776 coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_start_encoding()
777 coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_start_encoding()
792 ctx->frame_mem_ctrl &= ~CODA_FRAME_CHROMA_INTERLEAVE; in coda_start_encoding()
794 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in coda_start_encoding()
795 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in coda_start_encoding()
829 ctx->params.framerate = 0; in coda_start_encoding()
830 coda_write(dev, ctx->params.framerate, in coda_start_encoding()
833 ctx->params.codec_mode = ctx->codec->mode; in coda_start_encoding()
851 if (ctx->params.h264_deblk_enabled) { in coda_start_encoding()
852 value = ((ctx->params.h264_deblk_alpha & in coda_start_encoding()
855 ((ctx->params.h264_deblk_beta & in coda_start_encoding()
865 coda_write(dev, ctx->params.jpeg_restart_interval, in coda_start_encoding()
871 coda_jpeg_write_tables(ctx); in coda_start_encoding()
885 switch (ctx->params.slice_mode) { in coda_start_encoding()
890 value = (ctx->params.slice_max_mb & in coda_start_encoding()
898 value = (ctx->params.slice_max_bits & in coda_start_encoding()
907 value = ctx->params.gop_size & CODA_GOP_SIZE_MASK; in coda_start_encoding()
911 if (ctx->params.bitrate) { in coda_start_encoding()
913 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK) in coda_start_encoding()
924 coda_write(dev, ctx->params.intra_refresh, in coda_start_encoding()
941 if (ctx->params.h264_min_qp || ctx->params.h264_max_qp) { in coda_start_encoding()
943 ctx->params.h264_min_qp << CODA_QPMIN_OFFSET | in coda_start_encoding()
944 ctx->params.h264_max_qp << CODA_QPMAX_OFFSET, in coda_start_encoding()
948 if (ctx->params.h264_max_qp) in coda_start_encoding()
959 if (ctx->params.h264_min_qp) in coda_start_encoding()
961 if (ctx->params.h264_max_qp) in coda_start_encoding()
968 coda_setup_iram(ctx); in coda_start_encoding()
977 coda_write(dev, ctx->iram_info.search_ram_paddr, in coda_start_encoding()
979 coda_write(dev, ctx->iram_info.search_ram_size, in coda_start_encoding()
988 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); in coda_start_encoding()
1002 ctx->num_internal_frames = 4; in coda_start_encoding()
1004 ctx->num_internal_frames = 2; in coda_start_encoding()
1005 ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc); in coda_start_encoding()
1013 ctx->num_internal_frames = 0; in coda_start_encoding()
1025 coda_write(dev, ctx->iram_info.buf_bit_use, in coda_start_encoding()
1027 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in coda_start_encoding()
1029 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in coda_start_encoding()
1031 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in coda_start_encoding()
1033 coda_write(dev, ctx->iram_info.buf_ovl_use, in coda_start_encoding()
1036 coda_write(dev, ctx->iram_info.buf_btp_use, in coda_start_encoding()
1040 coda_write(dev, ctx->internal_frames[2].paddr, in coda_start_encoding()
1042 coda_write(dev, ctx->internal_frames[3].paddr, in coda_start_encoding()
1047 ret = coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF); in coda_start_encoding()
1054 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
1061 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_SPS, in coda_start_encoding()
1062 &ctx->vpu_header[0][0], in coda_start_encoding()
1063 &ctx->vpu_header_size[0]); in coda_start_encoding()
1071 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_PPS, in coda_start_encoding()
1072 &ctx->vpu_header[1][0], in coda_start_encoding()
1073 &ctx->vpu_header_size[1]); in coda_start_encoding()
1082 ctx->vpu_header_size[2] = coda_h264_padding( in coda_start_encoding()
1083 (ctx->vpu_header_size[0] + in coda_start_encoding()
1084 ctx->vpu_header_size[1]), in coda_start_encoding()
1085 ctx->vpu_header[2]); in coda_start_encoding()
1092 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOS, in coda_start_encoding()
1093 &ctx->vpu_header[0][0], in coda_start_encoding()
1094 &ctx->vpu_header_size[0]); in coda_start_encoding()
1098 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VIS, in coda_start_encoding()
1099 &ctx->vpu_header[1][0], in coda_start_encoding()
1100 &ctx->vpu_header_size[1]); in coda_start_encoding()
1104 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOL, in coda_start_encoding()
1105 &ctx->vpu_header[2][0], in coda_start_encoding()
1106 &ctx->vpu_header_size[2]); in coda_start_encoding()
1120 static int coda_prepare_encode(struct coda_ctx *ctx) in coda_prepare_encode() argument
1124 struct coda_dev *dev = ctx->dev; in coda_prepare_encode()
1132 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1133 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1134 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_prepare_encode()
1135 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_encode()
1138 src_buf->v4l2_buf.sequence = ctx->osequence; in coda_prepare_encode()
1139 dst_buf->v4l2_buf.sequence = ctx->osequence; in coda_prepare_encode()
1140 ctx->osequence++; in coda_prepare_encode()
1147 if (src_buf->v4l2_buf.sequence % ctx->params.gop_size) { in coda_prepare_encode()
1156 coda_set_gdi_regs(ctx); in coda_prepare_encode()
1165 ctx->vpu_header_size[0] + in coda_prepare_encode()
1166 ctx->vpu_header_size[1] + in coda_prepare_encode()
1167 ctx->vpu_header_size[2]; in coda_prepare_encode()
1169 ctx->vpu_header_size[0] - in coda_prepare_encode()
1170 ctx->vpu_header_size[1] - in coda_prepare_encode()
1171 ctx->vpu_header_size[2]; in coda_prepare_encode()
1173 &ctx->vpu_header[0][0], ctx->vpu_header_size[0]); in coda_prepare_encode()
1174 memcpy(vb2_plane_vaddr(dst_buf, 0) + ctx->vpu_header_size[0], in coda_prepare_encode()
1175 &ctx->vpu_header[1][0], ctx->vpu_header_size[1]); in coda_prepare_encode()
1176 memcpy(vb2_plane_vaddr(dst_buf, 0) + ctx->vpu_header_size[0] + in coda_prepare_encode()
1177 ctx->vpu_header_size[1], &ctx->vpu_header[2][0], in coda_prepare_encode()
1178 ctx->vpu_header_size[2]); in coda_prepare_encode()
1189 quant_param = ctx->params.h264_intra_qp; in coda_prepare_encode()
1192 quant_param = ctx->params.mpeg4_intra_qp; in coda_prepare_encode()
1198 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1206 quant_param = ctx->params.h264_inter_qp; in coda_prepare_encode()
1209 quant_param = ctx->params.mpeg4_inter_qp; in coda_prepare_encode()
1212 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1219 if (ctx->params.rot_mode) in coda_prepare_encode()
1220 rot_mode = CODA_ROT_MIR_ENABLE | ctx->params.rot_mode; in coda_prepare_encode()
1233 coda_write_base(ctx, q_data_src, src_buf, reg); in coda_prepare_encode()
1242 if (!ctx->streamon_out) { in coda_prepare_encode()
1244 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_prepare_encode()
1245 coda_write(dev, ctx->bit_stream_param, in coda_prepare_encode()
1250 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_encode()
1253 trace_coda_enc_pic_run(ctx, src_buf); in coda_prepare_encode()
1255 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_encode()
1260 static void coda_finish_encode(struct coda_ctx *ctx) in coda_finish_encode() argument
1263 struct coda_dev *dev = ctx->dev; in coda_finish_encode()
1266 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1267 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_finish_encode()
1269 trace_coda_enc_pic_done(ctx, dst_buf); in coda_finish_encode()
1273 wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_finish_encode()
1278 ctx->vpu_header_size[0] + in coda_finish_encode()
1279 ctx->vpu_header_size[1] + in coda_finish_encode()
1280 ctx->vpu_header_size[2]); in coda_finish_encode()
1285 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "frame size = %u\n", in coda_finish_encode()
1307 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1310 ctx->gopcounter--; in coda_finish_encode()
1311 if (ctx->gopcounter < 0) in coda_finish_encode()
1312 ctx->gopcounter = ctx->params.gop_size - 1; in coda_finish_encode()
1323 struct coda_ctx *ctx = container_of(work, struct coda_ctx, seq_end_work); in coda_seq_end_work() local
1324 struct coda_dev *dev = ctx->dev; in coda_seq_end_work()
1326 mutex_lock(&ctx->buffer_mutex); in coda_seq_end_work()
1330 "%d: %s: sent command 'SEQ_END' to coda\n", ctx->idx, in coda_seq_end_work()
1332 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) { in coda_seq_end_work()
1337 kfifo_init(&ctx->bitstream_fifo, in coda_seq_end_work()
1338 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_seq_end_work()
1340 coda_free_framebuffers(ctx); in coda_seq_end_work()
1343 mutex_unlock(&ctx->buffer_mutex); in coda_seq_end_work()
1346 static void coda_bit_release(struct coda_ctx *ctx) in coda_bit_release() argument
1348 mutex_lock(&ctx->buffer_mutex); in coda_bit_release()
1349 coda_free_framebuffers(ctx); in coda_bit_release()
1350 coda_free_context_buffers(ctx); in coda_bit_release()
1351 coda_free_bitstream_buffer(ctx); in coda_bit_release()
1352 mutex_unlock(&ctx->buffer_mutex); in coda_bit_release()
1369 static int coda_alloc_bitstream_buffer(struct coda_ctx *ctx, in coda_alloc_bitstream_buffer() argument
1372 if (ctx->bitstream.vaddr) in coda_alloc_bitstream_buffer()
1375 ctx->bitstream.size = roundup_pow_of_two(q_data->sizeimage * 2); in coda_alloc_bitstream_buffer()
1376 ctx->bitstream.vaddr = dma_alloc_writecombine( in coda_alloc_bitstream_buffer()
1377 &ctx->dev->plat_dev->dev, ctx->bitstream.size, in coda_alloc_bitstream_buffer()
1378 &ctx->bitstream.paddr, GFP_KERNEL); in coda_alloc_bitstream_buffer()
1379 if (!ctx->bitstream.vaddr) { in coda_alloc_bitstream_buffer()
1380 v4l2_err(&ctx->dev->v4l2_dev, in coda_alloc_bitstream_buffer()
1384 kfifo_init(&ctx->bitstream_fifo, in coda_alloc_bitstream_buffer()
1385 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_alloc_bitstream_buffer()
1390 static void coda_free_bitstream_buffer(struct coda_ctx *ctx) in coda_free_bitstream_buffer() argument
1392 if (ctx->bitstream.vaddr == NULL) in coda_free_bitstream_buffer()
1395 dma_free_writecombine(&ctx->dev->plat_dev->dev, ctx->bitstream.size, in coda_free_bitstream_buffer()
1396 ctx->bitstream.vaddr, ctx->bitstream.paddr); in coda_free_bitstream_buffer()
1397 ctx->bitstream.vaddr = NULL; in coda_free_bitstream_buffer()
1398 kfifo_init(&ctx->bitstream_fifo, NULL, 0); in coda_free_bitstream_buffer()
1401 static int coda_decoder_reqbufs(struct coda_ctx *ctx, in coda_decoder_reqbufs() argument
1411 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_decoder_reqbufs()
1412 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_decoder_reqbufs()
1415 ret = coda_alloc_bitstream_buffer(ctx, q_data_src); in coda_decoder_reqbufs()
1417 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1421 coda_free_bitstream_buffer(ctx); in coda_decoder_reqbufs()
1422 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1428 static int __coda_start_decoding(struct coda_ctx *ctx) in __coda_start_decoding() argument
1432 struct coda_dev *dev = ctx->dev; in __coda_start_decoding()
1439 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in __coda_start_decoding()
1440 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in __coda_start_decoding()
1441 bitstream_buf = ctx->bitstream.paddr; in __coda_start_decoding()
1442 bitstream_size = ctx->bitstream.size; in __coda_start_decoding()
1446 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in __coda_start_decoding()
1449 coda_kfifo_sync_to_device_full(ctx); in __coda_start_decoding()
1451 ctx->frame_mem_ctrl &= ~CODA_FRAME_CHROMA_INTERLEAVE; in __coda_start_decoding()
1453 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in __coda_start_decoding()
1454 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in __coda_start_decoding()
1456 ctx->display_idx = -1; in __coda_start_decoding()
1457 ctx->frm_dis_flg = 0; in __coda_start_decoding()
1458 coda_write(dev, 0, CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in __coda_start_decoding()
1469 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) in __coda_start_decoding()
1473 ctx->params.codec_mode = ctx->codec->mode; in __coda_start_decoding()
1476 ctx->params.codec_mode_aux = CODA_MP4_AUX_MPEG4; in __coda_start_decoding()
1478 ctx->params.codec_mode_aux = 0; in __coda_start_decoding()
1481 coda_write(dev, ctx->psbuf.paddr, in __coda_start_decoding()
1494 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT)) { in __coda_start_decoding()
1501 coda_kfifo_sync_from_device(ctx); in __coda_start_decoding()
1532 __func__, ctx->idx, width, height); in __coda_start_decoding()
1534 ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED); in __coda_start_decoding()
1535 if (ctx->num_internal_frames > CODA_MAX_FRAMEBUFFERS) { in __coda_start_decoding()
1538 CODA_MAX_FRAMEBUFFERS, ctx->num_internal_frames); in __coda_start_decoding()
1557 ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc); in __coda_start_decoding()
1564 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); in __coda_start_decoding()
1569 coda_setup_iram(ctx); in __coda_start_decoding()
1571 coda_write(dev, ctx->iram_info.buf_bit_use, in __coda_start_decoding()
1573 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in __coda_start_decoding()
1575 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in __coda_start_decoding()
1577 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in __coda_start_decoding()
1579 coda_write(dev, ctx->iram_info.buf_ovl_use, in __coda_start_decoding()
1582 coda_write(dev, ctx->iram_info.buf_btp_use, in __coda_start_decoding()
1608 coda_write(dev, ctx->slicebuf.paddr, in __coda_start_decoding()
1610 coda_write(dev, ctx->slicebuf.size / 1024, in __coda_start_decoding()
1630 if (coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF)) { in __coda_start_decoding()
1631 v4l2_err(&ctx->dev->v4l2_dev, in __coda_start_decoding()
1639 static int coda_start_decoding(struct coda_ctx *ctx) in coda_start_decoding() argument
1641 struct coda_dev *dev = ctx->dev; in coda_start_decoding()
1645 ret = __coda_start_decoding(ctx); in coda_start_decoding()
1651 static int coda_prepare_decode(struct coda_ctx *ctx) in coda_prepare_decode() argument
1654 struct coda_dev *dev = ctx->dev; in coda_prepare_decode()
1659 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_decode()
1660 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_decode()
1663 mutex_lock(&ctx->bitstream_mutex); in coda_prepare_decode()
1664 coda_fill_bitstream(ctx, true); in coda_prepare_decode()
1665 mutex_unlock(&ctx->bitstream_mutex); in coda_prepare_decode()
1667 if (coda_get_bitstream_payload(ctx) < 512 && in coda_prepare_decode()
1668 (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { in coda_prepare_decode()
1671 coda_get_bitstream_payload(ctx)); in coda_prepare_decode()
1672 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); in coda_prepare_decode()
1677 if (!ctx->initialized) { in coda_prepare_decode()
1678 int ret = __coda_start_decoding(ctx); in coda_prepare_decode()
1682 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); in coda_prepare_decode()
1685 ctx->initialized = 1; in coda_prepare_decode()
1690 coda_set_gdi_regs(ctx); in coda_prepare_decode()
1708 coda_write_base(ctx, q_data_dst, dst_buf, reg_addr); in coda_prepare_decode()
1711 coda_write(dev, CODA_ROT_MIR_ENABLE | ctx->params.rot_mode, in coda_prepare_decode()
1732 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_decode()
1735 meta = list_first_entry_or_null(&ctx->buffer_meta_list, in coda_prepare_decode()
1738 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) { in coda_prepare_decode()
1741 if (meta->end == (ctx->bitstream_fifo.kfifo.in & in coda_prepare_decode()
1742 ctx->bitstream_fifo.kfifo.mask)) { in coda_prepare_decode()
1751 kfifo_in(&ctx->bitstream_fifo, buf, pad); in coda_prepare_decode()
1755 coda_kfifo_sync_to_device_full(ctx); in coda_prepare_decode()
1760 trace_coda_dec_pic_run(ctx, meta); in coda_prepare_decode()
1762 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_decode()
1767 static void coda_finish_decode(struct coda_ctx *ctx) in coda_finish_decode() argument
1769 struct coda_dev *dev = ctx->dev; in coda_finish_decode()
1784 coda_kfifo_sync_from_device(ctx); in coda_finish_decode()
1790 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) { in coda_finish_decode()
1791 if (coda_get_bitstream_payload(ctx) >= ctx->bitstream.size - 512) in coda_finish_decode()
1792 kfifo_init(&ctx->bitstream_fifo, in coda_finish_decode()
1793 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_finish_decode()
1796 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_finish_decode()
1811 ctx->psbuf.size); in coda_finish_decode()
1815 ctx->slicebuf.size); in coda_finish_decode()
1822 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_finish_decode()
1859 ctx->hold = true; in coda_finish_decode()
1864 ctx->frm_dis_flg = coda_read(dev, in coda_finish_decode()
1865 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
1871 if (ctx->display_idx >= 0 && in coda_finish_decode()
1872 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
1873 ctx->frm_dis_flg &= ~(1 << ctx->display_idx); in coda_finish_decode()
1874 coda_write(dev, ctx->frm_dis_flg, in coda_finish_decode()
1875 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
1888 if (display_idx >= 0 && display_idx < ctx->num_internal_frames) in coda_finish_decode()
1889 ctx->sequence_offset++; in coda_finish_decode()
1890 else if (ctx->display_idx < 0) in coda_finish_decode()
1891 ctx->hold = true; in coda_finish_decode()
1894 } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) { in coda_finish_decode()
1899 val -= ctx->sequence_offset; in coda_finish_decode()
1900 mutex_lock(&ctx->bitstream_mutex); in coda_finish_decode()
1901 if (!list_empty(&ctx->buffer_meta_list)) { in coda_finish_decode()
1902 meta = list_first_entry(&ctx->buffer_meta_list, in coda_finish_decode()
1908 val, ctx->sequence_offset, in coda_finish_decode()
1911 ctx->frame_metas[decoded_idx] = *meta; in coda_finish_decode()
1915 memset(&ctx->frame_metas[decoded_idx], 0, in coda_finish_decode()
1917 ctx->frame_metas[decoded_idx].sequence = val; in coda_finish_decode()
1918 ctx->sequence_offset++; in coda_finish_decode()
1920 mutex_unlock(&ctx->bitstream_mutex); in coda_finish_decode()
1922 trace_coda_dec_pic_done(ctx, &ctx->frame_metas[decoded_idx]); in coda_finish_decode()
1926 ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_KEYFRAME; in coda_finish_decode()
1928 ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_PFRAME; in coda_finish_decode()
1930 ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_BFRAME; in coda_finish_decode()
1932 ctx->frame_errors[decoded_idx] = err_mb; in coda_finish_decode()
1940 ctx->hold = true; in coda_finish_decode()
1943 } else if (display_idx < 0 || display_idx >= ctx->num_internal_frames) { in coda_finish_decode()
1950 if (ctx->display_idx >= 0 && in coda_finish_decode()
1951 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
1952 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_decode()
1953 dst_buf->v4l2_buf.sequence = ctx->osequence++; in coda_finish_decode()
1958 dst_buf->v4l2_buf.flags |= ctx->frame_types[ctx->display_idx]; in coda_finish_decode()
1959 meta = &ctx->frame_metas[ctx->display_idx]; in coda_finish_decode()
1963 trace_coda_dec_rot_done(ctx, meta, dst_buf); in coda_finish_decode()
1978 v4l2_m2m_buf_done(dst_buf, ctx->frame_errors[display_idx] ? in coda_finish_decode()
1992 ctx->display_idx = display_idx; in coda_finish_decode()
2008 struct coda_ctx *ctx; in coda_irq_handler() local
2015 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); in coda_irq_handler()
2016 if (ctx == NULL) { in coda_irq_handler()
2023 trace_coda_bit_done(ctx); in coda_irq_handler()
2025 if (ctx->aborting) { in coda_irq_handler()
2026 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, in coda_irq_handler()
2030 if (coda_isbusy(ctx->dev)) { in coda_irq_handler()
2031 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, in coda_irq_handler()
2036 complete(&ctx->completion); in coda_irq_handler()