blob: a53edf46c43705f8c1df58b28ad3f57dfc5875c8 [file] [log] [blame]
Juan Quintela9436b8c2019-01-03 15:10:00 +01001/*
2 * Virtio input PCI Bindings
3 *
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
6 * top-level directory.
7 */
8
9#include "qemu/osdep.h"
10
Alex Bennéee1b1f532022-03-21 15:30:25 +000011#include "hw/virtio/virtio-pci.h"
Markus Armbrustera27bd6c2019-08-12 07:23:51 +020012#include "hw/qdev-properties.h"
Juan Quintela9436b8c2019-01-03 15:10:00 +010013#include "hw/virtio/virtio-input.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020014#include "qemu/module.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040015#include "qom/object.h"
Juan Quintela9436b8c2019-01-03 15:10:00 +010016
Juan Quintela9436b8c2019-01-03 15:10:00 +010017
18/*
19 * virtio-input-pci: This extends VirtioPCIProxy.
20 */
Eduardo Habkost80633962020-09-16 14:25:19 -040021OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputPCI, VIRTIO_INPUT_PCI)
Juan Quintela9436b8c2019-01-03 15:10:00 +010022
23struct VirtIOInputPCI {
24 VirtIOPCIProxy parent_obj;
25 VirtIOInput vdev;
26};
27
Sergio Lopez4b2321c2023-05-26 13:29:23 +020028#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#define TYPE_VIRTIO_MULTITOUCH_PCI "virtio-multitouch-pci"
Eduardo Habkost80633962020-09-16 14:25:19 -040033OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHIDPCI, VIRTIO_INPUT_HID_PCI)
Juan Quintela9436b8c2019-01-03 15:10:00 +010034
35struct VirtIOInputHIDPCI {
36 VirtIOPCIProxy parent_obj;
37 VirtIOInputHID vdev;
38};
39
40static Property virtio_input_pci_properties[] = {
41 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
42 DEFINE_PROP_END_OF_LIST(),
43};
44
45static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
46{
47 VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev);
48 DeviceState *vdev = DEVICE(&vinput->vdev);
49
Dr. David Alan Gilbertdd560402019-07-29 17:29:03 +010050 virtio_pci_force_virtio_1(vpci_dev);
Markus Armbruster99ba7772020-06-10 07:32:00 +020051 qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
Juan Quintela9436b8c2019-01-03 15:10:00 +010052}
53
54static void virtio_input_pci_class_init(ObjectClass *klass, void *data)
55{
56 DeviceClass *dc = DEVICE_CLASS(klass);
57 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
58 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
59
Marc-André Lureau4f67d302020-01-10 19:30:32 +040060 device_class_set_props(dc, virtio_input_pci_properties);
Juan Quintela9436b8c2019-01-03 15:10:00 +010061 k->realize = virtio_input_pci_realize;
62 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
63
64 pcidev_k->class_id = PCI_CLASS_INPUT_OTHER;
65}
66
67static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data)
68{
69 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
70
71 pcidev_k->class_id = PCI_CLASS_INPUT_KEYBOARD;
72}
73
74static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
75 void *data)
76{
77 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
78
79 pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE;
80}
81
82static void virtio_keyboard_initfn(Object *obj)
83{
84 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
85
86 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
87 TYPE_VIRTIO_KEYBOARD);
88}
89
90static void virtio_mouse_initfn(Object *obj)
91{
92 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
93
94 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
95 TYPE_VIRTIO_MOUSE);
96}
97
98static void virtio_tablet_initfn(Object *obj)
99{
100 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
101
102 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
103 TYPE_VIRTIO_TABLET);
104}
105
Sergio Lopez4b2321c2023-05-26 13:29:23 +0200106static void virtio_multitouch_initfn(Object *obj)
107{
108 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
109
110 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
111 TYPE_VIRTIO_MULTITOUCH);
112}
113
Juan Quintela9436b8c2019-01-03 15:10:00 +0100114static const TypeInfo virtio_input_pci_info = {
115 .name = TYPE_VIRTIO_INPUT_PCI,
116 .parent = TYPE_VIRTIO_PCI,
117 .instance_size = sizeof(VirtIOInputPCI),
118 .class_init = virtio_input_pci_class_init,
119 .abstract = true,
120};
121
122static const TypeInfo virtio_input_hid_pci_info = {
123 .name = TYPE_VIRTIO_INPUT_HID_PCI,
124 .parent = TYPE_VIRTIO_INPUT_PCI,
125 .instance_size = sizeof(VirtIOInputHIDPCI),
126 .abstract = true,
127};
128
129static const VirtioPCIDeviceTypeInfo virtio_keyboard_pci_info = {
130 .generic_name = TYPE_VIRTIO_KEYBOARD_PCI,
131 .parent = TYPE_VIRTIO_INPUT_HID_PCI,
132 .class_init = virtio_input_hid_kbd_pci_class_init,
133 .instance_size = sizeof(VirtIOInputHIDPCI),
134 .instance_init = virtio_keyboard_initfn,
135};
136
137static const VirtioPCIDeviceTypeInfo virtio_mouse_pci_info = {
138 .generic_name = TYPE_VIRTIO_MOUSE_PCI,
139 .parent = TYPE_VIRTIO_INPUT_HID_PCI,
140 .class_init = virtio_input_hid_mouse_pci_class_init,
141 .instance_size = sizeof(VirtIOInputHIDPCI),
142 .instance_init = virtio_mouse_initfn,
143};
144
145static const VirtioPCIDeviceTypeInfo virtio_tablet_pci_info = {
146 .generic_name = TYPE_VIRTIO_TABLET_PCI,
147 .parent = TYPE_VIRTIO_INPUT_HID_PCI,
148 .instance_size = sizeof(VirtIOInputHIDPCI),
149 .instance_init = virtio_tablet_initfn,
150};
151
Sergio Lopez4b2321c2023-05-26 13:29:23 +0200152static const VirtioPCIDeviceTypeInfo virtio_multitouch_pci_info = {
153 .generic_name = TYPE_VIRTIO_MULTITOUCH_PCI,
154 .parent = TYPE_VIRTIO_INPUT_HID_PCI,
155 .instance_size = sizeof(VirtIOInputHIDPCI),
156 .instance_init = virtio_multitouch_initfn,
157};
158
Juan Quintela9436b8c2019-01-03 15:10:00 +0100159static void virtio_pci_input_register(void)
160{
161 /* Base types: */
162 type_register_static(&virtio_input_pci_info);
163 type_register_static(&virtio_input_hid_pci_info);
164
165 /* Implementations: */
166 virtio_pci_types_register(&virtio_keyboard_pci_info);
167 virtio_pci_types_register(&virtio_mouse_pci_info);
168 virtio_pci_types_register(&virtio_tablet_pci_info);
Sergio Lopez4b2321c2023-05-26 13:29:23 +0200169 virtio_pci_types_register(&virtio_multitouch_pci_info);
Juan Quintela9436b8c2019-01-03 15:10:00 +0100170}
171
172type_init(virtio_pci_input_register)