drivers/media/pci/saa7164/saa7164-buffer.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/saa7164/saa7164-buffer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/saa7164/saa7164-buffer.c- Extension
.c- Size
- 8506 bytes
- Lines
- 286
- 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/slab.hsaa7164.h
Detected Declarations
function Copyrightfunction saa7164_buffer_deallocfunction saa7164_buffer_zero_offsetsfunction saa7164_buffer_activatefunction saa7164_buffer_cfg_portfunction saa7164_buffer_dealloc_user
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Driver for the NXP SAA7164 PCIe bridge
*
* Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
*/
#include <linux/slab.h>
#include "saa7164.h"
/* The PCI address space for buffer handling looks like this:
*
* +-u32 wide-------------+
* | +
* +-u64 wide------------------------------------+
* + +
* +----------------------+
* | CurrentBufferPtr + Pointer to current PCI buffer >-+
* +----------------------+ |
* | Unused + |
* +----------------------+ |
* | Pitch + = 188 (bytes) |
* +----------------------+ |
* | PCI buffer size + = pitch * number of lines (312) |
* +----------------------+ |
* |0| Buf0 Write Offset + |
* +----------------------+ v
* |1| Buf1 Write Offset + |
* +----------------------+ |
* |2| Buf2 Write Offset + |
* +----------------------+ |
* |3| Buf3 Write Offset + |
* +----------------------+ |
* ... More write offsets |
* +---------------------------------------------+ |
* +0| set of ptrs to PCI pagetables + |
* +---------------------------------------------+ |
* +1| set of ptrs to PCI pagetables + <--------+
* +---------------------------------------------+
* +2| set of ptrs to PCI pagetables +
* +---------------------------------------------+
* +3| set of ptrs to PCI pagetables + >--+
* +---------------------------------------------+ |
* ... More buffer pointers | +----------------+
* +->| pt[0] TS data |
* | +----------------+
* |
* | +----------------+
* +->| pt[1] TS data |
* | +----------------+
* | etc
*/
/* Allocate a new buffer structure and associated PCI space in bytes.
* len must be a multiple of sizeof(u64)
*/
struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_port *port,
u32 len)
{
struct tmHWStreamParameters *params = &port->hw_streamingparams;
struct saa7164_buffer *buf = NULL;
struct saa7164_dev *dev = port->dev;
int i;
if ((len == 0) || (len >= 65536) || (len % sizeof(u64))) {
log_warn("%s() SAA_ERR_BAD_PARAMETER\n", __func__);
goto ret;
}
buf = kzalloc_obj(*buf);
if (!buf)
goto ret;
buf->idx = -1;
buf->port = port;
buf->flags = SAA7164_BUFFER_FREE;
buf->pos = 0;
buf->actual_size = params->pitch * params->numberoflines;
buf->crc = 0;
/* TODO: arg len is being ignored */
buf->pci_size = SAA7164_PT_ENTRIES * 0x1000;
buf->pt_size = (SAA7164_PT_ENTRIES * sizeof(u64)) + 0x1000;
/* Allocate contiguous memory */
buf->cpu = dma_alloc_coherent(&port->dev->pci->dev, buf->pci_size,
&buf->dma, GFP_KERNEL);
if (!buf->cpu)
goto fail1;
Annotation
- Immediate include surface: `linux/slab.h`, `saa7164.h`.
- Detected declarations: `function Copyright`, `function saa7164_buffer_dealloc`, `function saa7164_buffer_zero_offsets`, `function saa7164_buffer_activate`, `function saa7164_buffer_cfg_port`, `function saa7164_buffer_dealloc_user`.
- 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.