]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Drivers/ArmGic/ArmGicCommonDxe.c
ArmPkg: Tidy GIC code before changes.
[mirror_edk2.git] / ArmPkg / Drivers / ArmGic / ArmGicCommonDxe.c
CommitLineData
69b5dc9f
OM
1/*++\r
2\r
b0393756 3Copyright (c) 2013-2017, ARM Ltd. All rights reserved.<BR>\r
69b5dc9f
OM
4\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13--*/\r
14\r
15#include "ArmGicDxe.h"\r
16\r
17VOID\r
18EFIAPI\r
19IrqInterruptHandler (\r
20 IN EFI_EXCEPTION_TYPE InterruptType,\r
21 IN EFI_SYSTEM_CONTEXT SystemContext\r
22 );\r
23\r
24VOID\r
25EFIAPI\r
26ExitBootServicesEvent (\r
27 IN EFI_EVENT Event,\r
28 IN VOID *Context\r
29 );\r
30\r
69b5dc9f 31// Making this global saves a few bytes in image size\r
69b5dc9f
OM
32EFI_HANDLE gHardwareInterruptHandle = NULL;\r
33\r
69b5dc9f 34// Notifications\r
69b5dc9f
OM
35EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;\r
36\r
37// Maximum Number of Interrupts\r
38UINTN mGicNumInterrupts = 0;\r
39\r
40HARDWARE_INTERRUPT_HANDLER *gRegisteredInterruptHandlers = NULL;\r
41\r
0458b423
OM
42/**\r
43 Register Handler for the specified interrupt source.\r
44\r
45 @param This Instance pointer for this protocol\r
46 @param Source Hardware source of the interrupt\r
47 @param Handler Callback for interrupt. NULL to unregister\r
48\r
49 @retval EFI_SUCCESS Source was updated to support Handler.\r
50 @retval EFI_DEVICE_ERROR Hardware could not be programmed.\r
51\r
52**/\r
53EFI_STATUS\r
54EFIAPI\r
55RegisterInterruptSource (\r
56 IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This,\r
57 IN HARDWARE_INTERRUPT_SOURCE Source,\r
58 IN HARDWARE_INTERRUPT_HANDLER Handler\r
59 )\r
60{\r
599f004b 61 if (Source >= mGicNumInterrupts) {\r
0458b423
OM
62 ASSERT(FALSE);\r
63 return EFI_UNSUPPORTED;\r
64 }\r
65\r
66 if ((Handler == NULL) && (gRegisteredInterruptHandlers[Source] == NULL)) {\r
67 return EFI_INVALID_PARAMETER;\r
68 }\r
69\r
70 if ((Handler != NULL) && (gRegisteredInterruptHandlers[Source] != NULL)) {\r
71 return EFI_ALREADY_STARTED;\r
72 }\r
73\r
74 gRegisteredInterruptHandlers[Source] = Handler;\r
75\r
76 // If the interrupt handler is unregistered then disable the interrupt\r
77 if (NULL == Handler){\r
78 return This->DisableInterruptSource (This, Source);\r
79 } else {\r
80 return This->EnableInterruptSource (This, Source);\r
81 }\r
82}\r
83\r
69b5dc9f
OM
84EFI_STATUS\r
85InstallAndRegisterInterruptService (\r
86 IN EFI_HARDWARE_INTERRUPT_PROTOCOL *InterruptProtocol,\r
87 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,\r
88 IN EFI_EVENT_NOTIFY ExitBootServicesEvent\r
89 )\r
90{\r
91 EFI_STATUS Status;\r
92 EFI_CPU_ARCH_PROTOCOL *Cpu;\r
b0393756
EL
93 CONST UINTN RihArraySize =\r
94 (sizeof(HARDWARE_INTERRUPT_HANDLER) * mGicNumInterrupts);\r
69b5dc9f
OM
95\r
96 // Initialize the array for the Interrupt Handlers\r
b0393756 97 gRegisteredInterruptHandlers = AllocateZeroPool (RihArraySize);\r
69b5dc9f
OM
98 if (gRegisteredInterruptHandlers == NULL) {\r
99 return EFI_OUT_OF_RESOURCES;\r
100 }\r
101\r
102 Status = gBS->InstallMultipleProtocolInterfaces (\r
103 &gHardwareInterruptHandle,\r
b0393756
EL
104 &gHardwareInterruptProtocolGuid,\r
105 InterruptProtocol,\r
69b5dc9f
OM
106 NULL\r
107 );\r
108 if (EFI_ERROR (Status)) {\r
109 return Status;\r
110 }\r
111\r
69b5dc9f 112 // Get the CPU protocol that this driver requires.\r
69b5dc9f
OM
113 Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);\r
114 if (EFI_ERROR (Status)) {\r
115 return Status;\r
116 }\r
117\r
69b5dc9f 118 // Unregister the default exception handler.\r
69b5dc9f
OM
119 Status = Cpu->RegisterInterruptHandler (Cpu, ARM_ARCH_EXCEPTION_IRQ, NULL);\r
120 if (EFI_ERROR (Status)) {\r
121 return Status;\r
122 }\r
123\r
69b5dc9f 124 // Register to receive interrupts\r
b0393756
EL
125 Status = Cpu->RegisterInterruptHandler (\r
126 Cpu,\r
127 ARM_ARCH_EXCEPTION_IRQ,\r
128 InterruptHandler\r
129 );\r
69b5dc9f
OM
130 if (EFI_ERROR (Status)) {\r
131 return Status;\r
132 }\r
133\r
134 // Register for an ExitBootServicesEvent\r
b0393756
EL
135 Status = gBS->CreateEvent (\r
136 EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
137 TPL_NOTIFY,\r
138 ExitBootServicesEvent,\r
139 NULL,\r
140 &EfiExitBootServicesEvent\r
141 );\r
69b5dc9f
OM
142\r
143 return Status;\r
144}\r