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 qdev_set_parent_bus(vdev
, BUS(&vpci_dev
->bus
));
53 virtio_pci_force_virtio_1(vpci_dev
);
54 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
57 static void virtio_input_pci_class_init(ObjectClass
*klass
, void *data
)
59 DeviceClass
*dc
= DEVICE_CLASS(klass
);
60 VirtioPCIClass
*k
= VIRTIO_PCI_CLASS(klass
);
61 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
63 dc
->props
= virtio_input_pci_properties
;
64 k
->realize
= virtio_input_pci_realize
;
65 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
67 pcidev_k
->class_id
= PCI_CLASS_INPUT_OTHER
;
70 static void virtio_input_hid_kbd_pci_class_init(ObjectClass
*klass
, void *data
)
72 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
74 pcidev_k
->class_id
= PCI_CLASS_INPUT_KEYBOARD
;
77 static void virtio_input_hid_mouse_pci_class_init(ObjectClass
*klass
,
80 PCIDeviceClass
*pcidev_k
= PCI_DEVICE_CLASS(klass
);
82 pcidev_k
->class_id
= PCI_CLASS_INPUT_MOUSE
;
85 static void virtio_keyboard_initfn(Object
*obj
)
87 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
89 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
90 TYPE_VIRTIO_KEYBOARD
);
93 static void virtio_mouse_initfn(Object
*obj
)
95 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
97 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
101 static void virtio_tablet_initfn(Object
*obj
)
103 VirtIOInputHIDPCI
*dev
= VIRTIO_INPUT_HID_PCI(obj
);
105 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
109 static const TypeInfo virtio_input_pci_info
= {
110 .name
= TYPE_VIRTIO_INPUT_PCI
,
111 .parent
= TYPE_VIRTIO_PCI
,
112 .instance_size
= sizeof(VirtIOInputPCI
),
113 .class_init
= virtio_input_pci_class_init
,
117 static const TypeInfo virtio_input_hid_pci_info
= {
118 .name
= TYPE_VIRTIO_INPUT_HID_PCI
,
119 .parent
= TYPE_VIRTIO_INPUT_PCI
,
120 .instance_size
= sizeof(VirtIOInputHIDPCI
),
124 static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info
= {
125 .generic_name
= TYPE_VIRTIO_KEYBOARD_PCI
,
126 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
127 .class_init
= virtio_input_hid_kbd_pci_class_init
,
128 .instance_size
= sizeof(VirtIOInputHIDPCI
),
129 .instance_init
= virtio_keyboard_initfn
,
132 static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info
= {
133 .generic_name
= TYPE_VIRTIO_MOUSE_PCI
,
134 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
135 .class_init
= virtio_input_hid_mouse_pci_class_init
,
136 .instance_size
= sizeof(VirtIOInputHIDPCI
),
137 .instance_init
= virtio_mouse_initfn
,
140 static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info
= {
141 .generic_name
= TYPE_VIRTIO_TABLET_PCI
,
142 .parent
= TYPE_VIRTIO_INPUT_HID_PCI
,
143 .instance_size
= sizeof(VirtIOInputHIDPCI
),
144 .instance_init
= virtio_tablet_initfn
,
147 static void virtio_pci_input_register(void)
150 type_register_static(&virtio_input_pci_info
);
151 type_register_static(&virtio_input_hid_pci_info
);
153 /* Implementations: */
154 virtio_pci_types_register(&virtio_keyboard_pci_info
);
155 virtio_pci_types_register(&virtio_mouse_pci_info
);
156 virtio_pci_types_register(&virtio_tablet_pci_info
);
159 type_init(virtio_pci_input_register
)