X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Omap35xxPkg%2FInterruptDxe%2FHardwareInterrupt.c;h=2ddc7c0566d090162b011703c29e60b5d0862e3e;hp=6e30eb7e67e1f7a14e3e3b06af7f0312c5f457ea;hb=f33d5d68abc02727dc828c1079e72ab65e1d63af;hpb=026e30c4bb80a73ac7c5c286711ae07b1c51108b diff --git a/Omap35xxPkg/InterruptDxe/HardwareInterrupt.c b/Omap35xxPkg/InterruptDxe/HardwareInterrupt.c index 6e30eb7e67..2ddc7c0566 100644 --- a/Omap35xxPkg/InterruptDxe/HardwareInterrupt.c +++ b/Omap35xxPkg/InterruptDxe/HardwareInterrupt.c @@ -1,9 +1,9 @@ /** @file - Template for Metronome Architecture Protocol driver of the ARM flavor + Handle OMAP35xx interrupt controller - Copyright (c) 2008-2009, Apple Inc. All rights reserved. - - All rights reserved. This program and the accompanying materials + Copyright (c) 2008 - 2010, Apple Inc. 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 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -30,8 +31,6 @@ // // Notifications // -VOID *CpuProtocolNotificationToken = NULL; -EFI_EVENT CpuProtocolNotificationEvent = (EFI_EVENT)NULL; EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL; @@ -39,7 +38,7 @@ HARDWARE_INTERRUPT_HANDLER gRegisteredInterruptHandlers[INT_NROF_VECTORS]; /** Shutdown our hardware - + DXE Core will disable interrupts and turn off the timer and disable interrupts after all the event handlers have run. @@ -58,6 +57,8 @@ ExitBootServicesEvent ( MmioWrite32 (INTCPS_MIR(1), 0xFFFFFFFF); MmioWrite32 (INTCPS_MIR(2), 0xFFFFFFFF); MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR); + + // Add code here to disable all FIQs as debugger may have turned one on } /** @@ -82,8 +83,16 @@ RegisterInterruptSource ( if (Source > MAX_VECTOR) { ASSERT(FALSE); return EFI_UNSUPPORTED; - } - + } + + if ((MmioRead32 (INTCPS_ILR(Source)) & INTCPS_ILR_FIQ) == INTCPS_ILR_FIQ) { + // This vector has been programmed as FIQ so we can't use it for IRQ + // EFI does not use FIQ, but the debugger can use it to check for + // ctrl-c. So this ASSERT means you have a conflict with the debug agent + ASSERT (FALSE); + return EFI_UNSUPPORTED; + } + if ((Handler == NULL) && (gRegisteredInterruptHandlers[Source] == NULL)) { return EFI_INVALID_PARAMETER; } @@ -116,17 +125,17 @@ EnableInterruptSource ( { UINTN Bank; UINTN Bit; - + if (Source > MAX_VECTOR) { ASSERT(FALSE); return EFI_UNSUPPORTED; } - + Bank = Source / 32; Bit = 1UL << (Source % 32); - + MmioWrite32 (INTCPS_MIR_CLEAR(Bank), Bit); - + return EFI_SUCCESS; } @@ -143,24 +152,24 @@ EnableInterruptSource ( **/ EFI_STATUS EFIAPI -DisableInterruptSource( +DisableInterruptSource ( IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source ) { UINTN Bank; UINTN Bit; - + if (Source > MAX_VECTOR) { ASSERT(FALSE); return EFI_UNSUPPORTED; } - + Bank = Source / 32; Bit = 1UL << (Source % 32); - + MmioWrite32 (INTCPS_MIR_SET(Bank), Bit); - + return EFI_SUCCESS; } @@ -187,11 +196,11 @@ GetInterruptSourceState ( { UINTN Bank; UINTN Bit; - + if (InterruptState == NULL) { return EFI_INVALID_PARAMETER; } - + if (Source > MAX_VECTOR) { ASSERT(FALSE); return EFI_UNSUPPORTED; @@ -199,16 +208,38 @@ GetInterruptSourceState ( Bank = Source / 32; Bit = 1UL << (Source % 32); - + if ((MmioRead32(INTCPS_MIR(Bank)) & Bit) == Bit) { *InterruptState = FALSE; } else { *InterruptState = TRUE; } - + return EFI_SUCCESS; } +/** + Signal to the hardware that the End Of Intrrupt state + has been reached. + + @param This Instance pointer for this protocol + @param Source Hardware source of the interrupt + + @retval EFI_SUCCESS Source interrupt EOI'ed. + @retval EFI_DEVICE_ERROR Hardware could not be programmed. + +**/ +EFI_STATUS +EFIAPI +EndOfInterrupt ( + IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This, + IN HARDWARE_INTERRUPT_SOURCE Source + ) +{ + MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR); + ArmDataSynchronizationBarrier (); + return EFI_SUCCESS; +} /** @@ -231,20 +262,22 @@ IrqInterruptHandler ( { UINT32 Vector; HARDWARE_INTERRUPT_HANDLER InterruptHandler; - - Vector = MmioRead32(INTCPS_SIR_IRQ) & INTCPS_SIR_IRQ_MASK; + + Vector = MmioRead32 (INTCPS_SIR_IRQ) & INTCPS_SIR_IRQ_MASK; // Needed to prevent infinite nesting when Time Driver lowers TPL MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR); + ArmDataSynchronizationBarrier (); InterruptHandler = gRegisteredInterruptHandlers[Vector]; if (InterruptHandler != NULL) { // Call the registered interrupt handler. - InterruptHandler(Vector, SystemContext); + InterruptHandler (Vector, SystemContext); } - + // Needed to clear after running the handler MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR); + ArmDataSynchronizationBarrier (); } // @@ -259,38 +292,56 @@ EFI_HARDWARE_INTERRUPT_PROTOCOL gHardwareInterruptProtocol = { RegisterInterruptSource, EnableInterruptSource, DisableInterruptSource, - GetInterruptSourceState + GetInterruptSourceState, + EndOfInterrupt }; -// -// Notification routines -// +STATIC VOID *mCpuArchProtocolNotifyEventRegistration; + +STATIC VOID -CpuProtocolInstalledNotification ( - IN EFI_EVENT Event, - IN VOID *Context +EFIAPI +CpuArchEventProtocolNotify ( + IN EFI_EVENT Event, + IN VOID *Context ) { - EFI_STATUS Status; EFI_CPU_ARCH_PROTOCOL *Cpu; - + EFI_STATUS Status; + // - // Get the cpu protocol that this driver requires. + // Get the CPU protocol that this driver requires. // - Status = gBS->LocateProtocol(&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu); - ASSERT_EFI_ERROR(Status); + Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: gBS->LocateProtocol() - %r\n", __FUNCTION__, + Status)); + ASSERT (FALSE); + return; + } // // Unregister the default exception handler. // - Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, NULL); - ASSERT_EFI_ERROR(Status); + Status = Cpu->RegisterInterruptHandler (Cpu, EXCEPT_ARM_IRQ, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Cpu->RegisterInterruptHandler() - %r\n", + __FUNCTION__, Status)); + ASSERT (FALSE); + return; + } // // Register to receive interrupts // - Status = Cpu->RegisterInterruptHandler(Cpu, EXCEPT_ARM_IRQ, IrqInterruptHandler); - ASSERT_EFI_ERROR(Status); + Status = Cpu->RegisterInterruptHandler (Cpu, EXCEPT_ARM_IRQ, + IrqInterruptHandler); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Cpu->RegisterInterruptHandler() - %r\n", + __FUNCTION__, Status)); + ASSERT (FALSE); + return; + } } /** @@ -311,6 +362,7 @@ InterruptDxeInitialize ( ) { EFI_STATUS Status; + EFI_EVENT CpuArchEvent; // Make sure the Interrupt Controller Protocol is not already installed in the system. ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gHardwareInterruptProtocolGuid); @@ -319,23 +371,31 @@ InterruptDxeInitialize ( MmioWrite32 (INTCPS_MIR(0), 0xFFFFFFFF); MmioWrite32 (INTCPS_MIR(1), 0xFFFFFFFF); MmioWrite32 (INTCPS_MIR(2), 0xFFFFFFFF); - MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR); - + MmioOr32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWIRQAGR); + Status = gBS->InstallMultipleProtocolInterfaces(&gHardwareInterruptHandle, &gHardwareInterruptProtocolGuid, &gHardwareInterruptProtocol, NULL); ASSERT_EFI_ERROR(Status); - - // Set up to be notified when the Cpu protocol is installed. - Status = gBS->CreateEvent(EVT_NOTIFY_SIGNAL, TPL_CALLBACK, CpuProtocolInstalledNotification, NULL, &CpuProtocolNotificationEvent); - ASSERT_EFI_ERROR(Status); - Status = gBS->RegisterProtocolNotify(&gEfiCpuArchProtocolGuid, CpuProtocolNotificationEvent, (VOID *)&CpuProtocolNotificationToken); - ASSERT_EFI_ERROR(Status); + // + // Install the interrupt handler as soon as the CPU arch protocol appears. + // + CpuArchEvent = EfiCreateProtocolNotifyEvent ( + &gEfiCpuArchProtocolGuid, + TPL_CALLBACK, + CpuArchEventProtocolNotify, + NULL, + &mCpuArchProtocolNotifyEventRegistration + ); + ASSERT (CpuArchEvent != NULL); // Register for an ExitBootServicesEvent Status = gBS->CreateEvent(EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + gBS->CloseEvent (CpuArchEvent); + } return Status; }