]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Change the TPL lock level to EFI_TPL_NOTIFY. Variable Service is called in ResetSyste...
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / DxeMain / DxeProtocolNotify.c
CommitLineData
878ddf1f 1/*++\r
2\r
53f491d3 3Copyright (c) 2006, Intel Corporation\r
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
a537f148 46#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
53f491d3 47#ifndef MDE_CPU_IPF\r
a537f148 48 //\r
49 // UEFI 2.0 added support for Capsule services. DXE CIS ??? Added support for this AP\r
50 //\r
045f4521 51 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE},\r
53f491d3 52#endif\r
a537f148 53#endif\r
878ddf1f 54 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
55 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
a537f148 56#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
57 //\r
58 // The ReportStatusCode Runtime service is in conflict with the UEFI 2.0 specificaiton\r
59 // Thus gEfiStatusCodeRuntimeProtocolGuid becomes a normal protocol in UEFI 2.0 systems\r
60 // It is only included if the EFI 1.10 with Tiano extensions is enabled for backward\r
61 // compatability\r
62 //\r
63 { &gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode, NULL, NULL, FALSE },\r
64#endif\r
878ddf1f 65 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
66 { NULL, (VOID **)NULL, NULL, NULL, FALSE }\r
67};\r
68\r
69\r
70EFI_STATUS\r
71CoreAllEfiServicesAvailable (\r
72 VOID\r
73 )\r
74/*++\r
75\r
76Routine Description:\r
77 Return TRUE if all AP services are availible.\r
78\r
79Arguments:\r
80 NONE\r
81\r
82Returns:\r
83 EFI_SUCCESS - All AP services are available\r
53f491d3 84 EFI_NOT_FOUND - At least one AP service is not available\r
878ddf1f 85\r
86--*/\r
87{\r
88 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
89\r
90 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
91 if (!Entry->Present) {\r
92 return EFI_NOT_FOUND;\r
93 }\r
94 }\r
95\r
96 return EFI_SUCCESS;\r
97}\r
98\r
1cc8ee78 99STATIC\r
878ddf1f 100VOID\r
101EFIAPI\r
102GenericArchProtocolNotify (\r
103 IN EFI_EVENT Event,\r
104 IN VOID *Context\r
105 )\r
106/*++\r
107\r
108Routine Description:\r
109 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().\r
110 This notify function is registered for every architectural protocol. This handler\r
53f491d3 111 updates mArchProtocol[] array entry with protocol instance data and sets it's\r
112 present flag to TRUE. If any constructor is required it is executed. The EFI\r
878ddf1f 113 System Table headers are updated.\r
114\r
115Arguments:\r
116\r
117 Event - The Event that is being processed, not used.\r
53f491d3 118\r
878ddf1f 119 Context - Event Context, not used.\r
120\r
121Returns:\r
122\r
123 None\r
124\r
125--*/\r
126{\r
127 EFI_STATUS Status;\r
128 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
129 VOID *Protocol;\r
130 BOOLEAN Found;\r
3ec2611d
LG
131 LIST_ENTRY *Link;\r
132 LIST_ENTRY TempLinkNode;\r
53f491d3 133\r
878ddf1f 134 Found = FALSE;\r
135 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
53f491d3 136\r
878ddf1f 137 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);\r
138 if (EFI_ERROR (Status)) {\r
139 continue;\r
53f491d3 140 }\r
141\r
878ddf1f 142 Found = TRUE;\r
143 Entry->Present = TRUE;\r
53f491d3 144\r
878ddf1f 145 //\r
146 // Update protocol global variable if one exists. Entry->Protocol points to a global variable\r
53f491d3 147 // if one exists in the DXE core for this Architectural Protocol\r
878ddf1f 148 //\r
149 if (Entry->Protocol != NULL) {\r
150 *(Entry->Protocol) = Protocol;\r
151 }\r
152\r
153 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {\r
154 //\r
155 // Register the Core timer tick handler with the Timer AP\r
156 //\r
157 gTimer->RegisterHandler (gTimer, CoreTimerTick);\r
158 }\r
159\r
160 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {\r
161 //\r
162 // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
163 //\r
164 CoreUpdateDebugTableCrc32 ();\r
3ec2611d
LG
165\r
166 //\r
167 // Update the Runtime Architectural protocol with the template that the core was\r
168 // using so there would not need to be a dependency on the Runtime AP\r
169 //\r
170\r
171 //\r
172 // Copy all the registered Image to new gRuntime protocol\r
173 //\r
174 for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {\r
175 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
176 InsertTailList (&gRuntime->ImageHead, Link);\r
177 }\r
178 //\r
179 // Copy all the registered Event to new gRuntime protocol\r
180 //\r
181 for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {\r
182 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
183 InsertTailList (&gRuntime->EventHead, Link);\r
184 }\r
185 \r
186 //\r
187 // Clean up gRuntimeTemplate\r
188 //\r
189 gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;\r
190 gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;\r
191 gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;\r
192 gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;\r
878ddf1f 193 }\r
194 }\r
195\r
196 //\r
197 // It's over kill to do them all every time, but it saves a lot of code.\r
198 //\r
199 if (Found) {\r
200 CalculateEfiHdrCrc (&gRT->Hdr);\r
201 CalculateEfiHdrCrc (&gBS->Hdr);\r
202 CalculateEfiHdrCrc (&gST->Hdr);\r
203 CalculateEfiHdrCrc (&gDS->Hdr);\r
204 }\r
205}\r
206\r
207\r
208\r
209VOID\r
210CoreNotifyOnArchProtocolInstallation (\r
211 VOID\r
212 )\r
213/*++\r
214\r
215Routine Description:\r
216 Creates an event that is fired everytime a Protocol of a specific type is installed\r
217\r
218Arguments:\r
219 NONE\r
220\r
221Returns:\r
222 NONE\r
223\r
224--*/\r
225{\r
226 EFI_STATUS Status;\r
227 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
228\r
229 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
53f491d3 230\r
878ddf1f 231 //\r
232 // Create the event\r
233 //\r
234 Status = CoreCreateEvent (\r
235 EFI_EVENT_NOTIFY_SIGNAL,\r
236 EFI_TPL_CALLBACK,\r
237 GenericArchProtocolNotify,\r
238 NULL,\r
239 &Entry->Event\r
240 );\r
241 ASSERT_EFI_ERROR(Status);\r
242\r
243 //\r
244 // Register for protocol notifactions on this event\r
245 //\r
246 Status = CoreRegisterProtocolNotify (\r
53f491d3 247 Entry->ProtocolGuid,\r
248 Entry->Event,\r
878ddf1f 249 &Entry->Registration\r
250 );\r
251 ASSERT_EFI_ERROR(Status);\r
252\r
253 }\r
254}\r
255\r
256//\r
257// Following is needed to display missing architectural protocols in debug builds\r
258//\r
259typedef struct {\r
260 EFI_GUID *ProtocolGuid;\r
261 CHAR16 *GuidString;\r
262} GUID_TO_STRING_PROTOCOL_ENTRY;\r
263\r
264static const GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {\r
265 { &gEfiSecurityArchProtocolGuid, (CHAR16 *)L"Security" },\r
266 { &gEfiCpuArchProtocolGuid, (CHAR16 *)L"CPU" },\r
267 { &gEfiMetronomeArchProtocolGuid, (CHAR16 *)L"Metronome" },\r
268 { &gEfiTimerArchProtocolGuid, (CHAR16 *)L"Timer" },\r
269 { &gEfiBdsArchProtocolGuid, (CHAR16 *)L"Bds" },\r
270 { &gEfiWatchdogTimerArchProtocolGuid, (CHAR16 *)L"Watchdog Timer" },\r
271 { &gEfiRuntimeArchProtocolGuid, (CHAR16 *)L"Runtime" },\r
272 { &gEfiVariableArchProtocolGuid, (CHAR16 *)L"Variable" },\r
273 { &gEfiVariableWriteArchProtocolGuid, (CHAR16 *)L"Variable Write" },\r
045f4521 274 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
275 { &gEfiCapsuleArchProtocolGuid, (CHAR16 *)L"Capsule" },\r
276 #endif\r
878ddf1f 277 { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter" },\r
278 { &gEfiResetArchProtocolGuid, (CHAR16 *)L"Reset" },\r
279// { &gEfiStatusCodeRuntimeProtocolGuid, (CHAR16 *)L"Status Code" },\r
280 { &gEfiRealTimeClockArchProtocolGuid, (CHAR16 *)L"Real Time Clock" }\r
281};\r
282\r
283VOID\r
284CoreDisplayMissingArchProtocols (\r
285 VOID\r
286 )\r
287/*++\r
288\r
289Routine Description:\r
290 Displays Architectural protocols that were not loaded and are required for DXE core to function\r
291 Only used in Debug Builds\r
292\r
293Arguments:\r
294 NONE\r
295\r
296Returns:\r
297 NONE\r
298\r
299--*/\r
300{\r
301 const GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r
302 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
303\r
304 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
305 if (!Entry->Present) {\r
306 MissingEntry = MissingProtocols;\r
307 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {\r
308 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r
309 DEBUG ((EFI_D_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));\r
310 break;\r
311 }\r
312 }\r
313 }\r
53f491d3 314 }\r
878ddf1f 315}\r