2 Handle OMAP35xx interrupt controller
4 Copyright (c) 2008-2010, Apple Inc. All rights reserved.
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/UefiLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/IoLib.h>
24 #include <Library/ArmLib.h>
26 #include <Protocol/Cpu.h>
27 #include <Protocol/HardwareInterrupt.h>
29 #include <Omap3530/Omap3530.h>
34 VOID
*CpuProtocolNotificationToken
= NULL
;
35 EFI_EVENT CpuProtocolNotificationEvent
= (EFI_EVENT
)NULL
;
36 EFI_EVENT EfiExitBootServicesEvent
= (EFI_EVENT
)NULL
;
39 HARDWARE_INTERRUPT_HANDLER gRegisteredInterruptHandlers
[INT_NROF_VECTORS
];
44 DXE Core will disable interrupts and turn off the timer and disable interrupts
45 after all the event handlers have run.
47 @param[in] Event The Event that is being processed
48 @param[in] Context Event Context
52 ExitBootServicesEvent (
57 // Disable all interrupts
58 MmioWrite32 (INTCPS_MIR(0), 0xFFFFFFFF);
59 MmioWrite32 (INTCPS_MIR(1), 0xFFFFFFFF);
60 MmioWrite32 (INTCPS_MIR(2), 0xFFFFFFFF);
61 MmioWrite32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWIRQAGR
);
63 // Add code here to disable all FIQs as debugger may have turned one on
67 Register Handler for the specified interrupt source.
69 @param This Instance pointer for this protocol
70 @param Source Hardware source of the interrupt
71 @param Handler Callback for interrupt. NULL to unregister
73 @retval EFI_SUCCESS Source was updated to support Handler.
74 @retval EFI_DEVICE_ERROR Hardware could not be programmed.
79 RegisterInterruptSource (
80 IN EFI_HARDWARE_INTERRUPT_PROTOCOL
*This
,
81 IN HARDWARE_INTERRUPT_SOURCE Source
,
82 IN HARDWARE_INTERRUPT_HANDLER Handler
85 if (Source
> MAX_VECTOR
) {
87 return EFI_UNSUPPORTED
;
90 if ((Handler
== NULL
) && (gRegisteredInterruptHandlers
[Source
] == NULL
)) {
91 return EFI_INVALID_PARAMETER
;
94 if ((Handler
!= NULL
) && (gRegisteredInterruptHandlers
[Source
] != NULL
)) {
95 return EFI_ALREADY_STARTED
;
98 gRegisteredInterruptHandlers
[Source
] = Handler
;
99 return This
->EnableInterruptSource(This
, Source
);
104 Enable interrupt source Source.
106 @param This Instance pointer for this protocol
107 @param Source Hardware source of the interrupt
109 @retval EFI_SUCCESS Source interrupt enabled.
110 @retval EFI_DEVICE_ERROR Hardware could not be programmed.
115 EnableInterruptSource (
116 IN EFI_HARDWARE_INTERRUPT_PROTOCOL
*This
,
117 IN HARDWARE_INTERRUPT_SOURCE Source
123 if (Source
> MAX_VECTOR
) {
125 return EFI_UNSUPPORTED
;
129 Bit
= 1UL << (Source
% 32);
131 MmioWrite32 (INTCPS_MIR_CLEAR(Bank
), Bit
);
138 Disable interrupt source Source.
140 @param This Instance pointer for this protocol
141 @param Source Hardware source of the interrupt
143 @retval EFI_SUCCESS Source interrupt disabled.
144 @retval EFI_DEVICE_ERROR Hardware could not be programmed.
149 DisableInterruptSource (
150 IN EFI_HARDWARE_INTERRUPT_PROTOCOL
*This
,
151 IN HARDWARE_INTERRUPT_SOURCE Source
157 if (Source
> MAX_VECTOR
) {
159 return EFI_UNSUPPORTED
;
163 Bit
= 1UL << (Source
% 32);
165 MmioWrite32 (INTCPS_MIR_SET(Bank
), Bit
);
173 Return current state of interrupt source Source.
175 @param This Instance pointer for this protocol
176 @param Source Hardware source of the interrupt
177 @param InterruptState TRUE: source enabled, FALSE: source disabled.
179 @retval EFI_SUCCESS InterruptState is valid
180 @retval EFI_DEVICE_ERROR InterruptState is not valid
185 GetInterruptSourceState (
186 IN EFI_HARDWARE_INTERRUPT_PROTOCOL
*This
,
187 IN HARDWARE_INTERRUPT_SOURCE Source
,
188 IN BOOLEAN
*InterruptState
194 if (InterruptState
== NULL
) {
195 return EFI_INVALID_PARAMETER
;
198 if (Source
> MAX_VECTOR
) {
200 return EFI_UNSUPPORTED
;
204 Bit
= 1UL << (Source
% 32);
206 if ((MmioRead32 (INTCPS_MIR(Bank
)) & Bit
) == Bit
) {
207 *InterruptState
= FALSE
;
209 *InterruptState
= TRUE
;
216 Signal to the hardware that the End Of Intrrupt state
219 @param This Instance pointer for this protocol
220 @param Source Hardware source of the interrupt
222 @retval EFI_SUCCESS Source interrupt EOI'ed.
223 @retval EFI_DEVICE_ERROR Hardware could not be programmed.
229 IN EFI_HARDWARE_INTERRUPT_PROTOCOL
*This
,
230 IN HARDWARE_INTERRUPT_SOURCE Source
233 MmioWrite32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWIRQAGR
);
234 ArmDataSyncronizationBarrier ();
240 EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs.
242 @param InterruptType Defines the type of interrupt or exception that
243 occurred on the processor.This parameter is processor architecture specific.
244 @param SystemContext A pointer to the processor context when
245 the interrupt occurred on the processor.
252 IrqInterruptHandler (
253 IN EFI_EXCEPTION_TYPE InterruptType
,
254 IN EFI_SYSTEM_CONTEXT SystemContext
258 HARDWARE_INTERRUPT_HANDLER InterruptHandler
;
260 Vector
= MmioRead32 (INTCPS_SIR_IRQ
) & INTCPS_SIR_IRQ_MASK
;
262 // Needed to prevent infinite nesting when Time Driver lowers TPL
263 MmioWrite32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWIRQAGR
);
264 ArmDataSyncronizationBarrier ();
266 InterruptHandler
= gRegisteredInterruptHandlers
[Vector
];
267 if (InterruptHandler
!= NULL
) {
268 // Call the registered interrupt handler.
269 InterruptHandler (Vector
, SystemContext
);
272 // Needed to clear after running the handler
273 MmioWrite32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWIRQAGR
);
274 ArmDataSyncronizationBarrier ();
278 // Making this global saves a few bytes in image size
280 EFI_HANDLE gHardwareInterruptHandle
= NULL
;
283 // The protocol instance produced by this driver
285 EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol
= {
286 RegisterInterruptSource
,
287 EnableInterruptSource
,
288 DisableInterruptSource
,
289 GetInterruptSourceState
,
294 // Notification routines
297 CpuProtocolInstalledNotification (
303 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
306 // Get the cpu protocol that this driver requires.
308 Status
= gBS
->LocateProtocol (&gEfiCpuArchProtocolGuid
, NULL
, (VOID
**)&Cpu
);
309 ASSERT_EFI_ERROR(Status
);
312 // Unregister the default exception handler.
314 Status
= Cpu
->RegisterInterruptHandler (Cpu
, EXCEPT_ARM_IRQ
, NULL
);
315 ASSERT_EFI_ERROR(Status
);
318 // Register to receive interrupts
320 Status
= Cpu
->RegisterInterruptHandler (Cpu
, EXCEPT_ARM_IRQ
, IrqInterruptHandler
);
321 ASSERT_EFI_ERROR(Status
);
325 Initialize the state information for the CPU Architectural Protocol
327 @param ImageHandle of the loaded driver
328 @param SystemTable Pointer to the System Table
330 @retval EFI_SUCCESS Protocol registered
331 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
332 @retval EFI_DEVICE_ERROR Hardware problems
336 InterruptDxeInitialize (
337 IN EFI_HANDLE ImageHandle
,
338 IN EFI_SYSTEM_TABLE
*SystemTable
343 // Make sure the Interrupt Controller Protocol is not already installed in the system.
344 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gHardwareInterruptProtocolGuid
);
346 // Make sure all interrupts are disabled by default.
347 MmioWrite32 (INTCPS_MIR(0), 0xFFFFFFFF);
348 MmioWrite32 (INTCPS_MIR(1), 0xFFFFFFFF);
349 MmioWrite32 (INTCPS_MIR(2), 0xFFFFFFFF);
350 MmioOr32 (INTCPS_CONTROL
, INTCPS_CONTROL_NEWIRQAGR
);
352 Status
= gBS
->InstallMultipleProtocolInterfaces(&gHardwareInterruptHandle
,
353 &gHardwareInterruptProtocolGuid
, &gHardwareInterruptProtocol
,
355 ASSERT_EFI_ERROR(Status
);
357 // Set up to be notified when the Cpu protocol is installed.
358 Status
= gBS
->CreateEvent(EVT_NOTIFY_SIGNAL
, TPL_CALLBACK
, CpuProtocolInstalledNotification
, NULL
, &CpuProtocolNotificationEvent
);
359 ASSERT_EFI_ERROR(Status
);
361 Status
= gBS
->RegisterProtocolNotify(&gEfiCpuArchProtocolGuid
, CpuProtocolNotificationEvent
, (VOID
*)&CpuProtocolNotificationToken
);
362 ASSERT_EFI_ERROR(Status
);
364 // Register for an ExitBootServicesEvent
365 Status
= gBS
->CreateEvent(EVT_SIGNAL_EXIT_BOOT_SERVICES
, TPL_NOTIFY
, ExitBootServicesEvent
, NULL
, &EfiExitBootServicesEvent
);
366 ASSERT_EFI_ERROR(Status
);