aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlof Johansson <olof@lixom.net>2013-12-26 14:00:13 -0500
committerOlof Johansson <olof@lixom.net>2013-12-26 14:01:11 -0500
commit51b052b0d31666e64cb97d3c620c0baff4792d91 (patch)
treeccdc40870bcc30d703ec891904d1bfd1f3e53c30
parent4ac63adc4f29f92a019b54eb02425357cf6c2967 (diff)
parentf47d41acfd65919c669921674444caa471723c87 (diff)
Merge tag 'tegra-for-3.14-trusted-foundations' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux into next/drivers
From Stephen Warren: ARM: tegra: Trusted Foundations firmware support Add support for the Trusted Foundations secure-mode firmware, as found on NVIDIA SHIELD. This allows Linux to run in non-secure mode on this board; all previous Tegra support has assumed the kernel is running in secure mode. (The base TF support has been discussed back and forth a lot; for now the most logical place for it seems to be under arch/arm, so we're adding it here. We can move it out to a common location in the future if needed). * tag 'tegra-for-3.14-trusted-foundations' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux: ARM: tegra: support Trusted Foundations by default ARM: tegra: set CPU reset handler using firmware ARM: tegra: split setting of CPU reset handler ARM: tegra: add support for Trusted Foundations of: add Trusted Foundations bindings documentation of: add vendor prefix for Trusted Logic Mobility ARM: add basic support for Trusted Foundations Signed-off-by: Olof Johansson <olof@lixom.net>
-rw-r--r--Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt20
-rw-r--r--Documentation/devicetree/bindings/arm/tegra.txt5
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.txt1
-rw-r--r--arch/arm/Kconfig2
-rw-r--r--arch/arm/Makefile1
-rw-r--r--arch/arm/configs/tegra_defconfig1
-rw-r--r--arch/arm/firmware/Kconfig28
-rw-r--r--arch/arm/firmware/Makefile1
-rw-r--r--arch/arm/firmware/trusted_foundations.c81
-rw-r--r--arch/arm/include/asm/trusted_foundations.h67
-rw-r--r--arch/arm/mach-tegra/Kconfig1
-rw-r--r--arch/arm/mach-tegra/reset.c40
-rw-r--r--arch/arm/mach-tegra/tegra.c2
13 files changed, 239 insertions, 11 deletions
diff --git a/Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt b/Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt
new file mode 100644
index 000000000000..780d0392a66b
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt
@@ -0,0 +1,20 @@
1Trusted Foundations
2-------------------
3
4Boards that use the Trusted Foundations secure monitor can signal its
5presence by declaring a node compatible with "tlm,trusted-foundations"
6under the /firmware/ node
7
8Required properties:
9- compatible: "tlm,trusted-foundations"
10- tlm,version-major: major version number of Trusted Foundations firmware
11- tlm,version-minor: minor version number of Trusted Foundations firmware
12
13Example:
14 firmware {
15 trusted-foundations {
16 compatible = "tlm,trusted-foundations";
17 tlm,version-major = <2>;
18 tlm,version-minor = <8>;
19 };
20 };
diff --git a/Documentation/devicetree/bindings/arm/tegra.txt b/Documentation/devicetree/bindings/arm/tegra.txt
index ed9c85334436..558ed4b4ef39 100644
--- a/Documentation/devicetree/bindings/arm/tegra.txt
+++ b/Documentation/devicetree/bindings/arm/tegra.txt
@@ -32,3 +32,8 @@ board-specific compatible values:
32 nvidia,whistler 32 nvidia,whistler
33 toradex,colibri_t20-512 33 toradex,colibri_t20-512
34 toradex,iris 34 toradex,iris
35
36Trusted Foundations
37-------------------------------------------
38Tegra supports the Trusted Foundation secure monitor. See the
39"tlm,trusted-foundations" binding's documentation for more details.
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index ce95ed1c6d3e..30261c831097 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -71,6 +71,7 @@ st STMicroelectronics
71ste ST-Ericsson 71ste ST-Ericsson
72stericsson ST-Ericsson 72stericsson ST-Ericsson
73ti Texas Instruments 73ti Texas Instruments
74tlm Trusted Logic Mobility
74toshiba Toshiba Corporation 75toshiba Toshiba Corporation
75toumaz Toumaz 76toumaz Toumaz
76v3 V3 Semiconductor 77v3 V3 Semiconductor
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ba0e23234ecf..ab8f2eb731bb 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1054,6 +1054,8 @@ config ARM_TIMER_SP804
1054 select CLKSRC_MMIO 1054 select CLKSRC_MMIO
1055 select CLKSRC_OF if OF 1055 select CLKSRC_OF if OF
1056 1056
1057source "arch/arm/firmware/Kconfig"
1058
1057source arch/arm/mm/Kconfig 1059source arch/arm/mm/Kconfig
1058 1060
1059config ARM_NR_BANKS 1061config ARM_NR_BANKS
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index c99b1086d83d..2cb05d4e4230 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -268,6 +268,7 @@ core-$(CONFIG_KVM_ARM_HOST) += arch/arm/kvm/
268core-y += arch/arm/kernel/ arch/arm/mm/ arch/arm/common/ 268core-y += arch/arm/kernel/ arch/arm/mm/ arch/arm/common/
269core-y += arch/arm/net/ 269core-y += arch/arm/net/
270core-y += arch/arm/crypto/ 270core-y += arch/arm/crypto/
271core-y += arch/arm/firmware/
271core-y += $(machdirs) $(platdirs) 272core-y += $(machdirs) $(platdirs)
272 273
273drivers-$(CONFIG_OPROFILE) += arch/arm/oprofile/ 274drivers-$(CONFIG_OPROFILE) += arch/arm/oprofile/
diff --git a/arch/arm/configs/tegra_defconfig b/arch/arm/configs/tegra_defconfig
index 4934295bb4f0..da753e31c850 100644
--- a/arch/arm/configs/tegra_defconfig
+++ b/arch/arm/configs/tegra_defconfig
@@ -33,6 +33,7 @@ CONFIG_PCI=y
33CONFIG_PCI_MSI=y 33CONFIG_PCI_MSI=y
34CONFIG_PCI_TEGRA=y 34CONFIG_PCI_TEGRA=y
35CONFIG_PCIEPORTBUS=y 35CONFIG_PCIEPORTBUS=y
36CONFIG_TRUSTED_FOUNDATIONS=y
36CONFIG_SMP=y 37CONFIG_SMP=y
37CONFIG_PREEMPT=y 38CONFIG_PREEMPT=y
38CONFIG_AEABI=y 39CONFIG_AEABI=y
diff --git a/arch/arm/firmware/Kconfig b/arch/arm/firmware/Kconfig
new file mode 100644
index 000000000000..bb00ccf00d66
--- /dev/null
+++ b/arch/arm/firmware/Kconfig
@@ -0,0 +1,28 @@
1config ARCH_SUPPORTS_FIRMWARE
2 bool
3
4config ARCH_SUPPORTS_TRUSTED_FOUNDATIONS
5 bool
6 select ARCH_SUPPORTS_FIRMWARE
7
8menu "Firmware options"
9 depends on ARCH_SUPPORTS_FIRMWARE
10
11config TRUSTED_FOUNDATIONS
12 bool "Trusted Foundations secure monitor support"
13 depends on ARCH_SUPPORTS_TRUSTED_FOUNDATIONS
14 help
15 Some devices (including most Tegra-based consumer devices on the
16 market) are booted with the Trusted Foundations secure monitor
17 active, requiring some core operations to be performed by the secure
18 monitor instead of the kernel.
19
20 This option allows the kernel to invoke the secure monitor whenever
21 required on devices using Trusted Foundations. See
22 arch/arm/include/asm/trusted_foundations.h or the
23 tl,trusted-foundations device tree binding documentation for details
24 on how to use it.
25
26 Say n if you don't know what this is about.
27
28endmenu
diff --git a/arch/arm/firmware/Makefile b/arch/arm/firmware/Makefile
new file mode 100644
index 000000000000..a71f16536b6c
--- /dev/null
+++ b/arch/arm/firmware/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o
diff --git a/arch/arm/firmware/trusted_foundations.c b/arch/arm/firmware/trusted_foundations.c
new file mode 100644
index 000000000000..ef1e3d8f4af0
--- /dev/null
+++ b/arch/arm/firmware/trusted_foundations.c
@@ -0,0 +1,81 @@
1/*
2 * Trusted Foundations support for ARM CPUs
3 *
4 * Copyright (c) 2013, NVIDIA Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/of.h>
20#include <asm/firmware.h>
21#include <asm/trusted_foundations.h>
22
23#define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200
24
25static void __naked tf_generic_smc(u32 type, u32 arg1, u32 arg2)
26{
27 asm volatile(
28 ".arch_extension sec\n\t"
29 "stmfd sp!, {r4 - r11, lr}\n\t"
30 __asmeq("%0", "r0")
31 __asmeq("%1", "r1")
32 __asmeq("%2", "r2")
33 "mov r3, #0\n\t"
34 "mov r4, #0\n\t"
35 "smc #0\n\t"
36 "ldmfd sp!, {r4 - r11, pc}"
37 :
38 : "r" (type), "r" (arg1), "r" (arg2)
39 : "memory");
40}
41
42static int tf_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
43{
44 tf_generic_smc(TF_SET_CPU_BOOT_ADDR_SMC, boot_addr, 0);
45
46 return 0;
47}
48
49static const struct firmware_ops trusted_foundations_ops = {
50 .set_cpu_boot_addr = tf_set_cpu_boot_addr,
51};
52
53void register_trusted_foundations(struct trusted_foundations_platform_data *pd)
54{
55 /*
56 * we are not using version information for now since currently
57 * supported SMCs are compatible with all TF releases
58 */
59 register_firmware_ops(&trusted_foundations_ops);
60}
61
62void of_register_trusted_foundations(void)
63{
64 struct device_node *node;
65 struct trusted_foundations_platform_data pdata;
66 int err;
67
68 node = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
69 if (!node)
70 return;
71
72 err = of_property_read_u32(node, "tlm,version-major",
73 &pdata.version_major);
74 if (err != 0)
75 panic("Trusted Foundation: missing version-major property\n");
76 err = of_property_read_u32(node, "tlm,version-minor",
77 &pdata.version_minor);
78 if (err != 0)
79 panic("Trusted Foundation: missing version-minor property\n");
80 register_trusted_foundations(&pdata);
81}
diff --git a/arch/arm/include/asm/trusted_foundations.h b/arch/arm/include/asm/trusted_foundations.h
new file mode 100644
index 000000000000..3bd36e2c5f2e
--- /dev/null
+++ b/arch/arm/include/asm/trusted_foundations.h
@@ -0,0 +1,67 @@
1/*
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
26#ifndef __ASM_ARM_TRUSTED_FOUNDATIONS_H
27#define __ASM_ARM_TRUSTED_FOUNDATIONS_H
28
29#include <linux/kconfig.h>
30#include <linux/printk.h>
31#include <linux/bug.h>
32#include <linux/of.h>
33
34struct trusted_foundations_platform_data {
35 unsigned int version_major;
36 unsigned int version_minor;
37};
38
39#if IS_ENABLED(CONFIG_TRUSTED_FOUNDATIONS)
40
41void register_trusted_foundations(struct trusted_foundations_platform_data *pd);
42void of_register_trusted_foundations(void);
43
44#else /* CONFIG_TRUSTED_FOUNDATIONS */
45
46static inline void register_trusted_foundations(
47 struct trusted_foundations_platform_data *pd)
48{
49 /*
50 * If we try to register TF, this means the system needs it to continue.
51 * Its absence if thus a fatal error.
52 */
53 panic("No support for Trusted Foundations, stopping...\n");
54}
55
56static inline void of_register_trusted_foundations(void)
57{
58 /*
59 * If we find the target should enable TF but does not support it,
60 * fail as the system won't be able to do much anyway
61 */
62 if (of_find_compatible_node(NULL, NULL, "tl,trusted-foundations"))
63 register_trusted_foundations(NULL);
64}
65#endif /* CONFIG_TRUSTED_FOUNDATIONS */
66
67#endif
diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig
index 09e740f58b27..00b85fd9285d 100644
--- a/arch/arm/mach-tegra/Kconfig
+++ b/arch/arm/mach-tegra/Kconfig
@@ -2,6 +2,7 @@ config ARCH_TEGRA
2 bool "NVIDIA Tegra" if ARCH_MULTI_V7 2 bool "NVIDIA Tegra" if ARCH_MULTI_V7
3 select ARCH_HAS_CPUFREQ 3 select ARCH_HAS_CPUFREQ
4 select ARCH_REQUIRE_GPIOLIB 4 select ARCH_REQUIRE_GPIOLIB
5 select ARCH_SUPPORTS_TRUSTED_FOUNDATIONS
5 select ARM_GIC 6 select ARM_GIC
6 select CLKSRC_MMIO 7 select CLKSRC_MMIO
7 select CLKSRC_OF 8 select CLKSRC_OF
diff --git a/arch/arm/mach-tegra/reset.c b/arch/arm/mach-tegra/reset.c
index 568f5bbf979d..146fe8e0ae7c 100644
--- a/arch/arm/mach-tegra/reset.c
+++ b/arch/arm/mach-tegra/reset.c
@@ -21,6 +21,7 @@
21 21
22#include <asm/cacheflush.h> 22#include <asm/cacheflush.h>
23#include <asm/hardware/cache-l2x0.h> 23#include <asm/hardware/cache-l2x0.h>
24#include <asm/firmware.h>
24 25
25#include "iomap.h" 26#include "iomap.h"
26#include "irammap.h" 27#include "irammap.h"
@@ -33,26 +34,18 @@
33 34
34static bool is_enabled; 35static bool is_enabled;
35 36
36static void __init tegra_cpu_reset_handler_enable(void) 37static void __init tegra_cpu_reset_handler_set(const u32 reset_address)
37{ 38{
38 void __iomem *iram_base = IO_ADDRESS(TEGRA_IRAM_RESET_BASE);
39 void __iomem *evp_cpu_reset = 39 void __iomem *evp_cpu_reset =
40 IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE + 0x100); 40 IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE + 0x100);
41 void __iomem *sb_ctrl = IO_ADDRESS(TEGRA_SB_BASE); 41 void __iomem *sb_ctrl = IO_ADDRESS(TEGRA_SB_BASE);
42 u32 reg; 42 u32 reg;
43 43
44 BUG_ON(is_enabled);
45 BUG_ON(tegra_cpu_reset_handler_size > TEGRA_IRAM_RESET_HANDLER_SIZE);
46
47 memcpy(iram_base, (void *)__tegra_cpu_reset_handler_start,
48 tegra_cpu_reset_handler_size);
49
50 /* 44 /*
51 * NOTE: This must be the one and only write to the EVP CPU reset 45 * NOTE: This must be the one and only write to the EVP CPU reset
52 * vector in the entire system. 46 * vector in the entire system.
53 */ 47 */
54 writel(TEGRA_IRAM_RESET_BASE + tegra_cpu_reset_handler_offset, 48 writel(reset_address, evp_cpu_reset);
55 evp_cpu_reset);
56 wmb(); 49 wmb();
57 reg = readl(evp_cpu_reset); 50 reg = readl(evp_cpu_reset);
58 51
@@ -66,8 +59,33 @@ static void __init tegra_cpu_reset_handler_enable(void)
66 writel(reg, sb_ctrl); 59 writel(reg, sb_ctrl);
67 wmb(); 60 wmb();
68 } 61 }
62}
63
64static void __init tegra_cpu_reset_handler_enable(void)
65{
66 void __iomem *iram_base = IO_ADDRESS(TEGRA_IRAM_RESET_BASE);
67 const u32 reset_address = TEGRA_IRAM_RESET_BASE +
68 tegra_cpu_reset_handler_offset;
69 int err;
70
71 BUG_ON(is_enabled);
72 BUG_ON(tegra_cpu_reset_handler_size > TEGRA_IRAM_RESET_HANDLER_SIZE);
69 73
70 is_enabled = true; 74 memcpy(iram_base, (void *)__tegra_cpu_reset_handler_start,
75 tegra_cpu_reset_handler_size);
76
77 err = call_firmware_op(set_cpu_boot_addr, 0, reset_address);
78 switch (err) {
79 case -ENOSYS:
80 tegra_cpu_reset_handler_set(reset_address);
81 /* pass-through */
82 case 0:
83 is_enabled = true;
84 break;
85 default:
86 pr_crit("Cannot set CPU reset handler: %d\n", err);
87 BUG();
88 }
71} 89}
72 90
73void __init tegra_cpu_reset_handler_init(void) 91void __init tegra_cpu_reset_handler_init(void)
diff --git a/arch/arm/mach-tegra/tegra.c b/arch/arm/mach-tegra/tegra.c
index 73368176c6e8..09a1f8d98ca2 100644
--- a/arch/arm/mach-tegra/tegra.c
+++ b/arch/arm/mach-tegra/tegra.c
@@ -40,6 +40,7 @@
40#include <asm/mach/arch.h> 40#include <asm/mach/arch.h>
41#include <asm/mach/time.h> 41#include <asm/mach/time.h>
42#include <asm/setup.h> 42#include <asm/setup.h>
43#include <asm/trusted_foundations.h>
43 44
44#include "apbio.h" 45#include "apbio.h"
45#include "board.h" 46#include "board.h"
@@ -90,6 +91,7 @@ static void __init tegra_init_cache(void)
90 91
91static void __init tegra_init_early(void) 92static void __init tegra_init_early(void)
92{ 93{
94 of_register_trusted_foundations();
93 tegra_apb_io_init(); 95 tegra_apb_io_init();
94 tegra_init_fuse(); 96 tegra_init_fuse();
95 tegra_cpu_reset_handler_init(); 97 tegra_cpu_reset_handler_init();