1
2
3
4
5
6
7
8
9 #ifndef __ASM_GENERIC_QSPINLOCK_TYPES_H
10 #define __ASM_GENERIC_QSPINLOCK_TYPES_H
11
12
13
14
15
16
17 #ifndef CONFIG_PARAVIRT
18 #include <linux/types.h>
19 #include <linux/atomic.h>
20 #endif
21
22 typedef struct qspinlock {
23 union {
24 atomic_t val;
25
26
27
28
29
30
31 #ifdef __LITTLE_ENDIAN
32 struct {
33 u8 locked;
34 u8 pending;
35 };
36 struct {
37 u16 locked_pending;
38 u16 tail;
39 };
40 #else
41 struct {
42 u16 tail;
43 u16 locked_pending;
44 };
45 struct {
46 u8 reserved[2];
47 u8 pending;
48 u8 locked;
49 };
50 #endif
51 };
52 } arch_spinlock_t;
53
54
55
56
57 #define __ARCH_SPIN_LOCK_UNLOCKED { { .val = ATOMIC_INIT(0) } }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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)
80
81 #define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS)
82 #if CONFIG_NR_CPUS < (1U << 14)
83 #define _Q_PENDING_BITS 8
84 #else
85 #define _Q_PENDING_BITS 1
86 #endif
87 #define _Q_PENDING_MASK _Q_SET_MASK(PENDING)
88
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)
92
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)
96
97 #define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET
98 #define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)
99
100 #define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
101 #define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
102
103 #endif