From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 4F7CC1EF094 for ; Tue, 7 Jan 2025 11:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736248956; cv=none; b=OCT2qvNGGJi7dNlvUrh71yJkCdo5KCcPGi/Err7LuH9kbTNy0qBKtI5gDST5Pic8QRkMqdtOzqbBNbxaLoXYtGy5E2SXRMM6RkWATkTSLC9ATASSQ7d3fl9bsBgxJodX28RIL7Bp7T5m780Yx/INdz8qfdojdKCRk8zLElVV6dI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736248956; c=relaxed/simple; bh=Fx9XB5ts9sXUh9O3/l7pGwJGGgpdlk1bk0cEGYOweMo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DlXKFJUPuZG13I28lgazgbMM5v00o+inelEPin3+vplXQAod3ciwsUfWLydRC1nit8Z0OBZvcd+Ec9GGojslLkezQDgAqi1UaR0oW7Zh5cdQXT+4lqMPSsi+wXvCt/bhdgl80NTzncVzQlQX2/JKfYJEaT3n3azfDOHXBw0jW5Y= 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=woKW3rU8; arc=none smtp.client-ip=209.85.214.182 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="woKW3rU8" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21a1e6fd923so5924165ad.1 for ; Tue, 07 Jan 2025 03:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736248950; x=1736853750; 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=jK9fggKbnQIV5hRTBl9969qRmfCDXZjN5H+SCocLudA=; b=woKW3rU8YbZ5atMKY6K4VJZqd6hKuqCVyZm4TOmkD5rPd7CuwKTsuEfct98/SqwCqT jbGZzjLUWdLm6knoU5ZOUKLYpd+LiEP7OJUY/H0tdN1TT4/7ayyDlHEyuWFAAB58HlNs 8FY7Mrh0/B9o5GC1Wsnsl+rdghWJDivOnGKF8haK9atbMygeTNHvUgP05IfrAHb7y0Dh XCNXHJJ/+DlcSREBoIv78EBQAfVAzfI1OkY/e3pEye4uQmijN79xb52IpQn0YqeG7w6y s3CG6zHaLoRhHdeEUdAICp6lJZXUhwzosnIkZz2ENh3rq4r/WmOdaV1EfK2xdP21hpko EJEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736248950; x=1736853750; 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=jK9fggKbnQIV5hRTBl9969qRmfCDXZjN5H+SCocLudA=; b=ehjToakJP+aJMnUh3mRMQXFCptyHSo4dVXqcS+XT5oPa2Vaac2ZvxjGWuXUuG0b1AB gu7XZulWOxpJQF345AfFhOW6ioA/w9Zvxdz94GCqlzZ6ZjXVK6MF+SGr4KL+lNIQlqDO alxoJyieVorhp8nOxU4OLSYLWcW2ylJ6e+9T8nmjWJf04vnoI9ScfmPS0zy95OXnkrwA CQSrwNU58OSnmWZSieJsrv/hPfAlrN3NrHR/wDAu3hZwJ6FqpGUSSAJI3RxBuRLCkR5o XFKkctNXT2BOI1CQctnMhy/vU2JjcxCz8VQyYsyGrN5UUc7RztIM9gb75kxTlN+G4yML 64oQ== X-Forwarded-Encrypted: i=1; AJvYcCWa1oJkHDCPX5O6WX34Oaf0UxJgMV/jN81D61azqA6oU5tnsmjmCs5siLTto29Th9Bv19LYSgfTD3jxV8w=@vger.kernel.org X-Gm-Message-State: AOJu0Yww4MpTVevd+Fru6DaB5xVtiu9IFn4jKXxOQSmTvRr8250NbX3t f70IOXUGe9UprCIAE3CxA7voADyEF2OwmTp/FY4FN5yUjWV84ebmCWVn+AVCegw= X-Gm-Gg: ASbGncvjrMf4zubCA0JLgMo6c9Yy9l5KiVm0P4ND6ebLxqxOXnNdo4g8Os929y4AG7d 8B1mfMnMYVqrXDu82I+/XUGT7vwkCcEOdlttevppmUeJntvGDDpCXPBj9bl9er6bgtEXpYz195v Ftms64ZYeUj9GCgATVHjDpuyQXxhSA2LIr3vzHhGxV+nHLfRRLoHcfVtRVBV72cCormsCmfpsjq UDfqJBQMnVbuXAD8z4ewIzCBZuPvN0x5Ue2Xfce68izv+4Z8o8enD6qTsI= X-Google-Smtp-Source: AGHT+IF9FSxiUi6E3vyUCMwDEsv53WHI4nW1IVtUaahS5ofFQcTzHYCfQCLCjg0emu7ogoZdphf3/A== X-Received: by 2002:a17:902:da8e:b0:215:b058:28a5 with SMTP id d9443c01a7336-219e6ea2855mr823470415ad.18.1736248950516; Tue, 07 Jan 2025 03:22:30 -0800 (PST) Received: from localhost ([122.172.84.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc962940sm307240865ad.34.2025.01.07.03.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 03:22:30 -0800 (PST) From: Viresh Kumar To: "Rafael J. Wysocki" , Miguel Ojeda , Danilo Krummrich , 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 , Stephen Boyd , Nishanth Menon , rust-for-linux@vger.kernel.org, Manos Pitsidianakis , Erik Schilling , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Joakim Bech , Rob Herring , linux-kernel@vger.kernel.org Subject: [PATCH V6 06/15] rust: Add bare minimal bindings for clk framework Date: Tue, 7 Jan 2025 16:51:39 +0530 Message-Id: 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: 8bit 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. 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_helper.h index 3225379abd2b..7a95d999ead8 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -15,6 +15,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 = if let Some(name) = name { + name.as_ptr() as *const _ + } else { + ptr::null() + }; + + // SAFETY: It is safe to call `clk_get()`, on a device pointer earlier 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 reference, 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 8a0cd60eb6cc..70694becc9ff 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -38,6 +38,7 @@ #[cfg(CONFIG_BLOCK)] pub mod block; mod build_assert; +pub mod clk; pub mod cpumask; pub mod cred; pub mod device; -- 2.31.1.272.g89b43f80a514