From nobody Mon Jun 15 07:38:16 2026 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9C2E34A3C9 for ; Wed, 8 Apr 2026 21:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.67.36.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775684596; cv=none; b=mvjsiDRHUDEuh52Vsalc0eo7Qm2brwwiZuZ1nuE2bT9FwVmWY843C/SLP/2oUhacTOyGKD4e9HzV0+gVG0niESLUDuHvsoFJnPFU0wHJvu93XT9S8RLKjYgEXGctY41yR6U6P+f4EFeIjBhDFcF4UHukjcj8vKvYASyqurARTwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775684596; c=relaxed/simple; bh=hjgYsOtc8kawODJJapp5r1fmy4bOwqHnuG97r7BjN3c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=G4KO5waYZJet5Nj9k7SFiQd52qXAmhxFgprvlR8hpVUCHmreUjl9cgOCyN2ckJommzUuqRvWNhWaSIFCTNHQ6ShdhK0rGsLshuhxXFoJx7rkOjUAE0hdvkNCVuzPHyyWp4ZDwaEUlrGd8/M7dxfkqdE8OWPYTioT0zjPVdW51z0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.de; spf=pass smtp.mailfrom=posteo.de; dkim=pass (2048-bit key) header.d=posteo.de header.i=@posteo.de header.b=KOJsfg7m; arc=none smtp.client-ip=185.67.36.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=posteo.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.de header.i=@posteo.de header.b="KOJsfg7m" Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 2DD1C240106 for ; Wed, 8 Apr 2026 23:43:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posteo.de; s=2017; t=1775684593; bh=X3vgjgsE21PSKunykNF1VP2ZIbZNWrLnny60tzqZzvY=; h=From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:To:Cc:Autocrypt:OpenPGP:From; b=KOJsfg7mONzxWSSQINZf3wJTN4JmY4Zt7t7XbucfK7NNRTCcvIzevPtsUED8mBsR9 0rO3jY8KIyRaHUyApietLbrUecIiZT12OAS28X+b16PB/AnG7chuOEJ6WdKPmFJW8n WSqbGUZIC3A4d3yLwkD3+zZBQMZuDkXndeVc+i6nFV9K5/ITc0E7zvO2RkOEAu1vej NjDpYHaikbxVgPHWPFj8oC8oI2yya0ihFv4eYXTsZcaUxFCPcm4wXvvLLaAkzJshH3 1zUYiV6thbgODoTmK2fzR82jWEIDGph3kV9B16kBBWFWGgfL+rOjHPvgy7V9Ye+Bbp Ix8HQRH/RoDpw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4frc4b4NPGz9rxL; Wed, 8 Apr 2026 23:43:11 +0200 (CEST) From: Markus Probst Date: Wed, 08 Apr 2026 21:43:12 +0000 Subject: [PATCH v4] rust: ACPI: fix missing match data for PRP0001 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-rust_acpi_prp0001-v4-1-87b78ad79239@posteo.de> X-B4-Tracking: v=1; b=H4sIAOrL1mkC/33OQQ7CIBAF0Ks0rMXAFMS68h7GGEoHZaEgINGY3 l2sGzXG5f+ZeTN3kjA6TGTV3EnE4pLzpxrErCHmoE97pG6omQCDBROM03hJeadNcLsQA2O10dA pLkXbSylJ3QsRrbtO5mb7yhHPl0rnV0l6nZAafzy6vGqKmjMajSLP2YNL2cfb9E7h0/Cfy4VTT u1CiwHQdiDEOviU0c8HnLQC74L8JUAVhF323Fim5NB+C+27oH4JbRWM7EHIjhlQH8I4jg/w21X GYgEAAA== X-Change-ID: 20260401-rust_acpi_prp0001-a2971543b555 To: "Rafael J. Wysocki" , Len Brown , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , Robert Moore Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, acpica-devel@lists.linux.dev, Markus Probst X-Developer-Signature: v=1; a=openpgp-sha256; l=8995; i=markus.probst@posteo.de; h=from:subject:message-id; bh=hjgYsOtc8kawODJJapp5r1fmy4bOwqHnuG97r7BjN3c=; b=owEBiQJ2/ZANAwAIATR2H/jnrUPSAcsmYgBp1svv5vrqDkAlKqS7ETfTKTDajTCzbS1tD08b1 AgSLjpj2H6JAk8EAAEIADkWIQSCdBjE9KxY53IwxHM0dh/4561D0gUCadbL7xsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDIACgkQNHYf+OetQ9JxUw/9ExDyXwW57YT3sFL0aatMYQDvgOE2hGa Z6L+6Yl1zzeigVIjjWW0gaZir1Ieo5jdm2Gic3szEHn1vC6t6S74Vj5oJYBkjSRX1DCkUx5ySLf VAVjIbm1zSk5cSlySaKciU1YkGnLB6di9hZTeMRyowznEmRTJ4ztVNGSnYqLG06chClNCtyD+0l Dg5UxL7pTrhDdnw0WuUy1KWhYa0FP2d9xxq51WV0M04rVLNNvzIBMg7OKi/pLjYvyY9NxI02rBI EIgKzSB7wt0u4nrRTCgg1H0RVu+XV5au2GQNyF9GxMxDb098ihHmAijj7i0WmTMYOFprVaYDPSq xm1Bv1wxHnFtUZ2s9TXFEWwrEnXn7dun81zrp6VysnO1YmvBRzmtX03LHrs3k2k62zDKb6YODWi aq/XrGVQV3+5Ebqf80cBtsd6YMAa24EhHHgY7KJw1hBaxX597wXpJIw5m3Xtc4CPUm33rNzKb+z mAoBh1fKNwgniKEI4S0LEU6NC8FU7SMMjjKdbc7l3MwZGY0SugTNMfTg9xRG+lU++p9kSGNURIi AwPBUJurTN0XihTVhDxLoeEQzPTn8JUE/LH68bbPJMayUgD36H+DSjKWh3UmQo4JcT07tNcVeoP MmuFZe8PFl/01wYEJ+kELtVaZ9NhrDrqaALUzhfQiEzAV4XPsj3E= X-Developer-Key: i=markus.probst@posteo.de; a=openpgp; fpr=827418C4F4AC58E77230C47334761FF8E7AD43D2 Autocrypt: addr=markus.probst@posteo.de; prefer-encrypt=mutual; keydata=xsFNBGiDvXgBEADAXUceKafpl46S35UmDh2wRvvx+UfZbcTjeQOlSwKP7YVJ4JOZrVs93qReNLkO WguIqPBxR9blQ4nyYrqSCV+MMw/3ifyXIm6Pw2YRUDg+WTEOjTixRCoWDgUj1nOsvJ9tVAm76Ww+ /pAnepVRafMID0rqEfD9oGv1YrfpeFJhyE2zUw3SyyNLIKWD6QeLRhKQRbSnsXhGLFBXCqt9k5JA RhgQof9zvztcCVlT5KVvuyfC4H+HzeGmu9201BVyihJwKdcKPq+n/aY5FUVxNTgtI9f8wIbmfAja oT1pjXSp+dszakA98fhONM98pOq723o/1ZGMZukyXFfsDGtA3BB79HoopHKujLGWAGskzClwTjRQ xBqxh/U/lL1pc+0xPWikTNCmtziCOvv0KA0arDOMQlyFvImzX6oGVgE4ksKQYbMZ3Ikw6L1Rv1J+ FvN0aNwOKgL2ztBRYscUGcQvA0Zo1fGCAn/BLEJvQYShWKeKqjyncVGoXFsz2AcuFKe1pwETSsN6 OZncjy32e4ktgs07cWBfx0v62b8md36jau+B6RVnnodaA8++oXl3FRwiEW8XfXWIjy4umIv93tb8 8ekYsfOfWkTS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1OcRbEI/HsoroVlEFbBRNBZLJUlnTPs8ZcU 4+8rq5YX1GUrJL3jf6SAfSgO7UdkEET3PdcKFYtS+ruV1Cp5V0q4kCfI5jk25iiz8grM2wOzVSsc l1mEkhiEPH87HP0whhb544iioSnumd3HJKL7dzhRegsMizatupp8D65A2JziW0WKopa1iw9fti3A aBeNN4ijKZchBXHPgVx+YtWRHfcm4l8= OpenPGP: url=https://posteo.de/keys/markus.probst@posteo.de.asc; preference=encrypt Export `acpi_of_match_device` function and use it to match the of device table against ACPI PRP0001 in Rust. This fixes id_info being None on ACPI PRP0001 devices. Using `device_get_match_data` is not possible, because Rust stores an index in the of device id instead of a data pointer. This was done this way to provide a convenient and obvious API for drivers, which can be evaluated in const context without the use of any unstable language features. Fixes: 7a718a1f26d1 ("rust: driver: implement `Adapter`") Signed-off-by: Markus Probst --- Changes in v4: - fix compilation on !CONFIG_ACPI - fix typo - add doc to `acpi_of_match_device` and remove from header file include - Link to v3: https://lore.kernel.org/r/20260407-rust_acpi_prp0001-v3-1-c5b= 24590c273@posteo.de Changes in v3: - use acpi/acpi_bus.h instead of drivers/acpi/internal.h to declare `acpi_of_match_device` - Link to v2: https://lore.kernel.org/r/20260405-rust_acpi_prp0001-v2-1-4f8= b1cf075d3@posteo.de Changes in v2: - keep unsafe block as short as possible - don't export acpi_of_match_device - add implementation decisions to commit msg - Link to v1: https://lore.kernel.org/r/20260401-rust_acpi_prp0001-v1-1-f6a= 4d2ef9244@posteo.de --- MAINTAINERS | 1 + drivers/acpi/bus.c | 6 ++-- include/acpi/acpi_bus.h | 4 +++ rust/bindings/bindings_helper.h | 1 + rust/helpers/acpi.c | 8 +++++ rust/helpers/helpers.c | 1 + rust/kernel/driver.rs | 74 +++++++++++++++++++++++++++++++++----= ---- 7 files changed, 79 insertions(+), 16 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index c3fe46d7c4bc..3a7b3b5f2a28 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -302,6 +302,7 @@ F: include/linux/acpi.h F: include/linux/fwnode.h F: include/linux/fw_table.h F: lib/fw_table.c +F: rust/helpers/acpi.c F: rust/kernel/acpi.rs F: tools/power/acpi/ =20 diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 2ec095e2009e..554dbddb1c8c 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -831,9 +831,9 @@ const struct acpi_device *acpi_companion_match(const st= ruct device *dev) * identifiers and a _DSD object with the "compatible" property, use that * property to match against the given list of identifiers. */ -static bool acpi_of_match_device(const struct acpi_device *adev, - const struct of_device_id *of_match_table, - const struct of_device_id **of_id) +bool acpi_of_match_device(const struct acpi_device *adev, + const struct of_device_id *of_match_table, + const struct of_device_id **of_id) { const union acpi_object *of_compatible, *obj; int i, nval; diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index aad1a95e6863..d0098f24346f 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -187,6 +187,10 @@ struct acpi_driver { * ----------- */ =20 +bool acpi_of_match_device(const struct acpi_device *adev, + const struct of_device_id *of_match_table, + const struct of_device_id **of_id); + /* Status (_STA) */ =20 struct acpi_device_status { diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index 083cc44aa952..a356f9682d93 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -29,6 +29,7 @@ #include =20 #include +#include #include #include #include diff --git a/rust/helpers/acpi.c b/rust/helpers/acpi.c new file mode 100644 index 000000000000..f2aa00ec99c2 --- /dev/null +++ b/rust/helpers/acpi.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +__rust_helper struct acpi_device *rust_helper_to_acpi_device_node(struct f= wnode_handle *fwnode) +{ + return to_acpi_device_node(fwnode); +} diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index a3c42e51f00a..8ecd1580aa69 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -9,6 +9,7 @@ =20 #define __rust_helper =20 +#include "acpi.c" #include "atomic.c" #include "atomic_ext.c" #include "auxiliary.c" diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index 36de8098754d..f8da6ba34017 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -278,6 +278,26 @@ fn init( } } =20 +// Calling the FFI function directly from the `Adapter` impl may result in= it being called +// directly from driver modules. This happens since the Rust compiler will= use monomorphisation, so +// it might happen that functions are instantiated within the calling driv= er module. For now, work +// around this with `#[inline(never)]` helpers. +// +// TODO: Remove once a more generic solution has been implemented. For ins= tance, we may be able to +// leverage `bindgen` to take care of this depending on whether a symbol i= s (already) exported. +#[cfg(CONFIG_ACPI)] +#[inline(never)] +#[allow(clippy::missing_safety_doc)] +#[must_use] +unsafe fn acpi_of_match_device( + adev: *const bindings::acpi_device, + of_match_table: *const bindings::of_device_id, + of_id: *mut *const bindings::of_device_id, +) -> bool { + // SAFETY: Safety requirements are the same as `bindings::acpi_of_matc= h_device`. + unsafe { bindings::acpi_of_match_device(adev, of_match_table, of_id) } +} + /// The bus independent adapter to match a drivers and a devices. /// /// This trait should be implemented by the bus specific adapter, which re= presents the connection @@ -329,35 +349,63 @@ fn acpi_id_info(dev: &device::Device) -> Option<&'sta= tic Self::IdInfo> { /// /// If this returns `None`, it means there is no match with an entry i= n the [`of::IdTable`]. fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> { - #[cfg(not(CONFIG_OF))] + let table =3D Self::of_id_table()?; + + #[cfg(not(any(CONFIG_OF, CONFIG_ACPI)))] { - let _ =3D dev; - None + let _ =3D (dev, table); } =20 #[cfg(CONFIG_OF)] { - let table =3D Self::of_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 `dev.as_raw()`. let raw_id =3D unsafe { bindings::of_match_device(table.as_ptr= (), dev.as_raw()) }; =20 - if raw_id.is_null() { - None - } else { + if !raw_id.is_null() { // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper = of `struct of_device_id` // and does not add additional invariants, so it's safe to= transmute. let id =3D unsafe { &*raw_id.cast::() }; =20 - Some( - table.info(::index( - id, - )), - ) + return Some(table.info( + ::= index(id), + )); } } + + #[cfg(CONFIG_ACPI)] + { + use core::ptr; + use device::property::FwNode; + + let mut raw_id =3D ptr::null(); + + let fwnode =3D dev.fwnode().map_or(ptr::null_mut(), FwNode::as= _raw); + + // SAFETY: `fwnode` is a pointer to a valid `fwnode_handle`. A= null pointer will be + // passed through the function. + let adev =3D unsafe { bindings::to_acpi_device_node(fwnode) }; + + // SAFETY: + // - `adev` is a valid pointer to `acpi_device` or is null. It= is guaranteed to be + // valid as long as `dev` is alive. + // - `table` has static lifetime, hence it's valid for read. + if unsafe { acpi_of_match_device(adev, table.as_ptr(), &raw mu= t raw_id) } { + // SAFETY: + // - the function returns true, therefore `raw_id` has bee= n set to a pointer to a + // valid `of_device_id`. + // - `DeviceId` is a `#[repr(transparent)]` wrapper of `st= ruct of_device_id` + // and does not add additional invariants, so it's safe = to transmute. + let id =3D unsafe { &*raw_id.cast::() }; + + return Some(table.info( + ::= index(id), + )); + } + } + + None } =20 /// Returns the driver's private data from the matching entry of any o= f the ID tables, if any. --- base-commit: 0e5d0a0b5ca6ea4e391d6786266405c5871e0151 change-id: 20260401-rust_acpi_prp0001-a2971543b555