From patchwork Wed Jun 11 17:44:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 895773 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 AFB9D273FE; Wed, 11 Jun 2025 17:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749663973; cv=none; b=QGIW8FbJNhSx/z/CQWIMefjJt9O79mGAVL7BbLXwCS2GfQjZQlcv6qTQ9SqJPiEGJvLlvcE3rFVORymNehpNKuABca4iYjZ9bNgBHLXfVWHMEj1gomQ2O6agO50aLLQ1BpUGZnDK0QXPzdQbcSSku1AfH2oQxzJath03Pc3pTyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749663973; c=relaxed/simple; bh=fLM1J7jVqqiZf/ld7d1JFGfRWVz+teNjK6y084/tbPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OYsA/VFh8BKNQ16b0t7aKBjEOcQtJJoh0Kkt5UDlxfcY/v+UZdp70vqzabysSFoPOQ5fQWEFofz9xHnMWCtH6VtV7LSG5Ntv4J/Kw2Ubgyd7oX1/wa5mjJBH/CjsmAnAjtBVlv7jsbXnuRQPx8kY0O9Uqkn8jtyuEXocspXnGeE= 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=bA91tdkU; arc=none smtp.client-ip=209.85.221.44 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="bA91tdkU" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3a4fb9c2436so108744f8f.1; Wed, 11 Jun 2025 10:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749663969; x=1750268769; 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=oudxA8JPC06HRjXurKEPIdr/6i2EGFIADSPFZLQo5s0=; b=bA91tdkU6onYX4fGazm4pYNEIDNPDZeV8Hnu4LfKRYgEUhIPawNFtdIDjZXdnNWmHL f6sc2EryXEetjIUwNeB/9x++MsB8X6icP+Ccd+qMX35AjoGqevR7pqD5apKDW/slNmOI MYsidSqyEm7T54h+H/y1oWID2iH0S3Lizl04drsMpEqWtNPLWHXEFndeDvF0IrALbM6l A3uHDyr3PVSC4at3KWE9xHvAxTtKpOBmwfFY9AqBZdM7hyPxzB0gzzE9FRrZpVmJbZlA q4P2NF/VN4OHzRNCNOkiD6LIDPI/57XxJ6jiKJB4coU7JiAhlh7wr9qtZ8huYhL6+IE9 Pt8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749663969; x=1750268769; 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=oudxA8JPC06HRjXurKEPIdr/6i2EGFIADSPFZLQo5s0=; b=UBrWEq3y2UnDy0M2K3nDRNRNyPm0JK2vEuZALkxxN2h3UnxOZYGDLpl0oz4TdWq0Kz IrS9G+zEJ2qxbbALUlPlF99ZF4KGQAw7NohueOKf9IOobTv4y6iYW5eDHmHdjUR73JKR Nw5FK5POGTXgrEGSLtZOKXaDWA6/+OX+QBaLoGu2/zP/12pEdx53+DHFV6mc8ULZ5oCT kN6plaaTr8YKTtmUeYvAjlG8L10R4NiycUy9CT4aLk13XM3hdX1IXSNGbUkQQUeHWVIM 1QMjZewIli5t42qf8zSCjSnSsIpqEwFfUMO0J/GD4tIUARvdmatYOcMo2DM0BaMtsXv3 2+dA== X-Forwarded-Encrypted: i=1; AJvYcCVf3YIFUMw5fW1FqKnuKbxEAs7JdMJ703n8AKYYCKLXNdM11W8aUx3WnFzq3HTHlW59LRhTaEL3DTSEgCFEss8=@vger.kernel.org, AJvYcCW1oEXQqazk2IRZUb8brOy4rpjk3T45PokPbyJjDvblon0ONITtfLillmVQ6YR4PqgJA0I116b46Bys@vger.kernel.org, AJvYcCX32+w9OShHlCKG4pxm8AhA1PgjnTXX3oCs8dGVqHCFD+E/95+KBi4VQ/q51ARFVYgJJ3V2SUBeUKWQZNZc@vger.kernel.org X-Gm-Message-State: AOJu0YyMoxXMZ8JBNmHOz8l3ZILB5lT6qWIZeGHuHKajm662OnjaWzUF PYmm+5DesYli+lbklUBw7Lf+FwE2HOx+gXGCZl2fHVKTanALu9ivlN06 X-Gm-Gg: ASbGnctxsFksvhdip2Nq2B/IVGo+EhanEMIaywSq3oVLRW/tJmVht4KWMK/wqIBbrth JjcOn+SPY4jd72ULLDNOUws9F5PD0iR3ZXLka0lfzZbA1fU5u1wP7BxUUVB5N4sp+0bKqbtqJUb 9344O946z0PLl6zmU2DQshXyLPmh0m2FhlcP9r5QT5CEg7komwD9jRNZ4Ck+R+YhyU3jafwc9/0 LG7Cp4uUva2J9inZU1Vmv7XlQSKlrLY3E/5I2KmSLAGFWrlm7n7DQ6ft99Lri057N3UGPj6IHd8 nmX3gNQjmkEoahq8Tbka3OANKNfF6AfPGalqtBML6wloxymRMEYL/fog6AQSVrVAWaoqRYgivg8 aJrV0w9NbfqwB+Tdg86yIo0qvitDW24yz3IFQ+T89Nx+C/t4= X-Google-Smtp-Source: AGHT+IGis81OISeR1H6EKCsnDF9D+IMc7DX0AsSIPHEM1aS4aL6icCQI8s3ZReBVHMGuxWp9hN3iTw== X-Received: by 2002:a05:6000:1785:b0:3a4:f7e6:284b with SMTP id ffacd0b85a97d-3a5606a262bmr288137f8f.10.1749663968775; Wed, 11 Jun 2025 10:46:08 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45325171e16sm27667525e9.18.2025.06.11.10.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:46:08 -0700 (PDT) Sender: Igor Korotin From: Igor Korotin To: ojeda@kernel.org, alex.gaynor@gmail.com, rafael@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, lenb@kernel.org, wedsonaf@gmail.com, viresh.kumar@linaro.org, alex.hung@amd.com, dingxiangfei2009@gmail.com Subject: [PATCH v5 1/6] rust: acpi: add `acpi::DeviceId` abstraction Date: Wed, 11 Jun 2025 18:44:06 +0100 Message-ID: <20250611174406.802093-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611174034.801460-1-igor.korotin.linux@gmail.com> References: <20250611174034.801460-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 `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 | 61 +++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 63 insertions(+) create mode 100644 rust/kernel/acpi.rs diff --git a/MAINTAINERS b/MAINTAINERS index a92290fffa16..6c809ea30e6a 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/ ACPI APEI diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs new file mode 100644 index 000000000000..f9a98dc4eb8a --- /dev/null +++ b/rust/kernel/acpi.rs @@ -0,0 +1,61 @@ +// 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 = &'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 = bindings::acpi_device_id; + + const DRIVER_DATA_OFFSET: usize = core::mem::offset_of!(bindings::acpi_device_id, driver_data); + + fn index(&self) -> usize { + self.0.driver_data as _ + } +} + +impl DeviceId { + const ACPI_ID_LEN: usize = 16; + + /// Create a new device id from an ACPI 'id' string. + pub const fn new(id: &'static CStr) -> Self { + assert!(id.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes"); + let src = id.as_bytes_with_nul(); + // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`. + // SAFETY: FFI type is valid to be zero-initialized. + let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() }; + let mut i = 0; + while i < src.len() { + acpi.id[i] = src[i]; + i += 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, $table_data: expr) => { + const $table_name: $crate::device_id::IdArray< + $crate::acpi::DeviceId, + $id_info_type, + { $table_data.len() }, + > = $crate::device_id::IdArray::new($table_data); + + $crate::module_device_table!("acpi", $module_table_name, $table_name); + }; +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 6b4774b2b1c3..5bbf3627212f 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -51,6 +51,7 @@ pub use ffi; +pub mod acpi; pub mod alloc; #[cfg(CONFIG_AUXILIARY_BUS)] pub mod auxiliary; From patchwork Wed Jun 11 17:46:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 895555 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 48FB12222BF; Wed, 11 Jun 2025 17:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664110; cv=none; b=po57G+7hhnyxO+1edlvuDN5jJfjvrQoZGESksa+/aAqKQd+YFAxFqOtEjTOYsDQ3gN3UPeW9H0EYmPCv2NYS+/vDr/AoZip5AOnpOxEuXt62b/eLFZef5yFS4jx7gfKzKq+CJfCv/D3BpoxSguWDSHfbzfAXFKjAqn0QIIZoaWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664110; c=relaxed/simple; bh=kdiPdMh5+sRzNgtYRKj/S0sAtUte5v+zpvWVg0DO3wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mv4wyTSPNILOqSNPxZ1PmLgyendbjmIVa97yp0yf94erd+W9rFmgRgs8wrVuCJj0/iWplB+qRO4KOdGek1sZ7tIq/j+iuDskyAp8AXWU/NxHVp/2F/zckzSggGHVmkaVNiCeHTbumB3v2haGYPgH8LNXsVPV1xGFAT7GYaEkm8E= 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=OWzVMf6s; arc=none smtp.client-ip=209.85.221.44 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="OWzVMf6s" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3a503d9ef59so128832f8f.3; Wed, 11 Jun 2025 10:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749664106; x=1750268906; 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=/5X6IDTVHTHpEsUSABa7MSKK8TKkDRNQdpFJlmd5FHY=; b=OWzVMf6s6ieIQYLHaHb6ghg7Xx8IL2sFjoZGw798cylsvbkontJo7bpzQVrFEu4Yuq iTOT/c2TIUt4xopwrqKsSA/oWVFA7D/4FGth21PIq2mDpzWfjdbZatc5dda/Q+KZQ/zK r4kapflS0SPVyP2rn55Ki32gFjFcPAqYPnOH/Cy3LGATKlNxM+2LCU2/0Q+yQQJ/bfAm x8YGJ/gy+Mnm3VidenQ9BgX12kRBpkJUcb8u+Gng6KL/QpH3Q6C3w19FiOIle2/f+OfW PAQA2a88e/0ox4kX4XUrN84pLHq8NYxgubVDFizKWUAsbwj9iRpfbCRz9RYK6Y2O1lwO rZYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749664106; x=1750268906; 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=/5X6IDTVHTHpEsUSABa7MSKK8TKkDRNQdpFJlmd5FHY=; b=YyZKE8/duq5Ok8fAQSy0YXB/WkBtcpJFtV35/64JiWv2oIb/PB/J41HeqenyLf/xiF SpS9rs4OWHKXbRBxl2hZhsiS0mJlBJ0cv8t1W6xoFZ/YNNhNiAKQo8dzMMFWILsLBzUe GDTyRLYXvOCmIeColvvKuUmQX046nTlH2dMQkvV3vLWLXOttHd2ZoWFXbo3SXbziIGUe 7FMnkq0XWGUiDJlLy5yjIT1wQyIZQQ3v2K+9TeczYLhV0KZkiAhZQcd6DT9fOIAD4WvH +V0mddy3eJm4zOpaOBl2/F2Ksrt7ShQAoldGMrYIPXRBtltjNXHC32/KrGRKf+jqW46C AKrg== X-Forwarded-Encrypted: i=1; AJvYcCVK4+34hZQUGvJmneRwXv9FBnZiBpBoJDctJhGhFRkT5xl0AlK2a6x+b6kmzZwkPhyO8BSsQzR6y0y/@vger.kernel.org, AJvYcCWCbYsyzcbBKWh4VEKShGTNE3gxa48CMCR5HsQKU93CPBle70oWfdBG7NXW1ObG7AoV1yg/wZeEiMdOGx/5PoQ=@vger.kernel.org, AJvYcCXK6NtMT+L48jUDnWJ6UQ/ILzALnMiziVrNbHuoXn0R4G3tRD1uZ6rHNB94rFYrUm2o8FkKZz5lNq5iO9n1@vger.kernel.org X-Gm-Message-State: AOJu0YyGDo4yqCngu++yQKtuzL8PH8TpySugk7bX4twkvd5f3p36cyh0 HD3eOJ0fYwPDYtbBqcca4Kg1xspxPHOHS/SL9mQvZX5Sn9f4ek56w4pv X-Gm-Gg: ASbGncssNsoINbtMNvNRcNp0B8QZUrAafeVBXzOP6MJIHWdWlxeIU3lLtdwp0qVBk0Y hIp5pmcFzdNMNYo4e2rI8Fp0Jf4OH96rToCQXGQKofckH+UbxHqlFfi5X/uEnNkiW7feORHKUkt rSrgSFOn53w7AP7SFyBiacuX8BUdMLU0g8DLKPwq5xJtPPH8iHZAvYMT4ZNSTH+gxMfrSAVdb0f X+GFhWY9US2ZYjmVKd2yNbo9i90VtogdqaGOxVufF64z1bgiDI903QTmUacGMr7FJh464nDjUNQ InqCTGKe2FAcnZ9GGf+Vlh+aLiyoTaF+aBqbiwqylBAK0Dge6YPNjQS2ky7aaz77U0531mgvUbd PaBM0ExYNGHQJkkRiGEK2YcVavlaK84S//jRF X-Google-Smtp-Source: AGHT+IEWahY4VTUQyB9OJcRC6ofG32cyzKi87gxJN/O8EUIgzlNL+d8o1qKXe//gLU6r8J4BUQxjGg== X-Received: by 2002:a5d:5f8b:0:b0:3a4:dd16:b287 with SMTP id ffacd0b85a97d-3a5586c9e06mr3087427f8f.19.1749664106429; Wed, 11 Jun 2025 10:48:26 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532522a5f3sm29567945e9.38.2025.06.11.10.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:48:25 -0700 (PDT) Sender: Igor Korotin From: Igor Korotin To: ojeda@kernel.org, alex.gaynor@gmail.com, rafael@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, lenb@kernel.org, wedsonaf@gmail.com, viresh.kumar@linaro.org, alex.hung@amd.com, dingxiangfei2009@gmail.com Subject: [PATCH v5 2/6] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]` Date: Wed, 11 Jun 2025 18:46:18 +0100 Message-ID: <20250611174618.802570-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611174034.801460-1-igor.korotin.linux@gmail.com> References: <20250611174034.801460-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 Refactor the `of_id_info` methods in the `Adapter` trait to reduce duplication. Previously, the method had two versions selected via `#[cfg(...)]` and `#[cfg(not(...))]`. This change merges them into a single method by using `#[cfg]` blocks within the method body. Suggested-by: Benno Lossin Signed-off-by: Igor Korotin --- rust/kernel/driver.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index ec9166cedfa7..cb62b75a0c0e 100644 --- a/rust/kernel/driver.rs +++ b/rust/kernel/driver.rs @@ -147,30 +147,32 @@ pub trait Adapter { /// Returns the driver's private data from the matching entry in the [`of::IdTable`], if any. /// /// If this returns `None`, it means there is no match with an entry in the [`of::IdTable`]. - #[cfg(CONFIG_OF)] fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> { - let table = Self::of_id_table()?; + #[cfg(not(CONFIG_OF))] + { + let _ = dev; + return None; + } - // 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::of_match_device(table.as_ptr(), dev.as_raw()) }; + #[cfg(CONFIG_OF)] + { + let table = Self::of_id_table()?; - 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::() }; + // 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::of_match_device(table.as_ptr(), dev.as_raw()) }; - Some(table.info(::index(id))) - } - } + 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::() }; - #[cfg(not(CONFIG_OF))] - #[allow(missing_docs)] - fn of_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo> { - None + Some(table.info(::index(id))) + } + } } /// Returns the driver's private data from the matching entry of any of the ID tables, if any. From patchwork Wed Jun 11 17:48:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 895772 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 5ACEA1CF7AF; Wed, 11 Jun 2025 17:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664255; cv=none; b=Q4tXuJOs1qzhvKKRDs0uzG+5tznrhgu0CZNGaRCukKSwpvUtFc55FB2r/fjC5456na1rAygT6OJydI/OyDRJ0edGP9MnJ9yagATsgZnuOQfBJuGRcWVnQ/gRj7qZfSMiErMAHzxkq51aCjBLfU+5jv0CXA02tGrRl6LNCLKfDaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664255; c=relaxed/simple; bh=1Hy3ujJXBqxV9lfXBO++FN2/fZmpMCZpJfkWT5aJ4iQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6ZsIuRgmdAVHbzeqJt7ZsRf1aP+v7LPMuLhHH0bAMSBng83+ZOJuduNHtxeIChBu6pbkSYSqedzgnetJ0cq+pSnqW68jQ34TWYcpMLf2w9Yaj5a/78jD6uLxhf45918RREOTKsvcVXM0QGfPEKUB+efW2ujrvzkWIChTs/HP18= 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=aSQGRtlV; arc=none smtp.client-ip=209.85.221.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="aSQGRtlV" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3a503d9ef59so130184f8f.3; Wed, 11 Jun 2025 10:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749664251; x=1750269051; 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=f7KlnwZB+CxVWmAEV673+n7G11D71TLYbf9q51R/jMw=; b=aSQGRtlVp15y590zOGhLrOTa9AG1LutadaePKtdJMJ3OCCPVGhraosTXwIHpSOvKFo 2g/LhyLJOJ0WFW7X7h60X/0AI7g/GFry6EaVWIRwHnPmZzuxSH96GYhWU1capO+Nyn3R SKtcyyaS3L4+KEsYuxyNkVoi+FXcgRDlD3YfKI3YoK1lwhHGUSyu5rvFBAz0t2ZubW7d K7MfXWC+3A7wx67EIOfg44K8oWn6yPdfvckoUueAYLTk+JiLLgRaWINq6R2JWNUXLFSW c1dQECkXMGL8nILQOmr4OD8HdTeDiMSO+i6L1lvw1gAtuvao4VPPJlxPwLuJ/gHhqDOy 2gwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749664252; x=1750269052; 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=f7KlnwZB+CxVWmAEV673+n7G11D71TLYbf9q51R/jMw=; b=LvQBBw5HmLfZUXEPmZfuN40HC4T7ifneUfcJYn4+iEYOxa8fIp8gNOINXSCzSwLRh8 c3DBtiHxmPESGvnGcJm1kxdOfhqKbRbypFD68sYOgs+IYPqbLFStnbZA855mcQy15ngX dYk4VlCT3PDyKBvDZUBmUfYL8sjTJ+UzT3hlHdVhRUVR6pIWXABKRfSE+KCV4R6cZkD7 pIVaXtzc2Lb3AzBpWKhNHghvcLrcrIHo6AGw6kOmmohVjP87MczV4eEf67V6DDv3tMWv V6MbFnXg2hKuwGRIAEuqgInqBgs6acfmUSENbNkfCa0GxklaisjcN34oG7UPgisAOHzv uiOA== X-Forwarded-Encrypted: i=1; AJvYcCUqw5H93k+j3WTrtkX/Pc1rg60rJ/2P0gackKOfNbOAccVZuwk9AS3AbO4PGV6fcotX66ydfBZdxT3QKycTcuQ=@vger.kernel.org, AJvYcCW9HNnAbXyywX/zBVQHHepcqlYhnkE+S+Xo5tTZxU4CBSfKeS/RPqS0JMrEuNTgXNu+g2L3a6qZ1XYj@vger.kernel.org, AJvYcCXbGgVW9l07Ps03TUicfSx99/yyu5LrsqlDRwmMZQKWA0BX2f8kOfSbdd49G4CJF1gIBldisW/hXDou8ECY@vger.kernel.org X-Gm-Message-State: AOJu0YypXQODh5IweWSANOeMflCwweb3jaRo7HYo0fI4uRZsmcDinTIw iRDh5Pf9cU38goY8TllTpwo/vFrB+KPJ4wgBAS/5yRzIZvOHcY0WAqze X-Gm-Gg: ASbGncvWPNrw4zoedQO63RiQ5yWOIrNWv4yfEK4OpMtqscr+S3A5Jar2LMRYuWiZx88 R90FWFSPyQVBuxkTZaUUDWUVIf99/GBpoArhF+/Pu7o7Einag5rbtHR9htsJeb4xzBuJgVaqXv8 q1510lgSAum24NwaKMbvAEiwDdYJ85KC1BBlon1x+eOLdgmsY5sq0c4Zg48rLN1ab8JjRRpJfcf iERHsUZNGLPidjgVxmY1WYCXfISuDh3OTCZthbZer6RY46zZRBsnkseUw/ItiyjT6iHpd0IQxgC OMSxf1D+AvvoQ39nxO1WpoJNF/kIaCNu29JVVufrMhCzBV4uO0q6pUZy3OxA4Oc7q1IYEqwAYq5 +aRJCnG6aXys+OHYjShdYqrOwXElAt21KE47X X-Google-Smtp-Source: AGHT+IEPDg33JpYVf5j0B125l1p0dMB8jKVW3wBukaaW8ms6rL5iY2qDPIvs/t5k1jjA+Pax7owafg== X-Received: by 2002:a05:6000:2283:b0:3a5:2e9c:edb with SMTP id ffacd0b85a97d-3a558a1f6acmr3423559f8f.47.1749664251298; Wed, 11 Jun 2025 10:50:51 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a532461211sm15744491f8f.86.2025.06.11.10.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:50:50 -0700 (PDT) Sender: Igor Korotin From: Igor Korotin To: ojeda@kernel.org, alex.gaynor@gmail.com, rafael@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, lenb@kernel.org, wedsonaf@gmail.com, viresh.kumar@linaro.org, alex.hung@amd.com, dingxiangfei2009@gmail.com Subject: [PATCH v5 3/6] rust: driver: Add ACPI id table support to Adapter trait Date: Wed, 11 Jun 2025 18:48:48 +0100 Message-ID: <20250611174848.802947-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611174034.801460-1-igor.korotin.linux@gmail.com> References: <20250611174034.801460-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. Signed-off-by: Igor Korotin --- rust/bindings/bindings_helper.h | 1 + rust/kernel/driver.rs | 41 ++++++++++++++++++++++++++++++++- rust/kernel/platform.rs | 6 ++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index bc494745f67b..dfb2dd500ef6 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -28,6 +28,7 @@ */ #include +#include #include #include #include diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs index cb62b75a0c0e..8389c122a047 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::{acpi, device, of, str::CStr, try_pin_init, types::Opaque, ThisModule}; use core::pin::Pin; use pin_init::{pin_data, pinned_drop, PinInit}; @@ -141,6 +141,40 @@ 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`]. + fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> { + #[cfg(not(CONFIG_ACPI))] + { + let _ = dev; + return None; + } + + #[cfg(CONFIG_ACPI)] + { + 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))) + } + } + } + /// The [`of::IdTable`] of the corresponding driver. fn of_id_table() -> Option>; @@ -180,6 +214,11 @@ 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::acpi_id_info(dev); + if id.is_some() { + return id; + } + let id = Self::of_id_info(dev); if id.is_some() { return id; diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 5b21fa517e55..5923d29a0511 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -5,7 +5,7 @@ //! C header: [`include/linux/platform_device.h`](srctree/include/linux/platform_device.h) use crate::{ - bindings, container_of, device, driver, + acpi, bindings, container_of, device, driver, error::{to_result, Result}, of, prelude::*, @@ -94,6 +94,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 Wed Jun 11 17:51:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 895554 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 BC82A20C494; Wed, 11 Jun 2025 17:53:34 +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=1749664416; cv=none; b=KAMeuniG833RlagezOzacTf/dFeD+ORziiH1Ak6uyBVDsOiR79lPN1R3RY0O59Y0heCmDwADvJkjtJu7XPcjU90JaS2dvCCNToHe5OqGZifuD51j59SpNtTESTz69s5nP42WKhBlLC9n7Qz0vEHw7GM/SzHIeDkMKIDxxErFN58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664416; c=relaxed/simple; bh=Po1X9rUgU4wi71QhvqOh3Icg0CCiu+EgO5R5WUZNJdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eJ10073WIxO/nEG8Y7BWJwUOJcr1IVQlEB44tfSHi7vXIH+dHcXeXozyeyzZWpWf/i1E9gCspDG7NKa/7RvVAQEfizoa4p/5w++WhEJXtDsv2fwPx5cy0+Wz9xfIw5Gu4F8nN8MY+TnO8804/o5Rw+kP2qZ+6150MKQyLlSCtMk= 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=guHekeuo; 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="guHekeuo" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a54690d369so154826f8f.3; Wed, 11 Jun 2025 10:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749664413; x=1750269213; 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=H6PUqmIbDWFmOXx3GycCUnmQ+C2eFlLVgcIz/6kRBRQ=; b=guHekeuoJ6+Th/UpFyROjtv6gqYn1lN+S+pf2STAZhB+5bd5K8hjgBpVAwkWK+Tmy9 KrnNQm2dgliHARXUXN5Kclzb783Raq+vnjxCYPrNrAVmk4EsdBmOkz7kBdZDdf/lq1p6 J+EtsqIrOvhw/1HD7SGqfiEmvAieHJfVhuuXPRJqAEnCxNM3wqstIr64VhNK7p8NyhB6 QbVZhZkHGpQgc5da+SgxQJ/mVcpFMuWJaOjwKG1zsOGPye8rqdq1D2fn7nACrJGHedBZ FIxoPqxDSRxkmRGDLldl/4Yb+eHSDd4xVnI/tlI9Up3sQtMITVOSnNxRhTkPdIFqE98x QN7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749664413; x=1750269213; 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=H6PUqmIbDWFmOXx3GycCUnmQ+C2eFlLVgcIz/6kRBRQ=; b=enpNAsOHCg5ffHjAzXRJV70rbBAwHPMZa987eT2RvWWf3NrfjwDkjuPLvRo17BE+fI BgK1WMj3xasyO40VWqEQCDjNRx/VI3opqn3sYpzGlyFWVIeKMoaLULRKu5Rox4sFctfz 1cY61dOXseVUpHvSgSDnRrztfisECDOv/prOdnRlbnR2SR1wdlA07yyGtD4a3E95MseQ CEdxAz3Uxwe/w9E3G8uT3Qbl85mvDLME9UR07Bzh0SyGcmx1TVBwsn23JI0w/rkK19aC 7bJFHvNgwSpM81k2F223k8y30oikG76ANkQR7LLf/mBaWD6dhNa1fQ9Ddvis1cHe0FPZ E/hA== X-Forwarded-Encrypted: i=1; AJvYcCUlN/Lz/K6Oj5DHVJ59A3UJ3qgAS5GlI/ZSfr7gj+dOhrwhUOYF40poVCJYgt/IMeCz3lhRKmu1lymBWpzfryU=@vger.kernel.org, AJvYcCW2BHqnlKojxq+23z0xnYJsxzwMOftyYOt6zA5VnLzQISyd1ZfJbqOsgwF9yCJ8222TzMCDazymz4amA8ak@vger.kernel.org, AJvYcCWwTF5mp2Db/kA/3pNLOSX+DFNV1/c0epqPHHpBf98QExvkoeNxLMgZdFl6btxv3KyUAmjvzgfjRIz1@vger.kernel.org X-Gm-Message-State: AOJu0YypB8rcDtrUgpWmvOAc1rPxXLgHNjPy1aXZPc9z/Hgj3mxrASEz H7djSke7QX+on79IqDD635I2Kf/c+XUOqkQhHXtye4RbQEZWZvDcf+jL X-Gm-Gg: ASbGncsl6z2/LHPST0SI0skY6W8r6InpEKJBYZV7HAF6YNdqwQPd1WfSMEgzq9zo9nY mnpoqbc4mKRQK5sCrIk2FzC5mLBBgF9vtlZfcPQpgNi67I9s9t5zcB7G1mD6hEn4vhZfjBrI8No KdyTeJC77UWFXqhnhbkjbAt7mtTDMoi/P5hIr+GjSdd7mDWlnKuZY7+AVofBeSvnquAKeo1ivEW xIRKgJEaJ41mKcm382hEXk3eyQzgphp72mgKu4a8M56bD8605YhFhJpkM2w7PKrZOuAFSs8I3Az mK/93PDItY3Eo11hSqkV90Xqy2JL9BpkicoQ8h83s1cc4WlxtyKjVrKZiyKPIZmHNjIESGY9IuA JlfYhF0anZH4NWepWm17co0N8NPREQ7n3gnDU X-Google-Smtp-Source: AGHT+IHHI6WBJu7sDHEdtjSpBu9n0uInWMVoRmYpWTOUeUcEnqml/Fr3nnahD1USMoDsWks5VhOaCQ== X-Received: by 2002:a05:6000:2512:b0:3a4:e502:81e1 with SMTP id ffacd0b85a97d-3a558a4238fmr3627250f8f.52.1749664412778; Wed, 11 Jun 2025 10:53:32 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a532463905sm16203603f8f.92.2025.06.11.10.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:53:32 -0700 (PDT) Sender: Igor Korotin From: Igor Korotin To: ojeda@kernel.org, alex.gaynor@gmail.com, rafael@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, lenb@kernel.org, wedsonaf@gmail.com, viresh.kumar@linaro.org, alex.hung@amd.com, dingxiangfei2009@gmail.com Subject: [PATCH v5 4/6] rust: platform: Add ACPI match table support to `Driver` trait Date: Wed, 11 Jun 2025 18:51:21 +0100 Message-ID: <20250611175121.803370-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611174034.801460-1-igor.korotin.linux@gmail.com> References: <20250611174034.801460-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 `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. In addition, set `OF_ID_TABLE` to `None` by default to match the behavior of `ACPI_ID_TABLE` and to avoid requiring drivers that do not use OF matching to import unnecessary dependencies or define dummy values. Signed-off-by: Igor Korotin --- rust/kernel/platform.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 5923d29a0511..62a9e4ec5c19 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -37,12 +37,18 @@ unsafe fn register( None => core::ptr::null(), }; + let acpi_table = match T::ACPI_ID_TABLE { + Some(table) => table.as_ptr(), + None => core::ptr::null(), + }; + // SAFETY: It's safe to set the fields of `struct platform_driver` on initialization. unsafe { (*pdrv.get()).driver.name = name.as_char_ptr(); (*pdrv.get()).probe = Some(Self::probe_callback); (*pdrv.get()).remove = Some(Self::remove_callback); (*pdrv.get()).driver.of_match_table = of_table; + (*pdrv.get()).driver.acpi_match_table = acpi_table; } // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. @@ -96,7 +102,7 @@ fn of_id_table() -> Option> { } fn acpi_id_table() -> Option> { - None + T::ACPI_ID_TABLE } } @@ -127,7 +133,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; /// @@ -140,9 +146,19 @@ macro_rules! module_platform_driver { /// ] /// ); /// +/// kernel::acpi_device_table!( +/// ACPI_TABLE, +/// MODULE_ACPI_TABLE, +/// ::IdInfo, +/// [ +/// (acpi::DeviceId::new(c_str!("TEST4321")), ()) +/// ] +/// ); +/// /// impl platform::Driver for MyDriver { /// type IdInfo = (); /// const OF_ID_TABLE: Option> = Some(&OF_TABLE); +/// const ACPI_ID_TABLE: Option> = Some(&ACPI_TABLE); /// /// fn probe( /// _pdev: &platform::Device, @@ -162,7 +178,10 @@ pub trait Driver: Send { type IdInfo: 'static; /// The table of OF device ids supported by the driver. - const OF_ID_TABLE: Option>; + const OF_ID_TABLE: Option> = None; + + /// The table of ACPI device ids supported by the driver. + const ACPI_ID_TABLE: Option> = None; /// Platform driver probe. /// From patchwork Wed Jun 11 17:53: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: 895771 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 C18F3230BFC; Wed, 11 Jun 2025 17:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664562; cv=none; b=DZ/ijCMac9TB3ryF6zvODjaMEQDpitIUbCVIPgod+fdhXqke4K+diSwY2O0aAEF5RBLGCnoB380eATyO8McHLVNIvrsw7DCFRmwAboQ8b6yB29bqmWuHLJmTDXvy2398lgpoDF+VR3NyCoGeqGkMJjih5fkxsP3BHeTkDR6PU20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664562; c=relaxed/simple; bh=9fNPWzQXE6cKwryeefEjE504/Qv01BUzHuW0hAhRs2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fuBi27t2CkhuzgEgtOcjfUusYkgT5AqGG5LAIXYb7MrmLXYSssBWYPGnBIy5ZRx6kZbsY/klX451rfEWhPoGzHBwbvZ1N0w2Ysh6nijtWO4VK+Sj23Jk5YShDJTckbhu8PHCvHvHI19fZDDSBdy09InylIr8dv1VkcF57H/tc+o= 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=KpS2/qJ+; arc=none smtp.client-ip=209.85.128.53 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="KpS2/qJ+" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-450cb2ddd46so239295e9.2; Wed, 11 Jun 2025 10:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749664559; x=1750269359; 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=mKy2YdV53E/AFNFLMwrNi4oE9E3ostFMU8yHIDbBt1s=; b=KpS2/qJ+2VVcGs4/hTvp+EWqjm06iXfTUO3OgjmK1ATiHsUROELcqcg4BiNaviI/Ep y9I44FeJgLKrrxYejC1/LIaLPejD6moy+o6B6q0IKAD0bW1oKjON803/LhNozRd2yj+h DWpcDb55KhV1zi4Dz3uyH+Cwq35vsUKs1FYk/6MVHQd0UXW0rtzAEETT+7xflXqrmm+2 0BZM0LxxYp0DGsovc6cWCIFAo7EDbFSvSNuhg+TgkQGwBuGqXGL9qGhJnllEaGMamVUX GUhftk4BmAuK4Jlw18atL+FKwf8xsu1Oh6KMqp3vj5gBGVIDE2AiHacxbpvQ57GzXL6r xE8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749664559; x=1750269359; 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=mKy2YdV53E/AFNFLMwrNi4oE9E3ostFMU8yHIDbBt1s=; b=xRpPxWsBVIxLM09UfewPdr9Qzure5fxtBeyG12vXy2kAIo1v2uPsBkmwWqyk8fNl2u 4vIMReQ6Fa+9/pmsdoW/JqPRXymwosO8Ffh3lLzP5TY+Gq/RrpIk0J561VpQqRzpV0M0 72z2HvAtadoVsmovklo7KFH9bhGbpE8GjxpRvwHW0J18HGwqbJoI5vpSTI1V0Dji2xKz oP/Xah/Yn0GYNGWuWwFOJ+Jj3eeJOwD6pCa9WtaYZhch/1SU+p/skImyAeNJe+B2Inef uaSHjuF+Fm9J0yXp6uewhuS0INeKNFCdBPMWx8yFBbkwc/55oqrw+oDm0IPIhBwiIrhb Omeg== X-Forwarded-Encrypted: i=1; AJvYcCUONAfUq9JL5T6tYT9o2GbWjYjOtnEUsep/cgB6qqqAuan1et0vJDTyD4CMDljljAPQG4PL64Nt0kWqgNX/@vger.kernel.org, AJvYcCWYiuFLkHsCL1jQ0/kcIB6R03CTXu8zszOpf0rljIiCVli67yYH3ypIg1UjTVsdxNCrvyUsv9kf2Hnq79XThos=@vger.kernel.org, AJvYcCXE24gVoY49Q5tMUH1c2Id0dYF0uAFXDG+tfyHTsV1aHpGbDtc1Zg35AbZ5YMYeLepAK9aAUvfWeY/X@vger.kernel.org X-Gm-Message-State: AOJu0YwtWAS9q0u1la5Knlo4FG5BmNuZvGWe/+olpEBc6TwcHZXRiPE/ +TeQCHb+SOkCtSF3vcoAMseJIE65SGwD+L+LgC7L2wLcX0kZvm958cgB X-Gm-Gg: ASbGncu4DtREdf6fIdq1FTHfZ5p/6QPkryQbgfA76HJ8UQLsDpkvVDF85Ixp5b8fp0f 3J95TqjiCGgEvQa4XyePqRwT57bC4PeeUfbHw2Cm14G1amSdQ+Ua3itSzPVQt7RKZA9awbgsCJR uXzb3YUNdAhopwi0SS5CYiJLQtciSpqzlxhJ77CRjpgvHSWU182HgUZ2/bB0s7/eUWxGhlXnEHV GTGL1Fcz6LLK156v8Tcq6ElUxmVBiR5INan7HLQ1e0Hqw7zmWU0g7zhk8SmNlg9u/B2dfSgyMSt X5Yz5CZ3Pbtq+b5wTe8xuRB/aRuUdAaBhBhqKBJuacS4JJ2EyczQzLie9IKMfHcsIUfdkHEnLE/ +gwxj3ga+EM56KenkgHFEV62UuFpE99LeoLrGxI4= X-Google-Smtp-Source: AGHT+IGGASlUeMTo9rc5uxwo086ujx5KrDNAyUjiQI20KWPNO95XcMXGwbdfWF5Z38D8Kl8Y5gy1+Q== X-Received: by 2002:a05:6000:2302:b0:3a5:2cf3:d6af with SMTP id ffacd0b85a97d-3a5586e95c1mr3242839f8f.45.1749664558892; Wed, 11 Jun 2025 10:55:58 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a532452d7esm15972558f8f.85.2025.06.11.10.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:55:58 -0700 (PDT) Sender: Igor Korotin From: Igor Korotin To: ojeda@kernel.org, alex.gaynor@gmail.com, rafael@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, lenb@kernel.org, wedsonaf@gmail.com, viresh.kumar@linaro.org, alex.hung@amd.com, dingxiangfei2009@gmail.com Subject: [PATCH v5 5/6] rust: cpufreq: Remove unnecessary `of` dependency in cpufreq example Date: Wed, 11 Jun 2025 18:53:53 +0100 Message-ID: <20250611175353.803835-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611174034.801460-1-igor.korotin.linux@gmail.com> References: <20250611174034.801460-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 Drop the explicit `use of` and `OF_ID_TABLE = None` assignment in the cpufreq driver registration example. Since `Adapter::OF_ID_TABLE` now defaults to `None`, drivers that do not require OpenFirmware matching no longer need to import `of` or define the constant explicitly. Signed-off-by: Igor Korotin --- rust/kernel/cpufreq.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs index b0a9c6182aec..789c4a8936ab 100644 --- a/rust/kernel/cpufreq.rs +++ b/rust/kernel/cpufreq.rs @@ -842,7 +842,7 @@ fn register_em(_policy: &mut Policy) { /// c_str, /// device::{Core, Device}, /// macros::vtable, -/// of, platform, +/// platform, /// sync::Arc, /// }; /// struct SampleDevice; @@ -887,7 +887,6 @@ fn register_em(_policy: &mut Policy) { /// /// impl platform::Driver for SampleDriver { /// type IdInfo = (); -/// const OF_ID_TABLE: Option> = None; /// /// fn probe( /// pdev: &platform::Device, From patchwork Wed Jun 11 17:56:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 895553 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 A6AEB188CC9; Wed, 11 Jun 2025 17:58:25 +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=1749664707; cv=none; b=W24lNVw5t1bZDYP7nfysvMksOOX4NTHnCXhqq1PJ35UnP/LXtp+iop88vnrjHw8eX8qanzj+2AKvuqd6e1GPySqtpZjAHtGVq9iXVTzmumojyxTu74giJDKyODu8VmK60WTgkS5nTEi6whYf5WToPp9CLqzng9QgrkEe26xmprk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749664707; c=relaxed/simple; bh=5+kbWDXXq4IG8sDuXqes6a43G6RDWXt2POCGQmcpyOc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=skiltTbEQGl4EeTgfpf8kiX4BvCEPJRsvlSG7hI1yQC8wJUrTJMezg/39PDzMsCjXZiJWVhNpPgBekGEhOLTAcQy2Kk6Wf5Cde/QEHEGkMrFrEZBTg3i/CWxechW8JQA2xrvAqqnZwYi+9HfbAL2f09etscAi9G+o0GJbRXT1G8= 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=MND96yGu; 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="MND96yGu" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-450cea01b9cso311295e9.0; Wed, 11 Jun 2025 10:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749664704; x=1750269504; 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=iuauSSTqx1TDFESDgGFVyFslKTU+wwALp8k7RA41ffM=; b=MND96yGuGsI/mxw1pkY2GBK/SYPyWN7LsLlV0QnwIvXzeTXpyyQt4hRVep5Gcfi8cW 1+t3DGg3YVo+W+s1GIo4uqiuonEOXMpmsrTkbrYSYomVBfdCIW5qdRMhs/0J/qqzPk9g 6iCmPy970p+8dUUBaSr5y+ABEodxcFyjhmJfK91qMntTVEeriYVzCYSOREFHoGj+8T5Z cNjdUCzjOuXkLaVRgmQUkUwPiO7n863act+s1GsFILBTHXA3bqGtLna7bDqreiWIyvJS dpnNRgFmlpkvnsZl0/TJbSBAcqarDEJnxaO53VnA+YJ9i/Vs3IxEemtAIVcw04pse/7i UC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749664704; x=1750269504; 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=iuauSSTqx1TDFESDgGFVyFslKTU+wwALp8k7RA41ffM=; b=oMQ1dlmD5yeBUxQfffSHhfJi3GoVUyZllfKEYMHKU5nR+CVQJRdljquDxQ9x7sOpWX Dd49QPo6XlCLkjTC+DOr81ACmcldfaxs+OQ0JKwXwU8sS7b4TkQzp/vv5nrW4KoDsm7r nwDyjyuYpNxGbak5IBheMszFXNckgWmJbM2jh70kQM8gWJIa25DqwPyR0TilvB1Q14Qz 0UvaLKnf9KEx56KT872lH0gdXeh9EOEoJ7tK8V7kM/uUevI2qBRCs3O6YJYk6SSElOlA VThB4LhLFQP/c/+krx70gXSBc4uqgx6mOhqmrCIwdRdClm0pjQtT9PVjUfWCoq62tMl5 6AeA== X-Forwarded-Encrypted: i=1; AJvYcCURbX4v3unlNzFNXOcoBqtQvGR9qAHq2nZgxIz/kB/bOS2K8mCJTbAXUJLhqHzGzvjyotjbLLjL3DFs6B3m@vger.kernel.org, AJvYcCUVeaWu6gp6GTa6WBBJfeidQCp1x5iM9mHy7YOA6gEOcx20x5rzWAPtME4UeOa7HLHzdcW+f+4rGWso@vger.kernel.org, AJvYcCW+kMXnnaRhsH+rKD/Nc85TT0vFBx271d7a9a4DFJc8hqAiY/U7/MT0KBSGWsNdwZBthINUkirtoi/LyrXTxDc=@vger.kernel.org X-Gm-Message-State: AOJu0YzeYlHRDLclxPFYDREImFZdSmNrJmDpeTNRjBXZYE5IdXIEa/Wl UKCwC2ZgrTcAGSia3SDm9RVDSaxotD6CjMTko5txJj/Q4MWCAcjpZJzUa3famaJ+wHg= X-Gm-Gg: ASbGncvtQfD2CqKxyMoMHgqOdRozUfIhG2nZnKWLOWyI/4YgKmRCVG3qhnucsyPndcF CcSQZR/LDwS2DG9tUVonmlQw6P437cMILlndf3yMkGNUCDCgC+9M3WTJG+P+D0tdBysHtvR/wdl vTUL9O9sJb/nc4RgVEFR5exZ6B7ct374uZYyPWRWyOAc7pSBma1qWa6stvA+UtP6RYKydhlmx+w TNALSlM75gzwFHbv0Nuh2p7YD5ONhtLZvLi/SDCkzd9C01N4TuBq2xJ3rLbfWeXt0NpTxBGFIhv 0LjkG55qhaIt2zfLLHsp7VOSD0TYshypQYZ+ZUKY3C04J6hkcgPhyMAjtSI+NAOilhNYmVqMsb9 9ar5m2knzs5s5PE9oR4z5Zk6DQ0iqrprVq6lw X-Google-Smtp-Source: AGHT+IEg0k970DGPt+HOeiv6kkgVg9C2xgXIHwMpy2WRypQIpwqG83M++zCuuFAXKTvjT5p9ZNVqEw== X-Received: by 2002:a05:600c:1c9e:b0:450:d4a6:799d with SMTP id 5b1f17b1804b1-4532b8c5807mr7781705e9.7.1749664703588; Wed, 11 Jun 2025 10:58:23 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532513e27fsm28248385e9.1.2025.06.11.10.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:58:23 -0700 (PDT) Sender: Igor Korotin From: Igor Korotin To: ojeda@kernel.org, alex.gaynor@gmail.com, rafael@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-acpi@vger.kernel.org Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, lenb@kernel.org, wedsonaf@gmail.com, viresh.kumar@linaro.org, alex.hung@amd.com, dingxiangfei2009@gmail.com Subject: [PATCH v5 6/6] samples: rust: add ACPI match table example to platform driver Date: Wed, 11 Jun 2025 18:56:20 +0100 Message-ID: <20250611175620.804242-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611174034.801460-1-igor.korotin.linux@gmail.com> References: <20250611174034.801460-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 | 71 +++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs index 8b42b3cfb363..35d5067aa023 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -2,7 +2,7 @@ //! Rust Platform driver sample. -use kernel::{c_str, device::Core, of, platform, prelude::*, types::ARef}; +use kernel::{acpi, c_str, device::Core, of, platform, prelude::*, types::ARef}; struct SampleDriver { pdev: ARef, @@ -17,9 +17,78 @@ struct SampleDriver { [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))] ); +// ACPI match table test +// +// This demonstrates how to test an ACPI-based Rust platform driver using QEMU +// with a custom SSDT. +// +// Steps: +// +// 1. **Create an SSDT source file** (`ssdt.dsl`) with the following content: +// +// ```asl +// DefinitionBlock ("", "SSDT", 2, "TEST", "VIRTACPI", 0x00000001) +// { +// Scope (\_SB) +// { +// Device (T432) +// { +// Name (_HID, "TEST4321") // ACPI hardware ID to match +// Name (_UID, 1) +// Name (_STA, 0x0F) // Device present, enabled +// Name (_CRS, ResourceTemplate () +// { +// Memory32Fixed (ReadWrite, 0xFED00000, 0x1000) +// }) +// } +// } +// } +// ``` +// +// 2. **Compile the table**: +// +// ```sh +// iasl -tc ssdt.dsl +// ``` +// +// This generates `ssdt.aml` +// +// 3. **Run QEMU** with the compiled AML file: +// +// ```sh +// qemu-system-x86_64 -m 512M \ +// -enable-kvm \ +// -kernel path/to/bzImage \ +// -append "root=/dev/sda console=ttyS0" \ +// -hda rootfs.img \ +// -serial stdio \ +// -acpitable file=ssdt.aml +// ``` +// +// Requirements: +// - The `rust_driver_platform` must be present either: +// - built directly into the kernel (`bzImage`), or +// - available as a `.ko` file and loadable from `rootfs.img` +// +// 4. **Verify it worked** by checking `dmesg`: +// +// ``` +// rust_driver_platform TEST4321:00: Probed with info: '0'. +// ``` +// +// This demonstrates ACPI table matching using a custom ID in QEMU with a minimal SSDT + +kernel::acpi_device_table!( + ACPI_TABLE, + MODULE_ACPI_TABLE, + ::IdInfo, + [(acpi::DeviceId::new(c_str!("TEST4321")), Info(0))] +); + impl platform::Driver for SampleDriver { type IdInfo = Info; const OF_ID_TABLE: Option> = Some(&OF_TABLE); + const ACPI_ID_TABLE: Option> = Some(&ACPI_TABLE); fn probe( pdev: &platform::Device,