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