From patchwork Tue Feb 22 15:08:43 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: 12755398 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 44011C433F5 for ; Tue, 22 Feb 2022 15:22:39 +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=pi7jI7uV6sUWQY7FX32ed/4Ktvc5TAT5y6BHBZlNQlI=; b=T8ChAKkqINAuQl nLQLrF8wBHSXO+CECUVTMFB/3I2XJB0vvwTZK81P3eBJwMCERfPRlgUQ8sO0k/X+UpeAUIdRGfDUd YWbcNMuHlgoPic46NGDpBsc5nHDY0uD8QKg2SenfSJKdTRqtM0ZTlmomHrXzPqb+W9VJk4JAqJMmW 1PmpkeIw7RQUmyDsgLFfjnWw27Wi7siM33+zadcTZ1kl2lyy30lrI/1kNBTWEsp40Q6SL8gnqkXMi 3Tv5sL2u2VchRMW1zp7mhQKpcknOKe4d7keo1mkJoLSvyRd8McLO5dGPiNzt+g4SzPH0qvPQIs4c/ +qC158/u4vm/Nx41aQdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWyI-00AATd-E5; Tue, 22 Feb 2022 15:20:58 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWoR-00A5qY-6u for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 15:10:50 +0000 Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 43107FF80A; Tue, 22 Feb 2022 15:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645542642; 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=hAqjOk4kWjLAaNNND+MI5XvviLpLYiGq26sQVn42k3Q=; b=fHLB8ZlKlFqgYwJZ9PYUe3AcDj86qjrTmV/R4mG1RAg6gPc2JMNV48pgIs7hrjIvhL+flk nxr7Fg3xPpwCdOX7OVJL1CJJZ5Lds8wo2uDX77SgNx+saugqgXkBGDWDVXuCy6hV1n23Jy 1mwVZqLo+ccrrtymHytyT2ja6CIECqez/uI+v5qG3sDHJRKAMZwT15e31Q/ZD+T//8Ke/V VJWnBY0jkAj8UtdksUm+NmUSMy0qpAaM1o2OvgxMgSB5EBrTDmhLrk0jWAcYuX6NFOFiJB HR9Vx1WyzF5qwUAaCAJgUQGpsgzSKegAhKb+8Ek74Od5zSbaBZseCScwa1wuBw== 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 1/4] ARM: at91: add code to handle secure calls Date: Tue, 22 Feb 2022 16:08:43 +0100 Message-Id: <20220222150846.255307-2-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_071047_685735_38080D4D X-CRM114-Status: GOOD ( 19.98 ) 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 Since OP-TEE now has a more complete support for sama5d2, add necessary code to perform SMC calls. The detection of OP-TEE is based on a specific device-tree node path (/firmware/optee) such has done by some other SoC. A check is added to avoid doing SMC calls without having OP-TEE. Signed-off-by: Clément Léger --- arch/arm/mach-at91/Makefile | 2 +- arch/arm/mach-at91/sam_secure.c | 46 +++++++++++++++++++++++++++++++++ arch/arm/mach-at91/sam_secure.h | 14 ++++++++++ arch/arm/mach-at91/sama5.c | 2 ++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-at91/sam_secure.c create mode 100644 arch/arm/mach-at91/sam_secure.h diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile index 522b680b6446..0dcc37180588 100644 --- a/arch/arm/mach-at91/Makefile +++ b/arch/arm/mach-at91/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_SOC_AT91RM9200) += at91rm9200.o obj-$(CONFIG_SOC_AT91SAM9) += at91sam9.o obj-$(CONFIG_SOC_SAM9X60) += sam9x60.o -obj-$(CONFIG_SOC_SAMA5) += sama5.o +obj-$(CONFIG_SOC_SAMA5) += sama5.o sam_secure.o obj-$(CONFIG_SOC_SAMA7) += sama7.o obj-$(CONFIG_SOC_SAMV7) += samv7.o diff --git a/arch/arm/mach-at91/sam_secure.c b/arch/arm/mach-at91/sam_secure.c new file mode 100644 index 000000000000..979fc3c892a3 --- /dev/null +++ b/arch/arm/mach-at91/sam_secure.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2012, Bootlin + */ + +#include +#include + +#include "sam_secure.h" + +static bool optee_available; + +#define SAM_SIP_SMC_STD_CALL_VAL(func_num) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_SIP, (func_num)) + +struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1) +{ + struct arm_smccc_res res = {.a0 = -1}; + + if (WARN_ON(!optee_available)) + return res; + + arm_smccc_smc(SAM_SIP_SMC_STD_CALL_VAL(fn), arg0, arg1, + 0, 0, 0, 0, 0, &res); + + return res; +} + +void __init sam_secure_init(void) +{ + struct device_node *np; + + /* + * We only check that the OP-TEE node is present and available. The + * OP-TEE kernel driver is not needed for the type of interaction made + * with OP-TEE here so the driver's status is not checked. + */ + np = of_find_node_by_path("/firmware/optee"); + if (np && of_device_is_available(np)) + optee_available = true; + of_node_put(np); + + if (optee_available) + pr_info("Running under OP-TEE firmware\n"); +} diff --git a/arch/arm/mach-at91/sam_secure.h b/arch/arm/mach-at91/sam_secure.h new file mode 100644 index 000000000000..af19e24ca59e --- /dev/null +++ b/arch/arm/mach-at91/sam_secure.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2012, Bootlin + */ + +#ifndef SAM_SECURE_H +#define SAM_SECURE_H + +#include + +void __init sam_secure_init(void); +struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1); + +#endif /* SAM_SECURE_H */ diff --git a/arch/arm/mach-at91/sama5.c b/arch/arm/mach-at91/sama5.c index 89dab7cf01e8..de5dd28b392e 100644 --- a/arch/arm/mach-at91/sama5.c +++ b/arch/arm/mach-at91/sama5.c @@ -14,6 +14,7 @@ #include #include "generic.h" +#include "sam_secure.h" static void __init sama5_dt_device_init(void) { @@ -47,6 +48,7 @@ MACHINE_END static void __init sama5d2_init(void) { of_platform_default_populate(NULL, NULL, NULL); + sam_secure_init(); sama5d2_pm_init(); } From patchwork Tue Feb 22 15:08:44 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: 12755395 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 8ABB9C433EF for ; Tue, 22 Feb 2022 15:19:24 +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=HniOoEdVPY1wBko4DV0+mxOB0UOCXhrrXOzRbvfoLCA=; b=a4NhKkHVkB70Pg RZQ6EEJybIKdfk+5VoqPlegURb/+5Fmbl3v8SulALhcWYbOcwWlj0gScucbVJ5UPjgcYAEOmMWpP0 1rVN8bHzxtFpdpRenGf+hvsAp/191NH81AITxrS1sbYJIEbUOQW65aql8hgToFRfz4nWX9UGJkkL/ c/S922urQ+i9C462TrRbEYW1w2zaAqsFmZUYiw3ecAjKoY7yr/64F7WKlCT+Jx5A2ayZ/s6ZICD12 aw6HCYLYJ+atTcNSZRzBMzAjNxb3TZRcJtNmoqyybuz9s5ARY5KS4zShBGJ7USfQHQavziptZSDMP bfbP21LCLBlkBNziEsAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWut-00A93p-QS; Tue, 22 Feb 2022 15:17:28 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWoQ-00A5qy-TP for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 15:10:50 +0000 Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0614AFF808; Tue, 22 Feb 2022 15:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645542643; 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=CtKL8F/Jq2zYU6K+/py9GTxpMsuM+hyFjUkbGMfpBM8=; b=fpCxi/gpQB8ymagHFzpSGHRh9evnDJfs8mijFq206mD+Yy/+eAZpotSk6Q7xmKRtKC7vsL 55v7gXCYcoCZ4WHRhrcnQX20PDTtRSc5GPGEf2AdetXvvvxPIz6byxlThuvejkgAyOLXKR 7uk48uZSRIKDZOeDP/VAwyeMJlZR1T9lJGs3SEgCkYtDuWAodQLkcbhbUAqQ10tlquglkw G70LtGtP2N0o+XEKKN28HP3TU249JHgbG1Hytv+wiyNRruTH08VjaPozBBG4e552gObvzh H7SSg3MRhTJtW6BKWxeewGMMeoUrVHK3CZ9ZfMSg779uR76bT3Ka0HItU0CI/g== 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 2/4] ARM: at91: pm: move "atmel.pm_modes" parsing into a common file Date: Tue, 22 Feb 2022 16:08:44 +0100 Message-Id: <20220222150846.255307-3-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_071047_334199_A861095D X-CRM114-Status: GOOD ( 17.78 ) 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 In order to add secure suspend support, split out code that will be reused to parse the boot argument "atmel.pm_modes". Signed-off-by: Clément Léger Reported-by: kernel test robot --- arch/arm/mach-at91/Makefile | 2 +- arch/arm/mach-at91/pm.c | 31 ++------------------------- arch/arm/mach-at91/pm.h | 7 ++++++ arch/arm/mach-at91/pm_common.c | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 arch/arm/mach-at91/pm_common.c diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile index 0dcc37180588..23620ccf7ab6 100644 --- a/arch/arm/mach-at91/Makefile +++ b/arch/arm/mach-at91/Makefile @@ -12,7 +12,7 @@ obj-$(CONFIG_SOC_SAMA7) += sama7.o obj-$(CONFIG_SOC_SAMV7) += samv7.o # Power Management -obj-$(CONFIG_ATMEL_PM) += pm.o pm_suspend.o +obj-$(CONFIG_ATMEL_PM) += pm.o pm_suspend.o pm_common.o ifeq ($(CONFIG_CPU_V7),y) AFLAGS_pm_suspend.o := -march=armv7-a diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c index dd6f4ce3f766..b575304ccf63 100644 --- a/arch/arm/mach-at91/pm.c +++ b/arch/arm/mach-at91/pm.c @@ -99,15 +99,6 @@ static struct at91_soc_pm soc_pm = { }, }; -static const match_table_t pm_modes __initconst = { - { AT91_PM_STANDBY, "standby" }, - { AT91_PM_ULP0, "ulp0" }, - { AT91_PM_ULP0_FAST, "ulp0-fast" }, - { AT91_PM_ULP1, "ulp1" }, - { AT91_PM_BACKUP, "backup" }, - { -1, NULL }, -}; - #define at91_ramc_read(id, field) \ __raw_readl(soc_pm.data.ramc[id] + field) @@ -1243,25 +1234,7 @@ void __init sama7_pm_init(void) static int __init at91_pm_modes_select(char *str) { - char *s; - substring_t args[MAX_OPT_ARGS]; - int standby, suspend; - - if (!str) - return 0; - - s = strsep(&str, ","); - standby = match_token(s, pm_modes, args); - if (standby < 0) - return 0; - - suspend = match_token(str, pm_modes, args); - if (suspend < 0) - return 0; - - soc_pm.data.standby_mode = standby; - soc_pm.data.suspend_mode = suspend; - - return 0; + return at91_pm_common_modes_select(str, &soc_pm.data.standby_mode, + &soc_pm.data.suspend_mode); } early_param("atmel.pm_modes", at91_pm_modes_select); diff --git a/arch/arm/mach-at91/pm.h b/arch/arm/mach-at91/pm.h index 53bdc9000e44..e9f7f9841afd 100644 --- a/arch/arm/mach-at91/pm.h +++ b/arch/arm/mach-at91/pm.h @@ -40,6 +40,13 @@ struct at91_pm_data { unsigned int pmc_mckr_offset; unsigned int pmc_version; }; + +#include + +extern const match_table_t pm_modes; + +int at91_pm_common_modes_select(char *str, int *standby_mode, int *suspend_mode); + #endif #endif diff --git a/arch/arm/mach-at91/pm_common.c b/arch/arm/mach-at91/pm_common.c new file mode 100644 index 000000000000..45b74fb0a211 --- /dev/null +++ b/arch/arm/mach-at91/pm_common.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include +#include + +#include "pm.h" + +const match_table_t pm_modes __initconst = { + { AT91_PM_STANDBY, "standby" }, + { AT91_PM_ULP0, "ulp0" }, + { AT91_PM_ULP0_FAST, "ulp0-fast" }, + { AT91_PM_ULP1, "ulp1" }, + { AT91_PM_BACKUP, "backup" }, + { -1, NULL }, +}; + +int at91_pm_common_modes_select(char *str, int *standby_mode, int *suspend_mode) +{ + char *s; + substring_t args[MAX_OPT_ARGS]; + int standby, suspend; + + if (!str) + return 0; + + s = strsep(&str, ","); + standby = match_token(s, pm_modes, args); + if (standby < 0) + return 0; + + suspend = match_token(str, pm_modes, args); + if (suspend < 0) + return 0; + + *standby_mode = standby; + *suspend_mode = suspend; + + return 0; +} 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) From patchwork Tue Feb 22 15:08:46 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: 12755397 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 D89B8C433F5 for ; Tue, 22 Feb 2022 15:21:39 +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=JkISUm7pU/DHUJQhSbmzj4UZZo8488G1YFCoyKSH7jo=; b=2F7Bh2Dd/kQT3G TuastumtQfjKwz5ZiRpDnM/S+zoW6jd4pJoRPub+pAQLXR7JxSZIdoSr2AiOPsE7CYw3aoZYGSGqW 1a/bEWMTOHIVsi+tJVSDN2m0fbGK7LO+xmnHJ2MMOOAaeXzLrOIUMwVhqq7atFZaxOFQ9IWGBxQRg pXHztnTi5HsGpS/XKFYqvbhIAAJahVeIzPRKrk2FlxEMVmDq40BOk16K5Zc8wpSKodfcCfDl3bYjD sZTCn+hiDSuQ620Q0AQe6SIm1pmuSs4FKZFTHoNEUQvdNtE1EOzIz/DHyT900pWaQoB+sEPE2Xg+f IIq0EchslYuehXKUdE7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWxK-00AA52-DO; Tue, 22 Feb 2022 15:20:00 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMWoR-00A5sF-Cg for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 15:10:49 +0000 Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 898D9FF810; Tue, 22 Feb 2022 15:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645542645; 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=OOzUysK3jq7AptlFGEUXnbGP4YiZSWMiMjPJXH0yfpY=; b=KoqrDVr6S5OlXWjEh9c4iYJKN8olSySo1900gjM5a4ZLYyl6bswEjGjPjdRduSC94LCTO5 kj2rP9rEZ4nYnOwyqg10Fb1H74hEgYfy4E3V73F6j35Q0cSdz88m0kdOxtzB1kTan/mjXw 17Q9zmwPbQLPOQFB+CmydJ/NQy0CsVigvKTaoB5Wb0YAhre5bN9NyRtEpSKk6IKygezoxK +whlrdy29Xm7kZjgkZwugh/wIV0UlY55jBFvvV5ybxVzVL4cOmYr7XU05ZhNsEzCOuSCQF WGagLCDdZDvqrh0wlILMqm5AbS4ItvD/njce9TQMRQX3+3vwLOlF7DIGgmG0Ew== 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 4/4] ARM: at91: pm: fix defines to select *_pm_init functions Date: Tue, 22 Feb 2022 16:08:46 +0100 Message-Id: <20220222150846.255307-5-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_071047_674663_A256730F X-CRM114-Status: GOOD ( 11.15 ) 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 These defines actually don't depend on CONFIG_PM but CONFIG_ATMEL_PM. In the same time, add a "or" with CONFIG_ATMEL_SECURE_PM since it can also provides these functions. Signed-off-by: Clément Léger --- arch/arm/mach-at91/generic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-at91/generic.h b/arch/arm/mach-at91/generic.h index 0c3960a8b3eb..279ab7e0cdca 100644 --- a/arch/arm/mach-at91/generic.h +++ b/arch/arm/mach-at91/generic.h @@ -8,7 +8,7 @@ #ifndef _AT91_GENERIC_H #define _AT91_GENERIC_H -#ifdef CONFIG_PM +#if defined(CONFIG_ATMEL_PM) || defined(CONFIG_ATMEL_SECURE_PM) extern void __init at91rm9200_pm_init(void); extern void __init at91sam9_pm_init(void); extern void __init sam9x60_pm_init(void);