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