From patchwork Mon May 2 15:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12834305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A99DEC433F5 for ; Mon, 2 May 2022 15:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TT5R8ZbALKtwnYxG9tan/M1a7E7iQZXToS6t8ywTY60=; b=ElFlMJZRuZo5b6 5QQ88NHCfXFEhVikbQwmS8hYDVx8KAzqtJfgY4EWzle7eSLXTkBjGFl1Ph8GAVj+FcuLsDo6Al3Pz vjsfcvwxHQF+qo7dfWdIkyCiBv6zCu9T6xZNG0yZ8rlTJepzA/8SZVmB/55LAnDsWSbWzhTG8k+qZ SaAO4szcoGuNE4OrvmkE5gDq+X7DoCuf3g2WoZWsYwNPa63vD0Vju/hCQ04fE4AF+CBtdEJ1ZNm76 D/I5TNf3Btwld3ff7p1MTUUSMR1mDyXfZUcCyCzHPT4tFUUwgJ9S6DeS558zpigJGu9q+WKZVdz6H bkrGKSMUxhK7rfkuFyqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlXu7-001UK2-7F; Mon, 02 May 2022 15:24:03 +0000 Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlXtn-001UC0-I9 for linux-arm-kernel@lists.infradead.org; Mon, 02 May 2022 15:23:52 +0000 Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id F398D240006; Mon, 2 May 2022 15:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1651505018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=epNsehOQ5G2G1dNlTN4p4tzZ/vqrI4nGDtqFzUY+KDg=; b=UWVp04zye+oewABRxix51t0TRsFXXR3pLjoejridAOZVIoUAaZGVHC0dkBUK97Qc4LOOHG h/Y59+vPypLBYLcCZjf1RRUv2vcJc7Sab1eha4osGA7LF9lmzgYiupY1l0VzcwDKIL7x/Z EzyQuIHjB0u+F7Nb/Uj5Us1BrOAp1xH4RFI8tO+6lzRboOJ2/99mzViA0WN+vN0lodshUB r/8fjiiyUsVvPevw06ErSaoVXMH45EpSTZ/a9vaW23m+9rkQ2bTtv+XG7VAuF2noDSv94Z ShyC061S5uaVWNylxQJvLOEOkd66AtRzpuGsDij3YknopqkNhWkJ7Dvla2npFA== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Russell King , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thomas Petazzoni Subject: [PATCH v3 2/2] ARM: at91: pm: add support for sama5d2 secure suspend Date: Mon, 2 May 2022 17:22:19 +0200 Message-Id: <20220502152219.216758-3-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220502152219.216758-1-clement.leger@bootlin.com> References: <20220502152219.216758-1-clement.leger@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220502_082343_931519_04350917 X-CRM114-Status: GOOD ( 18.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When running with OP-TEE, the suspend control is handled securely. Suspend can be entered using PSCI support. Since the sama5d2 supports multiple suspend modes, add a new CONFIG_ATMEL_SECURE_PM which will send a SMC call to select the suspend mode at init time. "atmel.pm_modes" boot argument is still supported for compatibility purposes but the standby value is actually ignored since PSCI suspend is used and it only support one mode (suspend). Signed-off-by: Clément Léger --- arch/arm/mach-at91/Kconfig | 11 +++++++++- arch/arm/mach-at91/pm.c | 36 +++++++++++++++++++++++++++++++++ arch/arm/mach-at91/sam_secure.h | 4 ++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig index 279810381256..0e05da5b0aa3 100644 --- a/arch/arm/mach-at91/Kconfig +++ b/arch/arm/mach-at91/Kconfig @@ -209,7 +209,16 @@ config SOC_SAMA5 select SRAM if PM config ATMEL_PM - bool + bool "Atmel PM support" + +config ATMEL_SECURE_PM + bool "Atmel Secure PM support" + depends on SOC_SAMA5D2 && ATMEL_PM + select ARM_PSCI + help + When running under a TEE, the suspend mode must be requested to be set + at TEE level. When enable, this option will use secure monitor calls + to set the suspend level. PSCI is then used to enter suspend. config SOC_SAMA7 bool diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c index 0fd609e26615..d6886af9b205 100644 --- a/arch/arm/mach-at91/pm.c +++ b/arch/arm/mach-at91/pm.c @@ -27,6 +27,7 @@ #include "generic.h" #include "pm.h" +#include "sam_secure.h" #define BACKUP_DDR_PHY_CALIBRATION (9) @@ -881,6 +882,35 @@ static int __init at91_pm_backup_init(void) return ret; } +static void at91_pm_secure_init(void) +{ + int suspend_mode; + struct arm_smccc_res res; + + suspend_mode = soc_pm.data.suspend_mode; + + res = sam_smccc_call(SAMA5_SMC_SIP_SET_SUSPEND_MODE, + suspend_mode, 0); + if (res.a0 == 0) { + pr_info("AT91: Secure PM: suspend mode set to %s\n", + pm_modes[suspend_mode].pattern); + return; + } + + pr_warn("AT91: Secure PM: %s mode not supported !\n", + pm_modes[suspend_mode].pattern); + + res = sam_smccc_call(SAMA5_SMC_SIP_GET_SUSPEND_MODE, 0, 0); + if (res.a0 == 0) { + pr_warn("AT91: Secure PM: failed to get default mode\n"); + return; + } + + pr_info("AT91: Secure PM: using default suspend mode %s\n", + pm_modes[suspend_mode].pattern); + + soc_pm.data.suspend_mode = res.a1; +} static const struct of_device_id atmel_shdwc_ids[] = { { .compatible = "atmel,sama5d2-shdwc" }, { .compatible = "microchip,sam9x60-shdwc" }, @@ -1213,6 +1243,12 @@ void __init sama5d2_pm_init(void) if (!IS_ENABLED(CONFIG_SOC_SAMA5D2)) return; + if (IS_ENABLED(CONFIG_ATMEL_SECURE_PM)) { + pr_warn("AT91: Secure PM: ignoring standby mode\n"); + at91_pm_secure_init(); + return; + } + at91_pm_modes_validate(modes, ARRAY_SIZE(modes)); at91_pm_modes_init(iomaps, ARRAY_SIZE(iomaps)); ret = at91_dt_ramc(false); diff --git a/arch/arm/mach-at91/sam_secure.h b/arch/arm/mach-at91/sam_secure.h index 360036672f52..1e7d8b20ba1e 100644 --- a/arch/arm/mach-at91/sam_secure.h +++ b/arch/arm/mach-at91/sam_secure.h @@ -8,6 +8,10 @@ #include +/* Secure Monitor mode APIs */ +#define SAMA5_SMC_SIP_SET_SUSPEND_MODE 0x400 +#define SAMA5_SMC_SIP_GET_SUSPEND_MODE 0x401 + void __init sam_secure_init(void); struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1);