From nobody Thu Oct 9 02:54:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62A0A270EB2; Sat, 21 Jun 2025 19:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750535492; cv=none; b=A8hCNS1j/p4vYRSkjNE8gyRT+vAQHdb3pdxopaYJ9HknZUxifnLvMdOJobadMjJ7/4liq5MtgIRfl8yDzsxH4oLlRDb4jWlNAU3GmfEJlBORaWO7VyAq10cwm8EeOBgcyAMgn4Bxx1ndBeJu94nSj2FqH0gLoMEQhesl6G2P2/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750535492; c=relaxed/simple; bh=pjAS50S4PI0FmiSCTxI6FL6s36Lw3uJn25OAPQ7R6MI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ndM+R8GSOZ0d443Le52f6Nu7od/nVhe3DTTHk7Z3DLIQMPlkaBMVgc9ODcBH0EN+16dT4bFUXCsA/mdkGuujw47FEHtM5Yg1oWJb6WDvxZP4CeJba6pYQreHe5WZUbgwPc+fWVtNilhoM5EosjJdXGdLMdq7w2FdcrvUs0Bh9JQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JAd2ESdF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JAd2ESdF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62AF0C4CEF1; Sat, 21 Jun 2025 19:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750535492; bh=pjAS50S4PI0FmiSCTxI6FL6s36Lw3uJn25OAPQ7R6MI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JAd2ESdFeOHFtJQFC/QSF+YDUBhemjZHjCp9UfZcZ+OUfJr2ofRUL885/rtHSVT1e v2Q3XmVM39n5uICtfLZWJQxrCJjBJuCI/o5OqI/BFyt5TtcpT33rV5TUPT9T+rBYJN K56ScRu2tCqkTIs4dIJXA1hHBthcSWSOVae0OLAgxGOHsyxBp0Bvcz7Dyic5Ek891+ 2gR/U6qAMfNF76Wt/8qGuTacGX3hVO7W0UcSkLFmd0EKaGXG7Csu6OBYMkTS09oOfO Bo1aLbzPTXHszpk50Kclml26EnskhEWgZczcYbNfdZvZeSbD5wwqcTNfQaK0AimhHY Wk2l3lik6od6g== From: Danilo Krummrich To: gregkh@linuxfoundation.org, rafael@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, 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, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, kwilczynski@kernel.org, bhelgaas@google.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Danilo Krummrich Subject: [PATCH 1/8] rust: device: introduce device::Internal Date: Sat, 21 Jun 2025 21:43:27 +0200 Message-ID: <20250621195118.124245-2-dakr@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250621195118.124245-1-dakr@kernel.org> References: <20250621195118.124245-1-dakr@kernel.org> 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" Introduce an internal device context, which is semantically equivalent to the Core device context, but reserved for bus abstractions. This allows implementing methods for the Device type, which are limited to be used within the core context of bus abstractions, i.e. restrict the availability for drivers. Signed-off-by: Danilo Krummrich --- rust/kernel/device.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index 665f5ceadecc..e9094d8322d5 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -261,6 +261,10 @@ pub trait DeviceContext: private::Sealed {} /// any of the bus callbacks, such as `probe()`. pub struct Core; =20 +/// Semantically the same as [`Core`] but reserved for internal usage of t= he corresponding bus +/// abstraction. +pub struct Internal; + /// The [`Bound`] context is the context of a bus specific device referenc= e when it is guaranteed to /// be bound for the duration of its lifetime. pub struct Bound; @@ -270,11 +274,13 @@ pub trait Sealed {} =20 impl Sealed for super::Bound {} impl Sealed for super::Core {} + impl Sealed for super::Internal {} impl Sealed for super::Normal {} } =20 impl DeviceContext for Bound {} impl DeviceContext for Core {} +impl DeviceContext for Internal {} impl DeviceContext for Normal {} =20 /// # Safety @@ -312,6 +318,13 @@ fn deref(&self) -> &Self::Target { #[macro_export] macro_rules! impl_device_context_deref { (unsafe { $device:ident }) =3D> { + // SAFETY: This macro has the exact same safety requirement as + // `__impl_device_context_deref!`. + ::kernel::__impl_device_context_deref!(unsafe { + $device, + $crate::device::Internal =3D> $crate::device::Core + }); + // SAFETY: This macro has the exact same safety requirement as // `__impl_device_context_deref!`. ::kernel::__impl_device_context_deref!(unsafe { @@ -345,6 +358,7 @@ fn from(dev: &$device<$src>) -> Self { #[macro_export] macro_rules! impl_device_context_into_aref { ($device:tt) =3D> { + ::kernel::__impl_device_context_into_aref!($crate::device::Interna= l, $device); ::kernel::__impl_device_context_into_aref!($crate::device::Core, $= device); ::kernel::__impl_device_context_into_aref!($crate::device::Bound, = $device); }; --=20 2.49.0