]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
c140d9fc30fafc41eb9754612a833a300f3dfe3e
[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 **/
210 VOID
211 CoreNotifyOnProtocolEntryTable (
212 EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry
213 )
214 {
215 EFI_STATUS Status;
216
217 for (; Entry->ProtocolGuid != NULL; Entry++) {
218 //
219 // Create the event
220 //
221 Status = CoreCreateEvent (
222 EVT_NOTIFY_SIGNAL,
223 TPL_CALLBACK,
224 GenericProtocolNotify,
225 Entry,
226 &Entry->Event
227 );
228 ASSERT_EFI_ERROR(Status);
229
230 //
231 // Register for protocol notifactions on this event
232 //
233 Status = CoreRegisterProtocolNotify (
234 Entry->ProtocolGuid,
235 Entry->Event,
236 &Entry->Registration
237 );
238 ASSERT_EFI_ERROR(Status);
239 }
240 }
241
242 /**
243 Creates an events for the Architectural Protocols and the optional protocols
244 that are fired everytime a Protocol of a specific type is installed.
245
246 **/
247 VOID
248 CoreNotifyOnProtocolInstallation (
249 VOID
250 )
251 {
252 CoreNotifyOnProtocolEntryTable (mArchProtocols);
253 CoreNotifyOnProtocolEntryTable (mOptionalProtocols);
254 }
255
256
257 /**
258 Displays Architectural protocols that were not loaded and are required for DXE
259 core to function. Only used in Debug Builds.
260
261 **/
262 VOID
263 CoreDisplayMissingArchProtocols (
264 VOID
265 )
266 {
267 EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;
268 CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;
269
270 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
271 if (!Entry->Present) {
272 for (MissingEntry = mMissingProtocols; MissingEntry->ProtocolGuid != NULL; MissingEntry++) {
273 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {
274 DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));
275 break;
276 }
277 }
278 }
279 }
280 }