Statistics
| Branch: | Revision:

root / hw / s390-virtio-bus.c @ cc9577cf

History | View | Annotate | Download (10.6 kB)

1 f3304eea Alexander Graf
/*
2 f3304eea Alexander Graf
 * QEMU S390 virtio target
3 f3304eea Alexander Graf
 *
4 f3304eea Alexander Graf
 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
5 f3304eea Alexander Graf
 *
6 f3304eea Alexander Graf
 * This library is free software; you can redistribute it and/or
7 f3304eea Alexander Graf
 * modify it under the terms of the GNU Lesser General Public
8 f3304eea Alexander Graf
 * License as published by the Free Software Foundation; either
9 f3304eea Alexander Graf
 * version 2 of the License, or (at your option) any later version.
10 f3304eea Alexander Graf
 *
11 f3304eea Alexander Graf
 * This library is distributed in the hope that it will be useful,
12 f3304eea Alexander Graf
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 f3304eea Alexander Graf
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 f3304eea Alexander Graf
 * Lesser General Public License for more details.
15 f3304eea Alexander Graf
 *
16 f3304eea Alexander Graf
 * You should have received a copy of the GNU Lesser General Public
17 f3304eea Alexander Graf
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 f3304eea Alexander Graf
 */
19 f3304eea Alexander Graf
20 f3304eea Alexander Graf
#include "hw.h"
21 f3304eea Alexander Graf
#include "block.h"
22 f3304eea Alexander Graf
#include "sysemu.h"
23 f3304eea Alexander Graf
#include "net.h"
24 f3304eea Alexander Graf
#include "boards.h"
25 f3304eea Alexander Graf
#include "monitor.h"
26 f3304eea Alexander Graf
#include "loader.h"
27 f3304eea Alexander Graf
#include "elf.h"
28 f3304eea Alexander Graf
#include "hw/virtio.h"
29 98b19252 Amit Shah
#include "hw/virtio-serial.h"
30 f3304eea Alexander Graf
#include "hw/sysbus.h"
31 f3304eea Alexander Graf
#include "kvm.h"
32 f3304eea Alexander Graf
33 f3304eea Alexander Graf
#include "hw/s390-virtio-bus.h"
34 f3304eea Alexander Graf
35 f3304eea Alexander Graf
/* #define DEBUG_S390 */
36 f3304eea Alexander Graf
37 f3304eea Alexander Graf
#ifdef DEBUG_S390
38 f3304eea Alexander Graf
#define dprintf(fmt, ...) \
39 f3304eea Alexander Graf
    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
40 f3304eea Alexander Graf
#else
41 f3304eea Alexander Graf
#define dprintf(fmt, ...) \
42 f3304eea Alexander Graf
    do { } while (0)
