1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_PARISC_FUTEX_H
3 #define _ASM_PARISC_FUTEX_H
5 #include <linux/futex.h>
6 #include <linux/uaccess.h>
7 #include <asm/atomic.h>
10 /* The following has to match the LWS code in syscall.S. We have
11 * 256 four-word locks. We use bits 20-27 of the futex virtual
12 * address for the hash index.
15 static inline unsigned long _futex_hash_index(unsigned long ua)
17 return (ua >> 2) & 0x3fc;
21 _futex_spin_lock_irqsave(arch_spinlock_t *s, unsigned long *flags)
23 local_irq_save(*flags);
28 _futex_spin_unlock_irqrestore(arch_spinlock_t *s, unsigned long *flags)
31 local_irq_restore(*flags);
35 arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
37 extern u32 lws_lock_start[];
38 unsigned long ua = (unsigned long)uaddr;
44 s = (arch_spinlock_t *)&lws_lock_start[_futex_hash_index(ua)];
45 _futex_spin_lock_irqsave(s, &flags);
47 /* Return -EFAULT if we encounter a page fault or COW break */
48 if (unlikely(get_user(oldval, uaddr) != 0)) {
50 goto out_pagefault_enable;
74 goto out_pagefault_enable;
77 if (unlikely(put_user(tmp, uaddr) != 0))
81 _futex_spin_unlock_irqrestore(s, &flags);
90 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
91 u32 oldval, u32 newval)
93 extern u32 lws_lock_start[];
94 unsigned long ua = (unsigned long)uaddr;
99 if (!access_ok(uaddr, sizeof(u32)))
102 /* HPPA has no cmpxchg in hardware and therefore the
103 * best we can do here is use an array of locks. The
104 * lock selected is based on a hash of the virtual
105 * address of the futex. This should scale to a couple
109 s = (arch_spinlock_t *)&lws_lock_start[_futex_hash_index(ua)];
110 _futex_spin_lock_irqsave(s, &flags);
111 if (unlikely(get_user(val, uaddr) != 0)) {
112 _futex_spin_unlock_irqrestore(s, &flags);
116 if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) {
117 _futex_spin_unlock_irqrestore(s, &flags);
122 _futex_spin_unlock_irqrestore(s, &flags);
127 #endif /*_ASM_PARISC_FUTEX_H*/