1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * SCLP definitions 4 * 5 * Based on the file pc-bios/s390-ccw/sclp.h from QEMU 6 * Copyright (c) 2013 Alexander Graf <agraf@suse.de> 7 * 8 * and based on the file include/hw/s390x/sclp.h from QEMU 9 * Copyright IBM Corp. 2012 10 * Author: Christian Borntraeger <borntraeger@de.ibm.com> 11 */ 12 13 #ifndef _S390X_SCLP_H_ 14 #define _S390X_SCLP_H_ 15 16 #define SCLP_CMD_CODE_MASK 0xffff00ff 17 18 /* SCLP command codes */ 19 #define SCLP_READ_CPU_INFO 0x00010001 20 #define SCLP_CMDW_READ_SCP_INFO 0x00020001 21 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 22 #define SCLP_READ_STORAGE_ELEMENT_INFO 0x00040001 23 #define SCLP_ATTACH_STORAGE_ELEMENT 0x00080001 24 #define SCLP_ASSIGN_STORAGE 0x000D0001 25 #define SCLP_CMD_READ_EVENT_DATA 0x00770005 26 #define SCLP_CMD_WRITE_EVENT_DATA 0x00760005 27 #define SCLP_CMD_WRITE_EVENT_MASK 0x00780005 28 29 /* SCLP Memory hotplug codes */ 30 #define SCLP_FC_ASSIGN_ATTACH_READ_STOR 0xE00000000000ULL 31 #define SCLP_STARTING_SUBINCREMENT_ID 0x10001 32 #define SCLP_INCREMENT_UNIT 0x10000 33 #define MAX_AVAIL_SLOTS 32 34 #define MAX_STORAGE_INCREMENTS 1020 35 36 /* CPU hotplug SCLP codes */ 37 #define SCLP_HAS_CPU_INFO 0x0C00000000000000ULL 38 #define SCLP_CMDW_READ_CPU_INFO 0x00010001 39 #define SCLP_CMDW_CONFIGURE_CPU 0x00110001 40 #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001 41 42 /* SCLP PCI codes */ 43 #define SCLP_HAS_IOA_RECONFIG 0x0000000040000000ULL 44 #define SCLP_CMDW_CONFIGURE_IOA 0x001a0001 45 #define SCLP_CMDW_DECONFIGURE_IOA 0x001b0001 46 #define SCLP_RECONFIG_PCI_ATYPE 2 47 48 /* SCLP response codes */ 49 #define SCLP_RC_NORMAL_READ_COMPLETION 0x0010 50 #define SCLP_RC_NORMAL_COMPLETION 0x0020 51 #define SCLP_RC_SCCB_BOUNDARY_VIOLATION 0x0100 52 #define SCLP_RC_NO_ACTION_REQUIRED 0x0120 53 #define SCLP_RC_INVALID_SCLP_COMMAND 0x01f0 54 #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK 0x0340 55 #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH 0x0300 56 #define SCLP_RC_STANDBY_READ_COMPLETION 0x0410 57 #define SCLP_RC_ADAPTER_IN_RESERVED_STATE 0x05f0 58 #define SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED 0x06f0 59 #define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED 0x09f0 60 #define SCLP_RC_INVALID_FUNCTION 0x40f0 61 #define SCLP_RC_NO_EVENT_BUFFERS_STORED 0x60f0 62 #define SCLP_RC_INVALID_SELECTION_MASK 0x70f0 63 #define SCLP_RC_INCONSISTENT_LENGTHS 0x72f0 64 #define SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR 0x73f0 65 #define SCLP_RC_INVALID_MASK_LENGTH 0x74f0 66 67 /* SCLP control mask bits */ 68 #define SCLP_CM2_VARIABLE_LENGTH_RESPONSE 0x80 69 70 /* SCLP function codes */ 71 #define SCLP_FC_NORMAL_WRITE 0 72 #define SCLP_FC_SINGLE_INCREMENT_ASSIGN 0x40 73 #define SCLP_FC_DUMP_INDICATOR 0x80 74 75 /* SCLP event buffer flags */ 76 #define SCLP_EVENT_BUFFER_ACCEPTED 0x80 77 78 /* Service Call Control Block (SCCB) and its elements */ 79 #define SCCB_SIZE 4096 80 81 typedef struct SCCBHeader { 82 uint16_t length; 83 uint8_t function_code; 84 uint8_t control_mask[3]; 85 uint16_t response_code; 86 } __attribute__((packed)) SCCBHeader; 87 88 #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader)) 89 #define SCCB_CPU_FEATURE_LEN 6 90 91 /* CPU information */ 92 typedef struct CPUEntry { 93 uint8_t address; 94 uint8_t reserved0; 95 uint8_t : 4; 96 uint8_t feat_sief2 : 1; 97 uint8_t feat_skeyi : 1; 98 uint8_t : 2; 99 uint8_t : 2; 100 uint8_t feat_gpere : 1; 101 uint8_t feat_siif : 1; 102 uint8_t feat_sigpif : 1; 103 uint8_t : 3; 104 uint8_t reserved2[3]; 105 uint8_t : 2; 106 uint8_t feat_ib : 1; 107 uint8_t feat_cei : 1; 108 uint8_t : 4; 109 uint8_t reserved3[6]; 110 uint8_t type; 111 uint8_t reserved1; 112 } __attribute__((packed)) CPUEntry; 113 114 extern struct sclp_facilities sclp_facilities; 115 116 struct sclp_facilities { 117 uint64_t has_sief2 : 1; 118 uint64_t has_skeyi : 1; 119 uint64_t has_gpere : 1; 120 uint64_t has_siif : 1; 121 uint64_t has_sigpif : 1; 122 uint64_t has_ib : 1; 123 uint64_t has_cei : 1; 124 125 uint64_t has_diag318 : 1; 126 uint64_t has_gsls : 1; 127 uint64_t has_cmma : 1; 128 uint64_t has_64bscao : 1; 129 uint64_t has_esca : 1; 130 uint64_t has_kss : 1; 131 uint64_t has_pfmfi : 1; 132 uint64_t has_ibs : 1; 133 uint64_t : 64 - 15; 134 }; 135 136 /* bit number within a certain byte */ 137 #define SCLP_FEAT_85_BIT_GSLS 7 138 #define SCLP_FEAT_98_BIT_KSS 0 139 #define SCLP_FEAT_116_BIT_64BSCAO 7 140 #define SCLP_FEAT_116_BIT_CMMA 6 141 #define SCLP_FEAT_116_BIT_ESCA 3 142 #define SCLP_FEAT_117_BIT_PFMFI 6 143 #define SCLP_FEAT_117_BIT_IBS 5 144 145 typedef struct ReadInfo { 146 SCCBHeader h; 147 uint16_t rnmax; 148 uint8_t rnsize; 149 uint8_t _reserved1[16 - 11]; /* 11-15 */ 150 uint16_t entries_cpu; /* 16-17 */ 151 uint16_t offset_cpu; /* 18-19 */ 152 uint8_t _reserved2[24 - 20]; /* 20-23 */ 153 uint8_t loadparm[8]; /* 24-31 */ 154 uint8_t _reserved3[48 - 32]; /* 32-47 */ 155 uint64_t facilities; /* 48-55 */ 156 uint8_t _reserved0[76 - 56]; /* 56-75 */ 157 uint32_t ibc_val; 158 uint8_t conf_char[99 - 80]; /* 80-98 */ 159 uint8_t mha_pow; 160 uint32_t rnsize2; 161 uint64_t rnmax2; 162 uint8_t _reserved6[116 - 112]; /* 112-115 */ 163 uint8_t conf_char_ext[120 - 116]; /* 116-119 */ 164 uint16_t highest_cpu; 165 uint8_t _reserved5[124 - 122]; /* 122-123 */ 166 uint32_t hmfai; 167 uint8_t reserved7[134 - 128]; /* 128-133 */ 168 uint8_t byte_134_diag318 : 1; 169 uint8_t : 7; 170 /* 171 * At the end of the ReadInfo, there are also the CPU entries (see 172 * struct CPUEntry). When the Extended-Length SCCB (ELS) feature is 173 * enabled, the start of the CPU entries array begins at an offset 174 * denoted by the offset_cpu field, otherwise it's at offset 128. 175 */ 176 } __attribute__((packed)) ReadInfo; 177 178 typedef struct ReadCpuInfo { 179 SCCBHeader h; 180 uint16_t nr_configured; /* 8-9 */ 181 uint16_t offset_configured; /* 10-11 */ 182 uint16_t nr_standby; /* 12-13 */ 183 uint16_t offset_standby; /* 14-15 */ 184 uint8_t reserved0[24-16]; /* 16-23 */ 185 struct CPUEntry entries[0]; 186 } __attribute__((packed)) ReadCpuInfo; 187 188 typedef struct ReadStorageElementInfo { 189 SCCBHeader h; 190 uint16_t max_id; 191 uint16_t assigned; 192 uint16_t standby; 193 uint8_t _reserved0[16 - 14]; /* 14-15 */ 194 uint32_t entries[0]; 195 } __attribute__((packed)) ReadStorageElementInfo; 196 197 typedef struct AttachStorageElement { 198 SCCBHeader h; 199 uint8_t _reserved0[10 - 8]; /* 8-9 */ 200 uint16_t assigned; 201 uint8_t _reserved1[16 - 12]; /* 12-15 */ 202 uint32_t entries[0]; 203 } __attribute__((packed)) AttachStorageElement; 204 205 typedef struct AssignStorage { 206 SCCBHeader h; 207 uint16_t rn; 208 } __attribute__((packed)) AssignStorage; 209 210 typedef struct IoaCfgSccb { 211 SCCBHeader header; 212 uint8_t atype; 213 uint8_t reserved1; 214 uint16_t reserved2; 215 uint32_t aid; 216 } __attribute__((packed)) IoaCfgSccb; 217 218 typedef struct SCCB { 219 SCCBHeader h; 220 char data[SCCB_DATA_LEN]; 221 } __attribute__((packed)) SCCB; 222 223 /* SCLP event types */ 224 #define SCLP_EVENT_ASCII_CONSOLE_DATA 0x1a 225 #define SCLP_EVENT_SIGNAL_QUIESCE 0x1d 226 227 /* SCLP event masks */ 228 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE 0x00000008 229 #define SCLP_EVENT_MASK_MSG_ASCII 0x00000040 230 #define SCLP_EVENT_MASK_MSG 0x40000000 231 232 #define SCLP_UNCONDITIONAL_READ 0x00 233 #define SCLP_SELECTIVE_READ 0x01 234 235 typedef struct WriteEventMask { 236 SCCBHeader h; 237 uint16_t _reserved; 238 uint16_t mask_length; 239 uint32_t cp_receive_mask; 240 uint32_t cp_send_mask; 241 uint32_t send_mask; 242 uint32_t receive_mask; 243 } __attribute__((packed)) WriteEventMask; 244 245 #define MDBTYP_GO 0x0001 246 #define MDBTYP_MTO 0x0004 247 #define EVTYP_MSG 0x02 248 #define LNTPFLGS_CNTLTEXT 0x8000 249 #define LNTPFLGS_LABELTEXT 0x4000 250 #define LNTPFLGS_DATATEXT 0x2000 251 #define LNTPFLGS_ENDTEXT 0x1000 252 #define LNTPFLGS_PROMPTTEXT 0x0800 253 254 typedef uint32_t sccb_mask_t; 255 256 /* SCLP line mode console related structures. */ 257 258 struct mto { 259 u16 length; 260 u16 type; 261 u16 line_type_flags; 262 u8 alarm_control; 263 u8 _reserved[3]; 264 } __attribute__((packed)); 265 266 struct go { 267 u16 length; 268 u16 type; 269 u32 domid; 270 u8 hhmmss_time[8]; 271 u8 th_time[3]; 272 u8 reserved_0; 273 u8 dddyyyy_date[7]; 274 u8 _reserved_1; 275 u16 general_msg_flags; 276 u8 _reserved_2[10]; 277 u8 originating_system_name[8]; 278 u8 job_guest_name[8]; 279 } __attribute__((packed)); 280 281 struct mdb_header { 282 u16 length; 283 u16 type; 284 u32 tag; 285 u32 revision_code; 286 } __attribute__((packed)); 287 288 struct mdb { 289 struct mdb_header header; 290 struct go go; 291 struct mto mto; 292 } __attribute__((packed)); 293 294 typedef struct EventBufferHeader { 295 uint16_t length; 296 uint8_t type; 297 uint8_t flags; 298 uint16_t _reserved; 299 } __attribute__((packed)) EventBufferHeader; 300 301 typedef struct WriteEventData { 302 SCCBHeader h; 303 EventBufferHeader ebh; 304 union { 305 char data[0]; 306 struct mdb mdb; 307 } msg; 308 } __attribute__((packed)) WriteEventData; 309 310 typedef struct ReadEventData { 311 SCCBHeader h; 312 EventBufferHeader ebh; 313 uint32_t mask; 314 } __attribute__((packed)) ReadEventData; 315 316 extern char _sccb[]; 317 void sclp_setup_int(void); 318 void sclp_handle_ext(void); 319 void sclp_wait_busy(void); 320 void sclp_mark_busy(void); 321 void sclp_clear_busy(void); 322 void sclp_console_setup(void); 323 void sclp_print(const char *str); 324 void sclp_read_info(void); 325 int sclp_get_cpu_num(void); 326 CPUEntry *sclp_get_cpu_entries(void); 327 void sclp_facilities_setup(void); 328 int sclp_service_call(unsigned int command, void *sccb); 329 void sclp_memory_setup(void); 330 uint64_t get_ram_size(void); 331 uint64_t get_max_ram_size(void); 332 333 #endif /* _S390X_SCLP_H_ */ 334