drivers/media/v4l2-core/v4l2-subdev.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-subdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-subdev.c- Extension
.c- Size
- 71743 bytes
- Lines
- 2764
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/export.hlinux/ioctl.hlinux/leds.hlinux/mm.hlinux/module.hlinux/overflow.hlinux/slab.hlinux/string.hlinux/types.hlinux/version.hlinux/videodev2.hmedia/v4l2-ctrls.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-fh.hmedia/v4l2-ioctl.hv4l2-subdev-priv.h
Detected Declarations
struct v4l2_subdev_stream_configfunction subdev_fh_initfunction subdev_fh_freefunction subdev_openfunction subdev_closefunction subdev_openfunction subdev_closefunction v4l2_subdev_enable_privacy_ledfunction v4l2_subdev_disable_privacy_ledfunction check_whichfunction check_padfunction check_statefunction check_formatfunction call_get_fmtfunction call_set_fmtfunction call_enum_mbus_codefunction call_enum_frame_sizefunction call_enum_frame_intervalfunction check_selectionfunction call_get_selectionfunction call_set_selectionfunction check_frame_intervalfunction call_get_frame_intervalfunction call_set_frame_intervalfunction call_get_frame_descfunction check_edidfunction call_get_edidfunction call_set_edidfunction call_s_dv_timingsfunction call_g_dv_timingsfunction call_query_dv_timingsfunction call_dv_timings_capfunction call_enum_dv_timingsfunction call_get_mbus_configfunction call_s_streamfunction subdev_ioctl_get_statefunction v4l2_subdev_copy_routesfunction subdev_do_ioctlfunction subdev_do_ioctl_lockfunction subdev_ioctlfunction subdev_compat_ioctl32function subdev_ioctlfunction subdev_compat_ioctl32function subdev_pollfunction v4l2_subdev_get_fwnode_pad_1_to_1function v4l2_subdev_link_validate_defaultfunction v4l2_subdev_link_validate_get_formatfunction __v4l2_link_validate_get_streams
Annotated Snippet
struct v4l2_subdev_stream_config {
u32 pad;
u32 stream;
bool enabled;
struct v4l2_mbus_framefmt fmt;
struct v4l2_rect crop;
struct v4l2_rect compose;
struct v4l2_fract interval;
};
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
/*
* The Streams API is an experimental feature. To use the Streams API, set
* 'v4l2_subdev_enable_streams_api' to 1 below.
*/
static bool v4l2_subdev_enable_streams_api;
#endif
/*
* Maximum stream ID is 63 for now, as we use u64 bitmask to represent a set
* of streams.
*
* Note that V4L2_FRAME_DESC_ENTRY_MAX is related: V4L2_FRAME_DESC_ENTRY_MAX
* restricts the total number of streams in a pad, although the stream ID is
* not restricted.
*/
#define V4L2_SUBDEV_MAX_STREAM_ID 63
#include "v4l2-subdev-priv.h"
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)
{
struct v4l2_subdev_state *state;
static struct lock_class_key key;
state = __v4l2_subdev_state_alloc(sd, "fh->state->lock", &key);
if (IS_ERR(state))
return PTR_ERR(state);
fh->state = state;
return 0;
}
static void subdev_fh_free(struct v4l2_subdev_fh *fh)
{
__v4l2_subdev_state_free(fh->state);
fh->state = NULL;
}
static int subdev_open(struct file *file)
{
struct video_device *vdev = video_devdata(file);
struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
struct v4l2_subdev_fh *subdev_fh;
int ret;
subdev_fh = kzalloc_obj(*subdev_fh);
if (subdev_fh == NULL)
return -ENOMEM;
ret = subdev_fh_init(subdev_fh, sd);
if (ret) {
kfree(subdev_fh);
return ret;
}
v4l2_fh_init(&subdev_fh->vfh, vdev);
v4l2_fh_add(&subdev_fh->vfh, file);
if (sd->v4l2_dev->mdev && sd->entity.graph_obj.mdev->dev) {
struct module *owner;
owner = sd->entity.graph_obj.mdev->dev->driver->owner;
if (!try_module_get(owner)) {
ret = -EBUSY;
goto err;
}
subdev_fh->owner = owner;
}
if (sd->internal_ops && sd->internal_ops->open) {
ret = sd->internal_ops->open(sd, subdev_fh);
if (ret < 0)
goto err;
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/ioctl.h`, `linux/leds.h`, `linux/mm.h`, `linux/module.h`, `linux/overflow.h`, `linux/slab.h`, `linux/string.h`.
- Detected declarations: `struct v4l2_subdev_stream_config`, `function subdev_fh_init`, `function subdev_fh_free`, `function subdev_open`, `function subdev_close`, `function subdev_open`, `function subdev_close`, `function v4l2_subdev_enable_privacy_led`, `function v4l2_subdev_disable_privacy_led`, `function check_which`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration 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.