diff mbox

[edk2,4/4] ArmVirtualizationPkg: implement DT-based ArmGicArchLib

Message ID 1423132136-19349-5-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel Feb. 5, 2015, 10:28 a.m. UTC
This implements the library class ArmGicArchLib tailored for device
tree based virt platforms. The recorded dynamic PCD is used to set
the supported GIC version, which means this library can only execute
post DXE core, but this is not a problem for the virt platforms.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 .../ArmVirtualizationPkg/ArmVirtualization.dsc.inc |  2 +-
 .../Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c  | 77 ++++++++++++++++++++++
 .../ArmVirtGicArchLib/ArmVirtGicArchLib.inf        | 40 +++++++++++
 3 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c
 create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf
diff mbox

Patch

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
index c72591ff48b7..345270f2eb19 100644
--- a/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
+++ b/ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualization.dsc.inc
@@ -68,7 +68,7 @@ 
   ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
   DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
   ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf
-  ArmGicArchLib|ArmPkg/Drivers/ArmGic/ArmGicArchLib.inf
+  ArmGicArchLib|ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf
   ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf
   ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
   ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf
diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c
new file mode 100644
index 000000000000..45f5aec92bce
--- /dev/null
+++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c
@@ -0,0 +1,77 @@ 
+/** @file
+  ArmGicArchLib library class implementation for DT based virt platforms
+
+  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+
+  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.
+
+**/
+
+#include <Base.h>
+
+#include <Library/ArmGicLib.h>
+#include <Library/ArmGicArchLib.h>
+#include <Library/PcdLib.h>
+#include <Library/DebugLib.h>
+
+#include <Drivers/ArmGic/GicV3/ArmGicV3Lib.h>
+
+STATIC ARM_GIC_ARCH_REVISION mArmGicSupportedArchRevision;
+
+RETURN_STATUS
+EFIAPI
+ArmVirtGicArchLibConstructor (
+  VOID
+  )
+{
+  UINT32  Val;
+
+  switch (PcdGet32 (PcdArmGicRevision)) {
+
+  case 3:
+    //
+    // The default implementation of ArmGicArchLib is responsible for enabling
+    // the system register interface on the GICv3 if one is found. So let's do
+    // the same here.
+    //
+    Val = ArmGicV3GetControlSystemRegisterEnable ();
+    if ((Val & ICC_SRE_EL2_SRE) == 0) {
+      ArmGicV3SetControlSystemRegisterEnable (Val | ICC_SRE_EL2_SRE);
+      Val = ArmGicV3GetControlSystemRegisterEnable ();
+    }
+
+    //
+    // Unlike the default implementation, there is no fall through to GICv2
+    // mode if this GICv3 cannot be driven in native mode due to the fact
+    // that the System Register interface is unavailable.
+    //
+    ASSERT (Val & ICC_SRE_EL2_SRE);
+
+    mArmGicSupportedArchRevision = ARM_GIC_ARCH_REVISION_3;
+    break;
+
+  case 2:
+    mArmGicSupportedArchRevision = ARM_GIC_ARCH_REVISION_2;
+    break;
+
+  default:
+    DEBUG ((EFI_D_ERROR, "%a: No GIC revision specified!\n", __FUNCTION__));
+    return RETURN_NOT_FOUND;
+  }
+  return RETURN_SUCCESS;
+}
+
+ARM_GIC_ARCH_REVISION
+EFIAPI
+ArmGicGetSupportedArchRevision (
+  VOID
+  )
+{
+  return mArmGicSupportedArchRevision;
+}
diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf
new file mode 100644
index 000000000000..ce682722ef1b
--- /dev/null
+++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.inf
@@ -0,0 +1,40 @@ 
+#/** @file
+#
+#  Component description file for ArmVirtGicArchLib module
+#
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+#
+#  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                      = ArmVirtGicArchLib
+  FILE_GUID                      = 87b0dc84-4661-4deb-a789-97977ff636ed
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmGicArchLib|DXE_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION
+  CONSTRUCTOR                    = ArmVirtGicArchLibConstructor
+
+[Sources]
+  ArmVirtGicArchLib.c
+
+[LibraryClasses]
+  PcdLib
+  DebugLib
+  ArmGicLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ArmPkg/ArmPkg.dec
+  ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec
+
+[Pcd]
+  gArmVirtualizationTokenSpaceGuid.PcdArmGicRevision