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-serial.h"
24 static void *qvirtio_serial_get_driver(QVirtioSerial
*v_serial
,
25 const char *interface
)
27 if (!g_strcmp0(interface
, "virtio-serial")) {
30 if (!g_strcmp0(interface
, "virtio")) {
31 return v_serial
->vdev
;
34 fprintf(stderr
, "%s not present in virtio-serial-device\n", interface
);
35 g_assert_not_reached();
38 static void *qvirtio_serial_device_get_driver(void *object
,
39 const char *interface
)
41 QVirtioSerialDevice
*v_serial
= object
;
42 return qvirtio_serial_get_driver(&v_serial
->serial
, interface
);
45 static void *virtio_serial_device_create(void *virtio_dev
,
46 QGuestAllocator
*t_alloc
,
49 QVirtioSerialDevice
*virtio_device
= g_new0(QVirtioSerialDevice
, 1);
50 QVirtioSerial
*interface
= &virtio_device
->serial
;
52 interface
->vdev
= virtio_dev
;
54 virtio_device
->obj
.get_driver
= qvirtio_serial_device_get_driver
;
56 return &virtio_device
->obj
;
59 /* virtio-serial-pci */
60 static void *qvirtio_serial_pci_get_driver(void *object
, const char *interface
)
62 QVirtioSerialPCI
*v_serial
= object
;
63 if (!g_strcmp0(interface
, "pci-device")) {
64 return v_serial
->pci_vdev
.pdev
;
66 return qvirtio_serial_get_driver(&v_serial
->serial
, interface
);
69 static void *virtio_serial_pci_create(void *pci_bus
, QGuestAllocator
*t_alloc
,
72 QVirtioSerialPCI
*virtio_spci
= g_new0(QVirtioSerialPCI
, 1);
73 QVirtioSerial
*interface
= &virtio_spci
->serial
;
74 QOSGraphObject
*obj
= &virtio_spci
->pci_vdev
.obj
;
76 virtio_pci_init(&virtio_spci
->pci_vdev
, pci_bus
, addr
);
77 interface
->vdev
= &virtio_spci
->pci_vdev
.vdev
;
79 obj
->get_driver
= qvirtio_serial_pci_get_driver
;
84 static void virtio_serial_register_nodes(void)
87 .devfn
= QPCI_DEVFN(4, 0),
90 QOSGraphEdgeOptions edge_opts
= { };
92 /* virtio-serial-device */
93 edge_opts
.extra_device_opts
= "id=vser0";
94 qos_node_create_driver("virtio-serial-device",
95 virtio_serial_device_create
);
96 qos_node_consumes("virtio-serial-device", "virtio-bus", &edge_opts
);
97 qos_node_produces("virtio-serial-device", "virtio");
98 qos_node_produces("virtio-serial-device", "virtio-serial");
100 /* virtio-serial-pci */
101 edge_opts
.extra_device_opts
= "id=vser0,addr=04.0";
102 add_qpci_address(&edge_opts
, &addr
);
103 qos_node_create_driver("virtio-serial-pci", virtio_serial_pci_create
);
104 qos_node_consumes("virtio-serial-pci", "pci-bus", &edge_opts
);
105 qos_node_produces("virtio-serial-pci", "pci-device");
106 qos_node_produces("virtio-serial-pci", "virtio");
107 qos_node_produces("virtio-serial-pci", "virtio-serial");
110 libqos_init(virtio_serial_register_nodes
);