From nobody Fri Dec 19 20:55:46 2025 Received: from sonic312-24.consmr.mail.ne1.yahoo.com (sonic312-24.consmr.mail.ne1.yahoo.com [66.163.191.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D56CD276026 for ; Thu, 5 Jun 2025 16:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.163.191.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142678; cv=none; b=In9lPpu2kufcyAyVVb6NdmK/ED89hVLajgu6TdTY5caxE3nJglFkG0WZcmyWUCRoXEWk4pBAWu8L6Jl3VcM3Vtb+EzYo16ZEe5wRWxJB+CFmvxC9eGA1QA4EpwEZi5CO8dtVq9ulfZRnwT/hpyKIsjzJzlUM4qoIB+E4v8KfOQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142678; c=relaxed/simple; bh=Se4lCUBfbvGUn11s4S6E/U27wBzXoxFTAw4Zl9wtOuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JjKd6lizZRMxv7tCc7vb+6fdpgZIcsIiuLLSB/MoGUEHalr7tf3ZzZv+QwYS68cnEdXCmQCr1rXhQ5Aax8z2c/9VIzv7y3hcptQnvHguFj9UBLH/qaDfsalhPLGH10hyBbLA/V08u32OaJuSU6CuKNOGxQOkSzjBKIYvB1w0dMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=yahoo.com; spf=pass smtp.mailfrom=yahoo.com; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b=uWK3Yz1G; arc=none smtp.client-ip=66.163.191.205 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=yahoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yahoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="uWK3Yz1G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1749142676; bh=S9xyrmw89L7efj2UYVH5a+PMETFLh/nhQ4bVH6JaxCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=uWK3Yz1Gvmx/rlC+ek/9+XLoHnBBgBE3ouYOp7vbKYeTh5VtHY5Qk5w4JPmPmMzAihUUK4BFTvsuz8S7ebGzdmj/Qu5H4I2/XVf5H7HMhe/AhIBaU3YcRYmUkmCPXgkJPPm/Jo2MP/MJomhsbmrrJgFS/1mJcqjpe+PDkWcLyBq+bvYpMMh3L6HTxLSH5AQECEcAzNS4X3ZympU3QTrHNzWALyFCzjDfnLmZmm+xJMPnkpbhk9RfLxwAuzy/0wxhCwpFFWtvnFwvJDiKD4NpAndxs03niLyPa6AruoVFHv5M4ZSkp/VbImliNRzz5TGzhD0UBiq8ahSLZjj0yYMBIQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1749142676; bh=vrqyb1JIu899nQ3aN4j+U8temFosmg5d2n7vwnSVk/Q=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=o9nlkL3nb+NPnR5IoGq+GCjrV9eXH8UQruPsELxgXLhp/zxAPjIg5KcdKlyj7hWGDpMbaXOEpK7jbMZOiDlakRjg7HD+pHW3zeKXFS9LxtzYTHqDS+1qBXKp2xG9vCmhVSqd6J9Nk2Ua3ep7NjV/bxo0M0PdW1grUp4MxV43myYo6NtAUFmds32rH2jh0S1pAyxlLWKiKEfYspM+0cOlXVn6JgTh5w7VH7ht0P0iABmIa9x1or8SznlZE3ionhwEdZhdg8uDl1IUNvhz60BXdnLaYrsXdYJfmcsAkRO0adBG3zJK+DCz/Jkcu9RVXUAg4xZ0t9x3wS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NgB8DTh8Rru0 ewdaqImohahTlrZarj1g0wSKQD3.5l0LrwD_FS5Xusqdqgd3Y6yFZrJXz7pulvTmKsd9hV5cbgF_ ieljg_4C8pYcsGs9.QwWlkybJN9.Bd16izDwSHQMlbuhlxcKqtEz8hSGdwscw4Hjsz7TDQDVkT1I 3CH.1kNwYXviPicTUzdJWL.pvfXLfxFClgQD.3b1L9Ps.m6E0GJk1NT5oGJP_KFjom7Q83GE407X FGGr.Afo- X-Sonic-MF: X-Sonic-ID: a01551b3-4643-4ab3-9acf-f5730c6599c7 Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ne1.yahoo.com with HTTP; Thu, 5 Jun 2025 16:57:56 +0000 Received: by hermes--production-ir2-858bd4ff7b-rsjdf (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1d1e6bdcafa85f1c72d86546e65fd43d; Thu, 05 Jun 2025 16:27:31 +0000 (UTC) From: Igor Korotin To: Miguel Ojeda , Alex Gaynor , Rob Herring , Saravana Kannan , "Rafael J . Wysocki" , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org Cc: Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Len Brown , Viresh Kumar , Wedson Almeida Filho , Alex Hung , Tamir Duberstein , FUJITA Tomonori , Xiangfei Ding , Igor Korotin Subject: [PATCH v2 3/5] rust: driver: Add ACPI id table support to Adapter trait Date: Thu, 5 Jun 2025 17:27:26 +0100 Message-ID: <20250605162726.3659792-1-igor.korotin@yahoo.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250605161956.3658374-1-igor.korotin.linux@gmail.com> References: <20250605161956.3658374-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Igor Korotin Extend the `Adapter` trait to support ACPI device identification. This mirrors the existing Open Firmware (OF) support (`of_id_table`) and enables Rust drivers to match and retrieve ACPI-specific device data when `CONFIG_ACPI` is enabled. To avoid breaking compilation, a stub implementation of `acpi_id_table()` is added to the Platform adapter; the full implementation will be provided in a subsequent patch. --- rust/bindings/bindings_helper.h | 1 + rust/kernel/driver.rs | 58 ++++++++++++++++++++++++++++++--- rust/kernel/platform.rs | 5 +++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index e0bcd130b494..d974fc6c141f 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -6,6 +6,7 @@ * Sorted alphabetically. */ =20 +#include #include #include #include diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index ec9166cedfa7..d4098596188a 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -6,7 +6,7 @@ //! register using the [`Registration`] class. =20 use crate::error::{Error, Result}; -use crate::{device, of, str::CStr, try_pin_init, types::Opaque, ThisModule= }; +use crate::{device, of, acpi, str::CStr, try_pin_init, types::Opaque, This= Module}; use core::pin::Pin; use pin_init::{pin_data, pinned_drop, PinInit}; =20 @@ -141,6 +141,38 @@ pub trait Adapter { /// The type holding driver private data about each device id supporte= d by the driver. type IdInfo: 'static; =20 + /// The [`acpi::IdTable`] of the corresponding driver + fn acpi_id_table() -> Option>; + + /// Returns the driver's private data from the matching entry in the [= `acpi::IdTable`], if any. + /// + /// If this returns `None`, it means there is no match with an entry i= n the [`acpi::IdTable`]. + #[cfg(CONFIG_ACPI)] + fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo>= { + let table =3D Self::acpi_id_table()?; + + // SAFETY: + // - `table` has static lifetime, hence it's valid for read, + // - `dev` is guaranteed to be valid while it's alive, and so is `= pdev.as_ref().as_raw()`. + let raw_id =3D unsafe { bindings::acpi_match_device(table.as_ptr()= , dev.as_raw()) }; + + if raw_id.is_null() { + None + } else { + // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper of `s= truct of_device_id` and + // does not add additional invariants, so it's safe to transmu= te. + let id =3D unsafe { &*raw_id.cast::() }; + + Some(table.info(::index(id))) + } + } + + #[cfg(not(CONFIG_ACPI))] + #[allow(missing_docs)] + fn acpi_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo= > { + None + } + /// The [`of::IdTable`] of the corresponding driver. fn of_id_table() -> Option>; =20 @@ -178,9 +210,27 @@ fn of_id_info(_dev: &device::Device) -> Option<&'stati= c Self::IdInfo> { /// If this returns `None`, it means that there is no match in any of = the ID tables directly /// associated with a [`device::Device`]. fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> { - let id =3D Self::of_id_info(dev); - if id.is_some() { - return id; + // SAFETY: `id_info` is called from `Adapter::probe_callback` with= a valid `dev` argument. + let fwnode =3D unsafe{ (*dev.as_raw()).fwnode}; + + // SAFETY: `bindings::is_acpi_device_node` checks `fwnode` before = accessing `fwnode->ops`, + // and only compares it with the address of `acpi_device_fwnode_op= s`. + if unsafe { bindings::is_acpi_device_node(fwnode) } { + let id =3D Self::acpi_id_info(dev); + + if id.is_some() { + return id; + } + } + + // SAFETY: `bindings::is_of_node` checks `fwnode` before accessing= `fwnode->ops`, + // and only compares it with the address of `of_fwnode_ops`. + if unsafe { bindings::is_of_node(fwnode) } { + let id =3D Self::of_id_info(dev); + + if id.is_some() { + return id; + } } =20 None diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index fd4a494f30e8..3cc9fe6ccfcf 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -5,6 +5,7 @@ //! C header: [`include/linux/platform_device.h`](srctree/include/linux/pl= atform_device.h) =20 use crate::{ + acpi, bindings, device, driver, error::{to_result, Result}, of, @@ -95,6 +96,10 @@ impl driver::Adapter for Adapter= { fn of_id_table() -> Option> { T::OF_ID_TABLE } + + fn acpi_id_table() -> Option> { + None + } } =20 /// Declares a kernel module that exposes a single platform driver. --=20 2.43.0