mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-19 09:04:57 +00:00
c942fddf87
Based on 3 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version [author] [kishon] [vijay] [abraham] [i] [kishon]@[ti] [com] this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version [author] [graeme] [gregory] [gg]@[slimlogic] [co] [uk] [author] [kishon] [vijay] [abraham] [i] [kishon]@[ti] [com] [based] [on] [twl6030]_[usb] [c] [author] [hema] [hk] [hemahk]@[ti] [com] this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details extracted by the scancode license scanner the SPDX license identifier GPL-2.0-or-later has been chosen to replace the boilerplate/reference in 1105 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Richard Fontana <rfontana@redhat.com> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190527070033.202006027@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
103 lines
2.3 KiB
C
103 lines
2.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Queued spinlock
|
|
*
|
|
* (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
|
|
*
|
|
* Authors: Waiman Long <waiman.long@hp.com>
|
|
*/
|
|
#ifndef __ASM_GENERIC_QSPINLOCK_TYPES_H
|
|
#define __ASM_GENERIC_QSPINLOCK_TYPES_H
|
|
|
|
/*
|
|
* Including atomic.h with PARAVIRT on will cause compilation errors because
|
|
* of recursive header file incluson via paravirt_types.h. So don't include
|
|
* it if PARAVIRT is on.
|
|
*/
|
|
#ifndef CONFIG_PARAVIRT
|
|
#include <linux/types.h>
|
|
#include <linux/atomic.h>
|
|
#endif
|
|
|
|
typedef struct qspinlock {
|
|
union {
|
|
atomic_t val;
|
|
|
|
/*
|
|
* By using the whole 2nd least significant byte for the
|
|
* pending bit, we can allow better optimization of the lock
|
|
* acquisition for the pending bit holder.
|
|
*/
|
|
#ifdef __LITTLE_ENDIAN
|
|
struct {
|
|
u8 locked;
|
|
u8 pending;
|
|
};
|
|
struct {
|
|
u16 locked_pending;
|
|
u16 tail;
|
|
};
|
|
#else
|
|
struct {
|
|
u16 tail;
|
|
u16 locked_pending;
|
|
};
|
|
struct {
|
|
u8 reserved[2];
|
|
u8 pending;
|
|
u8 locked;
|
|
};
|
|
#endif
|
|
};
|
|
} arch_spinlock_t;
|
|
|
|
/*
|
|
* Initializier
|
|
*/
|
|
#define __ARCH_SPIN_LOCK_UNLOCKED { { .val = ATOMIC_INIT(0) } }
|
|
|
|
/*
|
|
* Bitfields in the atomic value:
|
|
*
|
|
* When NR_CPUS < 16K
|
|
* 0- 7: locked byte
|
|
* 8: pending
|
|
* 9-15: not used
|
|
* 16-17: tail index
|
|
* 18-31: tail cpu (+1)
|
|
*
|
|
* When NR_CPUS >= 16K
|
|
* 0- 7: locked byte
|
|
* 8: pending
|
|
* 9-10: tail index
|
|
* 11-31: tail cpu (+1)
|
|
*/
|
|
#define _Q_SET_MASK(type) (((1U << _Q_ ## type ## _BITS) - 1)\
|
|
<< _Q_ ## type ## _OFFSET)
|
|
#define _Q_LOCKED_OFFSET 0
|
|
#define _Q_LOCKED_BITS 8
|
|
#define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED)
|
|
|
|
#define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS)
|
|
#if CONFIG_NR_CPUS < (1U << 14)
|
|
#define _Q_PENDING_BITS 8
|
|
#else
|
|
#define _Q_PENDING_BITS 1
|
|
#endif
|
|
#define _Q_PENDING_MASK _Q_SET_MASK(PENDING)
|
|
|
|
#define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)
|
|
#define _Q_TAIL_IDX_BITS 2
|
|
#define _Q_TAIL_IDX_MASK _Q_SET_MASK(TAIL_IDX)
|
|
|
|
#define _Q_TAIL_CPU_OFFSET (_Q_TAIL_IDX_OFFSET + _Q_TAIL_IDX_BITS)
|
|
#define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)
|
|
#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU)
|
|
|
|
#define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET
|
|
#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)
|
|
|
|
#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
|
|
#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
|
|
|
|
#endif /* __ASM_GENERIC_QSPINLOCK_TYPES_H */
|