xref: /openbmc/qemu/hw/virtio/virtio-rng-pci.c (revision 64552b6b)
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 #include "qemu/module.h"
18 
19 typedef struct VirtIORngPCI VirtIORngPCI;
20 
21 /*
22  * virtio-rng-pci: This extends VirtioPCIProxy.
23  */
24 #define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci-base"
25 #define VIRTIO_RNG_PCI(obj) \
26         OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
27 
28 struct VirtIORngPCI {
29     VirtIOPCIProxy parent_obj;
30     VirtIORNG vdev;
31 };
32 
33 static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
34 {
35     VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
36     DeviceState *vdev = DEVICE(&vrng->vdev);
37     Error *err = NULL;
38 
39     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
40     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
41     if (err) {
42         error_propagate(errp, err);
43         return;
44     }
45 
46     object_property_set_link(OBJECT(vrng),
47                              OBJECT(vrng->vdev.conf.rng), "rng",
48                              NULL);
49 }
50 
51 static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
52 {
53     DeviceClass *dc = DEVICE_CLASS(klass);
54     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
55     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
56 
57     k->realize = virtio_rng_pci_realize;
58     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
59 
60     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
61     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
62     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
63     pcidev_k->class_id = PCI_CLASS_OTHERS;
64 }
65 
66 static void virtio_rng_initfn(Object *obj)
67 {
68     VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj);
69 
70     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
71                                 TYPE_VIRTIO_RNG);
72 }
73 
74 static const VirtioPCIDeviceTypeInfo virtio_rng_pci_info = {
75     .base_name             = TYPE_VIRTIO_RNG_PCI,
76     .generic_name          = "virtio-rng-pci",
77     .transitional_name     = "virtio-rng-pci-transitional",
78     .non_transitional_name = "virtio-rng-pci-non-transitional",
79     .instance_size = sizeof(VirtIORngPCI),
80     .instance_init = virtio_rng_initfn,
81     .class_init    = virtio_rng_pci_class_init,
82 };
83 
84 static void virtio_rng_pci_register(void)
85 {
86     virtio_pci_types_register(&virtio_rng_pci_info);
87 }
88 
89 type_init(virtio_rng_pci_register)
90