From patchwork Fri Jun 13 13:40: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: 896015 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 0008519ABC3; Fri, 13 Jun 2025 13:42:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749822179; cv=none; b=PvYs3jBta4aStgU5lVD8IWKX1ugSGp68uVBfh0amtxNCw39jlqT/OeZeAaEZmA/ffCpJ4i3YGDL2lmfwgpqiRIU+2vqOIq4KR+puo+ek334ousTsBK0S1VEjumD4yxE1NOE6nJ/krt6gSQuxTlYciMw12G1eZgpQYhzk+docuUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749822179; c=relaxed/simple; bh=kdiPdMh5+sRzNgtYRKj/S0sAtUte5v+zpvWVg0DO3wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=agahtGzEi54B5F9LWYM2obbjelhTKsP4y6E4jM7+vclUwcRulwghAyYSd33cOTL+zbF9Ze2kCxVJQTxyD+eQkrtOryTwMWREnv989Cp1FVqHtfp0Jjss8tFA+DtiBqzszymrN1jqpr83SAzuJWesPoOKTy0Kd2bpgMTROXC2qRw= 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=R7v/a5nX; arc=none smtp.client-ip=209.85.221.42 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="R7v/a5nX" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3a4fb9c2436so1321383f8f.1; Fri, 13 Jun 2025 06:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749822176; x=1750426976; 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=R7v/a5nXcZ1hPE6Teu5COQktZBWtmrg/3WLFDI76xAH+IXsPChYDLZn8tiuJRBYTz9 EKuCdOqmJ61pXl42KLC1KUai109P75Ilxhp54/U7+jOVVKsnfp4oUTLeaRD/N+xZAt5t rKi4yi1V0WyIm45f3gUCPw//XcteD2qyJid6JdwigcwwFeGjNsiIyfyN3skSEVSWrQWO o7Nn9UlUzTxosVxpSmcCtFAv39dpIblLW22vvw3Bh+f3pP3QdfmyLs/rimoR6FuoACMx VAupx4hNzyhcAfOaN1vflNlD35cN6RRsCpIsTh+vexXkb/XhlhnSO8KvQkrU5OzMfJ2F 864g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749822176; x=1750426976; 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=jgJg5xApEVd5GObHb0rcdjuNhkgut3i9e1Ej++JJuX/P0Ag8f48y0WAaoyMGWVqWkY C6VEz6fvzv2fQ+YrLn0JaVBFjnGICc2Xx/E8wKKVGea2wUmFnXD4zSLEEs5IfJ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ASpa+zBLeqO+B+Gg8= X-Google-Smtp-Source: AGHT+IErpZfMNcD4uCLvcP/jWyCe4iFHGIQImMSC9pURAYXJyAQlvgrclcjpnEZwyzObV9itosVjVQ== X-Received: by 2002:a5d:584c:0:b0:3a4:e5ea:1ac0 with SMTP id ffacd0b85a97d-3a5686e3f89mr3290245f8f.5.1749822175949; Fri, 13 Jun 2025 06:42:55 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4531febf905sm93542555e9.0.2025.06.13.06.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 06:42:55 -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 v6 2/6] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]` Date: Fri, 13 Jun 2025 14:40:53 +0100 Message-ID: <20250613134053.1230903-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250613133517.1229722-1-igor.korotin.linux@gmail.com> References: <20250613133517.1229722-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 Fri Jun 13 13:49: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: 895999 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 4FFFB2E11D8; Fri, 13 Jun 2025 13:51:47 +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=1749822709; cv=none; b=iA/CeqMOjjozha1w/lsOB9Js4o0KTdZ96t5oAxHxjdBtBF4mImFXoZKdb2YRo9a4oVJZMZkO+8htsKyYeSHkUaCSAczZ20jvOR/YlKUkQf+HVgtxXQqi2v1V6eAErtUmJe31wvkyqMt8QQlkkHOz2TiRvjA662GrxOV2AKKoX84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749822709; c=relaxed/simple; bh=qrwoSmZh1uvAMGuc0OD8LaGxAk4MN2XVSm5XQa5DvhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nazL7Ov8WZT4CrG/0YaV0ZqkKzYG7ix5xG07D2TvK17VuxQewqnJ/UE1boDGudyeO6ahr97+TVMxII+L4CurTR8O5ovfStfEQ08LekdxxiHzHJjkvX+sOVm53I/ueCubv/v24GNsrMu6wikII7TNIQBYUBG/Z+1ZWOtDU4FmvSM= 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=ACaFf16e; 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="ACaFf16e" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3a4fea34e07so1314037f8f.1; Fri, 13 Jun 2025 06:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749822706; x=1750427506; 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=Xp6TNa4qUBX4uNwGZpN4h1HBng/ZXNtRsGZbvmQNhiQ=; b=ACaFf16e0MaWOwO/MBRkB4qrRKM9lLqr8j74FCQlSrXFE/bpdUBAan29e9UZMKs4i7 PdQXhw4Tq8ME1eXnJvafw5xPrqUbO6+SFHk7V5vfw4hVrcpIA/bL52wqTJFhKEj34kFz KVR/poYbJcx95j1nUVfpBxW4FBjsPDnxzVUjPVncfW+n+dy0bmi4ovhDGajFEt9vqOy3 57J5arwH/pOMBY1XduXwIlRJ6wJk+M6fLtbowBB5gD7Sc2TB8R4qhyaiRNkdiOvHltU3 Qg9Iu3K1vyq3nKDItkrlC8IejEOelVVqANuPFib01tO8GJdSPhgh2FGjwcEBLiJPHsDy TpMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749822706; x=1750427506; 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=Xp6TNa4qUBX4uNwGZpN4h1HBng/ZXNtRsGZbvmQNhiQ=; b=LKImXttKVE2rsPpJ6lUSLta47DnkrgaaPgXu7pLkqoEijK/Dh8TR1SOBO08LlhvfKP +RtA7bNf1K477jLC82j+sXkYCcxmfjUcfzsStp6Br8mtHbXKwem2v4F8jeeTthzNtF27 i5xnYLg/yKaNwxaEsUnGgXV1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+IGgi31tXooyEV3h/llbbLtPIOyeOEKKAWW17esYDZOUzx0JrD+WJRAVNUDlqd/B7dfjeISPGw== X-Received: by 2002:a5d:584b:0:b0:3a4:eeb6:3b6b with SMTP id ffacd0b85a97d-3a56876da63mr3590191f8f.43.1749822705452; Fri, 13 Jun 2025 06:51:45 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568b08c99sm2445560f8f.63.2025.06.13.06.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jun 2025 06:51:45 -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 v6 5/6] rust: platform: Add ACPI match table support to `Driver` trait Date: Fri, 13 Jun 2025 14:49:43 +0100 Message-ID: <20250613134943.1232287-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250613133517.1229722-1-igor.korotin.linux@gmail.com> References: <20250613133517.1229722-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. Signed-off-by: Igor Korotin --- rust/kernel/platform.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 2436f55b579b..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, @@ -164,6 +180,9 @@ pub trait Driver: Send { /// The table of OF device ids supported by the driver. 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. /// /// Called when a new platform device is added or discovered.