]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Merge R8->R9 tracker 5935 and 7080 to update runtime arch protocol to DxeCis 0.91...
[mirror_edk2.git] / EdkModulePkg / Core / Dxe / DxeMain / DxeProtocolNotify.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 DxeProtocolNotify.c
15
16 Abstract:
17
18 This file deals with Architecture Protocol (AP) registration in
19 the Dxe Core. The mArchProtocols[] array represents a list of
20 events that represent the Architectural Protocols.
21
22 --*/
23
24 #include <DxeMain.h>
25
26
27 //
28 // DXE Core Global Variables for all of the Architectural Protocols.
29 // If a protocol is installed mArchProtocols[].Present will be TRUE.
30 //
31 // CoreNotifyOnArchProtocolInstallation () fills in mArchProtocols[].Event
32 // and mArchProtocols[].Registration as it creates events for every array
33 // entry.
34 //
35
36 ARCHITECTURAL_PROTOCOL_ENTRY mArchProtocols[] = {
37 { &gEfiSecurityArchProtocolGuid, (VOID **)&gSecurity, NULL, NULL, FALSE },
38 { &gEfiCpuArchProtocolGuid, (VOID **)&gCpu, NULL, NULL, FALSE },
39 { &gEfiMetronomeArchProtocolGuid, (VOID **)&gMetronome, NULL, NULL, FALSE },
40 { &gEfiTimerArchProtocolGuid, (VOID **)&gTimer, NULL, NULL, FALSE },
41 { &gEfiBdsArchProtocolGuid, (VOID **)&gBds, NULL, NULL, FALSE },
42 { &gEfiWatchdogTimerArchProtocolGuid, (VOID **)&gWatchdogTimer, NULL, NULL, FALSE },
43 { &gEfiRuntimeArchProtocolGuid, (VOID **)&gRuntime, NULL, NULL, FALSE },
44 { &gEfiVariableArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
45 { &gEfiVariableWriteArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
46 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
47 #ifndef MDE_CPU_IPF
48 //
49 // UEFI 2.0 added support for Capsule services. DXE CIS ??? Added support for this AP
50 //
51 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE},
52 #endif
53 #endif
54 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
55 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
56 #if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
57 //
58 // The ReportStatusCode Runtime service is in conflict with the UEFI 2.0 specificaiton
59 // Thus gEfiStatusCodeRuntimeProtocolGuid becomes a normal protocol in UEFI 2.0 systems
60 // It is only included if the EFI 1.10 with Tiano extensions is enabled for backward
61 // compatability
62 //
63 { &gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode, NULL, NULL, FALSE },
64 #endif
65 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
66 { NULL, (VOID **)NULL, NULL, NULL, FALSE }
67 };
68
69
70 EFI_STATUS
71 CoreAllEfiServicesAvailable (
72 VOID
73 )
74 /*++
75
76 Routine Description:
77 Return TRUE if all AP services are availible.
78
79 Arguments:
80 NONE
81
82 Returns:
83 EFI_SUCCESS - All AP services are available
84 EFI_NOT_FOUND - At least one AP service is not available
85
86 --*/
87 {
88 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
89
90 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
91 if (!Entry->Present) {
92 return EFI_NOT_FOUND;
93 }
94 }
95
96 return EFI_SUCCESS;
97 }
98
99
100 VOID
101 EFIAPI
102 GenericArchProtocolNotify (
103 IN EFI_EVENT Event,
104 IN VOID *Context
105 )
106 /*++
107
108 Routine Description:
109 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
110 This notify function is registered for every architectural protocol. This handler
111 updates mArchProtocol[] array entry with protocol instance data and sets it's
112 present flag to TRUE. If any constructor is required it is executed. The EFI
113 System Table headers are updated.
114
115 Arguments:
116
117 Event - The Event that is being processed, not used.
118
119 Context - Event Context, not used.
120
121 Returns:
122
123 None
124
125 --*/
126 {
127 EFI_STATUS Status;
128 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
129 VOID *Protocol;
130 BOOLEAN Found;
131 LIST_ENTRY *Link;
132 LIST_ENTRY TempLinkNode;
133
134 Found = FALSE;
135 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
136
137 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);
138 if (EFI_ERROR (Status)) {
139 continue;
140 }
141
142 Found = TRUE;
143 Entry->Present = TRUE;
144
145 //
146 // Update protocol global variable if one exists. Entry->Protocol points to a global variable
147 // if one exists in the DXE core for this Architectural Protocol
148 //
149 if (Entry->Protocol != NULL) {
150 *(Entry->Protocol) = Protocol;
151 }
152
153 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {
154 //
155 // Register the Core timer tick handler with the Timer AP
156 //
157 gTimer->RegisterHandler (gTimer, CoreTimerTick);
158 }
159
160 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {
161 //
162 // When runtime architectural protocol is available, updates CRC32 in the Debug Table
163 //
164 CoreUpdateDebugTableCrc32 ();
165
166 //
167 // Update the Runtime Architectural protocol with the template that the core was
168 // using so there would not need to be a dependency on the Runtime AP
169 //
170
171 //
172 // Copy all the registered Image to new gRuntime protocol
173 //
174 for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {
175 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
176 InsertTailList (&gRuntime->ImageHead, Link);
177 }
178 //
179 // Copy all the registered Event to new gRuntime protocol
180 //
181 for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {
182 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
183 InsertTailList (&gRuntime->EventHead, Link);
184 }
185
186 //
187 // Clean up gRuntimeTemplate
188 //
189 gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;
190 gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;
191 gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;
192 gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;
193 }
194 }
195
196 //
197 // It's over kill to do them all every time, but it saves a lot of code.
198 //
199 if (Found) {
200 CalculateEfiHdrCrc (&gRT->Hdr);
201 CalculateEfiHdrCrc (&gBS->Hdr);
202 CalculateEfiHdrCrc (&gST->Hdr);
203 CalculateEfiHdrCrc (&gDS->Hdr);
204 }
205 }
206
207
208
209 VOID
210 CoreNotifyOnArchProtocolInstallation (
211 VOID
212 )
213 /*++
214
215 Routine Description:
216 Creates an event that is fired everytime a Protocol of a specific type is installed
217
218 Arguments:
219 NONE
220
221 Returns:
222 NONE
223
224 --*/
225 {
226 EFI_STATUS Status;
227 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
228
229 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
230
231 //
232 // Create the event
233 //
234 Status = CoreCreateEvent (
235 EFI_EVENT_NOTIFY_SIGNAL,
236 EFI_TPL_CALLBACK,
237 GenericArchProtocolNotify,
238 NULL,
239 &Entry->Event
240 );
241 ASSERT_EFI_ERROR(Status);
242
243 //
244 // Register for protocol notifactions on this event
245 //
246 Status = CoreRegisterProtocolNotify (
247 Entry->ProtocolGuid,
248 Entry->Event,
249 &Entry->Registration
250 );
251 ASSERT_EFI_ERROR(Status);
252
253 }
254 }
255
256 //
257 // Following is needed to display missing architectural protocols in debug builds
258 //
259 typedef struct {
260 EFI_GUID *ProtocolGuid;
261 CHAR16 *GuidString;
262 } GUID_TO_STRING_PROTOCOL_ENTRY;
263
264 static const GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {
265 { &gEfiSecurityArchProtocolGuid, (CHAR16 *)L"Security" },
266 { &gEfiCpuArchProtocolGuid, (CHAR16 *)L"CPU" },
267 { &gEfiMetronomeArchProtocolGuid, (CHAR16 *)L"Metronome" },
268 { &gEfiTimerArchProtocolGuid, (CHAR16 *)L"Timer" },
269 { &gEfiBdsArchProtocolGuid, (CHAR16 *)L"Bds" },
270 { &gEfiWatchdogTimerArchProtocolGuid, (CHAR16 *)L"Watchdog Timer" },
271 { &gEfiRuntimeArchProtocolGuid, (CHAR16 *)L"Runtime" },
272 { &gEfiVariableArchProtocolGuid, (CHAR16 *)L"Variable" },
273 { &gEfiVariableWriteArchProtocolGuid, (CHAR16 *)L"Variable Write" },
274 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
275 { &gEfiCapsuleArchProtocolGuid, (CHAR16 *)L"Capsule" },
276 #endif
277 { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter" },
278 { &gEfiResetArchProtocolGuid, (CHAR16 *)L"Reset" },
279 // { &gEfiStatusCodeRuntimeProtocolGuid, (CHAR16 *)L"Status Code" },
280 { &gEfiRealTimeClockArchProtocolGuid, (CHAR16 *)L"Real Time Clock" }
281 };
282
283 VOID
284 CoreDisplayMissingArchProtocols (
285 VOID
286 )
287 /*++
288
289 Routine Description:
290 Displays Architectural protocols that were not loaded and are required for DXE core to function
291 Only used in Debug Builds
292
293 Arguments:
294 NONE
295
296 Returns:
297 NONE
298
299 --*/
300 {
301 const GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;
302 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
303
304 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
305 if (!Entry->Present) {
306 MissingEntry = MissingProtocols;
307 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {
308 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {
309 DEBUG ((EFI_D_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));
310 break;
311 }
312 }
313 }
314 }
315 }