1 /* 2 * Vhost-user i2c virtio device PCI glue 3 * 4 * Copyright (c) 2021 Viresh Kumar <viresh.kumar@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-i2c.h" 12 #include "virtio-pci.h" 13 14 struct VHostUserI2CPCI { 15 VirtIOPCIProxy parent_obj; 16 VHostUserI2C vdev; 17 }; 18 19 typedef struct VHostUserI2CPCI VHostUserI2CPCI; 20 21 #define TYPE_VHOST_USER_I2C_PCI "vhost-user-i2c-pci-base" 22 23 DECLARE_INSTANCE_CHECKER(VHostUserI2CPCI, VHOST_USER_I2C_PCI, 24 TYPE_VHOST_USER_I2C_PCI) 25 26 static void vhost_user_i2c_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) 27 { 28 VHostUserI2CPCI *dev = VHOST_USER_I2C_PCI(vpci_dev); 29 DeviceState *vdev = DEVICE(&dev->vdev); 30 31 vpci_dev->nvectors = 1; 32 qdev_realize(vdev, BUS(&vpci_dev->bus), errp); 33 } 34 35 static void vhost_user_i2c_pci_class_init(ObjectClass *klass, void *data) 36 { 37 DeviceClass *dc = DEVICE_CLASS(klass); 38 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); 39 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); 40 k->realize = vhost_user_i2c_pci_realize; 41 set_bit(DEVICE_CATEGORY_INPUT, dc->categories); 42 pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; 43 pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */ 44 pcidev_k->revision = 0x00; 45 pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER; 46 } 47 48 static void vhost_user_i2c_pci_instance_init(Object *obj) 49 { 50 VHostUserI2CPCI *dev = VHOST_USER_I2C_PCI(obj); 51 52 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 53 TYPE_VHOST_USER_I2C); 54 } 55 56 static const VirtioPCIDeviceTypeInfo vhost_user_i2c_pci_info = { 57 .base_name = TYPE_VHOST_USER_I2C_PCI, 58 .non_transitional_name = "vhost-user-i2c-pci", 59 .instance_size = sizeof(VHostUserI2CPCI), 60 .instance_init = vhost_user_i2c_pci_instance_init, 61 .class_init = vhost_user_i2c_pci_class_init, 62 }; 63 64 static void vhost_user_i2c_pci_register(void) 65 { 66 virtio_pci_types_register(&vhost_user_i2c_pci_info); 67 } 68 69 type_init(vhost_user_i2c_pci_register); 70