1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP Secure API infrastructure.
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 * Santosh Shilimkar <santosh.shilimkar@ti.com>
7 * Copyright (C) 2012 Ivaylo Dimitrov <freemangordon@abv.bg>
8 * Copyright (C) 2013 Pali Rohár <pali@kernel.org>
11 #include <linux/arm-smccc.h>
12 #include <linux/cpu_pm.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
16 #include <linux/memblock.h>
19 #include <asm/cacheflush.h>
20 #include <asm/memblock.h>
23 #include "omap-secure.h"
26 static phys_addr_t omap_secure_memblock_base
;
30 #define OMAP_SIP_SMC_STD_CALL_VAL(func_num) \
31 ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
32 ARM_SMCCC_OWNER_SIP, (func_num))
34 static void __init
omap_optee_init_check(void)
36 struct device_node
*np
;
39 * We only check that the OP-TEE node is present and available. The
40 * OP-TEE kernel driver is not needed for the type of interaction made
41 * with OP-TEE here so the driver's status is not checked.
43 np
= of_find_node_by_path("/firmware/optee");
44 if (np
&& of_device_is_available(np
))
45 optee_available
= true;
50 * omap_secure_dispatcher - Routine to dispatch low power secure
52 * @idx: The HAL API index
53 * @flag: The flag indicating criticality of operation
54 * @nargs: Number of valid arguments out of four.
55 * @arg1, arg2, arg3 args4: Parameters passed to secure API
57 * Return the non-zero error value on failure.
59 u32
omap_secure_dispatcher(u32 idx
, u32 flag
, u32 nargs
, u32 arg1
, u32 arg2
,
62 static u32 buf
[NR_CPUS
][5];
77 * Secure API needs physical address
78 * pointer for the parameters
81 outer_clean_range(__pa(param
), __pa(param
+ 5));
82 ret
= omap_smc2(idx
, flag
, __pa(param
));
89 void omap_smccc_smc(u32 fn
, u32 arg
)
91 struct arm_smccc_res res
;
93 arm_smccc_smc(OMAP_SIP_SMC_STD_CALL_VAL(fn
), arg
,
94 0, 0, 0, 0, 0, 0, &res
);
95 WARN(res
.a0
, "Secure function call 0x%08x failed\n", fn
);
98 void omap_smc1(u32 fn
, u32 arg
)
101 * If this platform has OP-TEE installed we use ARM SMC calls
102 * otherwise fall back to the OMAP ROM style calls.
105 omap_smccc_smc(fn
, arg
);
110 /* Allocate the memory to save secure ram */
111 int __init
omap_secure_ram_reserve_memblock(void)
113 u32 size
= OMAP_SECURE_RAM_STORAGE
;
115 size
= ALIGN(size
, SECTION_SIZE
);
116 omap_secure_memblock_base
= arm_memblock_steal(size
, SECTION_SIZE
);
121 #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
122 u32
omap3_save_secure_ram(void *addr
, int size
)
127 if (size
!= OMAP3_SAVE_SECURE_RAM_SZ
)
128 return OMAP3_SAVE_SECURE_RAM_SZ
;
130 param
[0] = 4; /* Number of arguments */
131 param
[1] = __pa(addr
); /* Physical address for saving */
136 ret
= save_secure_ram_context(__pa(param
));
143 * rx51_secure_dispatcher: Routine to dispatch secure PPA API calls
144 * @idx: The PPA API index
145 * @process: Process ID
146 * @flag: The flag indicating criticality of operation
147 * @nargs: Number of valid arguments out of four.
148 * @arg1, arg2, arg3 args4: Parameters passed to secure API
150 * Return the non-zero error value on failure.
152 * NOTE: rx51_secure_dispatcher differs from omap_secure_dispatcher because
153 * it calling omap_smc3() instead omap_smc2() and param[0] is nargs+1
155 static u32
rx51_secure_dispatcher(u32 idx
, u32 process
, u32 flag
, u32 nargs
,
156 u32 arg1
, u32 arg2
, u32 arg3
, u32 arg4
)
161 param
[0] = nargs
+1; /* RX-51 needs number of arguments + 1 */
168 * Secure API needs physical address
169 * pointer for the parameters
174 outer_clean_range(__pa(param
), __pa(param
+ 5));
175 ret
= omap_smc3(idx
, process
, flag
, __pa(param
));
184 * rx51_secure_update_aux_cr: Routine to modify the contents of Auxiliary Control Register
185 * @set_bits: bits to set in ACR
186 * @clear_bits: bits to clear in ACR
188 * Return the non-zero error value on failure.
190 u32
rx51_secure_update_aux_cr(u32 set_bits
, u32 clear_bits
)
195 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr
));
199 return rx51_secure_dispatcher(RX51_PPA_WRITE_ACR
,
206 * rx51_secure_rng_call: Routine for HW random generator
208 u32
rx51_secure_rng_call(u32 ptr
, u32 count
, u32 flag
)
210 return rx51_secure_dispatcher(RX51_PPA_HWRNG
,
213 3, ptr
, count
, flag
, 0);
216 void __init
omap_secure_init(void)
218 omap_optee_init_check();
222 * Dummy dispatcher call after core OSWR and MPU off. Updates the ROM return
223 * address after MMU has been re-enabled after CPU1 has been woken up again.
224 * Otherwise the ROM code will attempt to use the earlier physical return
225 * address that got set with MMU off when waking up CPU1. Only used on secure
228 static int cpu_notifier(struct notifier_block
*nb
, unsigned long cmd
, void *v
)
231 case CPU_CLUSTER_PM_EXIT
:
232 omap_secure_dispatcher(OMAP4_PPA_SERVICE_0
,
243 static struct notifier_block secure_notifier_block
= {
244 .notifier_call
= cpu_notifier
,
247 static int __init
secure_pm_init(void)
249 if (omap_type() == OMAP2_DEVICE_TYPE_GP
|| !soc_is_omap44xx())
252 cpu_pm_register_notifier(&secure_notifier_block
);
256 omap_arch_initcall(secure_pm_init
);