xref: /openbmc/qemu/hw/s390x/virtio-ccw-balloon.c (revision 7da50d64)
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"
18*7da50d64SPaolo Bonzini #include "hw/virtio/virtio-balloon.h"
19*7da50d64SPaolo Bonzini 
20*7da50d64SPaolo Bonzini #define TYPE_VIRTIO_BALLOON_CCW "virtio-balloon-ccw"
21*7da50d64SPaolo Bonzini OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBalloonCcw, VIRTIO_BALLOON_CCW)
22*7da50d64SPaolo Bonzini 
23*7da50d64SPaolo Bonzini struct VirtIOBalloonCcw {
24*7da50d64SPaolo Bonzini     VirtioCcwDevice parent_obj;
25*7da50d64SPaolo Bonzini     VirtIOBalloon vdev;
26*7da50d64SPaolo Bonzini };
27dcfd8286SThomas Huth 
virtio_ccw_balloon_realize(VirtioCcwDevice * ccw_dev,Error ** errp)28dcfd8286SThomas Huth static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp)
29dcfd8286SThomas Huth {
30dcfd8286SThomas Huth     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
31dcfd8286SThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
32dcfd8286SThomas Huth 
3399ba777eSMarkus Armbruster     qdev_realize(vdev, BUS(&ccw_dev->bus), errp);
34dcfd8286SThomas Huth }
35dcfd8286SThomas Huth 
virtio_ccw_balloon_instance_init(Object * obj)36dcfd8286SThomas Huth static void virtio_ccw_balloon_instance_init(Object *obj)
37dcfd8286SThomas Huth {
38dcfd8286SThomas Huth     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
39dcfd8286SThomas Huth 
40dcfd8286SThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
41dcfd8286SThomas Huth                                 TYPE_VIRTIO_BALLOON);
42dcfd8286SThomas Huth     object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev),
43d2623129SMarkus Armbruster                               "guest-stats");
44dcfd8286SThomas Huth     object_property_add_alias(obj, "guest-stats-polling-interval",
45dcfd8286SThomas Huth                               OBJECT(&dev->vdev),
46d2623129SMarkus Armbruster                               "guest-stats-polling-interval");
47dcfd8286SThomas Huth }
48dcfd8286SThomas Huth 
49dcfd8286SThomas Huth static Property virtio_ccw_balloon_properties[] = {
50dcfd8286SThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
51dcfd8286SThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
52dcfd8286SThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
53dcfd8286SThomas Huth                        VIRTIO_CCW_MAX_REV),
54dcfd8286SThomas Huth     DEFINE_PROP_END_OF_LIST(),
55dcfd8286SThomas Huth };
56dcfd8286SThomas Huth 
virtio_ccw_balloon_class_init(ObjectClass * klass,void * data)57dcfd8286SThomas Huth static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
58dcfd8286SThomas Huth {
59dcfd8286SThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
60dcfd8286SThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
61dcfd8286SThomas Huth 
62dcfd8286SThomas Huth     k->realize = virtio_ccw_balloon_realize;
634f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_ccw_balloon_properties);
64dcfd8286SThomas Huth     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
65dcfd8286SThomas Huth }
66dcfd8286SThomas Huth 
67dcfd8286SThomas Huth static const TypeInfo virtio_ccw_balloon = {
68dcfd8286SThomas Huth     .name          = TYPE_VIRTIO_BALLOON_CCW,
69dcfd8286SThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
70dcfd8286SThomas Huth     .instance_size = sizeof(VirtIOBalloonCcw),
71dcfd8286SThomas Huth     .instance_init = virtio_ccw_balloon_instance_init,
72dcfd8286SThomas Huth     .class_init    = virtio_ccw_balloon_class_init,
73dcfd8286SThomas Huth };
74dcfd8286SThomas Huth 
virtio_ccw_balloon_register(void)75dcfd8286SThomas Huth static void virtio_ccw_balloon_register(void)
76dcfd8286SThomas Huth {
77dcfd8286SThomas Huth     type_register_static(&virtio_ccw_balloon);
78dcfd8286SThomas Huth }
79dcfd8286SThomas Huth 
80dcfd8286SThomas Huth type_init(virtio_ccw_balloon_register)
81