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