lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ab0252ff-b2a1-4e59-96f7-134e4e38be5c@de.bosch.com>
Date: Mon, 28 Oct 2024 14:44:01 +0100
From: Dirk Behme <dirk.behme@...bosch.com>
To: Danilo Krummrich <dakr@...nel.org>, <gregkh@...uxfoundation.org>,
	<rafael@...nel.org>, <bhelgaas@...gle.com>, <ojeda@...nel.org>,
	<alex.gaynor@...il.com>, <boqun.feng@...il.com>, <gary@...yguo.net>,
	<bjorn3_gh@...tonmail.com>, <benno.lossin@...ton.me>, <tmgross@...ch.edu>,
	<a.hindborg@...sung.com>, <aliceryhl@...gle.com>, <airlied@...il.com>,
	<fujita.tomonori@...il.com>, <lina@...hilina.net>, <pstanner@...hat.com>,
	<ajanulgu@...hat.com>, <lyude@...hat.com>, <robh@...nel.org>,
	<daniel.almeida@...labora.com>, <saravanak@...gle.com>
CC: <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
	<linux-pci@...r.kernel.org>, <devicetree@...r.kernel.org>
Subject: Re: [PATCH v3 15/16] rust: platform: add basic platform device /
 driver abstractions

On 22.10.2024 23:31, Danilo Krummrich wrote:
> Implement the basic platform bus abstractions required to write a basic
> platform driver. This includes the following data structures:
> 
> The `platform::Driver` trait represents the interface to the driver and
> provides `pci::Driver::probe` for the driver to implement.
> 
> The `platform::Device` abstraction represents a `struct platform_device`.
> 
> In order to provide the platform bus specific parts to a generic
> `driver::Registration` the `driver::RegistrationOps` trait is implemented
> by `platform::Adapter`.
> 
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
...
> diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
> new file mode 100644
> index 000000000000..addf5356f44f
> --- /dev/null
> +++ b/rust/kernel/platform.rs
...
> +/// IdTable type for platform drivers.
> +pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<of::DeviceId, T>;
> +
> +/// The platform driver trait.
> +///
> +/// # Example
> +///
> +///```
> +/// # use kernel::{bindings, c_str, of, platform};
> +///
> +/// struct MyDriver;
> +///
> +/// kernel::of_device_table!(
> +///     OF_TABLE,
> +///     MODULE_OF_TABLE,
> +///     <MyDriver as platform::Driver>::IdInfo,
> +///     [
> +///         (of::DeviceId::new(c_str!("redhat,my-device")), ())
> +///     ]
> +/// );
> +///
> +/// impl platform::Driver for MyDriver {
> +///     type IdInfo = ();
> +///     const ID_TABLE: platform::IdTable<Self::IdInfo> = &OF_TABLE;
> +///
> +///     fn probe(
> +///         _pdev: &mut platform::Device,
> +///         _id_info: Option<&Self::IdInfo>,
> +///     ) -> Result<Pin<KBox<Self>>> {
> +///         Err(ENODEV)
> +///     }
> +/// }
> +///```


Just in case it helps, having CONFIG_OF_UNITTEST with Rob's device tree 
add ons enabled adding something like [1] makes this example not compile 
only, but being executed as well:

...
rust_example_platform_driver testcase-data:platform-tests:test-device@2: 
Rust example platform driver probe() called.
...
# rust_doctest_kernel_platform_rs_0.location: rust/kernel/platform.rs:114
ok 63 rust_doctest_kernel_platform_rs_0
...

Best regards

Dirk

[1]

diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index addf5356f44f..a926233a789f 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -112,7 +112,8 @@ macro_rules! module_platform_driver {
  /// # Example
  ///
  ///```
-/// # use kernel::{bindings, c_str, of, platform};
+/// # mod module_example_platform_driver {
+/// # use kernel::{bindings, c_str, of, platform, prelude::*};
  ///
  /// struct MyDriver;
  ///
@@ -121,7 +122,7 @@ macro_rules! module_platform_driver {
  ///     MODULE_OF_TABLE,
  ///     <MyDriver as platform::Driver>::IdInfo,
  ///     [
-///         (of::DeviceId::new(c_str!("redhat,my-device")), ())
+///         (of::DeviceId::new(c_str!("test,rust-device")), ())
  ///     ]
  /// );
  ///
@@ -130,12 +131,22 @@ macro_rules! module_platform_driver {
  ///     const ID_TABLE: platform::IdTable<Self::IdInfo> = &OF_TABLE;
  ///
  ///     fn probe(
-///         _pdev: &mut platform::Device,
+///         pdev: &mut platform::Device,
  ///         _id_info: Option<&Self::IdInfo>,
  ///     ) -> Result<Pin<KBox<Self>>> {
+///         dev_info!(pdev.as_ref(), "Rust example platform driver 
probe() called.\n");
  ///         Err(ENODEV)
  ///     }
  /// }
+///
+/// kernel::module_platform_driver! {
+///     type: MyDriver,
+///     name: "rust_example_platform_driver",
+///     author: "Danilo Krummrich",
+///     description: "Rust example platform driver",
+///     license: "GPL v2",
+/// }
+/// # }
  ///```
  /// Drivers must implement this trait in order to get a platform 
driver registered. Please refer to
  /// the `Adapter` documentation for an example.



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