xref: /OK3568_Linux_fs/kernel/include/linux/firmware/trusted_foundations.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2013, NVIDIA Corporation.
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun /*
7*4882a593Smuzhiyun  * Support for the Trusted Foundations secure monitor.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Trusted Foundation comes active on some ARM consumer devices (most
10*4882a593Smuzhiyun  * Tegra-based devices sold on the market are concerned). Such devices can only
11*4882a593Smuzhiyun  * perform some basic operations, like setting the CPU reset vector, through
12*4882a593Smuzhiyun  * SMC calls to the secure monitor. The calls are completely specific to
13*4882a593Smuzhiyun  * Trusted Foundations, and do *not* follow the SMC calling convention or the
14*4882a593Smuzhiyun  * PSCI standard.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifndef __FIRMWARE_TRUSTED_FOUNDATIONS_H
18*4882a593Smuzhiyun #define __FIRMWARE_TRUSTED_FOUNDATIONS_H
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/printk.h>
21*4882a593Smuzhiyun #include <linux/bug.h>
22*4882a593Smuzhiyun #include <linux/of.h>
23*4882a593Smuzhiyun #include <linux/cpu.h>
24*4882a593Smuzhiyun #include <linux/smp.h>
25*4882a593Smuzhiyun #include <linux/types.h>
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include <asm/hardware/cache-l2x0.h>
28*4882a593Smuzhiyun #include <asm/outercache.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define TF_PM_MODE_LP0			0
31*4882a593Smuzhiyun #define TF_PM_MODE_LP1			1
32*4882a593Smuzhiyun #define TF_PM_MODE_LP1_NO_MC_CLK	2
33*4882a593Smuzhiyun #define TF_PM_MODE_LP2			3
34*4882a593Smuzhiyun #define TF_PM_MODE_LP2_NOFLUSH_L2	4
35*4882a593Smuzhiyun #define TF_PM_MODE_NONE			5
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun struct trusted_foundations_platform_data {
38*4882a593Smuzhiyun 	unsigned int version_major;
39*4882a593Smuzhiyun 	unsigned int version_minor;
40*4882a593Smuzhiyun };
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_TRUSTED_FOUNDATIONS)
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun void register_trusted_foundations(struct trusted_foundations_platform_data *pd);
45*4882a593Smuzhiyun void of_register_trusted_foundations(void);
46*4882a593Smuzhiyun bool trusted_foundations_registered(void);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #else /* CONFIG_TRUSTED_FOUNDATIONS */
tf_dummy_write_sec(unsigned long val,unsigned int reg)49*4882a593Smuzhiyun static inline void tf_dummy_write_sec(unsigned long val, unsigned int reg)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
register_trusted_foundations(struct trusted_foundations_platform_data * pd)53*4882a593Smuzhiyun static inline void register_trusted_foundations(
54*4882a593Smuzhiyun 				   struct trusted_foundations_platform_data *pd)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun 	/*
57*4882a593Smuzhiyun 	 * If the system requires TF and we cannot provide it, continue booting
58*4882a593Smuzhiyun 	 * but disable features that cannot be provided.
59*4882a593Smuzhiyun 	 */
60*4882a593Smuzhiyun 	pr_err("No support for Trusted Foundations, continuing in degraded mode.\n");
61*4882a593Smuzhiyun 	pr_err("Secondary processors as well as CPU PM will be disabled.\n");
62*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_CACHE_L2X0)
63*4882a593Smuzhiyun 	pr_err("L2X0 cache will be kept disabled.\n");
64*4882a593Smuzhiyun 	outer_cache.write_sec = tf_dummy_write_sec;
65*4882a593Smuzhiyun #endif
66*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SMP)
67*4882a593Smuzhiyun 	setup_max_cpus = 0;
68*4882a593Smuzhiyun #endif
69*4882a593Smuzhiyun 	cpu_idle_poll_ctrl(true);
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun 
of_register_trusted_foundations(void)72*4882a593Smuzhiyun static inline void of_register_trusted_foundations(void)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	/*
75*4882a593Smuzhiyun 	 * If we find the target should enable TF but does not support it,
76*4882a593Smuzhiyun 	 * fail as the system won't be able to do much anyway
77*4882a593Smuzhiyun 	 */
78*4882a593Smuzhiyun 	if (of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations"))
79*4882a593Smuzhiyun 		register_trusted_foundations(NULL);
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun 
trusted_foundations_registered(void)82*4882a593Smuzhiyun static inline bool trusted_foundations_registered(void)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	return false;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun #endif /* CONFIG_TRUSTED_FOUNDATIONS */
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun #endif
89