drivers/media/pci/mgb4/mgb4_vout.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/mgb4/mgb4_vout.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/mgb4/mgb4_vout.c- Extension
.c- Size
- 24760 bytes
- Lines
- 874
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/pci.hlinux/align.hlinux/dma/amd_xdma.hmedia/v4l2-ioctl.hmedia/videobuf2-v4l2.hmedia/videobuf2-dma-sg.hmedia/v4l2-dv-timings.hmgb4_core.hmgb4_dma.hmgb4_sysfs.hmgb4_io.hmgb4_cmt.hmgb4_vout.h
Detected Declarations
function get_timingsfunction return_all_buffersfunction queue_setupfunction buffer_initfunction buffer_preparefunction buffer_queuefunction stop_streamingfunction start_streamingfunction vidioc_querycapfunction vidioc_enum_fmtfunction vidioc_g_fmtfunction vidioc_try_fmtfunction vidioc_s_fmtfunction vidioc_g_outputfunction vidioc_s_outputfunction vidioc_enum_outputfunction vidioc_enum_frameintervalsfunction vidioc_g_parmfunction vidioc_s_parmfunction vidioc_g_dv_timingsfunction vidioc_s_dv_timingsfunction vidioc_enum_dv_timingsfunction vidioc_dv_timings_capfunction fh_openfunction dma_transferfunction handlerfunction ser_initfunction fpga_initfunction create_debugfsfunction mgb4_vout_free
Annotated Snippet
if (config & (1U << 20)) {
f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
} else {
if (config & (1U << 19))
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
else
f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
}
f->fmt.pix.bytesperline = (f->fmt.pix.width + voutdev->padding) * 2;
} else {
f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32;
f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW;
f->fmt.pix.bytesperline = (f->fmt.pix.width + voutdev->padding) * 4;
}
f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
return 0;
}
static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
{
struct mgb4_vout_dev *voutdev = video_drvdata(file);
struct mgb4_regs *video = &voutdev->mgbdev->video;
u32 pixelsize;
f->fmt.pix.width = voutdev->width;
f->fmt.pix.height = voutdev->height;
f->fmt.pix.field = V4L2_FIELD_NONE;
if (has_yuv(video) && f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) {
pixelsize = 2;
if (!(f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709 ||
f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M))
f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
} else {
pixelsize = 4;
f->fmt.pix.pixelformat = V4L2_PIX_FMT_ABGR32;
f->fmt.pix.colorspace = V4L2_COLORSPACE_RAW;
}
if (f->fmt.pix.bytesperline > f->fmt.pix.width * pixelsize &&
f->fmt.pix.bytesperline < f->fmt.pix.width * pixelsize * 2)
f->fmt.pix.bytesperline = ALIGN(f->fmt.pix.bytesperline,
pixelsize);
else
f->fmt.pix.bytesperline = f->fmt.pix.width * pixelsize;
f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
return 0;
}
static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
{
struct mgb4_vout_dev *voutdev = video_drvdata(file);
struct mgb4_regs *video = &voutdev->mgbdev->video;
u32 config, pixelsize;
int ret;
if (vb2_is_busy(&voutdev->queue))
return -EBUSY;
ret = vidioc_try_fmt(file, priv, f);
if (ret < 0)
return ret;
config = mgb4_read_reg(video, voutdev->config->regs.config);
if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV) {
pixelsize = 2;
config |= 1U << 16;
if (f->fmt.pix.colorspace == V4L2_COLORSPACE_REC709) {
config |= 1U << 20;
config |= 1U << 19;
} else if (f->fmt.pix.colorspace == V4L2_COLORSPACE_SMPTE170M) {
config &= ~(1U << 20);
config |= 1U << 19;
} else {
config &= ~(1U << 20);
config &= ~(1U << 19);
}
} else {
pixelsize = 4;
config &= ~(1U << 16);
}
mgb4_write_reg(video, voutdev->config->regs.config, config);
voutdev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width
* pixelsize)) / pixelsize;
Annotation
- Immediate include surface: `linux/pci.h`, `linux/align.h`, `linux/dma/amd_xdma.h`, `media/v4l2-ioctl.h`, `media/videobuf2-v4l2.h`, `media/videobuf2-dma-sg.h`, `media/v4l2-dv-timings.h`, `mgb4_core.h`.
- Detected declarations: `function get_timings`, `function return_all_buffers`, `function queue_setup`, `function buffer_init`, `function buffer_prepare`, `function buffer_queue`, `function stop_streaming`, `function start_streaming`, `function vidioc_querycap`, `function vidioc_enum_fmt`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.