1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "qemu/osdep.h"
20#include "libqtest.h"
21#include "libqos/qgraph.h"
22#include "libqos/virtio-rng.h"
23
24
25static void *qvirtio_rng_get_driver(QVirtioRng *v_rng,
26 const char *interface)
27{
28 if (!g_strcmp0(interface, "virtio-rng")) {
29 return v_rng;
30 }
31 if (!g_strcmp0(interface, "virtio")) {
32 return v_rng->vdev;
33 }
34
35 fprintf(stderr, "%s not present in virtio-rng-device\n", interface);
36 g_assert_not_reached();
37}
38
39static void *qvirtio_rng_device_get_driver(void *object,
40 const char *interface)
41{
42 QVirtioRngDevice *v_rng = object;
43 return qvirtio_rng_get_driver(&v_rng->rng, interface);
44}
45
46static void *virtio_rng_device_create(void *virtio_dev,
47 QGuestAllocator *t_alloc,
48 void *addr)
49{
50 QVirtioRngDevice *virtio_rdevice = g_new0(QVirtioRngDevice, 1);
51 QVirtioRng *interface = &virtio_rdevice->rng;
52
53 interface->vdev = virtio_dev;
54
55 virtio_rdevice->obj.get_driver = qvirtio_rng_device_get_driver;
56
57 return &virtio_rdevice->obj;
58}
59
60
61static void *qvirtio_rng_pci_get_driver(void *object, const char *interface)
62{
63 QVirtioRngPCI *v_rng = object;
64 if (!g_strcmp0(interface, "pci-device")) {
65 return v_rng->pci_vdev.pdev;
66 }
67 return qvirtio_rng_get_driver(&v_rng->rng, interface);
68}
69
70static void *virtio_rng_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
71 void *addr)
72{
73 QVirtioRngPCI *virtio_rpci = g_new0(QVirtioRngPCI, 1);
74 QVirtioRng *interface = &virtio_rpci->rng;
75 QOSGraphObject *obj = &virtio_rpci->pci_vdev.obj;
76
77 virtio_pci_init(&virtio_rpci->pci_vdev, pci_bus, addr);
78 interface->vdev = &virtio_rpci->pci_vdev.vdev;
79
80 obj->get_driver = qvirtio_rng_pci_get_driver;
81
82 return obj;
83}
84
85static void virtio_rng_register_nodes(void)
86{
87 QPCIAddress addr = {
88 .devfn = QPCI_DEVFN(4, 0),
89 };
90
91 QOSGraphEdgeOptions opts = {
92 .extra_device_opts = "addr=04.0",
93 };
94
95
96 qos_node_create_driver("virtio-rng-device", virtio_rng_device_create);
97 qos_node_consumes("virtio-rng-device", "virtio-bus", NULL);
98 qos_node_produces("virtio-rng-device", "virtio");
99 qos_node_produces("virtio-rng-device", "virtio-rng");
100
101
102 add_qpci_address(&opts, &addr);
103 qos_node_create_driver("virtio-rng-pci", virtio_rng_pci_create);
104 qos_node_consumes("virtio-rng-pci", "pci-bus", &opts);
105 qos_node_produces("virtio-rng-pci", "pci-device");
106 qos_node_produces("virtio-rng-pci", "virtio");
107 qos_node_produces("virtio-rng-pci", "virtio-rng");
108}
109
110libqos_init(virtio_rng_register_nodes);
111