From nobody Fri Dec 19 17:34:16 2025 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (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 283F71F2BAB; Thu, 5 Jun 2025 16:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749140627; cv=none; b=XK/5iR5/knhp3082J7Dw0F8b9CFn+SmYRXNqHt9wI6V2+15ReuuR1bDdEMiTEGqjV23ZsT3oBLY4kME7i74lFlBBuXYA8BkM5HoLnCNYbtPI3GXFdLdgvvskTzncdFzxlsUgS8dvSg5vkJWu2saTRGWt+YN0IPLqF5RLLApbziA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749140627; c=relaxed/simple; bh=B6QRYSwoEPKAw0CBU9/MKKr2LpuO0A+Kmwo/HZhwp2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IsoFQH/F+wh9DiITCwAFl+A9KUtgrrCeeCdW94NsWnIWPCdUQ1af9+UGZiGXzxNGJnGoEjAUku0wWYRUNnwYJQg0G3akI9uPLgwIBJNf07wHiWNAaBnabD5ms3YDOBZ0BnU8cQThL/6LRhfWkVUf20vbB9x5ycFwYp8ATyRbrdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yn5XN2qt; arc=none smtp.client-ip=209.85.128.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yn5XN2qt" Received: by mail-wm1-f65.google.com with SMTP id 5b1f17b1804b1-451e24dfe1aso10147265e9.3; Thu, 05 Jun 2025 09:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749140622; x=1749745422; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2F7GrQ5ZHjP6suHBJXzOsQaZFBrj5luNHrI/XyyD2TE=; b=Yn5XN2qtiojxVNbFGEKGHjBhrYwJmxdp6jQqLEoV3AXcNCwWoFZkwjVb41S9ARXnQp Tck0K9EhsqiKqPp7ajVgNAeNGxS7hCXXLwdleczdQcXqxxT1GPbf92YQ/BjrCskI430G sZrGmHb6+RT5fauFwJFnA4OGYq6A+ZWkv/VZh19erCMb5lKopTdGZdUHkduShxceGcIS ne2hMW4FpvvZnQtwl1ImDXmTj3jI/4OD41CEBcXqXU8RjB2Wb/9VnEcVtIDK1YmwDg5f AkWVcfj6QrRl24/aYB/Cp04fcYPU4dSlPtBRYh4iZj1O/8iLT8w8thpFCJL0mxJBYVZM dpgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749140622; x=1749745422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2F7GrQ5ZHjP6suHBJXzOsQaZFBrj5luNHrI/XyyD2TE=; b=hxohj2nFPoP48PtQX0UbDO9Rh1szXvfpsa3p3CWHMA6X7foMDvXnMqH+kqM9cIf78n Ud/eeUgn+E+M/mJ3mT6A7QeEv4ZFtNUbW3LIJsPs4nKZ0jT11//rRxZN9xjdMRmsSR8P j/ABl72h4o3tgHRmnt6WtZwXZpZdkzJZ2Yg45im6hV/7Snz6CFP5y6grq24s339d4gUn qIZn7jL8lSq2tcO6enFr1a2+Cm4UAQ7p3plhqdjsb9atxnudCe9VPJme6XoHjaxHVpN5 K8fdchIESjSOOtlcFedlte0qvq9cOSkEHdhUO82Qg8LCnsxd2ynQNumPLSntN4EucWER nU5g== X-Forwarded-Encrypted: i=1; AJvYcCX09IB7yyNTxTdRKNsJFdUBbcLK0Nl0vcePtgOdtkFw2ZaSyEOmbi/JWKd2sSN9MmYNn849z9v771Jl@vger.kernel.org, AJvYcCX4ydr5xOzqTeh/cUnHswxm82VylJA6spphdDi2f8z9p5BAUFeUCEX71F9WYEJo0+5aBhsbQQMf/L2gQg==@vger.kernel.org, AJvYcCXcPNVXm6+VO4WDtZt0AaeKlDQMikqYcrHOJVke8B2gVqFJ3mh1lV6F9SYmA37Xqa80KX/P69N6FsrgmkuW@vger.kernel.org, AJvYcCXrsDN18X05zoZH/0WmsYgYN37yAa/hlysXTiC8lNfOBPJdIeZqeSJ16z7fcyldbGlMfafptmq8U0k1L+ujPq0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/xyDImZAfiEf7HAhtHgQAD2JFbzCAmh+Ew6AXuIFxzzdiqER/ hX6bAxRkCgbpjNnt6IX0t4EWAZd9qLs8amMM7W1Ye0XLOxqA2vxQwrs9 X-Gm-Gg: ASbGncsfjZCG9SfWUz6kIuIdKR072jDc0NgAZvLYyqWQ7JehJpmm3vxOO3kzsN390e7 VPKO6MSvQkeZ/CX8+QASJv6ERzVx4T41afP/BHX9/3LkrxMkzvlXXLj5mWM4JVuaBWpXhloRwDP W1xfbQENNVKI5nqNrqGu/GtqbNf87bZhLsrzIhmjttPoWsFfTGX/ljt9AYpdhkycqxZQRMYq1pt qu+/vTPtrTjLHxVVE+LKzLQSuqQbLbxoRy8T6ns+mMJaKq2GH2w5rpgEHgfFXt9VCUdyIFfrpmj EukGZ0hZlvB5yu5w5DEox+fyJg+W5vngqt2eI0KwfQ/3A/+cchD8u3an+kEyFwDhIagFYFlHf3u W94GFutFF3T/K4fkEzCEKNnY= X-Google-Smtp-Source: AGHT+IFUzREo4CrSMybFCvDXcfF+zrn7VtJtHlVgCrTazl3OsJBFZMZ3pRtHj+4hJCjqe4EgIqLowg== X-Received: by 2002:a05:6000:1ace:b0:3a4:cfbf:51a0 with SMTP id ffacd0b85a97d-3a51dbcd6f3mr6839341f8f.21.1749140622061; Thu, 05 Jun 2025 09:23:42 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-451f9919671sm30128675e9.27.2025.06.05.09.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 09:23:41 -0700 (PDT) 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 1/5] rust: acpi: add `acpi::DeviceId` abstraction Date: Thu, 5 Jun 2025 17:23:26 +0100 Message-ID: <20250605162326.3659046-1-igor.korotin.linux@gmail.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" `acpi::DeviceId` is an abstraction around `struct acpi_device_id`. This is used by subsequent patches, in particular the i2c driver abstractions, to create ACPI device ID tables. Signed-off-by: Igor Korotin --- MAINTAINERS | 1 + rust/kernel/acpi.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 64 insertions(+) create mode 100644 rust/kernel/acpi.rs diff --git a/MAINTAINERS b/MAINTAINERS index b659fb27ab63..5f8dfae08454 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/kernel/acpi.rs F: tools/power/acpi/ =20 ACPI APEI diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs new file mode 100644 index 000000000000..2f526a0b2ed9 --- /dev/null +++ b/rust/kernel/acpi.rs @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Advanced Configuration and Power Interface abstractions. + +use crate::{bindings, device_id::RawDeviceId, prelude::*}; + +/// IdTable type for ACPI drivers. +pub type IdTable =3D &'static dyn kernel::device_id::IdTable; + +/// An ACPI device id. +#[repr(transparent)] +#[derive(Clone, Copy)] +pub struct DeviceId(bindings::acpi_device_id); + +// SAFETY: +// * `DeviceId` is a `#[repr(transparent)` wrapper of `struct acpi_device_= id` and does not add +// additional invariants, so it's safe to transmute to `RawType`. +// * `DRIVER_DATA_OFFSET` is the offset to the `data` field. +unsafe impl RawDeviceId for DeviceId { + type RawType =3D bindings::acpi_device_id; + + const DRIVER_DATA_OFFSET: usize =3D core::mem::offset_of!(bindings::ac= pi_device_id, driver_data); + + fn index(&self) -> usize { + self.0.driver_data as _ + } +} + +impl DeviceId { + const ACPI_ID_LEN: usize =3D 16; + + /// Create a new device id from an ACPI 'id' string. + pub const fn new(id: &'static CStr) -> Self { + assert!(id.len() <=3D Self::ACPI_ID_LEN, "ID exceeds 16 bytes"); + let src =3D id.as_bytes_with_nul(); + // Replace with `bindings::acpi_device_id::default()` once stabili= zed for `const`. + // SAFETY: FFI type is valid to be zero-initialized. + let mut acpi: bindings::acpi_device_id =3D unsafe { core::mem::zer= oed() }; + let mut i =3D 0; + while i < src.len() { + acpi.id[i] =3D src[i]; + i +=3D 1; + } + + Self(acpi) + } +} + +/// Create an ACPI `IdTable` with an "alias" for modpost. +#[macro_export] +macro_rules! acpi_device_table { + ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $tabl= e_data: expr) =3D> { + const $table_name: $crate::device_id::IdArray< + $crate::acpi::DeviceId, + $id_info_type, + { $table_data.len() }, + > =3D $crate::device_id::IdArray::new($table_data); + + $crate::module_device_table!("acpi", $module_table_name, $table_na= me); + }; +} + diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6e9287136cac..c2761bc7cfe6 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -51,6 +51,7 @@ =20 pub use ffi; =20 +pub mod acpi; pub mod alloc; #[cfg(CONFIG_BLOCK)] pub mod block; --=20 2.43.0 From nobody Fri Dec 19 17:34:16 2025 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (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 53DC8205ABB; Thu, 5 Jun 2025 16:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749140701; cv=none; b=U3Vq/yCDHPLBzM7jMwceGavDsPYkgBoX0/cHFc12RiQZT4bL0G91tPsoSRx7Rr7ZRJD39tFwvYsSZeCrLniXUECQ/Pt+Us3CYoZPJE/Pls/6n5L2mxPfAaTfVmWwRebGDz6JfdwInpO7ZbW/ubLTOCkDpxv/UYpMiVYnpCNOb7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749140701; c=relaxed/simple; bh=pwyfEO34JmMzSrSCOCcsHlL2iqGjz85h0/93mVFh7sA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RhAmPUrAV70srPlMUIuYvj+pZyZo6RH36394Wtk+AiCrqcp27HxyWciWVcHjS9NRleOyff3aCMWNUag3+drEUvd4gUX2wI4KoO8hwWCJNYoeqb4D/C5vvuR2JfJxPLSZPCrH8/g8rtwcp08XkvNZ53PemyfGA+XB2rxaLrGHy0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EvCyPG+a; arc=none smtp.client-ip=209.85.128.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EvCyPG+a" Received: by mail-wm1-f68.google.com with SMTP id 5b1f17b1804b1-450caff6336so7287585e9.3; Thu, 05 Jun 2025 09:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749140697; x=1749745497; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b1m1B6nQXZ8mPeTAYsXRWJ8xyXAKXvkl9Kc6auAK6DM=; b=EvCyPG+aUmDIqYVfudE5M7d6435+ur2jdppRIwgDLkmGm6M1+3EKiPQJcN9GwazhvD nbAEbuTu1BH6OyJY680dtzKwVOe/CsR0FC63vyXeNWzv1YzIZFsuThb7tLle59bNQ/Yq PAhZw1qQmG8A9n/4iPvGTl42M8R/0mcbEu5uG4bG97fzUxleNUGSoxmgYBvHdV1RzzLU cwYp1U5OxSIsTYGAcECdRjHMmH6qJhg1QzpkM9iRxlAy1s0d8LxweF0dGJdqUJzXM1qz FylMXAqu/HdK7HHnEbgyWsMVIOJKrYfoga7IZLWyDbAu/G8WY1PYY2szAezMHqtZA0mW 5F6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749140697; x=1749745497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b1m1B6nQXZ8mPeTAYsXRWJ8xyXAKXvkl9Kc6auAK6DM=; b=vE3N1Bmq/8xMcIGSMaT0AajwIQiq4+n6BQxv0DnU/zBBXmDZ9wElpXAarFAoaJWgPt WXmRF6wHkfofYPk6vRYoTUAwvkPYUMGki7He7cWS4MYHxsjtVt9vTCW2ZCvOn+bMs5IG 0grl5ITh9tV3F5GJyJ4ShHKd157ncFq5Ve/zTZSZ4GqxudzJvoCZ8QVa9DFaVbCMBgLt ehs3Dm+9co2e7bHE5uXg35NnjHIVTCOYtZBSoXSlxev8jrNLMn2r9W6adi+Osq9T2h8p dS2YiU1GYxI5fpJ5EOye0odNyhuyP0+8uhCPAHIHHX+QYhPe7l/cZEqxNmj23jB8O1IM mNvA== X-Forwarded-Encrypted: i=1; AJvYcCUgascl+yGN8WeOekGb/g8AIKD1mAxVmQLj8lJjGFXKqhWLexIAWwuoQ6Zn8sRFE2iQkCSuioG7nxOo@vger.kernel.org, AJvYcCVZbg97FKNMD5idStx7bJvWowPSbAxbdsnit6Efb2OjR9PVLhCsoG/TUFQOpjYRwjTO0l85gbJDIegPr+wuJoA=@vger.kernel.org, AJvYcCWdwvnrjFMuUJ64Or3KMZTmloUOTR19mC4M26F8ZsQpeai++Vlxe1i0H0WMeCJIanFFq7/u9X9J9kztAKWF@vger.kernel.org, AJvYcCXqcVE2fn//2foFy6ZuJ5LfYtvmfYSxHTdZnGRg/z28qsLR+nqwLnkjHvcuS1BXchzi8xfNbAEtcsWHbA==@vger.kernel.org X-Gm-Message-State: AOJu0YysTDrHp2dNu/+CrTnJwmBCO6dzNXZv2CCrcneBhMSMtTYizppG cDYcP8qt6Y0OtWx4WMIEAaI7/TCVk9PXKJCp3b62hyd+DqV0q2RptSrP X-Gm-Gg: ASbGnctw2vqdgHdFNePAe5ZCSxEC8xxpfj4tYHWSSlXgmRZqcbORYZmXmW5d1Dtq3l7 xcS/zyfQeDa7y3bli32nILV8FgamNVY5yCF6lbbGm5DL69iPa7yn/RQQqxCZETWaa597OIXlIYQ yWHF/0jFQ8menMajWqOQZLSyQ+Orr/1kT36OlNI6PYv6FLexynu4jIQvTkdoilvlZLmhZ8r3j4Y Tf1mA+V10K6MON75YtczJK+775fKnxzWqPd29SZRqXdEA+kUtjMYSDt5ij2USUyC+nZqZ6JwKFU 7yYqK3n/QswJY0AJoCgkljOtIxSzHduLdmz5NXWcYwsAQ2X1SbQTOOXOswSBRXmCtF3jcfcG1wA pY/lETYMUespqbTo= X-Google-Smtp-Source: AGHT+IGWavlZhoQ+/UyAySuEJA2L+CnHKDxy4aTjsHiVQaqroh/Imb+eG9Mk0IdvcIUwFOomrCjnRg== X-Received: by 2002:a05:600c:3106:b0:441:b3eb:570a with SMTP id 5b1f17b1804b1-451f0a6a94bmr75309925e9.2.1749140697424; Thu, 05 Jun 2025 09:24:57 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a526ddb8afsm2822451f8f.0.2025.06.05.09.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 09:24:57 -0700 (PDT) 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 2/5] rust: helpers: Add `is_of_node` helper function Date: Thu, 5 Jun 2025 17:24:53 +0100 Message-ID: <20250605162454.3659309-1-igor.korotin.linux@gmail.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" Add a helper function to determine whether a given device appears to be an Open Firmware (OF) node. This function will be used in Rust driver abstractions to support both ACPI and OF matching simultaneously in subsequent patches. Signed-off-by: Igor Korotin --- MAINTAINERS | 1 + rust/helpers/helpers.c | 1 + rust/helpers/of.c | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 rust/helpers/of.c diff --git a/MAINTAINERS b/MAINTAINERS index 5f8dfae08454..d6cadaa592aa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18215,6 +18215,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/gi= t/robh/linux.git F: Documentation/ABI/testing/sysfs-firmware-ofw F: drivers/of/ F: include/linux/of*.h +F: rust/helpers/of.c F: rust/kernel/of.rs F: scripts/dtc/ F: tools/testing/selftests/dt/ diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 80785b1e7a63..2fc5242aa47a 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -21,6 +21,7 @@ #include "jump_label.c" #include "kunit.c" #include "mutex.c" +#include "of.c" #include "page.c" #include "platform.c" #include "pci.c" diff --git a/rust/helpers/of.c b/rust/helpers/of.c new file mode 100644 index 000000000000..8913eaced716 --- /dev/null +++ b/rust/helpers/of.c @@ -0,0 +1,6 @@ +#include + +bool rust_helper_is_of_node(const struct fwnode_handle *fwnode) +{ + return is_of_node(fwnode); +} --=20 2.43.0 From nobody Fri Dec 19 17:34:16 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+wTAbtuk8Lqg== X-YMail-OSG: QFNIsLEVM1mqoF7iwn5REm71RGrFrfpkmo.PUXNRvSpoz6r1XVdmfQmkwLrXD3Q RX_ivAtcyUkxFRJJnvOADjvekpEoOgbvNWgl4KTu56TxvIZdG34nbVhwpBYo36F2Q3sXzjQANiV2 LIz0anEhqJNZpopYEWNnjKkh9fuRJuZM405cASisd.RIrjSrqXNS6EQnq.0yP.OrIpcbqs5z1Xav ZBvDQK0QXp0sVadLK.nMXLC.6qr4w2ypbWkLQ__u5d9LcS0MDcOnWpr8bB.gzmH.YkkWny12Hk_s GkeC0Zt8iuUW7MK8A5mt8U0R.cIgKiH0wxM4NdLkH_dy0HirMbTCibcW.8lw1NCNtsh6U_M.MkAS N_i9lIwIkOuspdve.NzGBn6JnWcxWR4b0aPZ7C4LPuAfi9.e0Dy2WdG6rQnbUjq_D5.K_x8k5JAW qvpeSUs2S7VN9lB00UlDnLbJcYECgiExS3CrvYVqbREMTNkloSLKMZpSjNkee8saXM8WkJmWhOeL Iy9hvSGFDMbv6zZyfvc8x2EP5_zShrGaOEk9pJ3eIReeGyQwFCWiycWYevvuo8lKASg8fwjAzNtg onQSx8Q_4HcwfHI551Pvz9osMHiRoXi4TyH3joqA2FEPzlXkns2PmW2LLyzVX0Vuy880xTOjT1Y3 BE.5Ke7fjzIc9a1Z86_fJVJw5IbKoBTwLF3VtIF0pEcdFOuPtrYL7sW9_VcKC_f8X6ek3vgoSx_y wrh1z1ZsYFrolRguzm7SWlnO_rzfWeAAhE_kBkS3A2wHiVXXsoXXqDFgU9cPrwTwGFW0UTsobBg0 9kDh.UjeOe5YGf_vbIdfxs5mXB0wdA8a.xKZWxOiDoaWpgPKgZMWb4rpcfiB6fyhUJLxz2AqEMe8 TVNFmKHgPPkv0I6piIAkkIzijt72B94ADS.520wZWmpe7Yi9QeB3xdwl92vgxkWL9g7OIa16GVzk TvFyAlZdMPpUMC2Fq0Kb9yXE6UF01jQ1ThJsC_Kfu_UjEYbZfYIR6nDfiVhQBxHjIP9SGO3OYVli u8PcNYPMu0HKhaE6yJIqa_S.Y0ncBSpFczMAyWSa_tkrfTvKa5XXF.k_XTvss3CzoLkfNcgQP86l 1UEabv_QOkYDaHZr49BBwacHA0jP_bNh9e0gPdJyLz2wjvvx7EmD.lHLLoaqdHhTIZkPjZBzbmn_ NxYs96oHCfXsqQWa3yXCkX89ggkaubvv2KNPGk_oH350skRyTYz.X.E51PtVHmF2aDO.1rL3uEud RyIyGFE35yRU0v96iu7f0hSKHPmjj1yRJiYtihtKkJ6S4_GZ2W5bcFnJnvMBbZnVIxwEar.oFO_b BC0yy6khmGqymWTIy_8QOn23COpxMyJDGRdUQ89cBCtDePNtZWwT_W9UOhoq1XyQbhG5ey9xMuv6 mROMsztHB.9sForSjzDAdgm.Fu8dh0aMxTPiWZtG6nI0NqQckC4ve5dl5abJSF3BFLaoGQXB5lX2 tJ7K0jMq3bfxqXWvMbJjcCCx3FGX6yIPJPHenoVkZtZn8m1ud1G1zlj2xBmXc_7RHQ_MY.kk7ec2 RV2FTnlkIKpIkWCGPlypPfWhtI0UCvPHaXYYESLe20AlRZj7MbVZ7QZoyDPe0XNqKMC_MMrAves0 XIqk_f8p0DzT4YYAqxfTddQ35_UUcJfBOJYEjeCUOYSHOqm_eAB4rJZiSfu.ucmw6yZPB5CZk7Kf KwYtjuayJmOwkfORE4_LlC2qhF0SXqPiwmnRoiX2K5WpRgrTdt.DM4eRsfARLU093YmB9oLS2nJi oWP_by4C.mCWXg_XF4prul58qAxA4PP0zzqrlxEs0MDSvqs6PRTauFD6lRq1NLkvrMDrTvhzkCIw PR5wrkLDbJC91jHQh9dZev97yKbavrtoFuS2ez5sPNR5VO_qTNzxrfXFjijeQkSXjEil.4sVP65h KZe76DbFvzHMQu2vW92GRhQ5GSasXoWrjcHsMcX3EAqFjnI2mJSeucnFxHAdcVESo8cnWavonaZm b3E_yzClCuY5Ea0b2kBmDRds5qwG_tD5n56EZbxxlyeZG4SMahjnENhjOaDEpZfKNgB8DTh8Rru0 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 From nobody Fri Dec 19 17:34:16 2025 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 ADF4B1FCFEF; Thu, 5 Jun 2025 16:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142277; cv=none; b=ar9LYdoQz4DpoON0cLSlllyWH6VWe4sZWIqVUe/dH3LSnEKz35OyKvvvdt7ubkKqpYzij8njzQPluHACtfJYECP4AG1Y1uAfVYp/NcL4boSuD/UFlrEy00XgHCHp8FEJWpQf56S0IPXU8CB15TbB/XnbEGP1fkBj84F4Uk8XSEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142277; c=relaxed/simple; bh=zFICxLJ7QOuBQtUlRFqXRP/ffC4QY3bC9sQSxn88Aj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHMxSiJFlq2ZSbcwRCD+o1CZbtWFf2JXYPfFonG1XbnX9CS4tmtjUQeTH8hzWsfPNr7SJbzfqe26fQglKjew1GL0MdbEZ2HO35ptvUpvSmh3+5vR1rPy52SpKvtgRpqWl2x9oxol6MwpS9zf1DlNa0KIz4rgeSZE6Vzj1QtSLag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NFxxUJNK; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NFxxUJNK" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a50956e5d3so1044970f8f.1; Thu, 05 Jun 2025 09:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749142274; x=1749747074; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+gws1FSnzirsIRI31OhrbcqvSnTpowd3o+HlbUmORps=; b=NFxxUJNKlLVHiztlJ2xngXiwD7Ox9V6Iji+w1eaPErqxJbK1AieLycZem0uXtNdqHA oT7fnUgVRCr6Y+gLE7YnUnRoYj7oi8bOUO/gRZyy+MAkviPa1UIWHp3QuF/hlHf4V7gf OVLmzDEGQiMHCiJ8njtu+Bud3K6tRk1c+dii19rfUcKDh9SWBEEK11kjYS3mhC4S5Vde MN96QBDSAJRgh06jQgIlWFGm0BsxdrBukCQQPMGqAha3wGlfg46S7OJVLOgkYsl/WNCa k7DEgJubL9lQNDCVRl9PvtJBrE6iWfjS3wU2OE5JQh7CF/BhrvRc3QRFzQEy45Acecm0 Anxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749142274; x=1749747074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+gws1FSnzirsIRI31OhrbcqvSnTpowd3o+HlbUmORps=; b=mhKsMwZrrE5tPau60/oOusTv4eJZ3krbez4H5gkaaNakNOkSzodtJYUGzeGcjdC2Ji VqXXCLZ601QLQyKwh3pLB9rz+N2Gdza7f861KZGMk0U6/ssAwtkNMxYxVbCJBYQN4WMC Mbbre53R0CnKRJmhLE4R8YMj0Mz1MK0PIyt31rcLAVbG1DA/SP6RM2RCdGsFcJWc0BO8 9HrRc9MJDQL5ZQiZmiDDhY819tM7jbDwI0OPUzou6jk4oFvgAteVA7/DAFZG8/S5Lsau Ttp7Akt5xlfbnxHHKkvacmIVXcuHAinqNfWlhwHhi29NJB9aokxejnFv3goh8K6HYQUs yp8w== X-Forwarded-Encrypted: i=1; AJvYcCUeqjuArp58zsPZXNwuL8NnVqmtGgRJ/4kxlhhJpaCgRutKw63Zep87gx6WxTd18dwHPb1UukMtknI+@vger.kernel.org, AJvYcCUujMBOnlz9L0CHZEY/ODuMRsNVrqD1mgWtOEOk3j5fDPLqLMwV/C08ZV7rHbbYvNJEncii+MNlRfsR+Q==@vger.kernel.org, AJvYcCVJRtA3bnbQNhfGx9w+gSfVXTVKE2qkxDXpnvbsmvqk2Ykji1FnDdWgkBeGoC/kjgFcwd5qVntRwTyw7Zo07kE=@vger.kernel.org, AJvYcCWx/ScIGONjf7K1JZEi2/y1URJkZFSeVz9Ndq1RBIOkEKgEddL9Xp038eQjpKW7GspRDnA55UM2Gj+Zu4Cm@vger.kernel.org X-Gm-Message-State: AOJu0YxScwW27TQuYRVVaJNphvMdAJ13cqtu5+wynWuovo0WjiZ5E3nQ 1VvS41qNuu4r0siijByH5Ikpk+mTcI6AGuQRgweycffyPlI34LoeOBcjeyn3LAsKyMM= X-Gm-Gg: ASbGncsVmv0xVSfmxYhykwhn0KjGUzDcbMNRTCNURvyOmNrwZBFX2BJroEXJd8mftdJ O8WeTlKaPfPJrVqeHU+0FwYCyT5ZboWg9PYAYJyVPwM7hjy49ppBKcDt5EoKVWzBDhk8Gf+F/8/ Y/Jx6wPI46/v7gn4JjxIUP6h6wFFyDCA9aL34J/Hx8gAybABBnJc7B8yN0LAfyh9U/ftq9j9Cf9 6JVW/94twoW8m7Ob9byV5kjy8zIlB8nuIO0d+tlW3Uusc3XUHs7hl38xuuDBk54rUNM9SJnXcmi DNDwlNAxvNaVEUjT7hpCj0ZrnnpmOw/EN0Uhr+/9H3UY4MEL6ZQaO4wSVjObBhsjkM3Mvj9Uewm 8cqX7VmhcJRqbFmJ/qYZnNoo= X-Google-Smtp-Source: AGHT+IETQzNQRtz4ljBAITFGPNNxQ8l9shjxzB/APN0oRFkd3PaYObXcukoJTxiNospnSQEsDUdM7Q== X-Received: by 2002:a05:6000:1448:b0:3a4:ffec:ee8e with SMTP id ffacd0b85a97d-3a51d968aadmr6341812f8f.36.1749142273474; Thu, 05 Jun 2025 09:51:13 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-451fe39fc52sm13286175e9.27.2025.06.05.09.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 09:51:13 -0700 (PDT) Sender: Igor Korotin 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:51:09 +0100 Message-ID: <20250605165109.3663553-1-igor.korotin.linux@gmail.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" 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 From nobody Fri Dec 19 17:34:16 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 5FC461D63C0; Thu, 5 Jun 2025 16:51:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142312; cv=none; b=lOFJSlKTLwgZCVJVvGq+Q4hy5dM4Xzp3Qcb/5JM/QDtk6QJEjflif2XU7LZA7scVM6uMtWgmfpywG+ECZk2SeMZYBpsZ8/+HbB4DLhBAhUsTot+8Sz7Y7F18DN24q5JU+1c712RDAsqF26jSriV70GjhOKMNSxlV3ssvqnrJZsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142312; c=relaxed/simple; bh=EKuEJj1hiN5FAUPJllRUOb+XzT5dqu2BT3noUkRJ9Rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CSu1wGIYThGBoOeGlkyecenKFTuBU84/YJi17W7ToIHvh6L5h4RjIl0kGeKJH0S2+jh0KCd8xLjwFcd/PlblKgnZrsrr+OAlwAZ7SG7JsM+wmXx78Bbd7AevvrtZ9uj3q8p8s2FJl7ZlxhmkU5wEZvWmonRM2v8ADJFM0xB5e3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hu3f3a49; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hu3f3a49" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-451d41e1ad1so10127595e9.1; Thu, 05 Jun 2025 09:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749142308; x=1749747108; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=Zb6n4xN+CaXNZLNAdkRh4qtNOwrRTbDiXvfunUMx5/8=; b=hu3f3a49ctgx2xSr9S86FGXyEKTuUYNUWePORqobm5O4Nw6k6lVhoRlLAvL2xNNYll 16CbhTpPqFZiQHvkz6rlXS/IzqZRwd3ZU+sRiy+MMOfAbMGzgc3fWH6jc35mkBZwQFAX a0dHiFrYoT3sEnBXIGgfSrZs2yjiy0Jp55mCkM8E9Yl15X04l/41zj5o52YNvv3e7RmN +0wRu4UB/xtBwhPZzQmutETtObAquUrbaSlrGNjOTl+vn3tO4GpSeLkC/Y9TPbgyzvpi /9Fs58k72MTEGPTyFZIxJBIwsNy30In2pHNRMCcTkU12CJFbb09aAG6AjFGsxQcmFj+O SN9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749142308; x=1749747108; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Zb6n4xN+CaXNZLNAdkRh4qtNOwrRTbDiXvfunUMx5/8=; b=f/n6jXlZfstgRDddDNHn1sJ1OsLc2415JfUuoZZiGO9ITmPHA7HkUDeJdxsq6gYUoL RfTGNr0eYbY3SVUUdymTPy7RAzx54H2qubk/+9T9AwiPk7PEq3UtA5sZhfs6tSXVr8r6 7vUMaiX12yvuyQXXJJfVju43QkZ2U9W2yc5VqF8ep9KIWzVEMhWx6GIJPVMUtmzPCsB7 w9VicrIaC8IyIRJzQVg0RFx2cuziGZKKhRpIgrwRQgUBQ+JCmcBRcm6gOCzySA0ZgnzP hUjd+V6TrwOSmWESKjjzBVDckqX2X+WlQMq4RbjVU06LRGiFnFBgTJh10u7Oyop8HSPl 3VXg== X-Forwarded-Encrypted: i=1; AJvYcCU18jPvok1adoYixYErGbpxUoN9hoKchliKYrmoSaGBhhszCZwv/G2WPQKISH48Y5dW+ziJCotQnj8oahKbvks=@vger.kernel.org, AJvYcCUUi404biVziQnxvLdLBBKPyuDTq2w+I5ntELU/gblBTkpZOf7FeLr2a6d+xt4h5XViv6N0Zs2FZwyC@vger.kernel.org, AJvYcCVDbOcM0R8F70RNZ6hV8jX6snm4hXYMxznQwrtb2DZfKmgbV+Z0QzIy1+0IIPqW8n63NfYglTv+eODjPA==@vger.kernel.org, AJvYcCX1qdFNrrdxi4APJjK4rHuxdPmq154gSca+vQ5gOT4O4xPp1Khsqh5ZhSsgKlT4uxho9hI1sGrXckIMb6Ch@vger.kernel.org X-Gm-Message-State: AOJu0Yxm4B/pPMZTjPD2qq9C4zXZ1DTl4BPA0hQHXUGOQdQMKmtvwy+1 UOpfaaUwiKRswsNq0DXuAV8PrkH9qIylgvBHq47aR44tjWaLTURV5vOD X-Gm-Gg: ASbGncv8l9Uu4BkkUXXxq9KQRgaLstGp1eYplXZVu8qAFGJzvH0DThMYVvOkPNUMbgH TFZc4LNpKRN9cQYPSskv31zJwDKvRURY2PYbjvj6YxhBvzOcEI63UAaKsRjKhvOM29nWMVam4xv Zg2WKJIJVh38o4QMGVscXbN3wJ62MVamxXy9zcQ/i+0PJO99DyQpX0mxqTv1O0UxIe9ll7rmdz6 qJ7yizwjZ6JmfSN7nDc42OxWmGbGhMcLrm2lbBDTjFwl6Qrl3JqIOWPeqWvJqo91L5/cW+DsvW6 sAL8pR5GPGfezX6vImTFDf3lh879hA8IiXF5u7iARekUW9Sm7QHRqoFYV2Va8Utxk3A68PTKb3Z gpeuujZYcjG4avxAfkwgqEPA= X-Google-Smtp-Source: AGHT+IErjGYl7sI7GIuDfz4J4eQlm8b9WIboTOmarv33R4sio/kFqZCnW1PcwtspN8KbUlz+HhwPGA== X-Received: by 2002:a05:600c:3504:b0:450:d00d:cc with SMTP id 5b1f17b1804b1-451f0f00d51mr73369675e9.2.1749142308298; Thu, 05 Jun 2025 09:51:48 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-451fb17b58fsm24015045e9.16.2025.06.05.09.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 09:51:47 -0700 (PDT) Sender: Igor Korotin 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 4/5] rust: platform: Add ACPI match table support to `Driver` trait Date: Thu, 5 Jun 2025 17:51:44 +0100 Message-ID: <20250605165145.3663681-1-igor.korotin.linux@gmail.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" Extend the `platform::Driver` trait to support ACPI device matching by adding the `ACPI_ID_TABLE` constant. This allows Rust platform drivers to define ACPI match tables alongside their existing OF match tables. These changes mirror the existing OF support and allow Rust platform drivers to match devices based on ACPI identifiers. To avoid breaking compilation, a stub ACPI match table definition is added to the Rust sample platform driver. Functional support for ACPI matching in the sample driver will be provided in a follow-up patch. Signed-off-by: Igor Korotin --- rust/kernel/platform.rs | 14 ++++++++++++-- samples/rust/rust_driver_platform.rs | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 3cc9fe6ccfcf..e6cc878a5a37 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -39,12 +39,18 @@ unsafe fn register( None =3D> core::ptr::null(), }; =20 + let acpi_table =3D match T::ACPI_ID_TABLE { + Some(table) =3D> table.as_ptr(), + None =3D> core::ptr::null(), + }; + // SAFETY: It's safe to set the fields of `struct platform_driver`= on initialization. unsafe { (*pdrv.get()).driver.name =3D name.as_char_ptr(); (*pdrv.get()).probe =3D Some(Self::probe_callback); (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).driver.of_match_table =3D of_table; + (*pdrv.get()).driver.acpi_match_table =3D acpi_table; } =20 // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. @@ -98,7 +104,7 @@ fn of_id_table() -> Option> { } =20 fn acpi_id_table() -> Option> { - None + T::ACPI_ID_TABLE } } =20 @@ -129,7 +135,7 @@ macro_rules! module_platform_driver { /// # Example /// ///``` -/// # use kernel::{bindings, c_str, device::Core, of, platform}; +/// # use kernel::{acpi, bindings, c_str, device::Core, of, platform}; /// /// struct MyDriver; /// @@ -145,6 +151,7 @@ macro_rules! module_platform_driver { /// impl platform::Driver for MyDriver { /// type IdInfo =3D (); /// const OF_ID_TABLE: Option> =3D Some(&OF_= TABLE); +/// const ACPI_ID_TABLE: Option> =3D Some(= &ACPI_TABLE); /// /// fn probe( /// _pdev: &platform::Device, @@ -165,6 +172,9 @@ pub trait Driver: Send { /// The table of OF device ids supported by the driver. const OF_ID_TABLE: Option>; =20 + /// The table of ACPI device ids supported by the driver. + const ACPI_ID_TABLE: Option>; + /// Platform driver probe. /// /// Called when a new platform device is added or discovered. diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_drive= r_platform.rs index 8b42b3cfb363..e3992e7a71e9 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -2,7 +2,7 @@ =20 //! Rust Platform driver sample. =20 -use kernel::{c_str, device::Core, of, platform, prelude::*, types::ARef}; +use kernel::{acpi, c_str, device::Core, of, platform, prelude::*, types::A= Ref}; =20 struct SampleDriver { pdev: ARef, @@ -20,6 +20,7 @@ struct SampleDriver { impl platform::Driver for SampleDriver { type IdInfo =3D Info; const OF_ID_TABLE: Option> =3D Some(&OF_TABL= E); + const ACPI_ID_TABLE: Option> =3D None; =20 fn probe( pdev: &platform::Device, --=20 2.43.0 From nobody Fri Dec 19 17:34:16 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 ADFEE274FF5; Thu, 5 Jun 2025 16:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142357; cv=none; b=YDk9vSClL+bWP825VFEIfKv0RO/8EGV6tMqzW/NgDzMPT0NcarnzQFVg6VXnU+8MzNWEylPX0XS9WzRYYAJCNyueYYQF61UqUV2qKe8KNQoBalSjMrCnICVutAHL1MvXMkrvE/LiQSKQO7sQgU1sZZHrpr/KkNYDb+dQTqRaZQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749142357; c=relaxed/simple; bh=eX5FQHelIYrl38B1a0jr4ldOd7+nuInFcQIy7hA5GlU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QsN99hg2PSLkohWMQ3KewkTkZ5fRIdthcLdBlEfYbOjLHL5F8JJ2q9dn5/AHWSTqp8dZJyUFwzzH/ZsBUIL2S3957r97R+vgUdAwrLlog4GV1+RKass5ZQ9zF+DSpMkuvRZNXsGWPC+GM08O4TlMSMKDv5w42mvlXa0rlKOPRFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S9dkOuxw; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S9dkOuxw" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-451d54214adso10653295e9.3; Thu, 05 Jun 2025 09:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749142354; x=1749747154; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=IYiYcUa0Zpd9O4aRs/ez0DwzmhVXN2VCaXs0fidvEQc=; b=S9dkOuxw9mBB+OGU0v9Knwtg8W9X6lcu1Lgs0B9rd25bCxCdWSBdsz+9naimxUZpNT zXKoXlZORkpr3S0TjV3pG1ycyRK2d84m5/ovPo/trWkmDA2J/QzkD9klymZJ0fNC5zt3 txZk0zNZOuXHCGi/477nCC9mDBT+IzRts9URxqsmsmKI5DgLMFJWDsyFA+0V9qH4OvLE jKZ6igxDjf/gXatGGgZZBdv9EUgeSnlSmsArsPSgPp/MaGcTJ7lYrrU1m/Bsu8xDKj9X 8H99VUR9E3Qd1ahRztb2naz/GrBhTH0/tD5vtceHwFxfWdEmZEogXPKZpYxpRg0HjdXw F3OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749142354; x=1749747154; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IYiYcUa0Zpd9O4aRs/ez0DwzmhVXN2VCaXs0fidvEQc=; b=iE+wUVVBPYFMJ4d8rA0YCVa5ZczN4zSedoHPIqJwQX3kbMfQlBQLtgDB4v8RV5lM3O hrrubXlCHkFKd8s4tcM2Q7QERTZPr28RFeR+FRBpBOlXHqX3wd63nvaAtoRrIT8gXF+r PaKAhQ+XP2hJIRPkTdyvB5SCGEV6tMbpX6c+DqIzkxqv5hqlgAqEcT8fbdJ0jVgT/ewG fUT00TVJcWOQu8nqTI1pUllv9lUlzYSIIJ38ObIV0//Yu6VCuwAsYba2rVn3ypcstwK0 N7LmZ0hsg8XgBDqsFQrnL3gcahW+6lknMJ566zKVO9NylP6hNIpljpPpvFs9sVh7D7DL r37A== X-Forwarded-Encrypted: i=1; AJvYcCUEjqxbczcnG1vvPTrAMHfbnYi0XBft5eYRAFeA2kAsw+Q5fa3weCrQ1VwoChNUxsQgqO8ZwzzQLAoaYnKp@vger.kernel.org, AJvYcCUv6O7DI5a9Fgz7s2uG+9qRvgI5eAYXo+IYnryfAcxhY3sZp4XtGgJZY8HxUtBUU/y2PVplR4MTRkWK@vger.kernel.org, AJvYcCXTg9F+iHMYPjCZUmP/H29DbBK3Ge9erMo+OP91X2FOVId4vGzBqpmNr8wSRMKJ9eZutqbG8KLRIvGLETK2Gi0=@vger.kernel.org, AJvYcCXlphbJHqCqNBdA0Yfr18H4lNlq0ZSL3ZfB7xILrpVoN6aiC0/h5C1lRlSp5m1FNEb744qsAZmxG+HoqA==@vger.kernel.org X-Gm-Message-State: AOJu0YzWcJlsf23o45L3vqZp2nQ8TyoP8HTLcSyT5p3TjlrT6Cft67q9 uRh8S8+tQFiqG8Aaa676BnLujep/bNr/Bve7ZpOl6wAH/P4UxlSKOZBG X-Gm-Gg: ASbGncvibyhaH127r5EwQL/SHVvdFuACb0tIG2dlS/sr2/J4/sM1sCmpvg6qyYIFAVu FBqZlQ0bNzaJfE7lhkAisP4qLL1JNuPHqwe2ANVl4AAL8jM2JBDhcJkgEipVXUI+7ZXgE8FKtvC Da+kgyKZA+nQS8HBPkVoZ5BHEmQLn57QNaF4I/Vcy8VWP9f4JLHp19j8nLBzFawwBLbAx1OwxJv EbAFEUQdNjWH85weUq2R0seP3K+FzIInhKEBqCBVa2lItmFqbjPQPdmKl++fL2ElRwgiPfLp++w dzu2hYL2Nv2nHaAqjrs0FVh4cPxwX6aGzSia7vlLhRt71VvkTYreLoDMtmSN9AW/ooWzOFG2k45 aYx2mi8A/mG+q X-Google-Smtp-Source: AGHT+IHeFI6tIeh1xtFilZ//Dhpls7kj68vpPnNlI9lKURjevXM8botgo7CebM3JFPfxAU3VtdR5kQ== X-Received: by 2002:a05:600c:870b:b0:43d:42b:e186 with SMTP id 5b1f17b1804b1-45201350c40mr291925e9.8.1749142353614; Thu, 05 Jun 2025 09:52:33 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a52a1993ebsm2184495f8f.93.2025.06.05.09.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 09:52:33 -0700 (PDT) Sender: Igor Korotin 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 5/5] samples: rust: add ACPI match table example to platform driver Date: Thu, 5 Jun 2025 17:52:31 +0100 Message-ID: <20250605165231.3663810-1-igor.korotin.linux@gmail.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" Extend the Rust sample platform driver to probe using device/driver name matching, OF ID table matching, or ACPI ID table matching. Signed-off-by: Igor Korotin --- samples/rust/rust_driver_platform.rs | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_drive= r_platform.rs index e3992e7a71e9..ee0780c1d6ae 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -17,10 +17,48 @@ struct SampleDriver { [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))] ); =20 +kernel::acpi_device_table!( + ACPI_TABLE, + MODULE_ACPI_TABLE, + ::IdInfo, + [(acpi::DeviceId::new(c_str!("TEST4321")), Info(0))] +); + +/// OF/ACPI match tables for Platform Driver implementation +/// +/// The platform::Driver requires declaration of both OF_ID_TABLE and +/// ACPI_ID_TABLE, but if driver is not going to use either of them +/// it can implement one of them or both as None. +/// +/// # Example: +/// +///``` +/// impl platform::Driver for SampleDriver { +/// type IdInfo =3D Info; +/// const OF_ID_TABLE: Option> =3D None; +/// const ACPI_ID_TABLE: Option> =3D None; +/// +/// fn probe( +/// pdev: &platform::Device, +/// info: Option<&Self::IdInfo>, +/// ) -> Result>> { +/// dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n"= ); +/// +/// if let Some(info) =3D info { +/// dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info= .0); +/// } +/// +/// let drvdata =3D KBox::new(Self { pdev: pdev.into() }, GFP_KERN= EL)?; +/// +/// Ok(drvdata.into()) +/// } +/// } +///``` + impl platform::Driver for SampleDriver { type IdInfo =3D Info; const OF_ID_TABLE: Option> =3D Some(&OF_TABL= E); - const ACPI_ID_TABLE: Option> =3D None; + const ACPI_ID_TABLE: Option> =3D Some(&ACP= I_TABLE); =20 fn probe( pdev: &platform::Device, --=20 2.43.0