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 void local_ctl_set_bit(unsigned int cr, unsigned int bit) 145 { 146 struct ctlreg reg; 147 148 local_ctl_store(cr, ®); 149 reg.val |= 1UL << bit; 150 local_ctl_load(cr, ®); 151 } 152 153 static __always_inline void local_ctl_clear_bit(unsigned int cr, unsigned int bit) 154 { 155 struct ctlreg reg; 156 157 local_ctl_store(cr, ®); 158 reg.val &= ~(1UL << bit); 159 local_ctl_load(cr, ®); 160 } 161 162 struct lowcore; 163 164 void system_ctlreg_lock(void); 165 void system_ctlreg_unlock(void); 166 void system_ctlreg_init_save_area(struct lowcore *lc); 167 void system_ctlreg_modify(unsigned int cr, unsigned long data, int request); 168 169 enum { 170 CTLREG_SET_BIT, 171 CTLREG_CLEAR_BIT, 172 CTLREG_LOAD, 173 }; 174 175 static inline void system_ctl_set_bit(unsigned int cr, unsigned int bit) 176 { 177 system_ctlreg_modify(cr, bit, CTLREG_SET_BIT); 178 } 179 180 static inline void system_ctl_clear_bit(unsigned int cr, unsigned int bit) 181 { 182 system_ctlreg_modify(cr, bit, CTLREG_CLEAR_BIT); 183 } 184 185 static inline void system_ctl_load(unsigned int cr, struct ctlreg *reg) 186 { 187 system_ctlreg_modify(cr, reg->val, CTLREG_LOAD); 188 } 189 190 union ctlreg0 { 191 unsigned long val; 192 struct ctlreg reg; 193 struct { 194 unsigned long : 8; 195 unsigned long tcx : 1; /* Transactional-Execution control */ 196 unsigned long pifo : 1; /* Transactional-Execution Program- 197 Interruption-Filtering Override */ 198 unsigned long : 3; 199 unsigned long ccc : 1; /* Cryptography counter control */ 200 unsigned long pec : 1; /* PAI extension control */ 201 unsigned long : 17; 202 unsigned long : 3; 203 unsigned long lap : 1; /* Low-address-protection control */ 204 unsigned long : 4; 205 unsigned long edat : 1; /* Enhanced-DAT-enablement control */ 206 unsigned long : 2; 207 unsigned long iep : 1; /* Instruction-Execution-Protection */ 208 unsigned long : 1; 209 unsigned long afp : 1; /* AFP-register control */ 210 unsigned long vx : 1; /* Vector enablement control */ 211 unsigned long : 7; 212 unsigned long sssm : 1; /* Service signal subclass mask */ 213 unsigned long : 9; 214 }; 215 }; 216 217 union ctlreg2 { 218 unsigned long val; 219 struct ctlreg reg; 220 struct { 221 unsigned long : 33; 222 unsigned long ducto : 25; 223 unsigned long : 1; 224 unsigned long gse : 1; 225 unsigned long : 1; 226 unsigned long tds : 1; 227 unsigned long tdc : 2; 228 }; 229 }; 230 231 union ctlreg5 { 232 unsigned long val; 233 struct ctlreg reg; 234 struct { 235 unsigned long : 33; 236 unsigned long pasteo: 25; 237 unsigned long : 6; 238 }; 239 }; 240 241 union ctlreg15 { 242 unsigned long val; 243 struct ctlreg reg; 244 struct { 245 unsigned long lsea : 61; 246 unsigned long : 3; 247 }; 248 }; 249 250 #endif /* __ASSEMBLY__ */ 251 #endif /* __ASM_S390_CTLREG_H */ 252