From patchwork Fri Jun 6 17:08:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894480 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 94C031DCB09; Fri, 6 Jun 2025 17:08:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749229705; cv=none; b=LcBQOxE/X+GfSM0gcLc9JGylW8VGFjSHY3WpeKICL9NSmWhs1LQTZWA27qxpmLHocSYX1fnrAwf8L4vXg9fWOsjDBnbD/QU0QkbSOGfazEtTl7iR2gn0XXSP30vybnUXpdr67k6PDL9y7p7QOLC+u1o21P+rc9F6kjPkBtPmYZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749229705; c=relaxed/simple; bh=0n6dKNaXjAtpClMuqrF6yIV1Y2xk3819lpUQzbOxuqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OMR2JcdsixDUvgumKF2HxQyS0jiSK+Ef3PTPKnrDAnIr6bYbJiRQoUiiyShOkcnN9N+pVBDOnhVkeBsekpAnU6sGxGnmibVFn3R83QxxkOqW4/vuSZK8P9N4KMMdj31BgIRbbkXQCCqnL1fkdmzGZVX2aktGM9LAJHWaQi8+hEw= 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=MNg7bG3S; arc=none smtp.client-ip=209.85.221.47 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="MNg7bG3S" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3a4f379662cso1996863f8f.0; Fri, 06 Jun 2025 10:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749229702; x=1749834502; 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=GRYCAFkO2zcpC+e8ef4KzR9UwAmJFdk1MxOth/JzNs4=; b=MNg7bG3SThDWAN5m6WlH8UjtUGPIhKUnCLvrq+ypxlFz/l2V4XRhIQ/NIKZHp/lB7y xr0Q7VnecrCy3o2GXEAk4Z8bO+FHJ6Z4NsoUF508HFnvBOXqbd3qEOIDJ0IH/Z7+CYt2 QMWPaettJV+5+gmv7bno/IaC2m0B+WYbL9YLn+s+F7cilEBr3bd9deR6GGB5ilnvsPJ7 mfaQ0Ie3LUrA/inGHmBCv88rGJkkW5f8zn76r2wN8Vtgi99hHxsO0AvhRjbCSHN3ZHko wKhOj+BDCH4Zr+2aTj9ydP2Melk5a5K+hdW6cD23bbHvB0UF5o/ivIS5UGagPP/0yCXq xVww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749229702; x=1749834502; 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=GRYCAFkO2zcpC+e8ef4KzR9UwAmJFdk1MxOth/JzNs4=; b=LJCXMG23Bv2cSlhMWnYSmf973KdwcT61ZgCbPVfOZEzhlw3COgwsEzVWZ4TyCOFEJP rLDlAhRXl+qJiUQ85ZhN4d2g6RQOpmqK0GEKLpqQ8E/TLJmKeCi421CZY4l0sUZqv2m0 ckVn4QmZLc7v7hAIpA3F3UCPGYluG4jYYMpJAHna4U8pmXj859xrmz1OKDKoEVOCNtYR AMkvOv2sM7mk5Ox2aMmwSO+3jxnkpKRl+5bxgEHNg4Tu8VJKk9pQvR31CJ+0+nA4whIv yCDuxZMLKxmgtE1d62xlbThI00W7WLuWK7JMwLd+FsqwHoap2VFK76MG2tj33ngkVK5b 37sQ== X-Forwarded-Encrypted: i=1; AJvYcCUSiHPQw/dJYS9RkPhzNRZFMAmkSC1OW1KnjV7pDEqTXE9CA1p+Mk0iL18KArJtsmvfGJYEWTgFv7qIn6FdqOw=@vger.kernel.org, AJvYcCW5XT+9ANBO9DCrp/MONXgXjgPO5REhHSlKH5nfbc+s2vZeyPDAmVnjGKR/K+aRyxT9kgEP7wuJRR8zoPY1@vger.kernel.org, AJvYcCXdjZpLBaDQRAhOp3QbBrBRf8skMoaK3tXbmzSnZI5wDt8IxC8EjrnBkXJoTDt075AymKywqsDK+EGN@vger.kernel.org X-Gm-Message-State: AOJu0YyKXiTX5LQNfCGlMRdJgN01TYen1YswZccC4Nb+U8FjwucyzFnM /fKV1B/UFwKUHRu73czDuCdfBw+Fe5CN6qvwopFgeROxq6RJmafksSt0 X-Gm-Gg: ASbGncsFs/1d+Lr6gJ/1Ac4g0bwjseFE28RISBDEwpZN3WNK1pB/FAqvGY3YD47VIhl LwllMfsVU7YEiPpc1no5+pRsz1lPQ7Sr3PpL05zUhmLgEoqPPVFMAvV4XQsqHcBbkNHkJ4Vs+pQ GtolBBVBK+D6k7F3vRpgLXsA889CfamTGp4IcaHJMH3eWfO1utTn5MUfQ64mVw7JrwoXOlF/izx DI7+Bp80WGTBWwQS9iKgKxYng8Wc2BPMZW1Dn8kE+oBjqxOx9dp4y9gWs1QB2PrT1p/RbtoQzVj eN85N/3w2Rdep5Fuwdxp40pitQFwpIv95GcQEpfYIc5OnBxJR0gDC2mrVySmDcMMurgR6gxSyDH Q0YxJ9lwsqR2KK6s2PmuPjn8MrOesRxtNTA== X-Google-Smtp-Source: AGHT+IEYJB/T6htKMIfvolJfKo2jkiliEKcvmU8R2tHOeMj6rr+QbYiU7LHeXV+HkIofpKDb5tBpOg== X-Received: by 2002:a05:6000:144b:b0:3a4:e706:52f5 with SMTP id ffacd0b85a97d-3a531ca6afemr3843032f8f.13.1749229701638; Fri, 06 Jun 2025 10:08:21 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244ee34sm2433606f8f.72.2025.06.06.10.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jun 2025 10:08:20 -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 v3 2/4] rust: driver: Add ACPI id table support to Adapter trait Date: Fri, 6 Jun 2025 18:08:17 +0100 Message-ID: <20250606170817.3881748-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250606170341.3880941-1-igor.korotin.linux@gmail.com> References: <20250606170341.3880941-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 | 39 ++++++++++++++++++++++++++++++++- rust/kernel/platform.rs | 6 ++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index ab37e1d35c70..002d84f06b42 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..638f1d270af8 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,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,6 +210,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 4917cb34e2fe..dd77934937d3 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, device, driver, + acpi, bindings, device, driver, error::{to_result, Result}, of, prelude::*, @@ -95,6 +95,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 Fri Jun 6 17:10:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894479 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 4E0111AC44D; Fri, 6 Jun 2025 17:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749229841; cv=none; b=VCodB4mv5IQeGOQOZG/01HWPGM8g3KSYufO5vnuo5m+MH8R99eY/oFGKqAiQF5e/44NC+abQjMnH/VY1XmuFlQDaAx2RxJAs88CtSOc4WadE1i13Qm27eQomLSpzHeJtesMhKE/eUgdDanWRmIM/6r56E68ZFtPozE1nq/C1vpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749229841; c=relaxed/simple; bh=BSMddBCJ41Ilbd2FWYJhzQ/QPewb+Wq1Q5rcDoc8ck8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CU2rb5DoIFSqnC57b3xM6evKxsDvWkug7w1bCYNcG7xnLP2K8Weq9Hf5LS42VnVyEnFlAQsx2WJvKmnH1EmHxHry+Q1lAMeSdBPXUA8FN8OkbOz3fa5gHfoGO1dp4nrKJ09ljHDDYmjcAuTioW9g/fyNYtEDzYbhDU0OY9HFNls= 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=UrjCs8N7; arc=none smtp.client-ip=209.85.128.51 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="UrjCs8N7" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-450cf0120cdso22105445e9.2; Fri, 06 Jun 2025 10:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749229838; x=1749834638; 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=gV0kqico3uMlw+LKBx7wC9FFLyMg8FZyPDHUacfhBv0=; b=UrjCs8N7e8KVUXXDtGD04wil/po2PON+tKzBosKjvYzF1m60xwrEPfd7NMJRj9ftoL IRoBlmLz4vn+kFAKyXHWMDnsaomSaRirM+7YjIQO1XfCZsJ1dD43PY4QQv5xZiZDEGxV YVpFSgK+BiUVPi2o4D+C9oAEHWUTb0CZl6Cwtmhlu1b2quwJgVLmnZICoMETVWiiYka3 CeJI2YlQ48D8iY+fz3cCm/ochDLndj8sERvoOAWvnUJa+jaf/2KOddtf82eIJpH8x3js rqJSyyWrcoZI9+ivQmrm0xtjui6z8S0tmW+iSlJ9fDu9QnztHK5nDa/IV8CU6VmP1hih VfFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749229838; x=1749834638; 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=gV0kqico3uMlw+LKBx7wC9FFLyMg8FZyPDHUacfhBv0=; b=ffWOAjxXWnpUUQnFXHSKFZNE5lmiXRwoAxNFajR9NyT7YpP0J+vYvs55WUFRriIGPr Cv1DHNnlerjL6FuU7fXjszoRDOtqGLWUB3YzG8nw73zQUe4dyxERzp1nGahpGC35yXuS rXIXo1xZkSOaojvdlb6dBk1XMcKKwUFJS+bJmsf0AghGXhyGkjIg42maVmfOxc904WeA ISbKG4FCq2BuYH+4CtSc8IQN34b6mpk7M6rPEaCVngNSkEpbC3aS6sY9jaQwkRYAlSqX qXgxjpBAIWF+pdLuMGL0Dy2NiC/ig06LhSBM8QH0r3QpXAT7DzoCFNFD67b/D1xXzhWz T2Ng== X-Forwarded-Encrypted: i=1; AJvYcCUyC4O6iwQ78tS0ohaAC/GZLzRGeyjegDu6NFo0LwRd4ypDbitfshNoLX6ZdIIs3OI46iY8qixmsoYt@vger.kernel.org, AJvYcCWRptTS+ChKDxiGDJqxDP1wAUnL3V24SQrCe5aQXWh5E+vZOMwUvWvQbe3HC/RC3fRJXuWbEuNPpvsvsro3@vger.kernel.org, AJvYcCWly/+smI9y4RVHTHFz8CpgCvUd/VSfcj/VcseGbRXMVwGxG+0NBFUCQEdvO1CkGZ9ah4s5ho220G6Gb3N/hk4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9BkSDifl9H/r/2I+iqPSqy0XdxhEkwMt09qysA36j/gNAypnd vQDcJ3gkO7YqtQRVudLTIL7hxuQ1j1+DqF4TVAFC8BvTu+oK7+De0pFj X-Gm-Gg: ASbGncv13fzuFMisNgdWDXGeI05mmJvb+b9Ci09/N8Ioq9HjkRvBupLIqy/3pBcbsO/ rU+sxGKiACca1OT94XG29E+R7aMmxH8ubCg4mejAXMR5SVU1uX1T4KwL9MnBi5mOtkBflN1JEom RsWhXAU3iWvaC09/bj+XIr1T97v79DtOvbtGBNJI1kpJKnMRQ+423nYKoEVknudiQkQsLXtYjrV doJRTYjk0lDOhnpYWf0uO0bzUNAzIVgSCLRHDW+Gv8Dpfb8F9YizSopK2W6U1/kAkZ9Avxv4j97 cLTpeWGs3dwqvVy1DND6tXfiSrZgnCB/G3u5LXpb9eTksMC19Ihcnh7ME8XHrulGWfit1ezDw+K 1tZXnbbrJDpN0 X-Google-Smtp-Source: AGHT+IGre1DzsJsOknujs9mDOmhMZQMaGS4A0WKDhGwFd4n2uetUZU5P4xfB3pK5rJjYQ/YrR6WQ0A== X-Received: by 2002:a05:6000:25c2:b0:3a3:648d:aa84 with SMTP id ffacd0b85a97d-3a5319b8ac6mr4174578f8f.5.1749229837424; Fri, 06 Jun 2025 10:10:37 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.. ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e0563cesm29798395e9.1.2025.06.06.10.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jun 2025 10:10:37 -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 v3 4/4] samples: rust: add ACPI match table example to platform driver Date: Fri, 6 Jun 2025 18:10:33 +0100 Message-ID: <20250606171033.3882079-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250606170341.3880941-1-igor.korotin.linux@gmail.com> References: <20250606170341.3880941-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 | 96 +++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs index e3992e7a71e9..be7c311dca07 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -17,10 +17,104 @@ 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))] +); + +/// 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: +/// +/// ```ignore +/// impl platform::Driver for SampleDriver { +/// type IdInfo = (); +/// 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"); +/// +/// 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,