From patchwork Mon Apr 9 13:11:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michalis Pappas X-Patchwork-Id: 896281 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=fastmail.fm Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fastmail.fm header.i=@fastmail.fm header.b="rJag/W2t"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BUgxXtNM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40KWMz171gz9s0t for ; Mon, 9 Apr 2018 23:28:30 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9DCA4C21E02; Mon, 9 Apr 2018 13:26:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 039D5C21C38; Mon, 9 Apr 2018 13:26:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 47772C21D72; Mon, 9 Apr 2018 13:11:57 +0000 (UTC) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lists.denx.de (Postfix) with ESMTPS id A9980C21CB1 for ; Mon, 9 Apr 2018 13:11:56 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 688E72121D; Mon, 9 Apr 2018 09:11:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 09 Apr 2018 09:11:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=Ghn/uBSgY0sxAXa0BjsPCjQMcTDjOSsgYdfvZdMQJ sQ=; b=rJag/W2tt++DDUzVp3uU9M+nT20zFJm1sAFrzy1mA+96JEzkyhUoRO7/L zYiySd6NRttkvAR1JndZ4Vl7S30VQcgIrW4/6SrjGSzsddyHzCosfQIWhuqui+Of PA2de6/gWoRsXT24pBsjdSTnd+wekC+UM0rE2HPW7G9hZMvj+LeyP6cRrFSPXdU+ Ui5vNrS62yDaP9Jp1L6y5N2/nMshXVWPU3685nq63ymC6ICMeR0+ja8Mcri397kN vc/5KbjL449zoSFGMGH6EXjBqTpOZwnGQa3fx55SLf0KIwq7PU2eIYlZlYZkA1T7 X25oXh53UW/DY6uZHjFLUJRrP20rQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Ghn/uBSgY0sxAXa0B jsPCjQMcTDjOSsgYdfvZdMQJsQ=; b=BUgxXtNMvYSh/6/lBKJg4N9SO6k7CafKs q3g2Hu+54iX5mF2czrz+bsRbsRdcAGIhpPz6C4YQ2NAS88aZChj2HBgeL1q+Rce3 tcc/XPf114bCOVpmvWojt2INql3eWMaDkVTtQWcFjLvqApXmwsxTG5ZRKYivxcHB dnSCW7DF1pfmn1wlIIRAWz8tAl4a+HWEzgfvceFribiRzWbJrbm6Kh2SgC5yksE/ 3020pnv58WKwU5wWoinofs5yVMUz8+B3ippE0vhJdHX/Ovp3Z2zPi5yCkGztsLbv hEZ3Tl7MNDr3LbZuvlJCIks6Vmaoj7fkQwFxtUj5GmlHnPbTcCyUg== X-ME-Sender: Received: from localhost.localdomain (130.43.65.170.dsl.dyn.forthnet.gr [130.43.65.170]) by mail.messagingengine.com (Postfix) with ESMTPA id 12679E5085; Mon, 9 Apr 2018 09:11:52 -0400 (EDT) From: Michalis Pappas To: u-boot@lists.denx.de Date: Mon, 9 Apr 2018 16:11:01 +0300 Message-Id: <20180409131101.5626-1-mpappas@fastmail.fm> X-Mailer: git-send-email 2.17.0 X-Mailman-Approved-At: Mon, 09 Apr 2018 13:25:57 +0000 Cc: trini@konsulko.com Subject: [U-Boot] [PATCH v2] arm64: Add SMC and HVC commands X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- cmd/Kconfig | 14 ++++++++++ cmd/Makefile | 2 ++ cmd/smccc.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 cmd/smccc.c -- 2.17.0 diff --git a/cmd/Kconfig b/cmd/Kconfig index 136836d146..a2b09620f3 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 ARM64 + help + Allows issuing Hypervisor Calls (HVCs). Mostly useful for + development and testing. + +config CMD_SMC + bool "Support the 'smc' command" + depends on ARM64 + 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 + * + * SPDX-License-Identifier: GPL-2.0+ + */ +#include +#include +#include +#include +#include +#include + +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", + " [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", + " [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 +