blob: 689e6565abfc4bea48e9425901387d6a096ed9d5 [file] [log] [blame]
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +09001/*
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
Alexandre Courbotb77b6e82014-02-07 13:35:05 +090025#define TF_CPU_PM 0xfffffffc
26#define TF_CPU_PM_S3 0xffffffe3
27#define TF_CPU_PM_S2 0xffffffe6
28#define TF_CPU_PM_S2_NO_MC_CLK 0xffffffe5
29#define TF_CPU_PM_S1 0xffffffe4
30#define TF_CPU_PM_S1_NOFLUSH_L2 0xffffffe7
31
32static unsigned long cpu_boot_addr;
33
Stefan Agner1e5b5cb2018-03-25 20:09:56 +020034static void tf_generic_smc(u32 type, u32 arg1, u32 arg2)
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090035{
Stefan Agner1e5b5cb2018-03-25 20:09:56 +020036 register u32 r0 asm("r0") = type;
37 register u32 r1 asm("r1") = arg1;
38 register u32 r2 asm("r2") = arg2;
39
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090040 asm volatile(
41 ".arch_extension sec\n\t"
Stefan Agner1e5b5cb2018-03-25 20:09:56 +020042 "stmfd sp!, {r4 - r11}\n\t"
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090043 __asmeq("%0", "r0")
44 __asmeq("%1", "r1")
45 __asmeq("%2", "r2")
46 "mov r3, #0\n\t"
47 "mov r4, #0\n\t"
48 "smc #0\n\t"
Stefan Agner1e5b5cb2018-03-25 20:09:56 +020049 "ldmfd sp!, {r4 - r11}\n\t"
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090050 :
Stefan Agner1e5b5cb2018-03-25 20:09:56 +020051 : "r" (r0), "r" (r1), "r" (r2)
52 : "memory", "r3", "r12", "lr");
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090053}
54
55static int tf_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
56{
Alexandre Courbotb77b6e82014-02-07 13:35:05 +090057 cpu_boot_addr = boot_addr;
58 tf_generic_smc(TF_SET_CPU_BOOT_ADDR_SMC, cpu_boot_addr, 0);
59
60 return 0;
61}
62
63static int tf_prepare_idle(void)
64{
65 tf_generic_smc(TF_CPU_PM, TF_CPU_PM_S1_NOFLUSH_L2, cpu_boot_addr);
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090066
67 return 0;
68}
69
70static const struct firmware_ops trusted_foundations_ops = {
71 .set_cpu_boot_addr = tf_set_cpu_boot_addr,
Alexandre Courbotb77b6e82014-02-07 13:35:05 +090072 .prepare_idle = tf_prepare_idle,
Alexandre Courbotd9a1bea2013-11-24 15:30:46 +090073};
74
75void register_trusted_foundations(struct trusted_foundations_platform_data *pd)
76{
77 /*
78 * we are not using version information for now since currently
79 * supported SMCs are compatible with all TF releases
80 */
81 register_firmware_ops(&trusted_foundations_ops);
82}
83
84void of_register_trusted_foundations(void)
85{
86 struct device_node *node;
87 struct trusted_foundations_platform_data pdata;
88 int err;
89
90 node = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
91 if (!node)
92 return;
93
94 err = of_property_read_u32(node, "tlm,version-major",
95 &pdata.version_major);
96 if (err != 0)
97 panic("Trusted Foundation: missing version-major property\n");
98 err = of_property_read_u32(node, "tlm,version-minor",
99 &pdata.version_minor);
100 if (err != 0)
101 panic("Trusted Foundation: missing version-minor property\n");
102 register_trusted_foundations(&pdata);
103}