All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Add Rust abstractions for nvmem-provider
@ 2026-02-04  4:04 Link Mauve
  2026-02-04  4:04 ` [PATCH v2 1/4] rust: io: Add big-endian read and write functions Link Mauve
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Link Mauve @ 2026-02-04  4:04 UTC (permalink / raw)
  To: rust-for-linux
  Cc: Link Mauve, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy (CS GROUP), Srinivas Kandagatla,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Ard Biesheuvel,
	Martin K. Petersen, Eric Biggers, Greg Kroah-Hartman, Lyude Paul,
	Asahi Lina, Viresh Kumar, Lorenzo Stoakes, Tamir Duberstein,
	FUJITA Tomonori, linuxppc-dev, linux-kernel, officialTechflashYT,
	Ash Logan, Roberto Van Eeden, Jonathan Neuschäfer

Hi, this is my first foray in Rust in the kernel!  I’m fairly used to
both Rust and the kernel, but not yet to both at the same time.

I wanted to try something simple before jumping to more advanced stuff
like DRM or V4L2 drivers, so I set on rewriting one of my old Wii
drivers in Rust.

I made sure there was no unsafe anywhere in the driver, and tried to
keep it to as few places as possible in the nvmem abstraction.

I’ve tested it on a Wii, using a downstream branch[1], plus the PowerPC
support patch[2], plus a terrible patch to make libcore not use integer
division on u64 or u128[3].  I’ve tested that the data I get out of this
driver result to the same data as the previous C driver.

Thanks for your time!

[1] https://github.com/Wii-Linux/wii-linux-ngx/commits/wii-mainline
[2] https://lore.kernel.org/rust-for-linux/20260204030507.8203-1-linkmauve@linkmauve.fr/T/
[3] https://linkmauve.fr/files/0001-XXX-Unimplement-core-fmt-on-u64-u128-and-Duration.patch

Changes since v1:
- Add Rust helpers to read and write as big endian.
- Set CONFIG_RUST=y in the Wii defconfig.
- Drop the patch to document nvmem-provider.h, this can go in a latter
  series.

In the nvmem abstractions:
- Replace as pointer casts with .cast(), .cast_const() and .cast_mut().
- Replace NvmemConfig::set_*() with NvmemConfig::with_*() to allow the
  builder pattern.
- Expose devm_nvmem_register() on Device instead of in NvmemConfig,
  making it both more correct and more evident coming from C.
- Make it set priv, reg_read and reg_write, as those are managed by the
  abstraction.

In the nintendo-otp driver:
- Add missing RUST depends
- Remove unnecessary reference to pdev in the driver.
- Simplify the loop using while let instead of break.
- Remove unnecessary Drop impl.
- Adapt to the NvmemConfig changes.
- Use c"" instead of c_str!().
- Correctly read and write as big endian.
- Keep a pinned reference to the iomem, otherwise the driver will crash
  trying to access unmapped memory.

Link Mauve (4):
  rust: io: Add big-endian read and write functions
  rust: nvmem: Add an abstraction for nvmem providers
  nvmem: Replace the Wii and Wii U OTP driver with a Rust one
  powerpc: wii_defconfig: Enable Rust

 arch/powerpc/configs/wii_defconfig |   1 +
 drivers/nvmem/Kconfig              |   1 +
 drivers/nvmem/Makefile             |   2 +-
 drivers/nvmem/nintendo-otp.c       | 122 ---------------------
 drivers/nvmem/nintendo_otp.rs      | 127 ++++++++++++++++++++++
 rust/bindings/bindings_helper.h    |   1 +
 rust/helpers/io.c                  |  34 ++++++
 rust/kernel/io.rs                  |  18 ++++
 rust/kernel/lib.rs                 |   2 +
 rust/kernel/nvmem.rs               | 163 +++++++++++++++++++++++++++++
 10 files changed, 348 insertions(+), 123 deletions(-)
 delete mode 100644 drivers/nvmem/nintendo-otp.c
 create mode 100644 drivers/nvmem/nintendo_otp.rs
 create mode 100644 rust/kernel/nvmem.rs

-- 
2.52.0



^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/4] rust: io: Add big-endian read and write functions
@ 2026-02-06 11:54 kernel test robot
  0 siblings, 0 replies; 24+ messages in thread
From: kernel test robot @ 2026-02-06 11:54 UTC (permalink / raw)
  Cc: oe-kbuild-all, llvm

In-Reply-To: <20260204040505.8447-2-linkmauve@linkmauve.fr>
References: <20260204040505.8447-2-linkmauve@linkmauve.fr>
TO: Link Mauve <linkmauve@linkmauve.fr>
TO: rust-for-linux@vger.kernel.org
CC: Link Mauve <linkmauve@linkmauve.fr>
CC: Madhavan Srinivasan <maddy@linux.ibm.com>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
CC: Srinivas Kandagatla <srini@kernel.org>
CC: Miguel Ojeda <ojeda@kernel.org>
CC: Boqun Feng <boqun@kernel.org>
CC: Gary Guo <gary@garyguo.net>
CC: "Björn Roy Baron" <bjorn3_gh@protonmail.com>
CC: Benno Lossin <lossin@kernel.org>
CC: Andreas Hindborg <a.hindborg@kernel.org>
CC: Alice Ryhl <aliceryhl@google.com>
CC: Trevor Gross <tmgross@umich.edu>
CC: Danilo Krummrich <dakr@kernel.org>
CC: Daniel Almeida <daniel.almeida@collabora.com>
CC: Ard Biesheuvel <ardb@kernel.org>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: Eric Biggers <ebiggers@google.com>
CC: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
CC: Lyude Paul <lyude@redhat.com>
CC: Asahi Lina <lina+kernel@asahilina.net>
CC: Viresh Kumar <viresh.kumar@linaro.org>
CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
CC: Tamir Duberstein <tamird@kernel.org>
CC: FUJITA Tomonori <fujita.tomonori@gmail.com>
CC: linuxppc-dev@lists.ozlabs.org
CC: linux-kernel@vger.kernel.org
CC: officialTechflashYT@gmail.com

Hi Link,

kernel test robot noticed the following build errors:

[auto build test ERROR on rust/rust-next]
[also build test ERROR on driver-core/driver-core-linus powerpc/next powerpc/fixes linus/master v6.19-rc8]
[cannot apply to driver-core/driver-core-testing driver-core/driver-core-next next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Link-Mauve/rust-io-Add-big-endian-read-and-write-functions/20260204-120734
base:   https://github.com/Rust-for-Linux/linux rust-next
patch link:    https://lore.kernel.org/r/20260204040505.8447-2-linkmauve%40linkmauve.fr
patch subject: [PATCH v2 1/4] rust: io: Add big-endian read and write functions
config: x86_64-buildonly-randconfig-002-20260206 (https://download.01.org/0day-ci/archive/20260206/202602061941.ODjAiGHN-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260206/202602061941.ODjAiGHN-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602061941.ODjAiGHN-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from rust/helpers/helpers.c:32:
>> rust/helpers/io.c:56:9: error: call to undeclared function 'ioread64be'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   56 |         return ioread64be(addr);
   |                ^
>> rust/helpers/io.c:95:2: error: call to undeclared function 'iowrite64be'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   95 |         iowrite64be(value, addr);
   |         ^
   2 errors generated.
   make[3]: *** [rust/Makefile:639: rust/helpers/helpers.o] Error 1 shuffle=2603731126
>> rust/helpers/io.c:56:9: error: call to undeclared function 'ioread64be'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
>> rust/helpers/io.c:95:2: error: call to undeclared function 'iowrite64be'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
>> Unable to generate bindings: clang diagnosed error: rust/helpers/io.c:56:9: error: call to undeclared function 'ioread64be'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
>> rust/helpers/io.c:95:2: error: call to undeclared function 'iowrite64be'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]


vim +/ioread64be +56 rust/helpers/io.c

    52	
    53	#ifdef CONFIG_64BIT
    54	u64 rust_helper_ioread64be(const void __iomem *addr)
    55	{
  > 56		return ioread64be(addr);
    57	}
    58	#endif
    59	
    60	void rust_helper_writeb(u8 value, void __iomem *addr)
    61	{
    62		writeb(value, addr);
    63	}
    64	
    65	void rust_helper_writew(u16 value, void __iomem *addr)
    66	{
    67		writew(value, addr);
    68	}
    69	
    70	void rust_helper_writel(u32 value, void __iomem *addr)
    71	{
    72		writel(value, addr);
    73	}
    74	
    75	#ifdef CONFIG_64BIT
    76	void rust_helper_writeq(u64 value, void __iomem *addr)
    77	{
    78		writeq(value, addr);
    79	}
    80	#endif
    81	
    82	void rust_helper_iowrite16be(u16 value, void __iomem *addr)
    83	{
    84		iowrite16be(value, addr);
    85	}
    86	
    87	void rust_helper_iowrite32be(u32 value, void __iomem *addr)
    88	{
    89		iowrite32be(value, addr);
    90	}
    91	
    92	#ifdef CONFIG_64BIT
    93	void rust_helper_iowrite64be(u64 value, void __iomem *addr)
    94	{
  > 95		iowrite64be(value, addr);
    96	}
    97	#endif
    98	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-03-04 18:47 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-04  4:04 [PATCH v2 0/4] Add Rust abstractions for nvmem-provider Link Mauve
2026-02-04  4:04 ` [PATCH v2 1/4] rust: io: Add big-endian read and write functions Link Mauve
2026-02-04 15:18   ` Danilo Krummrich
2026-02-04 15:20     ` Danilo Krummrich
2026-02-05 14:28     ` Daniel Almeida
2026-02-05 14:56       ` Danilo Krummrich
2026-02-05 15:16       ` Gary Guo
2026-02-05 17:28         ` Daniel Almeida
2026-02-05 19:05           ` Danilo Krummrich
2026-02-05 21:20             ` Link Mauve
2026-02-05 22:11               ` Danilo Krummrich
2026-02-05 22:31             ` Gary Guo
2026-02-05 22:43               ` Danilo Krummrich
2026-02-08 17:17                 ` Daniel Almeida
2026-02-08 17:52                   ` Danilo Krummrich
2026-02-05 22:46               ` Danilo Krummrich
2026-02-04  4:04 ` [PATCH v2 2/4] rust: nvmem: Add an abstraction for nvmem providers Link Mauve
2026-02-04 15:22   ` Danilo Krummrich
2026-02-05 12:48     ` Link Mauve
2026-02-05 12:57       ` Danilo Krummrich
2026-02-04  4:05 ` [PATCH v2 3/4] nvmem: Replace the Wii and Wii U OTP driver with a Rust one Link Mauve
2026-03-04 18:46   ` Link Mauve
2026-02-04  4:05 ` [PATCH v2 4/4] powerpc: wii_defconfig: Enable Rust Link Mauve
  -- strict thread matches above, loose matches on Subject: below --
2026-02-06 11:54 [PATCH v2 1/4] rust: io: Add big-endian read and write functions kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.