Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013, NVIDIA Corporation. |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 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 | |
Thierry Reding | 4cb5d9e | 2019-04-10 10:47:28 +0200 | [diff] [blame] | 17 | #ifndef __FIRMWARE_TRUSTED_FOUNDATIONS_H |
| 18 | #define __FIRMWARE_TRUSTED_FOUNDATIONS_H |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 19 | |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 20 | #include <linux/printk.h> |
| 21 | #include <linux/bug.h> |
| 22 | #include <linux/of.h> |
Alexandre Courbot | c3af6d6 | 2014-02-07 13:35:02 +0900 | [diff] [blame] | 23 | #include <linux/cpu.h> |
| 24 | #include <linux/smp.h> |
Dmitry Osipenko | ebc7c1a | 2019-03-18 01:52:06 +0300 | [diff] [blame] | 25 | #include <linux/types.h> |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 26 | |
Dmitry Osipenko | ebca2a6 | 2019-03-18 01:52:04 +0300 | [diff] [blame] | 27 | #include <asm/hardware/cache-l2x0.h> |
| 28 | #include <asm/outercache.h> |
| 29 | |
Dmitry Osipenko | 96446e2 | 2019-03-18 01:52:05 +0300 | [diff] [blame] | 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 | |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 36 | struct trusted_foundations_platform_data { |
| 37 | unsigned int version_major; |
| 38 | unsigned int version_minor; |
| 39 | }; |
| 40 | |
| 41 | #if IS_ENABLED(CONFIG_TRUSTED_FOUNDATIONS) |
| 42 | |
| 43 | void register_trusted_foundations(struct trusted_foundations_platform_data *pd); |
| 44 | void of_register_trusted_foundations(void); |
Dmitry Osipenko | ebc7c1a | 2019-03-18 01:52:06 +0300 | [diff] [blame] | 45 | bool trusted_foundations_registered(void); |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 46 | |
| 47 | #else /* CONFIG_TRUSTED_FOUNDATIONS */ |
Dmitry Osipenko | ebca2a6 | 2019-03-18 01:52:04 +0300 | [diff] [blame] | 48 | static inline void tf_dummy_write_sec(unsigned long val, unsigned int reg) |
| 49 | { |
| 50 | } |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 51 | |
| 52 | static inline void register_trusted_foundations( |
| 53 | struct trusted_foundations_platform_data *pd) |
| 54 | { |
| 55 | /* |
Alexandre Courbot | c3af6d6 | 2014-02-07 13:35:02 +0900 | [diff] [blame] | 56 | * If the system requires TF and we cannot provide it, continue booting |
| 57 | * but disable features that cannot be provided. |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 58 | */ |
Alexandre Courbot | c3af6d6 | 2014-02-07 13:35:02 +0900 | [diff] [blame] | 59 | pr_err("No support for Trusted Foundations, continuing in degraded mode.\n"); |
| 60 | pr_err("Secondary processors as well as CPU PM will be disabled.\n"); |
Dmitry Osipenko | ebca2a6 | 2019-03-18 01:52:04 +0300 | [diff] [blame] | 61 | #if IS_ENABLED(CONFIG_CACHE_L2X0) |
| 62 | pr_err("L2X0 cache will be kept disabled.\n"); |
| 63 | outer_cache.write_sec = tf_dummy_write_sec; |
| 64 | #endif |
Alexandre Courbot | 3aae97c | 2014-05-23 09:23:32 +0900 | [diff] [blame] | 65 | #if IS_ENABLED(CONFIG_SMP) |
Alexandre Courbot | c3af6d6 | 2014-02-07 13:35:02 +0900 | [diff] [blame] | 66 | setup_max_cpus = 0; |
Alexandre Courbot | 3aae97c | 2014-05-23 09:23:32 +0900 | [diff] [blame] | 67 | #endif |
Alexandre Courbot | c3af6d6 | 2014-02-07 13:35:02 +0900 | [diff] [blame] | 68 | cpu_idle_poll_ctrl(true); |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline void of_register_trusted_foundations(void) |
| 72 | { |
| 73 | /* |
| 74 | * If we find the target should enable TF but does not support it, |
| 75 | * fail as the system won't be able to do much anyway |
| 76 | */ |
Alexandre Courbot | a553b7f | 2014-02-07 13:35:01 +0900 | [diff] [blame] | 77 | if (of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations")) |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 78 | register_trusted_foundations(NULL); |
| 79 | } |
Dmitry Osipenko | ebc7c1a | 2019-03-18 01:52:06 +0300 | [diff] [blame] | 80 | |
| 81 | static inline bool trusted_foundations_registered(void) |
| 82 | { |
| 83 | return false; |
| 84 | } |
Alexandre Courbot | d9a1bea | 2013-11-24 15:30:46 +0900 | [diff] [blame] | 85 | #endif /* CONFIG_TRUSTED_FOUNDATIONS */ |
| 86 | |
| 87 | #endif |