STRUCT DRM_DEVICE(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– struct drm_device β€” NAME ✨

Okay bestie, so struct drm_device(9) is the DRM device structure β€” the whole big-deal data structure for a DRM card. This page lives in the Kernel API Manual and honestly it's giving "backstage pass to the graphics stack" energy. Let's get into it πŸ’…


🌸 SYNOPSIS 🌸

struct drm_device {
    int if_version;
    struct kref ref;
    struct device *dev;
    struct device *dma_dev;
    struct {
      struct list_head resources;
      void *final_kfree;
      spinlock_t lock;
    } managed;
    const struct drm_driver *driver;
    void *dev_private;
    struct drm_minor *primary;
    struct drm_minor *render;
    struct drm_minor *accel;
    bool registered;
    struct drm_master *master;
  #ifdef CONFIG_TRANSPARENT_HUGEPAGE;
    struct vfsmount *huge_mnt;
  #endif;
    u32 driver_features;
    bool unplugged;
    struct inode *anon_inode;
    char *unique;
    struct mutex master_mutex;
    atomic_t open_count;
    struct mutex filelist_mutex;
    struct list_head filelist;
    struct list_head filelist_internal;
    struct mutex clientlist_mutex;
    struct list_head clientlist;
    struct list_head client_sysrq_list;
    bool vblank_disable_immediate;
    struct drm_vblank_crtc *vblank;
    spinlock_t vblank_time_lock;
    spinlock_t vbl_lock;
    u32 max_vblank_count;
    struct list_head vblank_event_list;
    spinlock_t event_lock;
    unsigned int num_crtcs;
    struct drm_mode_config mode_config;
    struct mutex object_name_lock;
    struct idr object_name_idr;
    struct drm_vma_offset_manager *vma_offset_manager;
    struct drm_vram_mm *vram_mm;
    enum switch_power_state switch_power_state;
    struct drm_fb_helper *fb_helper;
    struct dentry *debugfs_root;
    struct mutex gem_lru_mutex;
};

πŸŽ€ Members πŸŽ€

Time for the member-by-member tour, bestie. Grab a snack πŸ“

  • if_version β€” the highest interface version that's been set.
  • ref β€” the object ref-count. Classic refcount moment.
  • dev β€” the device structure of the bus-device.
  • dma_dev β€” the device used for DMA operations. Lowkey only required if the device dev cannot do DMA by itself, and it should be NULL otherwise. Call drm_dev_dma_dev to get the DMA device instead of touching this field directly, and call drm_dev_set_dma_dev to set it.

So like, DRM devices are sometimes bound to virtual devices that can't perform DMA on their own β€” drivers should point this field at the respective DMA controller. 😌

Devices on USB and other peripheral busses also can't perform DMA by themselves, so dma_dev should point at the bus controller that does DMA on behalf of such a device. Required for importing buffers via dma-buf. πŸ¦‹

If it's set, the DRM core automatically releases the reference on the device. No cap.

  • managed β€” managed resources, linked to the lifetime of this drm_device as tracked by ref.
    • managed.resources β€” the managed resources list.
    • managed.final_kfree β€” pointer for the final kfree call.
    • managed.lock β€” protects managed.resources.
  • driver β€” the DRM driver managing the device.
  • dev_private β€” DRM driver private data. This is deprecated and should be left set to NULL. 🚩

Instead of using this pointer, it's recommended that drivers use devm_drm_dev_alloc and embed struct drm_device in their larger per-device structure. That's the move, fr fr.

  • primary β€” the Primary node. Drivers should not interact with this directly. debugfs interfaces can be registered with drm_debugfs_add_file, and sysfs should be directly added on the hardware (and not the character device node) struct device dev.
  • render β€” the Render node. Drivers should not interact with this directly, ever. Drivers should not expose any additional interfaces in debugfs or sysfs on this node. Like, at all. πŸ’€
  • accel β€” the Compute Acceleration node.
  • registered β€” internally used by drm_dev_register and drm_connector_register.
  • master β€” the currently active master for this device. Protected by master_mutex.
  • huge_mnt β€” huge tmpfs mountpoint used at GEM object initialization drm_gem_object_init. Drivers can call drm_gem_huge_mnt_create to create, mount and use it. The default tmpfs mountpoint (shm_mnt) is used if NULL.
  • driver_features β€” per-device driver features.

Drivers can clear specific flags here to disallow certain features on a per-device basis while still sharing a single struct drm_driver instance across all devices. Obsessed with the efficiency tbh ✨

  • unplugged β€” flag to tell if the device has been unplugged. See drm_dev_enter and drm_dev_is_unplugged.
  • anon_inode β€” inode for the private address-space.
  • unique β€” unique name of the device.
  • master_mutex β€” lock for drm_minor.master and drm_file.is_master.
  • open_count β€” usage counter for outstanding files open, protected by drm_global_mutex.
  • filelist_mutex β€” protects filelist.
  • filelist β€” list of userspace clients, linked through drm_file.lhead.
  • filelist_internal β€” list of open DRM files for in-kernel clients. Protected by filelist_mutex.
  • clientlist_mutex β€” protects clientlist access.
  • clientlist β€” list of in-kernel clients. Protected by clientlist_mutex.
  • client_sysrq_list β€” entry into the list of devices registered for sysrq. Allows in-kernel clients on this device to handle sysrq keys.
  • vblank_disable_immediate β€” if true, the vblank interrupt will be disabled immediately when the refcount drops to zero, instead of via the vblank disable timer.

This can be set to true if the hardware has a working vblank counter with high-precision timestamping (otherwise there are races 😭) and the driver uses drm_crtc_vblank_on and drm_crtc_vblank_off appropriately. Also, see max_vblank_count, drm_crtc_funcs.get_vblank_counter and drm_vblank_crtc_config.disable_immediate.

  • vblank β€” array of vblank tracking structures, one per struct drm_crtc. For historical reasons (vblank support predates kernel modesetting) this is free-standing and not part of struct drm_crtc itself. It must be initialized explicitly by calling drm_vblank_init.
  • vblank_time_lock β€” protects vblank count and time updates during vblank enable/disable.
  • vbl_lock β€” top-level vblank references lock, wraps the low-level vblank_time_lock.
  • max_vblank_count β€” maximum value of the vblank registers. This value +1 will result in a wrap-around of the vblank register. It's used by the vblank core to handle wrap-arounds.

If set to zero, the vblank core will try to guess the elapsed vblanks between times when the vblank interrupt is disabled, using high-precision timestamps. That approach is suffering from small races and imprecision over longer time periods, hence exposing a hardware vblank counter is always recommended. πŸ‘‘

This is the statically configured device-wide maximum. The driver can instead choose to use a runtime configurable per-crtc value drm_vblank_crtc.max_vblank_count, in which case max_vblank_count must be left at zero. See drm_crtc_set_max_vblank_count on how to use the per-crtc value.

If non-zero, drm_crtc_funcs.get_vblank_counter must be set.

  • vblank_event_list β€” list of vblank events.
  • event_lock β€” protects vblank_event_list and event delivery in general. See drm_send_event and drm_send_event_locked.
  • num_crtcs β€” number of CRTCs on this device.
  • mode_config β€” current mode config.
  • object_name_lock β€” GEM information.
  • object_name_idr β€” GEM information.
  • vma_offset_manager β€” GEM information.
  • vram_mm β€” VRAM MM memory manager.
  • switch_power_state β€” power state of the client. Used by drivers supporting the switcheroo driver. The state is maintained in the vga_switcheroo_client_ops.set_gpu_state callback.
  • fb_helper β€” pointer to the fbdev emulation structure. Set by drm_fb_helper_init and cleared by drm_fb_helper_fini.
  • debugfs_root β€” root directory for debugfs files.
  • gem_lru_mutex β€” lock protecting movement of GEM objects between LRUs.

πŸ¦‹ Description πŸ¦‹

This structure represents a complete card that may contain multiple heads. Main character energy, honestly 🫢


⭐ SEE ALSO ⭐

Kernel file ./include/drm/drm_device.h β€” plus struct drm_wedge_task_info(9), enum switch_power_state(9), drm_dev_dma_dev(9). Go read those too, bestie, iykyk πŸ’œ


That's the whole vibe check! Source path ./include/drm, dated October 2026, from the Kernel API Manual. Slay, go forth and initialize your vblanks correctly πŸ’…βœ¨πŸŽ€
πŸ“¦ where this page comes from