From nobody Wed Apr 8 04:41:10 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA6443DDDA3; Tue, 10 Mar 2026 18:41:33 +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=1773168100; cv=none; b=OIKprhdC8MoWYpPvjmsFj4xywsSdbRFGoveCks7L0MCcd+m+LWj5F1qpH/Lwrd/bJPaaRakqFEyRCLnYFGLCEZKRE/KipzSQk5DrpCSQSsBnzxyNNCt48tqYg6ofBa2JCTI4FNqkkbnQAhYYDFB7ePu77Gh0vnUT4vLzwdfv1KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773168100; c=relaxed/simple; bh=1QkmU4Mi4WIOxOY2NsEGq0vCDogKf52p+0AlpEx0gks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MnJFnUjdgdwPPCilcvn6UgFWxx0LI7PUvvADUBI29dNeaRlhv08yXhyyDC5hCdqeOLCEQKh4NVP9Bnwjs6TWqDuVkAfkTJRdz/KpgYxQOQr+plmde0rGsiXd3sts/7eqmmqqNV4mrNYQMpA52d32vOqYcMRPfMsIMRjuWnzrn3A= 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; 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 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 1290A14BF; Tue, 10 Mar 2026 11:41:27 -0700 (PDT) Received: from pluto.guest.local (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CCBB13F7BD; Tue, 10 Mar 2026 11:41:29 -0700 (PDT) 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, dan.carpenter@linaro.org, geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com, Cristian Marussi Subject: [PATCH v2 13/13] firmware: arm_scmi: Introduce all_rates_get clock operation Date: Tue, 10 Mar 2026 18:40:30 +0000 Message-ID: <20260310184030.3669330-14-cristian.marussi@arm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260310184030.3669330-1-cristian.marussi@arm.com> References: <20260310184030.3669330-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. Signed-off-by: Cristian Marussi Reviewed-by: Peng Fan --- drivers/firmware/arm_scmi/clock.c | 85 +++++++++++++++++++++---------- include/linux/scmi_protocol.h | 9 ++++ 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/= clock.c index f50689bf5414..082fb0db8681 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 @@ -475,10 +473,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", @@ -492,9 +490,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 */ @@ -513,10 +511,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; } @@ -537,7 +535,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)) @@ -548,12 +552,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; } @@ -589,7 +593,7 @@ scmi_clock_describe_rates_get_lazy(const struct scmi_pr= otocol_handle *ph, goto out; =20 /* If discrete grab the last value, which should be the max */ - if (clkd->rate_discrete && clkd->tot_rates > 3) { + if (clkd->r.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); @@ -621,16 +625,16 @@ 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 DISCRETE:%d -> Min %llu Max %llu\n", - clkd->info.name, clkd->rate_discrete, + clkd->info.name, clkd->r.rate_discrete, clkd->info.min_rate, clkd->info.max_rate); } =20 @@ -735,7 +739,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; @@ -749,14 +753,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, @@ -1070,6 +1100,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 5552ac04c820..c710107c2120 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; @@ -85,6 +91,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 @@ -104,6 +111,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