1 #ifndef __LINUX_SPINLOCK_TYPES_RAW_H
2 #define __LINUX_SPINLOCK_TYPES_RAW_H
3 
4 #include <linux/types.h>
5 
6 #if defined(CONFIG_SMP)
7 # include <asm/spinlock_types.h>
8 #else
9 # include <linux/spinlock_types_up.h>
10 #endif
11 
12 #include <linux/lockdep_types.h>
13 
14 typedef struct raw_spinlock {
15 	arch_spinlock_t raw_lock;
16 #ifdef CONFIG_DEBUG_SPINLOCK
17 	unsigned int magic, owner_cpu;
18 	void *owner;
19 #endif
20 #ifdef CONFIG_DEBUG_LOCK_ALLOC
21 	struct lockdep_map dep_map;
22 #endif
23 } raw_spinlock_t;
24 
25 #define SPINLOCK_MAGIC		0xdead4ead
26 
27 #define SPINLOCK_OWNER_INIT	((void *)-1L)
28 
29 #ifdef CONFIG_DEBUG_LOCK_ALLOC
30 # define RAW_SPIN_DEP_MAP_INIT(lockname)		\
31 	.dep_map = {					\
32 		.name = #lockname,			\
33 		.wait_type_inner = LD_WAIT_SPIN,	\
34 	}
35 # define SPIN_DEP_MAP_INIT(lockname)			\
36 	.dep_map = {					\
37 		.name = #lockname,			\
38 		.wait_type_inner = LD_WAIT_CONFIG,	\
39 	}
40 
41 # define LOCAL_SPIN_DEP_MAP_INIT(lockname)		\
42 	.dep_map = {					\
43 		.name = #lockname,			\
44 		.wait_type_inner = LD_WAIT_CONFIG,	\
45 		.lock_type = LD_LOCK_PERCPU,		\
46 	}
47 #else
48 # define RAW_SPIN_DEP_MAP_INIT(lockname)
49 # define SPIN_DEP_MAP_INIT(lockname)
50 # define LOCAL_SPIN_DEP_MAP_INIT(lockname)
51 #endif
52 
53 #ifdef CONFIG_DEBUG_SPINLOCK
54 # define SPIN_DEBUG_INIT(lockname)		\
55 	.magic = SPINLOCK_MAGIC,		\
56 	.owner_cpu = -1,			\
57 	.owner = SPINLOCK_OWNER_INIT,
58 #else
59 # define SPIN_DEBUG_INIT(lockname)
60 #endif
61 
62 #define __RAW_SPIN_LOCK_INITIALIZER(lockname)	\
63 {						\
64 	.raw_lock = __ARCH_SPIN_LOCK_UNLOCKED,	\
65 	SPIN_DEBUG_INIT(lockname)		\
66 	RAW_SPIN_DEP_MAP_INIT(lockname) }
67 
68 #define __RAW_SPIN_LOCK_UNLOCKED(lockname)	\
69 	(raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
70 
71 #define DEFINE_RAW_SPINLOCK(x)  raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
72 
73 #endif /* __LINUX_SPINLOCK_TYPES_RAW_H */
74