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-device.h"
13 #include "hw/virtio/virtio-pci.h"
15 struct VHostUserDevicePCI
{
16 VirtIOPCIProxy parent_obj
;
20 typedef struct VHostUserDevicePCI VHostUserDevicePCI
;
22 #define TYPE_VHOST_USER_DEVICE_PCI "vhost-user-device-pci-base"
24 DECLARE_INSTANCE_CHECKER(VHostUserDevicePCI
,
25 VHOST_USER_DEVICE_PCI
,
26 TYPE_VHOST_USER_DEVICE_PCI
)
28 static void vhost_user_device_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
30 VHostUserDevicePCI
*dev
= VHOST_USER_DEVICE_PCI(vpci_dev
);
31 DeviceState
*vdev
= DEVICE(&dev
->vub
);
33 vpci_dev
->nvectors
= 1;
34 qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
);
37 static void vhost_user_device_pci_class_init(ObjectClass
*klass
, void *data
)
39 DeviceClass
*dc
= DEVICE_CLASS(klass
);
40 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
41 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
42 k
->realize
= vhost_user_device_pci_realize
;
43 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
44 pcidev_k
->vendor_id
= PCI_VENDOR_ID_REDHAT_QUMRANET
;
45 pcidev_k
->device_id
= 0; /* Set by virtio-pci based on virtio id */
46 pcidev_k
->revision
= 0x00;
47 pcidev_k
->class_id
= PCI_CLASS_COMMUNICATION_OTHER
;
50 static void vhost_user_device_pci_instance_init(Object
*obj
)
52 VHostUserDevicePCI
*dev
= VHOST_USER_DEVICE_PCI(obj
);
54 virtio_instance_init_common(obj
, &dev
->vub
, sizeof(dev
->vub
),
55 TYPE_VHOST_USER_DEVICE
);
58 static const VirtioPCIDeviceTypeInfo vhost_user_device_pci_info
= {
59 .base_name
= TYPE_VHOST_USER_DEVICE_PCI
,
60 .non_transitional_name
= "vhost-user-device-pci",
61 .instance_size
= sizeof(VHostUserDevicePCI
),
62 .instance_init
= vhost_user_device_pci_instance_init
,
63 .class_init
= vhost_user_device_pci_class_init
,
66 static void vhost_user_device_pci_register(void)
68 virtio_pci_types_register(&vhost_user_device_pci_info
);
71 type_init(vhost_user_device_pci_register
);