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