Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp911068lqt; Fri, 7 Jun 2024 02:23:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHoKwoGqqJLwMxYKsGIx+MPLTdcc8bAQRLtYRL4PinbyKBnrZhxNgIhMLu4cw/ir5EPlU1zsd6xZpVVtjjXUKGQNS7kAjSBFHsOwNRew== X-Google-Smtp-Source: AGHT+IGc7iyOo6vcHR6vgC2pYP6O89U1THOzxFOxnwYtdeJqyWNQi8NVcFTxqaMYKaxiqFuX2Z/I X-Received: by 2002:a17:906:2989:b0:a68:ff92:46f0 with SMTP id a640c23a62f3a-a6cd5614c41mr142443066b.10.1717752233002; Fri, 07 Jun 2024 02:23:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717752232; cv=pass; d=google.com; s=arc-20160816; b=QPoKmxdslyDN01/a3lpO89xZAr8gmTHg0Kf6P/0fEpqmIKs6xPJrEkRdqdnhIoCbDM W3uyU6I0eV1lEYFHqM5PWr6Ppvw7HuzE3Htuf5zENyvxafmjKB8SowAR6bmx6BwUKiN/ v3+Oxfh9dvV+X1yA5pp1YOYsi7wsV/GgFVH6d3m1+UWrCjqVMvjbDFgkOv+89kFlOfg5 7YdcJ3fRMaXs4ELnqxpEACm2R7/VbNILPPBsmaAgcESk4NPMeQf4qhutEvFNE4vYKw5w kSn81ElEY0cslJUhEMbiY6ZB6G0K0y+hCbpD9NnzX7wBM46j7EyCu2VfWkvol6RjtiN/ dU+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zCjoSclVWZT0iDBq8VFLkZOWwHf6tFEcHjugFV93b9U=; fh=JFOfo9ES/0l1yhQUIIkBvoKSHCAqln0kuwanFQHrYkw=; b=G+U1tkgXH/AkIrYe9bXNx6BRyuKr6vPHBu1q+ld5TbyHm1YiamFA92d7ddqdpkSGen JWVb/PLCMYCkQ2SsXKa6GXodW6VNeZcAuXbEq8XVKvVcNwCLt4a5/T7vclK9PTGng7YB ZD2FKKe8QNXBy9wpAQy7U1LfySPEe+H5rykHP+b/od8lYIHuscyyerlleSz5Dk0s7UcN qKF92UuoaRYgn553kT968nCwWa+JRV3NcK8GQF/yj1zICyngMz5o2vGV0H2dIA2HARHH 4fDtzoP5u4P9qvfe2JeawkQ1wLeYCVJX5BpUvhNJ2mjJWMGMCp2lB6Mo2JQEEja1dRdY 0mWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UijrZEoU; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-205698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6edd322125si11970966b.409.2024.06.07.02.23.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 02:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UijrZEoU; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-205698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1041E1F282E9 for ; Fri, 7 Jun 2024 09:15:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6511515B989; Fri, 7 Jun 2024 09:13:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UijrZEoU" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 87A2615B97E for ; Fri, 7 Jun 2024 09:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717751586; cv=none; b=r7XyBDFkncMfxNdJjAyELIRv7tK5awAa9vyG8sjpAOuIWkwlBZjDQdzWSW4EOgWRnzxcqBEr90od6uG0W/ukgNkwggEEg08ZgawNbEXZAqW9dRIVTOp+d7xeoJTDB2ZshyXLB6w+tKz7ZAO552j2x6ykO989/e+irZP9o4yQIzs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717751586; c=relaxed/simple; bh=Y+dnDpoPgLDQbxi2D26tM1HhdBJGHB5DyqDp5BgM3qc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kcre10F9v8UkiAL0vrR1kavM1bCyD393YKDp18E9egVhZKEgkbVAC6u/3IzLf3ZTC1GLaehM4wC4GxhNM0fwb1nzjMV/ziROtH+ByudYWgNNy+NO9fdq8B3sdkMvGpNha+0phV2ykaW9VfbMKbL7RK1geuoSUv01+viQuyboN4U= 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=UijrZEoU; arc=none smtp.client-ip=209.85.210.180 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 Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70249faa853so1589968b3a.3 for ; Fri, 07 Jun 2024 02:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717751583; x=1718356383; 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=zCjoSclVWZT0iDBq8VFLkZOWwHf6tFEcHjugFV93b9U=; b=UijrZEoU5H2jKL+3r85xZOL8CZZlKZ3iHSAjm3NlzVBPUD6ODH0IVGld654yG/jER9 4a5GV7BB8q7s3UIoG0VEr+2M38kb8GM/7b4nC16r3tKdQJ+1VJ5yRoYgxfOY5VbIdkan 85RIERByXSas46utrRwy8zmPTqCSV5cwV7RAFYGbEBG3LarzmI3tdL4H5fxPWFQHubPc jJMEk4Tlfz1hVKjQ5WJNSlN+xg5m7YPQRTtzcPByC1cmyeS/3alKBa5RXQ21oW8b3Ofz oqzqBTjayUf6EQCG6nSHi/7YfiYotyOaEUv3KEY55r679jvpFpsDhQ+uM50yXMaK7uLW 8wiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717751583; x=1718356383; 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=zCjoSclVWZT0iDBq8VFLkZOWwHf6tFEcHjugFV93b9U=; b=fv7GmXAnSoPXJQgS27pPU5+TDzA1E4IWYzQIrHeVEKW7Cl4VYk/jQ8fcu0Fr6kojxz mctdDZ+egVR477lK0csHgNPLajyVofDbbI/Uip24YvDp5xzjSBBxIbRokrXobKskHgV9 /dHgq6FKlmPUFSYDhUoPEMTTZN2T1i0Jz3xbFMDbg2F9I2Rm9eygR/190emHFg91Vbo7 F0m11QmuocGPgqZVkBk1/o046gIXpTL21RzG0TP86dHtdLFh2V3MrSqJ/NM9mV3eJfKn DXG4c2EC8tFaLiwyrD+vpzbXgLmYDrHNmZv/33eJOVqTTVf5Y7d/B6Zw/XgrYmYKUBWx +Q2Q== X-Forwarded-Encrypted: i=1; AJvYcCVENLndL004r2kMi8Kyp40cOdBk/uJtK4THUHC4TrmH26lTgPcak+Lr5nvaIa4JuOm5vmd+sqP8QLjN7nD6bCD4td7GQ3tIT18hGjvD X-Gm-Message-State: AOJu0YygMBbUWu4Q81Xqa7n20nRHqAcK4eLQovlUuePZ+ig84A5Rylae Z6+OHGp+DC5GvYlWX7BlztF69IC6IIWvi9WymdihJ3Mo9MiDFO2yr80GjePqld0= X-Received: by 2002:a05:6a21:19a:b0:1b4:4370:60f with SMTP id adf61e73a8af0-1b443700773mr422429637.1.1717751582668; Fri, 07 Jun 2024 02:13:02 -0700 (PDT) Received: from localhost ([122.172.82.13]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd7d89a0sm29256535ad.128.2024.06.07.02.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 02:13:02 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Miguel Ojeda , 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: [RFC PATCH V2 7/8] rust: Extend OPP bindings with CPU frequency table Date: Fri, 7 Jun 2024 14:42:22 +0530 Message-Id: <6e703e990bd1ce864927060c53025506568fd0b8.1717750631.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: 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 ebcb77b52558..4833848f79b1 100644 --- a/rust/kernel/opp.rs +++ b/rust/kernel/opp.rs @@ -15,7 +15,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; @@ -343,6 +346,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: By the type invariants, we know that `self` owns a reference, so it is safe to + // relinquish it now. + unsafe { bindings::dev_pm_opp_free_cpufreq_table(self.dev.as_raw(), &mut self.as_ptr()) }; + } +} + /// Operating performance point (OPP) table. /// /// # Invariants @@ -538,6 +591,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