From patchwork Mon Dec 30 14:43:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313153 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 2BEB2109A for ; Mon, 30 Dec 2019 14:44:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 098E920663 for ; Mon, 30 Dec 2019 14:44:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VLgbT14a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727445AbfL3OoM (ORCPT ); Mon, 30 Dec 2019 09:44:12 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:40794 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727499AbfL3OoM (ORCPT ); Mon, 30 Dec 2019 09:44:12 -0500 Received: by mail-lj1-f194.google.com with SMTP id u1so33493726ljk.7 for ; Mon, 30 Dec 2019 06:44:10 -0800 (PST) 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=yJwsi3DMV/pwzB8sWAmHjBjjwOzOWtOVx10q5OKc/Qg=; b=VLgbT14aKbIweXjePyokMcXGIZ6qb6kWlnLdbU2O9QNBikijGUeMsDJ5BerDOGJVyP hT/gOq3EcoVXwl4kpM8e3733iP90YILT3RaXDUM2AuU9KGQt4qYTgy6f6jabQM8o6m0z f2Dw+FKT/VwRq6dj/Q+Mb4OPmk5DBWeU3Am8tGUkQkau5kdcLudikh879SjNbyZlbktm lKJi0S1dkLtuKh4sR51iIzOPusJcnwu9cu+P1Mbyr5xhvb7FvMb2wY+1GVhDzNKRCsz4 LDcl7o0n0E5yYOD6GEMWIYriiQq1ppx9SFRSm2kbu+C3hWO2xWy6bgqtGzmp6tbF8BLn M+Kw== 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=yJwsi3DMV/pwzB8sWAmHjBjjwOzOWtOVx10q5OKc/Qg=; b=ECSZcC7DcXXKCAl2vXl9ZSnRi24T9zb3Jb2f81ShGnEKbmQMzjukcdOlFek0XTzf4G NtZd4YOpvz1QeSHAJTzrXGlGHRc+XuMSGbmZ+pJSMgKzHAsOf0bsXvr8SQSbg/fIslJL VvjD/VKvtnXxkYq80B/fZwGIO6RJLu6a/NDH+1ZSh2utjphBH7PcKhXbTFJoNRRrBWHv FeScnQLvE9dx/nKjqRPnXJasEgw4UQ62MKW9Zeyja17QBAAUcpd2Wq7TM9YTO5YV2rU4 NBSxWr2N7n7n+/ShvfKanAcr9gDQtWXe1sNbvBVd6Yfd0eJK1lNvMQp7iadiGQ7YFgNP /1dg== X-Gm-Message-State: APjAAAVx22MjKg/xeDVS3PvFdFU0cdFBl52dhz5ACKJujDzYqcX3S8/e HOQem6Aim1C8gC4sQX50ICtUqA== X-Google-Smtp-Source: APXvYqwN0EAf9bCeoE9MhNqvKtGj6Kuzpeq236RUFu+VyIzagp3j7CmYdCtkZY/sNNfmqJXTyE+Ieg== X-Received: by 2002:a2e:9e43:: with SMTP id g3mr23393509ljk.37.1577717050174; Mon, 30 Dec 2019 06:44:10 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:09 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 01/15] cpuidle: psci: Align psci_power_state count with idle state count Date: Mon, 30 Dec 2019 15:43:48 +0100 Message-Id: <20191230144402.30195-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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: Sudeep Holla Instead of allocating 'n-1' states in psci_power_state to manage 'n' idle states which include "ARM WFI" state, it would be simpler to have 1:1 mapping between psci_power_state and cpuidle driver states. ARM WFI state(i.e. idx == 0) is handled specially in the generic macro CPU_PM_CPU_IDLE_ENTER_PARAM and hence state[-1] is not possible. However for sake of code readability, it is better to have 1:1 mapping and not use [idx - 1] to access psci_power_state corresponding to driver cpuidle state for idx. psci_power_state[0] is default initialised to 0 and is never accessed while entering WFI state. Reported-by: Ulf Hansson Signed-off-by: Sudeep Holla Reviewed-by: Ulf Hansson --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index f3c1a2396f98..361985f52ddd 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -30,7 +30,7 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, u32 *state = __this_cpu_read(psci_power_state); return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, - idx, state[idx - 1]); + idx, state[idx]); } static struct cpuidle_driver psci_idle_driver __initdata = { @@ -89,12 +89,14 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) if (!count) return -ENODEV; + count++; /* Add WFI state too */ psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 0; i < count; i++) { - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + for (i = 1; i < count; i++) { + state_node = of_parse_phandle(cpu_node, "cpu-idle-states", + i - 1); ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); From patchwork Mon Dec 30 14:43:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313157 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 D8C09109A for ; Mon, 30 Dec 2019 14:44:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD95A2071E for ; Mon, 30 Dec 2019 14:44:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OnI4QS8N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727497AbfL3OoO (ORCPT ); Mon, 30 Dec 2019 09:44:14 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:39364 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727577AbfL3OoO (ORCPT ); Mon, 30 Dec 2019 09:44:14 -0500 Received: by mail-lf1-f67.google.com with SMTP id y1so25245454lfb.6 for ; Mon, 30 Dec 2019 06:44:12 -0800 (PST) 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=r9qPRcXLVOFWseww0rJCrR4g4TyPzQrzTBExN2uOHy4=; b=OnI4QS8Nt6994mhUQcx1kQDuaQevESKsLPc8rxKnbqqWftkt+E1r46HY0dBwrhzkpc H44CDiCqlg8smjWuD0yvyE73+wlqhZc7C8QG6ZehqRlD8J9XekP0rDHcA7B/g56ltIWP bUEM5q0EiJK7TVg2z5KRi0Ltrl9DEgg9ggy0kBGFijfO1eRRqdLhKdOwo3W0oLE9mdvU IV2uouMDvacrdHlIGkvYikscyBPs4Ze+hKxYJ18DKMGMOCJzo3RqTCKiA+j/+So2dVSC VuJUrQz0V43p/P4mfxlsXrh58XgBede12nLo8nQeizi9nLDVu4UzH46v6abiJ65zZvgL fi5w== 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=r9qPRcXLVOFWseww0rJCrR4g4TyPzQrzTBExN2uOHy4=; b=qPI59OaahcSvwSYc3eAQEtRKgF+crtG1ZKE2QYpFOESAdEdPy0JzFyI4HhBrTG0RNc EEKHnG/0jZnMi9Sn/7axrfDyOp3HDLpB2CSbaEk5aBQcFttvqEJoPNoXgMMmFBMm/VSh 7VLKHsn/rDaH5/pSyS+/B1gLwaH4CoU5f1h4QWdx0Mqr4jpJfr+MupgrRmp8bDxOGL/y NKrbZ5ZxOdtMGQam1sFXOgHtvdq5ATtIehRmkUIDdo0Tu3tUwUmBQSuktN/XA02MKF/C L8mnwX26L0FgGFIv0wKPKVFTj+PBuCfHNt7QLRIVhU9ErFt5vVgypK0x0fdZ9jNIowgW /bNg== X-Gm-Message-State: APjAAAW7hU6wPDS9QZA/NQp56lW/lYceBDCQSvLys9esKzp3h1v+A5ht pT4ZZ6wPjLvS3K2ZGflsbcIVLQ== X-Google-Smtp-Source: APXvYqxzJBNjO1k6tBVSulP2pdf1igj0eM/c41xEG/qNA1Roj4AVOwV30PiEM9CDLX06bl+IWvOITg== X-Received: by 2002:a19:cc49:: with SMTP id c70mr38777845lfg.73.1577717051716; Mon, 30 Dec 2019 06:44:11 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:11 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v5 02/15] dt: psci: Update DT bindings to support hierarchical PSCI states Date: Mon, 30 Dec 2019 15:43:49 +0100 Message-Id: <20191230144402.30195-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 DT bindings for PM domains [1] and for PM domain idle states [2]. Let's also add an example into the document for the PSCI DT bindings, to clearly show the new hierarchical based layout. The currently supported flattened layout, is already described in the ARM idle states bindings [3], so let's leave that as is. [1] Documentation/devicetree/bindings/power/power_domain.txt [2] Documentation/devicetree/bindings/power/domain-idle-state.txt [3] Documentation/devicetree/bindings/arm/idle-states.txt Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Reviewed-by: Sudeep Holla Signed-off-by: Ulf Hansson --- Changes in v5: - None. --- .../devicetree/bindings/arm/cpus.yaml | 15 +++ .../devicetree/bindings/arm/psci.yaml | 104 ++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/cpus.yaml b/Documentation/devicetree/bindings/arm/cpus.yaml index c23c24ff7575..7a9c3ce2dbef 100644 --- a/Documentation/devicetree/bindings/arm/cpus.yaml +++ b/Documentation/devicetree/bindings/arm/cpus.yaml @@ -242,6 +242,21 @@ properties: where voltage is in V, frequency is in MHz. + power-domains: + $ref: '/schemas/types.yaml#/definitions/phandle-array' + description: + List of phandles and PM domain specifiers, as defined by bindings of the + PM domain provider (see also ../power_domain.txt). + + power-domain-names: + $ref: '/schemas/types.yaml#/definitions/string-array' + description: + A list of power domain name strings sorted in the same order as the + power-domains property. + + For PSCI based platforms, the name corresponding to the index of the PSCI + PM domain provider, must be "psci". + qcom,saw: $ref: '/schemas/types.yaml#/definitions/phandle' description: | diff --git a/Documentation/devicetree/bindings/arm/psci.yaml b/Documentation/devicetree/bindings/arm/psci.yaml index 7abdf58b335e..8ef85420b2ab 100644 --- a/Documentation/devicetree/bindings/arm/psci.yaml +++ b/Documentation/devicetree/bindings/arm/psci.yaml @@ -102,6 +102,34 @@ properties: [1] Kernel documentation - ARM idle states bindings Documentation/devicetree/bindings/arm/idle-states.txt + "#power-domain-cells": + description: + The number of cells in a PM domain specifier as per binding in [3]. + Must be 0 as to represent a single PM domain. + + 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 binding in [3]. The idle states + themselves must conform to the binding in [4] and must specify the + arm,psci-suspend-param property. + + It should also be noted that, in PSCI firmware v1.0 the OS-Initiated + (OSI) CPU suspend mode is introduced. Using a hierarchical representation + helps to implement support for OSI mode and OS implementations may choose + to mandate it. + + [3] Documentation/devicetree/bindings/power/power_domain.txt + [4] Documentation/devicetree/bindings/power/domain-idle-state.txt + + power-domains: + $ref: '/schemas/types.yaml#/definitions/phandle-array' + description: + List of phandles and PM domain specifiers, as defined by bindings of the + PM domain provider. required: - compatible @@ -160,4 +188,80 @@ examples: cpu_on = <0x95c10002>; cpu_off = <0x95c10001>; }; + + - |+ + + // Case 4: CPUs and CPU idle states described using the hierarchical model. + + cpus { + #size-cells = <0>; + #address-cells = <1>; + + 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 Mon Dec 30 14:43:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313163 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 E26A2159A for ; Mon, 30 Dec 2019 14:44:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C061220722 for ; Mon, 30 Dec 2019 14:44:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Gc+Fg4Tm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727593AbfL3OoQ (ORCPT ); Mon, 30 Dec 2019 09:44:16 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46266 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727569AbfL3OoQ (ORCPT ); Mon, 30 Dec 2019 09:44:16 -0500 Received: by mail-lf1-f67.google.com with SMTP id f15so25235819lfl.13 for ; Mon, 30 Dec 2019 06:44:14 -0800 (PST) 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=krY1+EzVUJ6sQ3sUZo42Ne6/cEpafTpvxV4MO9ew0Qs=; b=Gc+Fg4TmSoUG1xWh3kAAiPa4hscTTHTe6IdrmSqns5W0W+f7yJrWKqBYznZ+x0PfgH NXbjsuw2UWFrmRxEtu+ztS7HJpjnO0pQMsTaHMpUkWCneB+VdUs4fpaxwI4jqRs1A/0h HmWRvjF8FTPMxeZXibm2xawvWvneqvZysoeI74fqb3JuHPQ6wc9t52l/qvM9Xi1BIGbr Xm2ICKSM+SPWCTmZkaqkmasmkFKPO744rJ8SrsfKkjQQpjcXbjzrdM+UBEz2ONQJv4hM Eue69/Oc3VVQtL6NLjIDPyUe3oBQcFFKMow3ZJ7rP0IwzTXPWtSqWDS1snHLUYOL6hAG YM5A== 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=krY1+EzVUJ6sQ3sUZo42Ne6/cEpafTpvxV4MO9ew0Qs=; b=ejx2yA0OzLmEqAySOYsF5Jw2benwm4DYISqFGw2P9+qKyZzWEXiWccLU6UWJYjvv/M 2YaJN/bNSuUGkYnoHfvcc4l8RZ4/Xlf1/MpZ5FWtekd2yV1qaeOClZSO2ePSWZNZAaS8 CSkWMLt97kqhrEMRorSnBUxU1Fb8Rh4sD1R8pS1V6YT6bzZ5WE0LlFn0Q7KzxoMMfiQO 5iotNnd0d7a8kywgOR2C1+E/KO8vUl97StYX3gq6itQRgbvuGOFjrdiUz4ImB+dVdtLe SdlmGYBiXnNu2BSgJVRd9pVun0zwCb8aCd1SGpLunGR/ASlDfqCYI82UM5OhZCluTzZ5 hdcw== X-Gm-Message-State: APjAAAX+iy8Nd+JInqO/ju+qu2Z2kMT8MtCj83L1C7/t3lmHZjRjlGMY snqAyis94Hy+2dDRQ7S0p3sX0g== X-Google-Smtp-Source: APXvYqwJxfxFlD3Cgmg6BuZVIx15qUnVkISMIx+ar2b16DDxv2vUZ23t0kZT/+jP5v39VcqlR5CAmQ== X-Received: by 2002:a19:8a06:: with SMTP id m6mr35878357lfd.99.1577717053708; Mon, 30 Dec 2019 06:44:13 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:13 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 03/15] firmware: psci: Export functions to manage the OSI mode Date: Mon, 30 Dec 2019 15:43:50 +0100 Message-Id: <20191230144402.30195-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 --- Changes in v5: - None. --- 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 b3b6c15e7b36..2937d44b5df4 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -97,7 +97,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; } @@ -162,6 +162,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; @@ -544,9 +553,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 ebe0a881d13d..a67712b73b6c 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -18,6 +18,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 smccc_version { SMCCC_VERSION_1_0, From patchwork Mon Dec 30 14:43:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313165 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 A0000109A for ; Mon, 30 Dec 2019 14:44:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D03B20663 for ; Mon, 30 Dec 2019 14:44:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cy2p709J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727594AbfL3OoS (ORCPT ); Mon, 30 Dec 2019 09:44:18 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33109 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727584AbfL3OoR (ORCPT ); Mon, 30 Dec 2019 09:44:17 -0500 Received: by mail-lj1-f193.google.com with SMTP id y6so25494614lji.0 for ; Mon, 30 Dec 2019 06:44:15 -0800 (PST) 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=2SSEC2vfb168IYWIDWdargmVpZp+vFDhT4s2aSCvbsQ=; b=cy2p709JggRMYRuxWxFdSksTT9ddyA6a1dDrdu8q9fW1P86WFtSDw9ag8hPz6ZKNOQ kDbXHnK228dLnG1KkaVAm6OI3xR1KKNURB+OdJgoUO+EiSNZF9dXv9l9daoRmOzkGs2T 00+SgiucRmVEWbLY4IJz3gvwOyuL+S4e/7NiYFsWBMHBQDyjcT3EK2SkrWpoLwFdaPEg nBYjSUKXhhEzxyGYCZqZGc1kKT070puW5yjAnE/b9zsWciGHXcg8kN8xdQ5cmJzfHNmh R1vZZc3iISEj4NHiP3JQ70DFnvqLZX4hOO/+R8BfI/n3NfeJoC1NKuqgI8O5xUoMKVij T5qA== 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=2SSEC2vfb168IYWIDWdargmVpZp+vFDhT4s2aSCvbsQ=; b=srABPkLlKLm5h3qB3eP0btQw6r/x9IwV7cAqPo1Q8Kzuk6BBXyDQfwviHr2Gaea/Gn uinEosqDStDv1b4ri/7HgMLG17x8ILpSgJkAMxdm4ncf4/F3yHEivdXL5miFkuoz7N9t OPUIFFpjQYNwPo1HiHTLFfuty/jpgznT5KX0AV8N0JD0SvBCujxTW9YzfyBRfGZbZLZr s/W9/06bCAnH91a9+PNisTDXD/d6pjAAk+b61AfXKWGV86n5G/m47q5+gyzGFyMSPrHk GJd9USarqcCwypB6XOG0Kb8xevmaDI4tb0N8mSrglL5nQCF5j09ef+Se/1+E3HF9Uswq EdqA== X-Gm-Message-State: APjAAAV0tWGRYrDuy1YVI8x8DKkZoAuuDymxVsQyz3o6q32iRNZ9jF8V nOssK97JHcO2zbg0gBY8br5pJw== X-Google-Smtp-Source: APXvYqwKhyGXfftma4hgJ9/As4lgMAp1G9DT6skACgdPUdlDaDw5umtQpzwwdtRkeXNe5nNxtRZmUQ== X-Received: by 2002:a2e:88c4:: with SMTP id a4mr10783373ljk.174.1577717055205; Mon, 30 Dec 2019 06:44:15 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:14 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v5 04/15] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Mon, 30 Dec 2019 15:43:51 +0100 Message-Id: <20191230144402.30195-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 --- Changes in v5: - None. --- 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 db7fbc0c0893..614f0c674995 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -489,6 +489,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 Mon Dec 30 14:43:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313169 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 32C1D186D for ; Mon, 30 Dec 2019 14:44:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1037320722 for ; Mon, 30 Dec 2019 14:44:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jOMMern6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727591AbfL3OoS (ORCPT ); Mon, 30 Dec 2019 09:44:18 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37534 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727569AbfL3OoS (ORCPT ); Mon, 30 Dec 2019 09:44:18 -0500 Received: by mail-lf1-f66.google.com with SMTP id b15so25292606lfc.4 for ; Mon, 30 Dec 2019 06:44:17 -0800 (PST) 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=owx+SloUf8pds6VPSlJapJq+5ymBBPQ7iA/SKJJgwjU=; b=jOMMern6T7wiWE4/ufEPrcYPooLKd4g26VuETKc7rFkMRNBi7vRvt8RFhBr0UOWAnN wp11vcK5R9zGy6To03gCj2b0edl6KenBOw1Y+Jb4/Xv8ZSsYJBbEM/iOOcAndEOhUKDf t5WQq15GFK32RuJCD0MERQBiYIJz4eWhazo3dx3TlfMiVG41xKuXddbILMfHTxh9gzpj MQ64gwbw5YmhfRQDHZIZQzHQm7Gx93y0GfcirJquGCLKb31azdub1BUAwNDJhfvmnPwQ y1TQ1/1HmlOhpvbbHmNj8AVinJ+THuhmX6qe2QprHuwKGNVBuuPFIbtj7RLGpelLTurU VQIA== 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=owx+SloUf8pds6VPSlJapJq+5ymBBPQ7iA/SKJJgwjU=; b=rbR2gOneu8rKRHfitVgZwsQm1f6l3WJ+Zs/eeYDYsQz6oFMaqRWfw/dRQrDYFouaao x2Cj/cFoL9hr6+er3ehtZQ0JmfrAZi5PgE7DkNXHo26P1xg6tE51+rBQkmpcsqRR0SyP W9fDB4Lwlun63P3mEDwn7rJyG+4qDVet/b+iGhvIauJr9tprNZ1XnsZehf2NK3s/kVm2 NjIH3BO0F0dmhuuAu7avpfQGRDrwjUiEpZB3NE1eGE4f+weoqqrB9U244ZC46oNv+1ib Ek+nhGy8FFExMQSYMh/rRhTd0b7nlyfAnvD5Xaq7On7VwQ61CqV9p789cfvVyZ3gJwPB zWyg== X-Gm-Message-State: APjAAAVAgoBK7M5oKpC/NfzANTMslq5G61gVoWpWZgZ/Pc5S2gX75BUl SCbMt71rr+Lxcxw8u80qmeRZrg== X-Google-Smtp-Source: APXvYqxp/iitD6O/NdUA06r9/yZSgghJqfhQcVQLOvvXc32vodyNVAkq4131RInkIiKGlrJereqGvg== X-Received: by 2002:a19:f006:: with SMTP id p6mr37770832lfc.94.1577717056795; Mon, 30 Dec 2019 06:44:16 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:16 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v5 05/15] cpuidle: dt: Support hierarchical CPU idle states Date: Mon, 30 Dec 2019 15:43:52 +0100 Message-Id: <20191230144402.30195-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 --- Changes in v5: - None. --- 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 Mon Dec 30 14:43:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313173 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 3C88F109A for ; Mon, 30 Dec 2019 14:44:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BDD420722 for ; Mon, 30 Dec 2019 14:44:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="wG7mQUko" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727554AbfL3OoU (ORCPT ); Mon, 30 Dec 2019 09:44:20 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:45638 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfL3OoU (ORCPT ); Mon, 30 Dec 2019 09:44:20 -0500 Received: by mail-lj1-f194.google.com with SMTP id j26so33492085ljc.12 for ; Mon, 30 Dec 2019 06:44:19 -0800 (PST) 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=6qhaKAOOwBUfphZITjOkaySj3WTdBaYmHNTmS8ilyv4=; b=wG7mQUkoPejsVwzXXOR08qaX/pB5VvQfRie7bMqeCEZDWX6/8m1lt3cS7XNawUn2xu XMe4fcnuL8f9C0vHRJKGysck8qxoOMC50DHral3znLUFRh4dFzTa7cBTRvdiBY9RGsiJ 2uMf3PGS38C96bB3TAoX/OpgAVZDIus7XktEp05Y0clIcfD4bxDP0Vyj8HEq4lIKuzdy TDUIRxVUXm/kzgxN6BVIPqMzTYHNg4QmGEfyfbaruTVN5RulSwBpkD3XhfpD0ynnicdb MFoEgkcs0R0oX04FnDByktNiRwyDuiGeA7Ndor1L21m4KpMXcfjf60XZ3kXh3pc/fE9n YROg== 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=6qhaKAOOwBUfphZITjOkaySj3WTdBaYmHNTmS8ilyv4=; b=YlA9Htq4anxetK3b357a8p4j23sEujhYBPBaID3O2xDQx/q86COZFF5McShCOfuli1 AqCgt5uhTexncidXO+1Ei06nGjSCIDllPIgpuzTjkqSK7PUyVfXEVe3S1zxyKzjhT0tt R49BpqBrLSIPZwuxEnUjUFC3ka4G0UE9QQDjwDoaCy71ssjxJl3yO8eiuKgEH0nWwJzH of3XAaC4AD74AUdiwJyc0ZrCT8C6RsezO8lnwPD63Ji/Z2oxgdVIV/o2ie3ncgJ+agfK FZqMliPMkaXOj9P5ffeqnV28HxBNkD1ubXp/8Yt05SO0WPYK39vtHOnaxdq5p1GBlKeL sQag== X-Gm-Message-State: APjAAAWUKcLYWmUU9yY738VEPooIA3j7V0JTgEyoqi3wvkYJtUlVwuWa Kb4idkdOnxBNVmnu4kUZlPC2nA== X-Google-Smtp-Source: APXvYqzo7w+nzPjrwX/azlK6JCTeEG0nxZOnfsmsZ5aML/2fh5jWYLvgMQF5SaNVyXhNasLRLg8J8Q== X-Received: by 2002:a05:651c:327:: with SMTP id b7mr37221036ljp.22.1577717058420; Mon, 30 Dec 2019 06:44:18 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:17 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 06/15] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Mon, 30 Dec 2019 15:43:53 +0100 Message-Id: <20191230144402.30195-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 Reviewed-by: Sudeep Holla --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 361985f52ddd..761359be50f2 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -73,30 +73,24 @@ 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_count, 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; - - count++; /* Add WFI state too */ - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + state_count++; /* Add WFI state too */ + psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 1; i < count; i++) { + for (i = 1; i < state_count; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i - 1); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -106,6 +100,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_count) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0; @@ -115,7 +114,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_count) { struct device_node *cpu_node; int ret; @@ -131,7 +130,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_count, cpu); of_node_put(cpu_node); @@ -187,7 +186,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 Mon Dec 30 14:43:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313177 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 C7322109A for ; Mon, 30 Dec 2019 14:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6C4520663 for ; Mon, 30 Dec 2019 14:44:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gaWhEs8b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727601AbfL3OoW (ORCPT ); Mon, 30 Dec 2019 09:44:22 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35513 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727577AbfL3OoW (ORCPT ); Mon, 30 Dec 2019 09:44:22 -0500 Received: by mail-lj1-f195.google.com with SMTP id j1so26137219lja.2 for ; Mon, 30 Dec 2019 06:44:20 -0800 (PST) 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=8v5xuPr2EJ9DSJyEgwYWHNaPW3NhmJIKXs9ahA/QI14=; b=gaWhEs8bCTWDjEkiGpFUqwqn0GmNDQFWOkn0x0TuUvrI5mbmBk//3DIZtLQXKs5geY qZOvtle3WhKIeLFP4Jf/SaYuFwlcYSLHPyMWs99zDm1lmL1hR/5wxeqoI69Ti0korIh5 PmfFnwSLudQzFF1yugoRk7BpHN/tfDHzC9mmEwDiapNhF41HUTHdedRqODqM7S96A6uG bt7yFtA39kFLXZA+CCjihGvjyrxenBf/EJsQG9XvkaoZqTB4ZRdiGl0cms+egMgnp6W9 3zvKcfSuVKP3GLgFldKd0Ef/fh2TRxoLjaDsk8sD4a993+4iZ9mAKuW783awGHt96mi7 Mcuw== 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=8v5xuPr2EJ9DSJyEgwYWHNaPW3NhmJIKXs9ahA/QI14=; b=X5fgHSCs5k5/QT6PVUu7QgY+zojG63FcI46Q9mjw1sxUw4gx7tDXFmVGhzfktuEA+R ubwZ4rjk3zXOMdY6IzT5IB5n3OUZCpYwaMnNQzDA6WqH91tsLK05mgwQYodguAn4hrY/ ELrUa2/SKx7Efs1fSAwYE7PoKYMB9Fc6Y/RMnFHNQjyaFLd+hbuGTZUoQEZ5HE39svrt PONxxjB4TJzufT1czlhKzIAaKB11XAM6S1yuK8UD/iQ2If2kbJKbEpbiRMPAc72HwjX+ VowDG53bVmJP71441qSjs2UVTUMwiQLsCshmDu05LBJaKgfMjUI04nSB72Wadz+OaPzC czUA== X-Gm-Message-State: APjAAAU4pizzEORGI5flAqba9Uo9eJNdtFX/I2ef1kAitFqTjzepoTf8 0Y2cJBIjyiowSp55oMXE/f/DjQ== X-Google-Smtp-Source: APXvYqy2psF+SHAkdnmFnQHEnt8nfdz54W8h3uR+uQcrYtNUivkQ5xNld+aRPQg4nCP0yfXDA3vZcA== X-Received: by 2002:a2e:b1c3:: with SMTP id e3mr38270940lja.137.1577717060097; Mon, 30 Dec 2019 06:44:20 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:19 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 07/15] cpuidle: psci: Support hierarchical CPU idle states Date: Mon, 30 Dec 2019 15:43:54 +0100 Message-Id: <20191230144402.30195-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 761359be50f2..830995b8a56f 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -86,8 +86,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, return -ENOMEM; for (i = 1; i < state_count; i++) { - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - i - 1); + state_node = of_get_cpu_state_node(cpu_node, i - 1); if (!state_node) break; From patchwork Mon Dec 30 14:43:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313181 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 7EA1B13A4 for ; Mon, 30 Dec 2019 14:44:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C73B2071E for ; Mon, 30 Dec 2019 14:44:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CY8w9n0q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727551AbfL3OoY (ORCPT ); Mon, 30 Dec 2019 09:44:24 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39664 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfL3OoX (ORCPT ); Mon, 30 Dec 2019 09:44:23 -0500 Received: by mail-lj1-f196.google.com with SMTP id l2so33504792lja.6 for ; Mon, 30 Dec 2019 06:44:22 -0800 (PST) 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=neea4kQTvG+Bpgec4NpbRFMjAla+zHuzZZgjs6GRGkc=; b=CY8w9n0qANi3pwpse5njlfUuAXhBW7I2P8v6T8Momocn6zaJyS9eUNpXR6rklTo6dg sq+oD3qSYMqB0wdHlDpE3jkyYaDDnJHCkfrXPBz1GfhmtlV7apr9LScWjde4LbAIiZx0 RLOWOqpMSJiQcd3lmVt5H67wYDzWg+AdVC9P1T20yfcXI8ABlEREGNiOd4yO4jG7QCUI bkADMMLprTLR0eR+X7OmdFXwjGSeYM0Ngk65Ev77A+7MtvMrv27NP0obM/n5DvFCWGYy 5z7X2a5X9oYhJZ3SAkZHCYhKtbgKBoaNCtXSM71AdSInmuszfBFuZrl7vxgoyZ5wjZ4m 6I+g== 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=neea4kQTvG+Bpgec4NpbRFMjAla+zHuzZZgjs6GRGkc=; b=elCzye4y6uI0VhoY/JVshApFhPJ2gUX4j2M8IszTUdseklI3BmSQGbrc1YhrLVgP4P c4GxhNlD1lD4wkuG17dpwDlgydEqsQEHQ+PdXMRSg/WdyACmtSoOxfFG8QQI16cYRMuR sMdNURDYUpawqH7+6RsX8lVaYMd1F3MxOq2112j/EAWFUbp7jap0RNdveYhHRWR4l9Lg Em86fInKRgxRdQPWN+vdlX84QtLeUqrwPsYnqtnLVqF8FpV9Z5E6FSv5KoMTE5u0yygb T7el9nZ57U/SPEFt1hZ+116l768vjuBqB2mr2EEmOJn311hiCuetjdyiKLZNamy5LSxS vo1w== X-Gm-Message-State: APjAAAVUv7JXr5ClW3X1a5x7ej6il/zs/htMHmpZ4uCyMumoWOPtHmXZ S1sAwihBvixoNtU7l65mmPo5Ag== X-Google-Smtp-Source: APXvYqz4pHdrSZYvR9LPkn6aBxofeWRY+5WpuR/T2iFRqr3dH9alwMysRzcX9iPHqQj6c18Apu+KPg== X-Received: by 2002:a2e:93d5:: with SMTP id p21mr40357019ljh.50.1577717061929; Mon, 30 Dec 2019 06:44:21 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:21 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 08/15] cpuidle: psci: Add a helper to attach a CPU to its PM domain Date: Mon, 30 Dec 2019 15:43:55 +0100 Message-Id: <20191230144402.30195-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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. Note that, the implementation of the new helper function is in a new separate c-file, which may seems a bit too much at this point. However, subsequent changes that implements the remaining part of the PM domain support for cpuidle-psci, helps to justify this split. Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v5: - Declare psci_dt_attach_cpu() as __init. --- drivers/cpuidle/Makefile | 4 +++- drivers/cpuidle/cpuidle-psci-domain.c | 31 +++++++++++++++++++++++++++ drivers/cpuidle/cpuidle-psci.h | 12 +++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 drivers/cpuidle/cpuidle-psci-domain.c create mode 100644 drivers/cpuidle/cpuidle-psci.h 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..87f881c21af1 --- /dev/null +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PM domains for CPUs via genpd - managed by cpuidle-psci. + * + * Copyright (C) 2019 Linaro Ltd. + * Author: Ulf Hansson + * + */ + +#include +#include +#include +#include +#include + +#include "cpuidle-psci.h" + +struct device __init *psci_dt_attach_cpu(int cpu) +{ + struct device *dev; + + 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 new file mode 100644 index 000000000000..8609482cf490 --- /dev/null +++ b/drivers/cpuidle/cpuidle-psci.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __CPUIDLE_PSCI_H +#define __CPUIDLE_PSCI_H + +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF +struct device __init *psci_dt_attach_cpu(int cpu); +#else +static inline struct device __init *psci_dt_attach_cpu(int cpu) { return NULL; } +#endif + +#endif /* __CPUIDLE_PSCI_H */ From patchwork Mon Dec 30 14:43:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313187 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 D8A5113A4 for ; Mon, 30 Dec 2019 14:44:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6C84222C4 for ; Mon, 30 Dec 2019 14:44:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xKKUKeIO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727607AbfL3Oo0 (ORCPT ); Mon, 30 Dec 2019 09:44:26 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:40845 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfL3Oo0 (ORCPT ); Mon, 30 Dec 2019 09:44:26 -0500 Received: by mail-lj1-f196.google.com with SMTP id u1so33494573ljk.7 for ; Mon, 30 Dec 2019 06:44:24 -0800 (PST) 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=F62eMHvAlv7nF3GieiDqKuJt4z4o+7t76tdVx5DtOc8=; b=xKKUKeIOyuo2s2W+neuN/sbW173fQNrou3tC+j6v7Ko/GuV217MXietDZKhjA3Uskq +oGLDtucefGKWLnVAkdy0EhggOa4EVlAW3GgnRf3Q///TpMXhcvS47NgjBgaWEZcvHEa sNPyCIaZTNdpqI7KOnRBwON5a3hrpogrN9d9Ws+HKMrAubG/J+RRvvjmiuXp2X5RAeLx 6xSd9DNxkiJYPcmnO5P1a2Ljaf0kWX0Uv0AmAJhO8VjFrwyPTyVlJYM0h5cT5tIv0xYm DOGryt9AIk3n2s3w+VoyOqVcAFEb685q0iz4QCXHyot3S9+MEpZiMmxb1W2IxQea5VsV oLOg== 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=F62eMHvAlv7nF3GieiDqKuJt4z4o+7t76tdVx5DtOc8=; b=Z7Ma9saOIJ3rRBa8yPS1/dUQDNMYLVKod4RJmrDZKHhLrTSmrvVeYpC9+R3W/VH4s8 nUpP3PlKlOkZ5ROcDZmi5XyMMxQiZtCf9Gy46oiDPakMiJgEP/889n9Zr5Z3R3aYIYAb O6kVd0QGcfeeX9IVdofDfXIKhIK25JAbi7LcFzvEpHvZD+zXKHIAlhvgzYVYQXV2kABU 5onBEn6G0hDUBU2RD51cpTDEXxVcpihNrLvswj05RVCFTYMyM38msip3PHR62s35K+y5 23NTwOs/LJQDh49DBuGVQTxlVEMUWSkYQdxYoQsJYGUR1IG8Z8mVtfoWvAO+ZvmIbr1r wl1A== X-Gm-Message-State: APjAAAUsSqLTeFhTyWIDuESHp1qVwdgtaTgQyEMlpm6fW6eArqKhk/YW 8fFK3SNX9au/I8RJgR8Ki4n9YA== X-Google-Smtp-Source: APXvYqx5ku6KI9MfPdQZ+SWjpmvOotL42D1PWyIwc9k7LE5GzctpSfHSXBO4s15SrZ/WJeAsBlX0Ug== X-Received: by 2002:a2e:8e22:: with SMTP id r2mr32224867ljk.51.1577717063226; Mon, 30 Dec 2019 06:44:23 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:22 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 09/15] cpuidle: psci: Attach CPU devices to their PM domains Date: Mon, 30 Dec 2019 15:43:56 +0100 Message-Id: <20191230144402.30195-10-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 Reviewed-by: Sudeep Holla --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 830995b8a56f..6a87848be3c3 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -20,14 +20,20 @@ #include +#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 int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { - u32 *state = __this_cpu_read(psci_power_state); + u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state[idx]); @@ -79,6 +85,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int i, ret = 0; u32 *psci_states; struct device_node *state_node; + struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); state_count++; /* Add WFI state too */ psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL); @@ -104,8 +111,17 @@ 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; + /* Currently limit the hierarchical topology to be used in OSI mode. */ + if (psci_has_osi_support()) { + data->dev = psci_dt_attach_cpu(cpu); + if (IS_ERR(data->dev)) { + ret = PTR_ERR(data->dev); + goto free_mem; + } + } + + /* Idle states parsed correctly, store them in the per-cpu struct. */ + data->psci_states = psci_states; return 0; free_mem: From patchwork Mon Dec 30 14:43:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313189 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 ED04513A4 for ; Mon, 30 Dec 2019 14:44:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C19DC2080A for ; Mon, 30 Dec 2019 14:44:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="k+dt5ccd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbfL3Oo1 (ORCPT ); Mon, 30 Dec 2019 09:44:27 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39673 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727609AbfL3Oo1 (ORCPT ); Mon, 30 Dec 2019 09:44:27 -0500 Received: by mail-lj1-f196.google.com with SMTP id l2so33504954lja.6 for ; Mon, 30 Dec 2019 06:44:25 -0800 (PST) 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=sZefleScox1nm0+WYdQ3BBhBjbSL9pi9Q8gxjnjPNiI=; b=k+dt5ccdM3owzCTK74XbbbsHMqeeevmQDr+sXGOzZz/nvx6U4OyDozmpHNQUhuaKRe vRVVXwZjnYNFQ3TNWlJlAuJo7RQgfXlH+c2rsmGReY5lw4rMtjSN9RbIU2iPKUIKMXyg Am/JZdq9S2seigcx0WOPNH7heKDq3ujz9N9afSvlxLivAVB8SSuDmeC85/GDTrf0eWTI MbAXC7Vog/fdCvT99X/JoC1IfKYVLgJhYzLT+sqGCpwsXms2XobgUMwP++a5glp3poQn QKLTJHgyhyGIxD+zCfo0yHfKFCRR/77wPTYWkxwowB4AYOhFPIPJF/EesW3EJqk6QpFF lboQ== 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=sZefleScox1nm0+WYdQ3BBhBjbSL9pi9Q8gxjnjPNiI=; b=b14X0HbJRuG7U1a6lUWoXJ9Sg1NHrn2RlANhueTwuixsuqirD5JbqXKNwTuX0oM5T1 Z1LaJFVqKGA9gpmDkWyiZCH+1Xa9PreUrzRytYYPdl4Pq/ELO/L451hiPE2YqW2um1w6 dxr1UGWUMiC4xriDDzba+zsqHXUdCz9zAcDaYWWPuZ6k6mXQnIC7hvqIEGJB3jwOfjDa JjesRPOuiFk/ovUNyzknOz9VGKrgbvxno311HPOmBovJ8oWZJFTOi13SspghnQu12iNL U7XdqUjxqig29+XnDGzrrnnvDH993/vBaHZaGGDYZcQLhuIk3dhDfKdiPkKoArdOUbx8 RPnA== X-Gm-Message-State: APjAAAWl1V7JtTxLDefag7AyRolkyVs+vakZKMI/Egdw029aB0yocf+0 8e0iZSDaZpFbvv5CA6w3k8R8wg== X-Google-Smtp-Source: APXvYqxJiXnez81BgsM8+ozNoti4VBDX7b1Vf0pT/sSFBdtMD2BiZFUGesyFglHR4O41EPd4kYP/DA== X-Received: by 2002:a2e:80d9:: with SMTP id r25mr39573873ljg.8.1577717064736; Mon, 30 Dec 2019 06:44:24 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:24 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v5 10/15] cpuidle: psci: Prepare to use OS initiated suspend mode via PM domains Date: Mon, 30 Dec 2019 15:43:57 +0100 Message-Id: <20191230144402.30195-11-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 entering and idle state. To avoid executing the above OSI specific code in the ->enter() callback, while operating in the default PSCI Platform Coordinated mode, let's also add a new enter-function and use it for OSI. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 56 ++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 6a87848be3c3..9600fe674a89 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -29,14 +29,47 @@ struct psci_cpuidle_data { }; static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); +static DEFINE_PER_CPU(u32, domain_state); + +static inline 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 inline int psci_enter_state(int idx, u32 state) +{ + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); +} + +static int psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx) +{ + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); + u32 *states = data->psci_states; + u32 state = psci_get_domain_state(); + int ret; + + if (!state) + state = states[idx]; + + ret = psci_enter_state(idx, state); + + /* Clear the domain state to start fresh when back from idle. */ + psci_set_domain_state(0); + return ret; +} static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, - idx, state[idx]); + return psci_enter_state(idx, state[idx]); } static struct cpuidle_driver psci_idle_driver __initdata = { @@ -79,7 +112,8 @@ 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, +static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, + struct device_node *cpu_node, unsigned int state_count, int cpu) { int i, ret = 0; @@ -118,6 +152,15 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, ret = PTR_ERR(data->dev); goto free_mem; } + + /* + * Using the deepest state for the CPU to trigger a potential + * selection of a shared state for the domain, assumes the + * domain states are all deeper states. + */ + if (data->dev) + drv->states[state_count - 1].enter = + psci_enter_domain_idle_state; } /* Idle states parsed correctly, store them in the per-cpu struct. */ @@ -129,7 +172,8 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, return ret; } -static __init int psci_cpu_init_idle(unsigned int cpu, unsigned int state_count) +static __init int psci_cpu_init_idle(struct cpuidle_driver *drv, + unsigned int cpu, unsigned int state_count) { struct device_node *cpu_node; int ret; @@ -145,7 +189,7 @@ static __init int psci_cpu_init_idle(unsigned int cpu, unsigned int state_count) if (!cpu_node) return -ENODEV; - ret = psci_dt_cpu_init_idle(cpu_node, state_count, cpu); + ret = psci_dt_cpu_init_idle(drv, cpu_node, state_count, cpu); of_node_put(cpu_node); @@ -201,7 +245,7 @@ static int __init psci_idle_init_cpu(int cpu) /* * Initialize PSCI idle states. */ - ret = psci_cpu_init_idle(cpu, ret); + ret = psci_cpu_init_idle(drv, cpu, ret); if (ret) { pr_err("CPU %d failed to PSCI idle\n", cpu); goto out_kfree_drv; From patchwork Mon Dec 30 14:43:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313193 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 D448D109A for ; Mon, 30 Dec 2019 14:44:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B17E820722 for ; Mon, 30 Dec 2019 14:44:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JCpPFKZu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbfL3Oo2 (ORCPT ); Mon, 30 Dec 2019 09:44:28 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:35526 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727611AbfL3Oo2 (ORCPT ); Mon, 30 Dec 2019 09:44:28 -0500 Received: by mail-lj1-f196.google.com with SMTP id j1so26137476lja.2 for ; Mon, 30 Dec 2019 06:44:26 -0800 (PST) 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=KzTTqj8p23Akt27Kd2Hs4c3lg6YLbPXs3ATs0EVFR2M=; b=JCpPFKZuzoDLpUkDOuKcE6t8dYafbfR22Clus44/n9Hef4fPXDwh1TRjb+z065rvDg o/viC2PDowY6Nd/qjdwLbcafGiUjQEFMxLU6yqRKI8wPY10/9rarX+BejUdqBkbDm9vd 9Z9n5/eM+fkJVT5R5Vs/Dr7pRB35rJUaDClIXV9Z+UrVQ94QdsySErw4oBeFMtYlFd5L tOxKqgfFBSF+ojOLNFP8YRMHr8AIQ2jAmYy+8sa7jcSo3mkI1ZZ596uUE56pv1SOGxM5 lWD6v8tteSg8CojtKOusDP2q7wvntfRbAU4K2tC50TgVk4h7PGpP/FbUnVvDzNIXkm7h Qpow== 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=KzTTqj8p23Akt27Kd2Hs4c3lg6YLbPXs3ATs0EVFR2M=; b=HGgtfAalAQJuakvMJnnAbVPdO51pqPZ3CQ3zx7yGvUm5Wi0fJstctgqwKsPngAsj+j 8m93q/CZfH0HpKtAtFr4NnQktcHyYzMISGl7mz2kTVatpDdyDdW1evtPV6e/ucD3ujqg 4brKLD8JDnjFdxoqZ+D9IryDib7sJNoR2IIRGJUaCsTZJd/pCJEgf6DnfEVtiIIg5zQ6 YuuGlkzO+wiT94TMP8c+PmFHvVGhd9okzEQwYaWmJF6ulX6n/eA94rqCUVPr3SQcbefH qqrmoPWrDnVYDSqxI/gj9L6oUviOsA3s9RnuYESYywGM67qy8F01W5M9379/azn9nd3d LYtQ== X-Gm-Message-State: APjAAAXNIzrej+C2/pXSLgan5biWAXXwDfaZR4IoyqehjAa8EZagQ/Ar +nPNbUlHNh/F3JhI27SgIUR2FA== X-Google-Smtp-Source: APXvYqzGA3gtYNDs67k65CEee1AiLGVULQ9UOPYgswEyii5PPQ7+p9U9ijvBI9aT4vNl0v8Jdj0WmQ== X-Received: by 2002:a2e:a402:: with SMTP id p2mr39436965ljn.143.1577717066026; Mon, 30 Dec 2019 06:44:26 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:25 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 11/15] cpuidle: psci: Manage runtime PM in the idle path Date: Mon, 30 Dec 2019 15:43:58 +0100 Message-Id: <20191230144402.30195-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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. The triggering point for when runtime PM reference counting should be done, has been selected to the deepest idle state for the CPU. However, 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 Reviewed-by: Sudeep Holla --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 9600fe674a89..6e7804e697ed 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -51,14 +52,21 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, { struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); u32 *states = data->psci_states; - u32 state = psci_get_domain_state(); + struct device *pd_dev = data->dev; + u32 state; int ret; + /* Do runtime PM to manage a hierarchical CPU toplogy. */ + pm_runtime_put_sync_suspend(pd_dev); + + state = psci_get_domain_state(); if (!state) state = states[idx]; ret = psci_enter_state(idx, state); + pm_runtime_get_sync(pd_dev); + /* Clear the domain state to start fresh when back from idle. */ psci_set_domain_state(0); return ret; From patchwork Mon Dec 30 14:43:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313199 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 F1556109A for ; Mon, 30 Dec 2019 14:44:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D03D62071E for ; Mon, 30 Dec 2019 14:44:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cZDkTeTB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727618AbfL3Ooa (ORCPT ); Mon, 30 Dec 2019 09:44:30 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:46147 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727577AbfL3Ooa (ORCPT ); Mon, 30 Dec 2019 09:44:30 -0500 Received: by mail-lj1-f196.google.com with SMTP id m26so31068521ljc.13 for ; Mon, 30 Dec 2019 06:44:28 -0800 (PST) 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=iP0q67cVa7joTIBbxM/rB2PXgLYhwll7Ud0Qeuw7uE4=; b=cZDkTeTBaAAlRRZrP1XLtXSbuzbscAVY8zmWFyVTHUO5xJzFNqhSGbfNaVWsCH1AuX 4rT40nwkm1sYOV87tQsTVNYOpKm/XQgnTfubKy97NWJGHyYGyJ+cykHyuBuzwg1e4vI+ dP2uBSyDD85o+XaR8nCem4voDrHfRNDwol6CbGAaupD5x1CDQNr/ejTTClgbNp+xnOmR 2Bybqk0ajXhcvXbxyM51KKuqO7Pq9KUok4Z20H1s3n3ChONQsVe8t0SEdohf+xd9LlR9 TwQyqLl/Nqa3iyclS4fQCNrW5jt9RzhUB79qF7nkaemxrQzWOlFc+6vmMc74MtPky/iM eUnQ== 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=iP0q67cVa7joTIBbxM/rB2PXgLYhwll7Ud0Qeuw7uE4=; b=EkHWtCLdHI8Q6SJOpTIdYEuAu0SPiHUBIOO5ojEXzO6ok+CRugG4WSmC31+uGRofTc y+I5R8Di2X+EOy23wxq9GSj/xbL+6v4z4U4IvLJnrlTLAZG10MBQPTk0/byAz8iIcD5E dHsE/YAq1sOHpX67yOYmaG0usekqleSMu+vroQy+rZpSOkCnUbiS2+Zxoo59CIQGddrx YDj++Ftjm7sGjiHLIHMlr2l1Dc8w5YyGt6RR+jymvLaRy/e32SCvDn77GYFG9t30v9mI w7bT60jU/0SHULpbICDo4A/XwHVsC6+4NXtyYC4Pd9pyIseoaGiiNAM4j6P0s/8Dw+eK snXQ== X-Gm-Message-State: APjAAAXxlfIMrmgaOZP0rt5bJ0rpUo8+HU5fzhm6PAn8+Iykf1znYP1+ S7DxwQD7kjmZGaZ7bhYoM8xoOg== X-Google-Smtp-Source: APXvYqzBs/tiWnncxKxVYy6elFVnD48Lxju0cyn1aR3gEPXIkZtrCY33Ut1F1NTu0L4H0jjmnQTcwg== X-Received: by 2002:a2e:8090:: with SMTP id i16mr39630757ljg.88.1577717067493; Mon, 30 Dec 2019 06:44:27 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:26 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 12/15] cpuidle: psci: Support CPU hotplug for the hierarchical model Date: Mon, 30 Dec 2019 15:43:59 +0100 Message-Id: <20191230144402.30195-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 is used and when a CPU is put offline, that CPU prevents its PM domain from being powered off, which is because genpd observes the corresponding attached device as being active from a runtime PM point of view. Furthermore, any potential master PM domains are also prevented from being powered off. To address this limitation, let's add add a new CPU hotplug state (CPUHP_AP_CPU_PM_STARTING) and register up/down callbacks for it, which allows us to deal with runtime PM accordingly. Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v5: - Make CPUHP function/variable initdata. --- drivers/cpuidle/cpuidle-psci.c | 45 +++++++++++++++++++++++++++++++++- include/linux/cpuhotplug.h | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 6e7804e697ed..9d779be27071 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "CPUidle PSCI: " fmt +#include #include #include #include @@ -31,6 +32,7 @@ struct psci_cpuidle_data { static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); +static bool psci_cpuidle_use_cpuhp __initdata; static inline void psci_set_domain_state(u32 state) { @@ -72,6 +74,44 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return ret; } +static int psci_idle_cpuhp_up(unsigned int cpu) +{ + struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); + + if (pd_dev) + pm_runtime_get_sync(pd_dev); + + return 0; +} + +static int psci_idle_cpuhp_down(unsigned int cpu) +{ + struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); + + if (pd_dev) { + pm_runtime_put_sync(pd_dev); + /* Clear domain state to start fresh at next online. */ + psci_set_domain_state(0); + } + + return 0; +} + +static void __init psci_idle_init_cpuhp(void) +{ + int err; + + if (!psci_cpuidle_use_cpuhp) + return; + + err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING, + "cpuidle/psci:online", + psci_idle_cpuhp_up, + psci_idle_cpuhp_down); + if (err) + pr_warn("Failed %d while setup cpuhp state\n", err); +} + static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { @@ -166,9 +206,11 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, * selection of a shared state for the domain, assumes the * domain states are all deeper states. */ - if (data->dev) + if (data->dev) { drv->states[state_count - 1].enter = psci_enter_domain_idle_state; + psci_cpuidle_use_cpuhp = true; + } } /* Idle states parsed correctly, store them in the per-cpu struct. */ @@ -289,6 +331,7 @@ static int __init psci_idle_init(void) goto out_fail; } + psci_idle_init_cpuhp(); return 0; out_fail: diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index e51ee772b9f5..01f04ed6ad92 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -95,6 +95,7 @@ enum cpuhp_state { CPUHP_AP_OFFLINE, CPUHP_AP_SCHED_STARTING, CPUHP_AP_RCUTREE_DYING, + CPUHP_AP_CPU_PM_STARTING, CPUHP_AP_IRQ_GIC_STARTING, CPUHP_AP_IRQ_HIP04_STARTING, CPUHP_AP_IRQ_ARMADA_XP_STARTING, From patchwork Mon Dec 30 14:44:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313205 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 6ACE213A4 for ; Mon, 30 Dec 2019 14:44:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49EFC20722 for ; Mon, 30 Dec 2019 14:44:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="TZ7puyOx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727627AbfL3Oob (ORCPT ); Mon, 30 Dec 2019 09:44:31 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:43675 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727617AbfL3Oob (ORCPT ); Mon, 30 Dec 2019 09:44:31 -0500 Received: by mail-lj1-f196.google.com with SMTP id a13so33510162ljm.10 for ; Mon, 30 Dec 2019 06:44:29 -0800 (PST) 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=+SgAM3h033e/MLAOZ0d/dorO2oxTfoGPJAEbgrUK1sA=; b=TZ7puyOxM+yGMbc3OGs6XvJX2K3hv/kDgeQIRnULYOGBMEJf7MAYGjYEzFkRBHtmQq IPa0AzJ36KUXkdzKzwmlplSKsccO970rx5ZZ3m9v+Upw5gJBovxtKLmxzrx/oYtAF/6J D5OXvUSkffHvEGQQ77aW9k1QG8eGDi3q1Z9xZH7gNWN4Xo/Bk1SqhvBHZ+HySpzZN2Hh jvljaarakC0NGmGNMx/Of1925O2nOinjCd93Ysjf4/e5zhvKfsHScC7nur/jO5RHXC6X Fz2b4o+zUWUZR4UhN6WTDZvrWliv8ykVC5+1UMsGrQqKV6Yf8KbR8laDQKfoDH4ozQ44 HCNA== 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=+SgAM3h033e/MLAOZ0d/dorO2oxTfoGPJAEbgrUK1sA=; b=gSfQQ5RIAeiCCTQT7mSOnCfxG//bogovBCbLyWVlzF++C8RyBWBxjStPsWTocy+7ji MCsez5aKk6oEgOnP85WmIsuSW7FeSBXbesdXGqBwlP6PSulgP7Kymx/HKHb0uBWCOSSH cznmPss+sd+xbjAxl+pkw3hz4BLzP42i9AVsoGZdNVYkpPoKMUs2n80lRdkqSDGR3BXj gALFQzhbqVW/UAeLaxpodNND3Pgb+k40aA8btzUOAPTxVggsRPVUoqmrwxcE3+lgSC8Z fCYKm1hbcwsuwfIpy9XrGdtUzuIWtKa/B7ahBTDJ/u/PJWN02KpWq8iPT/6WDP7Nfxvl d9yg== X-Gm-Message-State: APjAAAWZ8uSiWZLyfAaHLcL02V6m4l1SMx58zo04Ny1K7e+bIDJruY2Y qri60ejpemXnitsi03sltRfHdg== X-Google-Smtp-Source: APXvYqwtFgk8DWwJIi01w0yOiYq/bVEMrpa/+7NeIkZiIuoO5wszwt+ezEkxoN7XmPdMpQ4zt6kx3g== X-Received: by 2002:a05:651c:1077:: with SMTP id y23mr38549803ljm.79.1577717069205; Mon, 30 Dec 2019 06:44:29 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:28 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 13/15] PM / Domains: Introduce a genpd OF helper that removes a subdomain Date: Mon, 30 Dec 2019 15:44:00 +0100 Message-Id: <20191230144402.30195-14-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 We already have the of_genpd_add_subdomain() helper, but no corresponding of_genpd_remove_subdomain(), so let's add it. Subsequent changes starts to make use of it. Signed-off-by: Ulf Hansson --- Changes in v5: - New patch. --- drivers/base/power/domain.c | 38 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 8 ++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 8e5725b11ee8..959d6d5eb000 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2302,6 +2302,44 @@ int of_genpd_add_subdomain(struct of_phandle_args *parent_spec, } EXPORT_SYMBOL_GPL(of_genpd_add_subdomain); +/** + * of_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. + * @parent_spec: OF phandle args to use for parent PM domain look-up + * @subdomain_spec: OF phandle args to use for subdomain look-up + * + * Looks-up a parent PM domain and subdomain based upon phandle args + * provided and removes the subdomain from the parent PM domain. Returns a + * negative error code on failure. + */ +int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec, + struct of_phandle_args *subdomain_spec) +{ + struct generic_pm_domain *parent, *subdomain; + int ret; + + mutex_lock(&gpd_list_lock); + + parent = genpd_get_from_provider(parent_spec); + if (IS_ERR(parent)) { + ret = PTR_ERR(parent); + goto out; + } + + subdomain = genpd_get_from_provider(subdomain_spec); + if (IS_ERR(subdomain)) { + ret = PTR_ERR(subdomain); + goto out; + } + + ret = pm_genpd_remove_subdomain(parent, subdomain); + +out: + mutex_unlock(&gpd_list_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(of_genpd_remove_subdomain); + /** * of_genpd_remove_last - Remove the last PM domain registered for a provider * @provider: Pointer to device structure associated with provider diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 5a31c711b896..9ec78ee53652 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -284,6 +284,8 @@ void of_genpd_del_provider(struct device_node *np); int of_genpd_add_device(struct of_phandle_args *args, struct device *dev); int of_genpd_add_subdomain(struct of_phandle_args *parent_spec, struct of_phandle_args *subdomain_spec); +int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec, + struct of_phandle_args *subdomain_spec); struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n); @@ -322,6 +324,12 @@ static inline int of_genpd_add_subdomain(struct of_phandle_args *parent_spec, return -ENODEV; } +static inline int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec, + struct of_phandle_args *subdomain_spec) +{ + return -ENODEV; +} + static inline int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n) { From patchwork Mon Dec 30 14:44:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313207 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 3701413A4 for ; Mon, 30 Dec 2019 14:44:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0AC9F20663 for ; Mon, 30 Dec 2019 14:44:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bq8UOsEy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727617AbfL3Ood (ORCPT ); Mon, 30 Dec 2019 09:44:33 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33863 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfL3Ood (ORCPT ); Mon, 30 Dec 2019 09:44:33 -0500 Received: by mail-lj1-f195.google.com with SMTP id z22so28698421ljg.1 for ; Mon, 30 Dec 2019 06:44:31 -0800 (PST) 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=JE02hg+B/QTwsutbOnDGGVXBmAWIdmulkW5XXOokyFg=; b=bq8UOsEy5KNKYrvHMWGaqWZ68Sfn+QSB+7EMXo87GY8qcpokHDVGNL0g8LQzlG3TUa iHq7wMHzM6xfxl4g+CUFhuroSyZ8D5ATOOQKNyJ1ZiUpCKnK6+HlAYgKIIyJ3/lCwWZD WKyyJSQ1KVtS9oQvWMWmf5PoWKI72gVd0qy/TaEkLKlULWCVBJd2+t9icgFEXhqDE/tY U/MwKlZQQEwBChSqnsXI4vnGBYF1Fy8nh2lvAkNq20IVEVQ4wiBsVq5WuoW5b5NqrhsL l1VZQVJsMazw72SdH2MOTb1veYU09g/Cnln4kWtP2LIlg5Hf/1Z5+r1Jk1d5dillWCgg vXyA== 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=JE02hg+B/QTwsutbOnDGGVXBmAWIdmulkW5XXOokyFg=; b=kJnvE3HipkyaS0xf3JSp6NCc6VCB3oYEeh2rIaME+zHZiX10QdWiS15P7plztWVzcn JP1Fzz8TQ5hRr0R9H9iPYAllkfl01EAH7EQwmsYD/2miPLjeEnsv4EJhivKziHNsp2xF Q1qSPiqfB2aTs7mvQehQUOdyJX7qd8InpGtq7Um8iD2BWxBQ3M4gz7BdaRmbkugM8UZ9 dS4bjDXlX4wOKu6SpWsdYSKQOA1mKmG/FXgSDJuPWaiXHCo74Zj9C6cEyO92qxjFXmxy e3ff3SlIQwgOaDg/toOy0LoqPOSVcwwZkQzRvyrC/yeJswd29NQxeP5BT7iG6Vl7R4jC 9swg== X-Gm-Message-State: APjAAAWKoD819weN99wX9vrRRNRvUSbJBBw1ssWSEwmrbagmlGZkWc64 okj/UNKfTo8Tz5lEb3Hq045T4Q== X-Google-Smtp-Source: APXvYqxlZUOpxfdTpvoCwyEmOCNS8buNKqm5CxY2aI9/cFZSf6+MMktwDWVj+F4tZG5LbvzgPyNSAA== X-Received: by 2002:a05:651c:1b3:: with SMTP id c19mr34481451ljn.115.1577717070811; Mon, 30 Dec 2019 06:44:30 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:30 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v5 14/15] cpuidle: psci: Add support for PM domains by using genpd Date: Mon, 30 Dec 2019 15:44:01 +0100 Message-Id: <20191230144402.30195-15-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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 let's use a subsys_initcall, 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 a 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 error codes. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v5: - Remove genpds in the error path, when enabling OSI failed. - Let psci_dt_attach_cpu() return NULL if OSI mode isn't enabled. - Make the osi_mode_enabled variable __initdata. - Drop some DT compatible strings, as PSCI v1.0 introduces OSI. --- drivers/cpuidle/cpuidle-psci-domain.c | 277 ++++++++++++++++++++++++++ drivers/cpuidle/cpuidle-psci.c | 4 +- drivers/cpuidle/cpuidle-psci.h | 5 + 3 files changed, 284 insertions(+), 2 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index 87f881c21af1..423f03bbeb74 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -7,18 +7,295 @@ * */ +#define pr_fmt(fmt) "CPUidle PSCI: " fmt + #include #include #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 __initdata; + +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 (!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, bool add) +{ + 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 = add ? of_genpd_add_subdomain(&parent, &child) : + of_genpd_remove_subdomain(&parent, &child); + of_node_put(parent.np); + if (ret) { + of_node_put(node); + return ret; + } + } + + return 0; +} + +static int __init psci_pd_add_topology(struct device_node *np) +{ + return psci_pd_init_topology(np, true); +} + +static void __init psci_pd_remove_topology(struct device_node *np) +{ + psci_pd_init_topology(np, false); +} + +static const struct of_device_id psci_of_match[] __initconst = { + { .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_add_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); + psci_pd_remove_topology(np); + goto remove_pd; + } + + 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); + struct device __init *psci_dt_attach_cpu(int cpu) { struct device *dev; + if (!osi_mode_enabled) + return NULL; + dev = dev_pm_domain_attach_by_name(get_cpu_device(cpu), "psci"); if (IS_ERR_OR_NULL(dev)) return dev; diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 9d779be27071..edd7a54ef0d3 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -34,7 +34,7 @@ static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); static bool psci_cpuidle_use_cpuhp __initdata; -static inline void psci_set_domain_state(u32 state) +void psci_set_domain_state(u32 state) { __this_cpu_write(domain_state, state); } @@ -143,7 +143,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 index 8609482cf490..7299a04dd467 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -3,6 +3,11 @@ #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); + #ifdef CONFIG_PM_GENERIC_DOMAINS_OF struct device __init *psci_dt_attach_cpu(int cpu); #else From patchwork Mon Dec 30 14:44:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11313213 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 CB23A109A for ; Mon, 30 Dec 2019 14:44:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A937B20722 for ; Mon, 30 Dec 2019 14:44:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s5zzc4Lz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727615AbfL3Oof (ORCPT ); Mon, 30 Dec 2019 09:44:35 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37953 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727630AbfL3Oof (ORCPT ); Mon, 30 Dec 2019 09:44:35 -0500 Received: by mail-lj1-f194.google.com with SMTP id w1so11532472ljh.5 for ; Mon, 30 Dec 2019 06:44:33 -0800 (PST) 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=pFHyotJ6IeS0NnPGUwSrCQs8d27XE2yrJ5nxr3VtYic=; b=s5zzc4Lzvw9BL4eBPMqCkzI1609Ctjtx+HMMegsZzrLbvJR3PQGlrle85pbQIAjvQv spD0gMVv3McQxNFa9n7sHSB0CtaQvF20UZS6K5kWhrw/1n0QclJEHvtiB5eSVvJ3yfWG lTg1kc+5OHIy3eladTvA82JxUYopI+/UzQCz8HJiivLaVAl3CPevey+/gcyxcbXuu4lo Ae882oP6a3qVoJHFFKttCYL4xHchd0e9DRbh+BmiqVAJGnXrXoajVof6Mep88AChD8nP bMhjSjVl8YnbU5WlaYGRh8onvQMHN7Gi3m37K1wv4IZidNEBKaAgQzZaK9dNoDXCyQtA EXtw== 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=pFHyotJ6IeS0NnPGUwSrCQs8d27XE2yrJ5nxr3VtYic=; b=GpdXRvLTFwhFq8BMwK541U92FPclUTFzvv+KoZBpDJOnH7Aoslo0eBi+SmJsBuSOPH CQ0SJ2Mpx3i8Bp+ZWR+Kp6Z+zfgJB8B2cGylxeGsP+1edyayeaTfr6WzSp/2MS65Ch/C v9l+aRMTTUQ404E0Xyj+WavFZAziLESDZBFCndgTIC/bZ4tmyYgDeIcmNy/r0XqnBbzP 9FfBkLNTkxYJQTru5eBATsTlzhzXgIh+k+kOfbXvOdbdaNon7pS5PotsLdhTOoe9QUEn zLCnenfvfmeO/lhVABx+4i9Lp4m2u24Xv1zQaPq3ysvi1nzKVMd0EndzFA+RbRO4dGFz s5zA== X-Gm-Message-State: APjAAAX1StyrpnGQq2GKRa9kJiLNG/Z+Z8L9HAyx4Izx4zQFVVI9nSGx BlkBiktSbV2Ka1PPmY/9n4zVaQ== X-Google-Smtp-Source: APXvYqxdwGv5e3gJirom9yUfoCDD87334k/2EA5omu7hFVl0AB/wYbg/vlbug4VqdBA+bheY1tQrbA== X-Received: by 2002:a2e:9a01:: with SMTP id o1mr37050340lji.247.1577717072600; Mon, 30 Dec 2019 06:44:32 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id a21sm18744931lfg.44.2019.12.30.06.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:32 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v5 15/15] arm64: dts: Convert to the hierarchical CPU topology layout for MSM8916 Date: Mon, 30 Dec 2019 15:44:02 +0100 Message-Id: <20191230144402.30195-16-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-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". Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v5: - None. --- 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 8686e101905c..282c36c8fa3b 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 {