1 /** @file
2 Top level C file for debug support driver. Contains initialization function.
3
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
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 "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 EFIAPI
InitializeDebugSupportDriver(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)42 InitializeDebugSupportDriver (
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46 {
47 EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;
48 EFI_STATUS Status;
49 EFI_HANDLE Handle;
50 EFI_HANDLE *HandlePtr;
51 UINTN NumHandles;
52 EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;
53
54 //
55 // First check to see that the debug support protocol for this processor
56 // type is not already installed
57 //
58 Status = gBS->LocateHandleBuffer (
59 ByProtocol,
60 &gEfiDebugSupportProtocolGuid,
61 NULL,
62 &NumHandles,
63 &HandlePtr
64 );
65
66 if (Status != EFI_NOT_FOUND) {
67 do {
68 NumHandles--;
69 Status = gBS->OpenProtocol (
70 HandlePtr[NumHandles],
71 &gEfiDebugSupportProtocolGuid,
72 (VOID **) &DebugSupportProtocolPtr,
73 ImageHandle,
74 NULL,
75 EFI_OPEN_PROTOCOL_GET_PROTOCOL
76 );
77 if ((Status == EFI_SUCCESS) && (DebugSupportProtocolPtr->Isa == EFI_ISA)) {
78 //
79 // a Debug Support protocol has been installed for this processor
80 //
81 FreePool (HandlePtr);
82 Status = EFI_ALREADY_STARTED;
83 goto ErrExit;
84 }
85 } while (NumHandles > 0);
86 FreePool (HandlePtr);
87 }
88
89 //
90 // Get our image information and install platform specific unload handler
91 //
92 Status = gBS->OpenProtocol (
93 ImageHandle,
94 &gEfiLoadedImageProtocolGuid,
95 (VOID **) &LoadedImageProtocolPtr,
96 ImageHandle,
97 NULL,
98 EFI_OPEN_PROTOCOL_GET_PROTOCOL
99 );
100 ASSERT (!EFI_ERROR (Status));
101 if (Status != EFI_SUCCESS) {
102 goto ErrExit;
103 }
104
105 LoadedImageProtocolPtr->Unload = PlUnloadDebugSupportDriver;
106
107 //
108 // Call hook for processor specific initialization
109 //
110 Status = PlInitializeDebugSupportDriver ();
111 ASSERT (!EFI_ERROR (Status));
112 if (Status != EFI_SUCCESS) {
113 goto ErrExit;
114 }
115
116 //
117 // Install Debug Support protocol to new handle
118 //
119 Handle = NULL;
120 Status = gBS->InstallProtocolInterface (
121 &Handle,
122 &gEfiDebugSupportProtocolGuid,
123 EFI_NATIVE_INTERFACE,
124 &mDebugSupportProtocolInterface
125 );
126 ASSERT (!EFI_ERROR (Status));
127 if (Status != EFI_SUCCESS) {
128 goto ErrExit;
129 }
130
131 ErrExit:
132 return Status;
133 }
134