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 "virtio-pci.h"
12 #include "hw/qdev-properties.h"
13 #include "hw/virtio/virtio-input.h"
14 #include "qemu/module.h"
16 typedef struct VirtIOInputPCI VirtIOInputPCI
;
17 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI
;
20 * virtio-input-pci: This extends VirtioPCIProxy.
22 #define VIRTIO_INPUT_PCI(obj) \
23 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
25 struct VirtIOInputPCI
{
26 VirtIOPCIProxy parent_obj
;
30 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
31 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
32 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
33 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
34 #define VIRTIO_INPUT_HID_PCI(obj) \
35 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
37 struct VirtIOInputHIDPCI
{
38 VirtIOPCIProxy parent_obj
;
42 static Property virtio_input_pci_properties
[] = {
43 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
, 2),
44 DEFINE_PROP_END_OF_LIST(),
47 static void virtio_input_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
49 VirtIOInputPCI
*vinput
= VIRTIO_INPUT_PCI(vpci_dev
);
50 DeviceState
*vdev
= DEVICE(&vinput
->vdev
);
52 virtio_pci_force_virtio_1(vpci_dev
);
53 qdev_realize(vdev
, BUS(&vpci_dev
->bus
), errp
);
56 static void virtio_input_pci_class_init(ObjectClass
*klass
, void *data
)
58 DeviceClass
*dc
= DEVICE_CLASS(klass
);
59 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
60 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
62 device_class_set_props(dc
, virtio_input_pci_properties
);
63 k
->realize
= virtio_input_pci_realize
;
64 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
66 pcidev_k
->class_id
= PCI_CLASS_INPUT_OTHER
;
69 static void virtio_input_hid_kbd_pci_class_init(ObjectClass
*klass
, void *data
)
71 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
73 pcidev_k
->class_id
= PCI_CLASS_INPUT_KEYBOARD
;
76 static void virtio_input_hid_mouse_pci_class_init(ObjectClass
*klass
,
79 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
81 pcidev_k
->class_id
= PCI_CLASS_INPUT_MOUSE
;
84 static void virtio_keyboard_initfn(Object
*obj
)
86 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
88 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
89 TYPE_VIRTIO_KEYBOARD
);
92 static void virtio_mouse_initfn(Object
*obj
)
94 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
96 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
100 static void virtio_tablet_initfn(Object
*obj
)
102 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
104 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
108 static const TypeInfo virtio_input_pci_info
= {
109 .name
= TYPE_VIRTIO_INPUT_PCI
,
110 .parent
= TYPE_VIRTIO_PCI
,
111 .instance_size
= sizeof(VirtIOInputPCI
),
112 .class_init
= virtio_input_pci_class_init
,
116 static const TypeInfo virtio_input_hid_pci_info
= {
117 .name
= TYPE_VIRTIO_INPUT_HID_PCI
,
118 .parent
= TYPE_VIRTIO_INPUT_PCI
,
119 .instance_size
= sizeof(VirtIOInputHIDPCI
),
123 static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info
= {
124 .generic_name
= TYPE_VIRTIO_KEYBOARD_PCI
,
125 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
126 .class_init
= virtio_input_hid_kbd_pci_class_init
,
127 .instance_size
= sizeof(VirtIOInputHIDPCI
),
128 .instance_init
= virtio_keyboard_initfn
,
131 static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info
= {
132 .generic_name
= TYPE_VIRTIO_MOUSE_PCI
,
133 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
134 .class_init
= virtio_input_hid_mouse_pci_class_init
,
135 .instance_size
= sizeof(VirtIOInputHIDPCI
),
136 .instance_init
= virtio_mouse_initfn
,
139 static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info
= {
140 .generic_name
= TYPE_VIRTIO_TABLET_PCI
,
141 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
142 .instance_size
= sizeof(VirtIOInputHIDPCI
),
143 .instance_init
= virtio_tablet_initfn
,
146 static void virtio_pci_input_register(void)
149 type_register_static(&virtio_input_pci_info
);
150 type_register_static(&virtio_input_hid_pci_info
);
152 /* Implementations: */
153 virtio_pci_types_register(&virtio_keyboard_pci_info
);
154 virtio_pci_types_register(&virtio_mouse_pci_info
);
155 virtio_pci_types_register(&virtio_tablet_pci_info
);
158 type_init(virtio_pci_input_register
)