]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Update code to support VS2013 tool chain.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeProtocolNotify.c
CommitLineData
23c98c94 1/** @file\r
504214c4
LG
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
cd5ebaa0
HT
6Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
7This program and the accompanying materials\r
28a00297 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
504214c4 15**/\r
28a00297 16\r
9c4ac31c 17#include "DxeMain.h"\r
28a00297 18\r
28a00297 19//\r
20// DXE Core Global Variables for all of the Architectural Protocols.\r
21// If a protocol is installed mArchProtocols[].Present will be TRUE.\r
22//\r
23// CoreNotifyOnArchProtocolInstallation () fills in mArchProtocols[].Event\r
24// and mArchProtocols[].Registration as it creates events for every array\r
25// entry.\r
26//\r
74e44290 27EFI_CORE_PROTOCOL_NOTIFY_ENTRY mArchProtocols[] = {\r
28 { &gEfiSecurityArchProtocolGuid, (VOID **)&gSecurity, NULL, NULL, FALSE },\r
29 { &gEfiCpuArchProtocolGuid, (VOID **)&gCpu, NULL, NULL, FALSE },\r
30 { &gEfiMetronomeArchProtocolGuid, (VOID **)&gMetronome, NULL, NULL, FALSE },\r
31 { &gEfiTimerArchProtocolGuid, (VOID **)&gTimer, NULL, NULL, FALSE },\r
32 { &gEfiBdsArchProtocolGuid, (VOID **)&gBds, NULL, NULL, FALSE },\r
33 { &gEfiWatchdogTimerArchProtocolGuid, (VOID **)&gWatchdogTimer, NULL, NULL, FALSE },\r
34 { &gEfiRuntimeArchProtocolGuid, (VOID **)&gRuntime, NULL, NULL, FALSE },\r
35 { &gEfiVariableArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
36 { &gEfiVariableWriteArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
37 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
38 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
39 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
40 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
41 { NULL, (VOID **)NULL, NULL, NULL, FALSE }\r
42};\r
28a00297 43\r
74e44290 44//\r
45// Optional protocols that the DXE Core will use if they are present\r
46//\r
47EFI_CORE_PROTOCOL_NOTIFY_ENTRY mOptionalProtocols[] = {\r
bc2dfdbc 48 { &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },\r
74e44290 49 { &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },\r
50 { NULL, (VOID **)NULL, NULL, NULL, FALSE }\r
28a00297 51};\r
52\r
44cfd8a8 53//\r
54// Following is needed to display missing architectural protocols in debug builds\r
55//\r
56typedef struct {\r
74e44290 57 EFI_GUID *ProtocolGuid;\r
58 CHAR8 *GuidString;\r
44cfd8a8 59} GUID_TO_STRING_PROTOCOL_ENTRY;\r
28a00297 60\r
b33339fa 61GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {\r
44cfd8a8 62 { &gEfiSecurityArchProtocolGuid, "Security" },\r
63 { &gEfiCpuArchProtocolGuid, "CPU" },\r
64 { &gEfiMetronomeArchProtocolGuid, "Metronome" },\r
65 { &gEfiTimerArchProtocolGuid, "Timer" },\r
66 { &gEfiBdsArchProtocolGuid, "Bds" },\r
67 { &gEfiWatchdogTimerArchProtocolGuid, "Watchdog Timer" },\r
68 { &gEfiRuntimeArchProtocolGuid, "Runtime" },\r
69 { &gEfiVariableArchProtocolGuid, "Variable" },\r
70 { &gEfiVariableWriteArchProtocolGuid, "Variable Write" },\r
71 { &gEfiCapsuleArchProtocolGuid, "Capsule" },\r
72 { &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter" },\r
73 { &gEfiResetArchProtocolGuid, "Reset" },\r
74e44290 74 { &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },\r
75 { NULL, "" }\r
44cfd8a8 76};\r
28a00297 77\r
162ed594 78/**\r
28a00297 79 Return TRUE if all AP services are availible.\r
80\r
022c6d45 81 @retval EFI_SUCCESS All AP services are available\r
162ed594 82 @retval EFI_NOT_FOUND At least one AP service is not available\r
28a00297 83\r
162ed594 84**/\r
85EFI_STATUS\r
86CoreAllEfiServicesAvailable (\r
87 VOID\r
88 )\r
28a00297 89{\r
74e44290 90 EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r
28a00297 91\r
74e44290 92 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
93 if (!Entry->Present) {\r
28a00297 94 return EFI_NOT_FOUND;\r
95 }\r
96 }\r
28a00297 97 return EFI_SUCCESS;\r
98}\r
99\r
28a00297 100\r
162ed594 101/**\r
28a00297 102 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().\r
103 This notify function is registered for every architectural protocol. This handler\r
104 updates mArchProtocol[] array entry with protocol instance data and sets it's\r
105 present flag to TRUE. If any constructor is required it is executed. The EFI\r
106 System Table headers are updated.\r
107\r
022c6d45 108 @param Event The Event that is being processed, not used.\r
162ed594 109 @param Context Event Context, not used.\r
28a00297 110\r
162ed594 111**/\r
162ed594 112VOID\r
113EFIAPI\r
74e44290 114GenericProtocolNotify (\r
115 IN EFI_EVENT Event,\r
116 IN VOID *Context\r
162ed594 117 )\r
28a00297 118{\r
119 EFI_STATUS Status;\r
74e44290 120 EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r
28a00297 121 VOID *Protocol;\r
28a00297 122 LIST_ENTRY *Link;\r
123 LIST_ENTRY TempLinkNode;\r
124\r
74e44290 125 //\r
126 // Get Entry from Context\r
127 //\r
128 Entry = (EFI_CORE_PROTOCOL_NOTIFY_ENTRY *)Context;\r
28a00297 129\r
74e44290 130 //\r
131 // See if the expected protocol is present in the handle database\r
132 //\r
133 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);\r
134 if (EFI_ERROR (Status)) {\r
135 return;\r
136 }\r
28a00297 137\r
74e44290 138 //\r
139 // Mark the protocol as present\r
140 //\r
141 Entry->Present = TRUE;\r
28a00297 142\r
74e44290 143 //\r
144 // Update protocol global variable if one exists. Entry->Protocol points to a global variable\r
145 // if one exists in the DXE core for this Architectural Protocol\r
146 //\r
147 if (Entry->Protocol != NULL) {\r
148 *(Entry->Protocol) = Protocol;\r
149 }\r
150\r
151 //\r
152 // Do special operations for Architectural Protocols\r
153 //\r
154\r
155 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {\r
28a00297 156 //\r
74e44290 157 // Register the Core timer tick handler with the Timer AP\r
28a00297 158 //\r
74e44290 159 gTimer->RegisterHandler (gTimer, CoreTimerTick);\r
160 }\r
28a00297 161\r
74e44290 162 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {\r
163 //\r
164 // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
165 //\r
166 CoreUpdateDebugTableCrc32 ();\r
28a00297 167\r
74e44290 168 //\r
169 // Update the Runtime Architectural protocol with the template that the core was\r
170 // using so there would not need to be a dependency on the Runtime AP\r
171 //\r
28a00297 172\r
74e44290 173 //\r
174 // Copy all the registered Image to new gRuntime protocol\r
175 //\r
176 for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {\r
177 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
178 InsertTailList (&gRuntime->ImageHead, Link);\r
179 }\r
180 //\r
181 // Copy all the registered Event to new gRuntime protocol\r
182 //\r
183 for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {\r
184 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));\r
185 InsertTailList (&gRuntime->EventHead, Link);\r
28a00297 186 }\r
74e44290 187\r
188 //\r
189 // Clean up gRuntimeTemplate\r
190 //\r
191 gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;\r
192 gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;\r
193 gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;\r
194 gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;\r
28a00297 195 }\r
196\r
197 //\r
198 // It's over kill to do them all every time, but it saves a lot of code.\r
199 //\r
74e44290 200 CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);\r
201 CalculateEfiHdrCrc (&gBS->Hdr);\r
202 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
203 CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);\r
28a00297 204}\r
205\r
162ed594 206/**\r
74e44290 207 Creates an event for each entry in a table that is fired everytime a Protocol \r
208 of a specific type is installed.\r
162ed594 209\r
12fbc893 210 @param Entry Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.\r
211\r
162ed594 212**/\r
28a00297 213VOID\r
74e44290 214CoreNotifyOnProtocolEntryTable (\r
215 EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry\r
28a00297 216 )\r
28a00297 217{\r
74e44290 218 EFI_STATUS Status;\r
28a00297 219\r
74e44290 220 for (; Entry->ProtocolGuid != NULL; Entry++) {\r
28a00297 221 //\r
222 // Create the event\r
223 //\r
224 Status = CoreCreateEvent (\r
225 EVT_NOTIFY_SIGNAL,\r
226 TPL_CALLBACK,\r
74e44290 227 GenericProtocolNotify,\r
228 Entry,\r
28a00297 229 &Entry->Event\r
230 );\r
231 ASSERT_EFI_ERROR(Status);\r
232\r
233 //\r
234 // Register for protocol notifactions on this event\r
235 //\r
236 Status = CoreRegisterProtocolNotify (\r
237 Entry->ProtocolGuid,\r
238 Entry->Event,\r
239 &Entry->Registration\r
240 );\r
241 ASSERT_EFI_ERROR(Status);\r
28a00297 242 }\r
243}\r
244\r
74e44290 245/**\r
246 Creates an events for the Architectural Protocols and the optional protocols \r
247 that are fired everytime a Protocol of a specific type is installed.\r
248\r
249**/\r
250VOID\r
251CoreNotifyOnProtocolInstallation (\r
252 VOID\r
253 )\r
254{\r
255 CoreNotifyOnProtocolEntryTable (mArchProtocols);\r
256 CoreNotifyOnProtocolEntryTable (mOptionalProtocols);\r
257}\r
258\r
162ed594 259\r
260/**\r
261 Displays Architectural protocols that were not loaded and are required for DXE\r
262 core to function. Only used in Debug Builds.\r
263\r
264**/\r
28a00297 265VOID\r
266CoreDisplayMissingArchProtocols (\r
267 VOID\r
268 )\r
28a00297 269{\r
74e44290 270 EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r
e94a9ff7 271 CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r
28a00297 272\r
74e44290 273 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
274 if (!Entry->Present) {\r
275 for (MissingEntry = mMissingProtocols; MissingEntry->ProtocolGuid != NULL; MissingEntry++) {\r
28a00297 276 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r
4fdc9129 277 DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));\r
28a00297 278 break;\r
279 }\r
280 }\r
281 }\r
282 }\r
283}\r