Skip to contentSkip to conversation

Support exporting SoC info from Rust

PATCH Superseded Matthew Maurer 3 participants 11 messages Dec 16, 2025 – Jan 14

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Support exporting SoC info from Rust

This is a fairly straightforward binding of soc_device_register and soc_device_unregister which allows a driver to export basic info about a SoC.

The last patch is a sample demonstrating usage, and can be dropped without issue.

---
Changes in v3:
- Renamed Registration::register to Registration::new
- Inlined registration function and avoided this usage, per Danilo's suggestion.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Switch to new import style
- Increased documentation. Some of this had to be gathered by looking at what is done in practice at the moment, as documentation was absent or did not match code.
- Remove Device intermediate abstraction
- Removed unnecessary pinning of BuiltDeviceAttributes - it only needs
to be pinned for registration, not to exist.
- Aesthetic renames (Attributes pluralization, dropping Device,
etc.)
- Use more representative values for attributes in the sample driver
- Fix swap of example values in the documentation for machine vs family
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Matthew Maurer (3):
rust: Add soc_device support
docs: ABI: sysfs-devices-soc: Fix swapped sample values
rust: Add SoC Driver Sample

 Documentation/ABI/testing/sysfs-devices-soc |   4 +-
 MAINTAINERS                                 |   2 +
 rust/bindings/bindings_helper.h             |   1 +
 rust/kernel/lib.rs                          |   2 +
 rust/kernel/soc.rs                          | 135 ++++++++++++++++++++++++++++
 samples/rust/Kconfig                        |  11 +++
 samples/rust/Makefile                       |   1 +
 samples/rust/rust_soc.rs                    |  82 +++++++++++++++++
 8 files changed, 236 insertions(+), 2 deletions(-)

---
base-commit: 008d3547aae5bc86fac3eda317489169c3fda112
change-id: 20251029-soc-bindings-9b0731bcdbed

Best regards,

Signature · 1 line
Matthew Maurer <[email protected]>
#1 lore raw

PATCH v3 1/3 rust: Add soc_device support

Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through soc_device_match.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   2 +
 rust/kernel/soc.rs              | 135 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
MAINTAINERS +1 -0
index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0bf9d074d28fdb6 100644
@@ -7700,6 +7700,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_debugfs_scoped.rs
 F:	samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a809bedc895697fd 100644
@@ -80,6 +80,7 @@
 #include <linux/sched.h>
 #include <linux/security.h>
 #include <linux/slab.h>
+#include <linux/sys_soc.h>
 #include <linux/task_work.h>
 #include <linux/tracepoint.h>
 #include <linux/usb.h>
rust/kernel/lib.rs +2 -0
index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b2247179439a90ba9 100644
@@ -138,6 +138,8 @@
 pub mod seq_file;
 pub mod sizes;
 pub mod slice;
+#[cfg(CONFIG_SOC_BUS)]
+pub mod soc;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/soc.rs new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.52.0.305.g3fc767764a-goog
#2 lore raw

Re: [PATCH v3 1/3] rust: Add soc_device support

Quoted 80 lines · Matthew Maurer

Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through soc_device_match.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   2 +
 rust/kernel/soc.rs              | 135 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
MAINTAINERS +1 -0
index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0bf9d074d28fdb6 100644
@@ -7700,6 +7700,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_debugfs_scoped.rs
 F:	samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a809bedc895697fd 100644
@@ -80,6 +80,7 @@
 #include <linux/sched.h>
 #include <linux/security.h>
 #include <linux/slab.h>
+#include <linux/sys_soc.h>
 #include <linux/task_work.h>
 #include <linux/tracepoint.h>
 #include <linux/usb.h>
rust/kernel/lib.rs +2 -0
index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b2247179439a90ba9 100644
@@ -138,6 +138,8 @@
 pub mod seq_file;
 pub mod sizes;
 pub mod slice;
