1 /* SPDX-License-Identifier: GPL-2.0-or-later */
5 * (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
7 * Authors: Waiman Long <waiman.long@hp.com>
9 #ifndef __ASM_GENERIC_QSPINLOCK_TYPES_H
10 #define __ASM_GENERIC_QSPINLOCK_TYPES_H
13 * Including atomic.h with PARAVIRT on will cause compilation errors because
14 * of recursive header file incluson via paravirt_types.h. So don't include
15 * it if PARAVIRT is on.
17 #ifndef CONFIG_PARAVIRT
18 #include <linux/types.h>
19 #include <linux/atomic.h>
22 typedef struct qspinlock
{
27 * By using the whole 2nd least significant byte for the
28 * pending bit, we can allow better optimization of the lock
29 * acquisition for the pending bit holder.
31 #ifdef __LITTLE_ENDIAN
57 #define __ARCH_SPIN_LOCK_UNLOCKED { { .val = ATOMIC_INIT(0) } }
60 * Bitfields in the atomic value:
67 * 18-31: tail cpu (+1)
73 * 11-31: tail cpu (+1)
75 #define _Q_SET_MASK(type) (((1U << _Q_ ## type ## _BITS) - 1)\
76 << _Q_ ## type ## _OFFSET)
77 #define _Q_LOCKED_OFFSET 0
78 #define _Q_LOCKED_BITS 8
79 #define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED)
81 #define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS)
82 #if CONFIG_NR_CPUS < (1U << 14)
83 #define _Q_PENDING_BITS 8
85 #define _Q_PENDING_BITS 1
87 #define _Q_PENDING_MASK _Q_SET_MASK(PENDING)
89 #define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)
90 #define _Q_TAIL_IDX_BITS 2
91 #define _Q_TAIL_IDX_MASK _Q_SET_MASK(TAIL_IDX)
93 #define _Q_TAIL_CPU_OFFSET (_Q_TAIL_IDX_OFFSET + _Q_TAIL_IDX_BITS)
94 #define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)
95 #define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU)
97 #define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET
98 #define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)
100 #define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
101 #define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
103 #endif /* __ASM_GENERIC_QSPINLOCK_TYPES_H */