From nobody Thu Dec 18 01:00:21 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 7FCF5258ED4 for ; Tue, 16 Dec 2025 00:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845822; cv=none; b=dx5O+ASVFrMeEdQCd4/jQn0WR82yt1310NWVQbugRafDKJb+W2buEKp7ui8LcXnq884a+qPOZ05XToGgZJvod9bxRAljfxiYMC6xAvt3nNEq0aAxjzis77ubpAJsuJhEWsVJ1Y72WVztJibhXPPZJIPS8GETaQHdQrliLBUcJgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845822; c=relaxed/simple; bh=fu4NDhxTN0vEcpv4FNXIV3vduXqLV7V5Xq8C3/HVXxc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Yn9P5GcFTCUwLglxgHVRW+COHPGKfJvyfGqi9ETM9XZ2K+4y5+9RiOlL6D7gj4JVvUAU7aoktD4cUOR2ocwqeXcTapLh8eL+IAx5hXLHrP4qspE388F+0fBkHGknsxs2d8oJm37WXvQe9AFpGbg7ubmq1xIjB8in0Vw9oJFtsJU= 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=aqf3zzpD; arc=none smtp.client-ip=209.85.215.201 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="aqf3zzpD" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b993eb2701bso3944821a12.0 for ; Mon, 15 Dec 2025 16:43:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765845820; x=1766450620; 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=n7LDngOMTvVQIllzb2Fwg2WMN04+Td6gaOqvNXOfbNU=; b=aqf3zzpDJCnN5iHxg5DeNMuuu9Bsei5/Kek0jy/zhChLQ1r1W7U6ldlB4Mq5IyhO3T 7JvbxNpWoVir3h5I/szlpDa4EoFm+gsGMYX0ka3JSB1j2lEmWI4H0MRYF5ueeqSWJTNU izqfliG0dyok58Cb/W159cQ4RArAHTMx7yQs08uNYTrb7GxMkdwn9x900y8MzNTATJxC nHdz+e3s4ZcaCIM+UjUc0uR3DfM1J8vwvLSfI0/NFC2M4PP3a1qPKsSoLvq1jPyeRwxm z+5ZIoLFMZEcykKiywgsKaE654JTIQbeGD3OaX6zDcajme4xt2W3RiSLkfkcL6EDgshK lqTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765845820; x=1766450620; 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=n7LDngOMTvVQIllzb2Fwg2WMN04+Td6gaOqvNXOfbNU=; b=ObLrcsQAGip55PdVpLhPti5baQhJ4AWuf5q6zoWmPAvn7wIwG0zkqEVn8Nu+aYFt7q jBaElAGORjmk9Gad0duQIT7m+7ww6mzG4K5JVKsdTeOjwwgQ9VojBy5dJ5vpbBUiFHkA YNL7qTx4H5mR50cL9D4KTxaXMR6tuDXqi1dICZQlgUt1RzYg0DZRCcoVg1CacZcd1fjy 2Yuh84cr2uI1YdNe1FEuBLfDBoHNXSZOsg7B91vgN18+hAW+7SPAiiyH1Vyk7X8T1nc1 ufAEfp3hcH+A0fhUNKoQkaCkHoQklZMmWOcXB3dvRqTmxD30UxXkR1IrnjyRXgG91DZf N+Hw== X-Gm-Message-State: AOJu0YxFG7h9IiMHXNWxXRneSYV2g4HXH4jvfQDL4FIunzz6Gj5njvma 2zgb6HQTb84364sVnZv+8zhAT/Z0NNMlYB3BVBZLs4gRMhSB8XTcPj2ZXjaCRFtvp6Gba1baoVG muWe9ud8RVg== X-Google-Smtp-Source: AGHT+IEpgLt2AHjnwwfV2EWOp+RGMgpkUD4QhWBb/tMFYvedkswQ0oBcRzRIkrA2/wTbNRjig8jxQfCBz+kp X-Received: from dybnz37.prod.google.com ([2002:a05:7300:e8a5:b0:2ab:9468:d9cf]) (user=mmaurer job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:2524:b0:2a6:a099:b8de with SMTP id 5a478bee46e88-2ac303c91bfmr5786752eec.30.1765845819697; Mon, 15 Dec 2025 16:43:39 -0800 (PST) Date: Tue, 16 Dec 2025 00:43:33 +0000 In-Reply-To: <20251216-soc-bindings-v2-0-1fb394cc921a@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251216-soc-bindings-v2-0-1fb394cc921a@google.com> X-Developer-Key: i=mmaurer@google.com; a=ed25519; pk=2Ezhl7+fEjTOMVFpplDeak2AdQ8cjJieLRVJdNzrW+E= X-Developer-Signature: v=1; a=ed25519-sha256; t=1765845816; l=8357; i=mmaurer@google.com; s=20250429; h=from:subject:message-id; bh=fu4NDhxTN0vEcpv4FNXIV3vduXqLV7V5Xq8C3/HVXxc=; b=I2UkfhO4bT9fSFWXABdqRNjvZBD7KaRjfJ4AnFifEtl8bQkkPYKH5W4/1JGapK84qibS2NTzj 0Uq/nvLWI72BQMrJawkD7iJQRCfNWEtz6hCcx3fFwrBTcasqWhypQWT X-Mailer: b4 0.14.2 Message-ID: <20251216-soc-bindings-v2-1-1fb394cc921a@google.com> Subject: [PATCH v2 1/3] 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 Allow SoC drivers in Rust to present metadata about their devices to userspace through /sys/devices/socX and other drivers to identify their properties through `soc_device_match`. Signed-off-by: Matthew Maurer --- MAINTAINERS | 1 + rust/bindings/bindings_helper.h | 1 + rust/kernel/lib.rs | 2 + rust/kernel/soc.rs | 145 ++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 149 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..fb9e461218787b5546805c0f04f= adbc5e3e054a6 --- /dev/null +++ b/rust/kernel/soc.rs @@ -0,0 +1,145 @@ +// 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, + error, + prelude::*, + str::CString, + types::Opaque, // +}; +use core::ptr::NonNull; + +/// Attributes for a SoC device. +/// +/// These are both exported to userspace under /sys/devices/socX and provi= ded to other drivers to +/// match against via `soc_device_match` (not yet available in Rust) to en= able quirks or +/// device-specific support where necessary. +/// +/// All fields are freeform - they have no specific formatting, just defin= ed meanings. +/// For example, the [`machine`](`Attributes::machine`) field could be "DB= 8500" or +/// "Qualcomm Technologies, Inc. SM8560 HDK", but regardless it should ide= ntify a board or product. +pub struct Attributes { + /// Should generally be a board ID or product ID. Examples + /// include DB8500 (ST-Ericsson) or "Qualcomm Technologies, inc. SM856= 0 HDK". + /// + /// If this field is not populated, the SoC infrastructure will try to= populate it from + /// `/model` in the device tree. + pub machine: Option, + /// The broader class this SoC belongs to. Examples include ux500 + /// (for DB8500) or Snapdragon (for SM8650). + /// + /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a J= EDEC JEP106 manufacturer + /// identification. + pub family: Option, + /// The manufacturing revision of the part. Frequently this is MAJOR.M= INOR, but not always. + pub revision: Option, + /// Serial Number - uniquely identifies a specific SoC. If present, sh= ould be unique (buying a + /// replacement part should change it if present). This field cannot b= e matched on and is + /// solely present to export through /sys. + pub serial_number: Option, + /// SoC ID - identifies a specific SoC kind in question, sometimes mor= e specifically than + /// `machine` if the same SoC is used in multiple products. Some devic= es use this to specify a + /// SoC name, e.g. "I.MX??", and others just print an ID number (e.g. = Tegra and Qualcomm). + /// + /// On chips with ARM firmware supporting SMCCC v1.2+, this may be a J= EDEC JEP106 manufacturer + /// identification (the family value) followed by a colon and then a 4= -digit ID value. + pub soc_id: Option, +} + +struct BuiltAttributes { + // While `inner` has pointers to `_backing`, it is to the interior of = the `CStrings`, not + // `backing` itself, so it does not need to be pinned. + _backing: Attributes, + // `Opaque` makes us `!Unpin`, as the registration holds a pointer to = `inner` when used. + inner: Opaque, +} + +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 BuiltAttributes { + fn as_mut_ptr(&self) -> *mut bindings::soc_device_attribute { + self.inner.get() + } +} + +impl Attributes { + fn build(self) -> BuiltAttributes { + BuiltAttributes { + inner: Opaque::new(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, + } + } +} + +/// # Safety +/// If a device is returned (e.g. no error), `attr` must remain valid for = reads until the +/// returned pointer is released through `soc_device_unregister`. +unsafe fn register_device(attr: Pin<&BuiltAttributes>) -> Result> { + let raw_soc =3D + // SAFETY: + // * The struct provided through attr is backed by pinned data= next to it, so as + // long as attr lives, the strings pointed to by the struct = will too. + // * `attr` is pinned, so the pinned data won't move. + // * If it returns a device, and so others may try to read thi= s data, by caller + // invariant, `attr` won't be released until the device is. + error::from_err_ptr(unsafe { bindings::soc_device_register(att= r.as_mut_ptr()) })?; + // `soc_device_register` should not return NULL, but it doesn't hurt t= o be paranoid. + NonNull::new(raw_soc).ok_or(EINVAL) +} + +#[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 Registration { + #[pin] + attr: BuiltAttributes, + soc_dev: NonNull, +} + +// SAFETY: We provide no operations through `&Registration`. +unsafe impl Sync for Registration {} + +// SAFETY: All pointers are normal allocations, not thread-specific. +unsafe impl Send for Registration {} + +#[pinned_drop] +impl PinnedDrop for Registration { + 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.as_ptr()) } + } +} + +impl Registration { + /// Register a new SoC device + pub fn register(attr: Attributes) -> 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 { + register_device(Pin::new_unchecked(&(*this.as_ptr(= )).attr))? + }, + }? Error) + } +} --=20 2.52.0.305.g3fc767764a-goog From nobody Thu Dec 18 01:00:21 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 2759226E708 for ; Tue, 16 Dec 2025 00:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845823; cv=none; b=G6jv3Cws0KjlIUdTo/dKb/bZIcJ9saNWvSSn9zMzWhZQzjxZL1Vbwta0B4XTZZMoGNrlnFDYcR9oYPFWjfH6RUYDlZi04OIn37ZRPGpSzq2zitFn7r5yCT0pB9fZeuyOJi/p6fkoQ5iYRC159EYGUV851jRbZ4XSbEWDttboXUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845823; c=relaxed/simple; bh=CVSJi029GHHHhn/9XoqWc3ttenxPMOVdAkj46I9t8q4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GWKjgJqfACHnC4LS6L1LG1U+fyeymT8klib19z3ulH8bbV5jAvqUO7eWYQmOfB0OcfXFvul98a72cSSXZ/Q3LghybwDGhWbavqvY2/DB2Je2NKLZNbaHceQnRiFfU2XLvLmpFuOauT/RMkINJ4x2cipsSeXwBLiA6ALnKQ17maU= 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=hK2EtDOr; arc=none smtp.client-ip=209.85.215.201 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="hK2EtDOr" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-bdf47c10220so7181274a12.3 for ; Mon, 15 Dec 2025 16:43:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765845821; x=1766450621; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=K64SM0RdH6aTuScbaCI3LTVobbk/h/tZc4xxokx/oAI=; b=hK2EtDOri1Zzq5yW2WVlZElKGBUnKgYXgvyt3peMuawu4wHTV1XGduB6K9rqj4BOAJ mAkPXna4bPnebxfydv8G6lFfrijRk2pSR7jK5L4RFKXyeHrrOJXJRfdLgWmnxx7w3hPf W3uaikl52UZ1/OUoa/BCHh6l+FsQj6E6v/TGmtmAhd0FJpAkDJOCKf01FAD8w79L5Qx6 KoS/Cm0vUGAI4aTdFGoHzzbYVPZcZ6ZlsEhjhO8dkYMPKe2NXQ5ugp9lgru+kJmhpKXH gyLTHpTOe7ZewUpdB1ne92Hr3S0xUY7XTAWzqoWdzmmbz+xG7UcUPOLf3SXfQTASyE+N lRRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765845821; x=1766450621; h=content-transfer-encoding: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=K64SM0RdH6aTuScbaCI3LTVobbk/h/tZc4xxokx/oAI=; b=kj6RQY66z1TkTWy5hI88bb4rD1m4nM5IwCuxeazXN5cXJ53ui+2n8f5pndYGBi4Zgn jN29H3F3PpgPq5LuBqYsbjAQADwxdcJwk2ni03wE+D2cn2SffJu42esiCf3RwvVj0TB1 DVCh8SYt52irPbmFDwm6oTDMFxB3fxeey5eYK274308SMcCV8y1mrU5aEjRKk5NUoDzM SingbBP9l5ivjb81gH3wVzbCysVGBSHCX83Vz3fQePWZunbc/NoC2unr8tlH/i2FGBdU HkCK+E6uk93TT1eTsIMpz11OZlV6x+PmxvdL8/Nl7yhx8gHzOErfDIhi5/B0xZ8wyRzC X3zw== X-Gm-Message-State: AOJu0YxRjl3JH2E5tP8CDNbLJtyW2//yJHum5eGUA6RYEQZOioFlvBAH r1E5zoZgdxYVDQemw+ifXt4Jx+PsD/CNeps25K6OeyKlqYFsi+P82DmA+rJMIMpgcS18t4LO/Ju INDrNQL5cyA== X-Google-Smtp-Source: AGHT+IGy7t2xxDrYvztIPhA1LeA7jj9Vcs8MdVuvRdWzB1+Byz/o3bEuXDfRNqZ4LeILsk2gh3AYrKc33dom X-Received: from dycph12.prod.google.com ([2002:a05:7300:dd4c:b0:2ae:372e:7e0c]) (user=mmaurer job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:1a07:b0:2a4:3594:d534 with SMTP id 5a478bee46e88-2ac2f86ffd5mr7676055eec.1.1765845821383; Mon, 15 Dec 2025 16:43:41 -0800 (PST) Date: Tue, 16 Dec 2025 00:43:34 +0000 In-Reply-To: <20251216-soc-bindings-v2-0-1fb394cc921a@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251216-soc-bindings-v2-0-1fb394cc921a@google.com> X-Developer-Key: i=mmaurer@google.com; a=ed25519; pk=2Ezhl7+fEjTOMVFpplDeak2AdQ8cjJieLRVJdNzrW+E= X-Developer-Signature: v=1; a=ed25519-sha256; t=1765845816; l=1220; i=mmaurer@google.com; s=20250429; h=from:subject:message-id; bh=Yq/lFcGTJAMxEgocC5K0vXqMYuCjGCsnZPv9LMzzDas=; b=/Y/ERfm2esLl9qZGHIMpak+FwybekPX2wT3RqJ2fYPhM0VMI1OTmhaOuytw0YNvhxHtgLEfMK 5jA525oguWVDm7PLD8XYeGs4Imnxi+wVyFLkHI3PrsAm4K5Y7V5XeKg X-Mailer: b4 0.14.2 Message-ID: <20251216-soc-bindings-v2-2-1fb394cc921a@google.com> Subject: [PATCH v2 2/3] docs: ABI: sysfs-devices-soc: Fix swapped sample values 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 , Lee Jones Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The sample values for `family` and `machine` were swapped relative to what the driver actually does, and doesn't match the field description. Signed-off-by: Matthew Maurer Reviewed-by: Lee Jones --- Documentation/ABI/testing/sysfs-devices-soc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-devices-soc b/Documentation/AB= I/testing/sysfs-devices-soc index 5269808ec35f8e2b18516556f886c77f5fac9401..cb6776a4afe02a76fe27ac6fc23= 6babdc7865287 100644 --- a/Documentation/ABI/testing/sysfs-devices-soc +++ b/Documentation/ABI/testing/sysfs-devices-soc @@ -17,14 +17,14 @@ Date: January 2012 contact: Lee Jones Description: Read-only attribute common to all SoCs. Contains the SoC machine - name (e.g. Ux500). + name (e.g. DB8500). =20 What: /sys/devices/socX/family Date: January 2012 contact: Lee Jones Description: Read-only attribute common to all SoCs. Contains SoC family name - (e.g. DB8500). + (e.g. ux500). =20 On many of ARM based silicon with SMCCC v1.2+ compliant firmware this will contain the JEDEC JEP106 manufacturer=E2=80=99s identification --=20 2.52.0.305.g3fc767764a-goog From nobody Thu Dec 18 01:00:21 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 C201426462E for ; Tue, 16 Dec 2025 00:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845826; cv=none; b=Kwi+aAeB2+dFrKqV0cb/m+NJ5UCu8ISTlTxkO9m282plbmg7+S92BegSTGueXUPTidCPb26ba8ctjJZArSF9N3s9K0Cfhfp/RtPp3t2sM+BJBEwW1hJEIB89/xAIFJlEudlAZx+F4A7aMxKDfnESzIKB0Pmi0NHLdwwKmUoPIdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845826; c=relaxed/simple; bh=dlSPSXUUuZTBuEOMuLNhyCqtNK/4BnjWXzaGUCDWza8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jWFbyRWs+3mqrbF5CriDVn91fySSSyL9PPFYj3Dbd08//QGroUeDwYu0zP/Yz75UWlpq/x9a//w+0yi79mkPhEkM0sAk3b5zblxb9jpoR8Fj7pwBvrW6eVLqyQLoIfLOBV16G7e5IKdWO1cwbtaS4qFkH3ERnjHNdz372IhNLj8= 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=Vb6gezk2; arc=none smtp.client-ip=209.85.215.201 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="Vb6gezk2" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b62da7602a0so4306800a12.2 for ; Mon, 15 Dec 2025 16:43:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765845823; x=1766450623; 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=2Olua55894s+jmELlwPHr+E0dxrcMSc3VbYbbTrCR7w=; b=Vb6gezk2rGCiMrcofRtx8XZdOC4vTwivv654yxjYZEE5JUSLq7dB2C5q/8FlnZyS8e uuZ0WJjlKExOl3ZZ+bcrU/YAgPmlc8CDqlcqmOUxG5Xz7TiOI6aMqblkcMmJnDYwVmWE 2gmKFgAIrXuJtI6mbvQ9LFa7z6Vp3/oK+TwV2Lq208fQMAswqjrafgV8o4PPSfQeU5VZ 5NvPiQwIlWR80KJX06KpSnWZFFEb1fUiLjfgDS5CGmO7hkLkqkGQ9oXBi1TFMXwQtAhj fiExBXgbtWlFWDX8HoGaXjENGb9Qa8BF1pu/dUsMoS5ec9Tjzgl/EsMkI0xVbT/L17AL cbbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765845823; x=1766450623; 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=2Olua55894s+jmELlwPHr+E0dxrcMSc3VbYbbTrCR7w=; b=TH6btwuENLxCr+dJYX9i4Kd6mZ+NaKMnQrkazSrrxtyaRRByOTaVVOEN3fYZuEDwIw jvYSMevVQ8nl7MXjt8sH3fm4fQ+RKvTaIfeTk3ok+UwrzwUR6T/nTIyaGX4mmFSPVgTk w1zvh6wSv1s0lNOMdWMWuFvw07Vp5/R2XEbanS26I7XpTt4S9GAFBBVoyb/XAsx83t8d RSXTwokFQ7Ki+fnCbuw9AbWo7GpBN8sZDjR6COCOmFLxgJ1LqtGb7rhlxOcpsjoPXoH/ V+YP4NC3Ht3gHNTNEGPfd+CkMys9afgADtYJ1rPDyvnCYchWfv7X8eUUCKjpEJl/nvkK 8JEA== X-Gm-Message-State: AOJu0YypTgRYSBeI2KkeE+xVH0EOHnwSprNqTtIFzrPboDqe5+niCmWq 4E7ceGeDky4kAGY7K/UtUX0y78KRE9fNEjMTh5tApAyDYP8JlksdKP9yb0J2Fr9urMBaBKtUXCe ImQrDUnLXbQ== X-Google-Smtp-Source: AGHT+IH+ymPrOT1h5JIPRnSJM5lyJ2b9Fm0qR4sSOUJjyf+BigLD0Z1ajkarMPK8rLvZk6Ef4dWCViCHuGcg X-Received: from dyz27.prod.google.com ([2002:a05:693c:409b:b0:2a4:6b08:61f1]) (user=mmaurer job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:d108:b0:2ac:1caa:8705 with SMTP id 5a478bee46e88-2ac3012bc6emr7751641eec.36.1765845822958; Mon, 15 Dec 2025 16:43:42 -0800 (PST) Date: Tue, 16 Dec 2025 00:43:35 +0000 In-Reply-To: <20251216-soc-bindings-v2-0-1fb394cc921a@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251216-soc-bindings-v2-0-1fb394cc921a@google.com> X-Developer-Key: i=mmaurer@google.com; a=ed25519; pk=2Ezhl7+fEjTOMVFpplDeak2AdQ8cjJieLRVJdNzrW+E= X-Developer-Signature: v=1; a=ed25519-sha256; t=1765845816; l=4651; i=mmaurer@google.com; s=20250429; h=from:subject:message-id; bh=dlSPSXUUuZTBuEOMuLNhyCqtNK/4BnjWXzaGUCDWza8=; b=94gYXanIz0Zch8KbyTo4cc5XHwovDBPm6fGGq1FyhXmwL66sdRQgeLtidpSlqL2Np/Uscp849 /jPSboPOaGmDtX66/0Tw6Oci6/XPIzDVM8jvPCl9CVwkuwqBwpodxYV X-Mailer: b4 0.14.2 Message-ID: <20251216-soc-bindings-v2-3-1fb394cc921a@google.com> Subject: [PATCH v2 3/3] 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 | 82 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 95 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..696c38a2ac9d030a7dc8928fd3e= f4cafc0d6ace2 --- /dev/null +++ b/samples/rust/rust_soc.rs @@ -0,0 +1,82 @@ +// 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::Registration, +} + +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!("My cool ACME15 dev b= oard"))?; + let family =3D CString::try_from(c_str!("ACME"))?; + let revision =3D CString::try_from(c_str!("1.2"))?; + let serial_number =3D CString::try_from(c_str!("12345"))?; + let soc_id =3D CString::try_from(c_str!("ACME15"))?; + + let attr =3D soc::Attributes { + 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::Registration::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