Skip to content

Commit 48840e1

Browse files
glneotmlind
authored andcommitted
ARM: OMAP2+: Use ARM SMC Calling Convention when OP-TEE is available
On High-Security(HS) OMAP2+ class devices a couple actions must be performed from the ARM TrustZone during boot. These traditionally can be performed by calling into the secure ROM code resident in this secure world using legacy SMC calls. Optionally OP-TEE can replace this secure world functionality by replacing the ROM after boot. ARM recommends a standard calling convention is used for this interaction (SMC Calling Convention). We check for the presence of OP-TEE and use this type of call to perform the needed actions, falling back to the legacy OMAP ROM call if OP-TEE is not available. Signed-off-by: Andrew F. Davis <[email protected]> Reviewed-by: Lokesh Vutla <[email protected]> Signed-off-by: Tony Lindgren <[email protected]>
1 parent dbebc8b commit 48840e1

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

arch/arm/mach-omap2/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ extern void gic_dist_disable(void);
255255
extern void gic_dist_enable(void);
256256
extern bool gic_dist_disabled(void);
257257
extern void gic_timer_retrigger(void);
258-
extern void omap_smc1(u32 fn, u32 arg);
258+
extern void _omap_smc1(u32 fn, u32 arg);
259259
extern void omap4_sar_ram_init(void);
260260
extern void __iomem *omap4_get_sar_ram_base(void);
261261
extern void omap4_mpuss_early_init(void);

arch/arm/mach-omap2/omap-secure.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Copyright (C) 2013 Pali Rohár <[email protected]>
99
*/
1010

11+
#include <linux/arm-smccc.h>
1112
#include <linux/kernel.h>
1213
#include <linux/init.h>
1314
#include <linux/io.h>
@@ -17,12 +18,17 @@
1718
#include <asm/cacheflush.h>
1819
#include <asm/memblock.h>
1920

21+
#include "common.h"
2022
#include "omap-secure.h"
2123

2224
static phys_addr_t omap_secure_memblock_base;
2325

2426
bool optee_available;
2527

28+
#define OMAP_SIP_SMC_STD_CALL_VAL(func_num) \
29+
ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
30+
ARM_SMCCC_OWNER_SIP, (func_num))
31+
2632
static void __init omap_optee_init_check(void)
2733
{
2834
struct device_node *np;
@@ -71,6 +77,27 @@ u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2,
7177
return ret;
7278
}
7379

80+
void omap_smccc_smc(u32 fn, u32 arg)
81+
{
82+
struct arm_smccc_res res;
83+
84+
arm_smccc_smc(OMAP_SIP_SMC_STD_CALL_VAL(fn), arg,
85+
0, 0, 0, 0, 0, 0, &res);
86+
WARN(res.a0, "Secure function call 0x%08x failed\n", fn);
87+
}
88+
89+
void omap_smc1(u32 fn, u32 arg)
90+
{
91+
/*
92+
* If this platform has OP-TEE installed we use ARM SMC calls
93+
* otherwise fall back to the OMAP ROM style calls.
94+
*/
95+
if (optee_available)
96+
omap_smccc_smc(fn, arg);
97+
else
98+
_omap_smc1(fn, arg);
99+
}
100+
74101
/* Allocate the memory to save secure ram */
75102
int __init omap_secure_ram_reserve_memblock(void)
76103
{

arch/arm/mach-omap2/omap-secure.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262

6363
extern u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs,
6464
u32 arg1, u32 arg2, u32 arg3, u32 arg4);
65+
extern void omap_smccc_smc(u32 fn, u32 arg);
66+
extern void omap_smc1(u32 fn, u32 arg);
6567
extern u32 omap_smc2(u32 id, u32 falg, u32 pargs);
6668
extern u32 omap_smc3(u32 id, u32 process, u32 flag, u32 pargs);
6769
extern phys_addr_t omap_secure_ram_mempool_base(void);

arch/arm/mach-omap2/omap-smc.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
* the monitor API number. It uses few CPU registers
1919
* internally and hence they need be backed up including
2020
* link register "lr".
21-
* Function signature : void omap_smc1(u32 fn, u32 arg)
21+
* Function signature : void _omap_smc1(u32 fn, u32 arg)
2222
*/
2323
.arch armv7-a
2424
.arch_extension sec
25-
ENTRY(omap_smc1)
25+
ENTRY(_omap_smc1)
2626
stmfd sp!, {r2-r12, lr}
2727
mov r12, r0
2828
mov r0, r1
2929
dsb
3030
smc #0
3131
ldmfd sp!, {r2-r12, pc}
32-
ENDPROC(omap_smc1)
32+
ENDPROC(_omap_smc1)
3333

3434
/**
3535
* u32 omap_smc2(u32 id, u32 falg, u32 pargs)

0 commit comments

Comments
 (0)