From patchwork Thu Jun 5 16:24:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894214 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_Roy_Baron?= , 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-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/git/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); +} From patchwork Thu Jun 5 16:51:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894213 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_Roy_Baron?= , 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-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_helper.h index e0bcd130b494..d974fc6c141f 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -6,6 +6,7 @@ * Sorted alphabetically. */ +#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. 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, ThisModule}; use core::pin::Pin; use pin_init::{pin_data, pinned_drop, PinInit}; @@ -141,6 +141,38 @@ pub trait Adapter { /// The type holding driver private data about each device id supported by the driver. type IdInfo: 'static; + /// 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 in the [`acpi::IdTable`]. + #[cfg(CONFIG_ACPI)] + fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> { + let table = 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 = 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 `struct of_device_id` and + // does not add additional invariants, so it's safe to transmute. + let id = 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>; @@ -178,9 +210,27 @@ fn of_id_info(_dev: &device::Device) -> Option<&'static 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 = 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 = 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_ops`. + if unsafe { bindings::is_acpi_device_node(fwnode) } { + let id = 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 = Self::of_id_info(dev); + + if id.is_some() { + return id; + } } 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/platform_device.h) 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 + } } /// Declares a kernel module that exposes a single platform driver. From patchwork Thu Jun 5 16:52:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894212 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_Roy_Baron?= , 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-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_driver_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))] ); +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 = Info; +/// const OF_ID_TABLE: Option> = None; +/// const ACPI_ID_TABLE: Option> = 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) = info { +/// dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0); +/// } +/// +/// let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?; +/// +/// Ok(drvdata.into()) +/// } +/// } +///``` + impl platform::Driver for SampleDriver { type IdInfo = Info; const OF_ID_TABLE: Option> = Some(&OF_TABLE); - const ACPI_ID_TABLE: Option> = None; + const ACPI_ID_TABLE: Option> = Some(&ACPI_TABLE); fn probe( pdev: &platform::Device,