1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/samples/rust/rust_driver_faux.rs
Lyude Paul 78418f300d rust/kernel: Add faux device bindings
This introduces a module for working with faux devices in rust, along with
adding sample code to show how the API is used. Unlike other types of
devices, we don't provide any hooks for device probe/removal - since these
are optional for the faux API and are unnecessary in rust.

Signed-off-by: Lyude Paul <lyude@redhat.com>
Cc: Maíra Canal <mairacanal@riseup.net>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/2025021026-exert-accent-b4c6@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-02-13 16:58:58 +01:00

29 lines
666 B
Rust

// SPDX-License-Identifier: GPL-2.0-only
//! Rust faux device sample.
use kernel::{c_str, faux, prelude::*, Module};
module! {
type: SampleModule,
name: "rust_faux_driver",
author: "Lyude Paul",
description: "Rust faux device sample",
license: "GPL",
}
struct SampleModule {
_reg: faux::Registration,
}
impl Module for SampleModule {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Initialising Rust Faux Device Sample\n");
let reg = faux::Registration::new(c_str!("rust-faux-sample-device"))?;
dev_info!(reg.as_ref(), "Hello from faux device!\n");
Ok(Self { _reg: reg })
}
}