From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 8B3591A0715 for ; Tue, 30 Jul 2024 10:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722335270; cv=none; b=pLqOko0zFNRD/M1SBVNGDEl5bvtAZVEBrHCxEgFpyMcZuivG/Gu56RtDo0XnioDs/RMY0QV7Fy5lqOcP/K6+5opgU8Di4jeV6L6e23kco+ASTdNKOfY7w1ENcfX1qFZDorRMjAuQchknn8XztZn6P7cJofj9Yl5uC33imnS3vA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722335270; c=relaxed/simple; bh=dO0CWc/xKDTHkuWPDNFu1TEYJonQR+X8T3Udl4DMBu8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CbPUpAFolo6Vu50SemoBc4zK6hOSZaEEC+IHaXNrp/fvw0lVe46iH9UQ/4fWex92P11B7Ch+h0cv0RMWdSnQV3h7w3fZ1a9O+3mPzvoMtLAlpC9Zrccgj/FsvnfmQ3U9y8C4omThplPw4AuaVlLmQbQTLCphxl233R24RzsL6Nk= 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=RcuWV5+B; arc=none smtp.client-ip=209.85.210.169 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="RcuWV5+B" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70d357040dbso3354812b3a.1 for ; Tue, 30 Jul 2024 03:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722335268; x=1722940068; 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=RcuWV5+BeoZYWqU4ujqXpdUswRDHWB/avZhFUl0N3VCoRhVb5iFyVdK+N6E3UtkwSx 1118Cxr7lRRbISDh7Vj21Ps6fmLFI2fFdzzSN7JkM/iMC3uZiwiHU+gunBzMfUVb1K6b ysOe7ZTkl0BzrqNm45hSe2KKgfZK6RzKLgmFwXWM2+xEVv1uHrLWqlGiVCtSGV8vnlX9 +AA4WodPynk7ATgVQjOeAyAbNKl6P1XV+tlXa04082iHCYtSDmIrJH4jK6kP6qnFHdCd nIm+ymsW3I80enl/P0TqAXt5UBq08amgq0HnSLvKKMeYBFG1wi8Bp/CUaUGdoTjUCCKN WC7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722335268; x=1722940068; 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=n5u3ptNKyitijVoGgRHAngJbk0sZ6q0m5SAO6myz6htPmfNpWakB2z7knVAXsQNvoK uK5mrjLqDIfs6WOhsor5FSnJmPmQN5KCqscDSQqyr1ju+lw6+pCpifqblpIjKn23IwAL MtcC0tepo3TNNsiplrAjJPHuwW9ymsYVJLSWfI7NRVDt2RS6GpQROoasxCWiH6JR4p1o XRE5lQIjkh08r91YHmkSX4Rjyb+vGNTCG8boI5nwlqrbbO1P1X2GEJdRKVwNGtgrOy90 Wo4aEISYxRwG/v6v/69JpUBp7NoeerOaSOSuOjsZFtw3jGLwx2AQt+hCOJz3KfYmZ3Ls ceLA== X-Forwarded-Encrypted: i=1; AJvYcCWD+2JOqn4jwg/pX84dP88fbVHnncO7xSiVy30x8+uTixLN8hqW4CH3sXJZ0O6Z4n+D4WuVMINoiUjeLiZKYO2rnQgbARBGeYZfDSiXgAs= X-Gm-Message-State: AOJu0YzbY5ARGNT2m63HVTBC25EYca1867ceHynXrFUTrZuOT6pzfEhF 4AApwS0jS0xlyRymzo1/i7rv9IwlO9DvbqEo/LNco4/hhVgwRO693pWSz4P1fWk= X-Google-Smtp-Source: AGHT+IGh5k77jhw4qnCpk6Wyl01TvyBbrQE0VQxUroorUPZ3Pe+onjAYfUxT64noXwHfpihD+swzFQ== X-Received: by 2002:a05:6a20:a11a:b0:1c4:8da5:219a with SMTP id adf61e73a8af0-1c4a1299d97mr10019110637.8.1722335267630; Tue, 30 Jul 2024 03:27:47 -0700 (PDT) Received: from localhost ([122.172.84.129]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead72ba2csm8424835b3a.93.2024.07.30.03.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 03:27:47 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Miguel Ojeda , Danilo Krummrich , Viresh Kumar , Nishanth Menon , Stephen Boyd , 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 , 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 V5 7/8] rust: Extend OPP bindings with CPU frequency table Date: Tue, 30 Jul 2024 15:57:04 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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}, }; -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}; use macros::vtable; @@ -376,6 +379,56 @@ extern "C" fn config_regulators( } } +/// 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 = ptr::null_mut(); + + // SAFETY: The requirements are satisfied by the existence of `Device` and its safety + // requirements. + to_result(unsafe { + bindings::dev_pm_opp_init_cpufreq_table(table.dev.as_raw(), &mut 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 = 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 `Device` 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( }) } + /// 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 `Device` and its safety -- 2.31.1.272.g89b43f80a514