1 /* 2 * Vhost-user generic virtio device PCI glue 3 * 4 * Copyright (c) 2023 Linaro Ltd 5 * Author: Alex Bennée <alex.bennee@linaro.org> 6 * 7 * SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 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" 14 15 struct VHostUserDevicePCI { 16 VirtIOPCIProxy parent_obj; 17 VHostUserBase vub; 18 }; 19 20 typedef struct VHostUserDevicePCI VHostUserDevicePCI; 21 22 #define TYPE_VHOST_USER_DEVICE_PCI "vhost-user-device-pci-base" 23 24 DECLARE_INSTANCE_CHECKER(VHostUserDevicePCI, 25 VHOST_USER_DEVICE_PCI, 26 TYPE_VHOST_USER_DEVICE_PCI) 27 28 static void vhost_user_device_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 29 { 30 VHostUserDevicePCI *dev = VHOST_USER_DEVICE_PCI(vpci_dev); 31 DeviceState *vdev = DEVICE(&dev->vub); 32 33 vpci_dev->nvectors = 1; 34 qdev_realize(vdev, BUS(&vpci_dev->bus), errp); 35 } 36 37 static void vhost_user_device_pci_class_init(ObjectClass *klass, void *data) 38 { 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; 48 } 49 50 static void vhost_user_device_pci_instance_init(Object *obj) 51 { 52 VHostUserDevicePCI *dev = VHOST_USER_DEVICE_PCI(obj); 53 54 virtio_instance_init_common(obj, &dev->vub, sizeof(dev->vub), 55 TYPE_VHOST_USER_DEVICE); 56 } 57 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, 64 }; 65 66 static void vhost_user_device_pci_register(void) 67 { 68 virtio_pci_types_register(&vhost_user_device_pci_info); 69 } 70 71 type_init(vhost_user_device_pci_register); 72