xref: /openbmc/qemu/include/hw/s390x/event-facility.h (revision f7160f32)
1 /*
2  * SCLP
3  *    Event Facility definitions
4  *
5  * Copyright IBM, Corp. 2012
6  *
7  * Authors:
8  *  Heinz Graalfs <graalfs@de.ibm.com>
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2 or (at your
11  * option) any later version.  See the COPYING file in the top-level directory.
12  *
13  */
14 
15 #ifndef HW_S390_SCLP_EVENT_FACILITY_H
16 #define HW_S390_SCLP_EVENT_FACILITY_H
17 
18 #include "qemu/thread.h"
19 #include "hw/qdev-core.h"
20 #include "hw/s390x/sclp.h"
21 
22 /* SCLP event types */
23 #define SCLP_EVENT_OPRTNS_COMMAND               0x01
24 #define SCLP_EVENT_MESSAGE                      0x02
25 #define SCLP_EVENT_CONFIG_MGT_DATA              0x04
26 #define SCLP_EVENT_PMSGCMD                      0x09
27 #define SCLP_EVENT_ASCII_CONSOLE_DATA           0x1a
28 #define SCLP_EVENT_SIGNAL_QUIESCE               0x1d
29 
30 /* SCLP event masks */
31 #define SCLP_EVMASK(T)  (1ULL << (sizeof(sccb_mask_t) * 8 - (T)))
32 
33 #define SCLP_EVENT_MASK_OP_CMD          SCLP_EVMASK(SCLP_EVENT_OPRTNS_COMMAND)
34 #define SCLP_EVENT_MASK_MSG             SCLP_EVMASK(SCLP_EVENT_MESSAGE)
35 #define SCLP_EVENT_MASK_CONFIG_MGT_DATA SCLP_EVMASK(SCLP_EVENT_CONFIG_MGT_DATA)
36 #define SCLP_EVENT_MASK_PMSGCMD         SCLP_EVMASK(SCLP_EVENT_PMSGCMD)
37 #define SCLP_EVENT_MASK_MSG_ASCII       SCLP_EVMASK(SCLP_EVENT_ASCII_CONSOLE_DATA)
38 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE  SCLP_EVMASK(SCLP_EVENT_SIGNAL_QUIESCE)
39 
40 #define SCLP_UNCONDITIONAL_READ                 0x00
41 #define SCLP_SELECTIVE_READ                     0x01
42 
43 #define TYPE_SCLP_EVENT "s390-sclp-event-type"
44 #define SCLP_EVENT(obj) \
45      OBJECT_CHECK(SCLPEvent, (obj), TYPE_SCLP_EVENT)
46 #define SCLP_EVENT_CLASS(klass) \
47      OBJECT_CLASS_CHECK(SCLPEventClass, (klass), TYPE_SCLP_EVENT)
48 #define SCLP_EVENT_GET_CLASS(obj) \
49      OBJECT_GET_CLASS(SCLPEventClass, (obj), TYPE_SCLP_EVENT)
50 
51 #define TYPE_SCLP_CPU_HOTPLUG "sclp-cpu-hotplug"
52 #define TYPE_SCLP_QUIESCE "sclpquiesce"
53 
54 #define SCLP_EVENT_MASK_LEN_MAX 1021
55 
56 typedef struct WriteEventMask {
57     SCCBHeader h;
58     uint16_t _reserved;
59     uint16_t mask_length;
60     uint8_t masks[];
61 /*
62  * Layout of the masks is
63  *  uint8_t cp_receive_mask[mask_length];
64  *  uint8_t cp_send_mask[mask_length];
65  *  uint8_t receive_mask[mask_length];
66  *  uint8_t send_mask[mask_length];
67  * where 1 <= mask_length <= SCLP_EVENT_MASK_LEN_MAX
68  */
69 } QEMU_PACKED WriteEventMask;
70 
71 #define WEM_CP_RECEIVE_MASK(wem, mask_len) ((wem)->masks)
72 #define WEM_CP_SEND_MASK(wem, mask_len) ((wem)->masks + (mask_len))
73 #define WEM_RECEIVE_MASK(wem, mask_len) ((wem)->masks + 2 * (mask_len))
74 #define WEM_SEND_MASK(wem, mask_len) ((wem)->masks + 3 * (mask_len))
75 
76 typedef uint64_t sccb_mask_t;
77 
78 typedef struct EventBufferHeader {
79     uint16_t length;
80     uint8_t  type;
81     uint8_t  flags;
82     uint16_t _reserved;
83 } QEMU_PACKED EventBufferHeader;
84 
85 typedef struct MdbHeader {
86     uint16_t length;
87     uint16_t type;
88     uint32_t tag;
89     uint32_t revision_code;
90 } QEMU_PACKED MdbHeader;
91 
92 typedef struct MTO {
93     uint16_t line_type_flags;
94     uint8_t  alarm_control;
95     uint8_t  _reserved[3];
96     char     message[];
97 } QEMU_PACKED MTO;
98 
99 typedef struct GO {
100     uint32_t domid;
101     uint8_t  hhmmss_time[8];
102     uint8_t  th_time[3];
103     uint8_t  _reserved_0;
104     uint8_t  dddyyyy_date[7];
105     uint8_t  _reserved_1;
106     uint16_t general_msg_flags;
107     uint8_t  _reserved_2[10];
108     uint8_t  originating_system_name[8];
109     uint8_t  job_guest_name[8];
110 } QEMU_PACKED GO;
111 
112 #define MESSAGE_TEXT 0x0004
113 
114 typedef struct MDBO {
115     uint16_t length;
116     uint16_t type;
117     union {
118         GO go;
119         MTO mto;
120     };
121 } QEMU_PACKED MDBO;
122 
123 typedef struct MDB {
124     MdbHeader header;
125     MDBO mdbo[];
126 } QEMU_PACKED MDB;
127 
128 typedef struct SclpMsg {
129     EventBufferHeader header;
130     MDB mdb;
131 } QEMU_PACKED SclpMsg;
132 
133 #define GDS_ID_MDSMU                            0x1310
134 #define GDS_ID_CPMSU                            0x1212
135 #define GDS_ID_TEXTCMD                          0x1320
136 
137 typedef struct GdsVector {
138     uint16_t length;
139     uint16_t gds_id;
140 } QEMU_PACKED GdsVector;
141 
142 #define GDS_KEY_SELFDEFTEXTMSG                  0x31
143 #define GDS_KEY_TEXTMSG                         0x30
144 
145 typedef struct GdsSubvector {
146     uint8_t length;
147     uint8_t key;
148 } QEMU_PACKED GdsSubvector;
149 
150 /* MDS Message Unit */
151 typedef struct MDMSU {
152     GdsVector mdmsu;
153     GdsVector cpmsu;
154     GdsVector text_command;
155     GdsSubvector self_def_text_message;
156     GdsSubvector text_message;
157 } QEMU_PACKED MDMSU;
158 
159 typedef struct WriteEventData {
160     SCCBHeader h;
161     EventBufferHeader ebh;
162 } QEMU_PACKED WriteEventData;
163 
164 typedef struct ReadEventData {
165     SCCBHeader h;
166     union {
167         sccb_mask_t mask;
168         EventBufferHeader ebh;
169     };
170 } QEMU_PACKED ReadEventData;
171 
172 typedef struct SCLPEvent {
173     DeviceState qdev;
174     bool event_pending;
175     char *name;
176 } SCLPEvent;
177 
178 typedef struct SCLPEventClass {
179     DeviceClass parent_class;
180     int (*init)(SCLPEvent *event);
181 
182     /* get SCLP's send mask */
183     sccb_mask_t (*get_send_mask)(void);
184 
185     /* get SCLP's receive mask */
186     sccb_mask_t (*get_receive_mask)(void);
187 
188     int (*read_event_data)(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
189                            int *slen);
190 
191     int (*write_event_data)(SCLPEvent *event, EventBufferHeader *evt_buf_hdr);
192 
193     /* can we handle this event type? */
194     bool (*can_handle_event)(uint8_t type);
195 } SCLPEventClass;
196 
197 #define TYPE_SCLP_EVENT_FACILITY "s390-sclp-event-facility"
198 #define EVENT_FACILITY(obj) \
199      OBJECT_CHECK(SCLPEventFacility, (obj), TYPE_SCLP_EVENT_FACILITY)
200 #define EVENT_FACILITY_CLASS(klass) \
201      OBJECT_CLASS_CHECK(SCLPEventFacilityClass, (klass), \
202                         TYPE_SCLP_EVENT_FACILITY)
203 #define EVENT_FACILITY_GET_CLASS(obj) \
204      OBJECT_GET_CLASS(SCLPEventFacilityClass, (obj), \
205                       TYPE_SCLP_EVENT_FACILITY)
206 
207 typedef struct SCLPEventFacilityClass {
208     SysBusDeviceClass parent_class;
209     void (*command_handler)(SCLPEventFacility *ef, SCCB *sccb, uint64_t code);
210     bool (*event_pending)(SCLPEventFacility *ef);
211 } SCLPEventFacilityClass;
212 
213 BusState *sclp_get_event_facility_bus(void);
214 
215 #endif
216