From patchwork Tue Feb 22 15:08:45 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: 12755399 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 008C2C433EF for ; Tue, 22 Feb 2022 15:23:46 +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=y+stVyeo+8l773bkBABSeokavIQQm7OZBWW+0IoiL2Y=; b=jquxSwVD4GwhTy zGjowZHEsUzDnlTHxL8q347bXm+tTNsi6Iaih1vLqebIgE3U8qHS3VFFhvomJP9K8bYgdVAbpM4cW wbUQqNsL7E4TLWyDO5yN5ULuNuR3Gxo/N6RonbIhIHaA4/EibtAM7S6TMWIqFbr7ToRcU7T/GSukl UQV1ZJCUUklGgKFXSynjiOm8fLmTppvIUsI8EZgompukocQRJs9Y/QWbMDQLCwq/cyONw2BwFe5re HI5BeMHFI1lzsbS2HGDP4vtxuyugwOUDddG+LCCmFGRfOBBun1nNflm80Gz85PvYhldXUE6AUkT2s v2r1+N8mW4vIp4CJqFMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWzE-00AB1q-Cz; Tue, 22 Feb 2022 15:21:58 +0000 Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWoS-00A5rX-Bj for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 15:10:51 +0000 Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B4240FF802; Tue, 22 Feb 2022 15:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645542644; 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=5OimyuXNq782pNwOtB/pBEMyzaWO+JIoSHKWQ8Ypj6U=; b=Kv5dL0wB6hkRopQz6doaUNuuJ+L4cBd0D4YI9/JE6dcGFAf03c+e44ZYpHqDQUjJB79w6x fYUIUroB7po1d3xLdYOvUqdfC+jeLStUz3USa7Gp1w3Ys8/HAfFKEIatest9KQBtcqdXBn Po5kU20En9IYv3HLLSsMrT8clkulscl16qfQplVGj5doSj2cobjY6NjmCgYapMis4+RP56 bi3aiRpHfaMr+tPC7BhGMWlV85s/XnFM+im1PTlbYrayFAi/ZhSn0j+AKJS6pjOd88PzzE 1pt6vAQpgyGNdYDUBfb4tz/75E7AWsPdXrut9+uJ+jGj1z5+XwPQJIm3bQRIRg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Russell King , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , =?utf-8?b?Q2zDqW1lbnQgTMOp?= =?utf-8?b?Z2Vy?= Subject: [PATCH 3/4] ARM: at91: pm: add support for sama5d2 secure suspend Date: Tue, 22 Feb 2022 16:08:45 +0100 Message-Id: <20220222150846.255307-4-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220222150846.255307-1-clement.leger@bootlin.com> References: <20220222150846.255307-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-20220222_071048_726230_B99CA1BD X-CRM114-Status: GOOD ( 21.96 ) 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. Since the sama5d2 supports multiple suspend modes add a new CONFIG_ATMEL_SECURE_PM which is mutually exclusive with CONFIG_ATMEL_PM and allows to issue a SMC call to select the suspend mode. "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 Reported-by: kernel test robot Reported-by: kernel test robot --- arch/arm/mach-at91/Kconfig | 14 ++++++- arch/arm/mach-at91/Makefile | 1 + arch/arm/mach-at91/pm_secure.c | 64 +++++++++++++++++++++++++++++ arch/arm/mach-at91/sam_secure.h | 4 ++ include/linux/platform_data/atmel.h | 2 +- 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-at91/pm_secure.c diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig index 02f6b108fd5d..bb11a914ad3e 100644 --- a/arch/arm/mach-at91/Kconfig +++ b/arch/arm/mach-at91/Kconfig @@ -201,14 +201,24 @@ config SOC_SAM_V7 config SOC_SAMA5 bool select ATMEL_AIC5_IRQ - select ATMEL_PM if PM select ATMEL_SDRAMC select MEMORY select SOC_SAM_V7 select SRAM if PM config ATMEL_PM - bool + bool "Atmel PM support" + default y if SOC_SAMA5 && PM + depends on !ATMEL_SECURE_PM + +config ATMEL_SECURE_PM + bool "Atmel Secure PM support" + depends on SOC_SAMA5D2 && PM + 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. + NOTE: This support is mutually exclusive with CONFIG_ATMEL_PM config SOC_SAMA7 bool diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile index 23620ccf7ab6..ebd88de8d0e7 100644 --- a/arch/arm/mach-at91/Makefile +++ b/arch/arm/mach-at91/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_SOC_SAMV7) += samv7.o # Power Management obj-$(CONFIG_ATMEL_PM) += pm.o pm_suspend.o pm_common.o +obj-$(CONFIG_ATMEL_SECURE_PM) += pm_secure.o pm_common.o ifeq ($(CONFIG_CPU_V7),y) AFLAGS_pm_suspend.o := -march=armv7-a diff --git a/arch/arm/mach-at91/pm_secure.c b/arch/arm/mach-at91/pm_secure.c new file mode 100644 index 000000000000..2f63ff8c6226 --- /dev/null +++ b/arch/arm/mach-at91/pm_secure.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2012, Bootlin + */ + +#include +#include +#include +#include +#include "generic.h" +#include "sam_secure.h" +#include "pm.h" + +static int suspend_mode = AT91_PM_ULP0; + +static void at91_pm_secure_init(void) +{ + struct arm_smccc_res res; + + 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; + } + suspend_mode = res.a1; + + pr_info("AT91: Secure PM: using default suspend mode %s\n", + pm_modes[suspend_mode].pattern); +} + +void __init sama5_pm_init(void) +{ +} + +void __init sama5d2_pm_init(void) +{ + at91_pm_secure_init(); +} + +int at91_suspend_entering_slow_clock(void) +{ + return (suspend_mode >= AT91_PM_ULP0); +} +EXPORT_SYMBOL(at91_suspend_entering_slow_clock); + +static int __init at91_pm_modes_select(char *str) +{ + int dummy; + + pr_warn("AT91: Secure PM: ignoring standby mode\n"); + + return at91_pm_common_modes_select(str, &dummy, &suspend_mode); +} +early_param("atmel.pm_modes", at91_pm_modes_select); diff --git a/arch/arm/mach-at91/sam_secure.h b/arch/arm/mach-at91/sam_secure.h index af19e24ca59e..b169317f61f6 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); diff --git a/include/linux/platform_data/atmel.h b/include/linux/platform_data/atmel.h index 73f63be509c4..cbb19712b4f0 100644 --- a/include/linux/platform_data/atmel.h +++ b/include/linux/platform_data/atmel.h @@ -7,7 +7,7 @@ #define __ATMEL_H__ /* FIXME: this needs a better location, but gets stuff building again */ -#ifdef CONFIG_ATMEL_PM +#if defined(CONFIG_ATMEL_PM) || defined(CONFIG_ATMEL_SECURE_PM) extern int at91_suspend_entering_slow_clock(void); #else static inline int at91_suspend_entering_slow_clock(void)