]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Clean up DxeCore to remove duplicate memory allocation & device path utility services...
[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 - 2008, 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 //
21 // DXE Core Global Variables for all of the Architectural Protocols.
22 // If a protocol is installed mArchProtocols[].Present will be TRUE.
23 //
24 // CoreNotifyOnArchProtocolInstallation () fills in mArchProtocols[].Event
25 // and mArchProtocols[].Registration as it creates events for every array
26 // entry.
27 //
28
29 ARCHITECTURAL_PROTOCOL_ENTRY mArchProtocols[] = {
30 { &gEfiSecurityArchProtocolGuid, (VOID **)&gSecurity, NULL, NULL, FALSE },
31 { &gEfiCpuArchProtocolGuid, (VOID **)&gCpu, NULL, NULL, FALSE },
32 { &gEfiMetronomeArchProtocolGuid, (VOID **)&gMetronome, NULL, NULL, FALSE },
33 { &gEfiTimerArchProtocolGuid, (VOID **)&gTimer, NULL, NULL, FALSE },
34 { &gEfiBdsArchProtocolGuid, (VOID **)&gBds, NULL, NULL, FALSE },
35 { &gEfiWatchdogTimerArchProtocolGuid, (VOID **)&gWatchdogTimer, NULL, NULL, FALSE },
36 { &gEfiRuntimeArchProtocolGuid, (VOID **)&gRuntime, NULL, NULL, FALSE },
37 { &gEfiVariableArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
38 { &gEfiVariableWriteArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
39 { &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
40 { &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
41 { &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
42 { &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
43 { NULL, (VOID **)NULL, NULL, NULL, FALSE }
44 };
45
46
47
48 /**
49 Return TRUE if all AP services are availible.
50
51 @retval EFI_SUCCESS All AP services are available
52 @retval EFI_NOT_FOUND At least one AP service is not available
53
54 **/
55 EFI_STATUS
56 CoreAllEfiServicesAvailable (
57 VOID
58 )
59 {
60 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
61
62 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
63 if (!Entry->Present) {
64 return EFI_NOT_FOUND;
65 }
66 }
67
68 return EFI_SUCCESS;
69 }
70
71
72 /**
73 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
74 This notify function is registered for every architectural protocol. This handler
75 updates mArchProtocol[] array entry with protocol instance data and sets it's
76 present flag to TRUE. If any constructor is required it is executed. The EFI
77 System Table headers are updated.
78
79 @param Event The Event that is being processed, not used.
80 @param Context Event Context, not used.
81
82 **/
83 VOID
84 EFIAPI
85 GenericArchProtocolNotify (
86 IN EFI_EVENT Event,
87 IN VOID *Context
88 )
89 {
90 EFI_STATUS Status;
91 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
92 VOID *Protocol;
93 BOOLEAN Found;
94 LIST_ENTRY *Link;
95 LIST_ENTRY TempLinkNode;
96
97 Found = FALSE;
98 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
99
100 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);
101 if (EFI_ERROR (Status)) {
102 continue;
103 }
104
105 Found = TRUE;
106 Entry->Present = TRUE;
107
108 //
109 // Update protocol global variable if one exists. Entry->Protocol points to a global variable
110 // if one exists in the DXE core for this Architectural Protocol
111 //
112 if (Entry->Protocol != NULL) {
113 *(Entry->Protocol) = Protocol;
114 }
115
116 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {
117 //
118 // Register the Core timer tick handler with the Timer AP
119 //
120 gTimer->RegisterHandler (gTimer, CoreTimerTick);
121 }
122
123 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {
124 //
125 // When runtime architectural protocol is available, updates CRC32 in the Debug Table
126 //
127 CoreUpdateDebugTableCrc32 ();
128
129 //
130 // Update the Runtime Architectural protocol with the template that the core was
131 // using so there would not need to be a dependency on the Runtime AP
132 //
133
134 //
135 // Copy all the registered Image to new gRuntime protocol
136 //
137 for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {
138 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
139 InsertTailList (&gRuntime->ImageHead, Link);
140 }
141 //
142 // Copy all the registered Event to new gRuntime protocol
143 //
144 for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {
145 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
146 InsertTailList (&gRuntime->EventHead, Link);
147 }
148
149 //
150 // Clean up gRuntimeTemplate
151 //
152 gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;
153 gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;
154 gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;
155 gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;
156 }
157 }
158
159 //
160 // It's over kill to do them all every time, but it saves a lot of code.
161 //
162 if (Found) {
163 CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);
164 CalculateEfiHdrCrc (&gBS->Hdr);
165 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
166 CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);
167 }
168 }
169
170
171
172 /**
173 Creates an event that is fired everytime a Protocol of a specific type is installed.
174
175 **/
176 VOID
177 CoreNotifyOnArchProtocolInstallation (
178 VOID
179 )
180 {
181 EFI_STATUS Status;
182 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
183
184 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
185
186 //
187 // Create the event
188 //
189 Status = CoreCreateEvent (
190 EVT_NOTIFY_SIGNAL,
191 TPL_CALLBACK,
192 GenericArchProtocolNotify,
193 NULL,
194 &Entry->Event
195 );
196 ASSERT_EFI_ERROR(Status);
197
198 //
199 // Register for protocol notifactions on this event
200 //
201 Status = CoreRegisterProtocolNotify (
202 Entry->ProtocolGuid,
203 Entry->Event,
204 &Entry->Registration
205 );
206 ASSERT_EFI_ERROR(Status);
207
208 }
209 }
210
211 //
212 // Following is needed to display missing architectural protocols in debug builds
213 //
214 typedef struct {
215 EFI_GUID *ProtocolGuid;
216 CHAR8 *GuidString;
217 } GUID_TO_STRING_PROTOCOL_ENTRY;
218
219 GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY MissingProtocols[] = {
220 { &gEfiSecurityArchProtocolGuid, "Security" },
221 { &gEfiCpuArchProtocolGuid, "CPU" },
222 { &gEfiMetronomeArchProtocolGuid, "Metronome" },
223 { &gEfiTimerArchProtocolGuid, "Timer" },
224 { &gEfiBdsArchProtocolGuid, "Bds" },
225 { &gEfiWatchdogTimerArchProtocolGuid, "Watchdog Timer" },
226 { &gEfiRuntimeArchProtocolGuid, "Runtime" },
227 { &gEfiVariableArchProtocolGuid, "Variable" },
228 { &gEfiVariableWriteArchProtocolGuid, "Variable Write" },
229 { &gEfiCapsuleArchProtocolGuid, "Capsule" },
230 { &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter" },
231 { &gEfiResetArchProtocolGuid, "Reset" },
232 { &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" }
233 };
234
235
236 /**
237 Displays Architectural protocols that were not loaded and are required for DXE
238 core to function. Only used in Debug Builds.
239
240 **/
241 VOID
242 CoreDisplayMissingArchProtocols (
243 VOID
244 )
245 {
246 CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;
247 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
248
249 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
250 if (!Entry->Present) {
251 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {
252 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {
253 DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));
254 break;
255 }
256 }
257 }
258 }
259 }