xref: /openbmc/qemu/hw/s390x/virtio-ccw.h (revision 33577b47)
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 
27 #include "css.h"
28 
29 #define VIRTUAL_CSSID 0xfe
30 
31 #define VIRTIO_CCW_CU_TYPE 0x3832
32 #define VIRTIO_CCW_CHPID_TYPE 0x32
33 
34 #define CCW_CMD_SET_VQ       0x13
35 #define CCW_CMD_VDEV_RESET   0x33
36 #define CCW_CMD_READ_FEAT    0x12
37 #define CCW_CMD_WRITE_FEAT   0x11
38 #define CCW_CMD_READ_CONF    0x22
39 #define CCW_CMD_WRITE_CONF   0x21
40 #define CCW_CMD_WRITE_STATUS 0x31
41 #define CCW_CMD_SET_IND      0x43
42 #define CCW_CMD_SET_CONF_IND 0x53
43 #define CCW_CMD_READ_VQ_CONF 0x32
44 #define CCW_CMD_SET_IND_ADAPTER 0x73
45 #define CCW_CMD_SET_VIRTIO_REV 0x83
46 
47 #define TYPE_VIRTIO_CCW_DEVICE "virtio-ccw-device"
48 #define VIRTIO_CCW_DEVICE(obj) \
49      OBJECT_CHECK(VirtioCcwDevice, (obj), TYPE_VIRTIO_CCW_DEVICE)
50 #define VIRTIO_CCW_DEVICE_CLASS(klass) \
51      OBJECT_CLASS_CHECK(VirtIOCCWDeviceClass, (klass), TYPE_VIRTIO_CCW_DEVICE)
52 #define VIRTIO_CCW_DEVICE_GET_CLASS(obj) \
53      OBJECT_GET_CLASS(VirtIOCCWDeviceClass, (obj), TYPE_VIRTIO_CCW_DEVICE)
54 
55 typedef struct VirtioBusState VirtioCcwBusState;
56 typedef struct VirtioBusClass VirtioCcwBusClass;
57 
58 #define TYPE_VIRTIO_CCW_BUS "virtio-ccw-bus"
59 #define VIRTIO_CCW_BUS(obj) \
60      OBJECT_CHECK(VirtioCcwBus, (obj), TYPE_VIRTIO_CCW_BUS)
61 #define VIRTIO_CCW_BUS_GET_CLASS(obj) \
62     OBJECT_CHECK(VirtioCcwBusState, (obj), TYPE_VIRTIO_CCW_BUS)
63 #define VIRTIO_CCW_BUS_CLASS(klass) \
64     OBJECT_CLASS_CHECK(VirtioCcwBusClass, klass, TYPE_VIRTIO_CCW_BUS)
65 
66 typedef struct VirtioCcwDevice VirtioCcwDevice;
67 
68 typedef struct VirtIOCCWDeviceClass {
69     DeviceClass parent_class;
70     void (*realize)(VirtioCcwDevice *dev, Error **errp);
71     int (*exit)(VirtioCcwDevice *dev);
72 } VirtIOCCWDeviceClass;
73 
74 /* Performance improves when virtqueue kick processing is decoupled from the
75  * vcpu thread using ioeventfd for some devices. */
76 #define VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT 1
77 #define VIRTIO_CCW_FLAG_USE_IOEVENTFD   (1 << VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT)
78 
79 struct VirtioCcwDevice {
80     DeviceState parent_obj;
81     SubchDev *sch;
82     char *bus_id;
83     int revision;
84     uint32_t max_rev;
85     VirtioBusState bus;
86     bool ioeventfd_started;
87     bool ioeventfd_disabled;
88     uint32_t flags;
89     uint8_t thinint_isc;
90     AdapterRoutes routes;
91     /* Guest provided values: */
92     IndAddr *indicators;
93     IndAddr *indicators2;
94     IndAddr *summary_indicator;
95     uint64_t ind_bit;
96 };
97 
98 /* The maximum virtio revision we support. */
99 #define VIRTIO_CCW_MAX_REV 1
100 static inline int virtio_ccw_rev_max(VirtioCcwDevice *dev)
101 {
102     return dev->max_rev;
103 }
104 
105 /* virtual css bus type */
106 typedef struct VirtualCssBus {
107     BusState parent_obj;
108 } VirtualCssBus;
109 
110 #define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus"
111 #define VIRTUAL_CSS_BUS(obj) \
112      OBJECT_CHECK(VirtualCssBus, (obj), TYPE_VIRTUAL_CSS_BUS)
113 
114 /* virtio-scsi-ccw */
115 
116 #define TYPE_VIRTIO_SCSI_CCW "virtio-scsi-ccw"
117 #define VIRTIO_SCSI_CCW(obj) \
118         OBJECT_CHECK(VirtIOSCSICcw, (obj), TYPE_VIRTIO_SCSI_CCW)
119 
120 typedef struct VirtIOSCSICcw {
121     VirtioCcwDevice parent_obj;
122     VirtIOSCSI vdev;
123 } VirtIOSCSICcw;
124 
125 #ifdef CONFIG_VHOST_SCSI
126 /* vhost-scsi-ccw */
127 
128 #define TYPE_VHOST_SCSI_CCW "vhost-scsi-ccw"
129 #define VHOST_SCSI_CCW(obj) \
130         OBJECT_CHECK(VHostSCSICcw, (obj), TYPE_VHOST_SCSI_CCW)
131 
132 typedef struct VHostSCSICcw {
133     VirtioCcwDevice parent_obj;
134     VHostSCSI vdev;
135 } VHostSCSICcw;
136 #endif
137 
138 /* virtio-blk-ccw */
139 
140 #define TYPE_VIRTIO_BLK_CCW "virtio-blk-ccw"
141 #define VIRTIO_BLK_CCW(obj) \
142         OBJECT_CHECK(VirtIOBlkCcw, (obj), TYPE_VIRTIO_BLK_CCW)
143 
144 typedef struct VirtIOBlkCcw {
145     VirtioCcwDevice parent_obj;
146     VirtIOBlock vdev;
147 } VirtIOBlkCcw;
148 
149 /* virtio-balloon-ccw */
150 
151 #define TYPE_VIRTIO_BALLOON_CCW "virtio-balloon-ccw"
152 #define VIRTIO_BALLOON_CCW(obj) \
153         OBJECT_CHECK(VirtIOBalloonCcw, (obj), TYPE_VIRTIO_BALLOON_CCW)
154 
155 typedef struct VirtIOBalloonCcw {
156     VirtioCcwDevice parent_obj;
157     VirtIOBalloon vdev;
158 } VirtIOBalloonCcw;
159 
160 /* virtio-serial-ccw */
161 
162 #define TYPE_VIRTIO_SERIAL_CCW "virtio-serial-ccw"
163 #define VIRTIO_SERIAL_CCW(obj) \
164         OBJECT_CHECK(VirtioSerialCcw, (obj), TYPE_VIRTIO_SERIAL_CCW)
165 
166 typedef struct VirtioSerialCcw {
167     VirtioCcwDevice parent_obj;
168     VirtIOSerial vdev;
169 } VirtioSerialCcw;
170 
171 /* virtio-net-ccw */
172 
173 #define TYPE_VIRTIO_NET_CCW "virtio-net-ccw"
174 #define VIRTIO_NET_CCW(obj) \
175         OBJECT_CHECK(VirtIONetCcw, (obj), TYPE_VIRTIO_NET_CCW)
176 
177 typedef struct VirtIONetCcw {
178     VirtioCcwDevice parent_obj;
179     VirtIONet vdev;
180 } VirtIONetCcw;
181 
182 /* virtio-rng-ccw */
183 
184 #define TYPE_VIRTIO_RNG_CCW "virtio-rng-ccw"
185 #define VIRTIO_RNG_CCW(obj) \
186         OBJECT_CHECK(VirtIORNGCcw, (obj), TYPE_VIRTIO_RNG_CCW)
187 
188 typedef struct VirtIORNGCcw {
189     VirtioCcwDevice parent_obj;
190     VirtIORNG vdev;
191 } VirtIORNGCcw;
192 
193 VirtualCssBus *virtual_css_bus_init(void);
194 void virtio_ccw_device_update_status(SubchDev *sch);
195 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch);
196 
197 #ifdef CONFIG_VIRTFS
198 #include "hw/9pfs/virtio-9p.h"
199 
200 #define TYPE_VIRTIO_9P_CCW "virtio-9p-ccw"
201 #define VIRTIO_9P_CCW(obj) \
202     OBJECT_CHECK(V9fsCCWState, (obj), TYPE_VIRTIO_9P_CCW)
203 
204 typedef struct V9fsCCWState {
205     VirtioCcwDevice parent_obj;
206     V9fsVirtioState vdev;
207 } V9fsCCWState;
208 
209 #endif /* CONFIG_VIRTFS */
210 
211 #endif
212