43 f3304eea Alexander Graf
#endif
44 f3304eea Alexander Graf
45 f3304eea Alexander Graf
struct BusInfo s390_virtio_bus_info = {
46 f3304eea Alexander Graf
    .name       = "s390-virtio",
47 f3304eea Alexander Graf
    .size       = sizeof(VirtIOS390Bus),
48 f3304eea Alexander Graf
};
49 f3304eea Alexander Graf
50 f3304eea Alexander Graf
typedef struct {
51 f3304eea Alexander Graf
    DeviceInfo qdev;
52 f3304eea Alexander Graf
    int (*init)(VirtIOS390Device *dev);
53 f3304eea Alexander Graf
} VirtIOS390DeviceInfo;
54 f3304eea Alexander Graf
55 f3304eea Alexander Graf
56 f3304eea Alexander Graf
static const VirtIOBindings virtio_s390_bindings;
57 f3304eea Alexander Graf
58 f3304eea Alexander Graf
static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
59 f3304eea Alexander Graf
60 f3304eea Alexander Graf
VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
61 f3304eea Alexander Graf
{
62 f3304eea Alexander Graf
    VirtIOS390Bus *bus;
63 f3304eea Alexander Graf
    BusState *_bus;
64 f3304eea Alexander Graf
    DeviceState *dev;
65 f3304eea Alexander Graf
66 f3304eea Alexander Graf
    /* Create bridge device */
67 f3304eea Alexander Graf
    dev = qdev_create(NULL, "s390-virtio-bridge");
68 f3304eea Alexander Graf
    qdev_init_nofail(dev);
69 f3304eea Alexander Graf
70 f3304eea Alexander Graf
    /* Create bus on bridge device */
71 f3304eea Alexander Graf
72 f3304eea Alexander Graf
    _bus = qbus_create(&s390_virtio_bus_info, dev, "s390-virtio");
73 f3304eea Alexander Graf
    bus = DO_UPCAST(VirtIOS390Bus, bus, _bus);
74 f3304eea Alexander Graf
75 f3304eea Alexander Graf
    bus->dev_page = *ram_size;
76 f3304eea Alexander Graf
    bus->dev_offs = bus->dev_page;
77 f3304eea Alexander Graf
    bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
78 f3304eea Alexander Graf
79 f3304eea Alexander Graf
    /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
80 f3304eea Alexander Graf
    *ram_size += S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
81 f3304eea Alexander Graf
82 f3304eea Alexander Graf
    return bus;
83 f3304eea Alexander Graf
}
84 f3304eea Alexander Graf
85 f3304eea Alexander Graf
static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
86 f3304eea Alexander Graf
{
87 f3304eea Alexander Graf
    VirtIOS390Bus *bus;
88 f3304eea Alexander Graf
    int dev_len;
89 f3304eea Alexander Graf
90 f3304eea Alexander Graf
    bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
91 f3304eea Alexander Graf
    dev->vdev = vdev;
92 f3304eea Alexander Graf
    dev->dev_offs = bus->dev_offs;
93 f3304eea Alexander Graf
    dev->feat_len = sizeof(uint32_t); /* always keep 32 bits features */
94 f3304eea Alexander Graf
95 f3304eea Alexander Graf
    dev_len = VIRTIO_DEV_OFFS_CONFIG;
96 f3304eea Alexander Graf
    dev_len += s390_virtio_device_num_vq(dev) * VIRTIO_VQCONFIG_LEN;
97 f3304eea Alexander Graf
    dev_len += dev->feat_len * 2;
98 f3304eea Alexander Graf
    dev_len += vdev->config_len;
99 f3304eea Alexander Graf
100 f3304eea Alexander Graf
    bus->dev_offs += dev_len;
101 f3304eea Alexander Graf
102 f3304eea Alexander Graf
    virtio_bind_device(vdev, &virtio_s390_bindings, dev);
103 8172539d Michael S. Tsirkin
    dev->host_features = vdev->get_features(vdev, dev->host_features);
104 f3304eea Alexander Graf
    s390_virtio_device_sync(dev);
105 f3304eea Alexander Graf
106 f3304eea Alexander Graf
    return 0;
107 f3304eea Alexander Graf
}
108 f3304eea Alexander Graf
109 f3304eea Alexander Graf
static int s390_virtio_net_init(VirtIOS390Device *dev)
110 f3304eea Alexander Graf
{
111 f3304eea Alexander Graf
    VirtIODevice *vdev;
112 f3304eea Alexander Graf
113 f3304eea Alexander Graf
    vdev = virtio_net_init((DeviceState *)dev, &dev->nic);
114 f3304eea Alexander Graf
    if (!vdev) {
115 f3304eea Alexander Graf
        return -1;
116 f3304eea Alexander Graf
    }
117 f3304eea Alexander Graf
118 f3304eea Alexander Graf
    return s390_virtio_device_init(dev, vdev);
119 f3304eea Alexander Graf
}
120 f3304eea Alexander Graf
121 f3304eea Alexander Graf
static int s390_virtio_blk_init(VirtIOS390Device *dev)
122 f3304eea Alexander Graf
{
123 f3304eea Alexander Graf
    VirtIODevice *vdev;
124 f3304eea Alexander Graf
125 ad509737 Amit Shah
    vdev = virtio_blk_init((DeviceState *)dev, &dev->block);
126 f3304eea Alexander Graf
    if (!vdev) {
127 f3304eea Alexander Graf
        return -1;
128 f3304eea Alexander Graf
    }
129 f3304eea Alexander Graf
130 f3304eea Alexander Graf
    return s390_virtio_device_init(dev, vdev);
131 f3304eea Alexander Graf
}
132 f3304eea Alexander Graf
133 98b19252 Amit Shah
static int s390_virtio_serial_init(VirtIOS390Device *dev)
134 f3304eea Alexander Graf
{
135 f3304eea Alexander Graf
    VirtIOS390Bus *bus;
136 f3304eea Alexander Graf
    VirtIODevice *vdev;
137 f3304eea Alexander Graf
    int r;
138 f3304eea Alexander Graf
139 f3304eea Alexander Graf
    bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
140 f3304eea Alexander Graf
141 98b19252 Amit Shah
    vdev = virtio_serial_init((DeviceState *)dev, dev->max_virtserial_ports);
142 f3304eea Alexander Graf
    if (!vdev) {
143 f3304eea Alexander Graf
        return -1;
144 f3304eea Alexander Graf
    }
145 f3304eea Alexander Graf
146 f3304eea Alexander Graf
    r = s390_virtio_device_init(dev, vdev);
147 f3304eea Alexander Graf
    if (!r) {
148 f3304eea Alexander Graf
        bus->console = dev;
149 f3304eea Alexander Graf
    }
150 f3304eea Alexander Graf
151 f3304eea Alexander Graf
    return r;
152 f3304eea Alexander Graf
}
153 f3304eea Alexander Graf
154 f3304eea Alexander Graf
static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
155 f3304eea Alexander Graf
{
156 f3304eea Alexander Graf
    ram_addr_t token_off;
157 f3304eea Alexander Graf
158 f3304eea Alexander Graf
    token_off = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
159 f3304eea Alexander Graf
                (vq * VIRTIO_VQCONFIG_LEN) +
160 f3304eea Alexander Graf
                VIRTIO_VQCONFIG_OFFS_TOKEN;
161 f3304eea Alexander Graf
162 f3304eea Alexander Graf
    return ldq_phys(token_off);
163 f3304eea Alexander Graf
}
164 f3304eea Alexander Graf
165 f3304eea Alexander Graf
static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev)
166 f3304eea Alexander Graf
{
167 f3304eea Alexander Graf
    VirtIODevice *vdev = dev->vdev;
168 f3304eea Alexander Graf
    int num_vq;
169 f3304eea Alexander Graf
170 f3304eea Alexander Graf
    for (num_vq = 0; num_vq < VIRTIO_PCI_QUEUE_MAX; num_vq++) {
171 f3304eea Alexander Graf
        if (!virtio_queue_get_num(vdev, num_vq)) {
172 f3304eea Alexander Graf
            break;
173 f3304eea Alexander Graf
        }
174 f3304eea Alexander Graf
    }
175 f3304eea Alexander Graf
176 f3304eea Alexander Graf
    return num_vq;
177 f3304eea Alexander Graf
}
178 f3304eea Alexander Graf
179 f3304eea Alexander Graf
static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
180 f3304eea Alexander Graf
{
181 f3304eea Alexander Graf
    ram_addr_t r = bus->next_ring;
182 f3304eea Alexander Graf
183 f3304eea Alexander Graf
    bus->next_ring += VIRTIO_RING_LEN;
184 f3304eea Alexander Graf
    return r;
185 f3304eea Alexander Graf
}
186 f3304eea Alexander Graf
187 baf0b55a Alexander Graf
void s390_virtio_device_sync(VirtIOS390Device *dev)
188 f3304eea Alexander Graf
{
189 f3304eea Alexander Graf
    VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
190 f3304eea Alexander Graf
    ram_addr_t cur_offs;
191 f3304eea Alexander Graf
    uint8_t num_vq;
192 f3304eea Alexander Graf
    int i;
193 f3304eea Alexander Graf
194 f3304eea Alexander Graf
    virtio_reset(dev->vdev);
195 f3304eea Alexander Graf
196 f3304eea Alexander Graf
    /* Sync dev space */
197 f3304eea Alexander Graf
    stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_TYPE, dev->vdev->device_id);
