blob: 8ffc7a472b5b9460ee35de117bb96aba0a579fcd [file] [log] [blame]
Chee Hong Ang0eebfab2020-12-24 18:21:00 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Intel Corporation <www.intel.com>
4 *
5 */
6
7#include <common.h>
8#include <asm/ptrace.h>
9#include <asm/system.h>
10#include <linux/intel-smc.h>
11
12int invoke_smc(u32 func_id, u64 *args, int arg_len, u64 *ret_arg, int ret_len)
13{
14 struct pt_regs regs;
15
16 memset(&regs, 0, sizeof(regs));
17 regs.regs[0] = func_id;
18
19 if (args)
20 memcpy(&regs.regs[1], args, arg_len * sizeof(*args));
21
22 smc_call(&regs);
23
24 if (ret_arg)
25 memcpy(ret_arg, &regs.regs[1], ret_len * sizeof(*ret_arg));
26
27 return regs.regs[0];
28}
29
30int smc_send_mailbox(u32 cmd, u32 len, u32 *arg, u8 urgent, u32 *resp_buf_len,
31 u32 *resp_buf)
32{
33 int ret;
34 u64 args[6];
35 u64 resp[3];
36
37 args[0] = cmd;
38 args[1] = (u64)arg;
39 args[2] = len;
40 args[3] = urgent;
41 args[4] = (u64)resp_buf;
42 if (resp_buf_len)
43 args[5] = *resp_buf_len;
44 else
45 args[5] = 0;
46
47 ret = invoke_smc(INTEL_SIP_SMC_MBOX_SEND_CMD, args, ARRAY_SIZE(args),
48 resp, ARRAY_SIZE(resp));
49
50 if (ret == INTEL_SIP_SMC_STATUS_OK && resp_buf && resp_buf_len) {
51 if (!resp[0])
52 *resp_buf_len = resp[1];
53 }
54
55 return (int)resp[0];
56}
Siew Chin Lim96fe4f62021-03-25 14:07:45 +080057
58int smc_get_usercode(u32 *usercode)
59{
60 int ret;
61 u64 resp;
62
63 if (!usercode)
64 return -EINVAL;
65
66 ret = invoke_smc(INTEL_SIP_SMC_GET_USERCODE, NULL, 0,
67 &resp, 1);
68
69 if (ret == INTEL_SIP_SMC_STATUS_OK)
70 *usercode = (u32)resp;
71
72 return ret;
73}