Viresh Kumar | 25c60a4 | 2022-08-02 10:50:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Vhost-user gpio virtio device PCI glue |
| 3 | * |
| 4 | * Copyright (c) 2022 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-gpio.h" |
| 12 | #include "hw/virtio/virtio-pci.h" |
| 13 | |
| 14 | struct VHostUserGPIOPCI { |
| 15 | VirtIOPCIProxy parent_obj; |
| 16 | VHostUserGPIO vdev; |
| 17 | }; |
| 18 | |
| 19 | typedef struct VHostUserGPIOPCI VHostUserGPIOPCI; |
| 20 | |
| 21 | #define TYPE_VHOST_USER_GPIO_PCI "vhost-user-gpio-pci-base" |
| 22 | |
| 23 | DECLARE_INSTANCE_CHECKER(VHostUserGPIOPCI, VHOST_USER_GPIO_PCI, |
| 24 | TYPE_VHOST_USER_GPIO_PCI) |
| 25 | |
| 26 | static void vhost_user_gpio_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
| 27 | { |
| 28 | VHostUserGPIOPCI *dev = VHOST_USER_GPIO_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_gpio_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_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; |
| 46 | } |
| 47 | |
| 48 | static void vhost_user_gpio_pci_instance_init(Object *obj) |
| 49 | { |
| 50 | VHostUserGPIOPCI *dev = VHOST_USER_GPIO_PCI(obj); |
| 51 | |
| 52 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
| 53 | TYPE_VHOST_USER_GPIO); |
| 54 | } |
| 55 | |
| 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, |
| 62 | }; |
| 63 | |
| 64 | static void vhost_user_gpio_pci_register(void) |
| 65 | { |
| 66 | virtio_pci_types_register(&vhost_user_gpio_pci_info); |
| 67 | } |
| 68 | |
| 69 | type_init(vhost_user_gpio_pci_register); |