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: 175746 Delivered-To: patches@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp2186059ocf; Thu, 10 Oct 2019 04:40:07 -0700 (PDT) X-Received: by 2002:a19:f11e:: with SMTP id p30mr5367364lfh.152.1570707607212; Thu, 10 Oct 2019 04:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707607; cv=none; d=google.com; s=arc-20160816; b=QDyPj2FxgrO6VxarAIie5lK90PEUzQ9jfcoqwMpUNoIV3RH84PLKFa1NSyCdcVqSi1 6y0esSIwe0FTY1hhFWaM5qkQj0sGyy7ydxCt3PkngZE4Y05RQJRcN6A4qXRm3aPkWWyn vl0VmRM6vLLaX4DyibeoBsuNlUG1XcmGgOepJXvJVvVB9MjHFh+cwtjQwXQyLK/CGSzw BNCxjnbCyEsmudsjO87CO2JfTTDFRkvwNgD/1W+txWNs8zkw9MYDmdugVX0JeHSkdtMv OQp5/yhgnFja/7Ci0TU63OEUfRjpAnQv2uB09qoa3z7CkQXFoPwPmefkWPPuChpbtfHX IPmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s32JeDhVlasQJ6pytWlkQPUAMG4/wlRqEgRTpBOYoJM=; b=ChtKyZ8rfrnqIChfQOBVrE/YuygqeWtEzZn3z3HEMZWdD3KKS/6rofVyCSnLCdJGws 1TDan6TWEZD5Ua5fKIhEkskEPA8TCNnjtev/frIrKBsSMGY7FtqzlbGo9f8Nhzgu4azU USYzVQBGA4kjMywAiLCMr74aURZayXH/VW/SmPgmJlyWLq3O23qQVF5W7AaUWUky5jgV BMnof1M1GsKWGRcatvSUBJocAbSTh2pFdmJWyxys90ZyXwuLbDeBAdLl3MUwVVcaPb9X lEdaSj467ZMOljY64AQQHQ0+8qs33Z+nDqMcC49uIVlPP/w2/xjal40pbyxH9KImj1HN iDiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oY4GQ9ts; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y15sor3293601ljh.48.2019.10.10.04.40.06 for (Google Transport Security); Thu, 10 Oct 2019 04:40:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oY4GQ9ts; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=qv9BTtiVwkzS+LLiBsg6bKufk39KTwLZUsstrv+kstJI6QY+uUGtYQmCYjZ7eVyYNy VaLcOVe12ALu+ihsv7sAqKMfHyKAuat6p1C0nhJ/tvvcd3SvqsuNFPznBkD0XgXl/AS/ mN2S6jXqhwxEXMWpwXUSQmRAd0WJ2kKrEhUhEX9xWQNYy2eW0N7s7CTjxGGQO+KLgbA7 v/LhczHpsbON2O2ArYot52doxaWkiH5+7pvRvxgWuwhK4JNJVb2i6Qe78hlRd4Wmyt// zybGf8rBI/az0dTLgzYiu+/EWe1Jk3lpPlENnJbAYk+1rxCMsStUtKV+Iwxp8HadMPe8 b7Sg== X-Gm-Message-State: APjAAAWDdJIa3nE/OfzXUTOd1ONPh3P44lLExxrLaSVd7pUEZI4t+/oz Bcp5bfIhTGAFr/S5k2xJ3l10+7iIqDJq0Q== 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) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:05 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 01/13] cpuidle: psci: Fix potential access to unmapped memory Date: Thu, 10 Oct 2019 13:39:25 +0200 Message-Id: <20191010113937.15962-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> 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(-) -- 2.17.1 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: 175747 Delivered-To: patches@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp2186088ocf; Thu, 10 Oct 2019 04:40:08 -0700 (PDT) X-Received: by 2002:ac2:4550:: with SMTP id j16mr1148503lfm.126.1570707608585; Thu, 10 Oct 2019 04:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707608; cv=none; d=google.com; s=arc-20160816; b=yQu3n8zsA3kzaAMrq8gx2P9x3chI3vd+CAN3zK+IODuwZDy53ywsVtg2v9KfYDQiod PhHquhV+dX6xtI7GE/DVTIxmetFSt8pmpoRsDfxQhAWLFRQfGKiASJDq+lY4pSqJQebW SNkJQDXypCjS2yG4+YpBSy5o8lpd5wVWfzj1T/R4VwVMWrVT8yAu6NVIYu9QJWFp9uz9 mdbwqy74EUsFLFCzhN0SlRrF+hNrCm3NjcVDlWmdXAQFQbWOBh3ODq45XFRmP/n3V3xr 001hDWjGdC995vvHOHcl0uPU2nrBYbc2G0Jwgd8RGOiKQXFDS74myqxtJoZDnACvDOv7 fhIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jyY5hfR8/N8coo7i/Rw81G3nXo/cAyXblG5DM904HwE=; b=YynaUgdeYCC3Ur7HAaMlIRYutCArmnwEIheM5ZH8l01Exh1h0WeWtOeAPKHm/rT1vr yQRKc8YRgFWXtEpbQMDO2OjwnBG55VLofEaYMIlSUfP8Z+9762WOJRZ0JJMkcQBUI5Qd 7hDfWHgFbzhunzbp/nsvqQfR6QriCgiV/i8ImSyXZBv2dARTrb5hj96y6JaY3y8e5tiP TGICB96oBuRjgy2Pp+nX5SWhtxD+O2iKpWPmRlGspx4AvXYrF6B77Hj9a4VEBUOCd+zS txXtOAllLYNqnxUML0kXlOUaxpiLAQOV/eCw1wW5UGgcaQI7hNLmNgbEZlOYM7emFHbE h0Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OgHOnIF/"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a13sor1689216lfi.53.2019.10.10.04.40.08 for (Google Transport Security); Thu, 10 Oct 2019 04:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OgHOnIF/"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=UIQyvrGzJ3eHcUVM+yQ9prFb1t49v9arkGnVQ4P4R5qDNF+OiEwjngocVht5tx0Xga xz2mx76sm/VnGU1U5vQ9EIiNT6LETUn4FFOrFtlkegAo5ut1c0bmlOlrgEoxQOLGcVGh FoF2ghr7OItWQfq0m1hCJeCYL2VO7RXzqqXi3nkwvcTC+BitPmz3c/S1VlX0L5yTAaSu IuvrdPrnUM3HpkASVN4TXtEYXSSZ9PpGAvIBxlTgIMtm19jE/kbYDCJiv8btzu0AOPT0 rj6XA0ydUYrlhvu5LBDoG2oriU6Qs0bWxtWwmh6GYC2RIAT0NLB5R/WB3iaugoWlMtSs BHXw== X-Gm-Message-State: APjAAAWfGSOtRLeEPoMUqsyz6xNA7eXxzw4nrZaYfoL4sQuMQPMTn3C8 GIp41HBJ1dVT8Lqt0c8GVOTmmeKW 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) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:06 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 02/13] dt: psci: Update DT bindings to support hierarchical PSCI states Date: Thu, 10 Oct 2019 13:39:26 +0200 Message-Id: <20191010113937.15962-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> 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 --- .../devicetree/bindings/arm/psci.yaml | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) -- 2.17.1 Reviewed-by: Sudeep Holla 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: 175748 Delivered-To: patches@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp2186119ocf; Thu, 10 Oct 2019 04:40:10 -0700 (PDT) X-Received: by 2002:a2e:7a18:: with SMTP id v24mr6235970ljc.75.1570707609939; Thu, 10 Oct 2019 04:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707609; cv=none; d=google.com; s=arc-20160816; b=DASXXLbwZ951jO0f9Rlba+7lOOA4dS1AKIT1rbbt5Il74Co3J+dXHR3qWBwYsXuKC/ UuGy26yjYsPOTDYWlZFzZkuXBx4f+olvVJwnNSN6aU4qsGOdhSvxesuYebuO2uBmGemd 9/K95WawXOQn2jf8QgipE6nxMJH6dFxLailubjp0kCWpd+TGeeZKPGr31ah3wlmRFPGf xMi+/VKORpUDT9hc2I3WAQCc47kwJLaPxhgSmQPoC8Udrz5Q/HIErSsGyqfG5ZOTaUCZ NXHJzyXjH8OHtBElbSoIioIC3oqD4AeDOMe8Bt/TlZM7ZE3bnyuxY9Fu2lbHkVK5N61r Eoig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v88JQU6vGgb8ri6uCDKoMwVq9Ia/h8wuaSmlcufCmYU=; b=VW1KofKDVbWOyirY9PH56Q/oea6qMdz43h75I8ht4nfgI4XvMVMmylhIZOzLhLgcD5 bBzF5k2TyIyyKsfBu6S/I8ZwAiRjV5dAy+2va1n+IOTBv9OKM+OyDAYkzI+rptvSykNl kVNx8aNoLt7/os4phbUC7RyYzQYvLlYU/0tAz/2ErMDjr4DBybqHwMX58g2nkw+ojGrz Hidg1inkumbacVtgRbiTNcJ1fImCl7DRDnxd2yX6abpT4KmotL1PBNIZMmp1C4pxF8Od fHINqGIT1VnUM/TdHNjjMbRwKxKFKcidniH+7n9cjh8nyBPtJBnAw5jAqD9dMIeoVEX8 TsjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jt87ZF+5; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b11sor3282933ljf.26.2019.10.10.04.40.09 for (Google Transport Security); Thu, 10 Oct 2019 04:40:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jt87ZF+5; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Z5JqeWiEe8cHAWBu4Nb9mL8v0Xn1kSsTUJwrxP5o193N1hGHJW8fypK5L+xBrISa6R //ucWKjnzwp8AQnenwOIrPGzTiZsrwH1LG0AMbOvRXOqLDQPsIHwv4mvnj64Ku11HyrI kZHPjH8itZ+uqOTh8Jn55bU4lxLbw33JtqYj2fgH8NIwvLWohyBoPZf09Y0v593fYB4L XpU9F7giCrCWYOIDrE3hVNyZ3Qu/IxV3E/HtVJIP/1Gqm6/dbkl6waieP52DxuRxUJcx RlK9f3EKnJJGKHU5gK6mEAqXaIp4qRDxw9dby4/E/Vm+W3td6qKIr6UE53Ubv7ad6WlG rOKQ== X-Gm-Message-State: APjAAAVcSEwuROteTWOIXqJoKEc4X4zoJ42mdNFrE+rouYY4RYHL2D4X f+rxxjhcA+UA++sH00W1EIiHus0B 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) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:08 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 03/13] firmware: psci: Export functions to manage the OSI mode Date: Thu, 10 Oct 2019 13:39:27 +0200 Message-Id: <20191010113937.15962-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> 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 --- drivers/firmware/psci/psci.c | 18 ++++++++++++++++-- include/linux/psci.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) -- 2.17.1 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: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: 175757 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2163093ill; Thu, 10 Oct 2019 04:41:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4d4liC8XQ0x0pUAD5vJ28+S1RpcgfjnKC7CXvbyhHh39a42CgLwbqtUPmf2lH2YXzgcaO X-Received: by 2002:aa7:df86:: with SMTP id b6mr7595989edy.107.1570707619622; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707619; cv=none; d=google.com; s=arc-20160816; b=gqqwYE3w20JoCcNM6ZlVxxYFHhxV8gyiWmxnjZiVBL0tOhN8ewpaMv+8niL15gMZaR C0Zwi0pJbrINl4d3/ID+8OnL9wo6msCnyabx9AyTVLRdpS+9FABC5p0xcfYHUjwooBd6 jrRwovMj9Z+EzocyajuGNSE0aJG4KjzUTxZr8JaLALPorfqh7gJGZpC93mWk3XiQF+bG 3cczuituKXzcb1D/KUH9xAZSvaLglCu4MoA3mCCqNgOEYuuh2SVk9x7DbmyaKH3NK9RF AvkjOnBhTdQA4yNnBa6voqZWK44IRimKG/TnOV+eW1kSLN060QorTGjfboi/4Tu/wjpT 7Ocg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=ferRzGdOQ81RhJ8JYe8eHCY/uZsagndf/mBJSw74io2lN1UR57SY2RniznRryl02Fo z++L7SdPWW/ajAWq5jt326aK8gQpxJQwddsOqxrBxvYcdfyU2GJjeE6wmi0uC8nqsg5s 6qfUWvtJ20hIzaefpudNN5+AlcuMMTkbdMhNV5NHnQikwk9e04YqjNjel0nHaPMnkomr gMwJG/+CFn5llp+J9XiSeXanTil90kt0AkLqS7RUByfXhTtaEHeyhfcPTYzZv8rs7t3R /d+zIoxr23Fn8qQbKOuP7ur1gZFtfTq2XdURGLEtUzKF7eEAdBflKdXXOHpkXkp9G4HD 1AFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/wpfkf4"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c60si3016856edd.327.2019.10.10.04.40.19; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/wpfkf4"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732838AbfJJLkS (ORCPT + 10 others); Thu, 10 Oct 2019 07:40:18 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39677 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728912AbfJJLkS (ORCPT ); Thu, 10 Oct 2019 07:40:18 -0400 Received: by mail-lj1-f194.google.com with SMTP id y3so5843002ljj.6 for ; Thu, 10 Oct 2019 04:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=w/wpfkf4JD7NtMhgYW5bka2jwABBrG/zFpdfSK+C6Y8ZEzk1usOy+0SZ037SEiwojW 8ikm7DR8YcoaSKOsLXm8/4fAoU66XIkDrdXmlfD0bKpQ4pPfXVVdHhNQ8eWlxdKdwF8m 3v9pJu7MyhXBh0O8lxuIkg9S/oSY3v5jPH/hUxyxae9He70A2JNrMcErYiipUzzxW6la RPJBm1dTBVGovcLV6kmCCd3lqZrimb7rDvRlZSKv2Ch/iQaQuACu1Dssa3Z+C2w/ecWr XF0jqnbdyn9OWFCh7gZX9bj7CuKUEM3iw2jfcQG61bDXCjKqE62EJgVMKO9gnqC4ni9I rSlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=XTiiHPaca3zKfvED602tFMW3tgK1ZoBUOflcvaMo/6Zbf/FYVHZHdQZS+rthdaa11s CXn/AFGvjCcm1WErZBV2mQlVxXFawqfJ/KB6iK/HFIQrZESH9quYof+xRRkJ26ATiZBk 6bc8bdOamR9tc251oTt6sv/KHngKokwp5NaGiYYHWpo+1LZ2W5jV0ieV6bxk5RtTa9v3 vwnrCYhDx3k8FIkO8djNeWUDsyCh2S6WermMgYFTwu3pMQD9m+2k5sR0zzUSgTSWLj8h S/rJtqj2Ih1nNW4lpInXqAWp5kNOuUZl8ovaH6IYp+7nE+DsUl4/X0tBUbdT/vKFsR2s Bpfg== X-Gm-Message-State: APjAAAWLtMgJ9VD2Eg5AcWEaNColfaYnbE7gIrP+oSrB9mTzjqr7J/18 MyBn/pOcj63VkziHGAHgM2VbLw== X-Received: by 2002:a2e:87ca:: with SMTP id v10mr5973843ljj.43.1570707614837; Thu, 10 Oct 2019 04:40:14 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:14 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 06/13] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Thu, 10 Oct 2019 13:39:30 +0200 Message-Id: <20191010113937.15962-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Iterating through the idle state nodes in DT, to find out the number of states that needs to be allocated is unnecessary, as it has already been done from dt_init_idle_driver(). Therefore, drop the iteration and use the number we already have at hand. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) -- 2.17.1 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: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: 175758 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2163579ill; Thu, 10 Oct 2019 04:42:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9hfZVYhMaq7JZlLro5PJJBAjGyGy2R09UrtIdpmm1EzPVdF96e2Fws//7aZish4OdgqXC X-Received: by 2002:aa7:c587:: with SMTP id g7mr7599485edq.151.1570707624158; Thu, 10 Oct 2019 04:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707624; cv=none; d=google.com; s=arc-20160816; b=E/ammXtL3ezbf246l/D0+H4S2Qi7nLNmduOnxfk4dWEpvAIjBlQVRhrILRg9V6HeqL a5cahCCjqdEAEyDoisSHPEzFD+jKmbEksJaCFAEbcIU/fyCt/PXqXRNFM3YIpz9VQqRg gI7yFzU2+3hUe8ifyGwlN7QqxF1G+3A8mbrcqTJdEBcXZZvLsMpBlz8Cyls/eXiV+6sj bvIXI+lmW0f/v+C1qwe/mUkpO4Jv8emWmisdkMdhT0OhzyQfUKGxijuWv7QEB8xH2uk8 RaA4LLZ4mN3Pir24nrKoxoz5isK/3NSB2CNg1TLRV9RFmKDO3T0Xmmaq4hy7nQy2zv/A sJOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=FM3+WiJ6iFDLSU9FwKlOgJvQtfVkwnhZSU29ebVJoP1+rTBjJdWIij5wzQxm5bOCqk NMVvYId73XqAPG3FI7AguzLLPpYUqhuYj04Gg7cDZx9OokHTrBaieyBJq/3rj9mnrVXs PnqWEJ4zGKayX0+z8RBJ37CmaYKwj5OlXOHphO7t38MK7zOFkEWAHJQPF6EwdGWGyZM8 qmio/nr4ijul16pyMpnQGjqF5TN9UePuvmGm5Y9/QUkM7eASz6t/NpNqqGIGNXx1x9OB LlIibpu7XEBPIXOUTfmHx/nmSwag05voyk9zcsO1Huyxl58O1CDc27nOdXRBw7XkTw4u gxDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pmkfwxka; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c60si3016856edd.327.2019.10.10.04.40.23; Thu, 10 Oct 2019 04:40:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pmkfwxka; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732671AbfJJLkX (ORCPT + 10 others); Thu, 10 Oct 2019 07:40:23 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46219 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732863AbfJJLkX (ORCPT ); Thu, 10 Oct 2019 07:40:23 -0400 Received: by mail-lf1-f67.google.com with SMTP id t8so4087880lfc.13 for ; Thu, 10 Oct 2019 04:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=pmkfwxkafYHpSiVu7Ke8qyTAai9lSVf06gP+DuoqVBCdmPXeDGwnD865H9L/eBz4ph Mc9ompj19KSeeGD0zY0gJs9/1NRziZ4G6M4cVNufONzPB091FVd+9U8bfrnXLjJGKtE9 pAQYezMrOQdjnwzzgKZmW5HKmYTuct69TUSjXw6+GrU/YHAfNCanJ6BDM38VmVxYsNbc cbh97OXyVvfcM6T5W7OaMF45PzJqZu++xoLU4W8ssiLmHyCzUXnjiE8RbIu+qjux57Tp ojfn/CavWRGpl+nUU0gmPejv7qQMlHjHX1NTievqsgP/5MBWzAGS8nANRqEZI38DpQ9t FjqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2v9/BZjYcJIdE6oCC/CcRM0giFXsQcqyknGG6jsekOw=; b=DMf77cSb2PjCHyeSI5TLhwDnAJG/z4ZPSf2xnzsFFuvf1VrjbYRcmtms7a5QhCmMxb vmA9BDbC3OSbJl9hbYF2Z+Y3qWV5Y9qFTFh2iqeJ11DkFFy0YstSvZx62wSAmtlBUoQS R7p5PQeV9kEYEcSHVT+3MXhU2a/9xI2b9hCAZYJE+QMPRi/VSptufz5L03+94Gcw+JiF V2QIm3zfX6rwMGy31buXYda7V2zi2hXhF6GMIm7yIRbAlldUhfPEscNrO0hF7Ybng5YQ xYugbyrXphtDdMttOociRoFRvKuRWGUqM96QlGXlJcgvtcO+/5Lp25X4bWWm4YK0Nq0b A3Eg== X-Gm-Message-State: APjAAAUQl0HTku91UmN+q341N0/HqU8I/k9Sd1Eeonl7hWvZB5IwUSxT d0E6q0S3YXbIwa4pd2133DiUdQ== X-Received: by 2002:a19:c392:: with SMTP id t140mr5888002lff.156.1570707619664; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:19 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH 09/13] cpuidle: psci: Add support for PM domains by using genpd Date: Thu, 10 Oct 2019 13:39:33 +0200 Message-Id: <20191010113937.15962-10-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When the hierarchical CPU topology layout is used in DT and the PSCI OSI mode is supported by the PSCI FW, let's initialize a corresponding PM domain topology by using genpd. This enables a CPU and a group of CPUs, when attached to the topology, to be power-managed accordingly. To trigger the attempt to initialize the genpd data structures a subsys_initcall is used, which should be early enough to allow CPUs, but also other devices to be attached. The initialization consists of parsing the PSCI OF node for the topology and the "domain idle states" DT bindings. In case the idle states are compatible with "domain-idle-state", the initialized genpd becomes responsible of selecting an idle state for the PM domain, via assigning it genpd governor. Note that, a successful initialization of the genpd data structures, is followed by a call to psci_set_osi_mode(), as to try to enable the OSI mode in the PSCI FW. In case this fails, we fall back into a degraded mode rather than bailing out and returning an error code. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/cpuidle/Makefile | 4 +- drivers/cpuidle/cpuidle-psci-domain.c | 281 ++++++++++++++++++++++++++ 2 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 drivers/cpuidle/cpuidle-psci-domain.c -- 2.17.1 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: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: 175756 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2163052ill; Thu, 10 Oct 2019 04:41:52 -0700 (PDT) X-Received: by 2002:a2e:b4f7:: with SMTP id s23mr5770302ljm.111.1570707623470; Thu, 10 Oct 2019 04:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707623; cv=none; d=google.com; s=arc-20160816; b=BtJatG8PHDVTcU8Tx6qEzSOJDPpw5PNB5I4u8QMDxwLpbEHYU+AKbsQ3pHHbaYQ6uX th+N99jTFz13hM0lyHkFt/h+7ZwRc4C2Z4iA984qPXf32QuvgrO23H8QCGN/Er/XRL7V S17QkWjWCy+JVnYu5zm5dPxploz/AsvTuRXxQsTrGZJCm8Xmb8fzFzfpjEeF0q8iLeJl RTJ5CxeU2tkwAyhfal8hOMM8hBcNSdRSrtBCsOqg8UVGf4J2z6Xq+7MGrFPXzIHEvv6q /XAJoYmkZHHBCRr5FL2i1ZC+hWql98BZQBXWZ9O4E2DZ9hoeNjeD3z9sJC1IInbf4+dQ 0r4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xwB/tavfIMYf7rxHdkrDdviMkDSYXD3kklyLW60B66Q=; b=q6Ad0UAsMOpYLbeP7uKwTM4QEpsuNHn6eQz9Fq7mfn3CMPREc40D7R4pTEpjSb66aG hZ9o8Y3sBrR6HBe9kxoO/orRQ04UP+FCtI7aao5BkU0SJ3u4RhqSLfYgDQwgUiw/hPXM DkhmPpNs5nNYjz1IP5VvELUzSrg42TJpvIYyrlcqQl/6oRbSA9DYBuglgN4uPvHc04rY rBT9wKD63DAPI0eSfSnY7tSxq+qLrnT02RUbYk5SJhiw52x3QQO5fNfIxAESU2Tmcgrj zV5iUqO3iHo9zViOVeGKA7joZYgKOfkcGlh5Q0K2EuUpssDUUQ9rS8TzDVxa5D4FiVu7 /pLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y5fnfZfz; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m10sor3309382ljg.4.2019.10.10.04.40.22 for (Google Transport Security); Thu, 10 Oct 2019 04:40:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y5fnfZfz; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=nMmCoCFB6v8kr6aQHGxgLUgz2UP5C6jpzwaEeKyOjs4v6cd1H2ytUk4WzVGOjRMj8h RDMzY4tiB29x0H9c8UeMBiftmiJdtHzkYY2svWwWtTYWONk/ch4yGgGw7Tt3WRFOUOR3 0gkg0u8RX1n2ZVu2yvxG88C2u+6/TY6GUh68lXQeN3iRaWp4zqprJ6CSxinTDTBBGkqt pO8cWrkfY1XfQ7WFyygIavNCjHgYMeSsW7+8Y0qjaQkWSq3Xvy+QTeR61l71+VVTb8CT 7DoYLTAA5bGnjDisMkxQIsy1l7kPis+eGsxlAMn7P0sQDtdnJajL4ECpV/aZ7OEeAj8v 2a9g== X-Gm-Message-State: APjAAAWMU8s1f4oFcc4pmRbqBWk72BUYWMzr2+YT+rQGEkZdfzUTwg19 e2Vx45N+gKoSGISt4u4vKvtgURSyY7txPg== 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) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:22 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 11/13] cpuidle: psci: Attach CPU devices to their PM domains Date: Thu, 10 Oct 2019 13:39:35 +0200 Message-Id: <20191010113937.15962-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> 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(-) -- 2.17.1 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: 175755 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2163038ill; Thu, 10 Oct 2019 04:41:51 -0700 (PDT) X-Received: by 2002:a19:700f:: with SMTP id h15mr3348786lfc.167.1570707624690; Thu, 10 Oct 2019 04:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707624; cv=none; d=google.com; s=arc-20160816; b=Ka8UeaMKpQiEeiDySTGY8GSmgVrrcZXBoVqJTdoVVMiIIPeSSviEoFOl6ft4ybfmL/ 1zSgJ/srGfjZtN8b+QcynRWXtyP44kQ/k//Hiky78q66C4fqQpDtv+C16UPsKUOkwOIh RZxpQuVtzeKvHA/J58XYZPEaqoScf/QnBGedkJWctVfG4XlX+Mz5/Z480TUiBGATyicR bbkdDx94E5khRj7gD5cl5gPA9Vn1pOLWAehzH70Tju3YXdxKdXTeOFEuQFLJERMPM9Xz CHqxe9XXjsc1os/5uPf0+/FjrM47G3A4YNNvRvq5Ds+PDDdTjKha9p4jxTan4Aja1EZH Q6rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=wrAf/m9xQV7VMcisy/i232IdO9+p4WOlrmO1i/lkHwMQ6I+9LaZVJa+Mjx2pd0RXQ8 v6SwUIaHjaA1jhqtBiUOcfZjnVNjTIBdfeSBMdwOhy0j6OgPv1rXUFjEsx3eXBIlEN8E KcKsKaxBow80mrjwV+9e4ZtGcYQuCyvnnd+FQdXh3GIZOQfp1sREDW1kKpe8KPArXHHS a7/v3EnxTR49cPDaR+ME3rIC61CLvagz+mRdcBgVOAN88oM0cSmh5dUcxaft6oiZnauk 2MzQf22aS6jTet/aGbAsk10Z51p6A37+8OgUaohkIUGfCaJx7lEZG3KHsGuG3S6gQ6xR AReA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S1K49Am4; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v9sor3237800ljj.12.2019.10.10.04.40.24 for (Google Transport Security); Thu, 10 Oct 2019 04:40:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S1K49Am4; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=agEsmcmoqXvKtnjCQmBt33A0YMlokMd9ACC/bwU11xNFtSqbsnUHyUUA+DrIdCJqrV 7RwY8sotxCtMIpLEZ5z3sfuYVY1IDMVCQOPbvXEwBHE1a5OAUfN4Thzoy0C7AO/zhODW vMOFWlChela3ThdT41E3+FRJ2lS34oxM2hW28kKkCo1jtgxE3dWZSO7ctXdroAdOYJHT j/P/LlVoPSsjxQqiQQAWtLV058ghJoTuVAkf1q+LIgT0pGnr6j6m8urAyUVlxKShzlSI ikmSOoE1qDcjrSj+t48hkEmKmoZUdkR6c6xCgOHnPE3S+T5/1PIlxD4z/NXx0BF55woZ nTlA== X-Gm-Message-State: APjAAAW7jfLTgfweU66CEMnIlcZKpyaDaADTmxg5ZxgfpN4ls11UmYf0 WP3g8+t77d1fZV+ORuu5fA17iQ98 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) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id p3sm1168937ljn.78.2019.10.10.04.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:23 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 12/13] cpuidle: psci: Manage runtime PM in the idle path Date: Thu, 10 Oct 2019 13:39:36 +0200 Message-Id: <20191010113937.15962-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> 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(-) -- 2.17.1 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;