+#[cfg(CONFIG_SOC_BUS)]
+pub mod soc;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/soc.rs new file +25 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0d6a36c83cb67ef20dc1e3d3995752f36e25ac9f
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2025 Google LLC.
+
+//! SoC Driver Abstraction.
+//!
+//! C header: [`include/linux/sys_soc.h`](srctree/include/linux/sys_soc.h)
+
+use crate::{
+    bindings,
+    error,
+    prelude::*,
+    str::CString,
+    types::Opaque, //
+};
+use core::ptr::NonNull;
+
+/// Attributes for a SoC device.
+///
+/// These are both exported to userspace under /sys/devices/socX and provided to other drivers to
+/// match against via `soc_device_match` (not yet available in Rust) to enable quirks or
+/// device-specific support where necessary.
+///
+/// All fields are freeform - they have no specific formatting, just defined meanings.
+/// For example, the [`machine`](`Attributes::machine`) field could be "DB8500" or

rust/kernel/soc.rs line 35

Quoted 10 lines
rust/kernel/soc.rs new file +10 -0
+/// "Qualcomm Technologies, Inc. SM8560 HDK", but regardless it should identify a board or product.
+pub struct Attributes {
+    /// Should generally be a board ID or product ID. Examples
+    /// include DB8500 (ST-Ericsson) or "Qualcomm Technologies, inc. SM8560 HDK".
+    ///
+    /// If this field is not populated, the SoC infrastructure will try to populate it from
+    /// `/model` in the device tree.
+    pub machine: Option<CString>,
+    /// The broader class this SoC belongs to. Examples include ux500
+    /// (for DB8500) or Snapdragon (for SM8650).

Formatting of the comments seems a bit off (also appears in other places, please reapply formatting globally to be sure).

Quoted 10 lines
rust/kernel/soc.rs new file +10 -0
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification.
+    pub family: Option<CString>,
+    /// The manufacturing revision of the part. Frequently this is MAJOR.MINOR, but not always.
+    pub revision: Option<CString>,
+    /// Serial Number - uniquely identifies a specific SoC. If present, should be unique (buying a
+    /// replacement part should change it if present). This field cannot be matched on and is
+    /// solely present to export through /sys.
+    pub serial_number: Option<CString>,

rust/kernel/soc.rs line 55

Quoted 10 lines
rust/kernel/soc.rs new file +10 -0
+    /// SoC ID - identifies a specific SoC kind in question, sometimes more specifically than
+    /// `machine` if the same SoC is used in multiple products. Some devices use this to specify a
+    /// SoC name, e.g. "I.MX??", and others just print an ID number (e.g. Tegra and Qualcomm).
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification (the family value) followed by a colon and then a 4-digit ID value.
+    pub soc_id: Option<CString>,
+}
+
+struct BuiltAttributes {

Even though this struct is private, some short documentation would be helpful - actually the explanation about the relationship between _backing and inner belongs here imho instead of in the member's documentation.

#3 lore raw

Re: [PATCH v3 1/3] rust: Add soc_device support

Quoted 87 lines · Alexandre Courbot
Quoted 85 lines · Matthew Maurer

Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through soc_device_match.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   2 +
 rust/kernel/soc.rs              | 135 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
MAINTAINERS +1 -0
index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0bf9d074d28fdb6 100644
@@ -7700,6 +7700,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_debugfs_scoped.rs
 F:   samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a809bedc895697fd 100644
@@ -80,6 +80,7 @@
 #include <linux/sched.h>
 #include <linux/security.h>
 #include <linux/slab.h>
+#include <linux/sys_soc.h>
 #include <linux/task_work.h>
 #include <linux/tracepoint.h>
 #include <linux/usb.h>
rust/kernel/lib.rs +2 -0
index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b2247179439a90ba9 100644
@@ -138,6 +138,8 @@
 pub mod seq_file;
 pub mod sizes;
 pub mod slice;
+#[cfg(CONFIG_SOC_BUS)]
+pub mod soc;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/soc.rs new file +30 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0d6a36c83cb67ef20dc1e3d3995752f36e25ac9f
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2025 Google LLC.
+
+//! SoC Driver Abstraction.
+//!
+//! C header: [`include/linux/sys_soc.h`](srctree/include/linux/sys_soc.h)
+
+use crate::{
+    bindings,
+    error,
+    prelude::*,
+    str::CString,
+    types::Opaque, //
+};
+use core::ptr::NonNull;
+
+/// Attributes for a SoC device.
+///
+/// These are both exported to userspace under /sys/devices/socX and provided to other drivers to
+/// match against via `soc_device_match` (not yet available in Rust) to enable quirks or
+/// device-specific support where necessary.
+///
+/// All fields are freeform - they have no specific formatting, just defined meanings.
+/// For example, the [`machine`](`Attributes::machine`) field could be "DB8500" or
+/// "Qualcomm Technologies, Inc. SM8560 HDK", but regardless it should identify a board or product.
+pub struct Attributes {
+    /// Should generally be a board ID or product ID. Examples
+    /// include DB8500 (ST-Ericsson) or "Qualcomm Technologies, inc. SM8560 HDK".
+    ///
Quoted 8 lines

rust/kernel/soc.rs line 35

Quoted 5 lines
rust/kernel/soc.rs new file +5 -0
+    /// If this field is not populated, the SoC infrastructure will try to populate it from
+    /// `/model` in the device tree.
+    pub machine: Option<CString>,
+    /// The broader class this SoC belongs to. Examples include ux500
+    /// (for DB8500) or Snapdragon (for SM8650).

Formatting of the comments seems a bit off (also appears in other places, please reapply formatting globally to be sure).

I have just re-run the rustfmt target on this commit, and see no changes. Is there something specific that you think is off?

Quoted 26 lines
Quoted 11 lines
rust/kernel/soc.rs new file +10 -0
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification.
+    pub family: Option<CString>,
+    /// The manufacturing revision of the part. Frequently this is MAJOR.MINOR, but not always.
+    pub revision: Option<CString>,
+    /// Serial Number - uniquely identifies a specific SoC. If present, should be unique (buying a
+    /// replacement part should change it if present). This field cannot be matched on and is
+    /// solely present to export through /sys.
+    pub serial_number: Option<CString>,

rust/kernel/soc.rs line 55

Quoted 10 lines
rust/kernel/soc.rs new file +10 -0
+    /// SoC ID - identifies a specific SoC kind in question, sometimes more specifically than
+    /// `machine` if the same SoC is used in multiple products. Some devices use this to specify a
+    /// SoC name, e.g. "I.MX??", and others just print an ID number (e.g. Tegra and Qualcomm).
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification (the family value) followed by a colon and then a 4-digit ID value.
+    pub soc_id: Option<CString>,
+}
+
+struct BuiltAttributes {

Even though this struct is private, some short documentation would be helpful - actually the explanation about the relationship between _backing and inner belongs here imho instead of in the member's documentation.

#4 lore raw

Re: [PATCH v3 1/3] rust: Add soc_device support

Quoted 98 lines · Matthew Maurer
Quoted 87 lines · Alexandre Courbot
Quoted 85 lines · Matthew Maurer

Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through soc_device_match.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   2 +
 rust/kernel/soc.rs              | 135 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
MAINTAINERS +1 -0
index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0bf9d074d28fdb6 100644
@@ -7700,6 +7700,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_debugfs_scoped.rs
 F:   samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a809bedc895697fd 100644
@@ -80,6 +80,7 @@
 #include <linux/sched.h>
 #include <linux/security.h>
 #include <linux/slab.h>
+#include <linux/sys_soc.h>
 #include <linux/task_work.h>
 #include <linux/tracepoint.h>
 #include <linux/usb.h>
rust/kernel/lib.rs +2 -0
index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b2247179439a90ba9 100644
@@ -138,6 +138,8 @@
 pub mod seq_file;
 pub mod sizes;
 pub mod slice;
+#[cfg(CONFIG_SOC_BUS)]
+pub mod soc;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/soc.rs new file +30 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0d6a36c83cb67ef20dc1e3d3995752f36e25ac9f
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2025 Google LLC.
+
+//! SoC Driver Abstraction.
+//!
+//! C header: [`include/linux/sys_soc.h`](srctree/include/linux/sys_soc.h)
+
+use crate::{
+    bindings,
+    error,
+    prelude::*,
+    str::CString,
+    types::Opaque, //
+};
+use core::ptr::NonNull;
+
+/// Attributes for a SoC device.
+///
+/// These are both exported to userspace under /sys/devices/socX and provided to other drivers to
+/// match against via `soc_device_match` (not yet available in Rust) to enable quirks or
+/// device-specific support where necessary.
+///
+/// All fields are freeform - they have no specific formatting, just defined meanings.
+/// For example, the [`machine`](`Attributes::machine`) field could be "DB8500" or
+/// "Qualcomm Technologies, Inc. SM8560 HDK", but regardless it should identify a board or product.
+pub struct Attributes {
+    /// Should generally be a board ID or product ID. Examples
+    /// include DB8500 (ST-Ericsson) or "Qualcomm Technologies, inc. SM8560 HDK".
+    ///
Quoted 8 lines

rust/kernel/soc.rs line 35

Quoted 5 lines
rust/kernel/soc.rs new file +5 -0
+    /// If this field is not populated, the SoC infrastructure will try to populate it from
+    /// `/model` in the device tree.
+    pub machine: Option<CString>,
+    /// The broader class this SoC belongs to. Examples include ux500
+    /// (for DB8500) or Snapdragon (for SM8650).

Formatting of the comments seems a bit off (also appears in other places, please reapply formatting globally to be sure).

Quoted 29 lines

I have just re-run the rustfmt target on this commit, and see no changes. Is there something specific that you think is off?

Quoted 26 lines
Quoted 11 lines
rust/kernel/soc.rs new file +10 -0
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification.
+    pub family: Option<CString>,
+    /// The manufacturing revision of the part. Frequently this is MAJOR.MINOR, but not always.
+    pub revision: Option<CString>,
+    /// Serial Number - uniquely identifies a specific SoC. If present, should be unique (buying a
+    /// replacement part should change it if present). This field cannot be matched on and is
+    /// solely present to export through /sys.
+    pub serial_number: Option<CString>,

rust/kernel/soc.rs line 55

Quoted 10 lines
rust/kernel/soc.rs new file +10 -0
+    /// SoC ID - identifies a specific SoC kind in question, sometimes more specifically than
+    /// `machine` if the same SoC is used in multiple products. Some devices use this to specify a
+    /// SoC name, e.g. "I.MX??", and others just print an ID number (e.g. Tegra and Qualcomm).
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification (the family value) followed by a colon and then a 4-digit ID value.
+    pub soc_id: Option<CString>,
+}
+
+struct BuiltAttributes {

Even though this struct is private, some short documentation would be helpful - actually the explanation about the relationship between _backing and inner belongs here imho instead of in the member's documentation.

I don't think I should do this unless there's some kernel-specific style guidance I'm unaware of (I checked and couldn't find anything, but maybe I missed something):
1. These are comments, not documentation. Documentation is intended for a user of an interface, comments are intended for a reader of the code. The information in these comments should not be considered by a user of BuiltAttributes, even an internal one.
2. Usually the reason to provide documentation for a private structure is that it is available for use at a larger scope than the local module, even if it's not accessible outside the crate, for the purposes of helping developers engage with the type either through an IDE or a local reference. That does not apply here - this is an implementation detail of Registration and should never be used outside this file.

That said, I don't care that deeply about where this text goes, so if consensus is that we'd prefer it to be in a doc comment I can put it there; it just seems wrong to me.

#5 lore raw

Re: [PATCH v3 1/3] rust: Add soc_device support

Quoted 4 lines · Matthew Maurer

I don't think I should do this unless there's some kernel-specific style guidance I'm unaware of (I checked and couldn't find anything, but maybe I missed something):

So we don't require private docs, but developers are always welcome to add them. It really depends on a case-by-case basis: sometimes docs are really needed, even if private, and other times not so much. Thus, so far, I considered it was best to leave it to the developer and see how code evolves.

In the future, the value/benefit of private docs may increase: I would like to have a runtime toggle for the user that shows/hides private and/or hidden items in the rendered docs, thus treating them as first-class docs (including e.g. checking their intra-doc links work). Upstream rustdoc seems to like the idea and even they even implemented a draft of it (see
https://github.com/Rust-for-Linux/linux/issues/350 -> "private/hidden items").

Comments vs. docs is an orthogonal part of this, and indeed, we use comments for implementation-oriented things, and docs for the users (and mixing them in the same place is also OK -- there is an example of that in our guidelines that I wrote for clarity). There are some exceptions and cases where it is reasonable to have either position but, generally, we should avoid aim to avoid details that are clearly implementation details in code documentation and vice versa.

As a rule of thumb: if a Rust item would have needed good docs to be understandable if it were public (or became public later on), then it should also have those docs even if it is private.

Cheers,
Miguel

#6 lore raw

Re: [PATCH v3 1/3] rust: Add soc_device support

In reply to Matthew Maurer
Quoted 144 lines · Matthew Maurer
Quoted 98 lines · Matthew Maurer
Quoted 87 lines · Alexandre Courbot
Quoted 85 lines · Matthew Maurer

Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through soc_device_match.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   2 +
 rust/kernel/soc.rs              | 135 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
MAINTAINERS +1 -0
index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0bf9d074d28fdb6 100644
@@ -7700,6 +7700,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_debugfs_scoped.rs
 F:   samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a809bedc895697fd 100644
@@ -80,6 +80,7 @@
 #include <linux/sched.h>
 #include <linux/security.h>
 #include <linux/slab.h>
+#include <linux/sys_soc.h>
 #include <linux/task_work.h>
 #include <linux/tracepoint.h>
 #include <linux/usb.h>
rust/kernel/lib.rs +2 -0
index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b2247179439a90ba9 100644
@@ -138,6 +138,8 @@
 pub mod seq_file;
 pub mod sizes;
 pub mod slice;
+#[cfg(CONFIG_SOC_BUS)]
+pub mod soc;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/soc.rs new file +30 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0d6a36c83cb67ef20dc1e3d3995752f36e25ac9f
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2025 Google LLC.
+
+//! SoC Driver Abstraction.
+//!
+//! C header: [`include/linux/sys_soc.h`](srctree/include/linux/sys_soc.h)
+
+use crate::{
+    bindings,
+    error,
+    prelude::*,
+    str::CString,
+    types::Opaque, //
+};
+use core::ptr::NonNull;
+
+/// Attributes for a SoC device.
+///
+/// These are both exported to userspace under /sys/devices/socX and provided to other drivers to
+/// match against via `soc_device_match` (not yet available in Rust) to enable quirks or
+/// device-specific support where necessary.
+///
+/// All fields are freeform - they have no specific formatting, just defined meanings.
+/// For example, the [`machine`](`Attributes::machine`) field could be "DB8500" or
+/// "Qualcomm Technologies, Inc. SM8560 HDK", but regardless it should identify a board or product.
+pub struct Attributes {
+    /// Should generally be a board ID or product ID. Examples
+    /// include DB8500 (ST-Ericsson) or "Qualcomm Technologies, inc. SM8560 HDK".
+    ///
Quoted 8 lines

rust/kernel/soc.rs line 35

Quoted 5 lines
rust/kernel/soc.rs new file +5 -0
+    /// If this field is not populated, the SoC infrastructure will try to populate it from
+    /// `/model` in the device tree.
+    pub machine: Option<CString>,
+    /// The broader class this SoC belongs to. Examples include ux500
+    /// (for DB8500) or Snapdragon (for SM8650).

Formatting of the comments seems a bit off (also appears in other places, please reapply formatting globally to be sure).

Quoted 29 lines

I have just re-run the rustfmt target on this commit, and see no changes. Is there something specific that you think is off?

Quoted 26 lines
Quoted 11 lines
rust/kernel/soc.rs new file +10 -0
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification.
+    pub family: Option<CString>,
+    /// The manufacturing revision of the part. Frequently this is MAJOR.MINOR, but not always.
+    pub revision: Option<CString>,
+    /// Serial Number - uniquely identifies a specific SoC. If present, should be unique (buying a
+    /// replacement part should change it if present). This field cannot be matched on and is
+    /// solely present to export through /sys.
+    pub serial_number: Option<CString>,

rust/kernel/soc.rs line 55

Quoted 10 lines
rust/kernel/soc.rs new file +10 -0
+    /// SoC ID - identifies a specific SoC kind in question, sometimes more specifically than
+    /// `machine` if the same SoC is used in multiple products. Some devices use this to specify a
+    /// SoC name, e.g. "I.MX??", and others just print an ID number (e.g. Tegra and Qualcomm).
+    ///
+    /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a JEDEC JEP106 manufacturer
+    /// identification (the family value) followed by a colon and then a 4-digit ID value.
+    pub soc_id: Option<CString>,
+}
+
+struct BuiltAttributes {

Even though this struct is private, some short documentation would be helpful - actually the explanation about the relationship between _backing and inner belongs here imho instead of in the member's documentation.

I don't think I should do this unless there's some kernel-specific style guidance I'm unaware of (I checked and couldn't find anything, but maybe I missed something):
1. These are comments, not documentation. Documentation is intended for a user of an interface, comments are intended for a reader of the code. The information in these comments should not be considered by a user of BuiltAttributes, even an internal one.
2. Usually the reason to provide documentation for a private structure is that it is available for use at a larger scope than the local module, even if it's not accessible outside the crate, for the purposes of helping developers engage with the type either through an IDE or a local reference. That does not apply here - this is an implementation detail of Registration and should never be used outside this file.

Quoted 3 lines

That said, I don't care that deeply about where this text goes, so if consensus is that we'd prefer it to be in a doc comment I can put it there; it just seems wrong to me.

My thinking for suggesting this is that this code is open; other folks might work on it later, who are not familiar with it.

Having the data structures properly documented is useful for them, especially if they are related to other types in ways that are not immediately obvious.

#7 lore raw

Re: [PATCH v3 1/3] rust: Add soc_device support

In reply to Matthew Maurer
Quoted 97 lines · Matthew Maurer
Quoted 87 lines · Alexandre Courbot
Quoted 85 lines · Matthew Maurer

Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through soc_device_match.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   2 +
 rust/kernel/soc.rs              | 135 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 139 insertions(+)
MAINTAINERS +1 -0
index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0bf9d074d28fdb6 100644
@@ -7700,6 +7700,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_debugfs_scoped.rs
 F:   samples/rust/rust_driver_platform.rs
rust/bindings/bindings_helper.h +1 -0
index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a809bedc895697fd 100644
@@ -80,6 +80,7 @@
 #include <linux/sched.h>
 #include <linux/security.h>
 #include <linux/slab.h>
+#include <linux/sys_soc.h>
 #include <linux/task_work.h>
 #include <linux/tracepoint.h>
 #include <linux/usb.h>
rust/kernel/lib.rs +2 -0
index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b2247179439a90ba9 100644
@@ -138,6 +138,8 @@
 pub mod seq_file;
 pub mod sizes;
 pub mod slice;
+#[cfg(CONFIG_SOC_BUS)]
+pub mod soc;
 mod static_assert;
 #[doc(hidden)]
 pub mod std_vendor;
rust/kernel/soc.rs new file +30 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0d6a36c83cb67ef20dc1e3d3995752f36e25ac9f
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2025 Google LLC.
+
+//! SoC Driver Abstraction.
+//!
+//! C header: [`include/linux/sys_soc.h`](srctree/include/linux/sys_soc.h)
+
+use crate::{
+    bindings,
+    error,
+    prelude::*,
+    str::CString,
+    types::Opaque, //
+};
+use core::ptr::NonNull;
+
+/// Attributes for a SoC device.
+///
+/// These are both exported to userspace under /sys/devices/socX and provided to other drivers to
+/// match against via `soc_device_match` (not yet available in Rust) to enable quirks or
+/// device-specific support where necessary.
+///
+/// All fields are freeform - they have no specific formatting, just defined meanings.
+/// For example, the [`machine`](`Attributes::machine`) field could be "DB8500" or
+/// "Qualcomm Technologies, Inc. SM8560 HDK", but regardless it should identify a board or product.
+pub struct Attributes {
+    /// Should generally be a board ID or product ID. Examples
+    /// include DB8500 (ST-Ericsson) or "Qualcomm Technologies, inc. SM8560 HDK".
+    ///
Quoted 8 lines

rust/kernel/soc.rs line 35

Quoted 5 lines
rust/kernel/soc.rs new file +5 -0
+    /// If this field is not populated, the SoC infrastructure will try to populate it from
+    /// `/model` in the device tree.
+    pub machine: Option<CString>,
+    /// The broader class this SoC belongs to. Examples include ux500
+    /// (for DB8500) or Snapdragon (for SM8650).

Formatting of the comments seems a bit off (also appears in other places, please reapply formatting globally to be sure).

Quoted 2 lines

I have just re-run the rustfmt target on this commit, and see no changes. Is there something specific that you think is off?

rustfmt doesn't touch comments IIUC.

What I had in mind was for instance that the first line of the comment for machine is shorter than it could be, i.e. the comments should be re-wrapped for consistency.

#8 lore raw

PATCH v3 2/3 docs: ABI: sysfs-devices-soc: Fix swapped sample values

In reply to Matthew Maurer

The sample values for family and machine were swapped relative to what the driver actually does, and doesn't match the field description.

---
 Documentation/ABI/testing/sysfs-devices-soc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-devices-soc +2 -2
index 5269808ec35f8e2b18516556f886c77f5fac9401..cb6776a4afe02a76fe27ac6fc236babdc7865287 100644
@@ -17,14 +17,14 @@ Date:		January 2012
 contact:	Lee Jones <[email protected]>
 Description:
 		Read-only attribute common to all SoCs. Contains the SoC machine
-		name (e.g. Ux500).
+		name (e.g. DB8500).
 
 What:		/sys/devices/socX/family
 Date:		January 2012
 contact:	Lee Jones <[email protected]>
 Description:
 		Read-only attribute common to all SoCs. Contains SoC family name
-		(e.g. DB8500).
+		(e.g. ux500).
 
 		On many of ARM based silicon with SMCCC v1.2+ compliant firmware
 		this will contain the JEDEC JEP106 manufacturer’s identification
Signature · 1 line
2.52.0.305.g3fc767764a-goog
#9 lore raw

PATCH v3 3/3 rust: Add SoC Driver Sample

In reply to Matthew Maurer

Shows registration of a SoC device upon receipt of a probe.

---
 MAINTAINERS              |  1 +
 samples/rust/Kconfig     | 11 +++++++
 samples/rust/Makefile    |  1 +
 samples/rust/rust_soc.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
MAINTAINERS +1 -0
index 4ff01fb0f1bda27002094113c0bf9d074d28fdb6..bb2e710277cc84dd6042d4d46076e665d9f68752 100644
@@ -7705,6 +7705,7 @@ F:	samples/rust/rust_debugfs.rs
 F:	samples/rust/rust_debugfs_scoped.rs
 F:	samples/rust/rust_driver_platform.rs
 F:	samples/rust/rust_driver_faux.rs
+F:	samples/rust/rust_soc.rs
 
 DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS)
 M:	Nishanth Menon <[email protected]>
samples/rust/Kconfig +11 -0
index 3efa51bfc8efccd91d9ee079ccd078ed1a6e8aa7..c49ab910634596aea4a1a73dac87585e084f420a 100644
@@ -161,6 +161,17 @@ config SAMPLE_RUST_DRIVER_AUXILIARY
 
 	  If unsure, say N.
 
+config SAMPLE_RUST_SOC
+	tristate "SoC Driver"
+	select SOC_BUS
+	help
+	  This option builds the Rust SoC driver sample.
+
+	  To compile this as a module, choose M here:
+	  the module will be called rust_soc.
+
+	  If unsure, say N.
+
 config SAMPLE_RUST_HOSTPROGS
 	bool "Host programs"
 	help
samples/rust/Makefile +1 -0
index f65885d1d62bf406b0db13121ef3e5b09829cfbc..6c0aaa58ccccfd12ef019f68ca784f6d977bc668 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB)		+= rust_driver_usb.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX)		+= rust_driver_faux.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY)	+= rust_driver_auxiliary.o
 obj-$(CONFIG_SAMPLE_RUST_CONFIGFS)		+= rust_configfs.o
