mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-24 09:06:34 +07:00
50acfb2b76
Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation version 2 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 extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 97 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190529141901.025053186@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
136 lines
2.4 KiB
C
136 lines
2.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2015 Regents of the University of California
|
|
* Copyright (C) 2017 SiFive
|
|
*/
|
|
|
|
#ifndef _ASM_RISCV_SPINLOCK_H
|
|
#define _ASM_RISCV_SPINLOCK_H
|
|
|
|
#include <linux/kernel.h>
|
|
#include <asm/current.h>
|
|
#include <asm/fence.h>
|
|
|
|
/*
|
|
* Simple spin lock operations. These provide no fairness guarantees.
|
|
*/
|
|
|
|
/* FIXME: Replace this with a ticket lock, like MIPS. */
|
|
|
|
#define arch_spin_is_locked(x) (READ_ONCE((x)->lock) != 0)
|
|
|
|
static inline void arch_spin_unlock(arch_spinlock_t *lock)
|
|
{
|
|
smp_store_release(&lock->lock, 0);
|
|
}
|
|
|
|
static inline int arch_spin_trylock(arch_spinlock_t *lock)
|
|
{
|
|
int tmp = 1, busy;
|
|
|
|
__asm__ __volatile__ (
|
|
" amoswap.w %0, %2, %1\n"
|
|
RISCV_ACQUIRE_BARRIER
|
|
: "=r" (busy), "+A" (lock->lock)
|
|
: "r" (tmp)
|
|
: "memory");
|
|
|
|
return !busy;
|
|
}
|
|
|
|
static inline void arch_spin_lock(arch_spinlock_t *lock)
|
|
{
|
|
while (1) {
|
|
if (arch_spin_is_locked(lock))
|
|
continue;
|
|
|
|
if (arch_spin_trylock(lock))
|
|
break;
|
|
}
|
|
}
|
|
|
|
/***********************************************************/
|
|
|
|
static inline void arch_read_lock(arch_rwlock_t *lock)
|
|
{
|
|
int tmp;
|
|
|
|
__asm__ __volatile__(
|
|
"1: lr.w %1, %0\n"
|
|
" bltz %1, 1b\n"
|
|
" addi %1, %1, 1\n"
|
|
" sc.w %1, %1, %0\n"
|
|
" bnez %1, 1b\n"
|
|
RISCV_ACQUIRE_BARRIER
|
|
: "+A" (lock->lock), "=&r" (tmp)
|
|
:: "memory");
|
|
}
|
|
|
|
static inline void arch_write_lock(arch_rwlock_t *lock)
|
|
{
|
|
int tmp;
|
|
|
|
__asm__ __volatile__(
|
|
"1: lr.w %1, %0\n"
|
|
" bnez %1, 1b\n"
|
|
" li %1, -1\n"
|
|
" sc.w %1, %1, %0\n"
|
|
" bnez %1, 1b\n"
|
|
RISCV_ACQUIRE_BARRIER
|
|
: "+A" (lock->lock), "=&r" (tmp)
|
|
:: "memory");
|
|
}
|
|
|
|
static inline int arch_read_trylock(arch_rwlock_t *lock)
|
|
{
|
|
int busy;
|
|
|
|
__asm__ __volatile__(
|
|
"1: lr.w %1, %0\n"
|
|
" bltz %1, 1f\n"
|
|
" addi %1, %1, 1\n"
|
|
" sc.w %1, %1, %0\n"
|
|
" bnez %1, 1b\n"
|
|
RISCV_ACQUIRE_BARRIER
|
|
"1:\n"
|
|
: "+A" (lock->lock), "=&r" (busy)
|
|
:: "memory");
|
|
|
|
return !busy;
|
|
}
|
|
|
|
static inline int arch_write_trylock(arch_rwlock_t *lock)
|
|
{
|
|
int busy;
|
|
|
|
__asm__ __volatile__(
|
|
"1: lr.w %1, %0\n"
|
|
" bnez %1, 1f\n"
|
|
" li %1, -1\n"
|
|
" sc.w %1, %1, %0\n"
|
|
" bnez %1, 1b\n"
|
|
RISCV_ACQUIRE_BARRIER
|
|
"1:\n"
|
|
: "+A" (lock->lock), "=&r" (busy)
|
|
:: "memory");
|
|
|
|
return !busy;
|
|
}
|
|
|
|
static inline void arch_read_unlock(arch_rwlock_t *lock)
|
|
{
|
|
__asm__ __volatile__(
|
|
RISCV_RELEASE_BARRIER
|
|
" amoadd.w x0, %1, %0\n"
|
|
: "+A" (lock->lock)
|
|
: "r" (-1)
|
|
: "memory");
|
|
}
|
|
|
|
static inline void arch_write_unlock(arch_rwlock_t *lock)
|
|
{
|
|
smp_store_release(&lock->lock, 0);
|
|
}
|
|
|
|
#endif /* _ASM_RISCV_SPINLOCK_H */
|