| 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 "hw/virtio/virtio-pci.h" |
| 18 | #include "hw/core/qdev-properties.h" |
| 19 | #include "hw/virtio/virtio-balloon.h" |
| 20 | #include "qapi/error.h" |
| 21 | #include "qemu/module.h" |
| 22 | #include "qom/object.h" |
| 23 | |
| 24 | typedef struct VirtIOBalloonPCI VirtIOBalloonPCI; |
| 25 | |
| 26 | /* |
| 27 | * virtio-balloon-pci: This extends VirtioPCIProxy. |
| 28 | */ |
| 29 | #define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci-base" |
| 30 | DECLARE_INSTANCE_CHECKER(VirtIOBalloonPCI, VIRTIO_BALLOON_PCI, |
| 31 | TYPE_VIRTIO_BALLOON_PCI) |
| 32 | |
| 33 | struct VirtIOBalloonPCI { |
| 34 | VirtIOPCIProxy parent_obj; |
| 35 | VirtIOBalloon vdev; |
| 36 | }; |
| 37 | |
| 38 | static const Property virtio_balloon_properties[] = { |
| 39 | DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, |
| 40 | VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), |
| 41 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, |
| 42 | DEV_NVECTORS_UNSPECIFIED), |
| 43 | }; |
| 44 | |
| 45 | static void virtio_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
| 46 | { |
| 47 | VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev); |
| 48 | DeviceState *vdev = DEVICE(&dev->vdev); |
| 49 | |
| 50 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { |
| 51 | vpci_dev->nvectors = 2; |
| 52 | } |
| 53 | |
| 54 | vpci_dev->class_code = PCI_CLASS_OTHERS; |
| 55 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
| 56 | } |
| 57 | |
| 58 | static void virtio_balloon_pci_class_init(ObjectClass *klass, const void *data) |
| 59 | { |
| 60 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 61 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); |
| 62 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); |
| 63 | k->realize = virtio_balloon_pci_realize; |
| 64 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
| 65 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; |
| 66 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON; |
| 67 | pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; |
| 68 | pcidev_k->class_id = PCI_CLASS_OTHERS; |
| 69 | device_class_set_props(dc, virtio_balloon_properties); |
| 70 | } |
| 71 | |
| 72 | static void virtio_balloon_pci_instance_init(Object *obj) |
| 73 | { |
| 74 | VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj); |
| 75 | |
| 76 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
| 77 | TYPE_VIRTIO_BALLOON); |
| 78 | object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev), |
| 79 | "guest-stats"); |
| 80 | object_property_add_alias(obj, "guest-stats-polling-interval", |
| 81 | OBJECT(&dev->vdev), |
| 82 | "guest-stats-polling-interval"); |
| 83 | } |
| 84 | |
| 85 | static const VirtioPCIDeviceTypeInfo virtio_balloon_pci_info = { |
| 86 | .base_name = TYPE_VIRTIO_BALLOON_PCI, |
| 87 | .generic_name = "virtio-balloon-pci", |
| 88 | .transitional_name = "virtio-balloon-pci-transitional", |
| 89 | .non_transitional_name = "virtio-balloon-pci-non-transitional", |
| 90 | .instance_size = sizeof(VirtIOBalloonPCI), |
| 91 | .instance_init = virtio_balloon_pci_instance_init, |
| 92 | .class_init = virtio_balloon_pci_class_init, |
| 93 | }; |
| 94 | |
| 95 | static void virtio_balloon_pci_register(void) |
| 96 | { |
| 97 | virtio_pci_types_register(&virtio_balloon_pci_info); |
| 98 | } |
| 99 | |
| 100 | type_init(virtio_balloon_pci_register) |