Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2209297rdf; Mon, 6 Nov 2023 07:42:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuadleju0seu5NggZiSKtvrWlbTcyHFTyh9oJ6fmP94bmb1xplG2qCAvaL7plKOOR1NEur X-Received: by 2002:a05:6e02:12c3:b0:359:4048:38d2 with SMTP id i3-20020a056e0212c300b00359404838d2mr93419ilm.0.1699285323030; Mon, 06 Nov 2023 07:42:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699285322; cv=none; d=google.com; s=arc-20160816; b=cfdkHgUp5a2/S0bEzoeSjJ1QHdCYFGt9ktOP8jEsFA41LOt4YuYNtmDoZJcZnqxXEh JTQR2Z7oWM6K0zFJXz6bTcM31TyCRvdpfy5fmDRaIGo2S2ULzgsvwH9Cfusbw8eqoDKU mBy9jwrAi3uCTZGwS5nrfsZqx+xbDM46Vdlhiimx1knJpdAXxY0aGSUDMGKA7U5FI2zJ DooOMM53Yb8HaeGk1NTygccKZ0fl0lDWY/s6LPxKFCVFhWTff1sHdsb0j+Re2Tj3QDnq IS/ej3RK8qprHMejx56aEaJjTYURCYa8sbBVflvE/EfDQA60bMAdQ5RwPKwp//hdjwiT wAfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zFsHwFdMSzfDdOBIFA7K/yvGX5wUXDR0ViZVLr0N5ZA=; fh=OQY8JyHQIkZ1hSTlGj+oiP6AYFN+bQcJXNwjQHeni8c=; b=mR60vjajEixQe0+d2/mRhYQgIZcFGWvaoN+c5CYAL4ixADPfkwSKZ39pIzaFBhEruU WkTat86LyX+pk5NBNtV2Q168HDP9rujqftZH6z/BXGdH5TeXVcAq6mMjL/oba4RdlblT i++wsx2vQ27NBpjl0KVHL+Y//oz6lSvgXSURSyNJpkv5wDuP5WN93S6AAwT0oJ1XfRrj wAkYpoSDKMp7mRb1AqhsdczuUzxOK68LIES4R8LkwXDLea8JeIVzBGcuApr+JSHloCBF h688/HQonQYFbkdjGZVNqCDtriPTEVUkqB1DmWNkbn1BYdr2qmuTxaLSfNIRIW29I4qf i0RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kttzcWpk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b0059b9e4e53d5si7676484pgv.218.2023.11.06.07.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 07:42:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kttzcWpk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C6418807754C; Mon, 6 Nov 2023 07:42:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232072AbjKFPmB (ORCPT + 99 others); Mon, 6 Nov 2023 10:42:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231929AbjKFPl7 (ORCPT ); Mon, 6 Nov 2023 10:41:59 -0500 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77E9210A for ; Mon, 6 Nov 2023 07:41:55 -0800 (PST) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-d9c66e70ebdso4677311276.2 for ; Mon, 06 Nov 2023 07:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699285314; x=1699890114; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=zFsHwFdMSzfDdOBIFA7K/yvGX5wUXDR0ViZVLr0N5ZA=; b=kttzcWpkkXww/BzeeF5piE/WVes8GdD+tqp7vBoO8rX89HaITuppjuBHXFrrXR7iKh uh+mn0xFsYvdyCFy/j6F+pR8tr5MwKNINBRJlniQb0r2PTEARWFD6kkWTMs92A7pUCkK dCHvUxo+sL0wLGxBMODwK+Lb/QvyaGKSVDzwbOrHJG8mtW0U9eLrDDYWb5fzLUUhGC2W zm7C5wMhlII0R39zHARw0ZqANk5zlTFa5+ALk6pfwSz6rliocAjs1AEcRCetLPplr3Ab xbzYqj4zqxXCc5Zj10pj7HxFfhrV+Iea/5UdDOdBFSdEHBcPb1hX5nI7Bk4C5+4xlXv6 fCOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699285314; x=1699890114; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zFsHwFdMSzfDdOBIFA7K/yvGX5wUXDR0ViZVLr0N5ZA=; b=BBORLX8OK4wCBnR6UgcaeksEWtv4VWbdotRymAxEwNOZ+iShkWA2aw6enZghgk5TBu FPK+SVLXfXm33NtfDv0lk0i8ls5ATZ2LHPNtZ38GNxewO25KFDRYEK8SQw9bUsLx2yb6 3DZqocA0VpFzwJ4iZIs4hvJg7Ob59s8PIHWzj4eCTelW7klSViavpPsbL4AeASjobiFW EvEGrJide1mFWswc0OjyJj4fgWCNaNP6ot3+TibKe0pXWVJN6ezGiSxQ1A9ToAKOIA9w VCOseGrADI/oItXIk3eWbIXrGB3sRcTUDsU0ifHR7AzTZOsCxWep8sDES95MfcQOFHpD zOhQ== X-Gm-Message-State: AOJu0YyMYNg6xghU9Fp1ny+omLFBPZ/suiiypnZhXakr0NDUd+IFM3bN /fZDTnprVTmdR6wCwuAM4RjN4CI10jd6XJENyhCIAw== X-Received: by 2002:a25:9805:0:b0:da0:c5eb:a6c6 with SMTP id a5-20020a259805000000b00da0c5eba6c6mr26313363ybo.32.1699285314491; Mon, 06 Nov 2023 07:41:54 -0800 (PST) MIME-Version: 1.0 References: <36de122e568dcba371d3581e5f936243b405a874.1698661048.git.viresh.kumar@linaro.org> In-Reply-To: <36de122e568dcba371d3581e5f936243b405a874.1698661048.git.viresh.kumar@linaro.org> From: Ulf Hansson Date: Mon, 6 Nov 2023 16:41:18 +0100 Message-ID: Subject: Re: [PATCH V2 1/3] OPP: Level zero is valid To: Viresh Kumar Cc: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Vincent Guittot , Stephan Gerhold , Konrad Dybcio , Manivannan Sadhasivam , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 07:42:01 -0800 (PST) On Mon, 30 Oct 2023 at 11:24, Viresh Kumar wrote: > > The level zero can be used by some OPPs to drop performance state vote > for the device. It is perfectly fine to allow the same. > > _set_opp_level() considers it as an invalid value currently and returns > early. > > In order to support this properly, initialize the level field with > U32_MAX, which denotes unused level field. > > Reported-by: Stephan Gerhold > Signed-off-by: Viresh Kumar Reviewed-by: Ulf Hansson Kind regards Uffe > --- > drivers/opp/core.c | 24 ++++++++++++++++++++---- > drivers/opp/of.c | 8 +++++++- > include/linux/pm_opp.h | 5 ++++- > 3 files changed, 31 insertions(+), 6 deletions(-) > > diff --git a/drivers/opp/core.c b/drivers/opp/core.c > index 84f345c69ea5..f2e2aa07b431 100644 > --- a/drivers/opp/core.c > +++ b/drivers/opp/core.c > @@ -201,7 +201,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq_indexed); > * @opp: opp for which level value has to be returned for > * > * Return: level read from device tree corresponding to the opp, else > - * return 0. > + * return U32_MAX. > */ > unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) > { > @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_level); > * @index: index of the required opp > * > * Return: performance state read from device tree corresponding to the > - * required opp, else return 0. > + * required opp, else return U32_MAX. > */ > unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, > unsigned int index) > @@ -808,6 +808,14 @@ struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev, > struct dev_pm_opp *opp; > > opp = _find_key_ceil(dev, &temp, 0, true, _read_level, NULL); > + > + /* False match */ > + if (temp == OPP_LEVEL_UNSET) { > + dev_err(dev, "%s: OPP levels aren't available\n", __func__); > + dev_pm_opp_put(opp); > + return ERR_PTR(-ENODEV); > + } > + > *level = temp; > return opp; > } > @@ -1049,12 +1057,18 @@ static int _set_opp_bw(const struct opp_table *opp_table, > static int _set_performance_state(struct device *dev, struct device *pd_dev, > struct dev_pm_opp *opp, int i) > { > - unsigned int pstate = likely(opp) ? opp->required_opps[i]->level: 0; > + unsigned int pstate = 0; > int ret; > > if (!pd_dev) > return 0; > > + if (likely(opp)) { > + pstate = opp->required_opps[i]->level; > + if (pstate == OPP_LEVEL_UNSET) > + return 0; > + } > + > ret = dev_pm_domain_set_performance_state(pd_dev, pstate); > if (ret) { > dev_err(dev, "Failed to set performance state of %s: %d (%d)\n", > @@ -1135,7 +1149,7 @@ static int _set_opp_level(struct device *dev, struct opp_table *opp_table, > int ret = 0; > > if (opp) { > - if (!opp->level) > + if (opp->level == OPP_LEVEL_UNSET) > return 0; > > level = opp->level; > @@ -1867,6 +1881,8 @@ struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table) > > INIT_LIST_HEAD(&opp->node); > > + opp->level = OPP_LEVEL_UNSET; > + > return opp; > } > > diff --git a/drivers/opp/of.c b/drivers/opp/of.c > index 81fa27599d58..85fad7ca0007 100644 > --- a/drivers/opp/of.c > +++ b/drivers/opp/of.c > @@ -1393,8 +1393,14 @@ int of_get_required_opp_performance_state(struct device_node *np, int index) > > opp = _find_opp_of_np(opp_table, required_np); > if (opp) { > - pstate = opp->level; > + if (opp->level == OPP_LEVEL_UNSET) { > + pr_err("%s: OPP levels aren't available for %pOF\n", > + __func__, np); > + } else { > + pstate = opp->level; > + } > dev_pm_opp_put(opp); > + > } > > dev_pm_opp_put_opp_table(opp_table); > diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h > index ccd97bcef269..af53101a1383 100644 > --- a/include/linux/pm_opp.h > +++ b/include/linux/pm_opp.h > @@ -92,9 +92,12 @@ struct dev_pm_opp_config { > struct device ***virt_devs; > }; > > +#define OPP_LEVEL_UNSET U32_MAX > + > /** > * struct dev_pm_opp_data - The data to use to initialize an OPP. > - * @level: The performance level for the OPP. > + * @level: The performance level for the OPP. Set level to OPP_LEVEL_UNSET if > + * level field isn't used. > * @freq: The clock rate in Hz for the OPP. > * @u_volt: The voltage in uV for the OPP. > */ > -- > 2.31.1.272.g89b43f80a514 >