qcom-socinfo Rust Implementation
Subsystems (4)
cover qcom-socinfo Rust Implementation
THIS IS NOT A PROPOSAL TO LAND THIS SERIES
This is a demonstration of implementing a real driver that uses DebugFS, primarily uploaded to serve as an example for API discussions on the DebugFS series [1].
There are a number of rough edges (transmute, intra-module bindings) and un-landed abstractions (SoC registration, randomness), but the main purpose of this series is to look at sample usage of DebugFS in
* driver/soc/qcom/socinfo_rust/socinfo_rust_scoped.rs
* driver/soc/qcom/socinfo_rust/socinfo_rust_file.rs
to show how this would look in the two different APIs.
The example outputs byte-identical (as checked by recursive diff on debugfs mounts) DebugFS files to the existing C driver. A real rewrite would likely be simpler as it would be willing to not precisely mimic newline quirks, etc.
[1] https://lore.kernel.org/all/[email protected]/
---
Matthew Maurer (5):
rust: Add soc_device support
rust: transmute: Cleanup + Fixes
rust: Add support for feeding entropy to randomness pool
soc: qcom: socinfo: File-based example
soc: qcom: socinfo: Scoped-based example
MAINTAINERS | 1 + drivers/soc/qcom/Kconfig | 12 + drivers/soc/qcom/Makefile | 2 + drivers/soc/qcom/smem.c | 9 + drivers/soc/qcom/socinfo_rust/bindings.rs | 126 +++++ drivers/soc/qcom/socinfo_rust/data.rs | 387 +++++++++++++++ drivers/soc/qcom/socinfo_rust/socinfo_rust_file.rs | 538 +++++++++++++++++++++ .../soc/qcom/socinfo_rust/socinfo_rust_scoped.rs | 367 ++++++++++++++ rust/bindings/bindings_helper.h | 8 + rust/kernel/lib.rs | 4 + rust/kernel/rand.rs | 14 + rust/kernel/soc.rs | 137 ++++++ rust/kernel/transmute.rs | 126 +++-- 13 files changed, 1681 insertions(+), 50 deletions(-)
---
base-commit: f3c5631f70e434e318c44001e2417d4770f06cd0
change-id: 20250818-qcom-socinfo-c58407a81ac6
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 9448855f52cb137ad246ae5fde9eab12eac5da94
prerequisite-change-id: 20250428-debugfs-rust-3cd5c97eb7d1:v10
prerequisite-patch-id: 78c729bc8c164ce7a7c3ff841e720518a7f28c54
prerequisite-patch-id: ca7c06b342af0d1f5b03f8907206f8b69a189c9b
prerequisite-patch-id: f3e7541c4e907d874c8f303c2da14dd3aafe05f6
prerequisite-patch-id: e892f83de14710bea11f042ed874c05ccb3bc972
prerequisite-patch-id: ce8a5988c32a6491bc36e87fb33b2e9adf254db8
prerequisite-patch-id: 0762df7763820dd608da15dfbd8b5309d7692aa9
prerequisite-patch-id: 23da818045894ee8c6f2a7d8ade002ccfc96cc3a
prerequisite-patch-id: 2bfdaa7c29838c44d80003c623067051617f2b5e
Best regards,
Signature · 1 line
Matthew Maurer <[email protected]>
PATCH 1/5 rust: Add soc_device support
Adds the ability to register SoC devices.
(This will be sent upstream in a separate request, it's uploaded now as a dependency of the example driver.)
--- MAINTAINERS | 1 + rust/bindings/bindings_helper.h | 1 + rust/kernel/lib.rs | 2 + rust/kernel/soc.rs | 137 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+)
MAINTAINERS +1 -0
@@ -7481,6 +7481,7 @@ F: rust/kernel/devres.rs F: rust/kernel/driver.rs F: rust/kernel/faux.rs F: rust/kernel/platform.rs +F: rust/kernel/soc.rs F: samples/rust/rust_debugfs.rs F: samples/rust/rust_scoped_debugfs.rs F: samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
@@ -72,6 +72,7 @@#include <linux/sched.h> #include <linux/security.h> #include <linux/slab.h> +#include <linux/sys_soc.h> #include <linux/tracepoint.h> #include <linux/wait.h> #include <linux/workqueue.h>
rust/kernel/lib.rs +2 -0
@@ -117,6 +117,8 @@pub mod security;pub mod seq_file;pub mod sizes; +#[cfg( CONFIG_SOC_BUS )] +pub mod soc;mod static_assert;#[doc(hidden)] pub mod std_vendor;
rust/kernel/soc.rs new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
2.51.0.rc1.167.g924127e9c0-goog
PATCH 2/5 rust: transmute: Cleanup + Fixes
In reply to Matthew MaurerThis change is not intended to go upstream as-is, the original FromBytes/AsBytes is being litigated on the list. This just fixes it up so that I can use it for this example.
--- rust/kernel/lib.rs | 1 + rust/kernel/transmute.rs | 126 ++++++++++++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 50 deletions(-)
rust/kernel/lib.rs +1 -0
@@ -18,6 +18,7 @@// // Stable since Rust 1.79.0. #![feature(inline_const)] +#![feature(pointer_is_aligned)] // // Stable since Rust 1.81.0. #![feature(lint_reasons)]
rust/kernel/transmute.rs +76 -50
169 lines not on this page · raw message
Signature · 1 line
2.51.0.rc1.167.g924127e9c0-goog
PATCH 3/5 rust: Add support for feeding entropy to randomness pool
In reply to Matthew Maurer(This will be separately sent to the list later.)
--- rust/bindings/bindings_helper.h | 1 + rust/kernel/lib.rs | 1 + rust/kernel/rand.rs | 14 ++++++++++++++ 3 files changed, 16 insertions(+)
rust/bindings/bindings_helper.h +1 -0
@@ -67,6 +67,7 @@#include <linux/pm_opp.h> #include <linux/poll.h> #include <linux/property.h> +#include <linux/random.h> #include <linux/refcount.h> #include <linux/regulator/consumer.h> #include <linux/sched.h>
rust/kernel/lib.rs +1 -0
@@ -112,6 +112,7 @@pub mod platform;pub mod prelude;pub mod print; +pub mod rand;pub mod rbtree;pub mod regulator;pub mod revocable;
rust/kernel/rand.rs new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Randomness. +//! +//! C header: [`include/linux/random.h`](../../../../include/linux/random.h) + +use crate ::bindings; +use crate ::ffi::c_void; + +/// Adds the given buffer to the entropy pool. +pub fn add_device_randomness (buf: &[u8 ]) { +// SAFETY: We just need the pointer to be valid for the length, which a slice provides. +unsafe { bindings::add_device_randomness (buf.as_ptr ().cast ::<c_void >(), buf.len ()) }; +}
Signature · 1 line
2.51.0.rc1.167.g924127e9c0-goog
PATCH 4/5 soc: qcom: socinfo: `File`-based example
In reply to Matthew MaurerRe-implements qcom-socinfo driver in Rust, using File-based DebugFS bindings.
--- drivers/soc/qcom/Kconfig | 12 + drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/smem.c | 4 + drivers/soc/qcom/socinfo_rust/bindings.rs | 126 +++++ drivers/soc/qcom/socinfo_rust/data.rs | 387 +++++++++++++++ drivers/soc/qcom/socinfo_rust/socinfo_rust_file.rs | 538 +++++++++++++++++++++ rust/bindings/bindings_helper.h | 6 + 7 files changed, 1074 insertions(+)
drivers/soc/qcom/Kconfig +12 -0
@@ -227,6 +227,18 @@ config QCOM_SOCINFO Say yes here to support the Qualcomm socinfo driver, providing information about the SoC to user space. +config QCOM_SOCINFO_RUST + tristate "Qualcomm socinfo driver" + depends on QCOM_SMEM && RUST + select SOC_BUS + help + Say yes here to support the Qualcomm socinfo driver, providing + information about the SoC to user space. + + This is a draft Rust re-implementation which will enable two + additional copies of the driver to registered alongside the + original. + config QCOM_SPM tristate "Qualcomm Subsystem Power Manager (SPM)" depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +1 -0
@@ -40,3 +40,4 @@ qcom_ice-objs += ice.o obj-$(CONFIG_QCOM_INLINE_CRYPTO_ENGINE) += qcom_ice.o obj-$(CONFIG_QCOM_PBS) += qcom-pbs.o obj-$(CONFIG_QCOM_UBWC_CONFIG) += ubwc_config.o +obj-$(CONFIG_QCOM_SOCINFO_RUST) += socinfo_rust/socinfo_rust_file.o
drivers/soc/qcom/smem.c +4 -0
@@ -1230,7 +1230,11 @@ static int qcom_smem_probe(struct platform_device *pdev) __smem = smem; +// TODO don't double load, this is just to diff the debugfs smem->socinfo =platform_device_register_data (&pdev->dev,"qcom-socinfo" , +PLATFORM_DEVID_NONE ,NULL ,0 ); +// TODO MODULE_ALIAS + smem->socinfo =platform_device_register_data (&pdev->dev,"qcom_socinfo_driver_file_rust" ,PLATFORM_DEVID_NONE ,NULL ,0 );if (IS_ERR (smem->socinfo))
drivers/soc/qcom/socinfo_rust/bindings.rs new file +126 -0
126 lines not on this page · raw message
drivers/soc/qcom/socinfo_rust/data.rs new file +387 -0
387 lines not on this page · raw message
drivers/soc/qcom/socinfo_rust/socinfo_rust_file.rs new file +538 -0
538 lines not on this page · raw message
rust/bindings/bindings_helper.h +6 -0
@@ -80,6 +80,12 @@#include <linux/xarray.h> #include <trace/events/rust_sample.h> +#if defined(CONFIG_QCOM_SOCINFO_RUST ) +#include <dt-bindings/arm/qcom,ids.h> +#include <linux/soc/qcom/smem.h> +#include <linux/soc/qcom/socinfo.h> +#endif +#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE )// Used by `#[export]` in `drivers/gpu/drm/drm_panic_qr.rs`. #include <drm/drm_panic.h>
Signature · 1 line
2.51.0.rc1.167.g924127e9c0-goog
PATCH 5/5 soc: qcom: socinfo: `Scoped`-based example
In reply to Matthew MaurerRe-implements qcom-socinfo driver in Rust, using Scoped-based DebugFS bindings.
--- drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/smem.c | 7 +- .../soc/qcom/socinfo_rust/socinfo_rust_scoped.rs | 367 +++++++++++++++++++++ 3 files changed, 374 insertions(+), 1 deletion(-)
drivers/soc/qcom/Makefile +1 -0
@@ -41,3 +41,4 @@ obj-$(CONFIG_QCOM_INLINE_CRYPTO_ENGINE) += qcom_ice.o obj-$(CONFIG_QCOM_PBS) += qcom-pbs.o obj-$(CONFIG_QCOM_UBWC_CONFIG) += ubwc_config.o obj-$(CONFIG_QCOM_SOCINFO_RUST) += socinfo_rust/socinfo_rust_file.o +obj-$(CONFIG_QCOM_SOCINFO_RUST) += socinfo_rust/socinfo_rust_scoped.o
drivers/soc/qcom/smem.c +6 -1
@@ -1230,13 +1230,18 @@ static int qcom_smem_probe(struct platform_device *pdev) __smem = smem; -// TODO don't double load, this is just to diff the debugfs +// TODO don't triple load, this is just to diff the debugfs smem->socinfo =platform_device_register_data (&pdev->dev,"qcom-socinfo" ,PLATFORM_DEVID_NONE ,NULL ,0 );// TODO MODULE_ALIAS smem->socinfo =platform_device_register_data (&pdev->dev,"qcom_socinfo_driver_file_rust" ,PLATFORM_DEVID_NONE ,NULL ,0 ); +// TODO MODULE_ALIAS + smem->socinfo =platform_device_register_data (&pdev->dev,"qcom_socinfo_driver_scoped_rust" , +PLATFORM_DEVID_NONE ,NULL , +0 ); +if (IS_ERR (smem->socinfo))dev_dbg (&pdev->dev,"failed to register socinfo device\n" );
drivers/soc/qcom/socinfo_rust/socinfo_rust_scoped.rs new file +367 -0
367 lines not on this page · raw message
Signature · 1 line
2.51.0.rc1.167.g924127e9c0-goog