From patchwork Thu Oct 10 11:39:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBBF21864 for ; Thu, 10 Oct 2019 11:40:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACFD021A4A for ; Thu, 10 Oct 2019 11:40:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oY4GQ9ts" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727709AbfJJLkK (ORCPT ); Thu, 10 Oct 2019 07:40:10 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46241 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727391AbfJJLkK (ORCPT ); Thu, 10 Oct 2019 07:40:10 -0400 Received: by mail-lj1-f194.google.com with SMTP id d1so5794742ljl.13 for ; Thu, 10 Oct 2019 04:40:07 -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=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=oY4GQ9tspotLOINThxk9Kbs/w01ctme9MEPIEv5nplvQc0Gfk2yTpx63vcTwtFKh4B B+T2P47iK3kLvh+AM79Ow8hzpSL3BwO3bqbzE3b2EGXWMtodySrd61pw72AcbbCRFUpW afPqjSPD0x36xrozZ3piihjF4z1ppF7c8+sdn5Eb7tbNOIM4xve2bbcEhfKjKH3SEPiz mq2/6LaFi7GwljgIrb1NuH0pROuM4yrNj2ZjU5Ymvi8IEwKvRk9+do8bNp27z4n8h5v2 epXCe1vP/SQbHMt0CKqt4ltRSdU/ZufhVj++KFLUQjmpFA0FFee9QlnZH1Yo6uEaRSRm /omw== 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=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=HPJiDCMruhWqF/CFxh6vhAMIn7Imiglrt6ZlyVoTgE/YpdGthlKLcYi/crm4yvtKPh QwHy0nSudQsIUOuHYW7Wcsz2ykN3PFOVXI9P2xWnPwgQXXZKMx6iPwvzzXaAe0Gji2P7 uWoN7u6AfPesE0IWzBSnnfsZ5s0Q8UMr7Kb9PEQDS2jHIZvnY25tOsZ40aUjlJEk/9bC 7Bj0Rbq60rfxlbjERQSrGNGi+hsGtxMKJGA3QeNqvfkzB3A9QHO4t4Dm8UcWcVS8omQS 5NftPHQLMTfcdN3sZ+QxSS7w9nQDOmuJqDGoc3EfQ95LsF7J4nAAn48F38pcrZzsgRuX Qgew== X-Gm-Message-State: APjAAAVXUJkmio8nmC8XGHuVQ869iEtujFLVth7eGGU9eKt4jE3BFgVP qMWsPu1ge8jN63Yq2BifhtwWkA== X-Google-Smtp-Source: APXvYqyGsGrLPyBDtCxTyveMalXdmwovqTcGDOWg4fzfp/TkTS6GWys0i/Jm2jUOUYV/1uUVYs7SYg== X-Received: by 2002:a05:651c:105c:: with SMTP id x28mr6132302ljm.114.1570707605886; Thu, 10 Oct 2019 04:40:05 -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 p3sm1168937ljn.78.2019.10.10.04.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:05 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 01/13] cpuidle: psci: Fix potential access to unmapped memory Date: Thu, 10 Oct 2019 13:39:25 +0200 Message-Id: <20191010113937.15962-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org When the WFI state have been selected, the in-parameter idx to psci_enter_idle_state() is zero. In this case, we must not index the state array as "state[idx - 1]", as it means accessing data outside the array. Fix the bug by pre-checking if idx is zero. Fixes: 9ffeb6d08c3a ("PSCI: cpuidle: Refactor CPU suspend power_state parameter handling") Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index f3c1a2396f98..2e91c8d6c211 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -27,10 +27,10 @@ static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { - u32 *state = __this_cpu_read(psci_power_state); + u32 *states = __this_cpu_read(psci_power_state); + u32 state = idx ? states[idx - 1] : 0; - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, - idx, state[idx - 1]); + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); } static struct cpuidle_driver psci_idle_driver __initdata = { From patchwork Thu Oct 10 11:39:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99DE11668 for ; Thu, 10 Oct 2019 11:40:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A71721D7C for ; Thu, 10 Oct 2019 11:40:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OgHOnIF/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727737AbfJJLkM (ORCPT ); Thu, 10 Oct 2019 07:40:12 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:39877 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727480AbfJJLkL (ORCPT ); Thu, 10 Oct 2019 07:40:11 -0400 Received: by mail-lf1-f65.google.com with SMTP id 72so4122872lfh.6 for ; Thu, 10 Oct 2019 04:40:08 -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=jyY5hfR8/N8coo7i/Rw81G3nXo/cAyXblG5DM904HwE=; b=OgHOnIF/JT9aqU5ULYziikH3VIpbyfjLcYtZ62ZAGion5jENQDB43lu6J4WKcJu6KY 52BLa6tvDhyxmjUbdlEIBfL4xtgznU7Qql5Yu5h35386cUJn2GYFKaqo4kJ64ogBJKiY POAOhEUixlR3um6FnqjifcyURYypxa3kqWLGjwyvOmRq8pKZNrIDz/50xhcgjnz8vVl5 mPj5/Y37vX4kKohxCKn5yzdcQlwykwhiySJ9g1Pl/HNVXTDyRpvJqTWPMhlz13rm95J8 zOwzOXLKnERt4j5NlWJg089O+KMqcioLvUndOe5GvbFVL/G/OyZ2hlMuG+PeFN64PMOo zqwg== 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=jyY5hfR8/N8coo7i/Rw81G3nXo/cAyXblG5DM904HwE=; b=UOfQEhxQkuUoB2LnuWdGrjN6vnzMgUkUCBa0XB6ZynuAeEOZqsm4/JqTlaS2Wq/71E QPcM7HKNOiWUu0sxqEhpPeFxaZ0baOf50cILmDBAb7RJH/z65TGBa84m6gAJ7BE3d6xu YrWCGGHEjkuR1eKKykRQtoxux0cKnWeyoes3g43Z+TzE5T1OmXkWxt4CbkDirx1g6kM/ n6X/XKmXP06pZy6as/nGcI1eSGOcGPgmlU4Ump0a2bVH9mrjrvQMkCVATltX5rb4Ngdt 1dnN2MEjnchq6Voz4bkadufQIoi4ZwZV8/s2gIJ0FsZ3J1nvjKFYXRF22HAi+m/weIQ/ GyFw== X-Gm-Message-State: APjAAAVBAgUx6sqP5DU0Bm5MBax2zziMUYsDZE+DQJpgvEyU3UhVouKf yYOXSdsSRpE+GhLvzPvSPehmlw== X-Google-Smtp-Source: APXvYqwVz/veomsjupLKt3xVJOp9HD2kp91pfcT6HzEDeMCrvfq1+l+xdbKIzxGRgkRxI/FcE66Vpw== X-Received: by 2002:a19:ca56:: with SMTP id h22mr5690879lfj.192.1570707608097; Thu, 10 Oct 2019 04:40:08 -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 p3sm1168937ljn.78.2019.10.10.04.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:06 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 02/13] dt: psci: Update DT bindings to support hierarchical PSCI states Date: Thu, 10 Oct 2019 13:39:26 +0200 Message-Id: <20191010113937.15962-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Update PSCI DT bindings to allow to represent idle states for CPUs and the CPU topology, by using a hierarchical layout. Primarily this is done by re-using the existing power domain description [1] and the domain idle state description [2]. Let's also take the opportunity to update the examples to clarify the difference between the currently supported flattened layout vs the new hierarchical layout. [1] Documentation/devicetree/bindings/power/power_domain.txt [2] Documentation/devicetree/bindings/power/domain-idle-state.txt Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- .../devicetree/bindings/arm/psci.yaml | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/psci.yaml b/Documentation/devicetree/bindings/arm/psci.yaml index 7abdf58b335e..360579bfa591 100644 --- a/Documentation/devicetree/bindings/arm/psci.yaml +++ b/Documentation/devicetree/bindings/arm/psci.yaml @@ -160,4 +160,157 @@ examples: cpu_on = <0x95c10002>; cpu_off = <0x95c10001>; }; + + - |+ + + // Case 4: PSCI v1.0, PSCI v0.2, PSCI v0.1. + + /* + * ARM systems can have multiple cores, sometimes in an hierarchical + * arrangement. This often, but not always, maps directly to the processor + * power topology of the system. Individual nodes in a topology have their + * own specific power states and can be better represented hierarchically. + * + * For these cases, the definitions of the idle states for the CPUs and the + * CPU topology, must conform to the power domain description [3]. The idle + * states themselves must conform to the domain idle state description [4] + * and must specify the arm,psci-suspend-param property. + * + * This allows two options to represent CPUs and CPU idle states. By using + * a flattened model as given in the first example below and by using a + * hierarchical model as given in the second example. + * + * It should also be noted that, in PSCI firmware v1.0 the OS-Initiated + * (OSI) CPU suspend mode is introduced. Using the hierarchical + * representation helps to implement support for OSI mode and OS + * implementations may choose to mandate it. + * + * [3] Kernel documentation - Power domain description + * Documentation/devicetree/bindings/power/power_domain.txt + * [4] Kernel documentation - Domain idle state description + * Documentation/devicetree/bindings/power/domain-idle-state.txt + */ + + // The flattened model + cpus { + + CPU0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53", "arm,armv8"; + reg = <0x0>; + enable-method = "psci"; + cpu-idle-states = <&CPU_PWRDN>, <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; + + CPU1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a57", "arm,armv8"; + reg = <0x100>; + enable-method = "psci"; + cpu-idle-states = <&CPU_PWRDN>, <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; + + idle-states { + + CPU_PWRDN: cpu-power-down { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x0000001>; + entry-latency-us = <10>; + exit-latency-us = <10>; + min-residency-us = <100>; + }; + + CLUSTER_RET: cluster-retention { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x1000011>; + entry-latency-us = <500>; + exit-latency-us = <500>; + min-residency-us = <2000>; + }; + + CLUSTER_PWRDN: cluster-power-down { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x1000031>; + entry-latency-us = <2000>; + exit-latency-us = <2000>; + min-residency-us = <6000>; + }; + }; + }; + + psci { + compatible = "arm,psci-1.0"; + method = "smc"; + }; + + // The hierarchical model + cpus { + + CPU0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53", "arm,armv8"; + reg = <0x0>; + enable-method = "psci"; + power-domains = <&CPU_PD0>; + power-domain-names = "psci"; + }; + + CPU1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a57", "arm,armv8"; + reg = <0x100>; + enable-method = "psci"; + power-domains = <&CPU_PD1>; + power-domain-names = "psci"; + }; + + idle-states { + + CPU_PWRDN: cpu-power-down { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x0000001>; + entry-latency-us = <10>; + exit-latency-us = <10>; + min-residency-us = <100>; + }; + + CLUSTER_RET: cluster-retention { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x1000011>; + entry-latency-us = <500>; + exit-latency-us = <500>; + min-residency-us = <2000>; + }; + + CLUSTER_PWRDN: cluster-power-down { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x1000031>; + entry-latency-us = <2000>; + exit-latency-us = <2000>; + min-residency-us = <6000>; + }; + }; + }; + + psci { + compatible = "arm,psci-1.0"; + method = "smc"; + + CPU_PD0: cpu-pd0 { + #power-domain-cells = <0>; + domain-idle-states = <&CPU_PWRDN>; + power-domains = <&CLUSTER_PD>; + }; + + CPU_PD1: cpu-pd1 { + #power-domain-cells = <0>; + domain-idle-states = <&CPU_PWRDN>; + power-domains = <&CLUSTER_PD>; + }; + + CLUSTER_PD: cluster-pd { + #power-domain-cells = <0>; + domain-idle-states = <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; + }; ... From patchwork Thu Oct 10 11:39:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4841676 for ; Thu, 10 Oct 2019 11:40:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2871420B7C for ; Thu, 10 Oct 2019 11:40:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jt87ZF+5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727391AbfJJLkL (ORCPT ); Thu, 10 Oct 2019 07:40:11 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33267 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727737AbfJJLkL (ORCPT ); Thu, 10 Oct 2019 07:40:11 -0400 Received: by mail-lj1-f194.google.com with SMTP id a22so5881573ljd.0 for ; Thu, 10 Oct 2019 04:40:10 -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=v88JQU6vGgb8ri6uCDKoMwVq9Ia/h8wuaSmlcufCmYU=; b=jt87ZF+5/DHtUlBRJ5BstY8Vh6NbAEk5UF5D0u9HLT6presiea5l2x37EGTavAgCM2 H6B9YduMYxyPWcZQ4LDD0neKrxzMhr4DDLJH8oBvjt+ks9l3QnWRR5PubXNd4vzUEa3V fgBE1oE+WU63PB9MXoMoWyvRweYDa/KA+enceW5fZYXZHR2ZMUhprzxuPtzW7IdBbqZ/ kGJTTsnM0FhDhek77frZusCt3Srayy/AEUjcMSLtjZYglG2TVmus+yHd4KOQekmMb080 WIB28o60K0vFD9ulrOuL9R6XqTAkOFwHwsw7PULu7sOOm3lOtCBUtvXHBX7li4uUnl0I C04Q== 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=v88JQU6vGgb8ri6uCDKoMwVq9Ia/h8wuaSmlcufCmYU=; b=TwFUxtKGmIVwfaG2Z4cAcGqmQzS+DhhQ4mppyyZg7j3xG0GrL58iSuImU8dTSZ0L41 0aRGrjeA3IN+GQENOTYqRhzTZMwNNsSX28xJUqXP+qYojhgPup0XQO8xdSTCeCYjS5Wc ADeWxeFBmmVgAaELvS3v+KqaycQ1JvadZD9VxH91jhs7O3LHB5A/JJoNPz8K/rfMBv4N yirkq/Wb3MAVhWWAHI2GhmbHeZBBNrou3nUY7bGXkSRT3qaV711b12/WLJ6qzJn3SCi/ kTFq81p/31opGzDmxJd5eQLsUUBEOwOc8yl+FdEvE3wB3gNIsnsjtJ0KmwX13FCIwvyK GtkA== X-Gm-Message-State: APjAAAXZ+Ic5Sa4kSa1p0hhay89fwy2Wkc1YPjNgU5wYYu1VkFJnvpc+ s92/TV10vfqROdEpHsnWf8952w== X-Google-Smtp-Source: APXvYqyCKks0JZZNViLz2Kmfcp+HjHLDr3UWaZTScndbtx975mvyfpGsTCg1ZMWYx/C2hWBuMccseA== X-Received: by 2002:a2e:9b8a:: with SMTP id z10mr6104674lji.80.1570707609559; Thu, 10 Oct 2019 04:40:09 -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 p3sm1168937ljn.78.2019.10.10.04.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:08 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 03/13] firmware: psci: Export functions to manage the OSI mode Date: Thu, 10 Oct 2019 13:39:27 +0200 Message-Id: <20191010113937.15962-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org To allow subsequent changes to implement support for OSI mode through the cpuidle-psci driver, export the existing psci_has_osi_support(). Export also a new function, psci_set_osi_mode(), that allows its caller to enable the OS-initiated CPU-suspend mode in the PSCI FW. To deal with backwards compatibility for a kernel started through a kexec call, default to set the CPU-suspend mode to the Platform Coordinated mode during boot. Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/firmware/psci/psci.c | 18 ++++++++++++++++-- include/linux/psci.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 84f4ff351c62..76f3a991d4d7 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -89,7 +89,7 @@ static inline bool psci_has_ext_power_state(void) PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK; } -static inline bool psci_has_osi_support(void) +bool psci_has_osi_support(void) { return psci_cpu_suspend_feature & PSCI_1_0_OS_INITIATED; } @@ -154,6 +154,15 @@ static u32 psci_get_version(void) return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); } +int psci_set_osi_mode(void) +{ + int err; + + err = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, + PSCI_1_0_SUSPEND_MODE_OSI, 0, 0); + return psci_to_linux_errno(err); +} + static int psci_cpu_suspend(u32 state, unsigned long entry_point) { int err; @@ -536,9 +545,14 @@ static int __init psci_1_0_init(struct device_node *np) if (err) return err; - if (psci_has_osi_support()) + if (psci_has_osi_support()) { pr_info("OSI mode supported.\n"); + /* Default to PC mode. */ + invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, + PSCI_1_0_SUSPEND_MODE_PC, 0, 0); + } + return 0; } diff --git a/include/linux/psci.h b/include/linux/psci.h index e2bacc6fd2f2..f76b45341adf 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -17,6 +17,8 @@ bool psci_tos_resident_on(int cpu); int psci_cpu_suspend_enter(u32 state); bool psci_power_state_is_valid(u32 state); +int psci_set_osi_mode(void); +bool psci_has_osi_support(void); enum psci_conduit { PSCI_CONDUIT_NONE, From patchwork Thu Oct 10 11:39:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE0DB1864 for ; Thu, 10 Oct 2019 11:40:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE3BA20B7C for ; Thu, 10 Oct 2019 11:40:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DanIYhUZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727480AbfJJLkO (ORCPT ); Thu, 10 Oct 2019 07:40:14 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46247 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731230AbfJJLkO (ORCPT ); Thu, 10 Oct 2019 07:40:14 -0400 Received: by mail-lj1-f194.google.com with SMTP id d1so5794975ljl.13 for ; Thu, 10 Oct 2019 04:40:12 -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=GuctgQaNXDpvCtGnyWFncLAWkLOPv4PuyrC/plBYoKw=; b=DanIYhUZr/1fcPOq8Ic6qUfgUj21pf/pck8soG6eZQCQYhtidxPLIlbpjpwqD+1XB+ LMxMZ2fIBihfggtcjrtFGfxbLLq8eIV21kCamNCqUj6Y/iWMUWu5aY+SkSB36/59rvHv j2I8r/mohLV8cTtkXEd+eQ4NLXVuf773dkPbaDzPLUWhrFdJ/PkSO1P1JFPRVaQlfxR6 x153P2vsxw0BA+ayURQPn/ry91aXPfcYe4iFNFCWze/i0veaWf0Nw7nIyqJZhu/YfH1Z HbqHDu1AQp+bYI6dm7I4KRDV4j0iojylqAYBVwYJwMtnRXRspSEkZSOnemFgvBXNAT0P fYJQ== 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=GuctgQaNXDpvCtGnyWFncLAWkLOPv4PuyrC/plBYoKw=; b=uZ1fw8fDFMO8Hl55FssT9S/5a5lcC1qx9aSc+O8zGeczD7bDS4Vfg1oGGNLK3eeTOU qGBwDm42oJaj2etARC/NZQRckZANO78hkEn9Xcx89luAB1fHjsA28FLm65RM8XzOltCn JvwCXrTAEgQ8Sx2rQVs7Nvb/e2UCgU2QDUvR+1/lSu0zsHm4S4H98ComhwrBVpDL2ds6 A57ODw+FKZzTWmRW4K2K6rrd/Cij0vxHV1FZYrTasdFULzFJECeDRAr/rWxYitxi9oX8 4k/JCwYKCh9DYxUB0PG3F0oW4xvIZgO7jgXSx2+SQ2wN1+RoAIg3UkKeUe9yg8Axkt+K uMhA== X-Gm-Message-State: APjAAAXlcBIT43s1ZEitUULZY09JpNIFrCMpnzU0MRNUXWYXYwywYqul 0yiZtlXNuwU7vPfisnKKJIEWxQ== X-Google-Smtp-Source: APXvYqzJlSXBelf9XaR8Fb0R4bdv691aPCwO1Z3PRCtK+D7bKXcC8xeURfNHeN93zAvSqzcikcMDsw== X-Received: by 2002:a2e:286:: with SMTP id y6mr6266107lje.184.1570707611403; Thu, 10 Oct 2019 04:40:11 -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 p3sm1168937ljn.78.2019.10.10.04.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:10 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 04/13] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Thu, 10 Oct 2019 13:39:28 +0200 Message-Id: <20191010113937.15962-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The CPU's idle state nodes are currently parsed at the common cpuidle DT library, but also when initializing data for specific CPU idle operations, as in the PSCI cpuidle driver case and qcom-spm cpuidle case. To avoid open-coding, let's introduce of_get_cpu_state_node(), which takes the device node for the CPU and the index to the requested idle state node, as in-parameters. In case a corresponding idle state node is found, it returns the node with the refcount incremented for it, else it returns NULL. Moreover, for PSCI there are two options to describe the CPU's idle states [1], either via a flattened description or a hierarchical layout. Hence, let's take both options into account. [1] Documentation/devicetree/bindings/arm/psci.yaml Suggested-by: Sudeep Holla Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Reviewed-by: Rob Herring Reviewed-by: Daniel Lezcano Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/of/base.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 1d667eb730e1..0e4cdf0f3864 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -477,6 +477,42 @@ int of_cpu_node_to_id(struct device_node *cpu_node) } EXPORT_SYMBOL(of_cpu_node_to_id); +/** + * of_get_cpu_state_node - Get CPU's idle state node at the given index + * + * @cpu_node: The device node for the CPU + * @index: The index in the list of the idle states + * + * Two generic methods can be used to describe a CPU's idle states, either via + * a flattened description through the "cpu-idle-states" binding or via the + * hierarchical layout, using the "power-domains" and the "domain-idle-states" + * bindings. This function check for both and returns the idle state node for + * the requested index. + * + * In case an idle state node is found at @index, the refcount is incremented + * for it, so call of_node_put() on it when done. Returns NULL if not found. + */ +struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + struct of_phandle_args args; + int err; + + err = of_parse_phandle_with_args(cpu_node, "power-domains", + "#power-domain-cells", 0, &args); + if (!err) { + struct device_node *state_node = + of_parse_phandle(args.np, "domain-idle-states", index); + + of_node_put(args.np); + if (state_node) + return state_node; + } + + return of_parse_phandle(cpu_node, "cpu-idle-states", index); +} +EXPORT_SYMBOL(of_get_cpu_state_node); + /** * __of_device_is_compatible() - Check if the node matches given constraints * @device: pointer to node diff --git a/include/linux/of.h b/include/linux/of.h index 844f89e1b039..c669c0a4732f 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -351,6 +351,8 @@ extern const void *of_get_property(const struct device_node *node, int *lenp); extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); extern struct device_node *of_get_next_cpu_node(struct device_node *prev); +extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index); #define for_each_property_of_node(dn, pp) \ for (pp = dn->properties; pp != NULL; pp = pp->next) @@ -765,6 +767,12 @@ static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) return NULL; } +static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + return NULL; +} + static inline int of_n_addr_cells(struct device_node *np) { return 0; From patchwork Thu Oct 10 11:39:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED2DE76 for ; Thu, 10 Oct 2019 11:40:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD50B2053B for ; Thu, 10 Oct 2019 11:40:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="T0nFsd0F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731230AbfJJLkP (ORCPT ); Thu, 10 Oct 2019 07:40:15 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:43879 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731916AbfJJLkP (ORCPT ); Thu, 10 Oct 2019 07:40:15 -0400 Received: by mail-lj1-f196.google.com with SMTP id n14so5809932ljj.10 for ; Thu, 10 Oct 2019 04:40:13 -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=uPQQL2LvieO3hRSdVOoT+soulZMhG9ActuEg4qQLyaA=; b=T0nFsd0F5yhLoTBaFcw7y7TSJ7swFLFrCm0iZ9fxXkpwH6LgoqyNcmtnY+mHnZ7wqA tzclaFDIjVJeRj4TRzdNHxas/7Vc8CSCkhEVswvN1U/GYZXItT1Dooz0x75Gut6BZJwe 4S12SRko6dhQUiVAR7mIGBsqkpltXwc+NMvmdHK8upCiNxXR8JCoLhsHRJqg1TNG15Iv a8dMDov2BYDB7gaiCVsBOvN3bHHR40LV7UsV9TRjpeuPT4Ri5Tw3COGyo494xPZWl7xQ Q9jZ1l0HBJVKHFxRnUwvZuXn9e9UCxKzqe6oBIidHY+cpmTeJzdcMO6Goptv3Oz/YpEU VJHQ== 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=uPQQL2LvieO3hRSdVOoT+soulZMhG9ActuEg4qQLyaA=; b=D+POr1ecRLAUScrKdX5RkbadKHMdI/G2iLTB+aNF+DwMx4gpSFMQ/22dlYA8MbgGcD DkN6d3tak2w8k4hrvCEFJmwmDlFfK7vH+2jAFMugSZ1+hC8zHRdhDPS1Ih29MEy0BcJm AiUg3tbi+PXi/ViakPc9QPhuyCroNYk7HbJ9QAeNwBjEfeIZ/TGKdd40MNS+szLIvXto XV2yKZEpQS50PG5wEBSDhPmtzX4GlqXW2Y7Dn1SoFEOAnMQ7zfduMexRKF8ZA0teTo7+ RCdmxJZSGImSCsKNqJkaZ/7y/hGxGoSf+prv8qKMjvQi26g7pxWOK2lGm+zk2PMQ0pkr IDjQ== X-Gm-Message-State: APjAAAVG68VJimT+BQNqltQAnEhRGus9RptmsNMEHwIII0BZpai7eP7E QWDBxjmMHAlsOTJ9MQyRNfq09A== X-Google-Smtp-Source: APXvYqwd9hZQk2PNNSWawnj+vwKKoXgMm6PDK8dcNZdYDc7Bp/XO4FPg5jdpJ5ioW9H9llCi9Uk6EQ== X-Received: by 2002:a2e:6f0f:: with SMTP id k15mr6301625ljc.12.1570707613211; Thu, 10 Oct 2019 04:40:13 -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 p3sm1168937ljn.78.2019.10.10.04.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:12 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 05/13] cpuidle: dt: Support hierarchical CPU idle states Date: Thu, 10 Oct 2019 13:39:29 +0200 Message-Id: <20191010113937.15962-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Lina Iyer Currently CPU's idle states are represented using the flattened model. Let's add support for the hierarchical layout, via converting to use of_get_cpu_state_node(). Suggested-by: Sudeep Holla Signed-off-by: Lina Iyer Reviewed-by: Daniel Lezcano Co-developed-by: Ulf Hansson Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/cpuidle/dt_idle_states.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c index d06d21a9525d..252f2a9686a6 100644 --- a/drivers/cpuidle/dt_idle_states.c +++ b/drivers/cpuidle/dt_idle_states.c @@ -111,8 +111,7 @@ static bool idle_state_valid(struct device_node *state_node, unsigned int idx, for (cpu = cpumask_next(cpumask_first(cpumask), cpumask); cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpumask)) { cpu_node = of_cpu_device_node_get(cpu); - curr_state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - idx); + curr_state_node = of_get_cpu_state_node(cpu_node, idx); if (state_node != curr_state_node) valid = false; @@ -170,7 +169,7 @@ int dt_init_idle_driver(struct cpuidle_driver *drv, cpu_node = of_cpu_device_node_get(cpumask_first(cpumask)); for (i = 0; ; i++) { - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + state_node = of_get_cpu_state_node(cpu_node, i); if (!state_node) break; From patchwork Thu Oct 10 11:39:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE87C1668 for ; Thu, 10 Oct 2019 11:40:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EFFD20B7C for ; Thu, 10 Oct 2019 11:40:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="w/wpfkf4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732821AbfJJLkR (ORCPT ); Thu, 10 Oct 2019 07:40:17 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:36959 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732671AbfJJLkR (ORCPT ); Thu, 10 Oct 2019 07:40:17 -0400 Received: by mail-lj1-f194.google.com with SMTP id l21so5850794lje.4 for ; Thu, 10 Oct 2019 04:40:15 -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=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=w/wpfkf4JD7NtMhgYW5bka2jwABBrG/zFpdfSK+C6Y8ZEzk1usOy+0SZ037SEiwojW 8ikm7DR8YcoaSKOsLXm8/4fAoU66XIkDrdXmlfD0bKpQ4pPfXVVdHhNQ8eWlxdKdwF8m 3v9pJu7MyhXBh0O8lxuIkg9S/oSY3v5jPH/hUxyxae9He70A2JNrMcErYiipUzzxW6la RPJBm1dTBVGovcLV6kmCCd3lqZrimb7rDvRlZSKv2Ch/iQaQuACu1Dssa3Z+C2w/ecWr XF0jqnbdyn9OWFCh7gZX9bj7CuKUEM3iw2jfcQG61bDXCjKqE62EJgVMKO9gnqC4ni9I rSlQ== 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=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=LimH59M68PLuTLs8L8lhvhBjUtMh6GaUMoNH3moYg3bMv4vFLQryPTuIUZKebxTXgc 9GXEiO1c+9jdhTgPH8+4Vc/jBOp+U0plaQ1FxqQBPHzJwesjQDO99cQG5UELyYAMqC0Q 6Ph62TIKRVSFpqCvT1NOx3IJkJJhVvJmwptf7MwRKmAwS3zkaY/GHpdgjAsDBKw7gnfy ppCawzE78VtbqSZe1mLsxfy4C0pPBUrxf6SdzdDmJk5aS8PZ6L6he81YguSrOlo8SrJv gVSeIXN7ccFrmYJckJemUxNMN5DIhlPz5DLdR4QW+HwS9CSaG0VQWt65dFLXiK7ClOqo O3yQ== X-Gm-Message-State: APjAAAVQavXiAav8F7bLo25cR6dxcUitrFppWqI/Xe8cl85LPa8XkYv6 VKDNm/ALQvD9fbgTLWyJkwqzGQ== X-Google-Smtp-Source: APXvYqx8XV+oQ6tAHK6bndR8s4uIRBDsgX8TGkAPZYFU0mns7A7hnFIcGWvIyBsKIHrN+DhA2aCXOg== X-Received: by 2002:a2e:87ca:: with SMTP id v10mr5973843ljj.43.1570707614837; Thu, 10 Oct 2019 04:40:14 -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 p3sm1168937ljn.78.2019.10.10.04.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:14 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 06/13] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Thu, 10 Oct 2019 13:39:30 +0200 Message-Id: <20191010113937.15962-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Iterating through the idle state nodes in DT, to find out the number of states that needs to be allocated is unnecessary, as it has already been done from dt_init_idle_driver(). Therefore, drop the iteration and use the number we already have at hand. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 2e91c8d6c211..1195a1056139 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -73,28 +73,22 @@ static int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) return 0; } -static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) +static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, + unsigned int state_nodes, int cpu) { - int i, ret = 0, count = 0; + int i, ret = 0; u32 *psci_states; struct device_node *state_node; - /* Count idle states */ - while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - count))) { - count++; - of_node_put(state_node); - } - - if (!count) - return -ENODEV; - - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + psci_states = kcalloc(state_nodes, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 0; i < count; i++) { + for (i = 0; i < state_nodes; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -104,6 +98,11 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } + if (i != state_nodes) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0; @@ -113,7 +112,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } -static __init int psci_cpu_init_idle(unsigned int cpu) +static __init int psci_cpu_init_idle(unsigned int cpu, unsigned int state_nodes) { struct device_node *cpu_node; int ret; @@ -129,7 +128,7 @@ static __init int psci_cpu_init_idle(unsigned int cpu) if (!cpu_node) return -ENODEV; - ret = psci_dt_cpu_init_idle(cpu_node, cpu); + ret = psci_dt_cpu_init_idle(cpu_node, state_nodes, cpu); of_node_put(cpu_node); @@ -185,7 +184,7 @@ static int __init psci_idle_init_cpu(int cpu) /* * Initialize PSCI idle states. */ - ret = psci_cpu_init_idle(cpu); + ret = psci_cpu_init_idle(cpu, ret); if (ret) { pr_err("CPU %d failed to PSCI idle\n", cpu); goto out_kfree_drv; From patchwork Thu Oct 10 11:39:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1C471668 for ; Thu, 10 Oct 2019 11:40:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B28B4208C3 for ; Thu, 10 Oct 2019 11:40:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EUAy07fB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732851AbfJJLkT (ORCPT ); Thu, 10 Oct 2019 07:40:19 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33994 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732671AbfJJLkT (ORCPT ); Thu, 10 Oct 2019 07:40:19 -0400 Received: by mail-lj1-f195.google.com with SMTP id j19so5885903lja.1 for ; Thu, 10 Oct 2019 04:40:17 -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=nvXOpVcM/IpothdU1ZKoTmNHFS7WJStir72tye3UWWE=; b=EUAy07fBsO1Wz5z3ljchfWd2sfdTxk2utOmWleJB60APniuQ0U3RAzfQdhfU/BWbU3 /PpxRmMYJ+bhc8H7y4zsGtOLcdqr9mF9vHT+BAF1w2huN0P/nPF6ZTE794efcWFcaxrq 82N6hkfxHfNP9zDCtgRDb7F7P1918eEHfSkhI8PK4xqSZVgc88lGjJ53etEeAcHIcwMP ytQqCscNLLgc+xJioNh+2NOpa9q7QFuCq+3m59fEwdALI0MT6g8ITkIlJ/WS9+aWE+B4 Z0vwxgptGD1RDuLRlsFVMW4k0nYmjTmLaNA4g29yjtIoKOgj6OhnsLkPjHkVD+6KZGZ4 qDXQ== 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=nvXOpVcM/IpothdU1ZKoTmNHFS7WJStir72tye3UWWE=; b=Sc1LxaF5Tilz3HCLz4iDFEmOuuDKZZD/XawoxQkiBeUPBt/AMih+IsGfuPWrCn25yf 9awjqzwoH/CZcJ/R6kmS/3khEby0x9HgwZtbHXUIcJ+2fB0Euc18nt6DFI60l0CvitHM iK7ucE8axbw3PMj2IaqMiEnZkMu6BjLPrly2H6iKOZadpp4/0jI1K3oHTkxjASk4Mitz x3WGwoYQ9aCwDW9PyoxdC3Ee0ABiUpuo2amQyKKUmwPh3sT0iOBLZCidvqnQwzb8Knpn 9E4VtjDuAJnMVjcSmUuV8kT3Ep9OK0fuBy/KTV2UavRw+SEz5bHssInFtfvaarzBi0hc Cujw== X-Gm-Message-State: APjAAAUBNlTcHMKntjuTyoZsyWYC7xra7Wdpfz+u4E9CZond9LGXl0BP sqjfAztKrh404BCjGvcbQT2F7g== X-Google-Smtp-Source: APXvYqxUdEhaIFvRKswg87UCzDQiM72AeRacZpBqrmORob2xGUbd6DLiJRFX4z5exUT/BNmXNpFbgQ== X-Received: by 2002:a2e:89c4:: with SMTP id c4mr5832114ljk.65.1570707616291; Thu, 10 Oct 2019 04:40:16 -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 p3sm1168937ljn.78.2019.10.10.04.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:15 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 07/13] cpuidle: psci: Support hierarchical CPU idle states Date: Thu, 10 Oct 2019 13:39:31 +0200 Message-Id: <20191010113937.15962-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Currently CPU's idle states are represented using the flattened model. Let's add support for the hierarchical layout, via converting to use of_get_cpu_state_node(). Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/cpuidle/cpuidle-psci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 1195a1056139..5c30f23a8a7b 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -85,7 +85,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, return -ENOMEM; for (i = 0; i < state_nodes; i++) { - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + state_node = of_get_cpu_state_node(cpu_node, i); if (!state_node) break; From patchwork Thu Oct 10 11:39:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D64001864 for ; Thu, 10 Oct 2019 11:40:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B779C21D7C for ; Thu, 10 Oct 2019 11:40:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fpTsBvZB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732848AbfJJLkV (ORCPT ); Thu, 10 Oct 2019 07:40:21 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:42042 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732792AbfJJLkU (ORCPT ); Thu, 10 Oct 2019 07:40:20 -0400 Received: by mail-lf1-f66.google.com with SMTP id c195so4110678lfg.9 for ; Thu, 10 Oct 2019 04:40:18 -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=p5qrlgEHHz72OqawbaM4oNKQbRiSCqvlNCrVec5FI84=; b=fpTsBvZBXrvTN9zR+IrMwIGukuhZz6A+ldBwdcZi85by9XgVOP/bWsZrqXdciNslhQ hPSQ87yb+x0ew8Zra1SvLTZ/P48Hr3FZUtR+nc3Bf+KjolueaFc8mzWO7hCTf5JTZ53J GY5IkZKAU60fnj9UwZMeKc4KEFiIVOqUHjv08fBOzAHTlLevorIgxgahat41rZdmOHja NUdOFzdcgrXCmknjYH2vORo7/nhAmDa0V6rUyNJERU3OmJlYnNSJONJXOFyK9xkZzVhT BZKrXoMMpkDffL35v7BHgNLabiW8/lWryfjLPNpRXqpI8THMQwTtCoxQ3KIMmGeK8+Ak oyhw== 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=p5qrlgEHHz72OqawbaM4oNKQbRiSCqvlNCrVec5FI84=; b=UglOsSXtPHXc7F/rxP47vPm0GcpgkY6wdx87qy1jU5DWTsN4K3JifzYQn/zCAZ1kfQ vbRr9AnwZNzepF4tpvgV0yg7ZYf1h92KqMR75MIu2xyNKqaAnMtSYuiLIjkGtckX/H4m ZLBWkQ7hKyg8KgKKfCpkrEpPZBeRbdDWyEgosvMZ35djKlWLN1GcmxAOrQ7YEaKzaMSl a2Cn+X+GAellEM56GgdNfYqOPeNSLzDWjIlPHbIQy8ZjJvI15c4ZSvQxBtqjBNhIqiqU a80iDsbeho8Tf7zycg+cAMBQo1oAjMhfT644PpIxxoPc8eg1L72uiVIP4MtkvyU1PRoG Z+Tw== X-Gm-Message-State: APjAAAV0L9xdKysPOboYPI0uc2mXQ8F81r/poGE9hqiXb1yqxEgi4rfx T3rf2GGWAl1t2uXss2pv0EJ90w== X-Google-Smtp-Source: APXvYqwurmeJAb45mxPdDwDdgYZyKg506CrXtVc4YhleXcNpg+js8O9MZD5A1KTQyHAY5EPoYkaFnA== X-Received: by 2002:a19:ed14:: with SMTP id y20mr5807432lfy.4.1570707618117; Thu, 10 Oct 2019 04:40:18 -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 p3sm1168937ljn.78.2019.10.10.04.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:17 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 08/13] cpuidle: psci: Prepare to use OS initiated suspend mode via PM domains Date: Thu, 10 Oct 2019 13:39:32 +0200 Message-Id: <20191010113937.15962-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The per CPU variable psci_power_state, contains an array of fixed values, which reflects the corresponding arm,psci-suspend-param parsed from DT, for each of the available CPU idle states. This isn't sufficient when using the hierarchical CPU topology in DT, in combination with having PSCI OS initiated (OSI) mode enabled. More precisely, in OSI mode, Linux is responsible of telling the PSCI FW what idle state the cluster (a group of CPUs) should enter, while in PSCI Platform Coordinated (PC) mode, each CPU independently votes for an idle state of the cluster. For this reason, introduce a per CPU variable called domain_state and implement two helper functions to read/write its value. Then let the domain_state take precedence over the regular selected state, when idling the CPU in psci_enter_idle_state(). This allows subsequent patches that implements support for PM domains for cpuidle-psci, to write the selected idle state parameter for the cluster into the domain_state variable. Furthermore, let's share the needed functions in a header file, to enable the support for PM domains to be implemented in a separate c-file. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 31 ++++++++++++++++++++++++++++--- drivers/cpuidle/cpuidle-psci.h | 11 +++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 drivers/cpuidle/cpuidle-psci.h diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 5c30f23a8a7b..a16467daf99d 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -20,17 +20,42 @@ #include +#include "cpuidle-psci.h" #include "dt_idle_states.h" static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +static DEFINE_PER_CPU(u32, domain_state); + +void psci_set_domain_state(u32 state) +{ + __this_cpu_write(domain_state, state); +} + +static inline u32 psci_get_domain_state(void) +{ + return __this_cpu_read(domain_state); +} + +static int __psci_enter_idle_state(int idx, u32 state) +{ + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); +} static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { + int ret; u32 *states = __this_cpu_read(psci_power_state); - u32 state = idx ? states[idx - 1] : 0; + u32 state = psci_get_domain_state(); - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); + if (!state && idx) + state = states[idx - 1]; + + ret = __psci_enter_idle_state(idx, state); + + /* Clear the domain state to start fresh when back from idle. */ + psci_set_domain_state(0); + return ret; } static struct cpuidle_driver psci_idle_driver __initdata = { @@ -56,7 +81,7 @@ static const struct of_device_id psci_idle_state_match[] __initconst = { { }, }; -static int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) +int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) { int err = of_property_read_u32(np, "arm,psci-suspend-param", state); diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h new file mode 100644 index 000000000000..e593de1784c3 --- /dev/null +++ b/drivers/cpuidle/cpuidle-psci.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __CPUIDLE_PSCI_H +#define __CPUIDLE_PSCI_H + +struct device_node; + +void psci_set_domain_state(u32 state); +int __init psci_dt_parse_state_node(struct device_node *np, u32 *state); + +#endif /* __CPUIDLE_PSCI_H */ From patchwork Thu Oct 10 11:39:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66C0D1668 for ; Thu, 10 Oct 2019 11:40:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FA172196E for ; Thu, 10 Oct 2019 11:40:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pmkfwxka" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732897AbfJJLkW (ORCPT ); Thu, 10 Oct 2019 07:40:22 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:34274 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732671AbfJJLkW (ORCPT ); Thu, 10 Oct 2019 07:40:22 -0400 Received: by mail-lf1-f68.google.com with SMTP id r22so4138606lfm.1 for ; Thu, 10 Oct 2019 04:40:20 -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=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=pmkfwxkafYHpSiVu7Ke8qyTAai9lSVf06gP+DuoqVBCdmPXeDGwnD865H9L/eBz4ph Mc9ompj19KSeeGD0zY0gJs9/1NRziZ4G6M4cVNufONzPB091FVd+9U8bfrnXLjJGKtE9 pAQYezMrOQdjnwzzgKZmW5HKmYTuct69TUSjXw6+GrU/YHAfNCanJ6BDM38VmVxYsNbc cbh97OXyVvfcM6T5W7OaMF45PzJqZu++xoLU4W8ssiLmHyCzUXnjiE8RbIu+qjux57Tp ojfn/CavWRGpl+nUU0gmPejv7qQMlHjHX1NTievqsgP/5MBWzAGS8nANRqEZI38DpQ9t FjqQ== 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=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=bWOLIae0W4un4KJB0cRgtvg/AVFvmlv3Z21jbsuEruJ7ETaZt4PvfUgj767hZmEZL+ g7SpZy+8CQo/KSKRaOeS/DsEtPIjWj41m4f3q8C0dyIaQIg++3t6drWvu/Hx+I4nMoAc RvqafWc5cHpvspsLAIx4ot370C9FYna4qh12ZeJcTAfJ8xUhzLUp0kop6u3cIKZO3yHk 4dwkHUoJvGnCzamXLvGQQyfhBmaJEdGupi2qRRavK4NCZ+V9WoX/D6QXPrcZVdRA5VAH KYo5iKfCA8RxNE1JfKcByHb6r0jpZhPs1+u4b4lzCxbAseMLIgIvXyNjJrWFT6gnOkAX 9nBA== X-Gm-Message-State: APjAAAWVKeCwJBml1fzA4QHxjw1riyICWsBsGtY0+ebWdw+Or/wgzFi3 3gbSP4WxeY5kYGAAFwxAs/Oibw== X-Google-Smtp-Source: APXvYqx1mFKVFqlLoIdvx8IvMJJulifnGJ7CfjYgTVgfhhrbHW5f47BT8zn+1dU3qSnhC5ZTUi5f1Q== X-Received: by 2002:a19:c392:: with SMTP id t140mr5888002lff.156.1570707619664; Thu, 10 Oct 2019 04:40:19 -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 p3sm1168937ljn.78.2019.10.10.04.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:19 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 09/13] cpuidle: psci: Add support for PM domains by using genpd Date: Thu, 10 Oct 2019 13:39:33 +0200 Message-Id: <20191010113937.15962-10-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org When the hierarchical CPU topology layout is used in DT and the PSCI OSI mode is supported by the PSCI FW, let's initialize a corresponding PM domain topology by using genpd. This enables a CPU and a group of CPUs, when attached to the topology, to be power-managed accordingly. To trigger the attempt to initialize the genpd data structures a subsys_initcall is used, which should be early enough to allow CPUs, but also other devices to be attached. The initialization consists of parsing the PSCI OF node for the topology and the "domain idle states" DT bindings. In case the idle states are compatible with "domain-idle-state", the initialized genpd becomes responsible of selecting an idle state for the PM domain, via assigning it genpd governor. Note that, a successful initialization of the genpd data structures, is followed by a call to psci_set_osi_mode(), as to try to enable the OSI mode in the PSCI FW. In case this fails, we fall back into a degraded mode rather than bailing out and returning an error code. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/cpuidle/Makefile | 4 +- drivers/cpuidle/cpuidle-psci-domain.c | 281 ++++++++++++++++++++++++++ 2 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 drivers/cpuidle/cpuidle-psci-domain.c diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index ee70d5cc5b99..cc8c769d7fa9 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -21,7 +21,9 @@ obj-$(CONFIG_ARM_U8500_CPUIDLE) += cpuidle-ux500.o obj-$(CONFIG_ARM_AT91_CPUIDLE) += cpuidle-at91.o obj-$(CONFIG_ARM_EXYNOS_CPUIDLE) += cpuidle-exynos.o obj-$(CONFIG_ARM_CPUIDLE) += cpuidle-arm.o -obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle-psci.o +obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle_psci.o +cpuidle_psci-y := cpuidle-psci.o +cpuidle_psci-$(CONFIG_PM_GENERIC_DOMAINS_OF) += cpuidle-psci-domain.o ############################################################################### # MIPS drivers diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c new file mode 100644 index 000000000000..3f5143ccc3e0 --- /dev/null +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -0,0 +1,281 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PM domains for CPUs via genpd - managed by cpuidle-psci. + * + * Copyright (C) 2019 Linaro Ltd. + * Author: Ulf Hansson + * + */ + +#define pr_fmt(fmt) "CPUidle PSCI: " fmt + +#include +#include +#include +#include +#include +#include + +#include "cpuidle-psci.h" + +struct psci_pd_provider { + struct list_head link; + struct device_node *node; +}; + +static LIST_HEAD(psci_pd_providers); +static bool osi_mode_enabled; + +static int psci_pd_power_off(struct generic_pm_domain *pd) +{ + struct genpd_power_state *state = &pd->states[pd->state_idx]; + u32 *pd_state; + + /* If we have failed to enable OSI mode, then abort power off. */ + if (!osi_mode_enabled) + return -EBUSY; + + if (!state->data) + return 0; + + /* OSI mode is enabled, set the corresponding domain state. */ + pd_state = state->data; + psci_set_domain_state(*pd_state); + + return 0; +} + +static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states, + int state_count) +{ + int i, ret; + u32 psci_state, *psci_state_buf; + + for (i = 0; i < state_count; i++) { + ret = psci_dt_parse_state_node(to_of_node(states[i].fwnode), + &psci_state); + if (ret) + goto free_state; + + psci_state_buf = kmalloc(sizeof(u32), GFP_KERNEL); + if (!psci_state_buf) { + ret = -ENOMEM; + goto free_state; + } + *psci_state_buf = psci_state; + states[i].data = psci_state_buf; + } + + return 0; + +free_state: + i--; + for (; i >= 0; i--) + kfree(states[i].data); + return ret; +} + +static int __init psci_pd_parse_states(struct device_node *np, + struct genpd_power_state **states, int *state_count) +{ + int ret; + + /* Parse the domain idle states. */ + ret = of_genpd_parse_idle_states(np, states, state_count); + if (ret) + return ret; + + /* Fill out the PSCI specifics for each found state. */ + ret = psci_pd_parse_state_nodes(*states, *state_count); + if (ret) + kfree(*states); + + return ret; +} + +static void psci_pd_free_states(struct genpd_power_state *states, + unsigned int state_count) +{ + int i; + + for (i = 0; i < state_count; i++) + kfree(states[i].data); + kfree(states); +} + +static int __init psci_pd_init(struct device_node *np) +{ + struct generic_pm_domain *pd; + struct psci_pd_provider *pd_provider; + struct dev_power_governor *pd_gov; + struct genpd_power_state *states = NULL; + int ret = -ENOMEM, state_count = 0; + + pd = kzalloc(sizeof(*pd), GFP_KERNEL); + if (!pd) + goto out; + + pd_provider = kzalloc(sizeof(*pd_provider), GFP_KERNEL); + if (!pd_provider) + goto free_pd; + + pd->name = kasprintf(GFP_KERNEL, "%pOF", np); + if (!pd->name) + goto free_pd_prov; + + /* + * Parse the domain idle states and let genpd manage the state selection + * for those being compatible with "domain-idle-state". + */ + ret = psci_pd_parse_states(np, &states, &state_count); + if (ret) + goto free_name; + + pd->free_states = psci_pd_free_states; + pd->name = kbasename(pd->name); + pd->power_off = psci_pd_power_off; + pd->states = states; + pd->state_count = state_count; + pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; + + /* Use governor for CPU PM domains if it has some states to manage. */ + pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL; + + ret = pm_genpd_init(pd, pd_gov, false); + if (ret) { + psci_pd_free_states(states, state_count); + goto free_name; + } + + ret = of_genpd_add_provider_simple(np, pd); + if (ret) + goto remove_pd; + + pd_provider->node = of_node_get(np); + list_add(&pd_provider->link, &psci_pd_providers); + + pr_debug("init PM domain %s\n", pd->name); + return 0; + +remove_pd: + pm_genpd_remove(pd); +free_name: + kfree(pd->name); +free_pd_prov: + kfree(pd_provider); +free_pd: + kfree(pd); +out: + pr_err("failed to init PM domain ret=%d %pOF\n", ret, np); + return ret; +} + +static void __init psci_pd_remove(void) +{ + struct psci_pd_provider *pd_provider, *it; + struct generic_pm_domain *genpd; + + list_for_each_entry_safe(pd_provider, it, &psci_pd_providers, link) { + of_genpd_del_provider(pd_provider->node); + + genpd = of_genpd_remove_last(pd_provider->node); + if (!IS_ERR(genpd)) + kfree(genpd); + + of_node_put(pd_provider->node); + list_del(&pd_provider->link); + kfree(pd_provider); + } +} + +static int __init psci_pd_init_topology(struct device_node *np) +{ + struct device_node *node; + struct of_phandle_args child, parent; + int ret; + + for_each_child_of_node(np, node) { + if (of_parse_phandle_with_args(node, "power-domains", + "#power-domain-cells", 0, &parent)) + continue; + + child.np = node; + child.args_count = 0; + + ret = of_genpd_add_subdomain(&parent, &child); + of_node_put(parent.np); + if (ret) { + of_node_put(node); + return ret; + } + } + + return 0; +} + +static const struct of_device_id psci_of_match[] __initconst = { + { .compatible = "arm,psci" }, + { .compatible = "arm,psci-0.2" }, + { .compatible = "arm,psci-1.0" }, + {} +}; + +static int __init psci_idle_init_domains(void) +{ + struct device_node *np = of_find_matching_node(NULL, psci_of_match); + struct device_node *node; + int ret = 0, pd_count = 0; + + if (!np) + return -ENODEV; + + /* Currently limit the hierarchical topology to be used in OSI mode. */ + if (!psci_has_osi_support()) + goto out; + + /* + * Parse child nodes for the "#power-domain-cells" property and + * initialize a genpd/genpd-of-provider pair when it's found. + */ + for_each_child_of_node(np, node) { + if (!of_find_property(node, "#power-domain-cells", NULL)) + continue; + + ret = psci_pd_init(node); + if (ret) + goto put_node; + + pd_count++; + } + + /* Bail out if not using the hierarchical CPU topology. */ + if (!pd_count) + goto out; + + /* Link genpd masters/subdomains to model the CPU topology. */ + ret = psci_pd_init_topology(np); + if (ret) + goto remove_pd; + + /* Try to enable OSI mode. */ + ret = psci_set_osi_mode(); + if (ret) + pr_warn("failed to enable OSI mode: %d\n", ret); + else + osi_mode_enabled = true; + + of_node_put(np); + pr_info("Initialized CPU PM domain topology\n"); + return pd_count; + +put_node: + of_node_put(node); +remove_pd: + if (pd_count) + psci_pd_remove(); + pr_err("failed to create CPU PM domains ret=%d\n", ret); +out: + of_node_put(np); + return ret; +} +subsys_initcall(psci_idle_init_domains); From patchwork Thu Oct 10 11:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DD871864 for ; Thu, 10 Oct 2019 11:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C09D21D7C for ; Thu, 10 Oct 2019 11:40:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yCBQoiMd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732923AbfJJLkY (ORCPT ); Thu, 10 Oct 2019 07:40:24 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:37565 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732792AbfJJLkY (ORCPT ); Thu, 10 Oct 2019 07:40:24 -0400 Received: by mail-lf1-f67.google.com with SMTP id w67so4125886lff.4 for ; Thu, 10 Oct 2019 04:40:21 -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=9/8dxTtZBh9YfBGYNaIy85l3qLceeSKusYT56QpkuBo=; b=yCBQoiMdVpg14N7nhofiE56fggpEHFr0HVoi4xdC8JzFHPbNJMS/F2y1VVTJBKZuTC aNn5dzzSU5wNfqOvEqKvJgULqbetSKXMz6OHhmqNm8eKPLJ9uhwrVNgwi3vZf8PeSsQD 4NAC2kJpAIw0djJbv+iRnckigLk6Gs+BL0XLj8AYMISeX4o2bCaJYTwmQ06ERfvFqxaj fpk1JLapasYW+8jrvPic5xbqbmZNFrwXSCRsp7aXuFdcocTPj/IHe+KDL5Wg8dtiGUzC BZgFLnw7x4uFHX7nt6HwREijg76i/aQswB1SM3165mfcQ95JTCj9nWDZCPGlYVEywnzd Fkmg== 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=9/8dxTtZBh9YfBGYNaIy85l3qLceeSKusYT56QpkuBo=; b=E2F+FiGcyxUj4KNv/FV9WtPf83A42YgYCI+niI9szm2nJFt5hwdDGuTm31MCl4TfcR XNj/k4u1lloxX9xL8eqmDAoGSKkidCeFxUc1Yi5ZRslRT19UZ769nM9WfoNY8ZB4fpVE 9hXJIEP5BRPzZjG7TaBRorTzEAqbQ28VUfSmQ7fMRidLblC4Bb+MKTG1RJHEQl5clOx/ C/BN2mgm4WVpVICR4qyInRVenmGsUxzJC0kgRQPl9LJFwuphskpW3/U2kCwFhIhJMGCz 5vJrY6pZwTD3BBh2nw03v0jyLysc+xp1Wwttu+fRhHI4i0noFpI/NyQ18Kwc+3qigMwV duLg== X-Gm-Message-State: APjAAAWU6d0QGGOjJtFSopm27QF77ldbqyJELFNLkQ1Wv1Yy9dMhDjYG tv76bNHxva+nKq5lSX7GQIlDfA== X-Google-Smtp-Source: APXvYqwBURUiaefQaEsTZzx0SIkFbzLdJWKemCCeeCEH1PQrpCLnZQiGZWhUoIwrmftKy94I18IgPw== X-Received: by 2002:ac2:47f1:: with SMTP id b17mr5257943lfp.31.1570707621209; Thu, 10 Oct 2019 04:40:21 -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 p3sm1168937ljn.78.2019.10.10.04.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:20 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 10/13] cpuidle: psci: Add a helper to attach a CPU to its PM domain Date: Thu, 10 Oct 2019 13:39:34 +0200 Message-Id: <20191010113937.15962-11-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Introduce a PSCI DT helper function, psci_dt_attach_cpu(), which takes a CPU number as an in-parameter and tries to attach the CPU's struct device to its corresponding PM domain. Let's makes use of dev_pm_domain_attach_by_name(), as it allows us to specify "psci" as the "name" of the PM domain to attach to. Additionally, let's also prepare the attached device to be power managed via runtime PM. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 21 +++++++++++++++++++++ drivers/cpuidle/cpuidle-psci.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index 3f5143ccc3e0..7429fd7626a1 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -9,9 +9,11 @@ #define pr_fmt(fmt) "CPUidle PSCI: " fmt +#include #include #include #include +#include #include #include #include @@ -279,3 +281,22 @@ static int __init psci_idle_init_domains(void) return ret; } subsys_initcall(psci_idle_init_domains); + +struct device *psci_dt_attach_cpu(int cpu) +{ + struct device *dev; + + /* Currently limit the hierarchical topology to be used in OSI mode. */ + if (!psci_has_osi_support()) + return NULL; + + dev = dev_pm_domain_attach_by_name(get_cpu_device(cpu), "psci"); + if (IS_ERR_OR_NULL(dev)) + return dev; + + pm_runtime_irq_safe(dev); + if (cpu_online(cpu)) + pm_runtime_get_sync(dev); + + return dev; +} diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h index e593de1784c3..d2e55cad9ac6 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -8,4 +8,10 @@ struct device_node; void psci_set_domain_state(u32 state); int __init psci_dt_parse_state_node(struct device_node *np, u32 *state); +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF +struct device *psci_dt_attach_cpu(int cpu); +#else +static inline struct device *psci_dt_attach_cpu(int cpu) { return NULL; } +#endif + #endif /* __CPUIDLE_PSCI_H */ From patchwork Thu Oct 10 11:39:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB6F51668 for ; Thu, 10 Oct 2019 11:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 890FB21929 for ; Thu, 10 Oct 2019 11:40:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="y5fnfZfz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732979AbfJJLkZ (ORCPT ); Thu, 10 Oct 2019 07:40:25 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:45531 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732927AbfJJLkZ (ORCPT ); Thu, 10 Oct 2019 07:40:25 -0400 Received: by mail-lj1-f194.google.com with SMTP id q64so5808411ljb.12 for ; Thu, 10 Oct 2019 04:40:23 -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=xwB/tavfIMYf7rxHdkrDdviMkDSYXD3kklyLW60B66Q=; b=y5fnfZfzF20HGrbuklXhoX4IRAb3sw2pVHlyIgINlkZsqTCt4OVzOnIglZ5AC79CtD DsNOJpfSilfGfXZtv/tEgCB3gQiuhIGvs1zshF7zwNcTf2qOF8Fc/rMwNcZXiZTL+kw6 Yzr2TdiZrnORg1wGpq19yH9Xcs0CIUPV2lm1fsXVYSjXlq+ZlST41yjYA2oN1KG7fjS6 5gBBGJP6W0zkh27WfEp5bCy2cXFBBYwBVSQxDFzIbvzoUWu2TihJdw0pV2UQGtwkzvsY tHxQK36pjsfWSB57iJO/4O/taNsevtQefN+dNqFOeyJ3soL1660gFAXKDgtQIhwhU66S B0UQ== 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=xwB/tavfIMYf7rxHdkrDdviMkDSYXD3kklyLW60B66Q=; b=GPrPQ1U7sfmhIrlXPuLwC6g/ZXtNl8fvDdh8y+yoFJtzoNjQdeq0Z/BkUThj55VxPO 0AmqupZU+XZ3E9stCHEyaj32mWG4BomRiJ7obgCh6JNShE8qZqLloyvYG30/wkzpYpjY 52A32VsXzFmPGIMNTEsZM18luHrYHES1+HVnKgnL5AsOGx3ezQYGnyk/DtQqbgmU2gt3 R39cKvqqwTxPLDLGj1EaayesG/8jo97CvbqAtAzwX9Mtu5UZkERHIpgVAevcgv02T9pM hlDUeq9Z7YDDRgUpx5qU6mrw6wIi3KIm9kz82zOr7dsyzbCFx8vXX3rXTc1QdGEIxKbJ rIJw== X-Gm-Message-State: APjAAAXD8gWQg4fJ5UZu0GbFbnoN6Htm83AG2I8/4o4ZXRwXKXiw/xTj AlBr+WqdjjPnW0AswDEKFXuFfQ== X-Google-Smtp-Source: APXvYqx9XzUujAF/LwxrlZOzoBs1q0AvlrOroFuQxRIn7MA18US1H4Ia1dTMLsrPBuGfqUBKeebXeA== X-Received: by 2002:a2e:9f4d:: with SMTP id v13mr6239064ljk.226.1570707622756; Thu, 10 Oct 2019 04:40:22 -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 p3sm1168937ljn.78.2019.10.10.04.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:22 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 11/13] cpuidle: psci: Attach CPU devices to their PM domains Date: Thu, 10 Oct 2019 13:39:35 +0200 Message-Id: <20191010113937.15962-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In order to enable a CPU to be power managed through its PM domain, let's try to attach it by calling psci_dt_attach_cpu() during the cpuidle initialization. psci_dt_attach_cpu() returns a pointer to the attached struct device, which later should be used for runtime PM, hence we need to store it somewhere. Rather than adding yet another per CPU variable, let's create a per CPU struct to collect the relevant per CPU variables. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index a16467daf99d..1510422c7a53 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -23,7 +23,12 @@ #include "cpuidle-psci.h" #include "dt_idle_states.h" -static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +struct psci_cpuidle_data { + u32 *psci_states; + struct device *dev; +}; + +static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); void psci_set_domain_state(u32 state) @@ -45,7 +50,7 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { int ret; - u32 *states = __this_cpu_read(psci_power_state); + u32 *states = __this_cpu_read(psci_cpuidle_data.psci_states); u32 state = psci_get_domain_state(); if (!state && idx) @@ -103,7 +108,9 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, { int i, ret = 0; u32 *psci_states; + struct device *dev; struct device_node *state_node; + struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); psci_states = kcalloc(state_nodes, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) @@ -128,8 +135,16 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, goto free_mem; } - /* Idle states parsed correctly, initialize per-cpu pointer */ - per_cpu(psci_power_state, cpu) = psci_states; + dev = psci_dt_attach_cpu(cpu); + if (IS_ERR(dev)) { + ret = PTR_ERR(dev); + goto free_mem; + } + + data->dev = dev; + + /* Idle states parsed correctly, store them in the per-cpu struct. */ + data->psci_states = psci_states; return 0; free_mem: From patchwork Thu Oct 10 11:39:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C0FE1668 for ; Thu, 10 Oct 2019 11:40:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BAB22053B for ; Thu, 10 Oct 2019 11:40:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S1K49Am4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732927AbfJJLk0 (ORCPT ); Thu, 10 Oct 2019 07:40:26 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36108 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732792AbfJJLk0 (ORCPT ); Thu, 10 Oct 2019 07:40:26 -0400 Received: by mail-lj1-f196.google.com with SMTP id v24so5860365ljj.3 for ; Thu, 10 Oct 2019 04:40:25 -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=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=S1K49Am4kSDehLMFo+y+aCn++SGdGyNEXyDKQRhsyEPFb1U+Qix4b9k4PUVRkwMwNo H1Drcbx+EDc2EDWjdPplZZWExubE/UfjqHL/TFs1EpwMdzjNtIKS46NPjhea/SBAVuq0 ayS5Uvhu+BLV2F9mmm/wYqmAwVyQLTTLhdmXercedrMYUeL842KegEAPuu1HoOsC5IYo wCEzh1VrCwNsmAM5iFSLdMYtQZX5h9kLTbBXKGX6RsmAHRa+SZp3SSXIEoYZ89kE7QUv Ygj6ExCVVuMj5lOyunwckLd0vQXnx7AbRGLkFUfRtC+bX6wI8fQg8yvPZKfW/oaWQgOe QXPQ== 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=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=Im4+ufTGOaZl6vbuwdKVinH11nV+5oV7FMsPHgUx1y+lZAx1Zmnfab3J91NT4WIytM YexwLC2eVHERT+5C0ZurkkL9XClygABP4UZSWNasbHq/ev7AFnfSsp8sy/q/XRxd2P3F FhdEb6C3SYPAFYv2Iae+tOeL6B+6Kdplacp+3CtDwSNoUAFn1vKkCrcPoy5y0lTblUft ke9wgS0bFYVX44AOKv2Lcw/0prbirCj3CgI553QbJUsC9O33/CHVr69AQj3JI+1SqlcF Hyu9JQAZmlrr86oUq9+kxg3Vib6MEBhazqQkC9mNUls+Pz6K74SvBovLnJqG3XolqC4s 8PZA== X-Gm-Message-State: APjAAAW1Sefwx9jUL9ThvNMJ5cwXCdxXMPq5QC9l5VB/+cGdupRp3XJD usD66K+LAEeVfvgaortVG2NlB4zJYB4= X-Google-Smtp-Source: APXvYqwOX8ItiDZEA+kQQBb68Jv+sNmaYtISkfDtd1UlzUU+vXQj3Y0mD4hDx6nLR//tbqlRlepYnA== X-Received: by 2002:a2e:8310:: with SMTP id a16mr177041ljh.48.1570707624283; Thu, 10 Oct 2019 04:40:24 -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 p3sm1168937ljn.78.2019.10.10.04.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:23 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 12/13] cpuidle: psci: Manage runtime PM in the idle path Date: Thu, 10 Oct 2019 13:39:36 +0200 Message-Id: <20191010113937.15962-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In case we have succeeded to attach a CPU to its PM domain, let's deploy runtime PM support for the corresponding attached device, to allow the CPU to be powered-managed accordingly. To set the triggering point for when runtime PM reference counting should be done, let's store the index of deepest idle state for the CPU in the per CPU struct. Then use this index to compare the selected idle state index when entering idle, as to understand whether runtime PM reference counting is needed or not. Note that, from the hierarchical point view, there may be good reasons to do runtime PM reference counting even on shallower idle states, but at this point this isn't supported, mainly due to limitations set by the generic PM domain. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 1510422c7a53..0919b40c1a85 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ struct psci_cpuidle_data { u32 *psci_states; + u32 rpm_state_id; struct device *dev; }; @@ -50,14 +52,28 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { int ret; - u32 *states = __this_cpu_read(psci_cpuidle_data.psci_states); - u32 state = psci_get_domain_state(); + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); + u32 *states = data->psci_states; + struct device *pd_dev = data->dev; + bool runtime_pm = (pd_dev && data->rpm_state_id == idx); + u32 state; + /* + * 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(pd_dev); + + state = psci_get_domain_state(); if (!state && idx) state = states[idx - 1]; ret = __psci_enter_idle_state(idx, state); + if (runtime_pm) + pm_runtime_get_sync(pd_dev); + /* Clear the domain state to start fresh when back from idle. */ psci_set_domain_state(0); return ret; @@ -142,6 +158,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, } data->dev = dev; + data->rpm_state_id = state_nodes; /* Idle states parsed correctly, store them in the per-cpu struct. */ data->psci_states = psci_states; From patchwork Thu Oct 10 11:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 352CE76 for ; Thu, 10 Oct 2019 11:40:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D81320B7C for ; Thu, 10 Oct 2019 11:40:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ttocmxpO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732944AbfJJLk2 (ORCPT ); Thu, 10 Oct 2019 07:40:28 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36111 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732792AbfJJLk2 (ORCPT ); Thu, 10 Oct 2019 07:40:28 -0400 Received: by mail-lj1-f193.google.com with SMTP id v24so5860456ljj.3 for ; Thu, 10 Oct 2019 04:40:26 -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=seqtCL6qQP1lHpVV6JxVbCofE6J8aEcyzCDtbKaRiuo=; b=ttocmxpO4BTiaii5K7cn0npU6eVhqZ9uMEDMEG7dnyW79epK0rCXS/lpw4SkqbYIYg W59Vn7rAze9cJVsyqKmksnN9Di4v2QsCN03gmrmsqBwJ/hkNQiPz0b1pmIgAI601KtUS aSppXlnpANOGQrmU9eDiPdCo6OV3bH+oi46O/xtlYtnNSj1loyozvQ3GaZcs7LOYfHih 30F0tcFKMkGwAo2oAQogPCkIcT9AmDSJ9rlR/88iiStn7tuBkFUijM/paQ7/7P3O8FJp cMKAdQl/TnVG7+eXCp+OBz/Zuzksl0YdnzPxvlspzR/jpoJqQbicu/XpqqncUNiFreNm lOHg== 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=seqtCL6qQP1lHpVV6JxVbCofE6J8aEcyzCDtbKaRiuo=; b=eq+IT0AFfwx6UBZkF788vxUdatkSk2kxbaZl0I2qw01/Ib650qegeijC+cw/7zKrVL KZhlX30k2AuagOJOzH5KaIdqeoLs6rRN08agdlcIATFyK78PPN1fT9fEmBIndkAqStvW QCNYl8qHGW9cBAt2P/omKtwJC0pVKqFt19ydK4o5FrYnHbA70FOu1gh6N7W7GeMcG/mp VaUcY9mu+k7Ul2InSlhPeEvHby5BClBOi0Hhw3+exLzR+2OCRS20Ehylp4zr0FiNQlsM KK1VUf5LpNBOsGptH0+78P0BUl3UTtOBiGHLf82Uqi5b9uXouLDhLm7+9aFmQIoAWhuh EsvA== X-Gm-Message-State: APjAAAVPwwoB/Vy1rEJe8cEszpNH3iTenmkpZipPBt/O0Z1A0Ptt3cKF /l4k7EFn7ZNkiTHewyy9DVfzYg== X-Google-Smtp-Source: APXvYqzAtQRFaFdOYUhWXaaCWhBIREvEFZI1olu/oFVmp742iMrFKC80mDD/KfhtuHeGyAmVXW6Erg== X-Received: by 2002:a2e:9205:: with SMTP id k5mr6239604ljg.202.1570707626147; Thu, 10 Oct 2019 04:40:26 -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 p3sm1168937ljn.78.2019.10.10.04.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:25 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Andy Gross , Lina Iyer Subject: [PATCH 13/13] arm64: dts: Convert to the hierarchical CPU topology layout for MSM8916 Date: Thu, 10 Oct 2019 13:39:37 +0200 Message-Id: <20191010113937.15962-14-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org To enable the OS to better support PSCI OS initiated CPU suspend mode, let's convert from the flattened layout to the hierarchical layout. In the hierarchical layout, let's create a power domain provider per CPU and describe the idle states for each CPU inside the power domain provider node. To group the CPUs into a cluster, let's add another power domain provider and make it act as the master domain. Note that, the CPU's idle states remains compatible with "arm,idle-state", while the cluster's idle state becomes compatible with "domain-idle-state". Cc: Andy Gross Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- arch/arm64/boot/dts/qcom/msm8916.dtsi | 57 +++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 5ea9fb8f2f87..1ece0c763592 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -102,10 +102,11 @@ reg = <0x0>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD0>; + power-domain-names = "psci"; }; CPU1: cpu@1 { @@ -114,10 +115,11 @@ reg = <0x1>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD1>; + power-domain-names = "psci"; }; CPU2: cpu@2 { @@ -126,10 +128,11 @@ reg = <0x2>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD2>; + power-domain-names = "psci"; }; CPU3: cpu@3 { @@ -138,10 +141,11 @@ reg = <0x3>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD3>; + power-domain-names = "psci"; }; L2_0: l2-cache { @@ -161,12 +165,57 @@ min-residency-us = <2000>; local-timer-stop; }; + + CLUSTER_RET: cluster-retention { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x41000012>; + entry-latency-us = <500>; + exit-latency-us = <500>; + min-residency-us = <2000>; + }; + + CLUSTER_PWRDN: cluster-gdhs { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x41000032>; + entry-latency-us = <2000>; + exit-latency-us = <2000>; + min-residency-us = <6000>; + }; }; }; psci { compatible = "arm,psci-1.0"; method = "smc"; + + CPU_PD0: cpu-pd0 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CPU_PD1: cpu-pd1 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CPU_PD2: cpu-pd2 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CPU_PD3: cpu-pd3 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CLUSTER_PD: cluster-pd { + #power-domain-cells = <0>; + domain-idle-states = <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; }; pmu {