drivers/media/platform/verisilicon/hantro_drv.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/verisilicon/hantro_drv.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/verisilicon/hantro_drv.c- Extension
.c- Size
- 34579 bytes
- Lines
- 1329
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/clk.hlinux/module.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/pm.hlinux/pm_runtime.hlinux/slab.hlinux/videodev2.hlinux/workqueue.hmedia/v4l2-event.hmedia/v4l2-mem2mem.hmedia/videobuf2-core.hmedia/videobuf2-vmalloc.hhantro_v4l2.hhantro.hhantro_hw.h
Detected Declarations
function hantro_get_reffunction hantro_job_finish_no_pmfunction hantro_job_finishfunction hantro_irq_donefunction hantro_watchdogfunction hantro_start_prepare_runfunction hantro_end_prepare_runfunction device_runfunction queue_initfunction hantro_try_ctrlfunction hantro_jpeg_s_ctrlfunction hantro_vp9_s_ctrlfunction hantro_hevc_s_ctrlfunction hantro_av1_s_ctrlfunction hantro_ctrls_setupfunction hantro_openfunction hantro_releasefunction hantro_register_entityfunction hantro_attach_funcfunction hantro_detach_funcfunction hantro_add_funcfunction hantro_add_enc_funcfunction hantro_add_dec_funcfunction hantro_remove_funcfunction hantro_remove_enc_funcfunction hantro_remove_dec_funcfunction properlyfunction for_each_matching_nodefunction hantro_probefunction hantro_removefunction hantro_runtime_resume
Annotated Snippet
if (ctx->ctrl_handler.error) {
vpu_err("Adding control (%d) failed %d\n",
controls[i].cfg.id,
ctx->ctrl_handler.error);
v4l2_ctrl_handler_free(&ctx->ctrl_handler);
return ctx->ctrl_handler.error;
}
}
return v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
}
/*
* V4L2 file operations.
*/
static int hantro_open(struct file *filp)
{
struct hantro_dev *vpu = video_drvdata(filp);
struct video_device *vdev = video_devdata(filp);
struct hantro_func *func = hantro_vdev_to_func(vdev);
struct hantro_ctx *ctx;
int allowed_codecs, ret;
/*
* We do not need any extra locking here, because we operate only
* on local data here, except reading few fields from dev, which
* do not change through device's lifetime (which is guaranteed by
* reference on module from open()) and V4L2 internal objects (such
* as vdev and ctx->fh), which have proper locking done in respective
* helper functions used here.
*/
ctx = kzalloc_obj(*ctx);
if (!ctx)
return -ENOMEM;
ctx->dev = vpu;
if (func->id == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
allowed_codecs = vpu->variant->codec & HANTRO_ENCODERS;
ctx->is_encoder = true;
} else if (func->id == MEDIA_ENT_F_PROC_VIDEO_DECODER) {
allowed_codecs = vpu->variant->codec & HANTRO_DECODERS;
ctx->is_encoder = false;
} else {
ret = -ENODEV;
goto err_ctx_free;
}
ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(vpu->m2m_dev, ctx, queue_init);
if (IS_ERR(ctx->fh.m2m_ctx)) {
ret = PTR_ERR(ctx->fh.m2m_ctx);
goto err_ctx_free;
}
v4l2_fh_init(&ctx->fh, vdev);
v4l2_fh_add(&ctx->fh, filp);
hantro_reset_fmts(ctx);
ret = hantro_ctrls_setup(vpu, ctx, allowed_codecs);
if (ret) {
vpu_err("Failed to set up controls\n");
goto err_fh_free;
}
ctx->fh.ctrl_handler = &ctx->ctrl_handler;
return 0;
err_fh_free:
v4l2_fh_del(&ctx->fh, filp);
v4l2_fh_exit(&ctx->fh);
err_ctx_free:
kfree(ctx);
return ret;
}
static int hantro_release(struct file *filp)
{
struct hantro_ctx *ctx = file_to_ctx(filp);
/*
* No need for extra locking because this was the last reference
* to this file.
*/
v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
v4l2_fh_del(&ctx->fh, filp);
v4l2_fh_exit(&ctx->fh);
v4l2_ctrl_handler_free(&ctx->ctrl_handler);
kfree(ctx);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/module.h`, `linux/of.h`, `linux/of_platform.h`, `linux/platform_device.h`, `linux/pm.h`, `linux/pm_runtime.h`, `linux/slab.h`.
- Detected declarations: `function hantro_get_ref`, `function hantro_job_finish_no_pm`, `function hantro_job_finish`, `function hantro_irq_done`, `function hantro_watchdog`, `function hantro_start_prepare_run`, `function hantro_end_prepare_run`, `function device_run`, `function queue_init`, `function hantro_try_ctrl`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.