1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright IBM Corp. 1999, 2009 4 * 5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 6 */ 7 8 #ifndef __ASM_S390_CTLREG_H 9 #define __ASM_S390_CTLREG_H 10 11 #include <linux/bits.h> 12 13 #define CR0_TRANSACTIONAL_EXECUTION_BIT (63 - 8) 14 #define CR0_CLOCK_COMPARATOR_SIGN_BIT (63 - 10) 15 #define CR0_CRYPTOGRAPHY_COUNTER_BIT (63 - 13) 16 #define CR0_PAI_EXTENSION_BIT (63 - 14) 17 #define CR0_CPUMF_EXTRACTION_AUTH_BIT (63 - 15) 18 #define CR0_WARNING_TRACK_BIT (63 - 30) 19 #define CR0_LOW_ADDRESS_PROTECTION_BIT (63 - 35) 20 #define CR0_FETCH_PROTECTION_OVERRIDE_BIT (63 - 38) 21 #define CR0_STORAGE_PROTECTION_OVERRIDE_BIT (63 - 39) 22 #define CR0_EDAT_BIT (63 - 40) 23 #define CR0_INSTRUCTION_EXEC_PROTECTION_BIT (63 - 43) 24 #define CR0_VECTOR_BIT (63 - 46) 25 #define CR0_MALFUNCTION_ALERT_SUBMASK_BIT (63 - 48) 26 #define CR0_EMERGENCY_SIGNAL_SUBMASK_BIT (63 - 49) 27 #define CR0_EXTERNAL_CALL_SUBMASK_BIT (63 - 50) 28 #define CR0_CLOCK_COMPARATOR_SUBMASK_BIT (63 - 52) 29 #define CR0_CPU_TIMER_SUBMASK_BIT (63 - 53) 30 #define CR0_SERVICE_SIGNAL_SUBMASK_BIT (63 - 54) 31 #define CR0_UNUSED_56_BIT (63 - 56) 32 #define CR0_INTERRUPT_KEY_SUBMASK_BIT (63 - 57) 33 #define CR0_MEASUREMENT_ALERT_SUBMASK_BIT (63 - 58) 34 #define CR0_ETR_SUBMASK_BIT (63 - 59) 35 #define CR0_IUCV_BIT (63 - 62) 36 37 #define CR0_TRANSACTIONAL_EXECUTION BIT(CR0_TRANSACTIONAL_EXECUTION_BIT) 38 #define CR0_CLOCK_COMPARATOR_SIGN BIT(CR0_CLOCK_COMPARATOR_SIGN_BIT) 39 #define CR0_CRYPTOGRAPHY_COUNTER BIT(CR0_CRYPTOGRAPHY_COUNTER_BIT) 40 #define CR0_PAI_EXTENSION BIT(CR0_PAI_EXTENSION_BIT) 41 #define CR0_CPUMF_EXTRACTION_AUTH BIT(CR0_CPUMF_EXTRACTION_AUTH_BIT) 42 #define CR0_WARNING_TRACK BIT(CR0_WARNING_TRACK_BIT) 43 #define CR0_LOW_ADDRESS_PROTECTION BIT(CR0_LOW_ADDRESS_PROTECTION_BIT) 44 #define CR0_FETCH_PROTECTION_OVERRIDE BIT(CR0_FETCH_PROTECTION_OVERRIDE_BIT) 45 #define CR0_STORAGE_PROTECTION_OVERRIDE BIT(CR0_STORAGE_PROTECTION_OVERRIDE_BIT) 46 #define CR0_EDAT BIT(CR0_EDAT_BIT) 47 #define CR0_INSTRUCTION_EXEC_PROTECTION BIT(CR0_INSTRUCTION_EXEC_PROTECTION_BIT) 48 #define CR0_VECTOR BIT(CR0_VECTOR_BIT) 49 #define CR0_MALFUNCTION_ALERT_SUBMASK BIT(CR0_MALFUNCTION_ALERT_SUBMASK_BIT) 50 #define CR0_EMERGENCY_SIGNAL_SUBMASK BIT(CR0_EMERGENCY_SIGNAL_SUBMASK_BIT) 51 #define CR0_EXTERNAL_CALL_SUBMASK BIT(CR0_EXTERNAL_CALL_SUBMASK_BIT) 52 #define CR0_CLOCK_COMPARATOR_SUBMASK BIT(CR0_CLOCK_COMPARATOR_SUBMASK_BIT) 53 #define CR0_CPU_TIMER_SUBMASK BIT(CR0_CPU_TIMER_SUBMASK_BIT) 54 #define CR0_SERVICE_SIGNAL_SUBMASK BIT(CR0_SERVICE_SIGNAL_SUBMASK_BIT) 55 #define CR0_UNUSED_56 BIT(CR0_UNUSED_56_BIT) 56 #define CR0_INTERRUPT_KEY_SUBMASK BIT(CR0_INTERRUPT_KEY_SUBMASK_BIT) 57 #define CR0_MEASUREMENT_ALERT_SUBMASK BIT(CR0_MEASUREMENT_ALERT_SUBMASK_BIT) 58 #define CR0_ETR_SUBMASK BIT(CR0_ETR_SUBMASK_BIT) 59 #define CR0_IUCV BIT(CR0_IUCV_BIT) 60 61 #define CR2_MIO_ADDRESSING_BIT (63 - 58) 62 #define CR2_GUARDED_STORAGE_BIT (63 - 59) 63 64 #define CR2_MIO_ADDRESSING BIT(CR2_MIO_ADDRESSING_BIT) 65 #define CR2_GUARDED_STORAGE BIT(CR2_GUARDED_STORAGE_BIT) 66 67 #define CR14_UNUSED_32_BIT (63 - 32) 68 #define CR14_UNUSED_33_BIT (63 - 33) 69 #define CR14_CHANNEL_REPORT_SUBMASK_BIT (63 - 35) 70 #define CR14_RECOVERY_SUBMASK_BIT (63 - 36) 71 #define CR14_DEGRADATION_SUBMASK_BIT (63 - 37) 72 #define CR14_EXTERNAL_DAMAGE_SUBMASK_BIT (63 - 38) 73 #define CR14_WARNING_SUBMASK_BIT (63 - 39) 74 75 #define CR14_UNUSED_32 BIT(CR14_UNUSED_32_BIT) 76 #define CR14_UNUSED_33 BIT(CR14_UNUSED_33_BIT) 77 #define CR14_CHANNEL_REPORT_SUBMASK BIT(CR14_CHANNEL_REPORT_SUBMASK_BIT) 78 #define CR14_RECOVERY_SUBMASK BIT(CR14_RECOVERY_SUBMASK_BIT) 79 #define CR14_DEGRADATION_SUBMASK BIT(CR14_DEGRADATION_SUBMASK_BIT) 80 #define CR14_EXTERNAL_DAMAGE_SUBMASK BIT(CR14_EXTERNAL_DAMAGE_SUBMASK_BIT) 81 #define CR14_WARNING_SUBMASK BIT(CR14_WARNING_SUBMASK_BIT) 82 83 #ifndef __ASSEMBLY__ 84 85 #include <linux/bug.h> 86 87 struct ctlreg { 88 unsigned long val; 89 }; 90 91 #define __local_ctl_load(low, high, array) do { \ 92 struct addrtype { \ 93 char _[sizeof(array)]; \ 94 }; \ 95 int _high = high; \ 96 int _low = low; \ 97 int _esize; \ 98 \ 99 _esize = (_high - _low + 1) * sizeof(struct ctlreg); \ 100 BUILD_BUG_ON(sizeof(struct addrtype) != _esize); \ 101 typecheck(struct ctlreg, array[0]); \ 102 asm volatile( \ 103 " lctlg %[_low],%[_high],%[_arr]\n" \ 104 : \ 105 : [_arr] "Q" (*(struct addrtype *)(&array)), \ 106 [_low] "i" (low), [_high] "i" (high) \ 107 : "memory"); \ 108 } while (0) 109 110 #define __local_ctl_store(low, high, array) do { \ 111 struct addrtype { \ 112 char _[sizeof(array)]; \ 113 }; \ 114 int _high = high; \ 115 int _low = low; \ 116 int _esize; \ 117 \ 118 _esize = (_high - _low + 1) * sizeof(struct ctlreg); \ 119 BUILD_BUG_ON(sizeof(struct addrtype) != _esize); \ 120 typecheck(struct ctlreg, array[0]); \ 121 asm volatile( \ 122 " stctg %[_low],%[_high],%[_arr]\n" \ 123 : [_arr] "=Q" (*(struct addrtype *)(&array)) \ 124 : [_low] "i" (low), [_high] "i" (high)); \ 125 } while (0) 126 127 static __always_inline void local_ctl_load(unsigned int cr, struct ctlreg *reg) 128 { 129 asm volatile( 130 " lctlg %[cr],%[cr],%[reg]\n" 131 : 132 : [reg] "Q" (*reg), [cr] "i" (cr) 133 : "memory"); 134 } 135 136 static __always_inline void local_ctl_store(unsigned int cr, struct ctlreg *reg) 137 { 138 asm volatile( 139 " stctg %[cr],%[cr],%[reg]\n" 140 : [reg] "=Q" (*reg) 141 : [cr] "i" (cr)); 142 } 143 144 static __always_inline struct ctlreg local_ctl_set_bit(unsigned int cr, unsigned int bit) 145 { 146 struct ctlreg new, old; 147 148 local_ctl_store(cr, &old); 149 new = old; 150 new.val |= 1UL << bit; 151 local_ctl_load(cr, &new); 152 return old; 153 } 154 155 static __always_inline struct ctlreg local_ctl_clear_bit(unsigned int cr, unsigned int bit) 156 { 157 struct ctlreg new, old; 158 159 local_ctl_store(cr, &old); 160 new = old; 161 new.val &= ~(1UL << bit); 162 local_ctl_load(cr, &new); 163 return old; 164 } 165 166 struct lowcore; 167 168 void system_ctlreg_lock(void); 169 void system_ctlreg_unlock(void); 170 void system_ctlreg_init_save_area(struct lowcore *lc); 171 void system_ctlreg_modify(unsigned int cr, unsigned long data, int request); 172 173 enum { 174 CTLREG_SET_BIT, 175 CTLREG_CLEAR_BIT, 176 CTLREG_LOAD, 177 }; 178 179 static inline void system_ctl_set_bit(unsigned int cr, unsigned int bit) 180 { 181 system_ctlreg_modify(cr, bit, CTLREG_SET_BIT); 182 } 183 184 static inline void system_ctl_clear_bit(unsigned int cr, unsigned int bit) 185 { 186 system_ctlreg_modify(cr, bit, CTLREG_CLEAR_BIT); 187 } 188 189 static inline void system_ctl_load(unsigned int cr, struct ctlreg *reg) 190 { 191 system_ctlreg_modify(cr, reg->val, CTLREG_LOAD); 192 } 193 194 union ctlreg0 { 195 unsigned long val; 196 struct ctlreg reg; 197 struct { 198 unsigned long : 8; 199 unsigned long tcx : 1; /* Transactional-Execution control */ 200 unsigned long pifo : 1; /* Transactional-Execution Program- 201 Interruption-Filtering Override */ 202 unsigned long : 3; 203 unsigned long ccc : 1; /* Cryptography counter control */ 204 unsigned long pec : 1; /* PAI extension control */ 205 unsigned long : 17; 206 unsigned long : 3; 207 unsigned long lap : 1; /* Low-address-protection control */ 208 unsigned long : 4; 209 unsigned long edat : 1; /* Enhanced-DAT-enablement control */ 210 unsigned long : 2; 211 unsigned long iep : 1; /* Instruction-Execution-Protection */ 212 unsigned long : 1; 213 unsigned long afp : 1; /* AFP-register control */ 214 unsigned long vx : 1; /* Vector enablement control */ 215 unsigned long : 7; 216 unsigned long sssm : 1; /* Service signal subclass mask */ 217 unsigned long : 9; 218 }; 219 }; 220 221 union ctlreg2 { 222 unsigned long val; 223 struct ctlreg reg; 224 struct { 225 unsigned long : 33; 226 unsigned long ducto : 25; 227 unsigned long : 1; 228 unsigned long gse : 1; 229 unsigned long : 1; 230 unsigned long tds : 1; 231 unsigned long tdc : 2; 232 }; 233 }; 234 235 union ctlreg5 { 236 unsigned long val; 237 struct ctlreg reg; 238 struct { 239 unsigned long : 33; 240 unsigned long pasteo: 25; 241 unsigned long : 6; 242 }; 243 }; 244 245 union ctlreg15 { 246 unsigned long val; 247 struct ctlreg reg; 248 struct { 249 unsigned long lsea : 61; 250 unsigned long : 3; 251 }; 252 }; 253 254 #endif /* __ASSEMBLY__ */ 255 #endif /* __ASM_S390_CTLREG_H */ 256