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:
committed by
mergify[bot]
parent
7c7184e201
commit
1436aea4d5
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
|
@@ -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.
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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 (
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -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
@@ -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
|
||||
|
@@ -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
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -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
@@ -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
|
||||
|
@@ -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
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user