drivers/media/platform/amphion/vpu_v4l2.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/amphion/vpu_v4l2.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/amphion/vpu_v4l2.c
Extension
.c
Size
21886 bytes
Lines
882
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (fmt->flags & V4L2_FMT_FLAG_COMPRESSED) {
			fmt->sizeimage[i] = clamp_val(fmt->sizeimage[i], SZ_128K, SZ_8M);
			fmt->bytesperline[i] = 0;
		}
	}

	return 0;
}

u32 vpu_get_fmt_plane_size(struct vpu_format *fmt, u32 plane_no)
{
	u32 size;
	int i;

	if (plane_no >= fmt->mem_planes)
		return 0;

	if (fmt->comp_planes == fmt->mem_planes)
		return fmt->sizeimage[plane_no];
	if (plane_no < fmt->mem_planes - 1)
		return fmt->sizeimage[plane_no];

	size = fmt->sizeimage[plane_no];
	for (i = fmt->mem_planes; i < fmt->comp_planes; i++)
		size += fmt->sizeimage[i];

	return size;
}

int vpu_try_fmt_common(struct vpu_inst *inst, struct v4l2_format *f, struct vpu_format *fmt)
{
	struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
	int i;
	int ret;

	fmt->pixfmt = pixmp->pixelformat;
	fmt->type = f->type;
	ret = vpu_init_format(inst, fmt);
	if (ret < 0)
		return ret;

	fmt->width = pixmp->width;
	fmt->height = pixmp->height;
	if (fmt->width)
		fmt->width = vpu_helper_valid_frame_width(inst, fmt->width);
	if (fmt->height)
		fmt->height = vpu_helper_valid_frame_height(inst, fmt->height);
	fmt->field = pixmp->field == V4L2_FIELD_ANY ? V4L2_FIELD_NONE : pixmp->field;
	vpu_calc_fmt_bytesperline(f, fmt);
	vpu_calc_fmt_sizeimage(inst, fmt);
	if ((fmt->flags & V4L2_FMT_FLAG_COMPRESSED) && pixmp->plane_fmt[0].sizeimage)
		fmt->sizeimage[0] = clamp_val(pixmp->plane_fmt[0].sizeimage, SZ_128K, SZ_8M);

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

	return 0;
}

static bool vpu_check_ready(struct vpu_inst *inst, u32 type)
{
	if (!inst)
		return false;
	if (inst->state == VPU_CODEC_STATE_DEINIT || inst->id < 0)
		return false;
	if (!inst->ops->check_ready)
		return true;
	return call_vop(inst, check_ready, type);
}

int vpu_process_output_buffer(struct vpu_inst *inst)
{
	struct v4l2_m2m_buffer *buf = NULL;
	struct vb2_v4l2_buffer *vbuf = NULL;

	if (!inst || !inst->fh.m2m_ctx)
		return -EINVAL;

	if (!vpu_check_ready(inst, inst->out_format.type))
		return -EINVAL;

Annotation

Implementation Notes