drivers/media/pci/tw686x/tw686x-video.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/tw686x/tw686x-video.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/tw686x/tw686x-video.c- Extension
.c- Size
- 33565 bytes
- Lines
- 1308
- 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/init.hlinux/delay.hlinux/list.hlinux/module.hlinux/kernel.hlinux/slab.hmedia/v4l2-common.hmedia/v4l2-event.hmedia/videobuf2-dma-contig.hmedia/videobuf2-dma-sg.hmedia/videobuf2-vmalloc.htw686x.htw686x-regs.h
Detected Declarations
function tw686x_buf_donefunction tw686x_memcpy_dma_freefunction tw686x_memcpy_dma_allocfunction tw686x_memcpy_buf_refillfunction tw686x_contig_buf_refillfunction tw686x_sg_desc_fillfunction tw686x_sg_buf_refillfunction tw686x_sg_dma_freefunction tw686x_sg_dma_allocfunction tw686x_sg_setupfunction tw686x_real_fpsfunction tw686x_fps_idxfunction tw686x_set_frameratefunction tw686x_queue_setupfunction tw686x_buf_queuefunction tw686x_clear_queuefunction tw686x_start_streamingfunction tw686x_stop_streamingfunction tw686x_buf_preparefunction tw686x_s_ctrlfunction tw686x_g_fmt_vid_capfunction tw686x_try_fmt_vid_capfunction tw686x_set_formatfunction tw686x_s_fmt_vid_capfunction tw686x_querycapfunction tw686x_set_standardfunction tw686x_s_stdfunction tw686x_querystdfunction tw686x_g_stdfunction tw686x_enum_framesizesfunction tw686x_enum_frameintervalsfunction tw686x_g_parmfunction tw686x_s_parmfunction tw686x_enum_fmt_vid_capfunction tw686x_set_inputfunction tw686x_s_inputfunction tw686x_g_inputfunction tw686x_enum_inputfunction tw686x_video_irqfunction for_each_set_bitfunction framefunction tw686x_video_freefunction tw686x_video_init
Annotated Snippet
while (len && buf_len) {
if (count == TW686X_MAX_SG_DESC_COUNT)
return -ENOMEM;
entry_len = min_t(unsigned int, len,
TW686X_MAX_SG_ENTRY_SIZE);
entry_len = min_t(unsigned int, entry_len, buf_len);
descs[count].phys = cpu_to_le32(phys);
descs[count++].flags_length =
cpu_to_le32(BIT(30) | entry_len);
phys += entry_len;
len -= entry_len;
buf_len -= entry_len;
}
if (!buf_len)
return 0;
}
return -ENOMEM;
}
static void tw686x_sg_buf_refill(struct tw686x_video_channel *vc,
unsigned int pb)
{
struct tw686x_dev *dev = vc->dev;
struct tw686x_v4l2_buf *buf;
while (!list_empty(&vc->vidq_queued)) {
unsigned int buf_len;
buf = list_first_entry(&vc->vidq_queued,
struct tw686x_v4l2_buf, list);
list_del(&buf->list);
buf_len = (vc->width * vc->height * vc->format->depth) >> 3;
if (tw686x_sg_desc_fill(vc->sg_descs[pb], buf, buf_len)) {
v4l2_err(&dev->v4l2_dev,
"dma%d: unable to fill %s-buffer\n",
vc->ch, pb ? "B" : "P");
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
continue;
}
buf->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE;
vc->curr_bufs[pb] = buf;
return;
}
vc->curr_bufs[pb] = NULL;
}
static void tw686x_sg_dma_free(struct tw686x_video_channel *vc,
unsigned int pb)
{
struct tw686x_dma_desc *desc = &vc->dma_descs[pb];
struct tw686x_dev *dev = vc->dev;
if (desc->size) {
dma_free_coherent(&dev->pci_dev->dev, desc->size, desc->virt,
desc->phys);
desc->virt = NULL;
}
vc->sg_descs[pb] = NULL;
}
static int tw686x_sg_dma_alloc(struct tw686x_video_channel *vc,
unsigned int pb)
{
struct tw686x_dma_desc *desc = &vc->dma_descs[pb];
struct tw686x_dev *dev = vc->dev;
u32 reg = pb ? DMA_PAGE_TABLE1_ADDR[vc->ch] :
DMA_PAGE_TABLE0_ADDR[vc->ch];
void *virt;
if (desc->size) {
virt = dma_alloc_coherent(&dev->pci_dev->dev, desc->size,
&desc->phys, GFP_KERNEL);
if (!virt) {
v4l2_err(&dev->v4l2_dev,
"dma%d: unable to allocate %s-buffer\n",
vc->ch, pb ? "B" : "P");
return -ENOMEM;
}
desc->virt = virt;
reg_write(dev, reg, desc->phys);
} else {
virt = dev->video_channels[0].dma_descs[pb].virt +
Annotation
- Immediate include surface: `linux/init.h`, `linux/delay.h`, `linux/list.h`, `linux/module.h`, `linux/kernel.h`, `linux/slab.h`, `media/v4l2-common.h`, `media/v4l2-event.h`.
- Detected declarations: `function tw686x_buf_done`, `function tw686x_memcpy_dma_free`, `function tw686x_memcpy_dma_alloc`, `function tw686x_memcpy_buf_refill`, `function tw686x_contig_buf_refill`, `function tw686x_sg_desc_fill`, `function tw686x_sg_buf_refill`, `function tw686x_sg_dma_free`, `function tw686x_sg_dma_alloc`, `function tw686x_sg_setup`.
- 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.