drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/nvidia/tegra-vde/dmabuf-cache.c- Extension
.c- Size
- 4763 bytes
- Lines
- 230
- 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.
- 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/dma-buf.hlinux/iova.hlinux/kernel.hlinux/list.hlinux/sched.hlinux/slab.hlinux/workqueue.hlinux/module.hvde.h
Detected Declarations
struct tegra_vde_cache_entryfunction tegra_vde_release_entryfunction tegra_vde_delayed_unmapfunction tegra_vde_dmabuf_cache_mapfunction list_for_each_entryfunction tegra_vde_dmabuf_cache_unmapfunction list_for_each_entryfunction tegra_vde_dmabuf_cache_unmap_syncfunction list_for_each_entry_safefunction tegra_vde_dmabuf_cache_unmap_all
Annotated Snippet
struct tegra_vde_cache_entry {
enum dma_data_direction dma_dir;
struct dma_buf_attachment *a;
struct delayed_work dwork;
struct tegra_vde *vde;
struct list_head list;
struct sg_table *sgt;
struct iova *iova;
unsigned int refcnt;
};
static void tegra_vde_release_entry(struct tegra_vde_cache_entry *entry)
{
struct dma_buf *dmabuf = entry->a->dmabuf;
WARN_ON_ONCE(entry->refcnt);
if (entry->vde->domain)
tegra_vde_iommu_unmap(entry->vde, entry->iova);
dma_buf_unmap_attachment_unlocked(entry->a, entry->sgt, entry->dma_dir);
dma_buf_detach(dmabuf, entry->a);
dma_buf_put(dmabuf);
list_del(&entry->list);
kfree(entry);
}
static void tegra_vde_delayed_unmap(struct work_struct *work)
{
struct tegra_vde_cache_entry *entry;
struct tegra_vde *vde;
entry = container_of(work, struct tegra_vde_cache_entry,
dwork.work);
vde = entry->vde;
mutex_lock(&vde->map_lock);
tegra_vde_release_entry(entry);
mutex_unlock(&vde->map_lock);
}
int tegra_vde_dmabuf_cache_map(struct tegra_vde *vde,
struct dma_buf *dmabuf,
enum dma_data_direction dma_dir,
struct dma_buf_attachment **ap,
dma_addr_t *addrp)
{
struct dma_buf_attachment *attachment;
struct tegra_vde_cache_entry *entry;
struct device *dev = vde->dev;
struct sg_table *sgt;
struct iova *iova;
int err;
mutex_lock(&vde->map_lock);
list_for_each_entry(entry, &vde->map_list, list) {
if (entry->a->dmabuf != dmabuf)
continue;
if (!cancel_delayed_work(&entry->dwork))
continue;
if (entry->dma_dir != dma_dir)
entry->dma_dir = DMA_BIDIRECTIONAL;
dma_buf_put(dmabuf);
if (vde->domain)
*addrp = iova_dma_addr(&vde->iova, entry->iova);
else
*addrp = sg_dma_address(entry->sgt->sgl);
goto ref;
}
attachment = dma_buf_attach(dmabuf, dev);
if (IS_ERR(attachment)) {
dev_err(dev, "Failed to attach dmabuf\n");
err = PTR_ERR(attachment);
goto err_unlock;
}
sgt = dma_buf_map_attachment_unlocked(attachment, dma_dir);
if (IS_ERR(sgt)) {
dev_err(dev, "Failed to get dmabufs sg_table\n");
err = PTR_ERR(sgt);
goto err_detach;
}
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/iova.h`, `linux/kernel.h`, `linux/list.h`, `linux/sched.h`, `linux/slab.h`, `linux/workqueue.h`, `linux/module.h`.
- Detected declarations: `struct tegra_vde_cache_entry`, `function tegra_vde_release_entry`, `function tegra_vde_delayed_unmap`, `function tegra_vde_dmabuf_cache_map`, `function list_for_each_entry`, `function tegra_vde_dmabuf_cache_unmap`, `function list_for_each_entry`, `function tegra_vde_dmabuf_cache_unmap_sync`, `function list_for_each_entry_safe`, `function tegra_vde_dmabuf_cache_unmap_all`.
- 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.
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.