xref: /openbmc/linux/arch/s390/include/asm/ctl_reg.h (revision 12eb4683)
1 /*
2  * Copyright IBM Corp. 1999, 2009
3  *
4  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
5  */
6 
7 #ifndef __ASM_CTL_REG_H
8 #define __ASM_CTL_REG_H
9 
10 #include <linux/bug.h>
11 
12 #ifdef CONFIG_64BIT
13 # define __CTL_LOAD	"lctlg"
14 # define __CTL_STORE	"stctg"
15 #else
16 # define __CTL_LOAD	"lctl"
17 # define __CTL_STORE	"stctl"
18 #endif
19 
20 #define __ctl_load(array, low, high) {					\
21 	typedef struct { char _[sizeof(array)]; } addrtype;		\
22 									\
23 	BUILD_BUG_ON(sizeof(addrtype) != (high - low + 1) * sizeof(long));\
24 	asm volatile(							\
25 		__CTL_LOAD " %1,%2,%0\n"				\
26 		: : "Q" (*(addrtype *)(&array)), "i" (low), "i" (high));\
27 }
28 
29 #define __ctl_store(array, low, high) {					\
30 	typedef struct { char _[sizeof(array)]; } addrtype;		\
31 									\
32 	BUILD_BUG_ON(sizeof(addrtype) != (high - low + 1) * sizeof(long));\
33 	asm volatile(							\
34 		__CTL_STORE " %1,%2,%0\n"				\
35 		: "=Q" (*(addrtype *)(&array))				\
36 		: "i" (low), "i" (high));				\
37 }
38 
39 static inline void __ctl_set_bit(unsigned int cr, unsigned int bit)
40 {
41 	unsigned long reg;
42 
43 	__ctl_store(reg, cr, cr);
44 	reg |= 1UL << bit;
45 	__ctl_load(reg, cr, cr);
46 }
47 
48 static inline void __ctl_clear_bit(unsigned int cr, unsigned int bit)
49 {
50 	unsigned long reg;
51 
52 	__ctl_store(reg, cr, cr);
53 	reg &= ~(1UL << bit);
54 	__ctl_load(reg, cr, cr);
55 }
56 
57 void smp_ctl_set_bit(int cr, int bit);
58 void smp_ctl_clear_bit(int cr, int bit);
59 
60 #ifdef CONFIG_SMP
61 # define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
62 # define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
63 #else
64 # define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
65 # define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
66 #endif
67 
68 #endif /* __ASM_CTL_REG_H */
69