drivers/gpu/drm/drm_gem_vram_helper.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_gem_vram_helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_gem_vram_helper.c- Extension
.c- Size
- 26341 bytes
- Lines
- 1014
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/export.hlinux/iosys-map.hlinux/module.hdrm/drm_debugfs.hdrm/drm_device.hdrm/drm_drv.hdrm/drm_file.hdrm/drm_framebuffer.hdrm/drm_gem_atomic_helper.hdrm/drm_gem_framebuffer_helper.hdrm/drm_gem_ttm_helper.hdrm/drm_gem_vram_helper.hdrm/drm_managed.hdrm/drm_mode.hdrm/drm_plane.hdrm/drm_prime.hdrm/drm_print.hdrm/ttm/ttm_range_manager.hdrm/ttm/ttm_tt.h
Detected Declarations
function drmm_vram_helper_initfunction drm_gem_vram_destroyfunction ttm_buffer_object_destroyfunction drm_gem_vram_placementfunction drm_gem_vram_createfunction drm_gem_vram_putfunction drm_gem_vram_pg_offsetfunction drm_gem_vram_offsetfunction drm_gem_vram_pin_lockedfunction drm_gem_vram_pinfunction drm_gem_vram_unpin_lockedfunction drm_gem_vram_unpinfunction drm_gem_vram_vmapfunction drm_gem_vram_vunmapfunction drm_gem_vram_fill_create_dumbfunction drm_is_gem_vramfunction drm_gem_vram_bo_driver_evict_flagsfunction drm_gem_vram_bo_driver_move_notifyfunction drm_gem_vram_bo_driver_movefunction drm_gem_vram_object_freefunction drm_gem_vram_driver_dumb_createfunction __drm_gem_vram_plane_helper_cleanup_fbfunction drm_gem_vram_plane_helper_prepare_fbfunction drm_gem_vram_plane_helper_cleanup_fbfunction drm_gem_vram_object_vmapfunction drm_gem_vram_object_vunmapfunction bo_driver_ttm_tt_destroyfunction bo_driver_evict_flagsfunction bo_driver_delete_mem_notifyfunction bo_driver_movefunction bo_driver_io_mem_reservefunction drm_vram_mm_debugfsfunction drm_vram_mm_debugfs_initfunction drm_vram_mm_initfunction drm_vram_mm_cleanupfunction drm_vram_helper_release_mmfunction drm_vram_mm_releasefunction drmm_vram_helper_initfunction drm_vram_helper_mode_valid_internalfunction drm_vram_helper_mode_validexport drm_gem_vram_createexport drm_gem_vram_putexport drm_gem_vram_offsetexport drm_gem_vram_vmapexport drm_gem_vram_vunmapexport drm_gem_vram_fill_create_dumbexport drm_gem_vram_driver_dumb_createexport drm_gem_vram_plane_helper_prepare_fb
Annotated Snippet
* &struct file_operations; as illustrated below.
*
* .. code-block:: c
*
* DEFINE_DRM_GEM_FOPS(fops);
* struct drm_driver drv = {
* .driver_feature = DRM_ ... ,
* .fops = &fops,
* DRM_GEM_VRAM_DRIVER
* };
*
* int init_drm_driver()
* {
* struct drm_device *dev;
* uint64_t vram_base;
* unsigned long vram_size;
* int ret;
*
* // setup device, vram base and size
* // ...
*
* ret = drmm_vram_helper_init(dev, vram_base, vram_size);
* if (ret)
* return ret;
* return 0;
* }
*
* This creates an instance of &struct drm_vram_mm, exports DRM userspace
* interfaces for GEM buffer management and initializes file operations to
* allow for accessing created GEM buffers. With this setup, the DRM driver
* manages an area of video RAM with VRAM MM and provides GEM VRAM objects
* to userspace.
*
* You don't have to clean up the instance of VRAM MM.
* drmm_vram_helper_init() is a managed interface that installs a
* clean-up handler to run during the DRM device's release.
*
* A buffer object that is pinned in video RAM has a fixed address within that
* memory region. Call drm_gem_vram_offset() to retrieve this value. Typically
* it's used to program the hardware's scanout engine for framebuffers, set
* the cursor overlay's image for a mouse cursor, or use it as input to the
* hardware's drawing engine.
*
* To access a buffer object's memory from the DRM driver, call
* drm_gem_vram_vmap(). It maps the buffer into kernel address
* space and returns the memory address. Use drm_gem_vram_vunmap() to
* release the mapping.
*/
/*
* Buffer-objects helpers
*/
static void drm_gem_vram_cleanup(struct drm_gem_vram_object *gbo)
{
/* We got here via ttm_bo_fini(), which means that the
* TTM buffer object in 'bo' has already been cleaned
* up; only release the GEM object.
*/
WARN_ON(gbo->vmap_use_count);
WARN_ON(iosys_map_is_set(&gbo->map));
drm_gem_object_release(&gbo->bo.base);
}
static void drm_gem_vram_destroy(struct drm_gem_vram_object *gbo)
{
drm_gem_vram_cleanup(gbo);
kfree(gbo);
}
static void ttm_buffer_object_destroy(struct ttm_buffer_object *bo)
{
struct drm_gem_vram_object *gbo = drm_gem_vram_of_bo(bo);
drm_gem_vram_destroy(gbo);
}
static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
unsigned long pl_flag)
{
u32 invariant_flags = 0;
unsigned int i;
unsigned int c = 0;
if (pl_flag & DRM_GEM_VRAM_PL_FLAG_TOPDOWN)
invariant_flags = TTM_PL_FLAG_TOPDOWN;
gbo->placement.placement = gbo->placements;
Annotation
- Immediate include surface: `linux/export.h`, `linux/iosys-map.h`, `linux/module.h`, `drm/drm_debugfs.h`, `drm/drm_device.h`, `drm/drm_drv.h`, `drm/drm_file.h`, `drm/drm_framebuffer.h`.
- Detected declarations: `function drmm_vram_helper_init`, `function drm_gem_vram_destroy`, `function ttm_buffer_object_destroy`, `function drm_gem_vram_placement`, `function drm_gem_vram_create`, `function drm_gem_vram_put`, `function drm_gem_vram_pg_offset`, `function drm_gem_vram_offset`, `function drm_gem_vram_pin_locked`, `function drm_gem_vram_pin`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: pattern 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.