1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Atomic operations for RISC_V */
#ifndef __CROS_EC_ATOMIC_H
#define __CROS_EC_ATOMIC_H
#include "common.h"
#include "cpu.h"
#include "task.h"
#define ATOMIC_OP(op, value, addr) \
({ \
uint32_t tmp; \
asm volatile ( \
"amo" #op ".w.aqrl %0, %2, %1" \
: "=r" (tmp), "+A" (*addr) \
: "r" (value)); \
tmp; \
})
static inline void atomic_clear(volatile uint32_t *addr, uint32_t bits)
{
ATOMIC_OP(and, ~bits, addr);
}
static inline void atomic_or(volatile uint32_t *addr, uint32_t bits)
{
ATOMIC_OP(or, bits, addr);
}
static inline void atomic_add(volatile uint32_t *addr, uint32_t value)
{
ATOMIC_OP(add, value, addr);
}
static inline void atomic_sub(volatile uint32_t *addr, uint32_t value)
{
ATOMIC_OP(add, -value, addr);
}
static inline uint32_t atomic_read_clear(volatile uint32_t *addr)
{
return ATOMIC_OP(and, 0, addr);
}
static inline uint32_t atomic_inc(volatile uint32_t *addr, uint32_t value)
{
return ATOMIC_OP(add, value, addr);
}
static inline uint32_t atomic_dec(volatile uint32_t *addr, uint32_t value)
{
return ATOMIC_OP(add, -value, addr);
}
#endif /* __CROS_EC_ATOMIC_H */
|