From patchwork Tue Feb 24 18:03:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 44975 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 774522029F for ; Tue, 24 Feb 2015 18:06:32 +0000 (UTC) Received: by wggy19 with SMTP id y19sf5273929wgg.1 for ; Tue, 24 Feb 2015 10:06:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=P7RnSLjnbOKhyczwXsH+7+NRk/eiSWL4cNotvQ/X1jg=; b=UyWlRfDbHbzpAkzU3ArOrYG9ynJcVqzbcjwUVlaMiPOcTtZzoUrZVCYqx/m3H2S6qA G0HIRG7vkoWqo4dIoj7X14ey4ceBdj4oEeqvV1HwJb2BTrgRU3MruXbfH9VpYdMK1JRX vy9o9p/f2ls5dDHqGEeeFoqAyaX2o6d+MLQfLFZWQBA8W8eQrk5ifgfr/7VcEHA0ULgB CWGcRiyuVWn4HrLPLOj/tqYIghHUIuqgwgnpKEF0a9GBo/Q6gAhAi/YcdjWb+yd1Npjd WiB/p7FVjD+cFaoaC0LzcJ5MsDHmgNxxtvUCI5LlGtSsdut30XNAoSIk43x3cucSDRPi 2R5A== X-Gm-Message-State: ALoCoQnOPs4j7QFAFthWuyT6sSMVSy6dnr1NpX3LqMsppo5r1lMbgEVdfIlXGcWR2rCuqwiFXwDv X-Received: by 10.112.77.101 with SMTP id r5mr2410872lbw.4.1424801191536; Tue, 24 Feb 2015 10:06:31 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.225 with SMTP id n1ls87959lah.52.gmail; Tue, 24 Feb 2015 10:06:31 -0800 (PST) X-Received: by 10.112.41.171 with SMTP id g11mr15198319lbl.107.1424801191106; Tue, 24 Feb 2015 10:06:31 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id p1si12506087lal.91.2015.02.24.10.06.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Feb 2015 10:06:31 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by labhs14 with SMTP id hs14so27537687lab.1 for ; Tue, 24 Feb 2015 10:06:30 -0800 (PST) X-Received: by 10.112.118.211 with SMTP id ko19mr15540428lbb.19.1424801190926; Tue, 24 Feb 2015 10:06:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp2079225lbj; Tue, 24 Feb 2015 10:06:29 -0800 (PST) X-Received: by 10.140.37.39 with SMTP id q36mr36827100qgq.18.1424801188936; Tue, 24 Feb 2015 10:06:28 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id h39si39872798qgd.108.2015.02.24.10.06.26 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Feb 2015 10:06:28 -0800 (PST) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQJrW-0003HR-SU; Tue, 24 Feb 2015 18:05:38 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQJrV-0003Ey-Ur for xen-devel@lists.xen.org; Tue, 24 Feb 2015 18:05:38 +0000 Received: from [193.109.254.147] by server-13.bemta-14.messagelabs.com id 9D/04-02635-17DBCE45; Tue, 24 Feb 2015 18:05:37 +0000 X-Env-Sender: ard.biesheuvel@linaro.org X-Msg-Ref: server-13.tower-27.messagelabs.com!1424801135!12574320!1 X-Originating-IP: [209.85.212.172] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10130 invoked from network); 24 Feb 2015 18:05:36 -0000 Received: from mail-wi0-f172.google.com (HELO mail-wi0-f172.google.com) (209.85.212.172) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 24 Feb 2015 18:05:36 -0000 Received: by mail-wi0-f172.google.com with SMTP id l15so27497657wiw.5 for ; Tue, 24 Feb 2015 10:05:35 -0800 (PST) X-Received: by 10.194.122.196 with SMTP id lu4mr35202319wjb.154.1424801135750; Tue, 24 Feb 2015 10:05:35 -0800 (PST) Received: from ards-macbook-pro.lan (bl11-65-113.dsl.telepac.pt. [85.244.65.113]) by mx.google.com with ESMTPSA id w8sm12792521wja.4.2015.02.24.10.05.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Feb 2015 10:05:34 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, olivier.martin@arm.com, lersek@redhat.com, roy.franz@linaro.org, leif.lindholm@linaro.org, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, anthony.perard@citrix.com, xen-devel@lists.xen.org, julien.grall@linaro.org, jordan.l.justen@intel.com, michael.d.kinney@intel.com Date: Tue, 24 Feb 2015 18:03:04 +0000 Message-Id: <1424800990-15777-24-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1424800990-15777-1-git-send-email-ard.biesheuvel@linaro.org> References: <1424800990-15777-1-git-send-email-ard.biesheuvel@linaro.org> Cc: wei.liu2@citrix.com, Ard Biesheuvel Subject: [Xen-devel] [PATCH v5 23/29] Ovmf/Xen: port XenBusDxe to other architectures X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: 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 Signed-off-by: Ard Biesheuvel --- OvmfPkg/XenBusDxe/GrantTable.c | 2 +- .../Ia32/InterlockedCompareExchange16.nasm | 42 -------------------- OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm | 16 -------- OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c | 33 ---------------- OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h | 38 ------------------ OvmfPkg/XenBusDxe/TestAndClearBit.c | 45 ++++++++++++++++++++++ .../X64/InterlockedCompareExchange16.nasm | 41 -------------------- OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm | 15 -------- OvmfPkg/XenBusDxe/XenBusDxe.h | 2 +- OvmfPkg/XenBusDxe/XenBusDxe.inf | 12 +----- 10 files changed, 49 insertions(+), 197 deletions(-) delete mode 100644 OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm delete mode 100644 OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm delete mode 100644 OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c delete mode 100644 OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h create mode 100644 OvmfPkg/XenBusDxe/TestAndClearBit.c delete mode 100644 OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm delete mode 100644 OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c index 19117fbe0373..6e47483f136f 100644 --- a/OvmfPkg/XenBusDxe/GrantTable.c +++ b/OvmfPkg/XenBusDxe/GrantTable.c @@ -35,9 +35,9 @@ #include #include +#include #include "GrantTable.h" -#include "InterlockedCompareExchange16.h" #define NR_RESERVED_ENTRIES 8 diff --git a/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm b/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm deleted file mode 100644 index d45582dd8109..000000000000 --- a/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.nasm +++ /dev/null @@ -1,42 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006, Intel Corporation. All rights reserved.
-; This program and the accompanying materials -; are licensed and made available under the terms and conditions of the BSD License -; which accompanies this distribution. The full text of the license may be found at -; http://opensource.org/licenses/bsd-license.php. -; -; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -; -; Module Name: -; -; InterlockedCompareExchange16.Asm -; -; Abstract: -; -; InterlockedCompareExchange16 function -; -; Notes: -; -;------------------------------------------------------------------------------ - - SECTION .text - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncCompareExchange16 ( -; IN UINT16 *Value, -; IN UINT16 CompareValue, -; IN UINT16 ExchangeValue -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(InternalSyncCompareExchange16) -ASM_PFX(InternalSyncCompareExchange16): - mov ecx, [esp + 4] - mov eax, [esp + 8] - mov edx, [esp + 12] - lock cmpxchg [ecx], dx - ret - diff --git a/OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm b/OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm deleted file mode 100644 index d77f74ef249d..000000000000 --- a/OvmfPkg/XenBusDxe/Ia32/TestAndClearBit.nasm +++ /dev/null @@ -1,16 +0,0 @@ -SECTION .text - -; INT32 -; EFIAPI -; TestAndClearBit ( -; IN INT32 Bit, -; IN volatile VOID* Address -; ); -global ASM_PFX(TestAndClearBit) -ASM_PFX(TestAndClearBit): - mov ecx, [esp + 4] - mov edx, [esp + 8] - lock btr [edx], ecx - sbb eax, eax - ret - diff --git a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c b/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c deleted file mode 100644 index 2b0fadd88dd1..000000000000 --- a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include "InterlockedCompareExchange16.h" - -/** - Performs an atomic compare exchange operation on a 16-bit unsigned integer. - - Performs an atomic compare exchange operation on the 16-bit unsigned integer - specified by Value. If Value is equal to CompareValue, then Value is set to - ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue, - then Value is returned. The compare exchange operation must be performed using - MP safe mechanisms. - - If Value is NULL, then ASSERT(). - - @param Value A pointer to the 16-bit value for the compare exchange - operation. - @param CompareValue 16-bit value used in compare operation. - @param ExchangeValue 16-bit value used in exchange operation. - - @return The original *Value before exchange. - -**/ -UINT16 -EFIAPI -InterlockedCompareExchange16 ( - IN OUT UINT16 *Value, - IN UINT16 CompareValue, - IN UINT16 ExchangeValue - ) -{ - ASSERT (Value != NULL); - return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue); -} diff --git a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h b/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h deleted file mode 100644 index fd3f15b1c8d6..000000000000 --- a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - Assembly implementation of InterlockedCompareExchange16. - - Look at the documentation of InterlockedCompareExchange16. -**/ -UINT16 -EFIAPI -InternalSyncCompareExchange16 ( - IN volatile UINT16 *Value, - IN UINT16 CompareValue, - IN UINT16 ExchangeValue - ); - -/** - Performs an atomic compare exchange operation on a 16-bit unsigned integer. - - Performs an atomic compare exchange operation on the 16-bit unsigned integer - specified by Value. If Value is equal to CompareValue, then Value is set to - ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue, - then Value is returned. The compare exchange operation must be performed using - MP safe mechanisms. - - If Value is NULL, then ASSERT(). - - @param Value A pointer to the 16-bit value for the compare exchange - operation. - @param CompareValue 16-bit value used in compare operation. - @param ExchangeValue 16-bit value used in exchange operation. - - @return The original *Value before exchange. -**/ -UINT16 -EFIAPI -InterlockedCompareExchange16 ( - IN OUT UINT16 *Value, - IN UINT16 CompareValue, - IN UINT16 ExchangeValue - ); diff --git a/OvmfPkg/XenBusDxe/TestAndClearBit.c b/OvmfPkg/XenBusDxe/TestAndClearBit.c new file mode 100644 index 000000000000..410677ee8acd --- /dev/null +++ b/OvmfPkg/XenBusDxe/TestAndClearBit.c @@ -0,0 +1,45 @@ +/** @file + Implementation of TestAndClearBit using compare-exchange primitive + + Copyright (C) 2015, Linaro Ltd. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include + +INT32 +EFIAPI +TestAndClearBit ( + IN INT32 Bit, + IN VOID *Address + ) +{ + UINT16 Word, Read; + UINT16 Mask; + + // + // Calculate the effective address relative to 'Address' based on the + // higher order bits of 'Bit'. Use signed shift instead of division to + // ensure we round towards -Inf, and end up with a positive shift in + // 'Bit', even if 'Bit' itself is negative. + // + Address += (Bit >> 4) * sizeof(UINT16); + Mask = 1U << (Bit & 15); + + for (Word = *(UINT16 *) Address; Word & Mask; Word = Read) { + Read = InterlockedCompareExchange16 (Address, Word, Word & ~Mask); + if (Read == Word) { + return 1; + } + } + return 0; +} diff --git a/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm b/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm deleted file mode 100644 index 048d1f32f6b9..000000000000 --- a/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.nasm +++ /dev/null @@ -1,41 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006, Intel Corporation. All rights reserved.
-; This program and the accompanying materials -; are licensed and made available under the terms and conditions of the BSD License -; which accompanies this distribution. The full text of the license may be found at -; http://opensource.org/licenses/bsd-license.php. -; -; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -; -; Module Name: -; -; InterlockedCompareExchange16.Asm -; -; Abstract: -; -; InterlockedCompareExchange16 function -; -; Notes: -; -;------------------------------------------------------------------------------ - - DEFAULT REL - SECTION .text - -;------------------------------------------------------------------------------ -; UINT16 -; EFIAPI -; InterlockedCompareExchange16 ( -; IN UINT16 *Value, -; IN UINT16 CompareValue, -; IN UINT16 ExchangeValue -; ); -;------------------------------------------------------------------------------ -global ASM_PFX(InternalSyncCompareExchange16) -ASM_PFX(InternalSyncCompareExchange16): - mov eax, edx - lock cmpxchg [rcx], r8w - ret - diff --git a/OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm b/OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm deleted file mode 100644 index a4859a62a250..000000000000 --- a/OvmfPkg/XenBusDxe/X64/TestAndClearBit.nasm +++ /dev/null @@ -1,15 +0,0 @@ -DEFAULT REL -SECTION .text - -; INT32 -; EFIAPI -; TestAndClearBit ( -; IN INT32 Bit, // rcx -; IN volatile VOID* Address // rdx -; ); -global ASM_PFX(TestAndClearBit) -ASM_PFX(TestAndClearBit): - lock btr [rdx], ecx - sbb eax, eax - ret - diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h index 6c306e017b07..953e4b72e85e 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.h +++ b/OvmfPkg/XenBusDxe/XenBusDxe.h @@ -122,7 +122,7 @@ INT32 EFIAPI TestAndClearBit ( IN INT32 Bit, - IN volatile VOID *Address + IN VOID *Address ); CHAR8* diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.inf b/OvmfPkg/XenBusDxe/XenBusDxe.inf index 31553ac5a64a..f0c5db98b1f4 100644 --- a/OvmfPkg/XenBusDxe/XenBusDxe.inf +++ b/OvmfPkg/XenBusDxe/XenBusDxe.inf @@ -34,8 +34,6 @@ DriverBinding.h ComponentName.c ComponentName.h - InterlockedCompareExchange16.c - InterlockedCompareExchange16.h GrantTable.c GrantTable.h EventChannel.c @@ -45,14 +43,7 @@ XenBus.c XenBus.h Helpers.c - -[Sources.IA32] - Ia32/InterlockedCompareExchange16.nasm - Ia32/TestAndClearBit.nasm - -[Sources.X64] - X64/InterlockedCompareExchange16.nasm - X64/TestAndClearBit.nasm + TestAndClearBit.c [LibraryClasses] UefiDriverEntryPoint @@ -64,6 +55,7 @@ DevicePathLib DebugLib XenHypercallLib + SynchronizationLib [Protocols] gEfiDriverBindingProtocolGuid