]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: Add ArmHvcLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 10 Sep 2014 18:46:23 +0000 (18:46 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 10 Sep 2014 18:46:23 +0000 (18:46 +0000)
This is a utility library closely modeled after ArmSmcLib, that allows
hypervisor call (HVC) instructions to be issued from C code.

Change-Id: I5f5c65f83e910ff98dbb2f5b031dad8c4f663daa
Contributed-under: TianoCore Contribution Agreement 1.0
Acked-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16088 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/ArmPkg.dsc
ArmPkg/Include/Library/ArmHvcLib.h [new file with mode: 0644]
ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S [new file with mode: 0644]
ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S [new file with mode: 0644]
ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm [new file with mode: 0644]
ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf [new file with mode: 0644]

index 3a51b5ce1c1445aab4d1d3dbe995a08f6590fde8..ad02281926b3e4103ea28e18dd1a296338d65b00 100644 (file)
@@ -36,7 +36,8 @@
   GCC:*_*_ARM_PLATFORM_FLAGS    == -march=armv7-a -mfpu=neon\r
   GCC:RELEASE_*_*_CC_FLAGS     = -DMDEPKG_NDEBUG\r
 \r
-  RVCT:*_*_ARM_PLATFORM_FLAGS  == --cpu Cortex-A8\r
+  # We use A15 to get the Secure and Virtualization extensions\r
+  RVCT:*_*_ARM_PLATFORM_FLAGS  == --cpu Cortex-A15\r
   RVCT:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG\r
 \r
 [LibraryClasses.common]\r
 \r
   ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf\r
   ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf\r
+  ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf\r
 \r
   ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
 \r
diff --git a/ArmPkg/Include/Library/ArmHvcLib.h b/ArmPkg/Include/Library/ArmHvcLib.h
new file mode 100644 (file)
index 0000000..4e9d1c4
--- /dev/null
@@ -0,0 +1,46 @@
+/** @file\r
+*\r
+*  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+*\r
+**/\r
+\r
+#ifndef __ARM_HVC_LIB__\r
+#define __ARM_HVC_LIB__\r
+\r
+/**\r
+ * The size of the HVC arguments are different between AArch64 and AArch32.\r
+ * The native size is used for the arguments.\r
+ */\r
+typedef struct {\r
+  UINTN  Arg0;\r
+  UINTN  Arg1;\r
+  UINTN  Arg2;\r
+  UINTN  Arg3;\r
+  UINTN  Arg4;\r
+  UINTN  Arg5;\r
+  UINTN  Arg6;\r
+  UINTN  Arg7;\r
+} ARM_HVC_ARGS;\r
+\r
+/**\r
+  Trigger an HVC call\r
+\r
+  HVC calls can take up to 8 arguments and return up to 4 return values.\r
+  Therefore, the 4 first fields in the ARM_HVC_ARGS structure are used\r
+  for both input and output values.\r
+\r
+**/\r
+VOID\r
+ArmCallHvc (\r
+  IN OUT ARM_HVC_ARGS *Args\r
+  );\r
+\r
+#endif\r
diff --git a/ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S b/ArmPkg/Library/ArmHvcLib/AArch64/ArmHvc.S
new file mode 100644 (file)
index 0000000..a15ae03
--- /dev/null
@@ -0,0 +1,42 @@
+//\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2014, Linaro Limited. All rights reserved.\r
+//\r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+.text\r
+.align 3\r
+\r
+GCC_ASM_EXPORT(ArmCallHvc)\r
+\r
+ASM_PFX(ArmCallHvc):\r
+  // Push x0 on the stack\r
+  str   x0, [sp, #-8]!\r
+\r
+  // Load the HVC arguments values into the appropriate registers\r
+  ldp   x6, x7, [x0, #48]\r
+  ldp   x4, x5, [x0, #32]\r
+  ldp   x2, x3, [x0, #16]\r
+  ldp   x0, x1, [x0, #0]\r
+\r
+  hvc   #0\r
+\r
+  // Pop the ARM_HVC_ARGS structure address from the stack into x9\r
+  ldr   x9, [sp], #8\r
+\r
+  // Store the HVC returned values into the appropriate registers\r
+  // A HVC call can return up to 4 values\r
+  stp   x2, x3, [x9, #16]\r
+  stp   x0, x1, [x9, #0]\r
+\r
+  mov   x0, x9\r
+\r
+  ret\r
diff --git a/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S b/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.S
new file mode 100644 (file)
index 0000000..25ceb6a
--- /dev/null
@@ -0,0 +1,53 @@
+//\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2014, Linaro Limited. All rights reserved.\r
+//\r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+.text\r
+.align 3\r
+.arch_extension virt\r
+\r
+GCC_ASM_EXPORT(ArmCallHvc)\r
+\r
+ASM_PFX(ArmCallHvc):\r
+    push    {r4-r8}\r
+    // r0 will be popped just after the HVC call\r
+    push    {r0}\r
+\r
+    // Load the HVC arguments values into the appropriate registers\r
+    ldr     r7, [r0, #28]\r
+    ldr     r6, [r0, #24]\r
+    ldr     r5, [r0, #20]\r
+    ldr     r4, [r0, #16]\r
+    ldr     r3, [r0, #12]\r
+    ldr     r2, [r0, #8]\r
+    ldr     r1, [r0, #4]\r
+    ldr     r0, [r0, #0]\r
+\r
+    hvc     #0\r
+\r
+    // Pop the ARM_HVC_ARGS structure address from the stack into r8\r
+    pop     {r8}\r
+\r
+    // Load the HVC returned values into the appropriate registers\r
+    // A HVC call can return up to 4 values - we do not need to store back r4-r7.\r
+    str     r3, [r8, #12]\r
+    str     r2, [r8, #8]\r
+    str     r1, [r8, #4]\r
+    str     r0, [r8, #0]\r
+\r
+    mov     r0, r8\r
+\r
+    // Restore the registers r4-r8\r
+    pop     {r4-r8}\r
+\r
+    bx      lr\r
diff --git a/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm b/ArmPkg/Library/ArmHvcLib/Arm/ArmHvc.asm
new file mode 100644 (file)
index 0000000..bac26fb
--- /dev/null
@@ -0,0 +1,53 @@
+//\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2014, Linaro Limited. All rights reserved.\r
+//\r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+    EXPORT ArmCallHvc\r
+\r
+    AREA   ArmHvc, CODE, READONLY\r
+\r
+ArmCallHvc\r
+    push    {r4-r8}\r
+    // r0 will be popped just after the HVC call\r
+    push     {r0}\r
+\r
+    // Load the HVC arguments values into the appropriate registers\r
+    ldr     r7, [r0, #28]\r
+    ldr     r6, [r0, #24]\r
+    ldr     r5, [r0, #20]\r
+    ldr     r4, [r0, #16]\r
+    ldr     r3, [r0, #12]\r
+    ldr     r2, [r0, #8]\r
+    ldr     r1, [r0, #4]\r
+    ldr     r0, [r0, #0]\r
+\r
+    hvc     #0\r
+\r
+    // Pop the ARM_HVC_ARGS structure address from the stack into r8\r
+    pop     {r8}\r
+\r
+    // Load the HVC returned values into the appropriate registers\r
+    // A HVC call can return up to 4 values - we do not need to store back r4-r7.\r
+    str     r3, [r8, #12]\r
+    str     r2, [r8, #8]\r
+    str     r1, [r8, #4]\r
+    str     r0, [r8, #0]\r
+\r
+    mov     r0, r8\r
+\r
+    // Restore the registers r4-r8\r
+    pop     {r4-r8}\r
+\r
+    bx      lr\r
+\r
+    END\r
diff --git a/ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf b/ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf
new file mode 100644 (file)
index 0000000..92efac5
--- /dev/null
@@ -0,0 +1,32 @@
+#/** @file\r
+#\r
+#  Copyright (c) 2012-2013, ARM Ltd. All rights reserved.<BR>\r
+#  Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmHvcLib\r
+  FILE_GUID                      = E594959A-D150-44D3-963B-BA90329D3D9A\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmHvcLib\r
+\r
+[Sources.ARM]\r
+  Arm/ArmHvc.asm    | RVCT\r
+  Arm/ArmHvc.S      | GCC\r
+\r
+[Sources.AARCH64]\r
+  AArch64/ArmHvc.S\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPkg/ArmPkg.dec\r