Revision: 18099
          http://sourceforge.net/p/edk2/code/18099
Author:   abiesheuvel
Date:     2015-07-28 20:44:58 +0000 (Tue, 28 Jul 2015)
Log Message:
-----------
ArmPkg: copy ArmGicArchLib to ArmGicArchSecLib

Clone ArmGicArchLib into a SEC phase specific ArmGicArchSecLib
so that we can modify the former in a subsequent patch to cache
the GIC revision in a global variable.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Reviewed-by: Leif Lindholm <[email protected]>
Tested-by: Leif Lindholm <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc
    trunk/edk2/ArmPlatformPkg/ArmPlatformPkg.dsc
    trunk/edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc
    trunk/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc

Added Paths:
-----------
    trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/
    trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/AArch64/
    trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/AArch64/ArmGicArchLib.c
    trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/Arm/
    trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/Arm/ArmGicArchLib.c
    trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf

Added: trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/AArch64/ArmGicArchLib.c
===================================================================
--- trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/AArch64/ArmGicArchLib.c          
                (rev 0)
+++ trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/AArch64/ArmGicArchLib.c  
2015-07-28 20:44:58 UTC (rev 18099)
@@ -0,0 +1,51 @@
+/** @file
+*
+*  Copyright (c) 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.
+*
+**/
+
+#include <Library/ArmLib.h>
+#include <Library/ArmGicLib.h>
+
+ARM_GIC_ARCH_REVISION
+EFIAPI
+ArmGicGetSupportedArchRevision (
+  VOID
+  )
+{
+  UINT32    IccSre;
+
+  // Ideally we would like to use the GICC IIDR Architecture version here, but
+  // this does not seem to be very reliable as the implementation could easily
+  // get it wrong. It is more reliable to check if the GICv3 System Register
+  // feature is implemented on the CPU. This is also convenient as our GICv3
+  // driver requires SRE. If only Memory mapped access is available we try to
+  // drive the GIC as a v2.
+  if (ArmReadIdPfr0 () & AARCH64_PFR0_GIC) {
+    // Make sure System Register access is enabled (SRE). This depends on the
+    // higher privilege level giving us permission, otherwise we will either
+    // cause an exception here, or the write doesn't stick in which case we 
need
+    // to fall back to the GICv2 MMIO interface.
+    // Note: We do not need to set ICC_SRE_EL2.Enable because the OS is started
+    // at the same exception level.
+    // It is the OS responsibility to set this bit.
+    IccSre = ArmGicV3GetControlSystemRegisterEnable ();
+    if (!(IccSre & ICC_SRE_EL2_SRE)) {
+      ArmGicV3SetControlSystemRegisterEnable (IccSre | ICC_SRE_EL2_SRE);
+      IccSre = ArmGicV3GetControlSystemRegisterEnable ();
+    }
+    if (IccSre & ICC_SRE_EL2_SRE) {
+      return ARM_GIC_ARCH_REVISION_3;
+    }
+  }
+
+  return ARM_GIC_ARCH_REVISION_2;
+}

Added: trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/Arm/ArmGicArchLib.c
===================================================================
--- trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/Arm/ArmGicArchLib.c              
                (rev 0)
+++ trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/Arm/ArmGicArchLib.c      
2015-07-28 20:44:58 UTC (rev 18099)
@@ -0,0 +1,51 @@
+/** @file
+*
+*  Copyright (c) 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.
+*
+**/
+
+#include <Library/ArmLib.h>
+#include <Library/ArmGicLib.h>
+
+ARM_GIC_ARCH_REVISION
+EFIAPI
+ArmGicGetSupportedArchRevision (
+  VOID
+  )
+{
+  UINT32    IccSre;
+
+  // Ideally we would like to use the GICC IIDR Architecture version here, but
+  // this does not seem to be very reliable as the implementation could easily
+  // get it wrong. It is more reliable to check if the GICv3 System Register
+  // feature is implemented on the CPU. This is also convenient as our GICv3
+  // driver requires SRE. If only Memory mapped access is available we try to
+  // drive the GIC as a v2.
+  if (ArmReadIdPfr1 () & ARM_PFR1_GIC) {
+    // Make sure System Register access is enabled (SRE). This depends on the
+    // higher privilege level giving us permission, otherwise we will either
+    // cause an exception here, or the write doesn't stick in which case we 
need
+    // to fall back to the GICv2 MMIO interface.
+    // Note: We do not need to set ICC_SRE_EL2.Enable because the OS is started
+    // at the same exception level.
+    // It is the OS responsibility to set this bit.
+    IccSre = ArmGicV3GetControlSystemRegisterEnable ();
+    if (!(IccSre & ICC_SRE_EL2_SRE)) {
+      ArmGicV3SetControlSystemRegisterEnable (IccSre| ICC_SRE_EL2_SRE);
+      IccSre = ArmGicV3GetControlSystemRegisterEnable ();
+    }
+    if (IccSre & ICC_SRE_EL2_SRE) {
+      return ARM_GIC_ARCH_REVISION_3;
+    }
+  }
+
+  return ARM_GIC_ARCH_REVISION_2;
+}

