2018-12-11 21:54:06 +08:00
|
|
|
/*
|
2019-01-24 14:11:10 +08:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
2018-12-11 21:54:06 +08:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RISCV_ATOMIC_H__
|
|
|
|
#define __RISCV_ATOMIC_H__
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
volatile long counter;
|
|
|
|
} atomic_t;
|
|
|
|
|
2019-04-11 08:41:52 +08:00
|
|
|
#define ATOMIC_INIT(_lptr, val) (_lptr)->counter = (val)
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2019-04-11 08:41:52 +08:00
|
|
|
#define ATOMIC_INITIALIZER(val) \
|
|
|
|
{ \
|
|
|
|
.counter = (val), \
|
|
|
|
}
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
long atomic_read(atomic_t *atom);
|
|
|
|
|
|
|
|
void atomic_write(atomic_t *atom, long value);
|
|
|
|
|
|
|
|
long atomic_add_return(atomic_t *atom, long value);
|
|
|
|
|
|
|
|
long atomic_sub_return(atomic_t *atom, long value);
|
|
|
|
|
2020-03-26 20:40:02 +08:00
|
|
|
long atomic_cmpxchg(atomic_t *atom, long oldval, long newval);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
2020-03-26 20:40:02 +08:00
|
|
|
long atomic_xchg(atomic_t *atom, long newval);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
unsigned int atomic_raw_xchg_uint(volatile unsigned int *ptr,
|
|
|
|
unsigned int newval);
|
2019-08-15 09:02:13 +08:00
|
|
|
|
|
|
|
unsigned long atomic_raw_xchg_ulong(volatile unsigned long *ptr,
|
|
|
|
unsigned long newval);
|
2019-01-21 15:23:28 +08:00
|
|
|
/**
|
|
|
|
* Set a bit in an atomic variable and return the new value.
|
|
|
|
* @nr : Bit to set.
|
|
|
|
* @atom: atomic variable to modify
|
|
|
|
*/
|
|
|
|
int atomic_set_bit(int nr, atomic_t *atom);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a bit in an atomic variable and return the new value.
|
|
|
|
* @nr : Bit to set.
|
|
|
|
* @atom: atomic variable to modify
|
|
|
|
*/
|
|
|
|
|
|
|
|
int atomic_clear_bit(int nr, atomic_t *atom);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a bit in any address and return the new value .
|
|
|
|
* @nr : Bit to set.
|
|
|
|
* @addr: Address to modify
|
|
|
|
*/
|
|
|
|
int atomic_raw_set_bit(int nr, volatile unsigned long *addr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a bit in any address and return the new value .
|
|
|
|
* @nr : Bit to set.
|
|
|
|
* @addr: Address to modify
|
|
|
|
*/
|
|
|
|
int atomic_raw_clear_bit(int nr, volatile unsigned long *addr);
|
2018-12-11 21:54:06 +08:00
|
|
|
|
|
|
|
#endif
|