The DRM subsystem is accessed throughDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Smithay/drm-rs/llms.txt
Use this file to discover all available pages before exploring further.
ioctl calls on an open file descriptor that points to a device node — typically something like /dev/dri/card0. drm-rs does not open these nodes for you. Instead, you bring your own file descriptor by wrapping it in a type that implements AsFd, then implement the drm::Device trait on that wrapper to unlock the full drm-rs API.
This design lets you obtain the file descriptor however is most appropriate for your program — directly via std::fs::File, through a seat manager such as logind, or via udev.
Device nodes under
/dev/dri/ are typically owned by the video group (or managed by udev rules tied to seat ownership). If you open the node directly without a seat manager, make sure your user is a member of the video group. Alternatively, use a session manager such as logind or seatd, which will hand you an authenticated file descriptor without requiring group membership.Step 1 — Create a Card wrapper struct
The minimal wrapper needs astd::fs::File (or any type that is itself AsFd) and an AsFd implementation that delegates to it.
Step 2 — Implement drm::Device
drm::Device is a trait with no required methods; every method has a default implementation backed by the underlying ioctl. All you need is an empty impl block:
drm::control::Device the same way:
Step 3 — Open the device
Step 4 — Query driver information
Once you have aCard, you can inspect the kernel driver that manages the hardware:
get_driver() returns a Driver struct. Its name(), date(), and description() methods all return &OsStr, reflecting the fact that driver metadata may not always be valid UTF-8.
Step 5 — Set client capabilities
Client capabilities opt the process into newer kernel APIs. You must enable them before using features that depend on them:ClientCapability variants:
| Variant | Purpose |
|---|---|
Stereo3D | Expose stereo 3D display modes |
UniversalPlanes | Expose all hardware plane types |
Atomic | Enable the atomic commit API |
AspectRatio | Include aspect ratio data in mode info |
WritebackConnectors | Expose writeback connector objects (requires Atomic) |
CursorPlaneHotspot | Enable cursor hotspot properties (requires Atomic) |
Step 6 — Check driver capabilities
Driver capabilities are hardware or driver-level features you can query at runtime:DriverCapability variants:
| Variant | Purpose |
|---|---|
DumbBuffer | CPU-mappable dumb buffer allocation |
Prime | PRIME buffer sharing (dmabuf) |
ASyncPageFlip | Asynchronous page flips (legacy API) |
AtomicASyncPageFlip | Asynchronous page flips (atomic API) |
SyncObj | Binary sync object support |
TimelineSyncObj | Timeline sync object support |
AddFB2Modifiers | Framebuffer tiling modifiers |
CursorWidth / CursorHeight | Maximum cursor plane dimensions |
DRM Master lock
The DRM Master lock is the kernel-enforced exclusive right to perform modesetting on a device. It is granted automatically when you open a primary node (/dev/dri/cardN) — as long as no other process already holds it.
You can explicitly acquire and release the lock:
acquire_master_lock() requires CAP_SYS_ADMIN privileges (i.e. root) or that your process already owns the primary node via session management. If a display server is running and holds the lock, you must use a mechanism like logind’s TakeDevice D-Bus call to receive a properly authenticated descriptor instead of opening the node directly.