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 SCLP_H 14 #define 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 : 3; 98 uint8_t features_res2 [SCCB_CPU_FEATURE_LEN - 1]; 99 uint8_t reserved2[6]; 100 uint8_t type; 101 uint8_t reserved1; 102 } __attribute__((packed)) CPUEntry; 103 104 extern struct sclp_facilities sclp_facilities; 105 106 struct sclp_facilities { 107 uint64_t has_sief2 : 1; 108 uint64_t has_diag318 : 1; 109 uint64_t : 62; 110 }; 111 112 typedef struct ReadInfo { 113 SCCBHeader h; 114 uint16_t rnmax; 115 uint8_t rnsize; 116 uint8_t _reserved1[16 - 11]; /* 11-15 */ 117 uint16_t entries_cpu; /* 16-17 */ 118 uint16_t offset_cpu; /* 18-19 */ 119 uint8_t _reserved2[24 - 20]; /* 20-23 */ 120 uint8_t loadparm[8]; /* 24-31 */ 121 uint8_t _reserved3[48 - 32]; /* 32-47 */ 122 uint64_t facilities; /* 48-55 */ 123 uint8_t _reserved0[76 - 56]; /* 56-75 */ 124 uint32_t ibc_val; 125 uint8_t conf_char[99 - 80]; /* 80-98 */ 126 uint8_t mha_pow; 127 uint32_t rnsize2; 128 uint64_t rnmax2; 129 uint8_t _reserved6[116 - 112]; /* 112-115 */ 130 uint8_t conf_char_ext[120 - 116]; /* 116-119 */ 131 uint16_t highest_cpu; 132 uint8_t _reserved5[124 - 122]; /* 122-123 */ 133 uint32_t hmfai; 134 uint8_t reserved7[134 - 128]; /* 128-133 */ 135 uint8_t byte_134_diag318 : 1; 136 uint8_t : 7; 137 /* 138 * At the end of the ReadInfo, there are also the CPU entries (see 139 * struct CPUEntry). When the Extended-Length SCCB (ELS) feature is 140 * enabled, the start of the CPU entries array begins at an offset 141 * denoted by the offset_cpu field, otherwise it's at offset 128. 142 */ 143 } __attribute__((packed)) ReadInfo; 144 145 typedef struct ReadCpuInfo { 146 SCCBHeader h; 147 uint16_t nr_configured; /* 8-9 */ 148 uint16_t offset_configured; /* 10-11 */ 149 uint16_t nr_standby; /* 12-13 */ 150 uint16_t offset_standby; /* 14-15 */ 151 uint8_t reserved0[24-16]; /* 16-23 */ 152 struct CPUEntry entries[0]; 153 } __attribute__((packed)) ReadCpuInfo; 154 155 typedef struct ReadStorageElementInfo { 156 SCCBHeader h; 157 uint16_t max_id; 158 uint16_t assigned; 159 uint16_t standby; 160 uint8_t _reserved0[16 - 14]; /* 14-15 */ 161 uint32_t entries[0]; 162 } __attribute__((packed)) ReadStorageElementInfo; 163 164 typedef struct AttachStorageElement { 165 SCCBHeader h; 166 uint8_t _reserved0[10 - 8]; /* 8-9 */ 167 uint16_t assigned; 168 uint8_t _reserved1[16 - 12]; /* 12-15 */ 169 uint32_t entries[0]; 170 } __attribute__((packed)) AttachStorageElement; 171 172 typedef struct AssignStorage { 173 SCCBHeader h; 174 uint16_t rn; 175 } __attribute__((packed)) AssignStorage; 176 177 typedef struct IoaCfgSccb { 178 SCCBHeader header; 179 uint8_t atype; 180 uint8_t reserved1; 181 uint16_t reserved2; 182 uint32_t aid; 183 } __attribute__((packed)) IoaCfgSccb; 184 185 typedef struct SCCB { 186 SCCBHeader h; 187 char data[SCCB_DATA_LEN]; 188 } __attribute__((packed)) SCCB; 189 190 /* SCLP event types */ 191 #define SCLP_EVENT_ASCII_CONSOLE_DATA 0x1a 192 #define SCLP_EVENT_SIGNAL_QUIESCE 0x1d 193 194 /* SCLP event masks */ 195 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE 0x00000008 196 #define SCLP_EVENT_MASK_MSG_ASCII 0x00000040 197 #define SCLP_EVENT_MASK_MSG 0x40000000 198 199 #define SCLP_UNCONDITIONAL_READ 0x00 200 #define SCLP_SELECTIVE_READ 0x01 201 202 typedef struct WriteEventMask { 203 SCCBHeader h; 204 uint16_t _reserved; 205 uint16_t mask_length; 206 uint32_t cp_receive_mask; 207 uint32_t cp_send_mask; 208 uint32_t send_mask; 209 uint32_t receive_mask; 210 } __attribute__((packed)) WriteEventMask; 211 212 #define MDBTYP_GO 0x0001 213 #define MDBTYP_MTO 0x0004 214 #define EVTYP_MSG 0x02 215 #define LNTPFLGS_CNTLTEXT 0x8000 216 #define LNTPFLGS_LABELTEXT 0x4000 217 #define LNTPFLGS_DATATEXT 0x2000 218 #define LNTPFLGS_ENDTEXT 0x1000 219 #define LNTPFLGS_PROMPTTEXT 0x0800 220 221 typedef uint32_t sccb_mask_t; 222 223 /* SCLP line mode console related structures. */ 224 225 struct mto { 226 u16 length; 227 u16 type; 228 u16 line_type_flags; 229 u8 alarm_control; 230 u8 _reserved[3]; 231 } __attribute__((packed)); 232 233 struct go { 234 u16 length; 235 u16 type; 236 u32 domid; 237 u8 hhmmss_time[8]; 238 u8 th_time[3]; 239 u8 reserved_0; 240 u8 dddyyyy_date[7]; 241 u8 _reserved_1; 242 u16 general_msg_flags; 243 u8 _reserved_2[10]; 244 u8 originating_system_name[8]; 245 u8 job_guest_name[8]; 246 } __attribute__((packed)); 247 248 struct mdb_header { 249 u16 length; 250 u16 type; 251 u32 tag; 252 u32 revision_code; 253 } __attribute__((packed)); 254 255 struct mdb { 256 struct mdb_header header; 257 struct go go; 258 struct mto mto; 259 } __attribute__((packed)); 260 261 typedef struct EventBufferHeader { 262 uint16_t length; 263 uint8_t type; 264 uint8_t flags; 265 uint16_t _reserved; 266 } __attribute__((packed)) EventBufferHeader; 267 268 typedef struct WriteEventData { 269 SCCBHeader h; 270 EventBufferHeader ebh; 271 union { 272 char data[0]; 273 struct mdb mdb; 274 } msg; 275 } __attribute__((packed)) WriteEventData; 276 277 typedef struct ReadEventData { 278 SCCBHeader h; 279 EventBufferHeader ebh; 280 uint32_t mask; 281 } __attribute__((packed)) ReadEventData; 282 283 extern char _sccb[]; 284 void sclp_setup_int(void); 285 void sclp_handle_ext(void); 286 void sclp_wait_busy(void); 287 void sclp_mark_busy(void); 288 void sclp_console_setup(void); 289 void sclp_print(const char *str); 290 void sclp_read_info(void); 291 int sclp_get_cpu_num(void); 292 CPUEntry *sclp_get_cpu_entries(void); 293 void sclp_facilities_setup(void); 294 int sclp_service_call(unsigned int command, void *sccb); 295 void sclp_memory_setup(void); 296 uint64_t get_ram_size(void); 297 uint64_t get_max_ram_size(void); 298 299 #endif /* SCLP_H */ 300