From: Dirk Behme <dirk.behme@gmail.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: gregkh@linuxfoundation.org, rafael@kernel.org,
bhelgaas@google.com, ojeda@kernel.org, alex.gaynor@gmail.com,
boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, tmgross@umich.edu,
a.hindborg@samsung.com, aliceryhl@google.com, airlied@gmail.com,
fujita.tomonori@gmail.com, lina@asahilina.net,
pstanner@redhat.com, ajanulgu@redhat.com, lyude@redhat.com,
robh@kernel.org, daniel.almeida@collabora.com,
saravanak@google.com, dirk.behme@de.bosch.com, j@jannau.net,
fabien.parent@linaro.org, chrisi.schrefl@gmail.com,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 13/13] samples: rust: add Rust platform sample driver
Date: Fri, 6 Dec 2024 10:29:29 +0100 [thread overview]
Message-ID: <417cebcb-6311-43c3-a74f-edef10be0fb7@gmail.com> (raw)
In-Reply-To: <Z1K22NjYjwhFnsit@pollux>
On 06.12.24 09:33, Danilo Krummrich wrote:
> On Thu, Dec 05, 2024 at 06:09:10PM +0100, Dirk Behme wrote:
>> Hi Danilo,
>>
>> On 05.12.24 15:14, Danilo Krummrich wrote:
>>> Add a sample Rust platform driver illustrating the usage of the platform
>>> bus abstractions.
>>>
>>> This driver probes through either a match of device / driver name or a
>>> match within the OF ID table.
>>>
>>> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
>>
>> Not a review comment, but a question/proposal:
>>
>> What do you think to convert the platform sample into an example/test?
>> And drop it in samples/rust then? Like [1] below?
>
> Generally, I think doctests are indeed preferrable. In this particular case
> though, I think it's better to have a sample module, since this way it can serve
> as go-to example of how to write a platform driver in Rust.
>
> Especially for (kernel) folks who do not have a Rust (for Linux) background it's
> way more accessible.
Yes, ack. Rob said the same :)
Thanks
Dirk
>> We would have (a) a complete example in the documentation and (b) some
>> (KUnit) test coverage and (c) have one patch less in the series and
>> (d) one file less to maintain long term.
>>
>> I think to remember that it was mentioned somewhere that a
>> documentation example / KUnit test is preferred over samples/rust (?).
>>
>> Just an idea :)
>>
>> Best regards
>>
>> Dirk
>>
>> [1]
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index ae576c842c51..365fc48b7041 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -7035,7 +7035,6 @@ F: rust/kernel/device_id.rs
>> F: rust/kernel/devres.rs
>> F: rust/kernel/driver.rs
>> F: rust/kernel/platform.rs
>> -F: samples/rust/rust_driver_platform.rs
>>
>> DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS)
>> M: Nishanth Menon <nm@ti.com>
>> diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
>> index 868cfddb75a2..77aeb6fc2120 100644
>> --- a/rust/kernel/platform.rs
>> +++ b/rust/kernel/platform.rs
>> @@ -142,30 +142,55 @@ macro_rules! module_platform_driver {
>> /// # Example
>> ///
>> ///```
>> -/// # use kernel::{bindings, c_str, of, platform};
>> +/// # mod mydriver {
>> +/// #
>> +/// # // Get this into the scope of the module to make the
>> assert_eq!() buildable
>> +/// # static __DOCTEST_ANCHOR: i32 = core::line!() as i32 - 4;
>> +/// #
>> +/// # use kernel::{c_str, of, platform, prelude::*};
>> +/// #
>> +/// struct MyDriver {
>> +/// pdev: platform::Device,
>> +/// }
>> ///
>> -/// struct MyDriver;
>> +/// struct Info(u32);
>> ///
>> /// kernel::of_device_table!(
>> /// OF_TABLE,
>> /// MODULE_OF_TABLE,
>> /// <MyDriver as platform::Driver>::IdInfo,
>> -/// [
>> -/// (of::DeviceId::new(c_str!("test,device")), ())
>> -/// ]
>> +/// [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
>> /// );
>> ///
>> /// impl platform::Driver for MyDriver {
>> -/// type IdInfo = ();
>> +/// type IdInfo = Info;
>> /// const OF_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)
>> +/// fn probe(pdev: &mut platform::Device, info:
>> Option<&Self::IdInfo>) -> Result<Pin<KBox<Self>>> {
>> +/// dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver
>> sample.\n");
>> +///
>> +/// assert_eq!(info.unwrap().0, 42);
>> +///
>> +/// let drvdata = KBox::new(Self { pdev: pdev.clone() },
>> GFP_KERNEL)?;
>> +///
>> +/// Ok(drvdata.into())
>> +/// }
>> +/// }
>> +///
>> +/// impl Drop for MyDriver {
>> +/// fn drop(&mut self) {
>> +/// dev_dbg!(self.pdev.as_ref(), "Remove Rust Platform driver
>> sample.\n");
>> /// }
>> /// }
>> +///
>> +/// kernel::module_platform_driver! {
>> +/// type: MyDriver,
>> +/// name: "rust_driver_platform",
>> +/// author: "Danilo Krummrich",
>> +/// description: "Rust Platform driver",
>> +/// license: "GPL v2",
>> +/// }
>> +/// # }
>> ///```
>> pub trait Driver {
>> /// The type holding information about each device id supported
>> by the driver.
>> diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig
>> index 70126b750426..6d468193cdd8 100644
>> --- a/samples/rust/Kconfig
>> +++ b/samples/rust/Kconfig
>> @@ -41,16 +41,6 @@ config SAMPLE_RUST_DRIVER_PCI
>>
>> If unsure, say N.
>>
>> -config SAMPLE_RUST_DRIVER_PLATFORM
>> - tristate "Platform Driver"
>> - help
>> - This option builds the Rust Platform driver sample.
>> -
>> - To compile this as a module, choose M here:
>> - the module will be called rust_driver_platform.
>> -
>> - If unsure, say N.
>> -
>> config SAMPLE_RUST_HOSTPROGS
>> bool "Host programs"
>> help
>> diff --git a/samples/rust/Makefile b/samples/rust/Makefile
>> index 761d13fff018..2f5b6bdb2fa5 100644
>> --- a/samples/rust/Makefile
>> +++ b/samples/rust/Makefile
>> @@ -4,7 +4,6 @@ ccflags-y += -I$(src) # needed for trace events
>> obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.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
>>
>> rust_print-y := rust_print_main.o rust_print_events.o
>>
>> diff --git a/samples/rust/rust_driver_platform.rs
>> b/samples/rust/rust_driver_platform.rs
>> deleted file mode 100644
>> index 2f0dbbe69e10..000000000000
>> --- a/samples/rust/rust_driver_platform.rs
>> +++ /dev/null
>> @@ -1,49 +0,0 @@
>> -// SPDX-License-Identifier: GPL-2.0
>> -
>> -//! Rust Platform driver sample.
>> -
>> -use kernel::{c_str, of, platform, prelude::*};
>> -
>> -struct SampleDriver {
>> - pdev: platform::Device,
>> -}
>> -
>> -struct Info(u32);
>> -
>> -kernel::of_device_table!(
>> - OF_TABLE,
>> - MODULE_OF_TABLE,
>> - <SampleDriver as platform::Driver>::IdInfo,
>> - [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
>> -);
>> -
>> -impl platform::Driver for SampleDriver {
>> - type IdInfo = Info;
>> - const OF_ID_TABLE: platform::IdTable<Self::IdInfo> = &OF_TABLE;
>> -
>> - fn probe(pdev: &mut platform::Device, info:
>> Option<&Self::IdInfo>) -> Result<Pin<KBox<Self>>> {
>> - dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n");
>> -
>> - if let Some(info) = info {
>> - dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n",
>> info.0);
>> - }
>> -
>> - let drvdata = KBox::new(Self { pdev: pdev.clone() },
>> GFP_KERNEL)?;
>> -
>> - Ok(drvdata.into())
>> - }
>> -}
>> -
>> -impl Drop for SampleDriver {
>> - fn drop(&mut self) {
>> - dev_dbg!(self.pdev.as_ref(), "Remove Rust Platform driver
>> sample.\n");
>> - }
>> -}
>> -
>> -kernel::module_platform_driver! {
>> - type: SampleDriver,
>> - name: "rust_driver_platform",
>> - author: "Danilo Krummrich",
>> - description: "Rust Platform driver",
>> - license: "GPL v2",
>> -}
>>
next prev parent reply other threads:[~2024-12-06 9:29 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 14:14 [PATCH v4 00/13] Device / Driver PCI / Platform Rust abstractions Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 01/13] rust: pass module name to `Module::init` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 02/13] rust: implement generic driver registration Danilo Krummrich
2024-12-06 13:57 ` Alice Ryhl
2024-12-06 18:13 ` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 03/13] rust: implement `IdArray`, `IdTable` and `RawDeviceId` Danilo Krummrich
2024-12-07 1:14 ` Fabien Parent
2024-12-09 10:45 ` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 04/13] rust: add rcu abstraction Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 05/13] rust: add `Revocable` type Danilo Krummrich
2024-12-06 15:11 ` Alice Ryhl
2024-12-09 10:40 ` Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 06/13] rust: add `io::{Io, IoRaw}` base types Danilo Krummrich
2024-12-06 14:13 ` Alice Ryhl
2024-12-11 14:52 ` Daniel Almeida
2024-12-05 14:14 ` [PATCH v4 07/13] rust: add devres abstraction Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 08/13] rust: pci: add basic PCI device / driver abstractions Danilo Krummrich
2024-12-06 14:01 ` Alice Ryhl
2024-12-09 10:44 ` Danilo Krummrich
2024-12-10 10:55 ` Alice Ryhl
2024-12-10 22:38 ` Danilo Krummrich
2024-12-11 13:06 ` Alice Ryhl
2024-12-11 14:32 ` Danilo Krummrich
2024-12-11 14:41 ` Greg KH
2024-12-11 14:42 ` Greg KH
2024-12-11 14:44 ` Alice Ryhl
2024-12-06 15:25 ` Alice Ryhl
2024-12-05 14:14 ` [PATCH v4 09/13] rust: pci: implement I/O mappable `pci::Bar` Danilo Krummrich
2024-12-06 10:44 ` Philipp Stanner
2024-12-05 14:14 ` [PATCH v4 10/13] samples: rust: add Rust PCI sample driver Danilo Krummrich
2024-12-05 14:14 ` [PATCH v4 11/13] rust: of: add `of::DeviceId` abstraction Danilo Krummrich
2024-12-09 21:22 ` Rob Herring
2024-12-05 14:14 ` [PATCH v4 12/13] rust: platform: add basic platform device / driver abstractions Danilo Krummrich
2024-12-09 22:37 ` Rob Herring
2024-12-09 23:13 ` Danilo Krummrich
2024-12-10 7:46 ` Greg KH
2024-12-10 9:34 ` Danilo Krummrich
2024-12-10 9:40 ` Greg KH
2024-12-05 14:14 ` [PATCH v4 13/13] samples: rust: add Rust platform sample driver Danilo Krummrich
2024-12-05 17:09 ` Dirk Behme
2024-12-05 18:03 ` Rob Herring
2024-12-06 6:39 ` Dirk Behme
2024-12-06 8:33 ` Danilo Krummrich
2024-12-06 9:29 ` Dirk Behme [this message]
2024-12-10 22:59 ` Rob Herring (Arm)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=417cebcb-6311-43c3-a74f-edef10be0fb7@gmail.com \
--to=dirk.behme@gmail.com \
--cc=a.hindborg@samsung.com \
--cc=airlied@gmail.com \
--cc=ajanulgu@redhat.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=chrisi.schrefl@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=dirk.behme@de.bosch.com \
--cc=fabien.parent@linaro.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=j@jannau.net \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=pstanner@redhat.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=saravanak@google.com \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).