]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Code scrub for DxeCore
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeProtocolNotify.c
... / ...
CommitLineData
1/** @file\r
2 This file deals with Architecture Protocol (AP) registration in\r
3 the Dxe Core. The mArchProtocols[] array represents a list of\r
4 events that represent the Architectural Protocols.\r
5\r
6Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <DxeMain.h>\r
18\r
19\r
20//\r
21// DXE Core Global Variables for all of the Architectural Protocols.\r
22// If a protocol is installed mArchProtocols[].Present will be TRUE.\r
23//\r
24// CoreNotifyOnArchProtocolInstallation () fills in mArchProtocols[].Event\r
25// and mArchProtocols[].Registration as it creates events for every array\r
26// entry.\r
27//\r
28\r
29ARCHITECTURAL_PROTOCOL_ENTRY mArchProtocols[] = {\r
30 { &gEfiSecurityArchProtocolGuid, (VOID **)&gSecurity, NULL, NULL, FALSE },\r
31 { &gEfiCpuArchProtocolGuid, (VOID **)&gCpu, NULL, NULL, FALSE },\r
32 { &gEfiMetronomeArchProtocolGuid, (VOID **)&gMetronome, NULL, NULL, FALSE },\r
33 { &gEfiTimerArchProtocolGuid, (VOID **)&gTimer, NULL, NULL, FALSE },\r
34 { &gEfiBdsArchProtocolGuid, (VOID **)&gBds, NULL, NULL, FALSE },\r
35 { &gEfiWatchdogTimerArchProtocolGuid, (VOID **)&gWatchdogTimer, NULL, NULL, FALSE },\r
36 { &gEfiRuntimeArchProtocolGuid, (VOID **)&gRuntime, NULL, NULL, FALSE },\r
37 { &gEfiVariableArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
38 { &gEfiVariableWriteArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
39 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
40 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
41 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
42 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
43 { NULL, (VOID **)NULL, NULL, NULL, FALSE }\r
44};\r
45\r
46\r
47\r
48/**\r
49 Return TRUE if all AP services are availible.\r
50\r
51 @retval EFI_SUCCESS All AP services are available \r
52 @retval EFI_NOT_FOUND At least one AP service is not available\r
53\r
54**/\r
55EFI_STATUS\r
56CoreAllEfiServicesAvailable (\r
57 VOID\r
58 )\r
59{\r
60 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
61\r
62 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
63 if (!Entry->Present) {\r
64 return EFI_NOT_FOUND;\r
65 }\r
66 }\r
67\r
68 return EFI_SUCCESS;\r
69}\r
70\r
71\r
72/**\r
73 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().\r
74 This notify function is registered for every architectural protocol. This handler\r
75 updates mArchProtocol[] array entry with protocol instance data and sets it's\r
76 present flag to TRUE. If any constructor is required it is executed. The EFI\r
77 System Table headers are updated.\r
78\r
79 @param Event The Event that is being processed, not used. \r
80 @param Context Event Context, not used.\r
81\r
82**/\r
83VOID\r
84EFIAPI\r
85GenericArchProtocolNotify (\r
86 IN EFI_EVENT Event,\r
87 IN VOID *Context\r
88 )\r
89{\r
90 EFI_STATUS Status;\r
91 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
92 VOID *Protocol;\r
93 BOOLEAN Found;\r
94 LIST_ENTRY *Link;\r
95 LIST_ENTRY TempLinkNode;\r
96\r
97 Found = FALSE;\r
98 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
99\r
100 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);\r
101 if (EFI_ERROR (Status)) {\r
102 continue;\r
103 }\r
104\r
105 Found = TRUE;\r
106 Entry->Present = TRUE;\r
107\r
108 //\r
109 // Update protocol global variable if one exists. Entry->Protocol points to a global variable\r
110 // if one exists in the DXE core for this Architectural Protocol\r
111 //\r
112 if (Entry->Protocol != NULL) {\r
113 *(Entry->Protocol) = Protocol;\r
114 }\r
115\r
116 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {\r
117 //\r
118 // Register the Core timer tick handler with the Timer AP\r
119 //\r
120 gTimer->RegisterHandler (gTimer, CoreTimerTick);\r
121 }\r
122\r
123 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {\r
124 //\r
125 // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
126 //\r
127 CoreUpdateDebugTableCrc32 ();\r
128\r
129 //\r
130 // Update the Runtime Architectural protocol with the template that the core was\r
131 // using so there would not need to be a dependency on the Runtime AP\r
132 //\r
133\r
134 //\r
135 // Copy all the registered Image to new gRuntime protocol\r
136 //\r
137 for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {\r
138 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
139 InsertTailList (&gRuntime->ImageHead, Link);\r
140 }\r
141 //\r
142 // Copy all the registered Event to new gRuntime protocol\r
143 //\r
144 for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {\r
145 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
146 InsertTailList (&gRuntime->EventHead, Link);\r
147 }\r
148\r
149 //\r
150 // Clean up gRuntimeTemplate\r
151 //\r
152 gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;\r
153 gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;\r
154 gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;\r
155 gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;\r
156 }\r
157 }\r
158\r
159 //\r
160 // It's over kill to do them all every time, but it saves a lot of code.\r
161 //\r
162 if (Found) {\r
163 CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);\r
164 CalculateEfiHdrCrc (&gDxeCoreBS->Hdr);\r
165 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
166 CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);\r
167 }\r
168}\r
169\r
170\r
171\r
172/**\r
173 Creates an event that is fired everytime a Protocol of a specific type is installed.\r
174\r
175**/\r
176VOID\r
177CoreNotifyOnArchProtocolInstallation (\r
178 VOID\r
179 )\r
180{\r
181 EFI_STATUS Status;\r
182 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
183\r
184 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
185\r
186 //\r
187 // Create the event\r
188 //\r
189 Status = CoreCreateEvent (\r
190 EVT_NOTIFY_SIGNAL,\r
191 TPL_CALLBACK,\r
192 GenericArchProtocolNotify,\r
193 NULL,\r
194 &Entry->Event\r
195 );\r
196 ASSERT_EFI_ERROR(Status);\r
197\r
198 //\r
199 // Register for protocol notifactions on this event\r
200 //\r
201 Status = CoreRegisterProtocolNotify (\r
202 Entry->ProtocolGuid,\r
203 Entry->Event,\r
204 &Entry->Registration\r
205 );\r
206 ASSERT_EFI_ERROR(Status);\r
207\r
208 }\r
209}\r
210\r
211//\r
212// Following is needed to display missing architectural protocols in debug builds\r
213//\r
214typedef struct {\r
215 EFI_GUID *ProtocolGuid;\r
216 CHAR16 *GuidString;\r
217} GUID_TO_STRING_PROTOCOL_ENTRY;\r
218\r
219CONST GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {\r
220 { &gEfiSecurityArchProtocolGuid, (CHAR16 *)L"Security" },\r
221 { &gEfiCpuArchProtocolGuid, (CHAR16 *)L"CPU" },\r
222 { &gEfiMetronomeArchProtocolGuid, (CHAR16 *)L"Metronome" },\r
223 { &gEfiTimerArchProtocolGuid, (CHAR16 *)L"Timer" },\r
224 { &gEfiBdsArchProtocolGuid, (CHAR16 *)L"Bds" },\r
225 { &gEfiWatchdogTimerArchProtocolGuid, (CHAR16 *)L"Watchdog Timer" },\r
226 { &gEfiRuntimeArchProtocolGuid, (CHAR16 *)L"Runtime" },\r
227 { &gEfiVariableArchProtocolGuid, (CHAR16 *)L"Variable" },\r
228 { &gEfiVariableWriteArchProtocolGuid, (CHAR16 *)L"Variable Write" },\r
229 { &gEfiCapsuleArchProtocolGuid, (CHAR16 *)L"Capsule" },\r
230 { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter" },\r
231 { &gEfiResetArchProtocolGuid, (CHAR16 *)L"Reset" },\r
232 { &gEfiRealTimeClockArchProtocolGuid, (CHAR16 *)L"Real Time Clock" }\r
233};\r
234\r
235\r
236/**\r
237 Displays Architectural protocols that were not loaded and are required for DXE\r
238 core to function. Only used in Debug Builds.\r
239\r
240**/\r
241VOID\r
242CoreDisplayMissingArchProtocols (\r
243 VOID\r
244 )\r
245{\r
246 CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r
247 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
248\r
249 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
250 if (!Entry->Present) {\r
251 MissingEntry = MissingProtocols;\r
252 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {\r
253 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r
254 DEBUG ((DEBUG_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));\r
255 break;\r
256 }\r
257 }\r
258 }\r
259 }\r
260}\r