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.
6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
7 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
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.
20 // DXE Core Global Variables for all of the Architectural Protocols.
21 // If a protocol is installed mArchProtocols[].Present will be TRUE.
23 // CoreNotifyOnArchProtocolInstallation () fills in mArchProtocols[].Event
24 // and mArchProtocols[].Registration as it creates events for every array
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
}
45 // Optional protocols that the DXE Core will use if they are present
47 EFI_CORE_PROTOCOL_NOTIFY_ENTRY mOptionalProtocols
[] = {
48 { &gEfiSmmBase2ProtocolGuid
, (VOID
**)&gSmmBase2
, NULL
, NULL
, FALSE
},
49 { NULL
, (VOID
**)NULL
, NULL
, NULL
, FALSE
}
53 // Following is needed to display missing architectural protocols in debug builds
56 EFI_GUID
*ProtocolGuid
;
58 } GUID_TO_STRING_PROTOCOL_ENTRY
;
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" },
78 Return TRUE if all AP services are availible.
80 @retval EFI_SUCCESS All AP services are available
81 @retval EFI_NOT_FOUND At least one AP service is not available
85 CoreAllEfiServicesAvailable (
89 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
;
91 for (Entry
= mArchProtocols
; Entry
->ProtocolGuid
!= NULL
; Entry
++) {
92 if (!Entry
->Present
) {
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.
107 @param Event The Event that is being processed, not used.
108 @param Context Event Context, not used.
113 GenericProtocolNotify (
119 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
;
122 LIST_ENTRY TempLinkNode
;
125 // Get Entry from Context
127 Entry
= (EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*)Context
;
130 // See if the expected protocol is present in the handle database
132 Status
= CoreLocateProtocol (Entry
->ProtocolGuid
, Entry
->Registration
, &Protocol
);
133 if (EFI_ERROR (Status
)) {
138 // Mark the protocol as present
140 Entry
->Present
= TRUE
;
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
146 if (Entry
->Protocol
!= NULL
) {
147 *(Entry
->Protocol
) = Protocol
;
151 // Do special operations for Architectural Protocols
154 if (CompareGuid (Entry
->ProtocolGuid
, &gEfiTimerArchProtocolGuid
)) {
156 // Register the Core timer tick handler with the Timer AP
158 gTimer
->RegisterHandler (gTimer
, CoreTimerTick
);
161 if (CompareGuid (Entry
->ProtocolGuid
, &gEfiRuntimeArchProtocolGuid
)) {
163 // When runtime architectural protocol is available, updates CRC32 in the Debug Table
165 CoreUpdateDebugTableCrc32 ();
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
173 // Copy all the registered Image to new gRuntime protocol
175 for (Link
= gRuntimeTemplate
.ImageHead
.ForwardLink
; Link
!= &gRuntimeTemplate
.ImageHead
; Link
= TempLinkNode
.ForwardLink
) {
176 CopyMem (&TempLinkNode
, Link
, sizeof(LIST_ENTRY
));
177 InsertTailList (&gRuntime
->ImageHead
, Link
);
180 // Copy all the registered Event to new gRuntime protocol
182 for (Link
= gRuntimeTemplate
.EventHead
.ForwardLink
; Link
!= &gRuntimeTemplate
.EventHead
; Link
= TempLinkNode
.ForwardLink
) {
183 CopyMem (&TempLinkNode
, Link
, sizeof(LIST_ENTRY
));
184 InsertTailList (&gRuntime
->EventHead
, Link
);
188 // Clean up gRuntimeTemplate
190 gRuntimeTemplate
.ImageHead
.ForwardLink
= &gRuntimeTemplate
.ImageHead
;
191 gRuntimeTemplate
.ImageHead
.BackLink
= &gRuntimeTemplate
.ImageHead
;
192 gRuntimeTemplate
.EventHead
.ForwardLink
= &gRuntimeTemplate
.EventHead
;
193 gRuntimeTemplate
.EventHead
.BackLink
= &gRuntimeTemplate
.EventHead
;
197 // It's over kill to do them all every time, but it saves a lot of code.
199 CalculateEfiHdrCrc (&gDxeCoreRT
->Hdr
);
200 CalculateEfiHdrCrc (&gBS
->Hdr
);
201 CalculateEfiHdrCrc (&gDxeCoreST
->Hdr
);
202 CalculateEfiHdrCrc (&gDxeCoreDS
->Hdr
);
206 Creates an event for each entry in a table that is fired everytime a Protocol
207 of a specific type is installed.
209 @param Entry Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.
213 CoreNotifyOnProtocolEntryTable (
214 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
219 for (; Entry
->ProtocolGuid
!= NULL
; Entry
++) {
223 Status
= CoreCreateEvent (
226 GenericProtocolNotify
,
230 ASSERT_EFI_ERROR(Status
);
233 // Register for protocol notifactions on this event
235 Status
= CoreRegisterProtocolNotify (
240 ASSERT_EFI_ERROR(Status
);
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.
250 CoreNotifyOnProtocolInstallation (
254 CoreNotifyOnProtocolEntryTable (mArchProtocols
);
255 CoreNotifyOnProtocolEntryTable (mOptionalProtocols
);
260 Displays Architectural protocols that were not loaded and are required for DXE
261 core to function. Only used in Debug Builds.
265 CoreDisplayMissingArchProtocols (
269 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
;
270 CONST GUID_TO_STRING_PROTOCOL_ENTRY
*MissingEntry
;
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
));