]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmGic: Function to locate the current CPU GIC redistributor
authorOlivier Martin <olivier.martin@arm.com>
Mon, 16 Feb 2015 10:22:07 +0000 (10:22 +0000)
committeroliviermartin <oliviermartin@Edk2>
Mon, 16 Feb 2015 10:22:07 +0000 (10:22 +0000)
CPU GIC Registributors are located next to each other in the GIC Redistributor
space.
The CPU GIC Redistributor is identified by its CPU affinity Aff3.Aff2.Aff1.Aff0.

This function returns the base address of the GIC Redistributor of
the calling CPU.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Tested-by: Ard Biesheuvel <ard@linaro.org>
Reviewed-by: Ard Biesheuvel <ard@linaro.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16873 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Drivers/ArmGic/ArmGicLib.c
ArmPkg/Drivers/ArmGic/ArmGicLib.inf
ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf

index 1e5924f5a49f0d396d40c76a2d8a5eec18cc120e..1e213019fee9c72c731e22e5768de9bc15de5323 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2015, 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
 \r
 #include <Base.h>\r
 #include <Library/ArmGicLib.h>\r
+#include <Library/ArmLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/IoLib.h>\r
+#include <Library/PcdLib.h>\r
 \r
 #include "GicV2/ArmGicV2Lib.h"\r
 #include "GicV3/ArmGicV3Lib.h"\r
 \r
+/**\r
+ * Return the base address of the GIC redistributor for the current CPU\r
+ *\r
+ * @param Revision  GIC Revision. The GIC redistributor might have a different\r
+ *                  granularity following the GIC revision.\r
+ *\r
+ * @retval Base address of the associated GIC Redistributor\r
+ */\r
+STATIC\r
+UINTN\r
+GicGetCpuRedistributorBase (\r
+  IN UINTN                 GicRedistributorBase,\r
+  IN ARM_GIC_ARCH_REVISION Revision\r
+  )\r
+{\r
+  UINTN Index;\r
+  UINTN MpId;\r
+  UINTN CpuAffinity;\r
+  UINTN Affinity;\r
+  UINTN GicRedistributorGranularity;\r
+  UINTN GicCpuRedistributorBase;\r
+\r
+  MpId = ArmReadMpidr ();\r
+  // Define CPU affinity as Affinity0[0:8], Affinity1[9:15], Affinity2[16:23], Affinity3[24:32]\r
+  // whereas Affinity3 is defined at [32:39] in MPIDR\r
+  CpuAffinity = (MpId & (ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2)) | ((MpId & ARM_CORE_AFF3) >> 8);\r
+\r
+  if (Revision == ARM_GIC_ARCH_REVISION_3) {\r
+    // 2 x 64KB frame: Redistributor control frame + SGI Control & Generation frame\r
+    GicRedistributorGranularity = ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_SGI_PPI_FRAME_SIZE;\r
+  } else {\r
+    ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
+    return 0;\r
+  }\r
+\r
+  GicCpuRedistributorBase = GicRedistributorBase;\r
+\r
+  for (Index = 0; Index < PcdGet32 (PcdCoreCount); Index++) {\r
+    Affinity = MmioRead64 (GicCpuRedistributorBase + ARM_GICR_TYPER) >> 32;\r
+    if (Affinity == CpuAffinity) {\r
+      return GicCpuRedistributorBase;\r
+    }\r
+\r
+    // Move to the next GIC Redistributor frame\r
+    GicRedistributorBase += GicRedistributorGranularity;\r
+  }\r
+\r
+  // The Redistributor has not been found for the current CPU\r
+  ASSERT_EFI_ERROR (EFI_NOT_FOUND);\r
+  return 0;\r
+}\r
+\r
 UINTN\r
 EFIAPI\r
 ArmGicGetInterfaceIdentification (\r
index a0d52043d6509bc37ac620e0571ade2d8b95efd7..9f466792e99617a8991d1900b61529da191802ae 100644 (file)
@@ -1,5 +1,5 @@
 #/* @file\r
-#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+#  Copyright (c) 2011-2015, 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
@@ -42,4 +42,8 @@
 \r
 [Packages]\r
   ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
   MdePkg/MdePkg.dec\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdCoreCount\r
index c08186dfe9677ebcd99df86f3969010962b7e640..9097b37f2b8146c4f721867c7d6bd5594621991e 100644 (file)
@@ -1,5 +1,5 @@
 #/* @file\r
-#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+#  Copyright (c) 2011-2015, 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
@@ -45,3 +45,6 @@
   ArmLib\r
   DebugLib\r
   IoLib\r
+\r
+[Pcd]\r
+  gArmPlatformTokenSpaceGuid.PcdCoreCount\r