blob: 4064e7c747156999b122b427e1dd24b47375fcd7 [file] [log] [blame]
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +09001/*
2 * Copyright (c) 2013, NVIDIA Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 * Support for the Trusted Foundations secure monitor.
17 *
18 * Trusted Foundation comes active on some ARM consumer devices (most
19 * Tegra-based devices sold on the market are concerned). Such devices can only
20 * perform some basic operations, like setting the CPU reset vector, through
21 * SMC calls to the secure monitor. The calls are completely specific to
22 * Trusted Foundations, and do *not* follow the SMC calling convention or the
23 * PSCI standard.
24 */
25
Thierry Reding4cb5d9e2019-04-10 10:47:28 +020026#ifndef __FIRMWARE_TRUSTED_FOUNDATIONS_H
27#define __FIRMWARE_TRUSTED_FOUNDATIONS_H
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090028
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090029#include <linux/printk.h>
30#include <linux/bug.h>
31#include <linux/of.h>
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090032#include <linux/cpu.h>
33#include <linux/smp.h>
Dmitry Osipenkoebc7c1a2019-03-18 01:52:06 +030034#include <linux/types.h>
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090035
Dmitry Osipenkoebca2a62019-03-18 01:52:04 +030036#include <asm/hardware/cache-l2x0.h>
37#include <asm/outercache.h>
38
Dmitry Osipenko96446e22019-03-18 01:52:05 +030039#define TF_PM_MODE_LP0 0
40#define TF_PM_MODE_LP1 1
41#define TF_PM_MODE_LP1_NO_MC_CLK 2
42#define TF_PM_MODE_LP2 3
43#define TF_PM_MODE_LP2_NOFLUSH_L2 4
44
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090045struct trusted_foundations_platform_data {
46 unsigned int version_major;
47 unsigned int version_minor;
48};
49
50#if IS_ENABLED(CONFIG_TRUSTED_FOUNDATIONS)
51
52void register_trusted_foundations(struct trusted_foundations_platform_data *pd);
53void of_register_trusted_foundations(void);
Dmitry Osipenkoebc7c1a2019-03-18 01:52:06 +030054bool trusted_foundations_registered(void);
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090055
56#else /* CONFIG_TRUSTED_FOUNDATIONS */
Dmitry Osipenkoebca2a62019-03-18 01:52:04 +030057static inline void tf_dummy_write_sec(unsigned long val, unsigned int reg)
58{
59}
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090060
61static inline void register_trusted_foundations(
62 struct trusted_foundations_platform_data *pd)
63{
64 /*
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090065 * If the system requires TF and we cannot provide it, continue booting
66 * but disable features that cannot be provided.
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090067 */
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090068 pr_err("No support for Trusted Foundations, continuing in degraded mode.\n");
69 pr_err("Secondary processors as well as CPU PM will be disabled.\n");
Dmitry Osipenkoebca2a62019-03-18 01:52:04 +030070#if IS_ENABLED(CONFIG_CACHE_L2X0)
71 pr_err("L2X0 cache will be kept disabled.\n");
72 outer_cache.write_sec = tf_dummy_write_sec;
73#endif
Alexandre Courbot3aae97c2014-05-23 09:23:32 +090074#if IS_ENABLED(CONFIG_SMP)
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090075 setup_max_cpus = 0;
Alexandre Courbot3aae97c2014-05-23 09:23:32 +090076#endif
Alexandre Courbotc3af6d62014-02-07 13:35:02 +090077 cpu_idle_poll_ctrl(true);
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090078}
79
80static inline void of_register_trusted_foundations(void)
81{
82 /*
83 * If we find the target should enable TF but does not support it,
84 * fail as the system won't be able to do much anyway
85 */
Alexandre Courbota553b7f2014-02-07 13:35:01 +090086 if (of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations"))
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090087 register_trusted_foundations(NULL);
88}
Dmitry Osipenkoebc7c1a2019-03-18 01:52:06 +030089
90static inline bool trusted_foundations_registered(void)
91{
92 return false;
93}
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090094#endif /* CONFIG_TRUSTED_FOUNDATIONS */
95
96#endif