198 f3304eea Alexander Graf
199 f3304eea Alexander Graf
    stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, s390_virtio_device_num_vq(dev));
200 f3304eea Alexander Graf
    stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN, dev->feat_len);
201 f3304eea Alexander Graf
202 f3304eea Alexander Graf
    stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN, dev->vdev->config_len);
203 f3304eea Alexander Graf
204 f3304eea Alexander Graf
    num_vq = s390_virtio_device_num_vq(dev);
205 f3304eea Alexander Graf
    stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq);
206 f3304eea Alexander Graf
207 f3304eea Alexander Graf
    /* Sync virtqueues */
208 f3304eea Alexander Graf
    for (i = 0; i < num_vq; i++) {
209 f3304eea Alexander Graf
        ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
210 f3304eea Alexander Graf
                        (i * VIRTIO_VQCONFIG_LEN);
211 f3304eea Alexander Graf
        ram_addr_t vring;
212 f3304eea Alexander Graf
213 f3304eea Alexander Graf
        vring = s390_virtio_next_ring(bus);
214 f3304eea Alexander Graf
        virtio_queue_set_addr(dev->vdev, i, vring);
215 f3304eea Alexander Graf
        virtio_queue_set_vector(dev->vdev, i, i);
216 f3304eea Alexander Graf
        stq_phys(vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);
217 f3304eea Alexander Graf
        stw_phys(vq + VIRTIO_VQCONFIG_OFFS_NUM, virtio_queue_get_num(dev->vdev, i));
218 f3304eea Alexander Graf
    }
