1 /*
2  * Vhost-user SCMI virtio device PCI glue
3  *
4  * SPDX-FileCopyrightText: Red Hat, Inc.
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7 
8 #include "qemu/osdep.h"
9 #include "hw/qdev-properties.h"
10 #include "hw/virtio/vhost-user-scmi.h"
11 #include "hw/virtio/virtio-pci.h"
12 
13 struct VHostUserSCMIPCI {
14     VirtIOPCIProxy parent_obj;
15     VHostUserSCMI vdev;
16 };
17 
18 typedef struct VHostUserSCMIPCI VHostUserSCMIPCI;
19 
20 #define TYPE_VHOST_USER_SCMI_PCI "vhost-user-scmi-pci-base"
21 
22 DECLARE_INSTANCE_CHECKER(VHostUserSCMIPCI, VHOST_USER_SCMI_PCI,
23                          TYPE_VHOST_USER_SCMI_PCI)
24 
25 static void vhost_user_scmi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
26 {
27     VHostUserSCMIPCI *dev = VHOST_USER_SCMI_PCI(vpci_dev);
28     DeviceState *vdev = DEVICE(&dev->vdev);
29 
30     vpci_dev->nvectors = 1;
31     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
32 }
33 
34 static void vhost_user_scmi_pci_class_init(ObjectClass *klass, void *data)
35 {
36     DeviceClass *dc = DEVICE_CLASS(klass);
37     VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
38     PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
39     k->realize = vhost_user_scmi_pci_realize;
40     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
41     pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
42     pcidev_k->device_id = 0; /* Set by virtio-pci based on virtio id */
43     pcidev_k->revision = 0x00;
44     pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
45 }
46 
47 static void vhost_user_scmi_pci_instance_init(Object *obj)
48 {
49     VHostUserSCMIPCI *dev = VHOST_USER_SCMI_PCI(obj);
50 
51     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
52                                 TYPE_VHOST_USER_SCMI);
53 }
54 
55 static const VirtioPCIDeviceTypeInfo vhost_user_scmi_pci_info = {
56     .base_name = TYPE_VHOST_USER_SCMI_PCI,
57     .non_transitional_name = "vhost-user-scmi-pci",
58     .instance_size = sizeof(VHostUserSCMIPCI),
59     .instance_init = vhost_user_scmi_pci_instance_init,
60     .class_init = vhost_user_scmi_pci_class_init,
61 };
62 
63 static void vhost_user_scmi_pci_register(void)
64 {
65     virtio_pci_types_register(&vhost_user_scmi_pci_info);
66 }
67 
68 type_init(vhost_user_scmi_pci_register);
69