On Tue, Jun 30, 2026 at 06:04:45PM -0300, Breno Rodrigues Alves wrote:
> This patch introduces an automated indexed state mechanism to optimize
> VRAM latency and command loops for the Radeon RX 580 architecture.
> Additionally, it provides a converted C-to-Rust sample char driver.
>
> Signed-off-by: Breno Rodrigues Alves <[email protected]>
> ---
> Documentation/rust/alves_guidelines.rst | 3 ++
> drivers/char/Kconfig | 7 +++++
> drivers/char/alves_char_dev.rs | 31 +++++++++++++++++++
> drivers/gpu/drm/amd/amdgpu/Makefile | 1 +
> drivers/gpu/drm/amd/amdgpu/alves_core.rs | 38 ++++++++++++++++++++++++
> 5 files changed, 80 insertions(+)
> create mode 100644 Documentation/rust/alves_guidelines.rst
> create mode 100644 drivers/char/alves_char_dev.rs
> create mode 100644 drivers/gpu/drm/amd/amdgpu/alves_core.rs
>
> diff --git a/Documentation/rust/alves_guidelines.rst
> b/Documentation/rust/alves_guidelines.rst
> new file mode 100644
> index 000000000..f6afa63de
> --- /dev/null
> +++ b/Documentation/rust/alves_guidelines.rst
> @@ -0,0 +1,3 @@
> +# Rust for Linux - Core Guidelines
> +- Style: Linear, pragmatic, flat, Linus Torvalds style.
> +- Constraints: Zero-cost abstractions, strict RAII, no binary bloat.
> diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
> index 9865227af..ace4df826 100644
> --- a/drivers/char/Kconfig
> +++ b/drivers/char/Kconfig
> @@ -372,3 +372,10 @@ config ADI
> driver include crash and makedumpfile.
>
> endmenu
> +config ALVES_CHAR_DEV
> + tristate "Alves C-to-Rust Character Device Driver"
> + depends on RUST
> + help
> + This is a character device driver migrated from C to Rust.
> + It acts as a core showcase of 2% module conversions.
> + Say Y or M here if you want to test the Rust infrastructure.
> diff --git a/drivers/char/alves_char_dev.rs b/drivers/char/alves_char_dev.rs
> new file mode 100644
> index 000000000..5ccb80ea4
> --- /dev/null
> +++ b/drivers/char/alves_char_dev.rs
> @@ -0,0 +1,31 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +//! Simple Character Device converted from legacy C to Rust using core
> Miscdev API.
Where is the original C code?
And what is going to interact with this in userspace? And how?
> +
> +use kernel::prelude::*;
> +use kernel::miscdev;
> +
> +module! {
> + type: AlvesCharDevice,
> + name: "alves_char_dev",
> + author: "Breno Rodrigues Alves",
> + description: "Pragmatic C-to-Rust converted character device driver",
> + license: "GPL OR MIT",
> +}
> +
> +struct AlvesCharDevice {
> + _dev: miscdev::Registration<AlvesCharDevice>,
> +}
> +
> +#[vtable]
> +impl miscdev::Options for AlvesCharDevice {
> + const NAME: \&"static CStr = c_str!("alves_char_dev");
> +}
> +
> +impl kernel::Module for AlvesCharDevice {
> + fn init(module: \&"static ThisModule) -> Result<Self> {
> + pr_info!("Alves C-to-Rust module initialized successfully
> +");
> + let dev = miscdev::Registration::new_reg(module)?;
> + Ok(AlvesCharDevice { _dev: dev })
> + }
> +}
This code doesn't actually do anything at all, how was it tested?
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index ba80542ea..b9f98c3e4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -349,3 +349,4 @@ include $(AMD_GPU_RAS_FULL_PATH)/Makefile
> amdgpu-y += $(AMD_GPU_RAS_FILES)
>
> obj-$(CONFIG_DRM_AMDGPU)+= amdgpu.o
> +amdgpu-y += alves_core.o
> diff --git a/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> new file mode 100644
> index 000000000..aa436763e
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> @@ -0,0 +1,38 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +//! AMDGPU RX 580 State Optimization Engine (Turing-inspired state machine)
> +//!
> +//! Copyright (C) 2026 Breno Rodrigues Alves.
> +
> +use kernel::prelude::*;
> +
> +#[derive(Copy, Clone, PartialEq, Eq)]
> +#[repr(u8)]
> +enum GpuState {
> + Idling = 0,
> + LowPower = 1,
> + ComputeActive = 2,
> + VramMaxPerf = 3,
> +}
> +
> +struct Rx580Engine {
> + current_state: GpuState,
> +}
> +
> +impl Rx580Engine {
> + fn transition(&mut self, symbol: u8) {
> + self.current_state = match (self.current_state, symbol) {
> + (GpuState::Idling, 0x01) => GpuState::LowPower,
> + (GpuState::LowPower, 0x02) => GpuState::ComputeActive,
> + (GpuState::ComputeActive, 0x03) => GpuState::VramMaxPerf,
> + (GpuState::VramMaxPerf, 0x00) => GpuState::Idling,
> + (state, _) => state,
> + };
> + }
> +}
> +
> +#[no_mangle]
> +pub extern "C" fn amdgpu_rust_rx580_optimize(register_sample: u32) {
> + let mut engine = Rx580Engine { current_state: GpuState::Idling };
> + let symbol = (register_sample \& 0xFF) as u8;
> + engine.transition(symbol);
> +}
Same here, this code doesn't do anything that I can tell. How was it
tested?
confused,
greg k-h