2 * libqos driver framework
4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1 as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
19 #include "qemu/osdep.h"
21 #include "qemu/module.h"
22 #include "libqos/qgraph.h"
23 #include "libqos/virtio-rng.h"
25 /* virtio-rng-device */
26 static void *qvirtio_rng_get_driver(QVirtioRng
*v_rng
,
27 const char *interface
)
29 if (!g_strcmp0(interface
, "virtio-rng")) {
32 if (!g_strcmp0(interface
, "virtio")) {
36 fprintf(stderr
, "%s not present in virtio-rng-device\n", interface
);
37 g_assert_not_reached();
40 static void *qvirtio_rng_device_get_driver(void *object
,
41 const char *interface
)
43 QVirtioRngDevice
*v_rng
= object
;
44 return qvirtio_rng_get_driver(&v_rng
->rng
, interface
);
47 static void *virtio_rng_device_create(void *virtio_dev
,
48 QGuestAllocator
*t_alloc
,
51 QVirtioRngDevice
*virtio_rdevice
= g_new0(QVirtioRngDevice
, 1);
52 QVirtioRng
*interface
= &virtio_rdevice
->rng
;
54 interface
->vdev
= virtio_dev
;
56 virtio_rdevice
->obj
.get_driver
= qvirtio_rng_device_get_driver
;
58 return &virtio_rdevice
->obj
;
62 static void *qvirtio_rng_pci_get_driver(void *object
, const char *interface
)
64 QVirtioRngPCI
*v_rng
= object
;
65 if (!g_strcmp0(interface
, "pci-device")) {
66 return v_rng
->pci_vdev
.pdev
;
68 return qvirtio_rng_get_driver(&v_rng
->rng
, interface
);
71 static void *virtio_rng_pci_create(void *pci_bus
, QGuestAllocator
*t_alloc
,
74 QVirtioRngPCI
*virtio_rpci
= g_new0(QVirtioRngPCI
, 1);
75 QVirtioRng
*interface
= &virtio_rpci
->rng
;
76 QOSGraphObject
*obj
= &virtio_rpci
->pci_vdev
.obj
;
78 virtio_pci_init(&virtio_rpci
->pci_vdev
, pci_bus
, addr
);
79 interface
->vdev
= &virtio_rpci
->pci_vdev
.vdev
;
81 obj
->get_driver
= qvirtio_rng_pci_get_driver
;
86 static void virtio_rng_register_nodes(void)
89 .devfn
= QPCI_DEVFN(4, 0),
92 QOSGraphEdgeOptions opts
= {
93 .extra_device_opts
= "addr=04.0",
96 /* virtio-rng-device */
97 qos_node_create_driver("virtio-rng-device", virtio_rng_device_create
);
98 qos_node_consumes("virtio-rng-device", "virtio-bus", NULL
);
99 qos_node_produces("virtio-rng-device", "virtio");
100 qos_node_produces("virtio-rng-device", "virtio-rng");
103 add_qpci_address(&opts
, &addr
);
104 qos_node_create_driver("virtio-rng-pci", virtio_rng_pci_create
);
105 qos_node_consumes("virtio-rng-pci", "pci-bus", &opts
);
106 qos_node_produces("virtio-rng-pci", "pci-device");
107 qos_node_produces("virtio-rng-pci", "virtio");
108 qos_node_produces("virtio-rng-pci", "virtio-rng");
111 libqos_init(virtio_rng_register_nodes
);