summaryrefslogtreecommitdiff
path: root/samples/rust
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-02-11 17:43:59 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2026-02-11 17:43:59 -0800
commitc6e62d002b7f0613f02d8707c80f2a7bd66808a0 (patch)
tree11f65a496c7d2d4a6e15dc062f973e1ad4b40bc0 /samples/rust
parent1c2b4a4c2bcb950f182eeeb33d94b565607608cf (diff)
parentba268514ea14b44570030e8ed2aef92a38679e85 (diff)
downloadlinux-next-c6e62d002b7f0613f02d8707c80f2a7bd66808a0.tar.gz
linux-next-c6e62d002b7f0613f02d8707c80f2a7bd66808a0.zip
Merge tag 'driver-core-7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core
Pull driver core updates from Danilo Krummrich: "Bus: - Ensure bus->match() is consistently called with the device lock held - Improve type safety of bus_find_device_by_acpi_dev() Devtmpfs: - Parse 'devtmpfs.mount=' boot parameter with kstrtoint() instead of simple_strtoul() - Avoid sparse warning by making devtmpfs_context_ops static IOMMU: - Do not register the qcom_smmu_tbu_driver in arm_smmu_device_probe() MAINTAINERS: - Add the new driver-core mailing list (driver-core@lists.linux.dev) to all relevant entries - Add missing tree location for "FIRMWARE LOADER (request_firmware)" - Add driver-model documentation to the "DRIVER CORE" entry - Add missing driver-core maintainers to the "AUXILIARY BUS" entry Misc: - Change return type of attribute_container_register() to void; it has always been infallible - Do not export sysfs_change_owner(), sysfs_file_change_owner() and device_change_owner() - Move devres_for_each_res() from the public devres header to drivers/base/base.h - Do not use a static struct device for the faux bus; allocate it dynamically Revocable: - Patches for the revocable synchronization primitive have been scheduled for v7.0-rc1, but have been reverted as they need some more refinement Rust: - Device: - Support dev_printk on all device types, not just the core Device struct; remove now-redundant .as_ref() calls in dev_* print calls - Devres: - Introduce an internal reference count in Devres<T> to avoid a deadlock condition in case of (indirect) nesting - DMA: - Allow drivers to tune the maximum DMA segment size via dma_set_max_seg_size() - I/O: - Introduce the concept of generic I/O backends to handle different kinds of device shared memory through a common interface. This enables higher-level concepts such as register abstractions, I/O slices, and field projections to be built generically on top. In a first step, introduce the Io, IoCapable<T>, and IoKnownSize trait hierarchy for sharing a common interface supporting offset validation and bound-checking logic between I/O backends. - Refactor MMIO to use the common I/O backend infrastructure - Misc: - Add __rust_helper annotations to C helpers for inlining into Rust code - Use "kernel vertical" style for imports - Replace kernel::c_str! with C string literals - Update ARef imports to use sync::aref - Use pin_init::zeroed() for struct auxiliary_device_id and debugfs file_operations initialization - Use LKMM atomic types in debugfs doc-tests - Various minor comment and documentation fixes - PCI: - Implement PCI configuration space accessors using the common I/O backend infrastructure - Document pci::Bar device endianness assumptions - SoC: - Abstractions for struct soc_device and struct soc_device_attribute - Sample driver for soc::Device" * tag 'driver-core-7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core: (79 commits) rust: devres: fix race condition due to nesting rust: dma: add missing __rust_helper annotations samples: rust: pci: Remove some additional `.as_ref()` for `dev_*` print Revert "revocable: Revocable resource management" Revert "revocable: Add Kunit test cases" Revert "selftests: revocable: Add kselftest cases" driver core: remove device_change_owner() export sysfs: remove exports of sysfs_*change_owner() driver core: disable revocable code from build revocable: Add KUnit test for concurrent access revocable: fix SRCU index corruption by requiring caller-provided storage revocable: Add KUnit test for provider lifetime races revocable: Fix races in revocable_alloc() using RCU driver core: fix inverted "locked" suffix of driver_match_device() rust: io: move MIN_SIZE and io_addr_assert to IoKnownSize rust: pci: re-export ConfigSpace rust: dma: allow drivers to tune max segment size gpu: tyr: remove redundant `.as_ref()` for `dev_*` print rust: auxiliary: use `pin_init::zeroed()` for device ID rust: debugfs: use pin_init::zeroed() for file_operations ...
Diffstat (limited to 'samples/rust')
-rw-r--r--samples/rust/Kconfig11
-rw-r--r--samples/rust/Makefile1
-rw-r--r--samples/rust/rust_debugfs.rs46
-rw-r--r--samples/rust/rust_debugfs_scoped.rs38
-rw-r--r--samples/rust/rust_dma.rs13
-rw-r--r--samples/rust/rust_driver_auxiliary.rs14
-rw-r--r--samples/rust/rust_driver_faux.rs10
-rw-r--r--samples/rust/rust_driver_pci.rs43
-rw-r--r--samples/rust/rust_driver_platform.rs42
-rw-r--r--samples/rust/rust_soc.rs79
10 files changed, 225 insertions, 72 deletions
diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig
index 3efa51bfc8ef..c49ab9106345 100644
--- a/samples/rust/Kconfig
+++ b/samples/rust/Kconfig
@@ -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
diff --git a/samples/rust/Makefile b/samples/rust/Makefile
index f65885d1d62b..6c0aaa58cccc 100644
--- a/samples/rust/Makefile
+++ b/samples/rust/Makefile
@@ -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
diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs
index 025e8f9d12de..0963efe19f93 100644
--- a/samples/rust/rust_debugfs.rs
+++ b/samples/rust/rust_debugfs.rs
@@ -32,14 +32,28 @@
//! ```
use core::str::FromStr;
-use kernel::c_str;
-use kernel::debugfs::{Dir, File};
-use kernel::new_mutex;
-use kernel::prelude::*;
-use kernel::sizes::*;
-use kernel::sync::atomic::{Atomic, Relaxed};
-use kernel::sync::Mutex;
-use kernel::{acpi, device::Core, of, platform, str::CString, types::ARef};
+use kernel::{
+ acpi,
+ debugfs::{
+ Dir,
+ File, //
+ },
+ device::Core,
+ new_mutex,
+ of,
+ platform,
+ prelude::*,
+ sizes::*,
+ str::CString,
+ sync::{
+ aref::ARef,
+ atomic::{
+ Atomic,
+ Relaxed, //
+ },
+ Mutex,
+ }, //
+};
kernel::module_platform_driver! {
type: RustDebugFs,
@@ -98,7 +112,7 @@ kernel::acpi_device_table!(
ACPI_TABLE,
MODULE_ACPI_TABLE,
<RustDebugFs as platform::Driver>::IdInfo,
- [(acpi::DeviceId::new(c_str!("LNUXBEEF")), ())]
+ [(acpi::DeviceId::new(c"LNUXBEEF"), ())]
);
impl platform::Driver for RustDebugFs {
@@ -125,34 +139,34 @@ impl platform::Driver for RustDebugFs {
impl RustDebugFs {
fn build_counter(dir: &Dir) -> impl PinInit<File<Atomic<usize>>> + '_ {
- dir.read_write_file(c_str!("counter"), Atomic::<usize>::new(0))
+ dir.read_write_file(c"counter", Atomic::<usize>::new(0))
}
fn build_inner(dir: &Dir) -> impl PinInit<File<Mutex<Inner>>> + '_ {
- dir.read_write_file(c_str!("pair"), new_mutex!(Inner { x: 3, y: 10 }))
+ dir.read_write_file(c"pair", new_mutex!(Inner { x: 3, y: 10 }))
}
fn new(pdev: &platform::Device<Core>) -> impl PinInit<Self, Error> + '_ {
- let debugfs = Dir::new(c_str!("sample_debugfs"));
+ let debugfs = Dir::new(c"sample_debugfs");
let dev = pdev.as_ref();
try_pin_init! {
Self {
_compatible <- debugfs.read_only_file(
- c_str!("compatible"),
+ c"compatible",
dev.fwnode()
.ok_or(ENOENT)?
- .property_read::<CString>(c_str!("compatible"))
+ .property_read::<CString>(c"compatible")
.required_by(dev)?,
),
counter <- Self::build_counter(&debugfs),
inner <- Self::build_inner(&debugfs),
array_blob <- debugfs.read_write_binary_file(
- c_str!("array_blob"),
+ c"array_blob",
new_mutex!([0x62, 0x6c, 0x6f, 0x62]),
),
vector_blob <- debugfs.read_write_binary_file(
- c_str!("vector_blob"),
+ c"vector_blob",
new_mutex!(kernel::kvec!(0x42; SZ_4K)?),
),
_debugfs: debugfs,
diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
index 702a6546d3fb..6a575a15a2c2 100644
--- a/samples/rust/rust_debugfs_scoped.rs
+++ b/samples/rust/rust_debugfs_scoped.rs
@@ -6,12 +6,20 @@
//! `Scope::dir` to create a variety of files without the need to separately
//! track them all.
-use kernel::debugfs::{Dir, Scope};
-use kernel::prelude::*;
-use kernel::sizes::*;
-use kernel::sync::atomic::Atomic;
-use kernel::sync::Mutex;
-use kernel::{c_str, new_mutex, str::CString};
+use kernel::{
+ debugfs::{
+ Dir,
+ Scope, //
+ },
+ new_mutex,
+ prelude::*,
+ sizes::*,
+ str::CString,
+ sync::{
+ atomic::Atomic,
+ Mutex, //
+ },
+};
module! {
type: RustScopedDebugFs,
@@ -80,7 +88,7 @@ fn create_file_write(
};
dir.read_write_file(&name, val);
}
- dir.read_write_binary_file(c_str!("blob"), &dev_data.blob);
+ dir.read_write_binary_file(c"blob", &dev_data.blob);
},
),
GFP_KERNEL,
@@ -119,20 +127,16 @@ struct DeviceData {
}
fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>> + '_ {
- base_dir.scope(
- ModuleData::init(dyn_dirs),
- c_str!("control"),
- |data, dir| {
- dir.write_only_callback_file(c_str!("create"), data, &create_file_write);
- dir.write_only_callback_file(c_str!("remove"), data, &remove_file_write);
- },
- )
+ base_dir.scope(ModuleData::init(dyn_dirs), c"control", |data, dir| {
+ dir.write_only_callback_file(c"create", data, &create_file_write);
+ dir.write_only_callback_file(c"remove", data, &remove_file_write);
+ })
}
impl kernel::Module for RustScopedDebugFs {
fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
- let base_dir = Dir::new(c_str!("rust_scoped_debugfs"));
- let dyn_dirs = base_dir.subdir(c_str!("dynamic"));
+ let base_dir = Dir::new(c"rust_scoped_debugfs");
+ let dyn_dirs = base_dir.subdir(c"dynamic");
Ok(Self {
_data: KBox::pin_init(init_control(&base_dir, dyn_dirs), GFP_KERNEL)?,
})
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index f53bce2a73e3..9c45851c876e 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -57,7 +57,7 @@ impl pci::Driver for DmaSampleDriver {
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
pin_init::pin_init_scope(move || {
- dev_info!(pdev.as_ref(), "Probe DMA test driver.\n");
+ dev_info!(pdev, "Probe DMA test driver.\n");
let mask = DmaMask::new::<64>();
@@ -88,9 +88,7 @@ impl pci::Driver for DmaSampleDriver {
#[pinned_drop]
impl PinnedDrop for DmaSampleDriver {
fn drop(self: Pin<&mut Self>) {
- let dev = self.pdev.as_ref();
-
- dev_info!(dev, "Unload DMA test driver.\n");
+ dev_info!(self.pdev, "Unload DMA test driver.\n");
for (i, value) in TEST_VALUES.into_iter().enumerate() {
let val0 = kernel::dma_read!(self.ca[i].h);
@@ -107,7 +105,12 @@ impl PinnedDrop for DmaSampleDriver {
}
for (i, entry) in self.sgt.iter().enumerate() {
- dev_info!(dev, "Entry[{}]: DMA address: {:#x}", i, entry.dma_address());
+ dev_info!(
+ self.pdev,
+ "Entry[{}]: DMA address: {:#x}",
+ i,
+ entry.dma_address(),
+ );
}
}
}
diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
index 65492a703f30..5c5a5105a3ff 100644
--- a/samples/rust/rust_driver_auxiliary.rs
+++ b/samples/rust/rust_driver_auxiliary.rs
@@ -5,20 +5,22 @@
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
use kernel::{
- auxiliary, c_str,
- device::{Bound, Core},
+ auxiliary,
+ device::{
+ Bound,
+ Core, //
+ },
devres::Devres,
driver,
- error::Error,
pci,
prelude::*,
- InPlaceModule,
+ InPlaceModule, //
};
use core::any::TypeId;
const MODULE_NAME: &CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
-const AUXILIARY_NAME: &CStr = c_str!("auxiliary");
+const AUXILIARY_NAME: &CStr = c"auxiliary";
struct AuxiliaryDriver;
@@ -36,7 +38,7 @@ impl auxiliary::Driver for AuxiliaryDriver {
fn probe(adev: &auxiliary::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
dev_info!(
- adev.as_ref(),
+ adev,
"Probing auxiliary driver for auxiliary device with id={}\n",
adev.id()
);
diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_faux.rs
index ecc9fd378cbd..99876c8e3743 100644
--- a/samples/rust/rust_driver_faux.rs
+++ b/samples/rust/rust_driver_faux.rs
@@ -2,7 +2,11 @@
//! Rust faux device sample.
-use kernel::{c_str, faux, prelude::*, Module};
+use kernel::{
+ faux,
+ prelude::*,
+ Module, //
+};
module! {
type: SampleModule,
@@ -20,9 +24,9 @@ impl Module for SampleModule {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Initialising Rust Faux Device Sample\n");
- let reg = faux::Registration::new(c_str!("rust-faux-sample-device"), None)?;
+ let reg = faux::Registration::new(c"rust-faux-sample-device", None)?;
- dev_info!(reg.as_ref(), "Hello from faux device!\n");
+ dev_info!(reg, "Hello from faux device!\n");
Ok(Self { _reg: reg })
}
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
index fa677991a5c4..d3d4a7931deb 100644
--- a/samples/rust/rust_driver_pci.rs
+++ b/samples/rust/rust_driver_pci.rs
@@ -4,7 +4,15 @@
//!
//! To make this driver probe, QEMU must be run with `-device pci-testdev`.
-use kernel::{c_str, device::Core, devres::Devres, pci, prelude::*, sync::aref::ARef};
+use kernel::{
+ device::Bound,
+ device::Core,
+ devres::Devres,
+ io::Io,
+ pci,
+ prelude::*,
+ sync::aref::ARef, //
+};
struct Regs;
@@ -58,6 +66,30 @@ impl SampleDriver {
Ok(bar.read32(Regs::COUNT))
}
+
+ fn config_space(pdev: &pci::Device<Bound>) {
+ let config = pdev.config_space();
+
+ // TODO: use the register!() macro for defining PCI configuration space registers once it
+ // has been move out of nova-core.
+ dev_info!(
+ pdev,
+ "pci-testdev config space read8 rev ID: {:x}\n",
+ config.read8(0x8)
+ );
+
+ dev_info!(
+ pdev,
+ "pci-testdev config space read16 vendor ID: {:x}\n",
+ config.read16(0)
+ );
+
+ dev_info!(
+ pdev,
+ "pci-testdev config space read32 BAR 0: {:x}\n",
+ config.read32(0x10)
+ );
+ }
}
impl pci::Driver for SampleDriver {
@@ -69,7 +101,7 @@ impl pci::Driver for SampleDriver {
pin_init::pin_init_scope(move || {
let vendor = pdev.vendor_id();
dev_dbg!(
- pdev.as_ref(),
+ pdev,
"Probe Rust PCI driver sample (PCI ID: {}, 0x{:x}).\n",
vendor,
pdev.device_id()
@@ -79,16 +111,17 @@ impl pci::Driver for SampleDriver {
pdev.set_master();
Ok(try_pin_init!(Self {
- bar <- pdev.iomap_region_sized::<{ Regs::END }>(0, c_str!("rust_driver_pci")),
+ bar <- pdev.iomap_region_sized::<{ Regs::END }>(0, c"rust_driver_pci"),
index: *info,
_: {
let bar = bar.access(pdev.as_ref())?;
dev_info!(
- pdev.as_ref(),
+ pdev,
"pci-testdev data-match count: {}\n",
Self::testdev(info, bar)?
);
+ Self::config_space(pdev);
},
pdev: pdev.into(),
}))
@@ -106,7 +139,7 @@ impl pci::Driver for SampleDriver {
#[pinned_drop]
impl PinnedDrop for SampleDriver {
fn drop(self: Pin<&mut Self>) {
- dev_dbg!(self.pdev.as_ref(), "Remove Rust PCI driver sample.\n");
+ dev_dbg!(self.pdev, "Remove Rust PCI driver sample.\n");
}
}
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 6bf4f0c9633d..f2229d176fb9 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -63,16 +63,20 @@
//!
use kernel::{
- acpi, c_str,
+ acpi,
device::{
self,
- property::{FwNodeReferenceArgs, NArgs},
+ property::{
+ FwNodeReferenceArgs,
+ NArgs, //
+ },
Core,
},
- of, platform,
+ of,
+ platform,
prelude::*,
str::CString,
- sync::aref::ARef,
+ sync::aref::ARef, //
};
struct SampleDriver {
@@ -85,14 +89,14 @@ kernel::of_device_table!(
OF_TABLE,
MODULE_OF_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
- [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
+ [(of::DeviceId::new(c"test,rust-device"), Info(42))]
);
kernel::acpi_device_table!(
ACPI_TABLE,
MODULE_ACPI_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
- [(acpi::DeviceId::new(c_str!("LNUXBEEF")), Info(0))]
+ [(acpi::DeviceId::new(c"LNUXBEEF"), Info(0))]
);
impl platform::Driver for SampleDriver {
@@ -124,49 +128,47 @@ impl SampleDriver {
fn properties_parse(dev: &device::Device) -> Result {
let fwnode = dev.fwnode().ok_or(ENOENT)?;
- if let Ok(idx) =
- fwnode.property_match_string(c_str!("compatible"), c_str!("test,rust-device"))
- {
+ if let Ok(idx) = fwnode.property_match_string(c"compatible", c"test,rust-device") {
dev_info!(dev, "matched compatible string idx = {}\n", idx);
}
- let name = c_str!("compatible");
+ let name = c"compatible";
let prop = fwnode.property_read::<CString>(name).required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:?}'\n");
- let name = c_str!("test,bool-prop");
- let prop = fwnode.property_read_bool(c_str!("test,bool-prop"));
+ let name = c"test,bool-prop";
+ let prop = fwnode.property_read_bool(c"test,bool-prop");
dev_info!(dev, "'{name}'='{prop}'\n");
- if fwnode.property_present(c_str!("test,u32-prop")) {
+ if fwnode.property_present(c"test,u32-prop") {
dev_info!(dev, "'test,u32-prop' is present\n");
}
- let name = c_str!("test,u32-optional-prop");
+ let name = c"test,u32-optional-prop";
let prop = fwnode.property_read::<u32>(name).or(0x12);
dev_info!(dev, "'{name}'='{prop:#x}' (default = 0x12)\n");
// A missing required property will print an error. Discard the error to
// prevent properties_parse from failing in that case.
- let name = c_str!("test,u32-required-prop");
+ let name = c"test,u32-required-prop";
let _ = fwnode.property_read::<u32>(name).required_by(dev);
- let name = c_str!("test,u32-prop");
+ let name = c"test,u32-prop";
let prop: u32 = fwnode.property_read(name).required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:#x}'\n");
- let name = c_str!("test,i16-array");
+ let name = c"test,i16-array";
let prop: [i16; 4] = fwnode.property_read(name).required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:?}'\n");
let len = fwnode.property_count_elem::<u16>(name)?;
dev_info!(dev, "'{name}' length is {len}\n");
- let name = c_str!("test,i16-array");
+ let name = c"test,i16-array";
let prop: KVec<i16> = fwnode.property_read_array_vec(name, 4)?.required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:?}' (KVec)\n");
for child in fwnode.children() {
- let name = c_str!("test,ref-arg");
+ let name = c"test,ref-arg";
let nargs = NArgs::N(2);
let prop: FwNodeReferenceArgs = child.property_get_reference_args(name, nargs, 0)?;
dev_info!(dev, "'{name}'='{prop:?}'\n");
@@ -178,7 +180,7 @@ impl SampleDriver {
impl Drop for SampleDriver {
fn drop(&mut self) {
- dev_dbg!(self.pdev.as_ref(), "Remove Rust Platform driver sample.\n");
+ dev_dbg!(self.pdev, "Remove Rust Platform driver sample.\n");
}
}
diff --git a/samples/rust/rust_soc.rs b/samples/rust/rust_soc.rs
new file mode 100644
index 000000000000..8079c1c48416
--- /dev/null
+++ b/samples/rust/rust_soc.rs
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Rust SoC Platform driver sample.
+
+use kernel::{
+ acpi,
+ device::Core,
+ of,
+ platform,
+ prelude::*,
+ soc,
+ str::CString,
+ sync::aref::ARef, //
+};
+use pin_init::pin_init_scope;
+
+#[pin_data]
+struct SampleSocDriver {
+ 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"test,rust-device"), ())]
+);
+
+kernel::acpi_device_table!(
+ ACPI_TABLE,
+ MODULE_ACPI_TABLE,
+ <SampleSocDriver as platform::Driver>::IdInfo,
+ [(acpi::DeviceId::new(c"LNUXBEEF"), ())]
+);
+
+impl platform::Driver for SampleSocDriver {
+ type IdInfo = ();
+ const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
+ const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
+
+ fn probe(
+ pdev: &platform::Device<Core>,
+ _info: Option<&Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> {
+ dev_dbg!(pdev, "Probe Rust SoC driver sample.\n");
+
+ let pdev = pdev.into();
+ pin_init_scope(move || {
+ let machine = CString::try_from(c"My cool ACME15 dev board")?;
+ let family = CString::try_from(c"ACME")?;
+ let revision = CString::try_from(c"1.2")?;
+ let serial_number = CString::try_from(c"12345")?;
+ let soc_id = CString::try_from(c"ACME15")?;
+
+ let attr = soc::Attributes {
+ machine: Some(machine),
+ family: Some(family),
+ revision: Some(revision),
+ serial_number: Some(serial_number),
+ soc_id: Some(soc_id),
+ };
+
+ Ok(try_pin_init!(SampleSocDriver {
+ pdev: pdev,
+ _dev_reg <- soc::Registration::new(attr),
+ }? Error))
+ })
+ }
+}
+
+kernel::module_platform_driver! {
+ type: SampleSocDriver,
+ name: "rust_soc",
+ authors: ["Matthew Maurer"],
+ description: "Rust SoC Driver",
+ license: "GPL",
+}