]> Git Repo - qemu.git/blame - tests/libqos/virtio-balloon.c
Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2019-05-21' into...
[qemu.git] / tests / libqos / virtio-balloon.c
CommitLineData
29241067
EGE
1/*
2 * libqos driver framework
3 *
4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <[email protected]>
5 *
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.
9 *
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.
14 *
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/>
17 */
18
19#include "qemu/osdep.h"
20#include "libqtest.h"
21#include "libqos/qgraph.h"
22#include "libqos/virtio-balloon.h"
23
24/* virtio-balloon-device */
25static void *qvirtio_balloon_get_driver(QVirtioBalloon *v_balloon,
26 const char *interface)
27{
28 if (!g_strcmp0(interface, "virtio-balloon")) {
29 return v_balloon;
30 }
31 if (!g_strcmp0(interface, "virtio")) {
32 return v_balloon->vdev;
33 }
34
35 fprintf(stderr, "%s not present in virtio-balloon-device\n", interface);
36 g_assert_not_reached();
37}
38
39static void *qvirtio_balloon_device_get_driver(void *object,
40 const char *interface)
41{
42 QVirtioBalloonDevice *v_balloon = object;
43 return qvirtio_balloon_get_driver(&v_balloon->balloon, interface);
44}
45
46static void *virtio_balloon_device_create(void *virtio_dev,
47 QGuestAllocator *t_alloc,
48 void *addr)
49{
50 QVirtioBalloonDevice *virtio_bdevice = g_new0(QVirtioBalloonDevice, 1);
51 QVirtioBalloon *interface = &virtio_bdevice->balloon;
52
53 interface->vdev = virtio_dev;
54
55 virtio_bdevice->obj.get_driver = qvirtio_balloon_device_get_driver;
56
57 return &virtio_bdevice->obj;
58}
59
60/* virtio-balloon-pci */
61static void *qvirtio_balloon_pci_get_driver(void *object,
62 const char *interface)
63{
64 QVirtioBalloonPCI *v_balloon = object;
65 if (!g_strcmp0(interface, "pci-device")) {
66 return v_balloon->pci_vdev.pdev;
67 }
68 return qvirtio_balloon_get_driver(&v_balloon->balloon, interface);
69}
70
71static void *virtio_balloon_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
72 void *addr)
73{
74 QVirtioBalloonPCI *virtio_bpci = g_new0(QVirtioBalloonPCI, 1);
75 QVirtioBalloon *interface = &virtio_bpci->balloon;
76 QOSGraphObject *obj = &virtio_bpci->pci_vdev.obj;
77
78
79 virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr);
80 interface->vdev = &virtio_bpci->pci_vdev.vdev;
81
82 obj->get_driver = qvirtio_balloon_pci_get_driver;
83
84 return obj;
85}
86
87static void virtio_balloon_register_nodes(void)
88{
89 QPCIAddress addr = {
90 .devfn = QPCI_DEVFN(4, 0),
91 };
92
93 QOSGraphEdgeOptions opts = {
94 .extra_device_opts = "addr=04.0",
95 };
96
97 /* virtio-balloon-device */
98 qos_node_create_driver("virtio-balloon-device",
99 virtio_balloon_device_create);
100 qos_node_consumes("virtio-balloon-device", "virtio-bus", NULL);
101 qos_node_produces("virtio-balloon-device", "virtio");
102 qos_node_produces("virtio-balloon-device", "virtio-balloon");
103
104 /* virtio-balloon-pci */
105 add_qpci_address(&opts, &addr);
106 qos_node_create_driver("virtio-balloon-pci", virtio_balloon_pci_create);
107 qos_node_consumes("virtio-balloon-pci", "pci-bus", &opts);
108 qos_node_produces("virtio-balloon-pci", "pci-device");
109 qos_node_produces("virtio-balloon-pci", "virtio");
110 qos_node_produces("virtio-balloon-pci", "virtio-balloon");
111}
112
113libqos_init(virtio_balloon_register_nodes);
This page took 0.050133 seconds and 4 git commands to generate.