pub trait Device: AsRawFd {
    fn acquire_master_lock(&self) -> Result<(), SystemError> { ... }
fn release_master_lock(&self) -> Result<(), SystemError> { ... }
fn generate_auth_token(&self) -> Result<AuthToken, SystemError> { ... }
fn authenticate_auth_token(
        token: AuthToken
    ) -> Result<(), SystemError> { ... }
fn set_client_capability(
        cap: ClientCapability,
        enable: bool
    ) -> Result<(), SystemError> { ... }
fn get_bus_id(&self) -> Result<BusID, SystemError> { ... }
fn authenticated(&self) -> Result<bool, SystemError> { ... }
fn get_driver_capability(
        cap: DriverCapability
    ) -> Result<u64, SystemError> { ... }
fn get_driver(&self) -> Result<Driver, SystemError> { ... } }
Expand description

This trait should be implemented by any object that acts as a DRM device. It is a prerequisite for using any DRM functionality.

This crate does not provide a concrete device object due to the various ways it can be implemented. The user of this crate is expected to implement it themselves and derive this trait as necessary. The example below demonstrates how to do this using a small wrapper.


extern crate drm;

use drm::Device;

use std::fs::File;
use std::fs::OpenOptions;

use std::os::unix::io::RawFd;
use std::os::unix::io::AsRawFd;

/// A simple wrapper for a device node.
struct Card(File);

/// Implementing [`AsRawFd`] is a prerequisite to implementing the traits found
/// in this crate. Here, we are just calling [`File::as_raw_fd()`] on the inner
/// [`File`].
impl AsRawFd for Card {
    fn as_raw_fd(&self) -> RawFd {

/// With [`AsRawFd`] implemented, we can now implement [`drm::Device`].
impl Device for Card {}

impl Card {
    /// Simple helper method for opening a [`Card`].
    fn open() -> Self {
        let mut options = OpenOptions::new();;

        // The normal location of the primary device node on Linux

Provided methods

Acquires the DRM Master lock for this process.


Acquiring the DRM Master is done automatically when the primary device node is opened. If you opened the primary device node and did not acquire the lock, another process likely has the lock.

This function is only available to processes with CAP_SYS_ADMIN privileges (usually as root)

Releases the DRM Master lock for another process to use.

👎 Deprecated:

Consider opening a render node instead.

Generates an AuthToken for this process.

Authenticates an AuthToken from another process.

Requests the driver to expose or hide certain capabilities. See ClientCapability for more information.

Gets the BusID of this device.

Check to see if our AuthToken has been authenticated by the DRM Master

Gets the value of a capability.

Possible errors: