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 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 "libqos/qgraph.h"
22 #include "libqos/virtio-rng.h"
24 /* virtio-rng-device */
25 static void *qvirtio_rng_get_driver(QVirtioRng
*v_rng
,
26 const char *interface
)
28 if (!g_strcmp0(interface
, "virtio-rng")) {
31 if (!g_strcmp0(interface
, "virtio")) {
35 fprintf(stderr
, "%s not present in virtio-rng-device\n", interface
);
36 g_assert_not_reached();
39 static void *qvirtio_rng_device_get_driver(void *object
,
40 const char *interface
)
42 QVirtioRngDevice
*v_rng
= object
;
43 return qvirtio_rng_get_driver(&v_rng
->rng
, interface
);
46 static void *virtio_rng_device_create(void *virtio_dev
,
47 QGuestAllocator
*t_alloc
,
50 QVirtioRngDevice
*virtio_rdevice
= g_new0(QVirtioRngDevice
, 1);
51 QVirtioRng
*interface
= &virtio_rdevice
->rng
;
53 interface
->vdev
= virtio_dev
;
55 virtio_rdevice
->obj
.get_driver
= qvirtio_rng_device_get_driver
;
57 return &virtio_rdevice
->obj
;
61 static void *qvirtio_rng_pci_get_driver(void *object
, const char *interface
)
63 QVirtioRngPCI
*v_rng
= object
;
64 if (!g_strcmp0(interface
, "pci-device")) {
65 return v_rng
->pci_vdev
.pdev
;
67 return qvirtio_rng_get_driver(&v_rng
->rng
, interface
);
70 static void *virtio_rng_pci_create(void *pci_bus
, QGuestAllocator
*t_alloc
,
73 QVirtioRngPCI
*virtio_rpci
= g_new0(QVirtioRngPCI
, 1);
74 QVirtioRng
*interface
= &virtio_rpci
->rng
;
75 QOSGraphObject
*obj
= &virtio_rpci
->pci_vdev
.obj
;
77 virtio_pci_init(&virtio_rpci
->pci_vdev
, pci_bus
, addr
);
78 interface
->vdev
= &virtio_rpci
->pci_vdev
.vdev
;
80 obj
->get_driver
= qvirtio_rng_pci_get_driver
;
85 static void virtio_rng_register_nodes(void)
88 .devfn
= QPCI_DEVFN(4, 0),
91 QOSGraphEdgeOptions opts
= {
92 .extra_device_opts
= "addr=04.0",
95 /* virtio-rng-device */
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");
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");
110 libqos_init(virtio_rng_register_nodes
);