rust/kernel: Add faux device bindings
Subsystems (2)
PATCH v3 1/1 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.
---
V2:
* Check for NULL on return from device_create(), not a pointer error
* Rename Device to Registration to make its purpose more clear
* Drop platform device comment from crate docstring.
* Update MAINTAINERS
V3:
* Clarify safety comment around thread-safety
* Return ENODEV on failure from new()
* Add missing newline in faux driver sample
* s/crate/module/ in descriptions
* Add newline after faux module docstring
* Fix missing markdown in safety comments
* Add missing INVARIANT: comment in Registration
* s/Registration/faux::Registration/ in rust_driver_faux.rs
--- MAINTAINERS | 2 + rust/bindings/bindings_helper.h | 1 + rust/kernel/faux.rs | 67 ++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + samples/rust/Kconfig | 10 +++++ samples/rust/Makefile | 1 + samples/rust/rust_driver_faux.rs | 29 ++++++++++++++ 7 files changed, 111 insertions(+) create mode 100644 rust/kernel/faux.rs create mode 100644 samples/rust/rust_driver_faux.rs
MAINTAINERS +2 -0
@@ -7119,8 +7119,10 @@ F: rust/kernel/device.rs F: rust/kernel/device_id.rs F: rust/kernel/devres.rs F: rust/kernel/driver.rs +F: rust/kernel/faux.rs F: rust/kernel/platform.rs F: samples/rust/rust_driver_platform.rs +F: samples/rust/rust_driver_faux.rs DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS) M: Nishanth Menon <[email protected]>
rust/bindings/bindings_helper.h +1 -0
@@ -11,6 +11,7 @@#include <linux/blk_types.h> #include <linux/blkdev.h> #include <linux/cred.h> +#include <linux/device/faux.h> #include <linux/errname.h> #include <linux/ethtool.h> #include <linux/file.h>
rust/kernel/faux.rs new file +67 -0
67 lines not on this page · raw message
rust/kernel/lib.rs +1 -0
@@ -46,6 +46,7 @@pub mod devres;pub mod driver;pub mod error; +pub mod faux;#[cfg( CONFIG_RUST_FW_LOADER_ABSTRACTIONS )] pub mod firmware;pub mod fs;
samples/rust/Kconfig +10 -0
@@ -61,6 +61,16 @@ config SAMPLE_RUST_DRIVER_PLATFORM If unsure, say N. +config SAMPLE_RUST_DRIVER_FAUX + tristate "Faux Driver" + help + This option builds the Rust Faux driver sample. + + To compile this as a module, choose M here: + the module will be called rust_driver_faux. + + If unsure, say N. + config SAMPLE_RUST_HOSTPROGS bool "Host programs" help
samples/rust/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_SAMPLE_RUST_MISC_DEVICE) += rust_misc_device.o obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PCI) += rust_driver_pci.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM) += rust_driver_platform.o +obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) += rust_driver_faux.o rust_print-y := rust_print_main.o rust_print_events.o
samples/rust/rust_driver_faux.rs new file +29 -0
@@ -0,0 +1,29 @@ +// 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: &'staticThisModule ) ->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 }) + } +}
base-commit: 808eb958781e4ebb6e9c0962af2e856767e20f45
prerequisite-patch-id: f05ff916822e21eec452f9e5b8d11339c409265a
Signature · 1 line
2.48.1
Greg Kroah-Hartman
maintainerQuoted 11 lines · Lyude Paul
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 <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Maíra Canal <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Miguel Ojeda <[email protected]>
Quoted 15 lines
---
V2:
* Check for NULL on return fromdevice_create(), not a pointer error
* Rename Device to Registration to make its purpose more clear
* Drop platform device comment from crate docstring.
* UpdateMAINTAINERS
V3:
* Clarify safety comment around thread-safety
* Return ENODEV on failure fromnew()
* Add missing newline in faux driver sample
* s/crate/module/ in descriptions
* Add newline after faux module docstring
* Fix missing markdown in safety comments
* Add missing INVARIANT: comment in Registration
* s/Registration/faux::Registration/ inrust_driver_faux.rs
Thanks, I've taken this into my series and fixed up the api where I added a "parent" pointer. I'll send it out in a bit...
thanks,
greg k-h