Received: by 10.223.164.202 with SMTP id h10csp1193704wrb; Tue, 7 Nov 2017 23:51:57 -0800 (PST) X-Google-Smtp-Source: ABhQp+RVEZ2ZOPVzeAwQOnBWPAUSSdM7PhnMrsq6JNaIjz0N3eIwSusJgTLLew4vr0ZNFQS7J1Ab X-Received: by 10.84.129.1 with SMTP id 1mr1465899plb.40.1510127517098; Tue, 07 Nov 2017 23:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510127517; cv=none; d=google.com; s=arc-20160816; b=Qkay4uJAhtNmEuSJ3bNcot9o5Y9ANKP645mFdQPD5tsggYxbUeRZR7yS6GrK4AlRoy e/JVfhtToDwBniwkDBddS22hRrvJFjqVxMxE3mNLF+VXDAWzKrRcJgTaQwJcAPfQ4oYA 5ebRk6D3mM96HjCB/wMklx/g+CNG4D1/OgFXnJcobOuPuZtgizw1wIvAbgStXXlOlk7m sj+8Rc+dTO1Swy/dwSAcYEtOFPMHnG8fKplthJFUyzNEjIGOALt5P6wr9xOcu3XJB0LT 8RGN+IJybl68Og6thEB7KR/AiVclcBHHR4FXkd7ujgDiBGhWoTGyKdcxe3PCW/Fw7MFf vH/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=qESlqYm4mwTFyIZxoiO4dC189AquJbzJN9xNsbrgtJo=; b=yEHYfOizaNxYL5ue9LHJyjYq29ZktnoGQzjdB8c8XqnXsCAYm8j3l4u2KOTSGmRMAz Y/2Z3ZJKTVfIicDGexuFvAJ5jdFBvl7Rc2JROJ6PNarJuuD/QZHkYwFB/XXnZHA7pTNA E0MKx5Sq9eEKPCPcUX6K1qeo4J+wyPPIN8G0dMQ0+/p/WNhcHwiQbqEzBVkhamJMc6w/ WscBjQBW2MoGfQV1SJSnM9pv5UH6JhLBGLZniTCWQYjqQ171CCqXyDf4Iw4kTQm3jUCo 6otVnBSZCS0KOh/lO6T7oOmu/5B3Z4/+OgLjLWTDi5uDPMUoMN1M9t3JgXFD+mezoR9x nsBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qu7xfytC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o19si3097219pgn.751.2017.11.07.23.51.44; Tue, 07 Nov 2017 23:51:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qu7xfytC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755085AbdKHG0o (ORCPT + 91 others); Wed, 8 Nov 2017 01:26:44 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:49469 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753864AbdKHGUZ (ORCPT ); Wed, 8 Nov 2017 01:20:25 -0500 Received: by mail-pf0-f193.google.com with SMTP id i5so1110320pfe.6; Tue, 07 Nov 2017 22:20:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=qESlqYm4mwTFyIZxoiO4dC189AquJbzJN9xNsbrgtJo=; b=qu7xfytC/3hNi/9zW46IW1R6qaUwupptax2mmD+xzh9jRZSVjDp+kfnra2/JCP9yNn dLYT2mMLyO1JRYcwc9ntrD21k+p+RrmuC+avodwGDXTc4B8CMkOcDlrxTaBTKZNZcSBY 6pi4cwL32MFjJwnc25J4VIromcw1Vv1Y14EGOVepfYf0MPMoC1GaLqUbjoW7iycQI/cA gGA+8vX73hXM4ypKwIxS6II4GQYdM2xGF1RR464qxxMkkQ0M+DIt3pWeWf8AQ5L89eOb Q6x4hRhrKHklwAIDunmDV/7ou7RtwmiC0DzH/zfKpoXbaOF8hrawdSqWsgmRLTs1ybW9 /Ccw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=qESlqYm4mwTFyIZxoiO4dC189AquJbzJN9xNsbrgtJo=; b=bjkO9j5QPXw9YheIY6NrEuUGSyeY154WHydBPT0B4M48nftgmJkrRlF836mrOFVvhK mDeBzmcWnG20njFe5lx5jiV+/6xcIwzWfG7kTBDESHFh3pRwcIUVeaaDleVjxVJZBdgi vkMccBMwUikQKqFePDPXGwTUmt0CtKkEU8xE1tad2/KzWdArjCC2oIY+SuACWlVCMIil o8epV8C4JuZCQK2HYaweZkVkJzjT9F2NGLVvdF0i1bJvJYZBHSp1uhwKTWt4bEfeVApG 6jqIwANeIw2OtsxndKNiZsBTDQZXX/Kz47qEeupoAxFtsL11tJTxJ96kCg8kBIcEyRAh ot1w== X-Gm-Message-State: AJaThX6R2WiI4B0xzygB8LmpTqZHi1KsPTNpoblnNC1EFT/7l77UASXx eFKaE2pagkQ6bkUU53F9fpM= X-Received: by 10.98.202.133 with SMTP id y5mr1410962pfk.122.1510122024269; Tue, 07 Nov 2017 22:20:24 -0800 (PST) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id a4sm6581339pfj.72.2017.11.07.22.20.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 22:20:23 -0800 (PST) From: Greentime Hu To: greentime@andestech.com, linux-kernel@vger.kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, netdev@vger.kernel.org Cc: green.hu@gmail.com, Vincent Chen Subject: [PATCH 11/31] nds32: Atomic operations Date: Wed, 8 Nov 2017 13:54:59 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greentime Hu Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu --- arch/nds32/include/asm/futex.h | 116 ++++++++++++++++++++++++ arch/nds32/include/asm/spinlock.h | 178 +++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 arch/nds32/include/asm/futex.h create mode 100644 arch/nds32/include/asm/spinlock.h diff --git a/arch/nds32/include/asm/futex.h b/arch/nds32/include/asm/futex.h new file mode 100644 index 0000000..5aa107c --- /dev/null +++ b/arch/nds32/include/asm/futex.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2005-2017 Andes Technology Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __NDS32_FUTEX_H__ +#define __NDS32_FUTEX_H__ + +#include +#include +#include + +#define __futex_atomic_ex_table(err_reg) \ + " .pushsection __ex_table,\"a\"\n" \ + " .align 3\n" \ + " .long 1b, 4f\n" \ + " .long 2b, 4f\n" \ + " .popsection\n" \ + " .pushsection .fixup,\"ax\"\n" \ + "4: move %0, " err_reg "\n" \ + " j 3b\n" \ + " .popsection" + +#define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg) \ + smp_mb(); \ + asm volatile( \ + " movi $ta, #0\n" \ + "1: llw %1, [%2+$ta]\n" \ + " " insn "\n" \ + "2: scw %0, [%2+$ta]\n" \ + " beqz %0, 1b\n" \ + " movi %0, #0\n" \ + "3:\n" \ + __futex_atomic_ex_table("%4") \ + : "=&r" (ret), "=&r" (oldval) \ + : "r" (uaddr), "r" (oparg), "i" (-EFAULT) \ + : "cc", "memory") +static inline int +futex_atomic_cmpxchg_inatomic(u32 * uval, u32 __user * uaddr, + u32 oldval, u32 newval) +{ + int ret = 0; + u32 val, tmp, flags; + + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32))) + return -EFAULT; + + smp_mb(); + asm volatile (" movi $ta, #0\n" + "1: llw %1, [%6 + $ta]\n" + " sub %3, %1, %4\n" + " cmovz %2, %5, %3\n" + " cmovn %2, %1, %3\n" + "2: scw %2, [%6 + $ta]\n" + " beqz %2, 1b\n" + "3:\n " __futex_atomic_ex_table("%7") + :"+&r"(ret), "=&r"(val), "=&r"(tmp), "=&r"(flags) + :"r"(oldval), "r"(newval), "r"(uaddr), "i"(-EFAULT) + :"$ta", "memory"); + smp_mb(); + + *uval = val; + return ret; +} + +static inline int +arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr) +{ + int oldval = 0, ret; + + + pagefault_disable(); + switch (op) { + case FUTEX_OP_SET: + __futex_atomic_op("move %0, %3", ret, oldval, tmp, uaddr, + oparg); + break; + case FUTEX_OP_ADD: + __futex_atomic_op("add %0, %1, %3", ret, oldval, tmp, uaddr, + oparg); + break; + case FUTEX_OP_OR: + __futex_atomic_op("or %0, %1, %3", ret, oldval, tmp, uaddr, + oparg); + break; + case FUTEX_OP_ANDN: + __futex_atomic_op("and %0, %1, %3", ret, oldval, tmp, uaddr, + ~oparg); + break; + case FUTEX_OP_XOR: + __futex_atomic_op("xor %0, %1, %3", ret, oldval, tmp, uaddr, + oparg); + break; + default: + ret = -ENOSYS; + } + + pagefault_enable(); + + if (!ret) + *oval = oldval; + + return ret; +} +#endif /* __NDS32_FUTEX_H__ */ diff --git a/arch/nds32/include/asm/spinlock.h b/arch/nds32/include/asm/spinlock.h new file mode 100644 index 0000000..dd5fc71 --- /dev/null +++ b/arch/nds32/include/asm/spinlock.h @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2005-2017 Andes Technology Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __ASM_SPINLOCK_H +#define __ASM_SPINLOCK_H + +#include + +#define arch_spin_is_locked(x) ((x)->lock != 0) + +#define arch_spin_unlock_wait(lock) \ + do { while (arch_spin_is_locked(lock)) cpu_relax(); } while (0) + +#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock) + +static inline void arch_spin_lock(arch_spinlock_t * lock) +{ + unsigned long tmp; + + __asm__ __volatile__("1:\n" + "\tllw\t%0, [%1]\n" + "\tbnez\t%0, 1b\n" + "\tmovi\t%0, #0x1\n" + "\tscw\t%0, [%1]\n" + "\tbeqz\t%0, 1b\n" + :"=&r"(tmp) + :"r"(&lock->lock) + :"memory"); +} + +static inline int arch_spin_trylock(arch_spinlock_t * lock) +{ + unsigned long ret, tmp; + + __asm__ __volatile__("1:\n" + "\tllw\t%0, [%2]\n" + "\tmovi\t%1, #0x1\n" + "\tscw\t%1, [%2]\n" + "\tbeqz\t%1, 1b\n" + :"=&r"(ret), "=&r"(tmp) + :"r"(&lock->lock) + :"memory"); + + return ret == 0; +} + +static inline void arch_spin_unlock(arch_spinlock_t * lock) +{ + __asm__ __volatile__("xor\t$r15, $r15, $r15\n" + "\tswi\t$r15, [%0]\n" + : + :"r"(&lock->lock) + :"memory"); +} + +static inline void arch_write_lock(arch_rwlock_t * rw) +{ + unsigned long tmp; + + __asm__ __volatile__("1:\n" + "\tllw\t%0, [%1]\n" + "\tbnez\t%0, 1b\n" + "\tsethi\t%0, 0x80000\n" + "\tscw\t%0, [%1]\n" + "\tbeqz\t%0, 1b\n" + :"=&r"(tmp) + :"r"(&rw->lock) + :"memory"); +} + +static inline void arch_write_unlock(arch_rwlock_t * rw) +{ + __asm__ __volatile__("xor\t$r15, $r15, $r15\n" + "\tswi\t$r15, [%0]\n" + : + :"r"(&rw->lock) + :"memory","$r15"); +} + +#define arch_write_can_lock(x) ((x)->lock == 0) +static inline void arch_read_lock(arch_rwlock_t * rw) +{ + int tmp; + + __asm__ __volatile__("1:\n" + "\tllw\t%0, [%1]\n" + "\tbltz\t%0, 1b\n" + "\taddi\t%0, %0, #1\n" + "\tscw\t%0, [%1]\n" + "\tbeqz\t%0, 1b\n" + :"=&r"(tmp) + :"r"(&rw->lock) + :"memory"); +} + +static inline void arch_read_unlock(arch_rwlock_t * rw) +{ + unsigned long tmp; + + __asm__ __volatile__("1:\n" + "\tllw\t%0, [%1]\n" + "\taddi\t%0, %0, #-1\n" + "\tscw\t%0, [%1]\n" + "\tbeqz\t%0, 1b\n" + :"=&r"(tmp) + :"r"(&rw->lock) + :"memory"); +} + +static inline int arch_read_trylock(arch_rwlock_t * rw) +{ + unsigned long ret, tmp; + + __asm__ __volatile__("\tmovi\t%0, #0x0\n" + "1:\n" + "\tllw\t%1, [%2]\n" + "\tbltz\t%1, 2f\n" + "\taddi\t%1, %1, #1\n" + "\tscw\t%1, [%2]\n" + "\tbeqz\t%1, 1b\n" + "\tmovi\t%0, #0x1\n" + "\tj\t3f\n" + "2:\n" + "\tscw\t%1, [%2]\n" + "3:\n" + :"=&r"(ret), "=&r"(tmp) + :"r"(&rw->lock) + :"memory"); + + return ret; +} + +static inline int arch_write_trylock(arch_rwlock_t * rw) +{ + unsigned long ret, tmp; + + __asm__ __volatile__("\tmovi\t%0, #0x0\n" + "1:\n" + "\tllw\t%1, [%2]\n" + "\tbnez\t%1, 2f\n" + "\tsethi\t%1, 0x80000\n" + "\tscw\t%1, [%2]\n" + "\tbeqz\t%1, 1b\n" + "\tmovi\t%0, #0x1\n" + "\tj\t3f\n" + "2:\n" + "\tscw\t%1, [%2]\n" + "3:\n" + :"=&r"(ret), "=&r"(tmp) + :"r"(&rw->lock) + :"memory"); + + return ret; +} + +#define arch_read_lock_flags(lock, flags) arch_read_lock(lock) +#define arch_write_lock_flags(lock, flags) arch_write_lock(lock) + +#define arch_read_can_lock(x) ((x)->lock < 0x80000000) + +#define arch_spin_relax(lock) cpu_relax() +#define arch_read_relax(lock) cpu_relax() +#define arch_write_relax(lock) cpu_relax() + +#endif /* __ASM_SPINLOCK_H */ -- 1.7.9.5 From 1584733742028566120@xxx Wed Nov 22 03:04:28 +0000 2017 X-GM-THRID: 1584732136887075962 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread