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.1 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/qgraph.h"
24 #include "libqos/virtio-scsi.h"
26 /* virtio-scsi-device */
27 static void *qvirtio_scsi_get_driver(QVirtioSCSI
*v_scsi
,
28 const char *interface
)
30 if (!g_strcmp0(interface
, "virtio-scsi")) {
33 if (!g_strcmp0(interface
, "virtio")) {
37 fprintf(stderr
, "%s not present in virtio-scsi-device\n", interface
);
38 g_assert_not_reached();
41 static void *qvirtio_scsi_device_get_driver(void *object
,
42 const char *interface
)
44 QVirtioSCSIDevice
*v_scsi
= object
;
45 return qvirtio_scsi_get_driver(&v_scsi
->scsi
, interface
);
48 static void *virtio_scsi_device_create(void *virtio_dev
,
49 QGuestAllocator
*t_alloc
,
52 QVirtioSCSIDevice
*virtio_bdevice
= g_new0(QVirtioSCSIDevice
, 1);
53 QVirtioSCSI
*interface
= &virtio_bdevice
->scsi
;
55 interface
->vdev
= virtio_dev
;
57 virtio_bdevice
->obj
.get_driver
= qvirtio_scsi_device_get_driver
;
59 return &virtio_bdevice
->obj
;
63 static void *qvirtio_scsi_pci_get_driver(void *object
,
64 const char *interface
)
66 QVirtioSCSIPCI
*v_scsi
= object
;
67 if (!g_strcmp0(interface
, "pci-device")) {
68 return v_scsi
->pci_vdev
.pdev
;
70 return qvirtio_scsi_get_driver(&v_scsi
->scsi
, interface
);
73 static void *virtio_scsi_pci_create(void *pci_bus
,
74 QGuestAllocator
*t_alloc
,
77 QVirtioSCSIPCI
*virtio_spci
= g_new0(QVirtioSCSIPCI
, 1);
78 QVirtioSCSI
*interface
= &virtio_spci
->scsi
;
79 QOSGraphObject
*obj
= &virtio_spci
->pci_vdev
.obj
;
81 virtio_pci_init(&virtio_spci
->pci_vdev
, pci_bus
, addr
);
82 interface
->vdev
= &virtio_spci
->pci_vdev
.vdev
;
84 g_assert_cmphex(interface
->vdev
->device_type
, ==, VIRTIO_ID_SCSI
);
86 obj
->get_driver
= qvirtio_scsi_pci_get_driver
;
91 static void virtio_scsi_register_nodes(void)
94 .devfn
= QPCI_DEVFN(4, 0),
97 QOSGraphEdgeOptions opts
= {
98 .before_cmd_line
= "-drive id=drv0,if=none,file=null-co://,"
99 "file.read-zeroes=on,format=raw",
100 .after_cmd_line
= "-device scsi-hd,bus=vs0.0,drive=drv0",
103 /* virtio-scsi-device */
104 opts
.extra_device_opts
= "id=vs0";
105 qos_node_create_driver("virtio-scsi-device",
106 virtio_scsi_device_create
);
107 qos_node_consumes("virtio-scsi-device", "virtio-bus", &opts
);
108 qos_node_produces("virtio-scsi-device", "virtio-scsi");
110 /* virtio-scsi-pci */
111 opts
.extra_device_opts
= "id=vs0,addr=04.0";
112 add_qpci_address(&opts
, &addr
);
113 qos_node_create_driver("virtio-scsi-pci", virtio_scsi_pci_create
);
114 qos_node_consumes("virtio-scsi-pci", "pci-bus", &opts
);
115 qos_node_produces("virtio-scsi-pci", "pci-device");
116 qos_node_produces("virtio-scsi-pci", "virtio-scsi");
119 libqos_init(virtio_scsi_register_nodes
);