blob: 085daba162a8036c5494131746975969974f4d92 [file] [log] [blame]
Chee Hong Angb5ddb912020-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}