Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp592410rdb; Thu, 30 Nov 2023 12:44:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnj6GaX+oZ3NkBajxsH9DIH6HIlN4KOvUj5gN+WvKLGng5s6m5thnvaDvD93YuYdqw/8C7 X-Received: by 2002:a05:6a21:a5a8:b0:18c:3fe8:d8cc with SMTP id gd40-20020a056a21a5a800b0018c3fe8d8ccmr23550408pzc.28.1701377067972; Thu, 30 Nov 2023 12:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701377067; cv=none; d=google.com; s=arc-20160816; b=XiAZwXjFttuI9ncRcDdVnf9pxCZ/o2EvXxFZSduij5X5EhjrqVgSjqbUkn2FIOqTDm 0DTLbKVujawZj+04U5QPgkmYTzr1hq+r3ZnZy/XCz7iR3jUY2pi/wPUshrkHPUl81lT1 V7JmF0vgCcqvTdhm/zkJUeIAZevS+1nXVEdHn6xt4dkfjsaxafHokqMh0Il5n1U9GEJV ZzewWqb4rpRQVTAds5CqSFipyH5/uQ3Wc5vphwmFovYaECwiIhOR+q0GOCHqa5Ym2mwm 6cY0HS1QQxzjevOhisvDVKGJv02A+VC8ZtesGkwYeOgRQYabUbgrw3pxVmX8v/qqARbM UJ3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8ouHH58sNpZzTcXwZ5LcxoOaUpuo59mjWdTi8F6WHEE=; fh=g3kSv4WvKlMaeFENGH9vsQAEMHCdLvlnRC6We8RThxY=; b=qJyA8gZ4rK/SmrQfYurQ31N0KsmDWN70H4RNeHJiXryihuSYYoUAJcsuWG6KhGo46o Al/Qk42ilZqDvYXCowUn9u3T5lkS7Nq11Uk00LgpAGgP/FgOoDvFB3ec3+rqWlIjrFep xOIMM3HALheQACc+uBPCnhX5iThlViKuHxgnhEGD7HhgjolqyzysGM1PKHzYyhgSgD5H LV+bqDQ8KmchoSukamaOHCzR0pYW5w3Pge57ccYB6qiP9m9JWz3CJXs2lvZULBClWWI7 qISKzCaVuS1xcWVh6bQLMNvj0T95qWdv+YS+KmFfD2OOfNORnkysprB9iiyeq3GQuGCA mokw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id pa16-20020a17090b265000b00285c4fd2ff0si2136648pjb.116.2023.11.30.12.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:44:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 41ABB82E8749; Thu, 30 Nov 2023 12:44:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235211AbjK3UoG (ORCPT + 99 others); Thu, 30 Nov 2023 15:44:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235246AbjK3UoA (ORCPT ); Thu, 30 Nov 2023 15:44:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B3438199B; Thu, 30 Nov 2023 12:43:59 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 28F9A143D; Thu, 30 Nov 2023 12:44:46 -0800 (PST) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2F0E83F73F; Thu, 30 Nov 2023 12:43:58 -0800 (PST) From: Sudeep Holla To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , quic_mdtipton@quicinc.com, quic_asartor@quicinc.com, quic_lingutla@quicinc.com, Sibi Sankar , linux-arm-msm@vger.kernel.org, Cristian Marussi Subject: [PATCH 2/2] firmware: arm_scmi: Fix possible frequency truncation when using level indexing mode Date: Thu, 30 Nov 2023 20:43:43 +0000 Message-ID: <20231130204343.503076-2-sudeep.holla@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231130204343.503076-1-sudeep.holla@arm.com> References: <20231130204343.503076-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 12:44:25 -0800 (PST) The multiplier is already promoted to u64, however the frequency calculations done when using level indexing mode doesn't use the multiplier computed. It instead hardcodes the multiplier value of 1000 at all the usage sites. Clean that up by assigning the multiplier value of 1000 when using the perf level indexing mode and upadte the frequency calculations to use the multiplier instead. It should fix the possible frequency truncation for all the values greater than or equal to 4GHz. Fixes: 31c7c1397a33 ("firmware: arm_scmi: Add v3.2 perf level indexing mode support") Reported-by: Sibi Sankar Closes: https://lore.kernel.org/all/20231129065748.19871-3-quic_sibis@quicinc.com/ Cc: Cristian Marussi Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/perf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index 8ce449922e55..875dcb71bb65 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -268,7 +268,8 @@ scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph, dom_info->sustained_perf_level = le32_to_cpu(attr->sustained_perf_level); if (!dom_info->sustained_freq_khz || - !dom_info->sustained_perf_level) + !dom_info->sustained_perf_level || + dom_info->level_indexing_mode) /* CPUFreq converts to kHz, hence default 1000 */ dom_info->mult_factor = 1000; else @@ -806,7 +807,7 @@ static int scmi_dvfs_device_opps_add(const struct scmi_protocol_handle *ph, if (!dom->level_indexing_mode) freq = dom->opp[idx].perf * dom->mult_factor; else - freq = dom->opp[idx].indicative_freq * 1000; + freq = dom->opp[idx].indicative_freq * dom->mult_factor; data.level = dom->opp[idx].perf; data.freq = freq; @@ -853,7 +854,8 @@ static int scmi_dvfs_freq_set(const struct scmi_protocol_handle *ph, u32 domain, } else { struct scmi_opp *opp; - opp = LOOKUP_BY_FREQ(dom->opps_by_freq, freq / 1000); + opp = LOOKUP_BY_FREQ(dom->opps_by_freq, + freq / dom->mult_factor); if (!opp) return -EIO; @@ -887,7 +889,7 @@ static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain, if (!opp) return -EIO; - *freq = opp->indicative_freq * 1000; + *freq = opp->indicative_freq * dom->mult_factor; } return ret; @@ -910,7 +912,7 @@ static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph, if (!dom->level_indexing_mode) opp_freq = opp->perf * dom->mult_factor; else - opp_freq = opp->indicative_freq * 1000; + opp_freq = opp->indicative_freq * dom->mult_factor; if (opp_freq < *freq) continue; -- 2.43.0