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 { &gEfiSecurity2ArchProtocolGuid
, (VOID
**)&gSecurity2
, NULL
, NULL
, FALSE
},
49 { &gEfiSmmBase2ProtocolGuid
, (VOID
**)&gSmmBase2
, NULL
, NULL
, FALSE
},
50 { NULL
, (VOID
**)NULL
, NULL
, NULL
, FALSE
}
54 // Following is needed to display missing architectural protocols in debug builds
57 EFI_GUID
*ProtocolGuid
;
59 } GUID_TO_STRING_PROTOCOL_ENTRY
;
61 GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols
[] = {
62 { &gEfiSecurityArchProtocolGuid
, "Security" },
63 { &gEfiCpuArchProtocolGuid
, "CPU" },
64 { &gEfiMetronomeArchProtocolGuid
, "Metronome" },
65 { &gEfiTimerArchProtocolGuid
, "Timer" },
66 { &gEfiBdsArchProtocolGuid
, "Bds" },
67 { &gEfiWatchdogTimerArchProtocolGuid
, "Watchdog Timer" },
68 { &gEfiRuntimeArchProtocolGuid
, "Runtime" },
69 { &gEfiVariableArchProtocolGuid
, "Variable" },
70 { &gEfiVariableWriteArchProtocolGuid
, "Variable Write" },
71 { &gEfiCapsuleArchProtocolGuid
, "Capsule" },
72 { &gEfiMonotonicCounterArchProtocolGuid
, "Monotonic Counter" },
73 { &gEfiResetArchProtocolGuid
, "Reset" },
74 { &gEfiRealTimeClockArchProtocolGuid
, "Real Time Clock" },
79 Return TRUE if all AP services are availible.
81 @retval EFI_SUCCESS All AP services are available
82 @retval EFI_NOT_FOUND At least one AP service is not available
86 CoreAllEfiServicesAvailable (
90 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
;
92 for (Entry
= mArchProtocols
; Entry
->ProtocolGuid
!= NULL
; Entry
++) {
93 if (!Entry
->Present
) {
102 Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
103 This notify function is registered for every architectural protocol. This handler
104 updates mArchProtocol[] array entry with protocol instance data and sets it's
105 present flag to TRUE. If any constructor is required it is executed. The EFI
106 System Table headers are updated.
108 @param Event The Event that is being processed, not used.
109 @param Context Event Context, not used.
114 GenericProtocolNotify (
120 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
;
123 LIST_ENTRY TempLinkNode
;
126 // Get Entry from Context
128 Entry
= (EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*)Context
;
131 // See if the expected protocol is present in the handle database
133 Status
= CoreLocateProtocol (Entry
->ProtocolGuid
, Entry
->Registration
, &Protocol
);
134 if (EFI_ERROR (Status
)) {
139 // Mark the protocol as present
141 Entry
->Present
= TRUE
;
144 // Update protocol global variable if one exists. Entry->Protocol points to a global variable
145 // if one exists in the DXE core for this Architectural Protocol
147 if (Entry
->Protocol
!= NULL
) {
148 *(Entry
->Protocol
) = Protocol
;
152 // Do special operations for Architectural Protocols
155 if (CompareGuid (Entry
->ProtocolGuid
, &gEfiTimerArchProtocolGuid
)) {
157 // Register the Core timer tick handler with the Timer AP
159 gTimer
->RegisterHandler (gTimer
, CoreTimerTick
);
162 if (CompareGuid (Entry
->ProtocolGuid
, &gEfiRuntimeArchProtocolGuid
)) {
164 // When runtime architectural protocol is available, updates CRC32 in the Debug Table
166 CoreUpdateDebugTableCrc32 ();
169 // Update the Runtime Architectural protocol with the template that the core was
170 // using so there would not need to be a dependency on the Runtime AP
174 // Copy all the registered Image to new gRuntime protocol
176 for (Link
= gRuntimeTemplate
.ImageHead
.ForwardLink
; Link
!= &gRuntimeTemplate
.ImageHead
; Link
= TempLinkNode
.ForwardLink
) {
177 CopyMem (&TempLinkNode
, Link
, sizeof(LIST_ENTRY
));
178 InsertTailList (&gRuntime
->ImageHead
, Link
);
181 // Copy all the registered Event to new gRuntime protocol
183 for (Link
= gRuntimeTemplate
.EventHead
.ForwardLink
; Link
!= &gRuntimeTemplate
.EventHead
; Link
= TempLinkNode
.ForwardLink
) {
184 CopyMem (&TempLinkNode
, Link
, sizeof(LIST_ENTRY
));
185 InsertTailList (&gRuntime
->EventHead
, Link
);
189 // Clean up gRuntimeTemplate
191 gRuntimeTemplate
.ImageHead
.ForwardLink
= &gRuntimeTemplate
.ImageHead
;
192 gRuntimeTemplate
.ImageHead
.BackLink
= &gRuntimeTemplate
.ImageHead
;
193 gRuntimeTemplate
.EventHead
.ForwardLink
= &gRuntimeTemplate
.EventHead
;
194 gRuntimeTemplate
.EventHead
.BackLink
= &gRuntimeTemplate
.EventHead
;
198 // It's over kill to do them all every time, but it saves a lot of code.
200 CalculateEfiHdrCrc (&gDxeCoreRT
->Hdr
);
201 CalculateEfiHdrCrc (&gBS
->Hdr
);
202 CalculateEfiHdrCrc (&gDxeCoreST
->Hdr
);
203 CalculateEfiHdrCrc (&gDxeCoreDS
->Hdr
);
207 Creates an event for each entry in a table that is fired everytime a Protocol
208 of a specific type is installed.
210 @param Entry Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.
214 CoreNotifyOnProtocolEntryTable (
215 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
220 for (; Entry
->ProtocolGuid
!= NULL
; Entry
++) {
224 Status
= CoreCreateEvent (
227 GenericProtocolNotify
,
231 ASSERT_EFI_ERROR(Status
);
234 // Register for protocol notifactions on this event
236 Status
= CoreRegisterProtocolNotify (
241 ASSERT_EFI_ERROR(Status
);
246 Creates an events for the Architectural Protocols and the optional protocols
247 that are fired everytime a Protocol of a specific type is installed.
251 CoreNotifyOnProtocolInstallation (
255 CoreNotifyOnProtocolEntryTable (mArchProtocols
);
256 CoreNotifyOnProtocolEntryTable (mOptionalProtocols
);
261 Displays Architectural protocols that were not loaded and are required for DXE
262 core to function. Only used in Debug Builds.
266 CoreDisplayMissingArchProtocols (
270 EFI_CORE_PROTOCOL_NOTIFY_ENTRY
*Entry
;
271 CONST GUID_TO_STRING_PROTOCOL_ENTRY
*MissingEntry
;
273 for (Entry
= mArchProtocols
; Entry
->ProtocolGuid
!= NULL
; Entry
++) {
274 if (!Entry
->Present
) {
275 for (MissingEntry
= mMissingProtocols
; MissingEntry
->ProtocolGuid
!= NULL
; MissingEntry
++) {
276 if (CompareGuid (Entry
->ProtocolGuid
, MissingEntry
->ProtocolGuid
)) {
277 DEBUG ((DEBUG_ERROR
, "\n%a Arch Protocol not present!!\n", MissingEntry
->GuidString
));