]>
Commit | Line | Data |
---|---|---|
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 |
6 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
7 | This program and the accompanying materials\r | |
28a00297 | 8 | are licensed and made available under the terms and conditions of the BSD License\r |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT 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 | 27 | EFI_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 | |
47 | EFI_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 | |
55 | typedef struct {\r | |
74e44290 | 56 | EFI_GUID *ProtocolGuid;\r |
57 | CHAR8 *GuidString;\r | |
44cfd8a8 | 58 | } GUID_TO_STRING_PROTOCOL_ENTRY;\r |
28a00297 | 59 | \r |
b33339fa | 60 | GLOBAL_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 |
84 | EFI_STATUS\r | |
85 | CoreAllEfiServicesAvailable (\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 | 111 | VOID\r |
112 | EFIAPI\r | |
74e44290 | 113 | GenericProtocolNotify (\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 |
12fbc893 | 209 | @param Entry Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.\r |
210 | \r | |
162ed594 | 211 | **/\r |
28a00297 | 212 | VOID\r |
74e44290 | 213 | CoreNotifyOnProtocolEntryTable (\r |
214 | EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry\r | |
28a00297 | 215 | )\r |
28a00297 | 216 | {\r |
74e44290 | 217 | EFI_STATUS Status;\r |
28a00297 | 218 | \r |
74e44290 | 219 | for (; Entry->ProtocolGuid != NULL; Entry++) {\r |
28a00297 | 220 | //\r |
221 | // Create the event\r | |
222 | //\r | |
223 | Status = CoreCreateEvent (\r | |
224 | EVT_NOTIFY_SIGNAL,\r | |
225 | TPL_CALLBACK,\r | |
74e44290 | 226 | GenericProtocolNotify,\r |
227 | Entry,\r | |
28a00297 | 228 | &Entry->Event\r |
229 | );\r | |
230 | ASSERT_EFI_ERROR(Status);\r | |
231 | \r | |
232 | //\r | |
233 | // Register for protocol notifactions on this event\r | |
234 | //\r | |
235 | Status = CoreRegisterProtocolNotify (\r | |
236 | Entry->ProtocolGuid,\r | |
237 | Entry->Event,\r | |
238 | &Entry->Registration\r | |
239 | );\r | |
240 | ASSERT_EFI_ERROR(Status);\r | |
28a00297 | 241 | }\r |
242 | }\r | |
243 | \r | |
74e44290 | 244 | /**\r |
245 | Creates an events for the Architectural Protocols and the optional protocols \r | |
246 | that are fired everytime a Protocol of a specific type is installed.\r | |
247 | \r | |
248 | **/\r | |
249 | VOID\r | |
250 | CoreNotifyOnProtocolInstallation (\r | |
251 | VOID\r | |
252 | )\r | |
253 | {\r | |
254 | CoreNotifyOnProtocolEntryTable (mArchProtocols);\r | |
255 | CoreNotifyOnProtocolEntryTable (mOptionalProtocols);\r | |
256 | }\r | |
257 | \r | |
162ed594 | 258 | \r |
259 | /**\r | |
260 | Displays Architectural protocols that were not loaded and are required for DXE\r | |
261 | core to function. Only used in Debug Builds.\r | |
262 | \r | |
263 | **/\r | |
28a00297 | 264 | VOID\r |
265 | CoreDisplayMissingArchProtocols (\r | |
266 | VOID\r | |
267 | )\r | |
28a00297 | 268 | {\r |
74e44290 | 269 | EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r |
e94a9ff7 | 270 | CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r |
28a00297 | 271 | \r |
74e44290 | 272 | for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r |
273 | if (!Entry->Present) {\r | |
274 | for (MissingEntry = mMissingProtocols; MissingEntry->ProtocolGuid != NULL; MissingEntry++) {\r | |
28a00297 | 275 | if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r |
4fdc9129 | 276 | DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));\r |
28a00297 | 277 | break;\r |
278 | }\r | |
279 | }\r | |
280 | }\r | |
281 | }\r | |
282 | }\r |