From patchwork Fri Aug 22 19:49:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 4766891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5D1D0C0338 for ; Fri, 22 Aug 2014 19:52:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A0AF42013A for ; Fri, 22 Aug 2014 19:52:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFCC32012F for ; Fri, 22 Aug 2014 19:52:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XKuqs-00045e-6C; Fri, 22 Aug 2014 19:50:22 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XKupq-0002Io-0r for linux-arm-kernel@bombadil.infradead.org; Fri, 22 Aug 2014 19:49:18 +0000 Received: from geoff by merlin.infradead.org with local (Exim 4.80.1 #2 (Red Hat Linux)) id 1XKupo-0004Ig-P4; Fri, 22 Aug 2014 19:49:16 +0000 Message-Id: <73d234924f6de3b3b274d5d5648e4bbea6810450.1408736066.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Wed, 20 Aug 2014 14:44:43 -0700 Subject: [PATCH 7/9] arm64: Add atomic macros to assembler.h To: Catalin Marinas , Will Deacon Date: Fri, 22 Aug 2014 19:49:16 +0000 Cc: linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an assembler macro definition 'atomic' for performing generic atomic operations. Also add macro definitions for atomic_add, atomic_sub, atomic_inc, and atomic_dec. Signed-off-by: Geoff Levand --- arch/arm64/include/asm/assembler.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 5901480..dad3118 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -23,6 +23,39 @@ #include #include +/** + * macro atomic - Macros for simple atomic operations. + * + * @op: The operation to perform. + * @reg: A 32 or 64 bit register to operate on. + * @value: The value for the operation. + * @tmp1: A scratch register the same size as @reg. Defaluts to x20. + * @tmp2: A 32 bit scratch register. Defaluts to w21. + **/ + + .macro atomic op:req, reg:req, value:req, tmp1=x20, tmp2=w21 +.Latomic\@: ldxr \tmp1, [\reg] + \op \tmp1, \tmp1, \value + stxr \tmp2, \tmp1, [\reg] + cbnz \tmp2, .Latomic\@ + .endm + + .macro atomic_add reg:req, value:req, tmp1=x20, tmp2=w21 + atomic add, \reg, \value, \tmp1, \tmp2 + .endm + + .macro atomic_sub reg:req, value:req, tmp1, tmp2 + atomic sub, \reg, \value, \tmp1, \tmp2 + .endm + + .macro atomic_inc reg:req, tmp1, tmp2 + atomic add, \reg, 1, \tmp1, \tmp2 + .endm + + .macro atomic_dec reg:req, tmp1, tmp2 + atomic sub, \reg, 1, \tmp1, \tmp2 + .endm + /* * Stack pushing/popping (register pairs only). Equivalent to store decrement * before, load increment after.