From 173d9edad4513492f3abbae1eb1b8f4436a98cbf Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Thu, 29 Feb 2024 11:57:30 +0300 Subject: [PATCH] MdeModulePkg: Refactored out CoreAcquireLockOrFail(), CoreAcquireLock() and CoreReleaseLock(). --- MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 4 +- MdeModulePkg/Core/Dxe/Event/Event.c | 4 +- MdeModulePkg/Core/Dxe/Event/Timer.c | 16 ++--- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 8 +-- MdeModulePkg/Core/Dxe/Hand/Handle.c | 4 +- MdeModulePkg/Core/Dxe/Hand/Locate.c | 2 +- .../Core/Dxe/Mem/MemoryProfileRecord.c | 4 +- MdeModulePkg/Core/Dxe/Mem/Page.c | 6 +- .../Core/Dxe/Misc/MemoryAttributesTable.c | 4 +- MdeModulePkg/Include/Library/MemoryPoolLib.h | 46 ------------- .../Library/MemoryPoolLib/InternalPool.c | 65 ------------------- .../Library/MemoryPoolLib/InternalPool.h | 3 + .../Library/MemoryPoolLib/MemoryPoolLib.inf | 1 - MdeModulePkg/Library/MemoryPoolLib/Pool.c | 8 +-- 14 files changed, 33 insertions(+), 142 deletions(-) delete mode 100644 MdeModulePkg/Library/MemoryPoolLib/InternalPool.c diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c index 6bd35b9d3d..d18599b2d2 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -204,7 +204,7 @@ CoreAcquireDispatcherLock ( VOID ) { - CoreAcquireLock (&mDispatcherLock); + EfiAcquireLock (&mDispatcherLock); } /** @@ -216,7 +216,7 @@ CoreReleaseDispatcherLock ( VOID ) { - CoreReleaseLock (&mDispatcherLock); + EfiReleaseLock (&mDispatcherLock); } /** diff --git a/MdeModulePkg/Core/Dxe/Event/Event.c b/MdeModulePkg/Core/Dxe/Event/Event.c index dc82abb021..a9896ea554 100644 --- a/MdeModulePkg/Core/Dxe/Event/Event.c +++ b/MdeModulePkg/Core/Dxe/Event/Event.c @@ -95,7 +95,7 @@ CoreAcquireEventLock ( VOID ) { - CoreAcquireLock (&gEventQueueLock); + EfiAcquireLock (&gEventQueueLock); } /** @@ -107,7 +107,7 @@ CoreReleaseEventLock ( VOID ) { - CoreReleaseLock (&gEventQueueLock); + EfiReleaseLock (&gEventQueueLock); } /** diff --git a/MdeModulePkg/Core/Dxe/Event/Timer.c b/MdeModulePkg/Core/Dxe/Event/Timer.c index 29e507c67c..c52925670d 100644 --- a/MdeModulePkg/Core/Dxe/Event/Timer.c +++ b/MdeModulePkg/Core/Dxe/Event/Timer.c @@ -74,9 +74,9 @@ CoreCurrentSystemTime ( { UINT64 SystemTime; - CoreAcquireLock (&mEfiSystemTimeLock); + EfiAcquireLock (&mEfiSystemTimeLock); SystemTime = mEfiSystemTime; - CoreReleaseLock (&mEfiSystemTimeLock); + EfiReleaseLock (&mEfiSystemTimeLock); return SystemTime; } @@ -102,7 +102,7 @@ CoreCheckTimers ( // // Check the timer database for expired timers // - CoreAcquireLock (&mEfiTimerLock); + EfiAcquireLock (&mEfiTimerLock); SystemTime = CoreCurrentSystemTime (); while (!IsListEmpty (&mEfiTimerList)) { @@ -151,7 +151,7 @@ CoreCheckTimers ( } } - CoreReleaseLock (&mEfiTimerLock); + EfiReleaseLock (&mEfiTimerLock); } /** @@ -194,7 +194,7 @@ CoreTimerTick ( // // Check runtiem flag in case there are ticks while exiting boot services // - CoreAcquireLock (&mEfiSystemTimeLock); + EfiAcquireLock (&mEfiSystemTimeLock); // // Update the system time @@ -213,7 +213,7 @@ CoreTimerTick ( } } - CoreReleaseLock (&mEfiSystemTimeLock); + EfiReleaseLock (&mEfiSystemTimeLock); } /** @@ -255,7 +255,7 @@ CoreSetTimer ( return EFI_INVALID_PARAMETER; } - CoreAcquireLock (&mEfiTimerLock); + EfiAcquireLock (&mEfiTimerLock); // // If the timer is queued to the timer database, remove it @@ -285,7 +285,7 @@ CoreSetTimer ( } } - CoreReleaseLock (&mEfiTimerLock); + EfiReleaseLock (&mEfiTimerLock); return EFI_SUCCESS; } diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 143b452d06..d43970665f 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -266,7 +266,7 @@ CoreAcquireGcdMemoryLock ( VOID ) { - CoreAcquireLock (&mGcdMemorySpaceLock); + EfiAcquireLock (&mGcdMemorySpaceLock); } /** @@ -278,7 +278,7 @@ CoreReleaseGcdMemoryLock ( VOID ) { - CoreReleaseLock (&mGcdMemorySpaceLock); + EfiReleaseLock (&mGcdMemorySpaceLock); } /** @@ -290,7 +290,7 @@ CoreAcquireGcdIoLock ( VOID ) { - CoreAcquireLock (&mGcdIoSpaceLock); + EfiAcquireLock (&mGcdIoSpaceLock); } /** @@ -302,7 +302,7 @@ CoreReleaseGcdIoLock ( VOID ) { - CoreReleaseLock (&mGcdIoSpaceLock); + EfiReleaseLock (&mGcdIoSpaceLock); } // diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index 3a4564a5e9..96d68c2221 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -29,7 +29,7 @@ CoreAcquireProtocolLock ( VOID ) { - CoreAcquireLock (&gProtocolDatabaseLock); + EfiAcquireLock (&gProtocolDatabaseLock); } /** @@ -41,7 +41,7 @@ CoreReleaseProtocolLock ( VOID ) { - CoreReleaseLock (&gProtocolDatabaseLock); + EfiReleaseLock (&gProtocolDatabaseLock); } /** diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c index 8f20c6332d..674e414971 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Locate.c +++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c @@ -600,7 +600,7 @@ CoreLocateProtocol ( // // Lock the protocol database // - Status = CoreAcquireLockOrFail (&gProtocolDatabaseLock); + Status = EfiAcquireLockOrFail (&gProtocolDatabaseLock); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c index f19a5d8abd..168a27fef3 100644 --- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c +++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c @@ -222,7 +222,7 @@ CoreAcquireMemoryProfileLock ( VOID ) { - CoreAcquireLock (&mMemoryProfileLock); + EfiAcquireLock (&mMemoryProfileLock); } /** @@ -233,7 +233,7 @@ CoreReleaseMemoryProfileLock ( VOID ) { - CoreReleaseLock (&mMemoryProfileLock); + EfiReleaseLock (&mMemoryProfileLock); } /** diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index d3e18b168a..bcb41780d1 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -104,7 +104,7 @@ CoreAcquireMemoryLock ( VOID ) { - CoreAcquireLock (&gMemoryLock); + EfiAcquireLock (&gMemoryLock); } /** @@ -116,7 +116,7 @@ CoreReleaseMemoryLock ( VOID ) { - CoreReleaseLock (&gMemoryLock); + EfiReleaseLock (&gMemoryLock); } /** @@ -2197,7 +2197,7 @@ CoreAllocatePoolPagesI ( VOID *Buffer; EFI_STATUS Status; - Status = CoreAcquireLockOrFail (&gMemoryLock); + Status = EfiAcquireLockOrFail (&gMemoryLock); if (EFI_ERROR (Status)) { return NULL; } diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index 98e8fab500..b37066aba1 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -339,7 +339,7 @@ CoreAcquiremMemoryAttributesTableLock ( VOID ) { - CoreAcquireLock (&mMemoryAttributesTableLock); + EfiAcquireLock (&mMemoryAttributesTableLock); } /** @@ -351,7 +351,7 @@ CoreReleasemMemoryAttributesTableLock ( VOID ) { - CoreReleaseLock (&mMemoryAttributesTableLock); + EfiReleaseLock (&mMemoryAttributesTableLock); } /** diff --git a/MdeModulePkg/Include/Library/MemoryPoolLib.h b/MdeModulePkg/Include/Library/MemoryPoolLib.h index ff1da3cca8..787046f1de 100644 --- a/MdeModulePkg/Include/Library/MemoryPoolLib.h +++ b/MdeModulePkg/Include/Library/MemoryPoolLib.h @@ -198,50 +198,4 @@ IsMemoryTypeToGuard ( IN UINT8 PageOrPool ); -/** - Raising to the task priority level of the mutual exclusion - lock, and then acquires ownership of the lock. - - @param Lock The lock to acquire - - @return Lock owned - -**/ -VOID -CoreAcquireLock ( - IN EFI_LOCK *Lock - ); - -/** - Initialize a basic mutual exclusion lock. Each lock - provides mutual exclusion access at it's task priority - level. Since there is no-premption (at any TPL) or - multiprocessor support, acquiring the lock only consists - of raising to the locks TPL. - - @param Lock The EFI_LOCK structure to initialize - - @retval EFI_SUCCESS Lock Owned. - @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned. - -**/ -EFI_STATUS -CoreAcquireLockOrFail ( - IN EFI_LOCK *Lock - ); - -/** - Releases ownership of the mutual exclusion lock, and - restores the previous task priority level. - - @param Lock The lock to release - - @return Lock unowned - -**/ -VOID -CoreReleaseLock ( - IN EFI_LOCK *Lock - ); - #endif diff --git a/MdeModulePkg/Library/MemoryPoolLib/InternalPool.c b/MdeModulePkg/Library/MemoryPoolLib/InternalPool.c deleted file mode 100644 index 5e506e080b..0000000000 --- a/MdeModulePkg/Library/MemoryPoolLib/InternalPool.c +++ /dev/null @@ -1,65 +0,0 @@ -/** @file - DXE Core functions necessary for pool management functions. - - Copyright (c) 2024, Mikhail Krichanov. All rights reserved. - SPDX-License-Identifier: BSD-3-Clause - -**/ - -#include -#include - -/** - Initialize a basic mutual exclusion lock. Each lock - provides mutual exclusion access at it's task priority - level. Since there is no-premption (at any TPL) or - multiprocessor support, acquiring the lock only consists - of raising to the locks TPL. - - @param Lock The EFI_LOCK structure to initialize - - @retval EFI_SUCCESS Lock Owned. - @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned. - -**/ -EFI_STATUS -CoreAcquireLockOrFail ( - IN EFI_LOCK *Lock - ) -{ - return EfiAcquireLockOrFail (Lock); -} - -/** - Raising to the task priority level of the mutual exclusion - lock, and then acquires ownership of the lock. - - @param Lock The lock to acquire - - @return Lock owned - -**/ -VOID -CoreAcquireLock ( - IN EFI_LOCK *Lock - ) -{ - EfiAcquireLock (Lock); -} - -/** - Releases ownership of the mutual exclusion lock, and - restores the previous task priority level. - - @param Lock The lock to release - - @return Lock unowned - -**/ -VOID -CoreReleaseLock ( - IN EFI_LOCK *Lock - ) -{ - EfiReleaseLock (Lock); -} diff --git a/MdeModulePkg/Library/MemoryPoolLib/InternalPool.h b/MdeModulePkg/Library/MemoryPoolLib/InternalPool.h index b0bb574f21..e800fd7acb 100644 --- a/MdeModulePkg/Library/MemoryPoolLib/InternalPool.h +++ b/MdeModulePkg/Library/MemoryPoolLib/InternalPool.h @@ -4,6 +4,9 @@ Copyright (c) 2024, Mikhail Krichanov. All rights reserved. SPDX-License-Identifier: BSD-3-Clause + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + **/ #ifndef _INTERNAL_POOL_H_ diff --git a/MdeModulePkg/Library/MemoryPoolLib/MemoryPoolLib.inf b/MdeModulePkg/Library/MemoryPoolLib/MemoryPoolLib.inf index 91bbda57a3..acc7c606be 100644 --- a/MdeModulePkg/Library/MemoryPoolLib/MemoryPoolLib.inf +++ b/MdeModulePkg/Library/MemoryPoolLib/MemoryPoolLib.inf @@ -20,7 +20,6 @@ # [Sources] - InternalPool.c InternalPool.h Pool.c diff --git a/MdeModulePkg/Library/MemoryPoolLib/Pool.c b/MdeModulePkg/Library/MemoryPoolLib/Pool.c index a35fa80058..19cb969d51 100644 --- a/MdeModulePkg/Library/MemoryPoolLib/Pool.c +++ b/MdeModulePkg/Library/MemoryPoolLib/Pool.c @@ -310,13 +310,13 @@ CoreInternalAllocatePool ( // // Acquire the memory lock and make the allocation // - Status = CoreAcquireLockOrFail (&mPoolMemoryLock); + Status = EfiAcquireLockOrFail (&mPoolMemoryLock); if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } *Buffer = CoreAllocatePoolI (PoolType, Size, NeedGuard); - CoreReleaseLock (&mPoolMemoryLock); + EfiReleaseLock (&mPoolMemoryLock); return (*Buffer != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES; } @@ -596,9 +596,9 @@ CoreInternalFreePool ( return EFI_INVALID_PARAMETER; } - CoreAcquireLock (&mPoolMemoryLock); + EfiAcquireLock (&mPoolMemoryLock); Status = CoreFreePoolI (Buffer, PoolType); - CoreReleaseLock (&mPoolMemoryLock); + EfiReleaseLock (&mPoolMemoryLock); return Status; }