drivers/gpu/drm/drm_gem_dma_helper.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_gem_dma_helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_gem_dma_helper.c- Extension
.c- Size
- 18403 bytes
- Lines
- 612
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/dma-mapping.hlinux/export.hlinux/mm.hlinux/module.hlinux/mutex.hlinux/slab.hdrm/drm.hdrm/drm_device.hdrm/drm_drv.hdrm/drm_dumb_buffers.hdrm/drm_gem_dma_helper.hdrm/drm_print.hdrm/drm_vma_manager.h
Detected Declarations
function ERR_PTRfunction ERR_PTRfunction drm_gem_dma_createfunction drm_gem_dma_freefunction drm_gem_dma_dumb_create_internalfunction drm_gem_dma_dumb_create_internalfunction drm_gem_dma_get_unmapped_areafunction drm_gem_dma_print_infofunction drm_gem_dma_prime_import_sg_tablefunction drm_gem_dma_vmapfunction drm_gem_dma_mmapfunction drm_gem_dma_prime_import_sg_tableexport drm_gem_dma_createexport drm_gem_dma_freeexport drm_gem_dma_dumb_create_internalexport drm_gem_dma_dumb_createexport drm_gem_dma_vm_opsexport drm_gem_dma_get_unmapped_areaexport drm_gem_dma_print_infoexport drm_gem_dma_get_sg_tableexport drm_gem_dma_prime_import_sg_tableexport drm_gem_dma_vmapexport drm_gem_dma_mmapexport drm_gem_dma_prime_import_sg_table_vmap
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* drm gem DMA helper functions
*
* Copyright (C) 2012 Sascha Hauer, Pengutronix
*
* Based on Samsung Exynos code
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
*/
#include <linux/dma-buf.h>
#include <linux/dma-mapping.h>
#include <linux/export.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <drm/drm.h>
#include <drm/drm_device.h>
#include <drm/drm_drv.h>
#include <drm/drm_dumb_buffers.h>
#include <drm/drm_gem_dma_helper.h>
#include <drm/drm_print.h>
#include <drm/drm_vma_manager.h>
/**
* DOC: dma helpers
*
* The DRM GEM/DMA helpers are a means to provide buffer objects that are
* presented to the device as a contiguous chunk of memory. This is useful
* for devices that do not support scatter-gather DMA (either directly or
* by using an intimately attached IOMMU).
*
* For devices that access the memory bus through an (external) IOMMU then
* the buffer objects are allocated using a traditional page-based
* allocator and may be scattered through physical memory. However they
* are contiguous in the IOVA space so appear contiguous to devices using
* them.
*
* For other devices then the helpers rely on CMA to provide buffer
* objects that are physically contiguous in memory.
*
* For GEM callback helpers in struct &drm_gem_object functions, see likewise
* named functions with an _object_ infix (e.g., drm_gem_dma_object_vmap() wraps
* drm_gem_dma_vmap()). These helpers perform the necessary type conversion.
*/
static const struct drm_gem_object_funcs drm_gem_dma_default_funcs = {
.free = drm_gem_dma_object_free,
.print_info = drm_gem_dma_object_print_info,
.get_sg_table = drm_gem_dma_object_get_sg_table,
.vmap = drm_gem_dma_object_vmap,
.mmap = drm_gem_dma_object_mmap,
.vm_ops = &drm_gem_dma_vm_ops,
};
/**
* __drm_gem_dma_create - Create a GEM DMA object without allocating memory
* @drm: DRM device
* @size: size of the object to allocate
* @private: true if used for internal purposes
*
* This function creates and initializes a GEM DMA object of the given size,
* but doesn't allocate any memory to back the object.
*
* Returns:
* A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
* error code on failure.
*/
static struct drm_gem_dma_object *
__drm_gem_dma_create(struct drm_device *drm, size_t size, bool private)
{
struct drm_gem_dma_object *dma_obj;
struct drm_gem_object *gem_obj;
int ret = 0;
if (drm->driver->gem_create_object) {
gem_obj = drm->driver->gem_create_object(drm, size);
if (IS_ERR(gem_obj))
return ERR_CAST(gem_obj);
dma_obj = to_drm_gem_dma_obj(gem_obj);
} else {
dma_obj = kzalloc_obj(*dma_obj);
if (!dma_obj)
return ERR_PTR(-ENOMEM);
gem_obj = &dma_obj->base;
}
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/dma-mapping.h`, `linux/export.h`, `linux/mm.h`, `linux/module.h`, `linux/mutex.h`, `linux/slab.h`, `drm/drm.h`.
- Detected declarations: `function ERR_PTR`, `function ERR_PTR`, `function drm_gem_dma_create`, `function drm_gem_dma_free`, `function drm_gem_dma_dumb_create_internal`, `function drm_gem_dma_dumb_create_internal`, `function drm_gem_dma_get_unmapped_area`, `function drm_gem_dma_print_info`, `function drm_gem_dma_prime_import_sg_table`, `function drm_gem_dma_vmap`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration 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.