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