blob: 85f888e86761e1b71bd0de2a891a160194e256d7 [file] [log] [blame]
Waiman Longa33fda32015-04-24 14:56:30 -04001/*
2 * Queued spinlock
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
15 *
16 * Authors: Waiman Long <waiman.long@hp.com>
17 */
18#ifndef __ASM_GENERIC_QSPINLOCK_TYPES_H
19#define __ASM_GENERIC_QSPINLOCK_TYPES_H
20
21/*
22 * Including atomic.h with PARAVIRT on will cause compilation errors because
23 * of recursive header file incluson via paravirt_types.h. So don't include
24 * it if PARAVIRT is on.
25 */
26#ifndef CONFIG_PARAVIRT
27#include <linux/types.h>
28#include <linux/atomic.h>
29#endif
30
31typedef struct qspinlock {
32 atomic_t val;
33} arch_spinlock_t;
34
35/*
36 * Bitfields in the atomic value:
37 *
Peter Zijlstra (Intel)69f9cae2015-04-24 14:56:34 -040038 * When NR_CPUS < 16K
39 * 0- 7: locked byte
40 * 8: pending
41 * 9-15: not used
42 * 16-17: tail index
43 * 18-31: tail cpu (+1)
44 *
45 * When NR_CPUS >= 16K
Waiman Longa33fda32015-04-24 14:56:30 -040046 * 0- 7: locked byte
Peter Zijlstra (Intel)c1fb1592015-04-24 14:56:32 -040047 * 8: pending
48 * 9-10: tail index
49 * 11-31: tail cpu (+1)
Waiman Longa33fda32015-04-24 14:56:30 -040050 */
51#define _Q_SET_MASK(type) (((1U << _Q_ ## type ## _BITS) - 1)\
52 << _Q_ ## type ## _OFFSET)
53#define _Q_LOCKED_OFFSET 0
54#define _Q_LOCKED_BITS 8
55#define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED)
56
Peter Zijlstra (Intel)c1fb1592015-04-24 14:56:32 -040057#define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS)
Peter Zijlstra (Intel)69f9cae2015-04-24 14:56:34 -040058#if CONFIG_NR_CPUS < (1U << 14)
59#define _Q_PENDING_BITS 8
60#else
Peter Zijlstra (Intel)c1fb1592015-04-24 14:56:32 -040061#define _Q_PENDING_BITS 1
Peter Zijlstra (Intel)69f9cae2015-04-24 14:56:34 -040062#endif
Peter Zijlstra (Intel)c1fb1592015-04-24 14:56:32 -040063#define _Q_PENDING_MASK _Q_SET_MASK(PENDING)
64
65#define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)
Waiman Longa33fda32015-04-24 14:56:30 -040066#define _Q_TAIL_IDX_BITS 2
67#define _Q_TAIL_IDX_MASK _Q_SET_MASK(TAIL_IDX)
68
69#define _Q_TAIL_CPU_OFFSET (_Q_TAIL_IDX_OFFSET + _Q_TAIL_IDX_BITS)
70#define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)
71#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU)
72
Peter Zijlstra (Intel)69f9cae2015-04-24 14:56:34 -040073#define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET
Waiman Long6403bd72015-04-24 14:56:33 -040074#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)
75
Waiman Longa33fda32015-04-24 14:56:30 -040076#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
Peter Zijlstra (Intel)c1fb1592015-04-24 14:56:32 -040077#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
Waiman Longa33fda32015-04-24 14:56:30 -040078
79#endif /* __ASM_GENERIC_QSPINLOCK_TYPES_H */