Skip to content

Commit

Permalink
Add minimal platform driver for bcm2835-rng
Browse files Browse the repository at this point in the history
Implements the bare minimum for a platform driver to register
itself with the core. It won't be able to do anything, except
show up in sysfs.

Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
  • Loading branch information
Sven Van Asbroeck committed May 18, 2021
1 parent af25e4e commit b136c6a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions drivers/char/hw_random/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ config HW_RANDOM_BCM2835

If unsure, say Y.

config HW_RANDOM_BCM2835_RUST
tristate "Rust implementation of Broadcom BCM2835 Random Number Generator"
depends on HAS_RUST && ARCH_BCM2835
help
This driver provides alternative Rust-based kernel-side support
for the Random Number Generator hardware found on the Broadcom
BCM2835 SoC.

To compile this driver as a module, choose M here: the
module will be called bcm2835_rng_rust

If unsure, say N.

config HW_RANDOM_IPROC_RNG200
tristate "Broadcom iProc/STB RNG200 support"
depends on ARCH_BCM_IPROC || ARCH_BCM2835 || ARCH_BRCMSTB
Expand Down
1 change: 1 addition & 0 deletions drivers/char/hw_random/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ obj-$(CONFIG_HW_RANDOM_PSERIES) += pseries-rng.o
obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o
obj-$(CONFIG_HW_RANDOM_HISI) += hisi-rng.o
obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
obj-$(CONFIG_HW_RANDOM_BCM2835_RUST) += bcm2835_rng_rust.o
obj-$(CONFIG_HW_RANDOM_IPROC_RNG200) += iproc-rng200.o
obj-$(CONFIG_HW_RANDOM_ST) += st-rng.o
obj-$(CONFIG_HW_RANDOM_XGENE) += xgene-rng.o
Expand Down
31 changes: 31 additions & 0 deletions drivers/char/hw_random/bcm2835_rng_rust.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-2.0

//! Broadcom BCM2835 Random Number Generator support.
#![no_std]
#![feature(allocator_api, global_asm)]

use alloc::boxed::Box;
use core::pin::Pin;
use kernel::prelude::*;
use kernel::{cstr, platdev};

module! {
type: RngModule,
name: b"bcm2835_rng_rust",
author: b"Rust for Linux Contributors",
description: b"BCM2835 Random Number Generator (RNG) driver",
license: b"GPL v2",
}

struct RngModule {
_pdev: Pin<Box<platdev::Registration>>,
}

impl KernelModule for RngModule {
fn init() -> Result<Self> {
let pdev = platdev::Registration::new_pinned(cstr!("bcm2835-rng-rust"), &THIS_MODULE)?;

Ok(RngModule { _pdev: pdev })
}
}

0 comments on commit b136c6a

Please sign in to comment.