summaryrefslogtreecommitdiff
path: root/cmd/smccc.c
blob: 0b19f6c68c6edb4d7b2c40e88aa93ef42de98122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2018
 * Michalis Pappas <mpappas@fastmail.fm>
 */
#include <asm/psci.h>
#include <common.h>
#include <command.h>
#include <linux/arm-smccc.h>
#include <linux/compiler.h>
#include <linux/psci.h>

static int do_call(struct cmd_tbl *cmdtp, int flag, int argc,
		   char *const argv[])
{
	struct arm_smccc_res res;

	unsigned long fid;

	unsigned long a1;
	unsigned long a2;
	unsigned long a3;
	unsigned long a4;
	unsigned long a5;
	unsigned long a6;
	unsigned long a7;

	if (argc < 2)
		return CMD_RET_USAGE;

	fid = simple_strtoul(argv[1], NULL, 16);

	a1 = argc > 2 ? simple_strtoul(argv[2], NULL, 16) : 0;
	a2 = argc > 3 ? simple_strtoul(argv[3], NULL, 16) : 0;
	a3 = argc > 4 ? simple_strtoul(argv[4], NULL, 16) : 0;
	a4 = argc > 5 ? simple_strtoul(argv[5], NULL, 16) : 0;
	a5 = argc > 6 ? simple_strtoul(argv[6], NULL, 16) : 0;
	a6 = argc > 7 ? simple_strtoul(argv[7], NULL, 16) : 0;
	a7 = argc > 8 ? simple_strtoul(argv[8], NULL, 16) : 0;

	if (!strcmp(argv[0], "smc"))
		arm_smccc_smc(fid, a1, a2, a3, a4, a5, a6, a7, &res);
	else
		arm_smccc_hvc(fid, a1, a2, a3, a4, a5, a6, a7, &res);

	printf("Res:  %ld %ld %ld %ld\n", res.a0, res.a1, res.a2, res.a3);

	return 0;
}

#ifdef CONFIG_CMD_SMC
U_BOOT_CMD(
	smc,	8,		2,	do_call,
	"Issue a Secure Monitor Call",
	"<fid> [arg1 ... arg6] [id]\n"
	"  - fid Function ID\n"
	"  - arg SMC arguments, passed to X1-X6 (default to zero)\n"
	"  - id  Secure OS ID / Session ID, passed to W7 (defaults to zero)\n"
);
#endif

#ifdef CONFIG_CMD_HVC
U_BOOT_CMD(
	hvc,	8,		2,	do_call,
	"Issue a Hypervisor Call",
	"<fid> [arg1...arg7] [id]\n"
	"  - fid Function ID\n"
	"  - arg HVC arguments, passed to X1-X6 (default to zero)\n"
	"  - id  Session ID, passed to W7 (defaults to zero)\n"
);
#endif