From patchwork Thu Oct 10 11:39:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183201 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 E4EE376 for ; Thu, 10 Oct 2019 11:40:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8692208C3 for ; Thu, 10 Oct 2019 11:40:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Fbdfrndo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oY4GQ9ts" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8692208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=s9RypHNQPlIXDmUJHJUgIAlL98wOhuk4fa3o6WQmOEU=; b=Fbdfrndop1YwffUwAG0jteCprk 8oo1gjQs6pc/N440L64yFcs7WIWm56kuCqU6CHeS0ihVIq42NwOT6rzXLJ2IjGdSbqkZBLaQ3ds3L /0Hm8jx73kcJjGGIjQaRM5oKYEHP8QADdwDwfIEOKRs5/If79q5tGNAnTockYN9RwqyvorahvxoLH bU9Lt7SnuAc/s06SMTNXA11Y+jd6B46Ix7gbggzPVNY7n7h/s3zIQ5lj4FR31zZVBjTAIk+gG4CUe UKjXVQgEnnZUh4npNjklzFTahSnWf4CRAU49jF/0fkzyIweXCtBjXJupaPiDKkBdIWbXr8WBncEFP PNKQSbmw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnw-0002uY-I8; Thu, 10 Oct 2019 11:40:24 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWng-0002Fa-C9 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:09 +0000 Received: by mail-lj1-x242.google.com with SMTP id m13so5804744ljj.11 for ; Thu, 10 Oct 2019 04:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=oY4GQ9tspotLOINThxk9Kbs/w01ctme9MEPIEv5nplvQc0Gfk2yTpx63vcTwtFKh4B B+T2P47iK3kLvh+AM79Ow8hzpSL3BwO3bqbzE3b2EGXWMtodySrd61pw72AcbbCRFUpW afPqjSPD0x36xrozZ3piihjF4z1ppF7c8+sdn5Eb7tbNOIM4xve2bbcEhfKjKH3SEPiz mq2/6LaFi7GwljgIrb1NuH0pROuM4yrNj2ZjU5Ymvi8IEwKvRk9+do8bNp27z4n8h5v2 epXCe1vP/SQbHMt0CKqt4ltRSdU/ZufhVj++KFLUQjmpFA0FFee9QlnZH1Yo6uEaRSRm /omw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=F0g72QCs5kda79qbfOp/dWWSIeRuMcAnqKuE7F6QRLNM4kfc+kD6HyhA2Gu5zxZOFX LEJG0tP1E1Fm1teJuQ7phOcn+jv2norgKjHoXfZiTcGIxaMwuQia0/KhCuBWu7Fj8t3z mz+Frwuolp8xSnZql9Cj8Ol4lpwNVVI6BBpL/zCv74okgNFf6SV/tq/a2HwIZTE2RFNn s3gUJPtRtABDLTBbiBj1srVtjdbLRM3aEQnAJUk0+enzMrWIWuRzbwCH6mvfieeXQ3Sp iPNW4oO0Uz9V2F+v8kbY4yhYfbAC7+Tv8ecnWiwG7O5gphPkZVJCjlXkVVI2Y6WNZAwg kKTQ== X-Gm-Message-State: APjAAAXYXCTqBbIpMd32cht0qmpTZRhmoxKqytw0ahYoWRiImM+zl+io mKxbexyonlx4ZBJibz/0nA27Aw== X-Google-Smtp-Source: APXvYqyGsGrLPyBDtCxTyveMalXdmwovqTcGDOWg4fzfp/TkTS6GWys0i/Jm2jUOUYV/1uUVYs7SYg== X-Received: by 2002:a05:651c:105c:: with SMTP id x28mr6132302ljm.114.1570707605886; Thu, 10 Oct 2019 04:40:05 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:05 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 01/13] cpuidle: psci: Fix potential access to unmapped memory Date: Thu, 10 Oct 2019 13:39:25 +0200 Message-Id: <20191010113937.15962-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044008_433890_D00120AB X-CRM114-Status: GOOD ( 14.23 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When the WFI state have been selected, the in-parameter idx to psci_enter_idle_state() is zero. In this case, we must not index the state array as "state[idx - 1]", as it means accessing data outside the array. Fix the bug by pre-checking if idx is zero. Fixes: 9ffeb6d08c3a ("PSCI: cpuidle: Refactor CPU suspend power_state parameter handling") Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index f3c1a2396f98..2e91c8d6c211 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -27,10 +27,10 @@ static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { - u32 *state = __this_cpu_read(psci_power_state); + u32 *states = __this_cpu_read(psci_power_state); + u32 state = idx ? states[idx - 1] : 0; - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, - idx, state[idx - 1]); + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); } static struct cpuidle_driver psci_idle_driver __initdata = { From patchwork Thu Oct 10 11:39:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183207 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 F17CC76 for ; Thu, 10 Oct 2019 11:40:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF80B2053B for ; Thu, 10 Oct 2019 11:40:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cIrf9/U4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OgHOnIF/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF80B2053B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=A9KgfaBrGXoc6VyNgXMBrEHK1yOut3WJ34bX+yDRg24=; b=cIrf9/U48nh6scbo3RIHf3cHOk Ntr30NPHjvFD1DKixP6upj2byW8OzBoJWMaZViWDyIdVkcvXEDB7HekCUq5K7OjOJSrbVdys4jX9V SpveofId9/ZKY7pKzNloBWbXHRTB1ylFP5la0PDI3AA3WZJvrTldCfJe4W6R4H715bhQziDJZG6AX MmYvbBJ6q3a0TSn3UJ2JCSl7MxeC0x/rEpXmrtqcWX1Irc/wemda85HD5+jvyP4zlOV0Ag1h2iT4M ygJlyugnpFq3N7bVFKrQ3mAGaS/VXKkdQiC9aN7oIrRLaMKtruwBMAmJY6O7b2H5kfTBGI6+mI8ih Sy9uZkPA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWoG-0003AY-RQ; Thu, 10 Oct 2019 11:40:44 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnh-0002TC-Uj for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:12 +0000 Received: by mail-lf1-x143.google.com with SMTP id d17so4121931lfa.7 for ; Thu, 10 Oct 2019 04:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jyY5hfR8/N8coo7i/Rw81G3nXo/cAyXblG5DM904HwE=; b=OgHOnIF/JT9aqU5ULYziikH3VIpbyfjLcYtZ62ZAGion5jENQDB43lu6J4WKcJu6KY 52BLa6tvDhyxmjUbdlEIBfL4xtgznU7Qql5Yu5h35386cUJn2GYFKaqo4kJ64ogBJKiY POAOhEUixlR3um6FnqjifcyURYypxa3kqWLGjwyvOmRq8pKZNrIDz/50xhcgjnz8vVl5 mPj5/Y37vX4kKohxCKn5yzdcQlwykwhiySJ9g1Pl/HNVXTDyRpvJqTWPMhlz13rm95J8 zOwzOXLKnERt4j5NlWJg089O+KMqcioLvUndOe5GvbFVL/G/OyZ2hlMuG+PeFN64PMOo zqwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jyY5hfR8/N8coo7i/Rw81G3nXo/cAyXblG5DM904HwE=; b=QJG//g5LSPcYhRKq/jVrPyUH+cYCTFP/p2qCD80VRGYNmLnrFCT0vZitPaqzW1hxW9 sLUUjOHet0hlG/ihaEStGrpYV1pedSYc5rnzLd1OEiyOLtgLlbUp8kxoY/mmg5VpZgAT OgiWgDCoSIfdBMqW1ovH1/L5q8vqH66UiYG2Ea1q4eHLPb1YEIxBFd2QWNx0h24QYMle ARy2/En4BHRRHH0nFIhKNeMPTkJcKcL+UxmBEIgkGOtJQJQupDFWr+I7qmQT/BRhzP+d 35oGVb0dzMLNMPtDm0ZAVlMSz5y8pzbZlexFCxQ23BDuo+iFde4Chnt7DDPQzBPMpf/J GU0Q== X-Gm-Message-State: APjAAAVdlfvoJYsNHhpZ3puBfoLbCR0Z2dmgVvPt6AeDI53JEnCGkEZ+ 2MBb2L5GiQTDDdVvgyEHNPr1SQ== X-Google-Smtp-Source: APXvYqwVz/veomsjupLKt3xVJOp9HD2kp91pfcT6HzEDeMCrvfq1+l+xdbKIzxGRgkRxI/FcE66Vpw== X-Received: by 2002:a19:ca56:: with SMTP id h22mr5690879lfj.192.1570707608097; Thu, 10 Oct 2019 04:40:08 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:06 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 02/13] dt: psci: Update DT bindings to support hierarchical PSCI states Date: Thu, 10 Oct 2019 13:39:26 +0200 Message-Id: <20191010113937.15962-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044010_035202_D0972FE4 X-CRM114-Status: GOOD ( 14.91 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:143 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Lina Iyer , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Update PSCI DT bindings to allow to represent idle states for CPUs and the CPU topology, by using a hierarchical layout. Primarily this is done by re-using the existing power domain description [1] and the domain idle state description [2]. Let's also take the opportunity to update the examples to clarify the difference between the currently supported flattened layout vs the new hierarchical layout. [1] Documentation/devicetree/bindings/power/power_domain.txt [2] Documentation/devicetree/bindings/power/domain-idle-state.txt Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- .../devicetree/bindings/arm/psci.yaml | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/psci.yaml b/Documentation/devicetree/bindings/arm/psci.yaml index 7abdf58b335e..360579bfa591 100644 --- a/Documentation/devicetree/bindings/arm/psci.yaml +++ b/Documentation/devicetree/bindings/arm/psci.yaml @@ -160,4 +160,157 @@ examples: cpu_on = <0x95c10002>; cpu_off = <0x95c10001>; }; + + - |+ + + // Case 4: PSCI v1.0, PSCI v0.2, PSCI v0.1. + + /* + * ARM systems can have multiple cores, sometimes in an hierarchical + * arrangement. This often, but not always, maps directly to the processor + * power topology of the system. Individual nodes in a topology have their + * own specific power states and can be better represented hierarchically. + * + * For these cases, the definitions of the idle states for the CPUs and the + * CPU topology, must conform to the power domain description [3]. The idle + * states themselves must conform to the domain idle state description [4] + * and must specify the arm,psci-suspend-param property. + * + * This allows two options to represent CPUs and CPU idle states. By using + * a flattened model as given in the first example below and by using a + * hierarchical model as given in the second example. + * + * It should also be noted that, in PSCI firmware v1.0 the OS-Initiated + * (OSI) CPU suspend mode is introduced. Using the hierarchical + * representation helps to implement support for OSI mode and OS + * implementations may choose to mandate it. + * + * [3] Kernel documentation - Power domain description + * Documentation/devicetree/bindings/power/power_domain.txt + * [4] Kernel documentation - Domain idle state description + * Documentation/devicetree/bindings/power/domain-idle-state.txt + */ + + // The flattened model + cpus { + + CPU0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53", "arm,armv8"; + reg = <0x0>; + enable-method = "psci"; + cpu-idle-states = <&CPU_PWRDN>, <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; + + CPU1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a57", "arm,armv8"; + reg = <0x100>; + enable-method = "psci"; + cpu-idle-states = <&CPU_PWRDN>, <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; + + idle-states { + + CPU_PWRDN: cpu-power-down { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x0000001>; + entry-latency-us = <10>; + exit-latency-us = <10>; + min-residency-us = <100>; + }; + + CLUSTER_RET: cluster-retention { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x1000011>; + entry-latency-us = <500>; + exit-latency-us = <500>; + min-residency-us = <2000>; + }; + + CLUSTER_PWRDN: cluster-power-down { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x1000031>; + entry-latency-us = <2000>; + exit-latency-us = <2000>; + min-residency-us = <6000>; + }; + }; + }; + + psci { + compatible = "arm,psci-1.0"; + method = "smc"; + }; + + // The hierarchical model + cpus { + + CPU0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a53", "arm,armv8"; + reg = <0x0>; + enable-method = "psci"; + power-domains = <&CPU_PD0>; + power-domain-names = "psci"; + }; + + CPU1: cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a57", "arm,armv8"; + reg = <0x100>; + enable-method = "psci"; + power-domains = <&CPU_PD1>; + power-domain-names = "psci"; + }; + + idle-states { + + CPU_PWRDN: cpu-power-down { + compatible = "arm,idle-state"; + arm,psci-suspend-param = <0x0000001>; + entry-latency-us = <10>; + exit-latency-us = <10>; + min-residency-us = <100>; + }; + + CLUSTER_RET: cluster-retention { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x1000011>; + entry-latency-us = <500>; + exit-latency-us = <500>; + min-residency-us = <2000>; + }; + + CLUSTER_PWRDN: cluster-power-down { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x1000031>; + entry-latency-us = <2000>; + exit-latency-us = <2000>; + min-residency-us = <6000>; + }; + }; + }; + + psci { + compatible = "arm,psci-1.0"; + method = "smc"; + + CPU_PD0: cpu-pd0 { + #power-domain-cells = <0>; + domain-idle-states = <&CPU_PWRDN>; + power-domains = <&CLUSTER_PD>; + }; + + CPU_PD1: cpu-pd1 { + #power-domain-cells = <0>; + domain-idle-states = <&CPU_PWRDN>; + power-domains = <&CLUSTER_PD>; + }; + + CLUSTER_PD: cluster-pd { + #power-domain-cells = <0>; + domain-idle-states = <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; + }; ... From patchwork Thu Oct 10 11:39:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183209 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 4F12176 for ; Thu, 10 Oct 2019 11:41:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2AB2B208C3 for ; Thu, 10 Oct 2019 11:41:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Gt/p32jH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jt87ZF+5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AB2B208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=I3e7JWrW5OBUUv01hudyiCSpaL9zeFQX7kTug03gDcQ=; b=Gt/p32jHufTc05yul+S22uPjuC fGv0tQVSxwhD7KOzwgsVswgUHbbKzOo/ebOPTnj4epJ4tet/4XPdsfrP6QLE2Vmd+MzrqyaavkeUF nbsel8Ci/ZILu7MYvYP+BBuhrTky81NFmDJj79M2vnT4gGGRTjaHGUTj+xL0fRWj2DxLakpjJR9sC ucR/HlO7EaO+SHDw/jYJbY698/WmfHkYOouKJk1Ebyczi+M5lwSc4W9xXoGv4Xg7u1p/VvvECe52l 7fm/skT9oynQ1hkgA0Z7uhSmGM+1rfH+TjHLfTTUzNHl/zfvxaIjz1srB41xwxXwZ+chIaYluVESD CpjnfhJQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWoX-0003No-4b; Thu, 10 Oct 2019 11:41:01 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnj-0002dx-6q for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:12 +0000 Received: by mail-lj1-x244.google.com with SMTP id 7so5834715ljw.7 for ; Thu, 10 Oct 2019 04:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v88JQU6vGgb8ri6uCDKoMwVq9Ia/h8wuaSmlcufCmYU=; b=jt87ZF+5/DHtUlBRJ5BstY8Vh6NbAEk5UF5D0u9HLT6presiea5l2x37EGTavAgCM2 H6B9YduMYxyPWcZQ4LDD0neKrxzMhr4DDLJH8oBvjt+ks9l3QnWRR5PubXNd4vzUEa3V fgBE1oE+WU63PB9MXoMoWyvRweYDa/KA+enceW5fZYXZHR2ZMUhprzxuPtzW7IdBbqZ/ kGJTTsnM0FhDhek77frZusCt3Srayy/AEUjcMSLtjZYglG2TVmus+yHd4KOQekmMb080 WIB28o60K0vFD9ulrOuL9R6XqTAkOFwHwsw7PULu7sOOm3lOtCBUtvXHBX7li4uUnl0I C04Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v88JQU6vGgb8ri6uCDKoMwVq9Ia/h8wuaSmlcufCmYU=; b=Kfufbd01U0W21mTrZPnpf70IHPh7xIMk/2wT21rxbLwX0FV6a69PGR9uaRZBuhNfzD 2YzDbO+5bmLxIrH1l90taHYz3tMv75d0LbRRsP2zSvRG8sIuMgwHXekUvt1T5YlnWXNJ KoKPN5YW/lKCz359GNnnsA2sWg9KvSUjEIfNzsMDvavakKw/eOnslcMEYKHCTOn3Rx6V 2DgxCReKU9tmM6cQe5gov3HqWuuZ5Z5D6IVx1XUpkmIYvPtzCc8RhvM8f9h2b+YOjQgS 2cqWCyGTBjewMemmC5//bOvpDza5leBoXQdP8HJjWta/ggB6a7daj/9lERT7SMDLoCmu J8rg== X-Gm-Message-State: APjAAAXw362COE2n7X1Xr9pjNgpQ8hFmgXKGh01Tf79aET8JnmjfTgTr LnJdny72cz4v7EcdB8mW1IQQfw== X-Google-Smtp-Source: APXvYqyCKks0JZZNViLz2Kmfcp+HjHLDr3UWaZTScndbtx975mvyfpGsTCg1ZMWYx/C2hWBuMccseA== X-Received: by 2002:a2e:9b8a:: with SMTP id z10mr6104674lji.80.1570707609559; Thu, 10 Oct 2019 04:40:09 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:08 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 03/13] firmware: psci: Export functions to manage the OSI mode Date: Thu, 10 Oct 2019 13:39:27 +0200 Message-Id: <20191010113937.15962-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044011_261972_8F306010 X-CRM114-Status: GOOD ( 15.55 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org To allow subsequent changes to implement support for OSI mode through the cpuidle-psci driver, export the existing psci_has_osi_support(). Export also a new function, psci_set_osi_mode(), that allows its caller to enable the OS-initiated CPU-suspend mode in the PSCI FW. To deal with backwards compatibility for a kernel started through a kexec call, default to set the CPU-suspend mode to the Platform Coordinated mode during boot. Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/firmware/psci/psci.c | 18 ++++++++++++++++-- include/linux/psci.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 84f4ff351c62..76f3a991d4d7 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -89,7 +89,7 @@ static inline bool psci_has_ext_power_state(void) PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK; } -static inline bool psci_has_osi_support(void) +bool psci_has_osi_support(void) { return psci_cpu_suspend_feature & PSCI_1_0_OS_INITIATED; } @@ -154,6 +154,15 @@ static u32 psci_get_version(void) return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); } +int psci_set_osi_mode(void) +{ + int err; + + err = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, + PSCI_1_0_SUSPEND_MODE_OSI, 0, 0); + return psci_to_linux_errno(err); +} + static int psci_cpu_suspend(u32 state, unsigned long entry_point) { int err; @@ -536,9 +545,14 @@ static int __init psci_1_0_init(struct device_node *np) if (err) return err; - if (psci_has_osi_support()) + if (psci_has_osi_support()) { pr_info("OSI mode supported.\n"); + /* Default to PC mode. */ + invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, + PSCI_1_0_SUSPEND_MODE_PC, 0, 0); + } + return 0; } diff --git a/include/linux/psci.h b/include/linux/psci.h index e2bacc6fd2f2..f76b45341adf 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -17,6 +17,8 @@ bool psci_tos_resident_on(int cpu); int psci_cpu_suspend_enter(u32 state); bool psci_power_state_is_valid(u32 state); +int psci_set_osi_mode(void); +bool psci_has_osi_support(void); enum psci_conduit { PSCI_CONDUIT_NONE, From patchwork Thu Oct 10 11:39:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183213 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 890201668 for ; Thu, 10 Oct 2019 11:41:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 583C22054F for ; Thu, 10 Oct 2019 11:41:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QSLZ2Bgk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DanIYhUZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 583C22054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=9hLgKz0kCa4Qsa+UROrtecbXdpkgG/952bdVmk6EAJI=; b=QSLZ2Bgks218xl5jK1UwMve/ly 8ayKTBtpreN3Xb9nVXt7JQEAEPvQVdvV/RuB5D0pVG6Pw69odjJmxmd33oS8qh4V3PsBHDk4zAb0X UQDG440lOJLGMab5WQ70c7gAQ4zAghef+hsQtnoH4NZ0Pb9T+HNjHqzXlYVlzwXy8HySU5ooNz8H9 qPhSHwxeSwaasqw8KoZ8I2/e2WIFyP+N7k3lbim35kENGIopLxZwY43qPmQRHFrIczkeugXBcxzbe fQzaH8MwokQsyiCpNzPiL3kZeT8Jes98qH8+6fqHsb/OA8cgeitM9M6oPvfkE7vwPRDda1bcADyNc ro+6hEJg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWoq-0003h4-Rz; Thu, 10 Oct 2019 11:41:20 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnk-0002iD-SU for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:14 +0000 Received: by mail-lj1-x243.google.com with SMTP id m13so5805006ljj.11 for ; Thu, 10 Oct 2019 04:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GuctgQaNXDpvCtGnyWFncLAWkLOPv4PuyrC/plBYoKw=; b=DanIYhUZr/1fcPOq8Ic6qUfgUj21pf/pck8soG6eZQCQYhtidxPLIlbpjpwqD+1XB+ LMxMZ2fIBihfggtcjrtFGfxbLLq8eIV21kCamNCqUj6Y/iWMUWu5aY+SkSB36/59rvHv j2I8r/mohLV8cTtkXEd+eQ4NLXVuf773dkPbaDzPLUWhrFdJ/PkSO1P1JFPRVaQlfxR6 x153P2vsxw0BA+ayURQPn/ry91aXPfcYe4iFNFCWze/i0veaWf0Nw7nIyqJZhu/YfH1Z HbqHDu1AQp+bYI6dm7I4KRDV4j0iojylqAYBVwYJwMtnRXRspSEkZSOnemFgvBXNAT0P fYJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GuctgQaNXDpvCtGnyWFncLAWkLOPv4PuyrC/plBYoKw=; b=sxm90FpNqn31aeNKufwMlWh3S0eAhT1tgvtx/eKB37YSfpudXcMMRRqAhCbD9xgcnR CE3qsnm6JL+i84iLiZHWdYtn2Cp0ZBIIkXae6VfYSOLr3rcZjkmOMb0/AvICgfmhjXBI 0O3oH7YqXxBI2H0IwSdlmcAjA8w8r2JjN9UHgKUcObeGvS5IeBG55DZJk7Hx0hIpN2Ks yk2aErYyzqjjfm7YFjAUwS3xc1onEsEHeutIL1NuKQbLE0rRLOhoLNNGkegBx1HiS6iM bSxvlg0AD+5zCiFht44EdEgKyzWYPP9LRbHeZmJc3b7ZnjxzGgTtWoWSlVcEzlphqnNO MT2w== X-Gm-Message-State: APjAAAWs2vIlzuumzDxF5QpHjKJYWSLUPNqy/4e7vGfyhcOnvxrmS7Fg TglfFUN3lISAp4/y2+pWam/C/g== X-Google-Smtp-Source: APXvYqzJlSXBelf9XaR8Fb0R4bdv691aPCwO1Z3PRCtK+D7bKXcC8xeURfNHeN93zAvSqzcikcMDsw== X-Received: by 2002:a2e:286:: with SMTP id y6mr6266107lje.184.1570707611403; Thu, 10 Oct 2019 04:40:11 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:10 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 04/13] of: base: Add of_get_cpu_state_node() to get idle states for a CPU node Date: Thu, 10 Oct 2019 13:39:28 +0200 Message-Id: <20191010113937.15962-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044012_952753_68B6EA4B X-CRM114-Status: GOOD ( 18.62 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:243 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Lina Iyer , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The CPU's idle state nodes are currently parsed at the common cpuidle DT library, but also when initializing data for specific CPU idle operations, as in the PSCI cpuidle driver case and qcom-spm cpuidle case. To avoid open-coding, let's introduce of_get_cpu_state_node(), which takes the device node for the CPU and the index to the requested idle state node, as in-parameters. In case a corresponding idle state node is found, it returns the node with the refcount incremented for it, else it returns NULL. Moreover, for PSCI there are two options to describe the CPU's idle states [1], either via a flattened description or a hierarchical layout. Hence, let's take both options into account. [1] Documentation/devicetree/bindings/arm/psci.yaml Suggested-by: Sudeep Holla Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Reviewed-by: Rob Herring Reviewed-by: Daniel Lezcano Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/of/base.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 1d667eb730e1..0e4cdf0f3864 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -477,6 +477,42 @@ int of_cpu_node_to_id(struct device_node *cpu_node) } EXPORT_SYMBOL(of_cpu_node_to_id); +/** + * of_get_cpu_state_node - Get CPU's idle state node at the given index + * + * @cpu_node: The device node for the CPU + * @index: The index in the list of the idle states + * + * Two generic methods can be used to describe a CPU's idle states, either via + * a flattened description through the "cpu-idle-states" binding or via the + * hierarchical layout, using the "power-domains" and the "domain-idle-states" + * bindings. This function check for both and returns the idle state node for + * the requested index. + * + * In case an idle state node is found at @index, the refcount is incremented + * for it, so call of_node_put() on it when done. Returns NULL if not found. + */ +struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + struct of_phandle_args args; + int err; + + err = of_parse_phandle_with_args(cpu_node, "power-domains", + "#power-domain-cells", 0, &args); + if (!err) { + struct device_node *state_node = + of_parse_phandle(args.np, "domain-idle-states", index); + + of_node_put(args.np); + if (state_node) + return state_node; + } + + return of_parse_phandle(cpu_node, "cpu-idle-states", index); +} +EXPORT_SYMBOL(of_get_cpu_state_node); + /** * __of_device_is_compatible() - Check if the node matches given constraints * @device: pointer to node diff --git a/include/linux/of.h b/include/linux/of.h index 844f89e1b039..c669c0a4732f 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -351,6 +351,8 @@ extern const void *of_get_property(const struct device_node *node, int *lenp); extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); extern struct device_node *of_get_next_cpu_node(struct device_node *prev); +extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index); #define for_each_property_of_node(dn, pp) \ for (pp = dn->properties; pp != NULL; pp = pp->next) @@ -765,6 +767,12 @@ static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) return NULL; } +static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, + int index) +{ + return NULL; +} + static inline int of_n_addr_cells(struct device_node *np) { return 0; From patchwork Thu Oct 10 11:39:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183215 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 6F77E76 for ; Thu, 10 Oct 2019 11:41:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 422072054F for ; Thu, 10 Oct 2019 11:41:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rupWPbW6"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="T0nFsd0F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 422072054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=j8zuXaCtzaHmwcOn1xLLpLW5Ebty7443t0BdUeEKCNc=; b=rupWPbW6dwRkmWrUgTPQWipf89 GgEfa5AJgoInkqCUNMPZjYdwZ1EGmQ2/4NbJjAadUWCtdx9weO11KYiIPN+87y5eV8vQ3e26KEX3J yANcY87CN30IO83t/jnd6w6d+/kEwWuj4reU/ScXqc+LmP0BewbMY6fIIgpA3aCGnT5lpgV/Bk6Ni bYnVct4vcPj0GuGAvS97lh2KBDdw01sRKCWLLxJ6EdklYGo4ZnUfg20PDmYCJyjCXJV61mWTW4wTv hJqtVyYCdwBQst0myRpxXwEJ+XJHXewEzrd7lufdo9TAQA2c3MYlRrOVtcZjmvzMitpFrUgkCty50 DvH3H1ww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWp4-0003uI-Pl; Thu, 10 Oct 2019 11:41:34 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnm-0002kG-Rf for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:16 +0000 Received: by mail-lj1-x242.google.com with SMTP id m7so5871813lji.2 for ; Thu, 10 Oct 2019 04:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uPQQL2LvieO3hRSdVOoT+soulZMhG9ActuEg4qQLyaA=; b=T0nFsd0F5yhLoTBaFcw7y7TSJ7swFLFrCm0iZ9fxXkpwH6LgoqyNcmtnY+mHnZ7wqA tzclaFDIjVJeRj4TRzdNHxas/7Vc8CSCkhEVswvN1U/GYZXItT1Dooz0x75Gut6BZJwe 4S12SRko6dhQUiVAR7mIGBsqkpltXwc+NMvmdHK8upCiNxXR8JCoLhsHRJqg1TNG15Iv a8dMDov2BYDB7gaiCVsBOvN3bHHR40LV7UsV9TRjpeuPT4Ri5Tw3COGyo494xPZWl7xQ Q9jZ1l0HBJVKHFxRnUwvZuXn9e9UCxKzqe6oBIidHY+cpmTeJzdcMO6Goptv3Oz/YpEU VJHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uPQQL2LvieO3hRSdVOoT+soulZMhG9ActuEg4qQLyaA=; b=gxH6sKDWDIxRY65UiM3nadBlEM9oW7UtZVWSKIfkOxuQF547rZS8HMVEzPvBixPL+i srYacxCH9fLyGXcCiIfKVU+Z+lTD3Gv94gisEwbMETVHVE1oJGX1ZFNp0ZIWsnao8ZB1 7GnRZV/Nkx2qSFxaPr3L1swEzL/Q/PHHfFLyv2SYcRYQKwoUats7bktY5Gd9qf+mFDR/ z6TY/wyW3P5TZtDyId783hU2YvTcI+Z0QUOU+DT1Nkm9PdNvXuDtuJmRM+4aHyhmOK64 teQrgFbAHmet22riHPaN0HAh/4x7SaIrMlzknOb52SJhqMfceTKQffQbCBXdDrCbux7Z kDsQ== X-Gm-Message-State: APjAAAU6PVP/qlNX9zjdsk88QCN5sN/Qk8dKofET44IGzHTwy7X4D/6Q gZrn+TpH+QGE++KypuQ1Kxqv2w== X-Google-Smtp-Source: APXvYqwd9hZQk2PNNSWawnj+vwKKoXgMm6PDK8dcNZdYDc7Bp/XO4FPg5jdpJ5ioW9H9llCi9Uk6EQ== X-Received: by 2002:a2e:6f0f:: with SMTP id k15mr6301625ljc.12.1570707613211; Thu, 10 Oct 2019 04:40:13 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:12 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 05/13] cpuidle: dt: Support hierarchical CPU idle states Date: Thu, 10 Oct 2019 13:39:29 +0200 Message-Id: <20191010113937.15962-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044014_922450_96A7BAD1 X-CRM114-Status: GOOD ( 13.35 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Lina Iyer , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Lina Iyer Currently CPU's idle states are represented using the flattened model. Let's add support for the hierarchical layout, via converting to use of_get_cpu_state_node(). Suggested-by: Sudeep Holla Signed-off-by: Lina Iyer Reviewed-by: Daniel Lezcano Co-developed-by: Ulf Hansson Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/cpuidle/dt_idle_states.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c index d06d21a9525d..252f2a9686a6 100644 --- a/drivers/cpuidle/dt_idle_states.c +++ b/drivers/cpuidle/dt_idle_states.c @@ -111,8 +111,7 @@ static bool idle_state_valid(struct device_node *state_node, unsigned int idx, for (cpu = cpumask_next(cpumask_first(cpumask), cpumask); cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpumask)) { cpu_node = of_cpu_device_node_get(cpu); - curr_state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - idx); + curr_state_node = of_get_cpu_state_node(cpu_node, idx); if (state_node != curr_state_node) valid = false; @@ -170,7 +169,7 @@ int dt_init_idle_driver(struct cpuidle_driver *drv, cpu_node = of_cpu_device_node_get(cpumask_first(cpumask)); for (i = 0; ; i++) { - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + state_node = of_get_cpu_state_node(cpu_node, i); if (!state_node) break; From patchwork Thu Oct 10 11:39:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183221 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 15F4E76 for ; Thu, 10 Oct 2019 11:41:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DDC0D2054F for ; Thu, 10 Oct 2019 11:41:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mxYwp3ih"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="w/wpfkf4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDC0D2054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3QgEYlb4PGFLJNih0/Sy/heCM8q7JibRxAzSqhH88lQ=; b=mxYwp3ihc+iVEianmX01T+8FHF 5aMFQ2RWeUd+1GNJPECf1ZoEAej2OYK2X1jeULHM6GwL6fBNRGpktfYumQXWHK9q6ASsyclHvGHmL s8cqFLBJjCjurDogaMLBqDuDV2C1yWApE1n2RUMQwST1w3y9Ddrj7o93JOVzCcMzeuR9DG5MbnGyD 1mjt0vJx2eqbdnUr/a0Q4icOqOkVVz8rrzju7nqS9C7ZHIyKPT8D95LU1FzslAPrNVHf115HmPIs6 JdJXWqjYbl8/QZnGNTFTN/Ju7EJOLFrfPfsfoYdqCPHGa21MjCTHyUIuciIdkf2DabcFWzoKKBiqc 0nSo5o2A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWpL-0004Bg-Sc; Thu, 10 Oct 2019 11:41:51 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWno-0002lx-CF for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:18 +0000 Received: by mail-lj1-x244.google.com with SMTP id v24so5859807ljj.3 for ; Thu, 10 Oct 2019 04:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=w/wpfkf4JD7NtMhgYW5bka2jwABBrG/zFpdfSK+C6Y8ZEzk1usOy+0SZ037SEiwojW 8ikm7DR8YcoaSKOsLXm8/4fAoU66XIkDrdXmlfD0bKpQ4pPfXVVdHhNQ8eWlxdKdwF8m 3v9pJu7MyhXBh0O8lxuIkg9S/oSY3v5jPH/hUxyxae9He70A2JNrMcErYiipUzzxW6la RPJBm1dTBVGovcLV6kmCCd3lqZrimb7rDvRlZSKv2Ch/iQaQuACu1Dssa3Z+C2w/ecWr XF0jqnbdyn9OWFCh7gZX9bj7CuKUEM3iw2jfcQG61bDXCjKqE62EJgVMKO9gnqC4ni9I rSlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=ZdMBwZ91aRNQFwnC/W9lC0GGE9WFIq0g5RPbbk3JBT3bl6Wi+qSywkaVUvSTe9yMIP /UEtzuWT++iX+EjR1JyAUGycMBLBC+87MFRNrrtj1d8HWODaWLTXZRtzLRnBBC0HNOtw srAqn+8CZRNhWEVa3jU+2kGC4edQsvjpVXbEhSrNoIke3daL/3G/xLzAVWYvr2oCxN5S mKEQFlpEI99hFWxK+NRpgS7PBRNvBJfb5YUpR/Zm+yuS4smDVtKEfL4nPoLRWqY9qMN4 yMnnAQrN1Wty4aiNIeyO154xo0bUibfiI10+82HiQc2tkq5vGzLKLTOVjAhUMAdoXQv2 bs7Q== X-Gm-Message-State: APjAAAWSKHLJNTbcatCchloNHH1uOdi5x2MVWp8oNaVA+1vKDPlJKGoA kyowZFZpNYuBC9ReoXK/JloDkQ== X-Google-Smtp-Source: APXvYqx8XV+oQ6tAHK6bndR8s4uIRBDsgX8TGkAPZYFU0mns7A7hnFIcGWvIyBsKIHrN+DhA2aCXOg== X-Received: by 2002:a2e:87ca:: with SMTP id v10mr5973843ljj.43.1570707614837; Thu, 10 Oct 2019 04:40:14 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:14 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 06/13] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Thu, 10 Oct 2019 13:39:30 +0200 Message-Id: <20191010113937.15962-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044016_446409_C5BC4974 X-CRM114-Status: GOOD ( 17.48 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Iterating through the idle state nodes in DT, to find out the number of states that needs to be allocated is unnecessary, as it has already been done from dt_init_idle_driver(). Therefore, drop the iteration and use the number we already have at hand. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 2e91c8d6c211..1195a1056139 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -73,28 +73,22 @@ static int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) return 0; } -static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) +static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, + unsigned int state_nodes, int cpu) { - int i, ret = 0, count = 0; + int i, ret = 0; u32 *psci_states; struct device_node *state_node; - /* Count idle states */ - while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - count))) { - count++; - of_node_put(state_node); - } - - if (!count) - return -ENODEV; - - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + psci_states = kcalloc(state_nodes, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 0; i < count; i++) { + for (i = 0; i < state_nodes; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -104,6 +98,11 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } + if (i != state_nodes) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0; @@ -113,7 +112,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } -static __init int psci_cpu_init_idle(unsigned int cpu) +static __init int psci_cpu_init_idle(unsigned int cpu, unsigned int state_nodes) { struct device_node *cpu_node; int ret; @@ -129,7 +128,7 @@ static __init int psci_cpu_init_idle(unsigned int cpu) if (!cpu_node) return -ENODEV; - ret = psci_dt_cpu_init_idle(cpu_node, cpu); + ret = psci_dt_cpu_init_idle(cpu_node, state_nodes, cpu); of_node_put(cpu_node); @@ -185,7 +184,7 @@ static int __init psci_idle_init_cpu(int cpu) /* * Initialize PSCI idle states. */ - ret = psci_cpu_init_idle(cpu); + ret = psci_cpu_init_idle(cpu, ret); if (ret) { pr_err("CPU %d failed to PSCI idle\n", cpu); goto out_kfree_drv; From patchwork Thu Oct 10 11:39:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183225 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 4CE4776 for ; Thu, 10 Oct 2019 11:42:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2486D2190F for ; Thu, 10 Oct 2019 11:42:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="s27AIK64"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EUAy07fB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2486D2190F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=I/LkAIG+WfrHksg/EAXYRshI9IA5StexkssXi/K2UOc=; b=s27AIK64bqPQwHgicRn5vJhgEh xuXTfS3YJrnc1hE9DA33YmoZoytHbxwigtQ0Z+PlwLL/mRrmx4Nlk0d/8CCff9BHMHYVN8BtU4KH6 W/8Od0TOEjF6Y7R5/g3EYRr+Ana8CGGZabHDvlPGUlRZsI/SUJQZ3SgoRDY2HeYIbWBgTOkntedyL 63s/d6lya4WxNLFSTCq65FqoTGTw1cqSjXwiBZaCK9+AzEoesDpQdhGXiA5N3bG/3R+9TtTOTbfaQ b44lo/yg9hqburfyM5EggIR34QHM4gDwBY1wd7OMykMmgjzokZx2hRfcgFsog3CgfTJBDBQoPE/Cd wLWZhU0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWpY-0004Pc-7S; Thu, 10 Oct 2019 11:42:04 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnq-0002ng-An for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:19 +0000 Received: by mail-lj1-x243.google.com with SMTP id y3so5843061ljj.6 for ; Thu, 10 Oct 2019 04:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nvXOpVcM/IpothdU1ZKoTmNHFS7WJStir72tye3UWWE=; b=EUAy07fBsO1Wz5z3ljchfWd2sfdTxk2utOmWleJB60APniuQ0U3RAzfQdhfU/BWbU3 /PpxRmMYJ+bhc8H7y4zsGtOLcdqr9mF9vHT+BAF1w2huN0P/nPF6ZTE794efcWFcaxrq 82N6hkfxHfNP9zDCtgRDb7F7P1918eEHfSkhI8PK4xqSZVgc88lGjJ53etEeAcHIcwMP ytQqCscNLLgc+xJioNh+2NOpa9q7QFuCq+3m59fEwdALI0MT6g8ITkIlJ/WS9+aWE+B4 Z0vwxgptGD1RDuLRlsFVMW4k0nYmjTmLaNA4g29yjtIoKOgj6OhnsLkPjHkVD+6KZGZ4 qDXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nvXOpVcM/IpothdU1ZKoTmNHFS7WJStir72tye3UWWE=; b=OSh32ARvXIwxTMdvocZo05+J/MoWiFgThA6QXoBwDmQRp4YK0WY38RFT7CEAQBLTn4 VsFAjSukSLrs36wdE22ZjG+9BvWQ9oOZVMOQzMDr1MesKo3K/lfAq/XMxjIPh5UYySQE JVoKQs2kpuByWnhNZhKCg/1Oo8/BsWcY+P5NsrybHMNXVEPqcrU6lnDCHH6sTxkEBwq4 pbNPdnwIyLo7cRjsCg30Djn1/u1xnmqNHicmw6pEJwjL9h41tMJTjTBnNNLq+LaRD0c0 fIhBgySaS5bFAqZ+s5j7dNwBML1Wp6h1RVHM1GHb0gQiMErWv43GmGvTpRvLn/+fgyJd HGUQ== X-Gm-Message-State: APjAAAWHUvdRnVW1wJ4BMFjGULhGGcXVIyiQSl7IZR1QzmdPBgi1dycT 1rzJIiVer6ZIqg3B4qsTSXp8XA== X-Google-Smtp-Source: APXvYqxUdEhaIFvRKswg87UCzDQiM72AeRacZpBqrmORob2xGUbd6DLiJRFX4z5exUT/BNmXNpFbgQ== X-Received: by 2002:a2e:89c4:: with SMTP id c4mr5832114ljk.65.1570707616291; Thu, 10 Oct 2019 04:40:16 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:15 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 07/13] cpuidle: psci: Support hierarchical CPU idle states Date: Thu, 10 Oct 2019 13:39:31 +0200 Message-Id: <20191010113937.15962-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044018_512537_04AB83DB X-CRM114-Status: GOOD ( 14.11 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:243 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently CPU's idle states are represented using the flattened model. Let's add support for the hierarchical layout, via converting to use of_get_cpu_state_node(). Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- drivers/cpuidle/cpuidle-psci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 1195a1056139..5c30f23a8a7b 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -85,7 +85,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, return -ENOMEM; for (i = 0; i < state_nodes; i++) { - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + state_node = of_get_cpu_state_node(cpu_node, i); if (!state_node) break; From patchwork Thu Oct 10 11:39:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183227 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 75D4B1668 for ; Thu, 10 Oct 2019 11:42:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 531752190F for ; Thu, 10 Oct 2019 11:42:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QDISuHMU"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fpTsBvZB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 531752190F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7krDBsSI7nRK9mnkokTj07qjilHlHj/bws6kkY3AlJk=; b=QDISuHMUhZX4N+E8i1/zAN+n1m 0lid3qz5PS/AddAQ7F8cIugd330FEy/oR0i6vAZj+M7hn9qoNGcB18opTHsa8cdWPWqmvGxdR5s2C tE7scaTDiRYMrd+6MPDJxQwhJ6hEkPzoF3mg0EpTHW7ewy1WEjX8uFRgP4UaPMDG4bWoyWEdgyVR4 m6qsYS5usD3ogaZtw8VUjMhrzw//hZATTTZbiRXLyZOsk834lP6FsbEG2pYouQLhCDstDmN1NiQ6T 0ZnyFNW2d3VA3PWNXBzIeP0CBhzhBIHO4xN/tqTId38b/XOgUVRjqyjOXRAVPd+6YT9qbTd9WuEuZ 61fHwIcg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWpj-0004cT-CM; Thu, 10 Oct 2019 11:42:15 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWns-0002pt-2Y for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:22 +0000 Received: by mail-lf1-x142.google.com with SMTP id r134so4109773lff.12 for ; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p5qrlgEHHz72OqawbaM4oNKQbRiSCqvlNCrVec5FI84=; b=fpTsBvZBXrvTN9zR+IrMwIGukuhZz6A+ldBwdcZi85by9XgVOP/bWsZrqXdciNslhQ hPSQ87yb+x0ew8Zra1SvLTZ/P48Hr3FZUtR+nc3Bf+KjolueaFc8mzWO7hCTf5JTZ53J GY5IkZKAU60fnj9UwZMeKc4KEFiIVOqUHjv08fBOzAHTlLevorIgxgahat41rZdmOHja NUdOFzdcgrXCmknjYH2vORo7/nhAmDa0V6rUyNJERU3OmJlYnNSJONJXOFyK9xkZzVhT BZKrXoMMpkDffL35v7BHgNLabiW8/lWryfjLPNpRXqpI8THMQwTtCoxQ3KIMmGeK8+Ak oyhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p5qrlgEHHz72OqawbaM4oNKQbRiSCqvlNCrVec5FI84=; b=UwRFYtTJCjs5zH2wsSVtAfbndYBvLfNZxK923Yq5Bvuv5o8Sc0W8zmVav0gp7SX7Ot /PrVvnGQxGdqsR/Elvvo6e9B694QuInRPa6QCRyEc0+EDAjFuAObljC2hzBKQVIJHKrS C1LfAMaU7e+vAjiUoZceCO3H0ZS+Hs2Voaht/bgt0l06N1LARCPniyZsRZQJ52QfEs24 UAnBQbf3cF10EtJcRu8NP1gAWKK2jeEgJWR8NGCjyRhklKf6EH2Q2SgehOR+EiPDYYfk 2SxvLPN9leZdNynNSUNbBYWk+HAmKvcI7MosIbBDHAJudeoAZU383BF92mwsvfZ6jhPR 9vyQ== X-Gm-Message-State: APjAAAWyPb9K+I1udZVck9MXuhuwVZFaDIVPGaQCiZQYQmTNoRW2uc2a trzo25snNNbBJqXrLO/s+mHJ2Q== X-Google-Smtp-Source: APXvYqwurmeJAb45mxPdDwDdgYZyKg506CrXtVc4YhleXcNpg+js8O9MZD5A1KTQyHAY5EPoYkaFnA== X-Received: by 2002:a19:ed14:: with SMTP id y20mr5807432lfy.4.1570707618117; Thu, 10 Oct 2019 04:40:18 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:17 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 08/13] cpuidle: psci: Prepare to use OS initiated suspend mode via PM domains Date: Thu, 10 Oct 2019 13:39:32 +0200 Message-Id: <20191010113937.15962-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044020_167517_952E1E73 X-CRM114-Status: GOOD ( 18.83 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:142 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Lina Iyer , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The per CPU variable psci_power_state, contains an array of fixed values, which reflects the corresponding arm,psci-suspend-param parsed from DT, for each of the available CPU idle states. This isn't sufficient when using the hierarchical CPU topology in DT, in combination with having PSCI OS initiated (OSI) mode enabled. More precisely, in OSI mode, Linux is responsible of telling the PSCI FW what idle state the cluster (a group of CPUs) should enter, while in PSCI Platform Coordinated (PC) mode, each CPU independently votes for an idle state of the cluster. For this reason, introduce a per CPU variable called domain_state and implement two helper functions to read/write its value. Then let the domain_state take precedence over the regular selected state, when idling the CPU in psci_enter_idle_state(). This allows subsequent patches that implements support for PM domains for cpuidle-psci, to write the selected idle state parameter for the cluster into the domain_state variable. Furthermore, let's share the needed functions in a header file, to enable the support for PM domains to be implemented in a separate c-file. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 31 ++++++++++++++++++++++++++++--- drivers/cpuidle/cpuidle-psci.h | 11 +++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 drivers/cpuidle/cpuidle-psci.h diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 5c30f23a8a7b..a16467daf99d 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -20,17 +20,42 @@ #include +#include "cpuidle-psci.h" #include "dt_idle_states.h" static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +static DEFINE_PER_CPU(u32, domain_state); + +void psci_set_domain_state(u32 state) +{ + __this_cpu_write(domain_state, state); +} + +static inline u32 psci_get_domain_state(void) +{ + return __this_cpu_read(domain_state); +} + +static int __psci_enter_idle_state(int idx, u32 state) +{ + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); +} static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { + int ret; u32 *states = __this_cpu_read(psci_power_state); - u32 state = idx ? states[idx - 1] : 0; + u32 state = psci_get_domain_state(); - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); + if (!state && idx) + state = states[idx - 1]; + + ret = __psci_enter_idle_state(idx, state); + + /* Clear the domain state to start fresh when back from idle. */ + psci_set_domain_state(0); + return ret; } static struct cpuidle_driver psci_idle_driver __initdata = { @@ -56,7 +81,7 @@ static const struct of_device_id psci_idle_state_match[] __initconst = { { }, }; -static int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) +int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) { int err = of_property_read_u32(np, "arm,psci-suspend-param", state); diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h new file mode 100644 index 000000000000..e593de1784c3 --- /dev/null +++ b/drivers/cpuidle/cpuidle-psci.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __CPUIDLE_PSCI_H +#define __CPUIDLE_PSCI_H + +struct device_node; + +void psci_set_domain_state(u32 state); +int __init psci_dt_parse_state_node(struct device_node *np, u32 *state); + +#endif /* __CPUIDLE_PSCI_H */ From patchwork Thu Oct 10 11:39:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183231 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 6A45776 for ; Thu, 10 Oct 2019 11:42:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4106F2054F for ; Thu, 10 Oct 2019 11:42:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="h8h0FpPl"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pmkfwxka" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4106F2054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=r11iSdXw5hSu26xNFvRK41NZIPp0gaokParx4rqh6T4=; b=h8h0FpPlF4QryOHg/cPWL3c7F8 K9SzZMO8GbS9HF5FQ1HgX+o7smrnuc2ofWsLilGpGMy33zDMSuHZ3evXECxuG0XrygMlVlGhk+0rB /QlMLbCNo/yPKzaIV9+oqxDHWVpcyRN5iV0tRfvuC438Q2fKYgOB6jmtCWHo8ipKIByrEqoPDHyod r0khCRfNY47tZNb/r3ShrHrKJ6FjufdUa/womrHXDhdEjH+ZFiAMRrGiwGOFq5lmfIy2QAB50Gb5d tTb6tjE0rPVpIUwfsBZTeyop1mqm3Tm1pDCzI5zMSV+KavEomE1po6u2JAsdQG+LQTJeP12LctICl bFPDim7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWqA-00054E-Cu; Thu, 10 Oct 2019 11:42:42 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnu-0002ri-I1 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:25 +0000 Received: by mail-lf1-x141.google.com with SMTP id q12so4111368lfc.11 for ; Thu, 10 Oct 2019 04:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=pmkfwxkafYHpSiVu7Ke8qyTAai9lSVf06gP+DuoqVBCdmPXeDGwnD865H9L/eBz4ph Mc9ompj19KSeeGD0zY0gJs9/1NRziZ4G6M4cVNufONzPB091FVd+9U8bfrnXLjJGKtE9 pAQYezMrOQdjnwzzgKZmW5HKmYTuct69TUSjXw6+GrU/YHAfNCanJ6BDM38VmVxYsNbc cbh97OXyVvfcM6T5W7OaMF45PzJqZu++xoLU4W8ssiLmHyCzUXnjiE8RbIu+qjux57Tp ojfn/CavWRGpl+nUU0gmPejv7qQMlHjHX1NTievqsgP/5MBWzAGS8nANRqEZI38DpQ9t FjqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=sYqFzPi3qJFAruQe7KT08KfmoRNvImKGR3RBrqTPEvaVAOrZMKECRWE1IVVDO4L/9w f9+7qMd3Y0/lZf2J0n/U9fiQID5GuYwYGl6S496FtFEJ3L3U36kbIzQ1kW7x61ZPs8zU 2oVh/O0f7v0sG1p+bTm01hRxn/2fiJqLL6gpjxQakeFxWehJqCZLL7C7YlJp1o9fggTI nFIG4YuSP9HTnxyEpfZOwlWXcXY22m+VqtU7zcU6S1n8pE/qnfn8ekE5nTgbE/Wxh6vo ejr9KPF6x/m87wEs0ZDbq/beF+qdMivnJjs1Qj/0/FinkujB4rBimNhJofVasiO1QUBF dEnw== X-Gm-Message-State: APjAAAU/ODMqAnkOx1C0l/abQR2Nnd3+4IzHJ3QhXQtOMgpRiC7zmXvw w07hNLJ1rWbeft0CDieUjYNc3w== X-Google-Smtp-Source: APXvYqx1mFKVFqlLoIdvx8IvMJJulifnGJ7CfjYgTVgfhhrbHW5f47BT8zn+1dU3qSnhC5ZTUi5f1Q== X-Received: by 2002:a19:c392:: with SMTP id t140mr5888002lff.156.1570707619664; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:19 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 09/13] cpuidle: psci: Add support for PM domains by using genpd Date: Thu, 10 Oct 2019 13:39:33 +0200 Message-Id: <20191010113937.15962-10-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044022_707686_6529EF8C X-CRM114-Status: GOOD ( 24.01 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:141 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Lina Iyer , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When the hierarchical CPU topology layout is used in DT and the PSCI OSI mode is supported by the PSCI FW, let's initialize a corresponding PM domain topology by using genpd. This enables a CPU and a group of CPUs, when attached to the topology, to be power-managed accordingly. To trigger the attempt to initialize the genpd data structures a subsys_initcall is used, which should be early enough to allow CPUs, but also other devices to be attached. The initialization consists of parsing the PSCI OF node for the topology and the "domain idle states" DT bindings. In case the idle states are compatible with "domain-idle-state", the initialized genpd becomes responsible of selecting an idle state for the PM domain, via assigning it genpd governor. Note that, a successful initialization of the genpd data structures, is followed by a call to psci_set_osi_mode(), as to try to enable the OSI mode in the PSCI FW. In case this fails, we fall back into a degraded mode rather than bailing out and returning an error code. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/cpuidle/Makefile | 4 +- drivers/cpuidle/cpuidle-psci-domain.c | 281 ++++++++++++++++++++++++++ 2 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 drivers/cpuidle/cpuidle-psci-domain.c diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index ee70d5cc5b99..cc8c769d7fa9 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -21,7 +21,9 @@ obj-$(CONFIG_ARM_U8500_CPUIDLE) += cpuidle-ux500.o obj-$(CONFIG_ARM_AT91_CPUIDLE) += cpuidle-at91.o obj-$(CONFIG_ARM_EXYNOS_CPUIDLE) += cpuidle-exynos.o obj-$(CONFIG_ARM_CPUIDLE) += cpuidle-arm.o -obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle-psci.o +obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle_psci.o +cpuidle_psci-y := cpuidle-psci.o +cpuidle_psci-$(CONFIG_PM_GENERIC_DOMAINS_OF) += cpuidle-psci-domain.o ############################################################################### # MIPS drivers diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c new file mode 100644 index 000000000000..3f5143ccc3e0 --- /dev/null +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -0,0 +1,281 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PM domains for CPUs via genpd - managed by cpuidle-psci. + * + * Copyright (C) 2019 Linaro Ltd. + * Author: Ulf Hansson + * + */ + +#define pr_fmt(fmt) "CPUidle PSCI: " fmt + +#include +#include +#include +#include +#include +#include + +#include "cpuidle-psci.h" + +struct psci_pd_provider { + struct list_head link; + struct device_node *node; +}; + +static LIST_HEAD(psci_pd_providers); +static bool osi_mode_enabled; + +static int psci_pd_power_off(struct generic_pm_domain *pd) +{ + struct genpd_power_state *state = &pd->states[pd->state_idx]; + u32 *pd_state; + + /* If we have failed to enable OSI mode, then abort power off. */ + if (!osi_mode_enabled) + return -EBUSY; + + if (!state->data) + return 0; + + /* OSI mode is enabled, set the corresponding domain state. */ + pd_state = state->data; + psci_set_domain_state(*pd_state); + + return 0; +} + +static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states, + int state_count) +{ + int i, ret; + u32 psci_state, *psci_state_buf; + + for (i = 0; i < state_count; i++) { + ret = psci_dt_parse_state_node(to_of_node(states[i].fwnode), + &psci_state); + if (ret) + goto free_state; + + psci_state_buf = kmalloc(sizeof(u32), GFP_KERNEL); + if (!psci_state_buf) { + ret = -ENOMEM; + goto free_state; + } + *psci_state_buf = psci_state; + states[i].data = psci_state_buf; + } + + return 0; + +free_state: + i--; + for (; i >= 0; i--) + kfree(states[i].data); + return ret; +} + +static int __init psci_pd_parse_states(struct device_node *np, + struct genpd_power_state **states, int *state_count) +{ + int ret; + + /* Parse the domain idle states. */ + ret = of_genpd_parse_idle_states(np, states, state_count); + if (ret) + return ret; + + /* Fill out the PSCI specifics for each found state. */ + ret = psci_pd_parse_state_nodes(*states, *state_count); + if (ret) + kfree(*states); + + return ret; +} + +static void psci_pd_free_states(struct genpd_power_state *states, + unsigned int state_count) +{ + int i; + + for (i = 0; i < state_count; i++) + kfree(states[i].data); + kfree(states); +} + +static int __init psci_pd_init(struct device_node *np) +{ + struct generic_pm_domain *pd; + struct psci_pd_provider *pd_provider; + struct dev_power_governor *pd_gov; + struct genpd_power_state *states = NULL; + int ret = -ENOMEM, state_count = 0; + + pd = kzalloc(sizeof(*pd), GFP_KERNEL); + if (!pd) + goto out; + + pd_provider = kzalloc(sizeof(*pd_provider), GFP_KERNEL); + if (!pd_provider) + goto free_pd; + + pd->name = kasprintf(GFP_KERNEL, "%pOF", np); + if (!pd->name) + goto free_pd_prov; + + /* + * Parse the domain idle states and let genpd manage the state selection + * for those being compatible with "domain-idle-state". + */ + ret = psci_pd_parse_states(np, &states, &state_count); + if (ret) + goto free_name; + + pd->free_states = psci_pd_free_states; + pd->name = kbasename(pd->name); + pd->power_off = psci_pd_power_off; + pd->states = states; + pd->state_count = state_count; + pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; + + /* Use governor for CPU PM domains if it has some states to manage. */ + pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL; + + ret = pm_genpd_init(pd, pd_gov, false); + if (ret) { + psci_pd_free_states(states, state_count); + goto free_name; + } + + ret = of_genpd_add_provider_simple(np, pd); + if (ret) + goto remove_pd; + + pd_provider->node = of_node_get(np); + list_add(&pd_provider->link, &psci_pd_providers); + + pr_debug("init PM domain %s\n", pd->name); + return 0; + +remove_pd: + pm_genpd_remove(pd); +free_name: + kfree(pd->name); +free_pd_prov: + kfree(pd_provider); +free_pd: + kfree(pd); +out: + pr_err("failed to init PM domain ret=%d %pOF\n", ret, np); + return ret; +} + +static void __init psci_pd_remove(void) +{ + struct psci_pd_provider *pd_provider, *it; + struct generic_pm_domain *genpd; + + list_for_each_entry_safe(pd_provider, it, &psci_pd_providers, link) { + of_genpd_del_provider(pd_provider->node); + + genpd = of_genpd_remove_last(pd_provider->node); + if (!IS_ERR(genpd)) + kfree(genpd); + + of_node_put(pd_provider->node); + list_del(&pd_provider->link); + kfree(pd_provider); + } +} + +static int __init psci_pd_init_topology(struct device_node *np) +{ + struct device_node *node; + struct of_phandle_args child, parent; + int ret; + + for_each_child_of_node(np, node) { + if (of_parse_phandle_with_args(node, "power-domains", + "#power-domain-cells", 0, &parent)) + continue; + + child.np = node; + child.args_count = 0; + + ret = of_genpd_add_subdomain(&parent, &child); + of_node_put(parent.np); + if (ret) { + of_node_put(node); + return ret; + } + } + + return 0; +} + +static const struct of_device_id psci_of_match[] __initconst = { + { .compatible = "arm,psci" }, + { .compatible = "arm,psci-0.2" }, + { .compatible = "arm,psci-1.0" }, + {} +}; + +static int __init psci_idle_init_domains(void) +{ + struct device_node *np = of_find_matching_node(NULL, psci_of_match); + struct device_node *node; + int ret = 0, pd_count = 0; + + if (!np) + return -ENODEV; + + /* Currently limit the hierarchical topology to be used in OSI mode. */ + if (!psci_has_osi_support()) + goto out; + + /* + * Parse child nodes for the "#power-domain-cells" property and + * initialize a genpd/genpd-of-provider pair when it's found. + */ + for_each_child_of_node(np, node) { + if (!of_find_property(node, "#power-domain-cells", NULL)) + continue; + + ret = psci_pd_init(node); + if (ret) + goto put_node; + + pd_count++; + } + + /* Bail out if not using the hierarchical CPU topology. */ + if (!pd_count) + goto out; + + /* Link genpd masters/subdomains to model the CPU topology. */ + ret = psci_pd_init_topology(np); + if (ret) + goto remove_pd; + + /* Try to enable OSI mode. */ + ret = psci_set_osi_mode(); + if (ret) + pr_warn("failed to enable OSI mode: %d\n", ret); + else + osi_mode_enabled = true; + + of_node_put(np); + pr_info("Initialized CPU PM domain topology\n"); + return pd_count; + +put_node: + of_node_put(node); +remove_pd: + if (pd_count) + psci_pd_remove(); + pr_err("failed to create CPU PM domains ret=%d\n", ret); +out: + of_node_put(np); + return ret; +} +subsys_initcall(psci_idle_init_domains); From patchwork Thu Oct 10 11:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183229 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 9B9F81864 for ; Thu, 10 Oct 2019 11:42:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6886521BE5 for ; Thu, 10 Oct 2019 11:42:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kJE7mM3N"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yCBQoiMd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6886521BE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HN5fVYUFap/W4H3AAnd/ur4AGmuUHSUoE2Og9rWE040=; b=kJE7mM3NNSEY/hpcjSQ9I3RnWp 6XEGhzOQhtiMCArS5ismoMDzcmOs342cEjtrSRnmEzy7EhpewbGppzJGPrqmT8N/VWxT0y6mjqRus 5JTsBRcvJKyo/eZqvpB+Y9Qme8ghlkmevFxAgKfutNN7MQNLiDy+6k3V5Jgo6PFpgFVchZsHqmPkI Pi+1c+5OZVK3BHQBWqRd1GV8J8LZ0epBoW/qOQN4Rvn0jOeNwqdDwuSknzVt6OU3dCm8pYQdAmXmk u4etFXHZGCGYAKFVUS0R1jIep5BCsogKAGTsSKE97WD/oFIdbGje7Syl8Mt6CH8kjiJDDtWeWlyNU ZIcYVpcg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWpv-0004qp-Co; Thu, 10 Oct 2019 11:42:27 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnu-0002sW-Vd for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:26 +0000 Received: by mail-lf1-x143.google.com with SMTP id y127so4141723lfc.0 for ; Thu, 10 Oct 2019 04:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9/8dxTtZBh9YfBGYNaIy85l3qLceeSKusYT56QpkuBo=; b=yCBQoiMdVpg14N7nhofiE56fggpEHFr0HVoi4xdC8JzFHPbNJMS/F2y1VVTJBKZuTC aNn5dzzSU5wNfqOvEqKvJgULqbetSKXMz6OHhmqNm8eKPLJ9uhwrVNgwi3vZf8PeSsQD 4NAC2kJpAIw0djJbv+iRnckigLk6Gs+BL0XLj8AYMISeX4o2bCaJYTwmQ06ERfvFqxaj fpk1JLapasYW+8jrvPic5xbqbmZNFrwXSCRsp7aXuFdcocTPj/IHe+KDL5Wg8dtiGUzC BZgFLnw7x4uFHX7nt6HwREijg76i/aQswB1SM3165mfcQ95JTCj9nWDZCPGlYVEywnzd Fkmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9/8dxTtZBh9YfBGYNaIy85l3qLceeSKusYT56QpkuBo=; b=fGCpwGJqpIA3htPVMRP/ueQjP9kvwj+SZXEEHrKFQOTskLeyAX7G4YKConXDsLs5I3 mYqALfGVCU1nPZj4ye5OEYSeV/tgsMTqUCjg1rhAwFhCSrKgIuzHIDkWSTxrP0duf+Uw iFjk1ZJ2hwbFQ9gewXBgNq7ohcxdFIztefoRecjBnN4Fg7kI1fhCEh7sxQZtaRNvEu/5 zBbcAev9Gf6GajKw5heXUHRJy7lB0TadbAt1sEX39mDVZB/8R0sny1Mc/KgQFM/ylsBq G56B8ertvyk884NrFfg83jNHq0MSnn3ZURck89Pm7ZudxoFLWjZO21XmjWQ+V+bqAMqb Jzaw== X-Gm-Message-State: APjAAAXTKGmqeSktYjNQjBlC58HC0USA+Q4536IOIQio7L4NouCkyfPL F+ygUE3Jsehee5WQeP+JcPVzrA== X-Google-Smtp-Source: APXvYqwBURUiaefQaEsTZzx0SIkFbzLdJWKemCCeeCEH1PQrpCLnZQiGZWhUoIwrmftKy94I18IgPw== X-Received: by 2002:ac2:47f1:: with SMTP id b17mr5257943lfp.31.1570707621209; Thu, 10 Oct 2019 04:40:21 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:20 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 10/13] cpuidle: psci: Add a helper to attach a CPU to its PM domain Date: Thu, 10 Oct 2019 13:39:34 +0200 Message-Id: <20191010113937.15962-11-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044023_077901_C82E38A9 X-CRM114-Status: GOOD ( 13.96 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:143 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Introduce a PSCI DT helper function, psci_dt_attach_cpu(), which takes a CPU number as an in-parameter and tries to attach the CPU's struct device to its corresponding PM domain. Let's makes use of dev_pm_domain_attach_by_name(), as it allows us to specify "psci" as the "name" of the PM domain to attach to. Additionally, let's also prepare the attached device to be power managed via runtime PM. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 21 +++++++++++++++++++++ drivers/cpuidle/cpuidle-psci.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index 3f5143ccc3e0..7429fd7626a1 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -9,9 +9,11 @@ #define pr_fmt(fmt) "CPUidle PSCI: " fmt +#include #include #include #include +#include #include #include #include @@ -279,3 +281,22 @@ static int __init psci_idle_init_domains(void) return ret; } subsys_initcall(psci_idle_init_domains); + +struct device *psci_dt_attach_cpu(int cpu) +{ + struct device *dev; + + /* Currently limit the hierarchical topology to be used in OSI mode. */ + if (!psci_has_osi_support()) + return NULL; + + dev = dev_pm_domain_attach_by_name(get_cpu_device(cpu), "psci"); + if (IS_ERR_OR_NULL(dev)) + return dev; + + pm_runtime_irq_safe(dev); + if (cpu_online(cpu)) + pm_runtime_get_sync(dev); + + return dev; +} diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h index e593de1784c3..d2e55cad9ac6 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -8,4 +8,10 @@ struct device_node; void psci_set_domain_state(u32 state); int __init psci_dt_parse_state_node(struct device_node *np, u32 *state); +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF +struct device *psci_dt_attach_cpu(int cpu); +#else +static inline struct device *psci_dt_attach_cpu(int cpu) { return NULL; } +#endif + #endif /* __CPUIDLE_PSCI_H */ From patchwork Thu Oct 10 11:39:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183233 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 D155976 for ; Thu, 10 Oct 2019 11:43:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79F472054F for ; Thu, 10 Oct 2019 11:43:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WrTzQHaF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="y5fnfZfz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79F472054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xsov6KUz45dH+mIixgEn39ziqaGz9qhRbKJyVgAdSoQ=; b=WrTzQHaFFSaZaK0w0cCrSQzoh3 nr5JWEEplpq3t1OHufRyloChKHdVHvxFyh7B5T2Njb+5ZmLo9RCsdXKiyTe8bYTslIBedwqLoW93g ztlt6yFN/rPSO85KWYxmejarILjtLzLdzeYVu8UOHmTj6pCFxki0N0EVhAlReEl8QEcA1Q5DK+ChV SF3d8CUMTalLK7SsbKfMoTXfJN2s0jC4MM3W708/DOzF8M4Vtf3dMnfG7GGLR4kkn/4dyvsfigHIA n9FePULne5WFFEPxxInmtqMzYhBYr2lZRe/CNewGWSO6WECzQV40H8rlnxbh86rIU0xZrXcrXtKOw ZLdrIhIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWqP-0005K3-C1; Thu, 10 Oct 2019 11:42:57 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnw-0002uB-JE for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:27 +0000 Received: by mail-lj1-x242.google.com with SMTP id l21so5851209lje.4 for ; Thu, 10 Oct 2019 04:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xwB/tavfIMYf7rxHdkrDdviMkDSYXD3kklyLW60B66Q=; b=y5fnfZfzF20HGrbuklXhoX4IRAb3sw2pVHlyIgINlkZsqTCt4OVzOnIglZ5AC79CtD DsNOJpfSilfGfXZtv/tEgCB3gQiuhIGvs1zshF7zwNcTf2qOF8Fc/rMwNcZXiZTL+kw6 Yzr2TdiZrnORg1wGpq19yH9Xcs0CIUPV2lm1fsXVYSjXlq+ZlST41yjYA2oN1KG7fjS6 5gBBGJP6W0zkh27WfEp5bCy2cXFBBYwBVSQxDFzIbvzoUWu2TihJdw0pV2UQGtwkzvsY tHxQK36pjsfWSB57iJO/4O/taNsevtQefN+dNqFOeyJ3soL1660gFAXKDgtQIhwhU66S B0UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xwB/tavfIMYf7rxHdkrDdviMkDSYXD3kklyLW60B66Q=; b=rpNQmbD2CsOhknUI72gWev4yhNvBP1xIjo5RMmT+WLrVVF6etnaZvPvlHbU0U0TF4v bIacPNjR58RPdrabSErt6LmS5gKHmwGLhQiyqH9XtLY026UPmyaMlarfasJLQIGOHcJN Nwp7n8c6y418cv62Rg16IL6M14bzSiBQKAZUKSau9v53ATXpTzLkrNo48K1R5QY/nKSi adjlsVPB8O3ya1/c8cFbVcLAqXmJEKsGJdTlukNvNQpY6r0Li9piE/RCLkRFOfQr6y+V 7E4XH/e3Rf+/6TKhweDmW+Fi7TU1uiBPBVDVTgNg2by5fwBEad4okuG6pdTm7kxrgrT0 2WGQ== X-Gm-Message-State: APjAAAVZg+dCnxGtiL4Vzt3ATrUxdOp5OwVisX4rvYYPbL97Vw3IZGf2 UL0Mr4eg7UAIcIFFTqLqhdXW6Q== X-Google-Smtp-Source: APXvYqx9XzUujAF/LwxrlZOzoBs1q0AvlrOroFuQxRIn7MA18US1H4Ia1dTMLsrPBuGfqUBKeebXeA== X-Received: by 2002:a2e:9f4d:: with SMTP id v13mr6239064ljk.226.1570707622756; Thu, 10 Oct 2019 04:40:22 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:22 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 11/13] cpuidle: psci: Attach CPU devices to their PM domains Date: Thu, 10 Oct 2019 13:39:35 +0200 Message-Id: <20191010113937.15962-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044024_682507_DDD2048B X-CRM114-Status: GOOD ( 15.00 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In order to enable a CPU to be power managed through its PM domain, let's try to attach it by calling psci_dt_attach_cpu() during the cpuidle initialization. psci_dt_attach_cpu() returns a pointer to the attached struct device, which later should be used for runtime PM, hence we need to store it somewhere. Rather than adding yet another per CPU variable, let's create a per CPU struct to collect the relevant per CPU variables. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index a16467daf99d..1510422c7a53 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -23,7 +23,12 @@ #include "cpuidle-psci.h" #include "dt_idle_states.h" -static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +struct psci_cpuidle_data { + u32 *psci_states; + struct device *dev; +}; + +static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); void psci_set_domain_state(u32 state) @@ -45,7 +50,7 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { int ret; - u32 *states = __this_cpu_read(psci_power_state); + u32 *states = __this_cpu_read(psci_cpuidle_data.psci_states); u32 state = psci_get_domain_state(); if (!state && idx) @@ -103,7 +108,9 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, { int i, ret = 0; u32 *psci_states; + struct device *dev; struct device_node *state_node; + struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); psci_states = kcalloc(state_nodes, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) @@ -128,8 +135,16 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, goto free_mem; } - /* Idle states parsed correctly, initialize per-cpu pointer */ - per_cpu(psci_power_state, cpu) = psci_states; + dev = psci_dt_attach_cpu(cpu); + if (IS_ERR(dev)) { + ret = PTR_ERR(dev); + goto free_mem; + } + + data->dev = dev; + + /* Idle states parsed correctly, store them in the per-cpu struct. */ + data->psci_states = psci_states; return 0; free_mem: From patchwork Thu Oct 10 11:39:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183235 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 F041C1668 for ; Thu, 10 Oct 2019 11:43:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CDF0B2054F for ; Thu, 10 Oct 2019 11:43:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GBOskwPp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S1K49Am4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDF0B2054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=laVWgwsn9aOxL+HNXa4EAgsQ5pIbetoULymklLkKWss=; b=GBOskwPpOM4DLCRx5Afc6ycfF+ p4r1Uq5m4saiy12Syg999cEs2ZAg7F+WdvwHDa44kq7GtNo7SjQvndJhCwdAOrL+wxTpLK1iW4pVi fqFWJ2gicxO1PnxTlD7b4/KJB9N5Gqc5wv1iwTryUHY7tEzxiIsQRWi8drPp/gxVCtNagx5DHFIZw mtGp6qmNKLawrd5Y0OglPsmQijNCZdQ0aqPB7M8ZpXIp1qmow4H8JWyBEHPd7tMiEzhUG0UJXzsg6 qsoSmD862nASyV5t1jB/D8lH8YcZLy2w3UczTFQvBNhCkMZWmnf2dTQZLPP+EohmJd+79Y4te2y9v t58XyFzQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWqh-0005Yg-0U; Thu, 10 Oct 2019 11:43:15 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnx-0002vT-Pw for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:28 +0000 Received: by mail-lj1-x244.google.com with SMTP id f5so5832578ljg.8 for ; Thu, 10 Oct 2019 04:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=S1K49Am4kSDehLMFo+y+aCn++SGdGyNEXyDKQRhsyEPFb1U+Qix4b9k4PUVRkwMwNo H1Drcbx+EDc2EDWjdPplZZWExubE/UfjqHL/TFs1EpwMdzjNtIKS46NPjhea/SBAVuq0 ayS5Uvhu+BLV2F9mmm/wYqmAwVyQLTTLhdmXercedrMYUeL842KegEAPuu1HoOsC5IYo wCEzh1VrCwNsmAM5iFSLdMYtQZX5h9kLTbBXKGX6RsmAHRa+SZp3SSXIEoYZ89kE7QUv Ygj6ExCVVuMj5lOyunwckLd0vQXnx7AbRGLkFUfRtC+bX6wI8fQg8yvPZKfW/oaWQgOe QXPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=NBvgKy0V1ZnrGloeDtGZ+1c8dbXx19pO5uyLOHldnl1+5YW/pbs88YkaXq9EGvYuoM B93cCuW8xlpaLyBPx9ezMGzl1OBpwqC5BDZFyqqwtjNh3VOyJOoxCvfU2BYkYXiYwh0P YVa108Htef1sH6zZ2US6Walvvp2h9Ikkiex2/jOTFXrJHIs8dsQQOowwq1XikaoP2Xbn z2x8zUqUp9SPnvS9ln8Np9mYxJcsh52s4STTY9YnWQyEsiwDMumfQXnlFSYv/uyOJPb1 pe83vE+7ukDNs+g9gGq7bff9puNI/+VzLQfkvr2ilKeiE9p3oKC1N20zHZI9DtLWqOiL 87XA== X-Gm-Message-State: APjAAAVgqySA2ySQq7uDDvPfZ1/DWei0Fs3Few2kF6BbwjECHXKSa6Iw 81ZuzoGefT/EXBQaapbI2QBTIg== X-Google-Smtp-Source: APXvYqwOX8ItiDZEA+kQQBb68Jv+sNmaYtISkfDtd1UlzUU+vXQj3Y0mD4hDx6nLR//tbqlRlepYnA== X-Received: by 2002:a2e:8310:: with SMTP id a16mr177041ljh.48.1570707624283; Thu, 10 Oct 2019 04:40:24 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:23 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 12/13] cpuidle: psci: Manage runtime PM in the idle path Date: Thu, 10 Oct 2019 13:39:36 +0200 Message-Id: <20191010113937.15962-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044026_084005_06601CD5 X-CRM114-Status: GOOD ( 18.55 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In case we have succeeded to attach a CPU to its PM domain, let's deploy runtime PM support for the corresponding attached device, to allow the CPU to be powered-managed accordingly. To set the triggering point for when runtime PM reference counting should be done, let's store the index of deepest idle state for the CPU in the per CPU struct. Then use this index to compare the selected idle state index when entering idle, as to understand whether runtime PM reference counting is needed or not. Note that, from the hierarchical point view, there may be good reasons to do runtime PM reference counting even on shallower idle states, but at this point this isn't supported, mainly due to limitations set by the generic PM domain. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 1510422c7a53..0919b40c1a85 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ struct psci_cpuidle_data { u32 *psci_states; + u32 rpm_state_id; struct device *dev; }; @@ -50,14 +52,28 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { int ret; - u32 *states = __this_cpu_read(psci_cpuidle_data.psci_states); - u32 state = psci_get_domain_state(); + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); + u32 *states = data->psci_states; + struct device *pd_dev = data->dev; + bool runtime_pm = (pd_dev && data->rpm_state_id == idx); + u32 state; + /* + * Do runtime PM if we are using the hierarchical CPU toplogy, but only + * when cpuidle have selected the deepest idle state for the CPU. + */ + if (runtime_pm) + pm_runtime_put_sync_suspend(pd_dev); + + state = psci_get_domain_state(); if (!state && idx) state = states[idx - 1]; ret = __psci_enter_idle_state(idx, state); + if (runtime_pm) + pm_runtime_get_sync(pd_dev); + /* Clear the domain state to start fresh when back from idle. */ psci_set_domain_state(0); return ret; @@ -142,6 +158,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, } data->dev = dev; + data->rpm_state_id = state_nodes; /* Idle states parsed correctly, store them in the per-cpu struct. */ data->psci_states = psci_states; From patchwork Thu Oct 10 11:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11183239 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 0367076 for ; Thu, 10 Oct 2019 11:43:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D5676208C3 for ; Thu, 10 Oct 2019 11:43:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qH21DFDZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ttocmxpO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5676208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hx9k121QeWza7amdRSCByPRpXVsWt16FrVIUPtg6TCw=; b=qH21DFDZLpUf3cTySg442GNO9M iKNh7CbnHdt8eg/Wcb3GQ0fqi9gtu2OWN9j7KhCGNDeDBFC+SJ43buoEqaZERKLNeep7U0GYLVrqm Saz9HLcF2+wCCFUFYCrNbt19iP29gpqdIrmhu9u93WDiqLGXpMfnEtuunoCdljtXhbEtbxRUi9mgN Y6SEodXwnTyEOZUveMzkiR/yZK2M5LJZwYd38b4/WEru11A9f2Wrp9YL6O/wlfReb+eXzfCn1pVeK ZsQ0MdSc6vTedq+f5nind+UNmyFo7gAiDf5ObfmkGkiZnXeYbi3DQ2l/IXa8YS8nWFUrkmzEgQnfu VuAPdWVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWqs-0005nQ-94; Thu, 10 Oct 2019 11:43:26 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIWnz-0002wf-Lg for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2019 11:40:29 +0000 Received: by mail-lj1-x243.google.com with SMTP id j19so5886440lja.1 for ; Thu, 10 Oct 2019 04:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=seqtCL6qQP1lHpVV6JxVbCofE6J8aEcyzCDtbKaRiuo=; b=ttocmxpO4BTiaii5K7cn0npU6eVhqZ9uMEDMEG7dnyW79epK0rCXS/lpw4SkqbYIYg W59Vn7rAze9cJVsyqKmksnN9Di4v2QsCN03gmrmsqBwJ/hkNQiPz0b1pmIgAI601KtUS aSppXlnpANOGQrmU9eDiPdCo6OV3bH+oi46O/xtlYtnNSj1loyozvQ3GaZcs7LOYfHih 30F0tcFKMkGwAo2oAQogPCkIcT9AmDSJ9rlR/88iiStn7tuBkFUijM/paQ7/7P3O8FJp cMKAdQl/TnVG7+eXCp+OBz/Zuzksl0YdnzPxvlspzR/jpoJqQbicu/XpqqncUNiFreNm lOHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=seqtCL6qQP1lHpVV6JxVbCofE6J8aEcyzCDtbKaRiuo=; b=ToNT6Ihm0rO/3YRXGdnbQ/r8NFVkLOi+7ZtNxfsY0AcmIyyjw1dL8CNZ3DZxZseUzh mwzYRpNFFM9uVX+Dn7iZUHIUXN+Mz3u8lL5RX7teOnzFFdLb8AR1Otup63QUwzkl0pnB tt7/SdWKw7bVi27lvzKIMTMsvXlbvbLrSwa8oI4yYYjtrX8Q0/CcOpYxPE90cAh6EUZZ Ruu3zTQWGI7AzaBrxMhE2O3VWv5CqG1yCdNjZQIBcn6KVDKRoen11nnRRZXaHB/+l99S 8rSX7D5bBqCIvkJSv4Zs31gUw7i7MlbnM0H4BWi9RFP5vxvmRQHSm+4tjOpoSbnvDjjF i0kQ== X-Gm-Message-State: APjAAAXZ/jUTGhzweAtHnjOAXd5s15Oyu6iwPQ5ZovpT/PYpLzN0FpWS 83WO7rQ+2VcxsGvxg5KQADg9Avfy73M= X-Google-Smtp-Source: APXvYqzAtQRFaFdOYUhWXaaCWhBIREvEFZI1olu/oFVmp742iMrFKC80mDD/KfhtuHeGyAmVXW6Erg== X-Received: by 2002:a2e:9205:: with SMTP id k5mr6239604ljg.202.1570707626147; Thu, 10 Oct 2019 04:40:26 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:25 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Subject: [PATCH 13/13] arm64: dts: Convert to the hierarchical CPU topology layout for MSM8916 Date: Thu, 10 Oct 2019 13:39:37 +0200 Message-Id: <20191010113937.15962-14-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191010_044027_805667_505605C9 X-CRM114-Status: GOOD ( 12.18 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:243 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Rob Herring , Lina Iyer , Andy Gross , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org To enable the OS to better support PSCI OS initiated CPU suspend mode, let's convert from the flattened layout to the hierarchical layout. In the hierarchical layout, let's create a power domain provider per CPU and describe the idle states for each CPU inside the power domain provider node. To group the CPUs into a cluster, let's add another power domain provider and make it act as the master domain. Note that, the CPU's idle states remains compatible with "arm,idle-state", while the cluster's idle state becomes compatible with "domain-idle-state". Cc: Andy Gross Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- arch/arm64/boot/dts/qcom/msm8916.dtsi | 57 +++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 5ea9fb8f2f87..1ece0c763592 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -102,10 +102,11 @@ reg = <0x0>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD0>; + power-domain-names = "psci"; }; CPU1: cpu@1 { @@ -114,10 +115,11 @@ reg = <0x1>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD1>; + power-domain-names = "psci"; }; CPU2: cpu@2 { @@ -126,10 +128,11 @@ reg = <0x2>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD2>; + power-domain-names = "psci"; }; CPU3: cpu@3 { @@ -138,10 +141,11 @@ reg = <0x3>; next-level-cache = <&L2_0>; enable-method = "psci"; - cpu-idle-states = <&CPU_SLEEP_0>; clocks = <&apcs>; operating-points-v2 = <&cpu_opp_table>; #cooling-cells = <2>; + power-domains = <&CPU_PD3>; + power-domain-names = "psci"; }; L2_0: l2-cache { @@ -161,12 +165,57 @@ min-residency-us = <2000>; local-timer-stop; }; + + CLUSTER_RET: cluster-retention { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x41000012>; + entry-latency-us = <500>; + exit-latency-us = <500>; + min-residency-us = <2000>; + }; + + CLUSTER_PWRDN: cluster-gdhs { + compatible = "domain-idle-state"; + arm,psci-suspend-param = <0x41000032>; + entry-latency-us = <2000>; + exit-latency-us = <2000>; + min-residency-us = <6000>; + }; }; }; psci { compatible = "arm,psci-1.0"; method = "smc"; + + CPU_PD0: cpu-pd0 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CPU_PD1: cpu-pd1 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CPU_PD2: cpu-pd2 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CPU_PD3: cpu-pd3 { + #power-domain-cells = <0>; + power-domains = <&CLUSTER_PD>; + domain-idle-states = <&CPU_SLEEP_0>; + }; + + CLUSTER_PD: cluster-pd { + #power-domain-cells = <0>; + domain-idle-states = <&CLUSTER_RET>, <&CLUSTER_PWRDN>; + }; }; pmu {