1 /* 2 * Copyright (c) 2017 Red Hat Inc 3 * 4 * Authors: 5 * David Hildenbrand <david@redhat.com> 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Library General Public License version 2. 9 */ 10 #ifndef _ASM_S390X_ARCH_DEF_H_ 11 #define _ASM_S390X_ARCH_DEF_H_ 12 13 struct psw { 14 uint64_t mask; 15 uint64_t addr; 16 }; 17 18 #define PSW_MASK_DAT 0x0400000000000000UL 19 #define PSW_MASK_PSTATE 0x0001000000000000UL 20 21 struct lowcore { 22 uint8_t pad_0x0000[0x0080 - 0x0000]; /* 0x0000 */ 23 uint32_t ext_int_param; /* 0x0080 */ 24 uint16_t cpu_addr; /* 0x0084 */ 25 uint16_t ext_int_code; /* 0x0086 */ 26 uint16_t svc_int_id; /* 0x0088 */ 27 uint16_t svc_int_code; /* 0x008a */ 28 uint16_t pgm_int_id; /* 0x008c */ 29 uint16_t pgm_int_code; /* 0x008e */ 30 uint32_t dxc_vxc; /* 0x0090 */ 31 uint16_t mon_class_nb; /* 0x0094 */ 32 uint8_t per_code; /* 0x0096 */ 33 uint8_t per_atmid; /* 0x0097 */ 34 uint64_t per_addr; /* 0x0098 */ 35 uint8_t exc_acc_id; /* 0x00a0 */ 36 uint8_t per_acc_id; /* 0x00a1 */ 37 uint8_t op_acc_id; /* 0x00a2 */ 38 uint8_t arch_mode_id; /* 0x00a3 */ 39 uint8_t pad_0x00a4[0x00a8 - 0x00a4]; /* 0x00a4 */ 40 uint64_t trans_exc_id; /* 0x00a8 */ 41 uint64_t mon_code; /* 0x00b0 */ 42 uint32_t subsys_id_word; /* 0x00b8 */ 43 uint32_t io_int_param; /* 0x00bc */ 44 uint32_t io_int_word; /* 0x00c0 */ 45 uint8_t pad_0x00c4[0x00c8 - 0x00c4]; /* 0x00c4 */ 46 uint32_t stfl; /* 0x00c8 */ 47 uint8_t pad_0x00cc[0x00e8 - 0x00cc]; /* 0x00cc */ 48 uint64_t mcck_int_code; /* 0x00e8 */ 49 uint8_t pad_0x00f0[0x00f4 - 0x00f0]; /* 0x00f0 */ 50 uint32_t ext_damage_code; /* 0x00f4 */ 51 uint64_t failing_storage_addr; /* 0x00f8 */ 52 uint64_t emon_ca_origin; /* 0x0100 */ 53 uint32_t emon_ca_size; /* 0x0108 */ 54 uint32_t emon_exc_count; /* 0x010c */ 55 uint64_t breaking_event_addr; /* 0x0110 */ 56 uint8_t pad_0x0118[0x0120 - 0x0118]; /* 0x0118 */ 57 struct psw restart_old_psw; /* 0x0120 */ 58 struct psw ext_old_psw; /* 0x0130 */ 59 struct psw svc_old_psw; /* 0x0140 */ 60 struct psw pgm_old_psw; /* 0x0150 */ 61 struct psw mcck_old_psw; /* 0x0160 */ 62 struct psw io_old_psw; /* 0x0170 */ 63 uint8_t pad_0x0180[0x01a0 - 0x0180]; /* 0x0180 */ 64 struct psw restart_new_psw; /* 0x01a0 */ 65 struct psw ext_new_psw; /* 0x01b0 */ 66 struct psw svc_new_psw; /* 0x01c0 */ 67 struct psw pgm_new_psw; /* 0x01d0 */ 68 struct psw mcck_new_psw; /* 0x01e0 */ 69 struct psw io_new_psw; /* 0x01f0 */ 70 /* sw definition: save area for registers in interrupt handlers */ 71 uint64_t sw_int_grs[16]; /* 0x0200 */ 72 uint64_t sw_int_fprs[16]; /* 0x0280 */ 73 uint32_t sw_int_fpc; /* 0x0300 */ 74 uint8_t pad_0x0304[0x11b0 - 0x0304]; /* 0x0304 */ 75 uint64_t mcck_ext_sa_addr; /* 0x11b0 */ 76 uint8_t pad_0x11b8[0x1200 - 0x11b8]; /* 0x11b8 */ 77 uint64_t fprs_sa[16]; /* 0x1200 */ 78 uint64_t grs_sa[16]; /* 0x1280 */ 79 struct psw psw_sa; /* 0x1300 */ 80 uint8_t pad_0x1310[0x1318 - 0x1310]; /* 0x1310 */ 81 uint32_t prefix_sa; /* 0x1318 */ 82 uint32_t fpc_sa; /* 0x131c */ 83 uint8_t pad_0x1320[0x1324 - 0x1320]; /* 0x1320 */ 84 uint32_t tod_pr_sa; /* 0x1324 */ 85 uint64_t cputm_sa; /* 0x1328 */ 86 uint64_t cc_sa; /* 0x1330 */ 87 uint8_t pad_0x1338[0x1340 - 0x1338]; /* 0x1338 */ 88 uint32_t ars_sa[16]; /* 0x1340 */ 89 uint64_t crs_sa[16]; /* 0x1380 */ 90 uint8_t pad_0x1400[0x1800 - 0x1400]; /* 0x1400 */ 91 uint8_t pgm_int_tdb[0x1900 - 0x1800]; /* 0x1800 */ 92 } __attribute__ ((__packed__)); 93 94 #define PGM_INT_CODE_OPERATION 0x01 95 #define PGM_INT_CODE_PRIVILEGED_OPERATION 0x02 96 #define PGM_INT_CODE_EXECUTE 0x03 97 #define PGM_INT_CODE_PROTECTION 0x04 98 #define PGM_INT_CODE_ADDRESSING 0x05 99 #define PGM_INT_CODE_SPECIFICATION 0x06 100 #define PGM_INT_CODE_DATA 0x07 101 #define PGM_INT_CODE_FIXED_POINT_OVERFLOW 0x08 102 #define PGM_INT_CODE_FIXED_POINT_DIVIDE 0x09 103 #define PGM_INT_CODE_DECIMAL_OVERFLOW 0x0a 104 #define PGM_INT_CODE_DECIMAL_DIVIDE 0x0b 105 #define PGM_INT_CODE_HFP_EXPONENT_OVERFLOW 0x0c 106 #define PGM_INT_CODE_HFP_EXPONENT_UNDERFLOW 0x0d 107 #define PGM_INT_CODE_HFP_SIGNIFICANCE 0x0e 108 #define PGM_INT_CODE_HFP_DIVIDE 0x0f 109 #define PGM_INT_CODE_SEGMENT_TRANSLATION 0x10 110 #define PGM_INT_CODE_PAGE_TRANSLATION 0x11 111 #define PGM_INT_CODE_TRANSLATION_SPEC 0x12 112 #define PGM_INT_CODE_SPECIAL_OPERATION 0x13 113 #define PGM_INT_CODE_OPERAND 0x15 114 #define PGM_INT_CODE_TRACE_TABLE 0x16 115 #define PGM_INT_CODE_VECTOR_PROCESSING 0x1b 116 #define PGM_INT_CODE_SPACE_SWITCH_EVENT 0x1c 117 #define PGM_INT_CODE_HFP_SQUARE_ROOT 0x1d 118 #define PGM_INT_CODE_PC_TRANSLATION_SPEC 0x1f 119 #define PGM_INT_CODE_AFX_TRANSLATION 0x20 120 #define PGM_INT_CODE_ASX_TRANSLATION 0x21 121 #define PGM_INT_CODE_LX_TRANSLATION 0x22 122 #define PGM_INT_CODE_EX_TRANSLATION 0x23 123 #define PGM_INT_CODE_PRIMARY_AUTHORITY 0x24 124 #define PGM_INT_CODE_SECONDARY_AUTHORITY 0x25 125 #define PGM_INT_CODE_LFX_TRANSLATION 0x26 126 #define PGM_INT_CODE_LSX_TRANSLATION 0x27 127 #define PGM_INT_CODE_ALET_SPECIFICATION 0x28 128 #define PGM_INT_CODE_ALEN_TRANSLATION 0x29 129 #define PGM_INT_CODE_ALE_SEQUENCE 0x2a 130 #define PGM_INT_CODE_ASTE_VALIDITY 0x2b 131 #define PGM_INT_CODE_ASTE_SEQUENCE 0x2c 132 #define PGM_INT_CODE_EXTENDED_AUTHORITY 0x2d 133 #define PGM_INT_CODE_LSTE_SEQUENCE 0x2e 134 #define PGM_INT_CODE_ASTE_INSTANCE 0x2f 135 #define PGM_INT_CODE_STACK_FULL 0x30 136 #define PGM_INT_CODE_STACK_EMPTY 0x31 137 #define PGM_INT_CODE_STACK_SPECIFICATION 0x32 138 #define PGM_INT_CODE_STACK_TYPE 0x33 139 #define PGM_INT_CODE_STACK_OPERATION 0x34 140 #define PGM_INT_CODE_ASCE_TYPE 0x38 141 #define PGM_INT_CODE_REGION_FIRST_TRANS 0x39 142 #define PGM_INT_CODE_REGION_SECOND_TRANS 0x3a 143 #define PGM_INT_CODE_REGION_THIRD_TRANS 0x3b 144 #define PGM_INT_CODE_MONITOR_EVENT 0x40 145 #define PGM_INT_CODE_PER 0x80 146 #define PGM_INT_CODE_CRYPTO_OPERATION 0x119 147 #define PGM_INT_CODE_TX_ABORTED_EVENT 0x200 148 149 struct cpuid { 150 uint64_t version : 8; 151 uint64_t id : 24; 152 uint64_t type : 16; 153 uint64_t format : 1; 154 uint64_t reserved : 15; 155 }; 156 157 static inline int tprot(unsigned long addr) 158 { 159 int cc; 160 161 asm volatile( 162 " tprot 0(%1),0\n" 163 " ipm %0\n" 164 " srl %0,28\n" 165 : "=d" (cc) : "a" (addr) : "cc"); 166 return cc; 167 } 168 169 static inline void lctlg(int cr, uint64_t value) 170 { 171 asm volatile( 172 " lctlg %1,%1,%0\n" 173 : : "Q" (value), "i" (cr)); 174 } 175 176 static inline uint64_t stctg(int cr) 177 { 178 uint64_t value; 179 180 asm volatile( 181 " stctg %1,%1,%0\n" 182 : "=Q" (value) : "i" (cr) : "memory"); 183 return value; 184 } 185 186 static inline void ctl_set_bit(int cr, unsigned int bit) 187 { 188 uint64_t reg; 189 190 reg = stctg(cr); 191 reg |= 1UL << bit; 192 lctlg(cr, reg); 193 } 194 195 static inline void ctl_clear_bit(int cr, unsigned int bit) 196 { 197 uint64_t reg; 198 199 reg = stctg(cr); 200 reg &= ~(1UL << bit); 201 lctlg(cr, reg); 202 } 203 204 static inline uint64_t extract_psw_mask(void) 205 { 206 uint32_t mask_upper = 0, mask_lower = 0; 207 208 asm volatile( 209 " epsw %0,%1\n" 210 : "+r" (mask_upper), "+r" (mask_lower) : : ); 211 212 return (uint64_t) mask_upper << 32 | mask_lower; 213 } 214 215 static inline void load_psw_mask(uint64_t mask) 216 { 217 struct psw psw = { 218 .mask = mask, 219 .addr = 0, 220 }; 221 uint64_t tmp = 0; 222 223 asm volatile( 224 " larl %0,0f\n" 225 " stg %0,8(%1)\n" 226 " lpswe 0(%1)\n" 227 "0:\n" 228 : "+r" (tmp) : "a" (&psw) : "memory", "cc" ); 229 } 230 231 static inline void enter_pstate(void) 232 { 233 uint64_t mask; 234 235 mask = extract_psw_mask(); 236 mask |= PSW_MASK_PSTATE; 237 load_psw_mask(mask); 238 } 239 240 #endif 241