Added: trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf
===================================================================
--- trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf             
                (rev 0)
+++ trunk/edk2/ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf     
2015-07-28 20:44:58 UTC (rev 18099)
@@ -0,0 +1,33 @@
+#/* @file
+#  Copyright (c) 2015, 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                      = ArmGicArchSecLib
+  FILE_GUID                      = c1dd9745-9459-4e9a-9f5b-99cbd233c27d
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmGicArchLib|SEC
+
+[Sources.ARM]
+  Arm/ArmGicArchLib.c
+
+[Sources.AARCH64]
+  AArch64/ArmGicArchLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ArmPkg/ArmPkg.dec
+
+[LibraryClasses]
+  ArmGicLib

Modified: trunk/edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc
===================================================================
--- trunk/edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc       2015-07-28 
20:44:44 UTC (rev 18098)
+++ trunk/edk2/ArmPlatformPkg/ArmPlatformPkg-2ndstage.dsc       2015-07-28 
20:44:58 UTC (rev 18099)
@@ -143,6 +143,7 @@
   
PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
   PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
   PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
+  ArmGicArchLib|ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf
 
 [LibraryClasses.common.SEC, LibraryClasses.common.PEIM]
   MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf

Modified: trunk/edk2/ArmPlatformPkg/ArmPlatformPkg.dsc
===================================================================
--- trunk/edk2/ArmPlatformPkg/ArmPlatformPkg.dsc        2015-07-28 20:44:44 UTC 
(rev 18098)
+++ trunk/edk2/ArmPlatformPkg/ArmPlatformPkg.dsc        2015-07-28 20:44:58 UTC 
(rev 18099)
@@ -139,6 +139,8 @@
   
DebugAgentLib|ArmPkg/Library/DebugAgentSymbolsBaseLib/DebugAgentSymbolsBaseLib.inf
   
DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLibBase.inf
 
+  ArmGicArchLib|ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf
+
 [LibraryClasses.common.SEC, LibraryClasses.common.PEIM]
   MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
 

Modified: trunk/edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc
===================================================================
--- trunk/edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc    
2015-07-28 20:44:44 UTC (rev 18098)
+++ trunk/edk2/ArmPlatformPkg/ArmRealViewEbPkg/ArmRealViewEb.dsc.inc    
2015-07-28 20:44:58 UTC (rev 18099)
@@ -137,6 +137,8 @@
   
PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
 !endif
 
+  ArmGicArchLib|ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf
+
 [LibraryClasses.common.SEC, LibraryClasses.common.PEIM]
   MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
 

Modified: trunk/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc
===================================================================
--- trunk/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc        
2015-07-28 20:44:44 UTC (rev 18098)
+++ trunk/edk2/ArmPlatformPkg/ArmVExpressPkg/ArmVExpress.dsc.inc        
2015-07-28 20:44:58 UTC (rev 18099)
@@ -151,6 +151,8 @@
   # Trustzone Support
   
ArmTrustedMonitorLib|ArmPlatformPkg/Library/ArmTrustedMonitorLibNull/ArmTrustedMonitorLibNull.inf
 
+  ArmGicArchLib|ArmPkg/Library/ArmGicArchSecLib/ArmGicArchSecLib.inf
+
 [LibraryClasses.common.PEI_CORE]
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to