2 * Virtio input PCI Bindings
4 * This work is licensed under the terms of the GNU GPL, version 2 or
5 * (at your option) any later version. See the COPYING file in the
9 #include "qemu/osdep.h"
11 #include "hw/virtio/virtio-pci.h"
12 #include "hw/qdev-properties.h"
13 #include "hw/virtio/virtio-input.h"
14 #include "qemu/module.h"
15 #include "qom/object.h"
19 * virtio-input-pci: This extends VirtioPCIProxy.
21 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputPCI
, VIRTIO_INPUT_PCI
)
23 struct VirtIOInputPCI
{
24 VirtIOPCIProxy parent_obj
;
28 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
29 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
30 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
31 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
32 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHIDPCI
, VIRTIO_INPUT_HID_PCI
)
34 struct VirtIOInputHIDPCI
{
35 VirtIOPCIProxy parent_obj
;
39 static Property virtio_input_pci_properties
[] = {
40 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
, 2),
41 DEFINE_PROP_END_OF_LIST(),
44 static void virtio_input_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
46 VirtIOInputPCI
*vinput
= VIRTIO_INPUT_PCI(vpci_dev
);
47 DeviceState
*vdev
= DEVICE(&vinput
->vdev
);
49 virtio_pci_force_virtio_1(vpci_dev
);
50 qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
);
53 static void virtio_input_pci_class_init(ObjectClass
*klass
, void *data
)
55 DeviceClass
*dc
= DEVICE_CLASS(klass
);
56 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
57 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
59 device_class_set_props(dc
, virtio_input_pci_properties
);
60 k
->realize
= virtio_input_pci_realize
;
61 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
63 pcidev_k
->class_id
= PCI_CLASS_INPUT_OTHER
;
66 static void virtio_input_hid_kbd_pci_class_init(ObjectClass
*klass
, void *data
)
68 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
70 pcidev_k
->class_id
= PCI_CLASS_INPUT_KEYBOARD
;
73 static void virtio_input_hid_mouse_pci_class_init(ObjectClass
*klass
,
76 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
78 pcidev_k
->class_id
= PCI_CLASS_INPUT_MOUSE
;
81 static void virtio_keyboard_initfn(Object
*obj
)
83 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
85 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
86 TYPE_VIRTIO_KEYBOARD
);
89 static void virtio_mouse_initfn(Object
*obj
)
91 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
93 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
97 static void virtio_tablet_initfn(Object
*obj
)
99 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
101 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
105 static const TypeInfo virtio_input_pci_info
= {
106 .name
= TYPE_VIRTIO_INPUT_PCI
,
107 .parent
= TYPE_VIRTIO_PCI
,
108 .instance_size
= sizeof(VirtIOInputPCI
),
109 .class_init
= virtio_input_pci_class_init
,
113 static const TypeInfo virtio_input_hid_pci_info
= {
114 .name
= TYPE_VIRTIO_INPUT_HID_PCI
,
115 .parent
= TYPE_VIRTIO_INPUT_PCI
,
116 .instance_size
= sizeof(VirtIOInputHIDPCI
),
120 static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info
= {
121 .generic_name
= TYPE_VIRTIO_KEYBOARD_PCI
,
122 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
123 .class_init
= virtio_input_hid_kbd_pci_class_init
,
124 .instance_size
= sizeof(VirtIOInputHIDPCI
),
125 .instance_init
= virtio_keyboard_initfn
,
128 static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info
= {
129 .generic_name
= TYPE_VIRTIO_MOUSE_PCI
,
130 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
131 .class_init
= virtio_input_hid_mouse_pci_class_init
,
132 .instance_size
= sizeof(VirtIOInputHIDPCI
),
133 .instance_init
= virtio_mouse_initfn
,
136 static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info
= {
137 .generic_name
= TYPE_VIRTIO_TABLET_PCI
,
138 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
139 .instance_size
= sizeof(VirtIOInputHIDPCI
),
140 .instance_init
= virtio_tablet_initfn
,
143 static void virtio_pci_input_register(void)
146 type_register_static(&virtio_input_pci_info
);
147 type_register_static(&virtio_input_hid_pci_info
);
149 /* Implementations: */
150 virtio_pci_types_register(&virtio_keyboard_pci_info
);
151 virtio_pci_types_register(&virtio_mouse_pci_info
);
152 virtio_pci_types_register(&virtio_tablet_pci_info
);
155 type_init(virtio_pci_input_register
)