2 * Vhost-user RNG virtio device PCI glue
4 * Copyright (c) 2021 Mathieu Poirier <mathieu.poirier@linaro.org>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
10 #include "hw/qdev-properties.h"
11 #include "hw/virtio/vhost-user-rng.h"
12 #include "hw/virtio/virtio-pci.h"
14 struct VHostUserRNGPCI
{
15 VirtIOPCIProxy parent_obj
;
19 typedef struct VHostUserRNGPCI VHostUserRNGPCI
;
21 #define TYPE_VHOST_USER_RNG_PCI "vhost-user-rng-pci-base"
23 DECLARE_INSTANCE_CHECKER(VHostUserRNGPCI
, VHOST_USER_RNG_PCI
,
24 TYPE_VHOST_USER_RNG_PCI
)
26 static Property vhost_user_rng_pci_properties
[] = {
27 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
,
28 DEV_NVECTORS_UNSPECIFIED
),
29 DEFINE_PROP_END_OF_LIST(),
32 static void vhost_user_rng_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
34 VHostUserRNGPCI
*dev
= VHOST_USER_RNG_PCI(vpci_dev
);
35 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
37 if (vpci_dev
->nvectors
== DEV_NVECTORS_UNSPECIFIED
) {
38 vpci_dev
->nvectors
= 1;
41 qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
);
44 static void vhost_user_rng_pci_class_init(ObjectClass
*klass
, void *data
)
46 DeviceClass
*dc
= DEVICE_CLASS(klass
);
47 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
48 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
49 k
->realize
= vhost_user_rng_pci_realize
;
50 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
51 device_class_set_props(dc
, vhost_user_rng_pci_properties
);
52 pcidev_k
->vendor_id
= PCI_VENDOR_ID_REDHAT_QUMRANET
;
53 pcidev_k
->device_id
= 0; /* Set by virtio-pci based on virtio id */
54 pcidev_k
->revision
= 0x00;
55 pcidev_k
->class_id
= PCI_CLASS_OTHERS
;
58 static void vhost_user_rng_pci_instance_init(Object
*obj
)
60 VHostUserRNGPCI
*dev
= VHOST_USER_RNG_PCI(obj
);
62 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
66 static const VirtioPCIDeviceTypeInfo vhost_user_rng_pci_info
= {
67 .base_name
= TYPE_VHOST_USER_RNG_PCI
,
68 .non_transitional_name
= "vhost-user-rng-pci",
69 .instance_size
= sizeof(VHostUserRNGPCI
),
70 .instance_init
= vhost_user_rng_pci_instance_init
,
71 .class_init
= vhost_user_rng_pci_class_init
,
74 static void vhost_user_rng_pci_register(void)
76 virtio_pci_types_register(&vhost_user_rng_pci_info
);
79 type_init(vhost_user_rng_pci_register
);