From patchwork Wed Sep 3 11:17:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36564 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AB642202E4 for ; Wed, 3 Sep 2014 11:18:46 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf44694416obc.8 for ; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=benmY7twtu3RDV5TGMv4mAJM5vkBVt671y2sVnzYkYU=; b=H9jHNLxgn/dmDqt6wo41A5rLA0a9oFl/igcbblzfGoRL965vbW0BzlEgTy6zLB2+px Ctcxny1VTJePTAAR53J9VnzzjWH0efmLaxL4ImKiSHBy3HxdOkr7RP1xlkojyCeV9RCl 6Df5nULQlZBBsUDQWjcWLZ+fnAMfCaL2NZSWqYgptG8S6i2O+c85v8ETqsdQ88cE730M gZf0IqEQqCRdNjKAKKDHpQZwaFMYCb2f2bIrJB9B9kd56+QuyXrhf1ACWUvT0o4nSjUk j8HN1saolwq1XYM/57+w2k3sR4ZRHG3XdLNsXkkVg9INu9dur7hIZDrcvoGpBGK7LYWO /Vvg== X-Gm-Message-State: ALoCoQlYrRuMX5MlQfCm4RdvFr+GKtiJhyET/z7ByGwQLc2tZ0FtTb9+nHnNC+BlLkfgQeR6DJzI X-Received: by 10.182.117.231 with SMTP id kh7mr22825849obb.0.1409743126328; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.16.112 with SMTP id 103ls2748954qga.9.gmail; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) X-Received: by 10.52.145.204 with SMTP id sw12mr25105vdb.79.1409743126196; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id v9si3467618vcs.20.2014.09.03.04.18.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so8453762vcb.22 for ; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) X-Received: by 10.220.175.17 with SMTP id v17mr5090382vcz.0.1409743126092; Wed, 03 Sep 2014 04:18:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp663935vcb; Wed, 3 Sep 2014 04:18:45 -0700 (PDT) X-Received: by 10.42.23.16 with SMTP id q16mr39272195icb.0.1409743124781; Wed, 03 Sep 2014 04:18:44 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id dx7si1662386igb.42.2014.09.03.04.18.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:44 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XP8aC-0004DJ-Ia; Wed, 03 Sep 2014 11:18:36 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XP8aB-0004DB-GT for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:35 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.179 as permitted sender) client-ip=74.125.82.179; envelope-from=ard.biesheuvel@linaro.org; helo=mail-we0-f179.google.com; Received: from mail-we0-f179.google.com ([74.125.82.179]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XP8aA-0007Zf-4b for edk2-devel@lists.sourceforge.net; Wed, 03 Sep 2014 11:18:35 +0000 Received: by mail-we0-f179.google.com with SMTP id t60so8415103wes.10 for ; Wed, 03 Sep 2014 04:18:27 -0700 (PDT) X-Received: by 10.194.187.241 with SMTP id fv17mr46473271wjc.13.1409743107876; Wed, 03 Sep 2014 04:18:27 -0700 (PDT) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id p1sm15258661wjy.22.2014.09.03.04.18.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:18:27 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Wed, 3 Sep 2014 13:17:56 +0200 Message-Id: <1409743096-14919-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409743096-14919-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409743096-14919-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1XP8aA-0007Zf-4b Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v6 03/23] ArmPkg: add ArmHvcLib X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This is a utility library closely modeled after ArmSmcLib, that allows hypervisor call (HVC) instructions to be issued from C code. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/Include/Library/ArmHvcLib.h | 42 ++++++++++++++++++++++++++++++ ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S | 38 +++++++++++++++++++++++++++ ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S | 43 +++++++++++++++++++++++++++++++ ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm | 43 +++++++++++++++++++++++++++++++ ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf | 32 +++++++++++++++++++++++ 5 files changed, 198 insertions(+) create mode 100644 ArmPkg/Include/Library/ArmHvcLib.h create mode 100644 ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S create mode 100644 ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S create mode 100644 ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm create mode 100644 ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf diff --git a/ArmPkg/Include/Library/ArmHvcLib.h b/ArmPkg/Include/Library/ArmHvcLib.h new file mode 100644 index 000000000000..b5c3d81cdf3d --- /dev/null +++ b/ArmPkg/Include/Library/ArmHvcLib.h @@ -0,0 +1,42 @@ +/** @file +* +* Copyright (c) 2012-2014, ARM Limited. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __ARM_HVC_LIB__ +#define __ARM_HVC_LIB__ + +/** + * The size of the HVC arguments are different between AArch64 and AArch32. + * The native size is used for the arguments. + */ +typedef struct { + UINTN Arg0; + UINTN Arg1; + UINTN Arg2; + UINTN Arg3; +} ARM_HVC_ARGS; + +/** + Trigger an HVC call + + HVC calls can take up to 4 arguments and return up to 4 return values. + Therefore, the 4 first fields in the ARM_HVC_ARGS structure are used + for both input and output values. + +**/ +VOID +ArmCallHvc ( + IN OUT ARM_HVC_ARGS *Args + ); + +#endif diff --git a/ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S b/ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S new file mode 100644 index 000000000000..156e5554cf5b --- /dev/null +++ b/ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S @@ -0,0 +1,38 @@ +// +// Copyright (c) 2012-2014, ARM Limited. All rights reserved. +// Copyright (c) 2014, Linaro Limited. All rights reserved. +// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BSD License +// which accompanies this distribution. The full text of the license may be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +// +// + +.text +.align 3 + +GCC_ASM_EXPORT(ArmCallHvc) + +ASM_PFX(ArmCallHvc): + // Push x0 on the stack + str x0, [sp, #-8]! + + // Load the HVC arguments values into the appropriate registers + ldp x2, x3, [x0, #16] + ldp x0, x1, [x0, #0] + + hvc #0 + + // Pop the ARM_HVC_ARGS structure address from the stack into x9 + ldr x9, [sp], #8 + + // Store the HVC returned values into the appropriate registers + // A HVC call can return up to 4 values + stp x2, x3, [x9, #16] + stp x0, x1, [x9, #0] + + ret diff --git a/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S b/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S new file mode 100644 index 000000000000..e48f2ebc2032 --- /dev/null +++ b/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S @@ -0,0 +1,43 @@ +// +// Copyright (c) 2012-2014, ARM Limited. All rights reserved. +// Copyright (c) 2014, Linaro Limited. All rights reserved. +// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BSD License +// which accompanies this distribution. The full text of the license may be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +// +// + +.text +.align 3 +.arch_extension virt + +GCC_ASM_EXPORT(ArmCallHvc) + +ASM_PFX(ArmCallHvc): + // r0 will be popped just after the HVC call + push {r0} + + // Load the HVC arguments values into the appropriate registers + ldr r3, [r0, #12] + ldr r2, [r0, #8] + ldr r1, [r0, #4] + ldr r0, [r0, #0] + + hvc #0 + + // Pop the ARM_HVC_ARGS structure address from the stack into ip + pop {ip} + + // Load the HVC returned values into the appropriate registers + // A HVC call can return up to 4 values + str r3, [ip, #12] + str r2, [ip, #8] + str r1, [ip, #4] + str r0, [ip, #0] + + bx lr diff --git a/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm b/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm new file mode 100644 index 000000000000..1275f590c8aa --- /dev/null +++ b/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm @@ -0,0 +1,43 @@ +// +// Copyright (c) 2012-2014, ARM Limited. All rights reserved. +// Copyright (c) 2014, Linaro Limited. All rights reserved. +// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BSD License +// which accompanies this distribution. The full text of the license may be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +// +// + + EXPORT ArmCallHvc + + AREA ArmHvc, CODE, READONLY + +ArmCallHvc + // r0 will be popped just after the HVC call + pop {r0} + + // Load the HVC arguments values into the appropriate registers + ldr r3, [r0, #12] + ldr r2, [r0, #8] + ldr r1, [r0, #4] + ldr r0, [r0, #0] + + hvc #0 + + // Pop the ARM_HVC_ARGS structure address from the stack into ip + pop {ip} + + // Load the HVC returned values into the appropriate registers + // A HVC call can return up to 4 values + str r3, [ip, #12] + str r2, [ip, #8] + str r1, [ip, #4] + str r0, [ip, #0] + + bx lr + + END diff --git a/ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf b/ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf new file mode 100644 index 000000000000..92efac5741c8 --- /dev/null +++ b/ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf @@ -0,0 +1,32 @@ +#/** @file +# +# Copyright (c) 2012-2013, ARM Ltd. All rights reserved.
+# Copyright (c) 2014, Linaro Ltd. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ArmHvcLib + FILE_GUID = E594959A-D150-44D3-963B-BA90329D3D9A + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmHvcLib + +[Sources.ARM] + Arm/ArmHvc.asm | RVCT + Arm/ArmHvc.S | GCC + +[Sources.AARCH64] + AArch64/ArmHvc.S + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec