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 _ASM_PARISC_FUTEX_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _ASM_PARISC_FUTEX_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/futex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <asm/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <asm/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) /* The following has to match the LWS code in syscall.S.  We have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)    sixteen four-word locks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) _futex_spin_lock_irqsave(u32 __user *uaddr, unsigned long int *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	extern u32 lws_lock_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	long index = ((long)uaddr & 0x7f8) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	arch_spinlock_t *s = (arch_spinlock_t *)&lws_lock_start[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	local_irq_save(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	arch_spin_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) _futex_spin_unlock_irqrestore(u32 __user *uaddr, unsigned long int *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	extern u32 lws_lock_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	long index = ((long)uaddr & 0x7f8) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	arch_spinlock_t *s = (arch_spinlock_t *)&lws_lock_start[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	arch_spin_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	local_irq_restore(*flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	unsigned long int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int oldval, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	_futex_spin_lock_irqsave(uaddr, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (unlikely(get_user(oldval, uaddr) != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		goto out_pagefault_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	tmp = oldval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	switch (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	case FUTEX_OP_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		tmp = oparg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case FUTEX_OP_ADD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		tmp += oparg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	case FUTEX_OP_OR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		tmp |= oparg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	case FUTEX_OP_ANDN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		tmp &= ~oparg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case FUTEX_OP_XOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		tmp ^= oparg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		ret = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) out_pagefault_enable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	_futex_spin_unlock_irqrestore(uaddr, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		*oval = oldval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			      u32 oldval, u32 newval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/* futex.c wants to do a cmpxchg_inatomic on kernel NULL, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * our gateway page, and causes no end of trouble...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (uaccess_kernel() && !uaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (!access_ok(uaddr, sizeof(u32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* HPPA has no cmpxchg in hardware and therefore the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 * best we can do here is use an array of locks. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * lock selected is based on a hash of the userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 * address. This should scale to a couple of CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	_futex_spin_lock_irqsave(uaddr, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (unlikely(get_user(val, uaddr) != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		_futex_spin_unlock_irqrestore(uaddr, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		_futex_spin_unlock_irqrestore(uaddr, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	*uval = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	_futex_spin_unlock_irqrestore(uaddr, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif /*__KERNEL__*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #endif /*_ASM_PARISC_FUTEX_H*/