1 /* 2 * Vhost-user RNG virtio device PCI glue 3 * 4 * Copyright (c) 2021 Mathieu Poirier <mathieu.poirier@linaro.org> 5 * 6 * SPDX-License-Identifier: GPL-2.0-or-later 7 */ 8 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" 13 14 struct VHostUserRNGPCI { 15 VirtIOPCIProxy parent_obj; 16 VHostUserRNG vdev; 17 }; 18 19 typedef struct VHostUserRNGPCI VHostUserRNGPCI; 20 21 #define TYPE_VHOST_USER_RNG_PCI "vhost-user-rng-pci-base" 22 23 DECLARE_INSTANCE_CHECKER(VHostUserRNGPCI, VHOST_USER_RNG_PCI, 24 TYPE_VHOST_USER_RNG_PCI) 25 26 static const Property vhost_user_rng_pci_properties[] = { 27 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 28 DEV_NVECTORS_UNSPECIFIED), 29 }; 30 31 static void vhost_user_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 32 { 33 VHostUserRNGPCI *dev = VHOST_USER_RNG_PCI(vpci_dev); 34 DeviceState *vdev = DEVICE(&dev->vdev); 35 36 if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { 37 vpci_dev->nvectors = 1; 38 } 39 40 qdev_realize(vdev, BUS(&vpci_dev->bus), errp); 41 } 42 43 static void vhost_user_rng_pci_class_init(ObjectClass *klass, void *data) 44 { 45 DeviceClass *dc = DEVICE_CLASS(klass); 46 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 47 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 48 k->realize = vhost_user_rng_pci_realize; 49 set_bit(DEVICE_CATEGORY_INPUT, dc->categories); 50 device_class_set_props(dc, vhost_user_rng_pci_properties); 51 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 52 pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ 53 pcidev_k->revision = 0x00; 54 pcidev_k->class_id = PCI_CLASS_OTHERS; 55 } 56 57 static void vhost_user_rng_pci_instance_init(Object *obj) 58 { 59 VHostUserRNGPCI *dev = VHOST_USER_RNG_PCI(obj); 60 61 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 62 TYPE_VHOST_USER_RNG); 63 } 64 65 static const VirtioPCIDeviceTypeInfo vhost_user_rng_pci_info = { 66 .base_name = TYPE_VHOST_USER_RNG_PCI, 67 .non_transitional_name = "vhost-user-rng-pci", 68 .instance_size = sizeof(VHostUserRNGPCI), 69 .instance_init = vhost_user_rng_pci_instance_init, 70 .class_init = vhost_user_rng_pci_class_init, 71 }; 72 73 static void vhost_user_rng_pci_register(void) 74 { 75 virtio_pci_types_register(&vhost_user_rng_pci_info); 76 } 77 78 type_init(vhost_user_rng_pci_register); 79