blob: 2549a2db56aa88aff38df04e54555a08474f9514 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +09002/*
3 * Copyright (c) 2013, NVIDIA Corporation.
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +09004 */
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 Reding4cb5d9e2019-04-10 10:47:28 +020017#ifndef __FIRMWARE_TRUSTED_FOUNDATIONS_H
18#define __FIRMWARE_TRUSTED_FOUNDATIONS_H
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090019
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090020#include <linux/printk.h>
21#include <linux/bug.h>
22#include <linux/of.h>
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090023#include <linux/cpu.h>
24#include <linux/smp.h>
Dmitry Osipenkoebc7c1a2019-03-18 01:52:06 +030025#include <linux/types.h>
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090026
Dmitry Osipenkoebca2a62019-03-18 01:52:04 +030027#include <asm/hardware/cache-l2x0.h>
28#include <asm/outercache.h>
29
Dmitry Osipenko96446e22019-03-18 01:52:05 +030030#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 Courbotd9a1bea2013-11-24 15:30:46 +090036struct trusted_foundations_platform_data {
37 unsigned int version_major;
38 unsigned int version_minor;
39};
40
41#if IS_ENABLED(CONFIG_TRUSTED_FOUNDATIONS)
42
43void register_trusted_foundations(struct trusted_foundations_platform_data *pd);
44void of_register_trusted_foundations(void);
Dmitry Osipenkoebc7c1a2019-03-18 01:52:06 +030045bool trusted_foundations_registered(void);
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090046
47#else /* CONFIG_TRUSTED_FOUNDATIONS */
Dmitry Osipenkoebca2a62019-03-18 01:52:04 +030048static inline void tf_dummy_write_sec(unsigned long val, unsigned int reg)
49{
50}
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090051
52static inline void register_trusted_foundations(
53 struct trusted_foundations_platform_data *pd)
54{
55 /*
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090056 * If the system requires TF and we cannot provide it, continue booting
57 * but disable features that cannot be provided.
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090058 */
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090059 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 Osipenkoebca2a62019-03-18 01:52:04 +030061#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 Courbot3aae97c2014-05-23 09:23:32 +090065#if IS_ENABLED(CONFIG_SMP)
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090066 setup_max_cpus = 0;
Alexandre Courbot3aae97c2014-05-23 09:23:32 +090067#endif
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090068 cpu_idle_poll_ctrl(true);
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090069}
70
71static 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 Courbota553b7f2014-02-07 13:35:01 +090077 if (of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations"))
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090078 register_trusted_foundations(NULL);
79}
Dmitry Osipenkoebc7c1a2019-03-18 01:52:06 +030080
81static inline bool trusted_foundations_registered(void)
82{
83 return false;
84}
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090085#endif /* CONFIG_TRUSTED_FOUNDATIONS */
86
87#endif