xref: /openbmc/qemu/hw/s390x/virtio-ccw.h (revision 878096ee)
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 
26 #define VIRTUAL_CSSID 0xfe
27 
28 #define VIRTIO_CCW_CU_TYPE 0x3832
29 #define VIRTIO_CCW_CHPID_TYPE 0x32
30 
31 #define CCW_CMD_SET_VQ       0x13
32 #define CCW_CMD_VDEV_RESET   0x33
33 #define CCW_CMD_READ_FEAT    0x12
34 #define CCW_CMD_WRITE_FEAT   0x11
35 #define CCW_CMD_READ_CONF    0x22
36 #define CCW_CMD_WRITE_CONF   0x21
37 #define CCW_CMD_WRITE_STATUS 0x31
38 #define CCW_CMD_SET_IND      0x43
39 #define CCW_CMD_SET_CONF_IND 0x53
40 #define CCW_CMD_READ_VQ_CONF 0x32
41 
42 #define TYPE_VIRTIO_CCW_DEVICE "virtio-ccw-device"
43 #define VIRTIO_CCW_DEVICE(obj) \
44      OBJECT_CHECK(VirtioCcwDevice, (obj), TYPE_VIRTIO_CCW_DEVICE)
45 #define VIRTIO_CCW_DEVICE_CLASS(klass) \
46      OBJECT_CLASS_CHECK(VirtIOCCWDeviceClass, (klass), TYPE_VIRTIO_CCW_DEVICE)
47 #define VIRTIO_CCW_DEVICE_GET_CLASS(obj) \
48      OBJECT_GET_CLASS(VirtIOCCWDeviceClass, (obj), TYPE_VIRTIO_CCW_DEVICE)
49 
50 typedef struct VirtioBusState VirtioCcwBusState;
51 typedef struct VirtioBusClass VirtioCcwBusClass;
52 
53 #define TYPE_VIRTIO_CCW_BUS "virtio-ccw-bus"
54 #define VIRTIO_CCW_BUS(obj) \
55      OBJECT_CHECK(VirtioCcwBus, (obj), TYPE_VIRTIO_CCW_BUS)
56 #define VIRTIO_CCW_BUS_GET_CLASS(obj) \
57     OBJECT_CHECK(VirtioCcwBusState, (obj), TYPE_VIRTIO_CCW_BUS)
58 #define VIRTIO_CCW_BUS_CLASS(klass) \
59     OBJECT_CLASS_CHECK(VirtioCcwBusClass, klass, TYPE_VIRTIO_CCW_BUS)
60 
61 typedef struct VirtioCcwDevice VirtioCcwDevice;
62 
63 typedef struct VirtIOCCWDeviceClass {
64     DeviceClass parent_class;
65     int (*init)(VirtioCcwDevice *dev);
66     int (*exit)(VirtioCcwDevice *dev);
67 } VirtIOCCWDeviceClass;
68 
69 /* Change here if we want to support more feature bits. */
70 #define VIRTIO_CCW_FEATURE_SIZE 1
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 struct VirtioCcwDevice {
78     DeviceState parent_obj;
79     SubchDev *sch;
80     VirtIODevice *vdev;
81     char *bus_id;
82     uint32_t host_features[VIRTIO_CCW_FEATURE_SIZE];
83     VirtioBusState bus;
84     bool ioeventfd_started;
85     bool ioeventfd_disabled;
86     uint32_t flags;
87     /* Guest provided values: */
88     hwaddr indicators;
89     hwaddr indicators2;
90 };
91 
92 /* virtual css bus type */
93 typedef struct VirtualCssBus {
94     BusState parent_obj;
95 } VirtualCssBus;
96 
97 #define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus"
98 #define VIRTUAL_CSS_BUS(obj) \
99      OBJECT_CHECK(VirtualCssBus, (obj), TYPE_VIRTUAL_CSS_BUS)
100 
101 /* virtio-scsi-ccw */
102 
103 #define TYPE_VIRTIO_SCSI_CCW "virtio-scsi-ccw"
104 #define VIRTIO_SCSI_CCW(obj) \
105         OBJECT_CHECK(VirtIOSCSICcw, (obj), TYPE_VIRTIO_SCSI_CCW)
106 
107 typedef struct VirtIOSCSICcw {
108     VirtioCcwDevice parent_obj;
109     VirtIOSCSI vdev;
110 } VirtIOSCSICcw;
111 
112 #ifdef CONFIG_VHOST_SCSI
113 /* vhost-scsi-ccw */
114 
115 #define TYPE_VHOST_SCSI_CCW "vhost-scsi-ccw"
116 #define VHOST_SCSI_CCW(obj) \
117         OBJECT_CHECK(VHostSCSICcw, (obj), TYPE_VHOST_SCSI_CCW)
118 
119 typedef struct VHostSCSICcw {
120     VirtioCcwDevice parent_obj;
121     VHostSCSI vdev;
122 } VHostSCSICcw;
123 #endif
124 
125 /* virtio-blk-ccw */
126 
127 #define TYPE_VIRTIO_BLK_CCW "virtio-blk-ccw"
128 #define VIRTIO_BLK_CCW(obj) \
129         OBJECT_CHECK(VirtIOBlkCcw, (obj), TYPE_VIRTIO_BLK_CCW)
130 
131 typedef struct VirtIOBlkCcw {
132     VirtioCcwDevice parent_obj;
133     VirtIOBlock vdev;
134     VirtIOBlkConf blk;
135 } VirtIOBlkCcw;
136 
137 /* virtio-balloon-ccw */
138 
139 #define TYPE_VIRTIO_BALLOON_CCW "virtio-balloon-ccw"
140 #define VIRTIO_BALLOON_CCW(obj) \
141         OBJECT_CHECK(VirtIOBalloonCcw, (obj), TYPE_VIRTIO_BALLOON_CCW)
142 
143 typedef struct VirtIOBalloonCcw {
144     VirtioCcwDevice parent_obj;
145     VirtIOBalloon vdev;
146 } VirtIOBalloonCcw;
147 
148 /* virtio-serial-ccw */
149 
150 #define TYPE_VIRTIO_SERIAL_CCW "virtio-serial-ccw"
151 #define VIRTIO_SERIAL_CCW(obj) \
152         OBJECT_CHECK(VirtioSerialCcw, (obj), TYPE_VIRTIO_SERIAL_CCW)
153 
154 typedef struct VirtioSerialCcw {
155     VirtioCcwDevice parent_obj;
156     VirtIOSerial vdev;
157 } VirtioSerialCcw;
158 
159 /* virtio-net-ccw */
160 
161 #define TYPE_VIRTIO_NET_CCW "virtio-net-ccw"
162 #define VIRTIO_NET_CCW(obj) \
163         OBJECT_CHECK(VirtIONetCcw, (obj), TYPE_VIRTIO_NET_CCW)
164 
165 typedef struct VirtIONetCcw {
166     VirtioCcwDevice parent_obj;
167     VirtIONet vdev;
168 } VirtIONetCcw;
169 
170 /* virtio-rng-ccw */
171 
172 #define TYPE_VIRTIO_RNG_CCW "virtio-rng-ccw"
173 #define VIRTIO_RNG_CCW(obj) \
174         OBJECT_CHECK(VirtIORNGCcw, (obj), TYPE_VIRTIO_RNG_CCW)
175 
176 typedef struct VirtIORNGCcw {
177     VirtioCcwDevice parent_obj;
178     VirtIORNG vdev;
179 } VirtIORNGCcw;
180 
181 VirtualCssBus *virtual_css_bus_init(void);
182 void virtio_ccw_device_update_status(SubchDev *sch);
183 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch);
184 #endif
185