From patchwork Fri Sep 5 11:56:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36822 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 48197202E4 for ; Fri, 5 Sep 2014 11:57:33 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id v10sf9681891pde.10 for ; Fri, 05 Sep 2014 04:57:27 -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=EMBRjbBiJMPjqT6yuBkEiUZWa88naZ7AvqFiIX62VJ94piOPSYwavIw2hfMbj7xw7F +HWt52QqxMiEYo/P7B9AadfwEavNShSmQUzNEuIOBcgWTGzRBYkhX/0VIp4hoPAadMN0 U5Q0R6q0KmMucDAtuF2zGzqTwczxn6rqeEyBPHEphAeFTS9OeEz0orVxs97fb1sNG+Im ivSsAKJ3KbOj0QINKbmvIaDMyzjXRetm+P5pSDuE4v8vxcxy3ZVjgzdsrmeTaeetKHPe 8olI+AJSk3geNvjlnKdCEg0I1mLJTVaC5NohBcESTLiLircf5j+dWJn0RtX+hLwiGrSM /dPw== X-Gm-Message-State: ALoCoQm/+FoYVtxUxeambXekrg75R6CGpfJ/M7HbOdMH95xd3Kz5f836OsxDNUeXtGpkml56c4Ke X-Received: by 10.66.193.227 with SMTP id hr3mr6727426pac.0.1409918246814; Fri, 05 Sep 2014 04:57:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.18 with SMTP id z18ls768435qge.0.gmail; Fri, 05 Sep 2014 04:57:26 -0700 (PDT) X-Received: by 10.221.61.5 with SMTP id wu5mr9743463vcb.13.1409918246708; Fri, 05 Sep 2014 04:57:26 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id cv1si993050vdc.22.2014.09.05.04.57.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 04:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so12147404vcb.39 for ; Fri, 05 Sep 2014 04:57:26 -0700 (PDT) X-Received: by 10.52.168.134 with SMTP id zw6mr837896vdb.37.1409918246620; Fri, 05 Sep 2014 04:57:26 -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 uj3csp71038vcb; Fri, 5 Sep 2014 04:57:26 -0700 (PDT) X-Received: by 10.50.43.233 with SMTP id z9mr3704645igl.41.1409918243048; Fri, 05 Sep 2014 04:57:23 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id y19si2855788icb.22.2014.09.05.04.57.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 05 Sep 2014 04:57:23 -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-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XPs8g-0005eg-4o; Fri, 05 Sep 2014 11:57:14 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XPs8e-0005eO-5Z for edk2-devel@lists.sourceforge.net; Fri, 05 Sep 2014 11:57:12 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.44 as permitted sender) client-ip=74.125.82.44; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f44.google.com; Received: from mail-wg0-f44.google.com ([74.125.82.44]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1XPs8c-0002yA-Qd for edk2-devel@lists.sourceforge.net; Fri, 05 Sep 2014 11:57:12 +0000 Received: by mail-wg0-f44.google.com with SMTP id m15so11575616wgh.27 for ; Fri, 05 Sep 2014 04:57:04 -0700 (PDT) X-Received: by 10.180.231.3 with SMTP id tc3mr3129338wic.18.1409918222761; Fri, 05 Sep 2014 04:57:02 -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 dc9sm1758798wib.5.2014.09.05.04.57.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Sep 2014 04:57:02 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com Date: Fri, 5 Sep 2014 13:56:33 +0200 Message-Id: <1409918214-29584-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1409918214-29584-1-git-send-email-ard.biesheuvel@linaro.org> References: <1409918214-29584-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: 1XPs8c-0002yA-Qd Cc: peter.maydell@linaro.org, ilias.biris@linaro.org, christoffer.dall@linaro.org Subject: [edk2] [PATCH v7 03/24] 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.180 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 Acked-by: Laszlo Ersek --- 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