1 /* 2 * Virtio rng PCI Bindings 3 * 4 * Copyright 2012 Red Hat, Inc. 5 * Copyright 2012 Amit Shah <amit.shah@redhat.com> 6 * 7 * This work is licensed under the terms of the GNU GPL, version 2 or 8 * (at your option) any later version. See the COPYING file in the 9 * top-level directory. 10 */ 11 12 #include "qemu/osdep.h" 13 14 #include "virtio-pci.h" 15 #include "hw/virtio/virtio-rng.h" 16 #include "qapi/error.h" 17 18 typedef struct VirtIORngPCI VirtIORngPCI; 19 20 /* 21 * virtio-rng-pci: This extends VirtioPCIProxy. 22 */ 23 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci-base" 24 #define VIRTIO_RNG_PCI(obj) \ 25 OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI) 26 27 struct VirtIORngPCI { 28 VirtIOPCIProxy parent_obj; 29 VirtIORNG vdev; 30 }; 31 32 static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 33 { 34 VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev); 35 DeviceState *vdev = DEVICE(&vrng->vdev); 36 Error *err = NULL; 37 38 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); 39 object_property_set_bool(OBJECT(vdev), true, "realized", &err); 40 if (err) { 41 error_propagate(errp, err); 42 return; 43 } 44 45 object_property_set_link(OBJECT(vrng), 46 OBJECT(vrng->vdev.conf.rng), "rng", 47 NULL); 48 } 49 50 static void virtio_rng_pci_class_init(ObjectClass *klass, void *data) 51 { 52 DeviceClass *dc = DEVICE_CLASS(klass); 53 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 54 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 55 56 k->realize = virtio_rng_pci_realize; 57 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 58 59 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 60 pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG; 61 pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; 62 pcidev_k->class_id = PCI_CLASS_OTHERS; 63 } 64 65 static void virtio_rng_initfn(Object *obj) 66 { 67 VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj); 68 69 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 70 TYPE_VIRTIO_RNG); 71 } 72 73 static const VirtioPCIDeviceTypeInfo virtio_rng_pci_info = { 74 .base_name = TYPE_VIRTIO_RNG_PCI, 75 .generic_name = "virtio-rng-pci", 76 .transitional_name = "virtio-rng-pci-transitional", 77 .non_transitional_name = "virtio-rng-pci-non-transitional", 78 .instance_size = sizeof(VirtIORngPCI), 79 .instance_init = virtio_rng_initfn, 80 .class_init = virtio_rng_pci_class_init, 81 }; 82 83 static void virtio_rng_pci_register(void) 84 { 85 virtio_pci_types_register(&virtio_rng_pci_info); 86 } 87 88 type_init(virtio_rng_pci_register) 89