]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DebugSupportDxe/DebugSupport.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 Debug Support Driver entry point.
21
22 Checks to see if there's not already a Debug Support protocol installed for
23 the selected processor before installing it.
24
25 @param[in] ImageHandle The firmware allocated handle for the EFI image.
26 @param[in] SystemTable A pointer to the EFI System Table.
27
28 @retval EFI_SUCCESS The entry point is executed successfully.
29 @retval EFI_ALREADY_STARTED Debug Support protocol is installed already.
30 @retval other Some error occurs when executing this entry point.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 InitializeDebugSupportDriver (
36 IN EFI_HANDLE ImageHandle,
37 IN EFI_SYSTEM_TABLE *SystemTable
38 )
39 {
40 EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;
41 EFI_STATUS Status;
42 EFI_HANDLE Handle;
43 EFI_HANDLE *HandlePtr;
44 UINTN NumHandles;
45 EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;
46
47 //
48 // First check to see that the debug support protocol for this processor
49 // type is not already installed
50 //
51 Status = gBS->LocateHandleBuffer (
52 ByProtocol,
53 &gEfiDebugSupportProtocolGuid,
54 NULL,
55 &NumHandles,
56 &HandlePtr
57 );
58
59 if (Status != EFI_NOT_FOUND) {
60 do {
61 NumHandles--;
62 Status = gBS->OpenProtocol (
63 HandlePtr[NumHandles],
64 &gEfiDebugSupportProtocolGuid,
65 (VOID **)&DebugSupportProtocolPtr,
66 ImageHandle,
67 NULL,
68 EFI_OPEN_PROTOCOL_GET_PROTOCOL
69 );
70 if ((Status == EFI_SUCCESS) && (DebugSupportProtocolPtr->Isa == EFI_ISA)) {
71 //
72 // a Debug Support protocol has been installed for this processor
73 //
74 FreePool (HandlePtr);
75 Status = EFI_ALREADY_STARTED;
76 goto ErrExit;
77 }
78 } while (NumHandles > 0);
79
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 }