+obj-$(CONFIG_SAMPLE_RUST_SOC)			+= rust_soc.o
 
 rust_print-y := rust_print_main.o rust_print_events.o
 
samples/rust/rust_soc.rs new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.52.0.305.g3fc767764a-goog
#10 lore raw

Re: [PATCH v3 3/3] rust: Add SoC Driver Sample

Quoted 81 lines · Matthew Maurer

Shows registration of a SoC device upon receipt of a probe.

---
 MAINTAINERS              |  1 +
 samples/rust/Kconfig     | 11 +++++++
 samples/rust/Makefile    |  1 +
 samples/rust/rust_soc.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
MAINTAINERS +1 -0
index 4ff01fb0f1bda27002094113c0bf9d074d28fdb6..bb2e710277cc84dd6042d4d46076e665d9f68752 100644
@@ -7705,6 +7705,7 @@ F:	samples/rust/rust_debugfs.rs
 F:	samples/rust/rust_debugfs_scoped.rs
 F:	samples/rust/rust_driver_platform.rs
 F:	samples/rust/rust_driver_faux.rs
+F:	samples/rust/rust_soc.rs
 
 DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS)
 M:	Nishanth Menon <[email protected]>
samples/rust/Kconfig +11 -0
index 3efa51bfc8efccd91d9ee079ccd078ed1a6e8aa7..c49ab910634596aea4a1a73dac87585e084f420a 100644
@@ -161,6 +161,17 @@ config SAMPLE_RUST_DRIVER_AUXILIARY
 
 	  If unsure, say N.
 
