percpu.h 3.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef __ARCH_S390_PERCPU__
#define __ARCH_S390_PERCPU__

4 5 6
#include <linux/preempt.h>
#include <asm/cmpxchg.h>

L
Linus Torvalds 已提交
7 8 9 10
/*
 * s390 uses its own implementation for per cpu data, the offset of
 * the cpu local data area is cached in the cpu's lowcore memory.
 */
11
#define __my_cpu_offset S390_lowcore.percpu_offset
L
Linus Torvalds 已提交
12

13 14 15 16 17
/*
 * For 64 bit module code, the module may be more than 4G above the
 * per cpu area, use weak definitions to force the compiler to
 * generate external references.
 */
18
#if defined(CONFIG_SMP) && defined(CONFIG_64BIT) && defined(MODULE)
19
#define ARCH_NEEDS_WEAK_PER_CPU
L
Linus Torvalds 已提交
20 21
#endif

22
#define arch_this_cpu_to_op(pcp, val, op)				\
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
do {									\
	typedef typeof(pcp) pcp_op_T__;					\
	pcp_op_T__ old__, new__, prev__;				\
	pcp_op_T__ *ptr__;						\
	preempt_disable();						\
	ptr__ = __this_cpu_ptr(&(pcp));					\
	prev__ = *ptr__;						\
	do {								\
		old__ = prev__;						\
		new__ = old__ op (val);					\
		switch (sizeof(*ptr__)) {				\
		case 8:							\
			prev__ = cmpxchg64(ptr__, old__, new__);	\
			break;						\
		default:						\
			prev__ = cmpxchg(ptr__, old__, new__);		\
		}							\
	} while (prev__ != old__);					\
	preempt_enable();						\
} while (0)

44 45 46 47
#define this_cpu_add_1(pcp, val) arch_this_cpu_to_op(pcp, val, +)
#define this_cpu_add_2(pcp, val) arch_this_cpu_to_op(pcp, val, +)
#define this_cpu_add_4(pcp, val) arch_this_cpu_to_op(pcp, val, +)
#define this_cpu_add_8(pcp, val) arch_this_cpu_to_op(pcp, val, +)
48

49 50 51 52
#define this_cpu_and_1(pcp, val) arch_this_cpu_to_op(pcp, val, &)
#define this_cpu_and_2(pcp, val) arch_this_cpu_to_op(pcp, val, &)
#define this_cpu_and_4(pcp, val) arch_this_cpu_to_op(pcp, val, &)
#define this_cpu_and_8(pcp, val) arch_this_cpu_to_op(pcp, val, &)
53

54 55 56 57
#define this_cpu_or_1(pcp, val) arch_this_cpu_to_op(pcp, val, |)
#define this_cpu_or_2(pcp, val) arch_this_cpu_to_op(pcp, val, |)
#define this_cpu_or_4(pcp, val) arch_this_cpu_to_op(pcp, val, |)
#define this_cpu_or_8(pcp, val) arch_this_cpu_to_op(pcp, val, |)
58

59 60 61 62
#define this_cpu_xor_1(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
#define this_cpu_xor_2(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
#define this_cpu_xor_4(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
#define this_cpu_xor_8(pcp, val) arch_this_cpu_to_op(pcp, val, ^)
63

64
#define arch_this_cpu_cmpxchg(pcp, oval, nval)			\
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
({									\
	typedef typeof(pcp) pcp_op_T__;					\
	pcp_op_T__ ret__;						\
	pcp_op_T__ *ptr__;						\
	preempt_disable();						\
	ptr__ = __this_cpu_ptr(&(pcp));					\
	switch (sizeof(*ptr__)) {					\
	case 8:								\
		ret__ = cmpxchg64(ptr__, oval, nval);			\
		break;							\
	default:							\
		ret__ = cmpxchg(ptr__, oval, nval);			\
	}								\
	preempt_enable();						\
	ret__;								\
})

82 83 84 85
#define this_cpu_cmpxchg_1(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
#define this_cpu_cmpxchg_2(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
#define this_cpu_cmpxchg_4(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
#define this_cpu_cmpxchg_8(pcp, oval, nval) arch_this_cpu_cmpxchg(pcp, oval, nval)
86

87
#include <asm-generic/percpu.h>
L
Linus Torvalds 已提交
88 89

#endif /* __ARCH_S390_PERCPU__ */