From patchwork Mon May 13 19:22:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 164063 Delivered-To: patches@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1728573ili; Mon, 13 May 2019 12:23:32 -0700 (PDT) X-Received: by 2002:a2e:8154:: with SMTP id t20mr2256ljg.180.1557775412060; Mon, 13 May 2019 12:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557775412; cv=none; d=google.com; s=arc-20160816; b=AuFHxk4OCUYE00ObS8ASwJw6LZ52e2oEXD1DjKUVYGTWwxtieEYjndW5gp/bydg+S8 mWHBnxYx3/dyuHVVw6HAG9JuBJTjx17Q/FG5+clK86kxJj6wnSrWN3QTkyN96z6Cqbun U+6xwCeuHg6B86AItWzTFBYmaghuky5hdKSZNA+wJsqieT7rv+vmK0x/RoXA+OpVQoZY VRQygZ5BE6guVGoEorDBcxP07jBUtHoRXYu3gR5qyhV2ffkVcUUQW3+nr9opiQM5a1sk ldcpF4wW68UzfjDJqfXqzT+pBosariaklGD/lEEbgSHzViPD/bpnjnmw97YE4O0rgWmB dL8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5L3+w8hUR6giXqb5Tz84iJ3SS/PuntIOYwjCkJwPh9s=; b=HhbFgCmCBXnRAGbYYk5BB+918BtLWRdnXh3nwDvsrJmAqKo1FBVKsHcMI9X0pZ+6GD sgjZkJGQ/R50vG+ppl9NyBZ9jUrv5b3HSTXLmD8Fkmu3VaOsA+9WQxprIxSSZj3zE6HA yYIKxK4FkCRRarDU3bg9qoC+rBh8EfDAjo5ndHbK8F5PTW0k16iC+s7SG6QxNfVkA6VU /+M6oa9dsHf6cv6WPIcBljzpynmhEi5qUr7BmoXg4N3Q0kLVI7IygyuNMQL0lA8Tx1JJ ywcvLhItYb5HvKqxDEFy+zPHf5ZpR2QHwAMMe8O5TNYZbKZ1QIJrDu+vXnbvk06YAIwH tSsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nuEds6uq; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n25sor2983409ljg.30.2019.05.13.12.23.31 for (Google Transport Security); Mon, 13 May 2019 12:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nuEds6uq; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5L3+w8hUR6giXqb5Tz84iJ3SS/PuntIOYwjCkJwPh9s=; b=nuEds6uqvSvhzFgPN0xx4WrLj+8Aq5wMne2aRP4Hl30ysRHF3JwffRDwh2I/w4NkhA ruqtjGmeavnUC5G6t1+5vD7jYhWzIibj7v8eKj+D5BqywqtbMj4VlBzc5f+oeCC7YVZr gMQJv7sBlyWAqagmqVCdQx6ievkrgzxp6P6VXhi+yjAzjEClLL/IUaPqLF+XdiUzD+wB PoZRlnXLRxkuWULBDbbLIts79BiF1YdM5kTUelzfYB3F6IWAddBJ1onCo4N+i653uveS lhlUL6q4MSOpQOYlAnyDByOwere/dmOdnrZOjhSfSGK/7nMJMIUGdCEIfOTBMbYwDCev MmjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5L3+w8hUR6giXqb5Tz84iJ3SS/PuntIOYwjCkJwPh9s=; b=q6Vkefv2NU1rw71huycM/ELiKPwxcd/OmFEtZe3Y3c0iDyPM5jyGL+rg6a0K4PcQBM JfNs6CKWFR5dRdgc/kSFtsbxbHSCue5fF208kqfdcQaEJ3jQhf0SlenNNDcb66HcVNYG tp1KCoUG+stEoAkd6r+M7tu3ECa5I9YmGqP1qvYlzxW68o4mQ0tqB0c63eHPnJK7+6S0 CAtzlLZru/Q5bdDATENTAbL47fCts7nkctVBwPi39pL0/3ZRxwJR/TMTqfSan8k15cJH xXlDiI9SLQW+ohKbjNXOYc3d9XPqhB0WzJCZGk1zYPiVnX8IAcTx2X7EUbmikcO521bL a/aw== X-Gm-Message-State: APjAAAUmrAsCZZPJd6L+VVbscT69vtvdISGUHTSrpbNookTm5MV0KiLS YoTgs/3ifTVHx4Z3nw7DRiVt2BIy X-Google-Smtp-Source: APXvYqwhviRoSbMrrPulC15a2Em5gq4bwlntBmk6fP/23jtstN9Z1J324DMrQRo3VkPOVmz3QA57og== X-Received: by 2002:a2e:9141:: with SMTP id q1mr14833265ljg.84.1557775411722; Mon, 13 May 2019 12:23:31 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q21sm3449365lfa.84.2019.05.13.12.23.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 12:23:31 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , "Raju P . L . S . S . S . N" , Amit Kucheria , Bjorn Andersson , Stephen Boyd , Niklas Cassel , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , Souvik Chakravarty , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Ulf Hansson Subject: [PATCH 14/18] drivers: firmware: psci: Manage runtime PM in the idle path for CPUs Date: Mon, 13 May 2019 21:22:56 +0200 Message-Id: <20190513192300.653-15-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513192300.653-1-ulf.hansson@linaro.org> References: <20190513192300.653-1-ulf.hansson@linaro.org> When the hierarchical CPU topology layout is used in DT, let's allow the CPU to be power managed through its PM domain, via deploying runtime PM support. To know for which idle states runtime PM reference counting is needed, let's store the index of deepest idle state for the CPU, in a per CPU variable. This allows psci_cpu_suspend_enter() to compare this index with the requested idle state index and then act accordingly. Signed-off-by: Ulf Hansson --- Changes: - Simplify the code by using the new per CPU struct, that stores the needed struct device*. --- drivers/firmware/psci/psci.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 54e23d4ed0ea..2c4157d3a616 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -298,6 +299,7 @@ static int __init psci_features(u32 psci_func_id) struct psci_cpuidle_data { u32 *psci_states; + u32 rpm_state_id; struct device *dev; }; @@ -385,6 +387,7 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, goto free_mem; data->dev = dev; + data->rpm_state_id = drv->state_count - 1; } /* Idle states parsed correctly, store them in the per-cpu struct. */ @@ -481,8 +484,11 @@ static int psci_suspend_finisher(unsigned long index) int psci_cpu_suspend_enter(unsigned long index) { int ret; - u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); - u32 composite_state = state[index - 1] | psci_get_domain_state(); + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); + u32 *states = data->psci_states; + struct device *dev = data->dev; + bool runtime_pm = (dev && data->rpm_state_id == index); + u32 composite_state; /* * idle state index 0 corresponds to wfi, should never be called @@ -491,11 +497,23 @@ int psci_cpu_suspend_enter(unsigned long index) if (WARN_ON_ONCE(!index)) return -EINVAL; + /* + * Do runtime PM if we are using the hierarchical CPU toplogy, but only + * when cpuidle have selected the deepest idle state for the CPU. + */ + if (runtime_pm) + pm_runtime_put_sync_suspend(dev); + + composite_state = states[index - 1] | psci_get_domain_state(); + if (!psci_power_state_loses_context(composite_state)) ret = psci_ops.cpu_suspend(composite_state, 0); else ret = cpu_suspend(index, psci_suspend_finisher); + if (runtime_pm) + pm_runtime_get_sync(dev); + /* Clear the domain state to start fresh when back from idle. */ psci_set_domain_state(0);