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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/interconnect.hlinux/ioctl.hlinux/list.hlinux/kernel.hlinux/module.hlinux/pm_runtime.hlinux/videodev2.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-mem2mem.hmedia/v4l2-ioctl.hmedia/videobuf2-v4l2.hmedia/videobuf2-dma-contig.hmedia/videobuf2-vmalloc.hvpu.hvpu_core.hvpu_v4l2.hvpu_msgs.hvpu_helpers.h
Detected Declarations
function vpu_inst_lockfunction vpu_inst_unlockfunction vpu_get_vb_phy_addrfunction vpu_get_vb_lengthfunction vpu_set_buffer_statefunction vpu_get_buffer_statefunction vpu_set_buffer_average_qpfunction vpu_v4l2_set_errorfunction vpu_notify_eosfunction vpu_notify_source_changefunction vpu_set_last_buffer_dequeuedfunction vpu_is_source_emptyfunction vpu_init_formatfunction vpu_calc_fmt_bytesperlinefunction vpu_calc_fmt_sizeimagefunction vpu_get_fmt_plane_sizefunction vpu_try_fmt_commonfunction vpu_check_readyfunction vpu_process_output_bufferfunction v4l2_m2m_for_each_src_buffunction vpu_process_capture_bufferfunction v4l2_m2m_for_each_dst_buffunction vpu_skip_framefunction v4l2_m2m_for_each_dst_buffunction v4l2_m2m_for_each_dst_buffunction vpu_get_num_buffersfunction vpu_m2m_device_runfunction vpu_vb2_queue_setupfunction vpu_vb2_buf_initfunction vpu_vb2_buf_out_validatefunction vpu_vb2_buf_preparefunction vpu_vb2_buf_finishfunction vpu_vb2_buffers_returnfunction vpu_vb2_start_streamingfunction vpu_vb2_stop_streamingfunction vpu_vb2_buf_queuefunction vpu_m2m_queue_initfunction vpu_v4l2_releasefunction vpu_v4l2_openfunction vpu_v4l2_closefunction vpu_add_funcfunction vpu_remove_func
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
- Immediate include surface: `linux/init.h`, `linux/interconnect.h`, `linux/ioctl.h`, `linux/list.h`, `linux/kernel.h`, `linux/module.h`, `linux/pm_runtime.h`, `linux/videodev2.h`.
- Detected declarations: `function vpu_inst_lock`, `function vpu_inst_unlock`, `function vpu_get_vb_phy_addr`, `function vpu_get_vb_length`, `function vpu_set_buffer_state`, `function vpu_get_buffer_state`, `function vpu_set_buffer_average_qp`, `function vpu_v4l2_set_error`, `function vpu_notify_eos`, `function vpu_notify_source_change`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.