pci: designware: Update MSI mapping unconditionally
[qemu/ar7.git] / tests / libqos / virtio-serial.c
blob3e5b8b82c743235c92f1798e0ed56cddf882546c
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 "qemu/module.h"
22 #include "libqos/qgraph.h"
23 #include "libqos/virtio-serial.h"
25 static void *qvirtio_serial_get_driver(QVirtioSerial *v_serial,
26 const char *interface)
28 if (!g_strcmp0(interface, "virtio-serial")) {
29 return v_serial;
31 if (!g_strcmp0(interface, "virtio")) {
32 return v_serial->vdev;
35 fprintf(stderr, "%s not present in virtio-serial-device\n", interface);
36 g_assert_not_reached();
39 static void *qvirtio_serial_device_get_driver(void *object,
40 const char *interface)
42 QVirtioSerialDevice *v_serial = object;
43 return qvirtio_serial_get_driver(&v_serial->serial, interface);
46 static void *virtio_serial_device_create(void *virtio_dev,
47 QGuestAllocator *t_alloc,
48 void *addr)
50 QVirtioSerialDevice *virtio_device = g_new0(QVirtioSerialDevice, 1);
51 QVirtioSerial *interface = &virtio_device->serial;
53 interface->vdev = virtio_dev;
55 virtio_device->obj.get_driver = qvirtio_serial_device_get_driver;
57 return &virtio_device->obj;
60 /* virtio-serial-pci */
61 static void *qvirtio_serial_pci_get_driver(void *object, const char *interface)
63 QVirtioSerialPCI *v_serial = object;
64 if (!g_strcmp0(interface, "pci-device")) {
65 return v_serial->pci_vdev.pdev;
67 return qvirtio_serial_get_driver(&v_serial->serial, interface);
70 static void *virtio_serial_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
71 void *addr)
73 QVirtioSerialPCI *virtio_spci = g_new0(QVirtioSerialPCI, 1);
74 QVirtioSerial *interface = &virtio_spci->serial;
75 QOSGraphObject *obj = &virtio_spci->pci_vdev.obj;
77 virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr);
78 interface->vdev = &virtio_spci->pci_vdev.vdev;
80 obj->get_driver = qvirtio_serial_pci_get_driver;
82 return obj;
85 static void virtio_serial_register_nodes(void)
87 QPCIAddress addr = {
88 .devfn = QPCI_DEVFN(4, 0),
91 QOSGraphEdgeOptions edge_opts = { };
93 /* virtio-serial-device */
94 edge_opts.extra_device_opts = "id=vser0";
95 qos_node_create_driver("virtio-serial-device",
96 virtio_serial_device_create);
97 qos_node_consumes("virtio-serial-device", "virtio-bus", &edge_opts);
98 qos_node_produces("virtio-serial-device", "virtio");
99 qos_node_produces("virtio-serial-device", "virtio-serial");
101 /* virtio-serial-pci */
102 edge_opts.extra_device_opts = "id=vser0,addr=04.0";
103 add_qpci_address(&edge_opts, &addr);
104 qos_node_create_driver("virtio-serial-pci", virtio_serial_pci_create);
105 qos_node_consumes("virtio-serial-pci", "pci-bus", &edge_opts);
106 qos_node_produces("virtio-serial-pci", "pci-device");
107 qos_node_produces("virtio-serial-pci", "virtio");
108 qos_node_produces("virtio-serial-pci", "virtio-serial");
111 libqos_init(virtio_serial_register_nodes);