219 f3304eea Alexander Graf
220 f3304eea Alexander Graf
    cur_offs = dev->dev_offs;
221 f3304eea Alexander Graf
    cur_offs += VIRTIO_DEV_OFFS_CONFIG;
222 f3304eea Alexander Graf
    cur_offs += num_vq * VIRTIO_VQCONFIG_LEN;
223 f3304eea Alexander Graf
224 f3304eea Alexander Graf
    /* Sync feature bitmap */
225 8172539d Michael S. Tsirkin
    stl_phys(cur_offs, dev->host_features);
226 f3304eea Alexander Graf
227 f3304eea Alexander Graf
    dev->feat_offs = cur_offs + dev->feat_len;
228 f3304eea Alexander Graf
    cur_offs += dev->feat_len * 2;
229 f3304eea Alexander Graf
230 f3304eea Alexander Graf
    /* Sync config space */
231 f3304eea Alexander Graf
    if (dev->vdev->get_config) {
232 f3304eea Alexander Graf
        dev->vdev->get_config(dev->vdev, dev->vdev->config);
233 f3304eea Alexander Graf
    }
234 f3304eea Alexander Graf
235 f3304eea Alexander Graf
    cpu_physical_memory_rw(cur_offs, dev->vdev->config, dev->vdev->config_len, 1);
236 f3304eea Alexander Graf
    cur_offs += dev->vdev->config_len;
237 f3304eea Alexander Graf
}
238 f3304eea Alexander Graf
239 f3304eea Alexander Graf
void s390_virtio_device_update_status(VirtIOS390Device *dev)
240 f3304eea Alexander Graf
{
241 f3304eea Alexander Graf
    VirtIODevice *vdev = dev->vdev;
242 f3304eea Alexander Graf
    uint32_t features;
243 f3304eea Alexander Graf
244 3e607cb5 Michael S. Tsirkin
    virtio_set_status(vdev, ldub_phys(dev->dev_offs + VIRTIO_DEV_OFFS_STATUS));
245 f3304eea Alexander Graf
246 f3304eea Alexander Graf
    /* Update guest supported feature bitmap */
247 f3304eea Alexander Graf
248 f3304eea Alexander Graf
    features = ldl_phys(dev->feat_offs);
249 f3304eea Alexander Graf
    if (vdev->set_features) {
250 f3304eea Alexander Graf
        vdev->set_features(vdev, features);
251 f3304eea Alexander Graf
    }
252 704a76fc Michael S. Tsirkin
    vdev->guest_features = features;
253 f3304eea Alexander Graf
}
254 f3304eea Alexander Graf
255 f3304eea Alexander Graf
VirtIOS390Device *s390_virtio_bus_console(VirtIOS390Bus *bus)
256 f3304eea Alexander Graf
{
257 f3304eea Alexander Graf
    return bus->console;
258 f3304eea Alexander Graf
}
259 f3304eea Alexander Graf
260 f3304eea Alexander Graf
/* Find a device by vring address */
261 f3304eea Alexander Graf
VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
262 f3304eea Alexander Graf
                                             ram_addr_t mem,
263 f3304eea Alexander Graf
                                             int *vq_num)
264 f3304eea Alexander Graf
{
265 f3304eea Alexander Graf
    VirtIOS390Device *_dev;
266 f3304eea Alexander Graf
    DeviceState *dev;
267 f3304eea Alexander Graf
    int i;
268 f3304eea Alexander Graf
269 f3304eea Alexander Graf
    QLIST_FOREACH(dev, &bus->bus.children, sibling) {
270 f3304eea Alexander Graf
        _dev = (VirtIOS390Device *)dev;
271 f3304eea Alexander Graf
        for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
272 f3304eea Alexander Graf
            if (!virtio_queue_get_addr(_dev->vdev, i))
273 f3304eea Alexander Graf
                break;
274 f3304eea Alexander Graf
            if (virtio_queue_get_addr(_dev->vdev, i) == mem) {
275 f3304eea Alexander Graf
                if (vq_num) {
276 f3304eea Alexander Graf
                    *vq_num = i;
277 f3304eea Alexander Graf
                }
278 f3304eea Alexander Graf
                return _dev;
279 f3304eea Alexander Graf
            }
280 f3304eea Alexander Graf
        }
281 f3304eea Alexander Graf
    }
