Added the StatusCode protocol installation for the IPF architecture; removed the...
[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
99\r
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
53f491d3 131\r
878ddf1f 132 Found = FALSE;\r
133 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
53f491d3 134\r
878ddf1f 135 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);\r
136 if (EFI_ERROR (Status)) {\r
137 continue;\r
53f491d3 138 }\r
139\r
878ddf1f 140 Found = TRUE;\r
141 Entry->Present = TRUE;\r
53f491d3 142\r
878ddf1f 143 //\r
144 // Update protocol global variable if one exists. Entry->Protocol points to a global variable\r
53f491d3 145 // if one exists in the DXE core for this Architectural Protocol\r
878ddf1f 146 //\r
147 if (Entry->Protocol != NULL) {\r
148 *(Entry->Protocol) = Protocol;\r
149 }\r
150\r
151 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {\r
152 //\r
153 // Register the Core timer tick handler with the Timer AP\r
154 //\r
155 gTimer->RegisterHandler (gTimer, CoreTimerTick);\r
156 }\r
157\r
158 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {\r
159 //\r
160 // When runtime architectural protocol is available, updates CRC32 in the Debug Table\r
161 //\r
162 CoreUpdateDebugTableCrc32 ();\r
163 }\r
164 }\r
165\r
166 //\r
167 // It's over kill to do them all every time, but it saves a lot of code.\r
168 //\r
169 if (Found) {\r
170 CalculateEfiHdrCrc (&gRT->Hdr);\r
171 CalculateEfiHdrCrc (&gBS->Hdr);\r
172 CalculateEfiHdrCrc (&gST->Hdr);\r
173 CalculateEfiHdrCrc (&gDS->Hdr);\r
174 }\r
175}\r
176\r
177\r
178\r
179VOID\r
180CoreNotifyOnArchProtocolInstallation (\r
181 VOID\r
182 )\r
183/*++\r
184\r
185Routine Description:\r
186 Creates an event that is fired everytime a Protocol of a specific type is installed\r
187\r
188Arguments:\r
189 NONE\r
190\r
191Returns:\r
192 NONE\r
193\r
194--*/\r
195{\r
196 EFI_STATUS Status;\r
197 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
198\r
199 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
53f491d3 200\r
878ddf1f 201 //\r
202 // Create the event\r
203 //\r
204 Status = CoreCreateEvent (\r
205 EFI_EVENT_NOTIFY_SIGNAL,\r
206 EFI_TPL_CALLBACK,\r
207 GenericArchProtocolNotify,\r
208 NULL,\r
209 &Entry->Event\r
210 );\r
211 ASSERT_EFI_ERROR(Status);\r
212\r
213 //\r
214 // Register for protocol notifactions on this event\r
215 //\r
216 Status = CoreRegisterProtocolNotify (\r
53f491d3 217 Entry->ProtocolGuid,\r
218 Entry->Event,\r
878ddf1f 219 &Entry->Registration\r
220 );\r
221 ASSERT_EFI_ERROR(Status);\r
222\r
223 }\r
224}\r
225\r
226//\r
227// Following is needed to display missing architectural protocols in debug builds\r
228//\r
229typedef struct {\r
230 EFI_GUID *ProtocolGuid;\r
231 CHAR16 *GuidString;\r
232} GUID_TO_STRING_PROTOCOL_ENTRY;\r
233\r
234static const GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {\r
235 { &gEfiSecurityArchProtocolGuid, (CHAR16 *)L"Security" },\r
236 { &gEfiCpuArchProtocolGuid, (CHAR16 *)L"CPU" },\r
237 { &gEfiMetronomeArchProtocolGuid, (CHAR16 *)L"Metronome" },\r
238 { &gEfiTimerArchProtocolGuid, (CHAR16 *)L"Timer" },\r
239 { &gEfiBdsArchProtocolGuid, (CHAR16 *)L"Bds" },\r
240 { &gEfiWatchdogTimerArchProtocolGuid, (CHAR16 *)L"Watchdog Timer" },\r
241 { &gEfiRuntimeArchProtocolGuid, (CHAR16 *)L"Runtime" },\r
242 { &gEfiVariableArchProtocolGuid, (CHAR16 *)L"Variable" },\r
243 { &gEfiVariableWriteArchProtocolGuid, (CHAR16 *)L"Variable Write" },\r
045f4521 244 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
245 { &gEfiCapsuleArchProtocolGuid, (CHAR16 *)L"Capsule" },\r
246 #endif\r
878ddf1f 247 { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter" },\r
248 { &gEfiResetArchProtocolGuid, (CHAR16 *)L"Reset" },\r
249// { &gEfiStatusCodeRuntimeProtocolGuid, (CHAR16 *)L"Status Code" },\r
250 { &gEfiRealTimeClockArchProtocolGuid, (CHAR16 *)L"Real Time Clock" }\r
251};\r
252\r
253VOID\r
254CoreDisplayMissingArchProtocols (\r
255 VOID\r
256 )\r
257/*++\r
258\r
259Routine Description:\r
260 Displays Architectural protocols that were not loaded and are required for DXE core to function\r
261 Only used in Debug Builds\r
262\r
263Arguments:\r
264 NONE\r
265\r
266Returns:\r
267 NONE\r
268\r
269--*/\r
270{\r
271 const GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r
272 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
273\r
274 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r
275 if (!Entry->Present) {\r
276 MissingEntry = MissingProtocols;\r
277 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {\r
278 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r
279 DEBUG ((EFI_D_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));\r
280 break;\r
281 }\r
282 }\r
283 }\r
53f491d3 284 }\r
878ddf1f 285}\r