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