xref: /kvm-unit-tests/lib/s390x/sclp.h (revision 4c8a99ca02252d4a2bee43f4558fe47ce5ab7ec0)
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[16 - 11];       /* 11-15 */
154 	uint16_t entries_cpu;               /* 16-17 */
155 	uint16_t offset_cpu;                /* 18-19 */
156 	uint8_t  _reserved2[24 - 20];       /* 20-23 */
157 	uint8_t  loadparm[8];               /* 24-31 */
158 	uint8_t  _reserved3[48 - 32];       /* 32-47 */
159 	uint64_t facilities;                /* 48-55 */
160 	uint8_t  _reserved0[76 - 56];       /* 56-75 */
161 	uint32_t ibc_val;
162 	uint8_t  conf_char[99 - 80];        /* 80-98 */
163 	uint8_t mha_pow;
164 	uint32_t rnsize2;
165 	uint64_t rnmax2;
166 	uint8_t  _reserved6[116 - 112];     /* 112-115 */
167 	uint8_t  conf_char_ext[120 - 116];   /* 116-119 */
168 	uint16_t highest_cpu;
169 	uint8_t  _reserved5[124 - 122];     /* 122-123 */
170 	uint32_t hmfai;
171 	uint8_t reserved7[134 - 128];       /* 128-133 */
172 	uint8_t byte_134_diag318 : 1;
173 	uint8_t : 7;
174 	/*
175 	 * At the end of the ReadInfo, there are also the CPU entries (see
176 	 * struct CPUEntry). When the Extended-Length SCCB (ELS) feature is
177 	 * enabled, the start of the CPU entries array begins at an offset
178 	 * denoted by the offset_cpu field, otherwise it's at offset 128.
179 	 */
180 } __attribute__((packed)) ReadInfo;
181 
182 typedef struct ReadCpuInfo {
183 	SCCBHeader h;
184 	uint16_t nr_configured;         /* 8-9 */
185 	uint16_t offset_configured;     /* 10-11 */
186 	uint16_t nr_standby;            /* 12-13 */
187 	uint16_t offset_standby;        /* 14-15 */
188 	uint8_t reserved0[24-16];       /* 16-23 */
189 	struct CPUEntry entries[0];
190 } __attribute__((packed)) ReadCpuInfo;
191 
192 typedef struct ReadStorageElementInfo {
193 	SCCBHeader h;
194 	uint16_t max_id;
195 	uint16_t assigned;
196 	uint16_t standby;
197 	uint8_t _reserved0[16 - 14]; /* 14-15 */
198 	uint32_t entries[0];
199 } __attribute__((packed)) ReadStorageElementInfo;
200 
201 typedef struct AttachStorageElement {
202 	SCCBHeader h;
203 	uint8_t _reserved0[10 - 8];  /* 8-9 */
204 	uint16_t assigned;
205 	uint8_t _reserved1[16 - 12]; /* 12-15 */
206 	uint32_t entries[0];
207 } __attribute__((packed)) AttachStorageElement;
208 
209 typedef struct AssignStorage {
210 	SCCBHeader h;
211 	uint16_t rn;
212 } __attribute__((packed)) AssignStorage;
213 
214 typedef struct IoaCfgSccb {
215 	SCCBHeader header;
216 	uint8_t atype;
217 	uint8_t reserved1;
218 	uint16_t reserved2;
219 	uint32_t aid;
220 } __attribute__((packed)) IoaCfgSccb;
221 
222 typedef struct SCCB {
223 	SCCBHeader h;
224 	char data[SCCB_DATA_LEN];
225 } __attribute__((packed)) SCCB;
226 
227 /* SCLP event types */
228 #define SCLP_EVENT_ASCII_CONSOLE_DATA           0x1a
229 #define SCLP_EVENT_SIGNAL_QUIESCE               0x1d
230 
231 /* SCLP event masks */
232 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE          0x00000008
233 #define SCLP_EVENT_MASK_MSG_ASCII               0x00000040
234 #define SCLP_EVENT_MASK_MSG          		0x40000000
235 
236 #define SCLP_UNCONDITIONAL_READ                 0x00
237 #define SCLP_SELECTIVE_READ                     0x01
238 
239 typedef struct WriteEventMask {
240 	SCCBHeader h;
241 	uint16_t _reserved;
242 	uint16_t mask_length;
243 	uint32_t cp_receive_mask;
244 	uint32_t cp_send_mask;
245 	uint32_t send_mask;
246 	uint32_t receive_mask;
247 } __attribute__((packed)) WriteEventMask;
248 
249 #define MDBTYP_GO               0x0001
250 #define MDBTYP_MTO              0x0004
251 #define EVTYP_MSG               0x02
252 #define LNTPFLGS_CNTLTEXT       0x8000
253 #define LNTPFLGS_LABELTEXT      0x4000
254 #define LNTPFLGS_DATATEXT       0x2000
255 #define LNTPFLGS_ENDTEXT        0x1000
256 #define LNTPFLGS_PROMPTTEXT     0x0800
257 
258 typedef uint32_t sccb_mask_t;
259 
260 /* SCLP line mode console related structures. */
261 
262 struct mto {
263 	u16 length;
264 	u16 type;
265 	u16 line_type_flags;
266 	u8  alarm_control;
267 	u8  _reserved[3];
268 } __attribute__((packed));
269 
270 struct go {
271 	u16 length;
272 	u16 type;
273 	u32 domid;
274 	u8  hhmmss_time[8];
275 	u8  th_time[3];
276 	u8  reserved_0;
277 	u8  dddyyyy_date[7];
278 	u8  _reserved_1;
279 	u16 general_msg_flags;
280 	u8  _reserved_2[10];
281 	u8  originating_system_name[8];
282 	u8  job_guest_name[8];
283 } __attribute__((packed));
284 
285 struct mdb_header {
286 	u16 length;
287 	u16 type;
288 	u32 tag;
289 	u32 revision_code;
290 } __attribute__((packed));
291 
292 struct mdb {
293 	struct mdb_header header;
294 	struct go go;
295 	struct mto mto;
296 } __attribute__((packed));
297 
298 typedef struct EventBufferHeader {
299 	uint16_t length;
300 	uint8_t  type;
301 	uint8_t  flags;
302 	uint16_t _reserved;
303 } __attribute__((packed)) EventBufferHeader;
304 
305 typedef struct WriteEventData {
306 	SCCBHeader h;
307 	EventBufferHeader ebh;
308 	union {
309 		char data[0];
310 		struct mdb mdb;
311 	} msg;
312 } __attribute__((packed)) WriteEventData;
313 
314 typedef struct ReadEventData {
315 	SCCBHeader h;
316 	EventBufferHeader ebh;
317 	uint32_t mask;
318 } __attribute__((packed)) ReadEventData;
319 
320 #define SCLP_EVENT_ASCII_TYPE_DATA_STREAM_FOLLOWS 0
321 typedef struct ReadEventDataAsciiConsole {
322 	SCCBHeader h;
323 	EventBufferHeader ebh;
324 	uint8_t type;
325 	char data[];
326 } __attribute__((packed)) ReadEventDataAsciiConsole;
327 
328 extern char _sccb[];
329 void sclp_setup_int(void);
330 void sclp_handle_ext(void);
331 void sclp_wait_busy(void);
332 void sclp_mark_busy(void);
333 void sclp_clear_busy(void);
334 void sclp_console_setup(void);
335 void sclp_print(const char *str);
336 void sclp_read_info(void);
337 int sclp_get_cpu_num(void);
338 CPUEntry *sclp_get_cpu_entries(void);
339 void sclp_facilities_setup(void);
340 int sclp_service_call(unsigned int command, void *sccb);
341 void sclp_memory_setup(void);
342 uint64_t get_ram_size(void);
343 uint64_t get_max_ram_size(void);
344 
345 #endif /* _S390X_SCLP_H_ */
346