xref: /openbmc/qemu/hw/s390x/virtio-ccw.h (revision 646c5478)
1 /*
2  * virtio ccw target definitions
3  *
4  * Copyright 2012,2015 IBM Corp.
5  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6  *            Pierre Morel <pmorel@linux.vnet.ibm.com>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or (at
9  * your option) any later version. See the COPYING file in the top-level
10  * directory.
11  */
12 
13 #ifndef HW_S390X_VIRTIO_CCW_H
14 #define HW_S390X_VIRTIO_CCW_H
15 
16 #include "hw/virtio/virtio-blk.h"
17 #include "hw/virtio/virtio-net.h"
18 #include "hw/virtio/virtio-serial.h"
19 #include "hw/virtio/virtio-scsi.h"
20 #ifdef CONFIG_VHOST_SCSI
21 #include "hw/virtio/vhost-scsi.h"
22 #endif
23 #include "hw/virtio/virtio-balloon.h"
24 #include "hw/virtio/virtio-rng.h"
25 #include "hw/virtio/virtio-bus.h"
26 #ifdef CONFIG_VHOST_VSOCK
27 #include "hw/virtio/vhost-vsock.h"
28 #endif /* CONFIG_VHOST_VSOCK */
29 
30 #include "hw/s390x/s390_flic.h"
31 #include "hw/s390x/css.h"
32 #include "ccw-device.h"
33 #include "hw/s390x/css-bridge.h"
34 
35 #define VIRTIO_CCW_CU_TYPE 0x3832
36 #define VIRTIO_CCW_CHPID_TYPE 0x32
37 
38 #define CCW_CMD_SET_VQ       0x13
39 #define CCW_CMD_VDEV_RESET   0x33
40 #define CCW_CMD_READ_FEAT    0x12
41 #define CCW_CMD_WRITE_FEAT   0x11
42 #define CCW_CMD_READ_CONF    0x22
43 #define CCW_CMD_WRITE_CONF   0x21
44 #define CCW_CMD_WRITE_STATUS 0x31
45 #define CCW_CMD_SET_IND      0x43
46 #define CCW_CMD_SET_CONF_IND 0x53
47 #define CCW_CMD_READ_VQ_CONF 0x32
48 #define CCW_CMD_READ_STATUS  0x72
49 #define CCW_CMD_SET_IND_ADAPTER 0x73
50 #define CCW_CMD_SET_VIRTIO_REV 0x83
51 
52 #define TYPE_VIRTIO_CCW_DEVICE "virtio-ccw-device"
53 #define VIRTIO_CCW_DEVICE(obj) \
54      OBJECT_CHECK(VirtioCcwDevice, (obj), TYPE_VIRTIO_CCW_DEVICE)
55 #define VIRTIO_CCW_DEVICE_CLASS(klass) \
56      OBJECT_CLASS_CHECK(VirtIOCCWDeviceClass, (klass), TYPE_VIRTIO_CCW_DEVICE)
57 #define VIRTIO_CCW_DEVICE_GET_CLASS(obj) \
58      OBJECT_GET_CLASS(VirtIOCCWDeviceClass, (obj), TYPE_VIRTIO_CCW_DEVICE)
59 
60 typedef struct VirtioBusState VirtioCcwBusState;
61 typedef struct VirtioBusClass VirtioCcwBusClass;
62 
63 #define TYPE_VIRTIO_CCW_BUS "virtio-ccw-bus"
64 #define VIRTIO_CCW_BUS(obj) \
65      OBJECT_CHECK(VirtioCcwBus, (obj), TYPE_VIRTIO_CCW_BUS)
66 #define VIRTIO_CCW_BUS_GET_CLASS(obj) \
67     OBJECT_CHECK(VirtioCcwBusState, (obj), TYPE_VIRTIO_CCW_BUS)
68 #define VIRTIO_CCW_BUS_CLASS(klass) \
69     OBJECT_CLASS_CHECK(VirtioCcwBusClass, klass, TYPE_VIRTIO_CCW_BUS)
70 
71 typedef struct VirtioCcwDevice VirtioCcwDevice;
72 
73 typedef struct VirtIOCCWDeviceClass {
74     CCWDeviceClass parent_class;
75     void (*realize)(VirtioCcwDevice *dev, Error **errp);
76     int (*exit)(VirtioCcwDevice *dev);
77 } VirtIOCCWDeviceClass;
78 
79 /* Performance improves when virtqueue kick processing is decoupled from the
80  * vcpu thread using ioeventfd for some devices. */
81 #define VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT 1
82 #define VIRTIO_CCW_FLAG_USE_IOEVENTFD   (1 << VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT)
83 
84 struct VirtioCcwDevice {
85     CcwDevice parent_obj;
86     int revision;
87     uint32_t max_rev;
88     VirtioBusState bus;
89     uint32_t flags;
90     uint8_t thinint_isc;
91     AdapterRoutes routes;
92     /* Guest provided values: */
93     IndAddr *indicators;
94     IndAddr *indicators2;
95     IndAddr *summary_indicator;
96     uint64_t ind_bit;
97 };
98 
99 /* The maximum virtio revision we support. */
100 #define VIRTIO_CCW_MAX_REV 2
101 static inline int virtio_ccw_rev_max(VirtioCcwDevice *dev)
102 {
103     return dev->max_rev;
104 }
105 
106 /* virtio-scsi-ccw */
107 
108 #define TYPE_VIRTIO_SCSI_CCW "virtio-scsi-ccw"
109 #define VIRTIO_SCSI_CCW(obj) \
110         OBJECT_CHECK(VirtIOSCSICcw, (obj), TYPE_VIRTIO_SCSI_CCW)
111 
112 typedef struct VirtIOSCSICcw {
113     VirtioCcwDevice parent_obj;
114     VirtIOSCSI vdev;
115 } VirtIOSCSICcw;
116 
117 #ifdef CONFIG_VHOST_SCSI
118 /* vhost-scsi-ccw */
119 
120 #define TYPE_VHOST_SCSI_CCW "vhost-scsi-ccw"
121 #define VHOST_SCSI_CCW(obj) \
122         OBJECT_CHECK(VHostSCSICcw, (obj), TYPE_VHOST_SCSI_CCW)
123 
124 typedef struct VHostSCSICcw {
125     VirtioCcwDevice parent_obj;
126     VHostSCSI vdev;
127 } VHostSCSICcw;
128 #endif
129 
130 /* virtio-blk-ccw */
131 
132 #define TYPE_VIRTIO_BLK_CCW "virtio-blk-ccw"
133 #define VIRTIO_BLK_CCW(obj) \
134         OBJECT_CHECK(VirtIOBlkCcw, (obj), TYPE_VIRTIO_BLK_CCW)
135 
136 typedef struct VirtIOBlkCcw {
137     VirtioCcwDevice parent_obj;
138     VirtIOBlock vdev;
139 } VirtIOBlkCcw;
140 
141 /* virtio-balloon-ccw */
142 
143 #define TYPE_VIRTIO_BALLOON_CCW "virtio-balloon-ccw"
144 #define VIRTIO_BALLOON_CCW(obj) \
145         OBJECT_CHECK(VirtIOBalloonCcw, (obj), TYPE_VIRTIO_BALLOON_CCW)
146 
147 typedef struct VirtIOBalloonCcw {
148     VirtioCcwDevice parent_obj;
149     VirtIOBalloon vdev;
150 } VirtIOBalloonCcw;
151 
152 /* virtio-serial-ccw */
153 
154 #define TYPE_VIRTIO_SERIAL_CCW "virtio-serial-ccw"
155 #define VIRTIO_SERIAL_CCW(obj) \
156         OBJECT_CHECK(VirtioSerialCcw, (obj), TYPE_VIRTIO_SERIAL_CCW)
157 
158 typedef struct VirtioSerialCcw {
159     VirtioCcwDevice parent_obj;
160     VirtIOSerial vdev;
161 } VirtioSerialCcw;
162 
163 /* virtio-net-ccw */
164 
165 #define TYPE_VIRTIO_NET_CCW "virtio-net-ccw"
166 #define VIRTIO_NET_CCW(obj) \
167         OBJECT_CHECK(VirtIONetCcw, (obj), TYPE_VIRTIO_NET_CCW)
168 
169 typedef struct VirtIONetCcw {
170     VirtioCcwDevice parent_obj;
171     VirtIONet vdev;
172 } VirtIONetCcw;
173 
174 /* virtio-rng-ccw */
175 
176 #define TYPE_VIRTIO_RNG_CCW "virtio-rng-ccw"
177 #define VIRTIO_RNG_CCW(obj) \
178         OBJECT_CHECK(VirtIORNGCcw, (obj), TYPE_VIRTIO_RNG_CCW)
179 
180 typedef struct VirtIORNGCcw {
181     VirtioCcwDevice parent_obj;
182     VirtIORNG vdev;
183 } VirtIORNGCcw;
184 
185 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch);
186 
187 #ifdef CONFIG_VIRTFS
188 #include "hw/9pfs/virtio-9p.h"
189 
190 #define TYPE_VIRTIO_9P_CCW "virtio-9p-ccw"
191 #define VIRTIO_9P_CCW(obj) \
192     OBJECT_CHECK(V9fsCCWState, (obj), TYPE_VIRTIO_9P_CCW)
193 
194 typedef struct V9fsCCWState {
195     VirtioCcwDevice parent_obj;
196     V9fsVirtioState vdev;
197 } V9fsCCWState;
198 
199 #endif /* CONFIG_VIRTFS */
200 
201 #ifdef CONFIG_VHOST_VSOCK
202 #define TYPE_VHOST_VSOCK_CCW "vhost-vsock-ccw"
203 #define VHOST_VSOCK_CCW(obj) \
204     OBJECT_CHECK(VHostVSockCCWState, (obj), TYPE_VHOST_VSOCK_CCW)
205 
206 typedef struct VHostVSockCCWState {
207     VirtioCcwDevice parent_obj;
208     VHostVSock vdev;
209 } VHostVSockCCWState;
210 
211 #endif /* CONFIG_VHOST_VSOCK */
212 
213 #endif
214