drivers/gpu/drm/msm/msm_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/msm/msm_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/msm/msm_gem.c- Extension
.c- Size
- 33188 bytes
- Lines
- 1395
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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-map-ops.hlinux/vmalloc.hlinux/spinlock.hlinux/shmem_fs.hlinux/dma-buf.hdrm/drm_dumb_buffers.hdrm/drm_prime.hdrm/drm_file.hdrm/drm_fourcc.htrace/events/gpu_mem.hmsm_drv.hmsm_gem.hmsm_gpu.hmsm_kms.h
Detected Declarations
function Copyrightfunction update_ctx_memfunction msm_gem_openfunction msm_gem_closefunction msm_gem_vma_getfunction msm_gem_vma_putfunction devicefunction sync_for_cpufunction update_lru_activefunction update_lru_lockedfunction update_lrufunction put_pagesfunction msm_gem_pin_obj_lockedfunction pin_obj_lockedfunction msm_gem_unpin_pages_lockedfunction msm_gem_pgprotfunction msm_gem_faultfunction drm_gem_for_each_gpuvm_bofunction drm_gpuvm_bo_for_each_vafunction drm_gem_for_each_gpuvm_bo_safefunction drm_gpuvm_bo_for_each_va_safefunction msm_gem_protfunction msm_gem_pin_vma_lockedfunction msm_gem_unpin_lockedfunction msm_gem_unpin_activefunction get_and_pin_iova_range_lockedfunction rangefunction msm_gem_get_and_pin_iovafunction msm_gem_get_iovafunction clear_iovafunction msm_gem_set_iovafunction is_kms_vmfunction elsefunction msm_gem_dumb_createfunction msm_gem_put_vaddr_lockedfunction msm_gem_put_vaddrfunction msm_gem_madvisefunction msm_gem_purgefunction msm_gem_evictfunction msm_gem_vunmapfunction msm_gem_activefunction msm_gem_cpu_prepfunction msm_gem_cpu_finifunction msm_gem_describefunction drm_gem_for_each_gpuvm_bofunction drm_gpuvm_bo_for_each_vafunction msm_gem_describe_objectsfunction msm_gem_free_object
Annotated Snippet
if (IS_ERR(p)) {
DRM_DEV_ERROR(dev->dev, "could not get pages: %ld\n",
PTR_ERR(p));
return p;
}
update_device_mem(dev->dev_private, obj->size);
msm_obj->pages = p;
msm_obj->sgt = drm_prime_pages_to_sg(obj->dev, p, npages);
if (IS_ERR(msm_obj->sgt)) {
void *ptr = ERR_CAST(msm_obj->sgt);
DRM_DEV_ERROR(dev->dev, "failed to allocate sgt\n");
msm_obj->sgt = NULL;
return ptr;
}
/* For non-cached buffers, ensure the new pages are clean
* because display controller, GPU, etc. are not coherent:
*/
if (msm_obj->flags & MSM_BO_WC)
sync_for_device(msm_obj);
update_lru(obj);
}
return msm_obj->pages;
}
static void put_pages(struct drm_gem_object *obj)
{
struct msm_gem_object *msm_obj = to_msm_bo(obj);
/*
* Skip gpuvm in the object free path to avoid a WARN_ON() splat.
* See explaination in msm_gem_assert_locked()
*/
if (kref_read(&obj->refcount))
drm_gpuvm_bo_gem_evict(obj, true);
if (msm_obj->pages) {
if (msm_obj->sgt) {
/* For non-cached buffers, ensure the new
* pages are clean because display controller,
* GPU, etc. are not coherent:
*/
if (msm_obj->flags & MSM_BO_WC)
sync_for_cpu(msm_obj);
sg_free_table(msm_obj->sgt);
kfree(msm_obj->sgt);
msm_obj->sgt = NULL;
}
update_device_mem(obj->dev->dev_private, -obj->size);
drm_gem_put_pages(obj, msm_obj->pages, true, false);
msm_obj->pages = NULL;
update_lru(obj);
}
}
struct page **msm_gem_get_pages_locked(struct drm_gem_object *obj, unsigned madv)
{
struct msm_gem_object *msm_obj = to_msm_bo(obj);
msm_gem_assert_locked(obj);
if (msm_obj->madv > madv) {
DRM_DEV_DEBUG_DRIVER(obj->dev->dev, "Invalid madv state: %u vs %u\n",
msm_obj->madv, madv);
return ERR_PTR(-EBUSY);
}
return get_pages(obj);
}
/*
* Update the pin count of the object, call under lru.lock
*/
void msm_gem_pin_obj_locked(struct drm_gem_object *obj)
{
struct msm_drm_private *priv = obj->dev->dev_private;
msm_gem_assert_locked(obj);
to_msm_bo(obj)->pin_count++;
Annotation
- Immediate include surface: `linux/dma-map-ops.h`, `linux/vmalloc.h`, `linux/spinlock.h`, `linux/shmem_fs.h`, `linux/dma-buf.h`, `drm/drm_dumb_buffers.h`, `drm/drm_prime.h`, `drm/drm_file.h`.
- Detected declarations: `function Copyright`, `function update_ctx_mem`, `function msm_gem_open`, `function msm_gem_close`, `function msm_gem_vma_get`, `function msm_gem_vma_put`, `function device`, `function sync_for_cpu`, `function update_lru_active`, `function update_lru_locked`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.