rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Short Circuit simplest Rust driver that touches real hardware?
@ 2021-04-26 19:47 Sven Van Asbroeck
  2021-04-26 20:22 ` Miguel Ojeda
  2021-04-26 20:58 ` Geert Stappers
  0 siblings, 2 replies; 6+ messages in thread
From: Sven Van Asbroeck @ 2021-04-26 19:47 UTC (permalink / raw)
  To: rust-for-linux

(Is this the correct forum for this discussion? Should it go on
Rust-for-Linux's GitHub instead?)

Senior Linux people have expressed interest in seeing a Rust driver
that touches actual hardware. Nvme has been suggested as an excellent
candidate. But, that's going to be quite complex, and possibly a long
way off still.

Is there merit in "short circuiting" a Rust driver that touches actual
hardware? I.e. only do the minimum that's reasonably required, to
drive a trivial piece of hardware.

Suggestion:
1. implement `platform_device` in Rust, just enough to be `probe()`d
by the kernel, and receive a live `struct device *` - we should wrap
this pointer in a suitable Rust abstraction of course.
2. implement the simplest `IoMemBlock` in Rust. Since we have a live
`struct device *`, the `IoMemBlock` constructor can simply call
`devm_platform_get_and_ioremap_resource(our struct device *)` in C,
which will automatically use the right method to retrieve the `void
__iomem *`: devicetree, platform data, etc, we don't have to care.
3. use the `IoMemBlock` above to implement a trivial iomem-only driver
as a module. A few possible candidates:
* h/w random number generator in Raspberry Pi Zero: `brcm,bcm2835-rng`
* SoC thermal sensor in Raspberry Pi Zero: `brcm,bcm2835-thermal`
4. we don't have `hwrng` or `thermal_hwmon` devices in Rust yet, but
we could perhaps expose this as a `misc_device`, which is something we
already have. A single temp or randnum readout might do the trick.

The Raspberry Pi Zero can be purchased for $10. There is [QEMU
support](https://qemu.readthedocs.io/en/latest/system/arm/raspi.html)
for the peripherals above.

Feedback and ideas welcome !

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] Short Circuit simplest Rust driver that touches real hardware?
  2021-04-26 19:47 [RFC] Short Circuit simplest Rust driver that touches real hardware? Sven Van Asbroeck
@ 2021-04-26 20:22 ` Miguel Ojeda
  2021-04-26 20:58 ` Geert Stappers
  1 sibling, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2021-04-26 20:22 UTC (permalink / raw)
  To: Sven Van Asbroeck; +Cc: rust-for-linux

On Mon, Apr 26, 2021 at 9:48 PM Sven Van Asbroeck <thesven73@gmail.com> wrote:
>
> (Is this the correct forum for this discussion? Should it go on
> Rust-for-Linux's GitHub instead?)

(Yes! No, this is exactly the kind of discussion that should go in the
mailing list :)

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] Short Circuit simplest Rust driver that touches real hardware?
  2021-04-26 19:47 [RFC] Short Circuit simplest Rust driver that touches real hardware? Sven Van Asbroeck
  2021-04-26 20:22 ` Miguel Ojeda
@ 2021-04-26 20:58 ` Geert Stappers
  2021-04-26 21:11   ` Sven Van Asbroeck
  2021-04-27  6:49   ` Greg KH
  1 sibling, 2 replies; 6+ messages in thread
From: Geert Stappers @ 2021-04-26 20:58 UTC (permalink / raw)
  To: Sven Van Asbroeck, rust-for-linux

On Mon, Apr 26, 2021 at 03:47:59PM -0400, Sven Van Asbroeck wrote:
>         ...
> 2. implement the simplest `IoMemBlock` in Rust. Since we have a live
> `struct device *`, the `IoMemBlock` constructor can simply call
> `devm_platform_get_and_ioremap_resource(our struct device *)` in C,
> which will automatically use the right method to retrieve the `void
> __iomem *`: devicetree, platform data, etc, we don't have to care.
> 3. use the `IoMemBlock` above to implement a trivial iomem-only driver
> as a module. A few possible candidates:
> * h/w random number generator in Raspberry Pi Zero: `brcm,bcm2835-rng`
> * SoC thermal sensor in Raspberry Pi Zero: `brcm,bcm2835-thermal`
> 4. we don't have `hwrng` or `thermal_hwmon` devices in Rust yet, but
> we could perhaps expose this as a `misc_device`, which is something we
> already have. A single temp or randnum readout might do the trick.
> 
> The Raspberry Pi Zero can be purchased for $10. There is [QEMU
> support](https://qemu.readthedocs.io/en/latest/system/arm/raspi.html)
> for the peripherals above.
> 
> Feedback and ideas welcome !

Hope that hardware manufactures see this opportunity.  Because I fear that
this cool project might get botched due lack of knowledge on hardware.


Implementing kernel module for 8250 UART in Rust is something that
wouldn't get botched due lack of hardware knowledge.



Regarding
Geert Stappers
-- 
Silence is hard to parse

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] Short Circuit simplest Rust driver that touches real hardware?
  2021-04-26 20:58 ` Geert Stappers
@ 2021-04-26 21:11   ` Sven Van Asbroeck
  2021-04-27  8:17     ` Geert Stappers
  2021-04-27  6:49   ` Greg KH
  1 sibling, 1 reply; 6+ messages in thread
From: Sven Van Asbroeck @ 2021-04-26 21:11 UTC (permalink / raw)
  To: Geert Stappers; +Cc: rust-for-linux

Hi Geert,

On Mon, Apr 26, 2021 at 4:58 PM Geert Stappers <stappers@stappers.nl> wrote:
>
> Hope that hardware manufactures see this opportunity.  Because I fear that
> this cool project might get botched due lack of knowledge on hardware.
>

Thanks for your input. Would you be able to elaborate why we lack
knowledge on these Raspberry Pi peripherals? Take the rng. When
reading its driver here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/hw_random/bcm2835-rng.c?h=v5.12#n62

it appears to be the case that the h/w is setup by writing a value to
two registers (RNG_STATUS, RNG_CTRL). Random data can then be read by
monitoring RNG_STATUS followed by a read from RNG_DATA.

Should be as simple as they come, no? What am I missing?

>
> Implementing kernel module for 8250 UART in Rust is something that
> wouldn't get botched due lack of hardware knowledge.

That's true, but also much more complex. Doesn't it depend on clocks
and interrupts? That's infrastructure we don't yet have in Rust.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] Short Circuit simplest Rust driver that touches real hardware?
  2021-04-26 20:58 ` Geert Stappers
  2021-04-26 21:11   ` Sven Van Asbroeck
