]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/SynchronizationLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / SynchronizationLib.h
index b3c8e870dd182529d6bb49d4e584ece853d13424..03906a0c53afef254bf6e66b768594065ab1fa72 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Provides synchronization functions.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -18,16 +12,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 ///\r
 /// Definitions for SPIN_LOCK\r
 ///\r
-typedef volatile UINTN              SPIN_LOCK;\r
-\r
+typedef volatile UINTN SPIN_LOCK;\r
 \r
 /**\r
   Retrieves the architecture-specific spin lock alignment requirements for\r
   optimal spin lock performance.\r
 \r
   This function retrieves the spin lock alignment requirements for optimal\r
-  performance on a given CPU architecture. The spin lock alignment must be a\r
-  power of two and is returned by this function. If there are no alignment\r
+  performance on a given CPU architecture. The spin lock alignment is byte alignment.\r
+  It must be a power of two and is returned by this function. If there are no alignment\r
   requirements, then 1 must be returned. The spin lock synchronization\r
   functions must function correctly if the spin lock size and alignment values\r
   returned by this function are not used at all. These values are hints to the\r
@@ -43,7 +36,6 @@ GetSpinLockProperties (
   VOID\r
   );\r
 \r
-\r
 /**\r
   Initializes a spin lock to the released state and returns the spin lock.\r
 \r
@@ -63,10 +55,9 @@ GetSpinLockProperties (
 SPIN_LOCK *\r
 EFIAPI\r
 InitializeSpinLock (\r
-  OUT      SPIN_LOCK                 *SpinLock\r
+  OUT      SPIN_LOCK  *SpinLock\r
   );\r
 \r
-\r
 /**\r
   Waits until a spin lock can be placed in the acquired state.\r
 \r
@@ -90,10 +81,9 @@ InitializeSpinLock (
 SPIN_LOCK *\r
 EFIAPI\r
 AcquireSpinLock (\r
-  IN OUT  SPIN_LOCK                 *SpinLock\r
+  IN OUT  SPIN_LOCK  *SpinLock\r
   );\r
 \r
-\r
 /**\r
   Attempts to place a spin lock in the acquired state.\r
 \r
@@ -114,10 +104,9 @@ AcquireSpinLock (
 BOOLEAN\r
 EFIAPI\r
 AcquireSpinLockOrFail (\r
-  IN OUT  SPIN_LOCK                 *SpinLock\r
+  IN OUT  SPIN_LOCK  *SpinLock\r
   );\r
 \r
-\r
 /**\r
   Releases a spin lock.\r
 \r
@@ -135,17 +124,15 @@ AcquireSpinLockOrFail (
 SPIN_LOCK *\r
 EFIAPI\r
 ReleaseSpinLock (\r
-  IN OUT  SPIN_LOCK                 *SpinLock\r
+  IN OUT  SPIN_LOCK  *SpinLock\r
   );\r
 \r
-\r
 /**\r
   Performs an atomic increment of a 32-bit unsigned integer.\r
 \r
   Performs an atomic increment of the 32-bit unsigned integer specified by\r
   Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
@@ -157,17 +144,15 @@ ReleaseSpinLock (
 UINT32\r
 EFIAPI\r
 InterlockedIncrement (\r
-  IN      UINT32                    *Value\r
+  IN      volatile UINT32  *Value\r
   );\r
 \r
-\r
 /**\r
   Performs an atomic decrement of a 32-bit unsigned integer.\r
 \r
   Performs an atomic decrement of the 32-bit unsigned integer specified by\r
   Value and returns the decremented value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
+  performed using MP safe mechanisms.\r
 \r
   If Value is NULL, then ASSERT().\r
 \r
@@ -179,9 +164,34 @@ InterlockedIncrement (
 UINT32\r
 EFIAPI\r
 InterlockedDecrement (\r
-  IN      UINT32                    *Value\r
+  IN      volatile UINT32  *Value\r
   );\r
 \r
+/**\r
+  Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
+  specified by Value.  If Value is equal to CompareValue, then Value is set to\r
+  ExchangeValue and CompareValue is returned.  If Value is not equal to CompareValue,\r
+  then Value is returned.  The compare exchange operation must be performed using\r
+  MP safe mechanisms.\r
+\r
+  If Value is NULL, then ASSERT().\r
+\r
+  @param  Value         A pointer to the 16-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  16-bit value used in compare operation.\r
+  @param  ExchangeValue 16-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+**/\r
+UINT16\r
+EFIAPI\r
+InterlockedCompareExchange16 (\r
+  IN OUT  volatile UINT16  *Value,\r
+  IN      UINT16           CompareValue,\r
+  IN      UINT16           ExchangeValue\r
+  );\r
 \r
 /**\r
   Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
@@ -205,12 +215,11 @@ InterlockedDecrement (
 UINT32\r
 EFIAPI\r
 InterlockedCompareExchange32 (\r
-  IN OUT  UINT32                    *Value,\r
-  IN      UINT32                    CompareValue,\r
-  IN      UINT32                    ExchangeValue\r
+  IN OUT  volatile UINT32  *Value,\r
+  IN      UINT32           CompareValue,\r
+  IN      UINT32           ExchangeValue\r
   );\r
 \r
-\r
 /**\r
   Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
 \r
@@ -232,12 +241,11 @@ InterlockedCompareExchange32 (
 UINT64\r
 EFIAPI\r
 InterlockedCompareExchange64 (\r
-  IN OUT  UINT64                    *Value,\r
-  IN      UINT64                    CompareValue,\r
-  IN      UINT64                    ExchangeValue\r
+  IN OUT  volatile UINT64  *Value,\r
+  IN      UINT64           CompareValue,\r
+  IN      UINT64           ExchangeValue\r
   );\r
 \r
-\r
 /**\r
   Performs an atomic compare exchange operation on a pointer value.\r
 \r
@@ -259,11 +267,9 @@ InterlockedCompareExchange64 (
 VOID *\r
 EFIAPI\r
 InterlockedCompareExchangePointer (\r
-  IN OUT  VOID                      **Value,\r
-  IN      VOID                      *CompareValue,\r
-  IN      VOID                      *ExchangeValue\r
+  IN OUT  VOID                      *volatile  *Value,\r
+  IN      VOID                                 *CompareValue,\r
+  IN      VOID                                 *ExchangeValue\r
   );\r
 \r
 #endif\r
-\r
-\r