From patchwork Fri Mar 3 21:48:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9603599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D1A9602B4 for ; Fri, 3 Mar 2017 21:50:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C3FF285D2 for ; Fri, 3 Mar 2017 21:50:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D9B328613; Fri, 3 Mar 2017 21:50:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CDB74285D2 for ; Fri, 3 Mar 2017 21:50:13 +0000 (UTC) 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=jOoaie8NokclfuNxC3rqrfsjYeOnVpeiTw+zHnG2RGs=; b=cbgLCR/hEqAjpO3Zw4ij4gW9q5 PIBu8x5SJUrXPC8S/71+34yPkUMcqtd137OmRHJgyYbUJTOjxN1TqdLbT+RszQ/YOGlh+aDpSGD1T v/CrpZXqpC+yKvpEaRgP9IviJBY+o5MuaYwyxHRgIhUIdzG2ttBpt+zNXWRNykR3mCSKWmj9OLQzg qeBCte8vM0dHGYtidRzaO/JedP3lNQEcj3jxF+70U9OoCJZB3id39Xe4ImEXBCb7QmBtXRRYa3sSL j1HAvXUQ85vg5wMoPhbhVTeaY/Fg9sU7W/eDWO2UWp6YfGCwbc2Ufqw19JHFt8+r1rVadsOYXXeug CmupbxyQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cjv5T-0000gS-JV; Fri, 03 Mar 2017 21:50:07 +0000 Received: from mail-pg0-x231.google.com ([2607:f8b0:400e:c05::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cjv4B-00005E-Rw for linux-arm-kernel@lists.infradead.org; Fri, 03 Mar 2017 21:48:50 +0000 Received: by mail-pg0-x231.google.com with SMTP id s67so47903978pgb.3 for ; Fri, 03 Mar 2017 13:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eCxvmbPu1OWzznUYiDOu9aLq4Cn4TAdcm0rc0g+TdRQ=; b=eULB9TJpSF9kUqR4t/acEajpsG6rdnZ3TUQD7WxDyRwBxcDzwGn//tnNugslanaD0T HMbP18efaaBmYNsqJZbD7O7Ml1B5rVsXn3UdvqKU4Kf79Zd+luLsjDbfGMjZvbDtXnDr cYWoZCBxbzmdXvZzmvBGh1eewnwFU8lp3TOS4= 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=eCxvmbPu1OWzznUYiDOu9aLq4Cn4TAdcm0rc0g+TdRQ=; b=lMojfnKTfzE84jCFYXUIREOuOci9JaqfURCPdeyqcagw4+Co8p9P+riY4YVB5HiJRV u60Zcy4xCnE37XI7hjqiSp+8Rvn9EpK15e+/90uCz2pyPshkwTvT6DcIy8TR4Px7a31X Vj52qcaTlu2RJszJVDn4IewWoBYbPsvCwdjf0wuJ5HQ7ptQR99TS4OgSPa6hIvdTjOxr guQfGCY5tTlriYnqtelVYl0IZjD4oPvNkeF6xClNJt44LJde0i2Lp/YsElFfeWdqGbeY 36gGdi62mqa5z8NSlwl5DKt7EtHt0pGTgZjSDJnITF/OrNw2pY6o34RAAXHLr7qQMSwJ bgQQ== X-Gm-Message-State: AMke39kp9n2IrAV7QOJS3OeSCpVaXIp6PqYv9s5BY9sNFqP06AMeSPDoLjfKzWt4C1dShBni X-Received: by 10.99.99.1 with SMTP id x1mr5893699pgb.134.1488577707002; Fri, 03 Mar 2017 13:48:27 -0800 (PST) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id q23sm25200585pfg.63.2017.03.03.13.48.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 13:48:25 -0800 (PST) From: Lina Iyer To: ulf.hansson@linaro.org, khilman@kernel.org, rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V5 2/6] drivers: firmware: psci: Allow OS Initiated suspend mode Date: Fri, 3 Mar 2017 13:48:13 -0800 Message-Id: <1488577697-127445-3-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488577697-127445-1-git-send-email-lina.iyer@linaro.org> References: <1488577697-127445-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170303_134847_948744_9EFBA215 X-CRM114-Status: GOOD ( 16.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , lorenzo.pieralisi@arm.com, Juri.Lelli@arm.com, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, brendan.jackman@arm.com, sudeep.holla@arm.com, andy.gross@linaro.org, Lina Iyer MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP PSCI firmware v1.0 onwards may support 2 different modes for CPU_SUSPEND. Platform coordinated mode is the default and every firmware should support it. OS Initiated mode is optional for the firmware to implement and allow Linux to make an better decision on the state of the CPU cluster heirarchy. With the kernel capable of deciding the state for CPU cluster and coherency domains, the OS Initiated mode may now be used by the kernel, provided the firmware supports it. SET_SUSPEND_MODE is a PSCI function available on v1.0 onwards and can be used to set the mode in the firmware. Cc: Lorenzo Pieralisi Cc: Mark Rutland Signed-off-by: Lina Iyer [Ulf: Rebased on 4.7 rc1] Signed-off-by: Ulf Hansson --- drivers/firmware/psci.c | 42 +++++++++++++++++++++++++++++------------- include/uapi/linux/psci.h | 5 +++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index 6c60a50..ec922b8 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -53,6 +53,7 @@ * require cooperation with a Trusted OS driver. */ static int resident_cpu = -1; +static bool psci_has_osi; bool psci_tos_resident_on(int cpu) { @@ -558,9 +559,8 @@ static int __init psci_0_2_init(struct device_node *np) int err; err = get_set_conduit_method(np); - if (err) - goto out_put_node; + return err; /* * Starting with v0.2, the PSCI specification introduced a call * (PSCI_VERSION) that allows probing the firmware version, so @@ -568,11 +568,7 @@ static int __init psci_0_2_init(struct device_node *np) * can be carried out according to the specific version reported * by firmware */ - err = psci_probe(); - -out_put_node: - of_node_put(np); - return err; + return psci_probe(); } /* @@ -584,9 +580,8 @@ static int __init psci_0_1_init(struct device_node *np) int err; err = get_set_conduit_method(np); - if (err) - goto out_put_node; + return err; pr_info("Using PSCI v0.1 Function IDs from DT\n"); @@ -610,15 +605,31 @@ static int __init psci_0_1_init(struct device_node *np) psci_ops.migrate = psci_migrate; } -out_put_node: - of_node_put(np); return err; } +static int __init psci_1_0_init(struct device_node *np) +{ + int ret; + + ret = psci_0_2_init(np); + if (ret) + return ret; + + /* Check if PSCI OSI mode is available */ + ret = psci_features(psci_function_id[PSCI_FN_CPU_SUSPEND]); + if (ret & PSCI_1_0_OS_INITIATED) { + if (!psci_features(PSCI_1_0_FN_SET_SUSPEND_MODE)) + psci_has_osi = true; + } + + return 0; +} + static const struct of_device_id psci_of_match[] __initconst = { { .compatible = "arm,psci", .data = psci_0_1_init}, { .compatible = "arm,psci-0.2", .data = psci_0_2_init}, - { .compatible = "arm,psci-1.0", .data = psci_0_2_init}, + { .compatible = "arm,psci-1.0", .data = psci_1_0_init}, {}, }; @@ -627,6 +638,7 @@ int __init psci_dt_init(void) struct device_node *np; const struct of_device_id *matched_np; psci_initcall_t init_fn; + int ret; np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np); @@ -634,7 +646,11 @@ int __init psci_dt_init(void) return -ENODEV; init_fn = (psci_initcall_t)matched_np->data; - return init_fn(np); + ret = init_fn(np); + + of_node_put(np); + + return ret; } #ifdef CONFIG_ACPI diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h index 3d7a0fc..7dd778e 100644 --- a/include/uapi/linux/psci.h +++ b/include/uapi/linux/psci.h @@ -48,6 +48,7 @@ #define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10) #define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14) +#define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15) #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) @@ -93,6 +94,10 @@ #define PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK \ (0x1 << PSCI_1_0_FEATURES_CPU_SUSPEND_PF_SHIFT) +#define PSCI_1_0_OS_INITIATED BIT(0) +#define PSCI_1_0_SUSPEND_MODE_PC 0 +#define PSCI_1_0_SUSPEND_MODE_OSI 1 + /* PSCI return values (inclusive of all PSCI versions) */ #define PSCI_RET_SUCCESS 0 #define PSCI_RET_NOT_SUPPORTED -1