Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2642663rdh; Mon, 30 Oct 2023 03:35:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwF6GDXbjoGvrSkbkbBd/zCXhAvjgxRIE5LoYCdoxgtb0QD+ge4ks/i60qqzK/idhBOB2I X-Received: by 2002:a05:6359:1a09:b0:168:e8e6:b91f with SMTP id rt9-20020a0563591a0900b00168e8e6b91fmr7470389rwb.18.1698662155453; Mon, 30 Oct 2023 03:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698662155; cv=none; d=google.com; s=arc-20160816; b=JCY2XFQkXkcJPEMO8Su5WSRi2g3AxxyMvB56gdXaLROcGhDQj0lYSCFCanfKcj5THI Nb8GLHbzsNSaHy+LuuQYGj4vIdnchy4g6H2tD53gmE/GJDkDQJq5zXtpOLg6B02jbDtp Oe6e2Yppv9SCJKVsCPaZO1aDfSQ8PbjVCaXrfnEaA4SMu4ElpLrL954dAYGDsWU4peDP 7S2mg2j8uB60OeiGqmkGDnD6d1ZfG27DEMSHSA7Qd4OInkyGGfOBBDWzCrYughuibLka GtFFCcMsI1Xz/D3Wy6taIF7hqedOyAofpbiYPWXgL051Xa7bmCaM7GL+cSidF2i3sDje lA0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fcED4WjT67F9vTej3BnZaz4/stcnOOOgNE1CTcd6l/E=; fh=Un7JazYSm8/kcjPcd/W8jKETxQG7VjjVg/N0ak4gg3I=; b=0JWfpS0/IK9kLgI4SFrwasA4z1GC/0EcvNAwgnCEqqJARKDBLG6lVTFP0H/wkGHL4B /DzSQloupCw8H43/LexSRHma5D2fwGkOxsPTO1+NQrpnZm2DZ6mEgaDJ6kFSpiYQf1jr eYnc/FYTrOJ37OfrVyi02QaC/tsly2FQY6yWRgutCI1uX/vjSG6ZUXv5oTD9WpZJkOQp rHl2M3Yee2Qwi1baSTDk0fD0mp/aO8qK3b7oajG0Zi+hOu8l3g2f6qjuyG7kakeoAGI9 Z74+lVf0GUyiVy3FoV8QD5GGBHXzJ1aasjCB00xa01vynBru42AZ6zG+NirStNgR5HN0 c+rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Itlp8lMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s22-20020a63e816000000b005ac39221cc8si4782057pgh.567.2023.10.30.03.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 03:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Itlp8lMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id C8C518083ABE; Mon, 30 Oct 2023 03:35:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232774AbjJ3Keh (ORCPT + 99 others); Mon, 30 Oct 2023 06:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233380AbjJ3KeA (ORCPT ); Mon, 30 Oct 2023 06:34:00 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB21E1BF8 for ; Mon, 30 Oct 2023 03:24:27 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6bd96cfb99cso3567743b3a.2 for ; Mon, 30 Oct 2023 03:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698661467; x=1699266267; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fcED4WjT67F9vTej3BnZaz4/stcnOOOgNE1CTcd6l/E=; b=Itlp8lMvy58UID6ioZWhAjfk515YBZ9LFmvOBkdL2zN7Jm2YaSWVR01ZEbfPBUVxTq 0hDMWVWgzUY1XNkEKdLRMumPtPgcfzdNW/8+omNFUG6TL8kXeMgJTFA5IKV0lbL4ipxL oTOsmdmDBo19hUJ9U1nbpT2nwKrdIPe1o6V8M9cjXgVyRz6kUo3QzHsgwXBNBb3aXTtu AaWOMsKNnMuXwppR/cLUMrEEDJ15Ke7fYL2h/e03sRY/nvVIP1Mg0DDc6xZO1YKQs7Lb 5/V8Jy35sN8X+5tHRrnamvz6LdAO2stqVNlIl/awFYZArmmS+nxa35ML0gPiRbrlwX2l MXbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698661467; x=1699266267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fcED4WjT67F9vTej3BnZaz4/stcnOOOgNE1CTcd6l/E=; b=G1fIzhJp4PyrToZ9YGYW6+cNxXXuOO3FkfiWTjmiwd4JHe/IPQPovF2+MoFM/YyCMK xatAg/0zzMuOx9xPUkbwn5xYvI6Fz/trp7ZPxP5gLUzYnXyi37yLvUdLHpQ6QtS/oVmI ymW5Dy1I6ClxD9ErhFNynv9a94IxMY2uLehPIxZscENQjk3yh9AlqtThWaMyHftUDPcb AGPbVIZrJ23/NfWXchd8hvfolIoER+58YBkHg1gj7LPNVy71yBl3xWQLXekR8wFBPH/m iFl/83G8ymIKXNZ6A6VOiWq+ug4kEPa9zAzgU2uU11Syupgm2LR5yHlHIu5djnIle+SX G9Ew== X-Gm-Message-State: AOJu0YxuGL6TKb5crlq/MXira4TpQdIMqHohYcakVbKjbGX1MM5XPA6L f76V68IfBT9rf37jAxj9mMoDnWBcDYkf45Epv8M= X-Received: by 2002:a05:6a00:21d0:b0:68e:2f6e:b4c0 with SMTP id t16-20020a056a0021d000b0068e2f6eb4c0mr7744981pfj.28.1698661466983; Mon, 30 Oct 2023 03:24:26 -0700 (PDT) Received: from localhost ([122.172.80.14]) by smtp.gmail.com with ESMTPSA id a18-20020aa78652000000b006be484e5b9bsm5600469pfo.58.2023.10.30.03.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 03:24:26 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Ulf Hansson , Stephan Gerhold , Konrad Dybcio , Manivannan Sadhasivam , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/3] OPP: Level zero is valid Date: Mon, 30 Oct 2023 15:54:15 +0530 Message-Id: <36de122e568dcba371d3581e5f936243b405a874.1698661048.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 30 Oct 2023 03:35:29 -0700 (PDT) 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 --- 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