From patchwork Thu Jul 18 23:43:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 813517 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 E7B361465BE for ; Thu, 18 Jul 2024 23:43:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346209; cv=none; b=SX83Bed6QtqFi3d6c5uG4i2CbT2VqgRifexMe/XBQR4f7mxYyFljwogQnsoGAsS/jkhuKlHn+Oni1H5rWTjmvwyT/jqkcyUDHtxWk82l06Mhv80fqpVWTO6Vd1JmmyIVzBvgnpABR/ViZ9pnqeanCVHlb+b1rVAtHQ/9/kUQI98= 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.46 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-f46.google.com with SMTP id 2adb3069b0e04-52ea2ce7abaso1466144e87.0 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=ON5eGfSOmuQ0rQ8irRNuW5k8K0y6ctvIYFeGh48pW7ouLDGccIjjhHl2R7G3yOXbwG jsNbtxpbGcaUrZf5ryJ0tTIhC8dZ0TkJXflBLETwvu1b85h/vTxmz86m0/DBzm8DO9Cw xiyxJ0nhid9M4apHirweegEk46Zdmsv/GXfGmB9nQT1IBNa+9kfDIiNlDjkgNb4SyZOh G7OSEluCTzDts6DlVE/9Kv6HSuwyU3sXQxTNaAapuT9hif5eiWuQDBFiJZFCfjLTkTvR c95mSLpoS4DOSowsMIEuJQti9PytMF86zhmc6pS+4qaW9ObGzsOIoTSw8NeAorM2CZz7 kkag== X-Forwarded-Encrypted: i=1; AJvYcCVHl6VIZBVrM0uYUszPMXH7q8iWcQ6i7qSUSiXVIqdZBpr8aXSaYjg9GWqh8HNPntUPM08Y6D4ebvH+XZEtzs8FfMSlEJ4an6Y= X-Gm-Message-State: AOJu0YwDn09HmorNnEtsZr1O1NJzBGbvEwnXrCnmBfy4GheoTpSEVQgV oKmdDvTSrX/5MRLwnBawLvLrmhfJObEjSkm/kNX6fiqSSzPe1YIjhGB9iqzsRIg= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_table, return 0; } +static int _set_opp_level(struct device *dev, struct dev_pm_opp *opp) +{ + unsigned int level = 0; + int ret = 0; + + if (opp) { + if (opp->level == OPP_LEVEL_UNSET) + return 0; + + level = opp->level; + } + + /* Request a new performance state through the device's PM domain. */ + ret = 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_table, struct dev_pm_opp *opp, bool up) @@ -1091,7 +1112,7 @@ static int _set_required_opps(struct device *dev, struct opp_table *opp_table, if (devs[index]) { required_opp = opp ? opp->required_opps[index] : NULL; - ret = dev_pm_opp_set_opp(devs[index], required_opp); + ret = _set_opp_level(devs[index], required_opp); if (ret) return ret; } @@ -1102,27 +1123,6 @@ static int _set_required_opps(struct device *dev, struct opp_table *opp_table, return 0; } -static int _set_opp_level(struct device *dev, struct dev_pm_opp *opp) -{ - unsigned int level = 0; - int ret = 0; - - if (opp) { - if (opp->level == OPP_LEVEL_UNSET) - return 0; - - level = opp->level; - } - - /* Request a new performance state through the device's PM domain. */ - ret = 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_table) { struct dev_pm_opp *opp = ERR_PTR(-ENODEV); @@ -2457,18 +2457,6 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, } } - /* - * 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 = -ENOMEM; - goto err; - } - opp_table->required_devs[index] = virt_dev; index++; name++; From patchwork Thu Jul 18 23:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 813321 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 195AF145FE3 for ; Thu, 18 Jul 2024 23:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346211; cv=none; b=kZ1TmW1i8AqX0D5WBPcEvJZpPcCf/nSOh0W1FbDGvpeKKFDu5Wnn1mxrjW4SICEkU0u2MgDPHNPXfCjpy+3L7Vxh6zuVWqXh11TZoTTiWXliF2jz5sa1FEKIW7HNfjTX1iME6X3qMBoV2y+UaTVdTquaXGcfFv72eznA3w9v8yk= 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.42 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-f42.google.com with SMTP id 2adb3069b0e04-52e9a550e9fso849950e87.0 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=hC8K4O/uf8tmabxgok8jKQpJ24GiLTsifeRVDCeylZaY0xhkwoculVS6ZS17woBCGJ UEtmlE5F/drEEsTtUeKFAVXD6D/FYcdF8CJ5gF7W6nMqKEystnMA4zgfPz1zjs3aRKyD EQGf6cM6g3JljXrVE0XcgWr3LUSF1CvSuotkP0Sn3le4+yx0G+CkQ5QfFsU5uq5YkywU vLz0Iz2aZMWikHV4MX4EamLmPzug+XDRmRudsVIhJ0hUZLLLIE2GAMSctMCvfsrSJyFK wC/aYZkrw6fhERF+5jPs7zxsltGqnk1+50v3RVWamdYd8TGn25ql/nIEcAwnPlHSegFf GwPw== X-Forwarded-Encrypted: i=1; AJvYcCVc9mu7qyTEbYolojmC0qqbu7COiQwKNyHrkuPClN9y1jq0Art1j2gzfsxz6Vy1gnJDZO/X1hC58Tky58fu4RPwSuQhQco9scA= X-Gm-Message-State: AOJu0YyxBFre1BB2+E26v3W9h+o3+5Wx1PWZsmC+RNrxbcoK+m4nEGPk kf9bbvFLdIeP/MdtTZHwfSqIen3CptiMjAck+IMWHH9S/okbswoJSI6yweaX8LE= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_table, struct device *dev, } -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; @@ -2484,36 +2485,70 @@ static int _opp_set_required_devs(struct opp_table *opp_table, return -EINVAL; } - /* 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; + } for (i = 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 = 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; - opp_table->required_devs[i] = 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 == 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 != table) { + dev_pm_opp_put_opp_table(table); + _get_opp_table_kref(required_opp_table); + opp_table->required_opp_tables[i] = required_opp_table; + } + + opp_table->required_devs[i] = required_dev; + return i; + } } - return 0; + dev_err(dev, "Missing OPP table, unable to set the required dev\n"); + return -ENODEV; } -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 = 0; i < opp_table->required_opp_count; i++) - opp_table->required_devs[i] = NULL; + opp_table->required_devs[index] = NULL; } 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); @@ -2630,7 +2665,7 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) /* Attach genpds */ if (config->genpd_names) { - if (config->required_devs) + if (config->required_dev) goto err; ret = _opp_attach_genpd(opp_table, dev, config->genpd_names, @@ -2639,13 +2674,15 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) goto err; data->flags |= OPP_CONFIG_GENPD; - } else if (config->required_devs) { - ret = _opp_set_required_devs(opp_table, dev, - config->required_devs); - if (ret) + } else if (config->required_dev && config->required_opp_table) { + ret = _opp_set_required_dev(opp_table, dev, + config->required_dev, + config->required_opp_table); + if (ret < 0) goto err; - data->flags |= OPP_CONFIG_REQUIRED_DEVS; + data->index = ret; + data->flags |= OPP_CONFIG_REQUIRED_DEV; } ret = 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) /** * 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; }; /** 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 genpd to - * attach. Mutually exclusive with required_devs. + * attach. Mutually exclusive with required_dev. * @virt_devs: Pointer to return the array of genpd virtual devices. Mutually - * exclusive with required_devs. - * @required_devs: Required OPP devices. Mutually exclusive with genpd_names/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 device. */ @@ -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; }; #define OPP_LEVEL_UNSET U32_MAX From patchwork Thu Jul 18 23:43:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 813516 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 0823E146D6A for ; Thu, 18 Jul 2024 23:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346211; cv=none; b=DWTMUO3UEHgrcFG8oGVDP/4CltAX+e/uJJtg53kJWTO9cnmTugdnYFjrgO0sYs89jkZxzD4UMG5vvFdjOpy60JfD2GlVCj7Ew1G7eaPJgSSwLCgXqD13SEEnkcP7ZenNqzIrq3oA8fvLfFN5qfczIlBn1Jel1mYMSC6M5w8JbAc= 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.50 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-f50.google.com with SMTP id 2adb3069b0e04-52e98087e32so1139322e87.2 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=hlWiuEsvtlVOOJSSDqeJvaTTWTqImvPYcW+DMCvgyXBM6IC9d4W++oWd4jHZUsIyZs Io/+DYxHAHzrzVb1MpKua3ogP1fRucS4Wqwg4cs8Ro31QTKxoIf/bndpNO10FMvxlvZc y+oauEmNRCOCcBMleatcPIsj4EsmaxuEm7A9P1HodAoO9u1Uo9oye5QyLULGHtlgDRkX Oq0bYlRAnLBTsN0Vt0t4rqSMOZEKwHFBmHBNlm/m3dhjASVnrGJ1S26Chagvp/wOQitj 8Zrb5McNFSLvWds9q8Z6i3kH1PQEZk249WSj9E/DAnLBliswyctZ/NcF8kzs8t24SSfj kUkQ== X-Forwarded-Encrypted: i=1; AJvYcCVoBy0CPXnuhxRgwg+DgukQGcKKK3N9zC0vZZDE1CGvR1IeSD11nEjXlKfPuSNQgO2jVFYhVW4pLm2+v68y/eQ8rtO6C/qbEKk= X-Gm-Message-State: AOJu0YwxlVW6KJM1K+IPKYFvIe0CeD1gy2rtnKT+mkUzLJy+5yirAOY1 x76WXsHRuR1MwFMPWve4zNGl5rXQJ8J5aev6FIYMT4FIjpHZ70vbF4TUMwGmNgyVPgr0BcXyM00 6 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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); } +static int genpd_set_required_opp(struct device *dev, unsigned int index) +{ + int ret, pstate; + + /* Set the default performance state */ + pstate = of_get_required_opp_performance_state(dev->of_node, index); + if (pstate < 0 && pstate != -ENODEV && pstate != -EOPNOTSUPP) { + ret = pstate; + goto err; + } else if (pstate > 0) { + ret = dev_pm_genpd_set_performance_state(dev, pstate); + if (ret) + goto err; + dev_gpd_data(dev)->default_pstate = 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_dev, unsigned int index, bool power_on) { struct of_phandle_args pd_args; struct generic_pm_domain *pd; - int pstate; int ret; ret = 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 = genpd_dev_pm_detach; dev->pm_domain->sync = genpd_dev_pm_sync; - /* Set the default performance state */ - pstate = of_get_required_opp_performance_state(dev->of_node, index); - if (pstate < 0 && pstate != -ENODEV && pstate != -EOPNOTSUPP) { - ret = pstate; + ret = genpd_set_required_opp(dev, index); + if (ret) goto err; - } else if (pstate > 0) { - ret = dev_pm_genpd_set_performance_state(dev, pstate); - if (ret) - goto err; - dev_gpd_data(dev)->default_pstate = pstate; - } 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; 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; } From patchwork Thu Jul 18 23:43:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 813320 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 3B9EB1474B4 for ; Thu, 18 Jul 2024 23:43:31 +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=1721346213; cv=none; b=AU7JvL/8CsxlaC7eNc9J1jFJz8XMTMiS35WxrdVce/sTVp95shQ6AIsP7C6BLjUne6cHeQdcKkzM4vk8qpddxZ24ZRS4T8WcPlkPbYuqIedeunvtErAXiGPlCfECl0CVszCi39LsHE/MDnyopJbokv79QfiNclCj3jgb8YG8SA4= 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.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="NDoUzT2N" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-52e99060b0dso1109729e87.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=D+oAlgT3J4pL/t9/4nsKqT0RR4jAEOFsHgQOUriqhOny0rToIhZtHHfjY/k0Q1kuxg ubm5dBAhC3hoYXFTQA1yP1zOo62vDe9f+Qfez9U2GMvu9yqRJR7rlkFvrNm0MJbP4Mbx tHZhgrQ8yHu5ORvDGQCocR/7RdAT+qyh+YYLhrMuS2NsFpNEcRJ06F1zYrcDi6P0N8rd PiUSQbl1lXbQryx0jmcBb0u4D6uCXglF2MI2/LapIBpkIsjtGMHfXHUoSkEPoIAGGHDR +oPK6T2sAo9fVz5phe8E9QQ+cSjwfCzJdW2EnTDh0oBhhAOlnYoFFqypYacH0siiv2uT K+MQ== X-Forwarded-Encrypted: i=1; AJvYcCVAgKhgjN1vFDO0WIqZDzwJgGd44wB8kGG/cZtCE+OuLyToQGA5SV2FNDa+o+7t+bvlqRLcRU+H6AW3Avkmsxm80Jrzqit/Rc8= X-Gm-Message-State: AOJu0YxDxhXlqQ7l5pZnp0qVaIHGarQKdM+QrIyXaRb1dj9a+KC4Z77k PcSNfISQBfbYpBQgtae3oQqPKJANht3j274wmzfaJlUh3hvrVLRgdb6eBUtmyFQ= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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_table) continue; dev_pm_domain_detach(opp_table->required_devs[index], false); - opp_table->required_devs[index] = NULL; } } @@ -2393,8 +2392,7 @@ static void _opp_detach_genpd(struct opp_table *opp_table) static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, const char * const *names, struct device ***virt_devs) { - struct device *virt_dev, *gdev; - struct opp_table *genpd_table; + struct device *virt_dev; int index = 0, ret = -EINVAL; const char * const *name = names; @@ -2427,37 +2425,6 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, goto err; } - /* - * 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 = dev_to_genpd_dev(virt_dev); - if (IS_ERR(gdev)) { - ret = PTR_ERR(gdev); - goto err; - } - - genpd_table = _find_opp_table(gdev); - if (!IS_ERR(genpd_table)) { - if (genpd_table != opp_table->required_opp_tables[index]) { - dev_pm_opp_put_opp_table(opp_table->required_opp_tables[index]); - opp_table->required_opp_tables[index] = genpd_table; - } else { - dev_pm_opp_put_opp_table(genpd_table); - } - } - - opp_table->required_devs[index] = 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); } +static struct opp_table *genpd_find_opp_table(struct generic_pm_domain *genpd, + 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 = link->parent; + + genpd_lock_nested(parent, depth + 1); + opp_table = 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 = dev_to_genpd(dev); + struct opp_table *opp_table; + int ret = 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 = genpd_find_opp_table(genpd, 0); + genpd_unlock(genpd); + + if (opp_table) { + struct dev_pm_opp_config config = { + .required_dev = dev, + .required_opp_table = opp_table, + }; + + ret = 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 = genpd_dev_pm_detach; dev->pm_domain->sync = genpd_dev_pm_sync; + ret = genpd_set_required_opp_dev(dev, base_dev); + if (ret) + goto err; + ret = genpd_set_required_opp(dev, index); if (ret) goto err; From patchwork Thu Jul 18 23:43:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 813515 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 716911482E0 for ; Thu, 18 Jul 2024 23:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346214; cv=none; b=nTRt7qXeY2dsaIzCrcNnWxWr/cWLszqB980dx8uaTTSp6gOflVF8uKVyRUutVlksZLXyGuGvvexNbQLwTC9Z0Qlz8lNwJlWY3JC36/OkUa2FBK92Ox6DuM9hjWtipwEkM9Xo1WZmvREH3mz9ryMHtYV4KyPAhk1aMT17+YIeMK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346214; c=relaxed/simple; bh=q9HqaY78viyGGiaUkgmvLpNWtXDFKV24MjRfrhvMn+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I26yREIzm2TVXRcg3pC9Ft9sX7B7WTHRsyCS8hJyiiEp2Uzb3SNTufkFvKVc4tb9vrSkeBNt0/sZ91HRSGeHn9Lb5+2kZZxABXFJIjHMa8fJwC4U1/pWLhyaqs6XAay01ZRSWNctnQmc291/u3ej7eDes1QEgT65fpZbKfl8xAo= 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.46 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-f46.google.com with SMTP id 2adb3069b0e04-52ea79e6979so1206442e87.2 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=UsiMUPmnM/snfdEEzLROGBb3fM/5CPwWrzsnIaAmp20oTVWrYJQix6Hv2YeUC7zqp1 HAD0ryruYZiKciGLUj4mzytCw+/zMxqzb8TRPughcVmM91v2titK/GtG49NjDncLpCK3 xRc6w2IdD8DWm0NYVekOQrJXMKSIPCZdXnfCiKZagCUbSBj+yvOPUkkI4R7nkxlrlb90 1plWPJ0kZmWEo3wJhI+W+LCIhEA/OGr6/8y0YIclg5xAeogoyrvKM4AYtnMK25AKDsg6 LxZRPtpm7bGa/xPmKCneYRR8N0RxTqIpMUb5sFdqINf7lmD9SuraWvPbR9L5s90R13yX /ktQ== X-Forwarded-Encrypted: i=1; AJvYcCWvxRHDg5HN1TuK8u8piygyTkceXmR4Fw7bUhbHSyTuJlIdS99C8Fr6/WVKMtrPahU+BINTjs5V63t/TFHRbSo3aSg2Dc5QL/k= X-Gm-Message-State: AOJu0YykXYKfvu80F0/wfx+h5ig9c6sHwyjo6jcgpVMj7JGIGU7J7kAH 4MeSLW04z0wFRG0CCDrMB8m2F8BJGCaUga/BLddODRC5ZpnnkJd5ydiFazakfr0= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 device *dev) return pd_to_genpd(dev->pm_domain); } -struct device *dev_to_genpd_dev(struct device *dev) -{ - struct generic_pm_domain *genpd = 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 state); int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); int dev_pm_genpd_remove_notifier(struct device *dev); @@ -308,11 +307,6 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd) return -EOPNOTSUPP; } -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) { From patchwork Thu Jul 18 23:43:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 813319 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 C4E1D14659C for ; Thu, 18 Jul 2024 23:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721346215; cv=none; b=CN88Nq6zm3TyzX2bm1dLmj38sOxwZo7EHgO9VFs9W5imtZaBczr6BICD9RMHU9lqQB/tyvHYUgWmlpA+7sNptkdqdEbff2ks8Q8Mc4d+ZJX133w8J8eG1U2KjiOPjlGPu/z0gtWKccPH9t1SvZS2DRhB3xcSobpo+/wRwx7ZDos= 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.42 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-f42.google.com with SMTP id 2adb3069b0e04-52ea929ea56so1856969e87.0 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=Fbz8jKFB+0VgxDXEVrC3s+FYBPMslwB9udszwvIy/MC1v8ZDWQQobhqM5AlLGSxjaa HErhLg9fiQh0f77BzePjRglOGD8p8THpMALSbppzgpC9jJb+BS556Q+0mPCLOQxyuZyf G8WQwSVW/Oqv3blp03nyGsW3ffbG5xm5RROgUwAbcIMnzb+L5s/hNFsRfAnJcqSe5Ke2 RBfg1txI/tpMcZohoRA+iCS1DKEhvuFH9xgOAeOZCgV4prg5JCpcrN50hR8cfsXCa2Ml NfqP+CW2TYi4uwhDwfgiD4fj0JNV6NrlKAqt8J4OpqUo2oqVRBNMBX1+HPkCn8LoSnZR d0Hg== X-Forwarded-Encrypted: i=1; AJvYcCWl+Z+RLnLbsNnVhtw6GOmsPNdOSzmD0WvNwyH+bnr5f43Iw/86sP4fRB1+udMYVflZKNZGfnfpkqGmOUVBaShaDLjiBZOcUIU= X-Gm-Message-State: AOJu0YyPANUEQAjIR3KoyxfyTnZT1MTtnFkoEiqqgFDfFh9nIZ/qF+ZF tASu7jlskmSCvpfRmiJ5w1vRcQn/Z5Vx4lZE7vJMecxbwK0r5uq7afiX+iGx1ns= 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-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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); } -static int _link_required_opps(struct dev_pm_opp *opp, struct opp_table *opp_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; } - /* - * 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 == 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 != OPP_LEVEL_UNSET)) - opp->level = opp->required_opps[0]->level; - } - } - return 0; } @@ -370,7 +337,7 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table, if (IS_ERR_OR_NULL(required_table)) continue; - ret = _link_required_opps(opp, opp_table, required_table, i); + ret = _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 *opp_table, int ret; list_for_each_entry(opp, &opp_table->opp_list, node) { - ret = _link_required_opps(opp, opp_table, new_table, index); + ret = _link_required_opps(opp, new_table, index); if (ret) return ret; }