From nobody Thu Oct 9 08:43:29 2025 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 6C54828505C; Wed, 18 Jun 2025 10:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241322; cv=none; b=H0sCxEQKcw8kz0aajojchxBmvzUjuBs8iS07zXpzIVPLYFvAwjMe2jPHfCD4b5MPyJ4mpzqgOmo1DVKrT05oTn53gOsTJ5Fib4e/o0AkY5lCOcLSMC3hBn/e2Is4Lnx+tW244XZghtg0POmI0fP9M+DKY0J6MqKsBjzhT24495Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241322; c=relaxed/simple; bh=PM3oiMkCf1SkhOWKY+/gl8R1ZWVyQafTba/3XCv24As=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pK2ooislCw6M/LgfIntunMzPAU3zF0RAe+/8G6BbiJCssmBPEN5UuIxR+BUWRLqMd7EdZPGLtsNhViAeqrfQBZoq9dBzkmKhd9g+cXan1dNSMWiWq9Sz9gCgXYqAvLl+ixjklaO2wkfkjk2BCP93WioQOi8abtsHaecezC0iOkQ= 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=ffhvQe2w; arc=none smtp.client-ip=209.85.128.43 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="ffhvQe2w" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-450dd065828so54694125e9.2; Wed, 18 Jun 2025 03:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750241319; x=1750846119; 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=vMzjEshtuGmJcwDym84s/UXUgcbvyW1pPiIeK/zCXQs=; b=ffhvQe2wJ9YoDFfQQA0LnRZCSUe7iK+p/36wYmE9rVphu5JVa3HfNcK0T2N2EPhjNU ZtX/20xskYB+lLyWAX7qQP+vBFx2PYpYMbC4f6YT7xB2bIcxCTPq1SoY8C7Aijpl7Lvq t2GpPv3QloVQd/bihtl8zJ5BeUqJUq2Kq+3vu/gR7s6oSQAoyFNXnbum/ZYaoONlXrUM YKSjM+j3aFL1k54T5ghqiBhPwghjpSta/J8v3BkA3NDaIl8v27PT5O6pg4259dkGe/FD q247rdFhegBZeqCiXx67gtV0qiVHJevFcRN+zYB+j53yZvHP9peaHd3EH8llDPWvnszf jmBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750241319; x=1750846119; 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=vMzjEshtuGmJcwDym84s/UXUgcbvyW1pPiIeK/zCXQs=; b=V+kUZa5bfj5+cD7aN4xTT9KeZLX3qDDUghIP/gZNzN+0YC1neQK61ISBkdVqxQNkyS 6SEORzw47GxuNle5SsAEJGwJwHiCLe8P2vHcsPRjFrTV/lMJywUq8DpPlBRSrX0RofyA d4W5HgI665zW0HP2LDihTAEvS9QKU69h0Q8/NG/i/A1ioCIMPnXEJlVl8cNvo9Nu/QsB +uTWMXy/FY/MWGfpOOBc1JXZCPAKJdvbUyG55AykdAg82zt3XxXTBtaH50xduXjJWO7x 3R2ctWnr/+w8wsAe98vCBMVzaJtn5Fx1v3z1gklcRkR2AkqL40WA37hFyWNgRCSxICcm liBA== X-Forwarded-Encrypted: i=1; AJvYcCUua5NeqVnGhWnEjXETTv1yeaENrJ2KYeuc/h8SrQg7xE0/0eihv7FgbZDeCXIfxz3pu8lZCakmYKCi57H9@vger.kernel.org, AJvYcCV3bQndGoR+la2Guryh85DMQpJlpOEU/9BE7zZqP6yzM1r4YYBS6zdmmsQnO9BOfUpezvO3L/6QtFL7bH6HWXM=@vger.kernel.org, AJvYcCV6gM2AfVT75s+VEogOwEJgq/1uQZ253Yuty7QL3LK8DPZnLvrOJDjq1otzzj23dSY5PN6X3dCdS3BA@vger.kernel.org X-Gm-Message-State: AOJu0YxB/Y4JnqaJpOVfDFrS9FsVmEMZ+Zcj1qMrmmrTUxgaNjKrq/4F of9u/lYfUpbE/s63m/XUcU94P3lsW7AWEQ+0wfI7hSXH80A3P+n+ypwx X-Gm-Gg: ASbGnctuegGePUPf7NKyq6uLUf0LFIHreiW40OJHolw64p/mYYbee01LaRicpyh+lOp KfZF9iAjFrEbe/VWNEImm9kiq2V6M8JGzmdX+zFBa33gYFsNbyUicaipKfRNc9loHwaH/iQfr+x afoFurfTkMfyHR5UMQLDRiCvJ8CXWhVM92AjvGY/Vz4Lfxyza/IbP0F0shkd+pPDJKpr0wWNSTf NNkyEfIvKWdqileWVAmcoQ6Whxd6CZWNvQwYi7Fp27lA+YOAWg+/K/9eym8sfrbS5JA/mp89w+p k0AYApxWLA01aaDM/asvJOwotncCoC55CyCpHnnIKBK6ZWdTQgqt6K+eRtpbxkDgPpaL1Nbkft+ l16r9iaJrTCIa0F/TsgHNSE7DRvRHwx9iqa/BL/E= X-Google-Smtp-Source: AGHT+IFWAjJNlkTSbKEj9ag9dCZUDRbFRfhT9FkaMsOUOcM/aGYq0xGr+w8AlC8AZoF7lkcJyJxlbQ== X-Received: by 2002:a05:6000:40ca:b0:3a5:3b15:ef52 with SMTP id ffacd0b85a97d-3a57239776dmr12332294f8f.8.1750241318499; Wed, 18 Jun 2025 03:08:38 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568a54b7asm16689305f8f.16.2025.06.18.03.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:08:38 -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 v7 1/9] rust: device: implement FwNode::is_compatible() Date: Wed, 18 Jun 2025 11:06:35 +0100 Message-ID: <20250618100636.3047585-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Danilo Krummrich Implement FwNode::is_compatible() to check whether a given match string is compatible with a FwNode. Signed-off-by: Danilo Krummrich --- rust/helpers/property.c | 6 ++++++ rust/kernel/device/property.rs | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/rust/helpers/property.c b/rust/helpers/property.c index 08f68e2dac4a..177b9ffd7ba4 100644 --- a/rust/helpers/property.c +++ b/rust/helpers/property.c @@ -6,3 +6,9 @@ void rust_helper_fwnode_handle_put(struct fwnode_handle *fw= node) { fwnode_handle_put(fwnode); } + +bool rust_helper_fwnode_device_is_compatible(const struct fwnode_handle *f= wnode, + const char *match) +{ + return fwnode_device_is_compatible(fwnode, match); +} diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs index 838509111e57..a946bf8d5571 100644 --- a/rust/kernel/device/property.rs +++ b/rust/kernel/device/property.rs @@ -93,6 +93,15 @@ pub fn property_present(&self, name: &CStr) -> bool { unsafe { bindings::fwnode_property_present(self.as_raw().cast_cons= t(), name.as_char_ptr()) } } =20 + /// Return `true` if this [`FwNode`] is compatible with `match_str`, `= false` otherwise. + pub fn is_compatible(&self, match_str: &CStr) -> bool { + // SAFETY: + // - By the invariant of `CStr`, `name.as_char_ptr()` is valid and= null-terminated. + // - The type invariant of `Self` guarantees that `self.as_raw() i= s a pointer to a valid + // `struct fwnode_handle`. + unsafe { bindings::fwnode_device_is_compatible(self.as_raw(), matc= h_str.as_char_ptr()) } + } + /// Returns firmware property `name` boolean value. pub fn property_read_bool(&self, name: &CStr) -> bool { // SAFETY: --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.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 3FD481E5215; Wed, 18 Jun 2025 10:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241597; cv=none; b=l58jvThrc+XjQnfUrakPEd6Mx+qQieLa4dgTQgQL/5xfdFPYlZPZ7iu/lOyBNK9uss0WFfLHbKJnCeFfz1cU1/biQNktuVgZW7k+37prGg9pjPjsyC2ZrNqd/P7KiOqylZN8QZeeX1720Xj2c/7LYQo/I3A6blymfbfCo7pWGqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241597; c=relaxed/simple; bh=pNNwV/XGoxOQv1CG9hWq28XZ9aN6GRVjgDsVYJmJ5t0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UN5EBxFL+oF8LbsOB/TmoK8gQjh4AnVpKqQC4/4MW1siFfmwK4lld+Qyl1lOWkh5fCkgFWdQaZeEp9XQHJ59d4rz5yzoKyMzOpQuWPfhiiPxFvdR4YLpfmTmlN+G8d9l9K0wQ4D0uHrLNhDmO0AZA3J8eceFjE12OM0Pitu5T4s= 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=h1prG0PP; arc=none smtp.client-ip=209.85.128.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="h1prG0PP" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4531e146a24so41332835e9.0; Wed, 18 Jun 2025 03:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750241594; x=1750846394; 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=JcnlFSZlZ2x3eUss2ZhS1aBPVnMt3wLpmm8ROrRN7RM=; b=h1prG0PPtxMCuTenFbwAPmpP8Xa9geIZMxrSa+bQje+Etbycp7wiCgBIJNZ5HIBOwi TL3dT/+l0ATTLJqNRZPAC2lZz4+TmOJSg58de+wJwncXGeyBEFmGGcOqqTR2j4rDZ7Dt JuboUWcLTp34kVeQ2lMsv9lt7xX8sn3zxksR35zU+TQhy+ob7F3fvVRtXJck/wBoyLZG O/wC6wY5X4XmTsCr6amKUEVfn4RWMC7Ga792a009oVz2dkdquVdLDVM+yDgWBYkC1XcS Kr3zT0Rz6BezFmfN4Y+XfXcwYCVHhp1oPyfgLPKqhuA5zXVIUAjktz1u2YJaFDxyxcPn boow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750241594; x=1750846394; 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=JcnlFSZlZ2x3eUss2ZhS1aBPVnMt3wLpmm8ROrRN7RM=; b=NPgGuyh4ixjxf6pjdTvUmCCjo3MOt1AYaHowASPj5wA1n8cI/515INUPTnJd6iEGdA H8xbRv+zR0NsOZ6d76TrMZH5NVvLsGwFuvcvNBm4M1hWblC3wFsTkS5Cqx0TnubDMMEt PFyyMPhE7Ev14NxAnCfq9surK31dGgIeJgTcWxlg+42tfhlC4TcG9fPZKC/SCLPpghSu L7ArdebOtjaqKNHJvTncj8crNCdprasPjPaa52yKAK8z5pnEC2D1N7gL5ld35binhxhe SP9Xydjx0JGDjFgsiMNoWQirlF1pCfzYJXUzpESMgvfwmcRFf6JPoVUZlbPV1y7zXEPD BHIg== X-Forwarded-Encrypted: i=1; AJvYcCUFTPDRH1bPPCNdzLvbXfOhMtXbes1IpuW75re8Z/jJSFAP3Xvx2bHArHxZ5hKZyKUQSSsJKYFOyBAx@vger.kernel.org, AJvYcCUHmN8JLpg0qTqY8l461XMow1weye8v6eW5+VxAdo/TCLUg+gN2g0WvXgzG/rkO4lEzhKI00+Nd0EcNclBR@vger.kernel.org, AJvYcCWswsqz64Ix6ZvGzhNMsKBK6Wl0bQ3EhBuV09VFR2BiEC9sCS53UYPu6OVIUwpyfnVj75+nMtFqN06LvZ7Ob00=@vger.kernel.org X-Gm-Message-State: AOJu0Yxmqj3lMJOSxL/h5tL7lpFLnE47LVo7PqlzBgOCjq1T/gg/GqW6 yDzeUnzgwVTn/S1hInIq2IlphOx2mxUhLjEpc9J+HejhDo5D+DnBu8wY X-Gm-Gg: ASbGnctiBwJnPniGsKYDVn0zGToCfs/tut96A4bDyNPPVObX9In1H3ULe/ofiRPtcYY LSI50yclAtPKee/1pDdRiAjvtvSq4eCf5e5lziWlqB2Pze7aZ937ohufXust4g+N55ddeEk8ewS gLGE/++i5wm7x9dRKanBpByRm74QzuMadE761gMHt1/rmRXFL+5BniMvBskWaawe2ByuIdpTWHX b//mMCoj3vEaTWXSF5TGVko3gzZOfwDs+xnfx/NuoXKqfYot0iCWnj1xTNOrrxC2XJrwAAeYbv0 yzZncma6YFYYLmmLZ26qBjEtlQFm5nV42AVaBADEWidsif2dD0rfa6eKMTpE2yjeg2cUI1H8cAI +FeFEQ25YL2Uzgdl3+2lYG1eScyearR1l/3QRLB4= X-Google-Smtp-Source: AGHT+IEwXfOH3FNaIAS2a78UClizMEIMKgdGdRhw9w824FJtI+ggGZqCrs6PgMh0KumZibH7adUEmg== X-Received: by 2002:a05:600c:3e8f:b0:442:dc75:5625 with SMTP id 5b1f17b1804b1-4533ca468e9mr157629865e9.5.1750241594282; Wed, 18 Jun 2025 03:13:14 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e256b95sm207100275e9.30.2025.06.18.03.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:13:13 -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 v7 2/9] samples: rust: platform: don't call as_ref() repeatedly Date: Wed, 18 Jun 2025 11:11:11 +0100 Message-ID: <20250618101111.3047980-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Danilo Krummrich In SampleDriver::probe() don't call pdev.as_ref() repeatedly, instead introduce a dedicated &Device. Signed-off-by: Danilo Krummrich --- samples/rust/rust_driver_platform.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_drive= r_platform.rs index c0abf78d0683..000bb915af60 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -32,13 +32,15 @@ fn probe( pdev: &platform::Device, info: Option<&Self::IdInfo>, ) -> Result>> { - dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n"); + let dev =3D pdev.as_ref(); + + dev_dbg!(dev, "Probe Rust Platform driver sample.\n"); =20 if let Some(info) =3D info { - dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0); + dev_info!(dev, "Probed with info: '{}'.\n", info.0); } =20 - Self::properties_parse(pdev.as_ref())?; + Self::properties_parse(dev)?; =20 let drvdata =3D KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?; =20 --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 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 2FBC71D63FC; Wed, 18 Jun 2025 10:15:29 +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=1750241731; cv=none; b=pZzcBoh5AHFmxEIeCO/H0cO4Spo4hR/A9694iweLB4XMcXjDPeCj0OOJuR3tTnvNcnLOeR/HXJHZa2Qkb4Lp7FnK83JI7ms0yT64ZP3kr1tlBKaVtV6nLdl7XOp2cQphNKwB7TyC4vtmyAGaCudYEhYk6/RGN+Fm4t7OQBJzLbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241731; c=relaxed/simple; bh=ltwb9DIv2KJ/ugDKG09NyjxtUjK7KgzzXwT+rpLfPek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WSs3k/yyTy8iL+ORyD88n+3dCIKrVbVU4posefJf9oVBa/e6yc03daJoQ9FanJ22qJkvbEV8bQh2LmIaLpv6K4Nb2w0c9nh4AwOOTN0u6amZjkhhx4KTU1IT4dlyLRzygagGicEjAUFspAcGj8ng6GRMuUXIEwt6F7/Llgdsuzs= 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=RAHCGE2M; 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="RAHCGE2M" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3a50956e5d3so5354572f8f.1; Wed, 18 Jun 2025 03:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750241728; x=1750846528; 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=jJsvhinXAz/28vXCLsDhFRnAr3ugS1hgCI0FXeRg2Pw=; b=RAHCGE2MlP3J8zFKH8GZFkN5y+BVE3oCfCN8coAqpMan2fFEN9mhD7Wgoi3/zr9mEK F9t2OGHvVwDx2cOLsYhNnWRkdDQb5yuNXiAiSAqnMnaikfEONlqmuhBGE1cY/unuzaxZ SFXiZdT3vO9fiV3HsxsQ9N2fLMCXba8UJBdrKjDURZAEydhuNe1w3hZfZIkFNWzi8Uwe 195lNKxrF+8Eo6K6MgQmQibuUBoe9OaE78vnq4UmOlZ5V0xO6oDbajh3LTERNZfZ9yHI hIXy7aF8I/2OAOtn2oIXSMwmqimOI1qLM/Hmx/D1N5L6eapqgzvSH+9zBxchQv5xEJi+ EY/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750241728; x=1750846528; 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=jJsvhinXAz/28vXCLsDhFRnAr3ugS1hgCI0FXeRg2Pw=; b=mvuUiJPFetY50g+8N5HwKGRvh7ozDXSzX/Eh/v/hcx7k6KiZIeqIY4qE/jVcXpzzpU J4apFdRcQK4YmA4oqBN9bh2OsQGvSZzkQjvUN3DuBFWHhrxSlxenYZ9ybcBa0Is/ulw+ 10i4Vd+5zX8nBsFoGjJiPZfsPCmlM3TadzT1rLgSw9nzR9h7r9mIk6P7CRSfJUJ7/K+z ElJqGYl5R9GyL2Dvo7cUXKKtOKwozRpsn9qytr4KoV0so/c9Hz6omhmHvFU46jHrYJte 6FiEljlcK5azpLGkj3sSUwteoYQQeu7x2I0NwoWWoVzrmqVVVjly2uDKrvb11Fovbggi cWdw== X-Forwarded-Encrypted: i=1; AJvYcCUVxXMx/UH6wMg3Vo9rBXki+Zij0naUbfjQoMx2/ET4Z721xO6yMksn3N41oFITvGCOt+VKqwD6DGSL@vger.kernel.org, AJvYcCVV/FsqoehO74Ql8q5gtKNUtCGqLEReOTl/c95bTZZLIgao8hINC5p+6RW/Np60fXj3tHhdosr2PjvJCsry@vger.kernel.org, AJvYcCWkQwYkeiyqJk0+mCBZlhZfE91Iq+XU4DoTrNWnq3khrjcIb2IH//59EWphyRC6S0cfDS+2bA8zJ3V1epd/Q1E=@vger.kernel.org X-Gm-Message-State: AOJu0Yziiphl/qNRgo8v/NO0bslYnkyIX0b+Z8tnRpjQAFxF9aMD4bEc pDYcNNspTE/oXp6Bk/Jy2WdXCifOHa2PeF1KXL0EVtogNdZ0jQoq59XB X-Gm-Gg: ASbGnctw/kdwyQtRwDAig7F1+XRsRs0bhkTmeoJw5WtTFbwwZapt/9VZVYX70NnZO98 KmU22YjgRNk+L94wwGpKD5jjk7F9dD1zMg8LX295oBml10h07xIDP7Y4jKBSJg+iN5GlUsbAfYA Q9xZfLxPLc4RS0uf5oNhHal7tOm0SBADRbWFg45or/nJYjDNNWvhng3aDHlaCKR9J3VMkBr3eer MDQ8FBLrO6N6q+kuybl6RvEexPZGlfNgzc60Dbc1MIPCyWMsPX5AQbjQlT30/umxxpLLPi3ovCp aHJYhzSfhtYWZp3MHZD2v6oxbNgC/TsHX4CYsSkmG31zXOAOBJWtjnVQeTEYX2h7GgCJWVmqzAb djah0R5lFzUOLO3KxKCn5O8Y5TjYAlP9dgWJY X-Google-Smtp-Source: AGHT+IHMgSwhUqWfJPYacZImHH+hqT1pGDyJydFaYgDyOIKYQNzn0o0KZQVvbpbNHsGoX4rc88bs5Q== X-Received: by 2002:a05:6000:1a88:b0:3a4:eeb5:58c0 with SMTP id ffacd0b85a97d-3a5723a43b5mr15751243f8f.20.1750241728005; Wed, 18 Jun 2025 03:15:28 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e25e89fsm197453115e9.33.2025.06.18.03.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:15:27 -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 v7 3/9] samples: rust: platform: conditionally call Self::properties_parse() Date: Wed, 18 Jun 2025 11:13:25 +0100 Message-ID: <20250618101325.3048187-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Danilo Krummrich Only call Self::properties_parse() when the device is compatible with "test,rust-device". Once we add ACPI support, we don't want the ACPI device to fail probing in Self::properties_parse(). Signed-off-by: Danilo Krummrich --- samples/rust/rust_driver_platform.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_drive= r_platform.rs index 000bb915af60..036dd0b899b0 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -40,7 +40,12 @@ fn probe( dev_info!(dev, "Probed with info: '{}'.\n", info.0); } =20 - Self::properties_parse(dev)?; + if dev + .fwnode() + .is_some_and(|node| node.is_compatible(c_str!("test,rust-devic= e"))) + { + Self::properties_parse(dev)?; + } =20 let drvdata =3D KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?; =20 --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 2966027F16D; Wed, 18 Jun 2025 10:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241861; cv=none; b=tIIk1CLnOJujT5bujdmWTgN0TUgK5aZHdp+T29uKcB6ahjhzknxbUAJtPzpL2jtyo/z47Elvy/bIjL5+XnXdQ2ARXN9aEX7GL6ZuyoXyH0GzVEqgeBINKtzs6/4PamnZMZhlF5ODJcUTnekSz5br903AjT2j6WjyWtaf7VyzcRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241861; c=relaxed/simple; bh=o0tgbZ6l9N8xB1X8Omt0Kq66IINCXwZBCo1mV7j2XGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NMkCSqm2VFVUJHHbV3GOcFLSfKptpu++JlCl9DmzTT1AkcqOM2vyi7+0PBpC5t0G1kqz5g7gD/FtGaQ7N9hBA2At2xkycdxleVvObYN81SYihdAv+MCwJnMFqWg2hnWCgSG9CjNFd9J6bUf/spqXO2Rvh3htcuSOiaJKBEEfKPg= 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=d/cypbIE; arc=none smtp.client-ip=209.85.128.49 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="d/cypbIE" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-451dbe494d6so85273735e9.1; Wed, 18 Jun 2025 03:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750241857; x=1750846657; 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=X3MCJ09iMYAJehaa7R4exb7fZmksRmxtphee/D+f4gE=; b=d/cypbIEMqZJV93dYpaSY4O9GNc2Lh1W/MICBd7+oq6X/GCuGDfB6+/FpcS6Sd9DYV JpFwLu6I/dubmuVnC2aBx56yOn4SDX/Nh3JoaiP+BaqmoE/vK1ASWJ7d/3+NFkPieRLE wqAQDoWbjxq/h7LcG9GAMpYImWCSWCrIYBi6eTSoLy5o86v7pkzUuenq8Mhq9EorCWJp 2Hthw6WqmlnI8DolBugcWLMY2txdlvs32JQdau2W3PQC6D+0ykv0j5AiZZsuNyhN9h5C XVEQ7ZZeOLiHx4ox1Fa3ogN+LqlzzyO85ylvFFOrNW7n9gdojibEO8BBc5xkQ/pgZQoi EcCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750241857; x=1750846657; 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=X3MCJ09iMYAJehaa7R4exb7fZmksRmxtphee/D+f4gE=; b=dOzvaQL0dFxMdmPM/EY2yRvR7J1l5IIFimRRJMq2ulNXrvkxiLyZUy+ArlNqgmEADu NExWHi0cMhJJ+3bpKoseoY/cGp8etpdIvHQsdAqj9BlK5Yp6Gi8ubPJc/NDVEmXuC4gG 0+ObzFHem6X/Q4Jbf7Gt6SItbe2DJJM2KKr4rbE32qjIJfoessryoc4xSI4cdyJl2g0k tIF4PdwrRVN94WfmojD0EDzw7yRqTgkHhSKKQM90+bD+OkPEFMnqlu4Hzf2fHg/kffJW 3yNrBu+tfRcEJxoo46PGJTYJ6SMt/EdUxli5BY5SNqUkdz1MBWxNby/qGujC6L3rBGQu IyNw== X-Forwarded-Encrypted: i=1; AJvYcCULwHClOf/XL+1pMzN2Xf3Aw01Jhwi+WUDqaplng/A4o0KR6fI/DDsNF0L6JNDF3axMaHgzdFM1kIl3svRX@vger.kernel.org, AJvYcCUYZiqYIIoCz2IeJMh4qQ9bRRNXAfvTFcBAtmHkJOM3C/+oBcqlDrx+mwNuTuQbYFsW19nrtMppremi@vger.kernel.org, AJvYcCWEPIF87Pb+6qQIrH7omSpH2xoNPg5+QFF5+tdu6DqjMtVliukA7C6gvQ9Z35s1cORJs4f2JD17yMnqdZ9v8x8=@vger.kernel.org X-Gm-Message-State: AOJu0YwLCWsWF1oNFTy88F0ySUj/r8A8RgpA5vcTNxiV+Ek+8KkKx1Yw 3FhyQY1veGtuCR9FZVzmvvuSYZaGCRrZC6QyR8jHT9cThN/SxMsToL9M X-Gm-Gg: ASbGnctSwv9j84Z5moy/7kdLXD62+Vx7PyUoMl2sKhxUJHAnO8LQBqNEXl83eKZHkgH QKd48nCz0NP76AXgIWgGlYoPavPXmg9v+vrC2oZevXIOjDenWDcM6hBtcqQZzSNoxa2xbOmjpFI jUr26XKBnqia40FUIDuMHaYz5Nlr+d/8nVJdItAkqoNoIjK8JZZzJbrhRgvYkSjp/CGrS+vG1b3 E9dtEGNXoj+sR+EF4AdRk0Yf3owH4mJezCCmx5LkcUUOu+piRGTvx+utaXFGwtHmyStXFbOtC94 3SsONESscNeqLJfUnoRrEwEWpJB8C0s0AVOxLUFGfOWgGL/Z/RBZJMl2HBDR7THRYeNr45Et1fr m3IIgX47RIxRS362moH2pp3K5b5w1SPzZkxE/ X-Google-Smtp-Source: AGHT+IHBSD5xgqVtLPW7Ie1ApLdXu1ylBvAlNyRg/m6dABbRKmGS4jcvbdLe12gs66fPRSQeQ+l9FQ== X-Received: by 2002:a05:6000:230e:b0:3a4:e740:cd72 with SMTP id ffacd0b85a97d-3a572396df6mr13827720f8f.13.1750241857173; Wed, 18 Jun 2025 03:17:37 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568a54a36sm16731721f8f.15.2025.06.18.03.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:17:36 -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 v7 4/9] rust: acpi: add `acpi::DeviceId` abstraction Date: Wed, 18 Jun 2025 11:15:33 +0100 Message-ID: <20250618101533.3048391-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" `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 | 60 +++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 62 insertions(+) create mode 100644 rust/kernel/acpi.rs diff --git a/MAINTAINERS b/MAINTAINERS index 9f724cd556f4..acd36c148479 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/ =20 ACPI APEI diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs new file mode 100644 index 000000000000..2b25dc9e07ac --- /dev/null +++ b/rust/kernel/acpi.rs @@ -0,0 +1,60 @@ +// 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 =3D &'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 =3D bindings::acpi_device_id; + + const DRIVER_DATA_OFFSET: usize =3D core::mem::offset_of!(bindings::ac= pi_device_id, driver_data); + + fn index(&self) -> usize { + self.0.driver_data as _ + } +} + +impl DeviceId { + const ACPI_ID_LEN: usize =3D 16; + + /// Create a new device id from an ACPI 'id' string. + pub const fn new(id: &[u8; N]) -> Self { + build_assert!(N <=3D Self::ACPI_ID_LEN, "ID exceeds 16 bytes"); + // Replace with `bindings::acpi_device_id::default()` once stabili= zed for `const`. + // SAFETY: FFI type is valid to be zero-initialized. + let mut acpi: bindings::acpi_device_id =3D unsafe { core::mem::zer= oed() }; + let mut i =3D 0; + while i < N { + acpi.id[i] =3D id[i]; + i +=3D 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, $tabl= e_data: expr) =3D> { + const $table_name: $crate::device_id::IdArray< + $crate::acpi::DeviceId, + $id_info_type, + { $table_data.len() }, + > =3D $crate::device_id::IdArray::new($table_data); + + $crate::module_device_table!("acpi", $module_table_name, $table_na= me); + }; +} 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 @@ =20 pub use ffi; =20 +pub mod acpi; pub mod alloc; #[cfg(CONFIG_AUXILIARY_BUS)] pub mod auxiliary; --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 6CD472857CF; Wed, 18 Jun 2025 10:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241988; cv=none; b=RL7gq/Lt0iwxcmkWiGVH4JHxyc9CsVWMmm9WW0ogduJpfBwaR2+AyJyZ6axx7rZx1jUHHeoFEsLC4prar0WD3sv0p+GjhCgyzPAD+Jl7APT4Ls3UGDPM6jxzSSMAi312fvuIHtk6l826fJb0wc1ZG2KMcVZfX2h85lbRjmomuaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750241988; c=relaxed/simple; bh=kdiPdMh5+sRzNgtYRKj/S0sAtUte5v+zpvWVg0DO3wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FQfo6ZSMJJ+QfcqCHKwwcIcNLM4rnwFDNE1KEo8OwW+uzM8WXMrsEypCT1P3ooJfNVrUBmEfz7eu/5BpVtwhJzlSlQjFWqzY/dzPXrJPRGTJWguPjWm/naPpUPC94zRyEBCh/FnGqnkOzPgLsUE5IBl8W5oTtzDHaaZnXtLkIX0= 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=cWBZKlpA; arc=none smtp.client-ip=209.85.221.49 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="cWBZKlpA" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3a50fc7ac4dso3953114f8f.0; Wed, 18 Jun 2025 03:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750241985; x=1750846785; 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=cWBZKlpA7WK6bTpiP2mJGrl1sFGOD3VQZYQZuYsIV850lUFdRZpyVBfRb3p2ZQ7Utg dIPVncWiZUm8CR6Otyo0QKKwGI9AauDs2r3G0vkAaCGrYilTB9Okk5Am9tPHUVzXCepc klTIGkmcb353yRYunszFMHvrkF9MPkiahDfWGwQs+BZWDmJFlhdtKeX0GiJFkc8keKQH LU27u4Ve9xJDcVoS9tzvky3pj1l0p+IPIVxxcCtpUSzJjTUPJ/yFLvG0WE8B2WFY93Ba 3JEyseLtY6IU3DkBKx4QAc7yp89zdz/7IuaVJVR+pCFIm5NGkn8zNeY3WZ1ET+tvfe3g DhgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750241985; x=1750846785; 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=MVR0GhKBcWJjQ7+A0qPKIqiLk2O0IgS03Tv+Es4HAiS2vL2S4vrOedcdeL9MVxSf5I gDa3gZwO8gFdup1v15nNBMo0U20Raq8Pk+C6Uoq9+nTKxnluAse5TPObZbzmiPvF8kV+ dHC+Bti8XTmaUQHOkDrE7DIq1v9OuaL3feYBPk7IxqORmROnwtjsx9oBYWeuDvNOvuAm ZgNNY5ym5d8YA69ZkJa8zMXXVs90r0Jf27GCG7bA1zO/OhGvwptbYc4cbAMsUzTrAKVK yNOLfr9nAaFoBg+EI1BDPsa5+oVGtLUNQ8LQTqqp2AMqmhd+QXjA5hfExZd+zai5agYf MKVw== X-Forwarded-Encrypted: i=1; AJvYcCUTUHMeaD2v2sCTADS+ZN4q7+obwAVI/8HQnQhSB6KUrodQwsayESPFwqpeJ8sGF/LShu28F5z77tJvnVkk@vger.kernel.org, AJvYcCUdIHURHQnKTBHktvdas5GOOEHX1F6ExBvQh8JFdAaKZpjac3leSUjGruzGGEogOKMpAn6m4DOAQLKuzTefHss=@vger.kernel.org, AJvYcCXEEd2qp3i1P5kPyTyQp5g+CYxmrcivkKIsEpWqvuOmNJrliPiAlZ19p7fns/pdgE2T+DY5e9MxLeCk@vger.kernel.org X-Gm-Message-State: AOJu0YwYVz2OTXySsd3P/zCP1zakNPcq+7PhS3o3Ym6HOwaM4/YXbNKO khUzMglhLKoq61pZ5CAka6gITSSSPF4py7QAMnOeKkNzmI2UpcRiF4ut X-Gm-Gg: ASbGnctwyFsgfHB2XBUwRO549gfHfd9wZnq/zEOTWp/otuccC4SVZuyzeXjkV5LGE7y 3zUCPx6bcQdISGE96+u8UB5hJxCxUKeBJAvXNfyGtvU4N2r51qLf+6E5/3IxygKze9hHd9n+AQ3 sdKw32wFh2E1wmRYGMRF/r9B0SLG+RNo4U+7SH6oVVAEqgWTO/0O/uKZHC8dKjmK6elJD6gkR3Q 4HwisRNr/UV/5+bFoLIJ/NkXOOjTC4V5+SbvMOsloaxbOLySzFhNeoMCi7/lSoliGOJObV4xSAs uRNi6UsjQUe11GF00pLIp9YPD6AJpglgomIfAl+ocf/YzQihLNkkk92yc1BDa1jg4QN+Ga8C9tf 1KuImZohbTckiyBSi3nsygydij6qdiiqnouRE X-Google-Smtp-Source: AGHT+IHB+U5DjgKYH28LDRAxh/14b9t99lBDOZmzIa0ejbzDXmc50b8UhG5Om/kD1z7jYZvFiiye4g== X-Received: by 2002:a05:6000:4b18:b0:3a4:dcfb:3118 with SMTP id ffacd0b85a97d-3a57236795cmr14608027f8f.10.1750241984501; Wed, 18 Jun 2025 03:19:44 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568a68b0esm16274027f8f.29.2025.06.18.03.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:19:44 -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 v7 5/9] rust: driver: Consolidate `Adapter::of_id_info` methods using `#[cfg]` Date: Wed, 18 Jun 2025 11:17:42 +0100 Message-ID: <20250618101742.3048622-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 i= n the [`of::IdTable`]. - #[cfg(CONFIG_OF)] fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> { - let table =3D Self::of_id_table()?; + #[cfg(not(CONFIG_OF))] + { + let _ =3D dev; + return None; + } =20 - // 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 =3D unsafe { bindings::of_match_device(table.as_ptr(), = dev.as_raw()) }; + #[cfg(CONFIG_OF)] + { + let table =3D Self::of_id_table()?; =20 - if raw_id.is_null() { - None - } else { - // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper of `s= truct of_device_id` and - // does not add additional invariants, so it's safe to transmu= te. - let id =3D 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 =3D unsafe { bindings::of_match_device(table.as_ptr= (), dev.as_raw()) }; =20 - Some(table.info(::index(id))) - } - } + if raw_id.is_null() { + None + } else { + // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper o= f `struct of_device_id` and + // does not add additional invariants, so it's safe to tra= nsmute. + let id =3D unsafe { &*raw_id.cast::() }; =20 - #[cfg(not(CONFIG_OF))] - #[allow(missing_docs)] - fn of_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo> { - None + Some(table.info(::index(id))) + } + } } =20 /// Returns the driver's private data from the matching entry of any o= f the ID tables, if any. --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 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 CD6C62877FF; Wed, 18 Jun 2025 10:21:57 +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=1750242120; cv=none; b=DZf0XWI5XZEHpZnbba5D2HAJhvATdsRQGe6C4GdG3rlwJ9TRJ6RtANwSnXCz/SJXwObYynHVwBLwOyqZSRwfXAuxR6MlL7EhzvmetgwR+zLTwfiV6a+1ovWL3tCuC6Nntqv4rKGgEz+sGJYiW1cqF2niAlEgEGCi8iJbzUqZ1J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242120; c=relaxed/simple; bh=1Hy3ujJXBqxV9lfXBO++FN2/fZmpMCZpJfkWT5aJ4iQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dZYxZVDtpB43qkdmmqb9csnwSmuijimnaVDz/NG7/o8wSpWkxcqPo9OdCwioerTQ4rUgBlzGqPKcpqCnOSnl4033oFpFSdGep/6NEnHgjPT+cRD5SMROuLpElD+NjtG1bkMzEBy17N+ufKMFNHj9Dc9BVrvox6aMofomOt0CaLM= 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=cXB2kXbk; 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="cXB2kXbk" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3a35c894313so7551132f8f.2; Wed, 18 Jun 2025 03:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750242116; x=1750846916; 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=cXB2kXbkuAy9hDfKDfZozzZfsEXtcUnC5DP7KWb5mDfLn8iFyvLx2qfoez9TMRevoo LXZ0HRUUBrP+z8uC0DJCrfBrBLWFmX1rzbtP7ZxPV99tPzLEwFAh/al/MwKBy6vb7g9N CZZjVbxoA4qZTzKrzRWBNZwWxk0ekKuau41orO6Lcd8v8jCEAQf6i5tYRFwZ41nDwBqf iExHvMaQ4iirdDJzPheE9Sj+5favfHkKUurh442+3h5qla/nw9HoWH3Dry8BB4eNS9bs zXPrpXcqWdQh8xDqvXnDK3BQVOnZobPuWOt77hqoi/ShOFY4dyAbaH4sKQjdI8zONoz3 OF/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750242116; x=1750846916; 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=hmkQtZGirV4abw1sCv5SMQ4lLWneYhxabsl7QJ00D99WtyE49qkIsLmM/7aepIcqFx uFSmbVBzAC3kskCt7DD8m/ZMPGmM8iClaWY6+iFj6rMEcnRtU/OJ+REFQO2cj7k0r9x3 UFnXQO24xpUDKtUijUJiOasmBYjqx3NZFfyq3aoUKjzESxnPdqQvAohCZfq7FuYow5Ht UQcOFwHYdxlZ8RyrEgybRjFVeDwZ4plsJjiI4H8+XNd3umeaLeaxQ/0CjBXAafsoTgMI 5oq9vC+SF8GgUytx84aE/fux4doZEOPLHB/ztvT76HKwsGg0Mb95UdJB2JtV9tTWyq1V bApw== X-Forwarded-Encrypted: i=1; AJvYcCVwGxHIAQ4mL2JWwaj+OsVs0fmAGJ7FHGOCGXPNJvLC21/33NivPF2q8bok1aRLcx+Rrx8DH/hNu6cL@vger.kernel.org, AJvYcCW+uPLT9OvPbQ711ZUGk5IObIoAG7NLEPsMPy/CeqhWAkqxNRcdzQ7JXgkjabcF03xundhPQPaGff0TdMoN@vger.kernel.org, AJvYcCX1+6igHnUsyFSLaG6qHAxpTpAhzeLlzAGNynF+OQbS0M6CKZc5w4VeKC/b4Y1oa7IgVcEmkYzAGZv8rFEgkCw=@vger.kernel.org X-Gm-Message-State: AOJu0YzP//yJ+4chSzvc+KrZQN5NaV68D4/gG9Kor2J7lNm0ef3kvCOt z3QiSGwZFiLRbvD/qnwyvsE7+JhYfsPbj6USYxV5izmWP/Lq4WYbgrOm X-Gm-Gg: ASbGncuc4grRK8U/xC4A5qhAs8UuWq5HuHKgBUSrbxOUjw42gsEDJgYmyulxpT5rlZy YijuTPoeLxyT4GZpM4D03tOHz81fc5d61AaxdMN+/TU3aE3xDQOiFMpkourdbmYrqXV+E8CFOan Ddz2LC1h/cyImgl30wt3nJeUNWjhB94ymFvZD8LDwEhS6g2w+Ga3Hb0Mn6OjdSvIuR/eUYrlT2m /hH6nwIuH2FakFwlJp+o2gbEVR/TCoLZrNgy3EiJfmmP4rJbJCq42+D86f0C039ESUaVNX3vqUG XSmmjBU05rNMCTocYRtOjK7uaCtpP+NtitqGGY7BAFkTRjI6MPOy1soHGzjn8y++hOiPnV3qlws WwlhMog0hDYUWxg1IPt3iLISJZvhVOpVGh05c X-Google-Smtp-Source: AGHT+IHTcdjTyyUyU7t1sq6t+9KngpxfIL2u1E+Zj8SLI9gfO4QlomLwU83Tc/eX4WSsq1bROLC11A== X-Received: by 2002:a05:6000:1acb:b0:3a4:f038:af76 with SMTP id ffacd0b85a97d-3a572e886ddmr14451774f8f.53.1750242115844; Wed, 18 Jun 2025 03:21:55 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568a53f79sm16320729f8f.4.2025.06.18.03.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:21: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 v7 6/9] rust: driver: Add ACPI id table support to Adapter trait Date: Wed, 18 Jun 2025 11:19:52 +0100 Message-ID: <20250618101952.3048902-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_helpe= r.h index bc494745f67b..dfb2dd500ef6 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -28,6 +28,7 @@ */ #include =20 +#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. =20 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, This= Module}; use core::pin::Pin; use pin_init::{pin_data, pinned_drop, PinInit}; =20 @@ -141,6 +141,40 @@ pub trait Adapter { /// The type holding driver private data about each device id supporte= d by the driver. type IdInfo: 'static; =20 + /// 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 i= n the [`acpi::IdTable`]. + fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo>= { + #[cfg(not(CONFIG_ACPI))] + { + let _ =3D dev; + return None; + } + + #[cfg(CONFIG_ACPI)] + { + let table =3D 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 =3D unsafe { bindings::acpi_match_device(table.as_p= tr(), dev.as_raw()) }; + + if raw_id.is_null() { + None + } else { + // SAFETY: `DeviceId` is a `#[repr(transparent)` wrapper o= f `struct of_device_id` and + // does not add additional invariants, so it's safe to tra= nsmute. + let id =3D unsafe { &*raw_id.cast::() }; + + Some(table.info(::index(id))) + } + } + } + /// The [`of::IdTable`] of the corresponding driver. fn of_id_table() -> Option>; =20 @@ -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 =3D Self::acpi_id_info(dev); + if id.is_some() { + return id; + } + let id =3D 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/pl= atform_device.h) =20 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 + } } =20 /// Declares a kernel module that exposes a single platform driver. --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 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 98B0827E7C0; Wed, 18 Jun 2025 10:24:20 +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=1750242262; cv=none; b=njANGiKaLSkj0B63C/gN6hcOOoTQm9lh55K+4vg8jzKVEATeXWLD4IzcBWaXOK23ARAqOFoMT1X3H4rqXv3MQgaV/thoG5h04jmGrj1voeUzNMPMR0tozSaKD8lyA2b7XxJxMrlk1wIYzuTIKo2jcXD90YZOZv7WVHiPak4roX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242262; c=relaxed/simple; bh=X3GP0rFGQWYb7D9EofmWO4CkjJb3nRBnJ4sS25K5GGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UFXAy223eERRqJC/Jzy1GK7i/B/sOXg1WEh+SavnJs3aEfZ9FlNd1st+xUPCrgE7ZZ+ICPhXrJ3+VNYUouz8WssXbAo6+dFNUAX446FWICbw3LW9JDrvtBU7ZHpELuvHpXBOqlp+kdU4gOO7RhbqQYAB6v38zmHeS09znpyBkkg= 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=fLXrOwT1; 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="fLXrOwT1" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3a51481a598so3907860f8f.3; Wed, 18 Jun 2025 03:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750242259; x=1750847059; 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=X/r6nOkep5bcePWw/OmX8epaR10E2HZMsLJvTHOobc0=; b=fLXrOwT1J5Y8bdFyDn/70qn+YD5ESDAh50Ptgk8VAKKuaPGParp0fHlgNvJGj99tsp adOuC0cVcgBgwb8JeitA1HmvYQGB2QqTMJgkdFRaO/+fvQC/gGZuK4kGfnUl6H2Twakf wxVc4ENtBJSAWQKxb7DpRWfJISXxCbdGg3i+68qs4sF+1HmwoPx2tuoPB1ahgermF58P SgeL3mY1R9BIl7MV1KRwFf4iC0h5DJSwi+rQ+I6lPfZDzKGo9kVInQ8I0UORSGFjtvkD 97Di5So1LSpReZ5+417M0mDGWW0umuUv1EsqzRUsMg4iXqwW+03Hb++neEv+G0+z4Tum sGxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750242259; x=1750847059; 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=X/r6nOkep5bcePWw/OmX8epaR10E2HZMsLJvTHOobc0=; b=qswKrS4ZM+jR+8YskIDB5WzpY4OZ9Xx9fDqVPoCX7/hO06Y2K7S7J9COyk63pXsU9D i3C79FrH/BydSguNIauZ/FUiTo9KL18/bTfuJoZ5Y5xQZq45Svlv3vy5l1wtb68SANds 2f0nqh2vr1LBysl/fJhr97Y6/bh6ypncbBbCy1gfuv3GolcZhnp15mmt+fdSs3ifA1H6 4QMIKu2Mt0TjtJSFzOwzKcNo+bP8xbI19PPFx87W8tmmPjfOBJXI+A5i6IVDXypjTC2A VAphdnlIxByHyLiLyRZfnbAJodO3RmO3KDrTuHHzWouZjwljbRLco20xaP2l55EtH703 H77w== X-Forwarded-Encrypted: i=1; AJvYcCUSLsu9g2mcKtCl3zcUTaiWZ2F4KkO0fCL6HzUneKfeY/YzNTOEfifmJrhzn94cbNSiZvG3S0gUQZPU@vger.kernel.org, AJvYcCUZjuScDyQPe9SNHyBOlGWccMXHq8ETjBFr4lVWbodbcxTfn1aQPnI2Y1+/BS/15GBwCCfyRrEyHuHkGtMVxvY=@vger.kernel.org, AJvYcCW9dvT5Ni2bc454p+VkuVCx3ueWuH9KubxYdGnokKJI9tCo18WpdckG7DU8Y33ZtxekaYuGV3OY7NK5b7mQ@vger.kernel.org X-Gm-Message-State: AOJu0YwdO76FCbTc0H/A9IABUzGX57ZMV5HzpPpc67rdPZuC8jvBXyfv H5t2JSR9wubZ4/YTSJURXYQs4BV5FJWzkgwTCnwlc+dtTxWIQTUm5iVwp0Kd4OWuJ68= X-Gm-Gg: ASbGncuLKk1SPM6vwr9/XuWnthz1NIppkU7Mt9HISwwAWsD4dAekSczOquKqqC5H83t LJTp9yCb1tjfi/IpYGNbcNi6XjcByLB81v0vDuuFdRZsOaLvsI6jDYTFURvP2j2AmQpJ/wShgF7 VwKsCQnX8+7CHWTkiTQ81vcbJmbrOjF8QD0+ad+Hpi16QmkshbSDgo89he10rttw/8Ubk1/Fsec tTIWHJqtyzVB+TdeF2h0oK5Wk3hVqtmgoPm7SIaXE0mtYnudtPkKM6mAQpsGjT4CCpDEeXhyr8J S3CXLmiLd6+5UzGCW1VCeJzDyv/io9M+R5mIayKcO5iD/4l5aavANmuNHb7KrhRLacYxLCYa2r1 jNx0s7PwPnXRDQnFkoiyqh9M0fomoDELwOJEC X-Google-Smtp-Source: AGHT+IEWJFosgYtVST8+ChR8BDeP/SmvQxlvk4F/BE7rA8OuYv9evRFDiLtSxCZZLKuCzhAMhcHWNw== X-Received: by 2002:a05:6000:144e:b0:3a4:f975:30f7 with SMTP id ffacd0b85a97d-3a572e58f6fmr13346541f8f.56.1750242258788; Wed, 18 Jun 2025 03:24:18 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568b08c7csm16769840f8f.50.2025.06.18.03.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:24:18 -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 v7 7/9] rust: platform: Set `OF_ID_TABLE` default to `None` in `Driver` trait Date: Wed, 18 Jun 2025 11:22:16 +0100 Message-ID: <20250618102216.3049450-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Provide a default value of `None` for `Driver::OF_ID_TABLE` to simplify driver implementations. Drivers that do not require OpenFirmware matching no longer need to import the `of` module or define the constant explicitly. This reduces unnecessary boilerplate and avoids pulling in unused dependencies. Signed-off-by: Igor Korotin --- rust/kernel/platform.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 5923d29a0511..2436f55b579b 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -162,7 +162,7 @@ pub trait Driver: Send { type IdInfo: 'static; =20 /// The table of OF device ids supported by the driver. - const OF_ID_TABLE: Option>; + const OF_ID_TABLE: Option> =3D None; =20 /// Platform driver probe. /// --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 3783C288C25; Wed, 18 Jun 2025 10:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242400; cv=none; b=div7dbqi2MwAkQZO7G+fpgsVyKwCVPtBOMe+t1A6pH//ff/+dpoMRTuh8pSW19RF/0AF2+0vgUDAbMnmEUcmE+eeTmaILdNq4Cn1HoFsY8T4oObDIT3/A/+OtRo8n75EuDWQAXQudPXIgK2aEGxYdvDkszRLEcVpVFKtsV4BZVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242400; c=relaxed/simple; bh=fCZg+qa6/P+Asbd0KRfxqaW80M7dwYJ1XuU8KBHp+rI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NVxmcoom04o7qeZbaolkr67REZ0NsV+DH2oQiBZPBQ+SizxP/07s1sMgsOTIa4sqwWY1hfrgQ8x4hIAMYYb0p4RRnm+LRUl9K5/EuOhp40ML717q9tmIwM1Jj9O5uIU+zAcib8FLzV1NOlcUsnTDVI0ppDGONK2IuHszs7jiJhM= 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=OQbwelzu; arc=none smtp.client-ip=209.85.221.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="OQbwelzu" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3a5257748e1so4859615f8f.2; Wed, 18 Jun 2025 03:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750242396; x=1750847196; 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=LKJ+35t8HG4O3r9CAZlhOHv1jc/h4zjJpE9N6VOcuWY=; b=OQbwelzuFV6htrWm8OUkMzdTM1PH5HTFnjhH5V+Uflf1Z6Vwr7i88XOo874bO0Oeyb cyN2jJok7mGUHprnWFbWflDYRb8tzhl6aHU+VlAPkXk74T5nEsV+AIRwSpRpPTTQU8Yl xs4GF8de0zAE5+iJ8O6SxRdRGjZu/QcZPzQopwzdPWHegMSgtYB0lF+JFUzOJjioX/Ol 1IwLirer8by/6M85I7wwxze9sA5/+OdLaaY44dgC+At8FFEdEM5Bx9eIM5OpsVLrpehd 7B2TXID9JlSJye6oIoJ1jJuxol5JDad7HA6K8Cq6ZkpED3hZjHXxah4c7+yrxZGjQ1mU kQMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750242396; x=1750847196; 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=LKJ+35t8HG4O3r9CAZlhOHv1jc/h4zjJpE9N6VOcuWY=; b=kF2dDvWFYQRZUK6kO9VnmG8H54szA4Y1UTMpo/qy5ObQ0I4sR+JwVKoblhYa+Z8vjo 63NWR5d55MRfetEcS+/0PGSanLAIUDm0w1uIVwAnvf/MptyENWDREwKzL66sr8KoOBss KsYQLzLEL6DMYc2pc7cAbk90dji4oAJIpsvb6gwwLdHVlIAh3FNAXD19KmYVPxCbW+f3 LXVYTh3sXmmuce886I1Q/QG7IzjldT0k4cLp7HhBd9WKvBep1y3BKGUPEgXJh1m87s+L D4HSdu70wkVhxB0iBGpXZM0bGhkqrqT+106zmqQaVepzUDbV54bt5nJkTccUbjubzHr5 8IdQ== X-Forwarded-Encrypted: i=1; AJvYcCWh08koQ8tFYUolQYx8w2l1kxjOg8WXd/t/7iqNncL+ETDPEY4E+g4cR2Szq1dxZHNUgA1G2oMIAa5um5N/@vger.kernel.org, AJvYcCXFLKjbe0BjHX89py/lMN4750Oz63NBAhyy4QIcNB7jgWxisoyb4Sc1DnFuOpqeRMOhQav6tkteVx2S@vger.kernel.org, AJvYcCXMsdCzrgM30stsSpYqdNeNfyZHY4+huimSeV75JVhk5kdxD8A2DMdebaZdW02F6Ta0zXoGwgY+H1R0COHrrBU=@vger.kernel.org X-Gm-Message-State: AOJu0YzD4ueTMyZCBKQMx25pKS4QAZuMkixyLUJArAd4frtZy1J4lJjW 8ZgZ/XfeYmuplNGgGg7fqgfS+FEscFKO9PpwyFrArasgKE8EkrwNgjSs X-Gm-Gg: ASbGncsjBnw16TTO5syV0OLaWFUSbBrMOwOcBXlqtF6413n/0e9eFGXM5Z03ETezOX7 TsRJ970eR/MpWPPTy/WSGehD4jcVEai92Nhut/Ni+MOiBxnDoO0PYoR35HVzlZ8phgyU50rCjXX 0zumnaO5gwBqQYJfpi/brSJQ23gZlqjJS+6+HLI+f/TuNphDYr+fI5AoiU/me9bC4s1fD5A4Utr iiTaWZlThqBjHsKSfMwRlRPBLUakFbNMX+6TrajohOOu2RZZZIVY4RlOUF65l8uzLQgW8VXuo5/ hCfEJ8vn0cwRmiOWrBCewiMV2ffAQhH/WOURlbKD7jMlfDYkaC5TmNTEUCnCufpBY5SH1PRKVmT /gwye4UNE6os50L1Vc52XCT4w7GZufvF9iK2l X-Google-Smtp-Source: AGHT+IHb5FsVZYv2LilMOYqaP1j1L8oMI+dOxYRmokRF04f8+Qm6HB/QZ6y9DdDo5scMmE+j6mIm7Q== X-Received: by 2002:a05:6000:4202:b0:3a4:dfaa:df8d with SMTP id ffacd0b85a97d-3a572367c45mr15194880f8f.9.1750242396332; Wed, 18 Jun 2025 03:26:36 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e2354fbsm199608085e9.15.2025.06.18.03.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:26:36 -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 v7 8/9] rust: platform: Add ACPI match table support to `Driver` trait Date: Wed, 18 Jun 2025 11:24:34 +0100 Message-ID: <20250618102434.3049816-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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..0d00ab9acef7 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -37,12 +37,18 @@ unsafe fn register( None =3D> core::ptr::null(), }; =20 + let acpi_table =3D match T::ACPI_ID_TABLE { + Some(table) =3D> table.as_ptr(), + None =3D> core::ptr::null(), + }; + // SAFETY: It's safe to set the fields of `struct platform_driver`= on initialization. unsafe { (*pdrv.get()).driver.name =3D name.as_char_ptr(); (*pdrv.get()).probe =3D Some(Self::probe_callback); (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).driver.of_match_table =3D of_table; + (*pdrv.get()).driver.acpi_match_table =3D acpi_table; } =20 // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. @@ -96,7 +102,7 @@ fn of_id_table() -> Option> { } =20 fn acpi_id_table() -> Option> { - None + T::ACPI_ID_TABLE } } =20 @@ -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(b"TST0001"), ()) +/// ] +/// ); +/// /// impl platform::Driver for MyDriver { /// type IdInfo =3D (); /// const OF_ID_TABLE: Option> =3D Some(&OF_= TABLE); +/// const ACPI_ID_TABLE: Option> =3D 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> =3D None; =20 + /// The table of ACPI device ids supported by the driver. + const ACPI_ID_TABLE: Option> =3D None; + /// Platform driver probe. /// /// Called when a new platform device is added or discovered. --=20 2.43.0 From nobody Thu Oct 9 08:43:29 2025 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 65D9821578F; Wed, 18 Jun 2025 10:28:58 +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=1750242540; cv=none; b=HUpHLQ3AoxKUCeY8rXOO/Jj4LHXtIy8/imfJy1mWWDOXuei4z2dil5T2W91MdJGVpE6xteGx1Nk0AVD6bmg4uLV2XgDZXPcrstJFzgfnebs4gnIqRUTlaFVIPzCS3iOzZBAEm98l++KamM3fvpTg5dLYJ/iZ1Xx+YQoRO0UIJWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750242540; c=relaxed/simple; bh=T0SJPHJhwVKORNMLpZJcWv8mbwrStmXpFFZ9WfsgFkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qGAndAMVCE3Lfr3LmZ0p5RQsLIIA320bBo7rRCFmfy0H+2XmE77VnccXM5/Um7qsdY84xKeNAnMypa2/ewRCLluxEE//9ET/j91SaPhnXMzyYL9IbPdOjdLqX0OlcIcNcD/8qypaf5PHyPd/4Pxspeh4trSHdF6t/qMotuNBvfI= 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=ZmLgEDOc; 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="ZmLgEDOc" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-451d7b50815so56795045e9.2; Wed, 18 Jun 2025 03:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750242537; x=1750847337; 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=AAsGZRd53w+Z7fyD/JC6KZq84tLoTkjPM83MNjJS0NE=; b=ZmLgEDOcqQq0o5zezDOuNDl1q1Xodbt/ACjR8+M+ALhwcnG6nPln3nP03o4Z28dido ChQZKXGy0K6QY/qIsv5bfbBWktAxN6pcYKLPUQRSp5MoLbgDSmCNtZUDeXrXsAD7iavK WLUQN/MM43dp+52gHnCB71wt/cJF8MLTX1xX42mSqm3EloPPLuGbTKE+8pTwc0ZNSWnw vUNRI1WrFm6sAr31T+J36AzaPaVJD/9l6yQi/TDkqBF8pB2g4bU9d/Ix/z4THnpnrFU0 9LCGyiGexb845KMa1rL60Upk1ZeuRn87jolJCIt0FDk7zJ+oSICqFqXjb4lwey2/YjSA pK7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750242537; x=1750847337; 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=AAsGZRd53w+Z7fyD/JC6KZq84tLoTkjPM83MNjJS0NE=; b=OO4oE20SWe10EmLqpTDiz9eSM1BomRgTanNKU9a7KRmPExSxifJTsxxMGRRtzHVnIy 3OfdkAN9fntSQ7/i3NIg4knBzdvOxqXoKABXwA2D3/DZlN6SUSDLE7AMotYuI2Juctti kDSL6C2l3EVOlCohb9kd79kBHTfUjDsdYGoXw4jo54vMnUtFE0Pg30DdpWJLmlhg4715 Dj8Fh1cVjxpLwDKP6l2LazW+4VyDyz/Mq/BtRYrdaItW8NJUF+C5Q1u8WA/AatLmBzOq 2480KzERhLy0iwY9+J0hDtY/NRzdLUHlmLALYR9LmQdDbIVHDGHeN1IR2VHmTD/vjujK QK5A== X-Forwarded-Encrypted: i=1; AJvYcCUgVour87XifuktOU0/4eYynM0yAr3Gturm4V4KC82vnW0JH5e+L1m62AMj3kl4EEpwrInBaEApdR6Gu+tMkz4=@vger.kernel.org, AJvYcCUwTIjry3Cg4LgMHUVXFV7GYFPNyiU4rdrKp4T2SM1dvftGgTtDPYpfvVneS17r8zBtgrq7XAlit3a9NkeG@vger.kernel.org, AJvYcCWmKxHi4pD9+iqMRLKMf2Y7mc7QKvs7NYLk9Oi6ZPl9SlcDNosFGvit/TowLeVWVs2l0Lsedk0Sb6tH@vger.kernel.org X-Gm-Message-State: AOJu0YzJ2J6Dh5nGxyJK0qB9oMZVG5YGLDblQIZQOVuf6VJ41Yo45ceH 4gIz3ihsEmny2NU/KdWQLEqoa1v3P1mtFPW8slrhh76/V/auLpyqP+sx X-Gm-Gg: ASbGncvcsbLrSCNUGLQ9/4cEg+5rH0Ks/eVEKg9Vp+qBQl3nuVbJ1Km8PmkR78ytxEw w7RQh1nmp7wDVGSo7XHZlJ7Bx416af9UA8W5tYXJjmUupkXTB+haU3cE5GSWul2wWEEK8PU/UiZ 4YaJ68AMtZKLX8QUJrYj5F7+wI4LUckAvCfDc/Kw1NNnEUeOJNKLqnt6ohOofKXtc8OA3I+UgSJ fIHr9AFhkR58wH3jDQUno7LIEZucvWAZmn7ZVlSUhLCPpdh6OH5rvg/dK1S7FTTv/SMuDmdLQlM GQdRrZiNADotZ0kPwvbaG/FQkQb0XOgde9mu7ECiJYMYrvLD+pDOd3SFW4OuIBF/fGa83dlauEZ EY/hHcq9j9gVP6nFDs9dbjgq/FuHlEcwImQ1DDvY= X-Google-Smtp-Source: AGHT+IG4qgyrL1HA5S/KZPAkJ4SBAyNYbQB2c36HChaEOrLssPGD5XPO47yPsV1kRMOz16sqHr2WfA== X-Received: by 2002:a05:600c:8012:b0:43b:ce36:7574 with SMTP id 5b1f17b1804b1-4533cae684fmr168876995e9.11.1750242536280; Wed, 18 Jun 2025 03:28:56 -0700 (PDT) Received: from igor-korotin-Precision-Tower-3620.airspan.com ([188.39.32.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4535971b18esm10060145e9.2.2025.06.18.03.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 03:28: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 v7 9/9] samples: rust: add ACPI match table example to platform driver Date: Wed, 18 Jun 2025 11:26:54 +0100 Message-ID: <20250618102654.3050345-1-igor.korotin.linux@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> References: <20250618100221.3047133-1-igor.korotin.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 70 +++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_drive= r_platform.rs index 036dd0b899b0..57e3ac77ef54 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -2,8 +2,68 @@ =20 //! Rust Platform driver sample. =20 +//! 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 cont= ent: +//! +//! ```asl +//! DefinitionBlock ("", "SSDT", 2, "TEST", "VIRTACPI", 0x00000001) +//! { +//! Scope (\_SB) +//! { +//! Device (T432) +//! { +//! Name (_HID, "TST0001") // 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=3D/dev/sda console=3DttyS0" \ +//! -hda rootfs.img \ +//! -serial stdio \ +//! -acpitable file=3Dssdt.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 TST0001:00: Probed with info: '0'. +//! ``` +//! + use kernel::{ - c_str, + acpi, c_str, device::{self, Core}, of, platform, prelude::*, @@ -24,9 +84,17 @@ struct SampleDriver { [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))] ); =20 +kernel::acpi_device_table!( + ACPI_TABLE, + MODULE_ACPI_TABLE, + ::IdInfo, + [(acpi::DeviceId::new(b"TST0001"), Info(0))] +); + impl platform::Driver for SampleDriver { type IdInfo =3D Info; const OF_ID_TABLE: Option> =3D Some(&OF_TABL= E); + const ACPI_ID_TABLE: Option> =3D Some(&ACP= I_TABLE); =20 fn probe( pdev: &platform::Device, --=20 2.43.0