From nobody Tue Dec 16 12:37:40 2025 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3E5D14659C for ; Thu, 18 Jul 2024 23:43:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346209; cv=none; b=lbudIKEVMrHcrv0ORAjquDP2j6GXdmf9edWynoeh/EaGEK4/+ljEs238jNzTftg6tvcVq/AbteaCWyZWLYkWZTHirhRURwjLQSq2jG3R7pmks2449xqfBvPVbjkqG8gQVTeRqHflEJgjev0BMsP6AdDC8dRr+/HkhKPPvuTsJXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346209; c=relaxed/simple; bh=HiN+rgq9gu0Chb+FnevRuAodoxjBWMVVAIsr/15wHVU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O4/h41/hNXrft3RSd8M8MkNs/z5aJXbuCagCgTonx1hEAiglEoI3Oke9Ez6MnH42vGcrR4KjGGxjOnt66VMCLkfdU20uEWQPZFYohrhdjtuBVQ8d37uRhzLWflZsTHrVJA36QGXtOjmEWIMqEmbTuJOT+2C7aRxHS5XLvXrIt8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=EQCRqAzo; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EQCRqAzo" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-52ed9b802ceso1031411e87.3 for ; Thu, 18 Jul 2024 16:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721346206; x=1721951006; 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=+zb2TnLEPy/yYn4OHpN9GAbJBX2HlvGglgTvnLaEwow=; b=EQCRqAzolnnkPwLdlVvSsRG8JkC2j5iMhLAMg7/OI0XaN/Niyeg7J84DkhgJBACsSJ RBtlu/jSzOeyuVxRG4+4KA7pUNFgo4BGeCUfhJ8e/LcFbJHVaTqRuRTABYs5pkiE+POf nd99qRC7HyvhanQAPA+N4DkKMai7eR16Mc22EWHBC81V3yT+P3R36zHiqKjwsN5S8w+j enc5WsGEBpkTmpie028WIouV6JCbbKlzITRqHMNL07uToUsCRVqnsABYcShOQggcOG+a fPisKIyJw+g8/UfV5Aomds5HmA/cpY/VWIYbPCxxYkG5m5HwnL/I/rWthL/a8eAoQXsM CTRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721346206; x=1721951006; 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=+zb2TnLEPy/yYn4OHpN9GAbJBX2HlvGglgTvnLaEwow=; b=S+S4IRC/EU+nauCSAkzus7rqRv9cwA2wNk+tQC9rSqTwUPkAIvOD8X7XsZRVRAUU8C CH6A/l6V2IuvxUyQ+ZgWQATKtE/ROGb6PPEOH6Hk6rUsfeaaVvl2NU5Lv1eZb8wrDqc8 VOf5dF+hrabn+tHTZiL9TxRkFWU7bieQoaGBShSKHGizwOuX3LHL4KaU9iO9NxvdPeBE 95il2udf6R6Ryzz0QODU3acI1aqUqlsKg7t5iASY2kYqPu1ohIBFMmZxQYKDPh//XNS8 NDdl45q49gPaOM+yvF0ca2DMsUYjs5k+fXtlsy8zuaW/z97zT86trAQqAHmPmkEcn5Uo GTGg== X-Forwarded-Encrypted: i=1; AJvYcCXK+Ov6OjRhz/cBGfhRo7KY7hFalfhG77fvMltxHWHI4Ne9zv86EAp7qwCYYMntFJmx0p9SjvrLEH9xPf//v8GThTlWl10hjUYdezqo X-Gm-Message-State: AOJu0YwMjXLBsgpv24/gkO3rxrHxEPldiik+AYO711Bv9QwQhQbe2ATJ nwBekfvkTN2J2CnoZkVA/s2ycOURthC9xqI0uuj1McREZyjJAS0dYqU0GuiyFng= X-Google-Smtp-Source: AGHT+IFF8smI3aMAQT3AbKX1NQGZpHaJaCkvum5gaxbfN2nJOzdqHbIsk7af5xBZTpN9HOnmw05rOw== X-Received: by 2002:a05:6512:ac7:b0:52b:9c8a:734f with SMTP id 2adb3069b0e04-52ee5411e3dmr5098927e87.50.1721346205884; Thu, 18 Jul 2024 16:43:25 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ef556b4fbsm22491e87.139.2024.07.18.16.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 16:43:25 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Prasad Sodagudi , Thierry Reding , Jonathan Hunter , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/6] OPP: Fix support for required OPPs for multiple PM domains Date: Fri, 19 Jul 2024 01:43:14 +0200 Message-Id: <20240718234319.356451-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718234319.356451-1-ulf.hansson@linaro.org> References: <20240718234319.356451-1-ulf.hansson@linaro.org> 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" It has turned out that having _set_required_opps() to recursively call dev_pm_opp_set_opp() to set the required OPPs, doesn't really work as well as we expected. More precisely, at each recursive call to dev_pm_opp_set_opp() we are changing the OPP for a genpd's OPP table for a device that has been attached to it. The problem with this, is that we may have several devices being attached to the same genpd, thus sharing the same OPP-table that is being used for their required OPPs. So, typically we may have several active requests simultaneously for different OPPs for a genpd's OPP table. This may lead to that the per device vote for a performance-state (opp-level) for a genpd doesn't get requested accordingly. Moreover, dev_pm_opp_set_opp() doesn't get called for a required OPP when a device has been attached to a single PM domain. Even if a consumer driver would attempt to assign the required-devs, via _opp_attach_genpd() or _opp_set_required_devs() it would not be possible, as there is no separate virtual device at hand to use in this case. The above said, let's fix the problem by replacing the call to dev_pm_opp_set_opp() in _set_required_opps() by a call to _set_opp_level(). At the moment there's no drawback doing this, as there is no need to manage anything but the performance-state of the genpd. If it later turns out that another resource needs to be managed for a required-OPP, it can still be extended without having to call dev_pm_opp_set_opp(). Fixes: e37440e7e2c2 ("OPP: Call dev_pm_opp_set_opp() for required OPPs") Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson --- Changes in v2: - Clarified the commitmsg. - Addressed some comments from Viresh. - Drop calls to _add_opp_dev() for required_devs. --- drivers/opp/core.c | 56 ++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 5f4598246a87..494f8860220d 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1061,6 +1061,27 @@ static int _set_opp_bw(const struct opp_table *opp_t= able, return 0; } =20 +static int _set_opp_level(struct device *dev, struct dev_pm_opp *opp) +{ + unsigned int level =3D 0; + int ret =3D 0; + + if (opp) { + if (opp->level =3D=3D OPP_LEVEL_UNSET) + return 0; + + level =3D opp->level; + } + + /* Request a new performance state through the device's PM domain. */ + ret =3D dev_pm_domain_set_performance_state(dev, level); + if (ret) + dev_err(dev, "Failed to set performance state %u (%d)\n", level, + ret); + + return ret; +} + /* This is only called for PM domain for now */ static int _set_required_opps(struct device *dev, struct opp_table *opp_ta= ble, struct dev_pm_opp *opp, bool up) @@ -1091,7 +1112,7 @@ static int _set_required_opps(struct device *dev, str= uct opp_table *opp_table, if (devs[index]) { required_opp =3D opp ? opp->required_opps[index] : NULL; =20 - ret =3D dev_pm_opp_set_opp(devs[index], required_opp); + ret =3D _set_opp_level(devs[index], required_opp); if (ret) return ret; } @@ -1102,27 +1123,6 @@ static int _set_required_opps(struct device *dev, st= ruct opp_table *opp_table, return 0; } =20 -static int _set_opp_level(struct device *dev, struct dev_pm_opp *opp) -{ - unsigned int level =3D 0; - int ret =3D 0; - - if (opp) { - if (opp->level =3D=3D OPP_LEVEL_UNSET) - return 0; - - level =3D opp->level; - } - - /* Request a new performance state through the device's PM domain. */ - ret =3D dev_pm_domain_set_performance_state(dev, level); - if (ret) - dev_err(dev, "Failed to set performance state %u (%d)\n", level, - ret); - - return ret; -} - static void _find_current_opp(struct device *dev, struct opp_table *opp_ta= ble) { struct dev_pm_opp *opp =3D ERR_PTR(-ENODEV); @@ -2457,18 +2457,6 @@ static int _opp_attach_genpd(struct opp_table *opp_t= able, struct device *dev, } } =20 - /* - * Add the virtual genpd device as a user of the OPP table, so - * we can call dev_pm_opp_set_opp() on it directly. - * - * This will be automatically removed when the OPP table is - * removed, don't need to handle that here. - */ - if (!_add_opp_dev(virt_dev, opp_table->required_opp_tables[index])) { - ret =3D -ENOMEM; - goto err; - } - opp_table->required_devs[index] =3D virt_dev; index++; name++; --=20 2.34.1 From nobody Tue Dec 16 12:37:40 2025 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A88B146A8B for ; Thu, 18 Jul 2024 23:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346211; cv=none; b=r0+P3PmD+jcpkq47Ky+Cj8UGoQI9VxlKSy2ER5cMwgc694jlsU9NuvRWNd2OpS9NGkiFkAwtvlrjgNWAF+Vk+6cQxBk01sGolN9Kr+gn3uvP8/nu/U/VHtzkFPMVOaq9fUcWQBk4XXJyU+mX+hqGIOlPYPzkWizFfRgRBfbfOhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346211; c=relaxed/simple; bh=KHxh8gu+LTIzkPIdHss7t+y3pqREJ7xgjz13gbGvcbU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H72xLPfu1IclgIXzdtg4Gk4v5tw9cG+ThDDx8kPyBXoagj0+bWTyPQJDJNpYO2xWVojowuBmqC5BsqTInjSz0i4jvTeOqbkhEkGw5C+mpZiT3KH2vHGYyQjHr2TcoMZvCpjkr9ASBL5AORBCkXpJaW0atcd23uc2RDZygwIIj/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=InrzBhHo; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="InrzBhHo" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-52ea16b429dso678116e87.1 for ; Thu, 18 Jul 2024 16:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721346207; x=1721951007; 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=0E4K3m18NzNAaiIJOKht8f12lpSSf/q6AadozsUAGZI=; b=InrzBhHog1B2qX1IxzVyyOppgqARAS+ZDLpNPYjZR11YkqCa6HliYKPT6PpNi9cR+s 8AsaY1gi1glRkGhVXfiT4MyZ5vEO4HCscRc2Th0ASOkDnl442efStxDTcxOS/hxNEwiC vKZP6ir1+h9gvFCyGJdEOiI5j3H5fwENu9upse5EpBgL2OY24Wu9cmhxGGmi128e8bcY FAwoYnu6bbX3wR6FY8H6w5SyEDG3EWZNMBuCim0v5D5/J5UH3EeAqBioQk7BTY4aq0hD K+Y3dHDLJYjC6DJTXOg0dfvYfg/kjff46GxMsVo1eO4A72cLqbWj0TsOdX9EszvjoCew of3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721346207; x=1721951007; 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=0E4K3m18NzNAaiIJOKht8f12lpSSf/q6AadozsUAGZI=; b=UpGoikj577CGQW6tG9dl6Qx05k/oy/P66XCvMrqPnojI3paykJkz11A90Bb0yjjOc0 GMcCbGx0084hyB7RTPkr1Rxs7e6UPWGz0s2U+6qLxXhjlbtrvIuhkantuxFOmaJRvgQQ vR+rOZXTFyXQAQIl4WpR9ZvAD8M5tL5biHuLjTDYcvxA2hfL/Y/+jWqGVAuBgrA5TZZ2 Q7WeOdm9kbYcFPNzfXdaEPloVWh7qCOuBChk/eXV2Y7wq6LsNFVVTNkZBTbCqo6uUM6J X28vILGwFQT6NIWgb9T6aN9rbv9lz3jTZSglCHiYKKf/u+hLH79miKoa8zkiSk5SXO6s jhXg== X-Forwarded-Encrypted: i=1; AJvYcCWwvhHbgPdgG+WuTnAeuJmrSzbpfzl/h7AY0iKP+5qM2aFGL3aZPZaQ4uumuxVAqo4No79+u/outqmXGCTf3lTZCyRGILv8PuV5e4Ss X-Gm-Message-State: AOJu0Yxoc2ed48dZICkMypd2jlh6yoidURX+vQ5z0FN5TD1yinlMAz1y 5/UvofsBOt6NTiLnrAPOSWZeLZ9GRi3sBMKj7BEQdIfqgN7d0+4j3zBP57P5LJs= X-Google-Smtp-Source: AGHT+IF4/9i2ZMuh/4tFXo5zf6/+vwOKWzikZWarKDokHXv+3/nfYbGMIJc93vRDdzW6MYNrmK/FGg== X-Received: by 2002:a05:6512:10c5:b0:52e:7278:a39d with SMTP id 2adb3069b0e04-52ef0875a86mr753924e87.0.1721346207064; Thu, 18 Jul 2024 16:43:27 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ef556b4fbsm22491e87.139.2024.07.18.16.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 16:43:26 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Prasad Sodagudi , Thierry Reding , Jonathan Hunter , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] OPP: Rework _set_required_devs() to manage a single device per call Date: Fri, 19 Jul 2024 01:43:15 +0200 Message-Id: <20240718234319.356451-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718234319.356451-1-ulf.hansson@linaro.org> References: <20240718234319.356451-1-ulf.hansson@linaro.org> 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" At this point there are no consumer drivers that makes use of _set_required_devs(), hence it should be straightforward to rework the code to enable it to better integrate with the genpd attach procedure. During genpd attach, one device is being attached to its PM domain. Therefore, let's also update the _set_required_devs() to work with this behaviour and instead trust callers to fill out one required_dev per call. Moving forward and as shown from a subsequent change, genpd becomes the first user of the reworked _set_required_dev(). Signed-off-by: Ulf Hansson --- Changes in v2: - Addressed some comments from Viresh. - Drop calls to _add_opp_dev() for required_devs. --- drivers/opp/core.c | 91 +++++++++++++++++++++++++++++------------- drivers/opp/opp.h | 4 +- include/linux/pm_opp.h | 10 +++-- 3 files changed, 73 insertions(+), 32 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 494f8860220d..b6a699286aaa 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2473,9 +2473,10 @@ static int _opp_attach_genpd(struct opp_table *opp_t= able, struct device *dev, =20 } =20 -static int _opp_set_required_devs(struct opp_table *opp_table, - struct device *dev, - struct device **required_devs) +static int _opp_set_required_dev(struct opp_table *opp_table, + struct device *dev, + struct device *required_dev, + struct opp_table *required_opp_table) { int i; =20 @@ -2484,36 +2485,70 @@ static int _opp_set_required_devs(struct opp_table = *opp_table, return -EINVAL; } =20 - /* Another device that shares the OPP table has set the required devs ? */ - if (opp_table->required_devs[0]) - return 0; + /* Genpd core takes care of propagation to parent genpd */ + if (opp_table->is_genpd) { + dev_err(dev, "%s: Operation not supported for genpds\n", __func__); + return -EOPNOTSUPP; + } =20 for (i =3D 0; i < opp_table->required_opp_count; i++) { - /* Genpd core takes care of propagation to parent genpd */ - if (required_devs[i] && opp_table->is_genpd && - opp_table->required_opp_tables[i]->is_genpd) { - dev_err(dev, "%s: Operation not supported for genpds\n", __func__); - return -EOPNOTSUPP; - } + struct opp_table *table =3D opp_table->required_opp_tables[i]; + + /* + * The OPP table should be available at this point. If not, it's + * not the one we are looking for. + */ + if (IS_ERR(table)) + continue; =20 - opp_table->required_devs[i] =3D required_devs[i]; + /* Move to the next available index. */ + if (opp_table->required_devs[i]) + continue; + + /* + * We need to compare the nodes for the OPP tables, rather than + * the OPP tables themselves, as we may have separate instances. + */ + if (required_opp_table->np =3D=3D table->np) { + /* + * The required_opp_tables parsing is not perfect, as + * the OPP core does the parsing solely based on the DT + * node pointers. The core sets the required_opp_tables + * entry to the first OPP table in the "opp_tables" + * list, that matches with the node pointer. + * + * If the target DT OPP table is used by multiple + * devices and they all create separate instances of + * 'struct opp_table' from it, then it is possible that + * the required_opp_tables entry may be set to the + * incorrect sibling device. Cross check it again and + * fix if required. + */ + if (required_opp_table !=3D table) { + dev_pm_opp_put_opp_table(table); + _get_opp_table_kref(required_opp_table); + opp_table->required_opp_tables[i] =3D required_opp_table; + } + + opp_table->required_devs[i] =3D required_dev; + return i; + } } =20 - return 0; + dev_err(dev, "Missing OPP table, unable to set the required dev\n"); + return -ENODEV; } =20 -static void _opp_put_required_devs(struct opp_table *opp_table) +static void _opp_put_required_dev(struct opp_table *opp_table, + unsigned int index) { - int i; - - for (i =3D 0; i < opp_table->required_opp_count; i++) - opp_table->required_devs[i] =3D NULL; + opp_table->required_devs[index] =3D NULL; } =20 static void _opp_clear_config(struct opp_config_data *data) { - if (data->flags & OPP_CONFIG_REQUIRED_DEVS) - _opp_put_required_devs(data->opp_table); + if (data->flags & OPP_CONFIG_REQUIRED_DEV) + _opp_put_required_dev(data->opp_table, data->index); else if (data->flags & OPP_CONFIG_GENPD) _opp_detach_genpd(data->opp_table); =20 @@ -2630,7 +2665,7 @@ int dev_pm_opp_set_config(struct device *dev, struct = dev_pm_opp_config *config) =20 /* Attach genpds */ if (config->genpd_names) { - if (config->required_devs) + if (config->required_dev) goto err; =20 ret =3D _opp_attach_genpd(opp_table, dev, config->genpd_names, @@ -2639,13 +2674,15 @@ int dev_pm_opp_set_config(struct device *dev, struc= t dev_pm_opp_config *config) goto err; =20 data->flags |=3D OPP_CONFIG_GENPD; - } else if (config->required_devs) { - ret =3D _opp_set_required_devs(opp_table, dev, - config->required_devs); - if (ret) + } else if (config->required_dev && config->required_opp_table) { + ret =3D _opp_set_required_dev(opp_table, dev, + config->required_dev, + config->required_opp_table); + if (ret < 0) goto err; =20 - data->flags |=3D OPP_CONFIG_REQUIRED_DEVS; + data->index =3D ret; + data->flags |=3D OPP_CONFIG_REQUIRED_DEV; } =20 ret =3D xa_alloc(&opp_configs, &id, data, XA_LIMIT(1, INT_MAX), diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index cff1fabd1ae3..5b5a4bd89c9e 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -35,12 +35,13 @@ extern struct list_head opp_tables; #define OPP_CONFIG_PROP_NAME BIT(3) #define OPP_CONFIG_SUPPORTED_HW BIT(4) #define OPP_CONFIG_GENPD BIT(5) -#define OPP_CONFIG_REQUIRED_DEVS BIT(6) +#define OPP_CONFIG_REQUIRED_DEV BIT(6) =20 /** * struct opp_config_data - data for set config operations * @opp_table: OPP table * @flags: OPP config flags + * @index: The position in the array of required_devs * * This structure stores the OPP config information for each OPP table * configuration by the callers. @@ -48,6 +49,7 @@ extern struct list_head opp_tables; struct opp_config_data { struct opp_table *opp_table; unsigned int flags; + unsigned int index; }; =20 /** diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 6424692c30b7..5fade5c4de40 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -63,10 +63,11 @@ typedef int (*config_clks_t)(struct device *dev, struct= opp_table *opp_table, * @supported_hw_count: Number of elements in the array. * @regulator_names: Array of pointers to the names of the regulator, NULL= terminated. * @genpd_names: Null terminated array of pointers containing names of gen= pd to - * attach. Mutually exclusive with required_devs. + * attach. Mutually exclusive with required_dev. * @virt_devs: Pointer to return the array of genpd virtual devices. Mutua= lly - * exclusive with required_devs. - * @required_devs: Required OPP devices. Mutually exclusive with genpd_nam= es/virt_devs. + * exclusive with required_dev. + * @required_dev: Required OPP device. Mutually exclusive with genpd_names= /virt_devs. + * @required_opp_table: The corresponding required OPP table for @required= _dev. * * This structure contains platform specific OPP configurations for the de= vice. */ @@ -81,7 +82,8 @@ struct dev_pm_opp_config { const char * const *regulator_names; const char * const *genpd_names; struct device ***virt_devs; - struct device **required_devs; + struct device *required_dev; + struct opp_table *required_opp_table; }; =20 #define OPP_LEVEL_UNSET U32_MAX --=20 2.34.1 From nobody Tue Dec 16 12:37:40 2025 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1CCE146D59 for ; Thu, 18 Jul 2024 23:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346211; cv=none; b=BwyYeRFzhnn+ZKJJl5Z69jRtldFm/y4iCq3aoF8QxX2wloZ1z/2G4OQltVyZ1Up2XUdW1HgYjvaaNVp4dww+rRrizvMsW1RAFs+cYoyxhnTS1xRAaOhZ49+tU1mGMa5Isks6XrPZxRfjsDD8ce5oTEBpFjU4mdAUSAiWSmyjW1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346211; c=relaxed/simple; bh=Y3hwNFUGYkYRfIHL/7k3SZgbiEUCm5J9K1Jr9I8q53M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ED/xJI7FQqFsiQrn//VviOhlyxXtVcas5aDd7F45NVtB3F2lVPRrkMJpp4Y47xgJ1kpvcU8n3egzOhJX4yU/lSapclu4RsET62CF1rM0gAMBA6Y8/hcMAqhGLAoTdFUuqpvb4IQb8JDoVMkNFtSLd7PYQETWA5Hy35reYAt+XsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=yKnCZb6K; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yKnCZb6K" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-52ea2f58448so1443607e87.1 for ; Thu, 18 Jul 2024 16:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721346208; x=1721951008; 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=Faj5QcK3We3F3NVuTbRR7vS8a3eBKTUsob4pR7kBr7Q=; b=yKnCZb6Khu8Vs/frX6dovOzo+VqjRnJLPt76bngbG/WkJpPmeL6numGXRUd1PqsRxK sr5YHmR6QeL0XnaBwUsxDzZ2IADNag2S2rIE6WNbPiowBiIiQLm4tH3zvqoy/+mp2305 7/2PeV1j2TZaI4AydX/rR6w1G0IW3uTCR8Cd/EaQVcYDRv1LWf2ACT/bUD0ZK6euw2DL mb+JS/fSvHb0LJcQJHeM5djNJmbU0I6wWHx1jWUu3QQFAEAc03vMBFoDvGsjvr7b2+ww BfrvFur/10FxxnMvk8wXd3yovtRzQXoIerCSI+VZb5kru4E/33F2HnLJBGLG4R4oJzV7 PNpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721346208; x=1721951008; 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=Faj5QcK3We3F3NVuTbRR7vS8a3eBKTUsob4pR7kBr7Q=; b=reOOYB5D9ri/h6/OUgvODg+XokfPVsDm2t4tE2kQjI+VGEp34FkOCFKXhDyxwV3Q67 8bJe/eW+HjatgzlCzm3sbf867mJ0EjSqrA2/gsgxIeJaCygQAIiwiSwXZKOPyYMoqmpu ehwPN2/xIDC7vLFmFWyhoz+PtnVn9rMDWGoSg5rZaq4Jq8/rd6XFQTpfvV0z/sTTJkwi X4ZDr0h9N7LQ436Z4AbIgT0DvddDSWIaCOPXatvux8JtV1BdcH61FJQv7yVMVdnpORt4 gYX5YMAerh2avH0MqS13+rJnMNyP3PrTyU2HvtMRXkrXo81tDHUANq/wfQIV/NhrTRrw YuMA== X-Forwarded-Encrypted: i=1; AJvYcCXnoUcncXuXF9Kqwmv1051N1b5aR5551NRxw9JTxOJZVrxGF7jTG2WWzux3gNgk+K0cFkreJ0MZ7c8wWmLHCQXenNQp3WbIHcybh2Dr X-Gm-Message-State: AOJu0Yxc0bIm9TBwmwukoRUrCnExOYTpGmiM5B9cszTpPwozjkIuFr0Q fhKOyydZsxaBQ+TtjgRt+CYNsvy1L7QZuk4DAccBxSJaKeW/9AUKEFkor7p0zk8= X-Google-Smtp-Source: AGHT+IHK7FOzBoV+1FS5of2LM4i6O9EZB5TaiB2xWzxT7vDsImay40B6se0ysI9gGqmvrwlYKjDpPA== X-Received: by 2002:a05:6512:234b:b0:52e:9cf0:69cf with SMTP id 2adb3069b0e04-52eeaea73bdmr3196721e87.62.1721346208245; Thu, 18 Jul 2024 16:43:28 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ef556b4fbsm22491e87.139.2024.07.18.16.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 16:43:27 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Prasad Sodagudi , Thierry Reding , Jonathan Hunter , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] pmdomain: core: Manage the default required OPP from a separate function Date: Fri, 19 Jul 2024 01:43:16 +0200 Message-Id: <20240718234319.356451-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718234319.356451-1-ulf.hansson@linaro.org> References: <20240718234319.356451-1-ulf.hansson@linaro.org> 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" To improve the readability of the code in __genpd_dev_pm_attach(), let's move out the required OPP handling into a separate function. Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- drivers/pmdomain/core.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 623d15b68707..930cd5382032 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -2774,12 +2774,34 @@ static void genpd_dev_pm_sync(struct device *dev) genpd_queue_power_off_work(pd); } =20 +static int genpd_set_required_opp(struct device *dev, unsigned int index) +{ + int ret, pstate; + + /* Set the default performance state */ + pstate =3D of_get_required_opp_performance_state(dev->of_node, index); + if (pstate < 0 && pstate !=3D -ENODEV && pstate !=3D -EOPNOTSUPP) { + ret =3D pstate; + goto err; + } else if (pstate > 0) { + ret =3D dev_pm_genpd_set_performance_state(dev, pstate); + if (ret) + goto err; + dev_gpd_data(dev)->default_pstate =3D pstate; + } + + return 0; +err: + dev_err(dev, "failed to set required performance state for power-domain %= s: %d\n", + dev_to_genpd(dev)->name, ret); + return ret; +} + static int __genpd_dev_pm_attach(struct device *dev, struct device *base_d= ev, unsigned int index, bool power_on) { struct of_phandle_args pd_args; struct generic_pm_domain *pd; - int pstate; int ret; =20 ret =3D of_parse_phandle_with_args(dev->of_node, "power-domains", @@ -2808,17 +2830,9 @@ static int __genpd_dev_pm_attach(struct device *dev,= struct device *base_dev, dev->pm_domain->detach =3D genpd_dev_pm_detach; dev->pm_domain->sync =3D genpd_dev_pm_sync; =20 - /* Set the default performance state */ - pstate =3D of_get_required_opp_performance_state(dev->of_node, index); - if (pstate < 0 && pstate !=3D -ENODEV && pstate !=3D -EOPNOTSUPP) { - ret =3D pstate; + ret =3D genpd_set_required_opp(dev, index); + if (ret) goto err; - } else if (pstate > 0) { - ret =3D dev_pm_genpd_set_performance_state(dev, pstate); - if (ret) - goto err; - dev_gpd_data(dev)->default_pstate =3D pstate; - } =20 if (power_on) { genpd_lock(pd); @@ -2840,8 +2854,6 @@ static int __genpd_dev_pm_attach(struct device *dev, = struct device *base_dev, return 1; =20 err: - dev_err(dev, "failed to set required performance state for power-domain %= s: %d\n", - pd->name, ret); genpd_remove_device(pd, dev); return ret; } --=20 2.34.1 From nobody Tue Dec 16 12:37:40 2025 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C921474C5 for ; Thu, 18 Jul 2024 23:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346213; cv=none; b=UKSBBID7Mxt3SJD3Tp6hQ8jEXO1DptpPLDvm7qsWnOAh/ipyLT32bYyXOtR0kYuQ+soEr1zxpj3n6beICkx8so1pBVmwTFKRx6RNfdeIchc9o5YmgJ+vtTdyxIXuljY6dMbY4ap1GzvK5aBVe7UNnyamKoiNv7vmVkRMbOJ5qi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346213; c=relaxed/simple; bh=NAfpFw+HWYAoDaBWfwr80BMUDZiqy4N+6uqMB5AAJX4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SU4SrKrzgSs1ecsCBuHfW7mdh8m2MX4/MyFlbQ5vWoS4jPBTKaNFmiRTZh4JxqnPe4kyFga0AxqC1i9KRs5Ciozh7Q4pt2iul3CusqXQQ4qLHXmMuwO+H0w7O9zAX75lhOcdj0ERw0s4FQq1PQQATORIVwkSTi3ecW518PeMPEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=NDoUzT2N; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="NDoUzT2N" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2eeb1ba040aso20133631fa.1 for ; Thu, 18 Jul 2024 16:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721346209; x=1721951009; 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=J9vI4SwwGNFQB5ve0cZ2IKXbIbaFjJCx9WMpU5iHjvI=; b=NDoUzT2N5rNubEzf8c2tkC1qn9EcLuP/3SANWyx5XWHbSmlYqH21RG3HrWKHEr9Rpe DmDMPngr5Ww4YsnQPELkoo5nqtCb/DcbCDjVn2RBtLl5H9EA3v++ktKU1h3XNILxMrUA ZDteHFXCPS8hbgZTbD6axL/+qtN1EYwtVdCsnahiH2AnxXlS8g+TUKpAZ0qq2e6MpnhL Bv6/bf4y9RwzUN7LRpJ85ZJtiYnK8h40Fz3xwnDvhujA72b2AeLbWGWLd1t7oOnSqWLG s5PrnBQ8GzM/z3rWR6XG0otadG6HbpM8MkK5BjiJekobe0jIMeMa8TgJgsUd8HotcvWN a9dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721346209; x=1721951009; 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=J9vI4SwwGNFQB5ve0cZ2IKXbIbaFjJCx9WMpU5iHjvI=; b=ScQ9v88mjziB6vcgMYSVGV8/+wkVlCrevs2NT3IUcSK4E9/kIXA2PukCiVpQX9RXMV LHo8N42OpbCcIZGKucP7rf4+DD1cCfJPiqMpr0yA6YLk0fufNUvVW7Ma/HJLR6zeY9aN tJWLevqKR3Q3K73KIlTWxODrDvDqEzG5FGPQftpyV5svaqCtnctiTRoeB5jeGMKWcuUx K64AjGnb6WyDf4Cf2Y+SvdGiugzROXh54Slxm1Me9uy9lzmUwWNIEWEhABNgtVnbQMzI Oev2PD5RLa/2znD0VcTnMOcZkHIWIU43ewva5blUApFMN+rVhaBRJqsHIVm0nd9aEwVW l6JQ== X-Forwarded-Encrypted: i=1; AJvYcCU3hxc9kUUlYA8V7cO/g3FlTRjQK9WdUpQtWcNn4STbpRmR1527+CJbcMmD0QvO/AT6ofN4dj2Upxwu0+geJv9Qa3/bAEsByQgrxNJt X-Gm-Message-State: AOJu0YxHpzLMAFwmksdHHsdfQlmc3cG0A9ThvszsiBY556JcCTrRT6ez PAJGXNEk8vRvnbKoi6hIOdvfTtWN14GwpxXhOyBe9sqWkOlcAeWs+AN438TGc0Y= X-Google-Smtp-Source: AGHT+IHhvBJQZZLF4qvCA1+VeH1XflwZ0B4C4bcRfZpPoV5ESlTMWrHmMyYLyE0Fj/9144c0IPpr/w== X-Received: by 2002:a05:6512:31ca:b0:52e:be30:7e7 with SMTP id 2adb3069b0e04-52ee53a25ebmr4597627e87.1.1721346209536; Thu, 18 Jul 2024 16:43:29 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ef556b4fbsm22491e87.139.2024.07.18.16.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 16:43:29 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Prasad Sodagudi , Thierry Reding , Jonathan Hunter , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] OPP/pmdomain: Set the required_dev for a required OPP during genpd attach Date: Fri, 19 Jul 2024 01:43:17 +0200 Message-Id: <20240718234319.356451-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718234319.356451-1-ulf.hansson@linaro.org> References: <20240718234319.356451-1-ulf.hansson@linaro.org> 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" Through dev_pm_opp_set_config() the _opp_attach_genpd() allows consumer drivers to hook up a device to its PM domains. Their corresponding virtual devices that are created by genpd during attach, are later being assigned as the required_devs for the corresponding required OPPs. In _opp_attach_genpd() we are also cross-checking whether the attached device's required OPPs really belongs to its PM domain's OPP table - and tries to fix it up if possible. In principle this works fine, but sometimes it's not convenient for consumer drivers to use _opp_attach_genpd(). Especially in the single PM domain case, when a device is usually attached by the bus-level ->probe() callbacks. Moreover, we now have dev_pm_domain_attach|detach_list() that helps consumer drivers to attach their devices to their PM domains. To improve the situation, let's instead assign the required_devs during device attach in genpd, by using _opp_set_required_dev(). In this way, the cross-check of the OPP table is always being done. Note that, we still need to allow existing users of _opp_attach_genpd(), which makes this change slightly more complicated. On the other hand, once we have migrated those users to dev_pm_domain_attach|detach_list(), the entire _opp_attach_genpd() should be removed. Signed-off-by: Ulf Hansson --- Changes in v2: - Clarified the commitmsg. - Add a check for #power-domain-cells in genpd to avoid assigning the required-devs for non-genpd-providers. --- drivers/opp/core.c | 35 +----------------------- drivers/pmdomain/core.c | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index b6a699286aaa..cad7e84c9ad3 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2369,7 +2369,6 @@ static void _opp_detach_genpd(struct opp_table *opp_t= able) continue; =20 dev_pm_domain_detach(opp_table->required_devs[index], false); - opp_table->required_devs[index] =3D NULL; } } =20 @@ -2393,8 +2392,7 @@ static void _opp_detach_genpd(struct opp_table *opp_t= able) static int _opp_attach_genpd(struct opp_table *opp_table, struct device *d= ev, const char * const *names, struct device ***virt_devs) { - struct device *virt_dev, *gdev; - struct opp_table *genpd_table; + struct device *virt_dev; int index =3D 0, ret =3D -EINVAL; const char * const *name =3D names; =20 @@ -2427,37 +2425,6 @@ static int _opp_attach_genpd(struct opp_table *opp_t= able, struct device *dev, goto err; } =20 - /* - * The required_opp_tables parsing is not perfect, as the OPP - * core does the parsing solely based on the DT node pointers. - * The core sets the required_opp_tables entry to the first OPP - * table in the "opp_tables" list, that matches with the node - * pointer. - * - * If the target DT OPP table is used by multiple devices and - * they all create separate instances of 'struct opp_table' from - * it, then it is possible that the required_opp_tables entry - * may be set to the incorrect sibling device. - * - * Cross check it again and fix if required. - */ - gdev =3D dev_to_genpd_dev(virt_dev); - if (IS_ERR(gdev)) { - ret =3D PTR_ERR(gdev); - goto err; - } - - genpd_table =3D _find_opp_table(gdev); - if (!IS_ERR(genpd_table)) { - if (genpd_table !=3D opp_table->required_opp_tables[index]) { - dev_pm_opp_put_opp_table(opp_table->required_opp_tables[index]); - opp_table->required_opp_tables[index] =3D genpd_table; - } else { - dev_pm_opp_put_opp_table(genpd_table); - } - } - - opp_table->required_devs[index] =3D virt_dev; index++; name++; } diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 930cd5382032..fdbc3aab9083 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -2774,6 +2774,61 @@ static void genpd_dev_pm_sync(struct device *dev) genpd_queue_power_off_work(pd); } =20 +static struct opp_table *genpd_find_opp_table(struct generic_pm_domain *ge= npd, + unsigned int depth) +{ + struct opp_table *opp_table; + struct gpd_link *link; + + if (genpd->opp_table) + return genpd->opp_table; + + list_for_each_entry(link, &genpd->child_links, child_node) { + struct generic_pm_domain *parent =3D link->parent; + + genpd_lock_nested(parent, depth + 1); + opp_table =3D genpd_find_opp_table(parent, depth + 1); + genpd_unlock(parent); + + if (opp_table) + return opp_table; + } + + return NULL; +} + +static int genpd_set_required_opp_dev(struct device *dev, + struct device *base_dev) +{ + struct generic_pm_domain *genpd =3D dev_to_genpd(dev); + struct opp_table *opp_table; + int ret =3D 0; + + /* Limit support to non-providers for now. */ + if (of_property_present(base_dev->of_node, "#power-domain-cells")) + return 0; + + if (!dev_pm_opp_of_has_required_opp(base_dev)) + return 0; + + genpd_lock(genpd); + opp_table =3D genpd_find_opp_table(genpd, 0); + genpd_unlock(genpd); + + if (opp_table) { + struct dev_pm_opp_config config =3D { + .required_dev =3D dev, + .required_opp_table =3D opp_table, + }; + + ret =3D devm_pm_opp_set_config(base_dev, &config); + if (ret < 0) + dev_err(dev, "failed to set opp config %d\n", ret); + } + + return ret; +} + static int genpd_set_required_opp(struct device *dev, unsigned int index) { int ret, pstate; @@ -2830,6 +2885,10 @@ static int __genpd_dev_pm_attach(struct device *dev,= struct device *base_dev, dev->pm_domain->detach =3D genpd_dev_pm_detach; dev->pm_domain->sync =3D genpd_dev_pm_sync; =20 + ret =3D genpd_set_required_opp_dev(dev, base_dev); + if (ret) + goto err; + ret =3D genpd_set_required_opp(dev, index); if (ret) goto err; --=20 2.34.1 From nobody Tue Dec 16 12:37:40 2025 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97C59148314 for ; Thu, 18 Jul 2024 23:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346215; cv=none; b=Ed4s59smWJwa+N3hMSe/U92n1SbvdMGVBk7V/1WLEdzIjCTCiC9Mhl0artbCkAd9Qie2Yj2C+w7VEB0s5yuUR4tI3rtWH0EXp4mrEh4Sj9BFHpkNX4vDfB2Odfh2M4cJj3p85uO2eHovXxBdjZv+ENM7QnQZsTjZAmpVWOvXvyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346215; c=relaxed/simple; bh=q9HqaY78viyGGiaUkgmvLpNWtXDFKV24MjRfrhvMn+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XYNn16nH5ckTtnLNqp22f01krNCsCxzrMCk5rfjScLWUQoDBt7nukhd1i76RrO+72F7iUbVrztjmKEyUs5qu2evstbHlmE4QhXdh6DOj6/5jShYurbqGEqPkLJfI7KwkVM/TlxA+DDz3uvTGK/+zikatXsq7o3e5C8nTpVWgM/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Z/I9ZBRo; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Z/I9ZBRo" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-52e99060b0dso1109750e87.1 for ; Thu, 18 Jul 2024 16:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721346211; x=1721951011; 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=qiy79RCH12nO+kuD43r9KxQZmT684plvYyRVA5SbNNc=; b=Z/I9ZBRoZ6zTywC1rtlBk+efuDYKgcIlMhFHnaljqMSk7EpqsX0/sA113l4E/o9wlu LRnKUuQoxlHIoF7qAxViIaEXgttiCIXeAlgfgFa9RNGBlRNc8bor845iQLHqrHTRtz4O RmSlhf8cVZ+8/w0EhpWMIk3iTlQWZJRzM/cZPdHDboYBagr8l2A02Ie9v3opihNWC6Ek pNtOxlYtwRFTQTRGQHqo9G1y42jCatIzqTsn9lkIeLhjIkoX7UCJcVxyHaGgHJBY+7Yr PB3OUriKodUml5FrPNfvDFkwlFuMqs3qOIh3KUzxgcgdOxdphMMt0OiL3Y8G2Rud1dby NbEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721346211; x=1721951011; 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=qiy79RCH12nO+kuD43r9KxQZmT684plvYyRVA5SbNNc=; b=SygKQNI/06HyJ22Gpo6m0Q8gMOBI7RXUXSVZuzzAdQFAPUhN7keFwmxGZY8VBdqkCO 6mstnnksifxsOAeR2Nt+6HeNy2wZxgMMzlsGLQXjGvhHceEoO022nU9UgvU/wC1XWwqy 6YTNzwiwWfqewGu+ahEozRqGnhWs9JU6WNT4tPFWeE52odAR0PDZSlmwPAm+lbO+d8Mo Oxomx2K3C6/GIkN5C6E5lmjHFNxmfTNgEGUzaX9CbWh6KY34NYuvmDkXKo7MRRyKC+BP hIEcWp8mlUg87elK7Q4UPsK/6+xxTKsixb/2JqB088M2vttWUERt5q1vCyk7MPHVcm6L Nasw== X-Forwarded-Encrypted: i=1; AJvYcCXbIv1qDxQTHgEoCLqtsRdVPUM7TrkuO+uORwzaenLkV5/62tFnR6b9q5IQPR5pquYwgZJiggjRiS/IwzVXM0Cgw5D7ThYXFeua2wjL X-Gm-Message-State: AOJu0YyWF+ujpNJE8cuzG5jRc0yqVh+PIpPh2qBIGRm588L0LsefVVbE SLjGKAkY5PhZVWXhOaTMWzJoZq58ZUme6qPNGaYppNOEtNwbGOYw7VYe2VUBkvo= X-Google-Smtp-Source: AGHT+IE/PQcs9Xj45ekRvDZ9k+t/Et7RHcrmh62SIuBoPAG7Wl7rJpYPtWq1KQeWzrJ9ZjlpqQ2KEA== X-Received: by 2002:a05:6512:39c7:b0:52c:8df9:2e6f with SMTP id 2adb3069b0e04-52ee5429228mr4551665e87.42.1721346210863; Thu, 18 Jul 2024 16:43:30 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ef556b4fbsm22491e87.139.2024.07.18.16.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 16:43:30 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Prasad Sodagudi , Thierry Reding , Jonathan Hunter , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] pmdomain: core: Drop the redundant dev_to_genpd_dev() Date: Fri, 19 Jul 2024 01:43:18 +0200 Message-Id: <20240718234319.356451-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718234319.356451-1-ulf.hansson@linaro.org> References: <20240718234319.356451-1-ulf.hansson@linaro.org> 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" There's no longer any users of dev_to_genpd_dev(), hence let's drop it. Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- drivers/pmdomain/core.c | 10 ---------- include/linux/pm_domain.h | 6 ------ 2 files changed, 16 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index fdbc3aab9083..bc89edcbd583 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -184,16 +184,6 @@ static struct generic_pm_domain *dev_to_genpd(struct d= evice *dev) return pd_to_genpd(dev->pm_domain); } =20 -struct device *dev_to_genpd_dev(struct device *dev) -{ - struct generic_pm_domain *genpd =3D dev_to_genpd(dev); - - if (IS_ERR(genpd)) - return ERR_CAST(genpd); - - return &genpd->dev; -} - static int genpd_stop_dev(const struct generic_pm_domain *genpd, struct device *dev) { diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index f24546a3d3db..772d3280d35f 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -260,7 +260,6 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain = *genpd, int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); int pm_genpd_remove(struct generic_pm_domain *genpd); -struct device *dev_to_genpd_dev(struct device *dev); int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int st= ate); int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *n= b); int dev_pm_genpd_remove_notifier(struct device *dev); @@ -308,11 +307,6 @@ static inline int pm_genpd_remove(struct generic_pm_do= main *genpd) return -EOPNOTSUPP; } =20 -static inline struct device *dev_to_genpd_dev(struct device *dev) -{ - return ERR_PTR(-EOPNOTSUPP); -} - static inline int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) { --=20 2.34.1 From nobody Tue Dec 16 12:37:40 2025 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD4D4146A6B for ; Thu, 18 Jul 2024 23:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346215; cv=none; b=RQMYkOTQv3DfOE/Sqnp25cyk9ldfgXtGfT3w1CTto+KqJFNgDp+/cR2gH1HpZMBhx7yN4FjW3C+OyqqqnGEgxG90G5wpNuPY01evuyfMpBLhb+FSrJoQpJOEdaYkFPXGJ/+9YpZNBDTqZ6Kw5KrAhYjgsJ+1zBFb1ePlw+/mZfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346215; c=relaxed/simple; bh=qimQZF+FWN9z++adsecIC/pT/coamrdDTurSaVUGTQs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HweU+TK4iVmY4PAae+plIwLEFWYQqE00zI7+DF1ylFQxfTe3R0ZT8Nycg+bfprFmF4PC5JDiBH9RWPB8Cd/aM19unQnfQkBIF0T2buHx6zJxlZ7jJf26XwdvOfBy0o5izunCiugfDF/7HFNNy7swb76XIttstvWqViix0e84nx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=u6KNyqmN; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="u6KNyqmN" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52e97e5a84bso1431673e87.2 for ; Thu, 18 Jul 2024 16:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721346212; x=1721951012; 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=X41EpoGFTr7V+lfPhB4bKmmLvKDngcfGjNQze8E5PAc=; b=u6KNyqmN8TZZocJzEu4W5hIcc/qF2FtxEZXkwZcsb3hobPsqT3FXsZ2gRz0MCCVBOB 6nndK5GyNRgkHvz1yImXOec3t+ud/8GxbZOvi+8DpoHzTiYCYPH2wBU0b5uxmY0sIT4O qjw7dfY0hbOt98+OmN573p+Jx37BQnr5LPg02uDPELKVg5KYhABuHa6Jc41r1HUZP6Jc 7CnAtnC3ZukEr0meXbxGsXL181sbbgaIahUVQZXq3QZJ/MeAWG62Hu8jFvOdbgFFvlxE 5+jejjY+JwRb0gkG6jU5fjIcTcGIAyuAcgsPhsTyot5obpr+u6S5E1URn5fxVr9GeC1K AxCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721346212; x=1721951012; 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=X41EpoGFTr7V+lfPhB4bKmmLvKDngcfGjNQze8E5PAc=; b=m1+m8J1/4B3szM3pbozZ6roDuN4OJZtkHEp9Qh6xiu5au0K7cX9BS/NUZUEaqSDolm dQNxDouQhgnCwdaeB+EVo7FGVgJpC6AQeek86cm2WDHL5uU9qsh3Lrbr8oX4ZC+uxUyE oDvCV1F7s6ilxXwyuIWgQSN/K1fbC7tBImyVmU+tRvT7nTS5WfFAWVi9lOjj5CHi0yB4 K5fqy3tOaLArXMORi1dRa0i7tArpTaTm0uRvI039i6352ifc2oJhlffkjBOJ9cDp4Er7 fdC2HoUqlixiiW6g6HWBJ8SuYDjVIagqtn/9HfRirIA4bafWUPHLC0eIPgv59VO+jIw/ toUw== X-Forwarded-Encrypted: i=1; AJvYcCUxOuX9Lv6pOIm+wKOsn8Rd8OvAGeqvCP62pTjrD9fM1sE+mw+1fSlA2L8RqwrlnHwrk5d9eSZVzNF6GnVQbSPLuqkQ4jL2rmpTebv0 X-Gm-Message-State: AOJu0YyfswR26+yJ/+abeChrhH9oRP67TClmywot/zKFifQ55CGaCCux mPMNYMnxnZ0eX/VTazp0ppGUtcQDnr0iCXiHo0/NshGBPRm4d0PZH569iZ8xQ84= X-Google-Smtp-Source: AGHT+IE9TgIAs0CUhULlnfsv1TaESmkfsLC57MT/HQS4rq5Rt9A4FzXWOTcdoX2vwlTRiyP6cV3eIQ== X-Received: by 2002:a05:6512:3a87:b0:52c:dd94:bda9 with SMTP id 2adb3069b0e04-52ee5452793mr5704184e87.56.1721346212081; Thu, 18 Jul 2024 16:43:32 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52ef556b4fbsm22491e87.139.2024.07.18.16.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 16:43:31 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Prasad Sodagudi , Thierry Reding , Jonathan Hunter , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] OPP: Drop redundant code in _link_required_opps() Date: Fri, 19 Jul 2024 01:43:19 +0200 Message-Id: <20240718234319.356451-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240718234319.356451-1-ulf.hansson@linaro.org> References: <20240718234319.356451-1-ulf.hansson@linaro.org> 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" Due to that the required-devs for the required OPPs are now always being assigned during the attach process in genpd, we no longer need the special treatment in _link_required_opps() for the single PM domain case. Let's therefore drop it. Signed-off-by: Ulf Hansson --- Changes in v2: - New patch. --- drivers/opp/of.c | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 55c8cfef97d4..fd5ed2858258 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -295,7 +295,7 @@ void _of_clear_opp(struct opp_table *opp_table, struct = dev_pm_opp *opp) of_node_put(opp->np); } =20 -static int _link_required_opps(struct dev_pm_opp *opp, struct opp_table *o= pp_table, +static int _link_required_opps(struct dev_pm_opp *opp, struct opp_table *required_table, int index) { struct device_node *np; @@ -313,39 +313,6 @@ static int _link_required_opps(struct dev_pm_opp *opp,= struct opp_table *opp_tab return -ENODEV; } =20 - /* - * There are two genpd (as required-opp) cases that we need to handle, - * devices with a single genpd and ones with multiple genpds. - * - * The single genpd case requires special handling as we need to use the - * same `dev` structure (instead of a virtual one provided by genpd - * core) for setting the performance state. - * - * It doesn't make sense for a device's DT entry to have both - * "opp-level" and single "required-opps" entry pointing to a genpd's - * OPP, as that would make the OPP core call - * dev_pm_domain_set_performance_state() for two different values for - * the same device structure. Lets treat single genpd configuration as a - * case where the OPP's level is directly available without required-opp - * link in the DT. - * - * Just update the `level` with the right value, which - * dev_pm_opp_set_opp() will take care of in the normal path itself. - * - * There is another case though, where a genpd's OPP table has - * required-opps set to a parent genpd. The OPP core expects the user to - * set the respective required `struct device` pointer via - * dev_pm_opp_set_config(). - */ - if (required_table->is_genpd && opp_table->required_opp_count =3D=3D 1 && - !opp_table->required_devs[0]) { - /* Genpd core takes care of propagation to parent genpd */ - if (!opp_table->is_genpd) { - if (!WARN_ON(opp->level !=3D OPP_LEVEL_UNSET)) - opp->level =3D opp->required_opps[0]->level; - } - } - return 0; } =20 @@ -370,7 +337,7 @@ static int _of_opp_alloc_required_opps(struct opp_table= *opp_table, if (IS_ERR_OR_NULL(required_table)) continue; =20 - ret =3D _link_required_opps(opp, opp_table, required_table, i); + ret =3D _link_required_opps(opp, required_table, i); if (ret) goto free_required_opps; } @@ -391,7 +358,7 @@ static int lazy_link_required_opps(struct opp_table *op= p_table, int ret; =20 list_for_each_entry(opp, &opp_table->opp_list, node) { - ret =3D _link_required_opps(opp, opp_table, new_table, index); + ret =3D _link_required_opps(opp, new_table, index); if (ret) return ret; } --=20 2.34.1