]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Ovmf/Xen: port XenBusDxe to other architectures
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 28 Feb 2015 20:33:34 +0000 (20:33 +0000)
committerlersek <lersek@Edk2>
Sat, 28 Feb 2015 20:33:34 +0000 (20:33 +0000)
This patch updates XenBusDxe to use the 16-bit compare and exchange
function that was introduced for this purpose to the
BaseSynchronizationLib. It also provides a new generic implementation
of TestAndClearBit () using the same 16-bit compare and exchange, making
this module fully architecture agnostic.

Contributed-under: TianoCore Contribution Agreement 1.0
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16975 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/XenBusDxe/GrantTable.c
OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm [deleted file]
OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm [deleted file]
OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c [deleted file]
OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h [deleted file]
OvmfPkg/XenBusDxe/TestAndClearBit.c [new file with mode: 0644]
OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm [deleted file]
OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm [deleted file]
OvmfPkg/XenBusDxe/XenBusDxe.h
OvmfPkg/XenBusDxe/XenBusDxe.inf

index 19117fbe0373efcb55f47b6f4235881fb744d8b3..6e47483f136f8217f47b2e9c8394ee8e17a5d9c4 100644 (file)
@@ -35,9 +35,9 @@
 #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
diff --git a/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm b/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm
deleted file mode 100644 (file)
index d45582d..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-;------------------------------------------------------------------------------\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
diff --git a/OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm b/OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm
deleted file mode 100644 (file)
index d77f74e..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-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
diff --git a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c b/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c
deleted file mode 100644 (file)
index 2b0fadd..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-#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
diff --git a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h b/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h
deleted file mode 100644 (file)
index fd3f15b..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**\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
diff --git a/OvmfPkg/XenBusDxe/TestAndClearBit.c b/OvmfPkg/XenBusDxe/TestAndClearBit.c
new file mode 100644 (file)
index 0000000..410677e
--- /dev/null
@@ -0,0 +1,45 @@
+/** @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
diff --git a/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm b/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm
deleted file mode 100644 (file)
index 048d1f3..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-;------------------------------------------------------------------------------\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
diff --git a/OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm b/OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm
deleted file mode 100644 (file)
index a4859a6..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-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
index 6c306e017b0780a74f01701e983ed9bb9c20ee6b..953e4b72e85e67992380e6a7a698b1ff89c22259 100644 (file)
@@ -122,7 +122,7 @@ INT32
 EFIAPI\r
 TestAndClearBit (\r
   IN INT32 Bit,\r
-  IN volatile VOID *Address\r
+  IN VOID  *Address\r
   );\r
 \r
 CHAR8*\r
index 31553ac5a64ae03551e741f34ba7391f7f4616bd..f0c5db98b1f437e26d8c83ca28a6db6cd492b22e 100644 (file)
@@ -34,8 +34,6 @@
   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
@@ -64,6 +55,7 @@
   DevicePathLib\r
   DebugLib\r
   XenHypercallLib\r
+  SynchronizationLib\r
 \r
 [Protocols]\r
   gEfiDriverBindingProtocolGuid\r