mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gladyshev Ilya <foxido@foxido.dev>
To: "foxido @ foxido . dev-cc= Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Len Brown" <lenb@kernel.org>, "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Tamir Duberstein" <tamird@gmail.com>,
	"Armin Wolf" <W_Armin@gmx.de>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-acpi@vger.kernel.org, "Gladyshev Ilya" <foxido@foxido.dev>
Subject: [RFC PATCH 3/3] rust: sample driver for WMI demonstrations
Date: Sun, 21 Dec 2025 21:22:39 +0300	[thread overview]
Message-ID: <905217b6dc4dda707e3596737b4ade9a210aa445.1766331321.git.foxido@foxido.dev> (raw)
In-Reply-To: <cover.1766331321.git.foxido@foxido.dev>

This driver is for RFC demonstration only. It will be removed before
real submission, however it's working and can be transformed into
sample driver
---
 drivers/platform/x86/Makefile        |  1 +
 drivers/platform/x86/redmi_wmi_rs.rs | 60 ++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 drivers/platform/x86/redmi_wmi_rs.rs

diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index d25762f7114f..3045e42618ef 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_MXM_WMI)			+= mxm-wmi.o
 obj-$(CONFIG_NVIDIA_WMI_EC_BACKLIGHT)	+= nvidia-wmi-ec-backlight.o
 obj-$(CONFIG_XIAOMI_WMI)		+= xiaomi-wmi.o
 obj-$(CONFIG_REDMI_WMI)			+= redmi-wmi.o
+obj-m					+= redmi_wmi_rs.o
 obj-$(CONFIG_GIGABYTE_WMI)		+= gigabyte-wmi.o
 
 # Acer
diff --git a/drivers/platform/x86/redmi_wmi_rs.rs b/drivers/platform/x86/redmi_wmi_rs.rs
new file mode 100644
index 000000000000..65300bad022d
--- /dev/null
+++ b/drivers/platform/x86/redmi_wmi_rs.rs
@@ -0,0 +1,60 @@
+//! This is SAMPLE DRIVER
+//! It doesn't aim into upstream and serves only demonstration purposes for
+//! RFC patchset
+
+use kernel::sync::atomic::{Atomic, Relaxed};
+
+use kernel::{
+    acpi::AcpiObject,
+    device, module_wmi_driver, pr_info,
+    prelude::*,
+    wmi::{self, Device, DeviceId, Driver},
+    wmi_device_table,
+};
+
+wmi_device_table!(
+    REDMI_TABLE,
+    MODULE_REDMI_TABLE,
+    <RedmiWMIDriver as Driver>::IdInfo,
+    [(DeviceId::new(b"46C93E13-EE9B-4262-8488-563BCA757FEF"), 12)]
+);
+
+struct RedmiWMIDriver {
+    probed_val: i32,
+    invokation_cnt: Atomic<i64>,
+}
+
+#[vtable]
+impl wmi::Driver for RedmiWMIDriver {
+    type IdInfo = i32;
+
+    const TABLE: &'static dyn kernel::device_id::IdTable<DeviceId, Self::IdInfo> = &REDMI_TABLE;
+
+    fn probe(
+        _: &Device<kernel::device::Core>,
+        id_info: &Self::IdInfo,
+    ) -> impl PinInit<Self, Error> {
+        pr_info!("Rust WMI Sample Driver probed with val {id_info}\n");
+
+        Ok(Self {
+            probed_val: *id_info,
+            invokation_cnt: Atomic::new(0),
+        })
+    }
+
+    fn notify(&self, _: &Device<device::Core>, _: &AcpiObject) {
+        pr_info!(
+            "Notified driver with probed_val: {}, invokation cnt: {}",
+            self.probed_val,
+            self.invokation_cnt.fetch_add(1, Relaxed)
+        );
+    }
+}
+
+module_wmi_driver!(
+    type: RedmiWMIDriver,
+    name: "redmi_wmi_sample",
+    authors: ["Gladyshev Ilya"],
+    description: "SAMPLE DRIVER for RFC demonstration only",
+    license: "GPL v2",
+);
-- 
2.51.1.dirty


  parent reply	other threads:[~2025-12-21 18:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-21 18:22 [RFC PATCH 0/3] rust: WMI abstractions Gladyshev Ilya
2025-12-21 18:22 ` [RFC PATCH 1/3] rust: implement wrapper for acpi_object Gladyshev Ilya
2025-12-22 11:35   ` Danilo Krummrich
2025-12-22 21:47     ` Gladyshev Ilya
2025-12-22 22:44       ` Danilo Krummrich
2025-12-23 15:02         ` Gladyshev Ilya
2025-12-22 19:32   ` Rafael J. Wysocki
2025-12-23 16:36     ` Gladyshev Ilya
2025-12-21 18:22 ` [RFC PATCH 2/3] rust: introduce WMI abstractions Gladyshev Ilya
2025-12-22 11:50   ` Danilo Krummrich
2025-12-25 18:06   ` Armin Wolf
2025-12-25 20:37     ` Gladyshev Ilya
2025-12-28 21:02       ` Armin Wolf
2025-12-21 18:22 ` Gladyshev Ilya [this message]
2025-12-22 11:52 ` [RFC PATCH 0/3] rust: " Danilo Krummrich
2025-12-22 21:30   ` Gladyshev Ilya
2025-12-25 17:56     ` Armin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=905217b6dc4dda707e3596737b4ade9a210aa445.1766331321.git.foxido@foxido.dev \
    --to=foxido@foxido.dev \
    --cc=W_Armin@gmx.de \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®