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