xref: /openbmc/qemu/hw/s390x/virtio-ccw-balloon.c (revision d2623129)
1dcfd8286SThomas Huth /*
2dcfd8286SThomas Huth  * virtio ccw balloon implementation
3dcfd8286SThomas Huth  *
4dcfd8286SThomas Huth  * Copyright 2012, 2015 IBM Corp.
5dcfd8286SThomas Huth  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6dcfd8286SThomas Huth  *
7dcfd8286SThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8dcfd8286SThomas Huth  * your option) any later version. See the COPYING file in the top-level
9dcfd8286SThomas Huth  * directory.
10dcfd8286SThomas Huth  */
11dcfd8286SThomas Huth 
12dcfd8286SThomas Huth #include "qemu/osdep.h"
13a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
14dcfd8286SThomas Huth #include "hw/virtio/virtio.h"
15dcfd8286SThomas Huth #include "qapi/error.h"
160b8fa32fSMarkus Armbruster #include "qemu/module.h"
17dcfd8286SThomas Huth #include "virtio-ccw.h"
18dcfd8286SThomas Huth 
19dcfd8286SThomas Huth static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp)
20dcfd8286SThomas Huth {
21dcfd8286SThomas Huth     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
22dcfd8286SThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
23dcfd8286SThomas Huth 
24dcfd8286SThomas Huth     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
25dcfd8286SThomas Huth     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
26dcfd8286SThomas Huth }
27dcfd8286SThomas Huth 
28dcfd8286SThomas Huth static void virtio_ccw_balloon_instance_init(Object *obj)
29dcfd8286SThomas Huth {
30dcfd8286SThomas Huth     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
31dcfd8286SThomas Huth 
32dcfd8286SThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
33dcfd8286SThomas Huth                                 TYPE_VIRTIO_BALLOON);
34dcfd8286SThomas Huth     object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev),
35*d2623129SMarkus Armbruster                               "guest-stats");
36dcfd8286SThomas Huth     object_property_add_alias(obj, "guest-stats-polling-interval",
37dcfd8286SThomas Huth                               OBJECT(&dev->vdev),
38*d2623129SMarkus Armbruster                               "guest-stats-polling-interval");
39dcfd8286SThomas Huth }
40dcfd8286SThomas Huth 
41dcfd8286SThomas Huth static Property virtio_ccw_balloon_properties[] = {
42dcfd8286SThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
43dcfd8286SThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
44dcfd8286SThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
45dcfd8286SThomas Huth                        VIRTIO_CCW_MAX_REV),
46dcfd8286SThomas Huth     DEFINE_PROP_END_OF_LIST(),
47dcfd8286SThomas Huth };
48dcfd8286SThomas Huth 
49dcfd8286SThomas Huth static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
50dcfd8286SThomas Huth {
51dcfd8286SThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
52dcfd8286SThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
53dcfd8286SThomas Huth 
54dcfd8286SThomas Huth     k->realize = virtio_ccw_balloon_realize;
554f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_ccw_balloon_properties);
56dcfd8286SThomas Huth     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
57dcfd8286SThomas Huth }
58dcfd8286SThomas Huth 
59dcfd8286SThomas Huth static const TypeInfo virtio_ccw_balloon = {
60dcfd8286SThomas Huth     .name          = TYPE_VIRTIO_BALLOON_CCW,
61dcfd8286SThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
62dcfd8286SThomas Huth     .instance_size = sizeof(VirtIOBalloonCcw),
63dcfd8286SThomas Huth     .instance_init = virtio_ccw_balloon_instance_init,
64dcfd8286SThomas Huth     .class_init    = virtio_ccw_balloon_class_init,
65dcfd8286SThomas Huth };
66dcfd8286SThomas Huth 
67dcfd8286SThomas Huth static void virtio_ccw_balloon_register(void)
68dcfd8286SThomas Huth {
69dcfd8286SThomas Huth     type_register_static(&virtio_ccw_balloon);
70dcfd8286SThomas Huth }
71dcfd8286SThomas Huth 
72dcfd8286SThomas Huth type_init(virtio_ccw_balloon_register)
73