drivers/media/v4l2-core/v4l2-event.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-event.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-event.c- Extension
.c- Size
- 8711 bytes
- Lines
- 374
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
media/v4l2-dev.hmedia/v4l2-fh.hmedia/v4l2-event.hlinux/mm.hlinux/sched.hlinux/slab.hlinux/export.h
Detected Declarations
function Copyrightfunction __v4l2_event_dequeuefunction v4l2_event_dequeuefunction __v4l2_event_queue_fhfunction v4l2_event_queuefunction v4l2_event_queue_fhfunction v4l2_event_pendingfunction v4l2_event_wake_allfunction __v4l2_event_unsubscribefunction v4l2_event_subscribefunction v4l2_event_unsubscribe_allfunction v4l2_event_unsubscribefunction v4l2_event_subdev_unsubscribefunction v4l2_event_src_replacefunction v4l2_event_src_mergefunction v4l2_src_change_event_subscribefunction v4l2_src_change_event_subdev_subscribeexport v4l2_event_dequeueexport v4l2_event_queueexport v4l2_event_queue_fhexport v4l2_event_pendingexport v4l2_event_wake_allexport v4l2_event_subscribeexport v4l2_event_unsubscribe_allexport v4l2_event_unsubscribeexport v4l2_event_subdev_unsubscribeexport v4l2_src_change_event_subscribeexport v4l2_src_change_event_subdev_subscribe
Annotated Snippet
if (sev->elems == 1) {
if (sev->ops && sev->ops->replace) {
sev->ops->replace(&kev->event, ev);
copy_payload = false;
}
} else if (sev->ops && sev->ops->merge) {
struct v4l2_kevent *second_oldest =
sev->events + sev_pos(sev, 0);
sev->ops->merge(&kev->event, &second_oldest->event);
}
}
/* Take one and fill it. */
kev = sev->events + sev_pos(sev, sev->in_use);
kev->event.type = ev->type;
if (copy_payload)
kev->event.u = ev->u;
kev->event.id = ev->id;
kev->ts = ts;
kev->event.sequence = fh->sequence;
sev->in_use++;
list_add_tail(&kev->list, &fh->available);
fh->navailable++;
wake_up_all(&fh->wait);
}
void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev)
{
struct v4l2_fh *fh;
unsigned long flags;
u64 ts;
if (vdev == NULL)
return;
ts = ktime_get_ns();
spin_lock_irqsave(&vdev->fh_lock, flags);
list_for_each_entry(fh, &vdev->fh_list, list)
__v4l2_event_queue_fh(fh, ev, ts);
spin_unlock_irqrestore(&vdev->fh_lock, flags);
}
EXPORT_SYMBOL_GPL(v4l2_event_queue);
void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev)
{
unsigned long flags;
u64 ts = ktime_get_ns();
spin_lock_irqsave(&fh->vdev->fh_lock, flags);
__v4l2_event_queue_fh(fh, ev, ts);
spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
}
EXPORT_SYMBOL_GPL(v4l2_event_queue_fh);
int v4l2_event_pending(struct v4l2_fh *fh)
{
return fh->navailable;
}
EXPORT_SYMBOL_GPL(v4l2_event_pending);
void v4l2_event_wake_all(struct video_device *vdev)
{
struct v4l2_fh *fh;
unsigned long flags;
if (!vdev)
return;
spin_lock_irqsave(&vdev->fh_lock, flags);
list_for_each_entry(fh, &vdev->fh_list, list)
wake_up_all(&fh->wait);
spin_unlock_irqrestore(&vdev->fh_lock, flags);
}
EXPORT_SYMBOL_GPL(v4l2_event_wake_all);
static void __v4l2_event_unsubscribe(struct v4l2_subscribed_event *sev)
{
struct v4l2_fh *fh = sev->fh;
unsigned int i;
lockdep_assert_held(&fh->subscribe_lock);
assert_spin_locked(&fh->vdev->fh_lock);
Annotation
- Immediate include surface: `media/v4l2-dev.h`, `media/v4l2-fh.h`, `media/v4l2-event.h`, `linux/mm.h`, `linux/sched.h`, `linux/slab.h`, `linux/export.h`.
- Detected declarations: `function Copyright`, `function __v4l2_event_dequeue`, `function v4l2_event_dequeue`, `function __v4l2_event_queue_fh`, `function v4l2_event_queue`, `function v4l2_event_queue_fh`, `function v4l2_event_pending`, `function v4l2_event_wake_all`, `function __v4l2_event_unsubscribe`, `function v4l2_event_subscribe`.
- 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.