aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/Kconfig2
-rw-r--r--arch/arm/mach-qcom/Kconfig3
-rw-r--r--arch/arm/mach-qcom/Makefile3
-rw-r--r--arch/arm/mach-qcom/platsmp.c23
-rw-r--r--arch/arm/mach-qcom/scm-boot.c39
-rw-r--r--arch/arm/mach-qcom/scm-boot.h26
-rw-r--r--arch/arm/mach-qcom/scm.c326
-rw-r--r--arch/arm/mach-qcom/scm.h25
8 files changed, 6 insertions, 441 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index f6c5b05e8de8..4d66f33cb200 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -2160,6 +2160,8 @@ source "net/Kconfig"
2160 2160
2161source "drivers/Kconfig" 2161source "drivers/Kconfig"
2162 2162
2163source "drivers/firmware/Kconfig"
2164
2163source "fs/Kconfig" 2165source "fs/Kconfig"
2164 2166
2165source "arch/arm/Kconfig.debug" 2167source "arch/arm/Kconfig.debug"
diff --git a/arch/arm/mach-qcom/Kconfig b/arch/arm/mach-qcom/Kconfig
index 48003ea652b9..2256cd1e25d1 100644
--- a/arch/arm/mach-qcom/Kconfig
+++ b/arch/arm/mach-qcom/Kconfig
@@ -22,7 +22,4 @@ config ARCH_MSM8974
22 bool "Enable support for MSM8974" 22 bool "Enable support for MSM8974"
23 select HAVE_ARM_ARCH_TIMER 23 select HAVE_ARM_ARCH_TIMER
24 24
25config QCOM_SCM
26 bool
27
28endif 25endif
diff --git a/arch/arm/mach-qcom/Makefile b/arch/arm/mach-qcom/Makefile
index 8f756ae1ae31..e324375fa919 100644
--- a/arch/arm/mach-qcom/Makefile
+++ b/arch/arm/mach-qcom/Makefile
@@ -1,5 +1,2 @@
1obj-y := board.o 1obj-y := board.o
2obj-$(CONFIG_SMP) += platsmp.o 2obj-$(CONFIG_SMP) += platsmp.o
3obj-$(CONFIG_QCOM_SCM) += scm.o scm-boot.o
4
5CFLAGS_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
diff --git a/arch/arm/mach-qcom/platsmp.c b/arch/arm/mach-qcom/platsmp.c
index 09cffed4c0a4..5cde63a64b34 100644
--- a/arch/arm/mach-qcom/platsmp.c
+++ b/arch/arm/mach-qcom/platsmp.c
@@ -17,10 +17,10 @@
17#include <linux/of_address.h> 17#include <linux/of_address.h>
18#include <linux/smp.h> 18#include <linux/smp.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/qcom_scm.h>
20 21
21#include <asm/smp_plat.h> 22#include <asm/smp_plat.h>
22 23
23#include "scm-boot.h"
24 24
25#define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x35a0 25#define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x35a0
26#define SCSS_CPU1CORE_RESET 0x2d80 26#define SCSS_CPU1CORE_RESET 0x2d80
@@ -319,25 +319,10 @@ static int kpssv2_boot_secondary(unsigned int cpu, struct task_struct *idle)
319 319
320static void __init qcom_smp_prepare_cpus(unsigned int max_cpus) 320static void __init qcom_smp_prepare_cpus(unsigned int max_cpus)
321{ 321{
322 int cpu, map; 322 int cpu;
323 unsigned int flags = 0;
324 static const int cold_boot_flags[] = {
325 0,
326 SCM_FLAG_COLDBOOT_CPU1,
327 SCM_FLAG_COLDBOOT_CPU2,
328 SCM_FLAG_COLDBOOT_CPU3,
329 };
330
331 for_each_present_cpu(cpu) {
332 map = cpu_logical_map(cpu);
333 if (WARN_ON(map >= ARRAY_SIZE(cold_boot_flags))) {
334 set_cpu_present(cpu, false);
335 continue;
336 }
337 flags |= cold_boot_flags[map];
338 }
339 323
340 if (scm_set_boot_addr(virt_to_phys(secondary_startup_arm), flags)) { 324 if (qcom_scm_set_cold_boot_addr(secondary_startup_arm,
325 cpu_present_mask)) {
341 for_each_present_cpu(cpu) { 326 for_each_present_cpu(cpu) {
342 if (cpu == smp_processor_id()) 327 if (cpu == smp_processor_id())
343 continue; 328 continue;
diff --git a/arch/arm/mach-qcom/scm-boot.c b/arch/arm/mach-qcom/scm-boot.c
deleted file mode 100644
index e8ff7beb6218..000000000000
--- a/arch/arm/mach-qcom/scm-boot.c
+++ /dev/null
@@ -1,39 +0,0 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/slab.h>
20
21#include "scm.h"
22#include "scm-boot.h"
23
24/*
25 * Set the cold/warm boot address for one of the CPU cores.
26 */
27int scm_set_boot_addr(u32 addr, int flags)
28{
29 struct {
30 __le32 flags;
31 __le32 addr;
32 } cmd;
33
34 cmd.addr = cpu_to_le32(addr);
35 cmd.flags = cpu_to_le32(flags);
36 return scm_call(SCM_SVC_BOOT, SCM_BOOT_ADDR,
37 &cmd, sizeof(cmd), NULL, 0);
38}
39EXPORT_SYMBOL(scm_set_boot_addr);
diff --git a/arch/arm/mach-qcom/scm-boot.h b/arch/arm/mach-qcom/scm-boot.h
deleted file mode 100644
index 3e210fb818bb..000000000000
--- a/arch/arm/mach-qcom/scm-boot.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#ifndef __MACH_SCM_BOOT_H
13#define __MACH_SCM_BOOT_H
14
15#define SCM_BOOT_ADDR 0x1
16#define SCM_FLAG_COLDBOOT_CPU1 0x01
17#define SCM_FLAG_COLDBOOT_CPU2 0x08
18#define SCM_FLAG_COLDBOOT_CPU3 0x20
19#define SCM_FLAG_WARMBOOT_CPU0 0x04
20#define SCM_FLAG_WARMBOOT_CPU1 0x02
21#define SCM_FLAG_WARMBOOT_CPU2 0x10
22#define SCM_FLAG_WARMBOOT_CPU3 0x40
23
24int scm_set_boot_addr(u32 addr, int flags);
25
26#endif
diff --git a/arch/arm/mach-qcom/scm.c b/arch/arm/mach-qcom/scm.c
deleted file mode 100644
index 1d9cf18c7091..000000000000
--- a/arch/arm/mach-qcom/scm.c
+++ /dev/null
@@ -1,326 +0,0 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#include <linux/slab.h>
19#include <linux/io.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/errno.h>
23#include <linux/err.h>
24
25#include <asm/outercache.h>
26#include <asm/cacheflush.h>
27
28#include "scm.h"
29
30#define SCM_ENOMEM -5
31#define SCM_EOPNOTSUPP -4
32#define SCM_EINVAL_ADDR -3
33#define SCM_EINVAL_ARG -2
34#define SCM_ERROR -1
35#define SCM_INTERRUPTED 1
36
37static DEFINE_MUTEX(scm_lock);
38
39/**
40 * struct scm_command - one SCM command buffer
41 * @len: total available memory for command and response
42 * @buf_offset: start of command buffer
43 * @resp_hdr_offset: start of response buffer
44 * @id: command to be executed
45 * @buf: buffer returned from scm_get_command_buffer()
46 *
47 * An SCM command is laid out in memory as follows:
48 *
49 * ------------------- <--- struct scm_command
50 * | command header |
51 * ------------------- <--- scm_get_command_buffer()
52 * | command buffer |
53 * ------------------- <--- struct scm_response and
54 * | response header | scm_command_to_response()
55 * ------------------- <--- scm_get_response_buffer()
56 * | response buffer |
57 * -------------------
58 *
59 * There can be arbitrary padding between the headers and buffers so
60 * you should always use the appropriate scm_get_*_buffer() routines
61 * to access the buffers in a safe manner.
62 */
63struct scm_command {
64 __le32 len;
65 __le32 buf_offset;
66 __le32 resp_hdr_offset;
67 __le32 id;
68 __le32 buf[0];
69};
70
71/**
72 * struct scm_response - one SCM response buffer
73 * @len: total available memory for response
74 * @buf_offset: start of response data relative to start of scm_response
75 * @is_complete: indicates if the command has finished processing
76 */
77struct scm_response {
78 __le32 len;
79 __le32 buf_offset;
80 __le32 is_complete;
81};
82
83/**
84 * alloc_scm_command() - Allocate an SCM command
85 * @cmd_size: size of the command buffer
86 * @resp_size: size of the response buffer
87 *
88 * Allocate an SCM command, including enough room for the command
89 * and response headers as well as the command and response buffers.
90 *
91 * Returns a valid &scm_command on success or %NULL if the allocation fails.
92 */
93static struct scm_command *alloc_scm_command(size_t cmd_size, size_t resp_size)
94{
95 struct scm_command *cmd;
96 size_t len = sizeof(*cmd) + sizeof(struct scm_response) + cmd_size +
97 resp_size;
98 u32 offset;
99
100 cmd = kzalloc(PAGE_ALIGN(len), GFP_KERNEL);
101 if (cmd) {
102 cmd->len = cpu_to_le32(len);
103 offset = offsetof(struct scm_command, buf);
104 cmd->buf_offset = cpu_to_le32(offset);
105 cmd->resp_hdr_offset = cpu_to_le32(offset + cmd_size);
106 }
107 return cmd;
108}
109
110/**
111 * free_scm_command() - Free an SCM command
112 * @cmd: command to free
113 *
114 * Free an SCM command.
115 */
116static inline void free_scm_command(struct scm_command *cmd)
117{
118 kfree(cmd);
119}
120
121/**
122 * scm_command_to_response() - Get a pointer to a scm_response
123 * @cmd: command
124 *
125 * Returns a pointer to a response for a command.
126 */
127static inline struct scm_response *scm_command_to_response(
128 const struct scm_command *cmd)
129{
130 return (void *)cmd + le32_to_cpu(cmd->resp_hdr_offset);
131}
132
133/**
134 * scm_get_command_buffer() - Get a pointer to a command buffer
135 * @cmd: command
136 *
137 * Returns a pointer to the command buffer of a command.
138 */
139static inline void *scm_get_command_buffer(const struct scm_command *cmd)
140{
141 return (void *)cmd->buf;
142}
143
144/**
145 * scm_get_response_buffer() - Get a pointer to a response buffer
146 * @rsp: response
147 *
148 * Returns a pointer to a response buffer of a response.
149 */
150static inline void *scm_get_response_buffer(const struct scm_response *rsp)
151{
152 return (void *)rsp + le32_to_cpu(rsp->buf_offset);
153}
154
155static int scm_remap_error(int err)
156{
157 pr_err("scm_call failed with error code %d\n", err);
158 switch (err) {
159 case SCM_ERROR:
160 return -EIO;
161 case SCM_EINVAL_ADDR:
162 case SCM_EINVAL_ARG:
163 return -EINVAL;
164 case SCM_EOPNOTSUPP:
165 return -EOPNOTSUPP;
166 case SCM_ENOMEM:
167 return -ENOMEM;
168 }
169 return -EINVAL;
170}
171
172static u32 smc(u32 cmd_addr)
173{
174 int context_id;
175 register u32 r0 asm("r0") = 1;
176 register u32 r1 asm("r1") = (u32)&context_id;
177 register u32 r2 asm("r2") = cmd_addr;
178 do {
179 asm volatile(
180 __asmeq("%0", "r0")
181 __asmeq("%1", "r0")
182 __asmeq("%2", "r1")
183 __asmeq("%3", "r2")
184#ifdef REQUIRES_SEC
185 ".arch_extension sec\n"
186#endif
187 "smc #0 @ switch to secure world\n"
188 : "=r" (r0)
189 : "r" (r0), "r" (r1), "r" (r2)
190 : "r3");
191 } while (r0 == SCM_INTERRUPTED);
192
193 return r0;
194}
195
196static int __scm_call(const struct scm_command *cmd)
197{
198 int ret;
199 u32 cmd_addr = virt_to_phys(cmd);
200
201 /*
202 * Flush the command buffer so that the secure world sees
203 * the correct data.
204 */
205 __cpuc_flush_dcache_area((void *)cmd, cmd->len);
206 outer_flush_range(cmd_addr, cmd_addr + cmd->len);
207
208 ret = smc(cmd_addr);
209 if (ret < 0)
210 ret = scm_remap_error(ret);
211
212 return ret;
213}
214
215static void scm_inv_range(unsigned long start, unsigned long end)
216{
217 u32 cacheline_size, ctr;
218
219 asm volatile("mrc p15, 0, %0, c0, c0, 1" : "=r" (ctr));
220 cacheline_size = 4 << ((ctr >> 16) & 0xf);
221
222 start = round_down(start, cacheline_size);
223 end = round_up(end, cacheline_size);
224 outer_inv_range(start, end);
225 while (start < end) {
226 asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)
227 : "memory");
228 start += cacheline_size;
229 }
230 dsb();
231 isb();
232}
233
234/**
235 * scm_call() - Send an SCM command
236 * @svc_id: service identifier
237 * @cmd_id: command identifier
238 * @cmd_buf: command buffer
239 * @cmd_len: length of the command buffer
240 * @resp_buf: response buffer
241 * @resp_len: length of the response buffer
242 *
243 * Sends a command to the SCM and waits for the command to finish processing.
244 *
245 * A note on cache maintenance:
246 * Note that any buffers that are expected to be accessed by the secure world
247 * must be flushed before invoking scm_call and invalidated in the cache
248 * immediately after scm_call returns. Cache maintenance on the command and
249 * response buffers is taken care of by scm_call; however, callers are
250 * responsible for any other cached buffers passed over to the secure world.
251 */
252int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len,
253 void *resp_buf, size_t resp_len)
254{
255 int ret;
256 struct scm_command *cmd;
257 struct scm_response *rsp;
258 unsigned long start, end;
259
260 cmd = alloc_scm_command(cmd_len, resp_len);
261 if (!cmd)
262 return -ENOMEM;
263
264 cmd->id = cpu_to_le32((svc_id << 10) | cmd_id);
265 if (cmd_buf)
266 memcpy(scm_get_command_buffer(cmd), cmd_buf, cmd_len);
267
268 mutex_lock(&scm_lock);
269 ret = __scm_call(cmd);
270 mutex_unlock(&scm_lock);
271 if (ret)
272 goto out;
273
274 rsp = scm_command_to_response(cmd);
275 start = (unsigned long)rsp;
276
277 do {
278 scm_inv_range(start, start + sizeof(*rsp));
279 } while (!rsp->is_complete);
280
281 end = (unsigned long)scm_get_response_buffer(rsp) + resp_len;
282 scm_inv_range(start, end);
283
284 if (resp_buf)
285 memcpy(resp_buf, scm_get_response_buffer(rsp), resp_len);
286out:
287 free_scm_command(cmd);
288 return ret;
289}
290EXPORT_SYMBOL(scm_call);
291
292u32 scm_get_version(void)
293{
294 int context_id;
295 static u32 version = -1;
296 register u32 r0 asm("r0");
297 register u32 r1 asm("r1");
298
299 if (version != -1)
300 return version;
301
302 mutex_lock(&scm_lock);
303
304 r0 = 0x1 << 8;
305 r1 = (u32)&context_id;
306 do {
307 asm volatile(
308 __asmeq("%0", "r0")
309 __asmeq("%1", "r1")
310 __asmeq("%2", "r0")
311 __asmeq("%3", "r1")
312#ifdef REQUIRES_SEC
313 ".arch_extension sec\n"
314#endif
315 "smc #0 @ switch to secure world\n"
316 : "=r" (r0), "=r" (r1)
317 : "r" (r0), "r" (r1)
318 : "r2", "r3");
319 } while (r0 == SCM_INTERRUPTED);
320
321 version = r1;
322 mutex_unlock(&scm_lock);
323
324 return version;
325}
326EXPORT_SYMBOL(scm_get_version);
diff --git a/arch/arm/mach-qcom/scm.h b/arch/arm/mach-qcom/scm.h
deleted file mode 100644
index 00b31ea58f29..000000000000
--- a/arch/arm/mach-qcom/scm.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#ifndef __MACH_SCM_H
13#define __MACH_SCM_H
14
15#define SCM_SVC_BOOT 0x1
16#define SCM_SVC_PIL 0x2
17
18extern int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len,
19 void *resp_buf, size_t resp_len);
20
21#define SCM_VERSION(major, minor) (((major) << 16) | ((minor) & 0xFF))
22
23extern u32 scm_get_version(void);
24
25#endif