Skip to content

Commit 0c9fd82

Browse files
clementlegerclaudiubeznea
authored andcommitted
ARM: at91: add code to handle secure calls
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 <clement.leger@bootlin.com> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> Signed-off-by: Nicolas Ferre <nicolas.ferre@microchip.com>
1 parent f611af4 commit 0c9fd82

4 files changed

Lines changed: 63 additions & 1 deletion

File tree

arch/arm/mach-at91/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
obj-$(CONFIG_SOC_AT91RM9200) += at91rm9200.o
88
obj-$(CONFIG_SOC_AT91SAM9) += at91sam9.o
99
obj-$(CONFIG_SOC_SAM9X60) += sam9x60.o
10-
obj-$(CONFIG_SOC_SAMA5) += sama5.o
10+
obj-$(CONFIG_SOC_SAMA5) += sama5.o sam_secure.o
1111
obj-$(CONFIG_SOC_SAMA7) += sama7.o
1212
obj-$(CONFIG_SOC_SAMV7) += samv7.o
1313

arch/arm/mach-at91/sam_secure.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (C) 2022, Microchip
4+
*/
5+
6+
#include <linux/arm-smccc.h>
7+
#include <linux/of.h>
8+
9+
#include "sam_secure.h"
10+
11+
static bool optee_available;
12+
13+
#define SAM_SIP_SMC_STD_CALL_VAL(func_num) \
14+
ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
15+
ARM_SMCCC_OWNER_SIP, (func_num))
16+
17+
struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1)
18+
{
19+
struct arm_smccc_res res = {.a0 = -1};
20+
21+
if (WARN_ON(!optee_available))
22+
return res;
23+
24+
arm_smccc_smc(SAM_SIP_SMC_STD_CALL_VAL(fn), arg0, arg1, 0, 0, 0, 0, 0,
25+
&res);
26+
27+
return res;
28+
}
29+
30+
void __init sam_secure_init(void)
31+
{
32+
struct device_node *np;
33+
34+
/*
35+
* We only check that the OP-TEE node is present and available. The
36+
* OP-TEE kernel driver is not needed for the type of interaction made
37+
* with OP-TEE here so the driver's status is not checked.
38+
*/
39+
np = of_find_node_by_path("/firmware/optee");
40+
if (np && of_device_is_available(np))
41+
optee_available = true;
42+
of_node_put(np);
43+
44+
if (optee_available)
45+
pr_info("Running under OP-TEE firmware\n");
46+
}

arch/arm/mach-at91/sam_secure.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2022, Microchip
4+
*/
5+
6+
#ifndef SAM_SECURE_H
7+
#define SAM_SECURE_H
8+
9+
#include <linux/arm-smccc.h>
10+
11+
void __init sam_secure_init(void);
12+
struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1);
13+
14+
#endif /* SAM_SECURE_H */

arch/arm/mach-at91/sama5.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/system_misc.h>
1515

1616
#include "generic.h"
17+
#include "sam_secure.h"
1718

1819
static void __init sama5_dt_device_init(void)
1920
{
@@ -47,6 +48,7 @@ MACHINE_END
4748
static void __init sama5d2_init(void)
4849
{
4950
of_platform_default_populate(NULL, NULL, NULL);
51+
sam_secure_init();
5052
sama5d2_pm_init();
5153
}
5254

0 commit comments

Comments
 (0)