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