From nobody Mon Dec 15 21:20:08 2025 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 7D1C523ED50 for ; Mon, 13 Jan 2025 11:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736767442; cv=none; b=NORBS5Xkw8kZZr0jP3DkKBhjlVuih5eQ0SefB+aCtwXT/w/C7iXPPzQMnwpVMLIcvdqIHwzSesSmMTc9PEcFd6ofKH2EbJCFTv7BTX8TT0vNPr0y7ygqlCGXEf16y9yCIBtILtbIUpv252F9BCP5KXlXuQkM+j42rMaKOP77Y9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736767442; c=relaxed/simple; bh=XP0PNO8G/853ZISR4NFJL60BlTm8G/dA7ahDgJPTbK0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SescKbGK7b0N4gQNeegZKJPuhn1T6NNfn8xgHV5y2KPVQKIl+tuYGBFw3Aiy7M8K8Rnct0/nOcioJS2NLWi9XksiheYA81ab6HqbMH0tkPBA18wtuXW6ZLz8JL0E6khIBJJJbaXHhI4l9+aacBJ1Y1X6gdmcXJ2HhRKLrkkhYjo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=pvJ/aNJN; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pvJ/aNJN" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ef6c56032eso5201335a91.2 for ; Mon, 13 Jan 2025 03:24:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736767440; x=1737372240; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=217qCdop/bVuj9XoV8EFEQ4K3BvCuSwvnN0rQfYprBA=; b=pvJ/aNJNM6hWazWxuQNk18EMYgd+DQl6rWe8maE2K6y694RoJQJS3Fw2E48J+Vh/8r 7FfGwN/ihgaV1QDaWWfp+kMOUB29dLZX0DnhwbE79I/jZUIWGyErGh5FXeoGApDnPdZK O8cWXyg838GYNaC2dHu0U0Z5FfOBlS/tWOHnmZJ2ldP+p+/+++J+rreaFfg6ttqEG/OD WTvlVw9BlK0UbpDXoY8vj7qWhMZwwzHLiU2c566Q+NBo2oVBwYH8+6r7E7HpjOMl6ezJ PfcL+tbmtlleGL3K//Qd/jhBIgzUfAKjLGz/3ILSD15hihymIWt57dWFCPmww6Br0S5U Vo4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736767440; x=1737372240; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=217qCdop/bVuj9XoV8EFEQ4K3BvCuSwvnN0rQfYprBA=; b=WPBhHUwn4bUduqovyzKnlbqK3nbzpGVnhnZZUVxfc6kmxX3vANozoK8wJ7d+xywgxN ZfkZa8XIrAJE4MyKOtlt5WvkU27tzC4yTgvTc9rRHB5QgLbQdPfkQshkl8zi5i8e1Ufi FiWnVJj1FLGiyJRpQTOMffahq0Wfh0cQL46AHzmnSOa2kiVihcuSq8K78qYpyE1mdTtc ak6liqRk3yXsWw0pk8UHH4Uk5n/yhuo6c2D80Cq25fV/Ku1/fBbMP1lRTt7s3wDI1gGf m+gtzuium0UuU4Igs0AHkLol1pqXp3a8n71fgS0NhelCFbcjxiLIrVbYUiQDYcsPXlu0 Zm5w== X-Forwarded-Encrypted: i=1; AJvYcCVlO4TBTGyY4y2FM2mABRFuf8AO/G2BsrCZatq/UgBY8BQS+iWap2MdD2kzRXNw/jfDmBZfBBEgcFggIS4=@vger.kernel.org X-Gm-Message-State: AOJu0YzCFgtUEF07fX6Iapj/BJy7yzxPTfuJ+ffoHibmu/1L5Redl+Bv gSWBpUbxo52FhlbRDiIhSzN4tkpIaobis+sdBZuncLfsMeMb2hPEn55/7fIeNgI= X-Gm-Gg: ASbGncuzruBCX6T1NtxG9Nua58ialZImlnsuQj2OYLRrGsD/kiDmF8BFOY6okYCAdKZ IfbZGh/QMf8tpjhZQyD/vf80k+YF4U0B9hljlWx/V892Dm8sqNy8b8sxpeMr0s2dXeYlwv0osbs n5u5wud54iL6jdEaWNP/BTx4c7xOZF0tuNunGCdl/55lzDX6pvoreeGvvag/ojMPnGtk0fUKZLz xFQnUI6PBouZDWHwbYVH71ybS2fCi9MO7F5Oc23yh8FSIpIWTSE3uojlaI= X-Google-Smtp-Source: AGHT+IHWlPorx8XJmvX79gE5sNkxZSUXnp+Pd6+S6Fek2hXtY7a65fTM8Lo2nmZmWQWd7i9agrQzmg== X-Received: by 2002:a17:90b:51c2:b0:2ee:ab29:1a63 with SMTP id 98e67ed59e1d1-2f548ea6331mr27577987a91.3.1736767439700; Mon, 13 Jan 2025 03:23:59 -0800 (PST) Received: from localhost ([122.172.84.139]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f53e1da400sm2352192a91.0.2025.01.13.03.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 03:23:59 -0800 (PST) From: Viresh Kumar To: "Rafael J. Wysocki" , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: [PATCH V7 07/16] rust: Add bare minimal bindings for clk framework Date: Mon, 13 Jan 2025 16:53:02 +0530 Message-Id: <8dd38c6dce256340a5a623503023736f8e9278d8.1736766672.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: 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" This adds very basic bindings for the clk framework, implements only clk_get() and clk_put(). These are the bare minimum bindings required for many users and are simple enough to add in the first attempt. These will be used by Rust based cpufreq / OPP core to begin with. Signed-off-by: Viresh Kumar --- rust/bindings/bindings_helper.h | 1 + rust/kernel/clk.rs | 48 +++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 1 + 3 files changed, 50 insertions(+) create mode 100644 rust/kernel/clk.rs diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index 59b4bc49d039..4eadcf645df0 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs new file mode 100644 index 000000000000..123cdb43b115 --- /dev/null +++ b/rust/kernel/clk.rs @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Clock abstractions. +//! +//! C header: [`include/linux/clk.h`](srctree/include/linux/clk.h) + +use crate::{ + bindings, + device::Device, + error::{from_err_ptr, Result}, + prelude::*, +}; + +use core::ptr; + +/// A simple implementation of `struct clk` from the C code. +#[repr(transparent)] +pub struct Clk(*mut bindings::clk); + +impl Clk { + /// Creates `Clk` instance for a device and a connection id. + pub fn new(dev: &Device, name: Option<&CStr>) -> Result { + let con_id =3D if let Some(name) =3D name { + name.as_ptr() as *const _ + } else { + ptr::null() + }; + + // SAFETY: It is safe to call `clk_get()`, on a device pointer ear= lier received from the C + // code. + Ok(Self(from_err_ptr(unsafe { + bindings::clk_get(dev.as_raw(), con_id) + })?)) + } + + /// Obtain the raw `struct clk *`. + pub fn as_raw(&self) -> *mut bindings::clk { + self.0 + } +} + +impl Drop for Clk { + fn drop(&mut self) { + // SAFETY: By the type invariants, we know that `self` owns a refe= rence, so it is safe to + // relinquish it now. + unsafe { bindings::clk_put(self.0) }; + } +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 2f72e1d8a6b7..5d43dc5ec9eb 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -39,6 +39,7 @@ pub mod block; #[doc(hidden)] pub mod build_assert; +pub mod clk; pub mod cpu; pub mod cpumask; pub mod cred; --=20 2.31.1.272.g89b43f80a514