2 * Vhost-user gpio virtio device PCI glue
4 * Copyright (c) 2022 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-gpio.h"
12 #include "hw/virtio/virtio-pci.h"
14 struct VHostUserGPIOPCI
{
15 VirtIOPCIProxy parent_obj
;
19 typedef struct VHostUserGPIOPCI VHostUserGPIOPCI
;
21 #define TYPE_VHOST_USER_GPIO_PCI "vhost-user-gpio-pci-base"
23 DECLARE_INSTANCE_CHECKER(VHostUserGPIOPCI
, VHOST_USER_GPIO_PCI
,
24 TYPE_VHOST_USER_GPIO_PCI
)
26 static void vhost_user_gpio_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
28 VHostUserGPIOPCI
*dev
= VHOST_USER_GPIO_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_gpio_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_gpio_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_gpio_pci_instance_init(Object
*obj
)
50 VHostUserGPIOPCI
*dev
= VHOST_USER_GPIO_PCI(obj
);
52 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
53 TYPE_VHOST_USER_GPIO
);
56 static const VirtioPCIDeviceTypeInfo vhost_user_gpio_pci_info
= {
57 .base_name
= TYPE_VHOST_USER_GPIO_PCI
,
58 .non_transitional_name
= "vhost-user-gpio-pci",
59 .instance_size
= sizeof(VHostUserGPIOPCI
),
60 .instance_init
= vhost_user_gpio_pci_instance_init
,
61 .class_init
= vhost_user_gpio_pci_class_init
,
64 static void vhost_user_gpio_pci_register(void)
66 virtio_pci_types_register(&vhost_user_gpio_pci_info
);
69 type_init(vhost_user_gpio_pci_register
);