]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Drivers/ArmGic/ArmGicCommonDxe.c
ArmPkg/ArmGic: Move the installation and the registration to InstallAndRegisterInterr...
[mirror_edk2.git] / ArmPkg / Drivers / ArmGic / ArmGicCommonDxe.c
1 /*++
2
3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
4
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 --*/
14
15 #include "ArmGicDxe.h"
16
17 VOID
18 EFIAPI
19 IrqInterruptHandler (
20 IN EFI_EXCEPTION_TYPE InterruptType,
21 IN EFI_SYSTEM_CONTEXT SystemContext
22 );
23
24 VOID
25 EFIAPI
26 ExitBootServicesEvent (
27 IN EFI_EVENT Event,
28 IN VOID *Context
29 );
30
31 //
32 // Making this global saves a few bytes in image size
33 //
34 EFI_HANDLE gHardwareInterruptHandle = NULL;
35
36 //
37 // Notifications
38 //
39 EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;
40
41 // Maximum Number of Interrupts
42 UINTN mGicNumInterrupts = 0;
43
44 HARDWARE_INTERRUPT_HANDLER *gRegisteredInterruptHandlers = NULL;
45
46 EFI_STATUS
47 InstallAndRegisterInterruptService (
48 IN EFI_HARDWARE_INTERRUPT_PROTOCOL *InterruptProtocol,
49 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
50 IN EFI_EVENT_NOTIFY ExitBootServicesEvent
51 )
52 {
53 EFI_STATUS Status;
54 EFI_CPU_ARCH_PROTOCOL *Cpu;
55
56 // Initialize the array for the Interrupt Handlers
57 gRegisteredInterruptHandlers = (HARDWARE_INTERRUPT_HANDLER*)AllocateZeroPool (sizeof(HARDWARE_INTERRUPT_HANDLER) * mGicNumInterrupts);
58 if (gRegisteredInterruptHandlers == NULL) {
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 Status = gBS->InstallMultipleProtocolInterfaces (
63 &gHardwareInterruptHandle,
64 &gHardwareInterruptProtocolGuid, InterruptProtocol,
65 NULL
66 );
67 if (EFI_ERROR (Status)) {
68 return Status;
69 }
70
71 //
72 // Get the CPU protocol that this driver requires.
73 //
74 Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Cpu);
75 if (EFI_ERROR (Status)) {
76 return Status;
77 }
78
79 //
80 // Unregister the default exception handler.
81 //
82 Status = Cpu->RegisterInterruptHandler (Cpu, ARM_ARCH_EXCEPTION_IRQ, NULL);
83 if (EFI_ERROR (Status)) {
84 return Status;
85 }
86
87 //
88 // Register to receive interrupts
89 //
90 Status = Cpu->RegisterInterruptHandler (Cpu, ARM_ARCH_EXCEPTION_IRQ, InterruptHandler);
91 if (EFI_ERROR (Status)) {
92 return Status;
93 }
94
95 // Register for an ExitBootServicesEvent
96 Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
97
98 return Status;
99 }