]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/DxeMain/DxeProtocolNotify.c
Update to fix minor coding style issues.
[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
52 @retval EFI_SUCCESS All AP services are available
53 @retval EFI_NOT_FOUND At least one AP service is not available
54
55 **/
56 EFI_STATUS
57 CoreAllEfiServicesAvailable (
58 VOID
59 )
60 {
61 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
62
63 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
64 if (!Entry->Present) {
65 return EFI_NOT_FOUND;
66 }
67 }
68
69 return EFI_SUCCESS;
70 }
71
72
73 /**
74 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
75 This notify function is registered for every architectural protocol. This handler
76 updates mArchProtocol[] array entry with protocol instance data and sets it's
77 present flag to TRUE. If any constructor is required it is executed. The EFI
78 System Table headers are updated.
79
80 @param Event The Event that is being processed, not used.
81 @param Context Event Context, not used.
82
83 **/
84 VOID
85 EFIAPI
86 GenericArchProtocolNotify (
87 IN EFI_EVENT Event,
88 IN VOID *Context
89 )
90 {
91 EFI_STATUS Status;
92 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
93 VOID *Protocol;
94 BOOLEAN Found;
95 LIST_ENTRY *Link;
96 LIST_ENTRY TempLinkNode;
97
98 Found = FALSE;
99 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
100
101 Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);
102 if (EFI_ERROR (Status)) {
103 continue;
104 }
105
106 Found = TRUE;
107 Entry->Present = TRUE;
108
109 //
110 // Update protocol global variable if one exists. Entry->Protocol points to a global variable
111 // if one exists in the DXE core for this Architectural Protocol
112 //
113 if (Entry->Protocol != NULL) {
114 *(Entry->Protocol) = Protocol;
115 }
116
117 if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {
118 //
119 // Register the Core timer tick handler with the Timer AP
120 //
121 gTimer->RegisterHandler (gTimer, CoreTimerTick);
122 }
123
124 if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {
125 //
126 // When runtime architectural protocol is available, updates CRC32 in the Debug Table
127 //
128 CoreUpdateDebugTableCrc32 ();
129
130 //
131 // Update the Runtime Architectural protocol with the template that the core was
132 // using so there would not need to be a dependency on the Runtime AP
133 //
134
135 //
136 // Copy all the registered Image to new gRuntime protocol
137 //
138 for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {
139 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
140 InsertTailList (&gRuntime->ImageHead, Link);
141 }
142 //
143 // Copy all the registered Event to new gRuntime protocol
144 //
145 for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {
146 CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
147 InsertTailList (&gRuntime->EventHead, Link);
148 }
149
150 //
151 // Clean up gRuntimeTemplate
152 //
153 gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;
154 gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;
155 gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;
156 gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;
157 }
158 }
159
160 //
161 // It's over kill to do them all every time, but it saves a lot of code.
162 //
163 if (Found) {
164 CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);
165 CalculateEfiHdrCrc (&gDxeCoreBS->Hdr);
166 CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
167 CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);
168 }
169 }
170
171
172
173
174 /**
175 Creates an event that is fired everytime a Protocol of a specific type is installed.
176
177 **/
178 VOID
179 CoreNotifyOnArchProtocolInstallation (
180 VOID
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 EVT_NOTIFY_SIGNAL,
193 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 { &gEfiCapsuleArchProtocolGuid, (CHAR16 *)L"Capsule" },
232 { &gEfiMonotonicCounterArchProtocolGuid, (CHAR16 *)L"Monotonic Counter" },
233 { &gEfiResetArchProtocolGuid, (CHAR16 *)L"Reset" },
234 // { &gEfiStatusCodeRuntimeProtocolGuid, (CHAR16 *)L"Status Code" },
235 { &gEfiRealTimeClockArchProtocolGuid, (CHAR16 *)L"Real Time Clock" }
236 };
237
238
239 /**
240 Displays Architectural protocols that were not loaded and are required for DXE
241 core to function. Only used in Debug Builds.
242
243 **/
244 VOID
245 CoreDisplayMissingArchProtocols (
246 VOID
247 )
248 {
249 const GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;
250 ARCHITECTURAL_PROTOCOL_ENTRY *Entry;
251
252 for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
253 if (!Entry->Present) {
254 MissingEntry = MissingProtocols;
255 for (MissingEntry = MissingProtocols; TRUE ; MissingEntry++) {
256 if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {
257 DEBUG ((DEBUG_ERROR, "\n%s Arch Protocol not present!!\n", MissingEntry->GuidString));
258 break;
259 }
260 }
261 }
262 }
263 }