Merge branch 'next' into for-linus
[linux.git] / arch / arm / firmware / trusted_foundations.c
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
25 static 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
42 static 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
49 static const struct firmware_ops trusted_foundations_ops = {
50         .set_cpu_boot_addr = tf_set_cpu_boot_addr,
51 };
52
53 void 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
62 void 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 }