Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef _ALPHA_LOCAL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _ALPHA_LOCAL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) typedef struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 	atomic_long_t a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) } local_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define LOCAL_INIT(i)	{ ATOMIC_LONG_INIT(i) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define local_read(l)	atomic_long_read(&(l)->a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define local_set(l,i)	atomic_long_set(&(l)->a, (i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define local_inc(l)	atomic_long_inc(&(l)->a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define local_dec(l)	atomic_long_dec(&(l)->a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define local_add(i,l)	atomic_long_add((i),(&(l)->a))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define local_sub(i,l)	atomic_long_sub((i),(&(l)->a))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static __inline__ long local_add_return(long i, local_t * l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	long temp, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	__asm__ __volatile__(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	"1:	ldq_l %0,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	"	addq %0,%3,%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	"	addq %0,%3,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	"	stq_c %0,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	"	beq %0,2f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	".subsection 2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	"2:	br 1b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	".previous"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	:"=&r" (temp), "=m" (l->a.counter), "=&r" (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	:"Ir" (i), "m" (l->a.counter) : "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static __inline__ long local_sub_return(long i, local_t * l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	long temp, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	__asm__ __volatile__(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	"1:	ldq_l %0,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	"	subq %0,%3,%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	"	subq %0,%3,%0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	"	stq_c %0,%1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	"	beq %0,2f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	".subsection 2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	"2:	br 1b\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	".previous"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	:"=&r" (temp), "=m" (l->a.counter), "=&r" (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	:"Ir" (i), "m" (l->a.counter) : "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define local_cmpxchg(l, o, n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	(cmpxchg_local(&((l)->a.counter), (o), (n)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * local_add_unless - add unless the number is a given value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @l: pointer of type local_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * @a: the amount to add to l...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * @u: ...unless l is equal to u.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * Atomically adds @a to @l, so long as it was not @u.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * Returns non-zero if @l was not @u, and zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define local_add_unless(l, a, u)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	long c, old;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	c = local_read(l);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	for (;;) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (unlikely(c == (u)))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			break;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		old = local_cmpxchg((l), c, c + (a));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (likely(old == c))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			break;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		c = old;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	c != (u);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define local_inc_not_zero(l) local_add_unless((l), 1, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define local_dec_return(l) local_sub_return(1,(l))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define local_inc_return(l) local_add_return(1,(l))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define local_sub_and_test(i,l) (local_sub_return((i), (l)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define local_inc_and_test(l) (local_add_return(1, (l)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define local_dec_and_test(l) (local_sub_return(1, (l)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /* Verify if faster than atomic ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define __local_inc(l)		((l)->a.counter++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define __local_dec(l)		((l)->a.counter++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define __local_add(i,l)	((l)->a.counter+=(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define __local_sub(i,l)	((l)->a.counter-=(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #endif /* _ALPHA_LOCAL_H */