xref: /rk3399_ARM-atf/plat/arm/board/tc/tc_stack_protector.c (revision e7be9243d071b37d13d826824ec4bb8c8b39caa2)
1 /*
2  * Copyright (c) 2024, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <stdint.h>
8 
9 #include <arch_helpers.h>
10 #include <plat/common/platform.h>
11 
12 #define RANDOM_CANARY_VALUE ((u_register_t) 3288484550995823360ULL)
13 
14 u_register_t plat_get_stack_protector_canary(void)
15 {
16 	/*
17 	 * On the Total Compute platform, it can generate RNG via MHU channel
18 	 * and communicate with RSE. But the stack protector canary function
19 	 * is needed prior to MHU channel gets ready.
20 	 *
21 	 * Since now MHU module cannot distinguish if MHU channel has been
22 	 * initialized or not, if it arbitrarily tries to send message, it will
23 	 * cause panic. For this reason, this function cannot rollback to
24 	 * dummy random number based on the MHU failure.
25 	 *
26 	 * For above reasons, simply return a value of the combination of a
27 	 * timer's value and a compile-time constant.
28 	 */
29 	return RANDOM_CANARY_VALUE ^ read_cntpct_el0();
30 }
31