xref: /qemu/hw/virtio/virtio-9p-pci.c (revision a81df1b6)
1 /*
2  * Virtio 9p PCI Bindings
3  *
4  * Copyright IBM, Corp. 2010
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  * Contributions after 2012-01-13 are licensed under the terms of the
13  * GNU GPL, version 2 or (at your option) any later version.
14  */
15 
16 #include "qemu/osdep.h"
17 
18 #include "virtio-pci.h"
19 #include "hw/9pfs/virtio-9p.h"
20 #include "hw/qdev-properties.h"
21 #include "qemu/module.h"
22 
23 /*
24  * virtio-9p-pci: This extends VirtioPCIProxy.
25  */
26 
27 #define TYPE_VIRTIO_9P_PCI "virtio-9p-pci-base"
28 #define VIRTIO_9P_PCI(obj) \
29         OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
30 
31 typedef struct V9fsPCIState {
32     VirtIOPCIProxy parent_obj;
33     V9fsVirtioState vdev;
34 } V9fsPCIState;
35 
36 static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
37 {
38     V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
39     DeviceState *vdev = DEVICE(&dev->vdev);
40 
41     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
42 }
43 
44 static Property virtio_9p_pci_properties[] = {
45     DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
46                     VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
47     DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
48     DEFINE_PROP_END_OF_LIST(),
49 };
50 
51 static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
52 {
53     DeviceClass *dc = DEVICE_CLASS(klass);
54     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
55     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
56 
57     k->realize = virtio_9p_pci_realize;
58     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
59     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_9P;
60     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
61     pcidev_k->class_id = 0x2;
62     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
63     device_class_set_props(dc, virtio_9p_pci_properties);
64 }
65 
66 static void virtio_9p_pci_instance_init(Object *obj)
67 {
68     V9fsPCIState *dev = VIRTIO_9P_PCI(obj);
69 
70     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
71                                 TYPE_VIRTIO_9P);
72 }
73 
74 static const VirtioPCIDeviceTypeInfo virtio_9p_pci_info = {
75     .base_name              = TYPE_VIRTIO_9P_PCI,
76     .generic_name           = "virtio-9p-pci",
77     .transitional_name      = "virtio-9p-pci-transitional",
78     .non_transitional_name  = "virtio-9p-pci-non-transitional",
79     .instance_size = sizeof(V9fsPCIState),
80     .instance_init = virtio_9p_pci_instance_init,
81     .class_init    = virtio_9p_pci_class_init,
82 };
83 
84 static void virtio_9p_pci_register(void)
85 {
86     virtio_pci_types_register(&virtio_9p_pci_info);
87 }
88 
89 type_init(virtio_9p_pci_register)
90