xref: /kvm-unit-tests/lib/s390x/sclp.h (revision 97b5f9553a48a15296462dc4c6170200b0dd70b8)
1 /*
2  * SCLP definitions
3  *
4  * Based on the file pc-bios/s390-ccw/sclp.h from QEMU
5  * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6  *
7  * and based on the file include/hw/s390x/sclp.h from QEMU
8  * Copyright IBM, Corp. 2012
9  * Author: Christian Borntraeger <borntraeger@de.ibm.com>
10  *
11  * This work is licensed under the terms of the GNU GPL, version 2 or (at
12  * your option) any later version. See the COPYING file in the top-level
13  * directory.
14  */
15 
16 #ifndef SCLP_H
17 #define SCLP_H
18 
19 #define SCLP_CMD_CODE_MASK                      0xffff00ff
20 
21 /* SCLP command codes */
22 #define SCLP_READ_CPU_INFO			0x00010001
23 #define SCLP_CMDW_READ_SCP_INFO                 0x00020001
24 #define SCLP_CMDW_READ_SCP_INFO_FORCED          0x00120001
25 #define SCLP_READ_STORAGE_ELEMENT_INFO          0x00040001
26 #define SCLP_ATTACH_STORAGE_ELEMENT             0x00080001
27 #define SCLP_ASSIGN_STORAGE                     0x000D0001
28 #define SCLP_CMD_READ_EVENT_DATA                0x00770005
29 #define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
30 #define SCLP_CMD_WRITE_EVENT_MASK               0x00780005
31 
32 /* SCLP Memory hotplug codes */
33 #define SCLP_FC_ASSIGN_ATTACH_READ_STOR         0xE00000000000ULL
34 #define SCLP_STARTING_SUBINCREMENT_ID           0x10001
35 #define SCLP_INCREMENT_UNIT                     0x10000
36 #define MAX_AVAIL_SLOTS                         32
37 #define MAX_STORAGE_INCREMENTS                  1020
38 
39 /* CPU hotplug SCLP codes */
40 #define SCLP_HAS_CPU_INFO                       0x0C00000000000000ULL
41 #define SCLP_CMDW_READ_CPU_INFO                 0x00010001
42 #define SCLP_CMDW_CONFIGURE_CPU                 0x00110001
43 #define SCLP_CMDW_DECONFIGURE_CPU               0x00100001
44 
45 /* SCLP PCI codes */
46 #define SCLP_HAS_IOA_RECONFIG                   0x0000000040000000ULL
47 #define SCLP_CMDW_CONFIGURE_IOA                 0x001a0001
48 #define SCLP_CMDW_DECONFIGURE_IOA               0x001b0001
49 #define SCLP_RECONFIG_PCI_ATYPE                 2
50 
51 /* SCLP response codes */
52 #define SCLP_RC_NORMAL_READ_COMPLETION          0x0010
53 #define SCLP_RC_NORMAL_COMPLETION               0x0020
54 #define SCLP_RC_SCCB_BOUNDARY_VIOLATION         0x0100
55 #define SCLP_RC_NO_ACTION_REQUIRED              0x0120
56 #define SCLP_RC_INVALID_SCLP_COMMAND            0x01f0
57 #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK       0x0340
58 #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH        0x0300
59 #define SCLP_RC_STANDBY_READ_COMPLETION         0x0410
60 #define SCLP_RC_ADAPTER_IN_RESERVED_STATE       0x05f0
61 #define SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED     0x06f0
62 #define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED       0x09f0
63 #define SCLP_RC_INVALID_FUNCTION                0x40f0
64 #define SCLP_RC_NO_EVENT_BUFFERS_STORED         0x60f0
65 #define SCLP_RC_INVALID_SELECTION_MASK          0x70f0
66 #define SCLP_RC_INCONSISTENT_LENGTHS            0x72f0
67 #define SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR       0x73f0
68 #define SCLP_RC_INVALID_MASK_LENGTH             0x74f0
69 
70 /* SCLP control mask bits */
71 #define SCLP_CM2_VARIABLE_LENGTH_RESPONSE       0x80
72 
73 /* SCLP function codes */
74 #define SCLP_FC_NORMAL_WRITE                    0
75 #define SCLP_FC_SINGLE_INCREMENT_ASSIGN         0x40
76 #define SCLP_FC_DUMP_INDICATOR                  0x80
77 
78 /* SCLP event buffer flags */
79 #define SCLP_EVENT_BUFFER_ACCEPTED              0x80
80 
81 /* Service Call Control Block (SCCB) and its elements */
82 #define SCCB_SIZE 4096
83 
84 typedef struct SCCBHeader {
85     uint16_t length;
86     uint8_t function_code;
87     uint8_t control_mask[3];
88     uint16_t response_code;
89 } __attribute__((packed)) SCCBHeader;
90 
91 #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))
92 #define SCCB_CPU_FEATURE_LEN 6
93 
94 /* CPU information */
95 typedef struct CPUEntry {
96     uint8_t address;
97     uint8_t reserved0;
98     uint8_t features[SCCB_CPU_FEATURE_LEN];
99     uint8_t reserved2[6];
100     uint8_t type;
101     uint8_t reserved1;
102 } __attribute__((packed)) CPUEntry;
103 
104 typedef struct ReadInfo {
105     SCCBHeader h;
106     uint16_t rnmax;
107     uint8_t rnsize;
108     uint8_t  _reserved1[16 - 11];       /* 11-15 */
109     uint16_t entries_cpu;               /* 16-17 */
110     uint16_t offset_cpu;                /* 18-19 */
111     uint8_t  _reserved2[24 - 20];       /* 20-23 */
112     uint8_t  loadparm[8];               /* 24-31 */
113     uint8_t  _reserved3[48 - 32];       /* 32-47 */
114     uint64_t facilities;                /* 48-55 */
115     uint8_t  _reserved0[76 - 56];       /* 56-75 */
116     uint32_t ibc_val;
117     uint8_t  conf_char[99 - 80];        /* 80-98 */
118     uint8_t mha_pow;
119     uint32_t rnsize2;
120     uint64_t rnmax2;
121     uint8_t  _reserved6[116 - 112];     /* 112-115 */
122     uint8_t  conf_char_ext[120 - 116];   /* 116-119 */
123     uint16_t highest_cpu;
124     uint8_t  _reserved5[124 - 122];     /* 122-123 */
125     uint32_t hmfai;
126     struct CPUEntry entries[0];
127 } __attribute__((packed)) ReadInfo;
128 
129 typedef struct ReadCpuInfo {
130     SCCBHeader h;
131     uint16_t nr_configured;         /* 8-9 */
132     uint16_t offset_configured;     /* 10-11 */
133     uint16_t nr_standby;            /* 12-13 */
134     uint16_t offset_standby;        /* 14-15 */
135     uint8_t reserved0[24-16];       /* 16-23 */
136     struct CPUEntry entries[0];
137 } __attribute__((packed)) ReadCpuInfo;
138 
139 typedef struct ReadStorageElementInfo {
140     SCCBHeader h;
141     uint16_t max_id;
142     uint16_t assigned;
143     uint16_t standby;
144     uint8_t _reserved0[16 - 14]; /* 14-15 */
145     uint32_t entries[0];
146 } __attribute__((packed)) ReadStorageElementInfo;
147 
148 typedef struct AttachStorageElement {
149     SCCBHeader h;
150     uint8_t _reserved0[10 - 8];  /* 8-9 */
151     uint16_t assigned;
152     uint8_t _reserved1[16 - 12]; /* 12-15 */
153     uint32_t entries[0];
154 } __attribute__((packed)) AttachStorageElement;
155 
156 typedef struct AssignStorage {
157     SCCBHeader h;
158     uint16_t rn;
159 } __attribute__((packed)) AssignStorage;
160 
161 typedef struct IoaCfgSccb {
162     SCCBHeader header;
163     uint8_t atype;
164     uint8_t reserved1;
165     uint16_t reserved2;
166     uint32_t aid;
167 } __attribute__((packed)) IoaCfgSccb;
168 
169 typedef struct SCCB {
170     SCCBHeader h;
171     char data[SCCB_DATA_LEN];
172  } __attribute__((packed)) SCCB;
173 
174 /* SCLP event types */
175 #define SCLP_EVENT_ASCII_CONSOLE_DATA           0x1a
176 #define SCLP_EVENT_SIGNAL_QUIESCE               0x1d
177 
178 /* SCLP event masks */
179 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE          0x00000008
180 #define SCLP_EVENT_MASK_MSG_ASCII               0x00000040
181 #define SCLP_EVENT_MASK_MSG          		0x40000000
182 
183 #define SCLP_UNCONDITIONAL_READ                 0x00
184 #define SCLP_SELECTIVE_READ                     0x01
185 
186 typedef struct WriteEventMask {
187     SCCBHeader h;
188     uint16_t _reserved;
189     uint16_t mask_length;
190     uint32_t cp_receive_mask;
191     uint32_t cp_send_mask;
192     uint32_t send_mask;
193     uint32_t receive_mask;
194 } __attribute__((packed)) WriteEventMask;
195 
196 #define MDBTYP_GO               0x0001
197 #define MDBTYP_MTO              0x0004
198 #define EVTYP_MSG               0x02
199 #define LNTPFLGS_CNTLTEXT       0x8000
200 #define LNTPFLGS_LABELTEXT      0x4000
201 #define LNTPFLGS_DATATEXT       0x2000
202 #define LNTPFLGS_ENDTEXT        0x1000
203 #define LNTPFLGS_PROMPTTEXT     0x0800
204 
205 typedef uint32_t sccb_mask_t;
206 
207 /* SCLP line mode console related structures. */
208 
209 struct mto {
210 	u16 length;
211 	u16 type;
212 	u16 line_type_flags;
213 	u8  alarm_control;
214 	u8  _reserved[3];
215 } __attribute__((packed));
216 
217 struct go {
218 	u16 length;
219 	u16 type;
220 	u32 domid;
221 	u8  hhmmss_time[8];
222 	u8  th_time[3];
223 	u8  reserved_0;
224 	u8  dddyyyy_date[7];
225 	u8  _reserved_1;
226 	u16 general_msg_flags;
227 	u8  _reserved_2[10];
228 	u8  originating_system_name[8];
229 	u8  job_guest_name[8];
230 } __attribute__((packed));
231 
232 struct mdb_header {
233 	u16 length;
234 	u16 type;
235 	u32 tag;
236 	u32 revision_code;
237 } __attribute__((packed));
238 
239 struct mdb {
240 	struct mdb_header header;
241 	struct go go;
242 	struct mto mto;
243 } __attribute__((packed));
244 
245 typedef struct EventBufferHeader {
246     uint16_t length;
247     uint8_t  type;
248     uint8_t  flags;
249     uint16_t _reserved;
250 } __attribute__((packed)) EventBufferHeader;
251 
252 typedef struct WriteEventData {
253     SCCBHeader h;
254     EventBufferHeader ebh;
255     union {
256 	char data[0];
257 	struct mdb mdb;
258     } msg;
259 } __attribute__((packed)) WriteEventData;
260 
261 typedef struct ReadEventData {
262     SCCBHeader h;
263     EventBufferHeader ebh;
264     uint32_t mask;
265 } __attribute__((packed)) ReadEventData;
266 
267 extern char _sccb[];
268 void sclp_setup_int(void);
269 void sclp_handle_ext(void);
270 void sclp_wait_busy(void);
271 void sclp_mark_busy(void);
272 void sclp_console_setup(void);
273 void sclp_print(const char *str);
274 int sclp_service_call(unsigned int command, void *sccb);
275 void sclp_memory_setup(void);
276 uint64_t get_ram_size(void);
277 uint64_t get_max_ram_size(void);
278 
279 #endif /* SCLP_H */
280