2 * Vhost-user generic virtio device PCI glue
4 * Copyright (c) 2023 Linaro Ltd
5 * Author: Alex Bennée <alex.bennee@linaro.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #include "qemu/osdep.h"
11 #include "hw/qdev-properties.h"
12 #include "hw/virtio/vhost-user-base.h"
13 #include "hw/virtio/virtio-pci.h"
15 struct VHostUserDevicePCI
{
16 VirtIOPCIProxy parent_obj
;
21 #define TYPE_VHOST_USER_DEVICE_PCI "vhost-user-device-pci-base"
23 OBJECT_DECLARE_SIMPLE_TYPE(VHostUserDevicePCI
, VHOST_USER_DEVICE_PCI
)
25 static void vhost_user_device_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
27 VHostUserDevicePCI
*dev
= VHOST_USER_DEVICE_PCI(vpci_dev
);
28 DeviceState
*vdev
= DEVICE(&dev
->vub
);
30 vpci_dev
->nvectors
= 1;
31 qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
);
34 static void vhost_user_device_pci_class_init(ObjectClass
*klass
, void *data
)
36 DeviceClass
*dc
= DEVICE_CLASS(klass
);
37 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
38 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
40 /* Reason: stop users confusing themselves */
41 dc
->user_creatable
= false;
43 k
->realize
= vhost_user_device_pci_realize
;
44 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
45 pcidev_k
->vendor_id
= PCI_VENDOR_ID_REDHAT_QUMRANET
;
46 pcidev_k
->device_id
= 0; /* Set by virtio-pci based on virtio id */
47 pcidev_k
->revision
= 0x00;
48 pcidev_k
->class_id
= PCI_CLASS_COMMUNICATION_OTHER
;
51 static void vhost_user_device_pci_instance_init(Object
*obj
)
53 VHostUserDevicePCI
*dev
= VHOST_USER_DEVICE_PCI(obj
);
55 virtio_instance_init_common(obj
, &dev
->vub
, sizeof(dev
->vub
),
56 TYPE_VHOST_USER_DEVICE
);
59 static const VirtioPCIDeviceTypeInfo vhost_user_device_pci_info
= {
60 .base_name
= TYPE_VHOST_USER_DEVICE_PCI
,
61 .non_transitional_name
= "vhost-user-device-pci",
62 .instance_size
= sizeof(VHostUserDevicePCI
),
63 .instance_init
= vhost_user_device_pci_instance_init
,
64 .class_init
= vhost_user_device_pci_class_init
,
67 static void vhost_user_device_pci_register(void)
69 virtio_pci_types_register(&vhost_user_device_pci_info
);
72 type_init(vhost_user_device_pci_register
);