From patchwork Thu Aug 25 20:03:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9299827 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 60FCE60B16 for ; Thu, 25 Aug 2016 20:05:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51A042935D for ; Thu, 25 Aug 2016 20:05:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 468EE2936B; Thu, 25 Aug 2016 20:05:16 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9394293AA for ; Thu, 25 Aug 2016 20:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932473AbcHYUEu (ORCPT ); Thu, 25 Aug 2016 16:04:50 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:35636 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757619AbcHYUEX (ORCPT ); Thu, 25 Aug 2016 16:04:23 -0400 Received: by mail-pf0-f178.google.com with SMTP id x72so20767677pfd.2 for ; Thu, 25 Aug 2016 13:04: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=HtyZr1NzvXLe6gvBWNAVAp1ysgP766cw7cyutkMVgvY=; b=AJFlc8TEHm0azMJ/VwTluDC2B0CgiILuuBIPJ5i5QDi5OG4CEP075xJ4bgWZkQby+C ydsSRp7ozK5uMQRmiNZCeg7z3wBmyuGy8HNKy8KI5nh9H8gNKhwq4Oc+V9m/6TNbB7zb HH0XsEMuHMhkqeuvMR1L9pw3AO2pb3+JZDnJE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HtyZr1NzvXLe6gvBWNAVAp1ysgP766cw7cyutkMVgvY=; b=kTVDFiMBjUaF2u1dVp4BCyAf5cVUit8IyLK51o+fkJnoXNiWc38qNYAm6NzAzUINng W7Ag+87b+pZYZxOCtO9msv+Mt9r40SZZu0v0OdXPn0zCEI2n8J3S4pl+MpXo1nfOdhMr OCQxP1QgZreyzixLByQGJsR25fhdXkq/4ZBfCd+qdEGRZevh6EvpYeqQdYIdfBgDy3yv Chv75nalRrG+zjtLUiw2bFiPQ7wMfUmyFYH+3K0tPHYU++BPrrBk1W3roXBlfpya6t2K YLRMjhkLOGmYjgR5JxYZJOpFOgJ9aoI4iBPZEeJRnNsPOXH/aALB+vqbvTfGB4QDuHee tfyA== X-Gm-Message-State: AE9vXwNnP+zO3mMtckYpzw4YK3vRmtr6oofRorsXp4+ELD9kT0IuzP/FiikzC506F9fAT3sn X-Received: by 10.98.31.219 with SMTP id l88mr19559562pfj.155.1472155451285; Thu, 25 Aug 2016 13:04:11 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id u1sm22841644pfu.12.2016.08.25.13.04.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 13:04:10 -0700 (PDT) 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 Cc: andy.gross@linaro.org, sboyd@codeaurora.org, linux-arm-msm@vger.kernel.org, brendan.jackman@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, Juri.Lelli@arm.com, Lina Iyer , Mark Rutland Subject: [PATCH v4 12/16] drivers: firmware: psci: Allow OS Initiated suspend mode Date: Thu, 25 Aug 2016 14:03:21 -0600 Message-Id: <1472155405-41841-13-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472155405-41841-1-git-send-email-lina.iyer@linaro.org> References: <1472155405-41841-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 03e0458..759b134 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -52,6 +52,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) { @@ -506,9 +507,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 @@ -516,11 +516,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(); } /* @@ -532,9 +528,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"); @@ -558,15 +553,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}, {}, }; @@ -575,6 +586,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); @@ -582,7 +594,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