]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/ArmGic/GicV2/ArmGicV2Dxe.c
ArmPkg: Tidy GIC code before changes.
[mirror_edk2.git] / ArmPkg / Drivers / ArmGic / GicV2 / ArmGicV2Dxe.c
index 743c534e04d9d8bc27002588e4303ceeca7c2494..3d5d034efbb1bf2e1e84841cab4175bc607845c2 100644 (file)
@@ -2,7 +2,7 @@
 \r
 Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR>\r
 Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>\r
-Portions copyright (c) 2011-2015, ARM Ltd. All rights reserved.<BR>\r
+Portions copyright (c) 2011-2017, ARM Ltd. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -22,8 +22,9 @@ Abstract:
 \r
 --*/\r
 \r
+#include <Library/ArmGicLib.h>\r
+\r
 #include "ArmGicDxe.h"\r
-#include "GicV2/ArmGicV2Lib.h"\r
 \r
 #define ARM_GIC_DEFAULT_PRIORITY  0x80\r
 \r
@@ -42,6 +43,7 @@ STATIC UINT32 mGicDistributorBase;
   @retval EFI_UNSUPPORTED   Source interrupt is not supported\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GicV2EnableInterruptSource (\r
@@ -49,7 +51,7 @@ GicV2EnableInterruptSource (
   IN HARDWARE_INTERRUPT_SOURCE          Source\r
   )\r
 {\r
-  if (Source > mGicNumInterrupts) {\r
+  if (Source >= mGicNumInterrupts) {\r
     ASSERT(FALSE);\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -69,6 +71,7 @@ GicV2EnableInterruptSource (
   @retval EFI_UNSUPPORTED   Source interrupt is not supported\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GicV2DisableInterruptSource (\r
@@ -76,7 +79,7 @@ GicV2DisableInterruptSource (
   IN HARDWARE_INTERRUPT_SOURCE          Source\r
   )\r
 {\r
-  if (Source > mGicNumInterrupts) {\r
+  if (Source >= mGicNumInterrupts) {\r
     ASSERT(FALSE);\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -97,6 +100,7 @@ GicV2DisableInterruptSource (
   @retval EFI_UNSUPPORTED   Source interrupt is not supported\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GicV2GetInterruptSourceState (\r
@@ -105,7 +109,7 @@ GicV2GetInterruptSourceState (
   IN BOOLEAN                            *InterruptState\r
   )\r
 {\r
-  if (Source > mGicNumInterrupts) {\r
+  if (Source >= mGicNumInterrupts) {\r
     ASSERT(FALSE);\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -126,6 +130,7 @@ GicV2GetInterruptSourceState (
   @retval EFI_UNSUPPORTED   Source interrupt is not supported\r
 \r
 **/\r
+STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GicV2EndOfInterrupt (\r
@@ -133,7 +138,7 @@ GicV2EndOfInterrupt (
   IN HARDWARE_INTERRUPT_SOURCE          Source\r
   )\r
 {\r
-  if (Source > mGicNumInterrupts) {\r
+  if (Source >= mGicNumInterrupts) {\r
     ASSERT(FALSE);\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -146,13 +151,15 @@ GicV2EndOfInterrupt (
   EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.\r
 \r
   @param  InterruptType    Defines the type of interrupt or exception that\r
-                           occurred on the processor.This parameter is processor architecture specific.\r
+                           occurred on the processor.This parameter is\r
+                           processor architecture specific.\r
   @param  SystemContext    A pointer to the processor context when\r
                            the interrupt occurred on the processor.\r
 \r
   @return None\r
 \r
 **/\r
+STATIC\r
 VOID\r
 EFIAPI\r
 GicV2IrqInterruptHandler (\r
@@ -165,9 +172,10 @@ GicV2IrqInterruptHandler (
 \r
   GicInterrupt = ArmGicV2AcknowledgeInterrupt (mGicInterruptInterfaceBase);\r
 \r
-  // Special Interrupts (ID1020-ID1023) have an Interrupt ID greater than the number of interrupt (ie: Spurious interrupt).\r
+  // Special Interrupts (ID1020-ID1023) have an Interrupt ID greater than the\r
+  // number of interrupt (ie: Spurious interrupt).\r
   if ((GicInterrupt & ARM_GIC_ICCIAR_ACKINTID) >= mGicNumInterrupts) {\r
-    // The special interrupt do not need to be acknowledge\r
+    // The special interrupts do not need to be acknowledged\r
     return;\r
   }\r
 \r
@@ -176,15 +184,12 @@ GicV2IrqInterruptHandler (
     // Call the registered interrupt handler.\r
     InterruptHandler (GicInterrupt, SystemContext);\r
   } else {\r
-    DEBUG ((EFI_D_ERROR, "Spurious GIC interrupt: 0x%x\n", GicInterrupt));\r
+    DEBUG ((DEBUG_ERROR, "Spurious GIC interrupt: 0x%x\n", GicInterrupt));\r
+    GicV2EndOfInterrupt (&gHardwareInterruptV2Protocol, GicInterrupt);\r
   }\r
-\r
-  GicV2EndOfInterrupt (&gHardwareInterruptV2Protocol, GicInterrupt);\r
 }\r
 \r
-//\r
 // The protocol instance produced by this driver\r
-//\r
 EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptV2Protocol = {\r
   RegisterInterruptSource,\r
   GicV2EnableInterruptSource,\r
@@ -196,12 +201,13 @@ EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptV2Protocol = {
 /**\r
   Shutdown our hardware\r
 \r
-  DXE Core will disable interrupts and turn off the timer and disable interrupts\r
-  after all the event handlers have run.\r
+  DXE Core will disable interrupts and turn off the timer and disable\r
+  interrupts after all the event handlers have run.\r
 \r
   @param[in]  Event   The Event that is being processed\r
   @param[in]  Context Event Context\r
 **/\r
+STATIC\r
 VOID\r
 EFIAPI\r
 GicV2ExitBootServicesEvent (\r
@@ -256,11 +262,12 @@ GicV2DxeInitialize (
   UINTN                   RegShift;\r
   UINT32                  CpuTarget;\r
 \r
-  // Make sure the Interrupt Controller Protocol is not already installed in the system.\r
+  // Make sure the Interrupt Controller Protocol is not already installed in\r
+  // the system.\r
   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gHardwareInterruptProtocolGuid);\r
 \r
-  mGicInterruptInterfaceBase = PcdGet32 (PcdGicInterruptInterfaceBase);\r
-  mGicDistributorBase = PcdGet32 (PcdGicDistributorBase);\r
+  mGicInterruptInterfaceBase = PcdGet64 (PcdGicInterruptInterfaceBase);\r
+  mGicDistributorBase = PcdGet64 (PcdGicDistributorBase);\r
   mGicNumInterrupts = ArmGicGetMaxNumInterrupts (mGicDistributorBase);\r
 \r
   for (Index = 0; Index < mGicNumInterrupts; Index++) {\r
@@ -276,25 +283,27 @@ GicV2DxeInitialize (
       );\r
   }\r
 \r
-  //\r
   // Targets the interrupts to the Primary Cpu\r
-  //\r
-\r
-  // Only Primary CPU will run this code. We can identify our GIC CPU ID by reading\r
-  // the GIC Distributor Target register. The 8 first GICD_ITARGETSRn are banked to each\r
-  // connected CPU. These 8 registers hold the CPU targets fields for interrupts 0-31.\r
-  // More Info in the GIC Specification about "Interrupt Processor Targets Registers"\r
-  //\r
-  // Read the first Interrupt Processor Targets Register (that corresponds to the 4\r
-  // first SGIs)\r
+\r
+  // Only Primary CPU will run this code. We can identify our GIC CPU ID by\r
+  // reading the GIC Distributor Target register. The 8 first GICD_ITARGETSRn\r
+  // are banked to each connected CPU. These 8 registers hold the CPU targets\r
+  // fields for interrupts 0-31. More Info in the GIC Specification about\r
+  // "Interrupt Processor Targets Registers"\r
+\r
+  // Read the first Interrupt Processor Targets Register (that corresponds to\r
+  // the 4 first SGIs)\r
   CpuTarget = MmioRead32 (mGicDistributorBase + ARM_GIC_ICDIPTR);\r
 \r
-  // The CPU target is a bit field mapping each CPU to a GIC CPU Interface. This value\r
-  // is 0 when we run on a uniprocessor platform.\r
+  // The CPU target is a bit field mapping each CPU to a GIC CPU Interface.\r
+  // This value is 0 when we run on a uniprocessor platform.\r
   if (CpuTarget != 0) {\r
     // The 8 first Interrupt Processor Targets Registers are read-only\r
     for (Index = 8; Index < (mGicNumInterrupts / 4); Index++) {\r
-      MmioWrite32 (mGicDistributorBase + ARM_GIC_ICDIPTR + (Index * 4), CpuTarget);\r
+      MmioWrite32 (\r
+        mGicDistributorBase + ARM_GIC_ICDIPTR + (Index * 4),\r
+        CpuTarget\r
+        );\r
     }\r
   }\r
 \r
@@ -311,7 +320,10 @@ GicV2DxeInitialize (
   ArmGicEnableDistributor (mGicDistributorBase);\r
 \r
   Status = InstallAndRegisterInterruptService (\r
-          &gHardwareInterruptV2Protocol, GicV2IrqInterruptHandler, GicV2ExitBootServicesEvent);\r
+             &gHardwareInterruptV2Protocol,\r
+             GicV2IrqInterruptHandler,\r
+             GicV2ExitBootServicesEvent\r
+             );\r
 \r
   return Status;\r
 }\r