--- zzzz-none-000/linux-4.4.60/arch/arm/include/asm/atomic.h 2017-04-08 07:53:53.000000000 +0000 +++ wasp-540e-714/linux-4.4.60/arch/arm/include/asm/atomic.h 2019-07-03 09:21:34.000000000 +0000 @@ -128,6 +128,63 @@ return oldval; } +static inline int atomic_inc_with_max_return(atomic_t *v, unsigned int max_value) +{ + int oldval, newval; + unsigned long tmp; + max_value -= 1; + + smp_mb(); + + __asm__ __volatile__ ("@ atomic_inc_with_max_return\n" +"1: ldrex %0, [%4]\n" +" teq %0, %5\n" +" beq 2f\n" +" add %1, %0, #1\n" +" strex %2, %1, [%4]\n" +" teq %2, #0\n" +" bne 1b\n" +"2:" + : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter) + : "r" (&v->counter), "r" (max_value) + : "cc"); + + if (likely((unsigned int)oldval != max_value)) + { + smp_mb(); + + return newval; + } + + return -1; +} + +static inline int atomic_inc_with_wrap_return(atomic_t *v, unsigned int max_value) +{ + int oldval, newval; + unsigned long tmp; + max_value -= 1; + + smp_mb(); + + __asm__ __volatile__ ("@ atomic_inc_with_wrap_return\n" +"1: ldrex %0, [%4]\n" +" teq %0, %5\n" +" moveq %1, #0\n" +" addne %1, %0, #1\n" +" strex %2, %1, [%4]\n" +" teq %2, #0\n" +" bne 1b\n" +"2:" + : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter) + : "r" (&v->counter), "r" (max_value) + : "cc"); + + smp_mb(); + + return newval; + +} #else /* ARM_ARCH_6 */