]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
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 | |
6 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
7 | This program and the accompanying materials\r | |
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 | |
15 | **/\r | |
16 | \r | |
17 | #include "DxeMain.h"\r | |
18 | \r | |
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 | |
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 | |
43 | \r | |
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 | { &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },\r | |
49 | { &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },\r | |
50 | { NULL, (VOID **)NULL, NULL, NULL, FALSE }\r | |
51 | };\r | |
52 | \r | |
53 | //\r | |
54 | // Following is needed to display missing architectural protocols in debug builds\r | |
55 | //\r | |
56 | typedef struct {\r | |
57 | EFI_GUID *ProtocolGuid;\r | |
58 | CHAR8 *GuidString;\r | |
59 | } GUID_TO_STRING_PROTOCOL_ENTRY;\r | |
60 | \r | |
61 | GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {\r | |
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 | |
74 | { &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },\r | |
75 | { NULL, "" }\r | |
76 | };\r | |
77 | \r | |
78 | /**\r | |
79 | Return TRUE if all AP services are available.\r | |
80 | \r | |
81 | @retval EFI_SUCCESS All AP services are available\r | |
82 | @retval EFI_NOT_FOUND At least one AP service is not available\r | |
83 | \r | |
84 | **/\r | |
85 | EFI_STATUS\r | |
86 | CoreAllEfiServicesAvailable (\r | |
87 | VOID\r | |
88 | )\r | |
89 | {\r | |
90 | EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r | |
91 | \r | |
92 | for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r | |
93 | if (!Entry->Present) {\r | |
94 | return EFI_NOT_FOUND;\r | |
95 | }\r | |
96 | }\r | |
97 | return EFI_SUCCESS;\r | |
98 | }\r | |
99 | \r | |
100 | \r | |
101 | /**\r | |
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 | |
108 | @param Event The Event that is being processed, not used.\r | |
109 | @param Context Event Context, not used.\r | |
110 | \r | |
111 | **/\r | |
112 | VOID\r | |
113 | EFIAPI\r | |
114 | GenericProtocolNotify (\r | |
115 | IN EFI_EVENT Event,\r | |
116 | IN VOID *Context\r | |
117 | )\r | |
118 | {\r | |
119 | EFI_STATUS Status;\r | |
120 | EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r | |
121 | VOID *Protocol;\r | |
122 | LIST_ENTRY *Link;\r | |
123 | LIST_ENTRY TempLinkNode;\r | |
124 | \r | |
125 | Protocol = NULL;\r | |
126 | \r | |
127 | //\r | |
128 | // Get Entry from Context\r | |
129 | //\r | |
130 | Entry = (EFI_CORE_PROTOCOL_NOTIFY_ENTRY *)Context;\r | |
131 | \r | |
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 | |
139 | \r | |
140 | //\r | |
141 | // Mark the protocol as present\r | |
142 | //\r | |
143 | Entry->Present = TRUE;\r | |
144 | \r | |
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 | |
158 | //\r | |
159 | // Register the Core timer tick handler with the Timer AP\r | |
160 | //\r | |
161 | gTimer->RegisterHandler (gTimer, CoreTimerTick);\r | |
162 | }\r | |
163 | \r | |
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 | |
169 | \r | |
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 | |
174 | \r | |
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 | |
188 | }\r | |
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 | |
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 | |
202 | CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);\r | |
203 | CalculateEfiHdrCrc (&gBS->Hdr);\r | |
204 | CalculateEfiHdrCrc (&gDxeCoreST->Hdr);\r | |
205 | CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);\r | |
206 | }\r | |
207 | \r | |
208 | /**\r | |
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 | |
211 | \r | |
212 | @param Entry Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.\r | |
213 | \r | |
214 | **/\r | |
215 | VOID\r | |
216 | CoreNotifyOnProtocolEntryTable (\r | |
217 | EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry\r | |
218 | )\r | |
219 | {\r | |
220 | EFI_STATUS Status;\r | |
221 | \r | |
222 | for (; Entry->ProtocolGuid != NULL; Entry++) {\r | |
223 | //\r | |
224 | // Create the event\r | |
225 | //\r | |
226 | Status = CoreCreateEvent (\r | |
227 | EVT_NOTIFY_SIGNAL,\r | |
228 | TPL_CALLBACK,\r | |
229 | GenericProtocolNotify,\r | |
230 | Entry,\r | |
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 | |
244 | }\r | |
245 | }\r | |
246 | \r | |
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 | |
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 | |
267 | VOID\r | |
268 | CoreDisplayMissingArchProtocols (\r | |
269 | VOID\r | |
270 | )\r | |
271 | {\r | |
272 | EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;\r | |
273 | CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;\r | |
274 | \r | |
275 | for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {\r | |
276 | if (!Entry->Present) {\r | |
277 | for (MissingEntry = mMissingProtocols; MissingEntry->ProtocolGuid != NULL; MissingEntry++) {\r | |
278 | if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {\r | |
279 | DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));\r | |
280 | break;\r | |
281 | }\r | |
282 | }\r | |
283 | }\r | |
284 | }\r | |
285 | }\r |