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