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 "qemu/module.h"
22 #include "standard-headers/linux/virtio_ids.h"
23 #include "libqos/virtio-9p.h"
24 #include "libqos/qgraph.h"
26 static QGuestAllocator
*alloc
;
28 static void virtio_9p_cleanup(QVirtio9P
*interface
)
30 qvirtqueue_cleanup(interface
->vdev
->bus
, interface
->vq
, alloc
);
33 static void virtio_9p_setup(QVirtio9P
*interface
)
35 interface
->vq
= qvirtqueue_setup(interface
->vdev
, alloc
, 0);
36 qvirtio_set_driver_ok(interface
->vdev
);
39 /* virtio-9p-device */
40 static void virtio_9p_device_destructor(QOSGraphObject
*obj
)
42 QVirtio9PDevice
*v_9p
= (QVirtio9PDevice
*) obj
;
43 QVirtio9P
*v9p
= &v_9p
->v9p
;
45 virtio_9p_cleanup(v9p
);
48 static void virtio_9p_device_start_hw(QOSGraphObject
*obj
)
50 QVirtio9PDevice
*v_9p
= (QVirtio9PDevice
*) obj
;
51 QVirtio9P
*v9p
= &v_9p
->v9p
;
56 static void *virtio_9p_get_driver(QVirtio9P
*v_9p
,
57 const char *interface
)
59 if (!g_strcmp0(interface
, "virtio-9p")) {
62 if (!g_strcmp0(interface
, "virtio")) {
66 fprintf(stderr
, "%s not present in virtio-9p-device\n", interface
);
67 g_assert_not_reached();
70 static void *virtio_9p_device_get_driver(void *object
, const char *interface
)
72 QVirtio9PDevice
*v_9p
= object
;
73 return virtio_9p_get_driver(&v_9p
->v9p
, interface
);
76 static void *virtio_9p_device_create(void *virtio_dev
,
77 QGuestAllocator
*t_alloc
,
80 QVirtio9PDevice
*virtio_device
= g_new0(QVirtio9PDevice
, 1);
81 QVirtio9P
*interface
= &virtio_device
->v9p
;
83 interface
->vdev
= virtio_dev
;
86 virtio_device
->obj
.destructor
= virtio_9p_device_destructor
;
87 virtio_device
->obj
.get_driver
= virtio_9p_device_get_driver
;
88 virtio_device
->obj
.start_hw
= virtio_9p_device_start_hw
;
90 return &virtio_device
->obj
;
94 static void virtio_9p_pci_destructor(QOSGraphObject
*obj
)
96 QVirtio9PPCI
*v9_pci
= (QVirtio9PPCI
*) obj
;
97 QVirtio9P
*interface
= &v9_pci
->v9p
;
98 QOSGraphObject
*pci_vobj
= &v9_pci
->pci_vdev
.obj
;
100 virtio_9p_cleanup(interface
);
101 qvirtio_pci_destructor(pci_vobj
);
104 static void virtio_9p_pci_start_hw(QOSGraphObject
*obj
)
106 QVirtio9PPCI
*v9_pci
= (QVirtio9PPCI
*) obj
;
107 QVirtio9P
*interface
= &v9_pci
->v9p
;
108 QOSGraphObject
*pci_vobj
= &v9_pci
->pci_vdev
.obj
;
110 qvirtio_pci_start_hw(pci_vobj
);
111 virtio_9p_setup(interface
);
114 static void *virtio_9p_pci_get_driver(void *object
, const char *interface
)
116 QVirtio9PPCI
*v_9p
= object
;
117 if (!g_strcmp0(interface
, "pci-device")) {
118 return v_9p
->pci_vdev
.pdev
;
120 return virtio_9p_get_driver(&v_9p
->v9p
, interface
);
123 static void *virtio_9p_pci_create(void *pci_bus
, QGuestAllocator
*t_alloc
,
126 QVirtio9PPCI
*v9_pci
= g_new0(QVirtio9PPCI
, 1);
127 QVirtio9P
*interface
= &v9_pci
->v9p
;
128 QOSGraphObject
*obj
= &v9_pci
->pci_vdev
.obj
;
130 virtio_pci_init(&v9_pci
->pci_vdev
, pci_bus
, addr
);
131 interface
->vdev
= &v9_pci
->pci_vdev
.vdev
;
134 g_assert_cmphex(interface
->vdev
->device_type
, ==, VIRTIO_ID_9P
);
136 obj
->destructor
= virtio_9p_pci_destructor
;
137 obj
->start_hw
= virtio_9p_pci_start_hw
;
138 obj
->get_driver
= virtio_9p_pci_get_driver
;
143 static void virtio_9p_register_nodes(void)
145 const char *str_simple
= "fsdev=fsdev0,mount_tag=" MOUNT_TAG
;
146 const char *str_addr
= "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG
;
149 .devfn
= QPCI_DEVFN(4, 0),
152 QOSGraphEdgeOptions opts
= {
153 .before_cmd_line
= "-fsdev synth,id=fsdev0",
156 /* virtio-9p-device */
157 opts
.extra_device_opts
= str_simple
,
158 qos_node_create_driver("virtio-9p-device", virtio_9p_device_create
);
159 qos_node_consumes("virtio-9p-device", "virtio-bus", &opts
);
160 qos_node_produces("virtio-9p-device", "virtio");
161 qos_node_produces("virtio-9p-device", "virtio-9p");
164 opts
.extra_device_opts
= str_addr
;
165 add_qpci_address(&opts
, &addr
);
166 qos_node_create_driver("virtio-9p-pci", virtio_9p_pci_create
);
167 qos_node_consumes("virtio-9p-pci", "pci-bus", &opts
);
168 qos_node_produces("virtio-9p-pci", "pci-device");
169 qos_node_produces("virtio-9p-pci", "virtio");
170 qos_node_produces("virtio-9p-pci", "virtio-9p");
174 libqos_init(virtio_9p_register_nodes
);