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