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