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/virtio/virtio-input.h"
13 #include "qemu/module.h"
15 typedef struct VirtIOInputPCI VirtIOInputPCI
;
16 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI
;
19 * virtio-input-pci: This extends VirtioPCIProxy.
21 #define VIRTIO_INPUT_PCI(obj) \
22 OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
24 struct VirtIOInputPCI
{
25 VirtIOPCIProxy parent_obj
;
29 #define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
30 #define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci"
31 #define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
32 #define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci"
33 #define VIRTIO_INPUT_HID_PCI(obj) \
34 OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
36 struct VirtIOInputHIDPCI
{
37 VirtIOPCIProxy parent_obj
;
41 static Property virtio_input_pci_properties
[] = {
42 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
, 2),
43 DEFINE_PROP_END_OF_LIST(),
46 static void virtio_input_pci_realize(VirtIOPCIProxy
*vpci_dev
, Error
**errp
)
48 VirtIOInputPCI
*vinput
= VIRTIO_INPUT_PCI(vpci_dev
);
49 DeviceState
*vdev
= DEVICE(&vinput
->vdev
);
51 qdev_set_parent_bus(vdev
, BUS(&vpci_dev
->bus
));
52 if (!virtio_pci_force_virtio_1(vpci_dev
, errp
)) {
55 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
58 static void virtio_input_pci_class_init(ObjectClass
*klass
, void *data
)
60 DeviceClass
*dc
= DEVICE_CLASS(klass
);
61 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
62 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
64 dc
->props
= virtio_input_pci_properties
;
65 k
->realize
= virtio_input_pci_realize
;
66 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
68 pcidev_k
->class_id
= PCI_CLASS_INPUT_OTHER
;
71 static void virtio_input_hid_kbd_pci_class_init(ObjectClass
*klass
, void *data
)
73 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
75 pcidev_k
->class_id
= PCI_CLASS_INPUT_KEYBOARD
;
78 static void virtio_input_hid_mouse_pci_class_init(ObjectClass
*klass
,
81 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
83 pcidev_k
->class_id
= PCI_CLASS_INPUT_MOUSE
;
86 static void virtio_keyboard_initfn(Object
*obj
)
88 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
90 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
91 TYPE_VIRTIO_KEYBOARD
);
94 static void virtio_mouse_initfn(Object
*obj
)
96 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
98 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
102 static void virtio_tablet_initfn(Object
*obj
)
104 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
106 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
110 static const TypeInfo virtio_input_pci_info
= {
111 .name
= TYPE_VIRTIO_INPUT_PCI
,
112 .parent
= TYPE_VIRTIO_PCI
,
113 .instance_size
= sizeof(VirtIOInputPCI
),
114 .class_init
= virtio_input_pci_class_init
,
118 static const TypeInfo virtio_input_hid_pci_info
= {
119 .name
= TYPE_VIRTIO_INPUT_HID_PCI
,
120 .parent
= TYPE_VIRTIO_INPUT_PCI
,
121 .instance_size
= sizeof(VirtIOInputHIDPCI
),
125 static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info
= {
126 .generic_name
= TYPE_VIRTIO_KEYBOARD_PCI
,
127 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
128 .class_init
= virtio_input_hid_kbd_pci_class_init
,
129 .instance_size
= sizeof(VirtIOInputHIDPCI
),
130 .instance_init
= virtio_keyboard_initfn
,
133 static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info
= {
134 .generic_name
= TYPE_VIRTIO_MOUSE_PCI
,
135 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
136 .class_init
= virtio_input_hid_mouse_pci_class_init
,
137 .instance_size
= sizeof(VirtIOInputHIDPCI
),
138 .instance_init
= virtio_mouse_initfn
,
141 static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info
= {
142 .generic_name
= TYPE_VIRTIO_TABLET_PCI
,
143 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
144 .instance_size
= sizeof(VirtIOInputHIDPCI
),
145 .instance_init
= virtio_tablet_initfn
,
148 static void virtio_pci_input_register(void)
151 type_register_static(&virtio_input_pci_info
);
152 type_register_static(&virtio_input_hid_pci_info
);
154 /* Implementations: */
155 virtio_pci_types_register(&virtio_keyboard_pci_info
);
156 virtio_pci_types_register(&virtio_mouse_pci_info
);
157 virtio_pci_types_register(&virtio_tablet_pci_info
);
160 type_init(virtio_pci_input_register
)