Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5555409yba; Mon, 13 May 2019 12:57:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwT9/GNa2RJm/kz/qzngSTkWzrFN8VxjXGTDy4EMp+3mp9gzMv3ts3/yomImHs62sl2JmkN X-Received: by 2002:aa7:8d81:: with SMTP id i1mr7879641pfr.244.1557777423158; Mon, 13 May 2019 12:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557777423; cv=none; d=google.com; s=arc-20160816; b=zr1gkfrMG/ieZnkVdoUEdQleVWs/KFkTofANpgmPc7EPW1h6zoLPUvtf07KnR1+Pxc RsGVU2CI8xHZEpZsit1lN2ZNgm6fQszuo8w2HyYkumz76SaAtcF3K4usgPzy2KjjiOnH oM5X9wqz+V0hbVPHAcUp8+yiG2FtqB3d46fK1qm0s3/Tp656uJOWKqimpJed3Zwh40GT pQ1Y5dgwqCxjxWspu+9dX1RHX7tkOTWgORa+vlL37eqO9EPZKuH5d0Yzgc/d8PVbqREC 5KQWc59iWS92Bzqa1GH6xCTZnfyBEr+b07Yn/Z2cdxj5jnUfQ+5oR8lJ/szKF0qF831K 2zRA== 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=WrUBlQWQzfbgrdk7klxniFTaW91XaiQj55o38mlFd9s=; b=ElV7mUzet1LsxolaHqMw6CVi2Q4bgITEWW9qTJeCBrC+DuNpgW/W16UFB4UwZUju/t /RW6jAWT6ITl8xnq5yrFaBWg6wr+2ju1Egb1SmCqbN/OQ0tGTlyyamRgoHpOluVC6vmr 25ivQvqYTv9yAOQuSuwAooiCwnPpbiTk4MHpzSwbjuxR08LjCozE4lSQeoXeQuMarLnH XWYKvM9ObMEl+KSsKirylaJSPk0GEs1DwtjLO39VHuK8FOe4nByMJ/aFd9cMRI9bCNdF w84kqZpjYvpTdy3obcsDZu831X3ZHCOi+r4XvLSlq8p3XFCWGXsVpmlqpSp2VKfxk9J0 w2Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sPy1xWva; 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 cj16si2638046plb.239.2019.05.13.12.56.47; Mon, 13 May 2019 12:57:03 -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=sPy1xWva; 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 S1727157AbfEMT3r (ORCPT + 99 others); Mon, 13 May 2019 15:29:47 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:44042 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbfEMT3q (ORCPT ); Mon, 13 May 2019 15:29:46 -0400 Received: by mail-lj1-f195.google.com with SMTP id e13so12060976ljl.11 for ; Mon, 13 May 2019 12:29:44 -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=WrUBlQWQzfbgrdk7klxniFTaW91XaiQj55o38mlFd9s=; b=sPy1xWvat53hABQ29ElA2SDvZnqfRV5oZCv6u9/BoxR2ZPqFXvyAG3a5TqRkJY1a78 ViroHIx+ON0jQRU/3UrEYHgnwsRgfEfK1eI6rvzBvxBl01A+l0VD3RNQr/pCLeiGgll5 oZk8WImmrSosBLIL5WDY5HKxk6DoQYAY3hOyay9Zaekc0Qx48OBqfoEIU9LOQbcuUzO9 y21fdWLhr9sVngZjVbZUtziI2z+WwnXK05qOJ7jaN6FqE68r4gmG+pebrx9IRchSta0X VzfAclg9EtvAhwIfrDB0k8yyetyh5giqMkUfQdSjeFYl6oWMRIbrHygy50HEN/rtT2Ov JANw== 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=WrUBlQWQzfbgrdk7klxniFTaW91XaiQj55o38mlFd9s=; b=Orc8sY3wM1BUy1jnXzm1SubTuWkfNubsUHuYrI9F2yvqacyn8gDUVjPUBFYUMqdVZv S67tJ3heMJIsJRbg67tJrarRBHfHY6e5wJasN37VF37MQOAKozezPEoBOtj7GLIebc7L ilaLOUHPfvlKaoH5snSHrK6PZvtkBmUvV5oOCJ5uE3jGg5B/N7ZDFbKiOAMxr6mWE3J1 H/+sQq0/rnlSuoFczp8WxHKbyih4NePdV0yGyVFwesD2VN5QNwxAW6rmAHc7Y5kEDg4Z VIuuzsk3zUyvOKWX3hJf85nA9qsFX43UsRdFyCgkdzYwo282/IN2jP3e5IUmTetRpxLZ L2zw== X-Gm-Message-State: APjAAAXcpFiInXUeauTlLP2sxe6mxe+LZt2WagAZklEu+3FNF8FeZgkx Os8skeYIr98FsCfAdTDF0L1fOA== X-Received: by 2002:a2e:2b58:: with SMTP id q85mr14768159lje.179.1557775413538; Mon, 13 May 2019 12:23:33 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 12:23:32 -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 15/18] drivers: firmware: psci: Support CPU hotplug for the hierarchical model Date: Mon, 13 May 2019 21:22:57 +0200 Message-Id: <20190513192300.653-16-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 is used and when a CPU has been put offline (hotplug), that same CPU prevents its PM domain and thus also potential master PM domains, from being powered off. This is because genpd observes the CPU's attached device as being active from a runtime PM point of view. To deal with this, let's decrease the runtime PM usage count by calling pm_runtime_put_sync_suspend() of the attached struct device when putting the CPU offline. Consequentially, we must then increase the runtime PM usage count, while putting the CPU online again. Signed-off-by: Ulf Hansson --- Changes: - Use get_logical_index() to find the CPU number. - Verify that a corresponding struct device* has been attached to the PM domain before doing runtime PM refrence counting. - Clear the domain state when the CPU goes offline, to start fresh. - Move code to internal helper functions and move them inside "ifdef CONFIG_CPU_IDLE. --- drivers/firmware/psci/psci.c | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 2c4157d3a616..5ad93c3694b5 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -93,6 +94,9 @@ static u32 psci_function_id[PSCI_FN_MAX]; static u32 psci_cpu_suspend_feature; static bool psci_system_reset2_supported; +static void psci_cpuidle_cpu_off(void); +static void psci_cpuidle_cpu_on(unsigned long cpuid); + static inline bool psci_has_ext_power_state(void) { return psci_cpu_suspend_feature & @@ -188,6 +192,8 @@ static int psci_cpu_off(u32 state) int err; u32 fn; + psci_cpuidle_cpu_off(); + fn = psci_function_id[PSCI_FN_CPU_OFF]; err = invoke_psci_fn(fn, state, 0, 0); return psci_to_linux_errno(err); @@ -200,7 +206,13 @@ static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) fn = psci_function_id[PSCI_FN_CPU_ON]; err = invoke_psci_fn(fn, cpuid, entry_point, 0); - return psci_to_linux_errno(err); + err = psci_to_linux_errno(err); + if (err) + return err; + + psci_cpuidle_cpu_on(cpuid); + + return 0; } static int psci_migrate(unsigned long cpuid) @@ -540,8 +552,41 @@ static int __init _psci_dt_topology_init(struct device_node *np) return ret; } + +static void psci_cpuidle_cpu_off(void) +{ + struct device *dev = __this_cpu_read(psci_cpuidle_data.dev); + + /* + * Drop the runtime PM usage count if the CPU has been attached to a + * CPU PM domain. This is needed to, for example, not prevent other + * master domains in the hierarchy to remain powered on. + */ + if (dev) + pm_runtime_put_sync_suspend(dev); +} + +static void psci_cpuidle_cpu_on(unsigned long cpuid) +{ + struct device *dev; + int cpu; + + if (!psci_dt_topology) + return; + + cpu = get_logical_index(cpuid); + if (cpu < 0) + return; + + dev = per_cpu(psci_cpuidle_data.dev, cpu); + if (dev) + pm_runtime_get_sync(dev); +} + #else static inline int _psci_dt_topology_init(struct device_node *np) { return 0; } +static void psci_cpuidle_cpu_off(void) {} +static void psci_cpuidle_cpu_on(unsigned long cpuid) {} #endif static int psci_system_suspend(unsigned long unused) -- 2.17.1