From owner-svn-src-head@freebsd.org Tue Nov 10 12:15:14 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 972C6A2A787; Tue, 10 Nov 2015 12:15:14 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5EDB017FD; Tue, 10 Nov 2015 12:15:14 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAACFDq3022534; Tue, 10 Nov 2015 12:15:13 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAACFD2E022533; Tue, 10 Nov 2015 12:15:13 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201511101215.tAACFD2E022533@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 10 Nov 2015 12:15:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290649 - head/sys/arm/include X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Nov 2015 12:15:14 -0000 Author: kib Date: Tue Nov 10 12:15:13 2015 New Revision: 290649 URL: https://svnweb.freebsd.org/changeset/base/290649 Log: Implement atomic_testandset_{32,int,long,64} for ARMv6. Only little-endian configuration for 64-bit variant is supported. Reviewed by: mmel Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D4113 Modified: head/sys/arm/include/atomic-v6.h Modified: head/sys/arm/include/atomic-v6.h ============================================================================== --- head/sys/arm/include/atomic-v6.h Tue Nov 10 12:02:41 2015 (r290648) +++ head/sys/arm/include/atomic-v6.h Tue Nov 10 12:15:13 2015 (r290649) @@ -593,6 +593,54 @@ atomic_store_rel_long(volatile u_long *p *p = v; } +static __inline int +atomic_testandset_32(volatile uint32_t *p, u_int v) +{ + uint32_t tmp, tmp2, res, mask; + + mask = 1u << (v & 0x1f); + tmp = tmp2 = 0; + __asm __volatile( + "1: ldrex %0, [%4] \n" + " orr %1, %0, %3 \n" + " strex %2, %1, [%4] \n" + " cmp %2, #0 \n" + " it ne \n" + " bne 1b \n" + : "=&r" (res), "=&r" (tmp), "=&r" (tmp2) + : "r" (mask), "r" (p) + : "cc", "memory"); + return ((res & mask) != 0); +} + +static __inline int +atomic_testandset_int(volatile u_int *p, u_int v) +{ + + return (atomic_testandset_32((volatile uint32_t *)p, v)); +} + +static __inline int +atomic_testandset_long(volatile u_long *p, u_int v) +{ + + return (atomic_testandset_32((volatile uint32_t *)p, v)); +} + +static __inline int +atomic_testandset_64(volatile uint64_t *p, u_int v) +{ + volatile uint32_t *p32; + + p32 = (volatile uint32_t *)p; + /* Assume little-endian */ + if (v >= 32) { + v &= 0x1f; + p32++; + } + return (atomic_testandset_32(p32, v)); +} + #undef ATOMIC_ACQ_REL #undef ATOMIC_ACQ_REL_LONG