From nobody Tue Jun 16 19:39:19 2026 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) (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 A872F34B190 for ; Mon, 20 Apr 2026 16:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.67.36.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776702071; cv=none; b=r+xTywcAEqEAYF4lgI/au3MK24a7Ij4rtLV5KinmqpVbYO4l77fB62H2W+H/QuZQXzwqdYD0gi+leaI5lQ/im3MyzxS8kzO/8l5NcUMsM+fQC37fQ9TJeSy1u/ir8Bx75bb6Fch68GvCHgpaJZz0ZJW5hZ71PWbGuw4hEq9XRls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776702071; c=relaxed/simple; bh=PxKqojnfMYxqtIeYA393xgc9ELDN3m3bbJAva1p/+us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=abspmdYppacuQKhWEWdsq651IDZIzhtV35uamHow8eZwoo1C6VOVR80qHJZAo5CLhq67Lgf7wnG+M9xFlLPGRecHXs5sae0hp7banodX6OMzCoefftKYHsNy7Fyw7QJFvNLyWh+pUxRW+wFDZjbsYRAEqsX9vSQYnoVC1ZWr0Fg= 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=MpnX9DjA; arc=none smtp.client-ip=185.67.36.65 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="MpnX9DjA" Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 08D51240029 for ; Mon, 20 Apr 2026 18:21:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posteo.de; s=2017; t=1776702067; bh=pXOwPYD3gQxeZDXKmxOu+NSUi5mDs/utK28LrubRWTE=; h=From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:To:Cc:Autocrypt:OpenPGP:From; b=MpnX9DjAjBxiNGqHytylCdaLQxPIo/ZIkwkQlVb9rfj/X1myIBMt3/jAf6gtvya4O JclN+EZb/tuxOZc5BE3Ol9piAd+yQer6XyFrolNymMNdOMmheqnpncv78gT52q28aR fEh4vGhI/rswrC0cjPV2dFmgXi5pu9IsCpkXqQANQnTKIiSaRKuzpZVBxqHzbEaR2N hNwi6vHNrHL2FD8Fg6ZrATLCpreDbBzXub53nEFrvFZkb3JLNkgE8iNpEXAUqJXwwq 6K282CjBso+5RArHxMLotSL2G23cp80k6GZBp194PDXFZmf8iknrq2G2/tyVdNXU3i 2ouPPTCd5Rmdw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4fzrMN2m7fz9rxB; Mon, 20 Apr 2026 18:21:04 +0200 (CEST) From: Markus Probst Date: Mon, 20 Apr 2026 16:21:05 +0000 Subject: [PATCH v5] 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: <20260420-rust_acpi_prp0001-v5-1-f77869b18b9f@posteo.de> X-B4-Tracking: v=1; b=H4sIAGlS5mkC/33Oy27DIBAF0F+xWJeIZ7Cz6n9UUcRjaFgkECAoV eR/L3U2Vmt1ea9mzswTFcgBCjoMT5ShhRLitQf5NiB71tdPwMH1jBhheyIIxfle6knbFE4pJ0J 6o9mkqBTcSClR30sZfHgs5sfxlTPc7p2urxIZXQDbeLmEehia2hH0M3cOpcb8tbzS6DL4z9VGM cV+r4Vj4CcmxHuKpULcOVi0xtaC3BJYF4QfDbWeKOn4b4GvBbUl8C5YaZiQE7FM/RHEWhi3BNG FURk1aqcmxqe1MM/zN60UAHOgAQAA 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=9506; i=markus.probst@posteo.de; h=from:subject:message-id; bh=PxKqojnfMYxqtIeYA393xgc9ELDN3m3bbJAva1p/+us=; b=owEBiQJ2/ZANAwAIATR2H/jnrUPSAcsmYgBp5lJv/xEjOfca+874czZil6lpW4NQRihjzI4xc CmNTpPt8fGJAk8EAAEIADkWIQSCdBjE9KxY53IwxHM0dh/4561D0gUCaeZSbxsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDIACgkQNHYf+OetQ9KPAg/8Dq9FbXb/jlLk2khKpxRhsRqpNYWJfHW LBJO5XEtXPo2GKalsiEQqxkeu0ALDgFuxQMUZeEf+X+Wnzw9MIDff2AQJi0qVCFYl6L/EWSNJOl MD6Jn1a/r+WFCW0i/6pit2pdp2WJhpWm8Y8zuu8KpI+lYV5qk8TP7xzbCrkwcq0av8nD1XUdWix xpCTTo1WnUsNhm1eclYhUVJCfqZgIxGbWZA3+pfNmhWLH+PgyJo1vNinVTgl6AchKx+AkklFGrd CgGuC+/hmv/PHFtOliJVfrwXh4tZZJYbVcBJklPMOj+qMvNSKr22SMzYNd2qYstT14BQL+s4Fp+ a9K6XMfhNdUTvJrxTFGL3Wew2/Ur+BO3uG5Ifqetq2apimM2nFici/6Ulat6HIFb/OCJ05mzKMH p6b7OlvTtGBpfDW+Aq1WQ3JAcg/UlwFnLpMITIJawZVNFtFeb4RwKB+xcu1A3qtXO/I3HaxQE7a T0e5mgYCb4R0cMm3BL5IRuZh43HP/5pxLXLURZeqmsF0Efiak6aCwQ3m4rP3ysAMnZ/c4M2ziQf cDS6G59lF/yuG/It6sWOnoMLPUWN1nYJpH6zWJS5CJBy4E9wCddakNKYSQDkVbNY+Xh08QojsmS 1Z3KbHOHxFhtK2J2Yq7iqSwBS5F0KprJPage93ivV/GB4iwh6Zb8= 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++oXl3FRwiEW8XfXWI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hWPbKmycxuX/D8SvnqavzAeAL1OcRbEI/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 v5: - provide a stub instead of canditionalize the caller - Link to v4: https://lore.kernel.org/r/20260408-rust_acpi_prp0001-v4-1-87b= 78ad79239@posteo.de 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 | 11 ++++++++ rust/helpers/acpi.c | 16 +++++++++++ rust/helpers/helpers.c | 1 + rust/kernel/driver.rs | 74 ++++++++++++++++++++++++++++++++++++++++-----= ---- 6 files changed, 93 insertions(+), 16 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index d1cc0e12fe1f..7da4eea48330 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..049301e71a11 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 { @@ -998,6 +1002,13 @@ int acpi_scan_add_dep(acpi_handle handle, struct acpi= _handle_list *dep_devices); u32 arch_acpi_add_auto_dep(acpi_handle handle); #else /* CONFIG_ACPI */ =20 +static inline 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) +{ + return false; +} + static inline int register_acpi_bus_type(void *bus) { return 0; } static inline int unregister_acpi_bus_type(void *bus) { return 0; } =20 diff --git a/rust/helpers/acpi.c b/rust/helpers/acpi.c new file mode 100644 index 000000000000..e75c9807bbad --- /dev/null +++ b/rust/helpers/acpi.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +__rust_helper bool rust_helper_acpi_of_match_device(const struct acpi_devi= ce *adev, + const struct of_device_id *of_match_table, + const struct of_device_id **of_id) +{ + return acpi_of_match_device(adev, of_match_table, of_id); +} + +__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..93e5dd6ae371 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. +#[inline(never)] +#[allow(clippy::missing_safety_doc)] +#[allow(dead_code)] +#[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: 3131ff5a117498bb4b9db3a238bb311cbf8383ce change-id: 20260401-rust_acpi_prp0001-a2971543b555