282 f3304eea Alexander Graf
283 f3304eea Alexander Graf
    return NULL;
284 f3304eea Alexander Graf
}
285 f3304eea Alexander Graf
286 f3304eea Alexander Graf
/* Find a device by device descriptor location */
287 f3304eea Alexander Graf
VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem)
288 f3304eea Alexander Graf
{
289 f3304eea Alexander Graf
    VirtIOS390Device *_dev;
290 f3304eea Alexander Graf
    DeviceState *dev;
291 f3304eea Alexander Graf
292 f3304eea Alexander Graf
    QLIST_FOREACH(dev, &bus->bus.children, sibling) {
293 f3304eea Alexander Graf
        _dev = (VirtIOS390Device *)dev;
294 f3304eea Alexander Graf
        if (_dev->dev_offs == mem) {
295 f3304eea Alexander Graf
            return _dev;
296 f3304eea Alexander Graf
        }
297 f3304eea Alexander Graf
    }
298 f3304eea Alexander Graf
299 f3304eea Alexander Graf
    return NULL;
300 f3304eea Alexander Graf
}
301 f3304eea Alexander Graf
302 f3304eea Alexander Graf
static void virtio_s390_notify(void *opaque, uint16_t vector)
303 f3304eea Alexander Graf
{
304 f3304eea Alexander Graf
    VirtIOS390Device *dev = (VirtIOS390Device*)opaque;
305 f3304eea Alexander Graf
    uint64_t token = s390_virtio_device_vq_token(dev, vector);
306 f3304eea Alexander Graf
307 f3304eea Alexander Graf
    /* XXX kvm dependency! */
308 86f3dba6 Alexander Graf
    kvm_s390_virtio_irq(s390_cpu_addr2state(0), 0, token);
309 f3304eea Alexander Graf
}
310 f3304eea Alexander Graf
311 8172539d Michael S. Tsirkin
static unsigned virtio_s390_get_features(void *opaque)
312 8172539d Michael S. Tsirkin
{
313 8172539d Michael S. Tsirkin
    VirtIOS390Device *dev = (VirtIOS390Device*)opaque;
314 8172539d Michael S. Tsirkin
    return dev->host_features;
315 8172539d Michael S. Tsirkin
}
316 8172539d Michael S. Tsirkin
317 f3304eea Alexander Graf
/**************** S390 Virtio Bus Device Descriptions *******************/
318 f3304eea Alexander Graf
319 f3304eea Alexander Graf
static const VirtIOBindings virtio_s390_bindings = {
320 f3304eea Alexander Graf
    .notify = virtio_s390_notify,
321 8172539d Michael S. Tsirkin
    .get_features = virtio_s390_get_features,
322 f3304eea Alexander Graf
};
323 f3304eea Alexander Graf
324 f3304eea Alexander Graf
static VirtIOS390DeviceInfo s390_virtio_net = {
325 f3304eea Alexander Graf
    .init = s390_virtio_net_init,
326 f3304eea Alexander Graf
    .qdev.name = "virtio-net-s390",
327 f3304eea Alexander Graf
    .qdev.size = sizeof(VirtIOS390Device),
328 f3304eea Alexander Graf
    .qdev.props = (Property[]) {
329 f3304eea Alexander Graf
        DEFINE_NIC_PROPERTIES(VirtIOS390Device, nic),
330 f3304eea Alexander Graf
        DEFINE_PROP_END_OF_LIST(),
331 f3304eea Alexander Graf
    },
332 f3304eea Alexander Graf
};
333 f3304eea Alexander Graf
334 f3304eea Alexander Graf
static VirtIOS390DeviceInfo s390_virtio_blk = {
335 f3304eea Alexander Graf
    .init = s390_virtio_blk_init,
336 f3304eea Alexander Graf
    .qdev.name = "virtio-blk-s390",
337 f3304eea Alexander Graf
    .qdev.size = sizeof(VirtIOS390Device),
338 f3304eea Alexander Graf
    .qdev.props = (Property[]) {
339 428c149b Christoph Hellwig
        DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
340 f3304eea Alexander Graf
        DEFINE_PROP_END_OF_LIST(),
341 f3304eea Alexander Graf
    },
342 f3304eea Alexander Graf
};
343 f3304eea Alexander Graf
344 98b19252 Amit Shah
static VirtIOS390DeviceInfo s390_virtio_serial = {
345 98b19252 Amit Shah
    .init = s390_virtio_serial_init,
346 98b19252 Amit Shah
    .qdev.name = "virtio-serial-s390",
347 98b19252 Amit Shah
    .qdev.alias = "virtio-serial",
348 f3304eea Alexander Graf
    .qdev.size = sizeof(VirtIOS390Device),
349 f3304eea Alexander Graf
    .qdev.props = (Property[]) {
350 98b19252 Amit Shah
        DEFINE_PROP_UINT32("max_ports", VirtIOS390Device, max_virtserial_ports,
351 98b19252 Amit Shah
                           31),
352 f3304eea Alexander Graf
        DEFINE_PROP_END_OF_LIST(),
353 f3304eea Alexander Graf
    },
354 f3304eea Alexander Graf
};
355 f3304eea Alexander Graf
356 f3304eea Alexander Graf
static int s390_virtio_busdev_init(DeviceState *dev, DeviceInfo *info)
357 f3304eea Alexander Graf
{
358 f3304eea Alexander Graf
    VirtIOS390DeviceInfo *_info = (VirtIOS390DeviceInfo *)info;
359 f3304eea Alexander Graf
    VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
360 f3304eea Alexander Graf
361 f3304eea Alexander Graf
    return _info->init(_dev);
362 f3304eea Alexander Graf
}
363 f3304eea Alexander Graf
364 f3304eea Alexander Graf
static void s390_virtio_bus_register_withprop(VirtIOS390DeviceInfo *info)
365 f3304eea Alexander Graf
{
366 f3304eea Alexander Graf
    info->qdev.init = s390_virtio_busdev_init;
367 f3304eea Alexander Graf
    info->qdev.bus_info = &s390_virtio_bus_info;
368 f3304eea Alexander Graf
369 f3304eea Alexander Graf
    assert(info->qdev.size >= sizeof(VirtIOS390Device));
370 f3304eea Alexander Graf
    qdev_register(&info->qdev);
371 f3304eea Alexander Graf
}
372 f3304eea Alexander Graf
373 f3304eea Alexander Graf
static void s390_virtio_register(void)
374 f3304eea Alexander Graf
{
375 98b19252 Amit Shah
    s390_virtio_bus_register_withprop(&s390_virtio_serial);
376 f3304eea Alexander Graf
    s390_virtio_bus_register_withprop(&s390_virtio_blk);
377 f3304eea Alexander Graf
    s390_virtio_bus_register_withprop(&s390_virtio_net);
378 f3304eea Alexander Graf
}
379 f3304eea Alexander Graf
device_init(s390_virtio_register);
380 f3304eea Alexander Graf
381 f3304eea Alexander Graf
382 f3304eea Alexander Graf
/***************** S390 Virtio Bus Bridge Device *******************/
383 f3304eea Alexander Graf
/* Only required to have the virtio bus as child in the system bus */
384 f3304eea Alexander Graf
385 f3304eea Alexander Graf
static int s390_virtio_bridge_init(SysBusDevice *dev)
386 f3304eea Alexander Graf
{
387 f3304eea Alexander Graf
    /* nothing */
388 f3304eea Alexander Graf
    return 0;
389 f3304eea Alexander Graf
}
390 f3304eea Alexander Graf
391 f3304eea Alexander Graf
static SysBusDeviceInfo s390_virtio_bridge_info = {
392 f3304eea Alexander Graf
    .init = s390_virtio_bridge_init,
393 f3304eea Alexander Graf
    .qdev.name  = "s390-virtio-bridge",
394 f3304eea Alexander Graf
    .qdev.size  = sizeof(SysBusDevice),
395 f3304eea Alexander Graf
    .qdev.no_user = 1,
396 f3304eea Alexander Graf
};
397 f3304eea Alexander Graf
398 f3304eea Alexander Graf
static void s390_virtio_register_devices(void)
399 f3304eea Alexander Graf
{
400 f3304eea Alexander Graf
    sysbus_register_withprop(&s390_virtio_bridge_info);
401 f3304eea Alexander Graf
}
402 f3304eea Alexander Graf
403 f3304eea Alexander Graf
device_init(s390_virtio_register_devices)