drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c- Extension
.c- Size
- 8660 bytes
- Lines
- 348
- Domain
- Driver Families
- Bucket
- drivers/gpu
- 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 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/dma-buf.hlinux/highmem.hlinux/dma-resv.hlinux/module.hasm/smp.hgem/i915_gem_dmabuf.hi915_drv.hi915_gem_object.hi915_scatterlist.hselftests/mock_dmabuf.cselftests/i915_gem_dmabuf.c
Detected Declarations
function i915_gem_dmabuf_vmapfunction i915_gem_dmabuf_vunmapfunction i915_gem_dmabuf_mmapfunction i915_gem_begin_cpu_accessfunction i915_gem_end_cpu_accessfunction i915_gem_dmabuf_attachfunction for_i915_gem_wwfunction i915_gem_dmabuf_detachfunction i915_gem_object_get_pages_dmabuffunction i915_gem_object_put_pages_dmabuf
Annotated Snippet
// SPDX-License-Identifier: MIT
/*
* Copyright 2012 Red Hat Inc
*/
#include <linux/dma-buf.h>
#include <linux/highmem.h>
#include <linux/dma-resv.h>
#include <linux/module.h>
#include <asm/smp.h>
#include "gem/i915_gem_dmabuf.h"
#include "i915_drv.h"
#include "i915_gem_object.h"
#include "i915_scatterlist.h"
MODULE_IMPORT_NS("DMA_BUF");
I915_SELFTEST_DECLARE(static bool force_different_devices;)
static struct drm_i915_gem_object *dma_buf_to_obj(struct dma_buf *buf)
{
return to_intel_bo(buf->priv);
}
static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attach,
enum dma_data_direction dir)
{
struct drm_i915_gem_object *obj = dma_buf_to_obj(attach->dmabuf);
struct sg_table *sgt;
struct scatterlist *src, *dst;
int ret, i;
/*
* Make a copy of the object's sgt, so that we can make an independent
* mapping
*/
sgt = kmalloc_obj(*sgt);
if (!sgt) {
ret = -ENOMEM;
goto err;
}
ret = sg_alloc_table(sgt, obj->mm.pages->orig_nents, GFP_KERNEL);
if (ret)
goto err_free;
dst = sgt->sgl;
for_each_sg(obj->mm.pages->sgl, src, obj->mm.pages->orig_nents, i) {
sg_set_page(dst, sg_page(src), src->length, 0);
dst = sg_next(dst);
}
ret = dma_map_sgtable(attach->dev, sgt, dir, DMA_ATTR_SKIP_CPU_SYNC);
if (ret)
goto err_free_sg;
return sgt;
err_free_sg:
sg_free_table(sgt);
err_free:
kfree(sgt);
err:
return ERR_PTR(ret);
}
static int i915_gem_dmabuf_vmap(struct dma_buf *dma_buf,
struct iosys_map *map)
{
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
void *vaddr;
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
if (IS_ERR(vaddr))
return PTR_ERR(vaddr);
iosys_map_set_vaddr(map, vaddr);
return 0;
}
static void i915_gem_dmabuf_vunmap(struct dma_buf *dma_buf,
struct iosys_map *map)
{
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
i915_gem_object_flush_map(obj);
i915_gem_object_unpin_map(obj);
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/highmem.h`, `linux/dma-resv.h`, `linux/module.h`, `asm/smp.h`, `gem/i915_gem_dmabuf.h`, `i915_drv.h`, `i915_gem_object.h`.
- Detected declarations: `function i915_gem_dmabuf_vmap`, `function i915_gem_dmabuf_vunmap`, `function i915_gem_dmabuf_mmap`, `function i915_gem_begin_cpu_access`, `function i915_gem_end_cpu_access`, `function i915_gem_dmabuf_attach`, `function for_i915_gem_ww`, `function i915_gem_dmabuf_detach`, `function i915_gem_object_get_pages_dmabuf`, `function i915_gem_object_put_pages_dmabuf`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- 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.