MdeModulePkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the MdeModulePkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:02 -08:00
committed by mergify[bot]
parent 7c7184e201
commit 1436aea4d5
994 changed files with 107608 additions and 101311 deletions

View File

@@ -15,15 +15,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Global stack used to evaluate dependency expressions
//
BOOLEAN *mDepexEvaluationStack = NULL;
BOOLEAN *mDepexEvaluationStackEnd = NULL;
BOOLEAN *mDepexEvaluationStackPointer = NULL;
BOOLEAN *mDepexEvaluationStack = NULL;
BOOLEAN *mDepexEvaluationStackEnd = NULL;
BOOLEAN *mDepexEvaluationStackPointer = NULL;
//
// Worker functions
//
/**
Grow size of the Depex stack
@@ -36,8 +35,8 @@ GrowDepexStack (
VOID
)
{
BOOLEAN *NewStack;
UINTN Size;
BOOLEAN *NewStack;
UINTN Size;
Size = DEPEX_STACK_SIZE_INCREMENT;
if (mDepexEvaluationStack != NULL) {
@@ -75,8 +74,6 @@ GrowDepexStack (
return EFI_SUCCESS;
}
/**
Push an element onto the Boolean Stack.
@@ -115,8 +112,6 @@ PushBool (
return EFI_SUCCESS;
}
/**
Pop an element from the Boolean stack.
@@ -146,8 +141,6 @@ PopBool (
return EFI_SUCCESS;
}
/**
Preprocess dependency expression and update DriverEntry to reflect the
state of Before, After, and SOR dependencies. If DriverEntry->Before
@@ -162,7 +155,7 @@ PopBool (
**/
EFI_STATUS
CorePreProcessDepex (
IN EFI_CORE_DRIVER_ENTRY *DriverEntry
IN EFI_CORE_DRIVER_ENTRY *DriverEntry
)
{
UINT8 *Iterator;
@@ -187,8 +180,6 @@ CorePreProcessDepex (
return EFI_SUCCESS;
}
/**
This is the POSTFIX version of the dependency evaluator. This code does
not need to handle Before or After, as it is not valid to call this
@@ -204,7 +195,7 @@ CorePreProcessDepex (
**/
BOOLEAN
CoreIsSchedulable (
IN EFI_CORE_DRIVER_ENTRY *DriverEntry
IN EFI_CORE_DRIVER_ENTRY *DriverEntry
)
{
EFI_STATUS Status;
@@ -214,7 +205,7 @@ CoreIsSchedulable (
EFI_GUID DriverGuid;
VOID *Interface;
Operator = FALSE;
Operator = FALSE;
Operator2 = FALSE;
if (DriverEntry->After || DriverEntry->Before) {
@@ -237,6 +228,7 @@ CoreIsSchedulable (
DEBUG ((DEBUG_DISPATCH, "FALSE\n RESULT = FALSE\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, "TRUE\n RESULT = TRUE\n"));
return TRUE;
}
@@ -247,7 +239,6 @@ CoreIsSchedulable (
//
mDepexEvaluationStackPointer = mDepexEvaluationStack;
Iterator = DriverEntry->Depex;
while (TRUE) {
@@ -264,158 +255,166 @@ CoreIsSchedulable (
// Look at the opcode of the dependency expression instruction.
//
switch (*Iterator) {
case EFI_DEP_BEFORE:
case EFI_DEP_AFTER:
//
// For a well-formed Dependency Expression, the code should never get here.
// The BEFORE and AFTER are processed prior to this routine's invocation.
// If the code flow arrives at this point, there was a BEFORE or AFTER
// that were not the first opcodes.
//
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n"));
ASSERT (FALSE);
case EFI_DEP_SOR:
//
// These opcodes can only appear once as the first opcode. If it is found
// at any other location, then the dependency expression evaluates to FALSE
//
if (Iterator != DriverEntry->Depex) {
DEBUG ((DEBUG_DISPATCH, " SOR\n"));
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected SOR opcode)\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, " SOR = Requested\n"));
//
// Otherwise, it is the first opcode and should be treated as a NOP.
//
break;
case EFI_DEP_BEFORE:
case EFI_DEP_AFTER:
//
// For a well-formed Dependency Expression, the code should never get here.
// The BEFORE and AFTER are processed prior to this routine's invocation.
// If the code flow arrives at this point, there was a BEFORE or AFTER
// that were not the first opcodes.
//
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n"));
ASSERT (FALSE);
case EFI_DEP_SOR:
//
// These opcodes can only appear once as the first opcode. If it is found
// at any other location, then the dependency expression evaluates to FALSE
//
if (Iterator != DriverEntry->Depex) {
DEBUG ((DEBUG_DISPATCH, " SOR\n"));
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected SOR opcode)\n"));
return FALSE;
}
case EFI_DEP_PUSH:
//
// Push operator is followed by a GUID. Test to see if the GUID protocol
// is installed and push the boolean result on the stack.
//
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
DEBUG ((DEBUG_DISPATCH, " SOR = Requested\n"));
//
// Otherwise, it is the first opcode and should be treated as a NOP.
//
break;
Status = CoreLocateProtocol (&DriverGuid, NULL, &Interface);
case EFI_DEP_PUSH:
//
// Push operator is followed by a GUID. Test to see if the GUID protocol
// is installed and push the boolean result on the stack.
//
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
Status = PushBool (FALSE);
} else {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
*Iterator = EFI_DEP_REPLACE_TRUE;
Status = CoreLocateProtocol (&DriverGuid, NULL, &Interface);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
Status = PushBool (FALSE);
} else {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
*Iterator = EFI_DEP_REPLACE_TRUE;
Status = PushBool (TRUE);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
case EFI_DEP_AND:
DEBUG ((DEBUG_DISPATCH, " AND\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(Operator && Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_OR:
DEBUG ((DEBUG_DISPATCH, " OR\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(Operator || Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_NOT:
DEBUG ((DEBUG_DISPATCH, " NOT\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(!Operator));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_TRUE:
DEBUG ((DEBUG_DISPATCH, " TRUE\n"));
Status = PushBool (TRUE);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
break;
case EFI_DEP_AND:
DEBUG ((DEBUG_DISPATCH, " AND\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_FALSE:
DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
Status = PushBool (FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
Status = PushBool ((BOOLEAN)(Operator && Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_END:
DEBUG ((DEBUG_DISPATCH, " END\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_OR:
DEBUG ((DEBUG_DISPATCH, " OR\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE"));
return Operator;
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_REPLACE_TRUE:
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
Status = PushBool ((BOOLEAN)(Operator || Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
Status = PushBool (TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_NOT:
DEBUG ((DEBUG_DISPATCH, " NOT\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
Status = PushBool ((BOOLEAN)(!Operator));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_TRUE:
DEBUG ((DEBUG_DISPATCH, " TRUE\n"));
Status = PushBool (TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_FALSE:
DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
Status = PushBool (FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_END:
DEBUG ((DEBUG_DISPATCH, " END\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE"));
return Operator;
case EFI_DEP_REPLACE_TRUE:
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
Status = PushBool (TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
default:
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n"));
goto Done;
default:
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n"));
goto Done;
}
//
@@ -432,5 +431,3 @@ CoreIsSchedulable (
Done:
return FALSE;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// DXE Core Global Variables for Protocols from PEI
//
EFI_HANDLE mDecompressHandle = NULL;
EFI_HANDLE mDecompressHandle = NULL;
//
// DXE Core globals for Architecture Protocols
@@ -27,18 +27,18 @@ EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *gWatchdogTimer = NULL;
//
// DXE Core globals for optional protocol dependencies
//
EFI_SMM_BASE2_PROTOCOL *gSmmBase2 = NULL;
EFI_SMM_BASE2_PROTOCOL *gSmmBase2 = NULL;
//
// DXE Core Global used to update core loaded image protocol handle
//
EFI_GUID *gDxeCoreFileName;
EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
EFI_GUID *gDxeCoreFileName;
EFI_LOADED_IMAGE_PROTOCOL *gDxeCoreLoadedImage;
//
// DXE Core Module Variables
//
EFI_BOOT_SERVICES mBootServices = {
EFI_BOOT_SERVICES mBootServices = {
{
EFI_BOOT_SERVICES_SIGNATURE, // Signature
EFI_BOOT_SERVICES_REVISION, // Revision
@@ -46,81 +46,81 @@ EFI_BOOT_SERVICES mBootServices = {
0, // CRC32
0 // Reserved
},
(EFI_RAISE_TPL) CoreRaiseTpl, // RaiseTPL
(EFI_RESTORE_TPL) CoreRestoreTpl, // RestoreTPL
(EFI_ALLOCATE_PAGES) CoreAllocatePages, // AllocatePages
(EFI_FREE_PAGES) CoreFreePages, // FreePages
(EFI_GET_MEMORY_MAP) CoreGetMemoryMap, // GetMemoryMap
(EFI_ALLOCATE_POOL) CoreAllocatePool, // AllocatePool
(EFI_FREE_POOL) CoreFreePool, // FreePool
(EFI_CREATE_EVENT) CoreCreateEvent, // CreateEvent
(EFI_SET_TIMER) CoreSetTimer, // SetTimer
(EFI_WAIT_FOR_EVENT) CoreWaitForEvent, // WaitForEvent
(EFI_SIGNAL_EVENT) CoreSignalEvent, // SignalEvent
(EFI_CLOSE_EVENT) CoreCloseEvent, // CloseEvent
(EFI_CHECK_EVENT) CoreCheckEvent, // CheckEvent
(EFI_INSTALL_PROTOCOL_INTERFACE) CoreInstallProtocolInterface, // InstallProtocolInterface
(EFI_REINSTALL_PROTOCOL_INTERFACE) CoreReinstallProtocolInterface, // ReinstallProtocolInterface
(EFI_UNINSTALL_PROTOCOL_INTERFACE) CoreUninstallProtocolInterface, // UninstallProtocolInterface
(EFI_HANDLE_PROTOCOL) CoreHandleProtocol, // HandleProtocol
(VOID *) NULL, // Reserved
(EFI_REGISTER_PROTOCOL_NOTIFY) CoreRegisterProtocolNotify, // RegisterProtocolNotify
(EFI_LOCATE_HANDLE) CoreLocateHandle, // LocateHandle
(EFI_LOCATE_DEVICE_PATH) CoreLocateDevicePath, // LocateDevicePath
(EFI_INSTALL_CONFIGURATION_TABLE) CoreInstallConfigurationTable, // InstallConfigurationTable
(EFI_IMAGE_LOAD) CoreLoadImage, // LoadImage
(EFI_IMAGE_START) CoreStartImage, // StartImage
(EFI_EXIT) CoreExit, // Exit
(EFI_IMAGE_UNLOAD) CoreUnloadImage, // UnloadImage
(EFI_EXIT_BOOT_SERVICES) CoreExitBootServices, // ExitBootServices
(EFI_GET_NEXT_MONOTONIC_COUNT) CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount
(EFI_STALL) CoreStall, // Stall
(EFI_SET_WATCHDOG_TIMER) CoreSetWatchdogTimer, // SetWatchdogTimer
(EFI_CONNECT_CONTROLLER) CoreConnectController, // ConnectController
(EFI_DISCONNECT_CONTROLLER) CoreDisconnectController, // DisconnectController
(EFI_OPEN_PROTOCOL) CoreOpenProtocol, // OpenProtocol
(EFI_CLOSE_PROTOCOL) CoreCloseProtocol, // CloseProtocol
(EFI_OPEN_PROTOCOL_INFORMATION) CoreOpenProtocolInformation, // OpenProtocolInformation
(EFI_PROTOCOLS_PER_HANDLE) CoreProtocolsPerHandle, // ProtocolsPerHandle
(EFI_LOCATE_HANDLE_BUFFER) CoreLocateHandleBuffer, // LocateHandleBuffer
(EFI_LOCATE_PROTOCOL) CoreLocateProtocol, // LocateProtocol
(EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces
(EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces
(EFI_CALCULATE_CRC32) CoreEfiNotAvailableYetArg3, // CalculateCrc32
(EFI_COPY_MEM) CopyMem, // CopyMem
(EFI_SET_MEM) SetMem, // SetMem
(EFI_CREATE_EVENT_EX) CoreCreateEventEx // CreateEventEx
(EFI_RAISE_TPL)CoreRaiseTpl, // RaiseTPL
(EFI_RESTORE_TPL)CoreRestoreTpl, // RestoreTPL
(EFI_ALLOCATE_PAGES)CoreAllocatePages, // AllocatePages
(EFI_FREE_PAGES)CoreFreePages, // FreePages
(EFI_GET_MEMORY_MAP)CoreGetMemoryMap, // GetMemoryMap
(EFI_ALLOCATE_POOL)CoreAllocatePool, // AllocatePool
(EFI_FREE_POOL)CoreFreePool, // FreePool
(EFI_CREATE_EVENT)CoreCreateEvent, // CreateEvent
(EFI_SET_TIMER)CoreSetTimer, // SetTimer
(EFI_WAIT_FOR_EVENT)CoreWaitForEvent, // WaitForEvent
(EFI_SIGNAL_EVENT)CoreSignalEvent, // SignalEvent
(EFI_CLOSE_EVENT)CoreCloseEvent, // CloseEvent
(EFI_CHECK_EVENT)CoreCheckEvent, // CheckEvent
(EFI_INSTALL_PROTOCOL_INTERFACE)CoreInstallProtocolInterface, // InstallProtocolInterface
(EFI_REINSTALL_PROTOCOL_INTERFACE)CoreReinstallProtocolInterface, // ReinstallProtocolInterface
(EFI_UNINSTALL_PROTOCOL_INTERFACE)CoreUninstallProtocolInterface, // UninstallProtocolInterface
(EFI_HANDLE_PROTOCOL)CoreHandleProtocol, // HandleProtocol
(VOID *)NULL, // Reserved
(EFI_REGISTER_PROTOCOL_NOTIFY)CoreRegisterProtocolNotify, // RegisterProtocolNotify
(EFI_LOCATE_HANDLE)CoreLocateHandle, // LocateHandle
(EFI_LOCATE_DEVICE_PATH)CoreLocateDevicePath, // LocateDevicePath
(EFI_INSTALL_CONFIGURATION_TABLE)CoreInstallConfigurationTable, // InstallConfigurationTable
(EFI_IMAGE_LOAD)CoreLoadImage, // LoadImage
(EFI_IMAGE_START)CoreStartImage, // StartImage
(EFI_EXIT)CoreExit, // Exit
(EFI_IMAGE_UNLOAD)CoreUnloadImage, // UnloadImage
(EFI_EXIT_BOOT_SERVICES)CoreExitBootServices, // ExitBootServices
(EFI_GET_NEXT_MONOTONIC_COUNT)CoreEfiNotAvailableYetArg1, // GetNextMonotonicCount
(EFI_STALL)CoreStall, // Stall
(EFI_SET_WATCHDOG_TIMER)CoreSetWatchdogTimer, // SetWatchdogTimer
(EFI_CONNECT_CONTROLLER)CoreConnectController, // ConnectController
(EFI_DISCONNECT_CONTROLLER)CoreDisconnectController, // DisconnectController
(EFI_OPEN_PROTOCOL)CoreOpenProtocol, // OpenProtocol
(EFI_CLOSE_PROTOCOL)CoreCloseProtocol, // CloseProtocol
(EFI_OPEN_PROTOCOL_INFORMATION)CoreOpenProtocolInformation, // OpenProtocolInformation
(EFI_PROTOCOLS_PER_HANDLE)CoreProtocolsPerHandle, // ProtocolsPerHandle
(EFI_LOCATE_HANDLE_BUFFER)CoreLocateHandleBuffer, // LocateHandleBuffer
(EFI_LOCATE_PROTOCOL)CoreLocateProtocol, // LocateProtocol
(EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces
(EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)CoreUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces
(EFI_CALCULATE_CRC32)CoreEfiNotAvailableYetArg3, // CalculateCrc32
(EFI_COPY_MEM)CopyMem, // CopyMem
(EFI_SET_MEM)SetMem, // SetMem
(EFI_CREATE_EVENT_EX)CoreCreateEventEx // CreateEventEx
};
EFI_DXE_SERVICES mDxeServices = {
EFI_DXE_SERVICES mDxeServices = {
{
DXE_SERVICES_SIGNATURE, // Signature
DXE_SERVICES_REVISION, // Revision
sizeof (DXE_SERVICES), // HeaderSize
0, // CRC32
0 // Reserved
0, // CRC32
0 // Reserved
},
(EFI_ADD_MEMORY_SPACE) CoreAddMemorySpace, // AddMemorySpace
(EFI_ALLOCATE_MEMORY_SPACE) CoreAllocateMemorySpace, // AllocateMemorySpace
(EFI_FREE_MEMORY_SPACE) CoreFreeMemorySpace, // FreeMemorySpace
(EFI_REMOVE_MEMORY_SPACE) CoreRemoveMemorySpace, // RemoveMemorySpace
(EFI_GET_MEMORY_SPACE_DESCRIPTOR) CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor
(EFI_SET_MEMORY_SPACE_ATTRIBUTES) CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes
(EFI_GET_MEMORY_SPACE_MAP) CoreGetMemorySpaceMap, // GetMemorySpaceMap
(EFI_ADD_IO_SPACE) CoreAddIoSpace, // AddIoSpace
(EFI_ALLOCATE_IO_SPACE) CoreAllocateIoSpace, // AllocateIoSpace
(EFI_FREE_IO_SPACE) CoreFreeIoSpace, // FreeIoSpace
(EFI_REMOVE_IO_SPACE) CoreRemoveIoSpace, // RemoveIoSpace
(EFI_GET_IO_SPACE_DESCRIPTOR) CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor
(EFI_GET_IO_SPACE_MAP) CoreGetIoSpaceMap, // GetIoSpaceMap
(EFI_DISPATCH) CoreDispatcher, // Dispatch
(EFI_SCHEDULE) CoreSchedule, // Schedule
(EFI_TRUST) CoreTrust, // Trust
(EFI_PROCESS_FIRMWARE_VOLUME) CoreProcessFirmwareVolume, // ProcessFirmwareVolume
(EFI_ADD_MEMORY_SPACE)CoreAddMemorySpace, // AddMemorySpace
(EFI_ALLOCATE_MEMORY_SPACE)CoreAllocateMemorySpace, // AllocateMemorySpace
(EFI_FREE_MEMORY_SPACE)CoreFreeMemorySpace, // FreeMemorySpace
(EFI_REMOVE_MEMORY_SPACE)CoreRemoveMemorySpace, // RemoveMemorySpace
(EFI_GET_MEMORY_SPACE_DESCRIPTOR)CoreGetMemorySpaceDescriptor, // GetMemorySpaceDescriptor
(EFI_SET_MEMORY_SPACE_ATTRIBUTES)CoreSetMemorySpaceAttributes, // SetMemorySpaceAttributes
(EFI_GET_MEMORY_SPACE_MAP)CoreGetMemorySpaceMap, // GetMemorySpaceMap
(EFI_ADD_IO_SPACE)CoreAddIoSpace, // AddIoSpace
(EFI_ALLOCATE_IO_SPACE)CoreAllocateIoSpace, // AllocateIoSpace
(EFI_FREE_IO_SPACE)CoreFreeIoSpace, // FreeIoSpace
(EFI_REMOVE_IO_SPACE)CoreRemoveIoSpace, // RemoveIoSpace
(EFI_GET_IO_SPACE_DESCRIPTOR)CoreGetIoSpaceDescriptor, // GetIoSpaceDescriptor
(EFI_GET_IO_SPACE_MAP)CoreGetIoSpaceMap, // GetIoSpaceMap
(EFI_DISPATCH)CoreDispatcher, // Dispatch
(EFI_SCHEDULE)CoreSchedule, // Schedule
(EFI_TRUST)CoreTrust, // Trust
(EFI_PROCESS_FIRMWARE_VOLUME)CoreProcessFirmwareVolume, // ProcessFirmwareVolume
(EFI_SET_MEMORY_SPACE_CAPABILITIES)CoreSetMemorySpaceCapabilities, // SetMemorySpaceCapabilities
};
EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
{
EFI_SYSTEM_TABLE_SIGNATURE, // Signature
EFI_SYSTEM_TABLE_REVISION, // Revision
@@ -142,7 +142,7 @@ EFI_SYSTEM_TABLE mEfiSystemTableTemplate = {
NULL // ConfigurationTable
};
EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
{
EFI_RUNTIME_SERVICES_SIGNATURE, // Signature
EFI_RUNTIME_SERVICES_REVISION, // Revision
@@ -150,23 +150,23 @@ EFI_RUNTIME_SERVICES mEfiRuntimeServicesTableTemplate = {
0, // CRC32
0 // Reserved
},
(EFI_GET_TIME) CoreEfiNotAvailableYetArg2, // GetTime
(EFI_SET_TIME) CoreEfiNotAvailableYetArg1, // SetTime
(EFI_GET_WAKEUP_TIME) CoreEfiNotAvailableYetArg3, // GetWakeupTime
(EFI_SET_WAKEUP_TIME) CoreEfiNotAvailableYetArg2, // SetWakeupTime
(EFI_SET_VIRTUAL_ADDRESS_MAP) CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap
(EFI_CONVERT_POINTER) CoreEfiNotAvailableYetArg2, // ConvertPointer
(EFI_GET_VARIABLE) CoreEfiNotAvailableYetArg5, // GetVariable
(EFI_GET_NEXT_VARIABLE_NAME) CoreEfiNotAvailableYetArg3, // GetNextVariableName
(EFI_SET_VARIABLE) CoreEfiNotAvailableYetArg5, // SetVariable
(EFI_GET_NEXT_HIGH_MONO_COUNT) CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount
(EFI_RESET_SYSTEM) CoreEfiNotAvailableYetArg4, // ResetSystem
(EFI_UPDATE_CAPSULE) CoreEfiNotAvailableYetArg3, // UpdateCapsule
(EFI_QUERY_CAPSULE_CAPABILITIES) CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities
(EFI_QUERY_VARIABLE_INFO) CoreEfiNotAvailableYetArg4 // QueryVariableInfo
(EFI_GET_TIME)CoreEfiNotAvailableYetArg2, // GetTime
(EFI_SET_TIME)CoreEfiNotAvailableYetArg1, // SetTime
(EFI_GET_WAKEUP_TIME)CoreEfiNotAvailableYetArg3, // GetWakeupTime
(EFI_SET_WAKEUP_TIME)CoreEfiNotAvailableYetArg2, // SetWakeupTime
(EFI_SET_VIRTUAL_ADDRESS_MAP)CoreEfiNotAvailableYetArg4, // SetVirtualAddressMap
(EFI_CONVERT_POINTER)CoreEfiNotAvailableYetArg2, // ConvertPointer
(EFI_GET_VARIABLE)CoreEfiNotAvailableYetArg5, // GetVariable
(EFI_GET_NEXT_VARIABLE_NAME)CoreEfiNotAvailableYetArg3, // GetNextVariableName
(EFI_SET_VARIABLE)CoreEfiNotAvailableYetArg5, // SetVariable
(EFI_GET_NEXT_HIGH_MONO_COUNT)CoreEfiNotAvailableYetArg1, // GetNextHighMonotonicCount
(EFI_RESET_SYSTEM)CoreEfiNotAvailableYetArg4, // ResetSystem
(EFI_UPDATE_CAPSULE)CoreEfiNotAvailableYetArg3, // UpdateCapsule
(EFI_QUERY_CAPSULE_CAPABILITIES)CoreEfiNotAvailableYetArg4, // QueryCapsuleCapabilities
(EFI_QUERY_VARIABLE_INFO)CoreEfiNotAvailableYetArg4 // QueryVariableInfo
};
EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.ImageHead),
INITIALIZE_LIST_HEAD_VARIABLE (gRuntimeTemplate.EventHead),
@@ -184,24 +184,24 @@ EFI_RUNTIME_ARCH_PROTOCOL gRuntimeTemplate = {
FALSE
};
EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;
EFI_RUNTIME_ARCH_PROTOCOL *gRuntime = &gRuntimeTemplate;
//
// DXE Core Global Variables for the EFI System Table, Boot Services Table,
// DXE Services Table, and Runtime Services Table
//
EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
EFI_DXE_SERVICES *gDxeCoreDS = &mDxeServices;
EFI_SYSTEM_TABLE *gDxeCoreST = NULL;
//
// For debug initialize gDxeCoreRT to template. gDxeCoreRT must be allocated from RT memory
// but gDxeCoreRT is used for ASSERT () and DEBUG () type macros so lets give it
// a value that will not cause debug infrastructure to crash early on.
//
EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
EFI_RUNTIME_SERVICES *gDxeCoreRT = &mEfiRuntimeServicesTableTemplate;
EFI_HANDLE gDxeCoreImageHandle = NULL;
BOOLEAN gMemoryMapTerminated = FALSE;
BOOLEAN gMemoryMapTerminated = FALSE;
//
// EFI Decompress Protocol
@@ -215,7 +215,7 @@ EFI_DECOMPRESS_PROTOCOL gEfiDecompress = {
// For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load
// Runtime code&boot time code
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = {0, 0};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoadModuleAtFixAddressConfigurationTable = { 0, 0 };
// Main entry point to the DXE Core
//
@@ -231,7 +231,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE gLoa
VOID
EFIAPI
DxeMain (
IN VOID *HobStart
IN VOID *HobStart
)
{
EFI_STATUS Status;
@@ -248,10 +248,11 @@ DxeMain (
// Setup the default exception handlers
//
VectorInfoList = NULL;
GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
if (GuidHob != NULL) {
VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));
VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));
}
Status = InitializeCpuExceptionHandlersEx (VectorInfoList, NULL);
ASSERT_EFI_ERROR (Status);
@@ -295,7 +296,7 @@ DxeMain (
// Call constructor for all libraries
//
ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);
PERF_CROSSMODULE_END ("PEI");
PERF_CROSSMODULE_END ("PEI");
PERF_CROSSMODULE_BEGIN ("DXE");
//
@@ -303,22 +304,28 @@ DxeMain (
// CoreInitializeMemoryServices()), now that library constructors have
// executed.
//
DEBUG ((DEBUG_INFO, "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",
__FUNCTION__, MemoryBaseAddress, MemoryLength));
DEBUG ((
DEBUG_INFO,
"%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",
__FUNCTION__,
MemoryBaseAddress,
MemoryLength
));
//
// Report DXE Core image information to the PE/COFF Extra Action Library
//
ZeroMem (&ImageContext, sizeof (ImageContext));
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;
ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*)(UINTN)ImageContext.ImageAddress);
ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID*)(UINTN)ImageContext.ImageAddress);
Status = PeCoffLoaderGetEntryPoint ((VOID*)(UINTN)ImageContext.ImageAddress, &EntryPoint);
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;
ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
ImageContext.SizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)ImageContext.ImageAddress);
Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)ImageContext.ImageAddress, &EntryPoint);
if (Status == EFI_SUCCESS) {
ImageContext.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)EntryPoint;
}
ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
ImageContext.Handle = (VOID *)(UINTN)gDxeCoreLoadedImage->ImageBase;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
PeCoffLoaderRelocateImageExtraAction (&ImageContext);
//
@@ -344,10 +351,11 @@ DxeMain (
// Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI
// Code and Tseg base to load SMM driver.
//
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);
ASSERT_EFI_ERROR (Status);
}
//
// Report Status Code here for DXE_ENTRY_POINT once it is available
//
@@ -371,56 +379,61 @@ DxeMain (
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));
DEBUG_CODE_BEGIN ();
EFI_PEI_HOB_POINTERS Hob;
EFI_PEI_HOB_POINTERS Hob;
for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \
Hob.MemoryAllocation->AllocDescriptor.MemoryType, \
Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \
Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));
}
for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \
Hob.MemoryAllocation->AllocDescriptor.MemoryType, \
Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress, \
Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1
));
}
for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"FV Hob 0x%0lx - 0x%0lx\n",
Hob.FirmwareVolume->BaseAddress,
Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1
));
} else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"FV2 Hob 0x%0lx - 0x%0lx\n",
Hob.FirmwareVolume2->BaseAddress,
Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1
));
}
for (Hob.Raw = HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"FV Hob 0x%0lx - 0x%0lx\n",
Hob.FirmwareVolume->BaseAddress,
Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume->Length - 1
));
} else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"FV2 Hob 0x%0lx - 0x%0lx\n",
Hob.FirmwareVolume2->BaseAddress,
Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1
));
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
" %g - %g\n",
&Hob.FirmwareVolume2->FvName,
&Hob.FirmwareVolume2->FileName
));
} else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",
Hob.FirmwareVolume3->BaseAddress,
Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,
Hob.FirmwareVolume3->AuthenticationStatus,
Hob.FirmwareVolume3->ExtractedFv
));
if (Hob.FirmwareVolume3->ExtractedFv) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
" %g - %g\n",
&Hob.FirmwareVolume2->FvName,
&Hob.FirmwareVolume2->FileName
&Hob.FirmwareVolume3->FvName,
&Hob.FirmwareVolume3->FileName
));
} else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"FV3 Hob 0x%0lx - 0x%0lx - 0x%x - 0x%x\n",
Hob.FirmwareVolume3->BaseAddress,
Hob.FirmwareVolume3->BaseAddress + Hob.FirmwareVolume3->Length - 1,
Hob.FirmwareVolume3->AuthenticationStatus,
Hob.FirmwareVolume3->ExtractedFv
));
if (Hob.FirmwareVolume3->ExtractedFv) {
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
" %g - %g\n",
&Hob.FirmwareVolume3->FvName,
&Hob.FirmwareVolume3->FileName
));
}
}
}
}
DEBUG_CODE_END ();
//
@@ -440,16 +453,17 @@ DxeMain (
//
GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
if (GuidHob != NULL) {
VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));
VectorInfo = VectorInfoList;
Index = 1;
VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *)(GET_GUID_HOB_DATA (GuidHob));
VectorInfo = VectorInfoList;
Index = 1;
while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
VectorInfo ++;
Index ++;
VectorInfo++;
Index++;
}
VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *) VectorInfoList);
VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *)VectorInfoList);
ASSERT (VectorInfo != NULL);
Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) VectorInfo);
Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *)VectorInfo);
ASSERT_EFI_ERROR (Status);
}
@@ -470,7 +484,8 @@ DxeMain (
//
Status = CoreInstallMultipleProtocolInterfaces (
&mDecompressHandle,
&gEfiDecompressProtocolGuid, &gEfiDecompress,
&gEfiDecompressProtocolGuid,
&gEfiDecompress,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -511,7 +526,7 @@ DxeMain (
// Display Architectural protocols that were not loaded if this is DEBUG build
//
DEBUG_CODE_BEGIN ();
CoreDisplayMissingArchProtocols ();
CoreDisplayMissingArchProtocols ();
DEBUG_CODE_END ();
//
@@ -519,14 +534,14 @@ DxeMain (
// evaluated to false if this is a debug build
//
DEBUG_CODE_BEGIN ();
CoreDisplayDiscoveredNotDispatched ();
CoreDisplayDiscoveredNotDispatched ();
DEBUG_CODE_END ();
//
// Assert if the Architectural Protocols are not present.
//
Status = CoreAllEfiServicesAvailable ();
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
//
// Report Status code that some Architectural Protocols are not present.
//
@@ -535,6 +550,7 @@ DxeMain (
(EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)
);
}
ASSERT_EFI_ERROR (Status);
//
@@ -559,9 +575,6 @@ DxeMain (
UNREACHABLE ();
}
/**
Place holder function until all the Boot Services and Runtime Services are
available.
@@ -574,7 +587,7 @@ DxeMain (
EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg1 (
UINTN Arg1
UINTN Arg1
)
{
//
@@ -586,7 +599,6 @@ CoreEfiNotAvailableYetArg1 (
return EFI_NOT_AVAILABLE_YET;
}
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -599,8 +611,8 @@ CoreEfiNotAvailableYetArg1 (
EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg2 (
UINTN Arg1,
UINTN Arg2
UINTN Arg1,
UINTN Arg2
)
{
//
@@ -612,7 +624,6 @@ CoreEfiNotAvailableYetArg2 (
return EFI_NOT_AVAILABLE_YET;
}
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -626,9 +637,9 @@ CoreEfiNotAvailableYetArg2 (
EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg3 (
UINTN Arg1,
UINTN Arg2,
UINTN Arg3
UINTN Arg1,
UINTN Arg2,
UINTN Arg3
)
{
//
@@ -640,7 +651,6 @@ CoreEfiNotAvailableYetArg3 (
return EFI_NOT_AVAILABLE_YET;
}
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -655,10 +665,10 @@ CoreEfiNotAvailableYetArg3 (
EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg4 (
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4
)
{
//
@@ -670,7 +680,6 @@ CoreEfiNotAvailableYetArg4 (
return EFI_NOT_AVAILABLE_YET;
}
/**
Place holder function until all the Boot Services and Runtime Services are available.
@@ -686,11 +695,11 @@ CoreEfiNotAvailableYetArg4 (
EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg5 (
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4,
UINTN Arg5
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4,
UINTN Arg5
)
{
//
@@ -702,7 +711,6 @@ CoreEfiNotAvailableYetArg5 (
return EFI_NOT_AVAILABLE_YET;
}
/**
Calcualte the 32-bit CRC in a EFI table using the service provided by the
gRuntime service.
@@ -712,10 +720,10 @@ CoreEfiNotAvailableYetArg5 (
**/
VOID
CalculateEfiHdrCrc (
IN OUT EFI_TABLE_HEADER *Hdr
IN OUT EFI_TABLE_HEADER *Hdr
)
{
UINT32 Crc;
UINT32 Crc;
Hdr->CRC32 = 0;
@@ -728,7 +736,6 @@ CalculateEfiHdrCrc (
Hdr->CRC32 = Crc;
}
/**
Terminates all boot services.
@@ -742,11 +749,11 @@ CalculateEfiHdrCrc (
EFI_STATUS
EFIAPI
CoreExitBootServices (
IN EFI_HANDLE ImageHandle,
IN UINTN MapKey
IN EFI_HANDLE ImageHandle,
IN UINTN MapKey
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Disable Timer
@@ -780,7 +787,7 @@ CoreExitBootServices (
(EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)
);
MemoryProtectionExitBootServicesCallback();
MemoryProtectionExitBootServicesCallback ();
//
// Disable interrupt of Debug timer.
@@ -822,7 +829,6 @@ CoreExitBootServices (
return Status;
}
/**
Given a compressed source buffer, this function retrieves the size of the
uncompressed buffer and the size of the scratch buffer required to decompress
@@ -865,20 +871,20 @@ CoreExitBootServices (
EFI_STATUS
EFIAPI
DxeMainUefiDecompressGetInfo (
IN EFI_DECOMPRESS_PROTOCOL *This,
IN VOID *Source,
IN UINT32 SourceSize,
OUT UINT32 *DestinationSize,
OUT UINT32 *ScratchSize
IN EFI_DECOMPRESS_PROTOCOL *This,
IN VOID *Source,
IN UINT32 SourceSize,
OUT UINT32 *DestinationSize,
OUT UINT32 *ScratchSize
)
{
if (Source == NULL || DestinationSize == NULL || ScratchSize == NULL) {
if ((Source == NULL) || (DestinationSize == NULL) || (ScratchSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
return UefiDecompressGetInfo (Source, SourceSize, DestinationSize, ScratchSize);
}
/**
Decompresses a compressed source buffer.
@@ -916,20 +922,20 @@ DxeMainUefiDecompressGetInfo (
EFI_STATUS
EFIAPI
DxeMainUefiDecompress (
IN EFI_DECOMPRESS_PROTOCOL *This,
IN VOID *Source,
IN UINT32 SourceSize,
IN OUT VOID *Destination,
IN UINT32 DestinationSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
IN EFI_DECOMPRESS_PROTOCOL *This,
IN VOID *Source,
IN UINT32 SourceSize,
IN OUT VOID *Destination,
IN UINT32 DestinationSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
{
EFI_STATUS Status;
UINT32 TestDestinationSize;
UINT32 TestScratchSize;
if (Source == NULL || Destination== NULL || Scratch == NULL) {
if ((Source == NULL) || (Destination == NULL) || (Scratch == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -938,7 +944,7 @@ DxeMainUefiDecompress (
return Status;
}
if (ScratchSize < TestScratchSize || DestinationSize < TestDestinationSize) {
if ((ScratchSize < TestScratchSize) || (DestinationSize < TestDestinationSize)) {
return RETURN_INVALID_PARAMETER;
}

View File

@@ -39,34 +39,34 @@ EFI_CORE_PROTOCOL_NOTIFY_ENTRY mArchProtocols[] = {
// Optional protocols that the DXE Core will use if they are present
//
EFI_CORE_PROTOCOL_NOTIFY_ENTRY mOptionalProtocols[] = {
{ &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },
{ &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },
{ NULL, (VOID **)NULL, NULL, NULL, FALSE }
{ &gEfiSecurity2ArchProtocolGuid, (VOID **)&gSecurity2, NULL, NULL, FALSE },
{ &gEfiSmmBase2ProtocolGuid, (VOID **)&gSmmBase2, NULL, NULL, FALSE },
{ NULL, (VOID **)NULL, NULL, NULL, FALSE }
};
//
// Following is needed to display missing architectural protocols in debug builds
//
typedef struct {
EFI_GUID *ProtocolGuid;
CHAR8 *GuidString;
EFI_GUID *ProtocolGuid;
CHAR8 *GuidString;
} GUID_TO_STRING_PROTOCOL_ENTRY;
GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {
{ &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" },
{ &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },
{ NULL, "" }
GLOBAL_REMOVE_IF_UNREFERENCED CONST GUID_TO_STRING_PROTOCOL_ENTRY mMissingProtocols[] = {
{ &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" },
{ &gEfiRealTimeClockArchProtocolGuid, "Real Time Clock" },
{ NULL, "" }
};
/**
@@ -88,10 +88,10 @@ CoreAllEfiServicesAvailable (
return EFI_NOT_FOUND;
}
}
return EFI_SUCCESS;
}
/**
Notification event handler registered by CoreNotifyOnArchProtocolInstallation ().
This notify function is registered for every architectural protocol. This handler
@@ -170,14 +170,15 @@ GenericProtocolNotify (
// 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));
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));
CopyMem (&TempLinkNode, Link, sizeof (LIST_ENTRY));
InsertTailList (&gRuntime->EventHead, Link);
}
@@ -213,28 +214,28 @@ CoreNotifyOnProtocolEntryTable (
{
EFI_STATUS Status;
for (; Entry->ProtocolGuid != NULL; Entry++) {
for ( ; Entry->ProtocolGuid != NULL; Entry++) {
//
// Create the event
//
Status = CoreCreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
GenericProtocolNotify,
Entry,
&Entry->Event
);
ASSERT_EFI_ERROR(Status);
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
GenericProtocolNotify,
Entry,
&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);
Entry->ProtocolGuid,
Entry->Event,
&Entry->Registration
);
ASSERT_EFI_ERROR (Status);
}
}
@@ -252,7 +253,6 @@ CoreNotifyOnProtocolInstallation (
CoreNotifyOnProtocolEntryTable (mOptionalProtocols);
}
/**
Displays Architectural protocols that were not loaded and are required for DXE
core to function. Only used in Debug Builds.

View File

@@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "DxeMain.h"
#include "Event.h"
@@ -19,27 +18,27 @@ EFI_TPL gEfiCurrentTpl = TPL_APPLICATION;
///
/// gEventQueueLock - Protects the event queues
///
EFI_LOCK gEventQueueLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
EFI_LOCK gEventQueueLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
///
/// gEventQueue - A list of event's to notify for each priority level
///
LIST_ENTRY gEventQueue[TPL_HIGH_LEVEL + 1];
LIST_ENTRY gEventQueue[TPL_HIGH_LEVEL + 1];
///
/// gEventPending - A bitmask of the EventQueues that are pending
///
UINTN gEventPending = 0;
UINTN gEventPending = 0;
///
/// gEventSignalQueue - A list of events to signal based on EventGroup type
///
LIST_ENTRY gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);
LIST_ENTRY gEventSignalQueue = INITIALIZE_LIST_HEAD_VARIABLE (gEventSignalQueue);
///
/// Enumerate the valid types
///
UINT32 mEventTable[] = {
UINT32 mEventTable[] = {
///
/// 0x80000200 Timer event with a notification function that is
/// queue when the event is signaled with SignalEvent()
@@ -85,8 +84,7 @@ UINT32 mEventTable[] = {
///
/// gIdleLoopEvent - Event which is signalled when the core is idle
///
EFI_EVENT gIdleLoopEvent = NULL;
EFI_EVENT gIdleLoopEvent = NULL;
/**
Enter critical section by acquiring the lock on gEventQueueLock.
@@ -100,7 +98,6 @@ CoreAcquireEventLock (
CoreAcquireLock (&gEventQueueLock);
}
/**
Exit critical section by releasing the lock on gEventQueueLock.
@@ -113,8 +110,6 @@ CoreReleaseEventLock (
CoreReleaseLock (&gEventQueueLock);
}
/**
Initializes "event" support.
@@ -126,9 +121,9 @@ CoreInitializeEventServices (
VOID
)
{
UINTN Index;
UINTN Index;
for (Index=0; Index <= TPL_HIGH_LEVEL; Index++) {
for (Index = 0; Index <= TPL_HIGH_LEVEL; Index++) {
InitializeListHead (&gEventQueue[Index]);
}
@@ -146,8 +141,6 @@ CoreInitializeEventServices (
return EFI_SUCCESS;
}
/**
Dispatches all pending events.
@@ -157,11 +150,11 @@ CoreInitializeEventServices (
**/
VOID
CoreDispatchEventNotifies (
IN EFI_TPL Priority
IN EFI_TPL Priority
)
{
IEVENT *Event;
LIST_ENTRY *Head;
IEVENT *Event;
LIST_ENTRY *Head;
CoreAcquireEventLock ();
ASSERT (gEventQueueLock.OwnerTpl == Priority);
@@ -171,7 +164,6 @@ CoreDispatchEventNotifies (
// Dispatch all the pending notifications
//
while (!IsListEmpty (Head)) {
Event = CR (Head->ForwardLink, IEVENT, NotifyLink, EVENT_SIGNATURE);
RemoveEntryList (&Event->NotifyLink);
@@ -203,8 +195,6 @@ CoreDispatchEventNotifies (
CoreReleaseEventLock ();
}
/**
Queues the event's notification function to fire.
@@ -213,10 +203,9 @@ CoreDispatchEventNotifies (
**/
VOID
CoreNotifyEvent (
IN IEVENT *Event
IN IEVENT *Event
)
{
//
// Event database must be locked
//
@@ -239,9 +228,6 @@ CoreNotifyEvent (
gEventPending |= (UINTN)(1 << Event->NotifyTpl);
}
/**
Signals all events in the EventGroup.
@@ -250,12 +236,12 @@ CoreNotifyEvent (
**/
VOID
CoreNotifySignalList (
IN EFI_GUID *EventGroup
IN EFI_GUID *EventGroup
)
{
LIST_ENTRY *Link;
LIST_ENTRY *Head;
IEVENT *Event;
LIST_ENTRY *Link;
LIST_ENTRY *Head;
IEVENT *Event;
CoreAcquireEventLock ();
@@ -270,7 +256,6 @@ CoreNotifySignalList (
CoreReleaseEventLock ();
}
/**
Creates an event.
@@ -292,18 +277,16 @@ CoreNotifySignalList (
EFI_STATUS
EFIAPI
CoreCreateEvent (
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN VOID *NotifyContext OPTIONAL,
OUT EFI_EVENT *Event
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN VOID *NotifyContext OPTIONAL,
OUT EFI_EVENT *Event
)
{
return CoreCreateEventEx (Type, NotifyTpl, NotifyFunction, NotifyContext, NULL, Event);
}
/**
Creates an event in a group.
@@ -327,21 +310,22 @@ CoreCreateEvent (
EFI_STATUS
EFIAPI
CoreCreateEventEx (
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN CONST VOID *NotifyContext OPTIONAL,
IN CONST EFI_GUID *EventGroup OPTIONAL,
OUT EFI_EVENT *Event
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN CONST VOID *NotifyContext OPTIONAL,
IN CONST EFI_GUID *EventGroup OPTIONAL,
OUT EFI_EVENT *Event
)
{
//
// If it's a notify type of event, check for invalid NotifyTpl
//
if ((Type & (EVT_NOTIFY_WAIT | EVT_NOTIFY_SIGNAL)) != 0) {
if (NotifyTpl != TPL_APPLICATION &&
NotifyTpl != TPL_CALLBACK &&
NotifyTpl != TPL_NOTIFY) {
if ((NotifyTpl != TPL_APPLICATION) &&
(NotifyTpl != TPL_CALLBACK) &&
(NotifyTpl != TPL_NOTIFY))
{
return EFI_INVALID_PARAMETER;
}
}
@@ -372,18 +356,17 @@ CoreCreateEventEx (
EFI_STATUS
EFIAPI
CoreCreateEventInternal (
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN CONST VOID *NotifyContext OPTIONAL,
IN CONST EFI_GUID *EventGroup OPTIONAL,
OUT EFI_EVENT *Event
IN UINT32 Type,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN CONST VOID *NotifyContext OPTIONAL,
IN CONST EFI_GUID *EventGroup OPTIONAL,
OUT EFI_EVENT *Event
)
{
EFI_STATUS Status;
IEVENT *IEvent;
INTN Index;
EFI_STATUS Status;
IEVENT *IEvent;
INTN Index;
if (Event == NULL) {
return EFI_INVALID_PARAMETER;
@@ -394,12 +377,13 @@ CoreCreateEventInternal (
//
Status = EFI_INVALID_PARAMETER;
for (Index = 0; Index < (sizeof (mEventTable) / sizeof (UINT32)); Index++) {
if (Type == mEventTable[Index]) {
Status = EFI_SUCCESS;
break;
}
if (Type == mEventTable[Index]) {
Status = EFI_SUCCESS;
break;
}
}
if(EFI_ERROR (Status)) {
if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
@@ -414,6 +398,7 @@ CoreCreateEventInternal (
if ((Type == EVT_SIGNAL_EXIT_BOOT_SERVICES) || (Type == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE)) {
return EFI_INVALID_PARAMETER;
}
if (CompareGuid (EventGroup, &gEfiEventExitBootServicesGuid)) {
Type = EVT_SIGNAL_EXIT_BOOT_SERVICES;
} else if (CompareGuid (EventGroup, &gEfiEventVirtualAddressChangeGuid)) {
@@ -439,17 +424,17 @@ CoreCreateEventInternal (
//
if ((NotifyFunction == NULL) ||
(NotifyTpl <= TPL_APPLICATION) ||
(NotifyTpl >= TPL_HIGH_LEVEL)) {
(NotifyTpl >= TPL_HIGH_LEVEL))
{
return EFI_INVALID_PARAMETER;
}
} else {
//
// No notification needed, zero ignored values
//
NotifyTpl = 0;
NotifyTpl = 0;
NotifyFunction = NULL;
NotifyContext = NULL;
NotifyContext = NULL;
}
//
@@ -460,12 +445,13 @@ CoreCreateEventInternal (
} else {
IEvent = AllocateZeroPool (sizeof (IEVENT));
}
if (IEvent == NULL) {
return EFI_OUT_OF_RESOURCES;
}
IEvent->Signature = EVENT_SIGNATURE;
IEvent->Type = Type;
IEvent->Type = Type;
IEvent->NotifyTpl = NotifyTpl;
IEvent->NotifyFunction = NotifyFunction;
@@ -484,7 +470,7 @@ CoreCreateEventInternal (
IEvent->RuntimeData.Type = Type;
IEvent->RuntimeData.NotifyTpl = NotifyTpl;
IEvent->RuntimeData.NotifyFunction = NotifyFunction;
IEvent->RuntimeData.NotifyContext = (VOID *) NotifyContext;
IEvent->RuntimeData.NotifyContext = (VOID *)NotifyContext;
//
// Work around the bug in the Platform Init specification (v1.7), reported
// as Mantis#2017: "EFI_RUNTIME_EVENT_ENTRY.Event" should have type
@@ -493,7 +479,7 @@ CoreCreateEventInternal (
// doesn't match the natural language description. Therefore we need an
// explicit cast here.
//
IEvent->RuntimeData.Event = (EFI_EVENT *) IEvent;
IEvent->RuntimeData.Event = (EFI_EVENT *)IEvent;
InsertTailList (&gRuntime->EventHead, &IEvent->RuntimeData.Link);
}
@@ -514,9 +500,6 @@ CoreCreateEventInternal (
return EFI_SUCCESS;
}
/**
Signals the event. Queues the event to be notified if needed.
@@ -529,10 +512,10 @@ CoreCreateEventInternal (
EFI_STATUS
EFIAPI
CoreSignalEvent (
IN EFI_EVENT UserEvent
IN EFI_EVENT UserEvent
)
{
IEVENT *Event;
IEVENT *Event;
Event = UserEvent;
@@ -565,7 +548,7 @@ CoreSignalEvent (
CoreReleaseEventLock ();
CoreNotifySignalList (&Event->EventGroup);
CoreAcquireEventLock ();
} else {
} else {
CoreNotifyEvent (Event);
}
}
@@ -575,8 +558,6 @@ CoreSignalEvent (
return EFI_SUCCESS;
}
/**
Check the status of an event.
@@ -590,7 +571,7 @@ CoreSignalEvent (
EFI_STATUS
EFIAPI
CoreCheckEvent (
IN EFI_EVENT UserEvent
IN EFI_EVENT UserEvent
)
{
IEVENT *Event;
@@ -613,7 +594,6 @@ CoreCheckEvent (
Status = EFI_NOT_READY;
if ((Event->SignalCount == 0) && ((Event->Type & EVT_NOTIFY_WAIT) != 0)) {
//
// Queue the wait notify function
//
@@ -621,6 +601,7 @@ CoreCheckEvent (
if (Event->SignalCount == 0) {
CoreNotifyEvent (Event);
}
CoreReleaseEventLock ();
}
@@ -633,7 +614,7 @@ CoreCheckEvent (
if (Event->SignalCount != 0) {
Event->SignalCount = 0;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
}
CoreReleaseEventLock ();
@@ -642,8 +623,6 @@ CoreCheckEvent (
return Status;
}
/**
Stops execution until an event is signaled.
@@ -661,13 +640,13 @@ CoreCheckEvent (
EFI_STATUS
EFIAPI
CoreWaitForEvent (
IN UINTN NumberOfEvents,
IN EFI_EVENT *UserEvents,
OUT UINTN *UserIndex
IN UINTN NumberOfEvents,
IN EFI_EVENT *UserEvents,
OUT UINTN *UserIndex
)
{
EFI_STATUS Status;
UINTN Index;
EFI_STATUS Status;
UINTN Index;
//
// Can only WaitForEvent at TPL_APPLICATION
@@ -684,10 +663,8 @@ CoreWaitForEvent (
return EFI_INVALID_PARAMETER;
}
for(;;) {
for(Index = 0; Index < NumberOfEvents; Index++) {
for ( ; ;) {
for (Index = 0; Index < NumberOfEvents; Index++) {
Status = CoreCheckEvent (UserEvents[Index]);
//
@@ -697,6 +674,7 @@ CoreWaitForEvent (
if (UserIndex != NULL) {
*UserIndex = Index;
}
return Status;
}
}
@@ -708,7 +686,6 @@ CoreWaitForEvent (
}
}
/**
Closes an event and frees the event structure.
@@ -721,7 +698,7 @@ CoreWaitForEvent (
EFI_STATUS
EFIAPI
CoreCloseEvent (
IN EFI_EVENT UserEvent
IN EFI_EVENT UserEvent
)
{
EFI_STATUS Status;
@@ -776,7 +753,7 @@ CoreCloseEvent (
// clear the Signature of Event before free pool.
//
Event->Signature = 0;
Status = CoreFreePool (Event);
Status = CoreFreePool (Event);
ASSERT_EFI_ERROR (Status);
return Status;

View File

@@ -10,18 +10,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef __EVENT_H__
#define __EVENT_H__
#define VALID_TPL(a) ((a) <= TPL_HIGH_LEVEL)
extern UINTN gEventPending;
#define VALID_TPL(a) ((a) <= TPL_HIGH_LEVEL)
extern UINTN gEventPending;
///
/// Set if Event is part of an event group
///
#define EVT_EXFLAG_EVENT_GROUP 0x01
#define EVT_EXFLAG_EVENT_GROUP 0x01
///
/// Set if Event is registered on a protocol notify
///
#define EVT_EXFLAG_EVENT_PROTOCOL_NOTIFICATION 0x02
#define EVT_EXFLAG_EVENT_PROTOCOL_NOTIFICATION 0x02
//
// EFI_EVENT
@@ -31,41 +30,40 @@ extern UINTN gEventPending;
/// Timer event information
///
typedef struct {
LIST_ENTRY Link;
UINT64 TriggerTime;
UINT64 Period;
LIST_ENTRY Link;
UINT64 TriggerTime;
UINT64 Period;
} TIMER_EVENT_INFO;
#define EVENT_SIGNATURE SIGNATURE_32('e','v','n','t')
#define EVENT_SIGNATURE SIGNATURE_32('e','v','n','t')
typedef struct {
UINTN Signature;
UINT32 Type;
UINT32 SignalCount;
UINTN Signature;
UINT32 Type;
UINT32 SignalCount;
///
/// Entry if the event is registered to be signalled
///
LIST_ENTRY SignalLink;
LIST_ENTRY SignalLink;
///
/// Notification information for this event
///
EFI_TPL NotifyTpl;
EFI_EVENT_NOTIFY NotifyFunction;
VOID *NotifyContext;
EFI_GUID EventGroup;
LIST_ENTRY NotifyLink;
UINT8 ExFlag;
EFI_TPL NotifyTpl;
EFI_EVENT_NOTIFY NotifyFunction;
VOID *NotifyContext;
EFI_GUID EventGroup;
LIST_ENTRY NotifyLink;
UINT8 ExFlag;
///
/// A list of all runtime events
///
EFI_RUNTIME_EVENT_ENTRY RuntimeData;
TIMER_EVENT_INFO Timer;
EFI_RUNTIME_EVENT_ENTRY RuntimeData;
TIMER_EVENT_INFO Timer;
} IEVENT;
//
// Internal prototypes
//
/**
Dispatches all pending events.
@@ -75,10 +73,9 @@ typedef struct {
**/
VOID
CoreDispatchEventNotifies (
IN EFI_TPL Priority
IN EFI_TPL Priority
);
/**
Initializes timer support.

View File

@@ -6,7 +6,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "DxeMain.h"
#include "Event.h"
@@ -14,16 +13,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Internal data
//
LIST_ENTRY mEfiTimerList = INITIALIZE_LIST_HEAD_VARIABLE (mEfiTimerList);
EFI_LOCK mEfiTimerLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL - 1);
EFI_EVENT mEfiCheckTimerEvent = NULL;
LIST_ENTRY mEfiTimerList = INITIALIZE_LIST_HEAD_VARIABLE (mEfiTimerList);
EFI_LOCK mEfiTimerLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL - 1);
EFI_EVENT mEfiCheckTimerEvent = NULL;
EFI_LOCK mEfiSystemTimeLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
UINT64 mEfiSystemTime = 0;
EFI_LOCK mEfiSystemTimeLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);
UINT64 mEfiSystemTime = 0;
//
// Timer functions
//
/**
Inserts the timer event.
@@ -33,12 +33,12 @@ UINT64 mEfiSystemTime = 0;
**/
VOID
CoreInsertEventTimer (
IN IEVENT *Event
IN IEVENT *Event
)
{
UINT64 TriggerTime;
LIST_ENTRY *Link;
IEVENT *Event2;
UINT64 TriggerTime;
LIST_ENTRY *Link;
IEVENT *Event2;
ASSERT_LOCKED (&mEfiTimerLock);
@@ -72,7 +72,7 @@ CoreCurrentSystemTime (
VOID
)
{
UINT64 SystemTime;
UINT64 SystemTime;
CoreAcquireLock (&mEfiSystemTimeLock);
SystemTime = mEfiSystemTime;
@@ -92,12 +92,12 @@ CoreCurrentSystemTime (
VOID
EFIAPI
CoreCheckTimers (
IN EFI_EVENT CheckEvent,
IN VOID *Context
IN EFI_EVENT CheckEvent,
IN VOID *Context
)
{
UINT64 SystemTime;
IEVENT *Event;
UINT64 SystemTime;
IEVENT *Event;
//
// Check the timer database for expired timers
@@ -154,7 +154,6 @@ CoreCheckTimers (
CoreReleaseLock (&mEfiTimerLock);
}
/**
Initializes timer support.
@@ -177,7 +176,6 @@ CoreInitializeTimer (
ASSERT_EFI_ERROR (Status);
}
/**
Called by the platform code to process a tick.
@@ -188,10 +186,10 @@ CoreInitializeTimer (
VOID
EFIAPI
CoreTimerTick (
IN UINT64 Duration
IN UINT64 Duration
)
{
IEVENT *Event;
IEVENT *Event;
//
// Check runtiem flag in case there are ticks while exiting boot services
@@ -218,8 +216,6 @@ CoreTimerTick (
CoreReleaseLock (&mEfiSystemTimeLock);
}
/**
Sets the type of timer and the trigger time for a timer event.
@@ -238,12 +234,12 @@ CoreTimerTick (
EFI_STATUS
EFIAPI
CoreSetTimer (
IN EFI_EVENT UserEvent,
IN EFI_TIMER_DELAY Type,
IN UINT64 TriggerTime
IN EFI_EVENT UserEvent,
IN EFI_TIMER_DELAY Type,
IN UINT64 TriggerTime
)
{
IEVENT *Event;
IEVENT *Event;
Event = UserEvent;
@@ -255,7 +251,7 @@ CoreSetTimer (
return EFI_INVALID_PARAMETER;
}
if ((UINT32)Type > TimerRelative || (Event->Type & EVT_TIMER) == 0) {
if (((UINT32)Type > TimerRelative) || ((Event->Type & EVT_TIMER) == 0)) {
return EFI_INVALID_PARAMETER;
}
@@ -270,14 +266,14 @@ CoreSetTimer (
}
Event->Timer.TriggerTime = 0;
Event->Timer.Period = 0;
Event->Timer.Period = 0;
if (Type != TimerCancel) {
if (Type == TimerPeriodic) {
if (TriggerTime == 0) {
gTimer->GetTimerPeriod (gTimer, &TriggerTime);
}
Event->Timer.Period = TriggerTime;
}

View File

@@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
CoreSetInterruptState (
IN BOOLEAN Enable
IN BOOLEAN Enable
)
{
EFI_STATUS Status;
@@ -26,21 +26,23 @@ CoreSetInterruptState (
if (gCpu == NULL) {
return;
}
if (!Enable) {
gCpu->DisableInterrupt (gCpu);
return;
}
if (gSmmBase2 == NULL) {
gCpu->EnableInterrupt (gCpu);
return;
}
Status = gSmmBase2->InSmm (gSmmBase2, &InSmm);
if (!EFI_ERROR (Status) && !InSmm) {
gCpu->EnableInterrupt(gCpu);
gCpu->EnableInterrupt (gCpu);
}
}
/**
Raise the task priority level to the new level.
High level is implemented by disabling processor interrupts.
@@ -53,22 +55,23 @@ CoreSetInterruptState (
EFI_TPL
EFIAPI
CoreRaiseTpl (
IN EFI_TPL NewTpl
IN EFI_TPL NewTpl
)
{
EFI_TPL OldTpl;
EFI_TPL OldTpl;
OldTpl = gEfiCurrentTpl;
if (OldTpl > NewTpl) {
DEBUG ((DEBUG_ERROR, "FATAL ERROR - RaiseTpl with OldTpl(0x%x) > NewTpl(0x%x)\n", OldTpl, NewTpl));
ASSERT (FALSE);
}
ASSERT (VALID_TPL (NewTpl));
//
// If raising to high level, disable interrupts
//
if (NewTpl >= TPL_HIGH_LEVEL && OldTpl < TPL_HIGH_LEVEL) {
if ((NewTpl >= TPL_HIGH_LEVEL) && (OldTpl < TPL_HIGH_LEVEL)) {
CoreSetInterruptState (FALSE);
}
@@ -80,9 +83,6 @@ CoreRaiseTpl (
return OldTpl;
}
/**
Lowers the task priority to the previous value. If the new
priority unmasks events at a higher priority, they are dispatched.
@@ -93,17 +93,18 @@ CoreRaiseTpl (
VOID
EFIAPI
CoreRestoreTpl (
IN EFI_TPL NewTpl
IN EFI_TPL NewTpl
)
{
EFI_TPL OldTpl;
EFI_TPL PendingTpl;
EFI_TPL OldTpl;
EFI_TPL PendingTpl;
OldTpl = gEfiCurrentTpl;
if (NewTpl > OldTpl) {
DEBUG ((DEBUG_ERROR, "FATAL ERROR - RestoreTpl with NewTpl(0x%x) > OldTpl(0x%x)\n", NewTpl, OldTpl));
ASSERT (FALSE);
}
ASSERT (VALID_TPL (NewTpl));
//
@@ -111,7 +112,7 @@ CoreRestoreTpl (
// interrupts are enabled
//
if (OldTpl >= TPL_HIGH_LEVEL && NewTpl < TPL_HIGH_LEVEL) {
if ((OldTpl >= TPL_HIGH_LEVEL) && (NewTpl < TPL_HIGH_LEVEL)) {
gEfiCurrentTpl = TPL_HIGH_LEVEL;
}
@@ -119,7 +120,7 @@ CoreRestoreTpl (
// Dispatch any pending events
//
while (gEventPending != 0) {
PendingTpl = (UINTN) HighBitSet64 (gEventPending);
PendingTpl = (UINTN)HighBitSet64 (gEventPending);
if (PendingTpl <= NewTpl) {
break;
}
@@ -128,6 +129,7 @@ CoreRestoreTpl (
if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
CoreSetInterruptState (TRUE);
}
CoreDispatchEventNotifies (gEfiCurrentTpl);
}
@@ -144,5 +146,4 @@ CoreRestoreTpl (
if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
CoreSetInterruptState (TRUE);
}
}

View File

@@ -6,11 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "DxeMain.h"
#include "FwVolDriver.h"
/**
Get the FFS file state by checking the highest bit set in the header's state field.
@@ -26,13 +24,13 @@ GetFileState (
IN EFI_FFS_FILE_HEADER *FfsHeader
)
{
EFI_FFS_FILE_STATE FileState;
UINT8 HighestBit;
EFI_FFS_FILE_STATE FileState;
UINT8 HighestBit;
FileState = FfsHeader->State;
if (ErasePolarity != 0) {
FileState = (EFI_FFS_FILE_STATE)~FileState;
FileState = (EFI_FFS_FILE_STATE) ~FileState;
}
HighestBit = 0x80;
@@ -40,11 +38,9 @@ GetFileState (
HighestBit >>= 1;
}
return (EFI_FFS_FILE_STATE) HighestBit;
return (EFI_FFS_FILE_STATE)HighestBit;
}
/**
Check if a block of buffer is erased.
@@ -58,16 +54,16 @@ GetFileState (
**/
BOOLEAN
IsBufferErased (
IN UINT8 ErasePolarity,
IN VOID *InBuffer,
IN UINTN BufferSize
IN UINT8 ErasePolarity,
IN VOID *InBuffer,
IN UINTN BufferSize
)
{
UINTN Count;
UINT8 EraseByte;
UINT8 *Buffer;
UINTN Count;
UINT8 EraseByte;
UINT8 *Buffer;
if(ErasePolarity == 1) {
if (ErasePolarity == 1) {
EraseByte = 0xFF;
} else {
EraseByte = 0;
@@ -83,8 +79,6 @@ IsBufferErased (
return TRUE;
}
/**
Verify checksum of the firmware volume header.
@@ -96,12 +90,12 @@ IsBufferErased (
**/
BOOLEAN
VerifyFvHeaderChecksum (
IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
)
{
UINT16 Checksum;
Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength);
Checksum = CalculateSum16 ((UINT16 *)FvHeader, FvHeader->HeaderLength);
if (Checksum == 0) {
return TRUE;
@@ -110,7 +104,6 @@ VerifyFvHeaderChecksum (
}
}
/**
Verify checksum of the FFS file header.
@@ -125,14 +118,15 @@ VerifyHeaderChecksum (
IN EFI_FFS_FILE_HEADER *FfsHeader
)
{
UINT8 HeaderChecksum;
UINT8 HeaderChecksum;
if (IS_FFS_FILE2 (FfsHeader)) {
HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER2));
HeaderChecksum = CalculateSum8 ((UINT8 *)FfsHeader, sizeof (EFI_FFS_FILE_HEADER2));
} else {
HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
HeaderChecksum = CalculateSum8 ((UINT8 *)FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
}
HeaderChecksum = (UINT8) (HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);
HeaderChecksum = (UINT8)(HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File);
if (HeaderChecksum == 0) {
return TRUE;
@@ -141,8 +135,6 @@ VerifyHeaderChecksum (
}
}
/**
Check if it's a valid FFS file header.
@@ -164,23 +156,22 @@ IsValidFfsHeader (
*FileState = GetFileState (ErasePolarity, FfsHeader);
switch (*FileState) {
case EFI_FILE_HEADER_VALID:
case EFI_FILE_DATA_VALID:
case EFI_FILE_MARKED_FOR_UPDATE:
case EFI_FILE_DELETED:
//
// Here we need to verify header checksum
//
return VerifyHeaderChecksum (FfsHeader);
case EFI_FILE_HEADER_VALID:
case EFI_FILE_DATA_VALID:
case EFI_FILE_MARKED_FOR_UPDATE:
case EFI_FILE_DELETED:
//
// Here we need to verify header checksum
//
return VerifyHeaderChecksum (FfsHeader);
case EFI_FILE_HEADER_CONSTRUCTION:
case EFI_FILE_HEADER_INVALID:
default:
return FALSE;
case EFI_FILE_HEADER_CONSTRUCTION:
case EFI_FILE_HEADER_INVALID:
default:
return FALSE;
}
}
/**
Check if it's a valid FFS file.
Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
@@ -203,25 +194,23 @@ IsValidFfsFile (
FileState = GetFileState (ErasePolarity, FfsHeader);
switch (FileState) {
case EFI_FILE_DELETED:
case EFI_FILE_DATA_VALID:
case EFI_FILE_MARKED_FOR_UPDATE:
DataCheckSum = FFS_FIXED_CHECKSUM;
if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {
if (IS_FFS_FILE2 (FfsHeader)) {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER2));
} else {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof(EFI_FFS_FILE_HEADER));
case EFI_FILE_DELETED:
case EFI_FILE_DATA_VALID:
case EFI_FILE_MARKED_FOR_UPDATE:
DataCheckSum = FFS_FIXED_CHECKSUM;
if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) {
if (IS_FFS_FILE2 (FfsHeader)) {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER2));
} else {
DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER));
}
}
}
if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) {
return TRUE;
}
default:
return FALSE;
if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) {
return TRUE;
}
default:
return FALSE;
}
}

View File

@@ -11,14 +11,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "FwVolDriver.h"
//
// Protocol notify related globals
//
VOID *gEfiFwVolBlockNotifyReg;
EFI_EVENT gEfiFwVolBlockEvent;
VOID *gEfiFwVolBlockNotifyReg;
EFI_EVENT gEfiFwVolBlockEvent;
FV_DEVICE mFvDevice = {
FV_DEVICE mFvDevice = {
FV2_DEVICE_SIGNATURE,
NULL,
NULL,
@@ -29,7 +28,7 @@ FV_DEVICE mFvDevice = {
FvReadFileSection,
FvWriteFile,
FvGetNextFile,
sizeof (UINTN),
sizeof (UINTN),
NULL,
FvGetVolumeInfo,
FvSetVolumeInfo
@@ -38,17 +37,17 @@ FV_DEVICE mFvDevice = {
NULL,
NULL,
NULL,
{ NULL, NULL },
{ NULL, NULL},
0,
0,
FALSE,
FALSE
};
//
// FFS helper functions
//
/**
Read data from Firmware Block by FVB protocol Read.
The data may cross the multi block ranges.
@@ -68,27 +67,27 @@ FV_DEVICE mFvDevice = {
**/
EFI_STATUS
ReadFvbData (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
IN OUT EFI_LBA *StartLba,
IN OUT UINTN *Offset,
IN UINTN DataSize,
OUT UINT8 *Data
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
IN OUT EFI_LBA *StartLba,
IN OUT UINTN *Offset,
IN UINTN DataSize,
OUT UINT8 *Data
)
{
UINTN BlockSize;
UINTN NumberOfBlocks;
UINTN BlockIndex;
UINTN ReadDataSize;
EFI_STATUS Status;
UINTN BlockSize;
UINTN NumberOfBlocks;
UINTN BlockIndex;
UINTN ReadDataSize;
EFI_STATUS Status;
//
// Try read data in current block
//
BlockIndex = 0;
ReadDataSize = DataSize;
Status = Fvb->Read (Fvb, *StartLba, *Offset, &ReadDataSize, Data);
Status = Fvb->Read (Fvb, *StartLba, *Offset, &ReadDataSize, Data);
if (Status == EFI_SUCCESS) {
*Offset += DataSize;
*Offset += DataSize;
return EFI_SUCCESS;
} else if (Status != EFI_BAD_BUFFER_SIZE) {
//
@@ -118,9 +117,10 @@ ReadFvbData (
if (EFI_ERROR (Status)) {
return Status;
}
Data += BlockSize;
Data += BlockSize;
DataSize -= BlockSize;
BlockIndex ++;
BlockIndex++;
}
//
@@ -150,7 +150,7 @@ ReadFvbData (
// Update Lba and Offset used by the following read.
//
*StartLba += BlockIndex;
*Offset = DataSize;
*Offset = DataSize;
return EFI_SUCCESS;
}
@@ -173,8 +173,8 @@ ReadFvbData (
**/
EFI_STATUS
GetFwVolHeader (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
)
{
EFI_STATUS Status;
@@ -187,10 +187,10 @@ GetFwVolHeader (
//
// Read the standard FV header
//
StartLba = 0;
Offset = 0;
StartLba = 0;
Offset = 0;
FvhLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER);
Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, (UINT8 *)&TempFvh);
Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, (UINT8 *)&TempFvh);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -207,7 +207,8 @@ GetFwVolHeader (
// understand it...
//
if ((!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
(!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
(!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid)))
{
return EFI_INVALID_PARAMETER;
}
@@ -228,8 +229,8 @@ GetFwVolHeader (
// Read the rest of the header
//
FvhLength = TempFvh.HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER);
Buffer = (UINT8 *)*FwVolHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER);
Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, Buffer);
Buffer = (UINT8 *)*FwVolHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER);
Status = ReadFvbData (Fvb, &StartLba, &Offset, FvhLength, Buffer);
if (EFI_ERROR (Status)) {
//
// Read failed so free buffer
@@ -240,8 +241,6 @@ GetFwVolHeader (
return Status;
}
/**
Free FvDevice resource when error happens
@@ -253,8 +252,8 @@ FreeFvDeviceResource (
IN FV_DEVICE *FvDevice
)
{
FFS_FILE_LIST_ENTRY *FfsFileEntry;
LIST_ENTRY *NextEntry;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
LIST_ENTRY *NextEntry;
//
// Free File List Entry
@@ -279,7 +278,7 @@ FreeFvDeviceResource (
CoreFreePool (FfsFileEntry);
FfsFileEntry = (FFS_FILE_LIST_ENTRY *) NextEntry;
FfsFileEntry = (FFS_FILE_LIST_ENTRY *)NextEntry;
}
if (!FvDevice->IsMemoryMapped) {
@@ -297,8 +296,6 @@ FreeFvDeviceResource (
return;
}
/**
Check if an FV is consistent and allocate cache for it.
@@ -314,30 +311,30 @@ FvCheck (
IN OUT FV_DEVICE *FvDevice
)
{
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExtHeader;
EFI_FVB_ATTRIBUTES_2 FvbAttributes;
EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
EFI_FFS_FILE_HEADER *FfsHeader;
UINT8 *CacheLocation;
UINTN Index;
EFI_LBA LbaIndex;
UINTN Size;
EFI_FFS_FILE_STATE FileState;
UINT8 *TopFvAddress;
UINTN TestLength;
EFI_PHYSICAL_ADDRESS PhysicalAddress;
BOOLEAN FileCached;
UINTN WholeFileSize;
EFI_FFS_FILE_HEADER *CacheFfsHeader;
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExtHeader;
EFI_FVB_ATTRIBUTES_2 FvbAttributes;
EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
EFI_FFS_FILE_HEADER *FfsHeader;
UINT8 *CacheLocation;
UINTN Index;
EFI_LBA LbaIndex;
UINTN Size;
EFI_FFS_FILE_STATE FileState;
UINT8 *TopFvAddress;
UINTN TestLength;
EFI_PHYSICAL_ADDRESS PhysicalAddress;
BOOLEAN FileCached;
UINTN WholeFileSize;
EFI_FFS_FILE_HEADER *CacheFfsHeader;
FileCached = FALSE;
FileCached = FALSE;
CacheFfsHeader = NULL;
Fvb = FvDevice->Fvb;
Fvb = FvDevice->Fvb;
FwVolHeader = FvDevice->FwVolHeader;
Status = Fvb->GetAttributes (Fvb, &FvbAttributes);
@@ -345,7 +342,7 @@ FvCheck (
return Status;
}
Size = (UINTN) FwVolHeader->FvLength;
Size = (UINTN)FwVolHeader->FvLength;
if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
FvDevice->IsMemoryMapped = TRUE;
@@ -357,10 +354,10 @@ FvCheck (
//
// Don't cache memory mapped FV really.
//
FvDevice->CachedFv = (UINT8 *) (UINTN) PhysicalAddress;
FvDevice->CachedFv = (UINT8 *)(UINTN)PhysicalAddress;
} else {
FvDevice->IsMemoryMapped = FALSE;
FvDevice->CachedFv = AllocatePool (Size);
FvDevice->CachedFv = AllocatePool (Size);
if (FvDevice->CachedFv == NULL) {
return EFI_OUT_OF_RESOURCES;
@@ -376,9 +373,9 @@ FvCheck (
//
// Copy FV into memory using the block map.
//
BlockMap = FwVolHeader->BlockMap;
BlockMap = FwVolHeader->BlockMap;
CacheLocation = FvDevice->CachedFv;
LbaIndex = 0;
LbaIndex = 0;
while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) {
//
// read the FV data
@@ -417,7 +414,6 @@ FvCheck (
FvDevice->ErasePolarity = 0;
}
//
// go through the whole FV cache, check the consistence of the FV.
// Make a linked list of all the Ffs file headers
@@ -432,21 +428,21 @@ FvCheck (
//
// Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists.
//
FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) (FvDevice->CachedFv + FwVolHeader->ExtHeaderOffset);
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);
FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(FvDevice->CachedFv + FwVolHeader->ExtHeaderOffset);
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolExtHeader + FwVolExtHeader->ExtHeaderSize);
} else {
FfsHeader = (EFI_FFS_FILE_HEADER *) (FvDevice->CachedFv + FwVolHeader->HeaderLength);
FfsHeader = (EFI_FFS_FILE_HEADER *)(FvDevice->CachedFv + FwVolHeader->HeaderLength);
}
FfsHeader = (EFI_FFS_FILE_HEADER *) ALIGN_POINTER (FfsHeader, 8);
TopFvAddress = FvDevice->EndOfCachedFv;
while (((UINTN) FfsHeader >= (UINTN) FvDevice->CachedFv) && ((UINTN) FfsHeader <= (UINTN) ((UINTN) TopFvAddress - sizeof (EFI_FFS_FILE_HEADER)))) {
FfsHeader = (EFI_FFS_FILE_HEADER *)ALIGN_POINTER (FfsHeader, 8);
TopFvAddress = FvDevice->EndOfCachedFv;
while (((UINTN)FfsHeader >= (UINTN)FvDevice->CachedFv) && ((UINTN)FfsHeader <= (UINTN)((UINTN)TopFvAddress - sizeof (EFI_FFS_FILE_HEADER)))) {
if (FileCached) {
CoreFreePool (CacheFfsHeader);
FileCached = FALSE;
}
TestLength = TopFvAddress - ((UINT8 *) FfsHeader);
TestLength = TopFvAddress - ((UINT8 *)FfsHeader);
if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
TestLength = sizeof (EFI_FFS_FILE_HEADER);
}
@@ -460,15 +456,18 @@ FvCheck (
if (!IsValidFfsHeader (FvDevice->ErasePolarity, FfsHeader, &FileState)) {
if ((FileState == EFI_FILE_HEADER_INVALID) ||
(FileState == EFI_FILE_HEADER_CONSTRUCTION)) {
(FileState == EFI_FILE_HEADER_CONSTRUCTION))
{
if (IS_FFS_FILE2 (FfsHeader)) {
if (!FvDevice->IsFfs3Fv) {
DEBUG ((DEBUG_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &FfsHeader->Name));
}
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER2));
} else {
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + sizeof (EFI_FFS_FILE_HEADER));
}
continue;
} else {
//
@@ -487,12 +486,13 @@ FvCheck (
// Here is to cache FFS file to memory buffer for following checksum calculating.
// And then, the cached file buffer can be also used for FvReadFile.
//
WholeFileSize = IS_FFS_FILE2 (CacheFfsHeader) ? FFS_FILE2_SIZE (CacheFfsHeader): FFS_FILE_SIZE (CacheFfsHeader);
WholeFileSize = IS_FFS_FILE2 (CacheFfsHeader) ? FFS_FILE2_SIZE (CacheFfsHeader) : FFS_FILE_SIZE (CacheFfsHeader);
CacheFfsHeader = AllocateCopyPool (WholeFileSize, CacheFfsHeader);
if (CacheFfsHeader == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
FileCached = TRUE;
}
}
@@ -509,11 +509,11 @@ FvCheck (
ASSERT (FFS_FILE2_SIZE (CacheFfsHeader) > 0x00FFFFFF);
if (!FvDevice->IsFfs3Fv) {
DEBUG ((DEBUG_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &CacheFfsHeader->Name));
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
//
// Adjust pointer to the next 8-byte aligned boundary.
//
FfsHeader = (EFI_FFS_FILE_HEADER *) (((UINTN) FfsHeader + 7) & ~0x07);
FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINTN)FfsHeader + 7) & ~0x07);
continue;
}
}
@@ -533,23 +533,22 @@ FvCheck (
goto Done;
}
FfsFileEntry->FfsHeader = CacheFfsHeader;
FfsFileEntry->FfsHeader = CacheFfsHeader;
FfsFileEntry->FileCached = FileCached;
FileCached = FALSE;
FileCached = FALSE;
InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link);
}
if (IS_FFS_FILE2 (CacheFfsHeader)) {
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + FFS_FILE2_SIZE (CacheFfsHeader));
} else {
FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + FFS_FILE_SIZE (CacheFfsHeader));
FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsHeader + FFS_FILE_SIZE (CacheFfsHeader));
}
//
// Adjust pointer to the next 8-byte aligned boundary.
//
FfsHeader = (EFI_FFS_FILE_HEADER *)(((UINTN)FfsHeader + 7) & ~0x07);
}
Done:
@@ -558,14 +557,13 @@ Done:
CoreFreePool (CacheFfsHeader);
FileCached = FALSE;
}
FreeFvDeviceResource (FvDevice);
}
return Status;
}
/**
This notification function is invoked when an instance of the
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL is produced. It layers an instance of the
@@ -579,32 +577,33 @@ Done:
VOID
EFIAPI
NotifyFwVolBlock (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_HANDLE Handle;
EFI_STATUS Status;
UINTN BufferSize;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
FV_DEVICE *FvDevice;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_HANDLE Handle;
EFI_STATUS Status;
UINTN BufferSize;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
FV_DEVICE *FvDevice;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
//
// Examine all new handles
//
for (;;) {
for ( ; ;) {
//
// Get the next handle
//
BufferSize = sizeof (Handle);
Status = CoreLocateHandle (
ByRegisterNotify,
NULL,
gEfiFwVolBlockNotifyReg,
&BufferSize,
&Handle
);
Status = CoreLocateHandle (
ByRegisterNotify,
NULL,
gEfiFwVolBlockNotifyReg,
&BufferSize,
&Handle
);
//
// If not found, we're done
@@ -631,6 +630,7 @@ NotifyFwVolBlock (
if (EFI_ERROR (Status)) {
continue;
}
ASSERT (FwVolHeader != NULL);
if (!VerifyFvHeaderChecksum (FwVolHeader)) {
@@ -653,7 +653,6 @@ NotifyFwVolBlock (
//
FvDevice->Fvb = Fvb;
}
} else {
//
// No FwVol protocol on the handle so create a new one
@@ -678,11 +677,11 @@ NotifyFwVolBlock (
// Install an New FV protocol on the existing handle
//
Status = CoreInstallProtocolInterface (
&Handle,
&gEfiFirmwareVolume2ProtocolGuid,
EFI_NATIVE_INTERFACE,
&FvDevice->Fv
);
&Handle,
&gEfiFirmwareVolume2ProtocolGuid,
EFI_NATIVE_INTERFACE,
&FvDevice->Fv
);
ASSERT_EFI_ERROR (Status);
} else {
//
@@ -696,8 +695,6 @@ NotifyFwVolBlock (
return;
}
/**
This routine is the driver initialization entry point. It registers
a notification function. This notification function are responsible
@@ -712,8 +709,8 @@ NotifyFwVolBlock (
EFI_STATUS
EFIAPI
FwVolDriverInit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
gEfiFwVolBlockEvent = EfiCreateProtocolNotifyEvent (

View File

@@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "FwVolDriver.h"
/**
Retrieves attributes, insures positive polarity of attribute bits, returns
resulting attributes in output parameter.
@@ -23,17 +22,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
FvGetVolumeAttributes (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
OUT EFI_FV_ATTRIBUTES *Attributes
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
OUT EFI_FV_ATTRIBUTES *Attributes
)
{
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FVB_ATTRIBUTES_2 FvbAttributes;
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FVB_ATTRIBUTES_2 FvbAttributes;
FvDevice = FV_DEVICE_FROM_THIS (This);
Fvb = FvDevice->Fvb;
Fvb = FvDevice->Fvb;
//
// First get the Firmware Volume Block Attributes
@@ -50,8 +49,6 @@ FvGetVolumeAttributes (
return Status;
}
/**
Sets current attributes for volume
@@ -72,7 +69,6 @@ FvSetVolumeAttributes (
return EFI_UNSUPPORTED;
}
/**
Return information of type InformationType for the requested firmware
volume.
@@ -89,17 +85,15 @@ FvSetVolumeAttributes (
EFI_STATUS
EFIAPI
FvGetVolumeInfo (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}
/**
Set information of type InformationType for the requested firmware
volume.
@@ -116,14 +110,11 @@ FvGetVolumeInfo (
EFI_STATUS
EFIAPI
FvSetVolumeInfo (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN UINTN BufferSize,
IN CONST VOID *Buffer
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN UINTN BufferSize,
IN CONST VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}

View File

@@ -10,40 +10,39 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef __FW_VOL_DRIVER_H_
#define __FW_VOL_DRIVER_H_
#define FV2_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '2')
#define FV2_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '2')
//
// Used to track all non-deleted files
//
typedef struct {
LIST_ENTRY Link;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN StreamHandle;
BOOLEAN FileCached;
LIST_ENTRY Link;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN StreamHandle;
BOOLEAN FileCached;
} FFS_FILE_LIST_ENTRY;
typedef struct {
UINTN Signature;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_HANDLE Handle;
EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;
UINTN Signature;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_HANDLE Handle;
EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINT8 *CachedFv;
UINT8 *EndOfCachedFv;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINT8 *CachedFv;
UINT8 *EndOfCachedFv;
FFS_FILE_LIST_ENTRY *LastKey;
FFS_FILE_LIST_ENTRY *LastKey;
LIST_ENTRY FfsFileListHeader;
LIST_ENTRY FfsFileListHeader;
UINT32 AuthenticationStatus;
UINT8 ErasePolarity;
BOOLEAN IsFfs3Fv;
BOOLEAN IsMemoryMapped;
UINT32 AuthenticationStatus;
UINT8 ErasePolarity;
BOOLEAN IsFfs3Fv;
BOOLEAN IsMemoryMapped;
} FV_DEVICE;
#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)
#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)
/**
Retrieves attributes, insures positive polarity of attribute bits, returns
@@ -58,11 +57,10 @@ typedef struct {
EFI_STATUS
EFIAPI
FvGetVolumeAttributes (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
OUT EFI_FV_ATTRIBUTES *Attributes
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
OUT EFI_FV_ATTRIBUTES *Attributes
);
/**
Sets current attributes for volume
@@ -80,7 +78,6 @@ FvSetVolumeAttributes (
IN OUT EFI_FV_ATTRIBUTES *Attributes
);
/**
Given the input key, search for the next matching file in the volume.
@@ -130,16 +127,14 @@ FvSetVolumeAttributes (
EFI_STATUS
EFIAPI
FvGetNextFile (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN OUT VOID *Key,
IN OUT EFI_FV_FILETYPE *FileType,
OUT EFI_GUID *NameGuid,
OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
OUT UINTN *Size
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN OUT VOID *Key,
IN OUT EFI_FV_FILETYPE *FileType,
OUT EFI_GUID *NameGuid,
OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
OUT UINTN *Size
);
/**
Locates a file in the firmware volume and
copies it to the supplied buffer.
@@ -183,16 +178,15 @@ FvGetNextFile (
EFI_STATUS
EFIAPI
FvReadFile (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *NameGuid,
IN OUT VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT EFI_FV_FILETYPE *FoundType,
OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
OUT UINT32 *AuthenticationStatus
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *NameGuid,
IN OUT VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT EFI_FV_FILETYPE *FoundType,
OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
OUT UINT32 *AuthenticationStatus
);
/**
Locates a section in a given FFS File and
copies it to the supplied buffer (not including section header).
@@ -233,7 +227,6 @@ FvReadFileSection (
OUT UINT32 *AuthenticationStatus
);
/**
Writes one or more files to the firmware volume.
@@ -264,7 +257,6 @@ FvWriteFile (
IN EFI_FV_WRITE_FILE_DATA *FileData
);
/**
Return information of type InformationType for the requested firmware
volume.
@@ -281,14 +273,12 @@ FvWriteFile (
EFI_STATUS
EFIAPI
FvGetVolumeInfo (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
);
/**
Set information of type InformationType for the requested firmware
volume.
@@ -305,14 +295,12 @@ FvGetVolumeInfo (
EFI_STATUS
EFIAPI
FvSetVolumeInfo (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN UINTN BufferSize,
IN CONST VOID *Buffer
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *InformationType,
IN UINTN BufferSize,
IN CONST VOID *Buffer
);
/**
Check if a block of buffer is erased.
@@ -326,12 +314,11 @@ FvSetVolumeInfo (
**/
BOOLEAN
IsBufferErased (
IN UINT8 ErasePolarity,
IN VOID *InBuffer,
IN UINTN BufferSize
IN UINT8 ErasePolarity,
IN VOID *InBuffer,
IN UINTN BufferSize
);
/**
Get the FFS file state by checking the highest bit set in the header's state field.
@@ -347,7 +334,6 @@ GetFileState (
IN EFI_FFS_FILE_HEADER *FfsHeader
);
/**
Set the FFS file state.
@@ -381,7 +367,6 @@ IsValidFfsHeader (
OUT EFI_FFS_FILE_STATE *FileState
);
/**
Check if it's a valid FFS file.
Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.

View File

@@ -29,8 +29,8 @@ Required Alignment Alignment Value in FFS FFS_ATTRIB_DATA_ALIGNMENT2 Align
8 MB 6 1 23
16 MB 7 1 24
**/
UINT8 mFvAttributes[] = {0, 4, 7, 9, 10, 12, 15, 16};
UINT8 mFvAttributes2[] = {17, 18, 19, 20, 21, 22, 23, 24};
UINT8 mFvAttributes[] = { 0, 4, 7, 9, 10, 12, 15, 16 };
UINT8 mFvAttributes2[] = { 17, 18, 19, 20, 21, 22, 23, 24 };
/**
Convert the FFS File Attributes to FV File Attributes
@@ -42,19 +42,19 @@ UINT8 mFvAttributes2[] = {17, 18, 19, 20, 21, 22, 23, 24};
**/
EFI_FV_FILE_ATTRIBUTES
FfsAttributes2FvFileAttributes (
IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes
)
{
UINT8 DataAlignment;
EFI_FV_FILE_ATTRIBUTES FileAttribute;
UINT8 DataAlignment;
EFI_FV_FILE_ATTRIBUTES FileAttribute;
DataAlignment = (UINT8) ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);
DataAlignment = (UINT8)((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);
ASSERT (DataAlignment < 8);
if ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT_2) != 0) {
FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes2[DataAlignment];
FileAttribute = (EFI_FV_FILE_ATTRIBUTES)mFvAttributes2[DataAlignment];
} else {
FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment];
FileAttribute = (EFI_FV_FILE_ATTRIBUTES)mFvAttributes[DataAlignment];
}
if ((FfsAttributes & FFS_ATTRIB_FIXED) == FFS_ATTRIB_FIXED) {
@@ -113,26 +113,26 @@ FfsAttributes2FvFileAttributes (
EFI_STATUS
EFIAPI
FvGetNextFile (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN OUT VOID *Key,
IN OUT EFI_FV_FILETYPE *FileType,
OUT EFI_GUID *NameGuid,
OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
OUT UINTN *Size
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN OUT VOID *Key,
IN OUT EFI_FV_FILETYPE *FileType,
OUT EFI_GUID *NameGuid,
OUT EFI_FV_FILE_ATTRIBUTES *Attributes,
OUT UINTN *Size
)
{
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FV_ATTRIBUTES FvAttributes;
EFI_FFS_FILE_HEADER *FfsFileHeader;
UINTN *KeyValue;
LIST_ENTRY *Link;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FV_ATTRIBUTES FvAttributes;
EFI_FFS_FILE_HEADER *FfsFileHeader;
UINTN *KeyValue;
LIST_ENTRY *Link;
FFS_FILE_LIST_ENTRY *FfsFileEntry;
FvDevice = FV_DEVICE_FROM_THIS (This);
Status = FvGetVolumeAttributes (This, &FvAttributes);
if (EFI_ERROR (Status)){
if (EFI_ERROR (Status)) {
return Status;
}
@@ -151,7 +151,7 @@ FvGetNextFile (
}
KeyValue = (UINTN *)Key;
for (;;) {
for ( ; ;) {
if (*KeyValue == 0) {
//
// Search for 1st matching file
@@ -171,7 +171,7 @@ FvGetNextFile (
return EFI_NOT_FOUND;
}
FfsFileEntry = (FFS_FILE_LIST_ENTRY *)Link->ForwardLink;
FfsFileEntry = (FFS_FILE_LIST_ENTRY *)Link->ForwardLink;
FfsFileHeader = (EFI_FFS_FILE_HEADER *)FfsFileEntry->FfsHeader;
//
@@ -199,7 +199,6 @@ FvGetNextFile (
//
break;
}
}
//
@@ -224,8 +223,6 @@ FvGetNextFile (
return EFI_SUCCESS;
}
/**
Locates a file in the firmware volume and
copies it to the supplied buffer.
@@ -269,25 +266,25 @@ FvGetNextFile (
EFI_STATUS
EFIAPI
FvReadFile (
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *NameGuid,
IN OUT VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT EFI_FV_FILETYPE *FoundType,
OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
OUT UINT32 *AuthenticationStatus
IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,
IN CONST EFI_GUID *NameGuid,
IN OUT VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT EFI_FV_FILETYPE *FoundType,
OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,
OUT UINT32 *AuthenticationStatus
)
{
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_GUID SearchNameGuid;
EFI_FV_FILETYPE LocalFoundType;
EFI_FV_FILE_ATTRIBUTES LocalAttributes;
UINTN FileSize;
UINT8 *SrcPtr;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN InputBufferSize;
UINTN WholeFileSize;
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_GUID SearchNameGuid;
EFI_FV_FILETYPE LocalFoundType;
EFI_FV_FILE_ATTRIBUTES LocalAttributes;
UINTN FileSize;
UINT8 *SrcPtr;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN InputBufferSize;
UINTN WholeFileSize;
if (NameGuid == NULL) {
return EFI_INVALID_PARAMETER;
@@ -295,7 +292,6 @@ FvReadFile (
FvDevice = FV_DEVICE_FROM_THIS (This);
//
// Keep looking until we find the matching NameGuid.
// The Key is really a FfsFileEntry
@@ -303,14 +299,14 @@ FvReadFile (
FvDevice->LastKey = 0;
do {
LocalFoundType = 0;
Status = FvGetNextFile (
This,
&FvDevice->LastKey,
&LocalFoundType,
&SearchNameGuid,
&LocalAttributes,
&FileSize
);
Status = FvGetNextFile (
This,
&FvDevice->LastKey,
&LocalFoundType,
&SearchNameGuid,
&LocalAttributes,
&FileSize
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
@@ -328,15 +324,16 @@ FvReadFile (
//
// Cache FFS file to memory buffer.
//
WholeFileSize = IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHeader): FFS_FILE_SIZE (FfsHeader);
FfsHeader = AllocateCopyPool (WholeFileSize, FfsHeader);
WholeFileSize = IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHeader) : FFS_FILE_SIZE (FfsHeader);
FfsHeader = AllocateCopyPool (WholeFileSize, FfsHeader);
if (FfsHeader == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Let FfsHeader in FfsFileEntry point to the cached file buffer.
//
FvDevice->LastKey->FfsHeader = FfsHeader;
FvDevice->LastKey->FfsHeader = FfsHeader;
FvDevice->LastKey->FileCached = TRUE;
}
}
@@ -349,16 +346,17 @@ FvReadFile (
//
// Calculate return values
//
*FoundType = FfsHeader->Type;
*FoundType = FfsHeader->Type;
*FileAttributes = FfsAttributes2FvFileAttributes (FfsHeader->Attributes);
if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {
*FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;
}
if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) {
*FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;
}
//
// Inherit the authentication status.
//
*AuthenticationStatus = FvDevice->AuthenticationStatus;
*BufferSize = FileSize;
*BufferSize = FileSize;
if (Buffer == NULL) {
//
@@ -371,9 +369,9 @@ FvReadFile (
// Skip over file header
//
if (IS_FFS_FILE2 (FfsHeader)) {
SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
} else {
SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
}
Status = EFI_SUCCESS;
@@ -389,7 +387,7 @@ FvReadFile (
//
// Callers buffer was not big enough
//
Status = EFI_WARN_BUFFER_TOO_SMALL;
Status = EFI_WARN_BUFFER_TOO_SMALL;
FileSize = InputBufferSize;
}
@@ -401,8 +399,6 @@ FvReadFile (
return Status;
}
/**
Locates a section in a given FFS File and
copies it to the supplied buffer (not including section header).
@@ -443,15 +439,15 @@ FvReadFileSection (
OUT UINT32 *AuthenticationStatus
)
{
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FV_FILETYPE FileType;
EFI_FV_FILE_ATTRIBUTES FileAttributes;
UINTN FileSize;
UINT8 *FileBuffer;
FFS_FILE_LIST_ENTRY *FfsEntry;
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FV_FILETYPE FileType;
EFI_FV_FILE_ATTRIBUTES FileAttributes;
UINTN FileSize;
UINT8 *FileBuffer;
FFS_FILE_LIST_ENTRY *FfsEntry;
if (NameGuid == NULL || Buffer == NULL) {
if ((NameGuid == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -461,27 +457,29 @@ FvReadFileSection (
// Read the file
//
Status = FvReadFile (
This,
NameGuid,
NULL,
&FileSize,
&FileType,
&FileAttributes,
AuthenticationStatus
);
This,
NameGuid,
NULL,
&FileSize,
&FileType,
&FileAttributes,
AuthenticationStatus
);
//
// Get the last key used by our call to FvReadFile as it is the FfsEntry for this file.
//
FfsEntry = (FFS_FILE_LIST_ENTRY *) FvDevice->LastKey;
FfsEntry = (FFS_FILE_LIST_ENTRY *)FvDevice->LastKey;
if (EFI_ERROR (Status)) {
return Status;
}
if (IS_FFS_FILE2 (FfsEntry->FfsHeader)) {
FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
FileBuffer = ((UINT8 *)FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
} else {
FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
FileBuffer = ((UINT8 *)FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
}
//
// Check to see that the file actually HAS sections before we go any further.
//
@@ -532,5 +530,3 @@ FvReadFileSection (
Done:
return Status;
}

View File

@@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "FwVolDriver.h"
/**
Writes one or more files to the firmware volume.
@@ -42,5 +41,3 @@ FvWriteFile (
{
return EFI_UNSUPPORTED;
}

View File

@@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "FwVolBlock.h"
FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {
FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {
{
{
HARDWARE_DEVICE_PATH,
@@ -23,8 +23,8 @@ FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {
}
},
EfiMemoryMappedIO,
(EFI_PHYSICAL_ADDRESS) 0,
(EFI_PHYSICAL_ADDRESS) 0,
(EFI_PHYSICAL_ADDRESS)0,
(EFI_PHYSICAL_ADDRESS)0,
},
{
END_DEVICE_PATH_TYPE,
@@ -36,7 +36,7 @@ FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {
}
};
FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {
FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {
{
{
MEDIA_DEVICE_PATH,
@@ -79,8 +79,6 @@ EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {
0
};
/**
Retrieves Volume attributes. No polarity translations are done.
@@ -97,7 +95,7 @@ FwVolBlockGetAttributes (
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -109,8 +107,6 @@ FwVolBlockGetAttributes (
return EFI_SUCCESS;
}
/**
Modifies the current settings of the firmware volume according to the input parameter.
@@ -134,8 +130,6 @@ FwVolBlockSetAttributes (
return EFI_UNSUPPORTED;
}
/**
The EraseBlock() function erases one or more blocks as denoted by the
variable argument list. The entire parameter list of blocks must be verified
@@ -162,15 +156,13 @@ FwVolBlockSetAttributes (
EFI_STATUS
EFIAPI
FwVolBlockEraseBlock (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
...
)
{
return EFI_UNSUPPORTED;
}
/**
Read the specified number of bytes from the block to the input buffer.
@@ -194,19 +186,19 @@ FwVolBlockEraseBlock (
EFI_STATUS
EFIAPI
FwVolBlockReadBlock (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN CONST EFI_LBA Lba,
IN CONST UINTN Offset,
IN OUT UINTN *NumBytes,
IN OUT UINT8 *Buffer
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN CONST EFI_LBA Lba,
IN CONST UINTN Offset,
IN OUT UINTN *NumBytes,
IN OUT UINT8 *Buffer
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINT8 *LbaOffset;
UINTN LbaStart;
UINTN NumOfBytesRead;
UINTN LbaIndex;
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINT8 *LbaOffset;
UINTN LbaStart;
UINTN NumOfBytesRead;
UINTN LbaIndex;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -217,7 +209,7 @@ FwVolBlockReadBlock (
return EFI_ACCESS_DENIED;
}
LbaIndex = (UINTN) Lba;
LbaIndex = (UINTN)Lba;
if (LbaIndex >= FvbDevice->NumBlocks) {
//
// Invalid Lba, read nothing.
@@ -242,9 +234,9 @@ FwVolBlockReadBlock (
NumOfBytesRead = FvbDevice->LbaCache[LbaIndex].Length - Offset;
}
LbaStart = FvbDevice->LbaCache[LbaIndex].Base;
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN) FvbDevice->BaseAddress);
LbaOffset = (UINT8 *) FwVolHeader + LbaStart + Offset;
LbaStart = FvbDevice->LbaCache[LbaIndex].Base;
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbDevice->BaseAddress);
LbaOffset = (UINT8 *)FwVolHeader + LbaStart + Offset;
//
// Perform read operation
@@ -259,8 +251,6 @@ FwVolBlockReadBlock (
return EFI_BAD_BUFFER_SIZE;
}
/**
Writes the specified number of bytes from the input buffer to the block.
@@ -288,18 +278,16 @@ FwVolBlockReadBlock (
EFI_STATUS
EFIAPI
FwVolBlockWriteBlock (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
)
{
return EFI_UNSUPPORTED;
}
/**
Get Fvb's base address.
@@ -317,7 +305,7 @@ FwVolBlockGetPhysicalAddress (
OUT EFI_PHYSICAL_ADDRESS *Address
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -329,8 +317,6 @@ FwVolBlockGetPhysicalAddress (
return EFI_UNSUPPORTED;
}
/**
Retrieves the size in bytes of a specific block within a firmware volume.
@@ -357,10 +343,10 @@ FwVolBlockGetBlockSize (
IN OUT UINTN *NumberOfBlocks
)
{
UINTN TotalBlocks;
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINTN TotalBlocks;
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
FvbDevice = FVB_DEVICE_FROM_THIS (This);
@@ -379,7 +365,7 @@ FwVolBlockGetBlockSize (
// Search the block map for the given block
//
TotalBlocks = 0;
while ((PtrBlockMapEntry->NumBlocks != 0) || (PtrBlockMapEntry->Length !=0 )) {
while ((PtrBlockMapEntry->NumBlocks != 0) || (PtrBlockMapEntry->Length != 0)) {
TotalBlocks += PtrBlockMapEntry->NumBlocks;
if (Lba < TotalBlocks) {
//
@@ -391,7 +377,7 @@ FwVolBlockGetBlockSize (
PtrBlockMapEntry++;
}
*BlockSize = PtrBlockMapEntry->Length;
*BlockSize = PtrBlockMapEntry->Length;
*NumberOfBlocks = TotalBlocks - (UINTN)Lba;
return EFI_SUCCESS;
@@ -408,14 +394,14 @@ FwVolBlockGetBlockSize (
**/
UINT32
GetFvbAuthenticationStatus (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
UINT32 AuthenticationStatus;
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
UINT32 AuthenticationStatus;
AuthenticationStatus = 0;
FvbDevice = BASE_CR (FvbProtocol, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance);
FvbDevice = BASE_CR (FvbProtocol, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance);
if (FvbDevice->Signature == FVB_DEVICE_SIGNATURE) {
AuthenticationStatus = FvbDevice->AuthenticationStatus;
}
@@ -444,24 +430,24 @@ GetFvbAuthenticationStatus (
**/
EFI_STATUS
ProduceFVBProtocolOnBuffer (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_HANDLE ParentHandle,
IN UINT32 AuthenticationStatus,
OUT EFI_HANDLE *FvProtocol OPTIONAL
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_HANDLE ParentHandle,
IN UINT32 AuthenticationStatus,
OUT EFI_HANDLE *FvProtocol OPTIONAL
)
{
EFI_STATUS Status;
EFI_FW_VOL_BLOCK_DEVICE *FvbDev;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINTN BlockIndex;
UINTN BlockIndex2;
UINTN LinearOffset;
UINT32 FvAlignment;
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
EFI_STATUS Status;
EFI_FW_VOL_BLOCK_DEVICE *FvbDev;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
UINTN BlockIndex;
UINTN BlockIndex2;
UINTN LinearOffset;
UINT32 FvAlignment;
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
FvAlignment = 0;
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN) BaseAddress;
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress;
//
// Validate FV Header, if not as expected, return
//
@@ -485,6 +471,7 @@ ProduceFVBProtocolOnBuffer (
if (FvAlignment < 8) {
FvAlignment = 8;
}
if ((UINTN)BaseAddress % FvAlignment != 0) {
//
// FvImage buffer is not at its required alignment.
@@ -508,10 +495,10 @@ ProduceFVBProtocolOnBuffer (
return EFI_OUT_OF_RESOURCES;
}
FvbDev->BaseAddress = BaseAddress;
FvbDev->FvbAttributes = FwVolHeader->Attributes;
FvbDev->BaseAddress = BaseAddress;
FvbDev->FvbAttributes = FwVolHeader->Attributes;
FvbDev->FwVolBlockInstance.ParentHandle = ParentHandle;
FvbDev->AuthenticationStatus = AuthenticationStatus;
FvbDev->AuthenticationStatus = AuthenticationStatus;
//
// Init the block caching fields of the device
@@ -520,7 +507,8 @@ ProduceFVBProtocolOnBuffer (
FvbDev->NumBlocks = 0;
for (PtrBlockMapEntry = FwVolHeader->BlockMap;
PtrBlockMapEntry->NumBlocks != 0;
PtrBlockMapEntry++) {
PtrBlockMapEntry++)
{
FvbDev->NumBlocks += PtrBlockMapEntry->NumBlocks;
}
@@ -531,6 +519,7 @@ ProduceFVBProtocolOnBuffer (
CoreFreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
}
FvbDev->LbaCache = AllocatePool (FvbDev->NumBlocks * sizeof (LBA_CACHE));
if (FvbDev->LbaCache == NULL) {
CoreFreePool (FvbDev);
@@ -540,14 +529,15 @@ ProduceFVBProtocolOnBuffer (
//
// Last, fill in the cache with the linear address of the blocks
//
BlockIndex = 0;
BlockIndex = 0;
LinearOffset = 0;
for (PtrBlockMapEntry = FwVolHeader->BlockMap;
PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {
PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++)
{
for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {
FvbDev->LbaCache[BlockIndex].Base = LinearOffset;
FvbDev->LbaCache[BlockIndex].Base = LinearOffset;
FvbDev->LbaCache[BlockIndex].Length = PtrBlockMapEntry->Length;
LinearOffset += PtrBlockMapEntry->Length;
LinearOffset += PtrBlockMapEntry->Length;
BlockIndex++;
}
}
@@ -559,22 +549,24 @@ ProduceFVBProtocolOnBuffer (
//
// FV does not contains extension header, then produce MEMMAP_DEVICE_PATH
//
FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
if (FvbDev->DevicePath == NULL) {
FreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
}
((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;
((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;
((FV_MEMMAP_DEVICE_PATH *)FvbDev->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;
((FV_MEMMAP_DEVICE_PATH *)FvbDev->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;
} else {
//
// FV contains extension header, then produce MEDIA_FW_VOL_DEVICE_PATH
//
FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
if (FvbDev->DevicePath == NULL) {
FreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
}
CopyGuid (
&((FV_PIWG_DEVICE_PATH *)FvbDev->DevicePath)->FvDevPath.FvName,
(GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset)
@@ -587,8 +579,10 @@ ProduceFVBProtocolOnBuffer (
//
Status = CoreInstallMultipleProtocolInterfaces (
&FvbDev->Handle,
&gEfiFirmwareVolumeBlockProtocolGuid, &FvbDev->FwVolBlockInstance,
&gEfiDevicePathProtocolGuid, FvbDev->DevicePath,
&gEfiFirmwareVolumeBlockProtocolGuid,
&FvbDev->FwVolBlockInstance,
&gEfiDevicePathProtocolGuid,
FvbDev->DevicePath,
NULL
);
@@ -602,8 +596,6 @@ ProduceFVBProtocolOnBuffer (
return Status;
}
/**
This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.
@@ -617,13 +609,13 @@ ProduceFVBProtocolOnBuffer (
EFI_STATUS
EFIAPI
FwVolBlockDriverInit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_PEI_HOB_POINTERS FvHob;
EFI_PEI_HOB_POINTERS Fv3Hob;
UINT32 AuthenticationStatus;
EFI_PEI_HOB_POINTERS FvHob;
EFI_PEI_HOB_POINTERS Fv3Hob;
UINT32 AuthenticationStatus;
//
// Core Needs Firmware Volumes to function
@@ -637,12 +629,15 @@ FwVolBlockDriverInit (
Fv3Hob.Raw = GetHobList ();
while ((Fv3Hob.Raw = GetNextHob (EFI_HOB_TYPE_FV3, Fv3Hob.Raw)) != NULL) {
if ((Fv3Hob.FirmwareVolume3->BaseAddress == FvHob.FirmwareVolume->BaseAddress) &&
(Fv3Hob.FirmwareVolume3->Length == FvHob.FirmwareVolume->Length)) {
(Fv3Hob.FirmwareVolume3->Length == FvHob.FirmwareVolume->Length))
{
AuthenticationStatus = Fv3Hob.FirmwareVolume3->AuthenticationStatus;
break;
}
Fv3Hob.Raw = GET_NEXT_HOB (Fv3Hob);
}
//
// Produce an FVB protocol for it
//
@@ -653,8 +648,6 @@ FwVolBlockDriverInit (
return EFI_SUCCESS;
}
/**
This DXE service routine is used to process a firmware volume. In
particular, it can be called by BDS to process a single firmware
@@ -679,22 +672,22 @@ FwVolBlockDriverInit (
EFI_STATUS
EFIAPI
CoreProcessFirmwareVolume (
IN VOID *FvHeader,
IN UINTN Size,
OUT EFI_HANDLE *FVProtocolHandle
IN VOID *FvHeader,
IN UINTN Size,
OUT EFI_HANDLE *FVProtocolHandle
)
{
VOID *Ptr;
EFI_STATUS Status;
*FVProtocolHandle = NULL;
Status = ProduceFVBProtocolOnBuffer (
(EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,
(UINT64)Size,
NULL,
0,
FVProtocolHandle
);
Status = ProduceFVBProtocolOnBuffer (
(EFI_PHYSICAL_ADDRESS)(UINTN)FvHeader,
(UINT64)Size,
NULL,
0,
FVProtocolHandle
);
//
// Since in our implementation we use register-protocol-notify to put a
// FV protocol on the FVB protocol handle, we can't directly verify that
@@ -703,17 +696,16 @@ CoreProcessFirmwareVolume (
// well. Otherwise we have to assume that the volume was corrupted
// somehow.
//
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
ASSERT (*FVProtocolHandle != NULL);
Ptr = NULL;
Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &Ptr);
if (EFI_ERROR(Status) || (Ptr == NULL)) {
Ptr = NULL;
Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Ptr);
if (EFI_ERROR (Status) || (Ptr == NULL)) {
return EFI_VOLUME_CORRUPTED;
}
return EFI_SUCCESS;
}
return Status;
}

View File

@@ -10,13 +10,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _FWVOL_BLOCK_H_
#define _FWVOL_BLOCK_H_
#define FVB_DEVICE_SIGNATURE SIGNATURE_32('_','F','V','B')
#define FVB_DEVICE_SIGNATURE SIGNATURE_32('_','F','V','B')
typedef struct {
UINTN Base;
UINTN Length;
UINTN Base;
UINTN Length;
} LBA_CACHE;
typedef struct {
@@ -44,11 +42,9 @@ typedef struct {
UINT32 AuthenticationStatus;
} EFI_FW_VOL_BLOCK_DEVICE;
#define FVB_DEVICE_FROM_THIS(a) \
CR(a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
/**
Retrieves Volume attributes. No polarity translations are done.
@@ -65,8 +61,6 @@ FwVolBlockGetAttributes (
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
);
/**
Modifies the current settings of the firmware volume according to the input parameter.
@@ -87,8 +81,6 @@ FwVolBlockSetAttributes (
IN CONST EFI_FVB_ATTRIBUTES_2 *Attributes
);
/**
The EraseBlock() function erases one or more blocks as denoted by the
variable argument list. The entire parameter list of blocks must be verified
@@ -115,12 +107,10 @@ FwVolBlockSetAttributes (
EFI_STATUS
EFIAPI
FwVolBlockEraseBlock (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
...
);
/**
Read the specified number of bytes from the block to the input buffer.
@@ -144,15 +134,13 @@ FwVolBlockEraseBlock (
EFI_STATUS
EFIAPI
FwVolBlockReadBlock (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN CONST EFI_LBA Lba,
IN CONST UINTN Offset,
IN OUT UINTN *NumBytes,
IN OUT UINT8 *Buffer
IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN CONST EFI_LBA Lba,
IN CONST UINTN Offset,
IN OUT UINTN *NumBytes,
IN OUT UINT8 *Buffer
);
/**
Writes the specified number of bytes from the input buffer to the block.
@@ -180,15 +168,13 @@ FwVolBlockReadBlock (
EFI_STATUS
EFIAPI
FwVolBlockWriteBlock (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
);
/**
Get Fvb's base address.
@@ -206,8 +192,6 @@ FwVolBlockGetPhysicalAddress (
OUT EFI_PHYSICAL_ADDRESS *Address
);
/**
Retrieves the size in bytes of a specific block within a firmware volume.
@@ -234,5 +218,4 @@ FwVolBlockGetBlockSize (
IN OUT UINTN *NumberOfBlocks
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -13,8 +13,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// GCD Operations
//
#define GCD_MEMORY_SPACE_OPERATION 0x20
#define GCD_IO_SPACE_OPERATION 0x40
#define GCD_MEMORY_SPACE_OPERATION 0x20
#define GCD_IO_SPACE_OPERATION 0x40
#define GCD_ADD_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 0)
#define GCD_ALLOCATE_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 1)
@@ -23,18 +23,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define GCD_SET_ATTRIBUTES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 4)
#define GCD_SET_CAPABILITIES_MEMORY_OPERATION (GCD_MEMORY_SPACE_OPERATION | 5)
#define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0)
#define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1)
#define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2)
#define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3)
#define GCD_ADD_IO_OPERATION (GCD_IO_SPACE_OPERATION | 0)
#define GCD_ALLOCATE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 1)
#define GCD_FREE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 2)
#define GCD_REMOVE_IO_OPERATION (GCD_IO_SPACE_OPERATION | 3)
//
// The data structure used to convert from GCD attributes to EFI Memory Map attributes
//
typedef struct {
UINT64 Attribute;
UINT64 Capability;
BOOLEAN Memory;
UINT64 Attribute;
UINT64 Capability;
BOOLEAN Memory;
} GCD_ATTRIBUTE_CONVERSION_ENTRY;
#endif

View File

@@ -9,10 +9,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "Handle.h"
//
// Driver Support Functions
//
/**
Connects one or more drivers to a controller.
@@ -48,22 +48,22 @@ CoreConnectController (
IN BOOLEAN Recursive
)
{
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
IHANDLE *Handle;
PROTOCOL_INTERFACE *Prot;
LIST_ENTRY *Link;
LIST_ENTRY *ProtLink;
OPEN_PROTOCOL_DATA *OpenData;
EFI_DEVICE_PATH_PROTOCOL *AlignedRemainingDevicePath;
EFI_HANDLE *ChildHandleBuffer;
UINTN ChildHandleCount;
UINTN Index;
UINTN HandleFilePathSize;
UINTN RemainingDevicePathSize;
EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_DEVICE_PATH_PROTOCOL *TempFilePath;
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
IHANDLE *Handle;
PROTOCOL_INTERFACE *Prot;
LIST_ENTRY *Link;
LIST_ENTRY *ProtLink;
OPEN_PROTOCOL_DATA *OpenData;
EFI_DEVICE_PATH_PROTOCOL *AlignedRemainingDevicePath;
EFI_HANDLE *ChildHandleBuffer;
UINTN ChildHandleCount;
UINTN Index;
UINTN HandleFilePathSize;
UINTN RemainingDevicePathSize;
EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_DEVICE_PATH_PROTOCOL *TempFilePath;
//
// Make sure ControllerHandle is valid
@@ -87,25 +87,27 @@ CoreConnectController (
ASSERT (HandleFilePath != NULL);
FilePath = HandleFilePath;
TempFilePath = NULL;
if (RemainingDevicePath != NULL && !Recursive) {
if ((RemainingDevicePath != NULL) && !Recursive) {
HandleFilePathSize = GetDevicePathSize (HandleFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
RemainingDevicePathSize = GetDevicePathSize (RemainingDevicePath);
TempFilePath = AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);
TempFilePath = AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);
ASSERT (TempFilePath != NULL);
CopyMem (TempFilePath, HandleFilePath, HandleFilePathSize);
CopyMem ((UINT8 *) TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);
CopyMem ((UINT8 *)TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);
FilePath = TempFilePath;
}
Status = gSecurity2->FileAuthentication (
gSecurity2,
FilePath,
NULL,
0,
FALSE
);
gSecurity2,
FilePath,
NULL,
0,
FALSE
);
if (TempFilePath != NULL) {
FreePool (TempFilePath);
}
if (EFI_ERROR (Status)) {
return Status;
}
@@ -169,15 +171,15 @@ CoreConnectController (
return ReturnStatus;
}
//
// Count ControllerHandle's children
//
for (Link = Handle->Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink) {
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink)
{
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
ChildHandleCount++;
@@ -188,7 +190,7 @@ CoreConnectController (
//
// Allocate a handle buffer for ControllerHandle's children
//
ChildHandleBuffer = AllocatePool (ChildHandleCount * sizeof(EFI_HANDLE));
ChildHandleBuffer = AllocatePool (ChildHandleCount * sizeof (EFI_HANDLE));
if (ChildHandleBuffer == NULL) {
CoreReleaseProtocolLock ();
return EFI_OUT_OF_RESOURCES;
@@ -198,10 +200,11 @@ CoreConnectController (
// Fill in a handle buffer with ControllerHandle's children
//
for (Link = Handle->Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink) {
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink)
{
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
ChildHandleBuffer[ChildHandleCount] = OpenData->ControllerHandle;
@@ -236,7 +239,6 @@ CoreConnectController (
return ReturnStatus;
}
/**
Add Driver Binding Protocols from Context Driver Image Handles to sorted
Driver Binding Protocol list.
@@ -296,11 +298,11 @@ AddSortedDriverBindingProtocol (
// Retrieve the Driver Binding Protocol associated with each Driver Binding Handle
//
Status = CoreHandleProtocol (
DriverBindingHandleBuffer[Index],
&gEfiDriverBindingProtocolGuid,
(VOID **) &DriverBinding
);
if (EFI_ERROR (Status) || DriverBinding == NULL) {
DriverBindingHandleBuffer[Index],
&gEfiDriverBindingProtocolGuid,
(VOID **)&DriverBinding
);
if (EFI_ERROR (Status) || (DriverBinding == NULL)) {
continue;
}
@@ -319,21 +321,22 @@ AddSortedDriverBindingProtocol (
);
}
}
return;
}
//
// Retrieve the Driver Binding Protocol from DriverBindingHandle
//
Status = CoreHandleProtocol(
Status = CoreHandleProtocol (
DriverBindingHandle,
&gEfiDriverBindingProtocolGuid,
(VOID **) &DriverBinding
(VOID **)&DriverBinding
);
//
// If DriverBindingHandle does not support the Driver Binding Protocol then return
//
if (EFI_ERROR (Status) || DriverBinding == NULL) {
if (EFI_ERROR (Status) || (DriverBinding == NULL)) {
return;
}
@@ -352,6 +355,7 @@ AddSortedDriverBindingProtocol (
if (*NumberOfSortedDriverBindingProtocols < DriverBindingHandleCount) {
SortedDriverBindingProtocols[*NumberOfSortedDriverBindingProtocols] = DriverBinding;
}
*NumberOfSortedDriverBindingProtocols = *NumberOfSortedDriverBindingProtocols + 1;
//
@@ -364,7 +368,6 @@ AddSortedDriverBindingProtocol (
}
}
/**
Connects a controller to a driver.
@@ -416,12 +419,12 @@ CoreConnectSingleController (
//
// Initialize local variables
//
DriverBindingHandleCount = 0;
DriverBindingHandleBuffer = NULL;
NumberOfSortedDriverBindingProtocols = 0;
SortedDriverBindingProtocols = NULL;
PlatformDriverOverride = NULL;
NewDriverBindingHandleBuffer = NULL;
DriverBindingHandleCount = 0;
DriverBindingHandleBuffer = NULL;
NumberOfSortedDriverBindingProtocols = 0;
SortedDriverBindingProtocols = NULL;
PlatformDriverOverride = NULL;
NewDriverBindingHandleBuffer = NULL;
//
// Get list of all Driver Binding Protocol Instances
@@ -468,7 +471,7 @@ CoreConnectSingleController (
Status = CoreLocateProtocol (
&gEfiPlatformDriverOverrideProtocolGuid,
NULL,
(VOID **) &PlatformDriverOverride
(VOID **)&PlatformDriverOverride
);
if (!EFI_ERROR (Status) && (PlatformDriverOverride != NULL)) {
DriverImageHandle = NULL;
@@ -501,7 +504,7 @@ CoreConnectSingleController (
Status = CoreHandleProtocol (
DriverBindingHandleBuffer[Index],
&gEfiDriverFamilyOverrideProtocolGuid,
(VOID **) &DriverFamilyOverride
(VOID **)&DriverFamilyOverride
);
if (!EFI_ERROR (Status) && (DriverFamilyOverride != NULL)) {
DriverFamilyOverrideVersion = DriverFamilyOverride->GetVersion (DriverFamilyOverride);
@@ -532,7 +535,7 @@ CoreConnectSingleController (
Status = CoreHandleProtocol (
ControllerHandle,
&gEfiBusSpecificDriverOverrideProtocolGuid,
(VOID **) &BusSpecificDriverOverride
(VOID **)&BusSpecificDriverOverride
);
if (!EFI_ERROR (Status) && (BusSpecificDriverOverride != NULL)) {
DriverImageHandle = NULL;
@@ -608,9 +611,10 @@ CoreConnectSingleController (
HighestIndex = Index;
}
}
if (SortIndex != HighestIndex) {
DriverBinding = SortedDriverBindingProtocols[SortIndex];
SortedDriverBindingProtocols[SortIndex] = SortedDriverBindingProtocols[HighestIndex];
DriverBinding = SortedDriverBindingProtocols[SortIndex];
SortedDriverBindingProtocols[SortIndex] = SortedDriverBindingProtocols[HighestIndex];
SortedDriverBindingProtocols[HighestIndex] = DriverBinding;
}
}
@@ -620,19 +624,18 @@ CoreConnectSingleController (
//
OneStarted = FALSE;
do {
//
// Loop through the sorted Driver Binding Protocol Instances in order, and see if
// any of the Driver Binding Protocols support the controller specified by
// ControllerHandle.
//
DriverBinding = NULL;
DriverFound = FALSE;
DriverFound = FALSE;
for (Index = 0; (Index < NumberOfSortedDriverBindingProtocols) && !DriverFound; Index++) {
if (SortedDriverBindingProtocols[Index] != NULL) {
DriverBinding = SortedDriverBindingProtocols[Index];
PERF_DRIVER_BINDING_SUPPORT_BEGIN (DriverBinding->DriverBindingHandle, ControllerHandle);
Status = DriverBinding->Supported(
Status = DriverBinding->Supported (
DriverBinding,
ControllerHandle,
RemainingDevicePath
@@ -640,7 +643,7 @@ CoreConnectSingleController (
PERF_DRIVER_BINDING_SUPPORT_END (DriverBinding->DriverBindingHandle, ControllerHandle);
if (!EFI_ERROR (Status)) {
SortedDriverBindingProtocols[Index] = NULL;
DriverFound = TRUE;
DriverFound = TRUE;
//
// A driver was found that supports ControllerHandle, so attempt to start the driver
@@ -692,8 +695,6 @@ CoreConnectSingleController (
return EFI_NOT_FOUND;
}
/**
Disonnects a controller from a driver
@@ -734,24 +735,24 @@ CoreDisconnectController (
IN EFI_HANDLE ChildHandle OPTIONAL
)
{
EFI_STATUS Status;
IHANDLE *Handle;
EFI_HANDLE *DriverImageHandleBuffer;
EFI_HANDLE *ChildBuffer;
UINTN Index;
UINTN HandleIndex;
UINTN DriverImageHandleCount;
UINTN ChildrenToStop;
UINTN ChildBufferCount;
UINTN StopCount;
BOOLEAN Duplicate;
BOOLEAN ChildHandleValid;
BOOLEAN DriverImageHandleValid;
LIST_ENTRY *Link;
LIST_ENTRY *ProtLink;
OPEN_PROTOCOL_DATA *OpenData;
PROTOCOL_INTERFACE *Prot;
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
EFI_STATUS Status;
IHANDLE *Handle;
EFI_HANDLE *DriverImageHandleBuffer;
EFI_HANDLE *ChildBuffer;
UINTN Index;
UINTN HandleIndex;
UINTN DriverImageHandleCount;
UINTN ChildrenToStop;
UINTN ChildBufferCount;
UINTN StopCount;
BOOLEAN Duplicate;
BOOLEAN ChildHandleValid;
BOOLEAN DriverImageHandleValid;
LIST_ENTRY *Link;
LIST_ENTRY *ProtLink;
OPEN_PROTOCOL_DATA *OpenData;
PROTOCOL_INTERFACE *Prot;
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
//
// Make sure ControllerHandle is valid
@@ -793,16 +794,18 @@ CoreDisconnectController (
CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink) {
ProtLink = ProtLink->ForwardLink)
{
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
DriverImageHandleCount++;
}
}
}
CoreReleaseProtocolLock ();
//
@@ -823,19 +826,21 @@ CoreDisconnectController (
CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink) {
ProtLink = ProtLink->ForwardLink)
{
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
Duplicate = FALSE;
for (Index = 0; Index< DriverImageHandleCount; Index++) {
for (Index = 0; Index < DriverImageHandleCount; Index++) {
if (DriverImageHandleBuffer[Index] == OpenData->AgentHandle) {
Duplicate = TRUE;
break;
}
}
if (!Duplicate) {
DriverImageHandleBuffer[DriverImageHandleCount] = OpenData->AgentHandle;
DriverImageHandleCount++;
@@ -843,12 +848,12 @@ CoreDisconnectController (
}
}
}
CoreReleaseProtocolLock ();
}
StopCount = 0;
for (HandleIndex = 0; HandleIndex < DriverImageHandleCount; HandleIndex++) {
if (DriverImageHandleBuffer != NULL) {
DriverImageHandle = DriverImageHandleBuffer[HandleIndex];
}
@@ -861,7 +866,7 @@ CoreDisconnectController (
&gEfiDriverBindingProtocolGuid,
(VOID **)&DriverBinding
);
if (EFI_ERROR (Status) || DriverBinding == NULL) {
if (EFI_ERROR (Status) || (DriverBinding == NULL)) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
@@ -870,30 +875,33 @@ CoreDisconnectController (
// Look at each protocol interface for a match
//
DriverImageHandleValid = FALSE;
ChildBufferCount = 0;
ChildBufferCount = 0;
CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink) {
ProtLink = ProtLink->ForwardLink)
{
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if (OpenData->AgentHandle == DriverImageHandle) {
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
ChildBufferCount++;
}
if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
DriverImageHandleValid = TRUE;
}
}
}
}
CoreReleaseProtocolLock ();
if (DriverImageHandleValid) {
ChildHandleValid = FALSE;
ChildBuffer = NULL;
ChildBuffer = NULL;
if (ChildBufferCount != 0) {
ChildBuffer = AllocatePool (sizeof (EFI_HANDLE) * ChildBufferCount);
if (ChildBuffer == NULL) {
@@ -905,13 +913,15 @@ CoreDisconnectController (
CoreAcquireProtocolLock ();
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
for (ProtLink = Prot->OpenList.ForwardLink;
ProtLink != &Prot->OpenList;
ProtLink = ProtLink->ForwardLink) {
ProtLink = ProtLink->ForwardLink)
{
OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
if ((OpenData->AgentHandle == DriverImageHandle) &&
((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0)) {
((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0))
{
Duplicate = FALSE;
for (Index = 0; Index < ChildBufferCount; Index++) {
if (ChildBuffer[Index] == OpenData->ControllerHandle) {
@@ -919,34 +929,39 @@ CoreDisconnectController (
break;
}
}
if (!Duplicate) {
ChildBuffer[ChildBufferCount] = OpenData->ControllerHandle;
if (ChildHandle == ChildBuffer[ChildBufferCount]) {
ChildHandleValid = TRUE;
}
ChildBufferCount++;
}
}
}
}
CoreReleaseProtocolLock ();
}
if (ChildHandle == NULL || ChildHandleValid) {
if ((ChildHandle == NULL) || ChildHandleValid) {
ChildrenToStop = 0;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
if (ChildBufferCount > 0) {
if (ChildHandle != NULL) {
ChildrenToStop = 1;
Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, &ChildHandle);
Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, &ChildHandle);
} else {
ChildrenToStop = ChildBufferCount;
Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, ChildBuffer);
Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, ChildBuffer);
}
}
if (!EFI_ERROR (Status) && ((ChildHandle == NULL) || (ChildBufferCount == ChildrenToStop))) {
Status = DriverBinding->Stop (DriverBinding, ControllerHandle, 0, NULL);
}
if (!EFI_ERROR (Status)) {
StopCount++;
}

File diff suppressed because it is too large Load Diff

View File

@@ -9,26 +9,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _HAND_H_
#define _HAND_H_
#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
///
/// IHANDLE - contains a list of protocol handles
///
typedef struct {
UINTN Signature;
UINTN Signature;
/// All handles list of IHANDLE
LIST_ENTRY AllHandles;
LIST_ENTRY AllHandles;
/// List of PROTOCOL_INTERFACE's for this handle
LIST_ENTRY Protocols;
UINTN LocateRequest;
LIST_ENTRY Protocols;
UINTN LocateRequest;
/// The Handle Database Key value when this handle was last created or modified
UINT64 Key;
UINT64 Key;
} IHANDLE;
#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
///
/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
@@ -36,18 +35,17 @@ typedef struct {
/// with a list of registered notifies.
///
typedef struct {
UINTN Signature;
UINTN Signature;
/// Link Entry inserted to mProtocolDatabase
LIST_ENTRY AllEntries;
LIST_ENTRY AllEntries;
/// ID of the protocol
EFI_GUID ProtocolID;
EFI_GUID ProtocolID;
/// All protocol interfaces
LIST_ENTRY Protocols;
LIST_ENTRY Protocols;
/// Registerd notification handlers
LIST_ENTRY Notify;
LIST_ENTRY Notify;
} PROTOCOL_ENTRY;
#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
///
@@ -55,55 +53,51 @@ typedef struct {
/// with a protocol interface structure
///
typedef struct {
UINTN Signature;
UINTN Signature;
/// Link on IHANDLE.Protocols
LIST_ENTRY Link;
LIST_ENTRY Link;
/// Back pointer
IHANDLE *Handle;
IHANDLE *Handle;
/// Link on PROTOCOL_ENTRY.Protocols
LIST_ENTRY ByProtocol;
LIST_ENTRY ByProtocol;
/// The protocol ID
PROTOCOL_ENTRY *Protocol;
PROTOCOL_ENTRY *Protocol;
/// The interface value
VOID *Interface;
VOID *Interface;
/// OPEN_PROTOCOL_DATA list
LIST_ENTRY OpenList;
UINTN OpenListCount;
LIST_ENTRY OpenList;
UINTN OpenListCount;
} PROTOCOL_INTERFACE;
#define OPEN_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('p','o','d','l')
typedef struct {
UINTN Signature;
///Link on PROTOCOL_INTERFACE.OpenList
LIST_ENTRY Link;
UINTN Signature;
/// Link on PROTOCOL_INTERFACE.OpenList
LIST_ENTRY Link;
EFI_HANDLE AgentHandle;
EFI_HANDLE ControllerHandle;
UINT32 Attributes;
UINT32 OpenCount;
EFI_HANDLE AgentHandle;
EFI_HANDLE ControllerHandle;
UINT32 Attributes;
UINT32 OpenCount;
} OPEN_PROTOCOL_DATA;
#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
///
/// PROTOCOL_NOTIFY - used for each register notification for a protocol
///
typedef struct {
UINTN Signature;
PROTOCOL_ENTRY *Protocol;
UINTN Signature;
PROTOCOL_ENTRY *Protocol;
/// All notifications for this protocol
LIST_ENTRY Link;
LIST_ENTRY Link;
/// Event to notify
EFI_EVENT Event;
EFI_EVENT Event;
/// Last position notified
LIST_ENTRY *Position;
LIST_ENTRY *Position;
} PROTOCOL_NOTIFY;
/**
Finds the protocol entry for the requested protocol.
The gProtocolDatabaseLock must be owned
@@ -116,11 +110,10 @@ typedef struct {
**/
PROTOCOL_ENTRY *
CoreFindProtocolEntry (
IN EFI_GUID *Protocol,
IN BOOLEAN Create
IN EFI_GUID *Protocol,
IN BOOLEAN Create
);
/**
Signal event for every protocol in protocol entry.
@@ -129,10 +122,9 @@ CoreFindProtocolEntry (
**/
VOID
CoreNotifyProtocolEntry (
IN PROTOCOL_ENTRY *ProtEntry
IN PROTOCOL_ENTRY *ProtEntry
);
/**
Finds the protocol instance for the requested handle and protocol.
Note: This function doesn't do parameters checking, it's caller's responsibility
@@ -147,12 +139,11 @@ CoreNotifyProtocolEntry (
**/
PROTOCOL_INTERFACE *
CoreFindProtocolInterface (
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
);
/**
Removes Protocol from the protocol list (but not the handle list).
@@ -165,12 +156,11 @@ CoreFindProtocolInterface (
**/
PROTOCOL_INTERFACE *
CoreRemoveInterfaceFromProtocol (
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
);
/**
Connects a controller to a driver.
@@ -215,11 +205,10 @@ CoreConnectSingleController (
**/
EFI_STATUS
CoreDisconnectControllersUsingProtocolInterface (
IN EFI_HANDLE UserHandle,
IN PROTOCOL_INTERFACE *Prot
IN EFI_HANDLE UserHandle,
IN PROTOCOL_INTERFACE *Prot
);
/**
Acquire lock on gProtocolDatabaseLock.
@@ -229,7 +218,6 @@ CoreAcquireProtocolLock (
VOID
);
/**
Release lock on gProtocolDatabaseLock.
@@ -239,7 +227,6 @@ CoreReleaseProtocolLock (
VOID
);
/**
Check whether a handle is a valid EFI_HANDLE
The gProtocolDatabaseLock must be owned
@@ -252,14 +239,14 @@ CoreReleaseProtocolLock (
**/
EFI_STATUS
CoreValidateHandle (
IN EFI_HANDLE UserHandle
IN EFI_HANDLE UserHandle
);
//
// Externs
//
extern EFI_LOCK gProtocolDatabaseLock;
extern LIST_ENTRY gHandleList;
extern UINT64 gHandleDatabaseKey;
extern EFI_LOCK gProtocolDatabaseLock;
extern LIST_ENTRY gHandleList;
extern UINT64 gHandleDatabaseKey;
#endif

View File

@@ -12,24 +12,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// ProtocolRequest - Last LocateHandle request ID
//
UINTN mEfiLocateHandleRequest = 0;
UINTN mEfiLocateHandleRequest = 0;
//
// Internal prototypes
//
typedef struct {
EFI_GUID *Protocol;
VOID *SearchKey;
LIST_ENTRY *Position;
PROTOCOL_ENTRY *ProtEntry;
EFI_GUID *Protocol;
VOID *SearchKey;
LIST_ENTRY *Position;
PROTOCOL_ENTRY *ProtEntry;
} LOCATE_POSITION;
typedef
IHANDLE *
(* CORE_GET_NEXT) (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
(*CORE_GET_NEXT) (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
);
/**
@@ -45,8 +45,8 @@ IHANDLE *
**/
IHANDLE *
CoreGetNextLocateAllHandles (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
);
/**
@@ -63,8 +63,8 @@ CoreGetNextLocateAllHandles (
**/
IHANDLE *
CoreGetNextLocateByRegisterNotify (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
);
/**
@@ -80,11 +80,10 @@ CoreGetNextLocateByRegisterNotify (
**/
IHANDLE *
CoreGetNextLocateByProtocol (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
);
/**
Internal function for locating the requested handle(s) and returns them in Buffer.
The caller should already have acquired the ProtocolLock.
@@ -106,21 +105,21 @@ CoreGetNextLocateByProtocol (
**/
EFI_STATUS
InternalCoreLocateHandle (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
)
{
EFI_STATUS Status;
LOCATE_POSITION Position;
PROTOCOL_NOTIFY *ProtNotify;
CORE_GET_NEXT GetNext;
UINTN ResultSize;
IHANDLE *Handle;
IHANDLE **ResultBuffer;
VOID *Interface;
EFI_STATUS Status;
LOCATE_POSITION Position;
PROTOCOL_NOTIFY *ProtNotify;
CORE_GET_NEXT GetNext;
UINTN ResultSize;
IHANDLE *Handle;
IHANDLE **ResultBuffer;
VOID *Interface;
if (BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
@@ -139,52 +138,55 @@ InternalCoreLocateHandle (
Position.SearchKey = SearchKey;
Position.Position = &gHandleList;
ResultSize = 0;
ResultBuffer = (IHANDLE **) Buffer;
Status = EFI_SUCCESS;
ResultSize = 0;
ResultBuffer = (IHANDLE **)Buffer;
Status = EFI_SUCCESS;
//
// Get the search function based on type
//
switch (SearchType) {
case AllHandles:
GetNext = CoreGetNextLocateAllHandles;
break;
case AllHandles:
GetNext = CoreGetNextLocateAllHandles;
break;
case ByRegisterNotify:
//
// Must have SearchKey for locate ByRegisterNotify
//
if (SearchKey == NULL) {
case ByRegisterNotify:
//
// Must have SearchKey for locate ByRegisterNotify
//
if (SearchKey == NULL) {
Status = EFI_INVALID_PARAMETER;
break;
}
GetNext = CoreGetNextLocateByRegisterNotify;
break;
case ByProtocol:
GetNext = CoreGetNextLocateByProtocol;
if (Protocol == NULL) {
Status = EFI_INVALID_PARAMETER;
break;
}
//
// Look up the protocol entry and set the head pointer
//
Position.ProtEntry = CoreFindProtocolEntry (Protocol, FALSE);
if (Position.ProtEntry == NULL) {
Status = EFI_NOT_FOUND;
break;
}
Position.Position = &Position.ProtEntry->Protocols;
break;
default:
Status = EFI_INVALID_PARAMETER;
break;
}
GetNext = CoreGetNextLocateByRegisterNotify;
break;
case ByProtocol:
GetNext = CoreGetNextLocateByProtocol;
if (Protocol == NULL) {
Status = EFI_INVALID_PARAMETER;
break;
}
//
// Look up the protocol entry and set the head pointer
//
Position.ProtEntry = CoreFindProtocolEntry (Protocol, FALSE);
if (Position.ProtEntry == NULL) {
Status = EFI_NOT_FOUND;
break;
}
Position.Position = &Position.ProtEntry->Protocols;
break;
default:
Status = EFI_INVALID_PARAMETER;
break;
}
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
return Status;
}
@@ -193,7 +195,7 @@ InternalCoreLocateHandle (
// Enumerate out the matching handles
//
mEfiLocateHandleRequest += 1;
for (; ;) {
for ( ; ;) {
//
// Get the next handle. If no more handles, stop
//
@@ -206,10 +208,10 @@ InternalCoreLocateHandle (
// Increase the resulting buffer size, and if this handle
// fits return it
//
ResultSize += sizeof(Handle);
ResultSize += sizeof (Handle);
if (ResultSize <= *BufferSize) {
*ResultBuffer = Handle;
ResultBuffer += 1;
*ResultBuffer = Handle;
ResultBuffer += 1;
}
}
@@ -230,13 +232,13 @@ InternalCoreLocateHandle (
*BufferSize = ResultSize;
if (SearchType == ByRegisterNotify && !EFI_ERROR(Status)) {
if ((SearchType == ByRegisterNotify) && !EFI_ERROR (Status)) {
//
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
ASSERT (SearchKey != NULL);
ProtNotify = SearchKey;
ProtNotify = SearchKey;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
}
@@ -265,25 +267,24 @@ InternalCoreLocateHandle (
EFI_STATUS
EFIAPI
CoreLocateHandle (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
)
{
EFI_STATUS Status;
EFI_STATUS Status;
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
Status = InternalCoreLocateHandle(SearchType, Protocol, SearchKey, BufferSize, Buffer);
Status = InternalCoreLocateHandle (SearchType, Protocol, SearchKey, BufferSize, Buffer);
CoreReleaseProtocolLock ();
return Status;
}
/**
Routine to get the next Handle, when you are searching for all handles.
@@ -297,11 +298,11 @@ CoreLocateHandle (
**/
IHANDLE *
CoreGetNextLocateAllHandles (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
)
{
IHANDLE *Handle;
IHANDLE *Handle;
//
// Next handle
@@ -311,8 +312,8 @@ CoreGetNextLocateAllHandles (
//
// If not at the end of the list, get the handle
//
Handle = NULL;
*Interface = NULL;
Handle = NULL;
*Interface = NULL;
if (Position->Position != &gHandleList) {
Handle = CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);
}
@@ -320,8 +321,6 @@ CoreGetNextLocateAllHandles (
return Handle;
}
/**
Routine to get the next Handle, when you are searching for register protocol
notifies.
@@ -336,8 +335,8 @@ CoreGetNextLocateAllHandles (
**/
IHANDLE *
CoreGetNextLocateByRegisterNotify (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
)
{
IHANDLE *Handle;
@@ -345,15 +344,15 @@ CoreGetNextLocateByRegisterNotify (
PROTOCOL_INTERFACE *Prot;
LIST_ENTRY *Link;
Handle = NULL;
*Interface = NULL;
Handle = NULL;
*Interface = NULL;
ProtNotify = Position->SearchKey;
//
// If this is the first request, get the next handle
//
if (ProtNotify != NULL) {
ASSERT(ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
ASSERT (ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
Position->SearchKey = NULL;
//
@@ -361,8 +360,8 @@ CoreGetNextLocateByRegisterNotify (
//
Link = ProtNotify->Position->ForwardLink;
if (Link != &ProtNotify->Protocol->Protocols) {
Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
*Interface = Prot->Interface;
}
}
@@ -370,7 +369,6 @@ CoreGetNextLocateByRegisterNotify (
return Handle;
}
/**
Routine to get the next Handle, when you are searching for a given protocol.
@@ -384,21 +382,21 @@ CoreGetNextLocateByRegisterNotify (
**/
IHANDLE *
CoreGetNextLocateByProtocol (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
)
{
IHANDLE *Handle;
LIST_ENTRY *Link;
PROTOCOL_INTERFACE *Prot;
Handle = NULL;
*Interface = NULL;
for (; ;) {
Handle = NULL;
*Interface = NULL;
for ( ; ;) {
//
// Next entry
//
Link = Position->Position->ForwardLink;
Link = Position->Position->ForwardLink;
Position->Position = Link;
//
@@ -412,8 +410,8 @@ CoreGetNextLocateByProtocol (
//
// Get the handle
//
Prot = CR(Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
*Interface = Prot->Interface;
//
@@ -429,7 +427,6 @@ CoreGetNextLocateByProtocol (
return Handle;
}
/**
Locates the handle to a device on the device path that supports the specified protocol.
@@ -449,22 +446,22 @@ CoreGetNextLocateByProtocol (
EFI_STATUS
EFIAPI
CoreLocateDevicePath (
IN EFI_GUID *Protocol,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT EFI_HANDLE *Device
IN EFI_GUID *Protocol,
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT EFI_HANDLE *Device
)
{
INTN SourceSize;
INTN Size;
INTN BestMatch;
UINTN HandleCount;
UINTN Index;
EFI_STATUS Status;
EFI_HANDLE *Handles;
EFI_HANDLE Handle;
EFI_HANDLE BestDevice;
EFI_DEVICE_PATH_PROTOCOL *SourcePath;
EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
INTN SourceSize;
INTN Size;
INTN BestMatch;
UINTN HandleCount;
UINTN Index;
EFI_STATUS Status;
EFI_HANDLE *Handles;
EFI_HANDLE Handle;
EFI_HANDLE BestDevice;
EFI_DEVICE_PATH_PROTOCOL *SourcePath;
EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
@@ -474,9 +471,9 @@ CoreLocateDevicePath (
return EFI_INVALID_PARAMETER;
}
Handles = NULL;
BestDevice = NULL;
SourcePath = *DevicePath;
Handles = NULL;
BestDevice = NULL;
SourcePath = *DevicePath;
TmpDevicePath = SourcePath;
while (!IsDevicePathEnd (TmpDevicePath)) {
if (IsDevicePathEndInstance (TmpDevicePath)) {
@@ -486,21 +483,22 @@ CoreLocateDevicePath (
//
break;
}
TmpDevicePath = NextDevicePathNode (TmpDevicePath);
}
SourceSize = (UINTN) TmpDevicePath - (UINTN) SourcePath;
SourceSize = (UINTN)TmpDevicePath - (UINTN)SourcePath;
//
// Get a list of all handles that support the requested protocol
//
Status = CoreLocateHandleBuffer (ByProtocol, Protocol, NULL, &HandleCount, &Handles);
if (EFI_ERROR (Status) || HandleCount == 0) {
if (EFI_ERROR (Status) || (HandleCount == 0)) {
return EFI_NOT_FOUND;
}
BestMatch = -1;
for(Index = 0; Index < HandleCount; Index += 1) {
for (Index = 0; Index < HandleCount; Index += 1) {
Handle = Handles[Index];
Status = CoreHandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&TmpDevicePath);
if (EFI_ERROR (Status)) {
@@ -513,9 +511,9 @@ CoreLocateDevicePath (
//
// Check if DevicePath is first part of SourcePath
//
Size = GetDevicePathSize (TmpDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
Size = GetDevicePathSize (TmpDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
ASSERT (Size >= 0);
if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0) {
if ((Size <= SourceSize) && (CompareMem (SourcePath, TmpDevicePath, (UINTN)Size) == 0)) {
//
// If the size is equal to the best match, then we
// have a duplicate device path for 2 different device
@@ -527,7 +525,7 @@ CoreLocateDevicePath (
// We've got a match, see if it's the best match so far
//
if (Size > BestMatch) {
BestMatch = Size;
BestMatch = Size;
BestDevice = Handle;
}
}
@@ -544,18 +542,18 @@ CoreLocateDevicePath (
}
if (Device == NULL) {
return EFI_INVALID_PARAMETER;
return EFI_INVALID_PARAMETER;
}
*Device = BestDevice;
//
// Return the remaining part of the device path
//
*DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) SourcePath) + BestMatch);
*DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)(((UINT8 *)SourcePath) + BestMatch);
return EFI_SUCCESS;
}
/**
Return the first Protocol Interface that matches the Protocol GUID. If
Registration is passed in, return a Protocol Instance that was just add
@@ -580,17 +578,17 @@ CoreLocateProtocol (
OUT VOID **Interface
)
{
EFI_STATUS Status;
LOCATE_POSITION Position;
PROTOCOL_NOTIFY *ProtNotify;
IHANDLE *Handle;
EFI_STATUS Status;
LOCATE_POSITION Position;
PROTOCOL_NOTIFY *ProtNotify;
IHANDLE *Handle;
if ((Interface == NULL) || (Protocol == NULL)) {
return EFI_INVALID_PARAMETER;
}
*Interface = NULL;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
//
// Set initial position
@@ -618,6 +616,7 @@ CoreLocateProtocol (
Status = EFI_NOT_FOUND;
goto Done;
}
Position.Position = &Position.ProtEntry->Protocols;
Handle = CoreGetNextLocateByProtocol (&Position, Interface);
@@ -632,7 +631,7 @@ CoreLocateProtocol (
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
ProtNotify = Registration;
ProtNotify = Registration;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
@@ -666,15 +665,15 @@ Done:
EFI_STATUS
EFIAPI
CoreLocateHandleBuffer (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
)
{
EFI_STATUS Status;
UINTN BufferSize;
EFI_STATUS Status;
UINTN BufferSize;
if (NumberHandles == NULL) {
return EFI_INVALID_PARAMETER;
@@ -684,14 +683,14 @@ CoreLocateHandleBuffer (
return EFI_INVALID_PARAMETER;
}
BufferSize = 0;
BufferSize = 0;
*NumberHandles = 0;
*Buffer = NULL;
*Buffer = NULL;
//
// Lock the protocol database
//
CoreAcquireProtocolLock();
CoreAcquireProtocolLock ();
Status = InternalCoreLocateHandle (
SearchType,
Protocol,
@@ -705,10 +704,11 @@ CoreLocateHandleBuffer (
//
// Add code to correctly handle expected errors from CoreLocateHandle().
//
if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
if (Status != EFI_INVALID_PARAMETER) {
Status = EFI_NOT_FOUND;
}
CoreReleaseProtocolLock ();
return Status;
}
@@ -727,14 +727,11 @@ CoreLocateHandleBuffer (
*Buffer
);
*NumberHandles = BufferSize / sizeof(EFI_HANDLE);
if (EFI_ERROR(Status)) {
*NumberHandles = BufferSize / sizeof (EFI_HANDLE);
if (EFI_ERROR (Status)) {
*NumberHandles = 0;
}
CoreReleaseProtocolLock ();
return Status;
}

View File

@@ -19,22 +19,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
CoreNotifyProtocolEntry (
IN PROTOCOL_ENTRY *ProtEntry
IN PROTOCOL_ENTRY *ProtEntry
)
{
PROTOCOL_NOTIFY *ProtNotify;
LIST_ENTRY *Link;
PROTOCOL_NOTIFY *ProtNotify;
LIST_ENTRY *Link;
ASSERT_LOCKED (&gProtocolDatabaseLock);
for (Link=ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {
ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
CoreSignalEvent (ProtNotify->Event);
}
}
/**
Removes Protocol from the protocol list (but not the handle list).
@@ -47,9 +45,9 @@ CoreNotifyProtocolEntry (
**/
PROTOCOL_INTERFACE *
CoreRemoveInterfaceFromProtocol (
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
)
{
PROTOCOL_INTERFACE *Prot;
@@ -61,14 +59,13 @@ CoreRemoveInterfaceFromProtocol (
Prot = CoreFindProtocolInterface (Handle, Protocol, Interface);
if (Prot != NULL) {
ProtEntry = Prot->Protocol;
//
// If there's a protocol notify location pointing to this entry, back it up one
//
for(Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {
ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
if (ProtNotify->Position == &Prot->ByProtocol) {
ProtNotify->Position = Prot->ByProtocol.BackLink;
@@ -84,7 +81,6 @@ CoreRemoveInterfaceFromProtocol (
return Prot;
}
/**
Add a new protocol notification record for the request protocol.
@@ -101,16 +97,16 @@ CoreRemoveInterfaceFromProtocol (
EFI_STATUS
EFIAPI
CoreRegisterProtocolNotify (
IN EFI_GUID *Protocol,
IN EFI_EVENT Event,
OUT VOID **Registration
IN EFI_GUID *Protocol,
IN EFI_EVENT Event,
OUT VOID **Registration
)
{
PROTOCOL_ENTRY *ProtEntry;
PROTOCOL_NOTIFY *ProtNotify;
EFI_STATUS Status;
PROTOCOL_ENTRY *ProtEntry;
PROTOCOL_NOTIFY *ProtNotify;
EFI_STATUS Status;
if ((Protocol == NULL) || (Event == NULL) || (Registration == NULL)) {
if ((Protocol == NULL) || (Event == NULL) || (Registration == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -124,16 +120,15 @@ CoreRegisterProtocolNotify (
ProtEntry = CoreFindProtocolEntry (Protocol, TRUE);
if (ProtEntry != NULL) {
//
// Allocate a new notification record
//
ProtNotify = AllocatePool (sizeof(PROTOCOL_NOTIFY));
ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));
if (ProtNotify != NULL) {
((IEVENT *)Event)->ExFlag |= EVT_EXFLAG_EVENT_PROTOCOL_NOTIFICATION;
ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
ProtNotify->Protocol = ProtEntry;
ProtNotify->Event = Event;
ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
ProtNotify->Protocol = ProtEntry;
ProtNotify->Event = Event;
//
// start at the begining
//
@@ -153,13 +148,12 @@ CoreRegisterProtocolNotify (
Status = EFI_OUT_OF_RESOURCES;
if (ProtNotify != NULL) {
*Registration = ProtNotify;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
}
return Status;
}
/**
Reinstall a protocol interface on a device handle. The OldInterface for Protocol is replaced by the NewInterface.
@@ -177,16 +171,16 @@ CoreRegisterProtocolNotify (
EFI_STATUS
EFIAPI
CoreReinstallProtocolInterface (
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol,
IN VOID *OldInterface,
IN VOID *NewInterface
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol,
IN VOID *OldInterface,
IN VOID *NewInterface
)
{
EFI_STATUS Status;
IHANDLE *Handle;
PROTOCOL_INTERFACE *Prot;
PROTOCOL_ENTRY *ProtEntry;
EFI_STATUS Status;
IHANDLE *Handle;
PROTOCOL_INTERFACE *Prot;
PROTOCOL_ENTRY *ProtEntry;
if (Protocol == NULL) {
return EFI_INVALID_PARAMETER;
@@ -202,7 +196,7 @@ CoreReinstallProtocolInterface (
goto Done;
}
Handle = (IHANDLE *) UserHandle;
Handle = (IHANDLE *)UserHandle;
//
// Check that Protocol exists on UserHandle, and Interface matches the interface in the database
//

File diff suppressed because it is too large Load Diff

View File

@@ -6,19 +6,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _IMAGE_H_
#define _IMAGE_H_
//
// Private Data Types
//
#define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')
#define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')
typedef struct {
UINTN Signature;
BOOLEAN FreeBuffer;
VOID *Source;
UINTN SourceSize;
UINTN Signature;
BOOLEAN FreeBuffer;
VOID *Source;
UINTN SourceSize;
} IMAGE_FILE_HANDLE;
#endif

View File

@@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Lock Stuff
//
/**
Initialize a basic mutual exclusion lock. Each lock
provides mutual exclusion access at it's task priority
@@ -45,8 +46,6 @@ CoreAcquireLockOrFail (
return EFI_SUCCESS;
}
/**
Raising to the task priority level of the mutual exclusion
lock, and then acquires ownership of the lock.
@@ -68,8 +67,6 @@ CoreAcquireLock (
Lock->Lock = EfiLockAcquired;
}
/**
Releases ownership of the mutual exclusion lock, and
restores the previous task priority level.
@@ -84,7 +81,7 @@ CoreReleaseLock (
IN EFI_LOCK *Lock
)
{
EFI_TPL Tpl;
EFI_TPL Tpl;
ASSERT (Lock != NULL);
ASSERT (Lock->Lock == EfiLockAcquired);
@@ -95,6 +92,3 @@ CoreReleaseLock (
CoreRestoreTpl (Tpl);
}

File diff suppressed because it is too large Load Diff

View File

@@ -51,15 +51,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Each entry occupies 8B/64b. 1-page can hold 512 entries, which spans 9
// bits in address. (512 = 1 << 9)
//
#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
#define GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT \
(EFI_PAGE_SHIFT - BYTE_LENGTH_SHIFT)
#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
// Use UINT64_index + bit_index_of_UINT64 to locate the bit in may
#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
#define GUARDED_HEAP_MAP_ENTRY_BITS \
(1 << GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT)
@@ -152,9 +152,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Memory type to guard (matching the related PCD definition)
//
#define GUARD_HEAP_TYPE_PAGE BIT0
#define GUARD_HEAP_TYPE_POOL BIT1
#define GUARD_HEAP_TYPE_FREED BIT4
#define GUARD_HEAP_TYPE_PAGE BIT0
#define GUARD_HEAP_TYPE_POOL BIT1
#define GUARD_HEAP_TYPE_FREED BIT4
#define GUARD_HEAP_TYPE_ALL \
(GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_FREED)
@@ -164,10 +164,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define HEAP_GUARD_DEBUG_LEVEL (DEBUG_POOL|DEBUG_PAGE)
typedef struct {
UINT32 TailMark;
UINT32 HeadMark;
EFI_PHYSICAL_ADDRESS Address;
LIST_ENTRY Link;
UINT32 TailMark;
UINT32 HeadMark;
EFI_PHYSICAL_ADDRESS Address;
LIST_ENTRY Link;
} HEAP_GUARD_NODE;
/**
@@ -219,8 +219,8 @@ CoreConvertPagesWithGuard (
**/
VOID
SetGuardForMemory (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
);
/**
@@ -233,8 +233,8 @@ SetGuardForMemory (
**/
VOID
UnsetGuardForMemory (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
);
/**
@@ -247,8 +247,8 @@ UnsetGuardForMemory (
**/
VOID
AdjustMemoryA (
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
);
/**
@@ -265,8 +265,8 @@ AdjustMemoryA (
**/
VOID
AdjustMemoryF (
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
);
/**
@@ -285,9 +285,9 @@ AdjustMemoryF (
**/
UINT64
AdjustMemoryS (
IN UINT64 Start,
IN UINT64 Size,
IN UINT64 SizeRequested
IN UINT64 Start,
IN UINT64 Size,
IN UINT64 SizeRequested
);
/**
@@ -301,7 +301,7 @@ AdjustMemoryS (
**/
BOOLEAN
IsPoolTypeToGuard (
IN EFI_MEMORY_TYPE MemoryType
IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -315,8 +315,8 @@ IsPoolTypeToGuard (
**/
BOOLEAN
IsPageTypeToGuard (
IN EFI_MEMORY_TYPE MemoryType,
IN EFI_ALLOCATE_TYPE AllocateType
IN EFI_MEMORY_TYPE MemoryType,
IN EFI_ALLOCATE_TYPE AllocateType
);
/**
@@ -330,7 +330,7 @@ IsPageTypeToGuard (
BOOLEAN
EFIAPI
IsMemoryGuarded (
IN EFI_PHYSICAL_ADDRESS Address
IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -344,7 +344,7 @@ IsMemoryGuarded (
BOOLEAN
EFIAPI
IsGuardPage (
IN EFI_PHYSICAL_ADDRESS Address
IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -369,9 +369,9 @@ DumpGuardedMemoryBitmap (
**/
VOID *
AdjustPoolHeadA (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages,
IN UINTN Size
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages,
IN UINTN Size
);
/**
@@ -383,7 +383,7 @@ AdjustPoolHeadA (
**/
VOID *
AdjustPoolHeadF (
IN EFI_PHYSICAL_ADDRESS Memory
IN EFI_PHYSICAL_ADDRESS Memory
);
/**
@@ -395,7 +395,7 @@ AdjustPoolHeadF (
**/
BOOLEAN
IsHeapGuardEnabled (
UINT8 GuardType
UINT8 GuardType
);
/**
@@ -418,8 +418,8 @@ HeapGuardCpuArchProtocolNotify (
**/
VOID
MergeGuardPages (
IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
IN EFI_PHYSICAL_ADDRESS MaxAddress
IN EFI_MEMORY_DESCRIPTOR *MemoryMapEntry,
IN EFI_PHYSICAL_ADDRESS MaxAddress
);
/**
@@ -433,8 +433,8 @@ MergeGuardPages (
VOID
EFIAPI
GuardFreedPagesChecked (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINTN Pages
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINTN Pages
);
/**
@@ -458,10 +458,10 @@ GuardFreedPagesChecked (
**/
BOOLEAN
PromoteGuardedFreePages (
OUT EFI_PHYSICAL_ADDRESS *StartAddress,
OUT EFI_PHYSICAL_ADDRESS *EndAddress
OUT EFI_PHYSICAL_ADDRESS *StartAddress,
OUT EFI_PHYSICAL_ADDRESS *EndAddress
);
extern BOOLEAN mOnGuarding;
extern BOOLEAN mOnGuarding;
#endif

View File

@@ -20,34 +20,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// | 0x80000000..0xFFFFFFFF - OS reserved |
// +---------------------------------------------------+
//
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
#define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
#define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
#define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
#define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
//
// MEMORY_MAP_ENTRY
//
#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
typedef struct {
UINTN Signature;
LIST_ENTRY Link;
BOOLEAN FromPages;
UINTN Signature;
LIST_ENTRY Link;
BOOLEAN FromPages;
EFI_MEMORY_TYPE Type;
UINT64 Start;
UINT64 End;
EFI_MEMORY_TYPE Type;
UINT64 Start;
UINT64 End;
UINT64 VirtualStart;
UINT64 Attribute;
UINT64 VirtualStart;
UINT64 Attribute;
} MEMORY_MAP;
//
// Internal prototypes
//
/**
Internal function. Used by the pool functions to allocate pages
to back pool allocation requests.
@@ -62,14 +61,12 @@ typedef struct {
**/
VOID *
CoreAllocatePoolPages (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN NumberOfPages,
IN UINTN Alignment,
IN BOOLEAN NeedGuard
IN EFI_MEMORY_TYPE PoolType,
IN UINTN NumberOfPages,
IN UINTN Alignment,
IN BOOLEAN NeedGuard
);
/**
Internal function. Frees pool pages allocated via AllocatePoolPages ()
@@ -79,12 +76,10 @@ CoreAllocatePoolPages (
**/
VOID
CoreFreePoolPages (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
);
/**
Internal function to allocate pool of a particular type.
Caller must have the memory lock held
@@ -103,8 +98,6 @@ CoreAllocatePoolI (
IN BOOLEAN NeedGuard
);
/**
Internal function to free a pool entry.
Caller must have the memory lock held
@@ -118,12 +111,10 @@ CoreAllocatePoolI (
**/
EFI_STATUS
CoreFreePoolI (
IN VOID *Buffer,
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
IN VOID *Buffer,
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
);
/**
Enter critical section by gaining lock on gMemoryLock.
@@ -133,7 +124,6 @@ CoreAcquireMemoryLock (
VOID
);
/**
Exit critical section by releasing lock on gMemoryLock.
@@ -165,18 +155,18 @@ CoreReleaseMemoryLock (
EFI_STATUS
EFIAPI
CoreInternalAllocatePages (
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NumberOfPages,
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NumberOfPages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN BOOLEAN NeedGuard
IN BOOLEAN NeedGuard
);
//
// Internal Global data
//
extern EFI_LOCK gMemoryLock;
extern LIST_ENTRY gMemoryMap;
extern LIST_ENTRY mGcdMemorySpaceMap;
extern EFI_LOCK gMemoryLock;
extern LIST_ENTRY gMemoryMap;
extern LIST_ENTRY mGcdMemorySpaceMap;
#endif

View File

@@ -8,13 +8,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
//
// MemoryLock - synchronizes access to the memory map and pool lists
//
EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
EFI_LOCK gMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
//
// MemoryMap - the current memory map
//
LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -10,36 +10,35 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Imem.h"
#include "HeapGuard.h"
STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
STATIC EFI_LOCK mPoolMemoryLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
#define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
#define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0')
typedef struct {
UINT32 Signature;
UINT32 Index;
LIST_ENTRY Link;
UINT32 Signature;
UINT32 Index;
LIST_ENTRY Link;
} POOL_FREE;
#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')
#define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
#define POOLPAGE_HEAD_SIGNATURE SIGNATURE_32('p','h','d','1')
typedef struct {
UINT32 Signature;
UINT32 Reserved;
EFI_MEMORY_TYPE Type;
UINTN Size;
CHAR8 Data[1];
UINT32 Signature;
UINT32 Reserved;
EFI_MEMORY_TYPE Type;
UINTN Size;
CHAR8 Data[1];
} POOL_HEAD;
#define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
#define SIZE_OF_POOL_HEAD OFFSET_OF(POOL_HEAD,Data)
#define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
#define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
typedef struct {
UINT32 Signature;
UINT32 Reserved;
UINTN Size;
UINT32 Signature;
UINT32 Reserved;
UINTN Size;
} POOL_TAIL;
#define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
#define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))
#define HEAD_TO_TAIL(a) \
((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
@@ -49,16 +48,16 @@ typedef struct {
// blocks between bins by splitting them up, while not wasting too much memory
// as we would in a strict power-of-2 sequence
//
STATIC CONST UINT16 mPoolSizeTable[] = {
STATIC CONST UINT16 mPoolSizeTable[] = {
128, 256, 384, 640, 1024, 1664, 2688, 4352, 7040, 11392, 18432, 29824
};
#define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
#define LIST_TO_SIZE(a) (mPoolSizeTable [a])
#define SIZE_TO_LIST(a) (GetPoolIndexFromSize (a))
#define LIST_TO_SIZE(a) (mPoolSizeTable [a])
#define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
#define MAX_POOL_LIST (ARRAY_SIZE (mPoolSizeTable))
#define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
#define MAX_POOL_SIZE (MAX_ADDRESS - POOL_OVERHEAD)
//
// Globals
@@ -66,22 +65,22 @@ STATIC CONST UINT16 mPoolSizeTable[] = {
#define POOL_SIGNATURE SIGNATURE_32('p','l','s','t')
typedef struct {
INTN Signature;
UINTN Used;
EFI_MEMORY_TYPE MemoryType;
LIST_ENTRY FreeList[MAX_POOL_LIST];
LIST_ENTRY Link;
INTN Signature;
UINTN Used;
EFI_MEMORY_TYPE MemoryType;
LIST_ENTRY FreeList[MAX_POOL_LIST];
LIST_ENTRY Link;
} POOL;
//
// Pool header for each memory type.
//
POOL mPoolHead[EfiMaxMemoryType];
POOL mPoolHead[EfiMaxMemoryType];
//
// List of pool header to search for the appropriate memory type.
//
LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
/**
Get pool size table index from the specified size.
@@ -94,16 +93,17 @@ LIST_ENTRY mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);
STATIC
UINTN
GetPoolIndexFromSize (
UINTN Size
UINTN Size
)
{
UINTN Index;
UINTN Index;
for (Index = 0; Index < MAX_POOL_LIST; Index++) {
if (mPoolSizeTable [Index] >= Size) {
if (mPoolSizeTable[Index] >= Size) {
return Index;
}
}
return MAX_POOL_LIST;
}
@@ -119,17 +119,16 @@ CoreInitializePool (
UINTN Type;
UINTN Index;
for (Type=0; Type < EfiMaxMemoryType; Type++) {
for (Type = 0; Type < EfiMaxMemoryType; Type++) {
mPoolHead[Type].Signature = 0;
mPoolHead[Type].Used = 0;
mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE) Type;
for (Index=0; Index < MAX_POOL_LIST; Index++) {
mPoolHead[Type].MemoryType = (EFI_MEMORY_TYPE)Type;
for (Index = 0; Index < MAX_POOL_LIST; Index++) {
InitializeListHead (&mPoolHead[Type].FreeList[Index]);
}
}
}
/**
Look up pool head for specified memory type.
@@ -143,9 +142,9 @@ LookupPoolHead (
IN EFI_MEMORY_TYPE MemoryType
)
{
LIST_ENTRY *Link;
POOL *Pool;
UINTN Index;
LIST_ENTRY *Link;
POOL *Pool;
UINTN Index;
if ((UINT32)MemoryType < EfiMaxMemoryType) {
return &mPoolHead[MemoryType];
@@ -156,10 +155,9 @@ LookupPoolHead (
// OS loaders that are provided by operating system vendors.
// MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.
//
if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
for (Link = mPoolHeadList.ForwardLink; Link != &mPoolHeadList; Link = Link->ForwardLink) {
Pool = CR(Link, POOL, Link, POOL_SIGNATURE);
Pool = CR (Link, POOL, Link, POOL_SIGNATURE);
if (Pool->MemoryType == MemoryType) {
return Pool;
}
@@ -170,10 +168,10 @@ LookupPoolHead (
return NULL;
}
Pool->Signature = POOL_SIGNATURE;
Pool->Used = 0;
Pool->Signature = POOL_SIGNATURE;
Pool->Used = 0;
Pool->MemoryType = MemoryType;
for (Index=0; Index < MAX_POOL_LIST; Index++) {
for (Index = 0; Index < MAX_POOL_LIST; Index++) {
InitializeListHead (&Pool->FreeList[Index]);
}
@@ -185,8 +183,6 @@ LookupPoolHead (
return NULL;
}
/**
Allocate pool of a particular type.
@@ -210,14 +206,15 @@ CoreInternalAllocatePool (
OUT VOID **Buffer
)
{
EFI_STATUS Status;
BOOLEAN NeedGuard;
EFI_STATUS Status;
BOOLEAN NeedGuard;
//
// If it's not a valid type, fail it
//
if ((PoolType >= EfiMaxMemoryType && PoolType < MEMORY_TYPE_OEM_RESERVED_MIN) ||
(PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory)) {
if (((PoolType >= EfiMaxMemoryType) && (PoolType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
(PoolType == EfiConventionalMemory) || (PoolType == EfiPersistentMemory))
{
return EFI_INVALID_PARAMETER;
}
@@ -278,7 +275,7 @@ CoreAllocatePool (
Status = CoreInternalAllocatePool (PoolType, Size, Buffer);
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePool,
PoolType,
Size,
@@ -287,6 +284,7 @@ CoreAllocatePool (
);
InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
}
return Status;
}
@@ -305,10 +303,10 @@ CoreAllocatePool (
STATIC
VOID *
CoreAllocatePoolPagesI (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN NoPages,
IN UINTN Granularity,
IN BOOLEAN NeedGuard
IN EFI_MEMORY_TYPE PoolType,
IN UINTN NoPages,
IN UINTN Granularity,
IN BOOLEAN NeedGuard
)
{
VOID *Buffer;
@@ -326,9 +324,15 @@ CoreAllocatePoolPagesI (
if (NeedGuard) {
SetGuardForMemory ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, NoPages);
}
ApplyMemoryProtectionPolicy(EfiConventionalMemory, PoolType,
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (NoPages));
ApplyMemoryProtectionPolicy (
EfiConventionalMemory,
PoolType,
(EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
EFI_PAGES_TO_SIZE (NoPages)
);
}
return Buffer;
}
@@ -350,27 +354,27 @@ CoreAllocatePoolI (
IN BOOLEAN NeedGuard
)
{
POOL *Pool;
POOL_FREE *Free;
POOL_HEAD *Head;
POOL_TAIL *Tail;
CHAR8 *NewPage;
VOID *Buffer;
UINTN Index;
UINTN FSize;
UINTN Offset, MaxOffset;
UINTN NoPages;
UINTN Granularity;
BOOLEAN HasPoolTail;
BOOLEAN PageAsPool;
POOL *Pool;
POOL_FREE *Free;
POOL_HEAD *Head;
POOL_TAIL *Tail;
CHAR8 *NewPage;
VOID *Buffer;
UINTN Index;
UINTN FSize;
UINTN Offset, MaxOffset;
UINTN NoPages;
UINTN Granularity;
BOOLEAN HasPoolTail;
BOOLEAN PageAsPool;
ASSERT_LOCKED (&mPoolMemoryLock);
if (PoolType == EfiACPIReclaimMemory ||
PoolType == EfiACPIMemoryNVS ||
PoolType == EfiRuntimeServicesCode ||
PoolType == EfiRuntimeServicesData) {
if ((PoolType == EfiACPIReclaimMemory) ||
(PoolType == EfiACPIMemoryNVS) ||
(PoolType == EfiRuntimeServicesCode) ||
(PoolType == EfiRuntimeServicesData))
{
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
@@ -380,8 +384,8 @@ CoreAllocatePoolI (
// Adjust the size by the pool header & tail overhead
//
HasPoolTail = !(NeedGuard &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
HasPoolTail = !(NeedGuard &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
PageAsPool = (IsHeapGuardEnabled (GUARD_HEAP_TYPE_FREED) && !mOnGuarding);
//
@@ -392,27 +396,30 @@ CoreAllocatePoolI (
Size = ALIGN_VARIABLE (Size);
Size += POOL_OVERHEAD;
Index = SIZE_TO_LIST(Size);
Pool = LookupPoolHead (PoolType);
if (Pool== NULL) {
Index = SIZE_TO_LIST (Size);
Pool = LookupPoolHead (PoolType);
if (Pool == NULL) {
return NULL;
}
Head = NULL;
//
// If allocation is over max size, just allocate pages for the request
// (slow)
//
if (Index >= SIZE_TO_LIST (Granularity) || NeedGuard || PageAsPool) {
if ((Index >= SIZE_TO_LIST (Granularity)) || NeedGuard || PageAsPool) {
if (!HasPoolTail) {
Size -= sizeof (POOL_TAIL);
}
NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard);
if (NeedGuard) {
Head = AdjustPoolHeadA ((EFI_PHYSICAL_ADDRESS)(UINTN)Head, NoPages, Size);
}
goto Done;
}
@@ -420,8 +427,7 @@ CoreAllocatePoolI (
// If there's no free pool in the proper list size, go get some more pages
//
if (IsListEmpty (&Pool->FreeList[Index])) {
Offset = LIST_TO_SIZE (Index);
Offset = LIST_TO_SIZE (Index);
MaxOffset = Granularity;
//
@@ -431,7 +437,7 @@ CoreAllocatePoolI (
if (!IsListEmpty (&Pool->FreeList[Index])) {
Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
RemoveEntryList (&Free->Link);
NewPage = (VOID *) Free;
NewPage = (VOID *)Free;
MaxOffset = LIST_TO_SIZE (Index);
goto Carve;
}
@@ -440,8 +446,12 @@ CoreAllocatePoolI (
//
// Get another page
//
NewPage = CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES (Granularity),
Granularity, NeedGuard);
NewPage = CoreAllocatePoolPagesI (
PoolType,
EFI_SIZE_TO_PAGES (Granularity),
Granularity,
NeedGuard
);
if (NewPage == NULL) {
goto Done;
}
@@ -450,7 +460,7 @@ CoreAllocatePoolI (
// Serve the allocation request from the head of the allocated block
//
Carve:
Head = (POOL_HEAD *) NewPage;
Head = (POOL_HEAD *)NewPage;
//
// Carve up remaining space into free pool blocks
@@ -458,15 +468,16 @@ Carve:
Index--;
while (Offset < MaxOffset) {
ASSERT (Index < MAX_POOL_LIST);
FSize = LIST_TO_SIZE(Index);
FSize = LIST_TO_SIZE (Index);
while (Offset + FSize <= MaxOffset) {
Free = (POOL_FREE *) &NewPage[Offset];
Free = (POOL_FREE *)&NewPage[Offset];
Free->Signature = POOL_FREE_SIGNATURE;
Free->Index = (UINT32)Index;
InsertHeadList (&Pool->FreeList[Index], &Free->Link);
Offset += FSize;
}
Index -= 1;
}
@@ -480,13 +491,12 @@ Carve:
Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);
RemoveEntryList (&Free->Link);
Head = (POOL_HEAD *) Free;
Head = (POOL_HEAD *)Free;
Done:
Buffer = NULL;
if (Head != NULL) {
//
// Account the allocation
//
@@ -497,7 +507,7 @@ Done:
//
Head->Signature = (PageAsPool) ? POOLPAGE_HEAD_SIGNATURE : POOL_HEAD_SIGNATURE;
Head->Size = Size;
Head->Type = (EFI_MEMORY_TYPE) PoolType;
Head->Type = (EFI_MEMORY_TYPE)PoolType;
Buffer = Head->Data;
if (HasPoolTail) {
@@ -514,22 +524,19 @@ Done:
DEBUG ((
DEBUG_POOL,
"AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n", PoolType,
"AllocatePoolI: Type %x, Addr %p (len %lx) %,ld\n",
PoolType,
Buffer,
(UINT64)Size,
(UINT64) Pool->Used
(UINT64)Pool->Used
));
} else {
DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64) Size));
DEBUG ((DEBUG_ERROR | DEBUG_POOL, "AllocatePool: failed to allocate %ld bytes\n", (UINT64)Size));
}
return Buffer;
}
/**
Frees pool.
@@ -543,11 +550,11 @@ Done:
EFI_STATUS
EFIAPI
CoreInternalFreePool (
IN VOID *Buffer,
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
IN VOID *Buffer,
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
)
{
EFI_STATUS Status;
EFI_STATUS Status;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
@@ -574,13 +581,13 @@ CoreFreePool (
IN VOID *Buffer
)
{
EFI_STATUS Status;
EFI_MEMORY_TYPE PoolType;
EFI_STATUS Status;
EFI_MEMORY_TYPE PoolType;
Status = CoreInternalFreePool (Buffer, &PoolType);
if (!EFI_ERROR (Status)) {
CoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePool,
PoolType,
0,
@@ -589,6 +596,7 @@ CoreFreePool (
);
InstallMemoryAttributesTableOnMemoryAllocation (PoolType);
}
return Status;
}
@@ -603,9 +611,9 @@ CoreFreePool (
STATIC
VOID
CoreFreePoolPagesI (
IN EFI_MEMORY_TYPE PoolType,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages
IN EFI_MEMORY_TYPE PoolType,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages
)
{
CoreAcquireMemoryLock ();
@@ -613,8 +621,12 @@ CoreFreePoolPagesI (
CoreReleaseMemoryLock ();
GuardFreedPagesChecked (Memory, NoPages);
ApplyMemoryProtectionPolicy (PoolType, EfiConventionalMemory,
(EFI_PHYSICAL_ADDRESS)(UINTN)Memory, EFI_PAGES_TO_SIZE (NoPages));
ApplyMemoryProtectionPolicy (
PoolType,
EfiConventionalMemory,
(EFI_PHYSICAL_ADDRESS)(UINTN)Memory,
EFI_PAGES_TO_SIZE (NoPages)
);
}
/**
@@ -628,13 +640,13 @@ CoreFreePoolPagesI (
STATIC
VOID
CoreFreePoolPagesWithGuard (
IN EFI_MEMORY_TYPE PoolType,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages
IN EFI_MEMORY_TYPE PoolType,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages
)
{
EFI_PHYSICAL_ADDRESS MemoryGuarded;
UINTN NoPagesGuarded;
EFI_PHYSICAL_ADDRESS MemoryGuarded;
UINTN NoPagesGuarded;
MemoryGuarded = Memory;
NoPagesGuarded = NoPages;
@@ -666,41 +678,44 @@ CoreFreePoolPagesWithGuard (
**/
EFI_STATUS
CoreFreePoolI (
IN VOID *Buffer,
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
IN VOID *Buffer,
OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
)
{
POOL *Pool;
POOL_HEAD *Head;
POOL_TAIL *Tail;
POOL_FREE *Free;
UINTN Index;
UINTN NoPages;
UINTN Size;
CHAR8 *NewPage;
UINTN Offset;
BOOLEAN AllFree;
UINTN Granularity;
BOOLEAN IsGuarded;
BOOLEAN HasPoolTail;
BOOLEAN PageAsPool;
POOL *Pool;
POOL_HEAD *Head;
POOL_TAIL *Tail;
POOL_FREE *Free;
UINTN Index;
UINTN NoPages;
UINTN Size;
CHAR8 *NewPage;
UINTN Offset;
BOOLEAN AllFree;
UINTN Granularity;
BOOLEAN IsGuarded;
BOOLEAN HasPoolTail;
BOOLEAN PageAsPool;
ASSERT(Buffer != NULL);
ASSERT (Buffer != NULL);
//
// Get the head & tail of the pool entry
//
Head = BASE_CR (Buffer, POOL_HEAD, Data);
ASSERT(Head != NULL);
ASSERT (Head != NULL);
if (Head->Signature != POOL_HEAD_SIGNATURE &&
Head->Signature != POOLPAGE_HEAD_SIGNATURE) {
ASSERT (Head->Signature == POOL_HEAD_SIGNATURE ||
Head->Signature == POOLPAGE_HEAD_SIGNATURE);
if ((Head->Signature != POOL_HEAD_SIGNATURE) &&
(Head->Signature != POOLPAGE_HEAD_SIGNATURE))
{
ASSERT (
Head->Signature == POOL_HEAD_SIGNATURE ||
Head->Signature == POOLPAGE_HEAD_SIGNATURE
);
return EFI_INVALID_PARAMETER;
}
IsGuarded = IsPoolTypeToGuard (Head->Type) &&
IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
IsGuarded = IsPoolTypeToGuard (Head->Type) &&
IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
HasPoolTail = !(IsGuarded &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
PageAsPool = (Head->Signature == POOLPAGE_HEAD_SIGNATURE);
@@ -734,14 +749,15 @@ CoreFreePoolI (
if (Pool == NULL) {
return EFI_INVALID_PARAMETER;
}
Pool->Used -= Size;
DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64) Pool->Used));
if (Head->Type == EfiACPIReclaimMemory ||
Head->Type == EfiACPIMemoryNVS ||
Head->Type == EfiRuntimeServicesCode ||
Head->Type == EfiRuntimeServicesData) {
DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64)Pool->Used));
if ((Head->Type == EfiACPIReclaimMemory) ||
(Head->Type == EfiACPIMemoryNVS) ||
(Head->Type == EfiRuntimeServicesCode) ||
(Head->Type == EfiRuntimeServicesData))
{
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
@@ -754,18 +770,17 @@ CoreFreePoolI (
//
// Determine the pool list
//
Index = SIZE_TO_LIST(Size);
Index = SIZE_TO_LIST (Size);
DEBUG_CLEAR_MEMORY (Head, Size);
//
// If it's not on the list, it must be pool pages
//
if (Index >= SIZE_TO_LIST (Granularity) || IsGuarded || PageAsPool) {
if ((Index >= SIZE_TO_LIST (Granularity)) || IsGuarded || PageAsPool) {
//
// Return the memory pages back to free memory
//
NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;
NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);
if (IsGuarded) {
Head = AdjustPoolHeadF ((EFI_PHYSICAL_ADDRESS)(UINTN)Head);
@@ -781,14 +796,12 @@ CoreFreePoolI (
NoPages
);
}
} else {
//
// Put the pool entry onto the free pool list
//
Free = (POOL_FREE *) Head;
ASSERT(Free != NULL);
Free = (POOL_FREE *)Head;
ASSERT (Free != NULL);
Free->Signature = POOL_FREE_SIGNATURE;
Free->Index = (UINT32)Index;
InsertHeadList (&Pool->FreeList[Index], &Free->Link);
@@ -798,46 +811,48 @@ CoreFreePoolI (
// entries
//
NewPage = (CHAR8 *)((UINTN)Free & ~(Granularity - 1));
Free = (POOL_FREE *) &NewPage[0];
ASSERT(Free != NULL);
Free = (POOL_FREE *)&NewPage[0];
ASSERT (Free != NULL);
if (Free->Signature == POOL_FREE_SIGNATURE) {
AllFree = TRUE;
Offset = 0;
Offset = 0;
while ((Offset < Granularity) && (AllFree)) {
Free = (POOL_FREE *) &NewPage[Offset];
ASSERT(Free != NULL);
Free = (POOL_FREE *)&NewPage[Offset];
ASSERT (Free != NULL);
if (Free->Signature != POOL_FREE_SIGNATURE) {
AllFree = FALSE;
}
Offset += LIST_TO_SIZE(Free->Index);
Offset += LIST_TO_SIZE (Free->Index);
}
if (AllFree) {
//
// All of the pool entries in the same page as Free are free pool
// entries
// Remove all of these pool entries from the free loop lists.
//
Free = (POOL_FREE *) &NewPage[0];
ASSERT(Free != NULL);
Free = (POOL_FREE *)&NewPage[0];
ASSERT (Free != NULL);
Offset = 0;
while (Offset < Granularity) {
Free = (POOL_FREE *) &NewPage[Offset];
ASSERT(Free != NULL);
Free = (POOL_FREE *)&NewPage[Offset];
ASSERT (Free != NULL);
RemoveEntryList (&Free->Link);
Offset += LIST_TO_SIZE(Free->Index);
Offset += LIST_TO_SIZE (Free->Index);
}
//
// Free the page
//
CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) (UINTN)NewPage,
EFI_SIZE_TO_PAGES (Granularity));
CoreFreePoolPagesI (
Pool->MemoryType,
(EFI_PHYSICAL_ADDRESS)(UINTN)NewPage,
EFI_SIZE_TO_PAGES (Granularity)
);
}
}
}
@@ -847,11 +862,10 @@ CoreFreePoolI (
// portion of that memory type has been freed. If it has, then free the
// list entry for that memory type
//
if (((UINT32) Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && Pool->Used == 0) {
if (((UINT32)Pool->MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) && (Pool->Used == 0)) {
RemoveEntryList (&Pool->Link);
CoreFreePoolI (Pool, NULL);
}
return EFI_SUCCESS;
}

View File

@@ -9,18 +9,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
EFI_DEBUG_IMAGE_INFO_TABLE_HEADER mDebugInfoTableHeader = {
0, // volatile UINT32 UpdateStatus;
0, // UINT32 TableSize;
NULL // EFI_DEBUG_IMAGE_INFO *EfiDebugImageInfoTable;
};
UINTN mMaxTableEntries = 0;
UINTN mMaxTableEntries = 0;
EFI_SYSTEM_TABLE_POINTER *mDebugTable = NULL;
#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof (VOID *))
/**
Creates and initializes the DebugImageInfo Table. Also creates the configuration
@@ -45,9 +44,9 @@ CoreInitializeDebugImageInfoTable (
// Ideally we would update the CRC now as well, but the service may not yet be available.
// See comments in the CoreUpdateDebugTableCrc32() function below for details.
//
Pages = EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER));
AlignmentMask = SIZE_4MB - 1;
RealPages = Pages + EFI_SIZE_TO_PAGES (SIZE_4MB);
Pages = EFI_SIZE_TO_PAGES (sizeof (EFI_SYSTEM_TABLE_POINTER));
AlignmentMask = SIZE_4MB - 1;
RealPages = Pages + EFI_SIZE_TO_PAGES (SIZE_4MB);
//
// Attempt to allocate memory below PcdMaxEfiSystemTablePointerAddress
@@ -58,6 +57,7 @@ CoreInitializeDebugImageInfoTable (
if (Memory == 0) {
Memory = MAX_ADDRESS;
}
Status = CoreAllocatePages (
AllocateMaxAddress,
EfiBootServicesData,
@@ -69,6 +69,7 @@ CoreInitializeDebugImageInfoTable (
DEBUG ((DEBUG_INFO, "Allocate memory for EFI_SYSTEM_TABLE_POINTER below PcdMaxEfiSystemTablePointerAddress failed. \
Retry to allocate memroy as close to the top of memory as feasible.\n"));
}
//
// If the initial memory allocation fails, then reattempt allocation
// as close to the top of memory as feasible.
@@ -88,7 +89,7 @@ CoreInitializeDebugImageInfoTable (
//
// Free overallocated pages
//
AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;
AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;
UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);
if (UnalignedPages > 0) {
//
@@ -97,6 +98,7 @@ CoreInitializeDebugImageInfoTable (
Status = CoreFreePages (Memory, UnalignedPages);
ASSERT_EFI_ERROR (Status);
}
Memory = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) {
@@ -117,7 +119,7 @@ CoreInitializeDebugImageInfoTable (
// Initialize EFI_SYSTEM_TABLE_POINTER structure
//
mDebugTable->Signature = EFI_SYSTEM_TABLE_SIGNATURE;
mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) gDxeCoreST;
mDebugTable->EfiSystemTableBase = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreST;
mDebugTable->Crc32 = 0;
//
@@ -128,7 +130,6 @@ CoreInitializeDebugImageInfoTable (
ASSERT_EFI_ERROR (Status);
}
/**
Update the CRC32 in the Debug Table.
Since the CRC32 service is made available by the Runtime driver, we have to
@@ -142,12 +143,11 @@ CoreUpdateDebugTableCrc32 (
VOID
)
{
ASSERT(mDebugTable != NULL);
ASSERT (mDebugTable != NULL);
mDebugTable->Crc32 = 0;
gBS->CalculateCrc32 ((VOID *)mDebugTable, sizeof (EFI_SYSTEM_TABLE_POINTER), &mDebugTable->Crc32);
}
/**
Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates
the table if it's not large enough to accomidate another entry.
@@ -160,15 +160,15 @@ CoreUpdateDebugTableCrc32 (
**/
VOID
CoreNewDebugImageInfoEntry (
IN UINT32 ImageInfoType,
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle
IN UINT32 ImageInfoType,
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_HANDLE ImageHandle
)
{
EFI_DEBUG_IMAGE_INFO *Table;
EFI_DEBUG_IMAGE_INFO *NewTable;
UINTN Index;
UINTN TableSize;
EFI_DEBUG_IMAGE_INFO *Table;
EFI_DEBUG_IMAGE_INFO *NewTable;
UINTN Index;
UINTN TableSize;
//
// Set the flag indicating that we're in the process of updating the table.
@@ -185,6 +185,7 @@ CoreNewDebugImageInfoEntry (
while (Table[Index].NormalImage != NULL) {
Index++;
}
//
// There must be an empty entry in the in the table.
//
@@ -194,11 +195,12 @@ CoreNewDebugImageInfoEntry (
// Table is full, so re-allocate another page for a larger table...
//
TableSize = mMaxTableEntries * EFI_DEBUG_TABLE_ENTRY_SIZE;
NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);
NewTable = AllocateZeroPool (TableSize + EFI_PAGE_SIZE);
if (NewTable == NULL) {
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
return;
}
//
// Copy the old table into the new one
//
@@ -210,7 +212,7 @@ CoreNewDebugImageInfoEntry (
//
// Update the table header
//
Table = NewTable;
Table = NewTable;
mDebugInfoTableHeader.EfiDebugImageInfoTable = NewTable;
//
// Enlarge the max table entries and set the first empty entry index to
@@ -228,7 +230,7 @@ CoreNewDebugImageInfoEntry (
//
// Update the entry
//
Table[Index].NormalImage->ImageInfoType = (UINT32) ImageInfoType;
Table[Index].NormalImage->ImageInfoType = (UINT32)ImageInfoType;
Table[Index].NormalImage->LoadedImageProtocolInstance = LoadedImage;
Table[Index].NormalImage->ImageHandle = ImageHandle;
//
@@ -237,11 +239,10 @@ CoreNewDebugImageInfoEntry (
mDebugInfoTableHeader.TableSize++;
mDebugInfoTableHeader.UpdateStatus |= EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED;
}
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
}
/**
Removes and frees an entry from the DebugImageInfo Table.
@@ -250,7 +251,7 @@ CoreNewDebugImageInfoEntry (
**/
VOID
CoreRemoveDebugImageInfoEntry (
EFI_HANDLE ImageHandle
EFI_HANDLE ImageHandle
)
{
EFI_DEBUG_IMAGE_INFO *Table;
@@ -261,7 +262,7 @@ CoreRemoveDebugImageInfoEntry (
Table = mDebugInfoTableHeader.EfiDebugImageInfoTable;
for (Index = 0; Index < mMaxTableEntries; Index++) {
if (Table[Index].NormalImage != NULL && Table[Index].NormalImage->ImageHandle == ImageHandle) {
if ((Table[Index].NormalImage != NULL) && (Table[Index].NormalImage->ImageHandle == ImageHandle)) {
//
// Found a match. Free up the record, then NULL the pointer to indicate the slot
// is free.
@@ -276,5 +277,6 @@ CoreRemoveDebugImageInfoEntry (
break;
}
}
mDebugInfoTableHeader.UpdateStatus &= ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS;
}

View File

@@ -8,9 +8,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#define CONFIG_TABLE_SIZE_INCREASED 0x10
#define CONFIG_TABLE_SIZE_INCREASED 0x10
UINTN mSystemTableAllocateSize = 0;
UINTN mSystemTableAllocateSize = 0;
/**
Boot Service called to add, modify, or remove a system configuration table from
@@ -30,13 +30,13 @@ UINTN mSystemTableAllocateSize = 0;
EFI_STATUS
EFIAPI
CoreInstallConfigurationTable (
IN EFI_GUID *Guid,
IN VOID *Table
IN EFI_GUID *Guid,
IN VOID *Table
)
{
UINTN Index;
EFI_CONFIGURATION_TABLE *EfiConfigurationTable;
EFI_CONFIGURATION_TABLE *OldTable;
UINTN Index;
EFI_CONFIGURATION_TABLE *EfiConfigurationTable;
EFI_CONFIGURATION_TABLE *OldTable;
//
// If Guid is NULL, then this operation cannot be performed
@@ -88,9 +88,7 @@ CoreInstallConfigurationTable (
&(gDxeCoreST->ConfigurationTable[Index + 1]),
(gDxeCoreST->NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
);
} else {
//
// No matching GUIDs were found, so this is an add operation.
//
@@ -110,7 +108,7 @@ CoreInstallConfigurationTable (
// Allocate a table with one additional entry.
//
mSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));
EfiConfigurationTable = AllocateRuntimePool (mSystemTableAllocateSize);
EfiConfigurationTable = AllocateRuntimePool (mSystemTableAllocateSize);
if (EfiConfigurationTable == NULL) {
//
// If a new table could not be allocated, then return an error.
@@ -159,7 +157,7 @@ CoreInstallConfigurationTable (
// Fill in the new entry
//
CopyGuid ((VOID *)&EfiConfigurationTable[Index].VendorGuid, Guid);
EfiConfigurationTable[Index].VendorTable = Table;
EfiConfigurationTable[Index].VendorTable = Table;
//
// This is an add operation, so increment the number of table entries

File diff suppressed because it is too large Load Diff

View File

@@ -45,26 +45,26 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Image type definitions
//
#define IMAGE_UNKNOWN 0x00000001
#define IMAGE_FROM_FV 0x00000002
#define IMAGE_UNKNOWN 0x00000001
#define IMAGE_FROM_FV 0x00000002
//
// Protection policy bit definition
//
#define DO_NOT_PROTECT 0x00000000
#define PROTECT_IF_ALIGNED_ELSE_ALLOW 0x00000001
#define DO_NOT_PROTECT 0x00000000
#define PROTECT_IF_ALIGNED_ELSE_ALLOW 0x00000001
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
#define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
#define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
#define PREVIOUS_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \
((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) - (Size)))
UINT32 mImageProtectionPolicy;
UINT32 mImageProtectionPolicy;
extern LIST_ENTRY mGcdMemorySpaceMap;
extern LIST_ENTRY mGcdMemorySpaceMap;
STATIC LIST_ENTRY mProtectedImageRecordList;
STATIC LIST_ENTRY mProtectedImageRecordList;
/**
Sort code section in image record, based upon CodeSegmentBase from low to high.
@@ -73,7 +73,7 @@ STATIC LIST_ENTRY mProtectedImageRecordList;
**/
VOID
SortImageRecordCodeSection (
IN IMAGE_PROPERTIES_RECORD *ImageRecord
IN IMAGE_PROPERTIES_RECORD *ImageRecord
);
/**
@@ -86,7 +86,7 @@ SortImageRecordCodeSection (
**/
BOOLEAN
IsImageRecordCodeSectionValid (
IN IMAGE_PROPERTIES_RECORD *ImageRecord
IN IMAGE_PROPERTIES_RECORD *ImageRecord
);
/**
@@ -99,12 +99,12 @@ IsImageRecordCodeSectionValid (
**/
UINT32
GetImageType (
IN CONST EFI_DEVICE_PATH_PROTOCOL *File
IN CONST EFI_DEVICE_PATH_PROTOCOL *File
)
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
if (File == NULL) {
return IMAGE_UNKNOWN;
@@ -113,13 +113,13 @@ GetImageType (
//
// First check to see if File is from a Firmware Volume
//
DeviceHandle = NULL;
TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) File;
Status = gBS->LocateDevicePath (
&gEfiFirmwareVolume2ProtocolGuid,
&TempDevicePath,
&DeviceHandle
);
DeviceHandle = NULL;
TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)File;
Status = gBS->LocateDevicePath (
&gEfiFirmwareVolume2ProtocolGuid,
&TempDevicePath,
&DeviceHandle
);
if (!EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (
DeviceHandle,
@@ -133,6 +133,7 @@ GetImageType (
return IMAGE_FROM_FV;
}
}
return IMAGE_UNKNOWN;
}
@@ -165,13 +166,13 @@ GetProtectionPolicyFromImageType (
**/
UINT32
GetUefiImageProtectionPolicy (
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
)
{
BOOLEAN InSmm;
UINT32 ImageType;
UINT32 ProtectionPolicy;
BOOLEAN InSmm;
UINT32 ImageType;
UINT32 ProtectionPolicy;
//
// Check SMM
@@ -180,6 +181,7 @@ GetUefiImageProtectionPolicy (
if (gSmmBase2 != NULL) {
gSmmBase2->InSmm (gSmmBase2, &InSmm);
}
if (InSmm) {
return FALSE;
}
@@ -192,11 +194,11 @@ GetUefiImageProtectionPolicy (
} else {
ImageType = GetImageType (LoadedImageDevicePath);
}
ProtectionPolicy = GetProtectionPolicyFromImageType (ImageType);
return ProtectionPolicy;
}
/**
Set UEFI image memory attributes.
@@ -206,23 +208,23 @@ GetUefiImageProtectionPolicy (
**/
VOID
SetUefiImageMemoryAttributes (
IN UINT64 BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
IN UINT64 BaseAddress,
IN UINT64 Length,
IN UINT64 Attributes
)
{
EFI_STATUS Status;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
UINT64 FinalAttributes;
Status = CoreGetMemorySpaceDescriptor(BaseAddress, &Descriptor);
ASSERT_EFI_ERROR(Status);
Status = CoreGetMemorySpaceDescriptor (BaseAddress, &Descriptor);
ASSERT_EFI_ERROR (Status);
FinalAttributes = (Descriptor.Attributes & EFI_CACHE_ATTRIBUTE_MASK) | (Attributes & EFI_MEMORY_ATTRIBUTE_MASK);
DEBUG ((DEBUG_INFO, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx (0x%016lx)\n", BaseAddress, Length, FinalAttributes));
ASSERT(gCpu != NULL);
ASSERT (gCpu != NULL);
gCpu->SetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes);
}
@@ -233,22 +235,22 @@ SetUefiImageMemoryAttributes (
**/
VOID
SetUefiImageProtectionAttributes (
IN IMAGE_PROPERTIES_RECORD *ImageRecord
IN IMAGE_PROPERTIES_RECORD *ImageRecord
)
{
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
LIST_ENTRY *ImageRecordCodeSectionLink;
LIST_ENTRY *ImageRecordCodeSectionEndLink;
LIST_ENTRY *ImageRecordCodeSectionList;
UINT64 CurrentBase;
UINT64 ImageEnd;
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
LIST_ENTRY *ImageRecordCodeSectionLink;
LIST_ENTRY *ImageRecordCodeSectionEndLink;
LIST_ENTRY *ImageRecordCodeSectionList;
UINT64 CurrentBase;
UINT64 ImageEnd;
ImageRecordCodeSectionList = &ImageRecord->CodeSegmentList;
CurrentBase = ImageRecord->ImageBase;
ImageEnd = ImageRecord->ImageBase + ImageRecord->ImageSize;
ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
ImageRecordCodeSectionLink = ImageRecordCodeSectionList->ForwardLink;
ImageRecordCodeSectionEndLink = ImageRecordCodeSectionList;
while (ImageRecordCodeSectionLink != ImageRecordCodeSectionEndLink) {
ImageRecordCodeSection = CR (
@@ -270,6 +272,7 @@ SetUefiImageProtectionAttributes (
EFI_MEMORY_XP
);
}
//
// CODE
//
@@ -280,6 +283,7 @@ SetUefiImageProtectionAttributes (
);
CurrentBase = ImageRecordCodeSection->CodeSegmentBase + ImageRecordCodeSection->CodeSegmentSize;
}
//
// Last DATA
//
@@ -294,7 +298,8 @@ SetUefiImageProtectionAttributes (
EFI_MEMORY_XP
);
}
return ;
return;
}
/**
@@ -315,24 +320,24 @@ IsMemoryProtectionSectionAligned (
UINT32 PageAlignment;
switch (MemoryType) {
case EfiRuntimeServicesCode:
case EfiACPIMemoryNVS:
PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
break;
case EfiRuntimeServicesData:
case EfiACPIReclaimMemory:
ASSERT (FALSE);
PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
break;
case EfiBootServicesCode:
case EfiLoaderCode:
case EfiReservedMemoryType:
PageAlignment = EFI_PAGE_SIZE;
break;
default:
ASSERT (FALSE);
PageAlignment = EFI_PAGE_SIZE;
break;
case EfiRuntimeServicesCode:
case EfiACPIMemoryNVS:
PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
break;
case EfiRuntimeServicesData:
case EfiACPIReclaimMemory:
ASSERT (FALSE);
PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
break;
case EfiBootServicesCode:
case EfiLoaderCode:
case EfiReservedMemoryType:
PageAlignment = EFI_PAGE_SIZE;
break;
default:
ASSERT (FALSE);
PageAlignment = EFI_PAGE_SIZE;
break;
}
if ((SectionAlignment & (PageAlignment - 1)) != 0) {
@@ -349,11 +354,11 @@ IsMemoryProtectionSectionAligned (
**/
VOID
FreeImageRecord (
IN IMAGE_PROPERTIES_RECORD *ImageRecord
IN IMAGE_PROPERTIES_RECORD *ImageRecord
)
{
LIST_ENTRY *CodeSegmentListHead;
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
LIST_ENTRY *CodeSegmentListHead;
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
CodeSegmentListHead = &ImageRecord->CodeSegmentList;
while (!IsListEmpty (CodeSegmentListHead)) {
@@ -370,6 +375,7 @@ FreeImageRecord (
if (ImageRecord->Link.ForwardLink != NULL) {
RemoveEntryList (&ImageRecord->Link);
}
FreePool (ImageRecord);
}
@@ -381,46 +387,47 @@ FreeImageRecord (
**/
VOID
ProtectUefiImage (
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
)
{
VOID *ImageAddress;
EFI_IMAGE_DOS_HEADER *DosHdr;
UINT32 PeCoffHeaderOffset;
UINT32 SectionAlignment;
EFI_IMAGE_SECTION_HEADER *Section;
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
UINT8 *Name;
UINTN Index;
IMAGE_PROPERTIES_RECORD *ImageRecord;
CHAR8 *PdbPointer;
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
BOOLEAN IsAligned;
UINT32 ProtectionPolicy;
VOID *ImageAddress;
EFI_IMAGE_DOS_HEADER *DosHdr;
UINT32 PeCoffHeaderOffset;
UINT32 SectionAlignment;
EFI_IMAGE_SECTION_HEADER *Section;
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
UINT8 *Name;
UINTN Index;
IMAGE_PROPERTIES_RECORD *ImageRecord;
CHAR8 *PdbPointer;
IMAGE_PROPERTIES_RECORD_CODE_SECTION *ImageRecordCodeSection;
BOOLEAN IsAligned;
UINT32 ProtectionPolicy;
DEBUG ((DEBUG_INFO, "ProtectUefiImageCommon - 0x%x\n", LoadedImage));
DEBUG ((DEBUG_INFO, " - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(UINTN)LoadedImage->ImageBase, LoadedImage->ImageSize));
if (gCpu == NULL) {
return ;
return;
}
ProtectionPolicy = GetUefiImageProtectionPolicy (LoadedImage, LoadedImageDevicePath);
switch (ProtectionPolicy) {
case DO_NOT_PROTECT:
return ;
case PROTECT_IF_ALIGNED_ELSE_ALLOW:
break;
default:
ASSERT(FALSE);
return ;
case DO_NOT_PROTECT:
return;
case PROTECT_IF_ALIGNED_ELSE_ALLOW:
break;
default:
ASSERT (FALSE);
return;
}
ImageRecord = AllocateZeroPool (sizeof(*ImageRecord));
ImageRecord = AllocateZeroPool (sizeof (*ImageRecord));
if (ImageRecord == NULL) {
return ;
return;
}
ImageRecord->Signature = IMAGE_PROPERTIES_RECORD_SIGNATURE;
//
@@ -431,7 +438,7 @@ ProtectUefiImage (
ImageAddress = LoadedImage->ImageBase;
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, " Image - %a\n", PdbPointer));
}
@@ -439,13 +446,13 @@ ProtectUefiImage (
//
// Check PE/COFF image
//
DosHdr = (EFI_IMAGE_DOS_HEADER *) (UINTN) ImageAddress;
DosHdr = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageAddress;
PeCoffHeaderOffset = 0;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
PeCoffHeaderOffset = DosHdr->e_lfanew;
}
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *) (UINTN) ImageAddress + PeCoffHeaderOffset);
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINT8 *)(UINTN)ImageAddress + PeCoffHeaderOffset);
if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
DEBUG ((DEBUG_VERBOSE, "Hdr.Pe32->Signature invalid - 0x%x\n", Hdr.Pe32->Signature));
// It might be image in SMM.
@@ -456,29 +463,33 @@ ProtectUefiImage (
// Get SectionAlignment
//
if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment;
} else {
SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment;
}
IsAligned = IsMemoryProtectionSectionAligned (SectionAlignment, LoadedImage->ImageCodeType);
if (!IsAligned) {
DEBUG ((DEBUG_VERBOSE, "!!!!!!!! ProtectUefiImageCommon - Section Alignment(0x%x) is incorrect !!!!!!!!\n",
SectionAlignment));
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
DEBUG ((
DEBUG_VERBOSE,
"!!!!!!!! ProtectUefiImageCommon - Section Alignment(0x%x) is incorrect !!!!!!!!\n",
SectionAlignment
));
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_VERBOSE, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
goto Finish;
}
Section = (EFI_IMAGE_SECTION_HEADER *) (
(UINT8 *) (UINTN) ImageAddress +
PeCoffHeaderOffset +
sizeof(UINT32) +
sizeof(EFI_IMAGE_FILE_HEADER) +
Hdr.Pe32->FileHeader.SizeOfOptionalHeader
);
Section = (EFI_IMAGE_SECTION_HEADER *)(
(UINT8 *)(UINTN)ImageAddress +
PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
Hdr.Pe32->FileHeader.SizeOfOptionalHeader
);
ImageRecord->CodeSegmentCount = 0;
InitializeListHead (&ImageRecord->CodeSegmentList);
for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {
@@ -518,14 +529,15 @@ ProtectUefiImage (
//
// Step 2: record code section
//
ImageRecordCodeSection = AllocatePool (sizeof(*ImageRecordCodeSection));
ImageRecordCodeSection = AllocatePool (sizeof (*ImageRecordCodeSection));
if (ImageRecordCodeSection == NULL) {
return ;
return;
}
ImageRecordCodeSection->Signature = IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE;
ImageRecordCodeSection->CodeSegmentBase = (UINTN)ImageAddress + Section[Index].VirtualAddress;
ImageRecordCodeSection->CodeSegmentSize = ALIGN_VALUE(Section[Index].SizeOfRawData, SectionAlignment);
ImageRecordCodeSection->CodeSegmentSize = ALIGN_VALUE (Section[Index].SizeOfRawData, SectionAlignment);
DEBUG ((DEBUG_VERBOSE, "ImageCode: 0x%016lx - 0x%016lx\n", ImageRecordCodeSection->CodeSegmentBase, ImageRecordCodeSection->CodeSegmentSize));
@@ -544,10 +556,11 @@ ProtectUefiImage (
// of course).
//
DEBUG ((DEBUG_WARN, "!!!!!!!! ProtectUefiImageCommon - CodeSegmentCount is 0 !!!!!!!!\n"));
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
}
goto Finish;
}
@@ -567,7 +580,7 @@ ProtectUefiImage (
// Round up the ImageSize, some CPU arch may return EFI_UNSUPPORTED if ImageSize is not aligned.
// Given that the loader always allocates full pages, we know the space after the image is not used.
//
ImageRecord->ImageSize = ALIGN_VALUE(LoadedImage->ImageSize, EFI_PAGE_SIZE);
ImageRecord->ImageSize = ALIGN_VALUE (LoadedImage->ImageSize, EFI_PAGE_SIZE);
//
// CPU ARCH present. Update memory attribute directly.
@@ -580,7 +593,7 @@ ProtectUefiImage (
InsertTailList (&mProtectedImageRecordList, &ImageRecord->Link);
Finish:
return ;
return;
}
/**
@@ -591,17 +604,18 @@ Finish:
**/
VOID
UnprotectUefiImage (
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath
)
{
IMAGE_PROPERTIES_RECORD *ImageRecord;
LIST_ENTRY *ImageRecordLink;
IMAGE_PROPERTIES_RECORD *ImageRecord;
LIST_ENTRY *ImageRecordLink;
if (PcdGet32(PcdImageProtectionPolicy) != 0) {
if (PcdGet32 (PcdImageProtectionPolicy) != 0) {
for (ImageRecordLink = mProtectedImageRecordList.ForwardLink;
ImageRecordLink != &mProtectedImageRecordList;
ImageRecordLink = ImageRecordLink->ForwardLink) {
ImageRecordLink = ImageRecordLink->ForwardLink)
{
ImageRecord = CR (
ImageRecordLink,
IMAGE_PROPERTIES_RECORD,
@@ -610,9 +624,11 @@ UnprotectUefiImage (
);
if (ImageRecord->ImageBase == (EFI_PHYSICAL_ADDRESS)(UINTN)LoadedImage->ImageBase) {
SetUefiImageMemoryAttributes (ImageRecord->ImageBase,
ImageRecord->ImageSize,
0);
SetUefiImageMemoryAttributes (
ImageRecord->ImageBase,
ImageRecord->ImageSize,
0
);
FreeImageRecord (ImageRecord);
return;
}
@@ -629,10 +645,10 @@ UnprotectUefiImage (
STATIC
UINT64
GetPermissionAttributeForMemoryType (
IN EFI_MEMORY_TYPE MemoryType
IN EFI_MEMORY_TYPE MemoryType
)
{
UINT64 TestBit;
UINT64 TestBit;
if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
@@ -665,27 +681,27 @@ SortMemoryMap (
IN UINTN DescriptorSize
)
{
EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
EFI_MEMORY_DESCRIPTOR TempMemoryMap;
EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
EFI_MEMORY_DESCRIPTOR TempMemoryMap;
MemoryMapEntry = MemoryMap;
MemoryMapEntry = MemoryMap;
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
while (MemoryMapEntry < MemoryMapEnd) {
while (NextMemoryMapEntry < MemoryMapEnd) {
if (MemoryMapEntry->PhysicalStart > NextMemoryMapEntry->PhysicalStart) {
CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof(EFI_MEMORY_DESCRIPTOR));
CopyMem (&TempMemoryMap, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
CopyMem (MemoryMapEntry, NextMemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
CopyMem (NextMemoryMapEntry, &TempMemoryMap, sizeof (EFI_MEMORY_DESCRIPTOR));
}
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NextMemoryMapEntry, DescriptorSize);
}
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
}
@@ -708,29 +724,30 @@ MergeMemoryMapForProtectionPolicy (
IN UINTN DescriptorSize
)
{
EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
UINT64 MemoryBlockLength;
EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
UINT64 Attributes;
EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
UINT64 MemoryBlockLength;
EFI_MEMORY_DESCRIPTOR *NewMemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *NextMemoryMapEntry;
UINT64 Attributes;
SortMemoryMap (MemoryMap, *MemoryMapSize, DescriptorSize);
MemoryMapEntry = MemoryMap;
MemoryMapEntry = MemoryMap;
NewMemoryMapEntry = MemoryMap;
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + *MemoryMapSize);
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + *MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof(EFI_MEMORY_DESCRIPTOR));
CopyMem (NewMemoryMapEntry, MemoryMapEntry, sizeof (EFI_MEMORY_DESCRIPTOR));
NextMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
do {
MemoryBlockLength = (UINT64) (EFI_PAGES_TO_SIZE((UINTN)MemoryMapEntry->NumberOfPages));
Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);
MemoryBlockLength = (UINT64)(EFI_PAGES_TO_SIZE ((UINTN)MemoryMapEntry->NumberOfPages));
Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);
if (((UINTN)NextMemoryMapEntry < (UINTN)MemoryMapEnd) &&
Attributes == GetPermissionAttributeForMemoryType (NextMemoryMapEntry->Type) &&
((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart)) {
(Attributes == GetPermissionAttributeForMemoryType (NextMemoryMapEntry->Type)) &&
((MemoryMapEntry->PhysicalStart + MemoryBlockLength) == NextMemoryMapEntry->PhysicalStart))
{
MemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
if (NewMemoryMapEntry != MemoryMapEntry) {
NewMemoryMapEntry->NumberOfPages += NextMemoryMapEntry->NumberOfPages;
@@ -744,16 +761,15 @@ MergeMemoryMapForProtectionPolicy (
}
} while (TRUE);
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
NewMemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (NewMemoryMapEntry, DescriptorSize);
}
*MemoryMapSize = (UINTN)NewMemoryMapEntry - (UINTN)MemoryMap;
return ;
return;
}
/**
Remove exec permissions from all regions whose type is identified by
PcdDxeNxMemoryProtectionPolicy.
@@ -764,20 +780,20 @@ InitializeDxeNxMemoryProtectionPolicy (
VOID
)
{
UINTN MemoryMapSize;
UINTN MapKey;
UINTN DescriptorSize;
UINT32 DescriptorVersion;
EFI_MEMORY_DESCRIPTOR *MemoryMap;
EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
EFI_STATUS Status;
UINT64 Attributes;
LIST_ENTRY *Link;
EFI_GCD_MAP_ENTRY *Entry;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
EFI_PHYSICAL_ADDRESS StackBase;
UINTN MemoryMapSize;
UINTN MapKey;
UINTN DescriptorSize;
UINT32 DescriptorVersion;
EFI_MEMORY_DESCRIPTOR *MemoryMap;
EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
EFI_STATUS Status;
UINT64 Attributes;
LIST_ENTRY *Link;
EFI_GCD_MAP_ENTRY *Entry;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
EFI_PHYSICAL_ADDRESS StackBase;
//
// Get the EFI memory map.
@@ -794,7 +810,7 @@ InitializeDxeNxMemoryProtectionPolicy (
);
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
do {
MemoryMap = (EFI_MEMORY_DESCRIPTOR *) AllocatePool (MemoryMapSize);
MemoryMap = (EFI_MEMORY_DESCRIPTOR *)AllocatePool (MemoryMapSize);
ASSERT (MemoryMap != NULL);
Status = gBS->GetMemoryMap (
&MemoryMapSize,
@@ -807,6 +823,7 @@ InitializeDxeNxMemoryProtectionPolicy (
FreePool (MemoryMap);
}
} while (Status == EFI_BUFFER_TOO_SMALL);
ASSERT_EFI_ERROR (Status);
StackBase = 0;
@@ -817,7 +834,7 @@ InitializeDxeNxMemoryProtectionPolicy (
Hob.Raw = GetHobList ();
while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
MemoryHob = Hob.MemoryAllocation;
if (CompareGuid(&gEfiHobMemoryAllocStackGuid, &MemoryHob->AllocDescriptor.Name)) {
if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &MemoryHob->AllocDescriptor.Name)) {
DEBUG ((
DEBUG_INFO,
"%a: StackBase = 0x%016lx StackSize = 0x%016lx\n",
@@ -833,6 +850,7 @@ InitializeDxeNxMemoryProtectionPolicy (
ASSERT ((StackBase & EFI_PAGE_MASK) == 0);
break;
}
Hob.Raw = GET_NEXT_HOB (Hob);
}
@@ -852,49 +870,52 @@ InitializeDxeNxMemoryProtectionPolicy (
MergeMemoryMapForProtectionPolicy (MemoryMap, &MemoryMapSize, DescriptorSize);
MemoryMapEntry = MemoryMap;
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) MemoryMap + MemoryMapSize);
while ((UINTN) MemoryMapEntry < (UINTN) MemoryMapEnd) {
MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);
if (Attributes != 0) {
SetUefiImageMemoryAttributes (
MemoryMapEntry->PhysicalStart,
LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),
Attributes);
Attributes
);
//
// Add EFI_MEMORY_RP attribute for page 0 if NULL pointer detection is
// enabled.
//
if (MemoryMapEntry->PhysicalStart == 0 &&
PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0) {
if ((MemoryMapEntry->PhysicalStart == 0) &&
(PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0))
{
ASSERT (MemoryMapEntry->NumberOfPages > 0);
SetUefiImageMemoryAttributes (
0,
EFI_PAGES_TO_SIZE (1),
EFI_MEMORY_RP | Attributes);
EFI_MEMORY_RP | Attributes
);
}
//
// Add EFI_MEMORY_RP attribute for the first page of the stack if stack
// guard is enabled.
//
if (StackBase != 0 &&
(StackBase >= MemoryMapEntry->PhysicalStart &&
StackBase < MemoryMapEntry->PhysicalStart +
LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT)) &&
PcdGetBool (PcdCpuStackGuard)) {
if ((StackBase != 0) &&
((StackBase >= MemoryMapEntry->PhysicalStart) &&
(StackBase < MemoryMapEntry->PhysicalStart +
LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT))) &&
PcdGetBool (PcdCpuStackGuard))
{
SetUefiImageMemoryAttributes (
StackBase,
EFI_PAGES_TO_SIZE (1),
EFI_MEMORY_RP | Attributes);
EFI_MEMORY_RP | Attributes
);
}
}
MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
}
FreePool (MemoryMap);
//
@@ -912,34 +933,40 @@ InitializeDxeNxMemoryProtectionPolicy (
Link = mGcdMemorySpaceMap.ForwardLink;
while (Link != &mGcdMemorySpaceMap) {
Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
if (Entry->GcdMemoryType == EfiGcdMemoryTypeReserved &&
Entry->EndAddress < MAX_ADDRESS &&
(Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)) {
if ((Entry->GcdMemoryType == EfiGcdMemoryTypeReserved) &&
(Entry->EndAddress < MAX_ADDRESS) &&
((Entry->Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)))
{
Attributes = GetPermissionAttributeForMemoryType (EfiConventionalMemory) |
(Entry->Attributes & EFI_CACHE_ATTRIBUTE_MASK);
DEBUG ((DEBUG_INFO,
DEBUG ((
DEBUG_INFO,
"Untested GCD memory space region: - 0x%016lx - 0x%016lx (0x%016lx)\n",
Entry->BaseAddress, Entry->EndAddress - Entry->BaseAddress + 1,
Attributes));
Entry->BaseAddress,
Entry->EndAddress - Entry->BaseAddress + 1,
Attributes
));
ASSERT(gCpu != NULL);
gCpu->SetMemoryAttributes (gCpu, Entry->BaseAddress,
Entry->EndAddress - Entry->BaseAddress + 1, Attributes);
ASSERT (gCpu != NULL);
gCpu->SetMemoryAttributes (
gCpu,
Entry->BaseAddress,
Entry->EndAddress - Entry->BaseAddress + 1,
Attributes
);
}
Link = Link->ForwardLink;
}
CoreReleaseGcdMemoryLock ();
}
}
/**
A notification for CPU_ARCH protocol.
@@ -951,16 +978,16 @@ InitializeDxeNxMemoryProtectionPolicy (
VOID
EFIAPI
MemoryProtectionCpuArchProtocolNotify (
IN EFI_EVENT Event,
IN VOID *Context
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
UINTN NoHandles;
EFI_HANDLE *HandleBuffer;
UINTN Index;
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;
UINTN NoHandles;
EFI_HANDLE *HandleBuffer;
UINTN Index;
DEBUG ((DEBUG_INFO, "MemoryProtectionCpuArchProtocolNotify:\n"));
Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu);
@@ -1001,20 +1028,22 @@ MemoryProtectionCpuArchProtocolNotify (
&gEfiLoadedImageProtocolGuid,
(VOID **)&LoadedImage
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
continue;
}
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiLoadedImageDevicePathProtocolGuid,
(VOID **)&LoadedImageDevicePath
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
LoadedImageDevicePath = NULL;
}
ProtectUefiImage (LoadedImage, LoadedImageDevicePath);
}
FreePool (HandleBuffer);
Done:
@@ -1029,8 +1058,8 @@ MemoryProtectionExitBootServicesCallback (
VOID
)
{
EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
LIST_ENTRY *Link;
EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
LIST_ENTRY *Link;
//
// We need remove the RT protection, because RT relocation need write code segment
@@ -1044,7 +1073,7 @@ MemoryProtectionExitBootServicesCallback (
if (mImageProtectionPolicy != 0) {
for (Link = gRuntime->ImageHead.ForwardLink; Link != &gRuntime->ImageHead; Link = Link->ForwardLink) {
RuntimeImage = BASE_CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);
SetUefiImageMemoryAttributes ((UINT64)(UINTN)RuntimeImage->ImageBase, ALIGN_VALUE(RuntimeImage->ImageSize, EFI_PAGE_SIZE), 0);
SetUefiImageMemoryAttributes ((UINT64)(UINTN)RuntimeImage->ImageBase, ALIGN_VALUE (RuntimeImage->ImageSize, EFI_PAGE_SIZE), 0);
}
}
}
@@ -1060,12 +1089,12 @@ MemoryProtectionExitBootServicesCallback (
VOID
EFIAPI
DisableNullDetectionAtTheEndOfDxe (
EFI_EVENT Event,
VOID *Context
EFI_EVENT Event,
VOID *Context
)
{
EFI_STATUS Status;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;
EFI_STATUS Status;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Desc;
DEBUG ((DEBUG_INFO, "DisableNullDetectionAtTheEndOfDxe(): start\r\n"));
//
@@ -1076,18 +1105,18 @@ DisableNullDetectionAtTheEndOfDxe (
if ((Desc.Capabilities & EFI_MEMORY_RP) == 0) {
Status = CoreSetMemorySpaceCapabilities (
0,
EFI_PAGE_SIZE,
Desc.Capabilities | EFI_MEMORY_RP
);
0,
EFI_PAGE_SIZE,
Desc.Capabilities | EFI_MEMORY_RP
);
ASSERT_EFI_ERROR (Status);
}
Status = CoreSetMemorySpaceAttributes (
0,
EFI_PAGE_SIZE,
Desc.Attributes & ~EFI_MEMORY_RP
);
0,
EFI_PAGE_SIZE,
Desc.Attributes & ~EFI_MEMORY_RP
);
ASSERT_EFI_ERROR (Status);
//
@@ -1115,7 +1144,7 @@ CoreInitializeMemoryProtection (
EFI_EVENT EndOfDxeEvent;
VOID *Registration;
mImageProtectionPolicy = PcdGet32(PcdImageProtectionPolicy);
mImageProtectionPolicy = PcdGet32 (PcdImageProtectionPolicy);
InitializeListHead (&mProtectedImageRecordList);
@@ -1128,8 +1157,10 @@ CoreInitializeMemoryProtection (
ASSERT ((GetPermissionAttributeForMemoryType (EfiBootServicesCode) & EFI_MEMORY_XP) == 0);
ASSERT ((GetPermissionAttributeForMemoryType (EfiRuntimeServicesCode) & EFI_MEMORY_XP) == 0);
ASSERT ((GetPermissionAttributeForMemoryType (EfiLoaderCode) & EFI_MEMORY_XP) == 0);
ASSERT (GetPermissionAttributeForMemoryType (EfiBootServicesData) ==
GetPermissionAttributeForMemoryType (EfiConventionalMemory));
ASSERT (
GetPermissionAttributeForMemoryType (EfiBootServicesData) ==
GetPermissionAttributeForMemoryType (EfiConventionalMemory)
);
Status = CoreCreateEvent (
EVT_NOTIFY_SIGNAL,
@@ -1138,7 +1169,7 @@ CoreInitializeMemoryProtection (
NULL,
&Event
);
ASSERT_EFI_ERROR(Status);
ASSERT_EFI_ERROR (Status);
//
// Register for protocol notifactions on this event
@@ -1148,25 +1179,26 @@ CoreInitializeMemoryProtection (
Event,
&Registration
);
ASSERT_EFI_ERROR(Status);
ASSERT_EFI_ERROR (Status);
//
// Register a callback to disable NULL pointer detection at EndOfDxe
//
if ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT0|BIT7))
== (BIT0|BIT7)) {
== (BIT0|BIT7))
{
Status = CoreCreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
DisableNullDetectionAtTheEndOfDxe,
NULL,
&gEfiEndOfDxeEventGroupGuid,
&EndOfDxeEvent
);
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
DisableNullDetectionAtTheEndOfDxe,
NULL,
&gEfiEndOfDxeEventGroupGuid,
&EndOfDxeEvent
);
ASSERT_EFI_ERROR (Status);
}
return ;
return;
}
/**
@@ -1178,12 +1210,13 @@ IsInSmm (
VOID
)
{
BOOLEAN InSmm;
BOOLEAN InSmm;
InSmm = FALSE;
if (gSmmBase2 != NULL) {
gSmmBase2->InSmm (gSmmBase2, &InSmm);
}
return InSmm;
}
@@ -1245,7 +1278,7 @@ ApplyMemoryProtectionPolicy (
// if any.
//
if (IsHeapGuardEnabled (GUARD_HEAP_TYPE_PAGE|GUARD_HEAP_TYPE_POOL)) {
if (IsGuardPage (Memory)) {
if (IsGuardPage (Memory)) {
Memory += EFI_PAGE_SIZE;
Length -= EFI_PAGE_SIZE;
if (Length == 0) {
@@ -1253,7 +1286,7 @@ ApplyMemoryProtectionPolicy (
}
}
if (IsGuardPage (Memory + Length - EFI_PAGE_SIZE)) {
if (IsGuardPage (Memory + Length - EFI_PAGE_SIZE)) {
Length -= EFI_PAGE_SIZE;
if (Length == 0) {
return EFI_SUCCESS;

View File

@@ -8,7 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#define WATCHDOG_TIMER_CALIBRATE_PER_SECOND 10000000
#define WATCHDOG_TIMER_CALIBRATE_PER_SECOND 10000000
/**
Sets the system's watchdog timer.
@@ -35,10 +35,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
CoreSetWatchdogTimer (
IN UINTN Timeout,
IN UINT64 WatchdogCode,
IN UINTN DataSize,
IN CHAR16 *WatchdogData OPTIONAL
IN UINTN Timeout,
IN UINT64 WatchdogCode,
IN UINTN DataSize,
IN CHAR16 *WatchdogData OPTIONAL
)
{
EFI_STATUS Status;

View File

@@ -30,6 +30,7 @@ CoreInternalWaitForTick (
gMetronome->WaitForTick (gMetronome, 0xffffffff);
Counter -= 0xffffffff;
}
gMetronome->WaitForTick (gMetronome, (UINT32)Counter);
}
@@ -46,7 +47,7 @@ CoreInternalWaitForTick (
EFI_STATUS
EFIAPI
CoreStall (
IN UINTN Microseconds
IN UINTN Microseconds
)
{
UINT64 Counter;
@@ -61,7 +62,7 @@ CoreStall (
// Counter = Microseconds * 10 / gMetronome->TickPeriod
// 0x1999999999999999 = (2^64 - 1) / 10
//
if ((UINT64) Microseconds > 0x1999999999999999ULL) {
if ((UINT64)Microseconds > 0x1999999999999999ULL) {
//
// Microseconds is too large to multiple by 10 first. Perform the divide
// operation first and loop 10 times to avoid 64-bit math overflow.
@@ -100,6 +101,7 @@ CoreStall (
//
Counter++;
}
CoreInternalWaitForTick (Counter);
}

View File

@@ -42,15 +42,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)
typedef struct {
UINT32 Signature;
LIST_ENTRY Link;
UINT32 Type;
UINT32 Size;
UINT32 Signature;
LIST_ENTRY Link;
UINT32 Type;
UINT32 Size;
//
// StreamBase + OffsetInStream == pointer to section header in stream. The
// stream base is always known when walking the sections within.
//
UINT32 OffsetInStream;
UINT32 OffsetInStream;
//
// Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
// encapsulating section. Otherwise, it contains the stream handle
@@ -58,33 +58,33 @@ typedef struct {
// encapsulating child is encountered, irrespective of whether the
// encapsulated stream is processed further.
//
UINTN EncapsulatedStreamHandle;
EFI_GUID *EncapsulationGuid;
UINTN EncapsulatedStreamHandle;
EFI_GUID *EncapsulationGuid;
//
// If the section REQUIRES an extraction protocol, register for RPN
// when the required GUIDed extraction protocol becomes available.
//
EFI_EVENT Event;
EFI_EVENT Event;
} CORE_SECTION_CHILD_NODE;
#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
#define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
#define STREAM_NODE_FROM_LINK(Node) \
CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)
typedef struct {
UINT32 Signature;
LIST_ENTRY Link;
UINTN StreamHandle;
UINT8 *StreamBuffer;
UINTN StreamLength;
LIST_ENTRY Children;
UINT32 Signature;
LIST_ENTRY Link;
UINTN StreamHandle;
UINT8 *StreamBuffer;
UINTN StreamLength;
LIST_ENTRY Children;
//
// Authentication status is from GUIDed encapsulations.
//
UINT32 AuthenticationStatus;
UINT32 AuthenticationStatus;
} CORE_SECTION_STREAM_NODE;
#define NULL_STREAM_HANDLE 0
#define NULL_STREAM_HANDLE 0
typedef struct {
CORE_SECTION_CHILD_NODE *ChildNode;
@@ -92,7 +92,6 @@ typedef struct {
VOID *Registration;
} RPN_EVENT_CONTEXT;
/**
The ExtractSection() function processes the input section and
allocates a buffer from the pool in which it returns the section
@@ -179,25 +178,24 @@ typedef struct {
EFI_STATUS
EFIAPI
CustomGuidedSectionExtract (
IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
);
//
// Module globals
//
LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);
LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);
EFI_HANDLE mSectionExtractionHandle = NULL;
EFI_HANDLE mSectionExtractionHandle = NULL;
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol = {
CustomGuidedSectionExtract
};
/**
Entry point of the section extraction code. Initializes an instance of the
section extraction interface and installs it on a new handle.
@@ -212,13 +210,13 @@ EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL mCustomGuidedSectionExtractionProtocol =
EFI_STATUS
EFIAPI
InitializeSectionExtraction (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_GUID *ExtractHandlerGuidTable;
UINTN ExtractHandlerNumber;
EFI_STATUS Status;
EFI_GUID *ExtractHandlerGuidTable;
UINTN ExtractHandlerNumber;
//
// Get custom extract guided section method guid list
@@ -231,18 +229,17 @@ InitializeSectionExtraction (
//
while (ExtractHandlerNumber-- > 0) {
Status = CoreInstallProtocolInterface (
&mSectionExtractionHandle,
&ExtractHandlerGuidTable [ExtractHandlerNumber],
EFI_NATIVE_INTERFACE,
&mCustomGuidedSectionExtractionProtocol
);
&mSectionExtractionHandle,
&ExtractHandlerGuidTable[ExtractHandlerNumber],
EFI_NATIVE_INTERFACE,
&mCustomGuidedSectionExtractionProtocol
);
ASSERT_EFI_ERROR (Status);
}
return Status;
}
/**
Check if a stream is valid.
@@ -254,16 +251,16 @@ InitializeSectionExtraction (
**/
BOOLEAN
IsValidSectionStream (
IN VOID *SectionStream,
IN UINTN SectionStreamLength
IN VOID *SectionStream,
IN UINTN SectionStreamLength
)
{
UINTN TotalLength;
UINTN SectionLength;
EFI_COMMON_SECTION_HEADER *SectionHeader;
EFI_COMMON_SECTION_HEADER *NextSectionHeader;
UINTN TotalLength;
UINTN SectionLength;
EFI_COMMON_SECTION_HEADER *SectionHeader;
EFI_COMMON_SECTION_HEADER *NextSectionHeader;
TotalLength = 0;
TotalLength = 0;
SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;
while (TotalLength < SectionStreamLength) {
@@ -272,6 +269,7 @@ IsValidSectionStream (
} else {
SectionLength = SECTION_SIZE (SectionHeader);
}
TotalLength += SectionLength;
if (TotalLength == SectionStreamLength) {
@@ -281,21 +279,20 @@ IsValidSectionStream (
//
// Move to the next byte following the section...
//
SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);
SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)SectionHeader + SectionLength);
//
// Figure out where the next section begins
//
NextSectionHeader = ALIGN_POINTER(SectionHeader, 4);
TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;
SectionHeader = NextSectionHeader;
NextSectionHeader = ALIGN_POINTER (SectionHeader, 4);
TotalLength += (UINTN)NextSectionHeader - (UINTN)SectionHeader;
SectionHeader = NextSectionHeader;
}
ASSERT (FALSE);
return FALSE;
}
/**
Worker function. Constructor for section streams.
@@ -331,15 +328,15 @@ IsValidSectionStream (
**/
EFI_STATUS
OpenSectionStreamEx (
IN UINTN SectionStreamLength,
IN VOID *SectionStream,
IN BOOLEAN AllocateBuffer,
IN UINT32 AuthenticationStatus,
OUT UINTN *SectionStreamHandle
IN UINTN SectionStreamLength,
IN VOID *SectionStream,
IN BOOLEAN AllocateBuffer,
IN UINT32 AuthenticationStatus,
OUT UINTN *SectionStreamHandle
)
{
CORE_SECTION_STREAM_NODE *NewStream;
EFI_TPL OldTpl;
CORE_SECTION_STREAM_NODE *NewStream;
EFI_TPL OldTpl;
//
// Allocate a new stream
@@ -360,6 +357,7 @@ OpenSectionStreamEx (
CoreFreePool (NewStream);
return EFI_OUT_OF_RESOURCES;
}
//
// Copy in stream data
//
@@ -382,8 +380,8 @@ OpenSectionStreamEx (
//
// Initialize the rest of the section stream
//
NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;
NewStream->StreamHandle = (UINTN) NewStream;
NewStream->Signature = CORE_SECTION_STREAM_SIGNATURE;
NewStream->StreamHandle = (UINTN)NewStream;
NewStream->StreamLength = SectionStreamLength;
InitializeListHead (&NewStream->Children);
NewStream->AuthenticationStatus = AuthenticationStatus;
@@ -400,7 +398,6 @@ OpenSectionStreamEx (
return EFI_SUCCESS;
}
/**
SEP member function. This function creates and returns a new section stream
handle to represent the new section stream.
@@ -419,9 +416,9 @@ OpenSectionStreamEx (
EFI_STATUS
EFIAPI
OpenSectionStream (
IN UINTN SectionStreamLength,
IN VOID *SectionStream,
OUT UINTN *SectionStreamHandle
IN UINTN SectionStreamLength,
IN VOID *SectionStream,
OUT UINTN *SectionStreamHandle
)
{
//
@@ -440,8 +437,6 @@ OpenSectionStream (
);
}
/**
Worker function. Determine if the input stream:child matches the input type.
@@ -459,26 +454,29 @@ OpenSectionStream (
**/
BOOLEAN
ChildIsType (
IN CORE_SECTION_STREAM_NODE *Stream,
IN CORE_SECTION_CHILD_NODE *Child,
IN EFI_SECTION_TYPE SearchType,
IN EFI_GUID *SectionDefinitionGuid
IN CORE_SECTION_STREAM_NODE *Stream,
IN CORE_SECTION_CHILD_NODE *Child,
IN EFI_SECTION_TYPE SearchType,
IN EFI_GUID *SectionDefinitionGuid
)
{
EFI_GUID_DEFINED_SECTION *GuidedSection;
EFI_GUID_DEFINED_SECTION *GuidedSection;
if (SearchType == EFI_SECTION_ALL) {
return TRUE;
}
if (Child->Type != SearchType) {
return FALSE;
}
if ((SearchType != EFI_SECTION_GUID_DEFINED) || (SectionDefinitionGuid == NULL)) {
return TRUE;
}
GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);
GuidedSection = (EFI_GUID_DEFINED_SECTION *)(Stream->StreamBuffer + Child->OffsetInStream);
if (IS_SECTION2 (GuidedSection)) {
return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *) GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);
return CompareGuid (&(((EFI_GUID_DEFINED_SECTION2 *)GuidedSection)->SectionDefinitionGuid), SectionDefinitionGuid);
} else {
return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);
}
@@ -499,33 +497,34 @@ ChildIsType (
**/
BOOLEAN
VerifyGuidedSectionGuid (
IN EFI_GUID *GuidedSectionGuid,
OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction
IN EFI_GUID *GuidedSectionGuid,
OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL **GuidedSectionExtraction
)
{
EFI_GUID *GuidRecorded;
VOID *Interface;
EFI_STATUS Status;
EFI_GUID *GuidRecorded;
VOID *Interface;
EFI_STATUS Status;
Interface = NULL;
//
// Check if there is the Guided Section GUID configuration table recorded the GUID itself.
//
Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **) &GuidRecorded);
Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **)&GuidRecorded);
if (Status == EFI_SUCCESS) {
if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {
//
// Found the recorded GuidedSectionGuid.
//
Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **) &Interface);
if (!EFI_ERROR (Status) && Interface != NULL) {
Status = CoreLocateProtocol (GuidedSectionGuid, NULL, (VOID **)&Interface);
if (!EFI_ERROR (Status) && (Interface != NULL)) {
//
// Found the supported Guided Section Extraction Porotocol for the Guided Section.
//
*GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *) Interface;
*GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *)Interface;
return TRUE;
}
return FALSE;
}
}
@@ -544,8 +543,8 @@ VerifyGuidedSectionGuid (
VOID
EFIAPI
NotifyGuidedExtraction (
IN EFI_EVENT Event,
IN VOID *RpnContext
IN EFI_EVENT Event,
IN VOID *RpnContext
)
{
EFI_STATUS Status;
@@ -558,7 +557,7 @@ NotifyGuidedExtraction (
Context = RpnContext;
GuidedHeader = (EFI_GUID_DEFINED_SECTION *) (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);
GuidedHeader = (EFI_GUID_DEFINED_SECTION *)(Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);
ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);
if (!VerifyGuidedSectionGuid (Context->ChildNode->EncapsulationGuid, &GuidedExtraction)) {
@@ -617,11 +616,11 @@ NotifyGuidedExtraction (
**/
VOID
CreateGuidedExtractionRpnEvent (
IN CORE_SECTION_STREAM_NODE *ParentStream,
IN CORE_SECTION_CHILD_NODE *ChildNode
IN CORE_SECTION_STREAM_NODE *ParentStream,
IN CORE_SECTION_CHILD_NODE *ChildNode
)
{
RPN_EVENT_CONTEXT *Context;
RPN_EVENT_CONTEXT *Context;
//
// Allocate new event structure and context
@@ -629,7 +628,7 @@ CreateGuidedExtractionRpnEvent (
Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));
ASSERT (Context != NULL);
Context->ChildNode = ChildNode;
Context->ChildNode = ChildNode;
Context->ParentStream = ParentStream;
Context->ChildNode->Event = EfiCreateProtocolNotifyEvent (
@@ -664,37 +663,37 @@ CreateGuidedExtractionRpnEvent (
**/
EFI_STATUS
CreateChildNode (
IN CORE_SECTION_STREAM_NODE *Stream,
IN UINT32 ChildOffset,
OUT CORE_SECTION_CHILD_NODE **ChildNode
IN CORE_SECTION_STREAM_NODE *Stream,
IN UINT32 ChildOffset,
OUT CORE_SECTION_CHILD_NODE **ChildNode
)
{
EFI_STATUS Status;
EFI_COMMON_SECTION_HEADER *SectionHeader;
EFI_COMPRESSION_SECTION *CompressionHeader;
EFI_GUID_DEFINED_SECTION *GuidedHeader;
EFI_DECOMPRESS_PROTOCOL *Decompress;
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
VOID *NewStreamBuffer;
VOID *ScratchBuffer;
UINT32 ScratchSize;
UINTN NewStreamBufferSize;
UINT32 AuthenticationStatus;
VOID *CompressionSource;
UINT32 CompressionSourceSize;
UINT32 UncompressedLength;
UINT8 CompressionType;
UINT16 GuidedSectionAttributes;
EFI_STATUS Status;
EFI_COMMON_SECTION_HEADER *SectionHeader;
EFI_COMPRESSION_SECTION *CompressionHeader;
EFI_GUID_DEFINED_SECTION *GuidedHeader;
EFI_DECOMPRESS_PROTOCOL *Decompress;
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
VOID *NewStreamBuffer;
VOID *ScratchBuffer;
UINT32 ScratchSize;
UINTN NewStreamBufferSize;
UINT32 AuthenticationStatus;
VOID *CompressionSource;
UINT32 CompressionSourceSize;
UINT32 UncompressedLength;
UINT8 CompressionType;
UINT16 GuidedSectionAttributes;
CORE_SECTION_CHILD_NODE *Node;
CORE_SECTION_CHILD_NODE *Node;
SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);
SectionHeader = (EFI_COMMON_SECTION_HEADER *)(Stream->StreamBuffer + ChildOffset);
//
// Allocate a new node
//
*ChildNode = AllocateZeroPool (sizeof (CORE_SECTION_CHILD_NODE));
Node = *ChildNode;
Node = *ChildNode;
if (Node == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -703,15 +702,16 @@ CreateChildNode (
// Now initialize it
//
Node->Signature = CORE_SECTION_CHILD_SIGNATURE;
Node->Type = SectionHeader->Type;
Node->Type = SectionHeader->Type;
if (IS_SECTION2 (SectionHeader)) {
Node->Size = SECTION2_SIZE (SectionHeader);
} else {
Node->Size = SECTION_SIZE (SectionHeader);
}
Node->OffsetInStream = ChildOffset;
Node->OffsetInStream = ChildOffset;
Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;
Node->EncapsulationGuid = NULL;
Node->EncapsulationGuid = NULL;
//
// If it's an encapsulating section, then create the new section stream also
@@ -726,18 +726,18 @@ CreateChildNode (
return EFI_NOT_FOUND;
}
CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;
CompressionHeader = (EFI_COMPRESSION_SECTION *)SectionHeader;
if (IS_SECTION2 (CompressionHeader)) {
CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));
CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));
UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->UncompressedLength;
CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionHeader)->CompressionType;
CompressionSource = (VOID *)((UINT8 *)CompressionHeader + sizeof (EFI_COMPRESSION_SECTION2));
CompressionSourceSize = (UINT32)(SECTION2_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION2));
UncompressedLength = ((EFI_COMPRESSION_SECTION2 *)CompressionHeader)->UncompressedLength;
CompressionType = ((EFI_COMPRESSION_SECTION2 *)CompressionHeader)->CompressionType;
} else {
CompressionSource = (VOID *) ((UINT8 *) CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));
CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));
UncompressedLength = CompressionHeader->UncompressedLength;
CompressionType = CompressionHeader->CompressionType;
CompressionSource = (VOID *)((UINT8 *)CompressionHeader + sizeof (EFI_COMPRESSION_SECTION));
CompressionSourceSize = (UINT32)(SECTION_SIZE (CompressionHeader) - sizeof (EFI_COMPRESSION_SECTION));
UncompressedLength = CompressionHeader->UncompressedLength;
CompressionType = CompressionHeader->CompressionType;
}
//
@@ -745,7 +745,7 @@ CreateChildNode (
//
if (UncompressedLength > 0) {
NewStreamBufferSize = UncompressedLength;
NewStreamBuffer = AllocatePool (NewStreamBufferSize);
NewStreamBuffer = AllocatePool (NewStreamBufferSize);
if (NewStreamBuffer == NULL) {
CoreFreePool (Node);
return EFI_OUT_OF_RESOURCES;
@@ -781,6 +781,7 @@ CreateChildNode (
if (!EFI_ERROR (Status)) {
Status = EFI_BAD_BUFFER_SIZE;
}
return Status;
}
@@ -808,7 +809,7 @@ CreateChildNode (
}
}
} else {
NewStreamBuffer = NULL;
NewStreamBuffer = NULL;
NewStreamBufferSize = 0;
}
@@ -824,17 +825,19 @@ CreateChildNode (
CoreFreePool (NewStreamBuffer);
return Status;
}
break;
case EFI_SECTION_GUID_DEFINED:
GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;
GuidedHeader = (EFI_GUID_DEFINED_SECTION *)SectionHeader;
if (IS_SECTION2 (GuidedHeader)) {
Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->SectionDefinitionGuid);
GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->Attributes;
Node->EncapsulationGuid = &(((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->SectionDefinitionGuid);
GuidedSectionAttributes = ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->Attributes;
} else {
Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;
GuidedSectionAttributes = GuidedHeader->Attributes;
}
if (VerifyGuidedSectionGuid (Node->EncapsulationGuid, &GuidedExtraction)) {
//
// NewStreamBuffer is always allocated by ExtractSection... No caller
@@ -903,21 +906,22 @@ CreateChildNode (
if (IS_SECTION2 (GuidedHeader)) {
Status = OpenSectionStreamEx (
SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
(UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *) GuidedHeader)->DataOffset,
SECTION2_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->DataOffset,
(UINT8 *)GuidedHeader + ((EFI_GUID_DEFINED_SECTION2 *)GuidedHeader)->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
} else {
Status = OpenSectionStreamEx (
SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
(UINT8 *) GuidedHeader + ((EFI_GUID_DEFINED_SECTION *) GuidedHeader)->DataOffset,
SECTION_SIZE (GuidedHeader) - ((EFI_GUID_DEFINED_SECTION *)GuidedHeader)->DataOffset,
(UINT8 *)GuidedHeader + ((EFI_GUID_DEFINED_SECTION *)GuidedHeader)->DataOffset,
TRUE,
AuthenticationStatus,
&Node->EncapsulatedStreamHandle
);
}
if (EFI_ERROR (Status)) {
CoreFreePool (Node);
return Status;
@@ -943,7 +947,6 @@ CreateChildNode (
return EFI_SUCCESS;
}
/**
Worker function Recursively searches / builds section stream database
looking for requested section.
@@ -978,22 +981,22 @@ CreateChildNode (
**/
EFI_STATUS
FindChildNode (
IN CORE_SECTION_STREAM_NODE *SourceStream,
IN EFI_SECTION_TYPE SearchType,
IN OUT UINTN *SectionInstance,
IN EFI_GUID *SectionDefinitionGuid,
IN UINT32 Depth,
OUT CORE_SECTION_CHILD_NODE **FoundChild,
OUT CORE_SECTION_STREAM_NODE **FoundStream,
OUT UINT32 *AuthenticationStatus
IN CORE_SECTION_STREAM_NODE *SourceStream,
IN EFI_SECTION_TYPE SearchType,
IN OUT UINTN *SectionInstance,
IN EFI_GUID *SectionDefinitionGuid,
IN UINT32 Depth,
OUT CORE_SECTION_CHILD_NODE **FoundChild,
OUT CORE_SECTION_STREAM_NODE **FoundStream,
OUT UINT32 *AuthenticationStatus
)
{
CORE_SECTION_CHILD_NODE *CurrentChildNode;
CORE_SECTION_CHILD_NODE *RecursedChildNode;
CORE_SECTION_STREAM_NODE *RecursedFoundStream;
UINT32 NextChildOffset;
EFI_STATUS ErrorStatus;
EFI_STATUS Status;
CORE_SECTION_CHILD_NODE *CurrentChildNode;
CORE_SECTION_CHILD_NODE *RecursedChildNode;
CORE_SECTION_STREAM_NODE *RecursedFoundStream;
UINT32 NextChildOffset;
EFI_STATUS ErrorStatus;
EFI_STATUS Status;
ASSERT (*SectionInstance > 0);
@@ -1002,14 +1005,15 @@ FindChildNode (
}
CurrentChildNode = NULL;
ErrorStatus = EFI_NOT_FOUND;
ErrorStatus = EFI_NOT_FOUND;
if (SourceStream->StreamLength == 0) {
return EFI_NOT_FOUND;
}
if (IsListEmpty (&SourceStream->Children) &&
SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)) {
(SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)))
{
//
// This occurs when a section stream exists, but no child sections
// have been parsed out yet. Therefore, extract the first child and add it
@@ -1030,9 +1034,9 @@ FindChildNode (
// adding children until either the requested section is found, or we run
// out of data
//
CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));
CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode (&SourceStream->Children));
for (;;) {
for ( ; ;) {
ASSERT (CurrentChildNode != NULL);
if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {
//
@@ -1043,8 +1047,8 @@ FindChildNode (
//
// Got it!
//
*FoundChild = CurrentChildNode;
*FoundStream = SourceStream;
*FoundChild = CurrentChildNode;
*FoundStream = SourceStream;
*AuthenticationStatus = SourceStream->AuthenticationStatus;
return EFI_SUCCESS;
}
@@ -1060,22 +1064,22 @@ FindChildNode (
// If the current node is an encapsulating node, recurse into it...
//
Status = FindChildNode (
(CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,
SearchType,
SectionInstance,
SectionDefinitionGuid,
Depth + 1,
&RecursedChildNode,
&RecursedFoundStream,
AuthenticationStatus
);
(CORE_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,
SearchType,
SectionInstance,
SectionDefinitionGuid,
Depth + 1,
&RecursedChildNode,
&RecursedFoundStream,
AuthenticationStatus
);
if (*SectionInstance == 0) {
//
// The recursive FindChildNode() call decreased (*SectionInstance) to
// zero.
//
ASSERT_EFI_ERROR (Status);
*FoundChild = RecursedChildNode;
*FoundChild = RecursedChildNode;
*FoundStream = RecursedFoundStream;
return EFI_SUCCESS;
} else {
@@ -1087,6 +1091,7 @@ FindChildNode (
//
return Status;
}
//
// Save the error code and continue to find the requested child node in
// the rest of the stream.
@@ -1120,7 +1125,7 @@ FindChildNode (
// Round up to 4 byte boundary
//
NextChildOffset += 3;
NextChildOffset &= ~(UINTN) 3;
NextChildOffset &= ~(UINTN)3;
if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {
//
// There's an unparsed child remaining in the stream, so create a new child node
@@ -1137,7 +1142,6 @@ FindChildNode (
}
}
/**
Worker function. Search stream database for requested stream handle.
@@ -1152,15 +1156,15 @@ FindChildNode (
**/
EFI_STATUS
FindStreamNode (
IN UINTN SearchHandle,
OUT CORE_SECTION_STREAM_NODE **FoundStream
IN UINTN SearchHandle,
OUT CORE_SECTION_STREAM_NODE **FoundStream
)
{
CORE_SECTION_STREAM_NODE *StreamNode;
CORE_SECTION_STREAM_NODE *StreamNode;
if (!IsListEmpty (&mStreamRoot)) {
StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));
for (;;) {
for ( ; ;) {
if (StreamNode->StreamHandle == SearchHandle) {
*FoundStream = StreamNode;
return EFI_SUCCESS;
@@ -1175,7 +1179,6 @@ FindStreamNode (
return EFI_NOT_FOUND;
}
/**
SEP member function. Retrieves requested section from section stream.
@@ -1237,32 +1240,31 @@ FindStreamNode (
EFI_STATUS
EFIAPI
GetSection (
IN UINTN SectionStreamHandle,
IN EFI_SECTION_TYPE *SectionType,
IN EFI_GUID *SectionDefinitionGuid,
IN UINTN SectionInstance,
IN VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT UINT32 *AuthenticationStatus,
IN BOOLEAN IsFfs3Fv
IN UINTN SectionStreamHandle,
IN EFI_SECTION_TYPE *SectionType,
IN EFI_GUID *SectionDefinitionGuid,
IN UINTN SectionInstance,
IN VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT UINT32 *AuthenticationStatus,
IN BOOLEAN IsFfs3Fv
)
{
CORE_SECTION_STREAM_NODE *StreamNode;
EFI_TPL OldTpl;
EFI_STATUS Status;
CORE_SECTION_CHILD_NODE *ChildNode;
CORE_SECTION_STREAM_NODE *ChildStreamNode;
UINTN CopySize;
UINT32 ExtractedAuthenticationStatus;
UINTN Instance;
UINT8 *CopyBuffer;
UINTN SectionSize;
EFI_COMMON_SECTION_HEADER *Section;
CORE_SECTION_STREAM_NODE *StreamNode;
EFI_TPL OldTpl;
EFI_STATUS Status;
CORE_SECTION_CHILD_NODE *ChildNode;
CORE_SECTION_STREAM_NODE *ChildStreamNode;
UINTN CopySize;
UINT32 ExtractedAuthenticationStatus;
UINTN Instance;
UINT8 *CopyBuffer;
UINTN SectionSize;
EFI_COMMON_SECTION_HEADER *Section;
ChildStreamNode = NULL;
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
Instance = SectionInstance + 1;
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
Instance = SectionInstance + 1;
//
// Locate target stream
@@ -1280,8 +1282,8 @@ GetSection (
//
// SectionType == NULL means return the WHOLE section stream...
//
CopySize = StreamNode->StreamLength;
CopyBuffer = StreamNode->StreamBuffer;
CopySize = StreamNode->StreamLength;
CopyBuffer = StreamNode->StreamBuffer;
*AuthenticationStatus = StreamNode->AuthenticationStatus;
} else {
//
@@ -1299,17 +1301,21 @@ GetSection (
);
if (EFI_ERROR (Status)) {
if (Status == EFI_ABORTED) {
DEBUG ((DEBUG_ERROR, "%a: recursion aborted due to nesting depth\n",
__FUNCTION__));
DEBUG ((
DEBUG_ERROR,
"%a: recursion aborted due to nesting depth\n",
__FUNCTION__
));
//
// Map "aborted" to "not found".
//
Status = EFI_NOT_FOUND;
}
goto GetSection_Done;
}
Section = (EFI_COMMON_SECTION_HEADER *) (ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);
Section = (EFI_COMMON_SECTION_HEADER *)(ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream);
if (IS_SECTION2 (Section)) {
ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF);
@@ -1318,12 +1324,14 @@ GetSection (
Status = EFI_NOT_FOUND;
goto GetSection_Done;
}
CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2);
CopySize = SECTION2_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER2);
CopyBuffer = (UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER2);
} else {
CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
CopyBuffer = (UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER);
CopySize = SECTION_SIZE (Section) - sizeof (EFI_COMMON_SECTION_HEADER);
CopyBuffer = (UINT8 *)Section + sizeof (EFI_COMMON_SECTION_HEADER);
}
*AuthenticationStatus = ExtractedAuthenticationStatus;
}
@@ -1333,7 +1341,7 @@ GetSection (
// Caller allocated buffer. Fill to size and return required size...
//
if (*BufferSize < CopySize) {
Status = EFI_WARN_BUFFER_TOO_SMALL;
Status = EFI_WARN_BUFFER_TOO_SMALL;
CopySize = *BufferSize;
}
} else {
@@ -1346,6 +1354,7 @@ GetSection (
goto GetSection_Done;
}
}
CopyMem (*Buffer, CopyBuffer, CopySize);
*BufferSize = SectionSize;
@@ -1355,7 +1364,6 @@ GetSection_Done:
return Status;
}
/**
Worker function. Destructor for child nodes.
@@ -1364,7 +1372,7 @@ GetSection_Done:
**/
VOID
FreeChildNode (
IN CORE_SECTION_CHILD_NODE *ChildNode
IN CORE_SECTION_CHILD_NODE *ChildNode
)
{
ASSERT (ChildNode->Signature == CORE_SECTION_CHILD_SIGNATURE);
@@ -1391,7 +1399,6 @@ FreeChildNode (
CoreFreePool (ChildNode);
}
/**
SEP member function. Deletes an existing section stream
@@ -1408,15 +1415,15 @@ FreeChildNode (
EFI_STATUS
EFIAPI
CloseSectionStream (
IN UINTN StreamHandleToClose,
IN BOOLEAN FreeStreamBuffer
IN UINTN StreamHandleToClose,
IN BOOLEAN FreeStreamBuffer
)
{
CORE_SECTION_STREAM_NODE *StreamNode;
EFI_TPL OldTpl;
EFI_STATUS Status;
LIST_ENTRY *Link;
CORE_SECTION_CHILD_NODE *ChildNode;
CORE_SECTION_STREAM_NODE *StreamNode;
EFI_TPL OldTpl;
EFI_STATUS Status;
LIST_ENTRY *Link;
CORE_SECTION_CHILD_NODE *ChildNode;
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
@@ -1430,13 +1437,15 @@ CloseSectionStream (
//
RemoveEntryList (&StreamNode->Link);
while (!IsListEmpty (&StreamNode->Children)) {
Link = GetFirstNode (&StreamNode->Children);
Link = GetFirstNode (&StreamNode->Children);
ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);
FreeChildNode (ChildNode);
}
if (FreeStreamBuffer) {
CoreFreePool (StreamNode->StreamBuffer);
}
CoreFreePool (StreamNode);
Status = EFI_SUCCESS;
} else {
@@ -1447,7 +1456,6 @@ CloseSectionStream (
return Status;
}
/**
The ExtractSection() function processes the input section and
allocates a buffer from the pool in which it returns the section
@@ -1534,19 +1542,19 @@ CloseSectionStream (
EFI_STATUS
EFIAPI
CustomGuidedSectionExtract (
IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
IN CONST EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
)
{
EFI_STATUS Status;
VOID *ScratchBuffer;
VOID *AllocatedOutputBuffer;
UINT32 OutputBufferSize;
UINT32 ScratchBufferSize;
UINT16 SectionAttribute;
EFI_STATUS Status;
VOID *ScratchBuffer;
VOID *AllocatedOutputBuffer;
UINT32 OutputBufferSize;
UINT32 ScratchBufferSize;
UINT16 SectionAttribute;
//
// Init local variable
@@ -1588,8 +1596,10 @@ CustomGuidedSectionExtract (
if (ScratchBuffer != NULL) {
FreePool (ScratchBuffer);
}
return EFI_OUT_OF_RESOURCES;
}
*OutputBuffer = AllocatedOutputBuffer;
}
@@ -1609,9 +1619,11 @@ CustomGuidedSectionExtract (
if (AllocatedOutputBuffer != NULL) {
CoreFreePool (AllocatedOutputBuffer);
}
if (ScratchBuffer != NULL) {
CoreFreePool (ScratchBuffer);
}
DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));
return Status;
}
@@ -1628,7 +1640,7 @@ CustomGuidedSectionExtract (
//
// Set real size of output buffer.
//
*OutputSize = (UINTN) OutputBufferSize;
*OutputSize = (UINTN)OutputBufferSize;
//
// Free unused scratch buffer.

View File

@@ -25,13 +25,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
)
{
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
//
// Allocate 128KB for the Stack
@@ -48,7 +48,7 @@ HandOffToDxeCore (
// Compute the top of the stack we were allocated. Pre-allocate a UINTN
// for safety.
//
TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
//
@@ -60,7 +60,7 @@ HandOffToDxeCore (
//
// Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,

View File

@@ -46,11 +46,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define STACK_SIZE 0x20000
#define BSP_STORE_SIZE 0x4000
//
// This PPI is installed to indicate the end of the PEI usage of memory
//
extern CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi;
extern CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi;
/**
This function installs the PPIs that require permanent memory.
@@ -83,7 +82,6 @@ DxeIplFindDxeCore (
VOID
);
/**
Main entry point to last PEIM
@@ -98,13 +96,11 @@ DxeIplFindDxeCore (
EFI_STATUS
EFIAPI
DxeLoadCore (
IN CONST EFI_DXE_IPL_PPI *This,
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_HOB_POINTERS HobList
IN CONST EFI_DXE_IPL_PPI *This,
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_HOB_POINTERS HobList
);
/**
Transfers control to DxeCore.
@@ -118,12 +114,10 @@ DxeLoadCore (
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
);
/**
Updates the Stack HOB passed to DXE phase.
@@ -136,8 +130,8 @@ HandOffToDxeCore (
**/
VOID
UpdateStackHob (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
);
/**
@@ -197,14 +191,13 @@ UpdateStackHob (
EFI_STATUS
EFIAPI
CustomGuidedSectionExtract (
IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
);
/**
Decompresses a section to the output buffer.
@@ -228,10 +221,10 @@ CustomGuidedSectionExtract (
EFI_STATUS
EFIAPI
Decompress (
IN CONST EFI_PEI_DECOMPRESS_PPI *This,
IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize
IN CONST EFI_PEI_DECOMPRESS_PPI *This,
IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize
);
#endif

View File

@@ -10,42 +10,41 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeIpl.h"
//
// Module Globals used in the DXE to PEI hand off
// These must be module globals, so the stack can be switched
//
CONST EFI_DXE_IPL_PPI mDxeIplPpi = {
CONST EFI_DXE_IPL_PPI mDxeIplPpi = {
DxeLoadCore
};
CONST EFI_PEI_PPI_DESCRIPTOR mDxeIplPpiList = {
CONST EFI_PEI_PPI_DESCRIPTOR mDxeIplPpiList = {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEfiDxeIplPpiGuid,
(VOID *) &mDxeIplPpi
(VOID *)&mDxeIplPpi
};
CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {
CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {
CustomGuidedSectionExtract
};
CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {
CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {
Decompress
};
CONST EFI_PEI_PPI_DESCRIPTOR mDecompressPpiList = {
CONST EFI_PEI_PPI_DESCRIPTOR mDecompressPpiList = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiDecompressPpiGuid,
(VOID *) &mDecompressPpi
(VOID *)&mDecompressPpi
};
CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {
CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiEndOfPeiSignalPpiGuid,
NULL
};
CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList = {
CONST EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMemoryDiscoveredPpiGuid,
InstallIplPermanentMemoryPpis
@@ -71,9 +70,9 @@ PeimInitializeDxeIpl (
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
VOID *Dummy;
EFI_STATUS Status;
EFI_BOOT_MODE BootMode;
VOID *Dummy;
BootMode = GetBootModeHob ();
@@ -98,7 +97,7 @@ PeimInitializeDxeIpl (
&gEfiPeiMemoryDiscoveredPpiGuid,
0,
NULL,
(VOID **) &Dummy
(VOID **)&Dummy
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
@@ -124,7 +123,7 @@ PeimInitializeDxeIpl (
// Install DxeIpl PPI.
//
Status = PeiServicesInstallPpi (&mDxeIplPpiList);
ASSERT_EFI_ERROR(Status);
ASSERT_EFI_ERROR (Status);
return Status;
}
@@ -148,10 +147,10 @@ InstallIplPermanentMemoryPpis (
IN VOID *Ppi
)
{
EFI_STATUS Status;
EFI_GUID *ExtractHandlerGuidTable;
UINTN ExtractHandlerNumber;
EFI_PEI_PPI_DESCRIPTOR *GuidPpi;
EFI_STATUS Status;
EFI_GUID *ExtractHandlerGuidTable;
UINTN ExtractHandlerNumber;
EFI_PEI_PPI_DESCRIPTOR *GuidPpi;
//
// Get custom extract guided section method guid list
@@ -162,14 +161,14 @@ InstallIplPermanentMemoryPpis (
// Install custom guided section extraction PPI
//
if (ExtractHandlerNumber > 0) {
GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));
GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *)AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));
ASSERT (GuidPpi != NULL);
while (ExtractHandlerNumber-- > 0) {
GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
GuidPpi->Ppi = (VOID *) &mCustomGuidedSectionExtractionPpi;
GuidPpi->Ppi = (VOID *)&mCustomGuidedSectionExtractionPpi;
GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];
Status = PeiServicesInstallPpi (GuidPpi++);
ASSERT_EFI_ERROR(Status);
Status = PeiServicesInstallPpi (GuidPpi++);
ASSERT_EFI_ERROR (Status);
}
}
@@ -177,7 +176,7 @@ InstallIplPermanentMemoryPpis (
// Install Decompress PPI.
//
Status = PeiServicesInstallPpi (&mDecompressPpiList);
ASSERT_EFI_ERROR(Status);
ASSERT_EFI_ERROR (Status);
return Status;
}
@@ -194,12 +193,12 @@ InstallIplPermanentMemoryPpis (
**/
BOOLEAN
ValidateMemoryTypeInfoVariable (
IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,
IN UINTN MemoryDataSize
IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,
IN UINTN MemoryDataSize
)
{
UINTN Count;
UINTN Index;
UINTN Count;
UINTN Index;
// Check the input parameter.
if (MemoryData == NULL) {
@@ -210,7 +209,7 @@ ValidateMemoryTypeInfoVariable (
Count = MemoryDataSize / sizeof (*MemoryData);
// Check Size
if (Count * sizeof(*MemoryData) != MemoryDataSize) {
if (Count * sizeof (*MemoryData) != MemoryDataSize) {
return FALSE;
}
@@ -246,28 +245,28 @@ ValidateMemoryTypeInfoVariable (
EFI_STATUS
EFIAPI
DxeLoadCore (
IN CONST EFI_DXE_IPL_PPI *This,
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_HOB_POINTERS HobList
IN CONST EFI_DXE_IPL_PPI *This,
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_HOB_POINTERS HobList
)
{
EFI_STATUS Status;
EFI_FV_FILE_INFO DxeCoreFileInfo;
EFI_PHYSICAL_ADDRESS DxeCoreAddress;
UINT64 DxeCoreSize;
EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;
EFI_BOOT_MODE BootMode;
EFI_PEI_FILE_HANDLE FileHandle;
EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;
EFI_PEI_LOAD_FILE_PPI *LoadFile;
UINTN Instance;
UINT32 AuthenticationState;
UINTN DataSize;
EFI_PEI_S3_RESUME2_PPI *S3Resume;
EFI_PEI_RECOVERY_MODULE_PPI *PeiRecovery;
EDKII_PEI_CAPSULE_ON_DISK_PPI *PeiCapsuleOnDisk;
EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1];
VOID *CapsuleOnDiskModePpi;
EFI_STATUS Status;
EFI_FV_FILE_INFO DxeCoreFileInfo;
EFI_PHYSICAL_ADDRESS DxeCoreAddress;
UINT64 DxeCoreSize;
EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;
EFI_BOOT_MODE BootMode;
EFI_PEI_FILE_HANDLE FileHandle;
EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;
EFI_PEI_LOAD_FILE_PPI *LoadFile;
UINTN Instance;
UINT32 AuthenticationState;
UINTN DataSize;
EFI_PEI_S3_RESUME2_PPI *S3Resume;
EFI_PEI_RECOVERY_MODULE_PPI *PeiRecovery;
EDKII_PEI_CAPSULE_ON_DISK_PPI *PeiCapsuleOnDisk;
EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1];
VOID *CapsuleOnDiskModePpi;
//
// if in S3 Resume, restore configure
@@ -279,7 +278,7 @@ DxeLoadCore (
&gEfiPeiS3Resume2PpiGuid,
0,
NULL,
(VOID **) &S3Resume
(VOID **)&S3Resume
);
if (EFI_ERROR (Status)) {
//
@@ -290,6 +289,7 @@ DxeLoadCore (
(EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_RESUME_PPI_NOT_FOUND)
);
}
ASSERT_EFI_ERROR (Status);
Status = S3Resume->S3RestoreConfig2 (S3Resume);
@@ -300,7 +300,7 @@ DxeLoadCore (
&gEfiPeiRecoveryModulePpiGuid,
0,
NULL,
(VOID **) &PeiRecovery
(VOID **)&PeiRecovery
);
if (EFI_ERROR (Status)) {
@@ -328,6 +328,7 @@ DxeLoadCore (
);
CpuDeadLoop ();
}
REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_START));
//
// Now should have a HOB with the DXE core
@@ -343,12 +344,12 @@ DxeLoadCore (
NULL,
&CapsuleOnDiskModePpi
);
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
Status = PeiServicesLocatePpi (
&gEdkiiPeiCapsuleOnDiskPpiGuid,
0,
NULL,
(VOID **) &PeiCapsuleOnDisk
(VOID **)&PeiCapsuleOnDisk
);
//
@@ -372,15 +373,15 @@ DxeLoadCore (
);
if (!EFI_ERROR (Status)) {
DataSize = sizeof (MemoryData);
Status = Variable->GetVariable (
Variable,
EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
&gEfiMemoryTypeInformationGuid,
NULL,
&DataSize,
&MemoryData
);
if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {
Status = Variable->GetVariable (
Variable,
EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
&gEfiMemoryTypeInformationGuid,
NULL,
&DataSize,
&MemoryData
);
if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable (MemoryData, DataSize)) {
//
// Build the GUID'd HOB for DXE
//
@@ -403,7 +404,7 @@ DxeLoadCore (
//
Instance = 0;
do {
Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, Instance++, NULL, (VOID **) &LoadFile);
Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, Instance++, NULL, (VOID **)&LoadFile);
//
// These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.
//
@@ -457,7 +458,6 @@ DxeLoadCore (
return EFI_OUT_OF_RESOURCES;
}
/**
Searches DxeCore in all firmware Volumes and loads the first
instance that contains DxeCore.
@@ -470,12 +470,12 @@ DxeIplFindDxeCore (
VOID
)
{
EFI_STATUS Status;
UINTN Instance;
EFI_PEI_FV_HANDLE VolumeHandle;
EFI_PEI_FILE_HANDLE FileHandle;
EFI_STATUS Status;
UINTN Instance;
EFI_PEI_FV_HANDLE VolumeHandle;
EFI_PEI_FILE_HANDLE FileHandle;
Instance = 0;
Instance = 0;
while (TRUE) {
//
// Traverse all firmware volume instances
@@ -488,13 +488,14 @@ DxeIplFindDxeCore (
if (EFI_ERROR (Status)) {
REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_EC_DXE_CORRUPT));
}
ASSERT_EFI_ERROR (Status);
//
// Find the DxeCore file type from the beginning in this firmware volume.
//
FileHandle = NULL;
Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);
Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);
if (!EFI_ERROR (Status)) {
//
// Find DxeCore FileHandle in this volume, then we skip other firmware volume and
@@ -502,6 +503,7 @@ DxeIplFindDxeCore (
//
return FileHandle;
}
//
// We cannot find DxeCore in this firmware volume, then search the next volume.
//
@@ -509,8 +511,6 @@ DxeIplFindDxeCore (
}
}
/**
The ExtractSection() function processes the input section and
returns a pointer to the section contents. If the section being
@@ -568,18 +568,18 @@ DxeIplFindDxeCore (
EFI_STATUS
EFIAPI
CustomGuidedSectionExtract (
IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
)
IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,
IN CONST VOID *InputSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize,
OUT UINT32 *AuthenticationStatus
)
{
EFI_STATUS Status;
UINT8 *ScratchBuffer;
UINT32 ScratchBufferSize;
UINT32 OutputBufferSize;
UINT16 SectionAttribute;
EFI_STATUS Status;
UINT8 *ScratchBuffer;
UINT32 ScratchBufferSize;
UINT32 OutputBufferSize;
UINT16 SectionAttribute;
//
// Init local variable
@@ -611,7 +611,7 @@ CustomGuidedSectionExtract (
}
}
if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) {
if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && (OutputBufferSize > 0)) {
//
// Allocate output buffer
//
@@ -619,6 +619,7 @@ CustomGuidedSectionExtract (
if (*OutputBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));
}
@@ -636,13 +637,11 @@ CustomGuidedSectionExtract (
return Status;
}
*OutputSize = (UINTN) OutputBufferSize;
*OutputSize = (UINTN)OutputBufferSize;
return EFI_SUCCESS;
}
/**
Decompresses a section to the output buffer.
@@ -666,21 +665,21 @@ CustomGuidedSectionExtract (
EFI_STATUS
EFIAPI
Decompress (
IN CONST EFI_PEI_DECOMPRESS_PPI *This,
IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize
)
IN CONST EFI_PEI_DECOMPRESS_PPI *This,
IN CONST EFI_COMPRESSION_SECTION *CompressionSection,
OUT VOID **OutputBuffer,
OUT UINTN *OutputSize
)
{
EFI_STATUS Status;
UINT8 *DstBuffer;
UINT8 *ScratchBuffer;
UINT32 DstBufferSize;
UINT32 ScratchBufferSize;
VOID *CompressionSource;
UINT32 CompressionSourceSize;
UINT32 UncompressedLength;
UINT8 CompressionType;
EFI_STATUS Status;
UINT8 *DstBuffer;
UINT8 *ScratchBuffer;
UINT32 DstBufferSize;
UINT32 ScratchBufferSize;
VOID *CompressionSource;
UINT32 CompressionSourceSize;
UINT32 UncompressedLength;
UINT8 CompressionType;
if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {
ASSERT (FALSE);
@@ -688,109 +687,113 @@ Decompress (
}
if (IS_SECTION2 (CompressionSection)) {
CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION2));
CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION2));
UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->UncompressedLength;
CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->CompressionType;
CompressionSource = (VOID *)((UINT8 *)CompressionSection + sizeof (EFI_COMPRESSION_SECTION2));
CompressionSourceSize = (UINT32)(SECTION2_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION2));
UncompressedLength = ((EFI_COMPRESSION_SECTION2 *)CompressionSection)->UncompressedLength;
CompressionType = ((EFI_COMPRESSION_SECTION2 *)CompressionSection)->CompressionType;
} else {
CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION));
CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION));
UncompressedLength = CompressionSection->UncompressedLength;
CompressionType = CompressionSection->CompressionType;
CompressionSource = (VOID *)((UINT8 *)CompressionSection + sizeof (EFI_COMPRESSION_SECTION));
CompressionSourceSize = (UINT32)(SECTION_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION));
UncompressedLength = CompressionSection->UncompressedLength;
CompressionType = CompressionSection->CompressionType;
}
//
// This is a compression set, expand it
//
switch (CompressionType) {
case EFI_STANDARD_COMPRESSION:
if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {
//
// Load EFI standard compression.
// For compressed data, decompress them to destination buffer.
//
Status = UefiDecompressGetInfo (
CompressionSource,
CompressionSourceSize,
&DstBufferSize,
&ScratchBufferSize
);
if (EFI_ERROR (Status)) {
case EFI_STANDARD_COMPRESSION:
if (FeaturePcdGet (PcdDxeIplSupportUefiDecompress)) {
//
// GetInfo failed
// Load EFI standard compression.
// For compressed data, decompress them to destination buffer.
//
DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));
Status = UefiDecompressGetInfo (
CompressionSource,
CompressionSourceSize,
&DstBufferSize,
&ScratchBufferSize
);
if (EFI_ERROR (Status)) {
//
// GetInfo failed
//
DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));
return EFI_NOT_FOUND;
}
//
// Allocate scratch buffer
//
ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
if (ScratchBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Allocate destination buffer
//
DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));
if (DstBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Call decompress function
//
Status = UefiDecompress (
CompressionSource,
DstBuffer,
ScratchBuffer
);
if (EFI_ERROR (Status)) {
//
// Decompress failed
//
DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));
return EFI_NOT_FOUND;
}
break;
} else {
//
// PcdDxeIplSupportUefiDecompress is FALSE
// Don't support UEFI decompression algorithm.
//
ASSERT (FALSE);
return EFI_NOT_FOUND;
}
//
// Allocate scratch buffer
//
ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
if (ScratchBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
case EFI_NOT_COMPRESSED:
//
// Allocate destination buffer
//
DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));
DstBufferSize = UncompressedLength;
DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));
if (DstBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Call decompress function
// stream is not actually compressed, just encapsulated. So just copy it.
//
Status = UefiDecompress (
CompressionSource,
DstBuffer,
ScratchBuffer
);
if (EFI_ERROR (Status)) {
//
// Decompress failed
//
DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));
return EFI_NOT_FOUND;
}
CopyMem (DstBuffer, CompressionSource, DstBufferSize);
break;
} else {
default:
//
// PcdDxeIplSupportUefiDecompress is FALSE
// Don't support UEFI decompression algorithm.
// Don't support other unknown compression type.
//
ASSERT (FALSE);
return EFI_NOT_FOUND;
}
case EFI_NOT_COMPRESSED:
//
// Allocate destination buffer
//
DstBufferSize = UncompressedLength;
DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));
if (DstBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// stream is not actually compressed, just encapsulated. So just copy it.
//
CopyMem (DstBuffer, CompressionSource, DstBufferSize);
break;
default:
//
// Don't support other unknown compression type.
//
ASSERT (FALSE);
return EFI_NOT_FOUND;
}
*OutputSize = DstBufferSize;
*OutputSize = DstBufferSize;
*OutputBuffer = DstBuffer;
return EFI_SUCCESS;
}
/**
Updates the Stack HOB passed to DXE phase.
@@ -803,11 +806,11 @@ Decompress (
**/
VOID
UpdateStackHob (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = GetHobList ();
while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
@@ -826,10 +829,10 @@ UpdateStackHob (
// Update the BSP Stack Hob to reflect the new stack info.
//
Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;
Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
break;
}
Hob.Raw = GET_NEXT_HOB (Hob);
}
}

View File

@@ -8,8 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeIpl.h"
/**
Transfers control to DxeCore.
@@ -23,13 +21,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
)
{
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
//
// Allocate 128KB for the Stack
@@ -41,7 +39,7 @@ HandOffToDxeCore (
// Compute the top of the stack we were allocated. Pre-allocate a UINTN
// for safety.
//
TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
//
@@ -53,7 +51,7 @@ HandOffToDxeCore (
//
// Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
//
// Transfer the control to the entry point of DxeCore.

View File

@@ -11,43 +11,61 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeIpl.h"
#include "VirtualMemory.h"
#define IDT_ENTRY_COUNT 32
#define IDT_ENTRY_COUNT 32
typedef struct _X64_IDT_TABLE {
//
// Reserved 4 bytes preceding PeiService and IdtTable,
// since IDT base address should be 8-byte alignment.
//
UINT32 Reserved;
CONST EFI_PEI_SERVICES **PeiService;
X64_IDT_GATE_DESCRIPTOR IdtTable[IDT_ENTRY_COUNT];
UINT32 Reserved;
CONST EFI_PEI_SERVICES **PeiService;
X64_IDT_GATE_DESCRIPTOR IdtTable[IDT_ENTRY_COUNT];
} X64_IDT_TABLE;
//
// Global Descriptor Table (GDT)
//
GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT gGdtEntries[] = {
/* selector { Global Segment Descriptor } */
/* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor
/* 0x08 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor
/* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor
/* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor
/* 0x20 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor
/* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor
/* 0x30 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor
/* 0x38 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor
/* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor
GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT gGdtEntries[] = {
/* selector { Global Segment Descriptor } */
/* 0x00 */ {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
}, // null descriptor
/* 0x08 */ {
{ 0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0 }
}, // linear data segment descriptor
/* 0x10 */ {
{ 0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0 }
}, // linear code segment descriptor
/* 0x18 */ {
{ 0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0 }
}, // system data segment descriptor
/* 0x20 */ {
{ 0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0 }
}, // system code segment descriptor
/* 0x28 */ {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
}, // spare segment descriptor
/* 0x30 */ {
{ 0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0 }
}, // system data segment descriptor
/* 0x38 */ {
{ 0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0 }
}, // system code segment descriptor
/* 0x40 */ {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
}, // spare segment descriptor
};
//
// IA32 Gdt register
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt = {
GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt = {
sizeof (gGdtEntries) - 1,
(UINTN) gGdtEntries
};
(UINTN)gGdtEntries
};
GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = {
GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = {
sizeof (X64_IDT_GATE_DESCRIPTOR) * IDT_ENTRY_COUNT - 1,
0
};
@@ -64,21 +82,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = {
**/
UINTN
Create4GPageTablesIa32Pae (
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize
)
{
UINT8 PhysicalAddressBits;
EFI_PHYSICAL_ADDRESS PhysicalAddress;
UINTN IndexOfPdpEntries;
UINTN IndexOfPageDirectoryEntries;
UINT32 NumberOfPdpEntriesNeeded;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMap;
PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry;
PAGE_TABLE_ENTRY *PageDirectoryEntry;
UINTN TotalPagesNum;
UINTN PageAddress;
UINT64 AddressEncMask;
UINT8 PhysicalAddressBits;
EFI_PHYSICAL_ADDRESS PhysicalAddress;
UINTN IndexOfPdpEntries;
UINTN IndexOfPageDirectoryEntries;
UINT32 NumberOfPdpEntriesNeeded;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMap;
PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry;
PAGE_TABLE_ENTRY *PageDirectoryEntry;
UINTN TotalPagesNum;
UINTN PageAddress;
UINT64 AddressEncMask;
//
// Make sure AddressEncMask is contained to smallest supported address field
@@ -90,53 +108,54 @@ Create4GPageTablesIa32Pae (
//
// Calculate the table entries needed.
//
NumberOfPdpEntriesNeeded = (UINT32) LShiftU64 (1, (PhysicalAddressBits - 30));
NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));
TotalPagesNum = NumberOfPdpEntriesNeeded + 1;
PageAddress = (UINTN) AllocatePageTableMemory (TotalPagesNum);
PageAddress = (UINTN)AllocatePageTableMemory (TotalPagesNum);
ASSERT (PageAddress != 0);
PageMap = (VOID *) PageAddress;
PageMap = (VOID *)PageAddress;
PageAddress += SIZE_4KB;
PageDirectoryPointerEntry = PageMap;
PhysicalAddress = 0;
PhysicalAddress = 0;
for (IndexOfPdpEntries = 0; IndexOfPdpEntries < NumberOfPdpEntriesNeeded; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {
//
// Each Directory Pointer entries points to a page of Page Directory entires.
// So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.
//
PageDirectoryEntry = (VOID *) PageAddress;
PageAddress += SIZE_4KB;
PageDirectoryEntry = (VOID *)PageAddress;
PageAddress += SIZE_4KB;
//
// Fill in a Page Directory Pointer Entries
//
PageDirectoryPointerEntry->Uint64 = (UINT64) (UINTN) PageDirectoryEntry | AddressEncMask;
PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask;
PageDirectoryPointerEntry->Bits.Present = 1;
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress += SIZE_2MB) {
if ((IsNullDetectionEnabled () && PhysicalAddress == 0)
|| ((PhysicalAddress < StackBase + StackSize)
&& ((PhysicalAddress + SIZE_2MB) > StackBase))) {
if ( (IsNullDetectionEnabled () && (PhysicalAddress == 0))
|| ( (PhysicalAddress < StackBase + StackSize)
&& ((PhysicalAddress + SIZE_2MB) > StackBase)))
{
//
// Need to split this 2M page that covers stack range.
//
Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, StackBase, StackSize, 0, 0);
Split2MPageTo4K (PhysicalAddress, (UINT64 *)PageDirectoryEntry, StackBase, StackSize, 0, 0);
} else {
//
// Fill in the Page Directory entries
//
PageDirectoryEntry->Uint64 = (UINT64) PhysicalAddress | AddressEncMask;
PageDirectoryEntry->Uint64 = (UINT64)PhysicalAddress | AddressEncMask;
PageDirectoryEntry->Bits.ReadWrite = 1;
PageDirectoryEntry->Bits.Present = 1;
PageDirectoryEntry->Bits.MustBe1 = 1;
PageDirectoryEntry->Bits.Present = 1;
PageDirectoryEntry->Bits.MustBe1 = 1;
}
}
}
for (; IndexOfPdpEntries < 512; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {
for ( ; IndexOfPdpEntries < 512; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {
ZeroMem (
PageDirectoryPointerEntry,
sizeof (PAGE_MAP_AND_DIRECTORY_POINTER)
@@ -149,7 +168,7 @@ Create4GPageTablesIa32Pae (
//
EnablePageTableProtection ((UINTN)PageMap, FALSE);
return (UINTN) PageMap;
return (UINTN)PageMap;
}
/**
@@ -164,9 +183,9 @@ IsIa32PaeSupport (
VOID
)
{
UINT32 RegEax;
UINT32 RegEdx;
BOOLEAN Ia32PaeSupport;
UINT32 RegEax;
UINT32 RegEdx;
BOOLEAN Ia32PaeSupport;
Ia32PaeSupport = FALSE;
AsmCpuid (0x0, &RegEax, NULL, NULL, NULL);
@@ -228,23 +247,23 @@ ToBuildPageTable (
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS BaseOfStack;
EFI_PHYSICAL_ADDRESS TopOfStack;
UINTN PageTables;
X64_IDT_GATE_DESCRIPTOR *IdtTable;
UINTN SizeOfTemplate;
VOID *TemplateBase;
EFI_PHYSICAL_ADDRESS VectorAddress;
UINT32 Index;
X64_IDT_TABLE *IdtTableForX64;
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;
BOOLEAN BuildPageTablesIa32Pae;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS BaseOfStack;
EFI_PHYSICAL_ADDRESS TopOfStack;
UINTN PageTables;
X64_IDT_GATE_DESCRIPTOR *IdtTable;
UINTN SizeOfTemplate;
VOID *TemplateBase;
EFI_PHYSICAL_ADDRESS VectorAddress;
UINT32 Index;
X64_IDT_TABLE *IdtTableForX64;
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;
BOOLEAN BuildPageTablesIa32Pae;
//
// Clear page 0 and mark it as allocated if NULL pointer detection is enabled.
@@ -257,7 +276,7 @@ HandOffToDxeCore (
Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);
ASSERT_EFI_ERROR (Status);
if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {
if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
//
// Compute the top of the stack we were allocated, which is used to load X64 dxe core.
// Pre-allocate a 32 bytes which confroms to x64 calling convention.
@@ -272,7 +291,7 @@ HandOffToDxeCore (
//
// x64 Calling Conventions requires that the stack must be aligned to 16 bytes
//
TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);
TopOfStack = (EFI_PHYSICAL_ADDRESS)(UINTN)ALIGN_POINTER (TopOfStack, 16);
//
// Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA
@@ -308,7 +327,7 @@ HandOffToDxeCore (
Status = PeiServicesAllocatePages (
EfiBootServicesData,
EFI_SIZE_TO_PAGES(sizeof (X64_IDT_TABLE) + SizeOfTemplate * IDT_ENTRY_COUNT),
EFI_SIZE_TO_PAGES (sizeof (X64_IDT_TABLE) + SizeOfTemplate * IDT_ENTRY_COUNT),
&VectorAddress
);
ASSERT_EFI_ERROR (Status);
@@ -317,28 +336,28 @@ HandOffToDxeCore (
// Store EFI_PEI_SERVICES** in the 4 bytes immediately preceding IDT to avoid that
// it may not be gotten correctly after IDT register is re-written.
//
IdtTableForX64 = (X64_IDT_TABLE *) (UINTN) VectorAddress;
IdtTableForX64 = (X64_IDT_TABLE *)(UINTN)VectorAddress;
IdtTableForX64->PeiService = GetPeiServicesTablePointer ();
VectorAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (IdtTableForX64 + 1);
VectorAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)(IdtTableForX64 + 1);
IdtTable = IdtTableForX64->IdtTable;
for (Index = 0; Index < IDT_ENTRY_COUNT; Index++) {
IdtTable[Index].Ia32IdtEntry.Bits.GateType = 0x8e;
IdtTable[Index].Ia32IdtEntry.Bits.Reserved_0 = 0;
IdtTable[Index].Ia32IdtEntry.Bits.Selector = SYS_CODE64_SEL;
IdtTable[Index].Ia32IdtEntry.Bits.GateType = 0x8e;
IdtTable[Index].Ia32IdtEntry.Bits.Reserved_0 = 0;
IdtTable[Index].Ia32IdtEntry.Bits.Selector = SYS_CODE64_SEL;
IdtTable[Index].Ia32IdtEntry.Bits.OffsetLow = (UINT16) VectorAddress;
IdtTable[Index].Ia32IdtEntry.Bits.OffsetHigh = (UINT16) (RShiftU64 (VectorAddress, 16));
IdtTable[Index].Offset32To63 = (UINT32) (RShiftU64 (VectorAddress, 32));
IdtTable[Index].Reserved = 0;
IdtTable[Index].Ia32IdtEntry.Bits.OffsetLow = (UINT16)VectorAddress;
IdtTable[Index].Ia32IdtEntry.Bits.OffsetHigh = (UINT16)(RShiftU64 (VectorAddress, 16));
IdtTable[Index].Offset32To63 = (UINT32)(RShiftU64 (VectorAddress, 32));
IdtTable[Index].Reserved = 0;
CopyMem ((VOID *) (UINTN) VectorAddress, TemplateBase, SizeOfTemplate);
AsmVectorFixup ((VOID *) (UINTN) VectorAddress, (UINT8) Index);
CopyMem ((VOID *)(UINTN)VectorAddress, TemplateBase, SizeOfTemplate);
AsmVectorFixup ((VOID *)(UINTN)VectorAddress, (UINT8)Index);
VectorAddress += SizeOfTemplate;
}
gLidtDescriptor.Base = (UINTN) IdtTable;
gLidtDescriptor.Base = (UINTN)IdtTable;
//
// Disable interrupt of Debug timer, since new IDT table cannot handle it.
@@ -380,11 +399,12 @@ HandOffToDxeCore (
if (Status == EFI_SUCCESS) {
DEBUG ((DEBUG_INFO, "Vector Hand-off Info PPI is gotten, GUIDed HOB is created!\n"));
VectorInfo = VectorHandoffInfoPpi->Info;
Index = 1;
Index = 1;
while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
VectorInfo ++;
Index ++;
VectorInfo++;
Index++;
}
BuildGuidDataHob (
&gEfiVectorHandoffInfoPpiGuid,
VectorHandoffInfoPpi->Info,
@@ -397,14 +417,14 @@ HandOffToDxeCore (
// for safety.
//
TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;
TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
TopOfStack = (EFI_PHYSICAL_ADDRESS)(UINTN)ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
PageTables = 0;
PageTables = 0;
BuildPageTablesIa32Pae = ToBuildPageTable ();
if (BuildPageTablesIa32Pae) {
PageTables = Create4GPageTablesIa32Pae (BaseOfStack, STACK_SIZE);
if (IsEnableNonExecNeeded ()) {
EnableExecuteDisableBit();
EnableExecuteDisableBit ();
}
}
@@ -450,14 +470,14 @@ HandOffToDxeCore (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
HobList.Raw,
NULL,
(VOID *) (UINTN) TopOfStack
(VOID *)(UINTN)TopOfStack
);
} else {
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
HobList.Raw,
NULL,
(VOID *) (UINTN) TopOfStack
(VOID *)(UINTN)TopOfStack
);
}
}

View File

@@ -22,28 +22,29 @@
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
)
{
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
//
//
// Allocate 128KB for the Stack
//
BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
if (BaseOfStack == NULL) {
DEBUG((DEBUG_ERROR, "%a: Can't allocate memory for stack.", __FUNCTION__));
ASSERT(FALSE);
DEBUG ((DEBUG_ERROR, "%a: Can't allocate memory for stack.", __FUNCTION__));
ASSERT (FALSE);
}
//
// Compute the top of the stack we were allocated. Pre-allocate a UINTN
// for safety.
//
TopOfStack = (VOID *)((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
//
@@ -51,13 +52,14 @@ HandOffToDxeCore (
//
Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "%a: Fail to signal End of PEI event.", __FUNCTION__));
ASSERT(FALSE);
DEBUG ((DEBUG_ERROR, "%a: Fail to signal End of PEI event.", __FUNCTION__));
ASSERT (FALSE);
}
//
// Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
DEBUG ((DEBUG_INFO, "DXE Core new stack at %x, stack pointer at %x\n", BaseOfStack, TopOfStack));
@@ -71,4 +73,3 @@ HandOffToDxeCore (
TopOfStack
);
}

View File

@@ -9,8 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeIpl.h"
#include "X64/VirtualMemory.h"
/**
Transfers control to DxeCore.
@@ -24,19 +22,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
)
{
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
UINTN PageTables;
UINT32 Index;
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;
VOID *GhcbBase;
UINTN GhcbSize;
VOID *BaseOfStack;
VOID *TopOfStack;
EFI_STATUS Status;
UINTN PageTables;
UINT32 Index;
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;
VOID *GhcbBase;
UINTN GhcbSize;
//
// Clear page 0 and mark it as allocated if NULL pointer detection is enabled.
@@ -58,11 +56,12 @@ HandOffToDxeCore (
if (Status == EFI_SUCCESS) {
DEBUG ((DEBUG_INFO, "Vector Hand-off Info PPI is gotten, GUIDed HOB is created!\n"));
VectorInfo = VectorHandoffInfoPpi->Info;
Index = 1;
Index = 1;
while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
VectorInfo ++;
Index ++;
VectorInfo++;
Index++;
}
BuildGuidDataHob (
&gEfiVectorHandoffInfoPpiGuid,
VectorHandoffInfoPpi->Info,
@@ -80,13 +79,13 @@ HandOffToDxeCore (
// Compute the top of the stack we were allocated. Pre-allocate a UINTN
// for safety.
//
TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
//
// Get the address and size of the GHCB pages
//
GhcbBase = (VOID *) PcdGet64 (PcdGhcbBase);
GhcbBase = (VOID *)PcdGet64 (PcdGhcbBase);
GhcbSize = PcdGet64 (PcdGhcbSize);
PageTables = 0;
@@ -94,8 +93,12 @@ HandOffToDxeCore (
//
// Create page table and save PageMapLevel4 to CR3
//
PageTables = CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS) (UINTN) BaseOfStack, STACK_SIZE,
(EFI_PHYSICAL_ADDRESS) (UINTN) GhcbBase, GhcbSize);
PageTables = CreateIdentityMappingPageTables (
(EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack,
STACK_SIZE,
(EFI_PHYSICAL_ADDRESS)(UINTN)GhcbBase,
GhcbSize
);
} else {
//
// Set NX for stack feature also require PcdDxeIplBuildPageTables be TRUE
@@ -118,7 +121,7 @@ HandOffToDxeCore (
//
// Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
//
// Transfer the control to the entry point of DxeCore.

View File

@@ -29,7 +29,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Global variable to keep track current available memory used as page table.
//
PAGE_TABLE_POOL *mPageTablePool = NULL;
PAGE_TABLE_POOL *mPageTablePool = NULL;
/**
Clear legacy memory located at the first 4K-page, if available.
@@ -42,39 +42,50 @@ PAGE_TABLE_POOL *mPageTablePool = NULL;
**/
VOID
ClearFirst4KPage (
IN VOID *HobStart
IN VOID *HobStart
)
{
EFI_PEI_HOB_POINTERS RscHob;
EFI_PEI_HOB_POINTERS MemHob;
BOOLEAN DoClear;
EFI_PEI_HOB_POINTERS RscHob;
EFI_PEI_HOB_POINTERS MemHob;
BOOLEAN DoClear;
RscHob.Raw = HobStart;
MemHob.Raw = HobStart;
DoClear = FALSE;
DoClear = FALSE;
//
// Check if page 0 exists and free
//
while ((RscHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,
RscHob.Raw)) != NULL) {
if (RscHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY &&
RscHob.ResourceDescriptor->PhysicalStart == 0) {
while ((RscHob.Raw = GetNextHob (
EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,
RscHob.Raw
)) != NULL)
{
if ((RscHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&
(RscHob.ResourceDescriptor->PhysicalStart == 0))
{
DoClear = TRUE;
//
// Make sure memory at 0-4095 has not been allocated.
//
while ((MemHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION,
MemHob.Raw)) != NULL) {
while ((MemHob.Raw = GetNextHob (
EFI_HOB_TYPE_MEMORY_ALLOCATION,
MemHob.Raw
)) != NULL)
{
if (MemHob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress
< EFI_PAGE_SIZE) {
< EFI_PAGE_SIZE)
{
DoClear = FALSE;
break;
}
MemHob.Raw = GET_NEXT_HOB (MemHob);
}
break;
}
RscHob.Raw = GET_NEXT_HOB (RscHob);
}
@@ -113,9 +124,9 @@ IsExecuteDisableBitAvailable (
VOID
)
{
UINT32 RegEax;
UINT32 RegEdx;
BOOLEAN Available;
UINT32 RegEax;
UINT32 RegEdx;
BOOLEAN Available;
Available = FALSE;
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
@@ -166,9 +177,9 @@ EnableExecuteDisableBit (
VOID
)
{
UINT64 MsrRegisters;
UINT64 MsrRegisters;
MsrRegisters = AsmReadMsr64 (0xC0000080);
MsrRegisters = AsmReadMsr64 (0xC0000080);
MsrRegisters |= BIT11;
AsmWriteMsr64 (0xC0000080, MsrRegisters);
}
@@ -189,20 +200,20 @@ EnableExecuteDisableBit (
**/
BOOLEAN
ToSplitPageTable (
IN EFI_PHYSICAL_ADDRESS Address,
IN UINTN Size,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
IN EFI_PHYSICAL_ADDRESS Address,
IN UINTN Size,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
)
{
if (IsNullDetectionEnabled () && Address == 0) {
if (IsNullDetectionEnabled () && (Address == 0)) {
return TRUE;
}
if (PcdGetBool (PcdCpuStackGuard)) {
if (StackBase >= Address && StackBase < (Address + Size)) {
if ((StackBase >= Address) && (StackBase < (Address + Size))) {
return TRUE;
}
}
@@ -221,6 +232,7 @@ ToSplitPageTable (
return FALSE;
}
/**
Initialize a buffer pool for page table use only.
@@ -240,18 +252,18 @@ ToSplitPageTable (
**/
BOOLEAN
InitializePageTablePool (
IN UINTN PoolPages
IN UINTN PoolPages
)
{
VOID *Buffer;
VOID *Buffer;
//
// Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for
// header.
//
PoolPages += 1; // Add one page for header.
PoolPages = ((PoolPages - 1) / PAGE_TABLE_POOL_UNIT_PAGES + 1) *
PAGE_TABLE_POOL_UNIT_PAGES;
PoolPages = ((PoolPages - 1) / PAGE_TABLE_POOL_UNIT_PAGES + 1) *
PAGE_TABLE_POOL_UNIT_PAGES;
Buffer = AllocateAlignedPages (PoolPages, PAGE_TABLE_POOL_ALIGNMENT);
if (Buffer == NULL) {
DEBUG ((DEBUG_ERROR, "ERROR: Out of aligned pages\r\n"));
@@ -262,19 +274,19 @@ InitializePageTablePool (
// Link all pools into a list for easier track later.
//
if (mPageTablePool == NULL) {
mPageTablePool = Buffer;
mPageTablePool = Buffer;
mPageTablePool->NextPool = mPageTablePool;
} else {
((PAGE_TABLE_POOL *)Buffer)->NextPool = mPageTablePool->NextPool;
mPageTablePool->NextPool = Buffer;
mPageTablePool = Buffer;
mPageTablePool->NextPool = Buffer;
mPageTablePool = Buffer;
}
//
// Reserve one page for pool header.
//
mPageTablePool->FreePages = PoolPages - 1;
mPageTablePool->Offset = EFI_PAGES_TO_SIZE (1);
mPageTablePool->FreePages = PoolPages - 1;
mPageTablePool->Offset = EFI_PAGES_TO_SIZE (1);
return TRUE;
}
@@ -298,10 +310,10 @@ InitializePageTablePool (
**/
VOID *
AllocatePageTableMemory (
IN UINTN Pages
IN UINTN Pages
)
{
VOID *Buffer;
VOID *Buffer;
if (Pages == 0) {
return NULL;
@@ -310,8 +322,9 @@ AllocatePageTableMemory (
//
// Renew the pool if necessary.
//
if (mPageTablePool == NULL ||
Pages > mPageTablePool->FreePages) {
if ((mPageTablePool == NULL) ||
(Pages > mPageTablePool->FreePages))
{
if (!InitializePageTablePool (Pages)) {
return NULL;
}
@@ -319,8 +332,8 @@ AllocatePageTableMemory (
Buffer = (UINT8 *)mPageTablePool + mPageTablePool->Offset;
mPageTablePool->Offset += EFI_PAGES_TO_SIZE (Pages);
mPageTablePool->FreePages -= Pages;
mPageTablePool->Offset += EFI_PAGES_TO_SIZE (Pages);
mPageTablePool->FreePages -= Pages;
return Buffer;
}
@@ -338,18 +351,18 @@ AllocatePageTableMemory (
**/
VOID
Split2MPageTo4K (
IN EFI_PHYSICAL_ADDRESS PhysicalAddress,
IN OUT UINT64 *PageEntry2M,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
IN EFI_PHYSICAL_ADDRESS PhysicalAddress,
IN OUT UINT64 *PageEntry2M,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
)
{
EFI_PHYSICAL_ADDRESS PhysicalAddress4K;
UINTN IndexOfPageTableEntries;
PAGE_TABLE_4K_ENTRY *PageTableEntry;
UINT64 AddressEncMask;
EFI_PHYSICAL_ADDRESS PhysicalAddress4K;
UINTN IndexOfPageTableEntries;
PAGE_TABLE_4K_ENTRY *PageTableEntry;
UINT64 AddressEncMask;
//
// Make sure AddressEncMask is contained to smallest supported address field
@@ -362,14 +375,14 @@ Split2MPageTo4K (
//
// Fill in 2M page entry.
//
*PageEntry2M = (UINT64) (UINTN) PageTableEntry | AddressEncMask | IA32_PG_P | IA32_PG_RW;
*PageEntry2M = (UINT64)(UINTN)PageTableEntry | AddressEncMask | IA32_PG_P | IA32_PG_RW;
PhysicalAddress4K = PhysicalAddress;
for (IndexOfPageTableEntries = 0; IndexOfPageTableEntries < 512; IndexOfPageTableEntries++, PageTableEntry++, PhysicalAddress4K += SIZE_4KB) {
//
// Fill in the Page Table entries
//
PageTableEntry->Uint64 = (UINT64) PhysicalAddress4K;
PageTableEntry->Uint64 = (UINT64)PhysicalAddress4K;
//
// The GHCB range consists of two pages per CPU, the GHCB and a
@@ -377,24 +390,28 @@ Split2MPageTo4K (
// unencrypted page while the per-CPU variable page needs to be
// mapped encrypted. These pages alternate in assignment.
//
if ((GhcbBase == 0)
|| (PhysicalAddress4K < GhcbBase)
|| (PhysicalAddress4K >= GhcbBase + GhcbSize)
|| (((PhysicalAddress4K - GhcbBase) & SIZE_4KB) != 0)) {
if ( (GhcbBase == 0)
|| (PhysicalAddress4K < GhcbBase)
|| (PhysicalAddress4K >= GhcbBase + GhcbSize)
|| (((PhysicalAddress4K - GhcbBase) & SIZE_4KB) != 0))
{
PageTableEntry->Uint64 |= AddressEncMask;
}
PageTableEntry->Bits.ReadWrite = 1;
if ((IsNullDetectionEnabled () && PhysicalAddress4K == 0) ||
(PcdGetBool (PcdCpuStackGuard) && PhysicalAddress4K == StackBase)) {
if ((IsNullDetectionEnabled () && (PhysicalAddress4K == 0)) ||
(PcdGetBool (PcdCpuStackGuard) && (PhysicalAddress4K == StackBase)))
{
PageTableEntry->Bits.Present = 0;
} else {
PageTableEntry->Bits.Present = 1;
}
if (PcdGetBool (PcdSetNxForStack)
&& (PhysicalAddress4K >= StackBase)
&& (PhysicalAddress4K < StackBase + StackSize)) {
if ( PcdGetBool (PcdSetNxForStack)
&& (PhysicalAddress4K >= StackBase)
&& (PhysicalAddress4K < StackBase + StackSize))
{
//
// Set Nx bit for stack.
//
@@ -416,18 +433,18 @@ Split2MPageTo4K (
**/
VOID
Split1GPageTo2M (
IN EFI_PHYSICAL_ADDRESS PhysicalAddress,
IN OUT UINT64 *PageEntry1G,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
IN EFI_PHYSICAL_ADDRESS PhysicalAddress,
IN OUT UINT64 *PageEntry1G,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
)
{
EFI_PHYSICAL_ADDRESS PhysicalAddress2M;
UINTN IndexOfPageDirectoryEntries;
PAGE_TABLE_ENTRY *PageDirectoryEntry;
UINT64 AddressEncMask;
EFI_PHYSICAL_ADDRESS PhysicalAddress2M;
UINTN IndexOfPageDirectoryEntries;
PAGE_TABLE_ENTRY *PageDirectoryEntry;
UINT64 AddressEncMask;
//
// Make sure AddressEncMask is contained to smallest supported address field
@@ -440,7 +457,7 @@ Split1GPageTo2M (
//
// Fill in 1G page entry.
//
*PageEntry1G = (UINT64) (UINTN) PageDirectoryEntry | AddressEncMask | IA32_PG_P | IA32_PG_RW;
*PageEntry1G = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask | IA32_PG_P | IA32_PG_RW;
PhysicalAddress2M = PhysicalAddress;
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += SIZE_2MB) {
@@ -448,15 +465,15 @@ Split1GPageTo2M (
//
// Need to split this 2M page that covers NULL or stack range.
//
Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, StackBase, StackSize, GhcbBase, GhcbSize);
Split2MPageTo4K (PhysicalAddress2M, (UINT64 *)PageDirectoryEntry, StackBase, StackSize, GhcbBase, GhcbSize);
} else {
//
// Fill in the Page Directory entries
//
PageDirectoryEntry->Uint64 = (UINT64) PhysicalAddress2M | AddressEncMask;
PageDirectoryEntry->Uint64 = (UINT64)PhysicalAddress2M | AddressEncMask;
PageDirectoryEntry->Bits.ReadWrite = 1;
PageDirectoryEntry->Bits.Present = 1;
PageDirectoryEntry->Bits.MustBe1 = 1;
PageDirectoryEntry->Bits.Present = 1;
PageDirectoryEntry->Bits.MustBe1 = 1;
}
}
}
@@ -471,9 +488,9 @@ Split1GPageTo2M (
**/
VOID
SetPageTablePoolReadOnly (
IN UINTN PageTableBase,
IN EFI_PHYSICAL_ADDRESS Address,
IN BOOLEAN Level4Paging
IN UINTN PageTableBase,
IN EFI_PHYSICAL_ADDRESS Address,
IN BOOLEAN Level4Paging
)
{
UINTN Index;
@@ -513,13 +530,13 @@ SetPageTablePoolReadOnly (
LevelSize[3] = SIZE_1GB;
LevelSize[4] = SIZE_512GB;
AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) &
PAGING_1G_ADDRESS_MASK_64;
PageTable = (UINT64 *)(UINTN)PageTableBase;
PoolUnitSize = PAGE_TABLE_POOL_UNIT_SIZE;
AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) &
PAGING_1G_ADDRESS_MASK_64;
PageTable = (UINT64 *)(UINTN)PageTableBase;
PoolUnitSize = PAGE_TABLE_POOL_UNIT_SIZE;
for (Level = (Level4Paging) ? 4 : 3; Level > 0; --Level) {
Index = ((UINTN)RShiftU64 (Address, LevelShift[Level]));
Index = ((UINTN)RShiftU64 (Address, LevelShift[Level]));
Index &= PAGING_PAE_INDEX_MASK;
PageAttr = PageTable[Index];
@@ -547,14 +564,13 @@ SetPageTablePoolReadOnly (
ASSERT (Index < EFI_PAGE_SIZE/sizeof (UINT64));
PageTable[Index] &= ~(UINT64)IA32_PG_RW;
PoolUnitSize -= LevelSize[Level];
PoolUnitSize -= LevelSize[Level];
++Index;
}
}
break;
} else {
//
// The smaller granularity of page must be needed.
@@ -566,18 +582,20 @@ SetPageTablePoolReadOnly (
PhysicalAddress = PageAttr & LevelMask[Level];
for (EntryIndex = 0;
EntryIndex < EFI_PAGE_SIZE/sizeof (UINT64);
++EntryIndex) {
EntryIndex < EFI_PAGE_SIZE/sizeof (UINT64);
++EntryIndex)
{
NewPageTable[EntryIndex] = PhysicalAddress | AddressEncMask |
IA32_PG_P | IA32_PG_RW;
if (Level > 2) {
NewPageTable[EntryIndex] |= IA32_PG_PS;
}
PhysicalAddress += LevelSize[Level - 1];
}
PageTable[Index] = (UINT64)(UINTN)NewPageTable | AddressEncMask |
IA32_PG_P | IA32_PG_RW;
IA32_PG_P | IA32_PG_RW;
PageTable = NewPageTable;
}
}
@@ -592,14 +610,14 @@ SetPageTablePoolReadOnly (
**/
VOID
EnablePageTableProtection (
IN UINTN PageTableBase,
IN BOOLEAN Level4Paging
IN UINTN PageTableBase,
IN BOOLEAN Level4Paging
)
{
PAGE_TABLE_POOL *HeadPool;
PAGE_TABLE_POOL *Pool;
UINT64 PoolSize;
EFI_PHYSICAL_ADDRESS Address;
PAGE_TABLE_POOL *HeadPool;
PAGE_TABLE_POOL *Pool;
UINT64 PoolSize;
EFI_PHYSICAL_ADDRESS Address;
if (mPageTablePool == NULL) {
return;
@@ -609,14 +627,14 @@ EnablePageTableProtection (
// Disable write protection, because we need to mark page table to be write
// protected.
//
AsmWriteCr0 (AsmReadCr0() & ~CR0_WP);
AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP);
//
// SetPageTablePoolReadOnly might update mPageTablePool. It's safer to
// remember original one in advance.
//
HeadPool = mPageTablePool;
Pool = HeadPool;
Pool = HeadPool;
do {
Address = (EFI_PHYSICAL_ADDRESS)(UINTN)Pool;
PoolSize = Pool->Offset + EFI_PAGES_TO_SIZE (Pool->FreePages);
@@ -627,9 +645,9 @@ EnablePageTableProtection (
// protection to them one by one.
//
while (PoolSize > 0) {
SetPageTablePoolReadOnly(PageTableBase, Address, Level4Paging);
Address += PAGE_TABLE_POOL_UNIT_SIZE;
PoolSize -= PAGE_TABLE_POOL_UNIT_SIZE;
SetPageTablePoolReadOnly (PageTableBase, Address, Level4Paging);
Address += PAGE_TABLE_POOL_UNIT_SIZE;
PoolSize -= PAGE_TABLE_POOL_UNIT_SIZE;
}
Pool = Pool->NextPool;
@@ -638,7 +656,7 @@ EnablePageTableProtection (
//
// Enable write protection, after page table attribute updated.
//
AsmWriteCr0 (AsmReadCr0() | CR0_WP);
AsmWriteCr0 (AsmReadCr0 () | CR0_WP);
}
/**
@@ -655,37 +673,37 @@ EnablePageTableProtection (
**/
UINTN
CreateIdentityMappingPageTables (
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
)
{
UINT32 RegEax;
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_ECX EcxFlags;
UINT32 RegEdx;
UINT8 PhysicalAddressBits;
EFI_PHYSICAL_ADDRESS PageAddress;
UINTN IndexOfPml5Entries;
UINTN IndexOfPml4Entries;
UINTN IndexOfPdpEntries;
UINTN IndexOfPageDirectoryEntries;
UINT32 NumberOfPml5EntriesNeeded;
UINT32 NumberOfPml4EntriesNeeded;
UINT32 NumberOfPdpEntriesNeeded;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel5Entry;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMap;
PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry;
PAGE_TABLE_ENTRY *PageDirectoryEntry;
UINTN TotalPagesNum;
UINTN BigPageAddress;
VOID *Hob;
BOOLEAN Page5LevelSupport;
BOOLEAN Page1GSupport;
PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry;
UINT64 AddressEncMask;
IA32_CR4 Cr4;
UINT32 RegEax;
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_ECX EcxFlags;
UINT32 RegEdx;
UINT8 PhysicalAddressBits;
EFI_PHYSICAL_ADDRESS PageAddress;
UINTN IndexOfPml5Entries;
UINTN IndexOfPml4Entries;
UINTN IndexOfPdpEntries;
UINTN IndexOfPageDirectoryEntries;
UINT32 NumberOfPml5EntriesNeeded;
UINT32 NumberOfPml4EntriesNeeded;
UINT32 NumberOfPdpEntriesNeeded;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel5Entry;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry;
PAGE_MAP_AND_DIRECTORY_POINTER *PageMap;
PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry;
PAGE_TABLE_ENTRY *PageDirectoryEntry;
UINTN TotalPagesNum;
UINTN BigPageAddress;
VOID *Hob;
BOOLEAN Page5LevelSupport;
BOOLEAN Page1GSupport;
PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry;
UINT64 AddressEncMask;
IA32_CR4 Cr4;
//
// Set PageMapLevel5Entry to suppress incorrect compiler/analyzer warnings
@@ -698,7 +716,7 @@ CreateIdentityMappingPageTables (
AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64;
Page1GSupport = FALSE;
if (PcdGetBool(PcdUse1GPageTable)) {
if (PcdGetBool (PcdUse1GPageTable)) {
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
if (RegEax >= 0x80000001) {
AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);
@@ -713,12 +731,12 @@ CreateIdentityMappingPageTables (
//
Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
if (Hob != NULL) {
PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;
} else {
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
if (RegEax >= 0x80000008) {
AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
PhysicalAddressBits = (UINT8) RegEax;
PhysicalAddressBits = (UINT8)RegEax;
} else {
PhysicalAddressBits = 36;
}
@@ -727,8 +745,12 @@ CreateIdentityMappingPageTables (
Page5LevelSupport = FALSE;
if (PcdGetBool (PcdUse5LevelPageTable)) {
AsmCpuidEx (
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS, CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_SUB_LEAF_INFO, NULL,
&EcxFlags.Uint32, NULL, NULL
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS,
CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_SUB_LEAF_INFO,
NULL,
&EcxFlags.Uint32,
NULL,
NULL
);
if (EcxFlags.Bits.FiveLevelPage != 0) {
Page5LevelSupport = TRUE;
@@ -743,7 +765,7 @@ CreateIdentityMappingPageTables (
// due to either unsupported by HW, or disabled by PCD.
//
ASSERT (PhysicalAddressBits <= 52);
if (!Page5LevelSupport && PhysicalAddressBits > 48) {
if (!Page5LevelSupport && (PhysicalAddressBits > 48)) {
PhysicalAddressBits = 48;
}
@@ -752,19 +774,19 @@ CreateIdentityMappingPageTables (
//
NumberOfPml5EntriesNeeded = 1;
if (PhysicalAddressBits > 48) {
NumberOfPml5EntriesNeeded = (UINT32) LShiftU64 (1, PhysicalAddressBits - 48);
PhysicalAddressBits = 48;
NumberOfPml5EntriesNeeded = (UINT32)LShiftU64 (1, PhysicalAddressBits - 48);
PhysicalAddressBits = 48;
}
NumberOfPml4EntriesNeeded = 1;
if (PhysicalAddressBits > 39) {
NumberOfPml4EntriesNeeded = (UINT32) LShiftU64 (1, PhysicalAddressBits - 39);
PhysicalAddressBits = 39;
NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, PhysicalAddressBits - 39);
PhysicalAddressBits = 39;
}
NumberOfPdpEntriesNeeded = 1;
ASSERT (PhysicalAddressBits > 30);
NumberOfPdpEntriesNeeded = (UINT32) LShiftU64 (1, PhysicalAddressBits - 30);
NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, PhysicalAddressBits - 30);
//
// Pre-allocate big pages to avoid later allocations.
@@ -782,17 +804,22 @@ CreateIdentityMappingPageTables (
TotalPagesNum--;
}
DEBUG ((DEBUG_INFO, "Pml5=%u Pml4=%u Pdp=%u TotalPage=%Lu\n",
NumberOfPml5EntriesNeeded, NumberOfPml4EntriesNeeded,
NumberOfPdpEntriesNeeded, (UINT64)TotalPagesNum));
DEBUG ((
DEBUG_INFO,
"Pml5=%u Pml4=%u Pdp=%u TotalPage=%Lu\n",
NumberOfPml5EntriesNeeded,
NumberOfPml4EntriesNeeded,
NumberOfPdpEntriesNeeded,
(UINT64)TotalPagesNum
));
BigPageAddress = (UINTN) AllocatePageTableMemory (TotalPagesNum);
BigPageAddress = (UINTN)AllocatePageTableMemory (TotalPagesNum);
ASSERT (BigPageAddress != 0);
//
// By architecture only one PageMapLevel4 exists - so lets allocate storage for it.
//
PageMap = (VOID *) BigPageAddress;
PageMap = (VOID *)BigPageAddress;
if (Page5LevelSupport) {
//
// By architecture only one PageMapLevel5 exists - so lets allocate storage for it.
@@ -800,94 +827,98 @@ CreateIdentityMappingPageTables (
PageMapLevel5Entry = PageMap;
BigPageAddress += SIZE_4KB;
}
PageAddress = 0;
PageAddress = 0;
for ( IndexOfPml5Entries = 0
; IndexOfPml5Entries < NumberOfPml5EntriesNeeded
; IndexOfPml5Entries++) {
; IndexOfPml5Entries < NumberOfPml5EntriesNeeded
; IndexOfPml5Entries++)
{
//
// Each PML5 entry points to a page of PML4 entires.
// So lets allocate space for them and fill them in in the IndexOfPml4Entries loop.
// When 5-Level Paging is disabled, below allocation happens only once.
//
PageMapLevel4Entry = (VOID *) BigPageAddress;
PageMapLevel4Entry = (VOID *)BigPageAddress;
BigPageAddress += SIZE_4KB;
if (Page5LevelSupport) {
//
// Make a PML5 Entry
//
PageMapLevel5Entry->Uint64 = (UINT64) (UINTN) PageMapLevel4Entry | AddressEncMask;
PageMapLevel5Entry->Uint64 = (UINT64)(UINTN)PageMapLevel4Entry | AddressEncMask;
PageMapLevel5Entry->Bits.ReadWrite = 1;
PageMapLevel5Entry->Bits.Present = 1;
PageMapLevel5Entry++;
}
for ( IndexOfPml4Entries = 0
; IndexOfPml4Entries < (NumberOfPml5EntriesNeeded == 1 ? NumberOfPml4EntriesNeeded : 512)
; IndexOfPml4Entries++, PageMapLevel4Entry++) {
; IndexOfPml4Entries < (NumberOfPml5EntriesNeeded == 1 ? NumberOfPml4EntriesNeeded : 512)
; IndexOfPml4Entries++, PageMapLevel4Entry++)
{
//
// Each PML4 entry points to a page of Page Directory Pointer entires.
// So lets allocate space for them and fill them in in the IndexOfPdpEntries loop.
//
PageDirectoryPointerEntry = (VOID *) BigPageAddress;
BigPageAddress += SIZE_4KB;
PageDirectoryPointerEntry = (VOID *)BigPageAddress;
BigPageAddress += SIZE_4KB;
//
// Make a PML4 Entry
//
PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry | AddressEncMask;
PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry | AddressEncMask;
PageMapLevel4Entry->Bits.ReadWrite = 1;
PageMapLevel4Entry->Bits.Present = 1;
PageMapLevel4Entry->Bits.Present = 1;
if (Page1GSupport) {
PageDirectory1GEntry = (VOID *) PageDirectoryPointerEntry;
PageDirectory1GEntry = (VOID *)PageDirectoryPointerEntry;
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress += SIZE_1GB) {
if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSize, GhcbBase, GhcbSize)) {
Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry, StackBase, StackSize, GhcbBase, GhcbSize);
Split1GPageTo2M (PageAddress, (UINT64 *)PageDirectory1GEntry, StackBase, StackSize, GhcbBase, GhcbSize);
} else {
//
// Fill in the Page Directory entries
//
PageDirectory1GEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;
PageDirectory1GEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;
PageDirectory1GEntry->Bits.ReadWrite = 1;
PageDirectory1GEntry->Bits.Present = 1;
PageDirectory1GEntry->Bits.MustBe1 = 1;
PageDirectory1GEntry->Bits.Present = 1;
PageDirectory1GEntry->Bits.MustBe1 = 1;
}
}
} else {
for ( IndexOfPdpEntries = 0
; IndexOfPdpEntries < (NumberOfPml4EntriesNeeded == 1 ? NumberOfPdpEntriesNeeded : 512)
; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {
; IndexOfPdpEntries < (NumberOfPml4EntriesNeeded == 1 ? NumberOfPdpEntriesNeeded : 512)
; IndexOfPdpEntries++, PageDirectoryPointerEntry++)
{
//
// Each Directory Pointer entries points to a page of Page Directory entires.
// So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.
//
PageDirectoryEntry = (VOID *) BigPageAddress;
BigPageAddress += SIZE_4KB;
PageDirectoryEntry = (VOID *)BigPageAddress;
BigPageAddress += SIZE_4KB;
//
// Fill in a Page Directory Pointer Entries
//
PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask;
PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask;
PageDirectoryPointerEntry->Bits.ReadWrite = 1;
PageDirectoryPointerEntry->Bits.Present = 1;
PageDirectoryPointerEntry->Bits.Present = 1;
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += SIZE_2MB) {
if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackSize, GhcbBase, GhcbSize)) {
//
// Need to split this 2M page that covers NULL or stack range.
//
Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry, StackBase, StackSize, GhcbBase, GhcbSize);
Split2MPageTo4K (PageAddress, (UINT64 *)PageDirectoryEntry, StackBase, StackSize, GhcbBase, GhcbSize);
} else {
//
// Fill in the Page Directory entries
//
PageDirectoryEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;
PageDirectoryEntry->Uint64 = (UINT64)PageAddress | AddressEncMask;
PageDirectoryEntry->Bits.ReadWrite = 1;
PageDirectoryEntry->Bits.Present = 1;
PageDirectoryEntry->Bits.MustBe1 = 1;
PageDirectoryEntry->Bits.Present = 1;
PageDirectoryEntry->Bits.MustBe1 = 1;
}
}
}
@@ -895,7 +926,7 @@ CreateIdentityMappingPageTables (
//
// Fill with null entry for unused PDPTE
//
ZeroMem (PageDirectoryPointerEntry, (512 - IndexOfPdpEntries) * sizeof(PAGE_MAP_AND_DIRECTORY_POINTER));
ZeroMem (PageDirectoryPointerEntry, (512 - IndexOfPdpEntries) * sizeof (PAGE_MAP_AND_DIRECTORY_POINTER));
}
}
@@ -906,7 +937,7 @@ CreateIdentityMappingPageTables (
}
if (Page5LevelSupport) {
Cr4.UintN = AsmReadCr4 ();
Cr4.UintN = AsmReadCr4 ();
Cr4.Bits.LA57 = 1;
AsmWriteCr4 (Cr4.UintN);
//
@@ -930,4 +961,3 @@ CreateIdentityMappingPageTables (
return (UINTN)PageMap;
}

View File

@@ -13,38 +13,37 @@ Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _VIRTUAL_MEMORY_H_
#define _VIRTUAL_MEMORY_H_
#define SYS_CODE64_SEL 0x38
#define SYS_CODE64_SEL 0x38
#pragma pack(1)
typedef union {
struct {
UINT32 LimitLow : 16;
UINT32 BaseLow : 16;
UINT32 BaseMid : 8;
UINT32 Type : 4;
UINT32 System : 1;
UINT32 Dpl : 2;
UINT32 Present : 1;
UINT32 LimitHigh : 4;
UINT32 Software : 1;
UINT32 Reserved : 1;
UINT32 DefaultSize : 1;
UINT32 Granularity : 1;
UINT32 BaseHigh : 8;
UINT32 LimitLow : 16;
UINT32 BaseLow : 16;
UINT32 BaseMid : 8;
UINT32 Type : 4;
UINT32 System : 1;
UINT32 Dpl : 2;
UINT32 Present : 1;
UINT32 LimitHigh : 4;
UINT32 Software : 1;
UINT32 Reserved : 1;
UINT32 DefaultSize : 1;
UINT32 Granularity : 1;
UINT32 BaseHigh : 8;
} Bits;
UINT64 Uint64;
UINT64 Uint64;
} IA32_GDT;
typedef struct {
IA32_IDT_GATE_DESCRIPTOR Ia32IdtEntry;
UINT32 Offset32To63;
UINT32 Reserved;
IA32_IDT_GATE_DESCRIPTOR Ia32IdtEntry;
UINT32 Offset32To63;
UINT32 Reserved;
} X64_IDT_GATE_DESCRIPTOR;
//
@@ -54,18 +53,18 @@ typedef struct {
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Reserved:1; // Reserved
UINT64 MustBeZero:2; // Must Be Zero
UINT64 Available:3; // Available for use by system software
UINT64 PageTableBaseAddress:40; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // No Execute bit
UINT64 Present : 1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite : 1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor : 1; // 0 = Supervisor, 1=User
UINT64 WriteThrough : 1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled : 1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed : 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Reserved : 1; // Reserved
UINT64 MustBeZero : 2; // Must Be Zero
UINT64 Available : 3; // Available for use by system software
UINT64 PageTableBaseAddress : 40; // Page Table Base Address
UINT64 AvabilableHigh : 11; // Available for use by system software
UINT64 Nx : 1; // No Execute bit
} Bits;
UINT64 Uint64;
} PAGE_MAP_AND_DIRECTORY_POINTER;
@@ -75,19 +74,19 @@ typedef union {
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 PAT:1; //
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available:3; // Available for use by system software
UINT64 PageTableBaseAddress:40; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
UINT64 Present : 1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite : 1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor : 1; // 0 = Supervisor, 1=User
UINT64 WriteThrough : 1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled : 1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed : 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty : 1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 PAT : 1; //
UINT64 Global : 1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available : 3; // Available for use by system software
UINT64 PageTableBaseAddress : 40; // Page Table Base Address
UINT64 AvabilableHigh : 11; // Available for use by system software
UINT64 Nx : 1; // 0 = Execute Code, 1 = No Code Execution
} Bits;
UINT64 Uint64;
} PAGE_TABLE_4K_ENTRY;
@@ -97,21 +96,21 @@ typedef union {
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 MustBe1:1; // Must be 1
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available:3; // Available for use by system software
UINT64 PAT:1; //
UINT64 MustBeZero:8; // Must be zero;
UINT64 PageTableBaseAddress:31; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
UINT64 Present : 1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite : 1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor : 1; // 0 = Supervisor, 1=User
UINT64 WriteThrough : 1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled : 1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed : 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty : 1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 MustBe1 : 1; // Must be 1
UINT64 Global : 1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available : 3; // Available for use by system software
UINT64 PAT : 1; //
UINT64 MustBeZero : 8; // Must be zero;
UINT64 PageTableBaseAddress : 31; // Page Table Base Address
UINT64 AvabilableHigh : 11; // Available for use by system software
UINT64 Nx : 1; // 0 = Execute Code, 1 = No Code Execution
} Bits;
UINT64 Uint64;
} PAGE_TABLE_ENTRY;
@@ -121,45 +120,45 @@ typedef union {
//
typedef union {
struct {
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 MustBe1:1; // Must be 1
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available:3; // Available for use by system software
UINT64 PAT:1; //
UINT64 MustBeZero:17; // Must be zero;
UINT64 PageTableBaseAddress:22; // Page Table Base Address
UINT64 AvabilableHigh:11; // Available for use by system software
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
UINT64 Present : 1; // 0 = Not present in memory, 1 = Present in memory
UINT64 ReadWrite : 1; // 0 = Read-Only, 1= Read/Write
UINT64 UserSupervisor : 1; // 0 = Supervisor, 1=User
UINT64 WriteThrough : 1; // 0 = Write-Back caching, 1=Write-Through caching
UINT64 CacheDisabled : 1; // 0 = Cached, 1=Non-Cached
UINT64 Accessed : 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
UINT64 Dirty : 1; // 0 = Not Dirty, 1 = written by processor on access to page
UINT64 MustBe1 : 1; // Must be 1
UINT64 Global : 1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
UINT64 Available : 3; // Available for use by system software
UINT64 PAT : 1; //
UINT64 MustBeZero : 17; // Must be zero;
UINT64 PageTableBaseAddress : 22; // Page Table Base Address
UINT64 AvabilableHigh : 11; // Available for use by system software
UINT64 Nx : 1; // 0 = Execute Code, 1 = No Code Execution
} Bits;
UINT64 Uint64;
} PAGE_TABLE_1G_ENTRY;
#pragma pack()
#define CR0_WP BIT16
#define CR0_WP BIT16
#define IA32_PG_P BIT0
#define IA32_PG_RW BIT1
#define IA32_PG_PS BIT7
#define IA32_PG_P BIT0
#define IA32_PG_RW BIT1
#define IA32_PG_PS BIT7
#define PAGING_PAE_INDEX_MASK 0x1FF
#define PAGING_PAE_INDEX_MASK 0x1FF
#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
#define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull
#define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull
#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull
#define PAGING_L1_ADDRESS_SHIFT 12
#define PAGING_L2_ADDRESS_SHIFT 21
#define PAGING_L3_ADDRESS_SHIFT 30
#define PAGING_L4_ADDRESS_SHIFT 39
#define PAGING_L1_ADDRESS_SHIFT 12
#define PAGING_L2_ADDRESS_SHIFT 21
#define PAGING_L3_ADDRESS_SHIFT 30
#define PAGING_L4_ADDRESS_SHIFT 39
#define PAGING_PML4E_NUMBER 4
#define PAGING_PML4E_NUMBER 4
#define PAGE_TABLE_POOL_ALIGNMENT BASE_2MB
#define PAGE_TABLE_POOL_UNIT_SIZE SIZE_2MB
@@ -168,9 +167,9 @@ typedef union {
(~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))
typedef struct {
VOID *NextPool;
UINTN Offset;
UINTN FreePages;
VOID *NextPool;
UINTN Offset;
UINTN FreePages;
} PAGE_TABLE_POOL;
/**
@@ -207,12 +206,12 @@ EnableExecuteDisableBit (
**/
VOID
Split2MPageTo4K (
IN EFI_PHYSICAL_ADDRESS PhysicalAddress,
IN OUT UINT64 *PageEntry2M,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
IN EFI_PHYSICAL_ADDRESS PhysicalAddress,
IN OUT UINT64 *PageEntry2M,
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbSize
);
/**
@@ -229,13 +228,12 @@ Split2MPageTo4K (
**/
UINTN
CreateIdentityMappingPageTables (
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbkSize
IN EFI_PHYSICAL_ADDRESS StackBase,
IN UINTN StackSize,
IN EFI_PHYSICAL_ADDRESS GhcbBase,
IN UINTN GhcbkSize
);
/**
Fix up the vector number in the vector code.
@@ -247,11 +245,10 @@ CreateIdentityMappingPageTables (
VOID
EFIAPI
AsmVectorFixup (
VOID *VectorBase,
UINT8 VectorNum
VOID *VectorBase,
UINT8 VectorNum
);
/**
Get the information of vector template.
@@ -278,7 +275,7 @@ AsmGetVectorTemplatInfo (
**/
VOID
ClearFirst4KPage (
IN VOID *HobStart
IN VOID *HobStart
);
/**
@@ -301,8 +298,8 @@ IsNullDetectionEnabled (
**/
VOID
EnablePageTableProtection (
IN UINTN PageTableBase,
IN BOOLEAN Level4Paging
IN UINTN PageTableBase,
IN BOOLEAN Level4Paging
);
/**
@@ -324,7 +321,7 @@ EnablePageTableProtection (
**/
VOID *
AllocatePageTableMemory (
IN UINTN Pages
IN UINTN Pages
);
#endif

View File

@@ -29,25 +29,22 @@ PeiGetBootMode (
IN OUT EFI_BOOT_MODE *BootMode
)
{
PEI_CORE_INSTANCE *PrivateData;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
PEI_CORE_INSTANCE *PrivateData;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
if (BootMode == NULL) {
return EFI_INVALID_PARAMETER;
}
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
HandOffHob = (PrivateData->HobList.HandoffInformationTable);
*BootMode = HandOffHob->BootMode;
HandOffHob = (PrivateData->HobList.HandoffInformationTable);
*BootMode = HandOffHob->BootMode;
return EFI_SUCCESS;
}
/**
This service enables PEIMs to update the boot mode variable.
@@ -65,16 +62,14 @@ PeiSetBootMode (
IN EFI_BOOT_MODE BootMode
)
{
PEI_CORE_INSTANCE *PrivateData;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
PEI_CORE_INSTANCE *PrivateData;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
HandOffHob = (PrivateData->HobList.HandoffInformationTable);
HandOffHob = (PrivateData->HobList.HandoffInformationTable);
HandOffHob->BootMode = BootMode;
return EFI_SUCCESS;
}

View File

@@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// This default instance of EFI_PEI_CPU_IO_PPI install assigned to EFI_PEI_SERVICE.CpuIo
/// when PeiCore's initialization.
///
EFI_PEI_CPU_IO_PPI gPeiDefaultCpuIoPpi = {
EFI_PEI_CPU_IO_PPI gPeiDefaultCpuIoPpi = {
{
PeiDefaultMemRead,
PeiDefaultMemWrite
@@ -66,12 +66,12 @@ EFI_PEI_CPU_IO_PPI gPeiDefaultCpuIoPpi = {
EFI_STATUS
EFIAPI
PeiDefaultMemRead (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
{
return EFI_NOT_AVAILABLE_YET;
@@ -99,12 +99,12 @@ PeiDefaultMemRead (
EFI_STATUS
EFIAPI
PeiDefaultMemWrite (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
{
return EFI_NOT_AVAILABLE_YET;
@@ -131,12 +131,12 @@ PeiDefaultMemWrite (
EFI_STATUS
EFIAPI
PeiDefaultIoRead (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
{
return EFI_NOT_AVAILABLE_YET;
@@ -163,12 +163,12 @@ PeiDefaultIoRead (
EFI_STATUS
EFIAPI
PeiDefaultIoWrite (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
{
return EFI_NOT_AVAILABLE_YET;
@@ -189,9 +189,9 @@ PeiDefaultIoWrite (
UINT8
EFIAPI
PeiDefaultIoRead8 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -212,9 +212,9 @@ PeiDefaultIoRead8 (
UINT16
EFIAPI
PeiDefaultIoRead16 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -235,9 +235,9 @@ PeiDefaultIoRead16 (
UINT32
EFIAPI
PeiDefaultIoRead32 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -258,9 +258,9 @@ PeiDefaultIoRead32 (
UINT64
EFIAPI
PeiDefaultIoRead64 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -279,10 +279,10 @@ PeiDefaultIoRead64 (
VOID
EFIAPI
PeiDefaultIoWrite8 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT8 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT8 Data
)
{
}
@@ -300,10 +300,10 @@ PeiDefaultIoWrite8 (
VOID
EFIAPI
PeiDefaultIoWrite16 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT16 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT16 Data
)
{
}
@@ -321,10 +321,10 @@ PeiDefaultIoWrite16 (
VOID
EFIAPI
PeiDefaultIoWrite32 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT32 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT32 Data
)
{
}
@@ -342,10 +342,10 @@ PeiDefaultIoWrite32 (
VOID
EFIAPI
PeiDefaultIoWrite64 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT64 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT64 Data
)
{
}
@@ -366,9 +366,9 @@ PeiDefaultIoWrite64 (
UINT8
EFIAPI
PeiDefaultMemRead8 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -390,9 +390,9 @@ PeiDefaultMemRead8 (
UINT16
EFIAPI
PeiDefaultMemRead16 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -414,9 +414,9 @@ PeiDefaultMemRead16 (
UINT32
EFIAPI
PeiDefaultMemRead32 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -438,9 +438,9 @@ PeiDefaultMemRead32 (
UINT64
EFIAPI
PeiDefaultMemRead64 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address
)
{
return 0;
@@ -460,10 +460,10 @@ PeiDefaultMemRead64 (
VOID
EFIAPI
PeiDefaultMemWrite8 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT8 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT8 Data
)
{
}
@@ -482,10 +482,10 @@ PeiDefaultMemWrite8 (
VOID
EFIAPI
PeiDefaultMemWrite16 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT16 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT16 Data
)
{
}
@@ -504,10 +504,10 @@ PeiDefaultMemWrite16 (
VOID
EFIAPI
PeiDefaultMemWrite32 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT32 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT32 Data
)
{
}
@@ -526,10 +526,10 @@ PeiDefaultMemWrite32 (
VOID
EFIAPI
PeiDefaultMemWrite64 (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT64 Data
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_CPU_IO_PPI *This,
IN UINT64 Address,
IN UINT64 Data
)
{
}

View File

@@ -49,19 +49,19 @@ IsPpiInstalled (
// possibilities of alignment faults for cross-compilation
// environments such as Intel?Itanium(TM).
//
CopyMem(&PpiGuid, Stack->Operator, sizeof(EFI_GUID));
CopyMem (&PpiGuid, Stack->Operator, sizeof (EFI_GUID));
//
// Check if the PPI is installed.
//
Status = PeiServicesLocatePpi(
Status = PeiServicesLocatePpi (
&PpiGuid, // GUID
0, // INSTANCE
NULL, // EFI_PEI_PPI_DESCRIPTOR
&PeiInstance // PPI
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
return FALSE;
}
@@ -90,22 +90,20 @@ IsPpiInstalled (
**/
BOOLEAN
PeimDispatchReadiness (
IN EFI_PEI_SERVICES **PeiServices,
IN VOID *DependencyExpression
IN EFI_PEI_SERVICES **PeiServices,
IN VOID *DependencyExpression
)
{
DEPENDENCY_EXPRESSION_OPERAND *Iterator;
EVAL_STACK_ENTRY *StackPtr;
EVAL_STACK_ENTRY EvalStack[MAX_GRAMMAR_SIZE];
Iterator = DependencyExpression;
Iterator = DependencyExpression;
StackPtr = EvalStack;
while (TRUE) {
switch (*(Iterator++)) {
//
// For performance reason we put the frequently used items in front of
// the rarely used items
@@ -125,8 +123,8 @@ PeimDispatchReadiness (
// Push the pointer to the PUSH opcode operator (pointer to PPI GUID)
// We will evaluate if the PPI is installed on the POP operation.
//
StackPtr->Operator = (VOID *) Iterator;
Iterator = Iterator + sizeof (EFI_GUID);
StackPtr->Operator = (VOID *)Iterator;
Iterator = Iterator + sizeof (EFI_GUID);
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = %a\n", StackPtr->Operator, IsPpiInstalled (PeiServices, StackPtr) ? "TRUE" : "FALSE"));
StackPtr++;
break;
@@ -138,6 +136,7 @@ PeimDispatchReadiness (
} else {
DEBUG ((DEBUG_DISPATCH, " OR\n"));
}
//
// Check to make sure the dependency grammar doesn't underflow the
// EvalStack on the two POPs for the AND operation. Don't need to
@@ -166,15 +165,16 @@ PeimDispatchReadiness (
//
if (*(Iterator - 1) == EFI_DEP_AND) {
if (!(IsPpiInstalled (PeiServices, StackPtr))) {
(StackPtr-1)->Result = FALSE;
(StackPtr-1)->Result = FALSE;
(StackPtr-1)->Operator = NULL;
}
} else {
if (IsPpiInstalled (PeiServices, StackPtr)) {
(StackPtr-1)->Result = TRUE;
(StackPtr-1)->Result = TRUE;
(StackPtr-1)->Operator = NULL;
}
}
break;
case (EFI_DEP_END):
@@ -188,6 +188,7 @@ PeimDispatchReadiness (
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Underflow Error)\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", IsPpiInstalled (PeiServices, StackPtr) ? "TRUE" : "FALSE"));
return IsPpiInstalled (PeiServices, StackPtr);
@@ -203,7 +204,8 @@ PeimDispatchReadiness (
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Underflow Error)\n"));
return FALSE;
}
(StackPtr-1)->Result = (BOOLEAN) !IsPpiInstalled (PeiServices, (StackPtr-1));
(StackPtr-1)->Result = (BOOLEAN) !IsPpiInstalled (PeiServices, (StackPtr-1));
(StackPtr-1)->Operator = NULL;
break;
@@ -214,6 +216,7 @@ PeimDispatchReadiness (
} else {
DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
}
//
// Check to make sure the dependency grammar doesn't overflow the
// EvalStack on the push
@@ -222,6 +225,7 @@ PeimDispatchReadiness (
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Underflow Error)\n"));
return FALSE;
}
//
// Iterator has increased by 1 after we retrieve the operand, so here we
// should get the value pointed by (Iterator - 1), in order to obtain the
@@ -232,6 +236,7 @@ PeimDispatchReadiness (
} else {
StackPtr->Result = FALSE;
}
StackPtr->Operator = NULL;
StackPtr++;
break;

View File

@@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _PEI_DEPENDENCY_H_
#define _PEI_DEPENDENCY_H_
#define MAX_GRAMMAR_SIZE 64
//
@@ -19,8 +18,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
typedef UINT8 DEPENDENCY_EXPRESSION_OPERAND;
typedef struct {
BOOLEAN Result;
VOID *Operator;
BOOLEAN Result;
VOID *Operator;
} EVAL_STACK_ENTRY;
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -14,19 +14,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
#define PEI_FW_VOL_SIGNATURE SIGNATURE_32('P','F','W','V')
typedef struct {
UINTN Signature;
BOOLEAN IsFfs3Fv;
EFI_PEI_FIRMWARE_VOLUME_PPI Fv;
UINTN Signature;
BOOLEAN IsFfs3Fv;
EFI_PEI_FIRMWARE_VOLUME_PPI Fv;
} PEI_FW_VOL_INSTANCE;
#define PEI_FW_VOL_INSTANCE_FROM_FV_THIS(a) \
CR(a, PEI_FW_VOL_INSTANCE, Fv, PEI_FW_VOL_SIGNATURE)
/**
Process a firmware volume and create a volume handle.
@@ -54,10 +52,10 @@ typedef struct {
EFI_STATUS
EFIAPI
PeiFfsFvPpiProcessVolume (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN VOID *Buffer,
IN UINTN BufferSize,
OUT EFI_PEI_FV_HANDLE *FvHandle
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN VOID *Buffer,
IN UINTN BufferSize,
OUT EFI_PEI_FV_HANDLE *FvHandle
);
/**
@@ -85,10 +83,10 @@ PeiFfsFvPpiProcessVolume (
EFI_STATUS
EFIAPI
PeiFfsFvPpiFindFileByType (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_FV_FILETYPE SearchType,
IN EFI_PEI_FV_HANDLE FvHandle,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_FV_FILETYPE SearchType,
IN EFI_PEI_FV_HANDLE FvHandle,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle
);
/**
@@ -119,10 +117,10 @@ PeiFfsFvPpiFindFileByType (
EFI_STATUS
EFIAPI
PeiFfsFvPpiFindFileByName (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN CONST EFI_GUID *FileName,
IN EFI_PEI_FV_HANDLE *FvHandle,
OUT EFI_PEI_FILE_HANDLE *FileHandle
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN CONST EFI_GUID *FileName,
IN EFI_PEI_FV_HANDLE *FvHandle,
OUT EFI_PEI_FILE_HANDLE *FileHandle
);
/**
@@ -147,10 +145,10 @@ PeiFfsFvPpiFindFileByName (
EFI_STATUS
EFIAPI
PeiFfsFvPpiFindSectionByType (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_SECTION_TYPE SearchType,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT VOID **SectionData
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_SECTION_TYPE SearchType,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT VOID **SectionData
);
/**
@@ -179,12 +177,12 @@ PeiFfsFvPpiFindSectionByType (
EFI_STATUS
EFIAPI
PeiFfsFvPpiFindSectionByType2 (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_SECTION_TYPE SearchType,
IN UINTN SearchInstance,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT VOID **SectionData,
OUT UINT32 *AuthenticationStatus
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_SECTION_TYPE SearchType,
IN UINTN SearchInstance,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT VOID **SectionData,
OUT UINT32 *AuthenticationStatus
);
/**
@@ -209,9 +207,9 @@ PeiFfsFvPpiFindSectionByType2 (
EFI_STATUS
EFIAPI
PeiFfsFvPpiGetFileInfo (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_FV_FILE_INFO *FileInfo
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_FV_FILE_INFO *FileInfo
);
/**
@@ -236,9 +234,9 @@ PeiFfsFvPpiGetFileInfo (
EFI_STATUS
EFIAPI
PeiFfsFvPpiGetFileInfo2 (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_FV_FILE_INFO2 *FileInfo
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_FV_FILE_INFO2 *FileInfo
);
/**
@@ -258,9 +256,9 @@ PeiFfsFvPpiGetFileInfo2 (
EFI_STATUS
EFIAPI
PeiFfsFvPpiGetVolumeInfo (
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_PEI_FV_HANDLE FvHandle,
OUT EFI_FV_INFO *VolumeInfo
IN CONST EFI_PEI_FIRMWARE_VOLUME_PPI *This,
IN EFI_PEI_FV_HANDLE FvHandle,
OUT EFI_FV_INFO *VolumeInfo
);
/**
@@ -295,11 +293,11 @@ FvHandleToCoreHandle (
**/
EFI_STATUS
FindFileEx (
IN CONST EFI_PEI_FV_HANDLE FvHandle,
IN CONST EFI_GUID *FileName OPTIONAL,
IN EFI_FV_FILETYPE SearchType,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
IN OUT EFI_PEI_FILE_HANDLE *AprioriFile OPTIONAL
IN CONST EFI_PEI_FV_HANDLE FvHandle,
IN CONST EFI_GUID *FileName OPTIONAL,
IN EFI_FV_FILETYPE SearchType,
IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
IN OUT EFI_PEI_FILE_HANDLE *AprioriFile OPTIONAL
);
/**
@@ -342,11 +340,11 @@ AddUnknownFormatFvInfo (
**/
EFI_STATUS
FindUnknownFormatFvInfo (
IN PEI_CORE_INSTANCE *PrivateData,
IN EFI_GUID *Format,
OUT VOID **FvInfo,
OUT UINT32 *FvInfoSize,
OUT UINT32 *AuthenticationStatus
IN PEI_CORE_INSTANCE *PrivateData,
IN EFI_GUID *Format,
OUT VOID **FvInfo,
OUT UINT32 *FvInfoSize,
OUT UINT32 *AuthenticationStatus
);
/**
@@ -364,9 +362,9 @@ FindUnknownFormatFvInfo (
EFI_STATUS
EFIAPI
ThirdPartyFvPpiNotifyCallback (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
);
#endif

View File

@@ -24,29 +24,29 @@ EFI_STATUS
EFIAPI
PeiGetHobList (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN OUT VOID **HobList
IN OUT VOID **HobList
)
{
PEI_CORE_INSTANCE *PrivateData;
PEI_CORE_INSTANCE *PrivateData;
//
// Only check this parameter in debug mode
//
DEBUG_CODE_BEGIN ();
if (HobList == NULL) {
return EFI_INVALID_PARAMETER;
}
if (HobList == NULL) {
return EFI_INVALID_PARAMETER;
}
DEBUG_CODE_END ();
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
*HobList = PrivateData->HobList.Raw;
*HobList = PrivateData->HobList.Raw;
return EFI_SUCCESS;
}
/**
Add a new HOB to the HOB List.
@@ -65,19 +65,18 @@ EFI_STATUS
EFIAPI
PeiCreateHob (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN UINT16 Type,
IN UINT16 Length,
IN OUT VOID **Hob
IN UINT16 Type,
IN UINT16 Length,
IN OUT VOID **Hob
)
{
EFI_STATUS Status;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
EFI_HOB_GENERIC_HEADER *HobEnd;
EFI_PHYSICAL_ADDRESS FreeMemory;
EFI_STATUS Status;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
EFI_HOB_GENERIC_HEADER *HobEnd;
EFI_PHYSICAL_ADDRESS FreeMemory;
Status = PeiGetHobList (PeiServices, Hob);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
return Status;
}
@@ -89,7 +88,8 @@ PeiCreateHob (
if (0x10000 - Length <= 0x7) {
return EFI_INVALID_PARAMETER;
}
Length = (UINT16)((Length + 0x7) & (~0x7));
Length = (UINT16)((Length + 0x7) & (~0x7));
FreeMemory = HandOffHob->EfiFreeMemoryTop -
HandOffHob->EfiFreeMemoryBottom;
@@ -101,19 +101,19 @@ PeiCreateHob (
return EFI_OUT_OF_RESOURCES;
}
*Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
((EFI_HOB_GENERIC_HEADER*) *Hob)->HobType = Type;
((EFI_HOB_GENERIC_HEADER*) *Hob)->HobLength = Length;
((EFI_HOB_GENERIC_HEADER*) *Hob)->Reserved = 0;
*Hob = (VOID *)(UINTN)HandOffHob->EfiEndOfHobList;
((EFI_HOB_GENERIC_HEADER *)*Hob)->HobType = Type;
((EFI_HOB_GENERIC_HEADER *)*Hob)->HobLength = Length;
((EFI_HOB_GENERIC_HEADER *)*Hob)->Reserved = 0;
HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);
HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)*Hob + Length);
HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->Reserved = 0;
HobEnd++;
HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
return EFI_SUCCESS;
}
@@ -130,26 +130,27 @@ PeiCreateHob (
**/
EFI_STATUS
PeiInstallSecHobData (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_HOB_GENERIC_HEADER *SecHobList
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_HOB_GENERIC_HEADER *SecHobList
)
{
EFI_STATUS Status;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
EFI_PEI_HOB_POINTERS HobStart;
EFI_PEI_HOB_POINTERS Hob;
UINTN SecHobListLength;
EFI_PHYSICAL_ADDRESS FreeMemory;
EFI_HOB_GENERIC_HEADER *HobEnd;
EFI_STATUS Status;
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
EFI_PEI_HOB_POINTERS HobStart;
EFI_PEI_HOB_POINTERS Hob;
UINTN SecHobListLength;
EFI_PHYSICAL_ADDRESS FreeMemory;
EFI_HOB_GENERIC_HEADER *HobEnd;
HandOffHob = NULL;
Status = PeiGetHobList (PeiServices, (VOID **) &HandOffHob);
if (EFI_ERROR(Status)) {
Status = PeiGetHobList (PeiServices, (VOID **)&HandOffHob);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (HandOffHob != NULL);
HobStart.Raw = (UINT8 *) SecHobList;
HobStart.Raw = (UINT8 *)SecHobList;
//
// The HobList must not contain a EFI_HOB_HANDOFF_INFO_TABLE HOB (PHIT) HOB.
//
@@ -158,8 +159,10 @@ PeiInstallSecHobData (
// Calculate the SEC HOB List length,
// not including the terminated HOB(EFI_HOB_TYPE_END_OF_HOB_LIST).
//
for (Hob.Raw = HobStart.Raw; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob));
SecHobListLength = (UINTN) Hob.Raw - (UINTN) HobStart.Raw;
for (Hob.Raw = HobStart.Raw; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
}
SecHobListLength = (UINTN)Hob.Raw - (UINTN)HobStart.Raw;
//
// The length must be 8-bytes aligned.
//
@@ -175,17 +178,17 @@ PeiInstallSecHobData (
return EFI_OUT_OF_RESOURCES;
}
Hob.Raw = (UINT8 *) (UINTN) HandOffHob->EfiEndOfHobList;
Hob.Raw = (UINT8 *)(UINTN)HandOffHob->EfiEndOfHobList;
CopyMem (Hob.Raw, HobStart.Raw, SecHobListLength);
HobEnd = (EFI_HOB_GENERIC_HEADER *) ((UINTN) Hob.Raw + SecHobListLength);
HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)Hob.Raw + SecHobListLength);
HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->Reserved = 0;
HobEnd++;
HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
return EFI_SUCCESS;
}
@@ -208,27 +211,27 @@ PeiCoreBuildHobHandoffInfoTable (
IN UINT64 MemoryLength
)
{
EFI_HOB_HANDOFF_INFO_TABLE *Hob;
EFI_HOB_GENERIC_HEADER *HobEnd;
EFI_HOB_HANDOFF_INFO_TABLE *Hob;
EFI_HOB_GENERIC_HEADER *HobEnd;
Hob = (VOID *)(UINTN)MemoryBegin;
HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);
Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
Hob->Header.HobLength = (UINT16) sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
Hob->Header.Reserved = 0;
Hob = (VOID *)(UINTN)MemoryBegin;
HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
Hob->Header.HobLength = (UINT16)sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
Hob->Header.Reserved = 0;
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
HobEnd->HobLength = (UINT16) sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->Reserved = 0;
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->Reserved = 0;
Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
Hob->BootMode = BootMode;
Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
Hob->BootMode = BootMode;
Hob->EfiMemoryTop = MemoryBegin + MemoryLength;
Hob->EfiMemoryBottom = MemoryBegin;
Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;
Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd + 1);
Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)(HobEnd + 1);
Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
return EFI_SUCCESS;
}

View File

@@ -8,13 +8,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PeiMain.h"
EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi = {
EFI_PEI_LOAD_FILE_PPI mPeiLoadImagePpi = {
PeiLoadImageLoadImageWrapper
};
EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList = {
EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiLoadFilePpiGuid,
&mPeiLoadImagePpi
@@ -36,17 +34,17 @@ EFI_PEI_PPI_DESCRIPTOR gPpiLoadFilePpiList = {
EFI_STATUS
EFIAPI
PeiImageRead (
IN VOID *FileHandle,
IN UINTN FileOffset,
IN UINTN *ReadSize,
OUT VOID *Buffer
IN VOID *FileHandle,
IN UINTN FileOffset,
IN UINTN *ReadSize,
OUT VOID *Buffer
)
{
CHAR8 *Destination8;
CHAR8 *Source8;
CHAR8 *Destination8;
CHAR8 *Source8;
Destination8 = Buffer;
Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
Destination8 = Buffer;
Source8 = (CHAR8 *)((UINTN)FileHandle + FileOffset);
if (Destination8 != Source8) {
CopyMem (Destination8, Source8, *ReadSize);
}
@@ -68,59 +66,61 @@ PeiImageRead (
**/
EFI_STATUS
CheckAndMarkFixLoadingMemoryUsageBitMap (
IN PEI_CORE_INSTANCE *Private,
IN EFI_PHYSICAL_ADDRESS ImageBase,
IN UINT32 ImageSize
IN PEI_CORE_INSTANCE *Private,
IN EFI_PHYSICAL_ADDRESS ImageBase,
IN UINT32 ImageSize
)
{
UINT32 DxeCodePageNumber;
UINT64 ReservedCodeSize;
EFI_PHYSICAL_ADDRESS PeiCodeBase;
UINT32 BaseOffsetPageNumber;
UINT32 TopOffsetPageNumber;
UINT32 Index;
UINT64 *MemoryUsageBitMap;
UINT32 DxeCodePageNumber;
UINT64 ReservedCodeSize;
EFI_PHYSICAL_ADDRESS PeiCodeBase;
UINT32 BaseOffsetPageNumber;
UINT32 TopOffsetPageNumber;
UINT32 Index;
UINT64 *MemoryUsageBitMap;
//
// The reserved code range includes RuntimeCodePage range, Boot time code range and PEI code range.
//
DxeCodePageNumber = PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
DxeCodePageNumber += PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
ReservedCodeSize = EFI_PAGES_TO_SIZE (DxeCodePageNumber + PcdGet32 (PcdLoadFixAddressPeiCodePageNumber));
PeiCodeBase = Private->LoadModuleAtFixAddressTopAddress - ReservedCodeSize;
//
// The reserved code range includes RuntimeCodePage range, Boot time code range and PEI code range.
//
DxeCodePageNumber = PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
DxeCodePageNumber += PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
ReservedCodeSize = EFI_PAGES_TO_SIZE(DxeCodePageNumber + PcdGet32(PcdLoadFixAddressPeiCodePageNumber));
PeiCodeBase = Private->LoadModuleAtFixAddressTopAddress - ReservedCodeSize;
//
// Test the memory range for loading the image in the PEI code range.
//
if (((Private->LoadModuleAtFixAddressTopAddress - EFI_PAGES_TO_SIZE (DxeCodePageNumber)) < (ImageBase + ImageSize)) ||
(PeiCodeBase > ImageBase))
{
return EFI_NOT_FOUND;
}
//
// Test the memory range for loading the image in the PEI code range.
//
if ((Private->LoadModuleAtFixAddressTopAddress - EFI_PAGES_TO_SIZE(DxeCodePageNumber)) < (ImageBase + ImageSize) ||
(PeiCodeBase > ImageBase)) {
return EFI_NOT_FOUND;
}
//
// Test if the memory is available or not.
//
MemoryUsageBitMap = Private->PeiCodeMemoryRangeUsageBitMap;
BaseOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - PeiCodeBase));
TopOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + ImageSize - PeiCodeBase));
for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
if ((MemoryUsageBitMap[Index / 64] & LShiftU64 (1, (Index % 64))) != 0) {
//
// This page is already used.
//
return EFI_NOT_FOUND;
}
}
//
// Test if the memory is available or not.
//
MemoryUsageBitMap = Private->PeiCodeMemoryRangeUsageBitMap;
BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - PeiCodeBase));
TopOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - PeiCodeBase));
for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
if ((MemoryUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
//
// This page is already used.
//
return EFI_NOT_FOUND;
}
}
//
// Being here means the memory range is available. So mark the bits for the memory range
//
for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
MemoryUsageBitMap[Index / 64] |= LShiftU64 (1, (Index % 64));
}
//
// Being here means the memory range is available. So mark the bits for the memory range
//
for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
MemoryUsageBitMap[Index / 64] |= LShiftU64(1, (Index % 64));
}
return EFI_SUCCESS;
return EFI_SUCCESS;
}
/**
Get the fixed loading address from image header assigned by build tool. This function only be called
@@ -135,109 +135,114 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
**/
EFI_STATUS
GetPeCoffImageFixLoadingAssignedAddress(
GetPeCoffImageFixLoadingAssignedAddress (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
IN PEI_CORE_INSTANCE *Private
)
{
UINTN SectionHeaderOffset;
EFI_STATUS Status;
EFI_IMAGE_SECTION_HEADER SectionHeader;
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
EFI_PHYSICAL_ADDRESS FixLoadingAddress;
UINT16 Index;
UINTN Size;
UINT16 NumberOfSections;
UINT64 ValueInSectionHeader;
UINTN SectionHeaderOffset;
EFI_STATUS Status;
EFI_IMAGE_SECTION_HEADER SectionHeader;
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
EFI_PHYSICAL_ADDRESS FixLoadingAddress;
UINT16 Index;
UINTN Size;
UINT16 NumberOfSections;
UINT64 ValueInSectionHeader;
FixLoadingAddress = 0;
Status = EFI_NOT_FOUND;
FixLoadingAddress = 0;
Status = EFI_NOT_FOUND;
//
// Get PeHeader pointer
//
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
if (ImageContext->IsTeImage) {
//
// for TE image, the fix loading address is saved in first section header that doesn't point
// to code section.
//
SectionHeaderOffset = sizeof (EFI_TE_IMAGE_HEADER);
NumberOfSections = ImgHdr->Te.NumberOfSections;
} else {
SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
}
//
// Get PeHeader pointer
//
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
if (ImageContext->IsTeImage) {
//
// for TE image, the fix loading address is saved in first section header that doesn't point
// to code section.
//
SectionHeaderOffset = sizeof (EFI_TE_IMAGE_HEADER);
NumberOfSections = ImgHdr->Te.NumberOfSections;
} else {
SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
}
//
// Get base address from the first section header that doesn't point to code section.
//
for (Index = 0; Index < NumberOfSections; Index++) {
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
Status = ImageContext->ImageRead (
ImageContext->Handle,
SectionHeaderOffset,
&Size,
&SectionHeader
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get base address from the first section header that doesn't point to code section.
//
for (Index = 0; Index < NumberOfSections; Index++) {
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
Status = ImageContext->ImageRead (
ImageContext->Handle,
SectionHeaderOffset,
&Size,
&SectionHeader
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = EFI_NOT_FOUND;
Status = EFI_NOT_FOUND;
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
//
// Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
// that doesn't point to code section in image header, as well as ImageBase field of image header. A notable thing is
// that for PEIM, the value in ImageBase field may not be equal to the value in PointerToRelocations & PointerToLineNumbers because
// for XIP PEIM, ImageBase field holds the image base address running on the Flash. And PointerToRelocations & PointerToLineNumbers
// hold the image base address when it is shadow to the memory. And there is an assumption that when the feature is enabled, if a
// module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers fields should NOT be Zero, or
// else, these 2 fields should be set to Zero
//
ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
if (ValueInSectionHeader != 0) {
//
// Found first section header that doesn't point to code section.
//
if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) > 0) {
//
// When LMFA feature is configured as Load Module at Fixed Absolute Address mode, PointerToRelocations & PointerToLineNumbers field
// hold the absolute address of image base running in memory
//
FixLoadingAddress = ValueInSectionHeader;
} else {
//
// When LMFA feature is configured as Load Module at Fixed offset mode, PointerToRelocations & PointerToLineNumbers field
// hold the offset relative to a platform-specific top address.
//
FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(Private->LoadModuleAtFixAddressTopAddress + (INT64)ValueInSectionHeader);
}
//
// Check if the memory range is available.
//
Status = CheckAndMarkFixLoadingMemoryUsageBitMap (Private, FixLoadingAddress, (UINT32) ImageContext->ImageSize);
if (!EFI_ERROR(Status)) {
//
// The assigned address is valid. Return the specified loading address
//
ImageContext->ImageAddress = FixLoadingAddress;
}
}
break;
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status= %r \n", (VOID *)(UINTN)FixLoadingAddress, Status));
return Status;
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
//
// Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
// that doesn't point to code section in image header, as well as ImageBase field of image header. A notable thing is
// that for PEIM, the value in ImageBase field may not be equal to the value in PointerToRelocations & PointerToLineNumbers because
// for XIP PEIM, ImageBase field holds the image base address running on the Flash. And PointerToRelocations & PointerToLineNumbers
// hold the image base address when it is shadow to the memory. And there is an assumption that when the feature is enabled, if a
// module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers fields should NOT be Zero, or
// else, these 2 fields should be set to Zero
//
ValueInSectionHeader = ReadUnaligned64 ((UINT64 *)&SectionHeader.PointerToRelocations);
if (ValueInSectionHeader != 0) {
//
// Found first section header that doesn't point to code section.
//
if ((INT64)PcdGet64 (PcdLoadModuleAtFixAddressEnable) > 0) {
//
// When LMFA feature is configured as Load Module at Fixed Absolute Address mode, PointerToRelocations & PointerToLineNumbers field
// hold the absolute address of image base running in memory
//
FixLoadingAddress = ValueInSectionHeader;
} else {
//
// When LMFA feature is configured as Load Module at Fixed offset mode, PointerToRelocations & PointerToLineNumbers field
// hold the offset relative to a platform-specific top address.
//
FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(Private->LoadModuleAtFixAddressTopAddress + (INT64)ValueInSectionHeader);
}
//
// Check if the memory range is available.
//
Status = CheckAndMarkFixLoadingMemoryUsageBitMap (Private, FixLoadingAddress, (UINT32)ImageContext->ImageSize);
if (!EFI_ERROR (Status)) {
//
// The assigned address is valid. Return the specified loading address
//
ImageContext->ImageAddress = FixLoadingAddress;
}
}
break;
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status= %r \n", (VOID *)(UINTN)FixLoadingAddress, Status));
return Status;
}
/**
Loads and relocates a PE/COFF image into memory.
@@ -258,30 +263,30 @@ GetPeCoffImageFixLoadingAssignedAddress(
**/
EFI_STATUS
LoadAndRelocatePeCoffImage (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN VOID *Pe32Data,
OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
OUT UINT64 *ImageSize,
OUT EFI_PHYSICAL_ADDRESS *EntryPoint
IN EFI_PEI_FILE_HANDLE FileHandle,
IN VOID *Pe32Data,
OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
OUT UINT64 *ImageSize,
OUT EFI_PHYSICAL_ADDRESS *EntryPoint
)
{
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
PEI_CORE_INSTANCE *Private;
UINT64 AlignImageSize;
BOOLEAN IsXipImage;
EFI_STATUS ReturnStatus;
BOOLEAN IsS3Boot;
BOOLEAN IsPeiModule;
BOOLEAN IsRegisterForShadow;
EFI_FV_FILE_INFO FileInfo;
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
PEI_CORE_INSTANCE *Private;
UINT64 AlignImageSize;
BOOLEAN IsXipImage;
EFI_STATUS ReturnStatus;
BOOLEAN IsS3Boot;
BOOLEAN IsPeiModule;
BOOLEAN IsRegisterForShadow;
EFI_FV_FILE_INFO FileInfo;
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
ReturnStatus = EFI_SUCCESS;
IsXipImage = FALSE;
ZeroMem (&ImageContext, sizeof (ImageContext));
ImageContext.Handle = Pe32Data;
ImageContext.Handle = Pe32Data;
ImageContext.ImageRead = PeiImageRead;
Status = PeCoffLoaderGetImageInfo (&ImageContext);
@@ -296,16 +301,18 @@ LoadAndRelocatePeCoffImage (
if (Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) {
IsS3Boot = TRUE;
}
IsRegisterForShadow = FALSE;
if ((Private->CurrentFileHandle == FileHandle)
&& (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISTER_FOR_SHADOW)) {
if ( (Private->CurrentFileHandle == FileHandle)
&& (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISTER_FOR_SHADOW))
{
IsRegisterForShadow = TRUE;
}
//
// XIP image that ImageAddress is same to Image handle.
//
if (ImageContext.ImageAddress == (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data) {
if (ImageContext.ImageAddress == (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data) {
IsXipImage = TRUE;
}
@@ -319,9 +326,10 @@ LoadAndRelocatePeCoffImage (
// Check whether the file type is PEI module.
//
IsPeiModule = FALSE;
if (FileInfo.FileType == EFI_FV_FILETYPE_PEI_CORE ||
FileInfo.FileType == EFI_FV_FILETYPE_PEIM ||
FileInfo.FileType == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER) {
if ((FileInfo.FileType == EFI_FV_FILETYPE_PEI_CORE) ||
(FileInfo.FileType == EFI_FV_FILETYPE_PEIM) ||
(FileInfo.FileType == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER))
{
IsPeiModule = TRUE;
}
@@ -332,14 +340,15 @@ LoadAndRelocatePeCoffImage (
((!IsPeiModule) || PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes) ||
(!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) ||
(IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))
) {
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));
)
{
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN)Pe32Data));
}
//
// Set default base address to current image address.
//
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data;
//
// Allocate Memory for the image when memory is ready, and image is relocatable.
@@ -350,12 +359,13 @@ LoadAndRelocatePeCoffImage (
((!IsPeiModule) || PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes) ||
(!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) ||
(IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))
) {
)
{
//
// Allocate more buffer to avoid buffer overflow.
//
if (ImageContext.IsTeImage) {
AlignImageSize = ImageContext.ImageSize + ((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);
AlignImageSize = ImageContext.ImageSize + ((EFI_TE_IMAGE_HEADER *)Pe32Data)->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);
} else {
AlignImageSize = ImageContext.ImageSize;
}
@@ -364,38 +374,44 @@ LoadAndRelocatePeCoffImage (
AlignImageSize += ImageContext.SectionAlignment;
}
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
Status = GetPeCoffImageFixLoadingAssignedAddress(&ImageContext, Private);
if (EFI_ERROR (Status)){
if ((PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
Status = GetPeCoffImageFixLoadingAssignedAddress (&ImageContext, Private);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Failed to load module at fixed address. \n"));
//
// The PEIM is not assigned valid address, try to allocate page to load it.
//
Status = PeiServicesAllocatePages (EfiBootServicesCode,
EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize),
&ImageContext.ImageAddress);
Status = PeiServicesAllocatePages (
EfiBootServicesCode,
EFI_SIZE_TO_PAGES ((UINT32)AlignImageSize),
&ImageContext.ImageAddress
);
}
} else {
Status = PeiServicesAllocatePages (EfiBootServicesCode,
EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize),
&ImageContext.ImageAddress);
Status = PeiServicesAllocatePages (
EfiBootServicesCode,
EFI_SIZE_TO_PAGES ((UINT32)AlignImageSize),
&ImageContext.ImageAddress
);
}
if (!EFI_ERROR (Status)) {
//
// Adjust the Image Address to make sure it is section alignment.
//
if (ImageContext.SectionAlignment > EFI_PAGE_SIZE) {
ImageContext.ImageAddress =
(ImageContext.ImageAddress + ImageContext.SectionAlignment - 1) &
~((UINTN)ImageContext.SectionAlignment - 1);
(ImageContext.ImageAddress + ImageContext.SectionAlignment - 1) &
~((UINTN)ImageContext.SectionAlignment - 1);
}
//
// Fix alignment requirement when Load IPF TeImage into memory.
// Skip the reserved space for the stripped PeHeader when load TeImage into memory.
//
if (ImageContext.IsTeImage) {
ImageContext.ImageAddress = ImageContext.ImageAddress +
((EFI_TE_IMAGE_HEADER *) Pe32Data)->StrippedSize -
((EFI_TE_IMAGE_HEADER *)Pe32Data)->StrippedSize -
sizeof (EFI_TE_IMAGE_HEADER);
}
} else {
@@ -406,8 +422,8 @@ LoadAndRelocatePeCoffImage (
//
// XIP image can still be invoked.
//
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;
ReturnStatus = EFI_WARN_BUFFER_TOO_SMALL;
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data;
ReturnStatus = EFI_WARN_BUFFER_TOO_SMALL;
} else {
//
// Non XIP image can't be loaded because no enough memory is allocated.
@@ -424,10 +440,12 @@ LoadAndRelocatePeCoffImage (
Status = PeCoffLoaderLoadImage (&ImageContext);
if (EFI_ERROR (Status)) {
if (ImageContext.ImageError == IMAGE_ERROR_INVALID_SECTION_ALIGNMENT) {
DEBUG ((DEBUG_ERROR, "PEIM Image Address 0x%11p doesn't meet with section alignment 0x%x.\n", (VOID*)(UINTN)ImageContext.ImageAddress, ImageContext.SectionAlignment));
DEBUG ((DEBUG_ERROR, "PEIM Image Address 0x%11p doesn't meet with section alignment 0x%x.\n", (VOID *)(UINTN)ImageContext.ImageAddress, ImageContext.SectionAlignment));
}
return Status;
}
//
// Relocate the image in our new buffer
//
@@ -439,7 +457,7 @@ LoadAndRelocatePeCoffImage (
//
// Flush the instruction cache so the image data is written before we execute it
//
if (ImageContext.ImageAddress != (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data) {
if (ImageContext.ImageAddress != (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data) {
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
}
@@ -462,15 +480,15 @@ LoadAndRelocatePeCoffImage (
**/
EFI_STATUS
LoadAndRelocatePeCoffImageInPlace (
IN VOID *Pe32Data,
IN VOID *ImageAddress
IN VOID *Pe32Data,
IN VOID *ImageAddress
)
{
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
ZeroMem (&ImageContext, sizeof (ImageContext));
ImageContext.Handle = Pe32Data;
ImageContext.Handle = Pe32Data;
ImageContext.ImageRead = PeiImageRead;
Status = PeCoffLoaderGetImageInfo (&ImageContext);
@@ -479,7 +497,7 @@ LoadAndRelocatePeCoffImageInPlace (
return Status;
}
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN) ImageAddress;
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)ImageAddress;
//
// Load the image in place
@@ -502,7 +520,7 @@ LoadAndRelocatePeCoffImageInPlace (
//
// Flush the instruction cache so the image data is written before we execute it
//
if (ImageContext.ImageAddress != (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data) {
if (ImageContext.ImageAddress != (EFI_PHYSICAL_ADDRESS)(UINTN)Pe32Data) {
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
}
@@ -525,10 +543,10 @@ PeiGetPe32Data (
OUT VOID **Pe32Data
)
{
EFI_STATUS Status;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
UINT32 AuthenticationState;
EFI_STATUS Status;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
UINT32 AuthenticationState;
*Pe32Data = NULL;
@@ -563,6 +581,7 @@ PeiGetPe32Data (
&AuthenticationState
);
}
return Status;
}
@@ -588,22 +607,22 @@ PeiGetPe32Data (
**/
EFI_STATUS
PeiLoadImageLoadImage (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg OPTIONAL,
OUT UINT64 *ImageSizeArg OPTIONAL,
OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
OUT UINT32 *AuthenticationState
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_FILE_HANDLE FileHandle,
OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg OPTIONAL,
OUT UINT64 *ImageSizeArg OPTIONAL,
OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
OUT UINT32 *AuthenticationState
)
{
EFI_STATUS Status;
VOID *Pe32Data;
EFI_PHYSICAL_ADDRESS ImageAddress;
UINT64 ImageSize;
EFI_PHYSICAL_ADDRESS ImageEntryPoint;
UINT16 Machine;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
EFI_STATUS Status;
VOID *Pe32Data;
EFI_PHYSICAL_ADDRESS ImageAddress;
UINT64 ImageSize;
EFI_PHYSICAL_ADDRESS ImageEntryPoint;
UINT16 Machine;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
*EntryPoint = 0;
ImageSize = 0;
@@ -654,12 +673,12 @@ PeiLoadImageLoadImage (
// If memory is installed, perform the shadow operations
//
Status = LoadAndRelocatePeCoffImage (
FileHandle,
Pe32Data,
&ImageAddress,
&ImageSize,
&ImageEntryPoint
);
FileHandle,
Pe32Data,
&ImageAddress,
&ImageSize,
&ImageEntryPoint
);
if (EFI_ERROR (Status)) {
return Status;
@@ -668,7 +687,7 @@ PeiLoadImageLoadImage (
//
// Got the entry point from the loaded Pe32Data
//
Pe32Data = (VOID *) ((UINTN) ImageAddress);
Pe32Data = (VOID *)((UINTN)ImageAddress);
*EntryPoint = ImageEntryPoint;
Machine = PeCoffLoaderGetMachineType (Pe32Data);
@@ -688,71 +707,70 @@ PeiLoadImageLoadImage (
}
DEBUG_CODE_BEGIN ();
CHAR8 *AsciiString;
CHAR8 EfiFileName[512];
INT32 Index;
INT32 StartIndex;
CHAR8 *AsciiString;
CHAR8 EfiFileName[512];
INT32 Index;
INT32 StartIndex;
//
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
//
if (Machine != EFI_IMAGE_MACHINE_IA64) {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)*EntryPoint));
} else {
//
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
// For IPF Image, the real entry point should be print.
//
if (Machine != EFI_IMAGE_MACHINE_IA64) {
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)*EntryPoint));
} else {
//
// For IPF Image, the real entry point should be print.
//
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)*EntryPoint)));
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)*EntryPoint)));
}
//
// Print Module Name by PeImage PDB file name.
//
AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);
if (AsciiString != NULL) {
StartIndex = 0;
for (Index = 0; AsciiString[Index] != 0; Index++) {
if ((AsciiString[Index] == '\\') || (AsciiString[Index] == '/')) {
StartIndex = Index + 1;
}
}
//
// Print Module Name by PeImage PDB file name.
// Copy the PDB file name to our temporary string, and replace .pdb with .efi
// The PDB file name is limited in the range of 0~511.
// If the length is bigger than 511, trim the redundant characters to avoid overflow in array boundary.
//
AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);
if (AsciiString != NULL) {
StartIndex = 0;
for (Index = 0; AsciiString[Index] != 0; Index++) {
if (AsciiString[Index] == '\\' || AsciiString[Index] == '/') {
StartIndex = Index + 1;
}
for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
EfiFileName[Index] = AsciiString[Index + StartIndex];
if (EfiFileName[Index] == 0) {
EfiFileName[Index] = '.';
}
//
// Copy the PDB file name to our temporary string, and replace .pdb with .efi
// The PDB file name is limited in the range of 0~511.
// If the length is bigger than 511, trim the redundant characters to avoid overflow in array boundary.
//
for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
EfiFileName[Index] = AsciiString[Index + StartIndex];
if (EfiFileName[Index] == 0) {
EfiFileName[Index] = '.';
}
if (EfiFileName[Index] == '.') {
EfiFileName[Index + 1] = 'e';
EfiFileName[Index + 2] = 'f';
EfiFileName[Index + 3] = 'i';
EfiFileName[Index + 4] = 0;
break;
}
if (EfiFileName[Index] == '.') {
EfiFileName[Index + 1] = 'e';
EfiFileName[Index + 2] = 'f';
EfiFileName[Index + 3] = 'i';
EfiFileName[Index + 4] = 0;
break;
}
if (Index == sizeof (EfiFileName) - 4) {
EfiFileName[Index] = 0;
}
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName));
}
if (Index == sizeof (EfiFileName) - 4) {
EfiFileName[Index] = 0;
}
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName));
}
DEBUG_CODE_END ();
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
return EFI_SUCCESS;
}
/**
The wrapper function of PeiLoadImageLoadImage().
@@ -811,7 +829,7 @@ RelocationIsStrip (
//
// DOS image header is present, so read the PE header after the DOS image header.
//
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
@@ -836,7 +854,7 @@ RelocationIsStrip (
} else {
return FALSE;
}
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
if ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0) {
return TRUE;
} else {
@@ -865,20 +883,20 @@ RelocationIsStrip (
**/
EFI_STATUS
PeiLoadImage (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_FILE_HANDLE FileHandle,
IN UINT8 PeimState,
OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
OUT UINT32 *AuthenticationState
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_FILE_HANDLE FileHandle,
IN UINT8 PeimState,
OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
OUT UINT32 *AuthenticationState
)
{
EFI_STATUS PpiStatus;
EFI_STATUS Status;
UINTN Index;
EFI_PEI_LOAD_FILE_PPI *LoadFile;
EFI_PHYSICAL_ADDRESS ImageAddress;
UINT64 ImageSize;
BOOLEAN IsStrip;
EFI_STATUS PpiStatus;
EFI_STATUS Status;
UINTN Index;
EFI_PEI_LOAD_FILE_PPI *LoadFile;
EFI_PHYSICAL_ADDRESS ImageAddress;
UINT64 ImageSize;
BOOLEAN IsStrip;
IsStrip = FALSE;
//
@@ -895,19 +913,19 @@ PeiLoadImage (
);
if (!EFI_ERROR (PpiStatus)) {
Status = LoadFile->LoadFile (
LoadFile,
FileHandle,
&ImageAddress,
&ImageSize,
EntryPoint,
AuthenticationState
);
if (!EFI_ERROR (Status) || Status == EFI_WARN_BUFFER_TOO_SMALL) {
LoadFile,
FileHandle,
&ImageAddress,
&ImageSize,
EntryPoint,
AuthenticationState
);
if (!EFI_ERROR (Status) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) {
//
// The shadowed PEIM must be relocatable.
//
if (PeimState == PEIM_STATE_REGISTER_FOR_SHADOW) {
IsStrip = RelocationIsStrip ((VOID *) (UINTN) ImageAddress);
IsStrip = RelocationIsStrip ((VOID *)(UINTN)ImageAddress);
ASSERT (!IsStrip);
if (IsStrip) {
return EFI_UNSUPPORTED;
@@ -917,20 +935,21 @@ PeiLoadImage (
//
// The image to be started must have the machine type supported by PeiCore.
//
ASSERT (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID *) (UINTN) ImageAddress)));
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID *) (UINTN) ImageAddress))) {
ASSERT (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID *)(UINTN)ImageAddress)));
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCoffLoaderGetMachineType ((VOID *)(UINTN)ImageAddress))) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
}
Index++;
} while (!EFI_ERROR (PpiStatus));
return PpiStatus;
}
/**
Install Pei Load File PPI.
@@ -942,8 +961,8 @@ PeiLoadImage (
**/
VOID
InitializeImageServices (
IN PEI_CORE_INSTANCE *PrivateData,
IN PEI_CORE_INSTANCE *OldCoreData
IN PEI_CORE_INSTANCE *PrivateData,
IN PEI_CORE_INSTANCE *OldCoreData
)
{
if (OldCoreData == NULL) {

View File

@@ -27,22 +27,20 @@ InitializeMemoryServices (
IN PEI_CORE_INSTANCE *OldCoreData
)
{
PrivateData->SwitchStackSignal = FALSE;
PrivateData->SwitchStackSignal = FALSE;
//
// First entering PeiCore, following code will initialized some field
// in PeiCore's private data according to hand off data from SEC core.
//
if (OldCoreData == NULL) {
PrivateData->PeiMemoryInstalled = FALSE;
PrivateData->HobList.Raw = SecCoreData->PeiTemporaryRamBase;
PeiCoreBuildHobHandoffInfoTable (
BOOT_WITH_FULL_CONFIGURATION,
(EFI_PHYSICAL_ADDRESS) (UINTN) SecCoreData->PeiTemporaryRamBase,
(UINTN) SecCoreData->PeiTemporaryRamSize
(EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->PeiTemporaryRamBase,
(UINTN)SecCoreData->PeiTemporaryRamSize
);
//
@@ -78,7 +76,7 @@ PeiInstallPeiMemory (
IN UINT64 MemoryLength
)
{
PEI_CORE_INSTANCE *PrivateData;
PEI_CORE_INSTANCE *PrivateData;
DEBUG ((DEBUG_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
@@ -98,7 +96,7 @@ PeiInstallPeiMemory (
PrivateData->PhysicalMemoryLength = MemoryLength;
PrivateData->FreePhysicalMemoryTop = MemoryBegin + MemoryLength;
PrivateData->SwitchStackSignal = TRUE;
PrivateData->SwitchStackSignal = TRUE;
return EFI_SUCCESS;
}
@@ -113,25 +111,26 @@ PeiInstallPeiMemory (
**/
VOID
MigrateMemoryPages (
IN PEI_CORE_INSTANCE *Private,
IN BOOLEAN TemporaryRamMigrated
IN PEI_CORE_INSTANCE *Private,
IN BOOLEAN TemporaryRamMigrated
)
{
EFI_PHYSICAL_ADDRESS NewMemPagesBase;
EFI_PHYSICAL_ADDRESS MemPagesBase;
EFI_PHYSICAL_ADDRESS NewMemPagesBase;
EFI_PHYSICAL_ADDRESS MemPagesBase;
Private->MemoryPages.Size = (UINTN) (Private->HobList.HandoffInformationTable->EfiMemoryTop -
Private->HobList.HandoffInformationTable->EfiFreeMemoryTop);
Private->MemoryPages.Size = (UINTN)(Private->HobList.HandoffInformationTable->EfiMemoryTop -
Private->HobList.HandoffInformationTable->EfiFreeMemoryTop);
if (Private->MemoryPages.Size == 0) {
//
// No any memory page allocated in pre-memory phase.
//
return;
}
Private->MemoryPages.Base = Private->HobList.HandoffInformationTable->EfiFreeMemoryTop;
ASSERT (Private->MemoryPages.Size <= Private->FreePhysicalMemoryTop);
NewMemPagesBase = Private->FreePhysicalMemoryTop - Private->MemoryPages.Size;
NewMemPagesBase = Private->FreePhysicalMemoryTop - Private->MemoryPages.Size;
NewMemPagesBase &= ~(UINT64)EFI_PAGE_MASK;
ASSERT (NewMemPagesBase >= Private->PhysicalMemoryBegin);
//
@@ -148,6 +147,7 @@ MigrateMemoryPages (
} else {
MemPagesBase -= Private->HeapOffset;
}
CopyMem ((VOID *)(UINTN)NewMemPagesBase, (VOID *)(UINTN)MemPagesBase, Private->MemoryPages.Size);
} else {
CopyMem ((VOID *)(UINTN)NewMemPagesBase, (VOID *)(UINTN)Private->MemoryPages.Base, Private->MemoryPages.Size);
@@ -155,13 +155,13 @@ MigrateMemoryPages (
if (NewMemPagesBase >= Private->MemoryPages.Base) {
Private->MemoryPages.OffsetPositive = TRUE;
Private->MemoryPages.Offset = (UINTN)(NewMemPagesBase - Private->MemoryPages.Base);
Private->MemoryPages.Offset = (UINTN)(NewMemPagesBase - Private->MemoryPages.Base);
} else {
Private->MemoryPages.OffsetPositive = FALSE;
Private->MemoryPages.Offset = (UINTN)(Private->MemoryPages.Base - NewMemPagesBase);
Private->MemoryPages.Offset = (UINTN)(Private->MemoryPages.Base - NewMemPagesBase);
}
DEBUG ((DEBUG_INFO, "Pages Offset = 0x%lX\n", (UINT64) Private->MemoryPages.Offset));
DEBUG ((DEBUG_INFO, "Pages Offset = 0x%lX\n", (UINT64)Private->MemoryPages.Offset));
Private->FreePhysicalMemoryTop = NewMemPagesBase;
}
@@ -174,30 +174,31 @@ MigrateMemoryPages (
**/
VOID
RemoveFvHobsInTemporaryMemory (
IN PEI_CORE_INSTANCE *Private
IN PEI_CORE_INSTANCE *Private
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
DEBUG ((DEBUG_INFO, "Removing FVs in FV HOB not already migrated to permanent memory.\n"));
for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV || GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2 || GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {
if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3)) {
FirmwareVolumeHob = Hob.FirmwareVolume;
DEBUG ((DEBUG_INFO, " Found FV HOB.\n"));
DEBUG ((
DEBUG_INFO,
" BA=%016lx L=%016lx\n",
FirmwareVolumeHob->BaseAddress,
FirmwareVolumeHob->Length
));
DEBUG_INFO,
" BA=%016lx L=%016lx\n",
FirmwareVolumeHob->BaseAddress,
FirmwareVolumeHob->Length
));
if (
!(
((EFI_PHYSICAL_ADDRESS) (UINTN) FirmwareVolumeHob->BaseAddress >= Private->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS) (UINTN) FirmwareVolumeHob->BaseAddress + (FirmwareVolumeHob->Length - 1)) < Private->FreePhysicalMemoryTop)
!(
((EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumeHob->BaseAddress >= Private->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumeHob->BaseAddress + (FirmwareVolumeHob->Length - 1)) < Private->FreePhysicalMemoryTop)
)
)
) {
{
DEBUG ((DEBUG_INFO, " Removing FV HOB to an FV in T-RAM (was not migrated).\n"));
Hob.Header->HobType = EFI_HOB_TYPE_UNUSED;
}
@@ -216,15 +217,15 @@ RemoveFvHobsInTemporaryMemory (
**/
VOID
ConvertFvHob (
IN PEI_CORE_INSTANCE *PrivateData,
IN UINTN OrgFvHandle,
IN UINTN FvHandle
IN PEI_CORE_INSTANCE *PrivateData,
IN UINTN OrgFvHandle,
IN UINTN FvHandle
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
EFI_HOB_FIRMWARE_VOLUME2 *FirmwareVolume2Hob;
EFI_HOB_FIRMWARE_VOLUME3 *FirmwareVolume3Hob;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
EFI_HOB_FIRMWARE_VOLUME2 *FirmwareVolume2Hob;
EFI_HOB_FIRMWARE_VOLUME3 *FirmwareVolume3Hob;
DEBUG ((DEBUG_INFO, "Converting FVs in FV HOB.\n"));
@@ -257,13 +258,13 @@ ConvertFvHob (
**/
VOID
ConvertMemoryAllocationHobs (
IN PEI_CORE_INSTANCE *PrivateData
IN PEI_CORE_INSTANCE *PrivateData
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
EFI_PHYSICAL_ADDRESS OldMemPagesBase;
UINTN OldMemPagesSize;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
EFI_PHYSICAL_ADDRESS OldMemPagesBase;
UINTN OldMemPagesSize;
if (PrivateData->MemoryPages.Size == 0) {
//
@@ -276,12 +277,13 @@ ConvertMemoryAllocationHobs (
OldMemPagesSize = PrivateData->MemoryPages.Size;
MemoryAllocationHob = NULL;
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
while (Hob.Raw != NULL) {
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
if ((MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress >= OldMemPagesBase) &&
(MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress < (OldMemPagesBase + OldMemPagesSize))
) {
)
{
if (PrivateData->MemoryPages.OffsetPositive) {
MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress += PrivateData->MemoryPages.Offset;
} else {
@@ -306,22 +308,22 @@ ConvertMemoryAllocationHobs (
**/
VOID
InternalBuildMemoryAllocationHob (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_MEMORY_TYPE MemoryType
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_MEMORY_TYPE MemoryType
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
//
// Search unused(freed) memory allocation HOB.
//
MemoryAllocationHob = NULL;
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_UNUSED);
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_UNUSED);
while (Hob.Raw != NULL) {
if (Hob.Header->HobLength == sizeof (EFI_HOB_MEMORY_ALLOCATION)) {
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
break;
}
@@ -370,14 +372,15 @@ InternalBuildMemoryAllocationHob (
**/
VOID
UpdateOrSplitMemoryAllocationHob (
IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINT64 Bytes,
IN EFI_MEMORY_TYPE MemoryType
IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINT64 Bytes,
IN EFI_MEMORY_TYPE MemoryType
)
{
if ((Memory + Bytes) <
(MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress + MemoryAllocationHob->AllocDescriptor.MemoryLength)) {
(MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress + MemoryAllocationHob->AllocDescriptor.MemoryLength))
{
//
// Last pages need to be split out.
//
@@ -403,8 +406,8 @@ UpdateOrSplitMemoryAllocationHob (
// Update the memory allocation HOB.
//
MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress = Memory;
MemoryAllocationHob->AllocDescriptor.MemoryLength = Bytes;
MemoryAllocationHob->AllocDescriptor.MemoryType = MemoryType;
MemoryAllocationHob->AllocDescriptor.MemoryLength = Bytes;
MemoryAllocationHob->AllocDescriptor.MemoryType = MemoryType;
}
/**
@@ -419,34 +422,34 @@ MergeFreeMemoryInMemoryAllocationHob (
VOID
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_PEI_HOB_POINTERS Hob2;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob2;
UINT64 Start;
UINT64 End;
BOOLEAN Merged;
EFI_PEI_HOB_POINTERS Hob;
EFI_PEI_HOB_POINTERS Hob2;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
EFI_HOB_MEMORY_ALLOCATION *MemoryHob2;
UINT64 Start;
UINT64 End;
BOOLEAN Merged;
Merged = FALSE;
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
while (Hob.Raw != NULL) {
if (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) {
MemoryHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;
Start = MemoryHob->AllocDescriptor.MemoryBaseAddress;
End = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength;
MemoryHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
Start = MemoryHob->AllocDescriptor.MemoryBaseAddress;
End = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength;
Hob2.Raw = GET_NEXT_HOB (Hob);
Hob2.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);
while (Hob2.Raw != NULL) {
if (Hob2.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) {
MemoryHob2 = (EFI_HOB_MEMORY_ALLOCATION *) Hob2.Raw;
MemoryHob2 = (EFI_HOB_MEMORY_ALLOCATION *)Hob2.Raw;
if (Start == (MemoryHob2->AllocDescriptor.MemoryBaseAddress + MemoryHob2->AllocDescriptor.MemoryLength)) {
//
// Merge adjacent two free memory ranges.
//
MemoryHob2->AllocDescriptor.MemoryLength += MemoryHob->AllocDescriptor.MemoryLength;
Merged = TRUE;
Merged = TRUE;
//
// Mark MemoryHob to be unused(freed).
//
@@ -457,8 +460,8 @@ MergeFreeMemoryInMemoryAllocationHob (
// Merge adjacent two free memory ranges.
//
MemoryHob2->AllocDescriptor.MemoryBaseAddress = MemoryHob->AllocDescriptor.MemoryBaseAddress;
MemoryHob2->AllocDescriptor.MemoryLength += MemoryHob->AllocDescriptor.MemoryLength;
Merged = TRUE;
MemoryHob2->AllocDescriptor.MemoryLength += MemoryHob->AllocDescriptor.MemoryLength;
Merged = TRUE;
//
// Mark MemoryHob to be unused(freed).
//
@@ -466,10 +469,12 @@ MergeFreeMemoryInMemoryAllocationHob (
break;
}
}
Hob2.Raw = GET_NEXT_HOB (Hob2);
Hob2.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob2.Raw);
}
}
Hob.Raw = GET_NEXT_HOB (Hob);
Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);
}
@@ -492,41 +497,44 @@ MergeFreeMemoryInMemoryAllocationHob (
**/
EFI_STATUS
FindFreeMemoryFromMemoryAllocationHob (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
IN UINTN Granularity,
OUT EFI_PHYSICAL_ADDRESS *Memory
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
IN UINTN Granularity,
OUT EFI_PHYSICAL_ADDRESS *Memory
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
UINT64 Bytes;
EFI_PHYSICAL_ADDRESS BaseAddress;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
UINT64 Bytes;
EFI_PHYSICAL_ADDRESS BaseAddress;
Bytes = LShiftU64 (Pages, EFI_PAGE_SHIFT);
BaseAddress = 0;
BaseAddress = 0;
MemoryAllocationHob = NULL;
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
while (Hob.Raw != NULL) {
if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) &&
(Hob.MemoryAllocation->AllocDescriptor.MemoryLength >= Bytes)) {
(Hob.MemoryAllocation->AllocDescriptor.MemoryLength >= Bytes))
{
//
// Found one memory allocation HOB with big enough free memory.
//
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;
BaseAddress = MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress +
MemoryAllocationHob->AllocDescriptor.MemoryLength - Bytes;
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
BaseAddress = MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress +
MemoryAllocationHob->AllocDescriptor.MemoryLength - Bytes;
//
// Make sure the granularity could be satisfied.
//
BaseAddress &= ~((EFI_PHYSICAL_ADDRESS) Granularity - 1);
BaseAddress &= ~((EFI_PHYSICAL_ADDRESS)Granularity - 1);
if (BaseAddress >= MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress) {
break;
}
BaseAddress = 0;
BaseAddress = 0;
MemoryAllocationHob = NULL;
}
//
// Continue to find.
//
@@ -545,6 +553,7 @@ FindFreeMemoryFromMemoryAllocationHob (
//
return FindFreeMemoryFromMemoryAllocationHob (MemoryType, Pages, Granularity, Memory);
}
return EFI_NOT_FOUND;
}
}
@@ -574,20 +583,20 @@ FindFreeMemoryFromMemoryAllocationHob (
EFI_STATUS
EFIAPI
PeiAllocatePages (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
OUT EFI_PHYSICAL_ADDRESS *Memory
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
OUT EFI_PHYSICAL_ADDRESS *Memory
)
{
EFI_STATUS Status;
PEI_CORE_INSTANCE *PrivateData;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;
UINTN RemainingPages;
UINTN Granularity;
UINTN Padding;
EFI_STATUS Status;
PEI_CORE_INSTANCE *PrivateData;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;
UINTN RemainingPages;
UINTN Granularity;
UINTN Padding;
if ((MemoryType != EfiLoaderCode) &&
(MemoryType != EfiLoaderData) &&
@@ -597,7 +606,8 @@ PeiAllocatePages (
(MemoryType != EfiBootServicesData) &&
(MemoryType != EfiACPIReclaimMemory) &&
(MemoryType != EfiReservedMemoryType) &&
(MemoryType != EfiACPIMemoryNVS)) {
(MemoryType != EfiACPIMemoryNVS))
{
return EFI_INVALID_PARAMETER;
}
@@ -613,16 +623,19 @@ PeiAllocatePages (
return EFI_NOT_AVAILABLE_YET;
}
if (RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY &&
(MemoryType == EfiACPIReclaimMemory ||
MemoryType == EfiACPIMemoryNVS ||
MemoryType == EfiRuntimeServicesCode ||
MemoryType == EfiRuntimeServicesData)) {
if ((RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY) &&
((MemoryType == EfiACPIReclaimMemory) ||
(MemoryType == EfiACPIMemoryNVS) ||
(MemoryType == EfiRuntimeServicesCode) ||
(MemoryType == EfiRuntimeServicesData)))
{
Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
DEBUG ((DEBUG_INFO, "AllocatePages: aligning allocation to %d KB\n",
Granularity / SIZE_1KB));
DEBUG ((
DEBUG_INFO,
"AllocatePages: aligning allocation to %d KB\n",
Granularity / SIZE_1KB
));
}
if (!PrivateData->PeiMemoryInstalled && PrivateData->SwitchStackSignal) {
@@ -630,11 +643,11 @@ PeiAllocatePages (
// When PeiInstallMemory is called but temporary memory has *not* been moved to permanent memory,
// the AllocatePage will depend on the field of PEI_CORE_INSTANCE structure.
//
FreeMemoryTop = &(PrivateData->FreePhysicalMemoryTop);
FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin);
FreeMemoryTop = &(PrivateData->FreePhysicalMemoryTop);
FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin);
} else {
FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);
FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);
FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);
FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);
}
//
@@ -642,7 +655,7 @@ PeiAllocatePages (
// If not aligned, make the allocation aligned.
//
Padding = *(FreeMemoryTop) & (Granularity - 1);
if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < Padding) {
if ((UINTN)(*FreeMemoryTop - *FreeMemoryBottom) < Padding) {
DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after padding.\n"));
return EFI_OUT_OF_RESOURCES;
}
@@ -676,9 +689,10 @@ PeiAllocatePages (
if (!EFI_ERROR (Status)) {
return Status;
}
DEBUG ((DEBUG_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));
DEBUG ((DEBUG_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));
return EFI_OUT_OF_RESOURCES;
DEBUG ((DEBUG_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64)Pages));
DEBUG ((DEBUG_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64)RemainingPages));
return EFI_OUT_OF_RESOURCES;
} else {
//
// Update the PHIT to reflect the memory usage
@@ -713,13 +727,13 @@ PeiAllocatePages (
**/
VOID
FreeMemoryAllocationHob (
IN PEI_CORE_INSTANCE *PrivateData,
IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHobToFree
IN PEI_CORE_INSTANCE *PrivateData,
IN OUT EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHobToFree
)
{
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
Hob.Raw = PrivateData->HobList.Raw;
@@ -744,20 +758,23 @@ FreeMemoryAllocationHob (
MemoryAllocationHobToFree->Header.HobType = EFI_HOB_TYPE_UNUSED;
MemoryAllocationHob = NULL;
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
while (Hob.Raw != NULL) {
if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) &&
(Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == *FreeMemoryTop)) {
(Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == *FreeMemoryTop))
{
//
// Found memory allocation HOB that has EfiConventionalMemory MemoryType and
// MemoryBaseAddress == new *FreeMemoryTop.
//
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
break;
}
Hob.Raw = GET_NEXT_HOB (Hob);
Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);
}
//
// Free memory allocation HOB iteratively.
//
@@ -783,23 +800,23 @@ FreeMemoryAllocationHob (
EFI_STATUS
EFIAPI
PeiFreePages (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN Pages
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN Pages
)
{
PEI_CORE_INSTANCE *PrivateData;
UINT64 Bytes;
UINT64 Start;
UINT64 End;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
PEI_CORE_INSTANCE *PrivateData;
UINT64 Bytes;
UINT64 Start;
UINT64 End;
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_MEMORY_ALLOCATION *MemoryAllocationHob;
Bytes = LShiftU64 (Pages, EFI_PAGE_SHIFT);
Start = Memory;
End = Start + Bytes - 1;
End = Start + Bytes - 1;
if (Pages == 0 || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
if ((Pages == 0) || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {
return EFI_INVALID_PARAMETER;
}
@@ -814,17 +831,19 @@ PeiFreePages (
}
MemoryAllocationHob = NULL;
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
while (Hob.Raw != NULL) {
if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType != EfiConventionalMemory) &&
(Memory >= Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress) &&
((Memory + Bytes) <= (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength))) {
((Memory + Bytes) <= (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength)))
{
//
// Found the memory allocation HOB that includes the memory pages to be freed.
//
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;
MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;
break;
}
Hob.Raw = GET_NEXT_HOB (Hob);
Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);
}
@@ -857,13 +876,13 @@ PeiFreePages (
EFI_STATUS
EFIAPI
PeiAllocatePool (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN UINTN Size,
OUT VOID **Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN UINTN Size,
OUT VOID **Buffer
)
{
EFI_STATUS Status;
EFI_HOB_MEMORY_POOL *Hob;
EFI_STATUS Status;
EFI_HOB_MEMORY_POOL *Hob;
//
// If some "post-memory" PEIM wishes to allocate larger pool,

View File

@@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// This default instance of EFI_PEI_PCI_CFG2_PPI install assigned to EFI_PEI_SERVICE.PciCfg
/// when PeiCore's initialization.
///
EFI_PEI_PCI_CFG2_PPI gPeiDefaultPciCfg2Ppi = {
EFI_PEI_PCI_CFG2_PPI gPeiDefaultPciCfg2Ppi = {
PeiDefaultPciCfg2Read,
PeiDefaultPciCfg2Write,
PeiDefaultPciCfg2Modify
@@ -45,11 +45,11 @@ EFI_PEI_PCI_CFG2_PPI gPeiDefaultPciCfg2Ppi = {
EFI_STATUS
EFIAPI
PeiDefaultPciCfg2Read (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PCI_CFG2_PPI *This,
IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
IN UINT64 Address,
IN OUT VOID *Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PCI_CFG2_PPI *This,
IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
IN UINT64 Address,
IN OUT VOID *Buffer
)
{
return EFI_NOT_AVAILABLE_YET;
@@ -76,11 +76,11 @@ PeiDefaultPciCfg2Read (
EFI_STATUS
EFIAPI
PeiDefaultPciCfg2Write (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PCI_CFG2_PPI *This,
IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
IN UINT64 Address,
IN OUT VOID *Buffer
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PCI_CFG2_PPI *This,
IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
IN UINT64 Address,
IN OUT VOID *Buffer
)
{
return EFI_NOT_AVAILABLE_YET;
@@ -110,12 +110,12 @@ PeiDefaultPciCfg2Write (
EFI_STATUS
EFIAPI
PeiDefaultPciCfg2Modify (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PCI_CFG2_PPI *This,
IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
IN UINT64 Address,
IN VOID *SetBits,
IN VOID *ClearBits
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PCI_CFG2_PPI *This,
IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
IN UINT64 Address,
IN VOID *SetBits,
IN VOID *ClearBits
)
{
return EFI_NOT_AVAILABLE_YET;

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PeiMain.h"
EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMemoryDiscoveredPpiGuid,
NULL
@@ -74,13 +74,13 @@ ShadowPeiCore (
IN PEI_CORE_INSTANCE *PrivateData
)
{
EFI_PEI_FILE_HANDLE PeiCoreFileHandle;
EFI_PHYSICAL_ADDRESS EntryPoint;
EFI_STATUS Status;
UINT32 AuthenticationState;
UINTN Index;
EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi;
UINTN PeiCoreFvIndex;
EFI_PEI_FILE_HANDLE PeiCoreFileHandle;
EFI_PHYSICAL_ADDRESS EntryPoint;
EFI_STATUS Status;
UINT32 AuthenticationState;
UINTN Index;
EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi;
UINTN PeiCoreFvIndex;
PeiCoreFileHandle = NULL;
//
@@ -94,20 +94,22 @@ ShadowPeiCore (
&gEfiPeiCoreFvLocationPpiGuid,
0,
NULL,
(VOID **) &PeiCoreFvLocationPpi
(VOID **)&PeiCoreFvLocationPpi
);
if (!EFI_ERROR (Status) && (PeiCoreFvLocationPpi->PeiCoreFvLocation != NULL)) {
//
// If PeiCoreFvLocation present, the PEI Core should be found from indicated FV
//
for (Index = 0; Index < PrivateData->FvCount; Index ++) {
for (Index = 0; Index < PrivateData->FvCount; Index++) {
if (PrivateData->Fv[Index].FvHandle == PeiCoreFvLocationPpi->PeiCoreFvLocation) {
PeiCoreFvIndex = Index;
break;
}
}
ASSERT (Index < PrivateData->FvCount);
}
//
// Find PEI Core from the given FV index
//
@@ -123,19 +125,19 @@ ShadowPeiCore (
// Shadow PEI Core into memory so it will run faster
//
Status = PeiLoadImage (
GetPeiServicesTablePointer (),
*((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),
PEIM_STATE_REGISTER_FOR_SHADOW,
&EntryPoint,
&AuthenticationState
);
GetPeiServicesTablePointer (),
*((EFI_PEI_FILE_HANDLE *)&PeiCoreFileHandle),
PEIM_STATE_REGISTER_FOR_SHADOW,
&EntryPoint,
&AuthenticationState
);
ASSERT_EFI_ERROR (Status);
//
// Compute the PeiCore's function address after shadowed PeiCore.
// _ModuleEntryPoint is PeiCore main function entry
//
return (PEICORE_FUNCTION_POINTER)((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);
return (PEICORE_FUNCTION_POINTER)((UINTN)EntryPoint + (UINTN)PeiCore - (UINTN)_ModuleEntryPoint);
}
/**
@@ -160,28 +162,28 @@ ShadowPeiCore (
VOID
EFIAPI
PeiCore (
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr,
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
IN VOID *Data
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr,
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
IN VOID *Data
)
{
PEI_CORE_INSTANCE PrivateData;
EFI_SEC_PEI_HAND_OFF *SecCoreData;
EFI_SEC_PEI_HAND_OFF NewSecCoreData;
EFI_STATUS Status;
PEI_CORE_TEMP_POINTERS TempPtr;
PEI_CORE_INSTANCE *OldCoreData;
EFI_PEI_CPU_IO_PPI *CpuIo;
EFI_PEI_PCI_CFG2_PPI *PciCfg;
EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable;
EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;
UINTN Index;
PEI_CORE_INSTANCE PrivateData;
EFI_SEC_PEI_HAND_OFF *SecCoreData;
EFI_SEC_PEI_HAND_OFF NewSecCoreData;
EFI_STATUS Status;
PEI_CORE_TEMP_POINTERS TempPtr;
PEI_CORE_INSTANCE *OldCoreData;
EFI_PEI_CPU_IO_PPI *CpuIo;
EFI_PEI_PCI_CFG2_PPI *PciCfg;
EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable;
EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;
UINTN Index;
//
// Retrieve context passed into PEI Core
//
OldCoreData = (PEI_CORE_INSTANCE *) Data;
SecCoreData = (EFI_SEC_PEI_HAND_OFF *) SecCoreDataPtr;
OldCoreData = (PEI_CORE_INSTANCE *)Data;
SecCoreData = (EFI_SEC_PEI_HAND_OFF *)SecCoreDataPtr;
//
// Perform PEI Core phase specific actions.
@@ -206,59 +208,73 @@ PeiCore (
if (OldCoreData->HeapOffsetPositive) {
OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);
if (OldCoreData->UnknownFvInfo != NULL) {
OldCoreData->UnknownFvInfo = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo + OldCoreData->HeapOffset);
OldCoreData->UnknownFvInfo = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *)((UINT8 *)OldCoreData->UnknownFvInfo + OldCoreData->HeapOffset);
}
if (OldCoreData->CurrentFvFileHandles != NULL) {
OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset);
OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *)((UINT8 *)OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset);
}
if (OldCoreData->PpiData.PpiList.PpiPtrs != NULL) {
OldCoreData->PpiData.PpiList.PpiPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiList.PpiPtrs + OldCoreData->HeapOffset);
OldCoreData->PpiData.PpiList.PpiPtrs = (PEI_PPI_LIST_POINTERS *)((UINT8 *)OldCoreData->PpiData.PpiList.PpiPtrs + OldCoreData->HeapOffset);
}
if (OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs != NULL) {
OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs + OldCoreData->HeapOffset);
OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *)((UINT8 *)OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs + OldCoreData->HeapOffset);
}
if (OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs != NULL) {
OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs + OldCoreData->HeapOffset);
OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *)((UINT8 *)OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs + OldCoreData->HeapOffset);
}
OldCoreData->Fv = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv + OldCoreData->HeapOffset);
for (Index = 0; Index < OldCoreData->FvCount; Index ++) {
OldCoreData->Fv = (PEI_CORE_FV_HANDLE *)((UINT8 *)OldCoreData->Fv + OldCoreData->HeapOffset);
for (Index = 0; Index < OldCoreData->FvCount; Index++) {
if (OldCoreData->Fv[Index].PeimState != NULL) {
OldCoreData->Fv[Index].PeimState = (UINT8 *) OldCoreData->Fv[Index].PeimState + OldCoreData->HeapOffset;
OldCoreData->Fv[Index].PeimState = (UINT8 *)OldCoreData->Fv[Index].PeimState + OldCoreData->HeapOffset;
}
if (OldCoreData->Fv[Index].FvFileHandles != NULL) {
OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles + OldCoreData->HeapOffset);
OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *)((UINT8 *)OldCoreData->Fv[Index].FvFileHandles + OldCoreData->HeapOffset);
}
}
OldCoreData->TempFileGuid = (EFI_GUID *) ((UINT8 *) OldCoreData->TempFileGuid + OldCoreData->HeapOffset);
OldCoreData->TempFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->TempFileHandles + OldCoreData->HeapOffset);
OldCoreData->TempFileGuid = (EFI_GUID *)((UINT8 *)OldCoreData->TempFileGuid + OldCoreData->HeapOffset);
OldCoreData->TempFileHandles = (EFI_PEI_FILE_HANDLE *)((UINT8 *)OldCoreData->TempFileHandles + OldCoreData->HeapOffset);
} else {
OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);
if (OldCoreData->UnknownFvInfo != NULL) {
OldCoreData->UnknownFvInfo = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo - OldCoreData->HeapOffset);
OldCoreData->UnknownFvInfo = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *)((UINT8 *)OldCoreData->UnknownFvInfo - OldCoreData->HeapOffset);
}
if (OldCoreData->CurrentFvFileHandles != NULL) {
OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset);
OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *)((UINT8 *)OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset);
}
if (OldCoreData->PpiData.PpiList.PpiPtrs != NULL) {
OldCoreData->PpiData.PpiList.PpiPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiList.PpiPtrs - OldCoreData->HeapOffset);
OldCoreData->PpiData.PpiList.PpiPtrs = (PEI_PPI_LIST_POINTERS *)((UINT8 *)OldCoreData->PpiData.PpiList.PpiPtrs - OldCoreData->HeapOffset);
}
if (OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs != NULL) {
OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs - OldCoreData->HeapOffset);
OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *)((UINT8 *)OldCoreData->PpiData.CallbackNotifyList.NotifyPtrs - OldCoreData->HeapOffset);
}
if (OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs != NULL) {
OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs - OldCoreData->HeapOffset);
OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs = (PEI_PPI_LIST_POINTERS *)((UINT8 *)OldCoreData->PpiData.DispatchNotifyList.NotifyPtrs - OldCoreData->HeapOffset);
}
OldCoreData->Fv = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv - OldCoreData->HeapOffset);
for (Index = 0; Index < OldCoreData->FvCount; Index ++) {
OldCoreData->Fv = (PEI_CORE_FV_HANDLE *)((UINT8 *)OldCoreData->Fv - OldCoreData->HeapOffset);
for (Index = 0; Index < OldCoreData->FvCount; Index++) {
if (OldCoreData->Fv[Index].PeimState != NULL) {
OldCoreData->Fv[Index].PeimState = (UINT8 *) OldCoreData->Fv[Index].PeimState - OldCoreData->HeapOffset;
OldCoreData->Fv[Index].PeimState = (UINT8 *)OldCoreData->Fv[Index].PeimState - OldCoreData->HeapOffset;
}
if (OldCoreData->Fv[Index].FvFileHandles != NULL) {
OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles - OldCoreData->HeapOffset);
OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *)((UINT8 *)OldCoreData->Fv[Index].FvFileHandles - OldCoreData->HeapOffset);
}
}
OldCoreData->TempFileGuid = (EFI_GUID *) ((UINT8 *) OldCoreData->TempFileGuid - OldCoreData->HeapOffset);
OldCoreData->TempFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->TempFileHandles - OldCoreData->HeapOffset);
OldCoreData->TempFileGuid = (EFI_GUID *)((UINT8 *)OldCoreData->TempFileGuid - OldCoreData->HeapOffset);
OldCoreData->TempFileHandles = (EFI_PEI_FILE_HANDLE *)((UINT8 *)OldCoreData->TempFileHandles - OldCoreData->HeapOffset);
}
//
@@ -276,10 +292,11 @@ PeiCore (
//
HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;
if (OldCoreData->HeapOffsetPositive) {
HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;
HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;
} else {
HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;
HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;
}
HandoffInformationTable->EfiMemoryTop = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength;
HandoffInformationTable->EfiMemoryBottom = OldCoreData->PhysicalMemoryBegin;
HandoffInformationTable->EfiFreeMemoryTop = OldCoreData->FreePhysicalMemoryTop;
@@ -306,22 +323,23 @@ PeiCore (
//
OldCoreData->PeimDispatcherReenter = TRUE;
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
if ((PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
//
// if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.
// Every bit in the array indicate the status of the corresponding memory page available or not
//
OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64));
OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32 (PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof (UINT64));
}
//
// Shadow PEI Core. When permanent memory is available, shadow
// PEI Core and PEIMs to get high performance.
//
OldCoreData->ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) PeiCore;
OldCoreData->ShadowedPeiCore = (PEICORE_FUNCTION_POINTER)(UINTN)PeiCore;
if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes) ||
(HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnS3Boot)) ||
(HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnBoot))) {
((HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot)) ||
((HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoot)))
{
OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);
}
@@ -334,7 +352,7 @@ PeiCore (
// Should never reach here.
//
ASSERT (FALSE);
CpuDeadLoop();
CpuDeadLoop ();
UNREACHABLE ();
}
@@ -347,8 +365,8 @@ PeiCore (
CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));
CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;
PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;
CpuIo = (VOID *)PrivateData.ServiceTableShadow.CpuIo;
PciCfg = (VOID *)PrivateData.ServiceTableShadow.PciCfg;
CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));
@@ -374,7 +392,7 @@ PeiCore (
//
// Initialize PEI Core Services
//
InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);
InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);
//
// Update performance measurements
@@ -387,7 +405,6 @@ PeiCore (
//
PERF_CROSSMODULE_BEGIN ("PEI");
PERF_INMODULE_BEGIN ("PreMem");
} else {
PERF_INMODULE_END ("PreMem");
PERF_INMODULE_BEGIN ("PostMem");
@@ -397,8 +414,8 @@ PeiCore (
// Complete PEI Core Service initialization
//
InitializeSecurityServices (&PrivateData.Ps, OldCoreData);
InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);
InitializeImageServices (&PrivateData, OldCoreData);
InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);
InitializeImageServices (&PrivateData, OldCoreData);
//
// Perform PEI Core Phase specific actions
@@ -416,7 +433,7 @@ PeiCore (
// If SEC provided the PpiList, process it.
//
if (PpiList != NULL) {
ProcessPpiListFromSec ((CONST EFI_PEI_SERVICES **) &PrivateData.Ps, PpiList);
ProcessPpiListFromSec ((CONST EFI_PEI_SERVICES **)&PrivateData.Ps, PpiList);
}
} else {
if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) {
@@ -443,7 +460,7 @@ PeiCore (
&gEfiTemporaryRamDonePpiGuid,
0,
NULL,
(VOID**)&TemporaryRamDonePpi
(VOID **)&TemporaryRamDonePpi
);
if (!EFI_ERROR (Status)) {
//
@@ -475,7 +492,7 @@ PeiCore (
//
// Check if InstallPeiMemory service was called on non-S3 resume boot path.
//
ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
ASSERT (PrivateData.PeiMemoryInstalled == TRUE);
}
//
@@ -518,7 +535,7 @@ PeiCore (
// Should never reach here.
//
ASSERT_EFI_ERROR (Status);
CpuDeadLoop();
CpuDeadLoop ();
UNREACHABLE ();
}

View File

@@ -21,19 +21,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
VOID
ConvertPointer (
IN OUT VOID **Pointer,
IN UINTN TempBottom,
IN UINTN TempTop,
IN UINTN Offset,
IN BOOLEAN OffsetPositive
IN OUT VOID **Pointer,
IN UINTN TempBottom,
IN UINTN TempTop,
IN UINTN Offset,
IN BOOLEAN OffsetPositive
)
{
if (((UINTN) *Pointer < TempTop) &&
((UINTN) *Pointer >= TempBottom)) {
if (((UINTN)*Pointer < TempTop) &&
((UINTN)*Pointer >= TempBottom))
{
if (OffsetPositive) {
*Pointer = (VOID *) ((UINTN) *Pointer + Offset);
*Pointer = (VOID *)((UINTN)*Pointer + Offset);
} else {
*Pointer = (VOID *) ((UINTN) *Pointer - Offset);
*Pointer = (VOID *)((UINTN)*Pointer - Offset);
}
}
}
@@ -55,7 +56,7 @@ ConvertPointerInRanges (
IN OUT VOID **Pointer
)
{
UINT8 IndexHole;
UINT8 IndexHole;
if (PrivateData->MemoryPages.Size != 0) {
//
@@ -96,7 +97,7 @@ ConvertPointerInRanges (
//
// Convert PPI pointer in old TempRam Hole
//
for (IndexHole = 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) {
for (IndexHole = 0; IndexHole < HOLE_MAX_NUMBER; IndexHole++) {
if (PrivateData->HoleData[IndexHole].Size == 0) {
continue;
}
@@ -139,12 +140,12 @@ ConvertSinglePpiPointer (
// 2. Convert the pointer to the GUID in the PPI or NOTIFY descriptor
// from the old TempRam to the relocated physical memory.
//
ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **) &PpiPointer->Ppi->Guid);
ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **)&PpiPointer->Ppi->Guid);
//
// 3. Convert the pointer to the PPI interface structure in the PPI descriptor
// from the old TempRam to the relocated physical memory.
//
ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **) &PpiPointer->Ppi->Ppi);
ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **)&PpiPointer->Ppi->Ppi);
}
/**
@@ -162,7 +163,7 @@ ConvertPpiPointers (
IN PEI_CORE_INSTANCE *PrivateData
)
{
UINT8 Index;
UINT8 Index;
//
// Convert normal PPIs.
@@ -210,10 +211,10 @@ ConvertPpiPointers (
**/
VOID
ConvertPpiPointersFv (
IN PEI_CORE_INSTANCE *PrivateData,
IN UINTN OrgFvHandle,
IN UINTN FvHandle,
IN UINTN FvSize
IN PEI_CORE_INSTANCE *PrivateData,
IN UINTN OrgFvHandle,
IN UINTN FvHandle,
IN UINTN FvSize
)
{
UINT8 Index;
@@ -229,18 +230,18 @@ ConvertPpiPointersFv (
if (FvHandle > OrgFvHandle) {
OffsetPositive = TRUE;
Offset = FvHandle - OrgFvHandle;
Offset = FvHandle - OrgFvHandle;
} else {
OffsetPositive = FALSE;
Offset = OrgFvHandle - FvHandle;
Offset = OrgFvHandle - FvHandle;
}
DEBUG ((DEBUG_VERBOSE, "Converting PPI pointers in FV.\n"));
DEBUG ((
DEBUG_VERBOSE,
" OrgFvHandle at 0x%08x. FvHandle at 0x%08x. FvSize = 0x%x\n",
(UINTN) OrgFvHandle,
(UINTN) FvHandle,
(UINTN)OrgFvHandle,
(UINTN)FvHandle,
FvSize
));
DEBUG ((
@@ -251,46 +252,46 @@ ConvertPpiPointersFv (
));
for (Index = 0; Index < PrivateData->PpiData.CallbackNotifyList.CurrentCount; Index++) {
ConvertPointer (
(VOID **) &PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **) &PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Notify->Guid,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **) &PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Notify->Notify,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **)&PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **)&PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Notify->Guid,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **)&PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Notify->Notify,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
}
for (Index = 0; Index < PrivateData->PpiData.DispatchNotifyList.CurrentCount; Index++) {
ConvertPointer (
(VOID **) &PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw,
(VOID **)&PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **) &PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Notify->Guid,
(VOID **)&PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Notify->Guid,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **) &PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Notify->Notify,
(VOID **)&PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Notify->Notify,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
@@ -300,21 +301,21 @@ ConvertPpiPointersFv (
for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
ConvertPointer (
(VOID **) &PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw,
(VOID **)&PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **) &PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Guid,
(VOID **)&PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Guid,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
OffsetPositive
);
ConvertPointer (
(VOID **) &PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Ppi,
(VOID **)&PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Ppi,
OrgFvHandle,
OrgFvHandle + FvSize,
Offset,
@@ -331,7 +332,8 @@ ConvertPpiPointersFv (
if ((((INT32 *)Guid)[0] == ((INT32 *)GuidCheckList[GuidIndex])[0]) &&
(((INT32 *)Guid)[1] == ((INT32 *)GuidCheckList[GuidIndex])[1]) &&
(((INT32 *)Guid)[2] == ((INT32 *)GuidCheckList[GuidIndex])[2]) &&
(((INT32 *)Guid)[3] == ((INT32 *)GuidCheckList[GuidIndex])[3])) {
(((INT32 *)Guid)[3] == ((INT32 *)GuidCheckList[GuidIndex])[3]))
{
FvInfoPpi = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Ppi;
DEBUG ((DEBUG_VERBOSE, " FvInfo: %p -> ", FvInfoPpi->FvInfo));
if ((UINTN)FvInfoPpi->FvInfo == OrgFvHandle) {
@@ -344,6 +346,7 @@ ConvertPpiPointersFv (
);
DEBUG ((DEBUG_VERBOSE, "%p", FvInfoPpi->FvInfo));
}
DEBUG ((DEBUG_VERBOSE, "\n"));
break;
}
@@ -360,11 +363,11 @@ ConvertPpiPointersFv (
**/
VOID
DumpPpiList (
IN PEI_CORE_INSTANCE *PrivateData
IN PEI_CORE_INSTANCE *PrivateData
)
{
DEBUG_CODE_BEGIN ();
UINTN Index;
UINTN Index;
if (PrivateData == NULL) {
return;
@@ -376,46 +379,51 @@ DumpPpiList (
"CallbackNotify[%2d] {%g} at 0x%x (%a)\n",
Index,
PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Notify->Guid,
(UINTN) PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw,
(UINTN)PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw,
(
!(
((EFI_PHYSICAL_ADDRESS) (UINTN) PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw >= PrivateData->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS) ((UINTN) PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw) + sizeof (EFI_PEI_NOTIFY_DESCRIPTOR)) < PrivateData->FreePhysicalMemoryTop)
)
!(
((EFI_PHYSICAL_ADDRESS)(UINTN)PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw >= PrivateData->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS)((UINTN)PrivateData->PpiData.CallbackNotifyList.NotifyPtrs[Index].Raw) + sizeof (EFI_PEI_NOTIFY_DESCRIPTOR)) < PrivateData->FreePhysicalMemoryTop)
)
? "CAR" : "Post-Memory"
)
)
));
}
for (Index = 0; Index < PrivateData->PpiData.DispatchNotifyList.CurrentCount; Index++) {
DEBUG ((DEBUG_VERBOSE,
"DispatchNotify[%2d] {%g} at 0x%x (%a)\n",
Index,
PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Notify->Guid,
(UINTN) PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw,
(
!(
((EFI_PHYSICAL_ADDRESS) (UINTN) PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw >=PrivateData->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS) ((UINTN) PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw) + sizeof (EFI_PEI_NOTIFY_DESCRIPTOR)) < PrivateData->FreePhysicalMemoryTop)
)
DEBUG ((
DEBUG_VERBOSE,
"DispatchNotify[%2d] {%g} at 0x%x (%a)\n",
Index,
PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Notify->Guid,
(UINTN)PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw,
(
!(
((EFI_PHYSICAL_ADDRESS)(UINTN)PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw >= PrivateData->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS)((UINTN)PrivateData->PpiData.DispatchNotifyList.NotifyPtrs[Index].Raw) + sizeof (EFI_PEI_NOTIFY_DESCRIPTOR)) < PrivateData->FreePhysicalMemoryTop)
)
? "CAR" : "Post-Memory"
)
));
));
}
for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
DEBUG ((DEBUG_VERBOSE,
"PPI[%2d] {%g} at 0x%x (%a)\n",
Index,
PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Guid,
(UINTN) PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw,
(
!(
((EFI_PHYSICAL_ADDRESS) (UINTN) PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw >= PrivateData->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS) ((UINTN) PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw) + sizeof (EFI_PEI_PPI_DESCRIPTOR)) < PrivateData->FreePhysicalMemoryTop)
)
DEBUG ((
DEBUG_VERBOSE,
"PPI[%2d] {%g} at 0x%x (%a)\n",
Index,
PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Guid,
(UINTN)PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw,
(
!(
((EFI_PHYSICAL_ADDRESS)(UINTN)PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw >= PrivateData->PhysicalMemoryBegin) &&
(((EFI_PHYSICAL_ADDRESS)((UINTN)PrivateData->PpiData.PpiList.PpiPtrs[Index].Raw) + sizeof (EFI_PEI_PPI_DESCRIPTOR)) < PrivateData->FreePhysicalMemoryTop)
)
? "CAR" : "Post-Memory"
)
));
));
}
DEBUG_CODE_END ();
}
@@ -444,21 +452,21 @@ InternalPeiInstallPpi (
IN BOOLEAN Single
)
{
PEI_CORE_INSTANCE *PrivateData;
PEI_PPI_LIST *PpiListPointer;
UINTN Index;
UINTN LastCount;
VOID *TempPtr;
PEI_CORE_INSTANCE *PrivateData;
PEI_PPI_LIST *PpiListPointer;
UINTN Index;
UINTN LastCount;
VOID *TempPtr;
if (PpiList == NULL) {
return EFI_INVALID_PARAMETER;
}
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
PpiListPointer = &PrivateData->PpiData.PpiList;
Index = PpiListPointer->CurrentCount;
LastCount = Index;
Index = PpiListPointer->CurrentCount;
LastCount = Index;
//
// This is loop installs all PPI descriptors in the PpiList. It is terminated
@@ -466,7 +474,7 @@ InternalPeiInstallPpi (
// EFI_PEI_PPI_DESCRIPTOR in the list.
//
for (;;) {
for ( ; ;) {
//
// Check if it is a valid PPI.
// If not, rollback list to exclude all in this list.
@@ -474,8 +482,8 @@ InternalPeiInstallPpi (
//
if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {
PpiListPointer->CurrentCount = LastCount;
DEBUG((DEBUG_ERROR, "ERROR -> InstallPpi: %g %p\n", PpiList->Guid, PpiList->Ppi));
return EFI_INVALID_PARAMETER;
DEBUG ((DEBUG_ERROR, "ERROR -> InstallPpi: %g %p\n", PpiList->Guid, PpiList->Ppi));
return EFI_INVALID_PARAMETER;
}
if (Index >= PpiListPointer->MaxCount) {
@@ -491,12 +499,12 @@ InternalPeiInstallPpi (
PpiListPointer->PpiPtrs,
sizeof (PEI_PPI_LIST_POINTERS) * PpiListPointer->MaxCount
);
PpiListPointer->PpiPtrs = TempPtr;
PpiListPointer->PpiPtrs = TempPtr;
PpiListPointer->MaxCount = PpiListPointer->MaxCount + PPI_GROWTH_STEP;
}
DEBUG((DEBUG_INFO, "Install PPI: %g\n", PpiList->Guid));
PpiListPointer->PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) PpiList;
DEBUG ((DEBUG_INFO, "Install PPI: %g\n", PpiList->Guid));
PpiListPointer->PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *)PpiList;
Index++;
PpiListPointer->CurrentCount++;
@@ -506,12 +514,14 @@ InternalPeiInstallPpi (
//
break;
} else if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST)
{
//
// Continue until the end of the PPI List.
//
break;
}
//
// Go to the next descriptor.
//
@@ -583,19 +593,18 @@ PeiReInstallPpi (
IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
)
{
PEI_CORE_INSTANCE *PrivateData;
UINTN Index;
PEI_CORE_INSTANCE *PrivateData;
UINTN Index;
if ((OldPpi == NULL) || (NewPpi == NULL)) {
return EFI_INVALID_PARAMETER;
}
if ((NewPpi->Flags & EFI_PEI_PPI_DESCRIPTOR_PPI) == 0) {
return EFI_INVALID_PARAMETER;
return EFI_INVALID_PARAMETER;
}
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
//
// Find the old PPI instance in the database. If we can not find it,
@@ -606,6 +615,7 @@ PeiReInstallPpi (
break;
}
}
if (Index == PrivateData->PpiData.PpiList.CurrentCount) {
return EFI_NOT_FOUND;
}
@@ -613,8 +623,8 @@ PeiReInstallPpi (
//
// Replace the old PPI with the new one.
//
DEBUG((DEBUG_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));
PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) NewPpi;
DEBUG ((DEBUG_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));
PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *)NewPpi;
//
// Process any callback level notifies for the newly installed PPI.
@@ -650,26 +660,25 @@ PeiReInstallPpi (
EFI_STATUS
EFIAPI
PeiLocatePpi (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_GUID *Guid,
IN UINTN Instance,
IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
IN OUT VOID **Ppi
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_GUID *Guid,
IN UINTN Instance,
IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
IN OUT VOID **Ppi
)
{
PEI_CORE_INSTANCE *PrivateData;
UINTN Index;
EFI_GUID *CheckGuid;
EFI_PEI_PPI_DESCRIPTOR *TempPtr;
PEI_CORE_INSTANCE *PrivateData;
UINTN Index;
EFI_GUID *CheckGuid;
EFI_PEI_PPI_DESCRIPTOR *TempPtr;
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
//
// Search the data base for the matching instance of the GUIDed PPI.
//
for (Index = 0; Index < PrivateData->PpiData.PpiList.CurrentCount; Index++) {
TempPtr = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi;
TempPtr = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi;
CheckGuid = TempPtr->Guid;
//
@@ -680,9 +689,9 @@ PeiLocatePpi (
if ((((INT32 *)Guid)[0] == ((INT32 *)CheckGuid)[0]) &&
(((INT32 *)Guid)[1] == ((INT32 *)CheckGuid)[1]) &&
(((INT32 *)Guid)[2] == ((INT32 *)CheckGuid)[2]) &&
(((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3])) {
(((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3]))
{
if (Instance == 0) {
if (PpiDescriptor != NULL) {
*PpiDescriptor = TempPtr;
}
@@ -691,9 +700,9 @@ PeiLocatePpi (
*Ppi = TempPtr->Ppi;
}
return EFI_SUCCESS;
}
Instance--;
}
}
@@ -738,15 +747,15 @@ InternalPeiNotifyPpi (
return EFI_INVALID_PARAMETER;
}
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
CallbackNotifyListPointer = &PrivateData->PpiData.CallbackNotifyList;
CallbackNotifyIndex = CallbackNotifyListPointer->CurrentCount;
LastCallbackNotifyCount = CallbackNotifyIndex;
CallbackNotifyIndex = CallbackNotifyListPointer->CurrentCount;
LastCallbackNotifyCount = CallbackNotifyIndex;
DispatchNotifyListPointer = &PrivateData->PpiData.DispatchNotifyList;
DispatchNotifyIndex = DispatchNotifyListPointer->CurrentCount;
LastDispatchNotifyCount = DispatchNotifyIndex;
DispatchNotifyIndex = DispatchNotifyListPointer->CurrentCount;
LastDispatchNotifyCount = DispatchNotifyIndex;
//
// This is loop installs all Notify descriptors in the NotifyList. It is
@@ -754,15 +763,15 @@ InternalPeiNotifyPpi (
// EFI_PEI_NOTIFY_DESCRIPTOR in the list.
//
for (;;) {
for ( ; ;) {
//
// If some of the PPI data is invalid restore original Notify PPI database value
//
if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) == 0) {
CallbackNotifyListPointer->CurrentCount = LastCallbackNotifyCount;
DispatchNotifyListPointer->CurrentCount = LastDispatchNotifyCount;
DEBUG((DEBUG_ERROR, "ERROR -> NotifyPpi: %g %p\n", NotifyList->Guid, NotifyList->Notify));
return EFI_INVALID_PARAMETER;
CallbackNotifyListPointer->CurrentCount = LastCallbackNotifyCount;
DispatchNotifyListPointer->CurrentCount = LastDispatchNotifyCount;
DEBUG ((DEBUG_ERROR, "ERROR -> NotifyPpi: %g %p\n", NotifyList->Guid, NotifyList->Notify));
return EFI_INVALID_PARAMETER;
}
if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) != 0) {
@@ -780,9 +789,10 @@ InternalPeiNotifyPpi (
sizeof (PEI_PPI_LIST_POINTERS) * CallbackNotifyListPointer->MaxCount
);
CallbackNotifyListPointer->NotifyPtrs = TempPtr;
CallbackNotifyListPointer->MaxCount = CallbackNotifyListPointer->MaxCount + CALLBACK_NOTIFY_GROWTH_STEP;
CallbackNotifyListPointer->MaxCount = CallbackNotifyListPointer->MaxCount + CALLBACK_NOTIFY_GROWTH_STEP;
}
CallbackNotifyListPointer->NotifyPtrs[CallbackNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;
CallbackNotifyListPointer->NotifyPtrs[CallbackNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *)NotifyList;
CallbackNotifyIndex++;
CallbackNotifyListPointer->CurrentCount++;
} else {
@@ -800,14 +810,15 @@ InternalPeiNotifyPpi (
sizeof (PEI_PPI_LIST_POINTERS) * DispatchNotifyListPointer->MaxCount
);
DispatchNotifyListPointer->NotifyPtrs = TempPtr;
DispatchNotifyListPointer->MaxCount = DispatchNotifyListPointer->MaxCount + DISPATCH_NOTIFY_GROWTH_STEP;
DispatchNotifyListPointer->MaxCount = DispatchNotifyListPointer->MaxCount + DISPATCH_NOTIFY_GROWTH_STEP;
}
DispatchNotifyListPointer->NotifyPtrs[DispatchNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;
DispatchNotifyListPointer->NotifyPtrs[DispatchNotifyIndex].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *)NotifyList;
DispatchNotifyIndex++;
DispatchNotifyListPointer->CurrentCount++;
}
DEBUG((DEBUG_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));
DEBUG ((DEBUG_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));
if (Single) {
//
@@ -815,12 +826,14 @@ InternalPeiNotifyPpi (
//
break;
} else if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST)
{
//
// Continue until the end of the Notify List.
//
break;
}
//
// Go to the next descriptor.
//
@@ -839,7 +852,7 @@ InternalPeiNotifyPpi (
CallbackNotifyListPointer->CurrentCount
);
return EFI_SUCCESS;
return EFI_SUCCESS;
}
/**
@@ -878,7 +891,7 @@ ProcessDispatchNotifyList (
IN PEI_CORE_INSTANCE *PrivateData
)
{
UINTN TempValue;
UINTN TempValue;
while (TRUE) {
//
@@ -927,6 +940,7 @@ ProcessDispatchNotifyList (
break;
}
}
return;
}
@@ -945,18 +959,18 @@ ProcessDispatchNotifyList (
VOID
ProcessNotify (
IN PEI_CORE_INSTANCE *PrivateData,
IN UINTN NotifyType,
IN INTN InstallStartIndex,
IN INTN InstallStopIndex,
IN INTN NotifyStartIndex,
IN INTN NotifyStopIndex
IN UINTN NotifyType,
IN INTN InstallStartIndex,
IN INTN InstallStopIndex,
IN INTN NotifyStartIndex,
IN INTN NotifyStopIndex
)
{
INTN Index1;
INTN Index2;
EFI_GUID *SearchGuid;
EFI_GUID *CheckGuid;
EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
INTN Index1;
INTN Index2;
EFI_GUID *SearchGuid;
EFI_GUID *CheckGuid;
EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
for (Index1 = NotifyStartIndex; Index1 < NotifyStopIndex; Index1++) {
if (NotifyType == EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK) {
@@ -977,13 +991,16 @@ ProcessNotify (
if ((((INT32 *)SearchGuid)[0] == ((INT32 *)CheckGuid)[0]) &&
(((INT32 *)SearchGuid)[1] == ((INT32 *)CheckGuid)[1]) &&
(((INT32 *)SearchGuid)[2] == ((INT32 *)CheckGuid)[2]) &&
(((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3])) {
DEBUG ((DEBUG_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %p\n",
(((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3]))
{
DEBUG ((
DEBUG_INFO,
"Notify: PPI Guid: %g, Peim notify entry point: %p\n",
SearchGuid,
NotifyDescriptor->Notify
));
NotifyDescriptor->Notify (
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
(EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
NotifyDescriptor,
(PrivateData->PpiData.PpiList.PpiPtrs[Index2].Ppi)->Ppi
);
@@ -1002,20 +1019,20 @@ ProcessNotify (
**/
VOID
ProcessPpiListFromSec (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
IN CONST EFI_PEI_SERVICES **PeiServices,
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
)
{
EFI_STATUS Status;
EFI_SEC_HOB_DATA_PPI *SecHobDataPpi;
EFI_HOB_GENERIC_HEADER *SecHobList;
EFI_STATUS Status;
EFI_SEC_HOB_DATA_PPI *SecHobDataPpi;
EFI_HOB_GENERIC_HEADER *SecHobList;
for (;;) {
for ( ; ;) {
if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES) != 0) {
//
// It is a notification PPI.
//
Status = InternalPeiNotifyPpi (PeiServices, (CONST EFI_PEI_NOTIFY_DESCRIPTOR *) PpiList, TRUE);
Status = InternalPeiNotifyPpi (PeiServices, (CONST EFI_PEI_NOTIFY_DESCRIPTOR *)PpiList, TRUE);
ASSERT_EFI_ERROR (Status);
} else {
//
@@ -1041,7 +1058,7 @@ ProcessPpiListFromSec (
// returned into the HOB list. It does this after installing all PPIs passed from SEC
// into the PPI database and before dispatching any PEIMs.
//
Status = PeiLocatePpi (PeiServices, &gEfiSecHobDataPpiGuid, 0, NULL, (VOID **) &SecHobDataPpi);
Status = PeiLocatePpi (PeiServices, &gEfiSecHobDataPpiGuid, 0, NULL, (VOID **)&SecHobDataPpi);
if (!EFI_ERROR (Status)) {
Status = SecHobDataPpi->GetHobs (SecHobDataPpi, &SecHobList);
if (!EFI_ERROR (Status)) {
@@ -1061,8 +1078,8 @@ ProcessPpiListFromSec (
**/
VOID
ConvertPeiCorePpiPointers (
IN PEI_CORE_INSTANCE *PrivateData,
IN PEI_CORE_FV_HANDLE *CoreFvHandle
IN PEI_CORE_INSTANCE *PrivateData,
IN PEI_CORE_FV_HANDLE *CoreFvHandle
)
{
EFI_FV_FILE_INFO FileInfo;
@@ -1080,11 +1097,11 @@ ConvertPeiCorePpiPointers (
// Find the PEI Core in the BFV in temporary memory.
//
Status = CoreFvHandle->FvPpi->FindFileByType (
CoreFvHandle->FvPpi,
EFI_FV_FILETYPE_PEI_CORE,
CoreFvHandle->FvHandle,
&PeiCoreFileHandle
);
CoreFvHandle->FvPpi,
EFI_FV_FILETYPE_PEI_CORE,
CoreFvHandle->FvHandle,
&PeiCoreFileHandle
);
ASSERT_EFI_ERROR (Status);
if (!EFI_ERROR (Status)) {
@@ -1097,21 +1114,21 @@ ConvertPeiCorePpiPointers (
//
// Find PEI Core EntryPoint in the BFV in temporary memory.
//
Status = PeCoffLoaderGetEntryPoint ((VOID *) (UINTN) PeiCoreImageBase, &PeiCoreEntryPoint);
Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, &PeiCoreEntryPoint);
ASSERT_EFI_ERROR (Status);
OrgImageBase = (UINTN) PeiCoreImageBase;
MigratedImageBase = (UINTN) _ModuleEntryPoint - ((UINTN) PeiCoreEntryPoint - (UINTN) PeiCoreImageBase);
OrgImageBase = (UINTN)PeiCoreImageBase;
MigratedImageBase = (UINTN)_ModuleEntryPoint - ((UINTN)PeiCoreEntryPoint - (UINTN)PeiCoreImageBase);
//
// Size of loaded PEI_CORE in permanent memory.
//
PeiCoreModuleSize = (UINTN)FileInfo.BufferSize - ((UINTN) OrgImageBase - (UINTN) FileInfo.Buffer);
PeiCoreModuleSize = (UINTN)FileInfo.BufferSize - ((UINTN)OrgImageBase - (UINTN)FileInfo.Buffer);
//
// Migrate PEI_CORE PPI pointers from temporary memory to newly
// installed PEI_CORE in permanent memory.
//
ConvertPpiPointersFv (PrivateData, (UINTN) OrgImageBase, (UINTN) MigratedImageBase, PeiCoreModuleSize);
ConvertPpiPointersFv (PrivateData, (UINTN)OrgImageBase, (UINTN)MigratedImageBase, PeiCoreModuleSize);
}
}

View File

@@ -59,7 +59,7 @@ PeiResetSystem (
//
// No reset PPIs are available yet.
//
return EFI_NOT_AVAILABLE_YET;
return EFI_NOT_AVAILABLE_YET;
}
/**

View File

@@ -8,11 +8,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PeiMain.h"
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEfiPeiSecurity2PpiGuid,
SecurityPpiNotifyCallback
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEfiPeiSecurity2PpiGuid,
SecurityPpiNotifyCallback
};
/**
@@ -25,13 +24,14 @@ EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
**/
VOID
InitializeSecurityServices (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_CORE_INSTANCE *OldCoreData
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_CORE_INSTANCE *OldCoreData
)
{
if (OldCoreData == NULL) {
PeiServicesNotifyPpi (&mNotifyList);
}
return;
}
@@ -55,7 +55,7 @@ SecurityPpiNotifyCallback (
IN VOID *Ppi
)
{
PEI_CORE_INSTANCE *PrivateData;
PEI_CORE_INSTANCE *PrivateData;
//
// Get PEI Core private data
@@ -68,6 +68,7 @@ SecurityPpiNotifyCallback (
if (PrivateData->PrivateSecurityPpi == NULL) {
PrivateData->PrivateSecurityPpi = (EFI_PEI_SECURITY2_PPI *)Ppi;
}
return EFI_SUCCESS;
}
@@ -85,14 +86,14 @@ SecurityPpiNotifyCallback (
**/
EFI_STATUS
VerifyPeim (
IN PEI_CORE_INSTANCE *PrivateData,
IN EFI_PEI_FV_HANDLE VolumeHandle,
IN EFI_PEI_FILE_HANDLE FileHandle,
IN UINT32 AuthenticationStatus
IN PEI_CORE_INSTANCE *PrivateData,
IN EFI_PEI_FV_HANDLE VolumeHandle,
IN EFI_PEI_FILE_HANDLE FileHandle,
IN UINT32 AuthenticationStatus
)
{
EFI_STATUS Status;
BOOLEAN DeferExecution;
EFI_STATUS Status;
BOOLEAN DeferExecution;
Status = EFI_NOT_FOUND;
if (PrivateData->PrivateSecurityPpi == NULL) {
@@ -109,7 +110,7 @@ VerifyPeim (
// Check to see if the image is OK
//
Status = PrivateData->PrivateSecurityPpi->AuthenticationState (
(CONST EFI_PEI_SERVICES **) &PrivateData->Ps,
(CONST EFI_PEI_SERVICES **)&PrivateData->Ps,
PrivateData->PrivateSecurityPpi,
AuthenticationStatus,
VolumeHandle,
@@ -120,10 +121,10 @@ VerifyPeim (
Status = EFI_SECURITY_VIOLATION;
}
}
return Status;
}
/**
Verify a Firmware volume.

View File

@@ -27,16 +27,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
PeiReportStatusCode (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN CONST EFI_GUID *CallerId,
IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN CONST EFI_GUID *CallerId,
IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
)
{
EFI_STATUS Status;
EFI_PEI_PROGRESS_CODE_PPI *StatusCodePpi;
EFI_STATUS Status;
EFI_PEI_PROGRESS_CODE_PPI *StatusCodePpi;
//
// Locate StatusCode Ppi.
@@ -50,19 +50,16 @@ PeiReportStatusCode (
if (!EFI_ERROR (Status)) {
Status = StatusCodePpi->ReportStatusCode (
PeiServices,
CodeType,
Value,
Instance,
CallerId,
Data
);
PeiServices,
CodeType,
Value,
Instance,
CallerId,
Data
);
return Status;
return Status;
}
return EFI_NOT_AVAILABLE_YET;
return EFI_NOT_AVAILABLE_YET;
}

View File

@@ -46,8 +46,8 @@ GrowDepexStack (
VOID
)
{
BOOLEAN *NewStack;
UINTN Size;
BOOLEAN *NewStack;
UINTN Size;
Size = DEPEX_STACK_SIZE_INCREMENT;
if (mDepexEvaluationStack != NULL) {
@@ -166,7 +166,7 @@ PopBool (
**/
BOOLEAN
SmmIsSchedulable (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry
IN EFI_SMM_DRIVER_ENTRY *DriverEntry
)
{
EFI_STATUS Status;
@@ -176,7 +176,7 @@ SmmIsSchedulable (
EFI_GUID DriverGuid;
VOID *Interface;
Operator = FALSE;
Operator = FALSE;
Operator2 = FALSE;
if (DriverEntry->After || DriverEntry->Before) {
@@ -205,7 +205,6 @@ SmmIsSchedulable (
//
mDepexEvaluationStackPointer = mDepexEvaluationStack;
Iterator = DriverEntry->Depex;
while (TRUE) {
@@ -222,148 +221,155 @@ SmmIsSchedulable (
// Look at the opcode of the dependency expression instruction.
//
switch (*Iterator) {
case EFI_DEP_BEFORE:
case EFI_DEP_AFTER:
//
// For a well-formed Dependency Expression, the code should never get here.
// The BEFORE and AFTER are processed prior to this routine's invocation.
// If the code flow arrives at this point, there was a BEFORE or AFTER
// that were not the first opcodes.
//
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n"));
ASSERT (FALSE);
case EFI_DEP_PUSH:
//
// Push operator is followed by a GUID. Test to see if the GUID protocol
// is installed and push the boolean result on the stack.
//
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
Status = SmmLocateProtocol (&DriverGuid, NULL, &Interface);
if (EFI_ERROR (Status)) {
case EFI_DEP_BEFORE:
case EFI_DEP_AFTER:
//
// For SMM Driver, it may depend on uefi protocols
// For a well-formed Dependency Expression, the code should never get here.
// The BEFORE and AFTER are processed prior to this routine's invocation.
// If the code flow arrives at this point, there was a BEFORE or AFTER
// that were not the first opcodes.
//
Status = gBS->LocateProtocol (&DriverGuid, NULL, &Interface);
}
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n"));
ASSERT (FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
Status = PushBool (FALSE);
} else {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
*Iterator = EFI_DEP_REPLACE_TRUE;
case EFI_DEP_PUSH:
//
// Push operator is followed by a GUID. Test to see if the GUID protocol
// is installed and push the boolean result on the stack.
//
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
Status = SmmLocateProtocol (&DriverGuid, NULL, &Interface);
if (EFI_ERROR (Status)) {
//
// For SMM Driver, it may depend on uefi protocols
//
Status = gBS->LocateProtocol (&DriverGuid, NULL, &Interface);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid));
Status = PushBool (FALSE);
} else {
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
*Iterator = EFI_DEP_REPLACE_TRUE;
Status = PushBool (TRUE);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
case EFI_DEP_AND:
DEBUG ((DEBUG_DISPATCH, " AND\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(Operator && Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_OR:
DEBUG ((DEBUG_DISPATCH, " OR\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(Operator || Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_NOT:
DEBUG ((DEBUG_DISPATCH, " NOT\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(!Operator));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_TRUE:
DEBUG ((DEBUG_DISPATCH, " TRUE\n"));
Status = PushBool (TRUE);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
break;
case EFI_DEP_AND:
DEBUG ((DEBUG_DISPATCH, " AND\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_FALSE:
DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
Status = PushBool (FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
Status = PushBool ((BOOLEAN)(Operator && Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_END:
DEBUG ((DEBUG_DISPATCH, " END\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_OR:
DEBUG ((DEBUG_DISPATCH, " OR\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE"));
return Operator;
Status = PopBool (&Operator2);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
case EFI_DEP_REPLACE_TRUE:
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
Status = PushBool (TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(Operator || Operator2));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
Iterator += sizeof (EFI_GUID);
break;
case EFI_DEP_NOT:
DEBUG ((DEBUG_DISPATCH, " NOT\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Status = PushBool ((BOOLEAN)(!Operator));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_TRUE:
DEBUG ((DEBUG_DISPATCH, " TRUE\n"));
Status = PushBool (TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_FALSE:
DEBUG ((DEBUG_DISPATCH, " FALSE\n"));
Status = PushBool (FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
break;
case EFI_DEP_END:
DEBUG ((DEBUG_DISPATCH, " END\n"));
Status = PopBool (&Operator);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE"));
return Operator;
case EFI_DEP_REPLACE_TRUE:
CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID));
DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid));
Status = PushBool (TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n"));
return FALSE;
}
Iterator += sizeof (EFI_GUID);
break;
default:
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n"));
goto Done;
default:
DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n"));
goto Done;
}
//

File diff suppressed because it is too large Load Diff

View File

@@ -12,8 +12,8 @@
// mProtocolDatabase - A list of all protocols in the system. (simple list for now)
// gHandleList - A list of all the handles in the system
//
LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);
LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);
LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);
LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);
/**
Check whether a handle is a valid EFI_HANDLE
@@ -35,9 +35,11 @@ SmmValidateHandle (
if (Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
if (Handle->Signature != EFI_HANDLE_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
@@ -52,13 +54,13 @@ SmmValidateHandle (
**/
PROTOCOL_ENTRY *
SmmFindProtocolEntry (
IN EFI_GUID *Protocol,
IN BOOLEAN Create
IN EFI_GUID *Protocol,
IN BOOLEAN Create
)
{
LIST_ENTRY *Link;
PROTOCOL_ENTRY *Item;
PROTOCOL_ENTRY *ProtEntry;
LIST_ENTRY *Link;
PROTOCOL_ENTRY *Item;
PROTOCOL_ENTRY *ProtEntry;
//
// Search the database for the matching GUID
@@ -67,9 +69,9 @@ SmmFindProtocolEntry (
ProtEntry = NULL;
for (Link = mProtocolDatabase.ForwardLink;
Link != &mProtocolDatabase;
Link = Link->ForwardLink) {
Item = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
Link = Link->ForwardLink)
{
Item = CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
if (CompareGuid (&Item->ProtocolID, Protocol)) {
//
// This is the protocol entry
@@ -84,7 +86,7 @@ SmmFindProtocolEntry (
// allocate a new entry
//
if ((ProtEntry == NULL) && Create) {
ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY));
ProtEntry = AllocatePool (sizeof (PROTOCOL_ENTRY));
if (ProtEntry != NULL) {
//
// Initialize new protocol entry structure
@@ -100,6 +102,7 @@ SmmFindProtocolEntry (
InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries);
}
}
return ProtEntry;
}
@@ -136,17 +139,19 @@ SmmFindProtocolInterface (
//
// Look at each protocol interface for any matches
//
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link=Link->ForwardLink) {
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
//
// If this protocol interface matches, remove it
//
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
if (Prot->Interface == Interface && Prot->Protocol == ProtEntry) {
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
if ((Prot->Interface == Interface) && (Prot->Protocol == ProtEntry)) {
break;
}
Prot = NULL;
}
}
return Prot;
}
@@ -218,7 +223,7 @@ SmmInstallProtocolInterfaceNotify (
// returns EFI_INVALID_PARAMETER if InterfaceType is invalid.
// Also added check for invalid UserHandle and Protocol pointers.
//
if (UserHandle == NULL || Protocol == NULL) {
if ((UserHandle == NULL) || (Protocol == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -229,10 +234,10 @@ SmmInstallProtocolInterfaceNotify (
//
// Print debug message
//
DEBUG((DEBUG_LOAD | DEBUG_INFO, "SmmInstallProtocolInterface: %g %p\n", Protocol, Interface));
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "SmmInstallProtocolInterface: %g %p\n", Protocol, Interface));
Status = EFI_OUT_OF_RESOURCES;
Prot = NULL;
Prot = NULL;
Handle = NULL;
if (*UserHandle != NULL) {
@@ -253,7 +258,7 @@ SmmInstallProtocolInterfaceNotify (
//
// Allocate a new protocol interface structure
//
Prot = AllocateZeroPool (sizeof(PROTOCOL_INTERFACE));
Prot = AllocateZeroPool (sizeof (PROTOCOL_INTERFACE));
if (Prot == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -264,7 +269,7 @@ SmmInstallProtocolInterfaceNotify (
//
Handle = (IHANDLE *)*UserHandle;
if (Handle == NULL) {
Handle = AllocateZeroPool (sizeof(IHANDLE));
Handle = AllocateZeroPool (sizeof (IHANDLE));
if (Handle == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -284,7 +289,7 @@ SmmInstallProtocolInterfaceNotify (
} else {
Status = SmmValidateHandle (Handle);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "SmmInstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
DEBUG ((DEBUG_ERROR, "SmmInstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
goto Done;
}
}
@@ -298,8 +303,8 @@ SmmInstallProtocolInterfaceNotify (
// Initialize the protocol interface structure
//
Prot->Signature = PROTOCOL_INTERFACE_SIGNATURE;
Prot->Handle = Handle;
Prot->Protocol = ProtEntry;
Prot->Handle = Handle;
Prot->Protocol = ProtEntry;
Prot->Interface = Interface;
//
@@ -320,6 +325,7 @@ SmmInstallProtocolInterfaceNotify (
if (Notify) {
SmmNotifyProtocol (Prot);
}
Status = EFI_SUCCESS;
Done:
@@ -335,8 +341,10 @@ Done:
if (Prot != NULL) {
FreePool (Prot);
}
DEBUG((DEBUG_ERROR, "SmmInstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
DEBUG ((DEBUG_ERROR, "SmmInstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
}
return Status;
}
@@ -417,6 +425,7 @@ SmmUninstallProtocolInterface (
RemoveEntryList (&Handle->AllHandles);
FreePool (Handle);
}
return Status;
}
@@ -452,12 +461,13 @@ SmmGetProtocolInterface (
// Look at each protocol interface for a match
//
for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);
ProtEntry = Prot->Protocol;
if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) {
return Prot;
}
}
return NULL;
}

File diff suppressed because it is too large Load Diff

View File

@@ -53,15 +53,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Each entry occupies 8B/64b. 1-page can hold 512 entries, which spans 9
// bits in address. (512 = 1 << 9)
//
#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
#define BYTE_LENGTH_SHIFT 3 // (8 = 1 << 3)
#define GUARDED_HEAP_MAP_TABLE_ENTRY_SHIFT \
(EFI_PAGE_SHIFT - BYTE_LENGTH_SHIFT)
#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
#define GUARDED_HEAP_MAP_TABLE_DEPTH 5
// Use UINT64_index + bit_index_of_UINT64 to locate the bit in may
#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
#define GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT 6 // (64 = 1 << 6)
#define GUARDED_HEAP_MAP_ENTRY_BITS \
(1 << GUARDED_HEAP_MAP_ENTRY_BIT_SHIFT)
@@ -154,8 +154,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Memory type to guard (matching the related PCD definition)
//
#define GUARD_HEAP_TYPE_PAGE BIT2
#define GUARD_HEAP_TYPE_POOL BIT3
#define GUARD_HEAP_TYPE_PAGE BIT2
#define GUARD_HEAP_TYPE_POOL BIT3
//
// Debug message level
@@ -163,10 +163,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define HEAP_GUARD_DEBUG_LEVEL (DEBUG_POOL|DEBUG_PAGE)
typedef struct {
UINT32 TailMark;
UINT32 HeadMark;
EFI_PHYSICAL_ADDRESS Address;
LIST_ENTRY Link;
UINT32 TailMark;
UINT32 HeadMark;
EFI_PHYSICAL_ADDRESS Address;
LIST_ENTRY Link;
} HEAP_GUARD_NODE;
/**
@@ -179,8 +179,8 @@ typedef struct {
**/
VOID
SetGuardForMemory (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
);
/**
@@ -193,8 +193,8 @@ SetGuardForMemory (
**/
VOID
UnsetGuardForMemory (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
);
/**
@@ -207,8 +207,8 @@ UnsetGuardForMemory (
**/
VOID
AdjustMemoryA (
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
);
/**
@@ -225,8 +225,8 @@ AdjustMemoryA (
**/
VOID
AdjustMemoryF (
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
IN OUT EFI_PHYSICAL_ADDRESS *Memory,
IN OUT UINTN *NumberOfPages
);
/**
@@ -240,7 +240,7 @@ AdjustMemoryF (
**/
BOOLEAN
IsPoolTypeToGuard (
IN EFI_MEMORY_TYPE MemoryType
IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -254,8 +254,8 @@ IsPoolTypeToGuard (
**/
BOOLEAN
IsPageTypeToGuard (
IN EFI_MEMORY_TYPE MemoryType,
IN EFI_ALLOCATE_TYPE AllocateType
IN EFI_MEMORY_TYPE MemoryType,
IN EFI_ALLOCATE_TYPE AllocateType
);
/**
@@ -269,7 +269,7 @@ IsPageTypeToGuard (
BOOLEAN
EFIAPI
IsMemoryGuarded (
IN EFI_PHYSICAL_ADDRESS Address
IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -283,7 +283,7 @@ IsMemoryGuarded (
BOOLEAN
EFIAPI
IsGuardPage (
IN EFI_PHYSICAL_ADDRESS Address
IN EFI_PHYSICAL_ADDRESS Address
);
/**
@@ -308,9 +308,9 @@ DumpGuardedMemoryBitmap (
**/
VOID *
AdjustPoolHeadA (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages,
IN UINTN Size
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NoPages,
IN UINTN Size
);
/**
@@ -322,7 +322,7 @@ AdjustPoolHeadA (
**/
VOID *
AdjustPoolHeadF (
IN EFI_PHYSICAL_ADDRESS Memory
IN EFI_PHYSICAL_ADDRESS Memory
);
/**
@@ -337,10 +337,10 @@ AdjustPoolHeadF (
**/
UINTN
InternalAllocMaxAddressWithGuard (
IN OUT LIST_ENTRY *FreePageList,
IN UINTN NumberOfPages,
IN UINTN MaxAddress,
IN EFI_MEMORY_TYPE MemoryType
IN OUT LIST_ENTRY *FreePageList,
IN UINTN NumberOfPages,
IN UINTN MaxAddress,
IN EFI_MEMORY_TYPE MemoryType
);
/**
@@ -383,10 +383,10 @@ IsHeapGuardEnabled (
**/
BOOLEAN
VerifyMemoryGuard (
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINTN NumberOfPages
);
extern BOOLEAN mOnGuarding;
extern BOOLEAN mOnGuarding;
#endif

View File

@@ -8,7 +8,7 @@
#include "PiSmmCore.h"
#define CONFIG_TABLE_SIZE_INCREASED 0x10
#define CONFIG_TABLE_SIZE_INCREASED 0x10
UINTN mSmmSystemTableAllocateSize = 0;
@@ -86,7 +86,6 @@ SmmInstallConfigurationTable (
&(ConfigurationTable[Index + 1]),
(gSmmCoreSmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE)
);
} else {
//
// No matching GUIDs were found, so this is an add operation.
@@ -106,7 +105,7 @@ SmmInstallConfigurationTable (
// Allocate a table with one additional entry.
//
mSmmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE));
ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);
ConfigurationTable = AllocatePool (mSmmSystemTableAllocateSize);
if (ConfigurationTable == NULL) {
//
// If a new table could not be allocated, then return an error.

View File

@@ -11,24 +11,24 @@
//
// ProtocolRequest - Last LocateHandle request ID
//
UINTN mEfiLocateHandleRequest = 0;
UINTN mEfiLocateHandleRequest = 0;
//
// Internal prototypes
//
typedef struct {
EFI_GUID *Protocol;
VOID *SearchKey;
LIST_ENTRY *Position;
PROTOCOL_ENTRY *ProtEntry;
EFI_GUID *Protocol;
VOID *SearchKey;
LIST_ENTRY *Position;
PROTOCOL_ENTRY *ProtEntry;
} LOCATE_POSITION;
typedef
IHANDLE *
(* CORE_GET_NEXT) (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
(*CORE_GET_NEXT) (
IN OUT LOCATE_POSITION *Position,
OUT VOID **Interface
);
/**
@@ -48,7 +48,7 @@ SmmGetNextLocateAllHandles (
OUT VOID **Interface
)
{
IHANDLE *Handle;
IHANDLE *Handle;
//
// Next handle
@@ -58,11 +58,12 @@ SmmGetNextLocateAllHandles (
//
// If not at the end of the list, get the handle
//
Handle = NULL;
*Interface = NULL;
Handle = NULL;
*Interface = NULL;
if (Position->Position != &gHandleList) {
Handle = CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);
}
return Handle;
}
@@ -89,15 +90,15 @@ SmmGetNextLocateByRegisterNotify (
PROTOCOL_INTERFACE *Prot;
LIST_ENTRY *Link;
Handle = NULL;
*Interface = NULL;
Handle = NULL;
*Interface = NULL;
ProtNotify = Position->SearchKey;
//
// If this is the first request, get the next handle
//
if (ProtNotify != NULL) {
ASSERT(ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
ASSERT (ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
Position->SearchKey = NULL;
//
@@ -105,11 +106,12 @@ SmmGetNextLocateByRegisterNotify (
//
Link = ProtNotify->Position->ForwardLink;
if (Link != &ProtNotify->Protocol->Protocols) {
Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
*Interface = Prot->Interface;
}
}
return Handle;
}
@@ -134,13 +136,13 @@ SmmGetNextLocateByProtocol (
LIST_ENTRY *Link;
PROTOCOL_INTERFACE *Prot;
Handle = NULL;
*Interface = NULL;
for (; ;) {
Handle = NULL;
*Interface = NULL;
for ( ; ;) {
//
// Next entry
//
Link = Position->Position->ForwardLink;
Link = Position->Position->ForwardLink;
Position->Position = Link;
//
@@ -154,8 +156,8 @@ SmmGetNextLocateByProtocol (
//
// Get the handle
//
Prot = CR(Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);
Handle = Prot->Handle;
*Interface = Prot->Interface;
//
@@ -167,6 +169,7 @@ SmmGetNextLocateByProtocol (
break;
}
}
return Handle;
}
@@ -194,17 +197,17 @@ SmmLocateProtocol (
OUT VOID **Interface
)
{
EFI_STATUS Status;
LOCATE_POSITION Position;
PROTOCOL_NOTIFY *ProtNotify;
IHANDLE *Handle;
EFI_STATUS Status;
LOCATE_POSITION Position;
PROTOCOL_NOTIFY *ProtNotify;
IHANDLE *Handle;
if ((Interface == NULL) || (Protocol == NULL)) {
return EFI_INVALID_PARAMETER;
}
*Interface = NULL;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
//
// Set initial position
@@ -223,6 +226,7 @@ SmmLocateProtocol (
if (Position.ProtEntry == NULL) {
return EFI_NOT_FOUND;
}
Position.Position = &Position.ProtEntry->Protocols;
Handle = SmmGetNextLocateByProtocol (&Position, Interface);
@@ -237,7 +241,7 @@ SmmLocateProtocol (
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
ProtNotify = Registration;
ProtNotify = Registration;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
@@ -298,51 +302,54 @@ SmmLocateHandle (
Position.SearchKey = SearchKey;
Position.Position = &gHandleList;
ResultSize = 0;
ResultBuffer = (IHANDLE **) Buffer;
Status = EFI_SUCCESS;
ResultSize = 0;
ResultBuffer = (IHANDLE **)Buffer;
Status = EFI_SUCCESS;
//
// Get the search function based on type
//
switch (SearchType) {
case AllHandles:
GetNext = SmmGetNextLocateAllHandles;
break;
case AllHandles:
GetNext = SmmGetNextLocateAllHandles;
break;
case ByRegisterNotify:
GetNext = SmmGetNextLocateByRegisterNotify;
//
// Must have SearchKey for locate ByRegisterNotify
//
if (SearchKey == NULL) {
Status = EFI_INVALID_PARAMETER;
}
break;
case ByRegisterNotify:
GetNext = SmmGetNextLocateByRegisterNotify;
//
// Must have SearchKey for locate ByRegisterNotify
//
if (SearchKey == NULL) {
Status = EFI_INVALID_PARAMETER;
}
case ByProtocol:
GetNext = SmmGetNextLocateByProtocol;
if (Protocol == NULL) {
break;
case ByProtocol:
GetNext = SmmGetNextLocateByProtocol;
if (Protocol == NULL) {
Status = EFI_INVALID_PARAMETER;
break;
}
//
// Look up the protocol entry and set the head pointer
//
Position.ProtEntry = SmmFindProtocolEntry (Protocol, FALSE);
if (Position.ProtEntry == NULL) {
Status = EFI_NOT_FOUND;
break;
}
Position.Position = &Position.ProtEntry->Protocols;
break;
default:
Status = EFI_INVALID_PARAMETER;
break;
}
//
// Look up the protocol entry and set the head pointer
//
Position.ProtEntry = SmmFindProtocolEntry (Protocol, FALSE);
if (Position.ProtEntry == NULL) {
Status = EFI_NOT_FOUND;
break;
}
Position.Position = &Position.ProtEntry->Protocols;
break;
default:
Status = EFI_INVALID_PARAMETER;
break;
}
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
return Status;
}
@@ -350,7 +357,7 @@ SmmLocateHandle (
// Enumerate out the matching handles
//
mEfiLocateHandleRequest += 1;
for (; ;) {
for ( ; ;) {
//
// Get the next handle. If no more handles, stop
//
@@ -363,10 +370,10 @@ SmmLocateHandle (
// Increase the resulting buffer size, and if this handle
// fits return it
//
ResultSize += sizeof(Handle);
ResultSize += sizeof (Handle);
if (ResultSize <= *BufferSize) {
*ResultBuffer = Handle;
ResultBuffer += 1;
*ResultBuffer = Handle;
ResultBuffer += 1;
}
}
@@ -387,13 +394,13 @@ SmmLocateHandle (
*BufferSize = ResultSize;
if (SearchType == ByRegisterNotify && !EFI_ERROR(Status)) {
if ((SearchType == ByRegisterNotify) && !EFI_ERROR (Status)) {
ASSERT (SearchKey != NULL);
//
// If this is a search by register notify and a handle was
// returned, update the register notification position
//
ProtNotify = SearchKey;
ProtNotify = SearchKey;
ProtNotify->Position = ProtNotify->Position->ForwardLink;
}
}
@@ -444,26 +451,27 @@ SmmLocateHandleBuffer (
return EFI_INVALID_PARAMETER;
}
BufferSize = 0;
BufferSize = 0;
*NumberHandles = 0;
*Buffer = NULL;
Status = SmmLocateHandle (
SearchType,
Protocol,
SearchKey,
&BufferSize,
*Buffer
);
*Buffer = NULL;
Status = SmmLocateHandle (
SearchType,
Protocol,
SearchKey,
&BufferSize,
*Buffer
);
//
// LocateHandleBuffer() returns incorrect status code if SearchType is
// invalid.
//
// Add code to correctly handle expected errors from SmmLocateHandle().
//
if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
if (Status != EFI_INVALID_PARAMETER) {
Status = EFI_NOT_FOUND;
}
return Status;
}
@@ -480,8 +488,8 @@ SmmLocateHandleBuffer (
*Buffer
);
*NumberHandles = BufferSize / sizeof(EFI_HANDLE);
if (EFI_ERROR(Status)) {
*NumberHandles = BufferSize / sizeof (EFI_HANDLE);
if (EFI_ERROR (Status)) {
*NumberHandles = 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -24,8 +24,8 @@ SmmNotifyProtocol (
LIST_ENTRY *Link;
ProtEntry = Prot->Protocol;
for (Link=ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {
ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
ProtNotify->Function (&ProtEntry->ProtocolID, Prot->Interface, Prot->Handle);
}
}
@@ -54,14 +54,13 @@ SmmRemoveInterfaceFromProtocol (
Prot = SmmFindProtocolInterface (Handle, Protocol, Interface);
if (Prot != NULL) {
ProtEntry = Prot->Protocol;
//
// If there's a protocol notify location pointing to this entry, back it up one
//
for(Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {
ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
if (ProtNotify->Position == &Prot->ByProtocol) {
ProtNotify->Position = Prot->ByProtocol.BackLink;
@@ -105,7 +104,7 @@ SmmRegisterProtocolNotify (
LIST_ENTRY *Link;
EFI_STATUS Status;
if (Protocol == NULL || Registration == NULL) {
if ((Protocol == NULL) || (Registration == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -113,16 +112,17 @@ SmmRegisterProtocolNotify (
//
// Get the protocol entry per Protocol
//
ProtEntry = SmmFindProtocolEntry ((EFI_GUID *) Protocol, FALSE);
ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, FALSE);
if (ProtEntry != NULL) {
ProtNotify = (PROTOCOL_NOTIFY * )*Registration;
ProtNotify = (PROTOCOL_NOTIFY *)*Registration;
for (Link = ProtEntry->Notify.ForwardLink;
Link != &ProtEntry->Notify;
Link = Link->ForwardLink) {
Link = Link->ForwardLink)
{
//
// Compare the notification record
//
if (ProtNotify == (CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))){
if (ProtNotify == (CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))) {
//
// If Registration is an existing registration, then unhook it
//
@@ -133,6 +133,7 @@ SmmRegisterProtocolNotify (
}
}
}
//
// If the registration is not found
//
@@ -144,19 +145,19 @@ SmmRegisterProtocolNotify (
//
// Get the protocol entry to add the notification too
//
ProtEntry = SmmFindProtocolEntry ((EFI_GUID *) Protocol, TRUE);
ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, TRUE);
if (ProtEntry != NULL) {
//
// Find whether notification already exist
//
for (Link = ProtEntry->Notify.ForwardLink;
Link != &ProtEntry->Notify;
Link = Link->ForwardLink) {
ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
Link = Link->ForwardLink)
{
ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);
if (CompareGuid (&ProtNotify->Protocol->ProtocolID, Protocol) &&
(ProtNotify->Function == Function)) {
(ProtNotify->Function == Function))
{
//
// Notification already exist
//
@@ -169,11 +170,11 @@ SmmRegisterProtocolNotify (
//
// Allocate a new notification record
//
ProtNotify = AllocatePool (sizeof(PROTOCOL_NOTIFY));
ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));
if (ProtNotify != NULL) {
ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;
ProtNotify->Protocol = ProtEntry;
ProtNotify->Function = Function;
ProtNotify->Protocol = ProtEntry;
ProtNotify->Function = Function;
//
// Start at the ending
//
@@ -190,7 +191,8 @@ SmmRegisterProtocolNotify (
Status = EFI_OUT_OF_RESOURCES;
if (ProtNotify != NULL) {
*Registration = ProtNotify;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
}
return Status;
}

View File

@@ -17,36 +17,34 @@ LIST_ENTRY mSmmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mSmmMemoryMap);
// For GetMemoryMap()
//
#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
#define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
typedef struct {
UINTN Signature;
LIST_ENTRY Link;
BOOLEAN FromStack;
EFI_MEMORY_TYPE Type;
UINT64 Start;
UINT64 End;
UINTN Signature;
LIST_ENTRY Link;
BOOLEAN FromStack;
EFI_MEMORY_TYPE Type;
UINT64 Start;
UINT64 End;
} MEMORY_MAP;
LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
LIST_ENTRY gMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (gMemoryMap);
#define MAX_MAP_DEPTH 6
#define MAX_MAP_DEPTH 6
///
/// mMapDepth - depth of new descriptor stack
///
UINTN mMapDepth = 0;
UINTN mMapDepth = 0;
///
/// mMapStack - space to use as temp storage to build new map descriptors
///
MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
UINTN mFreeMapStack = 0;
MEMORY_MAP mMapStack[MAX_MAP_DEPTH];
UINTN mFreeMapStack = 0;
///
/// This list maintain the free memory map list
///
LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
LIST_ENTRY mFreeMemoryMapEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mFreeMemoryMapEntryList);
/**
Allocates pages from the memory map.
@@ -91,16 +89,16 @@ AllocateMemoryMapEntry (
VOID
)
{
EFI_PHYSICAL_ADDRESS Mem;
EFI_STATUS Status;
MEMORY_MAP* FreeDescriptorEntries;
MEMORY_MAP* Entry;
UINTN Index;
EFI_PHYSICAL_ADDRESS Mem;
EFI_STATUS Status;
MEMORY_MAP *FreeDescriptorEntries;
MEMORY_MAP *Entry;
UINTN Index;
//DEBUG((DEBUG_INFO, "AllocateMemoryMapEntry\n"));
// DEBUG((DEBUG_INFO, "AllocateMemoryMapEntry\n"));
if (IsListEmpty (&mFreeMemoryMapEntryList)) {
//DEBUG((DEBUG_INFO, "mFreeMemoryMapEntryList is empty\n"));
// DEBUG((DEBUG_INFO, "mFreeMemoryMapEntryList is empty\n"));
//
// The list is empty, to allocate one page to refuel the list
//
@@ -113,13 +111,13 @@ AllocateMemoryMapEntry (
FALSE
);
ASSERT_EFI_ERROR (Status);
if(!EFI_ERROR (Status)) {
if (!EFI_ERROR (Status)) {
FreeDescriptorEntries = (MEMORY_MAP *)(UINTN)Mem;
//DEBUG((DEBUG_INFO, "New FreeDescriptorEntries - 0x%x\n", FreeDescriptorEntries));
// DEBUG((DEBUG_INFO, "New FreeDescriptorEntries - 0x%x\n", FreeDescriptorEntries));
//
// Enqueue the free memory map entries into the list
//
for (Index = 0; Index< RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
for (Index = 0; Index < RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof (MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
@@ -127,6 +125,7 @@ AllocateMemoryMapEntry (
return NULL;
}
}
//
// dequeue the first descriptor from the list
//
@@ -136,7 +135,6 @@ AllocateMemoryMapEntry (
return Entry;
}
/**
Internal function. Moves any memory descriptors that are on the
temporary descriptor stack to heap.
@@ -147,14 +145,14 @@ CoreFreeMemoryMapStack (
VOID
)
{
MEMORY_MAP *Entry;
MEMORY_MAP *Entry;
//
// If already freeing the map stack, then return
//
if (mFreeMapStack != 0) {
ASSERT (FALSE);
return ;
return;
}
//
@@ -175,8 +173,7 @@ CoreFreeMemoryMapStack (
mMapDepth -= 1;
if (mMapStack[mMapDepth].Link.ForwardLink != NULL) {
CopyMem (Entry , &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
CopyMem (Entry, &mMapStack[mMapDepth], sizeof (MEMORY_MAP));
Entry->FromStack = FALSE;
//
@@ -203,25 +200,25 @@ CoreFreeMemoryMapStack (
**/
VOID
InsertNewEntry (
IN LIST_ENTRY *Link,
IN UINT64 Start,
IN UINT64 End,
IN EFI_MEMORY_TYPE Type,
IN BOOLEAN Next,
IN BOOLEAN AddRegion
IN LIST_ENTRY *Link,
IN UINT64 Start,
IN UINT64 End,
IN EFI_MEMORY_TYPE Type,
IN BOOLEAN Next,
IN BOOLEAN AddRegion
)
{
MEMORY_MAP *Entry;
Entry = &mMapStack[mMapDepth];
Entry = &mMapStack[mMapDepth];
mMapDepth += 1;
ASSERT (mMapDepth < MAX_MAP_DEPTH);
Entry->FromStack = TRUE;
Entry->Signature = MEMORY_MAP_SIGNATURE;
Entry->Type = Type;
Entry->Start = Start;
Entry->End = End;
Entry->Type = Type;
Entry->Start = Start;
Entry->End = End;
if (Next) {
InsertHeadList (Link, &Entry->Link);
} else {
@@ -263,17 +260,17 @@ ConvertSmmMemoryMapEntry (
IN BOOLEAN AddRegion
)
{
LIST_ENTRY *Link;
MEMORY_MAP *Entry;
MEMORY_MAP *NextEntry;
LIST_ENTRY *NextLink;
MEMORY_MAP *PreviousEntry;
LIST_ENTRY *PreviousLink;
EFI_PHYSICAL_ADDRESS Start;
EFI_PHYSICAL_ADDRESS End;
LIST_ENTRY *Link;
MEMORY_MAP *Entry;
MEMORY_MAP *NextEntry;
LIST_ENTRY *NextLink;
MEMORY_MAP *PreviousEntry;
LIST_ENTRY *PreviousLink;
EFI_PHYSICAL_ADDRESS Start;
EFI_PHYSICAL_ADDRESS End;
Start = Memory;
End = Memory + EFI_PAGES_TO_SIZE(NumberOfPages) - 1;
End = Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1;
//
// Exclude memory region
@@ -296,8 +293,9 @@ ConvertSmmMemoryMapEntry (
if (Entry->Start > End) {
if ((Entry->Start == End + 1) && (Entry->Type == Type)) {
Entry->Start = Start;
return ;
return;
}
InsertNewEntry (
&Entry->Link,
Start,
@@ -306,7 +304,7 @@ ConvertSmmMemoryMapEntry (
FALSE,
AddRegion
);
return ;
return;
}
if ((Entry->Start <= Start) && (Entry->End >= End)) {
@@ -331,6 +329,7 @@ ConvertSmmMemoryMapEntry (
AddRegion
);
}
if (Entry->End > End) {
//
// ---------------------------------------------------
@@ -351,12 +350,13 @@ ConvertSmmMemoryMapEntry (
AddRegion
);
}
//
// Update this node
//
Entry->Start = Start;
Entry->End = End;
Entry->Type = Type;
Entry->End = End;
Entry->Type = Type;
//
// Check adjacent
@@ -375,6 +375,7 @@ ConvertSmmMemoryMapEntry (
RemoveOldEntry (NextEntry);
}
}
PreviousLink = Entry->Link.BackLink;
if (PreviousLink != &gMemoryMap) {
PreviousEntry = CR (PreviousLink, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
@@ -390,7 +391,8 @@ ConvertSmmMemoryMapEntry (
}
}
}
return ;
return;
}
}
@@ -409,9 +411,10 @@ ConvertSmmMemoryMapEntry (
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
if ((Entry->End + 1 == Start) && (Entry->Type == Type)) {
Entry->End = End;
return ;
return;
}
}
InsertNewEntry (
&gMemoryMap,
Start,
@@ -420,7 +423,7 @@ ConvertSmmMemoryMapEntry (
FALSE,
AddRegion
);
return ;
return;
}
/**
@@ -433,20 +436,19 @@ GetSmmMemoryMapEntryCount (
VOID
)
{
LIST_ENTRY *Link;
UINTN Count;
LIST_ENTRY *Link;
UINTN Count;
Count = 0;
Link = gMemoryMap.ForwardLink;
Link = gMemoryMap.ForwardLink;
while (Link != &gMemoryMap) {
Link = Link->ForwardLink;
Link = Link->ForwardLink;
Count++;
}
return Count;
}
/**
Internal Function. Allocate n pages from given free page node.
@@ -472,10 +474,11 @@ InternalAllocPagesOnOneNode (
if (Top > Pages->NumberOfPages) {
Top = Pages->NumberOfPages;
}
Bottom = Top - NumberOfPages;
if (Top < Pages->NumberOfPages) {
Node = (FREE_PAGE_LIST*)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top));
Node = (FREE_PAGE_LIST *)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top));
Node->NumberOfPages = Pages->NumberOfPages - Top;
InsertHeadList (&Pages->Link, &Node->Link);
}
@@ -511,11 +514,13 @@ InternalAllocMaxAddress (
for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
if (Pages->NumberOfPages >= NumberOfPages &&
(UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress) {
if ((Pages->NumberOfPages >= NumberOfPages) &&
((UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress))
{
return InternalAllocPagesOnOneNode (Pages, NumberOfPages, MaxAddress);
}
}
return (UINTN)(-1);
}
@@ -545,15 +550,17 @@ InternalAllocAddress (
}
EndAddress = Address + EFI_PAGES_TO_SIZE (NumberOfPages);
for (Node = FreePageList->BackLink; Node!= FreePageList; Node = Node->BackLink) {
for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
if ((UINTN)Pages <= Address) {
if ((UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages) < EndAddress) {
break;
}
return InternalAllocPagesOnOneNode (Pages, NumberOfPages, EndAddress);
}
}
return ~Address;
}
@@ -588,8 +595,9 @@ SmmInternalAllocatePagesEx (
{
UINTN RequestedAddress;
if (MemoryType != EfiRuntimeServicesCode &&
MemoryType != EfiRuntimeServicesData) {
if ((MemoryType != EfiRuntimeServicesCode) &&
(MemoryType != EfiRuntimeServicesData))
{
return EFI_INVALID_PARAMETER;
}
@@ -607,11 +615,11 @@ SmmInternalAllocatePagesEx (
case AllocateMaxAddress:
if (NeedGuard) {
*Memory = InternalAllocMaxAddressWithGuard (
&mSmmMemoryMap,
NumberOfPages,
RequestedAddress,
MemoryType
);
&mSmmMemoryMap,
NumberOfPages,
RequestedAddress,
MemoryType
);
if (*Memory == (UINTN)-1) {
return EFI_OUT_OF_RESOURCES;
} else {
@@ -628,6 +636,7 @@ SmmInternalAllocatePagesEx (
if (*Memory == (UINTN)-1) {
return EFI_OUT_OF_RESOURCES;
}
break;
case AllocateAddress:
*Memory = InternalAllocAddress (
@@ -638,6 +647,7 @@ SmmInternalAllocatePagesEx (
if (*Memory != RequestedAddress) {
return EFI_NOT_FOUND;
}
break;
default:
return EFI_INVALID_PARAMETER;
@@ -648,7 +658,7 @@ SmmInternalAllocatePagesEx (
//
ConvertSmmMemoryMapEntry (MemoryType, *Memory, NumberOfPages, AddRegion);
if (!AddRegion) {
CoreFreeMemoryMapStack();
CoreFreeMemoryMapStack ();
}
return EFI_SUCCESS;
@@ -682,8 +692,14 @@ SmmInternalAllocatePages (
IN BOOLEAN NeedGuard
)
{
return SmmInternalAllocatePagesEx (Type, MemoryType, NumberOfPages, Memory,
FALSE, NeedGuard);
return SmmInternalAllocatePagesEx (
Type,
MemoryType,
NumberOfPages,
Memory,
FALSE,
NeedGuard
);
}
/**
@@ -715,18 +731,24 @@ SmmAllocatePages (
BOOLEAN NeedGuard;
NeedGuard = IsPageTypeToGuard (MemoryType, Type);
Status = SmmInternalAllocatePages (Type, MemoryType, NumberOfPages, Memory,
NeedGuard);
Status = SmmInternalAllocatePages (
Type,
MemoryType,
NumberOfPages,
Memory,
NeedGuard
);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePages,
MemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
(VOID *) (UINTN) *Memory,
(VOID *)(UINTN)*Memory,
NULL
);
}
return Status;
}
@@ -747,13 +769,15 @@ InternalMergeNodes (
Next = BASE_CR (First->Link.ForwardLink, FREE_PAGE_LIST, Link);
ASSERT (
TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages);
TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages
);
if (TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) == First->NumberOfPages) {
First->NumberOfPages += Next->NumberOfPages;
RemoveEntryList (&Next->Link);
Next = First;
}
return Next;
}
@@ -784,17 +808,19 @@ SmmInternalFreePagesEx (
}
Pages = NULL;
Node = mSmmMemoryMap.ForwardLink;
Node = mSmmMemoryMap.ForwardLink;
while (Node != &mSmmMemoryMap) {
Pages = BASE_CR (Node, FREE_PAGE_LIST, Link);
if (Memory < (UINTN)Pages) {
break;
}
Node = Node->ForwardLink;
}
if (Node != &mSmmMemoryMap &&
Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages) {
if ((Node != &mSmmMemoryMap) &&
(Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages))
{
return EFI_INVALID_PARAMETER;
}
@@ -805,7 +831,7 @@ SmmInternalFreePagesEx (
}
}
Pages = (FREE_PAGE_LIST*)(UINTN)Memory;
Pages = (FREE_PAGE_LIST *)(UINTN)Memory;
Pages->NumberOfPages = NumberOfPages;
InsertTailList (Node, &Pages->Link);
@@ -824,7 +850,7 @@ SmmInternalFreePagesEx (
//
ConvertSmmMemoryMapEntry (EfiConventionalMemory, Memory, NumberOfPages, AddRegion);
if (!AddRegion) {
CoreFreeMemoryMapStack();
CoreFreeMemoryMapStack ();
}
return EFI_SUCCESS;
@@ -853,6 +879,7 @@ SmmInternalFreePages (
if (IsGuarded) {
return SmmInternalFreePagesExWithGuard (Memory, NumberOfPages, FALSE);
}
return SmmInternalFreePagesEx (Memory, NumberOfPages, FALSE);
}
@@ -872,9 +899,9 @@ InMemMap (
IN UINTN NumberOfPages
)
{
LIST_ENTRY *Link;
MEMORY_MAP *Entry;
EFI_PHYSICAL_ADDRESS Last;
LIST_ENTRY *Link;
MEMORY_MAP *Entry;
EFI_PHYSICAL_ADDRESS Last;
Last = Memory + EFI_PAGES_TO_SIZE (NumberOfPages) - 1;
@@ -912,22 +939,23 @@ SmmFreePages (
EFI_STATUS Status;
BOOLEAN IsGuarded;
if (!InMemMap(Memory, NumberOfPages)) {
if (!InMemMap (Memory, NumberOfPages)) {
return EFI_NOT_FOUND;
}
IsGuarded = IsHeapGuardEnabled () && IsMemoryGuarded (Memory);
Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
Status = SmmInternalFreePages (Memory, NumberOfPages, IsGuarded);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePages,
EfiMaxMemoryType,
EFI_PAGES_TO_SIZE (NumberOfPages),
(VOID *) (UINTN) Memory,
(VOID *)(UINTN)Memory,
NULL
);
}
return Status;
}
@@ -969,7 +997,7 @@ SmmAddMemoryRegion (
// Align range on an EFI_PAGE_SIZE boundary
//
AlignedMemBase = (UINTN)(MemBase + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
MemLength -= AlignedMemBase - MemBase;
MemLength -= AlignedMemBase - MemBase;
if (Type == EfiConventionalMemory) {
SmmInternalFreePagesEx (AlignedMemBase, TRUNCATE_TO_PAGES ((UINTN)MemLength), TRUE);
} else {
@@ -1019,11 +1047,11 @@ SmmCoreGetMemoryMap (
OUT UINT32 *DescriptorVersion
)
{
UINTN Count;
LIST_ENTRY *Link;
MEMORY_MAP *Entry;
UINTN Size;
UINTN BufferSize;
UINTN Count;
LIST_ENTRY *Link;
MEMORY_MAP *Entry;
UINTN Size;
UINTN BufferSize;
Size = sizeof (EFI_MEMORY_DESCRIPTOR);
@@ -1032,7 +1060,7 @@ SmmCoreGetMemoryMap (
// prevent people from having pointer math bugs in their code.
// now you have to use *DescriptorSize to make things work.
//
Size += sizeof(UINT64) - (Size % sizeof (UINT64));
Size += sizeof (UINT64) - (Size % sizeof (UINT64));
if (DescriptorSize != NULL) {
*DescriptorSize = Size;
@@ -1042,7 +1070,7 @@ SmmCoreGetMemoryMap (
*DescriptorVersion = EFI_MEMORY_DESCRIPTOR_VERSION;
}
Count = GetSmmMemoryMapEntryCount ();
Count = GetSmmMemoryMapEntryCount ();
BufferSize = Size * Count;
if (*MemoryMapSize < BufferSize) {
*MemoryMapSize = BufferSize;
@@ -1060,9 +1088,9 @@ SmmCoreGetMemoryMap (
Entry = CR (Link, MEMORY_MAP, Link, MEMORY_MAP_SIGNATURE);
Link = Link->ForwardLink;
MemoryMap->Type = Entry->Type;
MemoryMap->PhysicalStart = Entry->Start;
MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
MemoryMap->Type = Entry->Type;
MemoryMap->PhysicalStart = Entry->Start;
MemoryMap->NumberOfPages = RShiftU64 (Entry->End - Entry->Start + 1, EFI_PAGE_SHIFT);
MemoryMap = NEXT_MEMORY_DESCRIPTOR (MemoryMap, Size);
}

View File

@@ -27,12 +27,12 @@ EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst = {
SmmInstallConfigurationTable,
{
{
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmMemRead
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmMemWrite
(EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5, // SmmMemRead
(EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5 // SmmMemWrite
},
{
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmIoRead
(EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmIoWrite
(EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5, // SmmIoRead
(EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5 // SmmIoWrite
}
},
SmmAllocatePool,
@@ -81,30 +81,30 @@ BOOLEAN mAcpiS3Enable = FALSE;
// Table of SMI Handlers that are registered by the SMM Core when it is initialized
//
SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] = {
{ SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },
{ SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE },
{ SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },
{ SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE },
{ SmmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE },
{ SmmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, TRUE },
{ NULL, NULL, NULL, FALSE }
{ SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },
{ SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE },
{ SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },
{ SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE },
{ SmmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE },
{ SmmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, TRUE },
{ NULL, NULL, NULL, FALSE }
};
//
// Table of SMI Handlers that are registered by the SMM Core when it is initialized
//
SMM_CORE_SMI_HANDLERS mSmmCoreS3SmiHandlers[] = {
{ SmmS3SmmInitDoneHandler, &gEdkiiS3SmmInitDoneGuid, NULL, FALSE },
{ SmmEndOfS3ResumeHandler, &gEdkiiEndOfS3ResumeGuid, NULL, FALSE },
{ NULL, NULL, NULL, FALSE }
{ SmmS3SmmInitDoneHandler, &gEdkiiS3SmmInitDoneGuid, NULL, FALSE },
{ SmmEndOfS3ResumeHandler, &gEdkiiEndOfS3ResumeGuid, NULL, FALSE },
{ NULL, NULL, NULL, FALSE }
};
UINTN mFullSmramRangeCount;
EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
UINTN mFullSmramRangeCount;
EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
/**
Place holder function until all the SMM System Table Service are available.
@@ -123,11 +123,11 @@ EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
EFI_STATUS
EFIAPI
SmmEfiNotAvailableYetArg5 (
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4,
UINTN Arg5
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4,
UINTN Arg5
)
{
//
@@ -163,20 +163,20 @@ SmmLegacyBootHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
UINTN Index;
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
UINTN Index;
//
// Install SMM Legacy Boot protocol.
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiSmmLegacyBootProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiSmmLegacyBootProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
mInLegacyBoot = TRUE;
@@ -218,20 +218,20 @@ SmmExitBootServicesHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
UINTN Index;
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
UINTN Index;
//
// Install SMM Exit Boot Services protocol.
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiSmmExitBootServicesProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiSmmExitBootServicesProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
SmiHandlerUnRegister (DispatchHandle);
@@ -269,10 +269,10 @@ SmmExitBootServicesHandler (
EFI_STATUS
EFIAPI
SmmS3EntryCallBack (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
mDuringS3Resume = TRUE;
@@ -302,19 +302,19 @@ SmmReadyToBootHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
//
// Install SMM Ready To Boot protocol.
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiSmmReadyToBootProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiSmmReadyToBootProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
SmiHandlerUnRegister (DispatchHandle);
@@ -365,12 +365,12 @@ SmmReadyToLockHandler (
// Install SMM Ready to lock protocol
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEfiSmmReadyToLockProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEfiSmmReadyToLockProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
//
// Make sure SMM CPU I/O 2 Protocol has been installed into the handle database
@@ -381,9 +381,10 @@ SmmReadyToLockHandler (
// Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
//
DEBUG_CODE_BEGIN ();
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
}
DEBUG_CODE_END ();
//
@@ -396,7 +397,7 @@ SmmReadyToLockHandler (
// evaluated to false if this is a debug build
//
DEBUG_CODE_BEGIN ();
SmmDisplayDiscoveredNotDispatched ();
SmmDisplayDiscoveredNotDispatched ();
DEBUG_CODE_END ();
//
@@ -433,11 +434,11 @@ SmmEndOfDxeHandler (
IN OUT UINTN *CommBufferSize OPTIONAL
)
{
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch;
EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
EFI_HANDLE S3EntryHandle;
EFI_STATUS Status;
EFI_HANDLE SmmHandle;
EFI_SMM_SX_DISPATCH2_PROTOCOL *SxDispatch;
EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
EFI_HANDLE S3EntryHandle;
DEBUG ((DEBUG_INFO, "SmmEndOfDxeHandler\n"));
@@ -445,12 +446,12 @@ SmmEndOfDxeHandler (
// Install SMM EndOfDxe protocol
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEfiSmmEndOfDxeProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEfiSmmEndOfDxeProtocolGuid,
EFI_NATIVE_INTERFACE,
NULL
);
if (mAcpiS3Enable) {
//
@@ -468,12 +469,12 @@ SmmEndOfDxeHandler (
//
EntryRegisterContext.Type = SxS3;
EntryRegisterContext.Phase = SxEntry;
Status = SxDispatch->Register (
SxDispatch,
SmmS3EntryCallBack,
&EntryRegisterContext,
&S3EntryHandle
);
Status = SxDispatch->Register (
SxDispatch,
SmmS3EntryCallBack,
&EntryRegisterContext,
&S3EntryHandle
);
ASSERT_EFI_ERROR (Status);
}
}
@@ -518,12 +519,12 @@ SmmS3SmmInitDoneHandler (
// Install SMM S3SmmInitDone protocol
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiS3SmmInitDoneGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiS3SmmInitDoneGuid,
EFI_NATIVE_INTERFACE,
NULL
);
ASSERT_EFI_ERROR (Status);
//
@@ -531,10 +532,10 @@ SmmS3SmmInitDoneHandler (
// installation event.
//
Status = SmmUninstallProtocolInterface (
SmmHandle,
&gEdkiiS3SmmInitDoneGuid,
NULL
);
SmmHandle,
&gEdkiiS3SmmInitDoneGuid,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
@@ -577,12 +578,12 @@ SmmEndOfS3ResumeHandler (
// Install SMM EndOfS3Resume protocol
//
SmmHandle = NULL;
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiEndOfS3ResumeGuid,
EFI_NATIVE_INTERFACE,
NULL
);
Status = SmmInstallProtocolInterface (
&SmmHandle,
&gEdkiiEndOfS3ResumeGuid,
EFI_NATIVE_INTERFACE,
NULL
);
ASSERT_EFI_ERROR (Status);
//
@@ -590,10 +591,10 @@ SmmEndOfS3ResumeHandler (
// installation event.
//
Status = SmmUninstallProtocolInterface (
SmmHandle,
&gEdkiiEndOfS3ResumeGuid,
NULL
);
SmmHandle,
&gEdkiiEndOfS3ResumeGuid,
NULL
);
ASSERT_EFI_ERROR (Status);
mDuringS3Resume = FALSE;
@@ -614,10 +615,10 @@ SmmEndOfS3ResumeHandler (
**/
BOOLEAN
InternalIsBufferOverlapped (
IN UINT8 *Buff1,
IN UINTN Size1,
IN UINT8 *Buff2,
IN UINTN Size2
IN UINT8 *Buff1,
IN UINTN Size1,
IN UINT8 *Buff2,
IN UINTN Size2
)
{
//
@@ -644,7 +645,7 @@ VOID
EFIAPI
SmmEntryPoint (
IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext
)
)
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
@@ -693,9 +694,9 @@ SmmEntryPoint (
// Synchronous SMI for SMM Core or request from Communicate protocol
//
IsOverlapped = InternalIsBufferOverlapped (
(UINT8 *) CommunicationBuffer,
(UINT8 *)CommunicationBuffer,
BufferSize,
(UINT8 *) gSmmCorePrivate,
(UINT8 *)gSmmCorePrivate,
sizeof (*gSmmCorePrivate)
);
if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) || IsOverlapped) {
@@ -705,23 +706,23 @@ SmmEntryPoint (
// return EFI_INVALID_PARAMETER
//
gSmmCorePrivate->CommunicationBuffer = NULL;
gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
} else {
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
Status = SmiManage (
&CommunicateHeader->HeaderGuid,
NULL,
CommunicateHeader->Data,
&BufferSize
);
BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
Status = SmiManage (
&CommunicateHeader->HeaderGuid,
NULL,
CommunicateHeader->Data,
&BufferSize
);
//
// Update CommunicationBuffer, BufferSize and ReturnStatus
// Communicate service finished, reset the pointer to CommBuffer to NULL
//
gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
gSmmCorePrivate->CommunicationBuffer = NULL;
gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
}
}
}
@@ -755,13 +756,13 @@ SmmCoreInstallLoadedImage (
VOID
)
{
EFI_STATUS Status;
EFI_HANDLE Handle;
EFI_STATUS Status;
EFI_HANDLE Handle;
//
// Allocate a Loaded Image Protocol in EfiBootServicesData
//
Status = gBS->AllocatePool (EfiBootServicesData, sizeof(EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);
Status = gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);
ASSERT_EFI_ERROR (Status);
ZeroMem (mSmmCoreLoadedImage, sizeof (EFI_LOADED_IMAGE_PROTOCOL));
@@ -769,9 +770,9 @@ SmmCoreInstallLoadedImage (
// Fill in the remaining fields of the Loaded Image Protocol instance.
// Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
//
mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
mSmmCoreLoadedImage->SystemTable = gST;
mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
mSmmCoreLoadedImage->SystemTable = gST;
mSmmCoreLoadedImage->ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
mSmmCoreLoadedImage->ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
@@ -784,7 +785,8 @@ SmmCoreInstallLoadedImage (
Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&Handle,
&gEfiLoadedImageProtocolGuid, mSmmCoreLoadedImage,
&gEfiLoadedImageProtocolGuid,
mSmmCoreLoadedImage,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -792,40 +794,40 @@ SmmCoreInstallLoadedImage (
//
// Allocate a Loaded Image Protocol in SMM
//
Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof(EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry);
ASSERT_EFI_ERROR(Status);
Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof (EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry);
ASSERT_EFI_ERROR (Status);
ZeroMem (mSmmCoreDriverEntry, sizeof(EFI_SMM_DRIVER_ENTRY));
ZeroMem (mSmmCoreDriverEntry, sizeof (EFI_SMM_DRIVER_ENTRY));
//
// Fill in the remaining fields of the Loaded Image Protocol instance.
//
mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
mSmmCoreDriverEntry->SmmLoadedImage.ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST;
mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST;
mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
mSmmCoreDriverEntry->SmmLoadedImage.ImageCodeType = EfiRuntimeServicesCode;
mSmmCoreDriverEntry->SmmLoadedImage.ImageDataType = EfiRuntimeServicesData;
mSmmCoreDriverEntry->ImageEntryPoint = gSmmCorePrivate->PiSmmCoreEntryPoint;
mSmmCoreDriverEntry->ImageBuffer = gSmmCorePrivate->PiSmmCoreImageBase;
mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES((UINTN)gSmmCorePrivate->PiSmmCoreImageSize);
mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)gSmmCorePrivate->PiSmmCoreImageSize);
//
// Create a new image handle in the SMM handle database for the SMM Driver
//
mSmmCoreDriverEntry->SmmImageHandle = NULL;
Status = SmmInstallProtocolInterface (
&mSmmCoreDriverEntry->SmmImageHandle,
&gEfiLoadedImageProtocolGuid,
EFI_NATIVE_INTERFACE,
&mSmmCoreDriverEntry->SmmLoadedImage
);
ASSERT_EFI_ERROR(Status);
Status = SmmInstallProtocolInterface (
&mSmmCoreDriverEntry->SmmImageHandle,
&gEfiLoadedImageProtocolGuid,
EFI_NATIVE_INTERFACE,
&mSmmCoreDriverEntry->SmmLoadedImage
);
ASSERT_EFI_ERROR (Status);
return ;
return;
}
/**
@@ -876,7 +878,7 @@ SmmMain (
// Copy FullSmramRanges to SMRAM
//
mFullSmramRangeCount = gSmmCorePrivate->SmramRangeCount;
mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
ASSERT (mFullSmramRanges != NULL);
CopyMem (mFullSmramRanges, gSmmCorePrivate->SmramRanges, mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));

View File

@@ -62,10 +62,10 @@
// Used to build a table of SMI Handlers that the SMM Core registers
//
typedef struct {
EFI_SMM_HANDLER_ENTRY_POINT2 Handler;
EFI_GUID *HandlerType;
EFI_HANDLE DispatchHandle;
BOOLEAN UnRegister;
EFI_SMM_HANDLER_ENTRY_POINT2 Handler;
EFI_GUID *HandlerType;
EFI_HANDLE DispatchHandle;
BOOLEAN UnRegister;
} SMM_CORE_SMI_HANDLERS;
//
@@ -74,89 +74,89 @@ typedef struct {
#define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
typedef struct {
UINTN Signature;
LIST_ENTRY AllEntries; // All entries
typedef struct {
UINTN Signature;
LIST_ENTRY AllEntries; // All entries
EFI_GUID HandlerType; // Type of interrupt
LIST_ENTRY SmiHandlers; // All handlers
EFI_GUID HandlerType; // Type of interrupt
LIST_ENTRY SmiHandlers; // All handlers
} SMI_ENTRY;
#define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
typedef struct {
UINTN Signature;
LIST_ENTRY Link; // Link on SMI_ENTRY.SmiHandlers
EFI_SMM_HANDLER_ENTRY_POINT2 Handler; // The smm handler's entry point
UINTN CallerAddr; // The address of caller who register the SMI handler.
SMI_ENTRY *SmiEntry;
VOID *Context; // for profile
UINTN ContextSize; // for profile
typedef struct {
UINTN Signature;
LIST_ENTRY Link; // Link on SMI_ENTRY.SmiHandlers
EFI_SMM_HANDLER_ENTRY_POINT2 Handler; // The smm handler's entry point
UINTN CallerAddr; // The address of caller who register the SMI handler.
SMI_ENTRY *SmiEntry;
VOID *Context; // for profile
UINTN ContextSize; // for profile
} SMI_HANDLER;
//
// Structure for recording the state of an SMM Driver
//
#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
#define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
typedef struct {
UINTN Signature;
LIST_ENTRY Link; // mDriverList
UINTN Signature;
LIST_ENTRY Link; // mDriverList
LIST_ENTRY ScheduledLink; // mScheduledQueue
LIST_ENTRY ScheduledLink; // mScheduledQueue
EFI_HANDLE FvHandle;
EFI_GUID FileName;
EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
EFI_HANDLE FvHandle;
EFI_GUID FileName;
EFI_DEVICE_PATH_PROTOCOL *FvFileDevicePath;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
VOID *Depex;
UINTN DepexSize;
VOID *Depex;
UINTN DepexSize;
BOOLEAN Before;
BOOLEAN After;
EFI_GUID BeforeAfterGuid;
BOOLEAN Before;
BOOLEAN After;
EFI_GUID BeforeAfterGuid;
BOOLEAN Dependent;
BOOLEAN Scheduled;
BOOLEAN Initialized;
BOOLEAN DepexProtocolError;
BOOLEAN Dependent;
BOOLEAN Scheduled;
BOOLEAN Initialized;
BOOLEAN DepexProtocolError;
EFI_HANDLE ImageHandle;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_HANDLE ImageHandle;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
//
// Image EntryPoint in SMRAM
//
PHYSICAL_ADDRESS ImageEntryPoint;
PHYSICAL_ADDRESS ImageEntryPoint;
//
// Image Buffer in SMRAM
//
PHYSICAL_ADDRESS ImageBuffer;
PHYSICAL_ADDRESS ImageBuffer;
//
// Image Page Number
//
UINTN NumberOfPage;
EFI_HANDLE SmmImageHandle;
EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;
UINTN NumberOfPage;
EFI_HANDLE SmmImageHandle;
EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage;
} EFI_SMM_DRIVER_ENTRY;
#define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','d','l')
#define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','d','l')
///
/// IHANDLE - contains a list of protocol handles
///
typedef struct {
UINTN Signature;
UINTN Signature;
/// All handles list of IHANDLE
LIST_ENTRY AllHandles;
LIST_ENTRY AllHandles;
/// List of PROTOCOL_INTERFACE's for this handle
LIST_ENTRY Protocols;
UINTN LocateRequest;
LIST_ENTRY Protocols;
UINTN LocateRequest;
} IHANDLE;
#define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')
#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')
///
/// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
@@ -164,15 +164,15 @@ typedef struct {
/// with a list of registered notifies.
///
typedef struct {
UINTN Signature;
UINTN Signature;
/// Link Entry inserted to mProtocolDatabase
LIST_ENTRY AllEntries;
LIST_ENTRY AllEntries;
/// ID of the protocol
EFI_GUID ProtocolID;
EFI_GUID ProtocolID;
/// All protocol interfaces
LIST_ENTRY Protocols;
LIST_ENTRY Protocols;
/// Registered notification handlers
LIST_ENTRY Notify;
LIST_ENTRY Notify;
} PROTOCOL_ENTRY;
#define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('s','p','i','f')
@@ -182,33 +182,33 @@ typedef struct {
/// with a protocol interface structure
///
typedef struct {
UINTN Signature;
UINTN Signature;
/// Link on IHANDLE.Protocols
LIST_ENTRY Link;
LIST_ENTRY Link;
/// Back pointer
IHANDLE *Handle;
IHANDLE *Handle;
/// Link on PROTOCOL_ENTRY.Protocols
LIST_ENTRY ByProtocol;
LIST_ENTRY ByProtocol;
/// The protocol ID
PROTOCOL_ENTRY *Protocol;
PROTOCOL_ENTRY *Protocol;
/// The interface value
VOID *Interface;
VOID *Interface;
} PROTOCOL_INTERFACE;
#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','t','n')
#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','t','n')
///
/// PROTOCOL_NOTIFY - used for each register notification for a protocol
///
typedef struct {
UINTN Signature;
PROTOCOL_ENTRY *Protocol;
UINTN Signature;
PROTOCOL_ENTRY *Protocol;
/// All notifications for this protocol
LIST_ENTRY Link;
LIST_ENTRY Link;
/// Notification function
EFI_SMM_NOTIFY_FN Function;
EFI_SMM_NOTIFY_FN Function;
/// Last position notified
LIST_ENTRY *Position;
LIST_ENTRY *Position;
} PROTOCOL_NOTIFY;
//
@@ -253,9 +253,9 @@ EFI_STATUS
EFIAPI
SmmInstallConfigurationTable (
IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable,
IN CONST EFI_GUID *Guid,
IN VOID *Table,
IN UINTN TableSize
IN CONST EFI_GUID *Guid,
IN VOID *Table,
IN UINTN TableSize
);
/**
@@ -275,10 +275,10 @@ SmmInstallConfigurationTable (
EFI_STATUS
EFIAPI
SmmInstallProtocolInterface (
IN OUT EFI_HANDLE *UserHandle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface
IN OUT EFI_HANDLE *UserHandle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface
);
/**
@@ -300,10 +300,10 @@ SmmInstallProtocolInterface (
EFI_STATUS
EFIAPI
SmmAllocatePages (
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *Memory
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *Memory
);
/**
@@ -326,11 +326,11 @@ SmmAllocatePages (
EFI_STATUS
EFIAPI
SmmInternalAllocatePages (
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *Memory,
IN BOOLEAN NeedGuard
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN NumberOfPages,
OUT EFI_PHYSICAL_ADDRESS *Memory,
IN BOOLEAN NeedGuard
);
/**
@@ -347,8 +347,8 @@ SmmInternalAllocatePages (
EFI_STATUS
EFIAPI
SmmFreePages (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages
);
/**
@@ -367,9 +367,9 @@ SmmFreePages (
EFI_STATUS
EFIAPI
SmmInternalFreePages (
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages,
IN BOOLEAN IsGuarded
IN EFI_PHYSICAL_ADDRESS Memory,
IN UINTN NumberOfPages,
IN BOOLEAN IsGuarded
);
/**
@@ -388,9 +388,9 @@ SmmInternalFreePages (
EFI_STATUS
EFIAPI
SmmAllocatePool (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN Size,
OUT VOID **Buffer
IN EFI_MEMORY_TYPE PoolType,
IN UINTN Size,
OUT VOID **Buffer
);
/**
@@ -409,9 +409,9 @@ SmmAllocatePool (
EFI_STATUS
EFIAPI
SmmInternalAllocatePool (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN Size,
OUT VOID **Buffer
IN EFI_MEMORY_TYPE PoolType,
IN UINTN Size,
OUT VOID **Buffer
);
/**
@@ -426,7 +426,7 @@ SmmInternalAllocatePool (
EFI_STATUS
EFIAPI
SmmFreePool (
IN VOID *Buffer
IN VOID *Buffer
);
/**
@@ -441,7 +441,7 @@ SmmFreePool (
EFI_STATUS
EFIAPI
SmmInternalFreePool (
IN VOID *Buffer
IN VOID *Buffer
);
/**
@@ -463,11 +463,11 @@ SmmInternalFreePool (
**/
EFI_STATUS
SmmInstallProtocolInterfaceNotify (
IN OUT EFI_HANDLE *UserHandle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface,
IN BOOLEAN Notify
IN OUT EFI_HANDLE *UserHandle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface,
IN BOOLEAN Notify
);
/**
@@ -486,9 +486,9 @@ SmmInstallProtocolInterfaceNotify (
EFI_STATUS
EFIAPI
SmmUninstallProtocolInterface (
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol,
IN VOID *Interface
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol,
IN VOID *Interface
);
/**
@@ -505,9 +505,9 @@ SmmUninstallProtocolInterface (
EFI_STATUS
EFIAPI
SmmHandleProtocol (
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol,
OUT VOID **Interface
IN EFI_HANDLE UserHandle,
IN EFI_GUID *Protocol,
OUT VOID **Interface
);
/**
@@ -526,9 +526,9 @@ SmmHandleProtocol (
EFI_STATUS
EFIAPI
SmmRegisterProtocolNotify (
IN CONST EFI_GUID *Protocol,
IN EFI_SMM_NOTIFY_FN Function,
OUT VOID **Registration
IN CONST EFI_GUID *Protocol,
IN EFI_SMM_NOTIFY_FN Function,
OUT VOID **Registration
);
/**
@@ -552,11 +552,11 @@ SmmRegisterProtocolNotify (
EFI_STATUS
EFIAPI
SmmLocateHandle (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer
);
/**
@@ -632,10 +632,10 @@ SmmLocateHandleBuffer (
EFI_STATUS
EFIAPI
SmiManage (
IN CONST EFI_GUID *HandlerType,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN CONST EFI_GUID *HandlerType,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -652,9 +652,9 @@ SmiManage (
EFI_STATUS
EFIAPI
SmiHandlerRegister (
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
IN CONST EFI_GUID *HandlerType OPTIONAL,
OUT EFI_HANDLE *DispatchHandle
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
IN CONST EFI_GUID *HandlerType OPTIONAL,
OUT EFI_HANDLE *DispatchHandle
);
/**
@@ -669,7 +669,7 @@ SmiHandlerRegister (
EFI_STATUS
EFIAPI
SmiHandlerUnRegister (
IN EFI_HANDLE DispatchHandle
IN EFI_HANDLE DispatchHandle
);
/**
@@ -688,10 +688,10 @@ SmiHandlerUnRegister (
EFI_STATUS
EFIAPI
SmmDriverDispatchHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -710,10 +710,10 @@ SmmDriverDispatchHandler (
EFI_STATUS
EFIAPI
SmmLegacyBootHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -732,10 +732,10 @@ SmmLegacyBootHandler (
EFI_STATUS
EFIAPI
SmmReadyToLockHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -754,10 +754,10 @@ SmmReadyToLockHandler (
EFI_STATUS
EFIAPI
SmmEndOfDxeHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -776,10 +776,10 @@ SmmEndOfDxeHandler (
EFI_STATUS
EFIAPI
SmmExitBootServicesHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -798,10 +798,10 @@ SmmExitBootServicesHandler (
EFI_STATUS
EFIAPI
SmmReadyToBootHandler (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL
);
/**
@@ -865,15 +865,15 @@ SmmEndOfS3ResumeHandler (
EFI_STATUS
EFIAPI
SmmEfiNotAvailableYetArg5 (
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4,
UINTN Arg5
UINTN Arg1,
UINTN Arg2,
UINTN Arg3,
UINTN Arg4,
UINTN Arg5
);
//
//Functions used during debug builds
// Functions used during debug builds
//
/**
@@ -897,10 +897,10 @@ SmmDisplayDiscoveredNotDispatched (
**/
VOID
SmmAddMemoryRegion (
IN EFI_PHYSICAL_ADDRESS MemBase,
IN UINT64 MemLength,
IN EFI_MEMORY_TYPE Type,
IN UINT64 Attributes
IN EFI_PHYSICAL_ADDRESS MemBase,
IN UINT64 MemLength,
IN EFI_MEMORY_TYPE Type,
IN UINT64 Attributes
);
/**
@@ -914,8 +914,8 @@ SmmAddMemoryRegion (
**/
PROTOCOL_ENTRY *
SmmFindProtocolEntry (
IN EFI_GUID *Protocol,
IN BOOLEAN Create
IN EFI_GUID *Protocol,
IN BOOLEAN Create
);
/**
@@ -926,7 +926,7 @@ SmmFindProtocolEntry (
**/
VOID
SmmNotifyProtocol (
IN PROTOCOL_INTERFACE *Prot
IN PROTOCOL_INTERFACE *Prot
);
/**
@@ -943,9 +943,9 @@ SmmNotifyProtocol (
**/
PROTOCOL_INTERFACE *
SmmFindProtocolInterface (
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
);
/**
@@ -960,9 +960,9 @@ SmmFindProtocolInterface (
**/
PROTOCOL_INTERFACE *
SmmRemoveInterfaceFromProtocol (
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
IN IHANDLE *Handle,
IN EFI_GUID *Protocol,
IN VOID *Interface
);
/**
@@ -979,7 +979,7 @@ SmmRemoveInterfaceFromProtocol (
**/
BOOLEAN
SmmIsSchedulable (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry
IN EFI_SMM_DRIVER_ENTRY *DriverEntry
);
//
@@ -1018,8 +1018,8 @@ SmramProfileInstallProtocol (
**/
EFI_STATUS
RegisterSmramProfileImage (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
IN BOOLEAN RegisterToDxe
IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
IN BOOLEAN RegisterToDxe
);
/**
@@ -1036,8 +1036,8 @@ RegisterSmramProfileImage (
**/
EFI_STATUS
UnregisterSmramProfileImage (
IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
IN BOOLEAN UnregisterToDxe
IN EFI_SMM_DRIVER_ENTRY *DriverEntry,
IN BOOLEAN UnregisterToDxe
);
/**
@@ -1171,12 +1171,12 @@ SmmCoreInitializeSmiHandlerProfile (
EFI_STATUS
EFIAPI
SmiHandlerProfileRegisterHandler (
IN SMI_HANDLER_PROFILE_PROTOCOL *This,
IN EFI_GUID *HandlerGuid,
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
IN PHYSICAL_ADDRESS CallerAddress,
IN VOID *Context OPTIONAL,
IN UINTN ContextSize OPTIONAL
IN SMI_HANDLER_PROFILE_PROTOCOL *This,
IN EFI_GUID *HandlerGuid,
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
IN PHYSICAL_ADDRESS CallerAddress,
IN VOID *Context OPTIONAL,
IN UINTN ContextSize OPTIONAL
);
/**
@@ -1199,17 +1199,17 @@ SmiHandlerProfileRegisterHandler (
EFI_STATUS
EFIAPI
SmiHandlerProfileUnregisterHandler (
IN SMI_HANDLER_PROFILE_PROTOCOL *This,
IN EFI_GUID *HandlerGuid,
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
IN VOID *Context OPTIONAL,
IN UINTN ContextSize OPTIONAL
IN SMI_HANDLER_PROFILE_PROTOCOL *This,
IN EFI_GUID *HandlerGuid,
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
IN VOID *Context OPTIONAL,
IN UINTN ContextSize OPTIONAL
);
extern UINTN mFullSmramRangeCount;
extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
extern UINTN mFullSmramRangeCount;
extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
extern EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
@@ -1218,8 +1218,8 @@ extern EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
//
typedef struct {
LIST_ENTRY Link;
UINTN NumberOfPages;
LIST_ENTRY Link;
UINTN NumberOfPages;
} FREE_PAGE_LIST;
extern LIST_ENTRY mSmmMemoryMap;
@@ -1245,31 +1245,31 @@ extern LIST_ENTRY mSmmMemoryMap;
//
#define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
#define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')
#define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')
typedef struct {
UINT32 Signature;
BOOLEAN Available;
EFI_MEMORY_TYPE Type;
UINTN Size;
UINT32 Signature;
BOOLEAN Available;
EFI_MEMORY_TYPE Type;
UINTN Size;
} POOL_HEADER;
#define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')
#define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')
typedef struct {
UINT32 Signature;
UINT32 Reserved;
UINTN Size;
UINT32 Signature;
UINT32 Reserved;
UINTN Size;
} POOL_TAIL;
#define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
#define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
#define HEAD_TO_TAIL(a) \
((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
typedef struct {
POOL_HEADER Header;
LIST_ENTRY Link;
POOL_HEADER Header;
LIST_ENTRY Link;
} FREE_POOL_HEADER;
typedef enum {
@@ -1292,9 +1292,9 @@ extern LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];
**/
UINTN
InternalAllocPagesOnOneNode (
IN OUT FREE_PAGE_LIST *Pages,
IN UINTN NumberOfPages,
IN UINTN MaxAddress
IN OUT FREE_PAGE_LIST *Pages,
IN UINTN NumberOfPages,
IN UINTN MaxAddress
);
/**

View File

@@ -42,26 +42,26 @@
/// thos structure.
///
typedef struct {
UINTN Signature;
UINTN Signature;
///
/// The ImageHandle passed into the entry point of the SMM IPL. This ImageHandle
/// is used by the SMM Core to fill in the ParentImageHandle field of the Loaded
/// Image Protocol for each SMM Driver that is dispatched by the SMM Core.
///
EFI_HANDLE SmmIplImageHandle;
EFI_HANDLE SmmIplImageHandle;
///
/// The number of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM
/// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.
///
UINTN SmramRangeCount;
UINTN SmramRangeCount;
///
/// A table of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM
/// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.
///
EFI_SMRAM_DESCRIPTOR *SmramRanges;
EFI_SMRAM_DESCRIPTOR *SmramRanges;
///
/// The SMM Foundation Entry Point. The SMM Core fills in this field when the
@@ -72,48 +72,48 @@ typedef struct {
/// the SMM Foundation Entry Point as soon as the SMM Configuration Protocol is
/// available.
///
EFI_SMM_ENTRY_POINT SmmEntryPoint;
EFI_SMM_ENTRY_POINT SmmEntryPoint;
///
/// Boolean flag set to TRUE while an SMI is being processed by the SMM Core.
///
BOOLEAN SmmEntryPointRegistered;
BOOLEAN SmmEntryPointRegistered;
///
/// Boolean flag set to TRUE while an SMI is being processed by the SMM Core.
///
BOOLEAN InSmm;
BOOLEAN InSmm;
///
/// This field is set by the SMM Core then the SMM Core is initialized. This field is
/// used by the SMM Base 2 Protocol and SMM Communication Protocol implementations in
/// the SMM IPL.
///
EFI_SMM_SYSTEM_TABLE2 *Smst;
EFI_SMM_SYSTEM_TABLE2 *Smst;
///
/// This field is used by the SMM Communication Protocol to pass a buffer into
/// a software SMI handler and for the software SMI handler to pass a buffer back to
/// the caller of the SMM Communication Protocol.
///
VOID *CommunicationBuffer;
VOID *CommunicationBuffer;
///
/// This field is used by the SMM Communication Protocol to pass the size of a buffer,
/// in bytes, into a software SMI handler and for the software SMI handler to pass the
/// size, in bytes, of a buffer back to the caller of the SMM Communication Protocol.
///
UINTN BufferSize;
UINTN BufferSize;
///
/// This field is used by the SMM Communication Protocol to pass the return status from
/// a software SMI handler back to the caller of the SMM Communication Protocol.
///
EFI_STATUS ReturnStatus;
EFI_STATUS ReturnStatus;
EFI_PHYSICAL_ADDRESS PiSmmCoreImageBase;
UINT64 PiSmmCoreImageSize;
EFI_PHYSICAL_ADDRESS PiSmmCoreEntryPoint;
EFI_PHYSICAL_ADDRESS PiSmmCoreImageBase;
UINT64 PiSmmCoreImageSize;
EFI_PHYSICAL_ADDRESS PiSmmCoreEntryPoint;
} SMM_CORE_PRIVATE_DATA;
#endif

View File

@@ -140,10 +140,10 @@ SmmCommunicationCommunicate (
EFI_STATUS
EFIAPI
SmmCommunicationMmCommunicate2 (
IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
IN OUT VOID *CommBufferPhysical,
IN OUT VOID *CommBufferVirtual,
IN OUT UINTN *CommSize OPTIONAL
IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
IN OUT VOID *CommBufferPhysical,
IN OUT VOID *CommBufferVirtual,
IN OUT UINTN *CommSize OPTIONAL
);
/**
@@ -239,13 +239,13 @@ SmmIplSetVirtualAddressNotify (
// notifications required by the SMM IPL
//
typedef struct {
BOOLEAN Protocol;
BOOLEAN CloseOnLock;
EFI_GUID *Guid;
EFI_EVENT_NOTIFY NotifyFunction;
VOID *NotifyContext;
EFI_TPL NotifyTpl;
EFI_EVENT Event;
BOOLEAN Protocol;
BOOLEAN CloseOnLock;
EFI_GUID *Guid;
EFI_EVENT_NOTIFY NotifyFunction;
VOID *NotifyContext;
EFI_TPL NotifyTpl;
EFI_EVENT Event;
} SMM_IPL_EVENT_NOTIFICATION;
//
@@ -309,8 +309,8 @@ BOOLEAN mEndOfDxe = FALSE;
EFI_PHYSICAL_ADDRESS mSmramCacheBase;
UINT64 mSmramCacheSize;
EFI_SMM_COMMUNICATE_HEADER mCommunicateHeader;
EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *mLMFAConfigurationTable = NULL;
EFI_SMM_COMMUNICATE_HEADER mCommunicateHeader;
EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *mLMFAConfigurationTable = NULL;
//
// Table of Protocol notification and GUIDed Event notifications that the SMM IPL requires
@@ -389,15 +389,15 @@ SMM_IPL_EVENT_NOTIFICATION mSmmIplEvents[] = {
**/
VOID
GetSmramCacheRange (
IN EFI_SMRAM_DESCRIPTOR *SmramRange,
OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
OUT UINT64 *SmramCacheSize
IN EFI_SMRAM_DESCRIPTOR *SmramRange,
OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
OUT UINT64 *SmramCacheSize
)
{
UINTN Index;
EFI_PHYSICAL_ADDRESS RangeCpuStart;
UINT64 RangePhysicalSize;
BOOLEAN FoundAjacentRange;
UINTN Index;
EFI_PHYSICAL_ADDRESS RangeCpuStart;
UINT64 RangePhysicalSize;
BOOLEAN FoundAjacentRange;
*SmramCacheBase = SmramRange->CpuStart;
*SmramCacheSize = SmramRange->PhysicalSize;
@@ -407,17 +407,16 @@ GetSmramCacheRange (
for (Index = 0; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
RangeCpuStart = gSmmCorePrivate->SmramRanges[Index].CpuStart;
RangePhysicalSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
if (RangeCpuStart < *SmramCacheBase && *SmramCacheBase == (RangeCpuStart + RangePhysicalSize)) {
if ((RangeCpuStart < *SmramCacheBase) && (*SmramCacheBase == (RangeCpuStart + RangePhysicalSize))) {
*SmramCacheBase = RangeCpuStart;
*SmramCacheSize += RangePhysicalSize;
FoundAjacentRange = TRUE;
} else if ((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart && RangePhysicalSize > 0) {
} else if (((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart) && (RangePhysicalSize > 0)) {
*SmramCacheSize += RangePhysicalSize;
FoundAjacentRange = TRUE;
}
}
} while (FoundAjacentRange);
}
/**
@@ -465,7 +464,7 @@ SmmBase2GetSmstLocation (
OUT EFI_SMM_SYSTEM_TABLE2 **Smst
)
{
if ((This == NULL) ||(Smst == NULL)) {
if ((This == NULL) || (Smst == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -524,7 +523,7 @@ SmmCommunicationCommunicate (
return EFI_INVALID_PARAMETER;
}
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer;
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommBuffer;
if (CommSize == NULL) {
TempCommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + CommunicateHeader->MessageLength;
@@ -562,6 +561,7 @@ SmmCommunicationCommunicate (
if (CommSize != NULL) {
*CommSize = gSmmCorePrivate->BufferSize;
}
return gSmmCorePrivate->ReturnStatus;
}
@@ -571,7 +571,7 @@ SmmCommunicationCommunicate (
// has been called, then a direct invocation of the Software SMI is not allowed,
// so return EFI_INVALID_PARAMETER.
//
if (EfiGoneVirtual()) {
if (EfiGoneVirtual ()) {
return EFI_INVALID_PARAMETER;
}
@@ -585,19 +585,19 @@ SmmCommunicationCommunicate (
//
// Save current InSmm state and set InSmm state to TRUE
//
OldInSmm = gSmmCorePrivate->InSmm;
OldInSmm = gSmmCorePrivate->InSmm;
gSmmCorePrivate->InSmm = TRUE;
//
// Before SetVirtualAddressMap(), we are in SMM or SMRAM is open and unlocked, call SmiManage() directly.
//
TempCommSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
Status = gSmmCorePrivate->Smst->SmiManage (
&CommunicateHeader->HeaderGuid,
NULL,
CommunicateHeader->Data,
&TempCommSize
);
Status = gSmmCorePrivate->Smst->SmiManage (
&CommunicateHeader->HeaderGuid,
NULL,
CommunicateHeader->Data,
&TempCommSize
);
TempCommSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
if (CommSize != NULL) {
*CommSize = TempCommSize;
@@ -638,15 +638,17 @@ SmmCommunicationCommunicate (
EFI_STATUS
EFIAPI
SmmCommunicationMmCommunicate2 (
IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
IN OUT VOID *CommBufferPhysical,
IN OUT VOID *CommBufferVirtual,
IN OUT UINTN *CommSize OPTIONAL
IN CONST EFI_MM_COMMUNICATION2_PROTOCOL *This,
IN OUT VOID *CommBufferPhysical,
IN OUT VOID *CommBufferVirtual,
IN OUT UINTN *CommSize OPTIONAL
)
{
return SmmCommunicationCommunicate (&mSmmCommunication,
CommBufferPhysical,
CommSize);
return SmmCommunicationCommunicate (
&mSmmCommunication,
CommBufferPhysical,
CommSize
);
}
/**
@@ -663,14 +665,14 @@ SmmIplGuidedEventNotify (
IN VOID *Context
)
{
UINTN Size;
UINTN Size;
//
// Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
//
CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
mCommunicateHeader.MessageLength = 1;
mCommunicateHeader.Data[0] = 0;
mCommunicateHeader.Data[0] = 0;
//
// Generate the Software SMI and return the result
@@ -710,8 +712,8 @@ SmmIplDxeDispatchEventNotify (
IN VOID *Context
)
{
UINTN Size;
EFI_STATUS Status;
UINTN Size;
EFI_STATUS Status;
//
// Keep calling the SMM Core Dispatcher until there is no request to restart it.
@@ -724,7 +726,7 @@ SmmIplDxeDispatchEventNotify (
//
CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
mCommunicateHeader.MessageLength = 1;
mCommunicateHeader.Data[0] = 0;
mCommunicateHeader.Data[0] = 0;
//
// Generate the Software SMI and return the result
@@ -911,89 +913,94 @@ SmmIplSetVirtualAddressNotify (
@retval EFI_NOT_FOUND The image has no assigned fixed loading address.
**/
EFI_STATUS
GetPeCoffImageFixLoadingAssignedAddress(
GetPeCoffImageFixLoadingAssignedAddress (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
UINTN SectionHeaderOffset;
EFI_STATUS Status;
EFI_IMAGE_SECTION_HEADER SectionHeader;
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
EFI_PHYSICAL_ADDRESS FixLoadingAddress;
UINT16 Index;
UINTN Size;
UINT16 NumberOfSections;
EFI_PHYSICAL_ADDRESS SmramBase;
UINT64 SmmCodeSize;
UINT64 ValueInSectionHeader;
//
// Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
//
SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32(PcdLoadFixAddressSmmCodePageNumber));
UINTN SectionHeaderOffset;
EFI_STATUS Status;
EFI_IMAGE_SECTION_HEADER SectionHeader;
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
EFI_PHYSICAL_ADDRESS FixLoadingAddress;
UINT16 Index;
UINTN Size;
UINT16 NumberOfSections;
EFI_PHYSICAL_ADDRESS SmramBase;
UINT64 SmmCodeSize;
UINT64 ValueInSectionHeader;
FixLoadingAddress = 0;
Status = EFI_NOT_FOUND;
SmramBase = mLMFAConfigurationTable->SmramBase;
//
// Get PeHeader pointer
//
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
//
// Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
//
SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32 (PcdLoadFixAddressSmmCodePageNumber));
//
// Get base address from the first section header that doesn't point to code section.
//
for (Index = 0; Index < NumberOfSections; Index++) {
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
Status = ImageContext->ImageRead (
ImageContext->Handle,
SectionHeaderOffset,
&Size,
&SectionHeader
);
if (EFI_ERROR (Status)) {
return Status;
}
FixLoadingAddress = 0;
Status = EFI_NOT_FOUND;
SmramBase = mLMFAConfigurationTable->SmramBase;
//
// Get PeHeader pointer
//
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
Status = EFI_NOT_FOUND;
//
// Get base address from the first section header that doesn't point to code section.
//
for (Index = 0; Index < NumberOfSections; Index++) {
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
Status = ImageContext->ImageRead (
ImageContext->Handle,
SectionHeaderOffset,
&Size,
&SectionHeader
);
if (EFI_ERROR (Status)) {
return Status;
}
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
//
// Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
// first section header that doesn't point to code section in image header. And there is an assumption that when the
// feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers
// fields should NOT be Zero, or else, these 2 fields should be set to Zero
//
ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
if (ValueInSectionHeader != 0) {
//
// Found first section header that doesn't point to code section in which build tool saves the
// offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
//
FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
Status = EFI_NOT_FOUND;
if (SmramBase + SmmCodeSize > FixLoadingAddress && SmramBase <= FixLoadingAddress) {
//
// The assigned address is valid. Return the specified loading address
//
ImageContext->ImageAddress = FixLoadingAddress;
Status = EFI_SUCCESS;
}
}
break;
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoadingAddress, Status));
return Status;
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
//
// Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
// first section header that doesn't point to code section in image header. And there is an assumption that when the
// feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers
// fields should NOT be Zero, or else, these 2 fields should be set to Zero
//
ValueInSectionHeader = ReadUnaligned64 ((UINT64 *)&SectionHeader.PointerToRelocations);
if (ValueInSectionHeader != 0) {
//
// Found first section header that doesn't point to code section in which build tool saves the
// offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
//
FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
if ((SmramBase + SmmCodeSize > FixLoadingAddress) && (SmramBase <= FixLoadingAddress)) {
//
// The assigned address is valid. Return the specified loading address
//
ImageContext->ImageAddress = FixLoadingAddress;
Status = EFI_SUCCESS;
}
}
break;
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoadingAddress, Status));
return Status;
}
/**
Load the SMM Core image into SMRAM and executes the SMM Core from SMRAM.
@@ -1009,9 +1016,9 @@ GetPeCoffImageFixLoadingAssignedAddress(
**/
EFI_STATUS
ExecuteSmmCoreFromSmram (
IN OUT EFI_SMRAM_DESCRIPTOR *SmramRange,
IN OUT EFI_SMRAM_DESCRIPTOR *SmramRangeSmmCore,
IN VOID *Context
IN OUT EFI_SMRAM_DESCRIPTOR *SmramRange,
IN OUT EFI_SMRAM_DESCRIPTOR *SmramRangeSmmCore,
IN VOID *Context
)
{
EFI_STATUS Status;
@@ -1049,11 +1056,12 @@ ExecuteSmmCoreFromSmram (
if (EFI_ERROR (Status)) {
return Status;
}
//
// if Loading module at Fixed Address feature is enabled, the SMM core driver will be loaded to
// the address assigned by build tool.
//
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Get the fixed loading address assigned by Build tool
//
@@ -1066,23 +1074,23 @@ ExecuteSmmCoreFromSmram (
//
// Reserved Smram Region for SmmCore is not used, and remove it from SmramRangeCount.
//
gSmmCorePrivate->SmramRangeCount --;
gSmmCorePrivate->SmramRangeCount--;
} else {
DEBUG ((DEBUG_INFO, "LOADING MODULE FIXED ERROR: Loading module at fixed address at address failed\n"));
//
// Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
// specified by SmramRange
//
PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
//
// Align buffer on section boundary
@@ -1094,16 +1102,16 @@ ExecuteSmmCoreFromSmram (
// Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
// specified by SmramRange
//
PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
//
// Align buffer on section boundary
@@ -1150,7 +1158,7 @@ ExecuteSmmCoreFromSmram (
// Execute image
//
EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)ImageContext.EntryPoint;
Status = EntryPoint ((EFI_HANDLE)Context, gST);
Status = EntryPoint ((EFI_HANDLE)Context, gST);
}
}
@@ -1188,14 +1196,15 @@ SmmSplitSmramEntry (
IN OUT UINTN *FinalRangeCount
)
{
UINT64 RangeToCompareEnd;
UINT64 ReservedRangeToCompareEnd;
UINT64 RangeToCompareEnd;
UINT64 ReservedRangeToCompareEnd;
RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
(RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
(RangeToCompare->CpuStart < ReservedRangeToCompareEnd))
{
if (RangeToCompareEnd < ReservedRangeToCompareEnd) {
//
// RangeToCompare ReservedRangeToCompare
@@ -1222,14 +1231,14 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompare->PhysicalSize;
*FinalRangeCount += 1;
RangeToCompare->PhysicalSize = 0;
*FinalRangeCount += 1;
RangeToCompare->PhysicalSize = 0;
//
// 3. Update ReservedRanges[*ReservedRangeCount] and increment *ReservedRangeCount.
//
ReservedRanges[*ReservedRangeCount].SmramReservedStart = FinalRanges[*FinalRangeCount - 1].CpuStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
ReservedRanges[*ReservedRangeCount].SmramReservedSize = ReservedRangeToCompareEnd - RangeToCompareEnd;
*ReservedRangeCount += 1;
*ReservedRangeCount += 1;
} else {
//
// RangeToCompare ReservedRangeToCompare
@@ -1255,7 +1264,7 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompareEnd - RangeToCompare->CpuStart;
*FinalRangeCount += 1;
*FinalRangeCount += 1;
//
// 3. Update RangeToCompare.
//
@@ -1264,7 +1273,8 @@ SmmSplitSmramEntry (
RangeToCompare->PhysicalSize -= FinalRanges[*FinalRangeCount - 1].PhysicalSize;
}
} else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
(ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
(ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd))
{
if (ReservedRangeToCompareEnd < RangeToCompareEnd) {
//
// RangeToCompare ReservedRangeToCompare
@@ -1291,8 +1301,8 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompare->SmramReservedSize;
*FinalRangeCount += 1;
ReservedRangeToCompare->SmramReservedSize = 0;
*FinalRangeCount += 1;
ReservedRangeToCompare->SmramReservedSize = 0;
//
// 3. Update Ranges[*RangeCount] and increment *RangeCount.
//
@@ -1300,7 +1310,7 @@ SmmSplitSmramEntry (
Ranges[*RangeCount].PhysicalStart = FinalRanges[*FinalRangeCount - 1].PhysicalStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
Ranges[*RangeCount].RegionState = RangeToCompare->RegionState;
Ranges[*RangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompareEnd;
*RangeCount += 1;
*RangeCount += 1;
} else {
//
// RangeToCompare ReservedRangeToCompare
@@ -1327,7 +1337,7 @@ SmmSplitSmramEntry (
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompare->SmramReservedStart;
*FinalRangeCount += 1;
*FinalRangeCount += 1;
//
// 3. Update ReservedRangeToCompare.
//
@@ -1353,19 +1363,22 @@ SmmIsSmramOverlap (
IN EFI_SMM_RESERVED_SMRAM_REGION *ReservedRangeToCompare
)
{
UINT64 RangeToCompareEnd;
UINT64 ReservedRangeToCompareEnd;
UINT64 RangeToCompareEnd;
UINT64 ReservedRangeToCompareEnd;
RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
(RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
(RangeToCompare->CpuStart < ReservedRangeToCompareEnd))
{
return TRUE;
} else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
(ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
(ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd))
{
return TRUE;
}
return FALSE;
}
@@ -1383,35 +1396,35 @@ SmmIsSmramOverlap (
**/
EFI_SMRAM_DESCRIPTOR *
GetFullSmramRanges (
OUT UINTN *FullSmramRangeCount
OUT UINTN *FullSmramRangeCount
)
{
EFI_STATUS Status;
EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
UINTN Size;
UINTN Index;
UINTN Index2;
EFI_SMRAM_DESCRIPTOR *FullSmramRanges;
UINTN TempSmramRangeCount;
UINTN AdditionSmramRangeCount;
EFI_SMRAM_DESCRIPTOR *TempSmramRanges;
UINTN SmramRangeCount;
EFI_SMRAM_DESCRIPTOR *SmramRanges;
UINTN SmramReservedCount;
EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
UINTN MaxCount;
BOOLEAN Rescan;
EFI_STATUS Status;
EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
UINTN Size;
UINTN Index;
UINTN Index2;
EFI_SMRAM_DESCRIPTOR *FullSmramRanges;
UINTN TempSmramRangeCount;
UINTN AdditionSmramRangeCount;
EFI_SMRAM_DESCRIPTOR *TempSmramRanges;
UINTN SmramRangeCount;
EFI_SMRAM_DESCRIPTOR *SmramRanges;
UINTN SmramReservedCount;
EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
UINTN MaxCount;
BOOLEAN Rescan;
//
// Get SMM Configuration Protocol if it is present.
//
SmmConfiguration = NULL;
Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **) &SmmConfiguration);
Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **)&SmmConfiguration);
//
// Get SMRAM information.
//
Size = 0;
Size = 0;
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, NULL);
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
@@ -1431,7 +1444,7 @@ GetFullSmramRanges (
// Reserve one entry for SMM Core in the full SMRAM ranges.
//
AdditionSmramRangeCount = 1;
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Reserve two entries for all SMM drivers and SMM Core in the full SMRAM ranges.
//
@@ -1443,8 +1456,8 @@ GetFullSmramRanges (
// No reserved SMRAM entry from SMM Configuration Protocol.
//
*FullSmramRangeCount = SmramRangeCount + AdditionSmramRangeCount;
Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocateZeroPool (Size);
Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocateZeroPool (Size);
ASSERT (FullSmramRanges != NULL);
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, FullSmramRanges);
@@ -1490,19 +1503,19 @@ GetFullSmramRanges (
//
MaxCount = SmramRangeCount + 2 * SmramReservedCount;
Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *) AllocatePool (Size);
Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *)AllocatePool (Size);
ASSERT (SmramReservedRanges != NULL);
for (Index = 0; Index < SmramReservedCount; Index++) {
CopyMem (&SmramReservedRanges[Index], &SmmConfiguration->SmramReservedRegions[Index], sizeof (EFI_SMM_RESERVED_SMRAM_REGION));
}
Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
ASSERT (TempSmramRanges != NULL);
TempSmramRangeCount = 0;
SmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
SmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
ASSERT (SmramRanges != NULL);
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, SmramRanges);
ASSERT_EFI_ERROR (Status);
@@ -1522,7 +1535,8 @@ GetFullSmramRanges (
if (SmmIsSmramOverlap (
&SmramRanges[Index],
&SmramReservedRanges[Index2]
)) {
))
{
//
// There is overlap, need to split entry and then rescan.
//
@@ -1540,6 +1554,7 @@ GetFullSmramRanges (
}
}
}
if (!Rescan) {
//
// No any overlap, copy the entry to the temp SMRAM ranges.
@@ -1551,6 +1566,7 @@ GetFullSmramRanges (
}
}
} while (Rescan);
ASSERT (TempSmramRangeCount <= MaxCount);
//
@@ -1565,16 +1581,19 @@ GetFullSmramRanges (
break;
}
}
ASSERT (Index < TempSmramRangeCount);
for (Index2 = 0; Index2 < TempSmramRangeCount; Index2++) {
if ((Index2 != Index) && (TempSmramRanges[Index2].PhysicalSize != 0) && (TempSmramRanges[Index2].CpuStart < TempSmramRanges[Index].CpuStart)) {
Index = Index2;
}
}
CopyMem (&FullSmramRanges[*FullSmramRangeCount], &TempSmramRanges[Index], sizeof (EFI_SMRAM_DESCRIPTOR));
*FullSmramRangeCount += 1;
*FullSmramRangeCount += 1;
TempSmramRanges[Index].PhysicalSize = 0;
} while (*FullSmramRangeCount < TempSmramRangeCount);
ASSERT (*FullSmramRangeCount == TempSmramRangeCount);
*FullSmramRangeCount += AdditionSmramRangeCount;
@@ -1606,15 +1625,15 @@ SmmIplEntry (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINTN Index;
UINT64 MaxSize;
VOID *Registration;
UINT64 SmmCodeSize;
EFI_CPU_ARCH_PROTOCOL *CpuArch;
EFI_STATUS SetAttrStatus;
EFI_SMRAM_DESCRIPTOR *SmramRangeSmmDriver;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
EFI_STATUS Status;
UINTN Index;
UINT64 MaxSize;
VOID *Registration;
UINT64 SmmCodeSize;
EFI_CPU_ARCH_PROTOCOL *CpuArch;
EFI_STATUS SetAttrStatus;
EFI_SMRAM_DESCRIPTOR *SmramRangeSmmDriver;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
//
// Fill in the image handle of the SMM IPL so the SMM Core can use this as the
@@ -1663,7 +1682,7 @@ SmmIplEntry (
if (gSmmCorePrivate->SmramRanges[Index].CpuStart >= BASE_1MB) {
if ((gSmmCorePrivate->SmramRanges[Index].CpuStart + gSmmCorePrivate->SmramRanges[Index].PhysicalSize - 1) <= MAX_ADDRESS) {
if (gSmmCorePrivate->SmramRanges[Index].PhysicalSize >= MaxSize) {
MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
mCurrentSmramRange = &gSmmCorePrivate->SmramRanges[Index];
}
}
@@ -1674,7 +1693,9 @@ SmmIplEntry (
//
// Print debug message showing SMRAM window that will be used by SMM IPL and SMM Core
//
DEBUG ((DEBUG_INFO, "SMM IPL found SMRAM window %p - %p\n",
DEBUG ((
DEBUG_INFO,
"SMM IPL found SMRAM window %p - %p\n",
(VOID *)(UINTN)mCurrentSmramRange->CpuStart,
(VOID *)(UINTN)(mCurrentSmramRange->CpuStart + mCurrentSmramRange->PhysicalSize - 1)
));
@@ -1695,6 +1716,7 @@ SmmIplEntry (
MemDesc.Capabilities | SMRAM_CAPABILITIES
);
}
//
// If CPU AP is present, attempt to set SMRAM cacheability to WB and clear
// all paging attributes.
@@ -1702,15 +1724,15 @@ SmmIplEntry (
// is not available here.
//
CpuArch = NULL;
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);
if (!EFI_ERROR (Status)) {
MemDesc.Attributes &= ~(EFI_CACHE_ATTRIBUTE_MASK | EFI_MEMORY_ATTRIBUTE_MASK);
MemDesc.Attributes |= EFI_MEMORY_WB;
Status = gDS->SetMemorySpaceAttributes (
mSmramCacheBase,
mSmramCacheSize,
MemDesc.Attributes
);
Status = gDS->SetMemorySpaceAttributes (
mSmramCacheBase,
mSmramCacheSize,
MemDesc.Attributes
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));
}
@@ -1722,17 +1744,18 @@ SmmIplEntry (
);
DEBUG ((DEBUG_INFO, "SMRAM attributes: %016lx\n", MemDesc.Attributes));
ASSERT ((MemDesc.Attributes & EFI_MEMORY_ATTRIBUTE_MASK) == 0);
);
);
}
//
// if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load
// Modules At Fixed Address Configuration Table.
//
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
//
SmmCodeSize = LShiftU64 (PcdGet32(PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
SmmCodeSize = LShiftU64 (PcdGet32 (PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
//
// The SMRAM available memory is assumed to be larger than SmmCodeSize
//
@@ -1741,10 +1764,10 @@ SmmIplEntry (
// Retrieve Load modules At fixed address configuration table and save the SMRAM base.
//
Status = EfiGetSystemConfigurationTable (
&gLoadFixedAddressConfigurationTableGuid,
(VOID **) &mLMFAConfigurationTable
);
if (!EFI_ERROR (Status) && mLMFAConfigurationTable != NULL) {
&gLoadFixedAddressConfigurationTableGuid,
(VOID **)&mLMFAConfigurationTable
);
if (!EFI_ERROR (Status) && (mLMFAConfigurationTable != NULL)) {
mLMFAConfigurationTable->SmramBase = mCurrentSmramRange->CpuStart;
//
// Print the SMRAM base
@@ -1755,16 +1778,17 @@ SmmIplEntry (
//
// Fill the Smram range for all SMM code
//
SmramRangeSmmDriver = &gSmmCorePrivate->SmramRanges[gSmmCorePrivate->SmramRangeCount - 2];
SmramRangeSmmDriver = &gSmmCorePrivate->SmramRanges[gSmmCorePrivate->SmramRangeCount - 2];
SmramRangeSmmDriver->CpuStart = mCurrentSmramRange->CpuStart;
SmramRangeSmmDriver->PhysicalStart = mCurrentSmramRange->PhysicalStart;
SmramRangeSmmDriver->RegionState = mCurrentSmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmDriver->PhysicalSize = SmmCodeSize;
mCurrentSmramRange->PhysicalSize -= SmmCodeSize;
mCurrentSmramRange->CpuStart = mCurrentSmramRange->CpuStart + SmmCodeSize;
mCurrentSmramRange->PhysicalStart = mCurrentSmramRange->PhysicalStart + SmmCodeSize;
mCurrentSmramRange->PhysicalSize -= SmmCodeSize;
mCurrentSmramRange->CpuStart = mCurrentSmramRange->CpuStart + SmmCodeSize;
mCurrentSmramRange->PhysicalStart = mCurrentSmramRange->PhysicalStart + SmmCodeSize;
}
//
// Load SMM Core into SMRAM and execute it from SMRAM
//
@@ -1783,7 +1807,7 @@ SmmIplEntry (
// Attempt to reset SMRAM cacheability to UC
//
if (CpuArch != NULL) {
SetAttrStatus = gDS->SetMemorySpaceAttributes(
SetAttrStatus = gDS->SetMemorySpaceAttributes (
mSmramCacheBase,
mSmramCacheSize,
EFI_MEMORY_UC
@@ -1804,7 +1828,7 @@ SmmIplEntry (
// If the SMM Core could not be loaded then close SMRAM window, free allocated
// resources, and return an error so SMM IPL will be unloaded.
//
if (mCurrentSmramRange == NULL || EFI_ERROR (Status)) {
if ((mCurrentSmramRange == NULL) || EFI_ERROR (Status)) {
//
// Close all SMRAM ranges
//
@@ -1829,9 +1853,12 @@ SmmIplEntry (
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mSmmIplHandle,
&gEfiSmmBase2ProtocolGuid, &mSmmBase2,
&gEfiSmmCommunicationProtocolGuid, &mSmmCommunication,
&gEfiMmCommunication2ProtocolGuid, &mMmCommunication2,
&gEfiSmmBase2ProtocolGuid,
&mSmmBase2,
&gEfiSmmCommunicationProtocolGuid,
&mSmmCommunication,
&gEfiMmCommunication2ProtocolGuid,
&mMmCommunication2,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -1846,8 +1873,8 @@ SmmIplEntry (
mSmmIplEvents[Index].NotifyTpl,
mSmmIplEvents[Index].NotifyFunction,
mSmmIplEvents[Index].NotifyContext,
&Registration
);
&Registration
);
} else {
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,

View File

@@ -13,7 +13,7 @@ LIST_ENTRY mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];
// To cache the SMRAM base since when Loading modules At fixed address feature is enabled,
// all module is assigned an offset relative the SMRAM base in build time.
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase = 0;
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase = 0;
/**
Convert a UEFI memory type to SMM pool type.
@@ -24,21 +24,20 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddres
**/
SMM_POOL_TYPE
UefiMemoryTypeToSmmPoolType (
IN EFI_MEMORY_TYPE MemoryType
IN EFI_MEMORY_TYPE MemoryType
)
{
ASSERT ((MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData));
switch (MemoryType) {
case EfiRuntimeServicesCode:
return SmmPoolTypeCode;
case EfiRuntimeServicesData:
return SmmPoolTypeData;
default:
return SmmPoolTypeMax;
case EfiRuntimeServicesCode:
return SmmPoolTypeCode;
case EfiRuntimeServicesData:
return SmmPoolTypeData;
default:
return SmmPoolTypeMax;
}
}
/**
Called to initialize the memory service.
@@ -52,10 +51,10 @@ SmmInitializeMemoryServices (
IN EFI_SMRAM_DESCRIPTOR *SmramRanges
)
{
UINTN Index;
EFI_STATUS Status;
UINTN SmmPoolTypeIndex;
EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
UINTN Index;
EFI_STATUS Status;
UINTN SmmPoolTypeIndex;
EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
//
// Initialize Pool list
@@ -67,10 +66,10 @@ SmmInitializeMemoryServices (
}
Status = EfiGetSystemConfigurationTable (
&gLoadFixedAddressConfigurationTableGuid,
(VOID **) &LMFAConfigurationTable
);
if (!EFI_ERROR (Status) && LMFAConfigurationTable != NULL) {
&gLoadFixedAddressConfigurationTableGuid,
(VOID **)&LMFAConfigurationTable
);
if (!EFI_ERROR (Status) && (LMFAConfigurationTable != NULL)) {
gLoadModuleAtFixAddressSmramBase = LMFAConfigurationTable->SmramBase;
}
@@ -82,6 +81,7 @@ SmmInitializeMemoryServices (
if ((SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
continue;
}
SmmAddMemoryRegion (
SmramRanges[Index].CpuStart,
SmramRanges[Index].PhysicalSize,
@@ -97,6 +97,7 @@ SmmInitializeMemoryServices (
if ((SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) == 0) {
continue;
}
SmmAddMemoryRegion (
SmramRanges[Index].CpuStart,
SmramRanges[Index].PhysicalSize,
@@ -104,7 +105,6 @@ SmmInitializeMemoryServices (
SmramRanges[Index].RegionState
);
}
}
/**
@@ -132,19 +132,24 @@ InternalAllocPoolByIndex (
SMM_POOL_TYPE SmmPoolType;
Address = 0;
SmmPoolType = UefiMemoryTypeToSmmPoolType(PoolType);
SmmPoolType = UefiMemoryTypeToSmmPoolType (PoolType);
ASSERT (PoolIndex <= MAX_POOL_INDEX);
Status = EFI_SUCCESS;
Hdr = NULL;
Hdr = NULL;
if (PoolIndex == MAX_POOL_INDEX) {
Status = SmmInternalAllocatePages (AllocateAnyPages, PoolType,
EFI_SIZE_TO_PAGES (MAX_POOL_SIZE << 1),
&Address, FALSE);
Status = SmmInternalAllocatePages (
AllocateAnyPages,
PoolType,
EFI_SIZE_TO_PAGES (MAX_POOL_SIZE << 1),
&Address,
FALSE
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
Hdr = (FREE_POOL_HEADER *) (UINTN) Address;
Hdr = (FREE_POOL_HEADER *)(UINTN)Address;
} else if (!IsListEmpty (&mSmmPoolLists[SmmPoolType][PoolIndex])) {
Hdr = BASE_CR (GetFirstNode (&mSmmPoolLists[SmmPoolType][PoolIndex]), FREE_POOL_HEADER, Link);
RemoveEntryList (&Hdr->Link);
@@ -152,25 +157,25 @@ InternalAllocPoolByIndex (
Status = InternalAllocPoolByIndex (PoolType, PoolIndex + 1, &Hdr);
if (!EFI_ERROR (Status)) {
Hdr->Header.Signature = 0;
Hdr->Header.Size >>= 1;
Hdr->Header.Size >>= 1;
Hdr->Header.Available = TRUE;
Hdr->Header.Type = 0;
Tail = HEAD_TO_TAIL(&Hdr->Header);
Tail->Signature = 0;
Tail->Size = 0;
Hdr->Header.Type = 0;
Tail = HEAD_TO_TAIL (&Hdr->Header);
Tail->Signature = 0;
Tail->Size = 0;
InsertHeadList (&mSmmPoolLists[SmmPoolType][PoolIndex], &Hdr->Link);
Hdr = (FREE_POOL_HEADER*)((UINT8*)Hdr + Hdr->Header.Size);
Hdr = (FREE_POOL_HEADER *)((UINT8 *)Hdr + Hdr->Header.Size);
}
}
if (!EFI_ERROR (Status)) {
Hdr->Header.Signature = POOL_HEAD_SIGNATURE;
Hdr->Header.Size = MIN_POOL_SIZE << PoolIndex;
Hdr->Header.Size = MIN_POOL_SIZE << PoolIndex;
Hdr->Header.Available = FALSE;
Hdr->Header.Type = PoolType;
Tail = HEAD_TO_TAIL(&Hdr->Header);
Tail->Signature = POOL_TAIL_SIGNATURE;
Tail->Size = Hdr->Header.Size;
Hdr->Header.Type = PoolType;
Tail = HEAD_TO_TAIL (&Hdr->Header);
Tail->Signature = POOL_TAIL_SIGNATURE;
Tail->Size = Hdr->Header.Size;
}
*FreePoolHdr = Hdr;
@@ -192,21 +197,21 @@ InternalFreePoolByIndex (
IN POOL_TAIL *PoolTail
)
{
UINTN PoolIndex;
SMM_POOL_TYPE SmmPoolType;
UINTN PoolIndex;
SMM_POOL_TYPE SmmPoolType;
ASSERT ((FreePoolHdr->Header.Size & (FreePoolHdr->Header.Size - 1)) == 0);
ASSERT (((UINTN)FreePoolHdr & (FreePoolHdr->Header.Size - 1)) == 0);
ASSERT (FreePoolHdr->Header.Size >= MIN_POOL_SIZE);
SmmPoolType = UefiMemoryTypeToSmmPoolType(FreePoolHdr->Header.Type);
SmmPoolType = UefiMemoryTypeToSmmPoolType (FreePoolHdr->Header.Type);
PoolIndex = (UINTN) (HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT);
PoolIndex = (UINTN)(HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT);
FreePoolHdr->Header.Signature = 0;
FreePoolHdr->Header.Available = TRUE;
FreePoolHdr->Header.Type = 0;
PoolTail->Signature = 0;
PoolTail->Size = 0;
FreePoolHdr->Header.Type = 0;
PoolTail->Signature = 0;
PoolTail->Size = 0;
ASSERT (PoolIndex < MAX_POOL_INDEX);
InsertHeadList (&mSmmPoolLists[SmmPoolType][PoolIndex], &FreePoolHdr->Link);
return EFI_SUCCESS;
@@ -245,8 +250,9 @@ SmmInternalAllocatePool (
Address = 0;
if (PoolType != EfiRuntimeServicesCode &&
PoolType != EfiRuntimeServicesData) {
if ((PoolType != EfiRuntimeServicesCode) &&
(PoolType != EfiRuntimeServicesData))
{
return EFI_INVALID_PARAMETER;
}
@@ -258,14 +264,19 @@ SmmInternalAllocatePool (
// Adjust the size by the pool header & tail overhead
//
Size += POOL_OVERHEAD;
if (Size > MAX_POOL_SIZE || NeedGuard) {
if ((Size > MAX_POOL_SIZE) || NeedGuard) {
if (!HasPoolTail) {
Size -= sizeof (POOL_TAIL);
}
NoPages = EFI_SIZE_TO_PAGES (Size);
Status = SmmInternalAllocatePages (AllocateAnyPages, PoolType, NoPages,
&Address, NeedGuard);
Status = SmmInternalAllocatePages (
AllocateAnyPages,
PoolType,
NoPages,
&Address,
NeedGuard
);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -279,32 +290,33 @@ SmmInternalAllocatePool (
);
}
PoolHdr = (POOL_HEADER*)(UINTN)Address;
PoolHdr = (POOL_HEADER *)(UINTN)Address;
PoolHdr->Signature = POOL_HEAD_SIGNATURE;
PoolHdr->Size = EFI_PAGES_TO_SIZE (NoPages);
PoolHdr->Size = EFI_PAGES_TO_SIZE (NoPages);
PoolHdr->Available = FALSE;
PoolHdr->Type = PoolType;
PoolHdr->Type = PoolType;
if (HasPoolTail) {
PoolTail = HEAD_TO_TAIL (PoolHdr);
PoolTail = HEAD_TO_TAIL (PoolHdr);
PoolTail->Signature = POOL_TAIL_SIGNATURE;
PoolTail->Size = PoolHdr->Size;
PoolTail->Size = PoolHdr->Size;
}
*Buffer = PoolHdr + 1;
return Status;
}
Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT;
PoolIndex = (UINTN) HighBitSet32 ((UINT32)Size);
Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT;
PoolIndex = (UINTN)HighBitSet32 ((UINT32)Size);
if ((Size & (Size - 1)) != 0) {
PoolIndex++;
}
Status = InternalAllocPoolByIndex (PoolType, PoolIndex, &FreePoolHdr);
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
*Buffer = &FreePoolHdr->Header + 1;
}
return Status;
}
@@ -334,7 +346,7 @@ SmmAllocatePool (
Status = SmmInternalAllocatePool (PoolType, Size, Buffer);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionAllocatePool,
PoolType,
Size,
@@ -342,6 +354,7 @@ SmmAllocatePool (
NULL
);
}
return Status;
}
@@ -371,10 +384,10 @@ SmmInternalFreePool (
MemoryGuarded = IsHeapGuardEnabled () &&
IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer);
HasPoolTail = !(MemoryGuarded &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
HasPoolTail = !(MemoryGuarded &&
((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));
FreePoolHdr = (FREE_POOL_HEADER*)((POOL_HEADER*)Buffer - 1);
FreePoolHdr = (FREE_POOL_HEADER *)((POOL_HEADER *)Buffer - 1);
ASSERT (FreePoolHdr->Header.Signature == POOL_HEAD_SIGNATURE);
ASSERT (!FreePoolHdr->Header.Available);
if (FreePoolHdr->Header.Signature != POOL_HEAD_SIGNATURE) {
@@ -414,6 +427,7 @@ SmmInternalFreePool (
FALSE
);
}
return InternalFreePoolByIndex (FreePoolHdr, PoolTail);
}
@@ -437,7 +451,7 @@ SmmFreePool (
Status = SmmInternalFreePool (Buffer);
if (!EFI_ERROR (Status)) {
SmmCoreUpdateProfile (
(EFI_PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS (0),
(EFI_PHYSICAL_ADDRESS)(UINTN)RETURN_ADDRESS (0),
MemoryProfileActionFreePool,
EfiMaxMemoryType,
0,
@@ -445,5 +459,6 @@ SmmFreePool (
NULL
);
}
return Status;
}

View File

@@ -8,12 +8,12 @@
#include "PiSmmCore.h"
LIST_ENTRY mSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList);
LIST_ENTRY mSmiEntryList = INITIALIZE_LIST_HEAD_VARIABLE (mSmiEntryList);
SMI_ENTRY mRootSmiEntry = {
SMI_ENTRY mRootSmiEntry = {
SMI_ENTRY_SIGNATURE,
INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.AllEntries),
{0},
{ 0 },
INITIALIZE_LIST_HEAD_VARIABLE (mRootSmiEntry.SmiHandlers),
};
@@ -43,8 +43,8 @@ SmmCoreFindSmiEntry (
SmiEntry = NULL;
for (Link = mSmiEntryList.ForwardLink;
Link != &mSmiEntryList;
Link = Link->ForwardLink) {
Link = Link->ForwardLink)
{
Item = CR (Link, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
if (CompareGuid (&Item->HandlerType, HandlerType)) {
//
@@ -60,7 +60,7 @@ SmmCoreFindSmiEntry (
// allocate a new entry
//
if ((SmiEntry == NULL) && Create) {
SmiEntry = AllocatePool (sizeof(SMI_ENTRY));
SmiEntry = AllocatePool (sizeof (SMI_ENTRY));
if (SmiEntry != NULL) {
//
// Initialize new SMI entry structure
@@ -75,6 +75,7 @@ SmmCoreFindSmiEntry (
InsertTailList (&mSmiEntryList, &SmiEntry->AllEntries);
}
}
return SmiEntry;
}
@@ -108,7 +109,7 @@ SmiManage (
BOOLEAN SuccessReturn;
EFI_STATUS Status;
Status = EFI_NOT_FOUND;
Status = EFI_NOT_FOUND;
SuccessReturn = FALSE;
if (HandlerType == NULL) {
//
@@ -119,7 +120,7 @@ SmiManage (
//
// Non-root SMI handler
//
SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *) HandlerType, FALSE);
SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *)HandlerType, FALSE);
if (SmiEntry == NULL) {
//
// There is no handler registered for this interrupt source
@@ -127,62 +128,65 @@ SmiManage (
return Status;
}
}
Head = &SmiEntry->SmiHandlers;
for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
SmiHandler = CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
Status = SmiHandler->Handler (
(EFI_HANDLE) SmiHandler,
Context,
CommBuffer,
CommBufferSize
);
(EFI_HANDLE)SmiHandler,
Context,
CommBuffer,
CommBufferSize
);
switch (Status) {
case EFI_INTERRUPT_PENDING:
//
// If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then
// no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned.
//
if (HandlerType != NULL) {
return EFI_INTERRUPT_PENDING;
}
break;
case EFI_INTERRUPT_PENDING:
//
// If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then
// no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned.
//
if (HandlerType != NULL) {
return EFI_INTERRUPT_PENDING;
}
case EFI_SUCCESS:
//
// If at least one of the handlers returns EFI_SUCCESS then the function will return
// EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no
// additional handlers will be processed.
//
if (HandlerType != NULL) {
return EFI_SUCCESS;
}
SuccessReturn = TRUE;
break;
break;
case EFI_WARN_INTERRUPT_SOURCE_QUIESCED:
//
// If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED
// then the function will return EFI_SUCCESS.
//
SuccessReturn = TRUE;
break;
case EFI_SUCCESS:
//
// If at least one of the handlers returns EFI_SUCCESS then the function will return
// EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no
// additional handlers will be processed.
//
if (HandlerType != NULL) {
return EFI_SUCCESS;
}
case EFI_WARN_INTERRUPT_SOURCE_PENDING:
//
// If all the handlers returned EFI_WARN_INTERRUPT_SOURCE_PENDING
// then EFI_WARN_INTERRUPT_SOURCE_PENDING will be returned.
//
break;
SuccessReturn = TRUE;
break;
default:
//
// Unexpected status code returned.
//
ASSERT (FALSE);
break;
case EFI_WARN_INTERRUPT_SOURCE_QUIESCED:
//
// If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED
// then the function will return EFI_SUCCESS.
//
SuccessReturn = TRUE;
break;
case EFI_WARN_INTERRUPT_SOURCE_PENDING:
//
// If all the handlers returned EFI_WARN_INTERRUPT_SOURCE_PENDING
// then EFI_WARN_INTERRUPT_SOURCE_PENDING will be returned.
//
break;
default:
//
// Unexpected status code returned.
//
ASSERT (FALSE);
break;
}
}
@@ -216,7 +220,7 @@ SmiHandlerRegister (
SMI_ENTRY *SmiEntry;
LIST_ENTRY *List;
if (Handler == NULL || DispatchHandle == NULL) {
if ((Handler == NULL) || (DispatchHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -225,8 +229,8 @@ SmiHandlerRegister (
return EFI_OUT_OF_RESOURCES;
}
SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
SmiHandler->Handler = Handler;
SmiHandler->Signature = SMI_HANDLER_SIGNATURE;
SmiHandler->Handler = Handler;
SmiHandler->CallerAddr = (UINTN)RETURN_ADDRESS (0);
if (HandlerType == NULL) {
@@ -238,17 +242,18 @@ SmiHandlerRegister (
//
// None root SMI handler
//
SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *) HandlerType, TRUE);
SmiEntry = SmmCoreFindSmiEntry ((EFI_GUID *)HandlerType, TRUE);
if (SmiEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
}
List = &SmiEntry->SmiHandlers;
SmiHandler->SmiEntry = SmiEntry;
InsertTailList (List, &SmiHandler->Link);
*DispatchHandle = (EFI_HANDLE) SmiHandler;
*DispatchHandle = (EFI_HANDLE)SmiHandler;
return EFI_SUCCESS;
}
@@ -282,9 +287,10 @@ SmiHandlerUnRegister (
//
SmiHandler = NULL;
for ( HandlerLink = GetFirstNode (&mRootSmiEntry.SmiHandlers)
; !IsNull (&mRootSmiEntry.SmiHandlers, HandlerLink) && ((EFI_HANDLE) SmiHandler != DispatchHandle)
; HandlerLink = GetNextNode (&mRootSmiEntry.SmiHandlers, HandlerLink)
) {
; !IsNull (&mRootSmiEntry.SmiHandlers, HandlerLink) && ((EFI_HANDLE)SmiHandler != DispatchHandle)
; HandlerLink = GetNextNode (&mRootSmiEntry.SmiHandlers, HandlerLink)
)
{
SmiHandler = CR (HandlerLink, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
}
@@ -292,19 +298,21 @@ SmiHandlerUnRegister (
// Look for it in non-root SMI handlers
//
for ( EntryLink = GetFirstNode (&mSmiEntryList)
; !IsNull (&mSmiEntryList, EntryLink) && ((EFI_HANDLE) SmiHandler != DispatchHandle)
; EntryLink = GetNextNode (&mSmiEntryList, EntryLink)
) {
; !IsNull (&mSmiEntryList, EntryLink) && ((EFI_HANDLE)SmiHandler != DispatchHandle)
; EntryLink = GetNextNode (&mSmiEntryList, EntryLink)
)
{
SmiEntry = CR (EntryLink, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);
for ( HandlerLink = GetFirstNode (&SmiEntry->SmiHandlers)
; !IsNull (&SmiEntry->SmiHandlers, HandlerLink) && ((EFI_HANDLE) SmiHandler != DispatchHandle)
; HandlerLink = GetNextNode (&SmiEntry->SmiHandlers, HandlerLink)
) {
; !IsNull (&SmiEntry->SmiHandlers, HandlerLink) && ((EFI_HANDLE)SmiHandler != DispatchHandle)
; HandlerLink = GetNextNode (&SmiEntry->SmiHandlers, HandlerLink)
)
{
SmiHandler = CR (HandlerLink, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
}
}
if ((EFI_HANDLE) SmiHandler != DispatchHandle) {
if ((EFI_HANDLE)SmiHandler != DispatchHandle) {
return EFI_INVALID_PARAMETER;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/BaseLib.h>
@@ -36,7 +35,7 @@ RuntimeDriverCalculateCrc32 (
OUT UINT32 *CrcOut
)
{
if (Data == NULL || DataSize == 0 || CrcOut == NULL) {
if ((Data == NULL) || (DataSize == 0) || (CrcOut == NULL)) {
return EFI_INVALID_PARAMETER;
}

View File

@@ -45,20 +45,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Global Variables
//
EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;
UINTN mVirtualMapDescriptorSize;
UINTN mVirtualMapMaxIndex;
VOID *mMyImageBase;
EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;
UINTN mVirtualMapDescriptorSize;
UINTN mVirtualMapMaxIndex;
VOID *mMyImageBase;
//
// The handle onto which the Runtime Architectural Protocol instance is installed
//
EFI_HANDLE mRuntimeHandle = NULL;
EFI_HANDLE mRuntimeHandle = NULL;
//
// The Runtime Architectural Protocol instance produced by this driver
//
EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {
EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {
INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.ImageHead),
INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.EventHead),
@@ -79,6 +79,7 @@ EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {
//
// Worker Functions
//
/**
Calculate the 32-bit CRC in a EFI table using the Runtime Drivers
@@ -97,10 +98,10 @@ RuntimeDriverCalculateEfiHdrCrc (
{
UINT32 Crc;
Hdr->CRC32 = 0;
Hdr->CRC32 = 0;
Crc = 0;
RuntimeDriverCalculateCrc32 ((UINT8 *) Hdr, Hdr->HeaderSize, &Crc);
Crc = 0;
RuntimeDriverCalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
Hdr->CRC32 = Crc;
}
@@ -126,10 +127,10 @@ RuntimeDriverConvertPointer (
IN OUT VOID **ConvertAddress
)
{
UINTN Address;
UINT64 VirtEndOfRange;
EFI_MEMORY_DESCRIPTOR *VirtEntry;
UINTN Index;
UINTN Address;
UINT64 VirtEndOfRange;
EFI_MEMORY_DESCRIPTOR *VirtEntry;
UINTN Index;
//
// Make sure ConvertAddress is a valid pointer
@@ -137,10 +138,11 @@ RuntimeDriverConvertPointer (
if (ConvertAddress == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Get the address to convert
//
Address = (UINTN) *ConvertAddress;
Address = (UINTN)*ConvertAddress;
//
// If this is a null pointer, return if it's allowed
@@ -161,16 +163,16 @@ RuntimeDriverConvertPointer (
// platforms. If you get this ASSERT remove the UINTN and do a 64-bit
// multiply.
//
ASSERT (((UINTN) VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));
ASSERT (((UINTN)VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));
if ((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {
if (Address >= VirtEntry->PhysicalStart) {
VirtEndOfRange = VirtEntry->PhysicalStart + (((UINTN) VirtEntry->NumberOfPages) * EFI_PAGE_SIZE);
VirtEndOfRange = VirtEntry->PhysicalStart + (((UINTN)VirtEntry->NumberOfPages) * EFI_PAGE_SIZE);
if (Address < VirtEndOfRange) {
//
// Compute new address
//
*ConvertAddress = (VOID *) (Address - (UINTN) VirtEntry->PhysicalStart + (UINTN) VirtEntry->VirtualStart);
*ConvertAddress = (VOID *)(Address - (UINTN)VirtEntry->PhysicalStart + (UINTN)VirtEntry->VirtualStart);
return EFI_SUCCESS;
}
}
@@ -200,7 +202,7 @@ RuntimeDriverConvertPointer (
**/
EFI_STATUS
RuntimeDriverConvertInternalPointer (
IN OUT VOID **ConvertAddress
IN OUT VOID **ConvertAddress
)
{
return RuntimeDriverConvertPointer (0x0, ConvertAddress);
@@ -236,11 +238,11 @@ RuntimeDriverSetVirtualAddressMap (
IN EFI_MEMORY_DESCRIPTOR *VirtualMap
)
{
EFI_STATUS Status;
EFI_RUNTIME_EVENT_ENTRY *RuntimeEvent;
EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
LIST_ENTRY *Link;
EFI_PHYSICAL_ADDRESS VirtImageBase;
EFI_STATUS Status;
EFI_RUNTIME_EVENT_ENTRY *RuntimeEvent;
EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;
LIST_ENTRY *Link;
EFI_PHYSICAL_ADDRESS VirtImageBase;
//
// Can only switch to virtual addresses once the memory map is locked down,
@@ -249,12 +251,14 @@ RuntimeDriverSetVirtualAddressMap (
if (!mRuntime.AtRuntime || mRuntime.VirtualMode) {
return EFI_UNSUPPORTED;
}
//
// Only understand the original descriptor format
//
if (DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION || DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR)) {
if ((DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION) || (DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR))) {
return EFI_INVALID_PARAMETER;
}
//
// We are now committed to go to virtual mode, so lets get to it!
//
@@ -294,7 +298,7 @@ RuntimeDriverSetVirtualAddressMap (
// we need an explicit cast here.
//
RuntimeEvent->NotifyFunction (
(EFI_EVENT) RuntimeEvent->Event,
(EFI_EVENT)RuntimeEvent->Event,
RuntimeEvent->NotifyContext
);
}
@@ -309,19 +313,18 @@ RuntimeDriverSetVirtualAddressMap (
// We don't want to relocate our selves, as we only run in physical mode.
//
if (mMyImageBase != RuntimeImage->ImageBase) {
VirtImageBase = (EFI_PHYSICAL_ADDRESS) (UINTN) RuntimeImage->ImageBase;
Status = RuntimeDriverConvertPointer (0, (VOID **) &VirtImageBase);
VirtImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase;
Status = RuntimeDriverConvertPointer (0, (VOID **)&VirtImageBase);
ASSERT_EFI_ERROR (Status);
PeCoffLoaderRelocateImageForRuntime (
(EFI_PHYSICAL_ADDRESS) (UINTN) RuntimeImage->ImageBase,
(EFI_PHYSICAL_ADDRESS)(UINTN)RuntimeImage->ImageBase,
VirtImageBase,
(UINTN) RuntimeImage->ImageSize,
(UINTN)RuntimeImage->ImageSize,
RuntimeImage->RelocationData
);
InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN) RuntimeImage->ImageSize);
InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);
}
}
@@ -329,18 +332,18 @@ RuntimeDriverSetVirtualAddressMap (
// Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()
// and recompute the CRC-32
//
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetTime);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetTime);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetWakeupTime);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetWakeupTime);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->ResetSystem);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextHighMonotonicCount);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetVariable);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetVariable);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextVariableName);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryVariableInfo);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->UpdateCapsule);
RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryCapsuleCapabilities);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetTime);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetTime);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetWakeupTime);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetWakeupTime);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->ResetSystem);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetNextHighMonotonicCount);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetVariable);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->SetVariable);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->GetNextVariableName);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->QueryVariableInfo);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->UpdateCapsule);
RuntimeDriverConvertInternalPointer ((VOID **)&gRT->QueryCapsuleCapabilities);
RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);
//
@@ -350,9 +353,9 @@ RuntimeDriverSetVirtualAddressMap (
//
// Convert the runtime fields of the EFI System Table and recompute the CRC-32
//
RuntimeDriverConvertInternalPointer ((VOID **) &gST->FirmwareVendor);
RuntimeDriverConvertInternalPointer ((VOID **) &gST->ConfigurationTable);
RuntimeDriverConvertInternalPointer ((VOID **) &gST->RuntimeServices);
RuntimeDriverConvertInternalPointer ((VOID **)&gST->FirmwareVendor);
RuntimeDriverConvertInternalPointer ((VOID **)&gST->ConfigurationTable);
RuntimeDriverConvertInternalPointer ((VOID **)&gST->RuntimeServices);
RuntimeDriverCalculateEfiHdrCrc (&gST->Hdr);
//
@@ -383,12 +386,12 @@ RuntimeDriverSetVirtualAddressMap (
EFI_STATUS
EFIAPI
RuntimeDriverInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *MyLoadedImage;
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *MyLoadedImage;
//
// This image needs to be excluded from relocation for virtual mode, so cache
@@ -397,7 +400,7 @@ RuntimeDriverInitialize (
Status = gBS->HandleProtocol (
ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID**)&MyLoadedImage
(VOID **)&MyLoadedImage
);
ASSERT_EFI_ERROR (Status);
mMyImageBase = MyLoadedImage->ImageBase;

View File

@@ -24,10 +24,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/CacheMaintenanceLib.h>
#include <Library/PeCoffLib.h>
//
// Function Prototypes
//
/**
Calculate CRC32 for target data.
@@ -112,8 +112,8 @@ RuntimeDriverSetVirtualAddressMap (
EFI_STATUS
EFIAPI
RuntimeDriverInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
#endif