]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Fixed some naming issues and update to the EDK II name. I also fixed an issue with...
[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 //
48 // UEFI 2.0 added support for Capsule services. DXE CIS ??? Added support for this AP
49 //
50 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE},
51 #endif
52 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
53 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
54 #if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
55 //
56 // The ReportStatusCode Runtime service is in conflict with the UEFI 2.0 specificaiton
57 // Thus gEfiStatusCodeRuntimeProtocolGuid becomes a normal protocol in UEFI 2.0 systems
58 // It is only included if the EFI 1.10 with Tiano extensions is enabled for backward
59 // compatability
60 //
61 { &gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode, NULL, NULL, FALSE },
62 #endif
63 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
64 { NULL, (VOID **)NULL, NULL, NULL, FALSE }
65 };
66
67
68 EFI_STATUS
69 CoreAllEfiServicesAvailable (
70 VOID
71 )
72 /*++
73
74 Routine Description:
75 Return TRUE if all AP services are availible.
76
77 Arguments:
78 NONE
79
80 Returns:
81 EFI_SUCCESS - All AP services are available
82 EFI_NOT_FOUND - At least one AP service is not available
83
84 --*/
85 {
86 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
87
88 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
89 if (!Entry->Present) {
90 return EFI_NOT_FOUND;
91 }
92 }
93
94 return EFI_SUCCESS;
95 }
96
97
98 VOID
99 EFIAPI
100 GenericArchProtocolNotify (
101 IN EFI_EVENT Event,
102 IN VOID *Context
103 )
104 /*++
105
106 Routine Description:
107 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
108 This notify function is registered for every architectural protocol. This handler
109 updates mArchProtocol[] array entry with protocol instance data and sets it's
110 present flag to TRUE. If any constructor is required it is executed. The EFI
111 System Table headers are updated.
112
113 Arguments:
114
115 Event - The Event that is being processed, not used.
116
117 Context - Event Context, not used.
118
119 Returns:
120
121 None
122
123 --*/
124 {
125 EFI_STATUS Status;
126 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
127 VOID *Protocol;
128 BOOLEAN Found;
129
130 Found = FALSE;
131 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
132
133 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);
134 if (EFI_ERROR (Status)) {
135 continue;
136 }
137
138 Found = TRUE;
139 Entry->Present = TRUE;
140
141 //
142 // Update protocol global variable if one exists. Entry->Protocol points to a global variable
143 // if one exists in the DXE core for this Architectural Protocol
144 //
145 if (Entry->Protocol != NULL) {
146 *(Entry->Protocol) = Protocol;
147 }
148
149 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {
150 //
151 // Register the Core timer tick handler with the Timer AP
152 //
153 gTimer->RegisterHandler (gTimer, CoreTimerTick);
154 }
155
156 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {
157 //
158 // When runtime architectural protocol is available, updates CRC32 in the Debug Table
159 //
160 CoreUpdateDebugTableCrc32 ();
161 }
162 }
163
164 //
165 // It's over kill to do them all every time, but it saves a lot of code.
166 //
167 if (Found) {
168 CalculateEfiHdrCrc (&gRT->Hdr);
169 CalculateEfiHdrCrc (&gBS->Hdr);
170 CalculateEfiHdrCrc (&gST->Hdr);
171 CalculateEfiHdrCrc (&gDS->Hdr);
172 }
173 }
174
175
176
177 VOID
178 CoreNotifyOnArchProtocolInstallation (
179 VOID
180 )
181 /*++
182
183 Routine Description:
184 Creates an event that is fired everytime a Protocol of a specific type is installed
185
186 Arguments:
187 NONE
188
189 Returns:
190 NONE
191
192 --*/
193 {
194 EFI_STATUS Status;
195 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
196
197 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
198
199 //
200 // Create the event
201 //
202 Status = CoreCreateEvent (
203 EFI_EVENT_NOTIFY_SIGNAL,
204 EFI_TPL_CALLBACK,
205 GenericArchProtocolNotify,
206 NULL,
207 &Entry->Event
208 );
209 ASSERT_EFI_ERROR(Status);
210
211 //
212 // Register for protocol notifactions on this event
213 //
214 Status = CoreRegisterProtocolNotify (
215 Entry->ProtocolGuid,
216 Entry->Event,
217 &Entry->Registration
218 );
219 ASSERT_EFI_ERROR(Status);
220
221 }
222 }
223
224 //
225 // Following is needed to display missing architectural protocols in debug builds
226 //
227 typedef struct {
228 EFI_GUID *ProtocolGuid;
229 CHAR16 *GuidString;
230 } GUID_TO_STRING_PROTOCOL_ENTRY;
231
232 static const GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {
233 { &gEfiSecurityArchProtocolGuid, (CHAR16 *)L"Security" },
234 { &gEfiCpuArchProtocolGuid, (CHAR16 *)L"CPU" },
235 { &gEfiMetronomeArchProtocolGuid, (CHAR16 *)L"Metronome" },
236 { &gEfiTimerArchProtocolGuid, (CHAR16 *)L"Timer" },
237 { &gEfiBdsArchProtocolGuid, (CHAR16 *)L"Bds" },
238 { &gEfiWatchdogTimerArchProtocolGuid, (CHAR16 *)L"Watchdog Timer" },
239 { &gEfiRuntimeArchProtocolGuid, (CHAR16 *)L"Runtime" },
240 { &gEfiVariableArchProtocolGuid, (CHAR16 *)L"Variable" },
241 { &gEfiVariableWriteArchProtocolGuid, (CHAR16 *)L"Variable Write" },
242 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
243 { &gEfiCapsuleArchProtocolGuid, (CHAR16 *)L"Capsule" },
244 #endif
245 { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter" },
246 { &gEfiResetArchProtocolGuid, (CHAR16 *)L"Reset" },
247 // { &gEfiStatusCodeRuntimeProtocolGuid, (CHAR16 *)L"Status Code" },
248 { &gEfiRealTimeClockArchProtocolGuid, (CHAR16 *)L"Real Time Clock" }
249 };
250
251 VOID
252 CoreDisplayMissingArchProtocols (
253 VOID
254 )
255 /*++
256
257 Routine Description:
258 Displays Architectural protocols that were not loaded and are required for DXE core to function
259 Only used in Debug Builds
260
261 Arguments:
262 NONE
263
264 Returns:
265 NONE
266
267 --*/
268 {
269 const GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;
270 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
271
272 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
273 if (!Entry->Present) {
274 MissingEntry = MissingProtocols;
275 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {
276 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {
277 DEBUG ((EFI_D_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));
278 break;
279 }
280 }
281 }
282 }
283 }