]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/powerpc/include/asm/local.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ARCH_POWERPC_LOCAL_H
3 #define _ARCH_POWERPC_LOCAL_H
5 #ifdef CONFIG_PPC_BOOK3S_64
7 #include <linux/percpu.h>
8 #include <linux/atomic.h>
9 #include <linux/irqflags.h>
11 #include <asm/hw_irq.h>
18 #define LOCAL_INIT(i) { (i) }
20 static __inline__
long local_read(local_t
*l
)
22 return READ_ONCE(l
->v
);
25 static __inline__
void local_set(local_t
*l
, long i
)
30 #define LOCAL_OP(op, c_op) \
31 static __inline__ void local_##op(long i, local_t *l) \
33 unsigned long flags; \
35 powerpc_local_irq_pmu_save(flags); \
37 powerpc_local_irq_pmu_restore(flags); \
40 #define LOCAL_OP_RETURN(op, c_op) \
41 static __inline__ long local_##op##_return(long a, local_t *l) \
44 unsigned long flags; \
46 powerpc_local_irq_pmu_save(flags); \
48 powerpc_local_irq_pmu_restore(flags); \
53 #define LOCAL_OPS(op, c_op) \
55 LOCAL_OP_RETURN(op, c_op)
60 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
61 #define local_inc_return(l) local_add_return(1LL, l)
62 #define local_inc(l) local_inc_return(l)
65 * local_inc_and_test - increment and test
66 * @l: pointer of type local_t
68 * Atomically increments @l by 1
69 * and returns true if the result is zero, or false for all
72 #define local_inc_and_test(l) (local_inc_return(l) == 0)
74 #define local_dec_return(l) local_sub_return(1LL, l)
75 #define local_dec(l) local_dec_return(l)
76 #define local_sub_and_test(a, l) (local_sub_return((a), (l)) == 0)
77 #define local_dec_and_test(l) (local_dec_return((l)) == 0)
79 static __inline__
long local_cmpxchg(local_t
*l
, long o
, long n
)
84 powerpc_local_irq_pmu_save(flags
);
88 powerpc_local_irq_pmu_restore(flags
);
93 static __inline__
long local_xchg(local_t
*l
, long n
)
98 powerpc_local_irq_pmu_save(flags
);
101 powerpc_local_irq_pmu_restore(flags
);
107 * local_add_unless - add unless the number is a given value
108 * @l: pointer of type local_t
109 * @a: the amount to add to v...
110 * @u: ...unless v is equal to u.
112 * Atomically adds @a to @l, so long as it was not @u.
113 * Returns non-zero if @l was not @u, and zero otherwise.
115 static __inline__
int local_add_unless(local_t
*l
, long a
, long u
)
120 powerpc_local_irq_pmu_save(flags
);
125 powerpc_local_irq_pmu_restore(flags
);
130 #define local_inc_not_zero(l) local_add_unless((l), 1, 0)
132 /* Use these for per-cpu local_t variables: on some archs they are
133 * much more efficient than these naive implementations. Note they take
134 * a variable, not an address.
137 #define __local_inc(l) ((l)->v++)
138 #define __local_dec(l) ((l)->v++)
139 #define __local_add(i,l) ((l)->v+=(i))
140 #define __local_sub(i,l) ((l)->v-=(i))
142 #else /* CONFIG_PPC64 */
144 #include <asm-generic/local.h>
146 #endif /* CONFIG_PPC64 */
148 #endif /* _ARCH_POWERPC_LOCAL_H */