xref: /openbmc/qemu/hw/virtio/virtio-balloon-pci.c (revision e7bbc9b1)
1 /*
2  * Virtio balloon PCI Bindings
3  *
4  * Copyright IBM, Corp. 2007
5  * Copyright (c) 2009 CodeSourcery
6  *
7  * Authors:
8  *  Anthony Liguori   <aliguori@us.ibm.com>
9  *  Paul Brook        <paul@codesourcery.com>
10  *
11  * Contributions after 2012-01-13 are licensed under the terms of the
12  * GNU GPL, version 2 or (at your option) any later version.
13  */
14 
15 #include "qemu/osdep.h"
16 
17 #include "virtio-pci.h"
18 #include "hw/virtio/virtio-balloon.h"
19 #include "qapi/error.h"
20 
21 typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
22 
23 /*
24  * virtio-balloon-pci: This extends VirtioPCIProxy.
25  */
26 #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci-base"
27 #define VIRTIO_BALLOON_PCI(obj) \
28         OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
29 
30 struct VirtIOBalloonPCI {
31     VirtIOPCIProxy parent_obj;
32     VirtIOBalloon vdev;
33 };
34 static Property virtio_balloon_pci_properties[] = {
35     DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
36     DEFINE_PROP_END_OF_LIST(),
37 };
38 
39 static void virtio_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
40 {
41     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev);
42     DeviceState *vdev = DEVICE(&dev->vdev);
43 
44     if (vpci_dev->class_code != PCI_CLASS_OTHERS &&
45         vpci_dev->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */
46         vpci_dev->class_code = PCI_CLASS_OTHERS;
47     }
48 
49     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
50     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
51 }
52 
53 static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data)
54 {
55     DeviceClass *dc = DEVICE_CLASS(klass);
56     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
57     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
58     k->realize = virtio_balloon_pci_realize;
59     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
60     dc->props = virtio_balloon_pci_properties;
61     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
62     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
63     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
64     pcidev_k->class_id = PCI_CLASS_OTHERS;
65 }
66 
67 static void virtio_balloon_pci_instance_init(Object *obj)
68 {
69     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
70 
71     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
72                                 TYPE_VIRTIO_BALLOON);
73     object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev),
74                                   "guest-stats", &error_abort);
75     object_property_add_alias(obj, "guest-stats-polling-interval",
76                               OBJECT(&dev->vdev),
77                               "guest-stats-polling-interval", &error_abort);
78 }
79 
80 static const VirtioPCIDeviceTypeInfo virtio_balloon_pci_info = {
81     .base_name             = TYPE_VIRTIO_BALLOON_PCI,
82     .generic_name          = "virtio-balloon-pci",
83     .transitional_name     = "virtio-balloon-pci-transitional",
84     .non_transitional_name = "virtio-balloon-pci-non-transitional",
85     .instance_size = sizeof(VirtIOBalloonPCI),
86     .instance_init = virtio_balloon_pci_instance_init,
87     .class_init    = virtio_balloon_pci_class_init,
88 };
89 
90 static void virtio_balloon_pci_register(void)
91 {
92     virtio_pci_types_register(&virtio_balloon_pci_info);
93 }
94 
95 type_init(virtio_balloon_pci_register)
96