ArmPkg: only attempt buildin MmCommunicationDxe for AArch64
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / DebugSupport.c
1 /** @file
2 Top level C file for debug support driver. Contains initialization function.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PlDebugSupport.h"
10
11 EFI_DEBUG_SUPPORT_PROTOCOL mDebugSupportProtocolInterface = {
12 EFI_ISA,
13 GetMaximumProcessorIndex,
14 RegisterPeriodicCallback,
15 RegisterExceptionCallback,
16 InvalidateInstructionCache
17 };
18
19
20 /**
21 Debug Support Driver entry point.
22
23 Checks to see if there's not already a Debug Support protocol installed for
24 the selected processor before installing it.
25
26 @param[in] ImageHandle The firmware allocated handle for the EFI image.
27 @param[in] SystemTable A pointer to the EFI System Table.
28
29 @retval EFI_SUCCESS The entry point is executed successfully.
30 @retval EFI_ALREADY_STARTED Debug Support protocol is installed already.
31 @retval other Some error occurs when executing this entry point.
32
33 **/
34 EFI_STATUS
35 EFIAPI
36 InitializeDebugSupportDriver (
37 IN EFI_HANDLE ImageHandle,
38 IN EFI_SYSTEM_TABLE *SystemTable
39 )
40 {
41 EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;
42 EFI_STATUS Status;
43 EFI_HANDLE Handle;
44 EFI_HANDLE *HandlePtr;
45 UINTN NumHandles;
46 EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;
47
48 //
49 // First check to see that the debug support protocol for this processor
50 // type is not already installed
51 //
52 Status = gBS->LocateHandleBuffer (
53 ByProtocol,
54 &gEfiDebugSupportProtocolGuid,
55 NULL,
56 &NumHandles,
57 &HandlePtr
58 );
59
60 if (Status != EFI_NOT_FOUND) {
61 do {
62 NumHandles--;
63 Status = gBS->OpenProtocol (
64 HandlePtr[NumHandles],
65 &gEfiDebugSupportProtocolGuid,
66 (VOID **) &DebugSupportProtocolPtr,
67 ImageHandle,
68 NULL,
69 EFI_OPEN_PROTOCOL_GET_PROTOCOL
70 );
71 if ((Status == EFI_SUCCESS) && (DebugSupportProtocolPtr->Isa == EFI_ISA)) {
72 //
73 // a Debug Support protocol has been installed for this processor
74 //
75 FreePool (HandlePtr);
76 Status = EFI_ALREADY_STARTED;
77 goto ErrExit;
78 }
79 } while (NumHandles > 0);
80 FreePool (HandlePtr);
81 }
82
83 //
84 // Get our image information and install platform specific unload handler
85 //
86 Status = gBS->OpenProtocol (
87 ImageHandle,
88 &gEfiLoadedImageProtocolGuid,
89 (VOID **) &LoadedImageProtocolPtr,
90 ImageHandle,
91 NULL,
92 EFI_OPEN_PROTOCOL_GET_PROTOCOL
93 );
94 ASSERT (!EFI_ERROR (Status));
95 if (Status != EFI_SUCCESS) {
96 goto ErrExit;
97 }
98
99 LoadedImageProtocolPtr->Unload = PlUnloadDebugSupportDriver;
100
101 //
102 // Call hook for processor specific initialization
103 //
104 Status = PlInitializeDebugSupportDriver ();
105 ASSERT (!EFI_ERROR (Status));
106 if (Status != EFI_SUCCESS) {
107 goto ErrExit;
108 }
109
110 //
111 // Install Debug Support protocol to new handle
112 //
113 Handle = NULL;
114 Status = gBS->InstallProtocolInterface (
115 &Handle,
116 &gEfiDebugSupportProtocolGuid,
117 EFI_NATIVE_INTERFACE,
118 &mDebugSupportProtocolInterface
119 );
120 ASSERT (!EFI_ERROR (Status));
121 if (Status != EFI_SUCCESS) {
122 goto ErrExit;
123 }
124
125 ErrExit:
126 return Status;
127 }