drm_gem_mmap_obj(9)
π drm_gem_mmap_obj(9) π
okay bestie, buckle up β this is a page from the Kernel API Manual and we're about to make memory-mapping a GEM object make sense, no cap β¨
πΈ NAME πΈ
drm_gem_mmap_obj β memory map a GEM object π«Ά
β¨ SYNOPSIS β¨
int drm_gem_mmap_obj (struct drm_gem_object *obj , unsigned long
obj_size , struct vm_area_struct *vma );
π ARGUMENTS π
objβ the GEM object you're trying to map, aka the main character of this whole operation πobj_sizeβ the object size that's getting mapped, counted in bytes (yes, bytes, we're being precise here π )vmaβ the VMA for the area that's about to be mapped π¦
π DESCRIPTION π
So what this does is: it sets up the VMA so the GEM object can be mapped, using the GEM object's own vm_ops. That's the whole vibe.
And because GEM objects have different requirements depending on who they are, they've got two paths, and honestly both are valid:
- they can ship a fault handler inside their
vm_opsβ and in that case any access to the object gets trapped, so somebody can go do migration, GTT binding, surface register allocation, or performance monitoring π€ - or they can just
mmapthe buffer memory synchronously after callingdrm_gem_mmap_obj, and honestly? also iconic.
This function is mainly intended to implement the DMABUF mmap operation, specifically for when the GEM object isn't looked up based on its fake offset. And if you're trying to implement the DRM mmap operation instead? Drivers should be using the drm_gem_mmap function for that, not this one. Noted. π
β οΈ okay this part is important, like actually important:drm_gem_mmap_objassumes the user has already been granted access to the buffer, whereasdrm_gem_mmapis the one that prevents unprivileged users from mapping random objects. So callers must verify access restrictions before calling this helper. No skipping that step, bestie, fr fr π₯
Return value: it returns 0 or success, or -EINVAL if the object size is smaller than the VMA size, or if no vm_ops are provided. Like, that's the deal π
π SEE ALSO π
Kernel file ./drivers/gpu/drm/drm_gem.c β and here's the whole friend group, everybody say hi π
drm_gem_huge_mnt_create(9)drm_gem_init(9)drm_gem_object_init(9)drm_gem_private_object_init(9)drm_gem_private_object_fini(9)drm_gem_object_handle_get_if_exists_unlocked(9)drm_gem_object_handle_free(9)drm_gem_object_handle_put_unlocked(9)drm_gem_handle_delete(9)drm_gem_dumb_map_offset(9)drm_gem_handle_create_tail(9)drm_gem_handle_create(9)drm_gem_free_mmap_offset(9)drm_gem_create_mmap_offset_size(9)drm_gem_create_mmap_offset(9)drm_gem_get_pages(9)drm_gem_put_pages(9)drm_gem_objects_lookup(9)drm_gem_object_lookup(9)drm_gem_dma_resv_wait(9)drm_gem_open(9)drm_gem_release(9)drm_gem_object_release(9)drm_gem_object_free(9)drm_gem_vm_open(9)drm_gem_vm_close(9)drm_gem_get_unmapped_area(9)drm_gem_mmap(9)drm_gem_lock_reservations(9)drm_gem_lru_init(9)drm_gem_lru_remove(9)drm_gem_lru_move_tail_locked(9)drm_gem_lru_move_tail(9)drm_gem_lru_scan(9)drm_gem_evict_locked(9)
and that's the whole page, bestie π§π go map something responsibly
k bye, this was brought to you by the Kernel API Manual, living at ./drivers/gpu/drm, dated October 2026 β mwah, slay, periodt π
ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms