Commit 0db2fc4e authored by Yunfei Dong's avatar Yunfei Dong Committed by Mauro Carvalho Chehab
Browse files

media: mediatek: vcodec: remove the dependency of vcodec debug log



'mtk_vcodec_debug' and 'mtk_vcodec_err' depends on 'mtk_vcodec_ctx'
to get the index of each instance. Define two different macro
mtk_vdec_debug and mtk_venc_debug for decoder and encoder, and re-write
macro mtk_vcodec_debug as the common interface which is called
by mtk_vdec_debug and mtk_venc_debug. The vcodec debug log can be
separeated by encoder and decoder.

Signed-off-by: default avatarYunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: default avatarNicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent 17834e0a
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -31,9 +31,8 @@ struct mtk_vcodec_dev;
#define mtk_v4l2_err(fmt, args...)                \
	pr_err("[MTK_V4L2][ERROR] " fmt "\n", ##args)

#define mtk_vcodec_err(h, fmt, args...)				\
	pr_err("[MTK_VCODEC][ERROR][%d]: " fmt "\n",		\
	       ((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args)
#define mtk_vcodec_err(inst_id, plat_dev, fmt, args...)                                 \
	dev_err(&(plat_dev)->dev, "[MTK_VCODEC][ERROR][%d]: " fmt "\n", inst_id, ##args)

#if defined(CONFIG_DEBUG_FS)
extern int mtk_v4l2_dbg_level;
@@ -46,22 +45,31 @@ extern int mtk_vcodec_dbg;
				 __func__, __LINE__, ##args);	        \
	} while (0)

#define mtk_vcodec_debug(h, fmt, args...)				                      \
#define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...)                               \
	do {                                                                            \
		if (mtk_vcodec_dbg)                                                     \
			dev_dbg(&(((struct mtk_vcodec_ctx *)(h)->ctx)->dev->plat_dev->dev),   \
				"[MTK_VCODEC][%d]: %s, %d " fmt "\n",                         \
				((struct mtk_vcodec_ctx *)(h)->ctx)->id,                      \
				__func__, __LINE__, ##args);                                  \
			dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: %s, %d " fmt "\n", \
				inst_id, __func__, __LINE__, ##args);                   \
	} while (0)
#else
#define mtk_v4l2_debug(level, fmt, args...) pr_debug(fmt, ##args)

#define mtk_vcodec_debug(h, fmt, args...)			\
	pr_debug("[MTK_VCODEC][%d]: " fmt "\n",			\
		((struct mtk_vcodec_ctx *)(h)->ctx)->id, ##args)
#define mtk_vcodec_debug(inst_id, plat_dev, fmt, args...)			\
	dev_dbg(&(plat_dev)->dev, "[MTK_VCODEC][%d]: " fmt "\n", inst_id, ##args)
#endif

#define mtk_vdec_err(ctx, fmt, args...)                               \
	mtk_vcodec_err((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)

#define mtk_vdec_debug(ctx, fmt, args...)                             \
	mtk_vcodec_debug((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)

#define mtk_venc_err(ctx, fmt, args...)                               \
	mtk_vcodec_err((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)

#define mtk_venc_debug(ctx, fmt, args...)                              \
	mtk_vcodec_debug((ctx)->id, (ctx)->dev->plat_dev, fmt, ##args)

void __iomem *mtk_vcodec_get_reg_addr(void __iomem **reg_base, unsigned int reg_idx);
int mtk_vcodec_write_vdecsys(struct mtk_vcodec_ctx *ctx, unsigned int reg, unsigned int val);
int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem);
+61 −62
Original line number Diff line number Diff line
@@ -778,12 +778,11 @@ static int vdec_av1_slice_init_cdf_table(struct vdec_av1_slice_instance *instanc
	remote_cdf_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
						     (u32)vsi->cdf_table_addr);
	if (IS_ERR(remote_cdf_table)) {
		mtk_vcodec_err(instance, "failed to map cdf table\n");
		mtk_vdec_err(ctx, "failed to map cdf table\n");
		return PTR_ERR(remote_cdf_table);
	}

	mtk_vcodec_debug(instance, "map cdf table to 0x%p\n",
			 remote_cdf_table);
	mtk_vdec_debug(ctx, "map cdf table to 0x%p\n", remote_cdf_table);

	if (instance->cdf_table.va)
		mtk_vcodec_mem_free(ctx, &instance->cdf_table);
@@ -810,11 +809,11 @@ static int vdec_av1_slice_init_iq_table(struct vdec_av1_slice_instance *instance
	remote_iq_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
						    (u32)vsi->iq_table_addr);
	if (IS_ERR(remote_iq_table)) {
		mtk_vcodec_err(instance, "failed to map iq table\n");
		mtk_vdec_err(ctx, "failed to map iq table\n");
		return PTR_ERR(remote_iq_table);
	}

	mtk_vcodec_debug(instance, "map iq table to 0x%p\n", remote_iq_table);
	mtk_vdec_debug(ctx, "map iq table to 0x%p\n", remote_iq_table);

	if (instance->iq_table.va)
		mtk_vcodec_mem_free(ctx, &instance->iq_table);
@@ -965,7 +964,7 @@ static int vdec_av1_slice_alloc_working_buffer(struct vdec_av1_slice_instance *i
	if (level == instance->level)
		return 0;

	mtk_vcodec_debug(instance, "resolution level changed from %u to %u, %ux%u",
	mtk_vdec_debug(ctx, "resolution level changed from %u to %u, %ux%u",
		       instance->level, level, w, h);

	max_sb_w = DIV_ROUND_UP(max_w, 128);
@@ -1400,7 +1399,7 @@ static int vdec_av1_slice_setup_tile_group(struct vdec_av1_slice_instance *insta

	if (tile_group->num_tiles != tge_size ||
	    tile_group->num_tiles > V4L2_AV1_MAX_TILE_COUNT) {
		mtk_vcodec_err(instance, "invalid tge_size %d, tile_num:%d\n",
		mtk_vdec_err(instance->ctx, "invalid tge_size %d, tile_num:%d\n",
			     tge_size, tile_group->num_tiles);
		return -EINVAL;
	}
@@ -1408,7 +1407,7 @@ static int vdec_av1_slice_setup_tile_group(struct vdec_av1_slice_instance *insta
	for (i = 0; i < tge_size; i++) {
		if (i != ctrl_tge[i].tile_row * vsi->frame.uh.tile.tile_cols +
		    ctrl_tge[i].tile_col) {
			mtk_vcodec_err(instance, "invalid tge info %d, %d %d %d\n",
			mtk_vdec_err(instance->ctx, "invalid tge info %d, %d %d %d\n",
				     i, ctrl_tge[i].tile_row, ctrl_tge[i].tile_col,
				     vsi->frame.uh.tile.tile_rows);
			return -EINVAL;
@@ -1639,7 +1638,7 @@ static void vdec_av1_slice_setup_seg_buffer(struct vdec_av1_slice_instance *inst

	/* reset segment buffer */
	if (uh->primary_ref_frame == AV1_PRIMARY_REF_NONE || !uh->seg.segmentation_enabled) {
		mtk_vcodec_debug(instance, "reset seg %d\n", vsi->slot_id);
		mtk_vdec_debug(instance->ctx, "reset seg %d\n", vsi->slot_id);
		if (vsi->slot_id != AV1_INVALID_IDX) {
			buf = &instance->seg[vsi->slot_id];
			memset(buf->va, 0, buf->size);
@@ -1694,14 +1693,14 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins
		    uh->disable_frame_end_update_cdf == 0)
			tile_info_buf[tile_info_base + 4] |= (1 << 17);

		mtk_vcodec_debug(instance, "// tile buf %d pos(%dx%d) offset 0x%x\n",
		mtk_vdec_debug(instance->ctx, "// tile buf %d pos(%dx%d) offset 0x%x\n",
			       tile_num, tile_row, tile_col, tile_info_base);
		mtk_vcodec_debug(instance, "// %08x %08x %08x %08x\n",
		mtk_vdec_debug(instance->ctx, "// %08x %08x %08x %08x\n",
			       tile_info_buf[tile_info_base + 0],
			       tile_info_buf[tile_info_base + 1],
			       tile_info_buf[tile_info_base + 2],
			       tile_info_buf[tile_info_base + 3]);
		mtk_vcodec_debug(instance, "// %08x %08x %08x %08x\n",
		mtk_vdec_debug(instance->ctx, "// %08x %08x %08x %08x\n",
			       tile_info_buf[tile_info_base + 4],
			       tile_info_buf[tile_info_base + 5],
			       tile_info_buf[tile_info_base + 6],
@@ -1747,7 +1746,7 @@ static int vdec_av1_slice_update_lat(struct vdec_av1_slice_instance *instance,
	struct vdec_av1_slice_vsi *vsi;

	vsi = &pfc->vsi;
	mtk_vcodec_debug(instance, "frame %u LAT CRC 0x%08x, output size is %d\n",
	mtk_vdec_debug(instance->ctx, "frame %u LAT CRC 0x%08x, output size is %d\n",
		       pfc->seq, vsi->state.crc[0], vsi->state.out_size);

	/* buffer full, need to re-decode */
@@ -1859,10 +1858,10 @@ static int vdec_av1_slice_update_core(struct vdec_av1_slice_instance *instance,
{
	struct vdec_av1_slice_vsi *vsi = instance->core_vsi;

	mtk_vcodec_debug(instance, "frame %u Y_CRC %08x %08x %08x %08x\n",
	mtk_vdec_debug(instance->ctx, "frame %u Y_CRC %08x %08x %08x %08x\n",
		       pfc->seq, vsi->state.crc[0], vsi->state.crc[1],
		       vsi->state.crc[2], vsi->state.crc[3]);
	mtk_vcodec_debug(instance, "frame %u C_CRC %08x %08x %08x %08x\n",
	mtk_vdec_debug(instance->ctx, "frame %u C_CRC %08x %08x %08x %08x\n",
		       pfc->seq, vsi->state.crc[8], vsi->state.crc[9],
		       vsi->state.crc[10], vsi->state.crc[11]);

@@ -1887,14 +1886,14 @@ static int vdec_av1_slice_init(struct mtk_vcodec_ctx *ctx)

	ret = vpu_dec_init(&instance->vpu);
	if (ret) {
		mtk_vcodec_err(instance, "failed to init vpu dec, ret %d\n", ret);
		mtk_vdec_err(ctx, "failed to init vpu dec, ret %d\n", ret);
		goto error_vpu_init;
	}

	/* init vsi and global flags */
	vsi = instance->vpu.vsi;
	if (!vsi) {
		mtk_vcodec_err(instance, "failed to get AV1 vsi\n");
		mtk_vdec_err(ctx, "failed to get AV1 vsi\n");
		ret = -EINVAL;
		goto error_vsi;
	}
@@ -1902,19 +1901,19 @@ static int vdec_av1_slice_init(struct mtk_vcodec_ctx *ctx)
	instance->core_vsi = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler, (u32)vsi->core_vsi);

	if (!instance->core_vsi) {
		mtk_vcodec_err(instance, "failed to get AV1 core vsi\n");
		mtk_vdec_err(ctx, "failed to get AV1 core vsi\n");
		ret = -EINVAL;
		goto error_vsi;
	}

	if (vsi->vsi_size != sizeof(struct vdec_av1_slice_vsi))
		mtk_vcodec_err(instance, "remote vsi size 0x%x mismatch! expected: 0x%zx\n",
		mtk_vdec_err(ctx, "remote vsi size 0x%x mismatch! expected: 0x%zx\n",
			     vsi->vsi_size, sizeof(struct vdec_av1_slice_vsi));

	instance->irq_enabled = 1;
	instance->inneracing_mode = IS_VDEC_INNER_RACING(instance->ctx->dev->dec_capability);

	mtk_vcodec_debug(instance, "vsi 0x%p core_vsi 0x%llx 0x%p, inneracing_mode %d\n",
	mtk_vdec_debug(ctx, "vsi 0x%p core_vsi 0x%llx 0x%p, inneracing_mode %d\n",
		       vsi, vsi->core_vsi, instance->core_vsi, instance->inneracing_mode);

	ret = vdec_av1_slice_init_cdf_table(instance);
@@ -1942,7 +1941,7 @@ static void vdec_av1_slice_deinit(void *h_vdec)

	if (!instance)
		return;
	mtk_vcodec_debug(instance, "h_vdec 0x%p\n", h_vdec);
	mtk_vdec_debug(instance->ctx, "h_vdec 0x%p\n", h_vdec);
	vpu_dec_deinit(&instance->vpu);
	vdec_av1_slice_free_working_buffer(instance);
	vdec_msg_queue_deinit(&instance->ctx->msg_queue, instance->ctx);
@@ -1955,7 +1954,7 @@ static int vdec_av1_slice_flush(void *h_vdec, struct mtk_vcodec_mem *bs,
	struct vdec_av1_slice_instance *instance = h_vdec;
	int i;

	mtk_vcodec_debug(instance, "flush ...\n");
	mtk_vdec_debug(instance->ctx, "flush ...\n");

	vdec_msg_queue_wait_lat_buf_full(&instance->ctx->msg_queue);

@@ -1970,7 +1969,7 @@ static void vdec_av1_slice_get_pic_info(struct vdec_av1_slice_instance *instance
	struct mtk_vcodec_ctx *ctx = instance->ctx;
	u32 data[3];

	mtk_vcodec_debug(instance, "w %u h %u\n", ctx->picinfo.pic_w, ctx->picinfo.pic_h);
	mtk_vdec_debug(ctx, "w %u h %u\n", ctx->picinfo.pic_w, ctx->picinfo.pic_h);

	data[0] = ctx->picinfo.pic_w;
	data[1] = ctx->picinfo.pic_h;
@@ -2000,7 +1999,7 @@ static void vdec_av1_slice_get_crop_info(struct vdec_av1_slice_instance *instanc
	cr->width = ctx->picinfo.pic_w;
	cr->height = ctx->picinfo.pic_h;

	mtk_vcodec_debug(instance, "l=%d, t=%d, w=%d, h=%d\n",
	mtk_vdec_debug(ctx, "l=%d, t=%d, w=%d, h=%d\n",
		       cr->left, cr->top, cr->width, cr->height);
}

@@ -2019,7 +2018,7 @@ static int vdec_av1_slice_get_param(void *h_vdec, enum vdec_get_param_type type,
		vdec_av1_slice_get_crop_info(instance, out);
		break;
	default:
		mtk_vcodec_err(instance, "invalid get parameter type=%d\n", type);
		mtk_vdec_err(instance->ctx, "invalid get parameter type=%d\n", type);
		return -EINVAL;
	}

@@ -2043,7 +2042,7 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	/* init msgQ for the first time */
	if (vdec_msg_queue_init(&ctx->msg_queue, ctx,
				vdec_av1_slice_core_decode, sizeof(*pfc))) {
		mtk_vcodec_err(instance, "failed to init AV1 msg queue\n");
		mtk_vdec_err(ctx, "failed to init AV1 msg queue\n");
		return -ENOMEM;
	}

@@ -2053,7 +2052,7 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,

	lat_buf = vdec_msg_queue_dqbuf(&ctx->msg_queue.lat_ctx);
	if (!lat_buf) {
		mtk_vcodec_err(instance, "failed to get AV1 lat buf\n");
		mtk_vdec_err(ctx, "failed to get AV1 lat buf\n");
		return -EAGAIN;
	}
	pfc = (struct vdec_av1_slice_pfc *)lat_buf->private_data;
@@ -2065,14 +2064,14 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,

	ret = vdec_av1_slice_setup_lat(instance, bs, lat_buf, pfc);
	if (ret) {
		mtk_vcodec_err(instance, "failed to setup AV1 lat ret %d\n", ret);
		mtk_vdec_err(ctx, "failed to setup AV1 lat ret %d\n", ret);
		goto err_free_fb_out;
	}

	vdec_av1_slice_vsi_to_remote(vsi, instance->vsi);
	ret = vpu_dec_start(&instance->vpu, NULL, 0);
	if (ret) {
		mtk_vcodec_err(instance, "failed to dec AV1 ret %d\n", ret);
		mtk_vdec_err(ctx, "failed to dec AV1 ret %d\n", ret);
		goto err_free_fb_out;
	}
	if (instance->inneracing_mode)
@@ -2084,7 +2083,7 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
						   MTK_VDEC_LAT0);
		/* update remote vsi if decode timeout */
		if (ret) {
			mtk_vcodec_err(instance, "AV1 Frame %d decode timeout %d\n", pfc->seq, ret);
			mtk_vdec_err(ctx, "AV1 Frame %d decode timeout %d\n", pfc->seq, ret);
			WRITE_ONCE(instance->vsi->state.timeout, 1);
		}
		vpu_dec_end(&instance->vpu);
@@ -2095,7 +2094,7 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,

	/* LAT trans full, re-decode */
	if (ret == -EAGAIN) {
		mtk_vcodec_err(instance, "AV1 Frame %d trans full\n", pfc->seq);
		mtk_vdec_err(ctx, "AV1 Frame %d trans full\n", pfc->seq);
		if (!instance->inneracing_mode)
			vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);
		return 0;
@@ -2103,13 +2102,13 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,

	/* LAT trans full, no more UBE or decode timeout */
	if (ret == -ENOMEM || vsi->state.timeout) {
		mtk_vcodec_err(instance, "AV1 Frame %d insufficient buffer or timeout\n", pfc->seq);
		mtk_vdec_err(ctx, "AV1 Frame %d insufficient buffer or timeout\n", pfc->seq);
		if (!instance->inneracing_mode)
			vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);
		return -EBUSY;
	}
	vsi->trans.dma_addr_end += ctx->msg_queue.wdma_addr.dma_addr;
	mtk_vcodec_debug(instance, "lat dma 1 0x%pad 0x%pad\n",
	mtk_vdec_debug(ctx, "lat dma 1 0x%pad 0x%pad\n",
		       &pfc->vsi.trans.dma_addr, &pfc->vsi.trans.dma_addr_end);

	vdec_msg_queue_update_ube_wptr(&ctx->msg_queue, vsi->trans.dma_addr_end);
@@ -2124,7 +2123,7 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);

	if (pfc)
		mtk_vcodec_err(instance, "slice dec number: %d err: %d", pfc->seq, ret);
		mtk_vdec_err(ctx, "slice dec number: %d err: %d", pfc->seq, ret);

	return ret;
}
@@ -2157,13 +2156,13 @@ static int vdec_av1_slice_core_decode(struct vdec_lat_buf *lat_buf)

	ret = vdec_av1_slice_setup_core(instance, fb, lat_buf, pfc);
	if (ret) {
		mtk_vcodec_err(instance, "vdec_av1_slice_setup_core\n");
		mtk_vdec_err(ctx, "vdec_av1_slice_setup_core\n");
		goto err;
	}
	vdec_av1_slice_vsi_to_remote(&pfc->vsi, instance->core_vsi);
	ret = vpu_dec_core(&instance->vpu);
	if (ret) {
		mtk_vcodec_err(instance, "vpu_dec_core\n");
		mtk_vdec_err(ctx, "vpu_dec_core\n");
		goto err;
	}

@@ -2173,7 +2172,7 @@ static int vdec_av1_slice_core_decode(struct vdec_lat_buf *lat_buf)
						   MTK_VDEC_CORE);
		/* update remote vsi if decode timeout */
		if (ret) {
			mtk_vcodec_err(instance, "AV1 frame %d core timeout\n", pfc->seq);
			mtk_vdec_err(ctx, "AV1 frame %d core timeout\n", pfc->seq);
			WRITE_ONCE(instance->vsi->state.timeout, 1);
		}
		vpu_dec_core_end(&instance->vpu);
@@ -2181,11 +2180,11 @@ static int vdec_av1_slice_core_decode(struct vdec_lat_buf *lat_buf)

	ret = vdec_av1_slice_update_core(instance, lat_buf, pfc);
	if (ret) {
		mtk_vcodec_err(instance, "vdec_av1_slice_update_core\n");
		mtk_vdec_err(ctx, "vdec_av1_slice_update_core\n");
		goto err;
	}

	mtk_vcodec_debug(instance, "core dma_addr_end 0x%pad\n",
	mtk_vdec_debug(ctx, "core dma_addr_end 0x%pad\n",
		       &instance->core_vsi->trans.dma_addr_end);
	vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, instance->core_vsi->trans.dma_addr_end);

+31 −35
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ static int allocate_predication_buf(struct vdec_h264_inst *inst)
	inst->pred_buf.size = BUF_PREDICTION_SZ;
	err = mtk_vcodec_mem_alloc(inst->ctx, &inst->pred_buf);
	if (err) {
		mtk_vcodec_err(inst, "failed to allocate ppl buf");
		mtk_vdec_err(inst->ctx, "failed to allocate ppl buf");
		return err;
	}

@@ -176,7 +176,7 @@ static int alloc_mv_buf(struct vdec_h264_inst *inst, struct vdec_pic_info *pic)
		mem->size = buf_sz;
		err = mtk_vcodec_mem_alloc(inst->ctx, mem);
		if (err) {
			mtk_vcodec_err(inst, "failed to allocate mv buf");
			mtk_vdec_err(inst->ctx, "failed to allocate mv buf");
			return err;
		}
		inst->vsi->mv_buf_dma[i] = mem->dma_addr;
@@ -207,7 +207,7 @@ static int check_list_validity(struct vdec_h264_inst *inst, bool disp_list)
	if (list->count > H264_MAX_FB_NUM ||
	    list->read_idx >= H264_MAX_FB_NUM ||
	    list->write_idx >= H264_MAX_FB_NUM) {
		mtk_vcodec_err(inst, "%s list err: cnt=%d r_idx=%d w_idx=%d",
		mtk_vdec_err(inst->ctx, "%s list err: cnt=%d r_idx=%d w_idx=%d",
			     disp_list ? "disp" : "free", list->count,
			     list->read_idx, list->write_idx);
		return -EINVAL;
@@ -226,11 +226,11 @@ static void put_fb_to_free(struct vdec_h264_inst *inst, struct vdec_fb *fb)

		list = &inst->vsi->list_free;
		if (list->count == H264_MAX_FB_NUM) {
			mtk_vcodec_err(inst, "[FB] put fb free_list full");
			mtk_vdec_err(inst->ctx, "[FB] put fb free_list full");
			return;
		}

		mtk_vcodec_debug(inst, "[FB] put fb into free_list @(%p, %llx)",
		mtk_vdec_debug(inst->ctx, "[FB] put fb into free_list @(%p, %llx)",
			       fb->base_y.va, (u64)fb->base_y.dma_addr);

		list->fb_list[list->write_idx].vdec_fb_va = (u64)(uintptr_t)fb;
@@ -244,10 +244,9 @@ static void get_pic_info(struct vdec_h264_inst *inst,
			 struct vdec_pic_info *pic)
{
	*pic = inst->vsi->pic;
	mtk_vcodec_debug(inst, "pic(%d, %d), buf(%d, %d)",
	mtk_vdec_debug(inst->ctx, "pic(%d, %d), buf(%d, %d)",
		       pic->pic_w, pic->pic_h, pic->buf_w, pic->buf_h);
	mtk_vcodec_debug(inst, "fb size: Y(%d), C(%d)",
			 pic->fb_sz[0], pic->fb_sz[1]);
	mtk_vdec_debug(inst->ctx, "fb size: Y(%d), C(%d)", pic->fb_sz[0], pic->fb_sz[1]);
}

static void get_crop_info(struct vdec_h264_inst *inst, struct v4l2_rect *cr)
@@ -257,14 +256,14 @@ static void get_crop_info(struct vdec_h264_inst *inst, struct v4l2_rect *cr)
	cr->width = inst->vsi->crop.width;
	cr->height = inst->vsi->crop.height;

	mtk_vcodec_debug(inst, "l=%d, t=%d, w=%d, h=%d",
			 cr->left, cr->top, cr->width, cr->height);
	mtk_vdec_debug(inst->ctx, "l=%d, t=%d, w=%d, h=%d", cr->left, cr->top,
		       cr->width, cr->height);
}

static void get_dpb_size(struct vdec_h264_inst *inst, unsigned int *dpb_sz)
{
	*dpb_sz = inst->vsi->dec.dpb_sz;
	mtk_vcodec_debug(inst, "sz=%d", *dpb_sz);
	mtk_vdec_debug(inst->ctx, "sz=%d", *dpb_sz);
}

static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
@@ -283,7 +282,7 @@ static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)

	err = vpu_dec_init(&inst->vpu);
	if (err) {
		mtk_vcodec_err(inst, "vdec_h264 init err=%d", err);
		mtk_vdec_err(ctx, "vdec_h264 init err=%d", err);
		goto error_free_inst;
	}

@@ -292,7 +291,7 @@ static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
	if (err)
		goto error_deinit;

	mtk_vcodec_debug(inst, "H264 Instance >> %p", inst);
	mtk_vdec_debug(ctx, "H264 Instance >> %p", inst);

	ctx->drv_handle = inst;
	return 0;
@@ -344,7 +343,7 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	uint64_t y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
	uint64_t c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;

	mtk_vcodec_debug(inst, "+ [%d] FB y_dma=%llx c_dma=%llx va=%p",
	mtk_vdec_debug(inst->ctx, "+ [%d] FB y_dma=%llx c_dma=%llx va=%p",
		       ++inst->num_nalu, y_fb_dma, c_fb_dma, fb);

	/* bs NULL means flush decoder */
@@ -355,14 +354,14 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	buf_sz = bs->size;
	nal_start_idx = find_start_code(buf, buf_sz);
	if (nal_start_idx < 0) {
		mtk_vcodec_err(inst, "invalid nal start code");
		mtk_vdec_err(inst->ctx, "invalid nal start code");
		err = -EIO;
		goto err_free_fb_out;
	}

	nal_start = buf[nal_start_idx];
	nal_type = NAL_TYPE(buf[nal_start_idx]);
	mtk_vcodec_debug(inst, "\n + NALU[%d] type %d +\n", inst->num_nalu,
	mtk_vdec_debug(inst->ctx, "\n + NALU[%d] type %d +\n", inst->num_nalu,
		       nal_type);

	if (nal_type == NAL_H264_PPS) {
@@ -384,8 +383,7 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	err = vpu_dec_start(vpu, data, 2);
	if (err) {
		if (err > 0 && (DEC_ERR_RET(err) == H264_ERR_NOT_VALID)) {
			mtk_vcodec_err(inst, "- error bitstream - err = %d -",
				       err);
			mtk_vdec_err(inst->ctx, "- error bitstream - err = %d -", err);
			err = -EIO;
		}
		goto err_free_fb_out;
@@ -395,7 +393,7 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	if (*res_chg) {
		struct vdec_pic_info pic;

		mtk_vcodec_debug(inst, "- resolution changed -");
		mtk_vdec_debug(inst->ctx, "- resolution changed -");
		get_pic_info(inst, &pic);

		if (inst->vsi->dec.realloc_mv_buf) {
@@ -416,13 +414,12 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
		vpu_dec_end(vpu);
	}

	mtk_vcodec_debug(inst, "\n - NALU[%d] type=%d -\n", inst->num_nalu,
			 nal_type);
	mtk_vdec_debug(inst->ctx, "\n - NALU[%d] type=%d -\n", inst->num_nalu, nal_type);
	return 0;

err_free_fb_out:
	put_fb_to_free(inst, fb);
	mtk_vcodec_err(inst, "\n - NALU[%d] err=%d -\n", inst->num_nalu, err);
	mtk_vdec_err(inst->ctx, "\n - NALU[%d] err=%d -\n", inst->num_nalu, err);
	return err;
}

@@ -436,8 +433,7 @@ static void vdec_h264_get_fb(struct vdec_h264_inst *inst,
		return;

	if (list->count == 0) {
		mtk_vcodec_debug(inst, "[FB] there is no %s fb",
				 disp_list ? "disp" : "free");
		mtk_vdec_debug(inst->ctx, "[FB] there is no %s fb", disp_list ? "disp" : "free");
		*out_fb = NULL;
		return;
	}
@@ -447,7 +443,7 @@ static void vdec_h264_get_fb(struct vdec_h264_inst *inst,
	fb->status |= (disp_list ? FB_ST_DISPLAY : FB_ST_FREE);

	*out_fb = fb;
	mtk_vcodec_debug(inst, "[FB] get %s fb st=%d poc=%d %llx",
	mtk_vdec_debug(inst->ctx, "[FB] get %s fb st=%d poc=%d %llx",
		       disp_list ? "disp" : "free",
		       fb->status, list->fb_list[list->read_idx].poc,
		       list->fb_list[list->read_idx].vdec_fb_va);
@@ -484,7 +480,7 @@ static int vdec_h264_get_param(void *h_vdec, enum vdec_get_param_type type,
		break;

	default:
		mtk_vcodec_err(inst, "invalid get parameter type=%d", type);
		mtk_vdec_err(inst->ctx, "invalid get parameter type=%d", type);
		return -EINVAL;
	}

+23 −23
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ static int allocate_predication_buf(struct vdec_h264_slice_inst *inst)
	inst->pred_buf.size = BUF_PREDICTION_SZ;
	err = mtk_vcodec_mem_alloc(inst->ctx, &inst->pred_buf);
	if (err) {
		mtk_vcodec_err(inst, "failed to allocate ppl buf");
		mtk_vdec_err(inst->ctx, "failed to allocate ppl buf");
		return err;
	}

@@ -195,7 +195,7 @@ static int alloc_mv_buf(struct vdec_h264_slice_inst *inst,
		mem->size = buf_sz;
		err = mtk_vcodec_mem_alloc(inst->ctx, mem);
		if (err) {
			mtk_vcodec_err(inst, "failed to allocate mv buf");
			mtk_vdec_err(inst->ctx, "failed to allocate mv buf");
			return err;
		}
		inst->vsi_ctx.mv_buf_dma[i] = mem->dma_addr;
@@ -230,10 +230,10 @@ static void get_pic_info(struct vdec_h264_slice_inst *inst,
		ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes;

	*pic = ctx->picinfo;
	mtk_vcodec_debug(inst, "pic(%d, %d), buf(%d, %d)",
	mtk_vdec_debug(inst->ctx, "pic(%d, %d), buf(%d, %d)",
		       ctx->picinfo.pic_w, ctx->picinfo.pic_h,
		       ctx->picinfo.buf_w, ctx->picinfo.buf_h);
	mtk_vcodec_debug(inst, "Y/C(%d, %d)", ctx->picinfo.fb_sz[0],
	mtk_vdec_debug(inst->ctx, "Y/C(%d, %d)", ctx->picinfo.fb_sz[0],
		       ctx->picinfo.fb_sz[1]);

	if (ctx->last_decoded_picinfo.pic_w != ctx->picinfo.pic_w ||
@@ -259,14 +259,14 @@ static void get_crop_info(struct vdec_h264_slice_inst *inst, struct v4l2_rect *c
	cr->width = inst->vsi_ctx.crop.width;
	cr->height = inst->vsi_ctx.crop.height;

	mtk_vcodec_debug(inst, "l=%d, t=%d, w=%d, h=%d",
	mtk_vdec_debug(inst->ctx, "l=%d, t=%d, w=%d, h=%d",
		       cr->left, cr->top, cr->width, cr->height);
}

static void get_dpb_size(struct vdec_h264_slice_inst *inst, unsigned int *dpb_sz)
{
	*dpb_sz = inst->vsi_ctx.dec.dpb_sz;
	mtk_vcodec_debug(inst, "sz=%d", *dpb_sz);
	mtk_vdec_debug(inst->ctx, "sz=%d", *dpb_sz);
}

static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx)
@@ -285,7 +285,7 @@ static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx)

	err = vpu_dec_init(&inst->vpu);
	if (err) {
		mtk_vcodec_err(inst, "vdec_h264 init err=%d", err);
		mtk_vdec_err(ctx, "vdec_h264 init err=%d", err);
		goto error_free_inst;
	}

@@ -297,13 +297,13 @@ static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx)
	if (err)
		goto error_deinit;

	mtk_vcodec_debug(inst, "struct size = %zu,%zu,%zu,%zu\n",
	mtk_vdec_debug(ctx, "struct size = %zu,%zu,%zu,%zu\n",
		       sizeof(struct mtk_h264_sps_param),
		       sizeof(struct mtk_h264_pps_param),
		       sizeof(struct mtk_h264_dec_slice_param),
		       sizeof(struct mtk_h264_dpb_info));

	mtk_vcodec_debug(inst, "H264 Instance >> %p", inst);
	mtk_vdec_debug(ctx, "H264 Instance >> %p", inst);

	ctx->drv_handle = inst;
	return 0;
@@ -354,7 +354,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
	c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;

	mtk_vcodec_debug(inst, "+ [%d] FB y_dma=%llx c_dma=%llx va=%p",
	mtk_vdec_debug(inst->ctx, "+ [%d] FB y_dma=%llx c_dma=%llx va=%p",
		       inst->num_nalu, y_fb_dma, c_fb_dma, fb);

	inst->vsi_ctx.dec.bs_dma = (uint64_t)bs->dma_addr;
@@ -380,7 +380,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,

	*res_chg = inst->vsi_ctx.dec.resolution_changed;
	if (*res_chg) {
		mtk_vcodec_debug(inst, "- resolution changed -");
		mtk_vdec_debug(inst->ctx, "- resolution changed -");
		if (inst->vsi_ctx.dec.realloc_mv_buf) {
			err = alloc_mv_buf(inst, &inst->ctx->picinfo);
			inst->vsi_ctx.dec.realloc_mv_buf = false;
@@ -404,11 +404,11 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
	vpu_dec_end(vpu);

	memcpy(&inst->vsi_ctx, inst->vpu.vsi, sizeof(inst->vsi_ctx));
	mtk_vcodec_debug(inst, "\n - NALU[%d]", inst->num_nalu);
	mtk_vdec_debug(inst->ctx, "\n - NALU[%d]", inst->num_nalu);
	return 0;

err_free_fb_out:
	mtk_vcodec_err(inst, "\n - NALU[%d] err=%d -\n", inst->num_nalu, err);
	mtk_vdec_err(inst->ctx, "\n - NALU[%d] err=%d -\n", inst->num_nalu, err);
	return err;
}

@@ -430,7 +430,7 @@ static int vdec_h264_slice_get_param(void *h_vdec, enum vdec_get_param_type type
		break;

	default:
		mtk_vcodec_err(inst, "invalid get parameter type=%d", type);
		mtk_vdec_err(inst->ctx, "invalid get parameter type=%d", type);
		return -EINVAL;
	}

+60 −64

File changed.

Preview size limit exceeded, changes collapsed.

Loading