From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C81133FB042; Fri, 8 May 2026 15:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254413; cv=none; b=CPP3kwWt3jOKetbiPGdbJAuPcHnzm7wmEWkkCRVIlmiSquVei64CAkdFUUPwWnxbfy0BBkH05ucEFKmGiHP1ESKcEC+72KRxcVkM0wgqSrGKc+GBwzutgdzjaiL/lN5kQ5odBS3aQ6kNaTzkad2CuZAMnAs+NHk7VvknMMyEJDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254413; c=relaxed/simple; bh=WC1R4qV6I0MneBfZAXWbYrl3W9fg6IoQSFQXIfGStN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xf/PWRoLMQXYbzpGL+jwFKf+BxBrqgrl8Rr3KWnVj8lbUO4HPM8Q+pmOVBylvdMQGPFokmoY2nBReuJuBdkCYrtqK2bfrph1S2W3STfIop3LuG8y9BX5DDZHIfrzRlX95ShvTVmfn3zJaXt9gcLctcxYRGIr5xdzQRXiAeypptg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Yy6ACcdH; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Yy6ACcdH" 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 C24EC35A1; Fri, 8 May 2026 08:33:25 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E2F63F836; Fri, 8 May 2026 08:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254411; bh=WC1R4qV6I0MneBfZAXWbYrl3W9fg6IoQSFQXIfGStN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yy6ACcdHyLZwFPRCF5YoZsDdCuDhNbBt53WgsgTwkw5pXMphDJEm+JyJI2BoHwtBe sUJIU06Ry2i450l66La1uIHRU+A2pnqmVqLQkQ/T3HFRMtdfC0O9IpZ5HJV+/ICqdX pN015g+eu9rv8vr9PbbexLDueaXqzkVfgo7iEtjo= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Michael Turquette , Stephen Boyd Subject: [PATCH v4 01/15] clk: scmi: Fix clock rate rounding Date: Fri, 8 May 2026 16:32:46 +0100 Message-ID: <20260508153300.2224715-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" While the do_div() helper used for rounding expects its divisor argument to be a 32bits quantity, the currently provided divisor parameter is a 64bit value that, as a consequence, is silently truncated and a possible source of bugs. Fix by using the proper div64_ul helper. Cc: Michael Turquette Cc: Stephen Boyd Cc: linux-clk@vger.kernel.org Fixes: 7a8655e19bdb ("clk: scmi: Fix the rounding of clock rate") Signed-off-by: Cristian Marussi Reviewed-by: Brian Masney --- drivers/clk/clk-scmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index 6b286ea6f121..b6a12f3bc123 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include =20 #define NOT_ATOMIC false #define ATOMIC true @@ -83,7 +83,7 @@ static int scmi_clk_determine_rate(struct clk_hw *hw, =20 ftmp =3D req->rate - fmin; ftmp +=3D clk->info->range.step_size - 1; /* to round up */ - do_div(ftmp, clk->info->range.step_size); + ftmp =3D div64_ul(ftmp, clk->info->range.step_size); =20 req->rate =3D ftmp * clk->info->range.step_size + fmin; =20 --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7BD83FB05C; Fri, 8 May 2026 15:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254416; cv=none; b=GRx7m1iT22AHwwF8eAmMOzwQJpZvsGE7GANL5vnzTsKaWKiByKSgKgMfhVf7xkv9TO9edwRJFH7xpp6miXQ3S1iRNRNY7/rFOiUvO8aAZRfIF3l+7cNRHbwa+4MTencKkRyfBj3SP9eoy9IdMwTETgYLsNQzPP/Xbw8dyXxapoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254416; c=relaxed/simple; bh=FouQA+bv5j1EdgH3z1eqPEIT8/R9xB/bagn+V+J4Zec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=op2zXLrOyFIPMGTe4uewg5OUDO2IdtzvkNWDJ+n0v5cUV9nrrSOLMDX12yu+P1b98hC1A9bFZ+3vnbIzRrrbruvUBfhne/NwbrYDUNEST1JJkdKkL3Z0u4/LHpu76OjgT5fbDIB1ef9wyr3J8TO0pBUxKVktDHc1oDHk/LS5WM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=CkBDpsTP; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="CkBDpsTP" 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 C6325359E; Fri, 8 May 2026 08:33:28 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 743F63F836; Fri, 8 May 2026 08:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254414; bh=FouQA+bv5j1EdgH3z1eqPEIT8/R9xB/bagn+V+J4Zec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CkBDpsTPkap51NtTKTkH61LfsmVJoygGaWWLw8PJ7Vyb/nPrHR7mwKoCQhjuEa2md FwIUj/E+qbclws9F2vloxdYT52jBqVw6HZthpC7ou0JC6lOaOGHkIlFofw422jTZWO RAawwhAvzEzusEPfZE6op+RZxN63fFDL1MkeGxms= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v4 02/15] firmware: arm_scmi: Add clock determine_rate operation Date: Fri, 8 May 2026 16:32:47 +0100 Message-ID: <20260508153300.2224715-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Add a clock operation to help determining the effective rate, closest to the required one, that a specific clock can support. Calculation is currently performed kernel side and the logic is taken directly from the SCMI Clock driver: embedding the determinate rate logic in the protocol layer enables simplifications in the SCMI Clock protocol interface and will more easily accommodate further evolutions where such determine_rate logic into is optionally delegated to the platform SCMI server. Signed-off-by: Cristian Marussi --- v1 --> v2 - use the fixed rounding algo using div64_ul Spoiler alert next SCMI spec will most probably include a new CLOCK_DETERMINE_RATE command to delegate to the platform such calculations, so this clock proto_ops will be needed anyway sooner or later --- drivers/firmware/arm_scmi/clock.c | 42 +++++++++++++++++++++++++++++++ include/linux/scmi_protocol.h | 6 +++++ 2 files changed, 48 insertions(+) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index ab36871650a1..54b55517b759 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -5,6 +5,7 @@ * Copyright (C) 2018-2022 ARM Ltd. */ =20 +#include #include #include #include @@ -624,6 +625,46 @@ static int scmi_clock_rate_set(const struct scmi_proto= col_handle *ph, return ret; } =20 +static int scmi_clock_determine_rate(const struct scmi_protocol_handle *ph, + u32 clk_id, unsigned long *rate) +{ + u64 fmin, fmax, ftmp; + struct scmi_clock_info *clk; + struct clock_info *ci =3D ph->get_priv(ph); + + if (!rate) + return -EINVAL; + + clk =3D scmi_clock_domain_lookup(ci, clk_id); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + /* + * If we can't figure out what rate it will be, so just return the + * rate back to the caller. + */ + if (clk->rate_discrete) + return 0; + + fmin =3D clk->range.min_rate; + fmax =3D clk->range.max_rate; + if (*rate <=3D fmin) { + *rate =3D fmin; + return 0; + } else if (*rate >=3D fmax) { + *rate =3D fmax; + return 0; + } + + ftmp =3D *rate - fmin; + ftmp +=3D clk->range.step_size - 1; /* to round up */ + ftmp =3D div64_ul(ftmp, clk->range.step_size); + + *rate =3D ftmp * clk->range.step_size + fmin; + + return 0; +} + static int scmi_clock_config_set(const struct scmi_protocol_handle *ph, u32 clk_id, enum clk_state state, @@ -936,6 +977,7 @@ static const struct scmi_clk_proto_ops clk_proto_ops = =3D { .info_get =3D scmi_clock_info_get, .rate_get =3D scmi_clock_rate_get, .rate_set =3D scmi_clock_rate_set, + .determine_rate =3D scmi_clock_determine_rate, .enable =3D scmi_clock_enable, .disable =3D scmi_clock_disable, .state_get =3D scmi_clock_state_get, diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index aafaac1496b0..28579c145045 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -91,6 +91,10 @@ enum scmi_clock_oem_config { * @info_get: get the information of the specified clock * @rate_get: request the current clock rate of a clock * @rate_set: set the clock rate of a clock + * @determine_rate: determine the effective rate that can be supported by a + * clock calculating the closest allowed rate. + * Note that @rate is an input/output parameter used both to + * describe the requested rate and report the closest match * @enable: enables the specified clock * @disable: disables the specified clock * @state_get: get the status of the specified clock @@ -108,6 +112,8 @@ struct scmi_clk_proto_ops { u64 *rate); int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id, u64 rate); + int (*determine_rate)(const struct scmi_protocol_handle *ph, u32 clk_id, + unsigned long *rate); int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id, bool atomic); int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id, --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B8DC3FD134; Fri, 8 May 2026 15:33:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254419; cv=none; b=UJkQRkW8U7OyBn1mm+kKPK5iI1kO7XbTMhTwUtU35sEpvT3d/B0Ze7klol7Z37pOnPgk0Hm4NwQPLUTia0SGFBZCJ8BlDiAXSpqS0z9G+qPKBdpZWefCH8SdJBiT3lJAeTNDZ5qvXAhoGr2qZzy3XYOhHCccaGJyQ1TkkJair38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254419; c=relaxed/simple; bh=rgpT6JeYUUTF8dPGQi0+aswaXnBqWOyh+njR4c8YQ2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uhrT2P5zarbjgdXEkKHplzjjhG4FnIOSktAAOQnfr4Eko0CeEep8yMp7J+P8TXH33gPkUPeVPkB/ayqh2WHLUpHpNY8zjc4jqxRMBICCkg/DndNBPe6OVWJ6n7rQ1XQQhKGJvbC/HFCDTOAHiNymFqFC2ZUVfuno5EPIgUdaeHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=kIw2Ap/6; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="kIw2Ap/6" 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 6E27B359E; Fri, 8 May 2026 08:33:32 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 77E8F3F836; Fri, 8 May 2026 08:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254417; bh=rgpT6JeYUUTF8dPGQi0+aswaXnBqWOyh+njR4c8YQ2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kIw2Ap/61KRo21Tkwh1A2uyf3Iz/VBqQM0L6YOm3EwB38E0lgrOuMb0ZD2KvNURrT gs1rG6dhWjwp7kDVtli+ZKb2Dw9XRC0rmc1bSz96jbOta+TFeNFN3kkeVRhaWPN7Iv 9YjMSo1mlJr5Kv0Y1Tv0YaDmj7pyv1C1SHwzIA+4= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Brian Masney , Michael Turquette , Stephen Boyd Subject: [PATCH v4 03/15] clk: scmi: Use new determine_rate clock operation Date: Fri, 8 May 2026 16:32:48 +0100 Message-ID: <20260508153300.2224715-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Use the Clock protocol layer determine_rate logic to calculate the closest rate that can be supported by a specific clock. No functional change. Cc: Brian Masney Cc: Michael Turquette Cc: Stephen Boyd Cc: linux-clk@vger.kernel.org Signed-off-by: Cristian Marussi Reviewed-by: Brian Masney --- @brian: I'd modify further this clk-scmi driver, with a patch on top of this series, to properly use your new CLK_ROUNDING_NOOP flag once your series AND another (already reviewed) series on clk-scmi from Peng are in. --- drivers/clk/clk-scmi.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index b6a12f3bc123..c223e4ef1dd1 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include =20 @@ -57,35 +56,17 @@ static unsigned long scmi_clk_recalc_rate(struct clk_hw= *hw, static int scmi_clk_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { - u64 fmin, fmax, ftmp; + int ret; struct scmi_clk *clk =3D to_scmi_clk(hw); =20 /* - * We can't figure out what rate it will be, so just return the - * rate back to the caller. scmi_clk_recalc_rate() will be called - * after the rate is set and we'll know what rate the clock is + * If we could not get a better rate scmi_clk_recalc_rate() will be + * called after the rate is set and we'll know what rate the clock is * running at then. */ - if (clk->info->rate_discrete) - return 0; - - fmin =3D clk->info->range.min_rate; - fmax =3D clk->info->range.max_rate; - if (req->rate <=3D fmin) { - req->rate =3D fmin; - - return 0; - } else if (req->rate >=3D fmax) { - req->rate =3D fmax; - - return 0; - } - - ftmp =3D req->rate - fmin; - ftmp +=3D clk->info->range.step_size - 1; /* to round up */ - ftmp =3D div64_ul(ftmp, clk->info->range.step_size); - - req->rate =3D ftmp * clk->info->range.step_size + fmin; + ret =3D scmi_proto_clk_ops->determine_rate(clk->ph, clk->id, &req->rate); + if (ret) + return ret; =20 return 0; } --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB1493FD155; Fri, 8 May 2026 15:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254423; cv=none; b=RyB1ZDokT9kf4H9nI45G1qpNbsBJh+0VpYNIbiTymXQKBDt+TG+l08hdMb4dUrI13p4x1eCjr1bLEi1uDg4xTO9C1L0Eu6huWpHSx7rYOI3ze6T7BB5qWcuLFMAulEcSVosI7uqgfCds7L/wscs9rC32Yzc17XY1f3hjt4dAt5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254423; c=relaxed/simple; bh=3PpAaUWJz5Jjai21GNJJLV+2UFa/r2ZvY9KI4xPqbu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=isqVYQIaKmxTCo+Inoyi9BaFvdN3rz/BeWGVLlOehhb+m8hfixWPyHXhzjhqPzfBkeS37WFpGyDR+bHbcycBBqLvS3+zowA0oloS48S28xVAmxBexfAizCTVnWRIqKcZp6D54HIcbHA7iOWPibpYdmUntUHEfyiK+j9+LOJaCpc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=AzLZ6be2; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="AzLZ6be2" 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 BCDB735A3; Fri, 8 May 2026 08:33:35 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 242DF3F836; Fri, 8 May 2026 08:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254421; bh=3PpAaUWJz5Jjai21GNJJLV+2UFa/r2ZvY9KI4xPqbu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AzLZ6be2pedvCNNJIDR6AwOv60RWZOuITtb8rydrMEo/l289OmIF9Jlg1k+v54X7w PTOGR+GOg+VElvaOTPRwmhWmZD1sZf+brA+tP5tDyT3mZym5PGm1Kzh8WLcRw3UdsK AYdrmSTLKMPMScBV2J8q8gZjCqfB3khJldMUfgYU= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Peng Fan Subject: [PATCH v4 04/15] firmware: arm_scmi: Simplify clock rates exposed interface Date: Fri, 8 May 2026 16:32:49 +0100 Message-ID: <20260508153300.2224715-5-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Introduce a new internal struct scmi_clock_desc so as to be able to hide, in the future, some of the needlessly public fields currently kept inside scmi_clock_info, while keeping exposed only the two new min_rate and max_rate fields for each clock. No functional change. Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi --- v1 --> v2 - removed useless parenthesis - reworded comit message --- drivers/firmware/arm_scmi/clock.c | 145 +++++++++++++++--------------- include/linux/scmi_protocol.h | 2 + 2 files changed, 74 insertions(+), 73 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 54b55517b759..467b13a3a18f 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -157,13 +157,27 @@ struct scmi_clock_rate_notify_payld { __le32 rate_high; }; =20 +struct scmi_clock_desc { + u32 id; + bool rate_discrete; + unsigned int num_rates; + u64 rates[SCMI_MAX_NUM_RATES]; +#define RATE_MIN 0 +#define RATE_MAX 1 +#define RATE_STEP 2 + struct scmi_clock_info info; +}; + +#define to_desc(p) (container_of(p, struct scmi_clock_desc, info)) + struct clock_info { int num_clocks; int max_async_req; bool notify_rate_changed_cmd; bool notify_rate_change_requested_cmd; atomic_t cur_async_req; - struct scmi_clock_info *clk; + struct scmi_clock_desc *clkds; +#define CLOCK_INFO(c, i) (&(((c)->clkds + (i))->info)) int (*clock_config_set)(const struct scmi_protocol_handle *ph, u32 clk_id, enum clk_state state, enum scmi_clock_oem_config oem_type, @@ -185,7 +199,7 @@ scmi_clock_domain_lookup(struct clock_info *ci, u32 clk= _id) if (clk_id >=3D ci->num_clocks) return ERR_PTR(-EINVAL); =20 - return ci->clk + clk_id; + return CLOCK_INFO(ci, clk_id); } =20 static int @@ -226,8 +240,7 @@ scmi_clock_protocol_attributes_get(const struct scmi_pr= otocol_handle *ph, =20 struct scmi_clk_ipriv { struct device *dev; - u32 clk_id; - struct scmi_clock_info *clk; + struct scmi_clock_desc *clkd; }; =20 static void iter_clk_possible_parents_prepare_message(void *message, unsig= ned int desc_index, @@ -236,7 +249,7 @@ static void iter_clk_possible_parents_prepare_message(v= oid *message, unsigned in struct scmi_msg_clock_possible_parents *msg =3D message; const struct scmi_clk_ipriv *p =3D priv; =20 - msg->id =3D cpu_to_le32(p->clk_id); + msg->id =3D cpu_to_le32(p->clkd->id); /* Set the number of OPPs to be skipped/already read */ msg->skip_parents =3D cpu_to_le32(desc_index); } @@ -246,7 +259,6 @@ static int iter_clk_possible_parents_update_state(struc= t scmi_iterator_state *st { const struct scmi_msg_resp_clock_possible_parents *r =3D response; struct scmi_clk_ipriv *p =3D priv; - struct device *dev =3D ((struct scmi_clk_ipriv *)p)->dev; u32 flags; =20 flags =3D le32_to_cpu(r->num_parent_flags); @@ -258,12 +270,13 @@ static int iter_clk_possible_parents_update_state(str= uct scmi_iterator_state *st * assume it's returned+remaining on first call. */ if (!st->max_resources) { - p->clk->num_parents =3D st->num_returned + st->num_remaining; - p->clk->parents =3D devm_kcalloc(dev, p->clk->num_parents, - sizeof(*p->clk->parents), - GFP_KERNEL); - if (!p->clk->parents) { - p->clk->num_parents =3D 0; + p->clkd->info.num_parents =3D st->num_returned + st->num_remaining; + p->clkd->info.parents =3D devm_kcalloc(p->dev, + p->clkd->info.num_parents, + sizeof(*p->clkd->info.parents), + GFP_KERNEL); + if (!p->clkd->info.parents) { + p->clkd->info.num_parents =3D 0; return -ENOMEM; } st->max_resources =3D st->num_returned + st->num_remaining; @@ -280,29 +293,27 @@ static int iter_clk_possible_parents_process_response= (const struct scmi_protocol const struct scmi_msg_resp_clock_possible_parents *r =3D response; struct scmi_clk_ipriv *p =3D priv; =20 - u32 *parent =3D &p->clk->parents[st->desc_index + st->loop_idx]; + u32 *parent =3D &p->clkd->info.parents[st->desc_index + st->loop_idx]; =20 *parent =3D le32_to_cpu(r->possible_parents[st->loop_idx]); =20 return 0; } =20 -static int scmi_clock_possible_parents(const struct scmi_protocol_handle *= ph, u32 clk_id, - struct scmi_clock_info *clk) +static int scmi_clock_possible_parents(const struct scmi_protocol_handle *= ph, + u32 clk_id, struct clock_info *cinfo) { struct scmi_iterator_ops ops =3D { .prepare_message =3D iter_clk_possible_parents_prepare_message, .update_state =3D iter_clk_possible_parents_update_state, .process_response =3D iter_clk_possible_parents_process_response, }; - + struct scmi_clock_desc *clkd =3D &cinfo->clkds[clk_id]; struct scmi_clk_ipriv ppriv =3D { - .clk_id =3D clk_id, - .clk =3D clk, + .clkd =3D clkd, .dev =3D ph->dev, }; void *iter; - int ret; =20 iter =3D ph->hops->iter_response_init(ph, &ops, 0, CLOCK_POSSIBLE_PARENTS_GET, @@ -311,9 +322,7 @@ static int scmi_clock_possible_parents(const struct scm= i_protocol_handle *ph, u3 if (IS_ERR(iter)) return PTR_ERR(iter); =20 - ret =3D ph->hops->iter_response_run(iter); - - return ret; + return ph->hops->iter_response_run(iter); } =20 static int @@ -352,7 +361,7 @@ static int scmi_clock_attributes_get(const struct scmi_= protocol_handle *ph, u32 attributes; struct scmi_xfer *t; struct scmi_msg_resp_clock_attributes *attr; - struct scmi_clock_info *clk =3D cinfo->clk + clk_id; + struct scmi_clock_info *clk =3D CLOCK_INFO(cinfo, clk_id); =20 ret =3D ph->xops->xfer_get_init(ph, CLOCK_ATTRIBUTES, sizeof(clk_id), sizeof(*attr), &t); @@ -394,7 +403,7 @@ static int scmi_clock_attributes_get(const struct scmi_= protocol_handle *ph, clk->rate_change_requested_notifications =3D true; if (PROTOCOL_REV_MAJOR(ph->version) >=3D 0x3) { if (SUPPORTS_PARENT_CLOCK(attributes)) - scmi_clock_possible_parents(ph, clk_id, clk); + scmi_clock_possible_parents(ph, clk_id, cinfo); if (SUPPORTS_GET_PERMISSIONS(attributes)) scmi_clock_get_permissions(ph, clk_id, clk); if (SUPPORTS_EXTENDED_CONFIG(attributes)) @@ -424,7 +433,7 @@ static void iter_clk_describe_prepare_message(void *mes= sage, struct scmi_msg_clock_describe_rates *msg =3D message; const struct scmi_clk_ipriv *p =3D priv; =20 - msg->id =3D cpu_to_le32(p->clk_id); + msg->id =3D cpu_to_le32(p->clkd->id); /* Set the number of rates to be skipped/already read */ msg->rate_index =3D cpu_to_le32(desc_index); } @@ -457,14 +466,14 @@ iter_clk_describe_update_state(struct scmi_iterator_s= tate *st, flags =3D le32_to_cpu(r->num_rates_flags); st->num_remaining =3D NUM_REMAINING(flags); st->num_returned =3D NUM_RETURNED(flags); - p->clk->rate_discrete =3D RATE_DISCRETE(flags); + p->clkd->rate_discrete =3D RATE_DISCRETE(flags); =20 /* Warn about out of spec replies ... */ - if (!p->clk->rate_discrete && + if (!p->clkd->rate_discrete && (st->num_returned !=3D 3 || st->num_remaining !=3D 0)) { dev_warn(p->dev, "Out-of-spec CLOCK_DESCRIBE_RATES reply for %s - returned:%d remaining= :%d rx_len:%zd\n", - p->clk->name, st->num_returned, st->num_remaining, + p->clkd->info.name, st->num_returned, st->num_remaining, st->rx_len); =20 SCMI_QUIRK(clock_rates_triplet_out_of_spec, @@ -479,38 +488,19 @@ iter_clk_describe_process_response(const struct scmi_= protocol_handle *ph, const void *response, struct scmi_iterator_state *st, void *priv) { - int ret =3D 0; struct scmi_clk_ipriv *p =3D priv; const struct scmi_msg_resp_clock_describe_rates *r =3D response; =20 - if (!p->clk->rate_discrete) { - switch (st->desc_index + st->loop_idx) { - case 0: - p->clk->range.min_rate =3D RATE_TO_U64(r->rate[0]); - break; - case 1: - p->clk->range.max_rate =3D RATE_TO_U64(r->rate[1]); - break; - case 2: - p->clk->range.step_size =3D RATE_TO_U64(r->rate[2]); - break; - default: - ret =3D -EINVAL; - break; - } - } else { - u64 *rate =3D &p->clk->list.rates[st->desc_index + st->loop_idx]; + p->clkd->rates[st->desc_index + st->loop_idx] =3D + RATE_TO_U64(r->rate[st->loop_idx]); + p->clkd->num_rates++; =20 - *rate =3D RATE_TO_U64(r->rate[st->loop_idx]); - p->clk->list.num_rates++; - } - - return ret; + return 0; } =20 static int scmi_clock_describe_rates_get(const struct scmi_protocol_handle *ph, u32 c= lk_id, - struct scmi_clock_info *clk) + struct clock_info *cinfo) { int ret; void *iter; @@ -519,9 +509,9 @@ scmi_clock_describe_rates_get(const struct scmi_protoco= l_handle *ph, u32 clk_id, .update_state =3D iter_clk_describe_update_state, .process_response =3D iter_clk_describe_process_response, }; + struct scmi_clock_desc *clkd =3D &cinfo->clkds[clk_id]; struct scmi_clk_ipriv cpriv =3D { - .clk_id =3D clk_id, - .clk =3D clk, + .clkd =3D clkd, .dev =3D ph->dev, }; =20 @@ -536,16 +526,23 @@ scmi_clock_describe_rates_get(const struct scmi_proto= col_handle *ph, u32 clk_id, if (ret) return ret; =20 - if (!clk->rate_discrete) { + /* empty set ? */ + if (!clkd->num_rates) + return 0; + + if (!clkd->rate_discrete) { + clkd->info.max_rate =3D clkd->rates[RATE_MAX]; dev_dbg(ph->dev, "Min %llu Max %llu Step %llu Hz\n", - clk->range.min_rate, clk->range.max_rate, - clk->range.step_size); - } else if (clk->list.num_rates) { - sort(clk->list.rates, clk->list.num_rates, - sizeof(clk->list.rates[0]), rate_cmp_func, NULL); + clkd->rates[RATE_MIN], clkd->rates[RATE_MAX], + clkd->rates[RATE_STEP]); + } else { + sort(clkd->rates, clkd->num_rates, + sizeof(clkd->rates[0]), rate_cmp_func, NULL); + clkd->info.max_rate =3D clkd->rates[clkd->num_rates - 1]; } + clkd->info.min_rate =3D clkd->rates[RATE_MIN]; =20 - return ret; + return 0; } =20 static int @@ -630,6 +627,7 @@ static int scmi_clock_determine_rate(const struct scmi_= protocol_handle *ph, { u64 fmin, fmax, ftmp; struct scmi_clock_info *clk; + struct scmi_clock_desc *clkd; struct clock_info *ci =3D ph->get_priv(ph); =20 if (!rate) @@ -639,15 +637,17 @@ static int scmi_clock_determine_rate(const struct scm= i_protocol_handle *ph, if (IS_ERR(clk)) return PTR_ERR(clk); =20 + clkd =3D to_desc(clk); + /* * If we can't figure out what rate it will be, so just return the * rate back to the caller. */ - if (clk->rate_discrete) + if (clkd->rate_discrete) return 0; =20 - fmin =3D clk->range.min_rate; - fmax =3D clk->range.max_rate; + fmin =3D clk->min_rate; + fmax =3D clk->max_rate; if (*rate <=3D fmin) { *rate =3D fmin; return 0; @@ -657,10 +657,10 @@ static int scmi_clock_determine_rate(const struct scm= i_protocol_handle *ph, } =20 ftmp =3D *rate - fmin; - ftmp +=3D clk->range.step_size - 1; /* to round up */ - ftmp =3D div64_ul(ftmp, clk->range.step_size); + ftmp +=3D clkd->rates[RATE_STEP] - 1; /* to round up */ + ftmp =3D div64_ul(ftmp, clkd->rates[RATE_STEP]); =20 - *rate =3D ftmp * clk->range.step_size + fmin; + *rate =3D ftmp * clkd->rates[RATE_STEP] + fmin; =20 return 0; } @@ -1122,17 +1122,16 @@ static int scmi_clock_protocol_init(const struct sc= mi_protocol_handle *ph) if (ret) return ret; =20 - cinfo->clk =3D devm_kcalloc(ph->dev, cinfo->num_clocks, - sizeof(*cinfo->clk), GFP_KERNEL); - if (!cinfo->clk) + cinfo->clkds =3D devm_kcalloc(ph->dev, cinfo->num_clocks, + sizeof(*cinfo->clkds), GFP_KERNEL); + if (!cinfo->clkds) return -ENOMEM; =20 for (clkid =3D 0; clkid < cinfo->num_clocks; clkid++) { - struct scmi_clock_info *clk =3D cinfo->clk + clkid; - + cinfo->clkds[clkid].id =3D clkid; ret =3D scmi_clock_attributes_get(ph, clkid, cinfo); if (!ret) - scmi_clock_describe_rates_get(ph, clkid, clk); + scmi_clock_describe_rates_get(ph, clkid, cinfo); } =20 if (PROTOCOL_REV_MAJOR(ph->version) >=3D 0x3) { diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 28579c145045..7283302b0c85 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -51,6 +51,8 @@ struct scmi_clock_info { bool rate_ctrl_forbidden; bool parent_ctrl_forbidden; bool extended_config; + u64 min_rate; + u64 max_rate; union { struct { int num_rates; --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE2F22D0605; Fri, 8 May 2026 15:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254426; cv=none; b=ZJJHJ0mxOLsvfuK9QbiJAd2DT32iFOnCZp4Qr7AJWQ3JJEs8C8uUXBLgGLsx4BohxWOPIpQ+1H5GtnAUtqBsjiRVMmwfPuxAgTp6mXtVZhTbihxSGA16JzajWmHJ8NvSzzrlQ2PmbLfekULUZv0k03UOmmQEiLZhWV7cdVKOZDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254426; c=relaxed/simple; bh=AxDBdwk/l4DP4oCMpuyPHG7biswl244Z7Wb0hlRCNKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nvEI7aPvZwZ1Gm9HzaKtfQt29wgpPzb1zz753t83FjEy7nHFPRpY2Oku4NyTojZgfmWXfpgiFyn2WTWdZhYAtifgRUU6eZfaSCxvbRFhD1cJZL1Rcn8aDKhl8+/uuMpUP2hreaorzK0HsMjS1sUMtiP+0W2O/vNznulV8fWfq8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=NcmY0dKo; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="NcmY0dKo" 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 D975335A1; Fri, 8 May 2026 08:33:38 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6A0303F836; Fri, 8 May 2026 08:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254424; bh=AxDBdwk/l4DP4oCMpuyPHG7biswl244Z7Wb0hlRCNKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NcmY0dKovz8e70ZeF/T913vLKpW75cT/hlc79E4C8Q7GquaaXcXhY8NZB/0W5WHUt ixXfTstzv/RfRPzP5zp9M3MD3ZWngMxWBsM59t+1pJNDIms12ghNlSTCuIAHVjTy5F OpyoJL1ALFGmXDpWSvULZungsBFQvNl18snw6Iaw= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Michael Turquette , Stephen Boyd , Peng Fan Subject: [PATCH v4 05/15] clk: scmi: Use new simplified per-clock rate properties Date: Fri, 8 May 2026 16:32:50 +0100 Message-ID: <20260508153300.2224715-6-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Use the new min_rate and max_rate unified properties that provide the proper values without having to consider the clock type. Cc: Michael Turquette Cc: Stephen Boyd Cc: linux-clk@vger.kernel.org Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi Reviewed-by: Brian Masney --- v1 --> v2 - Collected Peng Reviewed-by tag --- drivers/clk/clk-scmi.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index c223e4ef1dd1..7c562559ad8b 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -202,7 +202,6 @@ static int scmi_clk_ops_init(struct device *dev, struct= scmi_clk *sclk, const struct clk_ops *scmi_ops) { int ret; - unsigned long min_rate, max_rate; =20 struct clk_init_data init =3D { .flags =3D CLK_GET_RATE_NOCACHE, @@ -217,20 +216,8 @@ static int scmi_clk_ops_init(struct device *dev, struc= t scmi_clk *sclk, if (ret) return ret; =20 - if (sclk->info->rate_discrete) { - int num_rates =3D sclk->info->list.num_rates; - - if (num_rates <=3D 0) - return -EINVAL; - - min_rate =3D sclk->info->list.rates[0]; - max_rate =3D sclk->info->list.rates[num_rates - 1]; - } else { - min_rate =3D sclk->info->range.min_rate; - max_rate =3D sclk->info->range.max_rate; - } - - clk_hw_set_rate_range(&sclk->hw, min_rate, max_rate); + clk_hw_set_rate_range(&sclk->hw, sclk->info->min_rate, + sclk->info->max_rate); return ret; } =20 --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7A593FBEC2; Fri, 8 May 2026 15:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254429; cv=none; b=BlfkmK1gDrBRjWf/fMOMZRwgGPKHQzHr48Q6U6wnC/BeM0YuuQFI+UUvqTrwkBGVsE21IFMOY5v+p592cFIEgBwLXVnA1HtFVfmmwWjr/+6b2S2beeudeuXDmeZieGIEctrAIXghv/Q+85U3umyShB0CNG/iOYcbGYqRTqULSiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254429; c=relaxed/simple; bh=O+pJK9yNpRW7ElmpapJx6mgOnLh69isNLEWDe2uLoJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNNw3uE41+2aYA/tAVKhCNlNlHO1vGGy1EjojMn/z8em0jVzlHNkvOl69Ml5jWNo1kCiJkyLVMobceSTqmIvtRaFuHw9vWZaecVRvi33R/LU4ohahKgwhoclTB2BC1BF0t1CgoBHkQ5Itma4up1TQuw0tz4xo1RO7lqJEOW0CXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Tw2Buhxn; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Tw2Buhxn" 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 E0E2B359E; Fri, 8 May 2026 08:33:41 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8853F3F836; Fri, 8 May 2026 08:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254427; bh=O+pJK9yNpRW7ElmpapJx6mgOnLh69isNLEWDe2uLoJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tw2Buhxn0MHjpOIImv4BM3iOROyKqlpEtq3DbYhamuHu2Q8jjLyemsJJWOD24tO15 LMHUCFu7LoxQE9MdprABVZx8WWnBIjWhOUTJ7bpvSD68BMxzDXDqyjNdG16nxE51uT Hy2mc4xFghmE16IlJq4YNCcWy7dbK78ca0zqe8v8= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Peng Fan Subject: [PATCH v4 06/15] firmware: arm_scmi: Drop unused clock rate interfaces Date: Fri, 8 May 2026 16:32:51 +0100 Message-ID: <20260508153300.2224715-7-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Only the unified interface exposing min_rate/max_rate is now used. Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi --- v3 --> v4 - Remove also unused public info.rate_discrete [Geert] v1 --> v2 - Collected Peng Reviewed-by tag --- include/linux/scmi_protocol.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 7283302b0c85..19834f85f5d3 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -44,7 +44,6 @@ struct scmi_revision_info { struct scmi_clock_info { char name[SCMI_MAX_STR_SIZE]; unsigned int enable_latency; - bool rate_discrete; bool rate_changed_notifications; bool rate_change_requested_notifications; bool state_ctrl_forbidden; @@ -53,17 +52,6 @@ struct scmi_clock_info { bool extended_config; u64 min_rate; u64 max_rate; - union { - struct { - int num_rates; - u64 rates[SCMI_MAX_NUM_RATES]; - } list; - struct { - u64 min_rate; - u64 max_rate; - u64 step_size; - } range; - }; int num_parents; u32 *parents; }; --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83F9D3FCB30; Fri, 8 May 2026 15:33:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254432; cv=none; b=m4XiCFSFxeLm4An9St67Wn9T2tqOdCretFI59dJ619APQIvogt2j/aJ3uXRx6X39F+KR6+szhzUmvAHEjMIUxlzBicT0/TbxyGXnzMugVbiPwbHyPVdCaR7Owrv4B3jC3rMSkoECzIsnhKqLmvmUc+CYX1I1LgUSYovfwz5XBaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254432; c=relaxed/simple; bh=kM+U8v3f2McW8OM5ONalrhlXqiBSrlQSwzAp9yyXSgY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j7ChK2t6MQAnMnSgUerrS8RufO7Q08tgV5PZxDrXQJoXRDNrO31NZKS/ITHejlB1ap3HLwtGief8nkDgt4bwizpO3Ih/QrASJC7Lskxd/TJcvgqPdYcqAWso0mDvRZfx+LJWQ8u7TJlhZMGbyQsfGNMGnVC7pgsT4qvNyzq3868= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=fxsUPOFg; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="fxsUPOFg" 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 9981F35A1; Fri, 8 May 2026 08:33:44 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8C70A3F836; Fri, 8 May 2026 08:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254430; bh=kM+U8v3f2McW8OM5ONalrhlXqiBSrlQSwzAp9yyXSgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fxsUPOFghTDuToJOqTOpKu4knl7XZGgMLInPrcTVOQcChZ64SAp5uO+NuHmz9yhuc dn8mHWAVYwVBGU9Wr4TlBt6ADjNRMDVBvpi/onU6pOvNGbpzAMMzBx4AabhsmoKfUb /iwszYNeKqYioM0MiuhtZVvJLNL3q6TbM/CvuWoU= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Peng Fan Subject: [PATCH v4 07/15] firmware: arm_scmi: Make clock rates allocation dynamic Date: Fri, 8 May 2026 16:32:52 +0100 Message-ID: <20260508153300.2224715-8-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Leveraging SCMI Clock protocol dynamic discovery capabilities, move away from the static per-clock rates allocation model in favour of a dynamic runtime allocation based on effectively discovered resources. No functional change. Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi --- v2 --> v3 - collected Review-by tags --- drivers/firmware/arm_scmi/clock.c | 19 ++++++++++++++++--- include/linux/scmi_protocol.h | 1 - 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 467b13a3a18f..c9b62edce4fd 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -161,7 +161,7 @@ struct scmi_clock_desc { u32 id; bool rate_discrete; unsigned int num_rates; - u64 rates[SCMI_MAX_NUM_RATES]; + u64 *rates; #define RATE_MIN 0 #define RATE_MAX 1 #define RATE_STEP 2 @@ -480,6 +480,18 @@ iter_clk_describe_update_state(struct scmi_iterator_st= ate *st, QUIRK_OUT_OF_SPEC_TRIPLET); } =20 + if (!st->max_resources) { + int num_rates =3D st->num_returned + st->num_remaining; + + p->clkd->rates =3D devm_kcalloc(p->dev, num_rates, + sizeof(*p->clkd->rates), GFP_KERNEL); + if (!p->clkd->rates) + return -ENOMEM; + + /* max_resources is used by the iterators to control bounds */ + st->max_resources =3D st->num_returned + st->num_remaining; + } + return 0; } =20 @@ -493,6 +505,8 @@ iter_clk_describe_process_response(const struct scmi_pr= otocol_handle *ph, =20 p->clkd->rates[st->desc_index + st->loop_idx] =3D RATE_TO_U64(r->rate[st->loop_idx]); + + /* Count only effectively discovered rates */ p->clkd->num_rates++; =20 return 0; @@ -515,8 +529,7 @@ scmi_clock_describe_rates_get(const struct scmi_protoco= l_handle *ph, u32 clk_id, .dev =3D ph->dev, }; =20 - iter =3D ph->hops->iter_response_init(ph, &ops, SCMI_MAX_NUM_RATES, - CLOCK_DESCRIBE_RATES, + iter =3D ph->hops->iter_response_init(ph, &ops, 0, CLOCK_DESCRIBE_RATES, sizeof(struct scmi_msg_clock_describe_rates), &cpriv); if (IS_ERR(iter)) diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 19834f85f5d3..0824a7dc4aae 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -15,7 +15,6 @@ =20 #define SCMI_MAX_STR_SIZE 64 #define SCMI_SHORT_NAME_MAX_SIZE 16 -#define SCMI_MAX_NUM_RATES 16 =20 /** * struct scmi_revision_info - version information structure --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEEDC3FD14B; Fri, 8 May 2026 15:33:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254435; cv=none; b=Yv/akqmjyVOC0pPefXq10jtkrR4oeYfG+Rw2IOSKO5FqN/rpEqHt14ix6sV6PXNq6bL/IZmkC63heqIOAkOJ+2/IncLkuEoadb8H5AVNxoWRR0Meu27BqAHCN3YU4lK7AMiJXcV5ThJGjJ3L7XN8BvnoOm+7Yhpz1bYuv+rrbkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254435; c=relaxed/simple; bh=FCP9MWDXBkmpmaTgWI8hodUMzwfIaYuwHBhh3J2kcKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iAN1CkVEtW0mCHkh75F6OR6+lNlfYE0vxxeYF5TqTTLid1M1sp1JyzULzCExjE6qvUo0C333bX87dc6EHsGsGgFYNQbmloBX5QSxFdIYmUq6i1MOz6qhnnfryFfDmkjkkH0Czt94y7TszaDvcun9Sl+83YOhazjdHN5r8fOmTVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=We8gpuWM; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="We8gpuWM" 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 B3AC935A2; Fri, 8 May 2026 08:33:47 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 46A623F836; Fri, 8 May 2026 08:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254433; bh=FCP9MWDXBkmpmaTgWI8hodUMzwfIaYuwHBhh3J2kcKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=We8gpuWMVkDmHnui9cmKinnAybqTZNAuKe+hyKXmEsKxKkZEsuPfoOdu5c0DU93NO WNTj7334SG2qs33M4ExZ26Oqu5x7SVvEJjCaDgH21wvTAQnK0HeEQdIauMrEfFf7S1 drGlI6jSs+Nfr0IQtbdqdRLaNOUVR8VCtfXTA/Ao= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Peng Fan Subject: [PATCH v4 08/15] firmware: arm_scmi: Harden clock parents discovery Date: Fri, 8 May 2026 16:32:53 +0100 Message-ID: <20260508153300.2224715-9-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Fix clock parents enumeration to account only for effectively discovered parents during enumeration, avoiding to trust the total number of parents declared upfront by the platform. Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi --- v2 --> v3 - collected Reviewed-by tags --- drivers/firmware/arm_scmi/clock.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index c9b62edce4fd..d07cfef243fd 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -270,15 +270,15 @@ static int iter_clk_possible_parents_update_state(str= uct scmi_iterator_state *st * assume it's returned+remaining on first call. */ if (!st->max_resources) { - p->clkd->info.num_parents =3D st->num_returned + st->num_remaining; - p->clkd->info.parents =3D devm_kcalloc(p->dev, - p->clkd->info.num_parents, + int num_parents =3D st->num_returned + st->num_remaining; + + p->clkd->info.parents =3D devm_kcalloc(p->dev, num_parents, sizeof(*p->clkd->info.parents), GFP_KERNEL); - if (!p->clkd->info.parents) { - p->clkd->info.num_parents =3D 0; + if (!p->clkd->info.parents) return -ENOMEM; - } + + /* max_resources is used by the iterators to control bounds */ st->max_resources =3D st->num_returned + st->num_remaining; } =20 @@ -293,9 +293,11 @@ static int iter_clk_possible_parents_process_response(= const struct scmi_protocol const struct scmi_msg_resp_clock_possible_parents *r =3D response; struct scmi_clk_ipriv *p =3D priv; =20 - u32 *parent =3D &p->clkd->info.parents[st->desc_index + st->loop_idx]; + p->clkd->info.parents[st->desc_index + st->loop_idx] =3D + le32_to_cpu(r->possible_parents[st->loop_idx]); =20 - *parent =3D le32_to_cpu(r->possible_parents[st->loop_idx]); + /* Count only effectively discovered parents */ + p->clkd->info.num_parents++; =20 return 0; } --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D3CB3FA5CD; Fri, 8 May 2026 15:33:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254438; cv=none; b=P78TjkjHUcxueYMxxFlQj/1SA79GDyFXeugKL1e8AfnDFQ3Y/5SezXtH8G735cfTLTn8Tc0mi6zBalwwFxxJgiGIR3Y6LLH40LL7FqbrV/WhzvNGFTD8riQAqbY61y3tNQYXgFLAHfcEJYgUxZaGWjL6Pq51UppLSvvGVqHct4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254438; c=relaxed/simple; bh=ydGSxVs7029/nGMXlye2/Mws9V6mzCtDA5RxCjGimS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ph5LMmEcP4aFq6oVhH3ECNeoH3/+LMH/U7i63LtV9fOKQ1+eFUEuLoU2QRwIBO4hKDroAGK2IDLBamR9yRQTxZJkg9VTT6GDFdqN5MhOowOlxKC0kwDTcBWZE9H+bVVZ/iDZADhTyD+VfHDMoZsVTiaDMWRB9TeFAryXm27AZTw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Yz/qTQTK; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Yz/qTQTK" 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 9E0E135A1; Fri, 8 May 2026 08:33:50 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5E6263F836; Fri, 8 May 2026 08:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254436; bh=ydGSxVs7029/nGMXlye2/Mws9V6mzCtDA5RxCjGimS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yz/qTQTKDRhTDFIc+YzNOod0joPX17wVBI60FSc6Jv0ijYAoeY/ZASEY/vu4eLhSK y3svLpyl56vJ2xw0x32YOeoeOAcG/FtIy2jnlhwtb8iNGyu21t7QpL6mMEfb0LHWJt Kyy91DOG3iLTocJHV3C8vogOga67rh4iKj1ZpDuQ= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Peng Fan Subject: [PATCH v4 09/15] firmware: arm_scmi: Refactor iterators internal allocation Date: Fri, 8 May 2026 16:32:54 +0100 Message-ID: <20260508153300.2224715-10-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Use cleanup handlers to manage iterator data structures. No functional change. Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi --- v2 --> v3 - collected Reviewed tags --- drivers/firmware/arm_scmi/driver.c | 35 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index f167194f7cf6..66cb64c8ed3d 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -17,6 +17,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 #include +#include #include #include #include @@ -1789,39 +1790,41 @@ static void *scmi_iterator_init(const struct scmi_p= rotocol_handle *ph, size_t tx_size, void *priv) { int ret; - struct scmi_iterator *i; =20 - i =3D devm_kzalloc(ph->dev, sizeof(*i), GFP_KERNEL); + struct scmi_iterator *i __free(kfree) =3D kzalloc(sizeof(*i), GFP_KERNEL); if (!i) return ERR_PTR(-ENOMEM); =20 + if (!ops || !ph) + return ERR_PTR(-EINVAL); + i->ph =3D ph; i->ops =3D ops; i->priv =3D priv; =20 ret =3D ph->xops->xfer_get_init(ph, msg_id, tx_size, 0, &i->t); - if (ret) { - devm_kfree(ph->dev, i); + if (ret) return ERR_PTR(ret); - } =20 i->state.max_resources =3D max_resources; i->msg =3D i->t->tx.buf; i->resp =3D i->t->rx.buf; =20 - return i; + return no_free_ptr(i); } =20 static int scmi_iterator_run(void *iter) { - int ret =3D -EINVAL; + int ret; struct scmi_iterator_ops *iops; const struct scmi_protocol_handle *ph; struct scmi_iterator_state *st; - struct scmi_iterator *i =3D iter; =20 - if (!i || !i->ops || !i->ph) - return ret; + if (!iter) + return -EINVAL; + + /* Take ownership of the iterator */ + struct scmi_iterator *i __free(kfree) =3D iter; =20 iops =3D i->ops; ph =3D i->ph; @@ -1846,12 +1849,12 @@ static int scmi_iterator_run(void *iter) break; } =20 - for (st->loop_idx =3D 0; st->loop_idx < st->num_returned; - st->loop_idx++) { + for (st->loop_idx =3D 0; !ret && st->loop_idx < st->num_returned; + st->loop_idx++) ret =3D iops->process_response(ph, i->resp, st, i->priv); - if (ret) - goto out; - } + + if (ret) + break; =20 st->desc_index +=3D st->num_returned; ph->xops->reset_rx_to_maxsz(ph, i->t); @@ -1861,10 +1864,8 @@ static int scmi_iterator_run(void *iter) */ } while (st->num_returned && st->num_remaining); =20 -out: /* Finalize and destroy iterator */ ph->xops->xfer_put(ph, i->t); - devm_kfree(ph->dev, i); =20 return ret; } --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D701D3FE346; Fri, 8 May 2026 15:33:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254441; cv=none; b=rdV0Ih5W6sbtxtO0A5AUApi2jw91X3QclD1f+wMnHVgqyw/CKrXK1uHApfbFX5h4LF4WbungXEzQhj6z7DgU9mOPqldUfa9vfJ+cIn03pzxMphONhQwcHhB7XmASSE04qPR4jdyM5MNAe0IjGvcucJpw0P0nz1t9TZ6ShckyV6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254441; c=relaxed/simple; bh=K7PZn6YSuIfgQkzQTbiCZFkzHkWlX1uWSHiLxI+Ap24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UsPP6tvwZU4w/wcTzFYQg+0xq0mDT5lklSlUMoYwiKRm95EGAt5Bxj4+ak8ayEjushZ0iwhv5uSbCpjlNsDWaJjClsebkcupnEWe36NIIpJ1ysOgiFxWU3K+d3FN8TfWSYaSqjNaNa0m+cMLbc4no07wk0JbKFRFedL960AIxU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=TkrMnpo5; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="TkrMnpo5" 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 E5E31359E; Fri, 8 May 2026 08:33:53 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4EE113F836; Fri, 8 May 2026 08:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254439; bh=K7PZn6YSuIfgQkzQTbiCZFkzHkWlX1uWSHiLxI+Ap24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TkrMnpo5Sdj88m1sj7xx+mNNfiz9+DqtqpFvBWn78XncUY/jhfdAqwG0kC62M//Ij g5sjyqF/9mYjTTvltzXci4skoD0Z7+SSOmxM8wcag/07tcpOQhx3Vfz+lFb8QXFh33 hwcmSKr9IoMbx0dP1lqVzcIbvaRxvGDYAqPEgxNo= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v4 10/15] firmware: arm_scmi: Add bound iterators support Date: Fri, 8 May 2026 16:32:55 +0100 Message-ID: <20260508153300.2224715-11-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" SCMI core stack provides some common helpers to handle in a unified way multipart message replies: such iterator-helpers, when run, currently process by default the whole set of discovered resources. Introduce an alternative way to run the initialized iterator on a limited range of resources. Note that the subset of resources that can be chosen is anyway limited by the SCMI protocol specification, since you are only allowed to choose the start-index on a multi-part enumeration NOT the end-index, so that the effective number of returned items by a bound iterators depends really on platform side decisions. Suggested-by: Etienne Carriere Signed-off-by: Cristian Marussi --- v2 --> v3 - fixed typos in commit message --- drivers/firmware/arm_scmi/clock.c | 3 +- drivers/firmware/arm_scmi/driver.c | 58 +++++++++++++++++++-------- drivers/firmware/arm_scmi/protocols.h | 13 +++++- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index d07cfef243fd..8ce889dfc87b 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -505,8 +505,7 @@ iter_clk_describe_process_response(const struct scmi_pr= otocol_handle *ph, struct scmi_clk_ipriv *p =3D priv; const struct scmi_msg_resp_clock_describe_rates *r =3D response; =20 - p->clkd->rates[st->desc_index + st->loop_idx] =3D - RATE_TO_U64(r->rate[st->loop_idx]); + p->clkd->rates[p->clkd->num_rates] =3D RATE_TO_U64(r->rate[st->loop_idx]); =20 /* Count only effectively discovered rates */ p->clkd->num_rates++; diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index 66cb64c8ed3d..cb4865fd8af2 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1813,48 +1813,50 @@ static void *scmi_iterator_init(const struct scmi_p= rotocol_handle *ph, return no_free_ptr(i); } =20 -static int scmi_iterator_run(void *iter) +static int __scmi_iterator_run(void *iter, unsigned int *start, unsigned i= nt *end) { int ret; struct scmi_iterator_ops *iops; const struct scmi_protocol_handle *ph; struct scmi_iterator_state *st; + struct scmi_iterator *i; =20 if (!iter) return -EINVAL; =20 - /* Take ownership of the iterator */ - struct scmi_iterator *i __free(kfree) =3D iter; - + i =3D iter; iops =3D i->ops; ph =3D i->ph; st =3D &i->state; =20 + /* Reinitialize state for next run */ + st->num_returned =3D 0; + st->num_remaining =3D 0; + st->desc_index =3D start ? *start : 0; + do { iops->prepare_message(i->msg, st->desc_index, i->priv); ret =3D ph->xops->do_xfer(ph, i->t); if (ret) - break; + return ret; =20 st->rx_len =3D i->t->rx.len; ret =3D iops->update_state(st, i->resp, i->priv); if (ret) - break; + return ret; =20 if (st->num_returned > st->max_resources - st->desc_index) { dev_err(ph->dev, "No. of resources can't exceed %d\n", st->max_resources); - ret =3D -EINVAL; - break; + return -EINVAL; } =20 - for (st->loop_idx =3D 0; !ret && st->loop_idx < st->num_returned; - st->loop_idx++) + for (st->loop_idx =3D 0; st->loop_idx < st->num_returned; st->loop_idx++= ) { ret =3D iops->process_response(ph, i->resp, st, i->priv); - - if (ret) - break; + if (ret) + return ret; + } =20 st->desc_index +=3D st->num_returned; ph->xops->reset_rx_to_maxsz(ph, i->t); @@ -1862,14 +1864,36 @@ static int scmi_iterator_run(void *iter) * check for both returned and remaining to avoid infinite * loop due to buggy firmware */ - } while (st->num_returned && st->num_remaining); + } while (st->num_returned && st->num_remaining && + (!end || (st->desc_index <=3D min(*end, st->max_resources - 1)))); =20 - /* Finalize and destroy iterator */ - ph->xops->xfer_put(ph, i->t); + return 0; +} + +static void scmi_iterator_cleanup(void *iter) +{ + struct scmi_iterator *i =3D iter; + + i->ph->xops->xfer_put(i->ph, i->t); + kfree(i); +} + +static int scmi_iterator_run(void *iter) +{ + int ret; + + ret =3D __scmi_iterator_run(iter, NULL, NULL); + scmi_iterator_cleanup(iter); =20 return ret; } =20 +static int scmi_iterator_run_bound(void *iter, unsigned int *start, + unsigned int *end) +{ + return __scmi_iterator_run(iter, start, end); +} + struct scmi_msg_get_fc_info { __le32 domain; __le32 message_id; @@ -2048,6 +2072,8 @@ static const struct scmi_proto_helpers_ops helpers_op= s =3D { .get_max_msg_size =3D scmi_common_get_max_msg_size, .iter_response_init =3D scmi_iterator_init, .iter_response_run =3D scmi_iterator_run, + .iter_response_run_bound =3D scmi_iterator_run_bound, + .iter_response_cleanup =3D scmi_iterator_cleanup, .protocol_msg_check =3D scmi_protocol_msg_check, .fastchannel_init =3D scmi_common_fastchannel_init, .fastchannel_db_ring =3D scmi_common_fastchannel_db_ring, diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_s= cmi/protocols.h index f51245aca259..e2ef604c16ef 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -259,7 +259,15 @@ struct scmi_fc_info { * multi-part responses using the custom operations * provided in @ops. * @iter_response_run: A common helper to trigger the run of a previously - * initialized iterator. + * initialized iterator. Note that unbound iterators are + * automatically cleaned up. + * @iter_response_run_bound: A common helper to trigger the run of a previ= ously + * initialized iterator, but only within the + * specified, optional, @start and @end resource + * indexes. Note that these bound-iterators need + * explicit cleanup via @iter_response_bound_cleanup. + * @iter_response_bound_cleanup: A common helper to finally release the it= erator + * for bound iterators. * @protocol_msg_check: A common helper to check is a specific protocol me= ssage * is supported. * @fastchannel_init: A common helper used to initialize FC descriptors by @@ -276,6 +284,9 @@ struct scmi_proto_helpers_ops { unsigned int max_resources, u8 msg_id, size_t tx_size, void *priv); int (*iter_response_run)(void *iter); + int (*iter_response_run_bound)(void *iter, + unsigned int *start, unsigned int *end); + void (*iter_response_cleanup)(void *iter); int (*protocol_msg_check)(const struct scmi_protocol_handle *ph, u32 message_id, u32 *attributes); void (*fastchannel_init)(const struct scmi_protocol_handle *ph, --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D29A3FE34F; Fri, 8 May 2026 15:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254443; cv=none; b=btvNoXOQTNnjBCE4g1BI6/e0qz1qJU/nb+5vPBQI5xtv+6N4pb3qFG9/rwLJj94UZi8C8lyhq5CVNoW8kytw6qY9ZuCfYHc22jG/McNrRgUv+G8F+Pd3wcY/sNIFnyLXjC2Iw3SPfv7lp5syGvcPIhtmoOIhAnZeusBAPf7K2jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254443; c=relaxed/simple; bh=jWS2Kp7HvdidNmNl9faasS1wYpc1rAAoOJ7CoT2qcrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sLkYcpbQuK2iFcqteT1O9NBTEYieYJUx9CcrjFAakf1Fpsat4T491ypVKkfgawaE5LsmNrKx7T6eVjiCxnqlYrGsDyVehZLhFqtn5U+YmZEo8FnUhzIUrOudKlofRMHUDzr5dJ+ZI4eNv/avxspObRbKZUCWS9IGPjr4tDTLO+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=dgTQHqZX; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="dgTQHqZX" 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 8DB1735A1; Fri, 8 May 2026 08:33:56 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 90A023F836; Fri, 8 May 2026 08:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254441; bh=jWS2Kp7HvdidNmNl9faasS1wYpc1rAAoOJ7CoT2qcrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dgTQHqZX4JOuHlXa6cwPcadiV1pTY93yfgGft9EA9xyea0fFp36LffE4PNCH7Yh99 5RK/SIJXNZtQmjVN0cBRpIDp5yKKxnSAwE9D9L21SvEE81qMyE96CB0GBuFts0uywZ rPP/jpJWb7SikkdSm3gGaD0rAh85/oUOxz2MtSWI= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v4 11/15] firmware: arm_scmi: Fix bound iterators returning too many items Date: Fri, 8 May 2026 16:32:56 +0100 Message-ID: <20260508153300.2224715-12-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" From: Geert Uytterhoeven When using a bound-iterator with an upper bound, commands are sent, and responses are received, until the upper bound is reached. However, it is up to the SCMI provider implementation to decide how many rates are returned in response to a single CLOCK_DESCRIBE_RATES command. If the last response contains rates beyond the specified upper bound, they are still passed up for further processing. This may lead to buffer overflows in unprepared callsites. While the imprecise bound handling may have been intentional (it was mentioned in the commit message introducing the code), it is still confusing for users, and may cause hard to debug crashes. Fix this by strictly enforcing the upper bound. Note that this may cause an increase in the number of CLOCK_DESCRIBE_RATES commands issued, as retrieving the last rate may no longer be done inadvertentently, but require its own command. Signed-off-by: Geert Uytterhoeven Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index cb4865fd8af2..fd031a8d40df 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1820,6 +1820,7 @@ static int __scmi_iterator_run(void *iter, unsigned i= nt *start, unsigned int *en const struct scmi_protocol_handle *ph; struct scmi_iterator_state *st; struct scmi_iterator *i; + unsigned int n; =20 if (!iter) return -EINVAL; @@ -1852,13 +1853,17 @@ static int __scmi_iterator_run(void *iter, unsigned= int *start, unsigned int *en return -EINVAL; } =20 - for (st->loop_idx =3D 0; st->loop_idx < st->num_returned; st->loop_idx++= ) { + if (end) + n =3D min(st->num_returned, *end - st->desc_index + 1); + else + n =3D st->num_returned; + for (st->loop_idx =3D 0; st->loop_idx < n; st->loop_idx++) { ret =3D iops->process_response(ph, i->resp, st, i->priv); if (ret) return ret; } =20 - st->desc_index +=3D st->num_returned; + st->desc_index +=3D n; ph->xops->reset_rx_to_maxsz(ph, i->t); /* * check for both returned and remaining to avoid infinite --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83A8F3FD13F; Fri, 8 May 2026 15:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254446; cv=none; b=Hhl0SjVKiKLotRfDlZ6Q8Uxbhpk8oCZw/AIMAL6i+fWsSuVwcXbVCCMC/c4aYos/gFSgA2lTa6Nf4Nm2lTxMjvX8ui//nIWpI9wSNOeOGbwgwDTbzGL+diAq72HUhSL9ts6JgnTLFU+aU6JzSvsUId4plEdmmf1v7kh8+1UcQ4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254446; c=relaxed/simple; bh=epQeOAzLViH9FFPlYuAgdsCGyUd9pX7SRAESRVy9dqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GAY6qVmZrHA9OnRMi52VsAxzAThc1WBs9zOXsCo9q9zSTFGAwwZmeJWQAPE98Xu8k1dbwOGvLyKBHVOG8Px5b6PdqfJrZOtc72M1bKi2WpXzXR2SVlcFFMLu22e7Z+Wo6sFUzHMh5MHZhRXpTPhQgphWNuyHm+VhoCsdsZyzOeg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=rfqkI8Nq; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="rfqkI8Nq" 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 7438C359E; Fri, 8 May 2026 08:33:59 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3F6E83F836; Fri, 8 May 2026 08:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254444; bh=epQeOAzLViH9FFPlYuAgdsCGyUd9pX7SRAESRVy9dqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfqkI8Nq6UlZeeK/tYd9uoR9+Uqd7gCciQfS9U4RokHI3yUHF2abPDKMJmpDR/kgI NMJHAYGb0payWN8Zwj5WsOFNuIHDb4jIb5hLyAGxxuhKQKu68EdLfnMJxfBfzBFO8J VuRJAooUIUzLVf9A8nCqydt9+cd4jBpgs5CRpYZY= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v4 12/15] firmware: arm_scmi: Use proper iter_response_bound_cleanup() name Date: Fri, 8 May 2026 16:32:57 +0100 Message-ID: <20260508153300.2224715-13-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" From: Geert Uytterhoeven The documentation speaks of the "iter_response_bound_cleanup()" protocol helper, while the actual helper is called "iter_response_cleanup()". Settle on the former name, because the helper is only needed when using bound-iterators. Signed-off-by: Geert Uytterhoeven Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 6 +++--- drivers/firmware/arm_scmi/protocols.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index fd031a8d40df..57785c0c0424 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1875,7 +1875,7 @@ static int __scmi_iterator_run(void *iter, unsigned i= nt *start, unsigned int *en return 0; } =20 -static void scmi_iterator_cleanup(void *iter) +static void scmi_iterator_bound_cleanup(void *iter) { struct scmi_iterator *i =3D iter; =20 @@ -1888,7 +1888,7 @@ static int scmi_iterator_run(void *iter) int ret; =20 ret =3D __scmi_iterator_run(iter, NULL, NULL); - scmi_iterator_cleanup(iter); + scmi_iterator_bound_cleanup(iter); =20 return ret; } @@ -2078,7 +2078,7 @@ static const struct scmi_proto_helpers_ops helpers_op= s =3D { .iter_response_init =3D scmi_iterator_init, .iter_response_run =3D scmi_iterator_run, .iter_response_run_bound =3D scmi_iterator_run_bound, - .iter_response_cleanup =3D scmi_iterator_cleanup, + .iter_response_bound_cleanup =3D scmi_iterator_bound_cleanup, .protocol_msg_check =3D scmi_protocol_msg_check, .fastchannel_init =3D scmi_common_fastchannel_init, .fastchannel_db_ring =3D scmi_common_fastchannel_db_ring, diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_s= cmi/protocols.h index e2ef604c16ef..15ad5162e37a 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -286,7 +286,7 @@ struct scmi_proto_helpers_ops { int (*iter_response_run)(void *iter); int (*iter_response_run_bound)(void *iter, unsigned int *start, unsigned int *end); - void (*iter_response_cleanup)(void *iter); + void (*iter_response_bound_cleanup)(void *iter); int (*protocol_msg_check)(const struct scmi_protocol_handle *ph, u32 message_id, u32 *attributes); void (*fastchannel_init)(const struct scmi_protocol_handle *ph, --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C73E40242E; Fri, 8 May 2026 15:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254450; cv=none; b=pv4cnhOBONM8AS9RrNf7Dl+EiQlllSrlma87ICIsSyv1KyBONrOwO+DXApBQr0gASjBGjM4oY1yDu9Gf22gpcBUQHM28x/vWamGzsDnrWh5khdioQ4zecK8X/EAfMB+FtX0Pv0bxOwZL2zvYwBJlKSvb3scqANY5keHpiARr8Os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254450; c=relaxed/simple; bh=At/1NpD+zdqtqKE6HMLapbaZvJjKAhoJJTEqLPkqWfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qpdz9UPr68RgK500Vlj1/oDEqametFsyiuPbUm5ICE8fwaZ852bSMelzU4/6OIkkQBv3t3XnlGabxzcasLwXr9yH3srA6upuC4mq4ONXGQgcXRPpGV1LmmctwazwyqhlRFfvS3gW8nC+Vtl/3AXjYDPWZaW3QwPAysTqR9qe1og= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=QZ6TouT3; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="QZ6TouT3" 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 32CBB35A1; Fri, 8 May 2026 08:34:02 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2114F3F836; Fri, 8 May 2026 08:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254447; bh=At/1NpD+zdqtqKE6HMLapbaZvJjKAhoJJTEqLPkqWfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZ6TouT3ZGJ7qEAg8FD3TpLIafElxJjwmuyEGROlbpoHTelSmQwt3xHbAexTMv1dk 2L6z3dliHwtwV0aUvqG+w/ZLWio+J95UzuVfN+njTOvaq6gJimMwPQ/z/P1KJ1Auh1 2r+MPEoumi0f/gpx79hdaUubalaOalb1NO2F2X3w= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v4 13/15] firmware: arm_scmi: Use bound iterators to minimize discovered rates Date: Fri, 8 May 2026 16:32:58 +0100 Message-ID: <20260508153300.2224715-14-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Clock rates are guaranteed to be returned in ascending order for SCMI clock protocol versions greater than 1.0: in such a case, use bounded iterators to minimize the number of message exchanges needed to discover min and max rate. Signed-off-by: Cristian Marussi --- v3 -> v4 - Fixed dev_dbg() to printout tot_rates [Geert] - Fixed broken build by renaming to iterator_bound_cleanup() v1 --> v2 - fixed final ret value in scmi_clock_describe_get --- drivers/firmware/arm_scmi/clock.c | 90 +++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 8ce889dfc87b..955bb9565ce3 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -160,6 +160,7 @@ struct scmi_clock_rate_notify_payld { struct scmi_clock_desc { u32 id; bool rate_discrete; + unsigned int tot_rates; unsigned int num_rates; u64 *rates; #define RATE_MIN 0 @@ -483,15 +484,16 @@ iter_clk_describe_update_state(struct scmi_iterator_s= tate *st, } =20 if (!st->max_resources) { - int num_rates =3D st->num_returned + st->num_remaining; + unsigned int tot_rates =3D st->num_returned + st->num_remaining; =20 - p->clkd->rates =3D devm_kcalloc(p->dev, num_rates, + p->clkd->rates =3D devm_kcalloc(p->dev, tot_rates, sizeof(*p->clkd->rates), GFP_KERNEL); if (!p->clkd->rates) return -ENOMEM; =20 /* max_resources is used by the iterators to control bounds */ - st->max_resources =3D st->num_returned + st->num_remaining; + p->clkd->tot_rates =3D tot_rates; + st->max_resources =3D tot_rates; } =20 return 0; @@ -514,8 +516,8 @@ iter_clk_describe_process_response(const struct scmi_pr= otocol_handle *ph, } =20 static int -scmi_clock_describe_rates_get(const struct scmi_protocol_handle *ph, u32 c= lk_id, - struct clock_info *cinfo) +scmi_clock_describe_rates_get_full(const struct scmi_protocol_handle *ph, + struct scmi_clock_desc *clkd) { int ret; void *iter; @@ -524,7 +526,6 @@ scmi_clock_describe_rates_get(const struct scmi_protoco= l_handle *ph, u32 clk_id, .update_state =3D iter_clk_describe_update_state, .process_response =3D iter_clk_describe_process_response, }; - struct scmi_clock_desc *clkd =3D &cinfo->clkds[clk_id]; struct scmi_clk_ipriv cpriv =3D { .clkd =3D clkd, .dev =3D ph->dev, @@ -544,17 +545,88 @@ scmi_clock_describe_rates_get(const struct scmi_proto= col_handle *ph, u32 clk_id, if (!clkd->num_rates) return 0; =20 + if (clkd->rate_discrete) + sort(clkd->rates, clkd->num_rates, + sizeof(clkd->rates[0]), rate_cmp_func, NULL); + + return 0; +} + +static int +scmi_clock_describe_rates_get_lazy(const struct scmi_protocol_handle *ph, + struct scmi_clock_desc *clkd) +{ + struct scmi_iterator_ops ops =3D { + .prepare_message =3D iter_clk_describe_prepare_message, + .update_state =3D iter_clk_describe_update_state, + .process_response =3D iter_clk_describe_process_response, + }; + struct scmi_clk_ipriv cpriv =3D { + .clkd =3D clkd, + .dev =3D ph->dev, + }; + unsigned int first, last; + void *iter; + int ret; + + iter =3D ph->hops->iter_response_init(ph, &ops, 0, CLOCK_DESCRIBE_RATES, + sizeof(struct scmi_msg_clock_describe_rates), + &cpriv); + if (IS_ERR(iter)) + return PTR_ERR(iter); + + /* Try to grab a triplet, so that in case is NON-discrete we are done */ + first =3D 0; + last =3D 2; + ret =3D ph->hops->iter_response_run_bound(iter, &first, &last); + if (ret) + goto out; + + /* If discrete grab the last value, which should be the max */ + if (clkd->rate_discrete && clkd->tot_rates > 3) { + first =3D clkd->tot_rates - 1; + last =3D clkd->tot_rates - 1; + ret =3D ph->hops->iter_response_run_bound(iter, &first, &last); + } + +out: + ph->hops->iter_response_bound_cleanup(iter); + + return ret; +} + +static int +scmi_clock_describe_rates_get(const struct scmi_protocol_handle *ph, + u32 clk_id, struct clock_info *cinfo) +{ + struct scmi_clock_desc *clkd =3D &cinfo->clkds[clk_id]; + int ret; + + /* + * Since only after SCMI Clock v1.0 the returned rates are guaranteed to + * be discovered in ascending order, lazy enumeration cannot be use for + * SCMI Clock v1.0 protocol. + */ + if (PROTOCOL_REV_MAJOR(ph->version) > 0x1) + ret =3D scmi_clock_describe_rates_get_lazy(ph, clkd); + else + ret =3D scmi_clock_describe_rates_get_full(ph, clkd); + + if (ret) + return ret; + + clkd->info.min_rate =3D clkd->rates[RATE_MIN]; if (!clkd->rate_discrete) { clkd->info.max_rate =3D clkd->rates[RATE_MAX]; dev_dbg(ph->dev, "Min %llu Max %llu Step %llu Hz\n", clkd->rates[RATE_MIN], clkd->rates[RATE_MAX], clkd->rates[RATE_STEP]); } else { - sort(clkd->rates, clkd->num_rates, - sizeof(clkd->rates[0]), rate_cmp_func, NULL); clkd->info.max_rate =3D clkd->rates[clkd->num_rates - 1]; + dev_dbg(ph->dev, "Clock:%s Num_Rates:%u -> Min %llu Max %llu\n", + clkd->info.name, clkd->tot_rates, + clkd->info.min_rate, clkd->info.max_rate); } - clkd->info.min_rate =3D clkd->rates[RATE_MIN]; =20 return 0; } --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFAE3402459; Fri, 8 May 2026 15:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254452; cv=none; b=mc9Wb7mrcWbNWqKb9VuQpsgF4iot4SRFS54vM3O4F0qqcOSZ8Kblvrd9U1ghz/WgjNi8+rZJ+adMOO9ImmFXddKZMQxTXMrG2ROyRHuwrtGXEbZkhhzvnKt+5XP8WrI3ae3v7I/cKx7zNllTYNJswyTue4yFWQgFx64SUYq6UzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254452; c=relaxed/simple; bh=STsX6b3KBooCmiC+B8JoLtiiyGldyQ5DAhwCGnjnvhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k6qUbfRF3IS0vHfPWrBF2lpuTPOhBpAhUz4IRcm7Z1ZM0bmeP9Om6m0P/WNJKFy7bJFpEsY9zNXgM/Hb020Zz9ox8bRsK0tkTyjYXnj5g7hTm+c0LOpLSOneWaXSBEvg3N+IKffuMZdMaMyTz0f+4dBKtQJ2sody685ccrnQFdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=UP+prNQM; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="UP+prNQM" 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 E0D93359E; Fri, 8 May 2026 08:34:04 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D506C3F836; Fri, 8 May 2026 08:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254450; bh=STsX6b3KBooCmiC+B8JoLtiiyGldyQ5DAhwCGnjnvhw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UP+prNQMf+nvYQ85658n34TX5u3a1kGTtXjybUk0uzJlMU5TP04o7e8yXlSinJFeT N7jf/9zodNIoWYzyq3z0SYhchx4TL1EyGfal/WfpHcxobNYQGvACWcFbjnmgQS08tH X+amAnLydNvSMHPekU2QXAmoMgP7l+RsO2vUn7r8= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v4 14/15] firmware: arm_scmi: Fix OOB in scmi_clock_describe_rates_get_lazy() Date: Fri, 8 May 2026 16:32:59 +0100 Message-ID: <20260508153300.2224715-15-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" From: Geert Uytterhoeven Lazy discovery of discrete rates works as follows: A. Grab the first three rates, B. Grab the last rate, if there are more than three rates. It is up to the SCMI provider implementation to decide how many rates are returned in response to a single CLOCK_DESCRIBE_RATES command. Each rate received is stored in the scmi_clock_rates.rates[] array, and .num_rates is updated accordingly. When more than 3 rates have been received after step A, the last rate may have been received already, and stored in scmi_clock_rates.rates[] (which has space for scmi_clock_desc.tot_rates entries). Hence grabbing the last rate again will store it a second time, beyond the end of the array. Fix this by only grabbing the last rate when we don't already have it. Signed-off-by: Geert Uytterhoeven Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/clock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index 955bb9565ce3..ab8c65ed785a 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -582,8 +582,11 @@ scmi_clock_describe_rates_get_lazy(const struct scmi_p= rotocol_handle *ph, if (ret) goto out; =20 - /* If discrete grab the last value, which should be the max */ - if (clkd->rate_discrete && clkd->tot_rates > 3) { + /* + * If discrete and we don't already have it, grab the last value, which + * should be the max + */ + if (clkd->rate_discrete && clkd->tot_rates > clkd->num_rates) { first =3D clkd->tot_rates - 1; last =3D clkd->tot_rates - 1; ret =3D ph->hops->iter_response_run_bound(iter, &first, &last); --=20 2.53.0 From nobody Wed Jun 10 20:31:38 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9AEF406287; Fri, 8 May 2026 15:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254455; cv=none; b=UyAa5WRR/IVIBcwYJMQaI+9x591MRBkNeK84NIOojByeQ/jExa/ubRot1HTRJgcX2HM0jdbeb9kDGPzHVOkHfcTOonrXv9502cylxtVwfZ0AZ6oFrHPF/zwU1j9TGWU7/71ij3EyvrzEjbiS7a5S8NQG/UTxqToxUayRmkDjaJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254455; c=relaxed/simple; bh=8o1RLPLqw7Q/fiIqOUH5PijDgRryHXsQuxEcHlAGU5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eP24clDt1gaO96dPAco4I/+jAGUDnxsGtjipgTvJ6KW9eOXfIAiiix7OWDvHXdZUo5LJdF6LC3gMOzgroj5udgVQ+86bcpl28Gt1F8Dq4kQnKA73jv+l16S6hYQNXpsQxafQxy4aIW9LpuAf5/hzCgrnsvslvbFjsgtKcKaxo7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=AFSfxaAX; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="AFSfxaAX" 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 0F6F835A1; Fri, 8 May 2026 08:34:08 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 907A33F836; Fri, 8 May 2026 08:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1778254453; bh=8o1RLPLqw7Q/fiIqOUH5PijDgRryHXsQuxEcHlAGU5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AFSfxaAX39J5vqLEKC1A/Tce8RVNIk8zeEfaapI9thtFMVHGnfnggawT/ADjsk2eY tq6RGVgX4hKzqs8TLNbaAo3q2pRT60j4pU+bEsQmne5ew9uHRg6tg4Oxs22LSTiamo PlQ9fYlify6cAQfdyYVnGj9meL1AxvM+4ptwY4/k= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: sudeep.holla@arm.com, philip.radford@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@foss.st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi , Peng Fan Subject: [PATCH v4 15/15] firmware: arm_scmi: Introduce all_rates_get clock operation Date: Fri, 8 May 2026 16:33:00 +0100 Message-ID: <20260508153300.2224715-16-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260508153300.2224715-1-cristian.marussi@arm.com> References: <20260508153300.2224715-1-cristian.marussi@arm.com> 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" Add a clock operation to get the whole set of rates available to a specific clock: when needed this request could transparently trigger a full rate discovery enumeration if this specific clock-rates were previously only lazily enumerated. Reviewed-by: Peng Fan Signed-off-by: Cristian Marussi --- v2 --> v3 - collected Reviewed tags --- drivers/firmware/arm_scmi/clock.c | 83 +++++++++++++++++++++---------- include/linux/scmi_protocol.h | 9 ++++ 2 files changed, 66 insertions(+), 26 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index ab8c65ed785a..42e666a628c7 100644 --- a/drivers/firmware/arm_scmi/clock.c +++ b/drivers/firmware/arm_scmi/clock.c @@ -159,10 +159,8 @@ struct scmi_clock_rate_notify_payld { =20 struct scmi_clock_desc { u32 id; - bool rate_discrete; unsigned int tot_rates; - unsigned int num_rates; - u64 *rates; + struct scmi_clock_rates r; #define RATE_MIN 0 #define RATE_MAX 1 #define RATE_STEP 2 @@ -469,10 +467,10 @@ iter_clk_describe_update_state(struct scmi_iterator_s= tate *st, flags =3D le32_to_cpu(r->num_rates_flags); st->num_remaining =3D NUM_REMAINING(flags); st->num_returned =3D NUM_RETURNED(flags); - p->clkd->rate_discrete =3D RATE_DISCRETE(flags); + p->clkd->r.rate_discrete =3D RATE_DISCRETE(flags); =20 /* Warn about out of spec replies ... */ - if (!p->clkd->rate_discrete && + if (!p->clkd->r.rate_discrete && (st->num_returned !=3D 3 || st->num_remaining !=3D 0)) { dev_warn(p->dev, "Out-of-spec CLOCK_DESCRIBE_RATES reply for %s - returned:%d remaining= :%d rx_len:%zd\n", @@ -486,9 +484,9 @@ iter_clk_describe_update_state(struct scmi_iterator_sta= te *st, if (!st->max_resources) { unsigned int tot_rates =3D st->num_returned + st->num_remaining; =20 - p->clkd->rates =3D devm_kcalloc(p->dev, tot_rates, - sizeof(*p->clkd->rates), GFP_KERNEL); - if (!p->clkd->rates) + p->clkd->r.rates =3D devm_kcalloc(p->dev, tot_rates, + sizeof(*p->clkd->r.rates), GFP_KERNEL); + if (!p->clkd->r.rates) return -ENOMEM; =20 /* max_resources is used by the iterators to control bounds */ @@ -507,10 +505,10 @@ iter_clk_describe_process_response(const struct scmi_= protocol_handle *ph, struct scmi_clk_ipriv *p =3D priv; const struct scmi_msg_resp_clock_describe_rates *r =3D response; =20 - p->clkd->rates[p->clkd->num_rates] =3D RATE_TO_U64(r->rate[st->loop_idx]); + p->clkd->r.rates[p->clkd->r.num_rates] =3D RATE_TO_U64(r->rate[st->loop_i= dx]); =20 /* Count only effectively discovered rates */ - p->clkd->num_rates++; + p->clkd->r.num_rates++; =20 return 0; } @@ -531,7 +529,13 @@ scmi_clock_describe_rates_get_full(const struct scmi_p= rotocol_handle *ph, .dev =3D ph->dev, }; =20 - iter =3D ph->hops->iter_response_init(ph, &ops, 0, CLOCK_DESCRIBE_RATES, + /* + * Using tot_rates as max_resources parameter here so as to trigger + * the dynamic allocation only when strictly needed: when trying a + * full enumeration after a lazy one tot_rates will be non-zero. + */ + iter =3D ph->hops->iter_response_init(ph, &ops, clkd->tot_rates, + CLOCK_DESCRIBE_RATES, sizeof(struct scmi_msg_clock_describe_rates), &cpriv); if (IS_ERR(iter)) @@ -542,12 +546,12 @@ scmi_clock_describe_rates_get_full(const struct scmi_= protocol_handle *ph, return ret; =20 /* empty set ? */ - if (!clkd->num_rates) + if (!clkd->r.num_rates) return 0; =20 - if (clkd->rate_discrete) - sort(clkd->rates, clkd->num_rates, - sizeof(clkd->rates[0]), rate_cmp_func, NULL); + if (clkd->r.rate_discrete && PROTOCOL_REV_MAJOR(ph->version) =3D=3D 0x1) + sort(clkd->r.rates, clkd->r.num_rates, + sizeof(clkd->r.rates[0]), rate_cmp_func, NULL); =20 return 0; } @@ -586,7 +590,7 @@ scmi_clock_describe_rates_get_lazy(const struct scmi_pr= otocol_handle *ph, * If discrete and we don't already have it, grab the last value, which * should be the max */ - if (clkd->rate_discrete && clkd->tot_rates > clkd->num_rates) { + if (clkd->r.rate_discrete && clkd->tot_rates > clkd->r.num_rates) { first =3D clkd->tot_rates - 1; last =3D clkd->tot_rates - 1; ret =3D ph->hops->iter_response_run_bound(iter, &first, &last); @@ -618,14 +622,14 @@ scmi_clock_describe_rates_get(const struct scmi_proto= col_handle *ph, if (ret) return ret; =20 - clkd->info.min_rate =3D clkd->rates[RATE_MIN]; - if (!clkd->rate_discrete) { - clkd->info.max_rate =3D clkd->rates[RATE_MAX]; + clkd->info.min_rate =3D clkd->r.rates[RATE_MIN]; + if (!clkd->r.rate_discrete) { + clkd->info.max_rate =3D clkd->r.rates[RATE_MAX]; dev_dbg(ph->dev, "Min %llu Max %llu Step %llu Hz\n", - clkd->rates[RATE_MIN], clkd->rates[RATE_MAX], - clkd->rates[RATE_STEP]); + clkd->r.rates[RATE_MIN], clkd->r.rates[RATE_MAX], + clkd->r.rates[RATE_STEP]); } else { - clkd->info.max_rate =3D clkd->rates[clkd->num_rates - 1]; + clkd->info.max_rate =3D clkd->r.rates[clkd->r.num_rates - 1]; dev_dbg(ph->dev, "Clock:%s Num_Rates:%u -> Min %llu Max %llu\n", clkd->info.name, clkd->tot_rates, clkd->info.min_rate, clkd->info.max_rate); @@ -732,7 +736,7 @@ static int scmi_clock_determine_rate(const struct scmi_= protocol_handle *ph, * If we can't figure out what rate it will be, so just return the * rate back to the caller. */ - if (clkd->rate_discrete) + if (clkd->r.rate_discrete) return 0; =20 fmin =3D clk->min_rate; @@ -746,14 +750,40 @@ static int scmi_clock_determine_rate(const struct scm= i_protocol_handle *ph, } =20 ftmp =3D *rate - fmin; - ftmp +=3D clkd->rates[RATE_STEP] - 1; /* to round up */ - ftmp =3D div64_ul(ftmp, clkd->rates[RATE_STEP]); + ftmp +=3D clkd->r.rates[RATE_STEP] - 1; /* to round up */ + ftmp =3D div64_ul(ftmp, clkd->r.rates[RATE_STEP]); =20 - *rate =3D ftmp * clkd->rates[RATE_STEP] + fmin; + *rate =3D ftmp * clkd->r.rates[RATE_STEP] + fmin; =20 return 0; } =20 +static const struct scmi_clock_rates * +scmi_clock_all_rates_get(const struct scmi_protocol_handle *ph, u32 clk_id) +{ + struct clock_info *ci =3D ph->get_priv(ph); + struct scmi_clock_desc *clkd; + struct scmi_clock_info *clk; + + clk =3D scmi_clock_domain_lookup(ci, clk_id); + if (IS_ERR(clk) || !clk->name[0]) + return NULL; + + clkd =3D to_desc(clk); + /* Needs full enumeration ? */ + if (clkd->r.rate_discrete && clkd->tot_rates !=3D clkd->r.num_rates) { + int ret; + + /* rates[] is already allocated BUT we need to re-enumerate */ + clkd->r.num_rates =3D 0; + ret =3D scmi_clock_describe_rates_get_full(ph, clkd); + if (ret) + return NULL; + } + + return &clkd->r; +} + static int scmi_clock_config_set(const struct scmi_protocol_handle *ph, u32 clk_id, enum clk_state state, @@ -1067,6 +1097,7 @@ static const struct scmi_clk_proto_ops clk_proto_ops = =3D { .rate_get =3D scmi_clock_rate_get, .rate_set =3D scmi_clock_rate_set, .determine_rate =3D scmi_clock_determine_rate, + .all_rates_get =3D scmi_clock_all_rates_get, .enable =3D scmi_clock_enable, .disable =3D scmi_clock_disable, .state_get =3D scmi_clock_state_get, diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 0824a7dc4aae..8046d086a225 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -40,6 +40,12 @@ struct scmi_revision_info { char sub_vendor_id[SCMI_SHORT_NAME_MAX_SIZE]; }; =20 +struct scmi_clock_rates { + bool rate_discrete; + unsigned int num_rates; + u64 *rates; +}; + struct scmi_clock_info { char name[SCMI_MAX_STR_SIZE]; unsigned int enable_latency; @@ -84,6 +90,7 @@ enum scmi_clock_oem_config { * clock calculating the closest allowed rate. * Note that @rate is an input/output parameter used both to * describe the requested rate and report the closest match + * @all_rates_get: get the list of all available rates for the specified c= lock. * @enable: enables the specified clock * @disable: disables the specified clock * @state_get: get the status of the specified clock @@ -103,6 +110,8 @@ struct scmi_clk_proto_ops { u64 rate); int (*determine_rate)(const struct scmi_protocol_handle *ph, u32 clk_id, unsigned long *rate); + const struct scmi_clock_rates __must_check *(*all_rates_get) + (const struct scmi_protocol_handle *ph, u32 clk_id); int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id, bool atomic); int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id, --=20 2.53.0