first commit

This commit is contained in:
Florian RICHER 2024-09-30 22:56:08 +02:00
commit 2d40952aab
5 changed files with 308 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

231
Cargo.lock generated Normal file
View file

@ -0,0 +1,231 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "bytemuck"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "drm"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d000ffcf7a146ee52444a31b78ac82f981ebba5de6fb19f0b1052d98c8e5f308"
dependencies = [
"bitflags",
"bytemuck",
"drm-ffi",
"drm-fourcc",
"rustix",
]
[[package]]
name = "drm-ffi"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e41459d99a9b529845f6d2c909eb9adf3b6d2f82635ae40be8de0601726e8b"
dependencies = [
"drm-sys",
"rustix",
]
[[package]]
name = "drm-fourcc"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4"
[[package]]
name = "drm-sys"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bafb66c8dbc944d69e15cfcc661df7e703beffbaec8bd63151368b06c5f9858c"
dependencies = [
"libc",
"linux-raw-sys 0.6.5",
]
[[package]]
name = "drm_test"
version = "0.1.0"
dependencies = [
"anyhow",
"drm",
]
[[package]]
name = "errno"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "libc"
version = "0.2.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
[[package]]
name = "linux-raw-sys"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]]
name = "linux-raw-sys"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a385b1be4e5c3e362ad2ffa73c392e53f031eaa5b7d648e64cd87f27f6063d7"
[[package]]
name = "proc-macro2"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustix"
version = "0.38.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys 0.4.14",
"windows-sys",
]
[[package]]
name = "syn"
version = "2.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "drm_test"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.89"
drm = "0.14.0"

56
src/card.rs Normal file
View file

@ -0,0 +1,56 @@
use drm::Device;
use std::os::fd::{AsFd, BorrowedFd};
use std::fmt::Debug;
// A simple wrapper for a device node.
pub struct Card(std::fs::File);
/// Implementing [`AsFd`] is a prerequisite to implementing the traits found
/// in this crate. Here, we are just calling [`File::as_fd()`] on the inner
/// [`File`].
impl AsFd for Card {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}
/// Simple helper methods for opening a `Card`.
impl Card {
pub fn open(path: &str) -> anyhow::Result<Self> {
let mut options = std::fs::OpenOptions::new();
options.read(true);
options.write(true);
let file = options.open(path)?;
Ok(Card(file))
}
}
impl drm::Device for Card {}
impl Debug for Card {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Driver version: {:?}\n", self.get_driver())?;
writeln!(f, "BUS ID: {:?}\n", self.get_bus_id())?;
writeln!(f, "Driver capatibilities:")?;
writeln!(f, "\tDumpBuffer: {:?}", self.get_driver_capability(drm::DriverCapability::DumbBuffer).ok())?;
writeln!(f, "\tVBlankHighCRTC: {:?}", self.get_driver_capability(drm::DriverCapability::VBlankHighCRTC).ok())?;
writeln!(f, "\tDumbPreferredDepth: {:?}", self.get_driver_capability(drm::DriverCapability::DumbPreferredDepth).ok())?;
writeln!(f, "\tDumbPreferShadow: {:?}", self.get_driver_capability(drm::DriverCapability::DumbPreferShadow).ok())?;
writeln!(f, "\tPrime: {:?}", self.get_driver_capability(drm::DriverCapability::Prime).ok())?;
writeln!(f, "\tMonotonicTimestamp: {:?}", self.get_driver_capability(drm::DriverCapability::MonotonicTimestamp).ok())?;
writeln!(f, "\tASyncPageFlip: {:?}", self.get_driver_capability(drm::DriverCapability::ASyncPageFlip).ok())?;
writeln!(f, "\tAtomicASyncPageFlip: {:?}", self.get_driver_capability(drm::DriverCapability::AtomicASyncPageFlip).ok())?;
writeln!(f, "\tCursorWidth: {:?}", self.get_driver_capability(drm::DriverCapability::CursorWidth).ok())?;
writeln!(f, "\tCursorHeight: {:?}", self.get_driver_capability(drm::DriverCapability::CursorHeight).ok())?;
writeln!(f, "\tAddFB2Modifiers: {:?}", self.get_driver_capability(drm::DriverCapability::AddFB2Modifiers).ok())?;
writeln!(f, "\tPageFlipTarget: {:?}", self.get_driver_capability(drm::DriverCapability::PageFlipTarget).ok())?;
writeln!(f, "\tCRTCInVBlankEvent: {:?}", self.get_driver_capability(drm::DriverCapability::CRTCInVBlankEvent).ok())?;
writeln!(f, "\tSyncObj: {:?}", self.get_driver_capability(drm::DriverCapability::SyncObj).ok())?;
writeln!(f, "\tTimelineSyncObj: {:?}", self.get_driver_capability(drm::DriverCapability::TimelineSyncObj).ok())?;
Ok(())
}
}

12
src/main.rs Normal file
View file

@ -0,0 +1,12 @@
mod card;
fn main() {
let gpu = match card::Card::open("/dev/dri/card1") {
Ok(gpu) => gpu,
Err(err) => {
panic!("Impossible to open DRM file : {:?}", err);
}
};
println!("{:?}", gpu);
}