xref: /openbmc/qemu/hw/s390x/virtio-ccw-serial.c (revision ae2b5d8381a73b27f35f19c988d45c78bb4d5768)
1901f5f16SThomas Huth /*
2901f5f16SThomas Huth  * virtio ccw serial implementation
3901f5f16SThomas Huth  *
4901f5f16SThomas Huth  * Copyright 2012, 2015 IBM Corp.
5901f5f16SThomas Huth  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6901f5f16SThomas Huth  *
7901f5f16SThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8901f5f16SThomas Huth  * your option) any later version. See the COPYING file in the top-level
9901f5f16SThomas Huth  * directory.
10901f5f16SThomas Huth  */
11901f5f16SThomas Huth 
12901f5f16SThomas Huth #include "qemu/osdep.h"
13901f5f16SThomas Huth #include "hw/virtio/virtio.h"
140b8fa32fSMarkus Armbruster #include "qemu/module.h"
15a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
16901f5f16SThomas Huth #include "hw/virtio/virtio-serial.h"
17901f5f16SThomas Huth #include "virtio-ccw.h"
18*7da50d64SPaolo Bonzini 
19*7da50d64SPaolo Bonzini #define TYPE_VIRTIO_SERIAL_CCW "virtio-serial-ccw"
20*7da50d64SPaolo Bonzini OBJECT_DECLARE_SIMPLE_TYPE(VirtioSerialCcw, VIRTIO_SERIAL_CCW)
21*7da50d64SPaolo Bonzini 
22*7da50d64SPaolo Bonzini struct VirtioSerialCcw {
23*7da50d64SPaolo Bonzini     VirtioCcwDevice parent_obj;
24*7da50d64SPaolo Bonzini     VirtIOSerial vdev;
25*7da50d64SPaolo Bonzini };
26901f5f16SThomas Huth 
virtio_ccw_serial_realize(VirtioCcwDevice * ccw_dev,Error ** errp)27901f5f16SThomas Huth static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp)
28901f5f16SThomas Huth {
29901f5f16SThomas Huth     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
30901f5f16SThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
31901f5f16SThomas Huth     DeviceState *proxy = DEVICE(ccw_dev);
32901f5f16SThomas Huth     char *bus_name;
33901f5f16SThomas Huth 
34901f5f16SThomas Huth     /*
35901f5f16SThomas Huth      * For command line compatibility, this sets the virtio-serial-device bus
36901f5f16SThomas Huth      * name as before.
37901f5f16SThomas Huth      */
38901f5f16SThomas Huth     if (proxy->id) {
39901f5f16SThomas Huth         bus_name = g_strdup_printf("%s.0", proxy->id);
40901f5f16SThomas Huth         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
41901f5f16SThomas Huth         g_free(bus_name);
42901f5f16SThomas Huth     }
43901f5f16SThomas Huth 
4499ba777eSMarkus Armbruster     qdev_realize(vdev, BUS(&ccw_dev->bus), errp);
45901f5f16SThomas Huth }
46901f5f16SThomas Huth 
47901f5f16SThomas Huth 
virtio_ccw_serial_instance_init(Object * obj)48901f5f16SThomas Huth static void virtio_ccw_serial_instance_init(Object *obj)
49901f5f16SThomas Huth {
50901f5f16SThomas Huth     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
51901f5f16SThomas Huth 
52901f5f16SThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
53901f5f16SThomas Huth                                 TYPE_VIRTIO_SERIAL);
54901f5f16SThomas Huth }
55901f5f16SThomas Huth 
56901f5f16SThomas Huth static Property virtio_ccw_serial_properties[] = {
57901f5f16SThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
58901f5f16SThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
59901f5f16SThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
60901f5f16SThomas Huth                        VIRTIO_CCW_MAX_REV),
61901f5f16SThomas Huth     DEFINE_PROP_END_OF_LIST(),
62901f5f16SThomas Huth };
63901f5f16SThomas Huth 
virtio_ccw_serial_class_init(ObjectClass * klass,void * data)64901f5f16SThomas Huth static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
65901f5f16SThomas Huth {
66901f5f16SThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
67901f5f16SThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
68901f5f16SThomas Huth 
69901f5f16SThomas Huth     k->realize = virtio_ccw_serial_realize;
704f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_ccw_serial_properties);
71901f5f16SThomas Huth     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
72901f5f16SThomas Huth }
73901f5f16SThomas Huth 
74901f5f16SThomas Huth static const TypeInfo virtio_ccw_serial = {
75901f5f16SThomas Huth     .name          = TYPE_VIRTIO_SERIAL_CCW,
76901f5f16SThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
77901f5f16SThomas Huth     .instance_size = sizeof(VirtioSerialCcw),
78901f5f16SThomas Huth     .instance_init = virtio_ccw_serial_instance_init,
79901f5f16SThomas Huth     .class_init    = virtio_ccw_serial_class_init,
80901f5f16SThomas Huth };
81901f5f16SThomas Huth 
virtio_ccw_serial_register(void)82901f5f16SThomas Huth static void virtio_ccw_serial_register(void)
83901f5f16SThomas Huth {
84901f5f16SThomas Huth     type_register_static(&virtio_ccw_serial);
85901f5f16SThomas Huth }
86901f5f16SThomas Huth 
87901f5f16SThomas Huth type_init(virtio_ccw_serial_register)
88