#include <IndustryStandard/Xen/memory.h>\r
\r
#include <Library/XenHypercallLib.h>\r
+#include <Library/SynchronizationLib.h>\r
\r
#include "GrantTable.h"\r
-#include "InterlockedCompareExchange16.h"\r
\r
#define NR_RESERVED_ENTRIES 8\r
\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2006, 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
-;\r
-; Module Name:\r
-;\r
-; InterlockedCompareExchange16.Asm\r
-;\r
-; Abstract:\r
-;\r
-; InterlockedCompareExchange16 function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- SECTION .text\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT32\r
-; EFIAPI\r
-; InternalSyncCompareExchange16 (\r
-; IN UINT16 *Value,\r
-; IN UINT16 CompareValue,\r
-; IN UINT16 ExchangeValue\r
-; );\r
-;------------------------------------------------------------------------------\r
-global ASM_PFX(InternalSyncCompareExchange16)\r
-ASM_PFX(InternalSyncCompareExchange16):\r
- mov ecx, [esp + 4]\r
- mov eax, [esp + 8]\r
- mov edx, [esp + 12]\r
- lock cmpxchg [ecx], dx\r
- ret\r
-\r
+++ /dev/null
-SECTION .text\r
-\r
-; INT32\r
-; EFIAPI\r
-; TestAndClearBit (\r
-; IN INT32 Bit,\r
-; IN volatile VOID* Address\r
-; );\r
-global ASM_PFX(TestAndClearBit)\r
-ASM_PFX(TestAndClearBit):\r
- mov ecx, [esp + 4]\r
- mov edx, [esp + 8]\r
- lock btr [edx], ecx\r
- sbb eax, eax\r
- ret\r
-\r
+++ /dev/null
-#include <Library/DebugLib.h>\r
-#include "InterlockedCompareExchange16.h"\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
-**/\r
-UINT16\r
-EFIAPI\r
-InterlockedCompareExchange16 (\r
- IN OUT UINT16 *Value,\r
- IN UINT16 CompareValue,\r
- IN UINT16 ExchangeValue\r
- )\r
-{\r
- ASSERT (Value != NULL);\r
- return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue);\r
-}\r
+++ /dev/null
-/**\r
- Assembly implementation of InterlockedCompareExchange16.\r
-\r
- Look at the documentation of InterlockedCompareExchange16.\r
-**/\r
-UINT16\r
-EFIAPI\r
-InternalSyncCompareExchange16 (\r
- IN volatile UINT16 *Value,\r
- IN UINT16 CompareValue,\r
- IN UINT16 ExchangeValue\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 UINT16 *Value,\r
- IN UINT16 CompareValue,\r
- IN UINT16 ExchangeValue\r
- );\r
--- /dev/null
+/** @file\r
+ Implementation of TestAndClearBit using compare-exchange primitive\r
+\r
+ Copyright (C) 2015, Linaro Ltd.\r
+\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
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Library/SynchronizationLib.h>\r
+\r
+INT32\r
+EFIAPI\r
+TestAndClearBit (\r
+ IN INT32 Bit,\r
+ IN VOID *Address\r
+ )\r
+{\r
+ UINT16 Word, Read;\r
+ UINT16 Mask;\r
+\r
+ //\r
+ // Calculate the effective address relative to 'Address' based on the\r
+ // higher order bits of 'Bit'. Use signed shift instead of division to\r
+ // ensure we round towards -Inf, and end up with a positive shift in\r
+ // 'Bit', even if 'Bit' itself is negative.\r
+ //\r
+ Address += (Bit >> 4) * sizeof(UINT16);\r
+ Mask = 1U << (Bit & 15);\r
+\r
+ for (Word = *(UINT16 *) Address; Word & Mask; Word = Read) {\r
+ Read = InterlockedCompareExchange16 (Address, Word, Word & ~Mask);\r
+ if (Read == Word) {\r
+ return 1;\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2006, 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
-;\r
-; Module Name:\r
-;\r
-; InterlockedCompareExchange16.Asm\r
-;\r
-; Abstract:\r
-;\r
-; InterlockedCompareExchange16 function\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- DEFAULT REL\r
- SECTION .text\r
-\r
-;------------------------------------------------------------------------------\r
-; UINT16\r
-; EFIAPI\r
-; InterlockedCompareExchange16 (\r
-; IN UINT16 *Value,\r
-; IN UINT16 CompareValue,\r
-; IN UINT16 ExchangeValue\r
-; );\r
-;------------------------------------------------------------------------------\r
-global ASM_PFX(InternalSyncCompareExchange16)\r
-ASM_PFX(InternalSyncCompareExchange16):\r
- mov eax, edx\r
- lock cmpxchg [rcx], r8w\r
- ret\r
-\r
+++ /dev/null
-DEFAULT REL\r
-SECTION .text\r
-\r
-; INT32\r
-; EFIAPI\r
-; TestAndClearBit (\r
-; IN INT32 Bit, // rcx\r
-; IN volatile VOID* Address // rdx\r
-; );\r
-global ASM_PFX(TestAndClearBit)\r
-ASM_PFX(TestAndClearBit):\r
- lock btr [rdx], ecx\r
- sbb eax, eax\r
- ret\r
-\r
EFIAPI\r
TestAndClearBit (\r
IN INT32 Bit,\r
- IN volatile VOID *Address\r
+ IN VOID *Address\r
);\r
\r
CHAR8*\r
DriverBinding.h\r
ComponentName.c\r
ComponentName.h\r
- InterlockedCompareExchange16.c\r
- InterlockedCompareExchange16.h\r
GrantTable.c\r
GrantTable.h\r
EventChannel.c\r
XenBus.c\r
XenBus.h\r
Helpers.c\r
-\r
-[Sources.IA32]\r
- Ia32/InterlockedCompareExchange16.nasm\r
- Ia32/TestAndClearBit.nasm\r
-\r
-[Sources.X64]\r
- X64/InterlockedCompareExchange16.nasm\r
- X64/TestAndClearBit.nasm\r
+ TestAndClearBit.c\r
\r
[LibraryClasses]\r
UefiDriverEntryPoint\r
DevicePathLib\r
DebugLib\r
XenHypercallLib\r
+ SynchronizationLib\r
\r
[Protocols]\r
gEfiDriverBindingProtocolGuid\r