]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Refine code to remove the last entry of mArchProtocol.
[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
9c4ac31c 17#include "DxeMain.h"\r
28a00297 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
e94a9ff7 39 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
28a00297 40 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
41 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },\r
3f143578 42 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE }\r
28a00297 43};\r
44\r
45\r
28a00297 46\r
162ed594 47/**\r
28a00297 48 Return TRUE if all AP services are availible.\r
49\r
022c6d45 50 @retval EFI_SUCCESS All AP services are available\r
162ed594 51 @retval EFI_NOT_FOUND At least one AP service is not available\r
28a00297 52\r
162ed594 53**/\r
54EFI_STATUS\r
55CoreAllEfiServicesAvailable (\r
56 VOID\r
57 )\r
28a00297 58{\r
3f143578 59 UINTN Index;\r
28a00297 60\r
3f143578 61 for (Index = 0; Index < sizeof (mArchProtocols) / sizeof (mArchProtocols[0]); Index++) {\r
62 if (!mArchProtocols[Index].Present) {\r
28a00297 63 return EFI_NOT_FOUND;\r
64 }\r
65 }\r
66\r
67 return EFI_SUCCESS;\r
68}\r
69\r
28a00297 70\r
162ed594 71/**\r
28a00297 72 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().\r
73 This notify function is registered for every architectural protocol. This handler\r
74 updates mArchProtocol[] array entry with protocol instance data and sets it's\r
75 present flag to TRUE. If any constructor is required it is executed. The EFI\r
76 System Table headers are updated.\r
77\r
022c6d45 78 @param Event The Event that is being processed, not used.\r
162ed594 79 @param Context Event Context, not used.\r
28a00297 80\r
162ed594 81**/\r
162ed594 82VOID\r
83EFIAPI\r
84GenericArchProtocolNotify (\r
85 IN EFI_EVENT Event,\r
86 IN VOID *Context\r
87 )\r
28a00297 88{\r
89 EFI_STATUS Status;\r
90 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
91 VOID *Protocol;\r
92 BOOLEAN Found;\r
93 LIST_ENTRY *Link;\r
94 LIST_ENTRY TempLinkNode;\r
3f143578 95 UINTN Index;\r
28a00297 96\r
97 Found = FALSE;\r
3f143578 98 for (Index = 0; Index < sizeof (mArchProtocols) / sizeof (mArchProtocols[0]); Index++) {\r
99 Entry = &mArchProtocols[Index];\r
28a00297 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
0e9b156d 165 CalculateEfiHdrCrc (&gBS->Hdr);\r
28a00297 166 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r
167 CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);\r
168 }\r
169}\r
170\r
171\r
172\r
162ed594 173/**\r
174 Creates an event that is fired everytime a Protocol of a specific type is installed.\r
175\r
176**/\r
28a00297 177VOID\r
178CoreNotifyOnArchProtocolInstallation (\r
179 VOID\r
180 )\r
28a00297 181{\r
182 EFI_STATUS Status;\r
183 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
3f143578 184 UINTN Index;\r
28a00297 185\r
3f143578 186 for (Index = 0; Index < sizeof (mArchProtocols) / sizeof (mArchProtocols[0]); Index++) {\r
187 Entry = &mArchProtocols[Index];\r
28a00297 188\r
189 //\r
190 // Create the event\r
191 //\r
192 Status = CoreCreateEvent (\r
193 EVT_NOTIFY_SIGNAL,\r
194 TPL_CALLBACK,\r
195 GenericArchProtocolNotify,\r
196 NULL,\r
197 &Entry->Event\r
198 );\r
199 ASSERT_EFI_ERROR(Status);\r
200\r
201 //\r
202 // Register for protocol notifactions on this event\r
203 //\r
204 Status = CoreRegisterProtocolNotify (\r
205 Entry->ProtocolGuid,\r
206 Entry->Event,\r
207 &Entry->Registration\r
208 );\r
209 ASSERT_EFI_ERROR(Status);\r
210\r
211 }\r
212}\r
213\r
214//\r
215// Following is needed to display missing architectural protocols in debug builds\r
216//\r
217typedef struct {\r
4fdc9129 218 EFI_GUID *ProtocolGuid;\r
219 CHAR8 *GuidString;\r
28a00297 220} GUID_TO_STRING_PROTOCOL_ENTRY;\r
221\r
4fdc9129 222GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {\r
223 { &gEfiSecurityArchProtocolGuid, "Security" },\r
224 { &gEfiCpuArchProtocolGuid, "CPU" },\r
225 { &gEfiMetronomeArchProtocolGuid, "Metronome" },\r
226 { &gEfiTimerArchProtocolGuid, "Timer" },\r
227 { &gEfiBdsArchProtocolGuid, "Bds" },\r
228 { &gEfiWatchdogTimerArchProtocolGuid, "Watchdog Timer" },\r
229 { &gEfiRuntimeArchProtocolGuid, "Runtime" },\r
230 { &gEfiVariableArchProtocolGuid, "Variable" },\r
231 { &gEfiVariableWriteArchProtocolGuid, "Variable Write" },\r
232 { &gEfiCapsuleArchProtocolGuid, "Capsule" },\r
233 { &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter" },\r
234 { &gEfiResetArchProtocolGuid, "Reset" },\r
235 { &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" }\r
28a00297 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
e94a9ff7 249 CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r
28a00297 250 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;\r
3f143578 251 UINTN Index;\r
28a00297 252\r
3f143578 253 for (Index = 0; Index < sizeof (mArchProtocols) / sizeof (mArchProtocols[0]); Index++) {\r
254 Entry = &mArchProtocols[Index];\r
28a00297 255 if (!Entry->Present) {\r
28a00297 256 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {\r
257 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r
4fdc9129 258 DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));\r
28a00297 259 break;\r
260 }\r
261 }\r
262 }\r
263 }\r
264}\r