+config SAMPLE_RUST_SOC
+	tristate "SoC Driver"
+	select SOC_BUS
+	help
+	  This option builds the Rust SoC driver sample.
+
+	  To compile this as a module, choose M here:
+	  the module will be called rust_soc.
+
+	  If unsure, say N.
+
 config SAMPLE_RUST_HOSTPROGS
 	bool "Host programs"
 	help
samples/rust/Makefile +1 -0
index f65885d1d62bf406b0db13121ef3e5b09829cfbc..6c0aaa58ccccfd12ef019f68ca784f6d977bc668 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB)		+= rust_driver_usb.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX)		+= rust_driver_faux.o
 obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY)	+= rust_driver_auxiliary.o
 obj-$(CONFIG_SAMPLE_RUST_CONFIGFS)		+= rust_configfs.o
+obj-$(CONFIG_SAMPLE_RUST_SOC)			+= rust_soc.o
 
 rust_print-y := rust_print_main.o rust_print_events.o
 
samples/rust/rust_soc.rs new file +19 -0
new file mode 100644
index 0000000000000000000000000000000000000000..33043b0ac8dadec36aebf369f0fb68dbb3b118ed
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Rust SoC Platform driver sample.
+
+use kernel::{
+    acpi,
+    c_str,
+    device::Core,
+    of,
+    platform,
+    prelude::*,
+    soc,
+    str::CString,
+    sync::aref::ARef, //
+};
+use pin_init::pin_init_scope;
+
+#[pin_data]
+struct SampleSocDriver {

samples/rust/rust_soc.rs line 29

Quoted 10 lines
samples/rust/rust_soc.rs new file +10 -0
+    pdev: ARef<platform::Device>,
+    #[pin]
+    _dev_reg: soc::Registration,
+}
+
+kernel::of_device_table!(
+    OF_TABLE,
+    MODULE_OF_TABLE,
+    <SampleSocDriver as platform::Driver>::IdInfo,
+    [(of::DeviceId::new(c_str!("test,rust-device")), ())]

C strings can now be declared using c"test,rust-device" (applies through this file).