xref: /openbmc/qemu/include/hw/s390x/sclp.h (revision 1fd6bb44)
1 /*
2  * SCLP Support
3  *
4  * Copyright IBM, Corp. 2012
5  *
6  * Authors:
7  *  Christian Borntraeger <borntraeger@de.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or (at your
10  * option) any later version.  See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef HW_S390_SCLP_H
15 #define HW_S390_SCLP_H
16 
17 #include <hw/sysbus.h>
18 #include <hw/qdev.h>
19 
20 /* SCLP command codes */
21 #define SCLP_CMDW_READ_SCP_INFO                 0x00020001
22 #define SCLP_CMDW_READ_SCP_INFO_FORCED          0x00120001
23 #define SCLP_CMD_READ_EVENT_DATA                0x00770005
24 #define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
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 response codes */
30 #define SCLP_RC_NORMAL_READ_COMPLETION          0x0010
31 #define SCLP_RC_NORMAL_COMPLETION               0x0020
32 #define SCLP_RC_INVALID_SCLP_COMMAND            0x01f0
33 #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK       0x0340
34 #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH        0x0300
35 #define SCLP_RC_INVALID_FUNCTION                0x40f0
36 #define SCLP_RC_NO_EVENT_BUFFERS_STORED         0x60f0
37 #define SCLP_RC_INVALID_SELECTION_MASK          0x70f0
38 #define SCLP_RC_INCONSISTENT_LENGTHS            0x72f0
39 #define SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR       0x73f0
40 #define SCLP_RC_INVALID_MASK_LENGTH             0x74f0
41 
42 
43 /* Service Call Control Block (SCCB) and its elements */
44 
45 #define SCCB_SIZE 4096
46 
47 #define SCLP_VARIABLE_LENGTH_RESPONSE           0x80
48 #define SCLP_EVENT_BUFFER_ACCEPTED              0x80
49 
50 #define SCLP_FC_NORMAL_WRITE                    0
51 
52 /*
53  * Normally packed structures are not the right thing to do, since all code
54  * must take care of endianness. We cannot use ldl_phys and friends for two
55  * reasons, though:
56  * - some of the embedded structures below the SCCB can appear multiple times
57  *   at different locations, so there is no fixed offset
58  * - we work on a private copy of the SCCB, since there are several length
59  *   fields, that would cause a security nightmare if we allow the guest to
60  *   alter the structure while we parse it. We cannot use ldl_p and friends
61  *   either without doing pointer arithmetics
62  * So we have to double check that all users of sclp data structures use the
63  * right endianness wrappers.
64  */
65 typedef struct SCCBHeader {
66     uint16_t length;
67     uint8_t function_code;
68     uint8_t control_mask[3];
69     uint16_t response_code;
70 } QEMU_PACKED SCCBHeader;
71 
72 #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))
73 
74 typedef struct ReadInfo {
75     SCCBHeader h;
76     uint16_t rnmax;
77     uint8_t rnsize;
78 } QEMU_PACKED ReadInfo;
79 
80 typedef struct SCCB {
81     SCCBHeader h;
82     char data[SCCB_DATA_LEN];
83  } QEMU_PACKED SCCB;
84 
85 static inline int sccb_data_len(SCCB *sccb)
86 {
87     return be16_to_cpu(sccb->h.length) - sizeof(sccb->h);
88 }
89 
90 #define TYPE_DEVICE_S390_SCLP "s390-sclp-device"
91 #define SCLP_S390_DEVICE(obj) \
92      OBJECT_CHECK(S390SCLPDevice, (obj), TYPE_DEVICE_S390_SCLP)
93 #define SCLP_S390_DEVICE_CLASS(klass) \
94      OBJECT_CLASS_CHECK(S390SCLPDeviceClass, (klass), \
95              TYPE_DEVICE_S390_SCLP)
96 #define SCLP_S390_DEVICE_GET_CLASS(obj) \
97      OBJECT_GET_CLASS(S390SCLPDeviceClass, (obj), \
98              TYPE_DEVICE_S390_SCLP)
99 
100 typedef struct SCLPEventFacility SCLPEventFacility;
101 
102 typedef struct S390SCLPDevice {
103     SysBusDevice busdev;
104     SCLPEventFacility *ef;
105     void (*sclp_command_handler)(SCLPEventFacility *ef, SCCB *sccb,
106                                  uint64_t code);
107     bool (*event_pending)(SCLPEventFacility *ef);
108 } S390SCLPDevice;
109 
110 typedef struct S390SCLPDeviceClass {
111     DeviceClass qdev;
112     int (*init)(S390SCLPDevice *sdev);
113 } S390SCLPDeviceClass;
114 
115 void s390_sclp_init(void);
116 void sclp_service_interrupt(uint32_t sccb);
117 
118 #endif
119