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