2 * Vhost-user i2c virtio device PCI glue
4 * Copyright (c) 2021 Viresh Kumar <viresh.kumar@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-i2c.h"
12 #include "hw/virtio/virtio-pci.h"
14 struct VHostUserI2CPCI
{
15 VirtIOPCIProxy parent_obj
;
19 typedef struct VHostUserI2CPCI VHostUserI2CPCI
;
21 #define TYPE_VHOST_USER_I2C_PCI "vhost-user-i2c-pci-base"
23 DECLARE_INSTANCE_CHECKER(VHostUserI2CPCI
, VHOST_USER_I2C_PCI
,
24 TYPE_VHOST_USER_I2C_PCI
)
26 static void vhost_user_i2c_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
28 VHostUserI2CPCI
*dev
= VHOST_USER_I2C_PCI(vpci_dev
);
29 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
31 vpci_dev
->nvectors
= 1;
32 qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
);
35 static void vhost_user_i2c_pci_class_init(ObjectClass
*klass
, void *data
)
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
;
48 static void vhost_user_i2c_pci_instance_init(Object
*obj
)
50 VHostUserI2CPCI
*dev
= VHOST_USER_I2C_PCI(obj
);
52 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
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
,
64 static void vhost_user_i2c_pci_register(void)
66 virtio_pci_types_register(&vhost_user_i2c_pci_info
);
69 type_init(vhost_user_i2c_pci_register
);