Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5556670yba; Mon, 13 May 2019 12:58:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUxTjR4up2RgDaYGWjhVpReZTiHRRY3wH2OOC+hiV6O0C+Xi5a7froTOv4vrG2aeqRXG3h X-Received: by 2002:a17:902:8343:: with SMTP id z3mr33559247pln.240.1557777512253; Mon, 13 May 2019 12:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557777512; cv=none; d=google.com; s=arc-20160816; b=dNyH2x0TfJHRVp7aQn7ac9560FewfMJzLPq9QB35/4Kgm+T1sEKKHCYWDrrNTTftF3 mUH7Bwz+2ntbGWjtoed6oaCVyKDvNyrv6xPU/Oex+uBneluSRydGuQs48cXNAK/Nlp2v rgIhnRt6UsVhZzihcu43FZoG2E/tV+R+DUwcZcC0HoMOA4Fw5Gm4U+n/O4XPdEZ2hNWj KhFjvB80BiLBG3anyd26F3j6C8QteOfUxqvwwwabVU3E9uE58CZS5dJXmI6Z23ItGQsD GzyGHibLANIEGj7pVvAsvhVaj1z6JfGhH2UYCNdc1fPsx/e36W8L1AKaOJquJIj4KOYD P4Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5L3+w8hUR6giXqb5Tz84iJ3SS/PuntIOYwjCkJwPh9s=; b=ijkA+IDkqx4NDbgC9zy6xubpc1v706o1RRPE32IGJfR3lJCHnO6ZsKVzOMsY0NTNM5 sabMckxe8KAKIYABoLbmn3DaYJ1cNpbxXbzJloFvyjQu8OQsr31zx6eE3sg9Ai9nLgPV BoSkhaNKjW1fDQmPFKu3HjW1g/4n+q6+qb8lXLYKmAxaqNSK4aNAFAw7iI9Wp3ojTeRk jdaykR6ZZpDa9tzw7c8oamWgtkZBDSqyV+WyTgZVeBXg79ZwnLZyZwtCc7mPnrl03Hr6 8FcVPLEN4PyNgJYwq8oRhW2TRbV/daTE8Z/zjQBMGhuiYZiXR3FY8x9kFP4WfJvoPmEW 6u1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nuEds6uq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si18678360pln.52.2019.05.13.12.58.16; Mon, 13 May 2019 12:58:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nuEds6uq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727204AbfEMTaF (ORCPT + 99 others); Mon, 13 May 2019 15:30:05 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:40324 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727171AbfEMTaF (ORCPT ); Mon, 13 May 2019 15:30:05 -0400 Received: by mail-lj1-f196.google.com with SMTP id d15so12079986ljc.7 for ; Mon, 13 May 2019 12:30:03 -0700 (PDT) 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=Bxcy5vZ6z7coYhWJfLDMx3b+bLzFbKvQXGCEtjCsy8OaveLbw7CFT6mnOrt3Co20mb NjlMfgNAhKZ04IUWyaLB+TIK2qySpkXKM6Rit0HKnTdlyLP3E2dKUzVlUgeUaJp/XpM+ rqcocsrJhGEuJ1/KbBDfYxODYQRgVCyx4wsiT4OqkqX8wwHCql8BpxVqCkByEaNxw4VU JMDy9CHxdbiK2anqBBnhOM6d63SIYTRf+HkVwSx7zn2hjVamiuaTPuc/q9wXT9BnHrod 7/rZmfVImEjumoBhETO0aq1EYnxseq/JMSR3/D4APbrXgL6YYF9pO3mCzL+qxwVhxZLy v95Q== X-Gm-Message-State: APjAAAVv2t6QmT+7EM7cOonZLjyNwIc0uMMhnGuOtkUN5DBjxqTlT7fO rrOXPo/bPf6zEJlp0nQs10yxlw== X-Received: by 2002:a2e:9141:: with SMTP id q1mr14833265ljg.84.1557775411722; Mon, 13 May 2019 12:23:31 -0700 (PDT) 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) 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); -- 2.17.1