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_sop : 1; 127 uint64_t has_gsls : 1; 128 uint64_t has_esop : 1; 129 uint64_t has_cmma : 1; 130 uint64_t has_64bscao : 1; 131 uint64_t has_esca : 1; 132 uint64_t has_kss : 1; 133 uint64_t has_pfmfi : 1; 134 uint64_t has_ibs : 1; 135 uint64_t : 64 - 15; 136 }; 137 138 /* bit number within a certain byte */ 139 #define SCLP_FEAT_80_BIT_SOP 2 140 #define SCLP_FEAT_85_BIT_GSLS 0 141 #define SCLP_FEAT_85_BIT_ESOP 6 142 #define SCLP_FEAT_98_BIT_KSS 7 143 #define SCLP_FEAT_116_BIT_64BSCAO 0 144 #define SCLP_FEAT_116_BIT_CMMA 1 145 #define SCLP_FEAT_116_BIT_ESCA 4 146 #define SCLP_FEAT_117_BIT_PFMFI 1 147 #define SCLP_FEAT_117_BIT_IBS 2 148 149 typedef struct ReadInfo { 150 SCCBHeader h; 151 uint16_t rnmax; 152 uint8_t rnsize; 153 uint8_t _reserved1[15 - 11]; /* 11-14 */ 154 uint8_t stsi_parm; /* 15-15 */ 155 uint16_t entries_cpu; /* 16-17 */ 156 uint16_t offset_cpu; /* 18-19 */ 157 uint8_t _reserved2[24 - 20]; /* 20-23 */ 158 uint8_t loadparm[8]; /* 24-31 */ 159 uint8_t _reserved3[48 - 32]; /* 32-47 */ 160 uint64_t facilities; /* 48-55 */ 161 uint8_t _reserved0[76 - 56]; /* 56-75 */ 162 uint32_t ibc_val; 163 uint8_t conf_char[99 - 80]; /* 80-98 */ 164 uint8_t mha_pow; 165 uint32_t rnsize2; 166 uint64_t rnmax2; 167 uint8_t _reserved6[116 - 112]; /* 112-115 */ 168 uint8_t conf_char_ext[120 - 116]; /* 116-119 */ 169 uint16_t highest_cpu; 170 uint8_t _reserved5[124 - 122]; /* 122-123 */ 171 uint32_t hmfai; 172 uint8_t reserved7[134 - 128]; /* 128-133 */ 173 uint8_t byte_134_diag318 : 1; 174 uint8_t : 7; 175 /* 176 * At the end of the ReadInfo, there are also the CPU entries (see 177 * struct CPUEntry). When the Extended-Length SCCB (ELS) feature is 178 * enabled, the start of the CPU entries array begins at an offset 179 * denoted by the offset_cpu field, otherwise it's at offset 128. 180 */ 181 } __attribute__((packed)) ReadInfo; 182 183 typedef struct ReadCpuInfo { 184 SCCBHeader h; 185 uint16_t nr_configured; /* 8-9 */ 186 uint16_t offset_configured; /* 10-11 */ 187 uint16_t nr_standby; /* 12-13 */ 188 uint16_t offset_standby; /* 14-15 */ 189 uint8_t reserved0[24-16]; /* 16-23 */ 190 struct CPUEntry entries[0]; 191 } __attribute__((packed)) ReadCpuInfo; 192 193 typedef struct ReadStorageElementInfo { 194 SCCBHeader h; 195 uint16_t max_id; 196 uint16_t assigned; 197 uint16_t standby; 198 uint8_t _reserved0[16 - 14]; /* 14-15 */ 199 uint32_t entries[0]; 200 } __attribute__((packed)) ReadStorageElementInfo; 201 202 typedef struct AttachStorageElement { 203 SCCBHeader h; 204 uint8_t _reserved0[10 - 8]; /* 8-9 */ 205 uint16_t assigned; 206 uint8_t _reserved1[16 - 12]; /* 12-15 */ 207 uint32_t entries[0]; 208 } __attribute__((packed)) AttachStorageElement; 209 210 typedef struct AssignStorage { 211 SCCBHeader h; 212 uint16_t rn; 213 } __attribute__((packed)) AssignStorage; 214 215 typedef struct IoaCfgSccb { 216 SCCBHeader header; 217 uint8_t atype; 218 uint8_t reserved1; 219 uint16_t reserved2; 220 uint32_t aid; 221 } __attribute__((packed)) IoaCfgSccb; 222 223 typedef struct SCCB { 224 SCCBHeader h; 225 char data[SCCB_DATA_LEN]; 226 } __attribute__((packed)) SCCB; 227 228 /* SCLP event types */ 229 #define SCLP_EVENT_OP_CMD 0x01 230 #define SCLP_EVENT_ASCII_CONSOLE_DATA 0x1a 231 #define SCLP_EVENT_SIGNAL_QUIESCE 0x1d 232 233 /* SCLP event masks */ 234 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE 0x00000008 235 #define SCLP_EVENT_MASK_MSG_ASCII 0x00000040 236 #define SCLP_EVENT_MASK_MSG 0x40000000 237 #define SCLP_EVENT_MASK_OPCMD 0x80000000 238 239 #define SCLP_UNCONDITIONAL_READ 0x00 240 #define SCLP_SELECTIVE_READ 0x01 241 242 typedef struct WriteEventMask { 243 SCCBHeader h; 244 uint16_t _reserved; 245 uint16_t mask_length; 246 uint32_t cp_receive_mask; 247 uint32_t cp_send_mask; 248 uint32_t send_mask; 249 uint32_t receive_mask; 250 } __attribute__((packed)) WriteEventMask; 251 252 #define MDBTYP_GO 0x0001 253 #define MDBTYP_MTO 0x0004 254 #define EVTYP_MSG 0x02 255 #define LNTPFLGS_CNTLTEXT 0x8000 256 #define LNTPFLGS_LABELTEXT 0x4000 257 #define LNTPFLGS_DATATEXT 0x2000 258 #define LNTPFLGS_ENDTEXT 0x1000 259 #define LNTPFLGS_PROMPTTEXT 0x0800 260 261 typedef uint32_t sccb_mask_t; 262 263 /* SCLP line mode console related structures. */ 264 265 struct mto { 266 u16 length; 267 u16 type; 268 u16 line_type_flags; 269 u8 alarm_control; 270 u8 _reserved[3]; 271 } __attribute__((packed)); 272 273 struct go { 274 u16 length; 275 u16 type; 276 u32 domid; 277 u8 hhmmss_time[8]; 278 u8 th_time[3]; 279 u8 reserved_0; 280 u8 dddyyyy_date[7]; 281 u8 _reserved_1; 282 u16 general_msg_flags; 283 u8 _reserved_2[10]; 284 u8 originating_system_name[8]; 285 u8 job_guest_name[8]; 286 } __attribute__((packed)); 287 288 struct mdb_header { 289 u16 length; 290 u16 type; 291 u32 tag; 292 u32 revision_code; 293 } __attribute__((packed)); 294 295 struct mdb { 296 struct mdb_header header; 297 struct go go; 298 struct mto mto; 299 } __attribute__((packed)); 300 301 /* vector keys and ids */ 302 #define GDS_ID_MDSMU 0x1310 303 #define GDS_ID_CPMSU 0x1212 304 #define GDS_ID_TEXTCMD 0x1320 305 #define GDS_KEY_SELFDEFTEXTMSG 0x31 306 #define EBC_MDB 0xd4c4c240 307 308 struct gds_vector { 309 uint16_t length; 310 uint16_t gds_id; 311 } __attribute__((packed)); 312 313 struct gds_subvector { 314 uint8_t length; 315 uint8_t key; 316 } __attribute__((packed)); 317 318 typedef struct EventBufferHeader { 319 uint16_t length; 320 uint8_t type; 321 uint8_t flags; 322 uint16_t _reserved; 323 } __attribute__((packed)) EventBufferHeader; 324 325 typedef struct WriteEventData { 326 SCCBHeader h; 327 EventBufferHeader ebh; 328 union { 329 char data[0]; 330 struct mdb mdb; 331 } msg; 332 } __attribute__((packed)) WriteEventData; 333 334 typedef struct ReadEventData { 335 SCCBHeader h; 336 EventBufferHeader ebh; 337 uint32_t mask; 338 } __attribute__((packed)) ReadEventData; 339 340 #define SCLP_EVENT_ASCII_TYPE_DATA_STREAM_FOLLOWS 0 341 typedef struct ReadEventDataAsciiConsole { 342 EventBufferHeader ebh; 343 uint8_t type; 344 char data[]; 345 } __attribute__((packed)) ReadEventDataAsciiConsole; 346 347 struct ReadEventDataLMConsole { 348 SCCBHeader h; 349 EventBufferHeader ebh; 350 struct gds_vector v[]; 351 }; 352 353 extern char _sccb[]; 354 void sclp_setup_int(void); 355 void sclp_handle_ext(void); 356 void sclp_wait_busy(void); 357 void sclp_mark_busy(void); 358 void sclp_clear_busy(void); 359 void sclp_console_setup(void); 360 void sclp_print(const char *str); 361 void sclp_read_info(void); 362 int sclp_get_cpu_num(void); 363 CPUEntry *sclp_get_cpu_entries(void); 364 void sclp_facilities_setup(void); 365 int sclp_service_call(unsigned int command, void *sccb); 366 void sclp_memory_setup(void); 367 uint64_t get_ram_size(void); 368 uint64_t get_max_ram_size(void); 369 uint64_t sclp_get_stsi_mnest(void); 370 371 #endif /* _S390X_SCLP_H_ */ 372