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