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, in coda_bitstream_queue()
192 src_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()
204 ctx->bitstream.size) in coda_bitstream_try_queue()
208 v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n"); in coda_bitstream_try_queue()
212 ret = coda_bitstream_queue(ctx, src_buf); in coda_bitstream_try_queue()
214 v4l2_err(&ctx->dev->v4l2_dev, "bitstream buffer overflow\n"); in coda_bitstream_try_queue()
218 if (ctx == v4l2_m2m_get_curr_priv(ctx->dev->m2m_dev)) in coda_bitstream_try_queue()
219 coda_kfifo_sync_to_device_write(ctx); in coda_bitstream_try_queue()
221 ctx->hold = false; in coda_bitstream_try_queue()
226 void coda_fill_bitstream(struct coda_ctx *ctx, bool streaming) in coda_fill_bitstream() argument
233 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) in coda_fill_bitstream()
236 while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) { in coda_fill_bitstream()
241 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
242 (coda_get_bitstream_payload(ctx) >= 512) && !ctx->hold) in coda_fill_bitstream()
245 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_fill_bitstream()
248 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG && in coda_fill_bitstream()
249 !coda_jpeg_check_buffer(ctx, &src_buf->vb2_buf)) { in coda_fill_bitstream()
250 v4l2_err(&ctx->dev->v4l2_dev, in coda_fill_bitstream()
252 ctx->qsequence); in coda_fill_bitstream()
253 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
262 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
268 start = ctx->bitstream_fifo.kfifo.in & in coda_fill_bitstream()
269 ctx->bitstream_fifo.kfifo.mask; in coda_fill_bitstream()
271 if (coda_bitstream_try_queue(ctx, src_buf)) { in coda_fill_bitstream()
276 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_fill_bitstream()
284 meta->end = ctx->bitstream_fifo.kfifo.in & in coda_fill_bitstream()
285 ctx->bitstream_fifo.kfifo.mask; in coda_fill_bitstream()
286 spin_lock_irqsave(&ctx->buffer_meta_lock, in coda_fill_bitstream()
289 &ctx->buffer_meta_list); in coda_fill_bitstream()
290 ctx->num_metas++; in coda_fill_bitstream()
291 spin_unlock_irqrestore(&ctx->buffer_meta_lock, in coda_fill_bitstream()
294 trace_coda_bit_queue(ctx, src_buf, meta); in coda_fill_bitstream()
304 void coda_bit_stream_end_flag(struct coda_ctx *ctx) in coda_bit_stream_end_flag() argument
306 struct coda_dev *dev = ctx->dev; in coda_bit_stream_end_flag()
308 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_bit_stream_end_flag()
313 (ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX))) { in coda_bit_stream_end_flag()
314 coda_write(dev, ctx->bit_stream_param, in coda_bit_stream_end_flag()
319 static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value) in coda_parabuf_write() argument
321 struct coda_dev *dev = ctx->dev; in coda_parabuf_write()
322 u32 *p = ctx->parabuf.vaddr; in coda_parabuf_write()
330 static inline int coda_alloc_context_buf(struct coda_ctx *ctx, in coda_alloc_context_buf() argument
334 return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry); in coda_alloc_context_buf()
338 static void coda_free_framebuffers(struct coda_ctx *ctx) in coda_free_framebuffers() argument
343 coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i]); in coda_free_framebuffers()
346 static int coda_alloc_framebuffers(struct coda_ctx *ctx, in coda_alloc_framebuffers() argument
349 struct coda_dev *dev = ctx->dev; in coda_alloc_framebuffers()
355 if (ctx->codec && (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || in coda_alloc_framebuffers()
356 ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264)) { in coda_alloc_framebuffers()
366 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
370 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda_alloc_framebuffers()
374 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && in coda_alloc_framebuffers()
378 ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i], in coda_alloc_framebuffers()
382 coda_free_framebuffers(ctx); in coda_alloc_framebuffers()
388 for (i = 0; i < ctx->num_internal_frames; i++) { in coda_alloc_framebuffers()
392 y = ctx->internal_frames[i].paddr; in coda_alloc_framebuffers()
395 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) { in coda_alloc_framebuffers()
403 coda_parabuf_write(ctx, i * 3 + 0, y); in coda_alloc_framebuffers()
404 coda_parabuf_write(ctx, i * 3 + 1, cb); in coda_alloc_framebuffers()
405 coda_parabuf_write(ctx, i * 3 + 2, cr); in coda_alloc_framebuffers()
408 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && in coda_alloc_framebuffers()
410 coda_parabuf_write(ctx, 96 + i, in coda_alloc_framebuffers()
411 ctx->internal_frames[i].paddr + in coda_alloc_framebuffers()
417 (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4)) in coda_alloc_framebuffers()
418 coda_parabuf_write(ctx, 97, ctx->internal_frames[0].paddr + in coda_alloc_framebuffers()
424 static void coda_free_context_buffers(struct coda_ctx *ctx) in coda_free_context_buffers() argument
426 struct coda_dev *dev = ctx->dev; in coda_free_context_buffers()
428 coda_free_aux_buf(dev, &ctx->slicebuf); in coda_free_context_buffers()
429 coda_free_aux_buf(dev, &ctx->psbuf); in coda_free_context_buffers()
431 coda_free_aux_buf(dev, &ctx->workbuf); in coda_free_context_buffers()
432 coda_free_aux_buf(dev, &ctx->parabuf); in coda_free_context_buffers()
435 static int coda_alloc_context_buffers(struct coda_ctx *ctx, in coda_alloc_context_buffers() argument
438 struct coda_dev *dev = ctx->dev; in coda_alloc_context_buffers()
442 if (!ctx->parabuf.vaddr) { in coda_alloc_context_buffers()
443 ret = coda_alloc_context_buf(ctx, &ctx->parabuf, in coda_alloc_context_buffers()
452 if (!ctx->slicebuf.vaddr && q_data->fourcc == V4L2_PIX_FMT_H264) { in coda_alloc_context_buffers()
456 ret = coda_alloc_context_buf(ctx, &ctx->slicebuf, size, in coda_alloc_context_buffers()
462 if (!ctx->psbuf.vaddr && dev->devtype->product == CODA_7541) { in coda_alloc_context_buffers()
463 ret = coda_alloc_context_buf(ctx, &ctx->psbuf, in coda_alloc_context_buffers()
469 if (!ctx->workbuf.vaddr) { in coda_alloc_context_buffers()
474 ret = coda_alloc_context_buf(ctx, &ctx->workbuf, size, in coda_alloc_context_buffers()
483 coda_free_context_buffers(ctx); in coda_alloc_context_buffers()
487 static int coda_encode_header(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf, in coda_encode_header() argument
491 struct coda_dev *dev = ctx->dev; in coda_encode_header()
506 ret = coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER); in coda_encode_header()
518 *size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)) - in coda_encode_header()
541 static void coda_setup_iram(struct coda_ctx *ctx) in coda_setup_iram() argument
543 struct coda_iram_info *iram_info = &ctx->iram_info; in coda_setup_iram()
544 struct coda_dev *dev = ctx->dev; in coda_setup_iram()
573 if (ctx->inst_type == CODA_INST_ENCODER) { in coda_setup_iram()
576 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_setup_iram()
613 } else if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
616 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_setup_iram()
641 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, in coda_setup_iram()
646 if (ctx->inst_type == CODA_INST_DECODER) { in coda_setup_iram()
747 static void coda9_set_frame_cache(struct coda_ctx *ctx, u32 fourcc) in coda9_set_frame_cache() argument
751 if (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) { in coda9_set_frame_cache()
760 coda_write(ctx->dev, cache_size, CODA9_CMD_SET_FRAME_CACHE_SIZE); in coda9_set_frame_cache()
770 coda_write(ctx->dev, cache_config, CODA9_CMD_SET_FRAME_CACHE_CONFIG); in coda9_set_frame_cache()
777 static int coda_encoder_reqbufs(struct coda_ctx *ctx, in coda_encoder_reqbufs() argument
787 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_encoder_reqbufs()
788 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_encoder_reqbufs()
792 coda_free_context_buffers(ctx); in coda_encoder_reqbufs()
798 static int coda_start_encoding(struct coda_ctx *ctx) in coda_start_encoding() argument
800 struct coda_dev *dev = ctx->dev; in coda_start_encoding()
810 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_start_encoding()
811 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_start_encoding()
814 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
824 if (!ctx->params.jpeg_qmat_tab[0]) in coda_start_encoding()
825 ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
826 if (!ctx->params.jpeg_qmat_tab[1]) in coda_start_encoding()
827 ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL); in coda_start_encoding()
828 coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality); in coda_start_encoding()
833 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in coda_start_encoding()
834 coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); in coda_start_encoding()
835 coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_start_encoding()
850 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in coda_start_encoding()
853 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in coda_start_encoding()
854 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda_start_encoding()
855 ctx->frame_mem_ctrl |= (0x3 << 9) | CODA9_FRAME_TILED2LINEAR; in coda_start_encoding()
856 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in coda_start_encoding()
890 ctx->params.framerate = 0; in coda_start_encoding()
891 coda_write(dev, ctx->params.framerate, in coda_start_encoding()
894 ctx->params.codec_mode = ctx->codec->mode; in coda_start_encoding()
912 if (ctx->params.h264_deblk_enabled) { in coda_start_encoding()
913 value = ((ctx->params.h264_deblk_alpha & in coda_start_encoding()
916 ((ctx->params.h264_deblk_beta & in coda_start_encoding()
926 coda_write(dev, ctx->params.jpeg_restart_interval, in coda_start_encoding()
932 coda_jpeg_write_tables(ctx); in coda_start_encoding()
946 switch (ctx->params.slice_mode) { in coda_start_encoding()
951 value = (ctx->params.slice_max_mb & in coda_start_encoding()
959 value = (ctx->params.slice_max_bits & in coda_start_encoding()
968 value = ctx->params.gop_size & CODA_GOP_SIZE_MASK; in coda_start_encoding()
972 if (ctx->params.bitrate) { in coda_start_encoding()
974 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK) in coda_start_encoding()
977 value |= (ctx->params.vbv_delay & in coda_start_encoding()
987 coda_write(dev, ctx->params.vbv_size, CODA_CMD_ENC_SEQ_RC_BUF_SIZE); in coda_start_encoding()
988 coda_write(dev, ctx->params.intra_refresh, in coda_start_encoding()
1005 if (ctx->params.h264_min_qp || ctx->params.h264_max_qp) { in coda_start_encoding()
1007 ctx->params.h264_min_qp << CODA_QPMIN_OFFSET | in coda_start_encoding()
1008 ctx->params.h264_max_qp << CODA_QPMAX_OFFSET, in coda_start_encoding()
1012 if (ctx->params.h264_max_qp) in coda_start_encoding()
1023 if (ctx->params.h264_min_qp) in coda_start_encoding()
1025 if (ctx->params.h264_max_qp) in coda_start_encoding()
1032 coda_setup_iram(ctx); in coda_start_encoding()
1041 coda_write(dev, ctx->iram_info.search_ram_paddr, in coda_start_encoding()
1043 coda_write(dev, ctx->iram_info.search_ram_size, in coda_start_encoding()
1052 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); in coda_start_encoding()
1063 ctx->initialized = 1; in coda_start_encoding()
1067 ctx->num_internal_frames = 4; in coda_start_encoding()
1069 ctx->num_internal_frames = 2; in coda_start_encoding()
1070 ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc); in coda_start_encoding()
1078 ctx->num_internal_frames = 0; in coda_start_encoding()
1090 coda_write(dev, ctx->iram_info.buf_bit_use, in coda_start_encoding()
1092 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in coda_start_encoding()
1094 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in coda_start_encoding()
1096 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in coda_start_encoding()
1098 coda_write(dev, ctx->iram_info.buf_ovl_use, in coda_start_encoding()
1101 coda_write(dev, ctx->iram_info.buf_btp_use, in coda_start_encoding()
1104 coda9_set_frame_cache(ctx, q_data_src->fourcc); in coda_start_encoding()
1107 coda_write(dev, ctx->internal_frames[2].paddr, in coda_start_encoding()
1109 coda_write(dev, ctx->internal_frames[3].paddr, in coda_start_encoding()
1114 ret = coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF); in coda_start_encoding()
1121 buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_start_encoding()
1128 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_SPS, in coda_start_encoding()
1129 &ctx->vpu_header[0][0], in coda_start_encoding()
1130 &ctx->vpu_header_size[0]); in coda_start_encoding()
1138 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_PPS, in coda_start_encoding()
1139 &ctx->vpu_header[1][0], in coda_start_encoding()
1140 &ctx->vpu_header_size[1]); in coda_start_encoding()
1149 ctx->vpu_header_size[2] = coda_h264_padding( in coda_start_encoding()
1150 (ctx->vpu_header_size[0] + in coda_start_encoding()
1151 ctx->vpu_header_size[1]), in coda_start_encoding()
1152 ctx->vpu_header[2]); in coda_start_encoding()
1159 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOS, in coda_start_encoding()
1160 &ctx->vpu_header[0][0], in coda_start_encoding()
1161 &ctx->vpu_header_size[0]); in coda_start_encoding()
1165 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VIS, in coda_start_encoding()
1166 &ctx->vpu_header[1][0], in coda_start_encoding()
1167 &ctx->vpu_header_size[1]); in coda_start_encoding()
1171 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOL, in coda_start_encoding()
1172 &ctx->vpu_header[2][0], in coda_start_encoding()
1173 &ctx->vpu_header_size[2]); in coda_start_encoding()
1187 static int coda_prepare_encode(struct coda_ctx *ctx) in coda_prepare_encode() argument
1191 struct coda_dev *dev = ctx->dev; in coda_prepare_encode()
1199 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1200 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_encode()
1201 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_prepare_encode()
1202 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_encode()
1205 src_buf->sequence = ctx->osequence; in coda_prepare_encode()
1206 dst_buf->sequence = ctx->osequence; in coda_prepare_encode()
1207 ctx->osequence++; in coda_prepare_encode()
1214 if (src_buf->sequence % ctx->params.gop_size) { in coda_prepare_encode()
1223 coda_set_gdi_regs(ctx); in coda_prepare_encode()
1232 ctx->vpu_header_size[0] + in coda_prepare_encode()
1233 ctx->vpu_header_size[1] + in coda_prepare_encode()
1234 ctx->vpu_header_size[2]; in coda_prepare_encode()
1236 ctx->vpu_header_size[0] - in coda_prepare_encode()
1237 ctx->vpu_header_size[1] - in coda_prepare_encode()
1238 ctx->vpu_header_size[2]; in coda_prepare_encode()
1240 &ctx->vpu_header[0][0], ctx->vpu_header_size[0]); in coda_prepare_encode()
1242 + ctx->vpu_header_size[0], &ctx->vpu_header[1][0], in coda_prepare_encode()
1243 ctx->vpu_header_size[1]); in coda_prepare_encode()
1245 + ctx->vpu_header_size[0] + ctx->vpu_header_size[1], in coda_prepare_encode()
1246 &ctx->vpu_header[2][0], ctx->vpu_header_size[2]); in coda_prepare_encode()
1257 quant_param = ctx->params.h264_intra_qp; in coda_prepare_encode()
1260 quant_param = ctx->params.mpeg4_intra_qp; in coda_prepare_encode()
1266 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1274 quant_param = ctx->params.h264_inter_qp; in coda_prepare_encode()
1277 quant_param = ctx->params.mpeg4_inter_qp; in coda_prepare_encode()
1280 v4l2_warn(&ctx->dev->v4l2_dev, in coda_prepare_encode()
1287 if (ctx->params.rot_mode) in coda_prepare_encode()
1288 rot_mode = CODA_ROT_MIR_ENABLE | ctx->params.rot_mode; in coda_prepare_encode()
1301 coda_write_base(ctx, q_data_src, src_buf, reg); in coda_prepare_encode()
1310 if (!ctx->streamon_out) { in coda_prepare_encode()
1312 ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; in coda_prepare_encode()
1313 coda_write(dev, ctx->bit_stream_param, in coda_prepare_encode()
1318 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_encode()
1321 trace_coda_enc_pic_run(ctx, src_buf); in coda_prepare_encode()
1323 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_encode()
1328 static void coda_finish_encode(struct coda_ctx *ctx) in coda_finish_encode() argument
1331 struct coda_dev *dev = ctx->dev; in coda_finish_encode()
1334 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1335 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_finish_encode()
1337 trace_coda_enc_pic_done(ctx, dst_buf); in coda_finish_encode()
1341 wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); in coda_finish_encode()
1346 ctx->vpu_header_size[0] + in coda_finish_encode()
1347 ctx->vpu_header_size[1] + in coda_finish_encode()
1348 ctx->vpu_header_size[2]); in coda_finish_encode()
1353 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "frame size = %u\n", in coda_finish_encode()
1375 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_encode()
1376 coda_m2m_buf_done(ctx, dst_buf, VB2_BUF_STATE_DONE); in coda_finish_encode()
1378 ctx->gopcounter--; in coda_finish_encode()
1379 if (ctx->gopcounter < 0) in coda_finish_encode()
1380 ctx->gopcounter = ctx->params.gop_size - 1; in coda_finish_encode()
1391 struct coda_ctx *ctx = container_of(work, struct coda_ctx, seq_end_work); in coda_seq_end_work() local
1392 struct coda_dev *dev = ctx->dev; in coda_seq_end_work()
1394 mutex_lock(&ctx->buffer_mutex); in coda_seq_end_work()
1397 if (ctx->initialized == 0) in coda_seq_end_work()
1401 "%d: %s: sent command 'SEQ_END' to coda\n", ctx->idx, in coda_seq_end_work()
1403 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) { in coda_seq_end_work()
1414 coda_hw_reset(ctx); in coda_seq_end_work()
1416 kfifo_init(&ctx->bitstream_fifo, in coda_seq_end_work()
1417 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_seq_end_work()
1419 coda_free_framebuffers(ctx); in coda_seq_end_work()
1421 ctx->initialized = 0; in coda_seq_end_work()
1425 mutex_unlock(&ctx->buffer_mutex); in coda_seq_end_work()
1428 static void coda_bit_release(struct coda_ctx *ctx) in coda_bit_release() argument
1430 mutex_lock(&ctx->buffer_mutex); in coda_bit_release()
1431 coda_free_framebuffers(ctx); in coda_bit_release()
1432 coda_free_context_buffers(ctx); in coda_bit_release()
1433 coda_free_bitstream_buffer(ctx); in coda_bit_release()
1434 mutex_unlock(&ctx->buffer_mutex); in coda_bit_release()
1451 static int coda_alloc_bitstream_buffer(struct coda_ctx *ctx, in coda_alloc_bitstream_buffer() argument
1454 if (ctx->bitstream.vaddr) in coda_alloc_bitstream_buffer()
1457 ctx->bitstream.size = roundup_pow_of_two(q_data->sizeimage * 2); in coda_alloc_bitstream_buffer()
1458 ctx->bitstream.vaddr = dma_alloc_wc(&ctx->dev->plat_dev->dev, in coda_alloc_bitstream_buffer()
1459 ctx->bitstream.size, in coda_alloc_bitstream_buffer()
1460 &ctx->bitstream.paddr, GFP_KERNEL); in coda_alloc_bitstream_buffer()
1461 if (!ctx->bitstream.vaddr) { in coda_alloc_bitstream_buffer()
1462 v4l2_err(&ctx->dev->v4l2_dev, in coda_alloc_bitstream_buffer()
1466 kfifo_init(&ctx->bitstream_fifo, in coda_alloc_bitstream_buffer()
1467 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_alloc_bitstream_buffer()
1472 static void coda_free_bitstream_buffer(struct coda_ctx *ctx) in coda_free_bitstream_buffer() argument
1474 if (ctx->bitstream.vaddr == NULL) in coda_free_bitstream_buffer()
1477 dma_free_wc(&ctx->dev->plat_dev->dev, ctx->bitstream.size, in coda_free_bitstream_buffer()
1478 ctx->bitstream.vaddr, ctx->bitstream.paddr); in coda_free_bitstream_buffer()
1479 ctx->bitstream.vaddr = NULL; in coda_free_bitstream_buffer()
1480 kfifo_init(&ctx->bitstream_fifo, NULL, 0); in coda_free_bitstream_buffer()
1483 static int coda_decoder_reqbufs(struct coda_ctx *ctx, in coda_decoder_reqbufs() argument
1493 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_decoder_reqbufs()
1494 ret = coda_alloc_context_buffers(ctx, q_data_src); in coda_decoder_reqbufs()
1497 ret = coda_alloc_bitstream_buffer(ctx, q_data_src); in coda_decoder_reqbufs()
1499 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1503 coda_free_bitstream_buffer(ctx); in coda_decoder_reqbufs()
1504 coda_free_context_buffers(ctx); in coda_decoder_reqbufs()
1510 static int __coda_start_decoding(struct coda_ctx *ctx) in __coda_start_decoding() argument
1514 struct coda_dev *dev = ctx->dev; in __coda_start_decoding()
1521 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in __coda_start_decoding()
1522 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in __coda_start_decoding()
1523 bitstream_buf = ctx->bitstream.paddr; in __coda_start_decoding()
1524 bitstream_size = ctx->bitstream.size; in __coda_start_decoding()
1528 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); in __coda_start_decoding()
1531 coda_kfifo_sync_to_device_full(ctx); in __coda_start_decoding()
1533 ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | in __coda_start_decoding()
1536 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; in __coda_start_decoding()
1537 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in __coda_start_decoding()
1538 ctx->frame_mem_ctrl |= (0x3 << 9) | CODA9_FRAME_TILED2LINEAR; in __coda_start_decoding()
1539 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); in __coda_start_decoding()
1541 ctx->display_idx = -1; in __coda_start_decoding()
1542 ctx->frm_dis_flg = 0; in __coda_start_decoding()
1543 coda_write(dev, 0, CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in __coda_start_decoding()
1554 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) in __coda_start_decoding()
1558 ctx->params.codec_mode = ctx->codec->mode; in __coda_start_decoding()
1561 ctx->params.codec_mode_aux = CODA_MP4_AUX_MPEG4; in __coda_start_decoding()
1563 ctx->params.codec_mode_aux = 0; in __coda_start_decoding()
1566 coda_write(dev, ctx->psbuf.paddr, in __coda_start_decoding()
1579 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT)) { in __coda_start_decoding()
1584 ctx->initialized = 1; in __coda_start_decoding()
1587 coda_kfifo_sync_from_device(ctx); in __coda_start_decoding()
1618 __func__, ctx->idx, width, height); in __coda_start_decoding()
1620 ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED); in __coda_start_decoding()
1621 if (ctx->num_internal_frames > CODA_MAX_FRAMEBUFFERS) { in __coda_start_decoding()
1624 CODA_MAX_FRAMEBUFFERS, ctx->num_internal_frames); in __coda_start_decoding()
1643 ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc); in __coda_start_decoding()
1650 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); in __coda_start_decoding()
1655 coda_setup_iram(ctx); in __coda_start_decoding()
1657 coda_write(dev, ctx->iram_info.buf_bit_use, in __coda_start_decoding()
1659 coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, in __coda_start_decoding()
1661 coda_write(dev, ctx->iram_info.buf_dbk_y_use, in __coda_start_decoding()
1663 coda_write(dev, ctx->iram_info.buf_dbk_c_use, in __coda_start_decoding()
1665 coda_write(dev, ctx->iram_info.buf_ovl_use, in __coda_start_decoding()
1668 coda_write(dev, ctx->iram_info.buf_btp_use, in __coda_start_decoding()
1672 coda9_set_frame_cache(ctx, dst_fourcc); in __coda_start_decoding()
1677 coda_write(dev, ctx->slicebuf.paddr, in __coda_start_decoding()
1679 coda_write(dev, ctx->slicebuf.size / 1024, in __coda_start_decoding()
1699 if (coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF)) { in __coda_start_decoding()
1700 v4l2_err(&ctx->dev->v4l2_dev, in __coda_start_decoding()
1708 static int coda_start_decoding(struct coda_ctx *ctx) in coda_start_decoding() argument
1710 struct coda_dev *dev = ctx->dev; in coda_start_decoding()
1714 ret = __coda_start_decoding(ctx); in coda_start_decoding()
1720 static int coda_prepare_decode(struct coda_ctx *ctx) in coda_prepare_decode() argument
1723 struct coda_dev *dev = ctx->dev; in coda_prepare_decode()
1729 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda_prepare_decode()
1730 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_prepare_decode()
1733 mutex_lock(&ctx->bitstream_mutex); in coda_prepare_decode()
1734 coda_fill_bitstream(ctx, true); in coda_prepare_decode()
1735 mutex_unlock(&ctx->bitstream_mutex); in coda_prepare_decode()
1737 if (coda_get_bitstream_payload(ctx) < 512 && in coda_prepare_decode()
1738 (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { in coda_prepare_decode()
1741 coda_get_bitstream_payload(ctx)); in coda_prepare_decode()
1742 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); in coda_prepare_decode()
1747 if (!ctx->initialized) { in coda_prepare_decode()
1748 int ret = __coda_start_decoding(ctx); in coda_prepare_decode()
1752 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); in coda_prepare_decode()
1755 ctx->initialized = 1; in coda_prepare_decode()
1760 coda_set_gdi_regs(ctx); in coda_prepare_decode()
1778 coda_write_base(ctx, q_data_dst, dst_buf, reg_addr); in coda_prepare_decode()
1781 coda_write(dev, CODA_ROT_MIR_ENABLE | ctx->params.rot_mode, in coda_prepare_decode()
1802 coda_write(dev, ctx->iram_info.axi_sram_use, in coda_prepare_decode()
1805 spin_lock_irqsave(&ctx->buffer_meta_lock, flags); in coda_prepare_decode()
1806 meta = list_first_entry_or_null(&ctx->buffer_meta_list, in coda_prepare_decode()
1809 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) { in coda_prepare_decode()
1812 if (meta->end == (ctx->bitstream_fifo.kfifo.in & in coda_prepare_decode()
1813 ctx->bitstream_fifo.kfifo.mask)) { in coda_prepare_decode()
1822 kfifo_in(&ctx->bitstream_fifo, buf, pad); in coda_prepare_decode()
1825 spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); in coda_prepare_decode()
1827 coda_kfifo_sync_to_device_full(ctx); in coda_prepare_decode()
1832 trace_coda_dec_pic_run(ctx, meta); in coda_prepare_decode()
1834 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); in coda_prepare_decode()
1839 static void coda_finish_decode(struct coda_ctx *ctx) in coda_finish_decode() argument
1841 struct coda_dev *dev = ctx->dev; in coda_finish_decode()
1857 coda_kfifo_sync_from_device(ctx); in coda_finish_decode()
1863 if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) { in coda_finish_decode()
1864 if (coda_get_bitstream_payload(ctx) >= ctx->bitstream.size - 512) in coda_finish_decode()
1865 kfifo_init(&ctx->bitstream_fifo, in coda_finish_decode()
1866 ctx->bitstream.vaddr, ctx->bitstream.size); in coda_finish_decode()
1869 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in coda_finish_decode()
1884 ctx->psbuf.size); in coda_finish_decode()
1888 ctx->slicebuf.size); in coda_finish_decode()
1895 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); in coda_finish_decode()
1932 ctx->hold = true; in coda_finish_decode()
1937 ctx->frm_dis_flg = coda_read(dev, in coda_finish_decode()
1938 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
1944 if (ctx->display_idx >= 0 && in coda_finish_decode()
1945 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
1946 ctx->frm_dis_flg &= ~(1 << ctx->display_idx); in coda_finish_decode()
1947 coda_write(dev, ctx->frm_dis_flg, in coda_finish_decode()
1948 CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); in coda_finish_decode()
1961 if (display_idx >= 0 && display_idx < ctx->num_internal_frames) in coda_finish_decode()
1962 ctx->sequence_offset++; in coda_finish_decode()
1963 else if (ctx->display_idx < 0) in coda_finish_decode()
1964 ctx->hold = true; in coda_finish_decode()
1967 } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) { in coda_finish_decode()
1972 val -= ctx->sequence_offset; in coda_finish_decode()
1973 spin_lock_irqsave(&ctx->buffer_meta_lock, flags); in coda_finish_decode()
1974 if (!list_empty(&ctx->buffer_meta_list)) { in coda_finish_decode()
1975 meta = list_first_entry(&ctx->buffer_meta_list, in coda_finish_decode()
1978 ctx->num_metas--; in coda_finish_decode()
1979 spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); in coda_finish_decode()
1990 val, ctx->sequence_offset, in coda_finish_decode()
1993 ctx->frame_metas[decoded_idx] = *meta; in coda_finish_decode()
1996 spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); in coda_finish_decode()
1998 memset(&ctx->frame_metas[decoded_idx], 0, in coda_finish_decode()
2000 ctx->frame_metas[decoded_idx].sequence = val; in coda_finish_decode()
2001 ctx->sequence_offset++; in coda_finish_decode()
2004 trace_coda_dec_pic_done(ctx, &ctx->frame_metas[decoded_idx]); in coda_finish_decode()
2008 ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_KEYFRAME; in coda_finish_decode()
2010 ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_PFRAME; in coda_finish_decode()
2012 ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_BFRAME; in coda_finish_decode()
2014 ctx->frame_errors[decoded_idx] = err_mb; in coda_finish_decode()
2022 ctx->hold = true; in coda_finish_decode()
2025 } else if (display_idx < 0 || display_idx >= ctx->num_internal_frames) { in coda_finish_decode()
2032 if (ctx->display_idx >= 0 && in coda_finish_decode()
2033 ctx->display_idx < ctx->num_internal_frames) { in coda_finish_decode()
2034 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda_finish_decode()
2035 dst_buf->sequence = ctx->osequence++; in coda_finish_decode()
2040 dst_buf->flags |= ctx->frame_types[ctx->display_idx]; in coda_finish_decode()
2041 meta = &ctx->frame_metas[ctx->display_idx]; in coda_finish_decode()
2045 trace_coda_dec_rot_done(ctx, dst_buf, meta); in coda_finish_decode()
2060 coda_m2m_buf_done(ctx, dst_buf, ctx->frame_errors[display_idx] ? in coda_finish_decode()
2074 ctx->display_idx = display_idx; in coda_finish_decode()
2090 struct coda_ctx *ctx; in coda_irq_handler() local
2097 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); in coda_irq_handler()
2098 if (ctx == NULL) { in coda_irq_handler()
2105 trace_coda_bit_done(ctx); in coda_irq_handler()
2107 if (ctx->aborting) { in coda_irq_handler()
2108 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, in coda_irq_handler()
2112 if (coda_isbusy(ctx->dev)) { in coda_irq_handler()
2113 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, in coda_irq_handler()
2118 complete(&ctx->completion); in coda_irq_handler()