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