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