1ed51adf4SFrançois Tigeot /*
2ed51adf4SFrançois Tigeot * Copyright (c) 2019 François Tigeot <ftigeot@wolfpond.org>
3ed51adf4SFrançois Tigeot * All rights reserved.
4ed51adf4SFrançois Tigeot *
5ed51adf4SFrançois Tigeot * Redistribution and use in source and binary forms, with or without
6ed51adf4SFrançois Tigeot * modification, are permitted provided that the following conditions
7ed51adf4SFrançois Tigeot * are met:
8ed51adf4SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
9ed51adf4SFrançois Tigeot * notice unmodified, this list of conditions, and the following
10ed51adf4SFrançois Tigeot * disclaimer.
11ed51adf4SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
12ed51adf4SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
13ed51adf4SFrançois Tigeot * documentation and/or other materials provided with the distribution.
14ed51adf4SFrançois Tigeot *
15ed51adf4SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16ed51adf4SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17ed51adf4SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18ed51adf4SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19ed51adf4SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20ed51adf4SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21ed51adf4SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22ed51adf4SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23ed51adf4SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24ed51adf4SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25ed51adf4SFrançois Tigeot */
26ed51adf4SFrançois Tigeot
27ed51adf4SFrançois Tigeot #ifndef _ASM_ATOMIC64_64_H_
28ed51adf4SFrançois Tigeot #define _ASM_ATOMIC64_64_H_
29ed51adf4SFrançois Tigeot
30ed51adf4SFrançois Tigeot #include <linux/types.h>
31ed51adf4SFrançois Tigeot
3255f3230cSFrançois Tigeot #include <cpu/x86_64/include/atomic.h>
3355f3230cSFrançois Tigeot
34ed51adf4SFrançois Tigeot static inline long
atomic64_add_return(int64_t i,atomic64_t * v)35ed51adf4SFrançois Tigeot atomic64_add_return(int64_t i, atomic64_t *v)
36ed51adf4SFrançois Tigeot {
37ed51adf4SFrançois Tigeot return i + atomic_fetchadd_64(&v->counter, i);
38ed51adf4SFrançois Tigeot }
39ed51adf4SFrançois Tigeot
40*78973132SSergey Zigachev /* From Linux */
41*78973132SSergey Zigachev static inline void
atomic64_inc(atomic64_t * v)42*78973132SSergey Zigachev atomic64_inc(atomic64_t *v)
43*78973132SSergey Zigachev {
44*78973132SSergey Zigachev __asm __volatile(MPLOCKED "incq %0"
45*78973132SSergey Zigachev : "=m" (v->counter)
46*78973132SSergey Zigachev : "m" (v->counter));
47*78973132SSergey Zigachev }
48*78973132SSergey Zigachev
49ed51adf4SFrançois Tigeot #endif /* _ASM_ATOMIC64_64_H_ */
50