drivers/gpu/drm/drm_gem_shmem_helper.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_gem_shmem_helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_gem_shmem_helper.c- Extension
.c- Size
- 28216 bytes
- Lines
- 1042
- 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/export.hlinux/module.hlinux/mutex.hlinux/shmem_fs.hlinux/slab.hlinux/vmalloc.hasm/set_memory.hkunit/visibility.hdrm/drm.hdrm/drm_device.hdrm/drm_drv.hdrm/drm_dumb_buffers.hdrm/drm_gem_shmem_helper.hdrm/drm_prime.hdrm/drm_print.h
Detected Declarations
function __drm_gem_shmem_initfunction drm_gem_shmem_initfunction __drm_gem_shmem_createfunction ERR_PTRfunction __drm_gem_shmem_free_sgt_lockedfunction drm_gem_shmem_releasefunction drm_gem_shmem_freefunction drm_gem_shmem_get_pages_lockedfunction drm_gem_shmem_put_pages_lockedfunction drm_gem_shmem_pin_lockedfunction drm_gem_shmem_unpin_lockedfunction drm_gem_shmem_pinfunction drm_gem_shmem_unpinfunction drm_gem_shmem_vunmap_lockedfunction drm_gem_shmem_vmap_lockedfunction drm_gem_shmem_create_with_handlefunction drm_gem_shmem_madvise_lockedfunction drm_gem_shmem_purge_lockedfunction drm_gem_shmem_dumb_createfunction drm_gem_shmem_record_mkwritefunction try_insert_pfnfunction drm_gem_shmem_any_faultfunction drm_gem_shmem_faultfunction drm_gem_shmem_vm_openfunction drm_gem_shmem_vm_closefunction drm_gem_shmem_pfn_mkwritefunction drm_gem_shmem_mmapfunction drm_gem_shmem_print_infofunction drm_gem_shmem_get_pages_sgtfunction drm_gem_shmem_get_sg_tablefunction drm_gem_shmem_prime_import_sg_tablefunction drm_gem_shmem_vmapfunction drm_gem_shmem_vunmapfunction drm_gem_shmem_madvisefunction drm_gem_shmem_purgeexport drm_gem_shmem_initexport drm_gem_shmem_createexport __drm_gem_shmem_free_sgt_lockedexport drm_gem_shmem_releaseexport drm_gem_shmem_freeexport drm_gem_shmem_put_pages_lockedexport drm_gem_shmem_pin_lockedexport drm_gem_shmem_unpin_lockedexport drm_gem_shmem_pinexport drm_gem_shmem_unpinexport drm_gem_shmem_vmap_lockedexport drm_gem_shmem_vunmap_lockedexport drm_gem_shmem_madvise_locked
Annotated Snippet
if (refcount_inc_not_zero(&shmem->vmap_use_count)) {
iosys_map_set_vaddr(map, shmem->vaddr);
return 0;
}
ret = drm_gem_shmem_pin_locked(shmem);
if (ret)
return ret;
if (shmem->map_wc)
prot = pgprot_writecombine(prot);
shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT,
VM_MAP, prot);
if (!shmem->vaddr) {
ret = -ENOMEM;
} else {
iosys_map_set_vaddr(map, shmem->vaddr);
refcount_set(&shmem->vmap_use_count, 1);
shmem->pages_mark_accessed_on_put = true;
shmem->pages_mark_dirty_on_put = true;
}
}
if (ret) {
drm_dbg_kms(obj->dev, "Failed to vmap pages, error %d\n", ret);
goto err_put_pages;
}
return 0;
err_put_pages:
if (!drm_gem_is_imported(obj))
drm_gem_shmem_unpin_locked(shmem);
return ret;
}
EXPORT_SYMBOL_GPL(drm_gem_shmem_vmap_locked);
/*
* drm_gem_shmem_vunmap_locked - Unmap a virtual mapping for a shmem GEM object
* @shmem: shmem GEM object
* @map: Kernel virtual address where the SHMEM GEM object was mapped
*
* This function cleans up a kernel virtual address mapping acquired by
* drm_gem_shmem_vmap_locked(). The mapping is only removed when the use count
* drops to zero.
*
* This function hides the differences between dma-buf imported and natively
* allocated objects.
*/
void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
struct iosys_map *map)
{
struct drm_gem_object *obj = &shmem->base;
dma_resv_assert_held(obj->resv);
if (drm_gem_is_imported(obj)) {
dma_buf_vunmap(obj->import_attach->dmabuf, map);
} else {
dma_resv_assert_held(shmem->base.resv);
if (refcount_dec_and_test(&shmem->vmap_use_count)) {
vunmap(shmem->vaddr);
shmem->vaddr = NULL;
drm_gem_shmem_unpin_locked(shmem);
}
}
}
EXPORT_SYMBOL_GPL(drm_gem_shmem_vunmap_locked);
static int
drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
struct drm_device *dev, size_t size,
uint32_t *handle)
{
struct drm_gem_shmem_object *shmem;
int ret;
shmem = drm_gem_shmem_create(dev, size);
if (IS_ERR(shmem))
return PTR_ERR(shmem);
/*
* Allocate an id of idr table where the obj is registered
* and handle has the id what user can see.
*/
ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
/* drop reference from allocate - handle holds it now. */
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/export.h`, `linux/module.h`, `linux/mutex.h`, `linux/shmem_fs.h`, `linux/slab.h`, `linux/vmalloc.h`, `asm/set_memory.h`.
- Detected declarations: `function __drm_gem_shmem_init`, `function drm_gem_shmem_init`, `function __drm_gem_shmem_create`, `function ERR_PTR`, `function __drm_gem_shmem_free_sgt_locked`, `function drm_gem_shmem_release`, `function drm_gem_shmem_free`, `function drm_gem_shmem_get_pages_locked`, `function drm_gem_shmem_put_pages_locked`, `function drm_gem_shmem_pin_locked`.
- 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.