drivers/media/v4l2-core/v4l2-dev.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-dev.c- Extension
.c- Size
- 38737 bytes
- Lines
- 1264
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/debugfs.hlinux/module.hlinux/types.hlinux/kernel.hlinux/mm.hlinux/string.hlinux/errno.hlinux/init.hlinux/kmod.hlinux/slab.hlinux/uaccess.hmedia/v4l2-common.hmedia/v4l2-device.hmedia/v4l2-ioctl.hmedia/v4l2-event.h
Detected Declarations
function index_showfunction dev_debug_showfunction dev_debug_storefunction name_showfunction devnode_setfunction devnode_clearfunction devnode_findfunction video_device_releasefunction video_device_release_emptyfunction video_getfunction video_putfunction v4l2_device_releasefunction prio_is_validfunction v4l2_prio_initfunction v4l2_prio_changefunction v4l2_prio_openfunction v4l2_prio_closefunction v4l2_prio_maxfunction v4l2_prio_checkfunction v4l2_readfunction v4l2_writefunction v4l2_pollfunction v4l2_ioctlfunction v4l2_get_unmapped_areafunction v4l2_mmapfunction v4l2_openfunction v4l2_releasefunction releasefunction get_indexfunction determine_valid_ioctlsfunction video_register_media_controllerfunction __video_register_devicefunction devicesfunction video_unregister_devicefunction video_device_pipeline_startfunction __video_device_pipeline_startfunction video_device_pipeline_stopfunction __video_device_pipeline_stopfunction video_device_pipeline_alloc_startfunction videodev_initfunction videodev_exitmodule init videodev_initexport video_device_allocexport video_device_releaseexport video_device_release_emptyexport video_devdataexport v4l2_prio_initexport v4l2_prio_change
Annotated Snippet
static const struct file_operations v4l2_fops = {
.owner = THIS_MODULE,
.read = v4l2_read,
.write = v4l2_write,
.open = v4l2_open,
.get_unmapped_area = v4l2_get_unmapped_area,
.mmap = v4l2_mmap,
.unlocked_ioctl = v4l2_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = v4l2_compat_ioctl32,
#endif
.release = v4l2_release,
.poll = v4l2_poll,
};
/**
* get_index - assign stream index number based on v4l2_dev
* @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
*
* Note that when this is called the new device has not yet been registered
* in the video_device array, but it was able to obtain a minor number.
*
* This means that we can always obtain a free stream index number since
* the worst case scenario is that there are VIDEO_NUM_DEVICES - 1 slots in
* use of the video_device array.
*
* Returns a free index number.
*/
static int get_index(struct video_device *vdev)
{
/* This can be static since this function is called with the global
videodev_lock held. */
static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
int i;
bitmap_zero(used, VIDEO_NUM_DEVICES);
for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
if (video_devices[i] != NULL &&
video_devices[i]->v4l2_dev == vdev->v4l2_dev) {
__set_bit(video_devices[i]->index, used);
}
}
return find_first_zero_bit(used, VIDEO_NUM_DEVICES);
}
#define SET_VALID_IOCTL(ops, cmd, op) \
do { if ((ops)->op) __set_bit(_IOC_NR(cmd), valid_ioctls); } while (0)
/* This determines which ioctls are actually implemented in the driver.
It's a one-time thing which simplifies video_ioctl2 as it can just do
a bit test.
Note that drivers can override this by setting bits to 1 in
vdev->valid_ioctls. If an ioctl is marked as 1 when this function is
called, then that ioctl will actually be marked as unimplemented.
It does that by first setting up the local valid_ioctls bitmap, and
at the end do a:
vdev->valid_ioctls = valid_ioctls & ~(vdev->valid_ioctls)
*/
static void determine_valid_ioctls(struct video_device *vdev)
{
const u32 vid_caps = V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_VIDEO_CAPTURE_MPLANE |
V4L2_CAP_VIDEO_OUTPUT |
V4L2_CAP_VIDEO_OUTPUT_MPLANE |
V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE;
const u32 meta_caps = V4L2_CAP_META_CAPTURE |
V4L2_CAP_META_OUTPUT;
DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops;
bool is_vid = vdev->vfl_type == VFL_TYPE_VIDEO &&
(vdev->device_caps & vid_caps);
bool is_vbi = vdev->vfl_type == VFL_TYPE_VBI;
bool is_radio = vdev->vfl_type == VFL_TYPE_RADIO;
bool is_sdr = vdev->vfl_type == VFL_TYPE_SDR;
bool is_tch = vdev->vfl_type == VFL_TYPE_TOUCH;
bool is_meta = vdev->vfl_type == VFL_TYPE_VIDEO &&
(vdev->device_caps & meta_caps);
bool is_rx = vdev->vfl_dir != VFL_DIR_TX;
bool is_tx = vdev->vfl_dir != VFL_DIR_RX;
bool is_io_mc = vdev->device_caps & V4L2_CAP_IO_MC;
bool has_streaming = vdev->device_caps & V4L2_CAP_STREAMING;
bool is_edid = vdev->device_caps & V4L2_CAP_EDID;
bitmap_zero(valid_ioctls, BASE_VIDIOC_PRIVATE);
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/mm.h`, `linux/string.h`, `linux/errno.h`, `linux/init.h`.
- Detected declarations: `function index_show`, `function dev_debug_show`, `function dev_debug_store`, `function name_show`, `function devnode_set`, `function devnode_clear`, `function devnode_find`, `function video_device_release`, `function video_device_release_empty`, `function video_get`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: pattern 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.