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