From patchwork Fri Jul 11 08:19:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 4531591 Return-Path: X-Original-To: patchwork-kvm@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 83AFABEEAA for ; Fri, 11 Jul 2014 08:21:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD179201C7 for ; Fri, 11 Jul 2014 08:21:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD233201EC for ; Fri, 11 Jul 2014 08:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752245AbaGKIU2 (ORCPT ); Fri, 11 Jul 2014 04:20:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60763 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752247AbaGKIUV (ORCPT ); Fri, 11 Jul 2014 04:20:21 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6B8KIa9019854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Jul 2014 04:20:18 -0400 Received: from hawk.usersys.redhat.com (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6B8Jmiu010067; Fri, 11 Jul 2014 04:20:16 -0400 From: Andrew Jones To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org, pbonzini@redhat.com Subject: [PATCH v6 13/17] arm: Add spinlock implementation Date: Fri, 11 Jul 2014 10:19:43 +0200 Message-Id: <1405066787-5793-14-git-send-email-drjones@redhat.com> In-Reply-To: <1405066787-5793-1-git-send-email-drjones@redhat.com> References: <1405066787-5793-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 From: Christoffer Dall Add simple busy-wait spinlock implementation for ARM. Signed-off-by: Christoffer Dall Signed-off-by: Andrew Jones --- config/config-arm.mak | 3 ++- lib/arm/asm/spinlock.h | 9 ++------- lib/arm/spinlock.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 lib/arm/spinlock.c diff --git a/config/config-arm.mak b/config/config-arm.mak index 3225018faf933..fb160b6c65e2a 100644 --- a/config/config-arm.mak +++ b/config/config-arm.mak @@ -36,7 +36,8 @@ cflatobjs += \ lib/virtio.o \ lib/chr-testdev.o \ lib/arm/io.o \ - lib/arm/setup.o + lib/arm/setup.o \ + lib/arm/spinlock.o libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o diff --git a/lib/arm/asm/spinlock.h b/lib/arm/asm/spinlock.h index 04f5a1a5538e2..2118a4b3751e0 100644 --- a/lib/arm/asm/spinlock.h +++ b/lib/arm/asm/spinlock.h @@ -5,12 +5,7 @@ struct spinlock { int v; }; -//TODO -static inline void spin_lock(struct spinlock *lock __unused) -{ -} -static inline void spin_unlock(struct spinlock *lock __unused) -{ -} +extern void spin_lock(struct spinlock *lock); +extern void spin_unlock(struct spinlock *lock); #endif /* _ASMARM_SPINLOCK_H_ */ diff --git a/lib/arm/spinlock.c b/lib/arm/spinlock.c new file mode 100644 index 0000000000000..d8a6d4c3383d6 --- /dev/null +++ b/lib/arm/spinlock.c @@ -0,0 +1,28 @@ +#include "libcflat.h" +#include "asm/spinlock.h" +#include "asm/barrier.h" + +void spin_lock(struct spinlock *lock) +{ + u32 val, fail; + + dmb(); + do { + asm volatile( + "1: ldrex %0, [%2]\n" + " teq %0, #0\n" + " bne 1b\n" + " mov %0, #1\n" + " strex %1, %0, [%2]\n" + : "=&r" (val), "=&r" (fail) + : "r" (&lock->v) + : "cc" ); + } while (fail); + dmb(); +} + +void spin_unlock(struct spinlock *lock) +{ + lock->v = 0; + dmb(); +}