@ 2021-04-27  6:49   ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-04-27  6:49 UTC (permalink / raw)
  To: Geert Stappers; +Cc: Sven Van Asbroeck, rust-for-linux

On Mon, Apr 26, 2021 at 10:58:10PM +0200, Geert Stappers wrote:
> On Mon, Apr 26, 2021 at 03:47:59PM -0400, Sven Van Asbroeck wrote:
> >         ...
> > 2. implement the simplest `IoMemBlock` in Rust. Since we have a live
> > `struct device *`, the `IoMemBlock` constructor can simply call
> > `devm_platform_get_and_ioremap_resource(our struct device *)` in C,
> > which will automatically use the right method to retrieve the `void
> > __iomem *`: devicetree, platform data, etc, we don't have to care.
> > 3. use the `IoMemBlock` above to implement a trivial iomem-only driver
> > as a module. A few possible candidates:
> > * h/w random number generator in Raspberry Pi Zero: `brcm,bcm2835-rng`
> > * SoC thermal sensor in Raspberry Pi Zero: `brcm,bcm2835-thermal`
> > 4. we don't have `hwrng` or `thermal_hwmon` devices in Rust yet, but
> > we could perhaps expose this as a `misc_device`, which is something we
> > already have. A single temp or randnum readout might do the trick.
> > 
> > The Raspberry Pi Zero can be purchased for $10. There is [QEMU
> > support](https://qemu.readthedocs.io/en/latest/system/arm/raspi.html)
> > for the peripherals above.
> > 
> > Feedback and ideas welcome !
> 
> Hope that hardware manufactures see this opportunity.  Because I fear that
> this cool project might get botched due lack of knowledge on hardware.
> 
> 
> Implementing kernel module for 8250 UART in Rust is something that
> wouldn't get botched due lack of hardware knowledge.

Uarts are anything but simple, sorry, look at how "big" the kernel
driver is in C for the 8250 support.

And yes, I recommend doing a "simple" driver that touches the hardware,
there's no reason not to duplicate one of the existing C drivers, in
fact, it makes more sense so that people can help understand the
comparison between the ways the two languages will work.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] Short Circuit simplest Rust driver that touches real hardware?
  2021-04-26 21:11   ` Sven Van Asbroeck
@ 2021-04-27  8:17     ` Geert Stappers
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Stappers @ 2021-04-27  8:17 UTC (permalink / raw)
  To: Sven Van Asbroeck, rust-for-linux


Hi Sven,
Hi Rust for Linux people,

 
On Mon, Apr 26, 2021 at 05:11:54PM -0400, Sven Van Asbroeck wrote:
> On Mon, Apr 26, 2021 at 4:58 PM Geert Stappers wrote:
> > On Mon, Apr 26, 2021, Sven Van Asbroeck wrote:
> > }
> > }   ... one specific piece of hardware ...
> > }
> >
> > Hope that hardware manufactures see this opportunity.  Because I fear that
> > this cool project might get botched due lack of knowledge on hardware.
> >
> 
> Thanks for your input. Would you be able to elaborate why we lack
> knowledge on these Raspberry Pi peripherals?

Hearsay "Broadcom doesn't provide hardware documentation".


> Take the rng. When reading its driver here:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/char/hw_random/bcm2835-rng.c?h=v5.12#n62
> 

Header of the file

  // SPDX-License-Identifier: GPL-2.0
  /*
   * Copyright (c) 2010-2012 Broadcom. All rights reserved.
   * Copyright (c) 2013 Lubomir Rintel
   */


not the same as a datasheet or other hardware information.

Lets call it "the best we have"    :-/


> it appears to be the case that the h/w is setup by writing a value to
> two registers (RNG_STATUS, RNG_CTRL). Random data can then be read by
> monitoring RNG_STATUS followed by a read from RNG_DATA.
> 
> Should be as simple as they come, no? What am I missing?
 
I can't tell how much those questions are rhetorical. So my guidance is

    People who say it cannot be done
    should not interrupt those who are doing it.


> > Implementing kernel module for 8250 UART in Rust is something that
> > wouldn't get botched due lack of hardware knowledge.
> 
> That's true, but also much more complex. Doesn't it depend on clocks
> and interrupts? That's infrastructure we don't yet have in Rust.

Which make this project such an interesting project.

 
Groeten
Geert Stappers
-- 
Silence is hard to parse

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-27  8:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 19:47 [RFC] Short Circuit simplest Rust driver that touches real hardware? Sven Van Asbroeck
2021-04-26 20:22 ` Miguel Ojeda
2021-04-26 20:58 ` Geert Stappers
2021-04-26 21:11   ` Sven Van Asbroeck
2021-04-27  8:17     ` Geert Stappers
2021-04-27  6:49   ` Greg KH

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox