blob: acd956f1c722b173b4a73245735d552913ca558a [file] [log] [blame]
Thomas Gleixner08dbd0f2019-05-29 07:12:41 -07001// SPDX-License-Identifier: GPL-2.0-only
Elliot Bermane0aa1532020-01-07 13:04:10 -08002/* Copyright (c) 2010,2015,2019 The Linux Foundation. All rights reserved.
Kumar Galab6a1dfb2015-03-11 16:28:10 -05003 * Copyright (C) 2015 Linaro Ltd.
Kumar Galab6a1dfb2015-03-11 16:28:10 -05004 */
5
6#include <linux/slab.h>
7#include <linux/io.h>
8#include <linux/module.h>
9#include <linux/mutex.h>
10#include <linux/errno.h>
11#include <linux/err.h>
12#include <linux/qcom_scm.h>
Elliot Berman02248982020-01-07 13:04:18 -080013#include <linux/arm-smccc.h>
Andy Gross16e59462016-06-03 18:25:25 -050014#include <linux/dma-mapping.h>
Kumar Galab6a1dfb2015-03-11 16:28:10 -050015
16#include "qcom_scm.h"
17
18#define QCOM_SCM_FLAG_COLDBOOT_CPU0 0x00
19#define QCOM_SCM_FLAG_COLDBOOT_CPU1 0x01
20#define QCOM_SCM_FLAG_COLDBOOT_CPU2 0x08
21#define QCOM_SCM_FLAG_COLDBOOT_CPU3 0x20
22
23#define QCOM_SCM_FLAG_WARMBOOT_CPU0 0x04
24#define QCOM_SCM_FLAG_WARMBOOT_CPU1 0x02
25#define QCOM_SCM_FLAG_WARMBOOT_CPU2 0x10
26#define QCOM_SCM_FLAG_WARMBOOT_CPU3 0x40
27
28struct qcom_scm_entry {
29 int flag;
30 void *entry;
31};
32
33static struct qcom_scm_entry qcom_scm_wb[] = {
34 { .flag = QCOM_SCM_FLAG_WARMBOOT_CPU0 },
35 { .flag = QCOM_SCM_FLAG_WARMBOOT_CPU1 },
36 { .flag = QCOM_SCM_FLAG_WARMBOOT_CPU2 },
37 { .flag = QCOM_SCM_FLAG_WARMBOOT_CPU3 },
38};
39
40static DEFINE_MUTEX(qcom_scm_lock);
41
Elliot Bermanefd2b152020-01-07 13:04:20 -080042#define MAX_QCOM_SCM_ARGS 10
43#define MAX_QCOM_SCM_RETS 3
44
45enum qcom_scm_arg_types {
46 QCOM_SCM_VAL,
47 QCOM_SCM_RO,
48 QCOM_SCM_RW,
49 QCOM_SCM_BUFVAL,
50};
51
52#define QCOM_SCM_ARGS_IMPL(num, a, b, c, d, e, f, g, h, i, j, ...) (\
53 (((a) & 0x3) << 4) | \
54 (((b) & 0x3) << 6) | \
55 (((c) & 0x3) << 8) | \
56 (((d) & 0x3) << 10) | \
57 (((e) & 0x3) << 12) | \
58 (((f) & 0x3) << 14) | \
59 (((g) & 0x3) << 16) | \
60 (((h) & 0x3) << 18) | \
61 (((i) & 0x3) << 20) | \
62 (((j) & 0x3) << 22) | \
63 ((num) & 0xf))
64
65#define QCOM_SCM_ARGS(...) QCOM_SCM_ARGS_IMPL(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
66
67/**
68 * struct qcom_scm_desc
69 * @arginfo: Metadata describing the arguments in args[]
70 * @args: The array of arguments for the secure syscall
71 */
72struct qcom_scm_desc {
73 u32 svc;
74 u32 cmd;
75 u32 arginfo;
76 u64 args[MAX_QCOM_SCM_ARGS];
77 u32 owner;
78};
79
80/**
81 * struct qcom_scm_res
82 * @result: The values returned by the secure syscall
83 */
84struct qcom_scm_res {
85 u64 result[MAX_QCOM_SCM_RETS];
86};
87
Elliot Berman590e9282020-01-07 13:04:21 -080088/**
89 * struct arm_smccc_args
90 * @args: The array of values used in registers in smc instruction
91 */
92struct arm_smccc_args {
93 unsigned long args[8];
94};
95
Elliot Bermanfd62c302020-01-07 13:04:19 -080096#define SCM_LEGACY_FNID(s, c) (((s) << 10) | ((c) & 0x3ff))
97
Kumar Galab6a1dfb2015-03-11 16:28:10 -050098/**
Elliot Bermane0aa1532020-01-07 13:04:10 -080099 * struct scm_legacy_command - one SCM command buffer
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500100 * @len: total available memory for command and response
101 * @buf_offset: start of command buffer
102 * @resp_hdr_offset: start of response buffer
103 * @id: command to be executed
Elliot Bermane0aa1532020-01-07 13:04:10 -0800104 * @buf: buffer returned from scm_legacy_get_command_buffer()
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500105 *
106 * An SCM command is laid out in memory as follows:
107 *
Elliot Bermane0aa1532020-01-07 13:04:10 -0800108 * ------------------- <--- struct scm_legacy_command
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500109 * | command header |
Elliot Bermane0aa1532020-01-07 13:04:10 -0800110 * ------------------- <--- scm_legacy_get_command_buffer()
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500111 * | command buffer |
Elliot Bermane0aa1532020-01-07 13:04:10 -0800112 * ------------------- <--- struct scm_legacy_response and
113 * | response header | scm_legacy_command_to_response()
114 * ------------------- <--- scm_legacy_get_response_buffer()
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500115 * | response buffer |
116 * -------------------
117 *
118 * There can be arbitrary padding between the headers and buffers so
Elliot Bermane0aa1532020-01-07 13:04:10 -0800119 * you should always use the appropriate scm_legacy_get_*_buffer() routines
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500120 * to access the buffers in a safe manner.
121 */
Elliot Bermane0aa1532020-01-07 13:04:10 -0800122struct scm_legacy_command {
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500123 __le32 len;
124 __le32 buf_offset;
125 __le32 resp_hdr_offset;
126 __le32 id;
127 __le32 buf[0];
128};
129
130/**
Elliot Bermane0aa1532020-01-07 13:04:10 -0800131 * struct scm_legacy_response - one SCM response buffer
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500132 * @len: total available memory for response
Elliot Bermane0aa1532020-01-07 13:04:10 -0800133 * @buf_offset: start of response data relative to start of scm_legacy_response
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500134 * @is_complete: indicates if the command has finished processing
135 */
Elliot Bermane0aa1532020-01-07 13:04:10 -0800136struct scm_legacy_response {
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500137 __le32 len;
138 __le32 buf_offset;
139 __le32 is_complete;
140};
141
142/**
Elliot Bermane0aa1532020-01-07 13:04:10 -0800143 * scm_legacy_command_to_response() - Get a pointer to a scm_legacy_response
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500144 * @cmd: command
145 *
146 * Returns a pointer to a response for a command.
147 */
Elliot Bermane0aa1532020-01-07 13:04:10 -0800148static inline struct scm_legacy_response *scm_legacy_command_to_response(
149 const struct scm_legacy_command *cmd)
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500150{
151 return (void *)cmd + le32_to_cpu(cmd->resp_hdr_offset);
152}
153
154/**
Elliot Bermane0aa1532020-01-07 13:04:10 -0800155 * scm_legacy_get_command_buffer() - Get a pointer to a command buffer
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500156 * @cmd: command
157 *
158 * Returns a pointer to the command buffer of a command.
159 */
Elliot Bermane0aa1532020-01-07 13:04:10 -0800160static inline void *scm_legacy_get_command_buffer(
161 const struct scm_legacy_command *cmd)
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500162{
163 return (void *)cmd->buf;
164}
165
166/**
Elliot Bermane0aa1532020-01-07 13:04:10 -0800167 * scm_legacy_get_response_buffer() - Get a pointer to a response buffer
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500168 * @rsp: response
169 *
170 * Returns a pointer to a response buffer of a response.
171 */
Elliot Bermane0aa1532020-01-07 13:04:10 -0800172static inline void *scm_legacy_get_response_buffer(
173 const struct scm_legacy_response *rsp)
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500174{
175 return (void *)rsp + le32_to_cpu(rsp->buf_offset);
176}
177
Elliot Berman590e9282020-01-07 13:04:21 -0800178static void __scm_legacy_do(const struct arm_smccc_args *smc,
179 struct arm_smccc_res *res)
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500180{
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500181 do {
Elliot Berman590e9282020-01-07 13:04:21 -0800182 arm_smccc_smc(smc->args[0], smc->args[1], smc->args[2],
183 smc->args[3], smc->args[4], smc->args[5],
184 smc->args[6], smc->args[7], res);
185 } while (res->a0 == QCOM_SCM_INTERRUPTED);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500186}
187
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500188/**
Elliot Bermanefd2b152020-01-07 13:04:20 -0800189 * qcom_scm_call() - Sends a command to the SCM and waits for the command to
190 * finish processing.
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500191 *
192 * A note on cache maintenance:
193 * Note that any buffers that are expected to be accessed by the secure world
194 * must be flushed before invoking qcom_scm_call and invalidated in the cache
195 * immediately after qcom_scm_call returns. Cache maintenance on the command
196 * and response buffers is taken care of by qcom_scm_call; however, callers are
197 * responsible for any other cached buffers passed over to the secure world.
198 */
Elliot Bermanefd2b152020-01-07 13:04:20 -0800199static int qcom_scm_call(struct device *dev, const struct qcom_scm_desc *desc,
200 struct qcom_scm_res *res)
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500201{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800202 u8 arglen = desc->arginfo & 0xf;
Elliot Berman590e9282020-01-07 13:04:21 -0800203 int ret = 0, context_id;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800204 unsigned int i;
Elliot Bermane0aa1532020-01-07 13:04:10 -0800205 struct scm_legacy_command *cmd;
206 struct scm_legacy_response *rsp;
Elliot Berman590e9282020-01-07 13:04:21 -0800207 struct arm_smccc_args smc = {0};
208 struct arm_smccc_res smc_res;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800209 const size_t cmd_len = arglen * sizeof(__le32);
210 const size_t resp_len = MAX_QCOM_SCM_RETS * sizeof(__le32);
Andy Gross16e59462016-06-03 18:25:25 -0500211 size_t alloc_len = sizeof(*cmd) + cmd_len + sizeof(*rsp) + resp_len;
212 dma_addr_t cmd_phys;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800213 __le32 *arg_buf;
214 const __le32 *res_buf;
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500215
Andy Gross16e59462016-06-03 18:25:25 -0500216 cmd = kzalloc(PAGE_ALIGN(alloc_len), GFP_KERNEL);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500217 if (!cmd)
218 return -ENOMEM;
219
Andy Gross16e59462016-06-03 18:25:25 -0500220 cmd->len = cpu_to_le32(alloc_len);
221 cmd->buf_offset = cpu_to_le32(sizeof(*cmd));
222 cmd->resp_hdr_offset = cpu_to_le32(sizeof(*cmd) + cmd_len);
Elliot Bermanefd2b152020-01-07 13:04:20 -0800223 cmd->id = cpu_to_le32(SCM_LEGACY_FNID(desc->svc, desc->cmd));
Andy Gross16e59462016-06-03 18:25:25 -0500224
Elliot Bermanefd2b152020-01-07 13:04:20 -0800225 arg_buf = scm_legacy_get_command_buffer(cmd);
226 for (i = 0; i < arglen; i++)
227 arg_buf[i] = cpu_to_le32(desc->args[i]);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500228
Elliot Bermane0aa1532020-01-07 13:04:10 -0800229 rsp = scm_legacy_command_to_response(cmd);
Andy Gross16e59462016-06-03 18:25:25 -0500230
231 cmd_phys = dma_map_single(dev, cmd, alloc_len, DMA_TO_DEVICE);
232 if (dma_mapping_error(dev, cmd_phys)) {
233 kfree(cmd);
234 return -ENOMEM;
235 }
236
Elliot Berman590e9282020-01-07 13:04:21 -0800237 smc.args[0] = 1;
238 smc.args[1] = (unsigned long)&context_id;
239 smc.args[2] = cmd_phys;
240
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500241 mutex_lock(&qcom_scm_lock);
Elliot Berman590e9282020-01-07 13:04:21 -0800242 __scm_legacy_do(&smc, &smc_res);
243 if (smc_res.a0)
244 ret = qcom_scm_remap_error(smc_res.a0);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500245 mutex_unlock(&qcom_scm_lock);
246 if (ret)
247 goto out;
248
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500249 do {
Andy Gross16e59462016-06-03 18:25:25 -0500250 dma_sync_single_for_cpu(dev, cmd_phys + sizeof(*cmd) + cmd_len,
251 sizeof(*rsp), DMA_FROM_DEVICE);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500252 } while (!rsp->is_complete);
253
Elliot Bermanefd2b152020-01-07 13:04:20 -0800254 dma_sync_single_for_cpu(dev, cmd_phys + sizeof(*cmd) + cmd_len +
255 le32_to_cpu(rsp->buf_offset),
256 resp_len, DMA_FROM_DEVICE);
257
258 if (res) {
259 res_buf = scm_legacy_get_response_buffer(rsp);
260 for (i = 0; i < MAX_QCOM_SCM_RETS; i++)
261 res->result[i] = le32_to_cpu(res_buf[i]);
Andy Gross16e59462016-06-03 18:25:25 -0500262 }
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500263out:
Andy Gross16e59462016-06-03 18:25:25 -0500264 dma_unmap_single(dev, cmd_phys, alloc_len, DMA_TO_DEVICE);
265 kfree(cmd);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500266 return ret;
267}
268
Elliot Bermane0aa1532020-01-07 13:04:10 -0800269#define SCM_LEGACY_CLASS_REGISTER (0x2 << 8)
270#define SCM_LEGACY_MASK_IRQS BIT(5)
271#define SCM_LEGACY_ATOMIC_ID(svc, cmd, n) \
Elliot Bermanfd62c302020-01-07 13:04:19 -0800272 ((SCM_LEGACY_FNID(svc, cmd) << 12) | \
Elliot Bermane0aa1532020-01-07 13:04:10 -0800273 SCM_LEGACY_CLASS_REGISTER | \
274 SCM_LEGACY_MASK_IRQS | \
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500275 (n & 0xf))
276
277/**
278 * qcom_scm_call_atomic1() - Send an atomic SCM command with one argument
279 * @svc_id: service identifier
280 * @cmd_id: command identifier
281 * @arg1: first argument
282 *
283 * This shall only be used with commands that are guaranteed to be
284 * uninterruptable, atomic and SMP safe.
285 */
286static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1)
287{
288 int context_id;
Elliot Berman02248982020-01-07 13:04:18 -0800289 struct arm_smccc_res res;
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500290
Elliot Berman02248982020-01-07 13:04:18 -0800291 arm_smccc_smc(SCM_LEGACY_ATOMIC_ID(svc, cmd, 1),
292 (unsigned long)&context_id, arg1, 0, 0, 0, 0, 0, &res);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500293
Elliot Berman02248982020-01-07 13:04:18 -0800294 return res.a0;
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500295}
296
Andy Gross13e77742016-06-03 18:25:23 -0500297/**
298 * qcom_scm_call_atomic2() - Send an atomic SCM command with two arguments
299 * @svc_id: service identifier
300 * @cmd_id: command identifier
301 * @arg1: first argument
302 * @arg2: second argument
303 *
304 * This shall only be used with commands that are guaranteed to be
305 * uninterruptable, atomic and SMP safe.
306 */
307static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2)
308{
309 int context_id;
Elliot Berman02248982020-01-07 13:04:18 -0800310 struct arm_smccc_res res;
Andy Gross13e77742016-06-03 18:25:23 -0500311
Elliot Berman02248982020-01-07 13:04:18 -0800312 arm_smccc_smc(SCM_LEGACY_ATOMIC_ID(svc, cmd, 2),
313 (unsigned long)&context_id, arg1, 0, 0, 0, 0, 0, &res);
Andy Gross13e77742016-06-03 18:25:23 -0500314
Elliot Berman02248982020-01-07 13:04:18 -0800315 return res.a0;
Andy Gross13e77742016-06-03 18:25:23 -0500316}
317
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500318/**
319 * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus
320 * @entry: Entry point function for the cpus
321 * @cpus: The cpumask of cpus that will use the entry point
322 *
323 * Set the cold boot address of the cpus. Any cpu outside the supported
324 * range would be removed from the cpu present mask.
325 */
326int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus)
327{
328 int flags = 0;
329 int cpu;
330 int scm_cb_flags[] = {
331 QCOM_SCM_FLAG_COLDBOOT_CPU0,
332 QCOM_SCM_FLAG_COLDBOOT_CPU1,
333 QCOM_SCM_FLAG_COLDBOOT_CPU2,
334 QCOM_SCM_FLAG_COLDBOOT_CPU3,
335 };
336
337 if (!cpus || (cpus && cpumask_empty(cpus)))
338 return -EINVAL;
339
340 for_each_cpu(cpu, cpus) {
341 if (cpu < ARRAY_SIZE(scm_cb_flags))
342 flags |= scm_cb_flags[cpu];
343 else
344 set_cpu_present(cpu, false);
345 }
346
Elliot Berman5443cc52020-01-07 13:04:11 -0800347 return qcom_scm_call_atomic2(QCOM_SCM_SVC_BOOT, QCOM_SCM_BOOT_SET_ADDR,
Andy Gross13e77742016-06-03 18:25:23 -0500348 flags, virt_to_phys(entry));
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500349}
350
351/**
352 * qcom_scm_set_warm_boot_addr() - Set the warm boot address for cpus
353 * @entry: Entry point function for the cpus
354 * @cpus: The cpumask of cpus that will use the entry point
355 *
356 * Set the Linux entry point for the SCM to transfer control to when coming
357 * out of a power down. CPU power down may be executed on cpuidle or hotplug.
358 */
Andy Gross16e59462016-06-03 18:25:25 -0500359int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,
360 const cpumask_t *cpus)
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500361{
362 int ret;
363 int flags = 0;
364 int cpu;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800365 struct qcom_scm_desc desc = {
366 .svc = QCOM_SCM_SVC_BOOT,
367 .cmd = QCOM_SCM_BOOT_SET_ADDR,
368 };
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500369
370 /*
371 * Reassign only if we are switching from hotplug entry point
372 * to cpuidle entry point or vice versa.
373 */
374 for_each_cpu(cpu, cpus) {
375 if (entry == qcom_scm_wb[cpu].entry)
376 continue;
377 flags |= qcom_scm_wb[cpu].flag;
378 }
379
380 /* No change in entry function */
381 if (!flags)
382 return 0;
383
Elliot Bermanefd2b152020-01-07 13:04:20 -0800384 desc.args[0] = flags;
385 desc.args[1] = virt_to_phys(entry);
386 desc.arginfo = QCOM_SCM_ARGS(2);
387
388 ret = qcom_scm_call(dev, &desc, NULL);
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500389 if (!ret) {
390 for_each_cpu(cpu, cpus)
391 qcom_scm_wb[cpu].entry = entry;
392 }
393
394 return ret;
395}
396
397/**
398 * qcom_scm_cpu_power_down() - Power down the cpu
399 * @flags - Flags to flush cache
400 *
401 * This is an end point to power down cpu. If there was a pending interrupt,
402 * the control would return from this function, otherwise, the cpu jumps to the
403 * warm boot entry point set for this cpu upon reset.
404 */
405void __qcom_scm_cpu_power_down(u32 flags)
406{
Elliot Berman5443cc52020-01-07 13:04:11 -0800407 qcom_scm_call_atomic1(QCOM_SCM_SVC_BOOT, QCOM_SCM_BOOT_TERMINATE_PC,
Kumar Galab6a1dfb2015-03-11 16:28:10 -0500408 flags & QCOM_SCM_FLUSH_FLAG_MASK);
409}
jilai wang9626b692015-04-10 16:15:59 -0400410
Andy Gross16e59462016-06-03 18:25:25 -0500411int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id)
jilai wang9626b692015-04-10 16:15:59 -0400412{
413 int ret;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800414 struct qcom_scm_desc desc = {
415 .svc = QCOM_SCM_SVC_INFO,
416 .cmd = QCOM_SCM_INFO_IS_CALL_AVAIL,
417 .args[0] = SCM_LEGACY_FNID(svc_id, cmd_id),
418 .arginfo = QCOM_SCM_ARGS(1),
419 };
420 struct qcom_scm_res res;
jilai wang9626b692015-04-10 16:15:59 -0400421
Elliot Bermanefd2b152020-01-07 13:04:20 -0800422 ret = qcom_scm_call(dev, &desc, &res);
jilai wang9626b692015-04-10 16:15:59 -0400423
Elliot Bermanefd2b152020-01-07 13:04:20 -0800424 return ret ? : res.result[0];
jilai wang9626b692015-04-10 16:15:59 -0400425}
426
Andy Gross16e59462016-06-03 18:25:25 -0500427int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,
428 u32 req_cnt, u32 *resp)
jilai wang9626b692015-04-10 16:15:59 -0400429{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800430 int ret;
431 struct qcom_scm_desc desc = {
432 .svc = QCOM_SCM_SVC_HDCP,
433 .cmd = QCOM_SCM_HDCP_INVOKE,
434 };
435 struct qcom_scm_res res;
436
jilai wang9626b692015-04-10 16:15:59 -0400437 if (req_cnt > QCOM_SCM_HDCP_MAX_REQ_CNT)
438 return -ERANGE;
439
Elliot Bermanefd2b152020-01-07 13:04:20 -0800440 desc.args[0] = req[0].addr;
441 desc.args[1] = req[0].val;
442 desc.args[2] = req[1].addr;
443 desc.args[3] = req[1].val;
444 desc.args[4] = req[2].addr;
445 desc.args[5] = req[2].val;
446 desc.args[6] = req[3].addr;
447 desc.args[7] = req[3].val;
448 desc.args[8] = req[4].addr;
449 desc.args[9] = req[4].val;
450 desc.arginfo = QCOM_SCM_ARGS(10);
451
452 ret = qcom_scm_call(dev, &desc, &res);
453 *resp = res.result[0];
454
455 return ret;
jilai wang9626b692015-04-10 16:15:59 -0400456}
Kumar Gala6b1751a2016-06-03 18:25:26 -0500457
Rob Clarkb0a16142019-08-23 05:16:33 -0700458int __qcom_scm_ocmem_lock(struct device *dev, u32 id, u32 offset, u32 size,
459 u32 mode)
460{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800461 struct qcom_scm_desc desc = {
462 .svc = QCOM_SCM_SVC_OCMEM,
463 .cmd = QCOM_SCM_OCMEM_LOCK_CMD,
464 };
Rob Clarkb0a16142019-08-23 05:16:33 -0700465
Elliot Bermanefd2b152020-01-07 13:04:20 -0800466 desc.args[0] = id;
467 desc.args[1] = offset;
468 desc.args[2] = size;
469 desc.args[3] = mode;
470 desc.arginfo = QCOM_SCM_ARGS(4);
Rob Clarkb0a16142019-08-23 05:16:33 -0700471
Elliot Bermanefd2b152020-01-07 13:04:20 -0800472 return qcom_scm_call(dev, &desc, NULL);
Rob Clarkb0a16142019-08-23 05:16:33 -0700473}
474
475int __qcom_scm_ocmem_unlock(struct device *dev, u32 id, u32 offset, u32 size)
476{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800477 struct qcom_scm_desc desc = {
478 .svc = QCOM_SCM_SVC_OCMEM,
479 .cmd = QCOM_SCM_OCMEM_UNLOCK_CMD,
480 };
Rob Clarkb0a16142019-08-23 05:16:33 -0700481
Elliot Bermanefd2b152020-01-07 13:04:20 -0800482 desc.args[0] = id;
483 desc.args[1] = offset;
484 desc.args[2] = size;
485 desc.arginfo = QCOM_SCM_ARGS(3);
Rob Clarkb0a16142019-08-23 05:16:33 -0700486
Elliot Bermanefd2b152020-01-07 13:04:20 -0800487 return qcom_scm_call(dev, &desc, NULL);
Rob Clarkb0a16142019-08-23 05:16:33 -0700488}
489
Kumar Gala6b1751a2016-06-03 18:25:26 -0500490void __qcom_scm_init(void)
491{
492}
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700493
494bool __qcom_scm_pas_supported(struct device *dev, u32 peripheral)
495{
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700496 int ret;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800497 struct qcom_scm_desc desc = {
498 .svc = QCOM_SCM_SVC_PIL,
499 .cmd = QCOM_SCM_PIL_PAS_IS_SUPPORTED,
500 };
501 struct qcom_scm_res res;
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700502
Elliot Bermanefd2b152020-01-07 13:04:20 -0800503 desc.args[0] = peripheral;
504 desc.arginfo = QCOM_SCM_ARGS(1);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700505
Elliot Bermanefd2b152020-01-07 13:04:20 -0800506 ret = qcom_scm_call(dev, &desc, &res);
507
508 return ret ? false : !!res.result[0];
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700509}
510
511int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral,
512 dma_addr_t metadata_phys)
513{
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700514 int ret;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800515 struct qcom_scm_desc desc = {
516 .svc = QCOM_SCM_SVC_PIL,
517 .cmd = QCOM_SCM_PIL_PAS_INIT_IMAGE,
518 };
519 struct qcom_scm_res res;
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700520
Elliot Bermanefd2b152020-01-07 13:04:20 -0800521 desc.args[0] = peripheral;
522 desc.args[1] = metadata_phys;
523 desc.arginfo = QCOM_SCM_ARGS(2, QCOM_SCM_VAL, QCOM_SCM_RW);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700524
Elliot Bermanefd2b152020-01-07 13:04:20 -0800525 ret = qcom_scm_call(dev, &desc, &res);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700526
Elliot Bermanefd2b152020-01-07 13:04:20 -0800527 return ret ? : res.result[0];
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700528}
529
530int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral,
Elliot Bermanefd2b152020-01-07 13:04:20 -0800531 phys_addr_t addr, phys_addr_t size)
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700532{
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700533 int ret;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800534 struct qcom_scm_desc desc = {
535 .svc = QCOM_SCM_SVC_PIL,
536 .cmd = QCOM_SCM_PIL_PAS_MEM_SETUP,
537 };
538 struct qcom_scm_res res;
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700539
Elliot Bermanefd2b152020-01-07 13:04:20 -0800540 desc.args[0] = peripheral;
541 desc.args[1] = addr;
542 desc.args[2] = size;
543 desc.arginfo = QCOM_SCM_ARGS(3);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700544
Elliot Bermanefd2b152020-01-07 13:04:20 -0800545 ret = qcom_scm_call(dev, &desc, &res);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700546
Elliot Bermanefd2b152020-01-07 13:04:20 -0800547 return ret ? : res.result[0];
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700548}
549
550int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral)
551{
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700552 int ret;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800553 struct qcom_scm_desc desc = {
554 .svc = QCOM_SCM_SVC_PIL,
555 .cmd = QCOM_SCM_PIL_PAS_AUTH_AND_RESET,
556 };
557 struct qcom_scm_res res;
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700558
Elliot Bermanefd2b152020-01-07 13:04:20 -0800559 desc.args[0] = peripheral;
560 desc.arginfo = QCOM_SCM_ARGS(1);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700561
Elliot Bermanefd2b152020-01-07 13:04:20 -0800562 ret = qcom_scm_call(dev, &desc, &res);
563
564 return ret ? : res.result[0];
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700565}
566
567int __qcom_scm_pas_shutdown(struct device *dev, u32 peripheral)
568{
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700569 int ret;
Elliot Bermanefd2b152020-01-07 13:04:20 -0800570 struct qcom_scm_desc desc = {
571 .svc = QCOM_SCM_SVC_PIL,
572 .cmd = QCOM_SCM_PIL_PAS_SHUTDOWN,
573 };
574 struct qcom_scm_res res;
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700575
Elliot Bermanefd2b152020-01-07 13:04:20 -0800576 desc.args[0] = peripheral;
577 desc.arginfo = QCOM_SCM_ARGS(1);
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700578
Elliot Bermanefd2b152020-01-07 13:04:20 -0800579 ret = qcom_scm_call(dev, &desc, &res);
580
581 return ret ? : res.result[0];
Bjorn Anderssonf01e90f2015-09-23 12:56:12 -0700582}
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700583
584int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)
585{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800586 struct qcom_scm_desc desc = {
587 .svc = QCOM_SCM_SVC_PIL,
588 .cmd = QCOM_SCM_PIL_PAS_MSS_RESET,
589 };
590 struct qcom_scm_res res;
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700591 int ret;
592
Elliot Bermanefd2b152020-01-07 13:04:20 -0800593 desc.args[0] = reset;
594 desc.args[1] = 0;
595 desc.arginfo = QCOM_SCM_ARGS(2);
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700596
Elliot Bermanefd2b152020-01-07 13:04:20 -0800597 ret = qcom_scm_call(dev, &desc, &res);
598
599 return ret ? : res.result[0];
Bjorn Anderssondd4fe5b2016-06-17 10:40:43 -0700600}
Andy Grossa811b422017-01-16 23:24:15 -0600601
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700602int __qcom_scm_set_dload_mode(struct device *dev, bool enable)
603{
Elliot Berman5443cc52020-01-07 13:04:11 -0800604 return qcom_scm_call_atomic2(QCOM_SCM_SVC_BOOT, QCOM_SCM_BOOT_SET_DLOAD_MODE,
605 enable ? QCOM_SCM_BOOT_SET_DLOAD_MODE : 0, 0);
Bjorn Andersson8c1b7dc2017-08-14 15:46:18 -0700606}
607
Andy Grossa811b422017-01-16 23:24:15 -0600608int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id)
609{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800610 struct qcom_scm_desc desc = {
611 .svc = QCOM_SCM_SVC_BOOT,
612 .cmd = QCOM_SCM_BOOT_SET_REMOTE_STATE,
613 };
614 struct qcom_scm_res res;
Andy Grossa811b422017-01-16 23:24:15 -0600615 int ret;
616
Elliot Bermanefd2b152020-01-07 13:04:20 -0800617 desc.args[0] = state;
618 desc.args[1] = id;
Andy Grossa811b422017-01-16 23:24:15 -0600619
Elliot Bermanefd2b152020-01-07 13:04:20 -0800620 ret = qcom_scm_call(dev, &desc, &res);
Andy Grossa811b422017-01-16 23:24:15 -0600621
Elliot Bermanefd2b152020-01-07 13:04:20 -0800622 return ret ? : res.result[0];
Andy Grossa811b422017-01-16 23:24:15 -0600623}
Rob Clarka2c680c2017-03-14 11:18:03 -0400624
Avaneesh Kumar Dwivedid82bd352017-10-24 21:22:24 +0530625int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,
626 size_t mem_sz, phys_addr_t src, size_t src_sz,
627 phys_addr_t dest, size_t dest_sz)
628{
629 return -ENODEV;
630}
631
Rob Clarka2c680c2017-03-14 11:18:03 -0400632int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id,
633 u32 spare)
634{
Elliot Bermanefd2b152020-01-07 13:04:20 -0800635 struct qcom_scm_desc desc = {
636 .svc = QCOM_SCM_SVC_MP,
637 .cmd = QCOM_SCM_MP_RESTORE_SEC_CFG,
638 };
639 struct qcom_scm_res res;
640 int ret;
Rob Clark0434a402019-08-23 05:16:34 -0700641
Elliot Bermanefd2b152020-01-07 13:04:20 -0800642 desc.args[0] = device_id;
643 desc.args[1] = spare;
644 desc.arginfo = QCOM_SCM_ARGS(2);
Rob Clark0434a402019-08-23 05:16:34 -0700645
Elliot Bermanefd2b152020-01-07 13:04:20 -0800646 ret = qcom_scm_call(dev, &desc, &res);
Rob Clark0434a402019-08-23 05:16:34 -0700647
Elliot Bermanefd2b152020-01-07 13:04:20 -0800648 return ret ? : res.result[0];
Rob Clarka2c680c2017-03-14 11:18:03 -0400649}
Stanimir Varbanovb182cc42017-03-14 11:18:04 -0400650
651int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare,
652 size_t *size)
653{
654 return -ENODEV;
655}
656
657int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
658 u32 spare)
659{
660 return -ENODEV;
661}
Bjorn Andersson4e659db2017-08-14 15:46:17 -0700662
663int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
664 unsigned int *val)
665{
666 int ret;
667
668 ret = qcom_scm_call_atomic1(QCOM_SCM_SVC_IO, QCOM_SCM_IO_READ, addr);
669 if (ret >= 0)
670 *val = ret;
671
672 return ret < 0 ? ret : 0;
673}
674
675int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val)
676{
677 return qcom_scm_call_atomic2(QCOM_SCM_SVC_IO, QCOM_SCM_IO_WRITE,
678 addr, val);
679}
Vivek Gautam5eb0e0e2019-09-20 13:34:28 +0530680
681int __qcom_scm_qsmmu500_wait_safe_toggle(struct device *dev, bool enable)
682{
683 return -ENODEV;
684}