[PATCH] rust: dmi: add basic DMI matching abstraction

From: Nick Dowsett via B4 Relay

Date: Sat Nov 21 2026 - 23:29:01 EST


From: Nick Dowsett <nick42d@xxxxxxxxx>

Exposes `linux/dmi.h` to bindgen, adds MAINTAINERS entry and adds an MVP
of `kernel::dmi` module.

Signed-off-by: Nick Dowsett <nick42d@xxxxxxxxx>
---
This patch adds an initial Rust abstraction for DMI, exposing
`dmi::Field` and `get_system_info()`.

It is intended as a minimal prerequisite for the `clevo-laptop` Rust
platform driver (submitted separately), which needs to check
`dmi::Field::BoardName`.

Review note for RFL reviewers:
`dmi::get_system_info` is currently marked safe under the assumption that
Rust code is always called after DMI is initialised. Would be keen to
have this validated. Alternatively I think a minimal patch to C could
actually make this safe earlier if required.
---
MAINTAINERS | 1 +
rust/bindings/bindings_helper.h | 1 +
rust/kernel/dmi.rs | 82 +++++++++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 1 +
4 files changed, 85 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 44540a1eb2b8..92a227e2345e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7977,6 +7977,7 @@ F: Documentation/ABI/testing/sysfs-firmware-dmi-tables
F: drivers/firmware/dmi-id.c
F: drivers/firmware/dmi_scan.c
F: include/linux/dmi.h
+F: rust/kernel/dmi.rs

DOCUMENTATION
M: Jonathan Corbet <corbet@xxxxxxx>
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 3791af0aadc7..ed4ce2ca351d 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -56,6 +56,7 @@
#include <linux/dma-fence.h>
#include <linux/dma-mapping.h>
#include <linux/dma-resv.h>
+#include <linux/dmi.h>
#include <linux/errname.h>
#include <linux/ethtool.h>
#include <linux/fdtable.h>
diff --git a/rust/kernel/dmi.rs b/rust/kernel/dmi.rs
new file mode 100644
index 000000000000..410a1a84ce08
--- /dev/null
+++ b/rust/kernel/dmi.rs
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Abstractions for DMI (Desktop Management Interface).
+//!
+//! C header: [`include/linux/dmi.h`](srctree/include/linux/device-id/dmi.h)
+
+use crate::{
+ bindings,
+ prelude::*, //
+};
+
+/// Corresponds to each DMI identifier type from [`enum dmi_field`].
+///
+/// # Invariant
+///
+/// Each variant must correspond to a valid [`enum dmi_field`] variant.
+///
+/// [`enum dmi_field`]: srctree/include/linux/device-id/dmi.h
+#[repr(u32)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[expect(missing_docs, reason = "C version of these consts are undocumented")]
+pub enum Field {
+ None = bindings::dmi_field_DMI_NONE,
+ BiosVendor = bindings::dmi_field_DMI_BIOS_VENDOR,
+ BiosVersion = bindings::dmi_field_DMI_BIOS_VERSION,
+ BiosDate = bindings::dmi_field_DMI_BIOS_DATE,
+ BiosRelease = bindings::dmi_field_DMI_BIOS_RELEASE,
+ EcFirmwareRelease = bindings::dmi_field_DMI_EC_FIRMWARE_RELEASE,
+ SysVendor = bindings::dmi_field_DMI_SYS_VENDOR,
+ ProductName = bindings::dmi_field_DMI_PRODUCT_NAME,
+ ProductVersion = bindings::dmi_field_DMI_PRODUCT_VERSION,
+ ProductSerial = bindings::dmi_field_DMI_PRODUCT_SERIAL,
+ ProductUuid = bindings::dmi_field_DMI_PRODUCT_UUID,
+ ProductSku = bindings::dmi_field_DMI_PRODUCT_SKU,
+ ProductFamily = bindings::dmi_field_DMI_PRODUCT_FAMILY,
+ BoardVendor = bindings::dmi_field_DMI_BOARD_VENDOR,
+ BoardName = bindings::dmi_field_DMI_BOARD_NAME,
+ BoardVersion = bindings::dmi_field_DMI_BOARD_VERSION,
+ BoardSerial = bindings::dmi_field_DMI_BOARD_SERIAL,
+ BoardAssetTag = bindings::dmi_field_DMI_BOARD_ASSET_TAG,
+ ChassisVendor = bindings::dmi_field_DMI_CHASSIS_VENDOR,
+ ChassisType = bindings::dmi_field_DMI_CHASSIS_TYPE,
+ ChassisVersion = bindings::dmi_field_DMI_CHASSIS_VERSION,
+ ChassisSerial = bindings::dmi_field_DMI_CHASSIS_SERIAL,
+ ChassisAssetTag = bindings::dmi_field_DMI_CHASSIS_ASSET_TAG,
+ OemString = bindings::dmi_field_DMI_OEM_STRING,
+}
+
+/// Returns the DMI string for `field`, or [`None`] if unavailable or `CONFIG_DMI` is disabled.
+///
+/// # Examples
+///
+/// ```
+/// # use kernel::dmi::{self, Field};
+/// if let Some(vendor) = dmi::get_system_info(Field::SysVendor) {
+/// pr_debug!("Vendor string is {vendor}");
+/// }
+/// ```
+pub fn get_system_info(field: Field) -> Option<&'static CStr> {
+ // NOTE: This can be upgraded to cfg-select post Rust 1.95.
+ #[cfg(CONFIG_DMI)]
+ {
+ // SAFETY:
+ // - `field` is a valid variant of `enum dmi_field`.
+ // - `dmi_get_system_info` is safe to call after DMI has been set up during init.
+ // This occurs during `setup_arch` on x86/loongarch/mips and `core_initcall`
+ // on arm64/riscv - before any Rust code is run.
+ let ptr = unsafe { bindings::dmi_get_system_info(field as c_int) };
+ if ptr.is_null() {
+ return None;
+ }
+ // SAFETY: If non-null, `dmi_get_system_info` returns a C string that
+ // lives for the life of the kernel.
+ Some(unsafe { CStr::from_char_ptr(ptr) })
+ }
+ #[cfg(not(CONFIG_DMI))]
+ {
+ // Squash `unused_variables` error.
+ let _ = field;
+ None
+ }
+}
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index 1ab41129d557..22f10c5d97e8 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -69,6 +69,7 @@
pub mod dma;
#[cfg(CONFIG_DMA_SHARED_BUFFER)]
pub mod dma_buf;
+pub mod dmi;
pub mod driver;
#[cfg(CONFIG_DRM = "y")]
pub mod drm;

---
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
change-id: 20261121-rust-dmi-c49d2041d7e2

Best regards,
--
Nick Dowsett <nick42d@xxxxxxxxx>