From patchwork Wed Jun 4 12:29:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894020 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) (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 8D06A28F929; Wed, 4 Jun 2025 12:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749040339; cv=none; b=q5KKbVi/bcKR9ogsuacrSY+494FTtWn+LOVvUa8bRbIHxuBaAr1xoX3jjGqLwnBFXkGszzrf17aG6L3SmzYs1JViW4Jj5XwkAfY2cwmdUT5LW3xLvOv9R0Z6VgJWLTW47fgVfKoMi4lxbQHiEkJC5gmNdXF7sr10Aff+7OJfVQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749040339; c=relaxed/simple; bh=B6QRYSwoEPKAw0CBU9/MKKr2LpuO0A+Kmwo/HZhwp2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lsxP9qK2HkvAItZFyuDLuUN1htjlpqagCVvuXsSlSDjNJa4/Csb1JvDPymZSAuwEZUQkIYeATgFUMhsqoPHJfkR/nXY6kRJbsvZR1W3a2IFhrJOm8Q9YUNpiZJAmWwxq1FyKFCTAzug9OVpBrzr8XHUh7gNNwMF7+ZzRNIoGJQU= 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=mJXJo3u9; arc=none smtp.client-ip=209.85.221.67 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="mJXJo3u9" Received: by mail-wr1-f67.google.com with SMTP id ffacd0b85a97d-3a374f727dbso5912881f8f.0; Wed, 04 Jun 2025 05:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749040336; x=1749645136; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2F7GrQ5ZHjP6suHBJXzOsQaZFBrj5luNHrI/XyyD2TE=; b=mJXJo3u9xwPWKoJjPkypG6bn2wAkNiibra0tqugwDYfNAmcFCd1fgwK99W8nNq6OYD aLuqxLEptG+Xe3bU8G/Nw38tSX/ftpbKGuQY8jQLPhzZpH+YE63zm+buQKbuVS57VIN6 PGTs2V+Ffrt39iLgwUqXtIYsrlphoThcvp2pgmFCaiktua8u6ET9eMjbKZUAR8vXWKQ2 z3t2fac84tKw/D8HYYGiU6Euek8K6gjqD+fKpSznF/OgJIVYSLvFXR1Vy9nBP8OgGkGC /ZgeJhMcK4eLlD8jGxdvW2ErRqWK+m2AdcPzedTXhOUw5/4IY0EyoQLWWlOkBtMXTx3N 2uqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749040336; x=1749645136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2F7GrQ5ZHjP6suHBJXzOsQaZFBrj5luNHrI/XyyD2TE=; b=gNVjR96Atpf77y221YLnlA/bZMVIFuhGz67Nd/ck6lmrzK352Jl13UrgFoHBQ6oPVg iv0wMIt6ZlX/M1PTiVc8MeSo5JYr/uxLCfLQCKo8rXYhCHYDQupUpIwjfF7OqtamyKjY VZwvCLsogBH8Z3Dm1NkHERctC/qrJD8y9j6Kih7le1TWR7ZlOApiFgz4Kg0ivcWoTDUW RgXfs+g4wxXwDsrmxFUY/S+45Hr5OpW5XYTSPJdpSdpzumdjY35xGT+dAJeT5VIU7IOx iqqJENN73nYcpuMhl596DcjqV+hL+J6x+mfjmcCAz3ugIy+1b0tgHCJvqvq70NFU2vKz hfgQ== X-Forwarded-Encrypted: i=1; AJvYcCWASuHyDLDxe2pEGlENxegm77Q6kIhBE+CVx4oq41o1Mz3MAP5honUkSQRYJ+eWqCRYpqDWdD54gwRotA==@vger.kernel.org, AJvYcCWMxIZP/RL6AVppQuSUkUHPeZOIs7gLDv02kPfH4ho/ygaRd37CsCv3Clr6tZCi9GAxLLeeT2yH3zwwI1PhJvY=@vger.kernel.org, AJvYcCX+stnmli2CPQH1FF4QdQcJDSL4pduSq3R/MPEjaTAc1e8+L9+59P1nZTdxeQesEBghTZe/oeJYBMumeRYM@vger.kernel.org, AJvYcCX5DIvw3wr0OSCRSATyXgICo8fmBk9k4t7bCZ9plpr5xuDPKXiTlMasxTyhUe9OBXCc8Gzcsobtrloo@vger.kernel.org X-Gm-Message-State: AOJu0Yykt4WGpxXiSaUcyj/4O3dx0XrICD46PApKkHw0mmIAytBeUKml cPevO6PUG7sD1VU5wOLWwG6o9y6/rkGd1G+LmgJeER/RVLOZv1j6QzvI X-Gm-Gg: ASbGncsV1lxuFtB776WtLoPZTg2cFC/HhkEgzdC6bUV8W9Wf6dTzeOFQib5aMX3R82Q orM2KXiGl6vgn5POZLJQ9ES2bfCwG2isST3kggtD6Kb1ksjwksm/ozGlqS2ugl5esVohNaScozq BcjVYmJk8FxCYTC34Avy4VWipbOoooIhz0zSC6SEwsov0FIAyhK3vsH/2CjYt3m46ERKmdvA3f4 t//PcTAqODt72TmDKiKqz7iKbgd+k+kXsEwsB9OmhA6kvUjJm+Ht1BmXGKjwJavt4QvXGiXRJTf fZAEziR/20NAyzM17YAg05VxhQZvQVti5NUDOGRzkcP1dHT3tJAx8jYNioLJhgH/jSCxtBwXOKH S9VOLxsSGaH+ksu5oh91+tED4AxaU X-Google-Smtp-Source: AGHT+IG/YAHVEgsT0iwtMleHoRoZoKaEfTJVyrwismrWf/GQQyXUTjEX15d+2pC18p8+ckzjRlUlFA== X-Received: by 2002:a05:6000:2489:b0:3a4:f644:95f0 with SMTP id ffacd0b85a97d-3a51d9791a6mr2036983f8f.54.1749040335466; Wed, 04 Jun 2025 05:32:15 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-450d8006c21sm194467085e9.33.2025.06.04.05.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 05:32:14 -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 v1 1/5] rust: acpi: add `acpi::DeviceId` abstraction Date: Wed, 4 Jun 2025 13:29:40 +0100 Message-ID: <20250604122945.3445776-2-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604122945.3445776-1-igor.korotin.linux@gmail.com> References: <20250604122945.3445776-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 | 62 +++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 64 insertions(+) create mode 100644 rust/kernel/acpi.rs diff --git a/MAINTAINERS b/MAINTAINERS index b659fb27ab63..5f8dfae08454 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -302,6 +302,7 @@ F: include/linux/acpi.h F: include/linux/fwnode.h F: include/linux/fw_table.h F: lib/fw_table.c +F: rust/kernel/acpi.rs F: tools/power/acpi/ ACPI APEI diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs new file mode 100644 index 000000000000..2f526a0b2ed9 --- /dev/null +++ b/rust/kernel/acpi.rs @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Advanced Configuration and Power Interface abstractions. + +use crate::{bindings, device_id::RawDeviceId, prelude::*}; + +/// IdTable type for ACPI drivers. +pub type IdTable = &'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 6e9287136cac..c2761bc7cfe6 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_BLOCK)] pub mod block; From patchwork Wed Jun 4 12:29:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Korotin X-Patchwork-Id: 894019 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) (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 8163628FA9A; Wed, 4 Jun 2025 12:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749040346; cv=none; b=RORpP8aWzPJL0JDr3/y2swEla0C8NOQEuCJhMsV6xirBbTMpjmfczQTVzH08TZ6BzU+ASL/vKs7stZnJSjfD1a6o3fM8vOjJ5AgusE9ze2zRYdWwyW+h5pagnk3Uv9JSEzeW0ffc5LgXbsyEYmuP7jc3ifSHTGFd9vGtV5kfffc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749040346; c=relaxed/simple; bh=EKuEJj1hiN5FAUPJllRUOb+XzT5dqu2BT3noUkRJ9Rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RTSrMKbbFDb+l2lv+5UbO5jL0xdf1fgsTlj0vtST8U3qGftEoTcyRgSGz8Kvh0VwEuabtsxBGSJ5dUCKBDbVnyXQYE4wBtJGkd5FE0WXZJ8sm+iFk9iNzXLs9tsNp7d9socNjVNtiHT7q7cRgLnO55OhKVCaJoF6xGXrR0qFH1g= 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=QKacmE3f; arc=none smtp.client-ip=209.85.128.67 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="QKacmE3f" Received: by mail-wm1-f67.google.com with SMTP id 5b1f17b1804b1-450caff6336so42011355e9.3; Wed, 04 Jun 2025 05:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749040342; x=1749645142; 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=Zb6n4xN+CaXNZLNAdkRh4qtNOwrRTbDiXvfunUMx5/8=; b=QKacmE3fBKmoq77l2hVR+i2gvGWOO5Hqq8jpQ/sc8zOZ5xsaDwBhZaz0lhGxS95TSO VrICSgyQOLiWvN7Sw9OHOG6pMOkAAJv0AZEv0G1oVJgx5jfKvk0Mxa4sxo7dRe9yUfmT tjRnqlk0bCWzU5UTxHLxZBWJ7Zv1sRuhyI17upTiVuvfpMVPlemy8PBW5SDwyXvVWP7B 8pfMJAPNyz9CPN4jGCBaGpimw6cyowGN9SU+ywXXWCZTdzOvA3SyNF8RzCH8MBdw7EWz jOQ7aXsFbIjBfDomhNc9r4hppHqAx444VQIAWiM7bDdNtimHGwKtMDTaraiU40VmJqk5 0qzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749040343; x=1749645143; 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=Zb6n4xN+CaXNZLNAdkRh4qtNOwrRTbDiXvfunUMx5/8=; b=ksElP5p2Pb0PQFkVyeDaIWaXiF1O1lYYwcGKdbcclvcHb8zVdIdWyloPffj4lO6/BY dG17q8cFnc+LXs/ge4BRxF5DkKURENppwiZ5IrfXtt50n/96EpuN3CbmMF2Ov4eMyj3y gLtuaLuKME7qF82ovoaC+XkUiMpyFGV55gKFQgkq3jMgsScOed6a5N4lCNGBmWn05knP ezpjeEy8By/tPtNnx2HFQXD4IKDRGazoKlHaIXVILDKjrkhpDaiuAP4fJVYbI5TFmdPw gALvu7+2bzAAfa15Jx0GaAiBPXNBIANq0C0aIwmuiL0zcHEcWqF/pSJGt69yO8wM3yhu RYRQ== X-Forwarded-Encrypted: i=1; AJvYcCUAWdgzvA14/xwV+zUXdP0j8Pvd4gthI5nQPNwlXMiMiNERoev8X6RLSEhvpUfDjfueZXZVkORozhVVb79T@vger.kernel.org, AJvYcCULXgIlbgxxlV6rCb4nQehUSYVIY7NECsRrze6vgXPFuxW8UMickqf7v9wf0zG0bUCMQZaezCeg7J5w/XFJUSo=@vger.kernel.org, AJvYcCVg+KOJ2lqEaN6q8S7FjcmjNH7Z1mzI/Ue/r6jU2k2ALVjM4N8KKmKEO66eFb2nA4FUKRfNGG7VBtT6Kg==@vger.kernel.org, AJvYcCWRWpzjH55Y47ixlK5U/ncVR2uOjoy09eK1SItuJxe9jN76JFBkzVbKetM5eGdZil4jfRwahpMfPqDl@vger.kernel.org X-Gm-Message-State: AOJu0YwixhAFX+s1mMAPRizzJEtox/EbxIPnJl5Gx1TkLs+WpR4Itlbn bMnIKNIwKgg+0y+WMAjpCwqyAFL9zaqJaoGStEL8SRmY8lsORJGqKVXj8by9PFWC X-Gm-Gg: ASbGncuZHUkf6MbKWyU4Vt380mRvwudnFxQ2c3AiiJhvm8UvxON8pNb3qfuuDSftzZh qNiQZssF6aScWradmO1PrtcSaDlSa5TVc4o5cd6fMFtV/0saUiEIOSlnREd1K8toNbo5xMCis+K pL+Op3SPY58BiUiLjIrVlTdHmTUfRUpDS1k3XXyv5VOuxD4mIpXoRCa/mjgMLiEVx2JynUIOnyu WSXfC+YYzFd5NVwTCSQAWsQfBN8qg50pOxS///13CxEMIde6yFNohxY/3CKq0b4kd0Y2k6G1qsr af2o4mm4U+Cwe3GT+xkp+7rc5XSxORHDa00/BgGtFt0tDzvj7LazkUT+u02zqwh+1NP837Rntb6 LPJYYrleRqb9p08LaLlQFZK5W+HGhuRDuPeZOy5c= X-Google-Smtp-Source: AGHT+IFhjQKYa6TmqFc5RdnTJpBhC99HefNd12BPqVLoU7t0wxGN1xn/KoXcIxM1eKnDWp8Oj5kJJA== X-Received: by 2002:a05:600c:4686:b0:43b:ce36:7574 with SMTP id 5b1f17b1804b1-451f0a8a2b9mr21941225e9.11.1749040342334; Wed, 04 Jun 2025 05:32:22 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-450d8006c21sm194467085e9.33.2025.06.04.05.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jun 2025 05:32:20 -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 v1 4/5] rust: platform: Add ACPI match table support to `Driver` trait Date: Wed, 4 Jun 2025 13:29:43 +0100 Message-ID: <20250604122945.3445776-5-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250604122945.3445776-1-igor.korotin.linux@gmail.com> References: <20250604122945.3445776-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. To avoid breaking compilation, a stub ACPI match table definition is added to the Rust sample platform driver. Functional support for ACPI matching in the sample driver will be provided in a follow-up patch. Signed-off-by: Igor Korotin --- rust/kernel/platform.rs | 14 ++++++++++++-- samples/rust/rust_driver_platform.rs | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 3cc9fe6ccfcf..e6cc878a5a37 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -39,12 +39,18 @@ unsafe fn register( None => 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`. @@ -98,7 +104,7 @@ fn of_id_table() -> Option> { } fn acpi_id_table() -> Option> { - None + T::ACPI_ID_TABLE } } @@ -129,7 +135,7 @@ macro_rules! module_platform_driver { /// # Example /// ///``` -/// # use kernel::{bindings, c_str, device::Core, of, platform}; +/// # use kernel::{acpi, bindings, c_str, device::Core, of, platform}; /// /// struct MyDriver; /// @@ -145,6 +151,7 @@ macro_rules! module_platform_driver { /// impl platform::Driver for MyDriver { /// type IdInfo = (); /// const OF_ID_TABLE: Option> = Some(&OF_TABLE); +/// const ACPI_ID_TABLE: Option> = Some(&ACPI_TABLE); /// /// fn probe( /// _pdev: &platform::Device, @@ -165,6 +172,9 @@ pub trait Driver: Send { /// The table of OF device ids supported by the driver. const OF_ID_TABLE: Option>; + /// The table of ACPI device ids supported by the driver. + const ACPI_ID_TABLE: Option>; + /// Platform driver probe. /// /// Called when a new platform device is added or discovered. diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs index 8b42b3cfb363..e3992e7a71e9 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, @@ -20,6 +20,7 @@ struct SampleDriver { impl platform::Driver for SampleDriver { type IdInfo = Info; const OF_ID_TABLE: Option> = Some(&OF_TABLE); + const ACPI_ID_TABLE: Option> = None; fn probe( pdev: &platform::Device,