2008-05-21 03:40:12 +02:00
|
|
|
/** @file
|
2008-04-09 09:07:50 +02:00
|
|
|
This file deals with Architecture Protocol (AP) registration in
|
|
|
|
the Dxe Core. The mArchProtocols[] array represents a list of
|
|
|
|
events that represent the Architectural Protocols.
|
|
|
|
|
2010-04-24 11:49:11 +02:00
|
|
|
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials
|
2007-07-04 12:51:54 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
#include "DxeMain.h"
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// DXE Core Global Variables for all of the Architectural Protocols.
|
|
|
|
// If a protocol is installed mArchProtocols[].Present will be TRUE.
|
|
|
|
//
|
|
|
|
// CoreNotifyOnArchProtocolInstallation () fills in mArchProtocols[].Event
|
|
|
|
// and mArchProtocols[].Registration as it creates events for every array
|
|
|
|
// entry.
|
|
|
|
//
|
2010-02-16 21:59:57 +01:00
|
|
|
EFI_CORE_PROTOCOL_NOTIFY_ENTRY mArchProtocols[] = {
|
|
|
|
{ &gEfiSecurityArchProtocolGuid, (VOID **)&gSecurity, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiCpuArchProtocolGuid, (VOID **)&gCpu, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiMetronomeArchProtocolGuid, (VOID **)&gMetronome, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiTimerArchProtocolGuid, (VOID **)&gTimer, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiBdsArchProtocolGuid, (VOID **)&gBds, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiWatchdogTimerArchProtocolGuid, (VOID **)&gWatchdogTimer, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiRuntimeArchProtocolGuid, (VOID **)&gRuntime, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiVariableArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiVariableWriteArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiCapsuleArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiMonotonicCounterArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiResetArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
|
|
|
|
{ &gEfiRealTimeClockArchProtocolGuid, (VOID **)NULL, NULL, NULL, FALSE },
|
|
|
|
{ NULL, (VOID **)NULL, NULL, NULL, FALSE }
|
|
|
|
};
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// Optional protocols that the DXE Core will use if they are present
|
|
|
|
//
|
|
|
|
EFI_CORE_PROTOCOL_NOTIFY_ENTRY mOptionalProtocols[] = {
|
2012-08-22 04:32:12 +02:00
|
|
|
{ &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },
|
2010-02-16 21:59:57 +01:00
|
|
|
{ &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },
|
|
|
|
{ NULL, (VOID **)NULL, NULL, NULL, FALSE }
|
2007-07-04 12:51:54 +02:00
|
|
|
};
|
|
|
|
|
2008-10-27 12:40:49 +01:00
|
|
|
//
|
|
|
|
// Following is needed to display missing architectural protocols in debug builds
|
|
|
|
//
|
|
|
|
typedef struct {
|
2010-02-16 21:59:57 +01:00
|
|
|
EFI_GUID *ProtocolGuid;
|
|
|
|
CHAR8 *GuidString;
|
2008-10-27 12:40:49 +01:00
|
|
|
} GUID_TO_STRING_PROTOCOL_ENTRY;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 03:52:15 +01:00
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {
|
2008-10-27 12:40:49 +01:00
|
|
|
{ &gEfiSecurityArchProtocolGuid, "Security" },
|
|
|
|
{ &gEfiCpuArchProtocolGuid, "CPU" },
|
|
|
|
{ &gEfiMetronomeArchProtocolGuid, "Metronome" },
|
|
|
|
{ &gEfiTimerArchProtocolGuid, "Timer" },
|
|
|
|
{ &gEfiBdsArchProtocolGuid, "Bds" },
|
|
|
|
{ &gEfiWatchdogTimerArchProtocolGuid, "Watchdog Timer" },
|
|
|
|
{ &gEfiRuntimeArchProtocolGuid, "Runtime" },
|
|
|
|
{ &gEfiVariableArchProtocolGuid, "Variable" },
|
|
|
|
{ &gEfiVariableWriteArchProtocolGuid, "Variable Write" },
|
|
|
|
{ &gEfiCapsuleArchProtocolGuid, "Capsule" },
|
|
|
|
{ &gEfiMonotonicCounterArchProtocolGuid, "Monotonic Counter" },
|
|
|
|
{ &gEfiResetArchProtocolGuid, "Reset" },
|
2010-02-16 21:59:57 +01:00
|
|
|
{ &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },
|
|
|
|
{ NULL, "" }
|
2008-10-27 12:40:49 +01:00
|
|
|
};
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Return TRUE if all AP services are availible.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_SUCCESS All AP services are available
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_NOT_FOUND At least one AP service is not available
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
CoreAllEfiServicesAvailable (
|
|
|
|
VOID
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
2010-02-16 21:59:57 +01:00
|
|
|
EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
|
|
|
|
if (!Entry->Present) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
|
|
|
|
This notify function is registered for every architectural protocol. This handler
|
|
|
|
updates mArchProtocol[] array entry with protocol instance data and sets it's
|
|
|
|
present flag to TRUE. If any constructor is required it is executed. The EFI
|
|
|
|
System Table headers are updated.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param Event The Event that is being processed, not used.
|
2008-05-09 09:08:30 +02:00
|
|
|
@param Context Event Context, not used.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2010-02-16 21:59:57 +01:00
|
|
|
GenericProtocolNotify (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2008-05-09 09:08:30 +02:00
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2010-02-16 21:59:57 +01:00
|
|
|
EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID *Protocol;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
LIST_ENTRY TempLinkNode;
|
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// Get Entry from Context
|
|
|
|
//
|
|
|
|
Entry = (EFI_CORE_PROTOCOL_NOTIFY_ENTRY *)Context;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// See if the expected protocol is present in the handle database
|
|
|
|
//
|
|
|
|
Status = CoreLocateProtocol (Entry->ProtocolGuid, Entry->Registration, &Protocol);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// Mark the protocol as present
|
|
|
|
//
|
|
|
|
Entry->Present = TRUE;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// Update protocol global variable if one exists. Entry->Protocol points to a global variable
|
|
|
|
// if one exists in the DXE core for this Architectural Protocol
|
|
|
|
//
|
|
|
|
if (Entry->Protocol != NULL) {
|
|
|
|
*(Entry->Protocol) = Protocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do special operations for Architectural Protocols
|
|
|
|
//
|
|
|
|
|
|
|
|
if (CompareGuid (Entry->ProtocolGuid, &gEfiTimerArchProtocolGuid)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2010-02-16 21:59:57 +01:00
|
|
|
// Register the Core timer tick handler with the Timer AP
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2010-02-16 21:59:57 +01:00
|
|
|
gTimer->RegisterHandler (gTimer, CoreTimerTick);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
if (CompareGuid (Entry->ProtocolGuid, &gEfiRuntimeArchProtocolGuid)) {
|
|
|
|
//
|
|
|
|
// When runtime architectural protocol is available, updates CRC32 in the Debug Table
|
|
|
|
//
|
|
|
|
CoreUpdateDebugTableCrc32 ();
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// Update the Runtime Architectural protocol with the template that the core was
|
|
|
|
// using so there would not need to be a dependency on the Runtime AP
|
|
|
|
//
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
//
|
|
|
|
// Copy all the registered Image to new gRuntime protocol
|
|
|
|
//
|
|
|
|
for (Link = gRuntimeTemplate.ImageHead.ForwardLink; Link != &gRuntimeTemplate.ImageHead; Link = TempLinkNode.ForwardLink) {
|
|
|
|
CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
|
|
|
|
InsertTailList (&gRuntime->ImageHead, Link);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Copy all the registered Event to new gRuntime protocol
|
|
|
|
//
|
|
|
|
for (Link = gRuntimeTemplate.EventHead.ForwardLink; Link != &gRuntimeTemplate.EventHead; Link = TempLinkNode.ForwardLink) {
|
|
|
|
CopyMem (&TempLinkNode, Link, sizeof(LIST_ENTRY));
|
|
|
|
InsertTailList (&gRuntime->EventHead, Link);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2010-02-16 21:59:57 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Clean up gRuntimeTemplate
|
|
|
|
//
|
|
|
|
gRuntimeTemplate.ImageHead.ForwardLink = &gRuntimeTemplate.ImageHead;
|
|
|
|
gRuntimeTemplate.ImageHead.BackLink = &gRuntimeTemplate.ImageHead;
|
|
|
|
gRuntimeTemplate.EventHead.ForwardLink = &gRuntimeTemplate.EventHead;
|
|
|
|
gRuntimeTemplate.EventHead.BackLink = &gRuntimeTemplate.EventHead;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// It's over kill to do them all every time, but it saves a lot of code.
|
|
|
|
//
|
2010-02-16 21:59:57 +01:00
|
|
|
CalculateEfiHdrCrc (&gDxeCoreRT->Hdr);
|
|
|
|
CalculateEfiHdrCrc (&gBS->Hdr);
|
|
|
|
CalculateEfiHdrCrc (&gDxeCoreST->Hdr);
|
|
|
|
CalculateEfiHdrCrc (&gDxeCoreDS->Hdr);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2010-02-16 21:59:57 +01:00
|
|
|
Creates an event for each entry in a table that is fired everytime a Protocol
|
|
|
|
of a specific type is installed.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2010-02-24 09:09:39 +01:00
|
|
|
@param Entry Pointer to EFI_CORE_PROTOCOL_NOTIFY_ENTRY.
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID
|
2010-02-16 21:59:57 +01:00
|
|
|
CoreNotifyOnProtocolEntryTable (
|
|
|
|
EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry
|
2007-07-04 12:51:54 +02:00
|
|
|
)
|
|
|
|
{
|
2010-02-16 21:59:57 +01:00
|
|
|
EFI_STATUS Status;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
for (; Entry->ProtocolGuid != NULL; Entry++) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Create the event
|
|
|
|
//
|
|
|
|
Status = CoreCreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_CALLBACK,
|
2010-02-16 21:59:57 +01:00
|
|
|
GenericProtocolNotify,
|
|
|
|
Entry,
|
2007-07-04 12:51:54 +02:00
|
|
|
&Entry->Event
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Register for protocol notifactions on this event
|
|
|
|
//
|
|
|
|
Status = CoreRegisterProtocolNotify (
|
|
|
|
Entry->ProtocolGuid,
|
|
|
|
Entry->Event,
|
|
|
|
&Entry->Registration
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
/**
|
|
|
|
Creates an events for the Architectural Protocols and the optional protocols
|
|
|
|
that are fired everytime a Protocol of a specific type is installed.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CoreNotifyOnProtocolInstallation (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CoreNotifyOnProtocolEntryTable (mArchProtocols);
|
|
|
|
CoreNotifyOnProtocolEntryTable (mOptionalProtocols);
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Displays Architectural protocols that were not loaded and are required for DXE
|
|
|
|
core to function. Only used in Debug Builds.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
VOID
|
|
|
|
CoreDisplayMissingArchProtocols (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2010-02-16 21:59:57 +01:00
|
|
|
EFI_CORE_PROTOCOL_NOTIFY_ENTRY *Entry;
|
2008-07-18 11:50:09 +02:00
|
|
|
CONST GUID_TO_STRING_PROTOCOL_ENTRY *MissingEntry;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2010-02-16 21:59:57 +01:00
|
|
|
for (Entry = mArchProtocols; Entry->ProtocolGuid != NULL; Entry++) {
|
|
|
|
if (!Entry->Present) {
|
|
|
|
for (MissingEntry = mMissingProtocols; MissingEntry->ProtocolGuid != NULL; MissingEntry++) {
|
2007-07-04 12:51:54 +02:00
|
|
|
if (CompareGuid (Entry->ProtocolGuid, MissingEntry->ProtocolGuid)) {
|
2008-08-18 10:40:52 +02:00
|
|
|
DEBUG ((DEBUG_ERROR, "\n%a Arch Protocol not present!!\n", MissingEntry->GuidString));
|
2007-07-04 12:51:54 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|