STRUCT DRM_GEM_OBJECT_FUNCS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– struct drm_gem_object_funcs (9) πŸ’–

okay so bestie, welcome to the Kernel API Manual ✨ this one's all about the GEM object function table, and honestly? it's giving "the plug for everything your GEM object can do." buckle up πŸŽ€


🌸 NAME 🌸

struct drm_gem_object_funcs β€” GEM object functions. yep, that's the whole name, no cap πŸ’…


✨ SYNOPSIS ✨

like, here's the whole vibe, every single pointer, verbatim, do not touch πŸ”₯

struct drm_gem_object_funcs {
    void (*free)(struct drm_gem_object *obj);
    int (*open)(struct drm_gem_object *obj, struct drm_file *file);
    void (*close)(struct drm_gem_object *obj, struct drm_file *file);
    void (*print_info)(struct drm_printer *p, unsigned int indent, const struct drm_gem_object *obj);
    struct dma_buf *(*export)(struct drm_gem_object *obj, int flags);
    int (*pin)(struct drm_gem_object *obj);
    void (*unpin)(struct drm_gem_object *obj);
    struct sg_table *(*get_sg_table)(struct drm_gem_object *obj);
    int (*vmap)(struct drm_gem_object *obj, struct iosys_map *map);
    void (*vunmap)(struct drm_gem_object *obj, struct iosys_map *map);
    int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);
    int (*evict)(struct drm_gem_object *obj);
    enum drm_gem_object_status (*status)(struct drm_gem_object *obj);
    size_t (*rss)(struct drm_gem_object *obj);
    const struct vm_operations_struct *vm_ops;
 };

πŸ¦‹ Members πŸ¦‹

🌟 free

Deconstructor for drm_gem_objects. that's the cleanup girlie, the one who takes out the trash on the way out πŸ—‘οΈ

This callback is mandatory. like, you literally cannot skip it, it's not optional, bestie 😭

🌟 open

Called upon GEM handle creation. new handle just dropped πŸ‘‘

This callback is optional.

🌟 close

Called upon GEM handle release. bye bestie, handle's gone 🫢

This callback is optional.

If your driver subclasses struct drm_gem_object, it can implement this optional hook for printing additional driver specific info. extra lore, driver edition πŸ“–

drm_printf_indent should be used in the callback, passing it the indent argument. don't freehand the indentation, that's the whole point ✨

This callback is called from drm_gem_print_info.

This callback is optional.

🌟 export

Export the backing buffer as a dma_buf. If this is not set, drm_gem_prime_export is used instead. so like, a fallback exists, slay πŸ’…

This callback is optional.

🌟 pin

Pin the backing buffer in memory, such that dma-buf importers can access it. Used by the drm_gem_map_attach helper. keep it in place, no moving, periodt 🧲

This callback is optional.

🌟 unpin

Unpin the backing buffer. Used by the drm_gem_map_detach helper. okay you can move again, freed πŸ¦‹

This callback is optional.

🌟 get_sg_table

Returns a Scatter-Gather table representation of the buffer. Used when exporting a buffer by the drm_gem_map_dma_buf helper.

Releasing is done by calling dma_unmap_sg_attrs and sg_free_table in drm_gem_unmap_buf, therefore these helpers and this callback here cannot be used for sg tables pointing at driver private memory ranges. like, read that twice, it's a real one ⚠️

See also drm_prime_pages_to_sg.

🌟 vmap

Returns a virtual address for the buffer. Used by the drm_gem_dmabuf_vmap helper. Called with a held GEM reservation lock. πŸ”’

This callback is optional.

🌟 vunmap

Releases the address previously returned by vmap. Used by the drm_gem_dmabuf_vunmap helper. Called with a held GEM reservation lock. πŸ”’

This callback is optional.

🌟 mmap

Handle mmap of the gem object, setup vma accordingly. it's giving memory-mapped main character energy πŸŽ€

This callback is optional.

The callback is used by both drm_gem_mmap_obj and drm_gem_prime_mmap. When mmap is present, vm_ops is not used β€” the mmap callback must set vma->vm_ops instead. pick one, bestie, don't do both 😀

🌟 evict

Evicts the gem object out from memory. Used by the drm_gem_object_evict helper. Returns 0 on success, -errno otherwise. Called with a held GEM reservation lock. πŸ”’

This callback is optional.

🌟 status

The optional status callback can return additional object state which determines which stats the object is counted against. The callback is called under table_lock. Racing against object status change is "harmless", and the callback can expect to not race against object destruction. so like, relax, the quote marks around "harmless" are doing a lot of work but you're fine πŸ’€

Called by drm_show_memory_stats.

🌟 rss

Return resident size of the object in physical memory. πŸ“

Called by drm_show_memory_stats.

🌟 vm_ops

Virtual memory operations used with mmap. πŸ—ΊοΈ

This is optional but necessary for mmap support. so like, optional in the same way a phone case is optional, iykyk πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./include/drm/drm_gem.h β€” and the whole friend group:


okay that's the whole page, you ate that 🫢 this little beauty lives in ./include/drm, dated October 2026, and it's filed under struct drm_gem_object_funcs(9) β€” go build something iconic with it, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from