STRUCT DRM_DEVICE(9)
π 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 devicedevcannot do DMA by itself, and it should beNULLotherwise. Calldrm_dev_dma_devto get the DMA device instead of touching this field directly, and calldrm_dev_set_dma_devto 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 thisdrm_deviceas tracked byref.managed.resourcesβ the managed resources list.managed.final_kfreeβ pointer for the finalkfreecall.managed.lockβ protectsmanaged.resources.
driverβ the DRM driver managing the device.dev_privateβ DRM driver private data. This is deprecated and should be left set toNULL. π©
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 withdrm_debugfs_add_file, and sysfs should be directly added on the hardware (and not the character device node)struct devicedev.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 bydrm_dev_registeranddrm_connector_register.masterβ the currently active master for this device. Protected bymaster_mutex.huge_mntβ huge tmpfs mountpoint used at GEM object initializationdrm_gem_object_init. Drivers can calldrm_gem_huge_mnt_createto create, mount and use it. The default tmpfs mountpoint (shm_mnt) is used ifNULL.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. Seedrm_dev_enteranddrm_dev_is_unplugged.anon_inodeβ inode for the private address-space.uniqueβ unique name of the device.master_mutexβ lock fordrm_minor.masteranddrm_file.is_master.open_countβ usage counter for outstanding files open, protected bydrm_global_mutex.filelist_mutexβ protectsfilelist.filelistβ list of userspace clients, linked throughdrm_file.lhead.filelist_internalβ list of open DRM files for in-kernel clients. Protected byfilelist_mutex.clientlist_mutexβ protectsclientlistaccess.clientlistβ list of in-kernel clients. Protected byclientlist_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 perstruct drm_crtc. For historical reasons (vblank support predates kernel modesetting) this is free-standing and not part ofstruct drm_crtcitself. It must be initialized explicitly by callingdrm_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-levelvblank_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β protectsvblank_event_listand event delivery in general. Seedrm_send_eventanddrm_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 thevga_switcheroo_client_ops.set_gpu_statecallback.fb_helperβ pointer to the fbdev emulation structure. Set bydrm_fb_helper_initand cleared bydrm_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
- 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