From nobody Wed Dec 17 11:59:19 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 43EC714EC5E for ; Thu, 11 Jul 2024 06:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720681117; cv=none; b=Q0eXmta99QcCMR7SZfjaQCiCvxAlfccCNmmjTnrndwrGBYZqN3awS6UlPvLBS3VkZt8DZNXEV8gdwt6QXRQkBkplTuXX+tuF/5kvXi/38UNXdGW19epxt9wxQm+ZVYmqDeNFLNWhzh2pGLSDK0POUmdoRRG32wl4cArdxmQzyX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720681117; c=relaxed/simple; bh=dO0CWc/xKDTHkuWPDNFu1TEYJonQR+X8T3Udl4DMBu8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U8Hf10Y1iyLr84taOsAK5ZdIXuDVmvTqDK6xWZwrZybJ7VCLbFOwSimwL4r/Mqr3aI+n6q+xb0GE2aykcNk+LvD8XZYpCx48oaw1xAZiyUrUyJIZg0gzuAhO18HKvwHzAZ97C9PWjgRa5JYyZAMkFKDH71zvxe008Csgc1XBfkk= 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=ZBuR8xO0; arc=none smtp.client-ip=209.85.214.170 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="ZBuR8xO0" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fb0d88fd25so4207445ad.0 for ; Wed, 10 Jul 2024 23:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720681116; x=1721285916; 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=uGcVVh6shkk/cP1y6RKWzcHFgRZvU/7gGba22DNsHXQ=; b=ZBuR8xO0kKEasHfScUj71x1BedhSpHYdCSlX+2lMFVrXyPeUVKdDdKbTheFeC7R+Hf GDR70Ij2bPpsy8ChmRJVb1SGCxvDSlixjE6dpE3c79lmchfP43ZK0LFEonIEnwJyqUNk xYrivKPhS990Q1J4JYA+Hcno29sskie2M03WirQFD7st7VDmjnbfjGBhkIiksOSt2vRk kC2901z2nEB+xtFEMMhUQn9aZd6kkovDSzZRbd2lfBVlghjmEYyDw9kzcytOKKpjWOmV UaiCkAt4FaFHqKtNrbXvLuIJpS3BmdE7fAnrJOV8dBWkc6oR57u4ocTFHzSbDiw0dy+C DlqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720681116; x=1721285916; 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=uGcVVh6shkk/cP1y6RKWzcHFgRZvU/7gGba22DNsHXQ=; b=s4oUKH/h1rAGNMd41W33pVY10EfLlA3sTXv4XqEVqhagfu7fGpaj++WemRMUhVBCpn H4KVJdxIZ5Xr72AYUOM5GYgBFhZgUAyzJqMnLcAXrtm00YMjqU+OUP2X1QNfdT3SB0ot AMfvh53NCmFBJ34ry2coXpwhvK9cGOUFSgRWUmHuPiFSSkJmDDxElPk8XdyWu0JWgn9w AUjy4JwovAMkVGnZEnnJCd1L/RMPrrTGJOYPN/7QPZa4rGozheyMPzN20u95ctkZv+7k WpgcrF+mJv3iEEfPvnZMSZH8K5gGei7TW9Bz9vxq22+lGddVdYoCq3KBOm4PobDt64aO ZCqA== X-Forwarded-Encrypted: i=1; AJvYcCX5Nm6PV3O/kO5FkRLc2QyuywHFPI43z2BoL8KgsLlQFjDKeuyzQ+Y/YDVEekvCTynFRPnEJzTfzdp3MSzNo4gh9tvH/Mjzu+k4b82V X-Gm-Message-State: AOJu0Yxify0HiE/0QM2drC1nKPGR1fakKaDqBefIDGYn/oE2rx2GDc6Z ugJZWGxTHMt6eprS6VChnv0uPZZy+lCLv1/1hJ5JocrAPsYKWz+TkZKjYTtC6T8= X-Google-Smtp-Source: AGHT+IHttmQ+CJmAEGiN+ZpLgx1FkTxuA+txB4y8lJKqk+ahCAt7PiixgF+qi4Udu0Q7oaRRF/rSwA== X-Received: by 2002:a17:902:f78e:b0:1fb:8e29:621f with SMTP id d9443c01a7336-1fbdba13720mr24954095ad.16.1720681115548; Wed, 10 Jul 2024 23:58:35 -0700 (PDT) Received: from localhost ([122.172.84.129]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ad0103sm43520175ad.279.2024.07.10.23.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 23:58:35 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Miguel Ojeda , Danilo Krummrich , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl 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 V4 7/8] rust: Extend OPP bindings with CPU frequency table Date: Thu, 11 Jul 2024 12:27:49 +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: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds bindings for CPUFreq core related API. Signed-off-by: Viresh Kumar --- rust/kernel/opp.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs index 113652448056..7317a5e922cc 100644 --- a/rust/kernel/opp.rs +++ b/rust/kernel/opp.rs @@ -16,7 +16,10 @@ types::{ARef, AlwaysRefCounted, Opaque}, }; =20 -use core::{ffi::c_char, marker::PhantomData, ptr}; +#[cfg(CONFIG_CPU_FREQ)] +use crate::cpufreq; + +use core::{ffi::c_char, marker::PhantomData, ops::Deref, ptr}; =20 use macros::vtable; =20 @@ -376,6 +379,56 @@ extern "C" fn config_regulators( } } =20 +/// CPU Frequency table created from OPP entries. +#[cfg(CONFIG_CPU_FREQ)] +pub struct FreqTable { + dev: ARef, + table: cpufreq::Table, +} + +#[cfg(CONFIG_CPU_FREQ)] +impl FreqTable { + /// Creates new instance of [`FreqTable`] from raw pointer. + fn new(table: &Table) -> Result { + let mut ptr: *mut bindings::cpufreq_frequency_table =3D ptr::null_= mut(); + + // SAFETY: The requirements are satisfied by the existence of `Dev= ice` and its safety + // requirements. + to_result(unsafe { + bindings::dev_pm_opp_init_cpufreq_table(table.dev.as_raw(), &m= ut ptr) + })?; + Ok(Self { + dev: table.dev.clone(), + // SAFETY: The `ptr` is guaranteed by the C code to be valid. + table: unsafe { cpufreq::Table::from_raw(ptr) }, + }) + } + + /// Returns reference to the underlying [`cpufreq::Table`]. + pub fn table(&self) -> &cpufreq::Table { + &self.table + } +} + +#[cfg(CONFIG_CPU_FREQ)] +impl Deref for FreqTable { + type Target =3D cpufreq::Table; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.table + } +} + +#[cfg(CONFIG_CPU_FREQ)] +impl Drop for FreqTable { + fn drop(&mut self) { + // SAFETY: The requirements are satisfied by the existence of `Dev= ice` and its safety + // requirements. + unsafe { bindings::dev_pm_opp_free_cpufreq_table(self.dev.as_raw()= , &mut self.as_raw()) }; + } +} + /// Operating performance point (OPP) table. /// /// Wraps the kernel's `struct opp_table`. @@ -580,6 +633,12 @@ pub fn adjust_voltage( }) } =20 + /// Create cpufreq table from OPP table. + #[cfg(CONFIG_CPU_FREQ)] + pub fn to_cpufreq_table(&mut self) -> Result { + FreqTable::new(self) + } + /// Sets a matching OPP based on frequency. pub fn set_rate(&self, freq: u64) -> Result<()> { // SAFETY: The requirements are satisfied by the existence of `Dev= ice` and its safety --=20 2.31.1.272.g89b43f80a514