rust: helpers: add SPI helpers
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 rust: helpers: add SPI helpers
Add C helpers for the SPI functions that are static inline in C and therefore cannot be accessed from Rust directly: spi_unregister_driver(), spi_write() and spi_read().
Also include <linux/spi/spi.h> in the bindgen bindings helper, so that the Rust side can access the SPI data types.
--- rust/bindings/bindings_helper.h | 1 + rust/helpers/helpers.c | 1 + rust/helpers/spi.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 rust/helpers/spi.c
rust/bindings/bindings_helper.h +1 -0
@@ -88,6 +88,7 @@#include <linux/security.h> #include <linux/serdev.h> #include <linux/slab.h> +#include <linux/spi/spi.h> #include <linux/sys_soc.h> #include <linux/task_work.h> #include <linux/tracepoint.h>
rust/helpers/helpers.c +1 -0
@@ -96,6 +96,7 @@#include "serdev.c" #include "signal.c" #include "slab.c" +#include "spi.c" #include "spinlock.c" #include "string.c" #include "srcu.c"
rust/helpers/spi.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/spi/spi.h> + +__rust_helper +void rust_helper_spi_unregister_driver(struct spi_driver *sdrv) +{ +spi_unregister_driver (sdrv); +} + +__rust_helper +int rust_helper_spi_write(struct spi_device *spi, const void *buf, size_t len) +{ +return spi_write (spi, buf, len); +} + +__rust_helper +int rust_helper_spi_read(struct spi_device *spi, void *buf, size_t len) +{ +return spi_read (spi, buf, len); +}
Signature · 1 line
2.43.0
PATCH 2/3 rust: spi: add SPI driver abstractions
In reply to a message not in the archiveAdd the Rust abstractions for the SPI driver subsystem, allowing SPI drivers to be written in Rust.
This adds the following abstractions:
- spi::DeviceId: a driver-side device id.
- spi::Adapter: the registration of SPI drivers, implementing driver::DriverLayout and driver::RegistrationOps.
- spi::Driver: the trait that SPI drivers implement, with probe(), shutdown() and unbind() callbacks.
- spi::SpiDevice: a representation of struct spi_device, providing device configuration accessors and the setup(), write(), read() and write_then_read() operations.
- module_spi_driver! and spi_device_table! macros.
--- rust/kernel/Kconfig.test | 11 + rust/kernel/lib.rs | 1 + rust/kernel/spi.rs | 529 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 541 insertions(+) create mode 100644 rust/kernel/spi.rs
rust/kernel/Kconfig.test +11 -0
@@ -94,6 +94,17 @@ config RUST_BUG_KUNIT_TEST If unsure, say N. +config RUST_SPI_KUNIT_TEST + bool "KUnit tests for the Rust SPI driver abstractions" if !KUNIT_ALL_TESTS + depends on SPI=y + default KUNIT_ALL_TESTS + help + This option enables KUnit tests for the Rust SPI driver + abstractions. These are only for development and testing, not + for regular kernel use cases. + + If unsure, say N. + config RUST_TIME_KUNIT_TEST bool "KUnit tests for the Rust time API" if !KUNIT_ALL_TESTS default KUNIT_ALL_TESTS
rust/kernel/lib.rs +1 -0
@@ -133,6 +133,7 @@pub mod sizes;#[cfg( CONFIG_SOC_BUS )] pub mod soc; +pub mod spi;#[doc(hidden)] pub mod std_vendor;pub mod str;
rust/kernel/spi.rs new file +529 -0
529 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 3/3 samples: rust: add SPI driver sample
In reply to a message not in the archiveAdd a sample driver for the Rust SPI abstractions to demonstrate their usage.
--- samples/rust/Kconfig | 11 ++++++ samples/rust/Makefile | 1 + samples/rust/rust_driver_spi.rs | 66 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 samples/rust/rust_driver_spi.rs
samples/rust/Kconfig +11 -0
@@ -84,6 +84,17 @@ config SAMPLE_RUST_DEBUGFS_SCOPED If unsure, say N. +config SAMPLE_RUST_DRIVER_SPI + tristate "SPI Driver" + depends on SPI=y + help + This option builds the Rust SPI driver sample. + + To compile this as a module, choose M here: + the module will be called rust_driver_spi. + + If unsure, say N. + config SAMPLE_RUST_DRIVER_I2C tristate "I2C Driver" depends on I2C=y
samples/rust/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_SAMPLE_RUST_DEBUGFS) += rust_debugfs.o obj-$(CONFIG_SAMPLE_RUST_DEBUGFS_SCOPED) += rust_debugfs_scoped.o obj-$(CONFIG_SAMPLE_RUST_DMA) += rust_dma.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_I2C) += rust_driver_i2c.o +obj-$(CONFIG_SAMPLE_RUST_DRIVER_SPI) += rust_driver_spi.o obj-$(CONFIG_SAMPLE_RUST_I2C_CLIENT) += rust_i2c_client.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PCI) += rust_driver_pci.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM) += rust_driver_platform.o
samples/rust/rust_driver_spi.rs new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.43.0