spapr_pci: Improve error message
[qemu/ar7.git] / tests / libqos / virtio-balloon.c
blob7e6e9e9de56660efe015d8105efbf75b62064fb6
1 /*
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"
20 #include "libqtest.h"
21 #include "libqos/qgraph.h"
22 #include "libqos/virtio-balloon.h"
24 /* virtio-balloon-device */
25 static void *qvirtio_balloon_get_driver(QVirtioBalloon *v_balloon,
26 const char *interface)
28 if (!g_strcmp0(interface, "virtio-balloon")) {
29 return v_balloon;
31 if (!g_strcmp0(interface, "virtio")) {
32 return v_balloon->vdev;
35 fprintf(stderr, "%s not present in virtio-balloon-device\n", interface);
36 g_assert_not_reached();
39 static void *qvirtio_balloon_device_get_driver(void *object,
40 const char *interface)
42 QVirtioBalloonDevice *v_balloon = object;
43 return qvirtio_balloon_get_driver(&v_balloon->balloon, interface);
46 static void *virtio_balloon_device_create(void *virtio_dev,
47 QGuestAllocator *t_alloc,
48 void *addr)
50 QVirtioBalloonDevice *virtio_bdevice = g_new0(QVirtioBalloonDevice, 1);
51 QVirtioBalloon *interface = &virtio_bdevice->balloon;
53 interface->vdev = virtio_dev;
55 virtio_bdevice->obj.get_driver = qvirtio_balloon_device_get_driver;
57 return &virtio_bdevice->obj;
60 /* virtio-balloon-pci */
61 static void *qvirtio_balloon_pci_get_driver(void *object,
62 const char *interface)
64 QVirtioBalloonPCI *v_balloon = object;
65 if (!g_strcmp0(interface, "pci-device")) {
66 return v_balloon->pci_vdev.pdev;
68 return qvirtio_balloon_get_driver(&v_balloon->balloon, interface);
71 static void *virtio_balloon_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
72 void *addr)
74 QVirtioBalloonPCI *virtio_bpci = g_new0(QVirtioBalloonPCI, 1);
75 QVirtioBalloon *interface = &virtio_bpci->balloon;
76 QOSGraphObject *obj = &virtio_bpci->pci_vdev.obj;
79 virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr);
80 interface->vdev = &virtio_bpci->pci_vdev.vdev;
82 obj->get_driver = qvirtio_balloon_pci_get_driver;
84 return obj;
87 static void virtio_balloon_register_nodes(void)
89 QPCIAddress addr = {
90 .devfn = QPCI_DEVFN(4, 0),
93 QOSGraphEdgeOptions opts = {
94 .extra_device_opts = "addr=04.0",
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");
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");
113 libqos_init(virtio_balloon_register_nodes);