drivers/gpu/drm/drm_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_gem.c- Extension
.c- Size
- 48754 bytes
- Lines
- 1770
- 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.
- 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/export.hlinux/file.hlinux/fs.hlinux/fs_context.hlinux/iosys-map.hlinux/mem_encrypt.hlinux/mm.hlinux/mman.hlinux/module.hlinux/pagemap.hlinux/folio_batch.hlinux/sched/mm.hlinux/shmem_fs.hlinux/slab.hlinux/string_helpers.hlinux/types.hlinux/uaccess.hdrm/drm.hdrm/drm_device.hdrm/drm_drv.hdrm/drm_file.hdrm/drm_gem.hdrm/drm_managed.hdrm/drm_print.hdrm/drm_vma_manager.hdrm_internal.h
Detected Declarations
function filesfunction drm_gem_object_initfunction drm_gem_init_releasefunction drm_gem_initfunction drm_gem_huge_mnt_createfunction drm_gem_private_object_initfunction drm_gem_private_object_finifunction drm_gem_object_handle_getfunction drm_gem_object_handle_get_if_exists_unlockedfunction drm_gem_object_handle_freefunction drm_gem_object_exported_dma_buf_freefunction drm_gem_object_handle_put_unlockedfunction drm_gem_object_release_handlefunction drm_gem_handle_createfunction drm_gem_dumb_map_offsetfunction drm_gem_handle_deletefunction drm_gem_handle_createfunction drm_gem_create_mmap_offsetfunction mmapfunction mmapfunction drm_gem_check_release_batchfunction drm_gem_put_pagesfunction drm_gem_put_pagesfunction objects_lookupfunction drm_gem_object_putfunction drm_gem_object_lookupfunction drm_gem_dma_resv_waitfunction drm_gem_close_ioctlfunction drm_gem_flink_ioctlfunction drm_gem_open_ioctlfunction drm_gem_change_handle_ioctlfunction drm_gem_openfunction drm_gem_releasefunction drm_gem_object_initfunction drm_gem_object_freefunction drm_gem_vm_openfunction drm_gem_vm_closefunction vm_opsfunction drm_gem_object_putfunction infunction infunction drm_gem_print_infofunction drm_gem_vmap_lockedfunction drm_gem_vunmap_lockedfunction drm_gem_lockfunction drm_gem_unlockfunction drm_gem_vmapfunction drm_gem_vunmap
Annotated Snippet
if (ret < 0) {
spin_lock(&file_priv->table_lock);
idr_remove(&file_priv->object_idr, new_handle);
idr_replace(&file_priv->object_idr, obj, args->handle);
spin_unlock(&file_priv->table_lock);
goto out_unlock;
}
drm_prime_remove_buf_handle(&file_priv->prime, args->handle);
}
ret = 0;
spin_lock(&file_priv->table_lock);
idr_remove(&file_priv->object_idr, args->handle);
obj = idr_replace(&file_priv->object_idr, obj, new_handle);
spin_unlock(&file_priv->table_lock);
WARN_ON(obj != NULL);
out_unlock:
mutex_unlock(&file_priv->prime.lock);
return ret;
}
/**
* drm_gem_open - initializes GEM file-private structures at devnode open time
* @dev: drm_device which is being opened by userspace
* @file_private: drm file-private structure to set up
*
* Called at device open time, sets up the structure for handling refcounting
* of mm objects.
*/
void
drm_gem_open(struct drm_device *dev, struct drm_file *file_private)
{
idr_init_base(&file_private->object_idr, 1);
spin_lock_init(&file_private->table_lock);
}
/**
* drm_gem_release - release file-private GEM resources
* @dev: drm_device which is being closed by userspace
* @file_private: drm file-private structure to clean up
*
* Called at close time when the filp is going away.
*
* Releases any remaining references on objects by this filp.
*/
void
drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
{
idr_for_each(&file_private->object_idr,
&drm_gem_object_release_handle, file_private);
idr_destroy(&file_private->object_idr);
}
/**
* drm_gem_object_release - release GEM buffer object resources
* @obj: GEM buffer object
*
* This releases any structures and resources used by @obj and is the inverse of
* drm_gem_object_init().
*/
void
drm_gem_object_release(struct drm_gem_object *obj)
{
if (obj->filp)
fput(obj->filp);
drm_gem_private_object_fini(obj);
drm_gem_free_mmap_offset(obj);
drm_gem_lru_remove(obj);
}
EXPORT_SYMBOL(drm_gem_object_release);
/**
* drm_gem_object_free - free a GEM object
* @kref: kref of the object to free
*
* Called after the last reference to the object has been lost.
*
* Frees the object
*/
void
drm_gem_object_free(struct kref *kref)
{
struct drm_gem_object *obj =
container_of(kref, struct drm_gem_object, refcount);
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/export.h`, `linux/file.h`, `linux/fs.h`, `linux/fs_context.h`, `linux/iosys-map.h`, `linux/mem_encrypt.h`, `linux/mm.h`.
- Detected declarations: `function files`, `function drm_gem_object_init`, `function drm_gem_init_release`, `function drm_gem_init`, `function drm_gem_huge_mnt_create`, `function drm_gem_private_object_init`, `function drm_gem_private_object_fini`, `function drm_gem_object_handle_get`, `function drm_gem_object_handle_get_if_exists_unlocked`, `function drm_gem_object_handle_free`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration 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.