]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DebugSupportDxe/DebugSupport.c
ECC clean up.
[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 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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 //
16 // private header files
17 //
18 #include "PlDebugSupport.h"
19
20 //
21 // This is a global that is the actual interface
22 //
23 EFI_DEBUG_SUPPORT_PROTOCOL gDebugSupportProtocolInterface = {
24 EFI_ISA,
25 GetMaximumProcessorIndex,
26 RegisterPeriodicCallback,
27 RegisterExceptionCallback,
28 InvalidateInstructionCache
29 };
30
31
32 /**
33 Debug Port Driver entry point.
34
35 Checks to see there's not already a DebugSupport protocol installed for
36 the selected processor before installing protocol.
37
38 @param[in] ImageHandle The firmware allocated handle for the EFI image.
39 @param[in] SystemTable A pointer to the EFI System Table.
40
41 @retval EFI_SUCCESS The entry point is executed successfully.
42 @retval EFI_ALREADY_STARTED DebugSupport protocol is installed already.
43 @retval other Some error occurs when executing this entry point.
44
45 **/
46 EFI_STATUS
47 InitializeDebugSupportDriver (
48 IN EFI_HANDLE ImageHandle,
49 IN EFI_SYSTEM_TABLE *SystemTable
50 )
51 {
52 EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;
53 EFI_STATUS Status;
54 EFI_HANDLE Handle;
55 EFI_HANDLE *HandlePtr;
56 UINTN NumHandles;
57 EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;
58
59 //
60 // Install Protocol Interface...
61 //
62 // First check to see that the debug support protocol for this processor
63 // type is not already installed
64 //
65 Status = gBS->LocateHandleBuffer (
66 ByProtocol,
67 &gEfiDebugSupportProtocolGuid,
68 NULL,
69 &NumHandles,
70 &HandlePtr
71 );
72
73 if (Status != EFI_NOT_FOUND) {
74 do {
75 NumHandles--;
76 Status = gBS->OpenProtocol (
77 HandlePtr[NumHandles],
78 &gEfiDebugSupportProtocolGuid,
79 (VOID **) &DebugSupportProtocolPtr,
80 ImageHandle,
81 NULL,
82 EFI_OPEN_PROTOCOL_GET_PROTOCOL
83 );
84 if (Status == EFI_SUCCESS && DebugSupportProtocolPtr->Isa == EFI_ISA) {
85 FreePool (HandlePtr);
86 Status = EFI_ALREADY_STARTED;
87 goto ErrExit;
88 }
89 } while (NumHandles > 0);
90 FreePool (HandlePtr);
91 }
92
93 //
94 // Get our image information and install platform specific unload handler
95 //
96 Status = gBS->OpenProtocol (
97 ImageHandle,
98 &gEfiLoadedImageProtocolGuid,
99 (VOID **) &LoadedImageProtocolPtr,
100 ImageHandle,
101 NULL,
102 EFI_OPEN_PROTOCOL_GET_PROTOCOL
103 );
104 ASSERT (!EFI_ERROR (Status));
105 if (Status != EFI_SUCCESS) {
106 goto ErrExit;
107 }
108
109 LoadedImageProtocolPtr->Unload = PlUnloadDebugSupportDriver;
110
111 //
112 // Call hook for platform specific initialization
113 //
114 Status = PlInitializeDebugSupportDriver ();
115 ASSERT (!EFI_ERROR (Status));
116 if (Status != EFI_SUCCESS) {
117 goto ErrExit;
118 }
119
120 //
121 // Install DebugSupport protocol to new handle
122 //
123 Handle = NULL;
124 Status = gBS->InstallProtocolInterface (
125 &Handle,
126 &gEfiDebugSupportProtocolGuid,
127 EFI_NATIVE_INTERFACE,
128 &gDebugSupportProtocolInterface
129 );
130 ASSERT (!EFI_ERROR (Status));
131 if (Status != EFI_SUCCESS) {
132 goto ErrExit;
133 }
134
135 ErrExit:
136 return Status;
137 }