From nobody Sun Dec 14 06:34:33 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 9481630F7EE for ; Fri, 12 Dec 2025 23:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765581309; cv=none; b=uw270piJ3icjo6JJtQX1Jgco6DTdl4B77uArriDzs7XJPTJ5atLh6eeIOhg1ok3+Blox1v5AQK/RtBxGiPrkSs2mYcO/ZgAEU8ilgUSECcodCJnAx8/N/w9gBatKO8VzmIIJ0Jp7eu9RdXxnjQ9qyDffJVS49B7pHJfsceD1dLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765581309; c=relaxed/simple; bh=BB+Eg8n+4O9ZedIQbOqF11dMdqp9IJcEk7Jpmsg8upI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oM4asnGMjIVl1l2EzoeSGV1KK4rpCcueSxwYFkJB61YyhJwUEEiKcTwYjdCrmbZ9n8YP6FRrEDW7DVUzVMfKJjSlFviXVhW2PqLu4/z2NAZq4L1Q4llb/Naxau108qEdfy+CuzLX9r7z6UEn8wxQH45XFoAy9thFZfchoXBDgi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=33Yiwnm0; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="33Yiwnm0" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b630b4d8d52so1686652a12.3 for ; Fri, 12 Dec 2025 15:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765581307; x=1766186107; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QX553GJLvlV7oXg2YdBVQASii+8KSTzYKv8qfYedNdg=; b=33Yiwnm0B4RiQF+NObt/L5E0mt1UDf053pxQELsbSSUkkra7tM2db8j/Dzc811hVeh BoY+YlVytfbBRZ1fFDat/NjnD3zEa0UnSX/qSqJz6334AS4cOwsd/+tvWH3SctrcGjAt KIzoVyHZ19IQTFUpauLvQPH96xQdRl8Sl31JfNZIYDQeiQUfVY4KG8uIWNzqtYA9xSPM Y2VfsvBu/PcAvpF+9y0Sd6oyK5NCkaLVI2OTgR1LfAeCwAgv95JqKJXFC0oIseSvG7Dc LwaPv9iPScFdBnu4y5DxLDwjJEUlpmbq6c7xhPFKwZ2hl/CjHB0n1O101xQC45w5lBZI 09FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765581307; x=1766186107; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QX553GJLvlV7oXg2YdBVQASii+8KSTzYKv8qfYedNdg=; b=MpG2ojKYG1864hv2Eyv+C7Z+Bun5PI1oldmsLVnlhvoZJLijfeKITBjSxYWcQtQ5bI /1gpHlkPiCSax5gqJm9FpYfVMMVPn1/KWPnmkFNZMDcQzmTXo1k0YdkLpkNwzXuZvlJC hvuD/+VC3F81jU+TDBJ6l0ZtT5Uk8zy4EJSQj0FbRxmQnwSt9oMIrJq6xhucw48Y308N 7/v1F1radpqHW+pxEe1jcPutkPdsiomfsOb0k2yf+ZhLPcnZ7HpHiPu2QdrztVBJJxXo iq8zDvZVxq238A+motv3UaqycMMx8+bLf9bNR/hcW5F5lmD+m5WZA5RZjhiQWNgn4lh9 1/lQ== X-Gm-Message-State: AOJu0Yz4nTml8MpUNWPVHJrm3unq6OF4iMEUdxU6aVtCmlmjSIX0H5dR GXVlF+V7+P53gHgmrWuVCG+Oz6OA0qWRNvzy5R4jRp8BQofY0g+CG4FaP4TX9UkxHFCQ29tGP3K u4F3fcIELcg== X-Google-Smtp-Source: AGHT+IF9LnQXtjA599msQYqIJ97ArWAA7r5j7LWzMKTbd3Ox6en5Nxc/AEMs8ti50UoeRuf+ObVybQ40bQQq X-Received: from dyaa9.prod.google.com ([2002:a05:693c:40c9:b0:2a6:a19b:9a22]) (user=mmaurer job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:f144:b0:2a4:6a87:7285 with SMTP id 5a478bee46e88-2ac3014dc4fmr2165890eec.39.1765581306758; Fri, 12 Dec 2025 15:15:06 -0800 (PST) Date: Fri, 12 Dec 2025 23:14:55 +0000 In-Reply-To: <20251212-soc-bindings-v1-0-db51044ce805@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251212-soc-bindings-v1-0-db51044ce805@google.com> X-Developer-Key: i=mmaurer@google.com; a=ed25519; pk=2Ezhl7+fEjTOMVFpplDeak2AdQ8cjJieLRVJdNzrW+E= X-Developer-Signature: v=1; a=ed25519-sha256; t=1765581303; l=6876; i=mmaurer@google.com; s=20250429; h=from:subject:message-id; bh=BB+Eg8n+4O9ZedIQbOqF11dMdqp9IJcEk7Jpmsg8upI=; b=lu50R0mQBljHaheW/ktEJbF5o08ArK46LmiiwgMs9soVPjx2r1Bn3bEKoqUT3sLyh+FHzc3Qi EXEZ7lxG9cICNYy/1G5+FWmRMPvPcMw2hjxCpw1Vm7vdHhQn4JiQi8d X-Mailer: b4 0.14.2 Message-ID: <20251212-soc-bindings-v1-1-db51044ce805@google.com> Subject: [PATCH 1/2] rust: Add soc_device support From: Matthew Maurer To: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Matthew Maurer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Adds the ability to register SoC devices. Signed-off-by: Matthew Maurer --- MAINTAINERS | 1 + rust/bindings/bindings_helper.h | 1 + rust/kernel/lib.rs | 2 + rust/kernel/soc.rs | 137 ++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 141 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c5a7cda26c600e49c7ab0d547306d3281333f672..4ff01fb0f1bda27002094113c0b= f9d074d28fdb6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7700,6 +7700,7 @@ F: rust/kernel/devres.rs F: rust/kernel/driver.rs F: rust/kernel/faux.rs F: rust/kernel/platform.rs +F: rust/kernel/soc.rs F: samples/rust/rust_debugfs.rs F: samples/rust/rust_debugfs_scoped.rs F: samples/rust/rust_driver_platform.rs diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index a067038b4b422b4256f4a2b75fe644d47e6e82c8..9fdf76ca630e00715503e2a3a80= 9bedc895697fd 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -80,6 +80,7 @@ #include #include #include +#include #include #include #include diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index f812cf12004286962985a068665443dc22c389a2..6d637e2fed1b605e2dfc2e7b224= 7179439a90ba9 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -138,6 +138,8 @@ pub mod seq_file; pub mod sizes; pub mod slice; +#[cfg(CONFIG_SOC_BUS)] +pub mod soc; mod static_assert; #[doc(hidden)] pub mod std_vendor; diff --git a/rust/kernel/soc.rs b/rust/kernel/soc.rs new file mode 100644 index 0000000000000000000000000000000000000000..b8412751a5ca8839e588cf5bd52= f2e6a7f33d457 --- /dev/null +++ b/rust/kernel/soc.rs @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2025 Google LLC. + +//! SoC Driver Abstraction +//! +//! C header: [`include/linux/sys_soc.h`](srctree/include/linux/sys_soc.h) + +use crate::bindings; +use crate::error; +use crate::prelude::*; +use crate::str::CString; +use core::marker::PhantomPinned; +use core::ptr::addr_of; + +/// Attributes for a SoC device +pub struct DeviceAttribute { + /// Machine + pub machine: Option, + /// Family + pub family: Option, + /// Revision + pub revision: Option, + /// Serial Number + pub serial_number: Option, + /// SoC ID + pub soc_id: Option, +} + +// SAFETY: We provide no operations through `&BuiltDeviceAttribute` +unsafe impl Sync for BuiltDeviceAttribute {} + +// SAFETY: All pointers are normal allocations, not thread-specific +unsafe impl Send for BuiltDeviceAttribute {} + +#[pin_data] +struct BuiltDeviceAttribute { + #[pin] + backing: DeviceAttribute, + inner: bindings::soc_device_attribute, + // Since `inner` has pointers to `backing`, we are !Unpin + #[pin] + _pin: PhantomPinned, +} + +fn cstring_to_c(mcs: &Option) -> *const kernel::ffi::c_char { + mcs.as_ref() + .map(|cs| cs.as_char_ptr()) + .unwrap_or(core::ptr::null()) +} + +impl BuiltDeviceAttribute { + fn as_mut_ptr(&self) -> *mut bindings::soc_device_attribute { + core::ptr::from_ref(&self.inner).cast_mut() + } +} + +impl DeviceAttribute { + fn build(self) -> impl PinInit { + pin_init!(BuiltDeviceAttribute { + inner: bindings::soc_device_attribute { + machine: cstring_to_c(&self.machine), + family: cstring_to_c(&self.family), + revision: cstring_to_c(&self.revision), + serial_number: cstring_to_c(&self.serial_number), + soc_id: cstring_to_c(&self.soc_id), + data: core::ptr::null(), + custom_attr_group: core::ptr::null(), + }, + backing: self, + _pin: PhantomPinned, + }) + } +} + +// SAFETY: We provide no operations through &Device +unsafe impl Sync for Device {} + +// SAFETY: Device holds a pointer to a `soc_device`, which may be sent to = any thread. +unsafe impl Send for Device {} + +/// A registered soc device +#[repr(transparent)] +pub struct Device(*mut bindings::soc_device); + +impl Device { + /// # Safety + /// * `attr` must be pinned + /// * `attr` must be valid for reads during the function call + /// * If a device is returned (e.g. no error), `attr` must remain vali= d for reads until the + /// returned `Device` is dropped. + unsafe fn register(attr: *const BuiltDeviceAttribute) -> Result { + let raw_soc =3D + // SAFETY: The struct provided through attr is backed by pinne= d data next to it, so as + // long as attr lives, the strings pointed to by the struct wi= ll too. By caller + // invariant, `attr` is pinned, so the pinned data won't move.= By caller invariant, + // `attr` is valid during this call. If it returns a device, a= nd so others may try to + // read this data, by caller invariant, `attr` won't be releas= ed until the device is. + error::from_err_ptr(unsafe { bindings::soc_device_register((*a= ttr).as_mut_ptr()) })?; + Ok(Device(raw_soc)) + } +} + +#[pin_data(PinnedDrop)] +/// Registration handle for your soc_dev. If you let it go out of scope, y= our soc_dev will be +/// unregistered. +pub struct DeviceRegistration { + #[pin] + attr: BuiltDeviceAttribute, + soc_dev: Device, + // Since Device transitively points to the contents of attr, we are !U= npin + #[pin] + _pin: PhantomPinned, +} + +#[pinned_drop] +impl PinnedDrop for DeviceRegistration { + fn drop(self: Pin<&mut Self>) { + // SAFETY: Device always contains a live pointer to a soc_device t= hat can be unregistered + unsafe { bindings::soc_device_unregister(self.soc_dev.0) } + } +} + +impl DeviceRegistration { + /// Register a new SoC device + pub fn register(attr: DeviceAttribute) -> impl PinInit { + try_pin_init!(&this in Self { + attr <- attr.build(), + // SAFETY: We have already initialized attr, and we ar= e inside PinInit and Self + // is !Unpin, so attr won't be moved and is valid. If = it returns success, attr + // will not be dropped until after our `PinnedDrop` im= plementation runs, so the + // device will be unregistered first. + soc_dev: unsafe { Device::register(addr_of!((*this.as_= ptr()).attr))? }, + _pin: PhantomPinned, + }? Error) + } +} --=20 2.52.0.305.g3fc767764a-goog From nobody Sun Dec 14 06:34:33 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 4BC162D2488 for ; Fri, 12 Dec 2025 23:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765581312; cv=none; b=ZG2IqMwMmdzuWQnaYu4iFZMGrrgOvkIRqefK4XroeHcWjZOOWirDjXtG0G0KdYruAX6ORSh7Z3YuVQ4G7SYkIU90PjDIUmVHnugPj6PzPjQEpTCJeOaOmh0T1qtOVe2GUky8PWlsqOjfRWD2gdPBJvNLPu06dnfUphxuHJg0FSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765581312; c=relaxed/simple; bh=AQz7A04h1bgLBtHKWjo2r4fkCOjEQnkQFoWC2phwYWs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RamF9UGycYhkUTPKL/5Kaltlm0uYvEQmKLsycvBXupDoMlGbSlB21WGXa6keVL5fpEfVysQ8Uu+asnH2t3S6tH3zvn6kNpS8fv5YRpRbBQhIKnp2zjmhRLhqW0h6V0nTjenRacVBOPYLZHx68GaPeSLqOpZOjZz28Wyjtvy6p70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=anv04UdF; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="anv04UdF" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b99f6516262so3728444a12.3 for ; Fri, 12 Dec 2025 15:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765581309; x=1766186109; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ITRsrBfFLPXeEMYmsYqDsrHYJ78/qjByazuVizcrhmQ=; b=anv04UdF3RnaU7LmoM7Ascnd3l4FKSS2zclh+c9eAiAxThslrAbowz8fjxbPQGrGSl V5Z965bjIK/R3C1EsHz7YT6hDuIxhLOTj6LWtFTvLnMiy6+BdgkjUJFY9jnzgITEnLrP b8Mmx8acj2Ey4WgjKu3GZNpP+dL7lOYCQ6G5tc2tRimffRsrHBl6OEFZhYZSgAlSUkCJ ryZGR2Nr+t5ZeXUpe4mhxaG7pW1MhnngXpXtZ3bzXA0kIzZKsOw+MXZCnE1TNl1SzRFu GMxpPTWwnWi35/qi5PJftm3pzMx6a2UzGrrtizRPJhbBSMzHuXb9wJ0OzAdw7l2sUYXq gDew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765581309; x=1766186109; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ITRsrBfFLPXeEMYmsYqDsrHYJ78/qjByazuVizcrhmQ=; b=mjrp2QBVDHtsjp6aKtlRAwp5EpsajipwVsTqm+qcPgFMr57/shXP4TxtJQ3nkfh67j 2DXq8z5PR2OpNBQK99p5nXv2eGZLfWe9WnSoZA2MiVx28XJ8ATxyU+lzbCJ6iPpUxdAO EM8SvHYrPdwITS5zfXjc1bE5zeDKWsPUhUtdtEnlgQu7pMx4TUkMduViyOD1aTio7fTb U1ZSAYjcBKmvSANvqggX2vxoICMOkvjuYrHucja2X1tO32/AwBxHu2CWbD3FLZPPFOxZ R3M2MsHiq/3vK7IH7kLaJf5wGVeuqHFpY5zTBA6aYgidn0OKAsDrrbWHYOjLmjabYuyC FL2g== X-Gm-Message-State: AOJu0YzKzjhPE8r195Vz75GCPTokiQHn4Ry2CYAy3gE56ZpJUVvYOQQl Oq+fcOWRA7+2G58IzhYXTEuuhGSScVqW922/Cr4ZPIJZNrMJcGs6cifK2nLXUcjbMsbEeNgC2aI NAmmUNmf8Bg== X-Google-Smtp-Source: AGHT+IH2FAFHDmZscleFJuxwBaCJeQNIlsiysJoXrY1tEUcgzyr/DK3TBhmPpSnM5HkhHW1QyNBRhdP0yIGJ X-Received: from dybcq12.prod.google.com ([2002:a05:7300:a10c:b0:2a4:6577:68f1]) (user=mmaurer job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:7b07:b0:2a4:3592:cf60 with SMTP id 5a478bee46e88-2ac3018c36bmr2323371eec.4.1765581309423; Fri, 12 Dec 2025 15:15:09 -0800 (PST) Date: Fri, 12 Dec 2025 23:14:56 +0000 In-Reply-To: <20251212-soc-bindings-v1-0-db51044ce805@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251212-soc-bindings-v1-0-db51044ce805@google.com> X-Developer-Key: i=mmaurer@google.com; a=ed25519; pk=2Ezhl7+fEjTOMVFpplDeak2AdQ8cjJieLRVJdNzrW+E= X-Developer-Signature: v=1; a=ed25519-sha256; t=1765581303; l=4640; i=mmaurer@google.com; s=20250429; h=from:subject:message-id; bh=AQz7A04h1bgLBtHKWjo2r4fkCOjEQnkQFoWC2phwYWs=; b=35cWEktAnNrcaDwjo6AUDaAdjvcnCNtHIsKKlB3IxUTeLWsyDmnQjx/zfUQZjy9OS3MCZpPe4 fz3KpgonsEEC/N1R1xwNHDIgwKPLTAvacYJof1wkjzSzALJvAQV3qch X-Mailer: b4 0.14.2 Message-ID: <20251212-soc-bindings-v1-2-db51044ce805@google.com> Subject: [PATCH 2/2] rust: Add SoC Driver Sample From: Matthew Maurer To: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Matthew Maurer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Shows registration of a SoC device upon receipt of a probe. Signed-off-by: Matthew Maurer --- MAINTAINERS | 1 + samples/rust/Kconfig | 11 +++++++ samples/rust/Makefile | 1 + samples/rust/rust_soc.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 87 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 4ff01fb0f1bda27002094113c0bf9d074d28fdb6..bb2e710277cc84dd6042d4d4607= 6e665d9f68752 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7705,6 +7705,7 @@ F: samples/rust/rust_debugfs.rs F: samples/rust/rust_debugfs_scoped.rs F: samples/rust/rust_driver_platform.rs F: samples/rust/rust_driver_faux.rs +F: samples/rust/rust_soc.rs =20 DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS) M: Nishanth Menon diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index 3efa51bfc8efccd91d9ee079ccd078ed1a6e8aa7..c49ab910634596aea4a1a73dac8= 7585e084f420a 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -161,6 +161,17 @@ config SAMPLE_RUST_DRIVER_AUXILIARY =20 If unsure, say N. =20 +config SAMPLE_RUST_SOC + tristate "SoC Driver" + select SOC_BUS + help + This option builds the Rust SoC driver sample. + + To compile this as a module, choose M here: + the module will be called rust_soc. + + If unsure, say N. + config SAMPLE_RUST_HOSTPROGS bool "Host programs" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index f65885d1d62bf406b0db13121ef3e5b09829cfbc..6c0aaa58ccccfd12ef019f68ca7= 84f6d977bc668 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB) +=3D rust_driver_us= b.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) +=3D rust_driver_faux.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY) +=3D rust_driver_auxiliary.o obj-$(CONFIG_SAMPLE_RUST_CONFIGFS) +=3D rust_configfs.o +obj-$(CONFIG_SAMPLE_RUST_SOC) +=3D rust_soc.o =20 rust_print-y :=3D rust_print_main.o rust_print_events.o =20 diff --git a/samples/rust/rust_soc.rs b/samples/rust/rust_soc.rs new file mode 100644 index 0000000000000000000000000000000000000000..ca0294819f100fa7b713c6b41c5= b8a9b3906b863 --- /dev/null +++ b/samples/rust/rust_soc.rs @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust SoC Platform driver sample. + +use kernel::{ + acpi, c_str, device::Core, of, platform, prelude::*, soc, str::CString= , sync::aref::ARef, +}; +use pin_init::pin_init_scope; + +#[pin_data] +struct SampleSocDriver { + pdev: ARef, + #[pin] + _dev_reg: soc::DeviceRegistration, +} + +kernel::of_device_table!( + OF_TABLE, + MODULE_OF_TABLE, + ::IdInfo, + [(of::DeviceId::new(c_str!("test,rust-device")), ())] +); + +kernel::acpi_device_table!( + ACPI_TABLE, + MODULE_ACPI_TABLE, + ::IdInfo, + [(acpi::DeviceId::new(c_str!("LNUXBEEF")), ())] +); + +impl platform::Driver for SampleSocDriver { + type IdInfo =3D (); + const OF_ID_TABLE: Option> =3D Some(&OF_TABL= E); + const ACPI_ID_TABLE: Option> =3D Some(&ACP= I_TABLE); + + fn probe( + pdev: &platform::Device, + _info: Option<&Self::IdInfo>, + ) -> impl PinInit { + let dev =3D pdev.as_ref(); + + dev_dbg!(dev, "Probe Rust SoC driver sample.\n"); + + let pdev =3D pdev.into(); + pin_init_scope(move || { + let machine =3D CString::try_from(c_str!("Rust Machine"))?; + let family =3D CString::try_from(c_str!("Rust Family"))?; + let revision =3D CString::try_from(c_str!("Rust Revision"))?; + let serial_number =3D CString::try_from(c_str!("Rust Serial Nu= mber"))?; + let soc_id =3D CString::try_from(c_str!("Rust SoC ID"))?; + + let attr =3D soc::DeviceAttribute { + machine: Some(machine), + family: Some(family), + revision: Some(revision), + serial_number: Some(serial_number), + soc_id: Some(soc_id), + }; + + Ok(try_pin_init!(SampleSocDriver { + pdev: pdev, + _dev_reg <- soc::DeviceRegistration::register(attr), + }? Error)) + }) + } +} + +kernel::module_platform_driver! { + type: SampleSocDriver, + name: "rust_soc", + authors: ["Matthew Maurer"], + description: "Rust SoC Driver", + license: "GPL", +} --=20 2.52.0.305.g3fc767764a-goog