1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2018
4 * Michalis Pappas <mpappas@fastmail.fm>
5 */
6 #include <asm/psci.h>
7 #include <command.h>
8 #include <vsprintf.h>
9 #include <linux/arm-smccc.h>
10 #include <linux/compiler.h>
11 #include <linux/psci.h>
12 #include <linux/string.h>
13
do_call(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])14 static int do_call(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
16 {
17 struct arm_smccc_res res;
18
19 unsigned long fid;
20
21 unsigned long a1;
22 unsigned long a2;
23 unsigned long a3;
24 unsigned long a4;
25 unsigned long a5;
26 unsigned long a6;
27 unsigned long a7;
28
29 if (argc < 2)
30 return CMD_RET_USAGE;
31
32 fid = hextoul(argv[1], NULL);
33
34 a1 = argc > 2 ? hextoul(argv[2], NULL) : 0;
35 a2 = argc > 3 ? hextoul(argv[3], NULL) : 0;
36 a3 = argc > 4 ? hextoul(argv[4], NULL) : 0;
37 a4 = argc > 5 ? hextoul(argv[5], NULL) : 0;
38 a5 = argc > 6 ? hextoul(argv[6], NULL) : 0;
39 a6 = argc > 7 ? hextoul(argv[7], NULL) : 0;
40 a7 = argc > 8 ? hextoul(argv[8], NULL) : 0;
41
42 if (!strcmp(argv[0], "smc"))
43 arm_smccc_smc(fid, a1, a2, a3, a4, a5, a6, a7, &res);
44 else
45 arm_smccc_hvc(fid, a1, a2, a3, a4, a5, a6, a7, &res);
46
47 printf("Res: 0x%lx 0x%lx 0x%lx 0x%lx\n", res.a0, res.a1, res.a2, res.a3);
48
49 return 0;
50 }
51
52 #ifdef CONFIG_CMD_SMC
53 U_BOOT_CMD(
54 smc, 9, 2, do_call,
55 "Issue a Secure Monitor Call",
56 "<fid> [arg1 ... arg6] [id]\n"
57 " - fid Function ID\n"
58 " - arg SMC arguments, passed to X1-X6 (default to zero)\n"
59 " - id Secure OS ID / Session ID, passed to W7 (defaults to zero)\n"
60 );
61 #endif
62
63 #ifdef CONFIG_CMD_HVC
64 U_BOOT_CMD(
65 hvc, 9, 2, do_call,
66 "Issue a Hypervisor Call",
67 "<fid> [arg1...arg6] [id]\n"
68 " - fid Function ID\n"
69 " - arg HVC arguments, passed to X1-X6 (default to zero)\n"
70 " - id Session ID, passed to W7 (defaults to zero)\n"
71 );
72 #endif
73