All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michalis Pappas <mpappas@fastmail.fm>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3] arm64: Add SMC and HVC commands
Date: Mon,  9 Apr 2018 18:17:36 +0300	[thread overview]
Message-ID: <20180409151736.8046-1-mpappas@fastmail.fm> (raw)

This patch adds smc and hvc commands, that allow issuing Secure Monitor
Calls and Hypervisor Calls conforming to the ARM SMC Calling Convention.

Add Kconfig items to allow each command can be individually enabled.

Signed-off-by: Michalis Pappas <mpappas@fastmail.fm>
---

 cmd/Kconfig  | 14 ++++++++++
 cmd/Makefile |  2 ++
 cmd/smccc.c  | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 cmd/smccc.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 136836d146..2176b98ccb 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1348,6 +1348,20 @@ config CMD_HASH
 	  saved to memory or to an environment variable. It is also possible
 	  to verify a hash against data in memory.

+config CMD_HVC
+	bool "Support the 'hvc' command"
+	depends on ARM_SMCCC
+	help
+	  Allows issuing Hypervisor Calls (HVCs). Mostly useful for
+	  development and testing.
+
+config CMD_SMC
+	bool "Support the 'smc' command"
+	depends on ARM_SMCCC
+	help
+	  Allows issuing Secure Monitor Calls (SMCs). Mostly useful for
+	  development and testing.
+
 config HASH_VERIFY
 	bool "hash -v"
 	depends on CMD_HASH
diff --git a/cmd/Makefile b/cmd/Makefile
index 9a358e4801..5656a1a40a 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_CMD_FS_GENERIC) += fs.o
 obj-$(CONFIG_CMD_FUSE) += fuse.o
 obj-$(CONFIG_CMD_GETTIME) += gettime.o
 obj-$(CONFIG_CMD_GPIO) += gpio.o
+obj-$(CONFIG_CMD_HVC) += smccc.o
 obj-$(CONFIG_CMD_I2C) += i2c.o
 obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
 obj-$(CONFIG_CMD_HASH) += hash.o
@@ -113,6 +114,7 @@ obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
 obj-$(CONFIG_CMD_SPI) += spi.o
 obj-$(CONFIG_CMD_STRINGS) += strings.o
+obj-$(CONFIG_CMD_SMC) += smccc.o
 obj-$(CONFIG_CMD_TERMINAL) += terminal.o
 obj-$(CONFIG_CMD_TIME) += time.o
 obj-$(CONFIG_CMD_TRACE) += trace.o
diff --git a/cmd/smccc.c b/cmd/smccc.c
new file mode 100644
index 0000000000..2fa7c23999
--- /dev/null
+++ b/cmd/smccc.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018
+ * Michalis Pappas <mpappas@fastmail.fm>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#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(cmd_tbl_t *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
+
--
2.17.0

             reply	other threads:[~2018-04-09 15:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09 15:17 Michalis Pappas [this message]
2018-04-11 12:36 ` [U-Boot] [PATCH v3] arm64: Add SMC and HVC commands Simon Glass
2018-04-12  9:20   ` Michalis Pappas
2018-04-12 16:41     ` Simon Glass
2018-04-11  9:30 Michalis Pappas
2018-04-11  9:35 ` Michalis Pappas
2018-04-11 12:36   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180409151736.8046-1-mpappas@fastmail.fm \
    --to=mpappas@fastmail.fm \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.