Commit d21ce554 authored by Ming Qian's avatar Ming Qian Committed by Mauro Carvalho Chehab
Browse files

media: amphion: tell and handle contiguous and non contiguous format



Driver should tell the number of memory planes and component planes.
the amphion vpu support non contiguous planes,
but for compatibility with other device
that only support contiguous planes.
driver can add support for contiguous planes in the same time.
Then the mem_planes can be different from the comp_planes.
driver need to handle buffer according mem_planes and comp_planes.

So driver can support NV12 and NV12M.

Signed-off-by: default avatarMing Qian <ming.qian@nxp.com>
Reviewed-by: default avatarTommaso Merciai <tommaso.merciai@amarulasolutions.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 5b8bb216
Loading
Loading
Loading
Loading
+98 −89
Original line number Diff line number Diff line
@@ -69,72 +69,85 @@ struct vdec_t {
static const struct vpu_format vdec_formats[] = {
	{
		.pixfmt = V4L2_PIX_FMT_NV12M_8L128,
		.num_planes = 2,
		.mem_planes = 2,
		.comp_planes = 2,
		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
	},
	{
		.pixfmt = V4L2_PIX_FMT_NV12M_10BE_8L128,
		.num_planes = 2,
		.mem_planes = 2,
		.comp_planes = 2,
		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
	},
	{
		.pixfmt = V4L2_PIX_FMT_H264,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_H264_MVC,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_HEVC,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_VC1_ANNEX_G,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_VC1_ANNEX_L,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_MPEG2,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_MPEG4,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_XVID,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_VP8,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{
		.pixfmt = V4L2_PIX_FMT_H263,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION
		.flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_COMPRESSED
	},
	{0, 0, 0, 0},
};
@@ -256,23 +269,22 @@ static int vdec_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f)
	int ret = -EINVAL;

	vpu_inst_lock(inst);
	if (!V4L2_TYPE_IS_OUTPUT(f->type) && vdec->fixed_fmt) {
		if (f->index == 0) {
			f->pixelformat = inst->cap_format.pixfmt;
			f->flags = inst->cap_format.flags;
			ret = 0;
		}
	if (V4L2_TYPE_IS_CAPTURE(f->type) && vdec->fixed_fmt) {
		fmt = vpu_get_format(inst, f->type);
		if (f->index == 1)
			fmt = vpu_helper_find_sibling(inst, f->type, fmt->pixfmt);
		if (f->index > 1)
			fmt = NULL;
	} else {
		fmt = vpu_helper_enum_format(inst, f->type, f->index);
		memset(f->reserved, 0, sizeof(f->reserved));
	}
	if (!fmt)
		goto exit;

	memset(f->reserved, 0, sizeof(f->reserved));
	f->pixelformat = fmt->pixfmt;
	f->flags = fmt->flags;
	ret = 0;
	}

exit:
	vpu_inst_unlock(inst);
	return ret;
@@ -290,14 +302,14 @@ static int vdec_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
	cur_fmt = vpu_get_format(inst, f->type);

	pixmp->pixelformat = cur_fmt->pixfmt;
	pixmp->num_planes = cur_fmt->num_planes;
	pixmp->num_planes = cur_fmt->mem_planes;
	pixmp->width = cur_fmt->width;
	pixmp->height = cur_fmt->height;
	pixmp->field = cur_fmt->field;
	pixmp->flags = cur_fmt->flags;
	for (i = 0; i < pixmp->num_planes; i++) {
		pixmp->plane_fmt[i].bytesperline = cur_fmt->bytesperline[i];
		pixmp->plane_fmt[i].sizeimage = cur_fmt->sizeimage[i];
		pixmp->plane_fmt[i].sizeimage = vpu_get_fmt_plane_size(cur_fmt, i);
	}

	f->fmt.pix_mp.colorspace = vdec->codec_info.color_primaries;
@@ -313,10 +325,19 @@ static int vdec_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
{
	struct vpu_inst *inst = to_inst(file);
	struct vdec_t *vdec = inst->priv;

	vpu_try_fmt_common(inst, f);
	struct vpu_format fmt;

	vpu_inst_lock(inst);
	if (V4L2_TYPE_IS_CAPTURE(f->type) && vdec->fixed_fmt) {
		struct vpu_format *cap_fmt = vpu_get_format(inst, f->type);

		if (!vpu_helper_match_format(inst, cap_fmt->type, cap_fmt->pixfmt,
					     f->fmt.pix_mp.pixelformat))
			f->fmt.pix_mp.pixelformat = cap_fmt->pixfmt;
	}

	vpu_try_fmt_common(inst, f, &fmt);

	if (vdec->fixed_fmt) {
		f->fmt.pix_mp.colorspace = vdec->codec_info.color_primaries;
		f->fmt.pix_mp.xfer_func = vdec->codec_info.transfer_chars;
@@ -336,7 +357,7 @@ static int vdec_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
static int vdec_s_fmt_common(struct vpu_inst *inst, struct v4l2_format *f)
{
	struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
	const struct vpu_format *fmt;
	struct vpu_format fmt;
	struct vpu_format *cur_fmt;
	struct vb2_queue *q;
	struct vdec_t *vdec = inst->priv;
@@ -351,36 +372,30 @@ static int vdec_s_fmt_common(struct vpu_inst *inst, struct v4l2_format *f)
	if (vb2_is_busy(q))
		return -EBUSY;

	fmt = vpu_try_fmt_common(inst, f);
	if (!fmt)
	if (vpu_try_fmt_common(inst, f, &fmt))
		return -EINVAL;

	cur_fmt = vpu_get_format(inst, f->type);
	if (V4L2_TYPE_IS_OUTPUT(f->type) && inst->state != VPU_CODEC_STATE_DEINIT) {
		if (cur_fmt->pixfmt != fmt->pixfmt) {
		if (cur_fmt->pixfmt != fmt.pixfmt) {
			vdec->reset_codec = true;
			vdec->fixed_fmt = false;
		}
	}
	cur_fmt->pixfmt = fmt->pixfmt;
	if (V4L2_TYPE_IS_OUTPUT(f->type) || !vdec->fixed_fmt) {
		cur_fmt->num_planes = fmt->num_planes;
		cur_fmt->flags = fmt->flags;
		cur_fmt->width = pixmp->width;
		cur_fmt->height = pixmp->height;
		for (i = 0; i < fmt->num_planes; i++) {
			cur_fmt->sizeimage[i] = pixmp->plane_fmt[i].sizeimage;
			cur_fmt->bytesperline[i] = pixmp->plane_fmt[i].bytesperline;
		}
		if (pixmp->field != V4L2_FIELD_ANY)
			cur_fmt->field = pixmp->field;
		memcpy(cur_fmt, &fmt, sizeof(*cur_fmt));
	} else {
		pixmp->num_planes = cur_fmt->num_planes;
		if (vpu_helper_match_format(inst, f->type, cur_fmt->pixfmt, pixmp->pixelformat)) {
			cur_fmt->pixfmt = fmt.pixfmt;
			cur_fmt->mem_planes = fmt.mem_planes;
		}
		pixmp->pixelformat = cur_fmt->pixfmt;
		pixmp->num_planes = cur_fmt->mem_planes;
		pixmp->width = cur_fmt->width;
		pixmp->height = cur_fmt->height;
		for (i = 0; i < pixmp->num_planes; i++) {
			pixmp->plane_fmt[i].bytesperline = cur_fmt->bytesperline[i];
			pixmp->plane_fmt[i].sizeimage = cur_fmt->sizeimage[i];
			pixmp->plane_fmt[i].sizeimage = vpu_get_fmt_plane_size(cur_fmt, i);
		}
		pixmp->field = cur_fmt->field;
	}
@@ -680,9 +695,11 @@ static struct vpu_vb2_buffer *vdec_find_buffer(struct vpu_inst *inst, u32 luma)
static void vdec_buf_done(struct vpu_inst *inst, struct vpu_frame_info *frame)
{
	struct vdec_t *vdec = inst->priv;
	struct vpu_format *cur_fmt;
	struct vpu_vb2_buffer *vpu_buf;
	struct vb2_v4l2_buffer *vbuf;
	u32 sequence;
	int i;

	if (!frame)
		return;
@@ -701,6 +718,7 @@ static void vdec_buf_done(struct vpu_inst *inst, struct vpu_frame_info *frame)
		return;
	}

	cur_fmt = vpu_get_format(inst, inst->cap_format.type);
	vbuf = &vpu_buf->m2m_buf.vb;
	if (vbuf->vb2_buf.index != frame->id)
		dev_err(inst->dev, "[%d] buffer id(%d, %d) dismatch\n",
@@ -709,9 +727,9 @@ static void vdec_buf_done(struct vpu_inst *inst, struct vpu_frame_info *frame)
	if (vpu_get_buffer_state(vbuf) != VPU_BUF_STATE_DECODED)
		dev_err(inst->dev, "[%d] buffer(%d) ready without decoded\n", inst->id, frame->id);
	vpu_set_buffer_state(vbuf, VPU_BUF_STATE_READY);
	vb2_set_plane_payload(&vbuf->vb2_buf, 0, inst->cap_format.sizeimage[0]);
	vb2_set_plane_payload(&vbuf->vb2_buf, 1, inst->cap_format.sizeimage[1]);
	vbuf->field = inst->cap_format.field;
	for (i = 0; i < vbuf->vb2_buf.num_planes; i++)
		vb2_set_plane_payload(&vbuf->vb2_buf, i, vpu_get_fmt_plane_size(cur_fmt, i));
	vbuf->field = cur_fmt->field;
	vbuf->sequence = sequence;
	dev_dbg(inst->dev, "[%d][OUTPUT TS]%32lld\n", inst->id, vbuf->vb2_buf.timestamp);

@@ -749,8 +767,7 @@ static void vdec_stop_done(struct vpu_inst *inst)
static bool vdec_check_source_change(struct vpu_inst *inst)
{
	struct vdec_t *vdec = inst->priv;
	const struct vpu_format *fmt;
	int i;
	const struct vpu_format *sibling;

	if (!inst->fh.m2m_ctx)
		return false;
@@ -758,9 +775,12 @@ static bool vdec_check_source_change(struct vpu_inst *inst)
	if (vdec->reset_codec)
		return false;

	sibling = vpu_helper_find_sibling(inst, inst->cap_format.type, inst->cap_format.pixfmt);
	if (sibling && vdec->codec_info.pixfmt == sibling->pixfmt)
		vdec->codec_info.pixfmt = inst->cap_format.pixfmt;

	if (!vb2_is_streaming(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx)))
		return true;
	fmt = vpu_helper_find_format(inst, inst->cap_format.type, vdec->codec_info.pixfmt);
	if (inst->cap_format.pixfmt != vdec->codec_info.pixfmt)
		return true;
	if (inst->cap_format.width != vdec->codec_info.decoded_width)
@@ -777,14 +797,6 @@ static bool vdec_check_source_change(struct vpu_inst *inst)
		return true;
	if (inst->crop.height != vdec->codec_info.height)
		return true;
	if (fmt && inst->cap_format.num_planes != fmt->num_planes)
		return true;
	for (i = 0; i < inst->cap_format.num_planes; i++) {
		if (inst->cap_format.bytesperline[i] != vdec->codec_info.bytesperline[i])
			return true;
		if (inst->cap_format.sizeimage[i] != vdec->codec_info.sizeimage[i])
			return true;
	}

	return false;
}
@@ -792,27 +804,21 @@ static bool vdec_check_source_change(struct vpu_inst *inst)
static void vdec_init_fmt(struct vpu_inst *inst)
{
	struct vdec_t *vdec = inst->priv;
	const struct vpu_format *fmt;
	int i;
	struct v4l2_format f;

	fmt = vpu_helper_find_format(inst, inst->cap_format.type, vdec->codec_info.pixfmt);
	inst->out_format.width = vdec->codec_info.width;
	inst->out_format.height = vdec->codec_info.height;
	inst->cap_format.width = vdec->codec_info.decoded_width;
	inst->cap_format.height = vdec->codec_info.decoded_height;
	inst->cap_format.pixfmt = vdec->codec_info.pixfmt;
	if (fmt) {
		inst->cap_format.num_planes = fmt->num_planes;
		inst->cap_format.flags = fmt->flags;
	}
	for (i = 0; i < inst->cap_format.num_planes; i++) {
		inst->cap_format.bytesperline[i] = vdec->codec_info.bytesperline[i];
		inst->cap_format.sizeimage[i] = vdec->codec_info.sizeimage[i];
	}
	memset(&f, 0, sizeof(f));
	f.type = inst->cap_format.type;
	f.fmt.pix_mp.pixelformat = vdec->codec_info.pixfmt;
	f.fmt.pix_mp.width = vdec->codec_info.decoded_width;
	f.fmt.pix_mp.height = vdec->codec_info.decoded_height;
	if (vdec->codec_info.progressive)
		inst->cap_format.field = V4L2_FIELD_NONE;
		f.fmt.pix_mp.field = V4L2_FIELD_NONE;
	else
		inst->cap_format.field = V4L2_FIELD_SEQ_TB;
		f.fmt.pix_mp.field = V4L2_FIELD_SEQ_TB;
	vpu_try_fmt_common(inst, &f, &inst->cap_format);

	inst->out_format.width = vdec->codec_info.width;
	inst->out_format.height = vdec->codec_info.height;
}

static void vdec_init_crop(struct vpu_inst *inst)
@@ -971,7 +977,10 @@ static int vdec_response_frame(struct vpu_inst *inst, struct vb2_v4l2_buffer *vb
	info.tag = vdec->seq_tag;
	info.luma_addr = vpu_get_vb_phy_addr(&vbuf->vb2_buf, 0);
	info.luma_size = inst->cap_format.sizeimage[0];
	if (vbuf->vb2_buf.num_planes > 1)
		info.chroma_addr = vpu_get_vb_phy_addr(&vbuf->vb2_buf, 1);
	else
		info.chroma_addr = info.luma_addr + info.luma_size;
	info.chromau_size = inst->cap_format.sizeimage[1];
	info.bytesperline = inst->cap_format.bytesperline[0];
	ret = vpu_session_alloc_fs(inst, &info);
@@ -980,7 +989,7 @@ static int vdec_response_frame(struct vpu_inst *inst, struct vb2_v4l2_buffer *vb

	vpu_buf->tag = info.tag;
	vpu_buf->luma = info.luma_addr;
	vpu_buf->chroma_u = info.chromau_size;
	vpu_buf->chroma_u = info.chroma_addr;
	vpu_buf->chroma_v = 0;
	vpu_set_buffer_state(vbuf, VPU_BUF_STATE_INUSE);
	vdec->slots[info.id] = vpu_buf;
+12 −21
Original line number Diff line number Diff line
@@ -69,13 +69,16 @@ struct venc_frame_t {
static const struct vpu_format venc_formats[] = {
	{
		.pixfmt = V4L2_PIX_FMT_NV12M,
		.num_planes = 2,
		.mem_planes = 2,
		.comp_planes = 2,
		.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
	},
	{
		.pixfmt = V4L2_PIX_FMT_H264,
		.num_planes = 1,
		.mem_planes = 1,
		.comp_planes = 1,
		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
		.flags = V4L2_FMT_FLAG_COMPRESSED
	},
	{0, 0, 0, 0},
};
@@ -173,14 +176,14 @@ static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
	cur_fmt = vpu_get_format(inst, f->type);

	pixmp->pixelformat = cur_fmt->pixfmt;
	pixmp->num_planes = cur_fmt->num_planes;
	pixmp->num_planes = cur_fmt->mem_planes;
	pixmp->width = cur_fmt->width;
	pixmp->height = cur_fmt->height;
	pixmp->field = cur_fmt->field;
	pixmp->flags = cur_fmt->flags;
	for (i = 0; i < pixmp->num_planes; i++) {
		pixmp->plane_fmt[i].bytesperline = cur_fmt->bytesperline[i];
		pixmp->plane_fmt[i].sizeimage = cur_fmt->sizeimage[i];
		pixmp->plane_fmt[i].sizeimage = vpu_get_fmt_plane_size(cur_fmt, i);
	}

	f->fmt.pix_mp.colorspace = venc->params.color.primaries;
@@ -194,8 +197,9 @@ static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
static int venc_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
{
	struct vpu_inst *inst = to_inst(file);
	struct vpu_format fmt;

	vpu_try_fmt_common(inst, f);
	vpu_try_fmt_common(inst, f, &fmt);

	return 0;
}
@@ -203,12 +207,11 @@ static int venc_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
{
	struct vpu_inst *inst = to_inst(file);
	const struct vpu_format *fmt;
	struct vpu_format fmt;
	struct vpu_format *cur_fmt;
	struct vb2_queue *q;
	struct venc_t *venc = inst->priv;
	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
	int i;

	q = v4l2_m2m_get_vq(inst->fh.m2m_ctx, f->type);
	if (!q)
@@ -216,24 +219,12 @@ static int venc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
	if (vb2_is_busy(q))
		return -EBUSY;

	fmt = vpu_try_fmt_common(inst, f);
	if (!fmt)
	if (vpu_try_fmt_common(inst, f, &fmt))
		return -EINVAL;

	cur_fmt = vpu_get_format(inst, f->type);

	cur_fmt->pixfmt = fmt->pixfmt;
	cur_fmt->num_planes = fmt->num_planes;
	cur_fmt->flags = fmt->flags;
	cur_fmt->width = pix_mp->width;
	cur_fmt->height = pix_mp->height;
	for (i = 0; i < fmt->num_planes; i++) {
		cur_fmt->sizeimage[i] = pix_mp->plane_fmt[i].sizeimage;
		cur_fmt->bytesperline[i] = pix_mp->plane_fmt[i].bytesperline;
	}

	if (pix_mp->field != V4L2_FIELD_ANY)
		cur_fmt->field = pix_mp->field;
	memcpy(cur_fmt, &fmt, sizeof(*cur_fmt));

	if (V4L2_TYPE_IS_OUTPUT(f->type)) {
		venc->params.input_format = cur_fmt->pixfmt;
+3 −1
Original line number Diff line number Diff line
@@ -84,7 +84,8 @@ struct vpu_dev {

struct vpu_format {
	u32 pixfmt;
	unsigned int num_planes;
	u32 mem_planes;
	u32 comp_planes;
	u32 type;
	u32 flags;
	u32 width;
@@ -92,6 +93,7 @@ struct vpu_format {
	u32 sizeimage[VIDEO_MAX_PLANES];
	u32 bytesperline[VIDEO_MAX_PLANES];
	u32 field;
	u32 sibling;
};

struct vpu_core_resources {
+4 −4
Original line number Diff line number Diff line
@@ -90,9 +90,9 @@ static int vpu_dbg_instance(struct seq_file *s, void *data)
			vq->last_buffer_dequeued);
	if (seq_write(s, str, num))
		return 0;
	for (i = 0; i < inst->out_format.num_planes; i++) {
	for (i = 0; i < inst->out_format.mem_planes; i++) {
		num = scnprintf(str, sizeof(str), " %d(%d)",
				inst->out_format.sizeimage[i],
				vpu_get_fmt_plane_size(&inst->out_format, i),
				inst->out_format.bytesperline[i]);
		if (seq_write(s, str, num))
			return 0;
@@ -114,9 +114,9 @@ static int vpu_dbg_instance(struct seq_file *s, void *data)
			vq->last_buffer_dequeued);
	if (seq_write(s, str, num))
		return 0;
	for (i = 0; i < inst->cap_format.num_planes; i++) {
	for (i = 0; i < inst->cap_format.mem_planes; i++) {
		num = scnprintf(str, sizeof(str), " %d(%d)",
				inst->cap_format.sizeimage[i],
				vpu_get_fmt_plane_size(&inst->cap_format, i),
				inst->cap_format.bytesperline[i]);
		if (seq_write(s, str, num))
			return 0;
+40 −5
Original line number Diff line number Diff line
@@ -59,6 +59,36 @@ const struct vpu_format *vpu_helper_find_format(struct vpu_inst *inst, u32 type,
	return NULL;
}

const struct vpu_format *vpu_helper_find_sibling(struct vpu_inst *inst, u32 type, u32 pixelfmt)
{
	const struct vpu_format *fmt;
	const struct vpu_format *sibling;

	fmt = vpu_helper_find_format(inst, type, pixelfmt);
	if (!fmt || !fmt->sibling)
		return NULL;

	sibling = vpu_helper_find_format(inst, type, fmt->sibling);
	if (!sibling || sibling->sibling != fmt->pixfmt ||
	    sibling->comp_planes != fmt->comp_planes)
		return NULL;

	return sibling;
}

bool vpu_helper_match_format(struct vpu_inst *inst, u32 type, u32 fmta, u32 fmtb)
{
	const struct vpu_format *sibling;

	if (fmta == fmtb)
		return true;

	sibling = vpu_helper_find_sibling(inst, type, fmta);
	if (sibling && sibling->pixfmt == fmtb)
		return true;
	return false;
}

const struct vpu_format *vpu_helper_enum_format(struct vpu_inst *inst, u32 type, int index)
{
	const struct vpu_format *pfmt;
@@ -123,9 +153,10 @@ static u32 get_nv12_plane_size(u32 width, u32 height, int plane_no,
	u32 bytesperline;
	u32 size = 0;

	bytesperline = ALIGN(width, stride);
	bytesperline = width;
	if (pbl)
		bytesperline = max(bytesperline, *pbl);
	bytesperline = ALIGN(bytesperline, stride);
	height = ALIGN(height, 2);
	if (plane_no == 0)
		size = bytesperline * height;
@@ -148,13 +179,13 @@ static u32 get_tiled_8l128_plane_size(u32 fmt, u32 width, u32 height, int plane_

	if (interlaced)
		hs++;
	if (fmt == V4L2_PIX_FMT_NV12M_10BE_8L128)
	if (fmt == V4L2_PIX_FMT_NV12M_10BE_8L128 || fmt == V4L2_PIX_FMT_NV12_10BE_8L128)
		bitdepth = 10;
	bytesperline = DIV_ROUND_UP(width * bitdepth, BITS_PER_BYTE);
	bytesperline = ALIGN(bytesperline, 1 << ws);
	bytesperline = ALIGN(bytesperline, stride);
	if (pbl)
		bytesperline = max(bytesperline, *pbl);
	bytesperline = ALIGN(bytesperline, 1 << ws);
	bytesperline = ALIGN(bytesperline, stride);
	height = ALIGN(height, 1 << hs);
	if (plane_no == 0)
		size = bytesperline * height;
@@ -172,9 +203,10 @@ static u32 get_default_plane_size(u32 width, u32 height, int plane_no,
	u32 bytesperline;
	u32 size = 0;

	bytesperline = ALIGN(width, stride);
	bytesperline = width;
	if (pbl)
		bytesperline = max(bytesperline, *pbl);
	bytesperline = ALIGN(bytesperline, stride);
	if (plane_no == 0)
		size = bytesperline * height;
	if (pbl)
@@ -187,9 +219,12 @@ u32 vpu_helper_get_plane_size(u32 fmt, u32 w, u32 h, int plane_no,
			      u32 stride, u32 interlaced, u32 *pbl)
{
	switch (fmt) {
	case V4L2_PIX_FMT_NV12:
	case V4L2_PIX_FMT_NV12M:
		return get_nv12_plane_size(w, h, plane_no, stride, interlaced, pbl);
	case V4L2_PIX_FMT_NV12_8L128:
	case V4L2_PIX_FMT_NV12M_8L128:
	case V4L2_PIX_FMT_NV12_10BE_8L128:
	case V4L2_PIX_FMT_NV12M_10BE_8L128:
		return get_tiled_8l128_plane_size(fmt, w, h, plane_no, stride, interlaced, pbl);
	default:
Loading