From patchwork Fri Feb 12 20:50:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 8297551 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4F323C02AA for ; Fri, 12 Feb 2016 20:57:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C5E42042B for ; Fri, 12 Feb 2016 20:57:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 57885203F4 for ; Fri, 12 Feb 2016 20:57:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aUKkQ-0002Kd-Qm; Fri, 12 Feb 2016 20:55:26 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aUKh5-0006YQ-TK for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2016 20:52:03 +0000 Received: by mail-pf0-x230.google.com with SMTP id e127so53014055pfe.3 for ; Fri, 12 Feb 2016 12:51:39 -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=uLapP8ck13277NtAt0HaY1XfEGxPdS4HiOCcnwpQJZc=; b=U30K74SMoaOZwcO5oucFatqb8QPM8u3c+nNKI1gHDk/4IQfL9yA9mGjNvvQLvVeKuJ k3lDRYkVcT0gBNBroZsxg4q7r47thA3HkxbKmA9Xdo8r91wmuvucMqhyGyrL2u0JTtWW 30lWfllwNnGOVWKeoFvHb1KG4dkac82KBJRrA= 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=uLapP8ck13277NtAt0HaY1XfEGxPdS4HiOCcnwpQJZc=; b=ay1+dHB/DX+0OnLrtwvnwFWUen6Cymv5ui9eZBIHfL+oijEDicWwE94GEUB6w4MHOA PmFtkEG11wDBPzCnIgyMJe/AIhfG1UeUaJJGEnDYcFAESJ+aBUSLh2G7OVkh3pVzQ6b6 de6XwywamZwSwwP6xVj0/rQyKXP+peBoxMgg+VRfcA+I1VF0CUA0S+PwFJum1QX7j6tr u7v6Jly8p87A4uU7qVYIWeBkziXpBhO8rkFJeDz58cUmb2/AUDC0pHP8XUCUykoctGPC utYDO0JbTnu3YxxJWm+Jg6EHTmvcPo4KieI87u3Qnsl5NVMtgQzLc3k73jQI1NMjPlti r5nA== X-Gm-Message-State: AG10YOSyC3OTNlZJl/NwbSVr+Piu0lYVrSytrfYZCl4RJVXYE+wbjNM8E6Sn+pYfD7U8zyXS X-Received: by 10.98.71.15 with SMTP id u15mr5058810pfa.161.1455310299316; Fri, 12 Feb 2016 12:51:39 -0800 (PST) Received: from ubuntu.localdomain ([172.56.8.98]) by smtp.gmail.com with ESMTPSA id x12sm21401070pfi.88.2016.02.12.12.51.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 12:51:38 -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: [RFC v2 09/12] drivers: firmware: psci: Allow OS Initiated suspend mode Date: Fri, 12 Feb 2016 13:50:35 -0700 Message-Id: <1455310238-8963-10-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455310238-8963-1-git-send-email-lina.iyer@linaro.org> References: <1455310238-8963-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160212_125200_349168_9A19764D X-CRM114-Status: GOOD ( 16.00 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , k.kozlowski@samsung.com, lorenzo.pieralisi@arm.com, ahaslam@baylibre.com, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, msivasub@codeaurora.org, geert@linux-m68k.org, Lina Iyer , agross@codeaurora.org, mtitinger@baylibre.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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. The firmware shall also be the default mode. 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 --- drivers/firmware/psci.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/psci.h | 2 ++ include/uapi/linux/psci.h | 5 +++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index f25cd79..03c084e 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -49,12 +49,19 @@ * require cooperation with a Trusted OS driver. */ static int resident_cpu = -1; +static bool has_osi_pd; +static bool psci_suspend_mode_is_osi; bool psci_tos_resident_on(int cpu) { return cpu == resident_cpu; } +bool psci_has_osi_pd_support(void) +{ + return has_osi_pd; +} + struct psci_operations psci_ops; typedef unsigned long (psci_fn)(unsigned long, unsigned long, @@ -250,6 +257,26 @@ static int psci_system_suspend(unsigned long unused) virt_to_phys(cpu_resume), 0, 0); } +int psci_set_suspend_mode_osi(bool enable) +{ + int ret; + int mode; + + if (enable && !psci_has_osi_pd_support()) + return -ENODEV; + + if (enable == psci_suspend_mode_is_osi) + return 0; + + mode = enable ? PSCI_1_0_SUSPEND_MODE_OSI : PSCI_1_0_SUSPEND_MODE_PC; + ret = invoke_psci_fn(PSCI_FN_NATIVE(1_0, SET_SUSPEND_MODE), + mode, 0, 0); + if (!ret) + psci_suspend_mode_is_osi = enable; + + return psci_to_linux_errno(ret); +} + static int psci_system_suspend_enter(suspend_state_t state) { return cpu_suspend(0, psci_system_suspend); @@ -443,10 +470,26 @@ out_put_node: 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_FN_NATIVE(0_2, CPU_SUSPEND)); + if (ret & PSCI_1_0_OS_INITIATED) + has_osi_pd = true; + + return 0; +} + static const struct of_device_id const 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}, {}, }; diff --git a/include/linux/psci.h b/include/linux/psci.h index 12c4865..deae633 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -23,6 +23,8 @@ bool psci_tos_resident_on(int cpu); bool psci_power_state_loses_context(u32 state); bool psci_power_state_is_valid(u32 state); +bool psci_has_osi_pd_support(void); +int psci_set_suspend_mode_osi(bool enable); struct psci_operations { int (*cpu_suspend)(u32 state, unsigned long entry_point); diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h index 3d7a0fc..eaab6e3 100644 --- a/include/uapi/linux/psci.h +++ b/include/uapi/linux/psci.h @@ -50,6 +50,7 @@ #define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14) #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) +#define PSCI_1_0_FN64_SET_SUSPEND_MODE PSCI_0_2_FN64(15) /* PSCI v0.2 power state encoding for CPU_SUSPEND function */ #define PSCI_0_2_POWER_STATE_ID_MASK 0xffff @@ -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