blob: 48e9ff38e2fb9e28796ce35bd97dee31fd7eb19b [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
11#include "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
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"
Eduardo Habkost80633962020-09-16 14:25:19 -040032OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHIDPCI, VIRTIO_INPUT_HID_PCI)
Juan Quintela9436b8c2019-01-03 15:10:00 +010033
34struct VirtIOInputHIDPCI {
35 VirtIOPCIProxy parent_obj;
36 VirtIOInputHID vdev;
37};
38
39static Property virtio_input_pci_properties[] = {
40 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
41 DEFINE_PROP_END_OF_LIST(),
42};
43
44static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
45{
46 VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev);
47 DeviceState *vdev = DEVICE(&vinput->vdev);
48
Dr. David Alan Gilbertdd560402019-07-29 17:29:03 +010049 virtio_pci_force_virtio_1(vpci_dev);
Markus Armbruster99ba7772020-06-10 07:32:00 +020050 qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
Juan Quintela9436b8c2019-01-03 15:10:00 +010051}
52
53static void virtio_input_pci_class_init(ObjectClass *klass, void *data)
54{
55 DeviceClass *dc = DEVICE_CLASS(klass);
56 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
57 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
58
Marc-André Lureau4f67d302020-01-10 19:30:32 +040059 device_class_set_props(dc, virtio_input_pci_properties);
Juan Quintela9436b8c2019-01-03 15:10:00 +010060 k->realize = virtio_input_pci_realize;
61 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
62
63 pcidev_k->class_id = PCI_CLASS_INPUT_OTHER;
64}
65
66static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data)
67{
68 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
69
70 pcidev_k->class_id = PCI_CLASS_INPUT_KEYBOARD;
71}
72
73static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
74 void *data)
75{
76 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
77
78 pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE;
79}
80
81static void virtio_keyboard_initfn(Object *obj)
82{
83 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
84
85 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
86 TYPE_VIRTIO_KEYBOARD);
87}
88
89static void virtio_mouse_initfn(Object *obj)
90{
91 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
92
93 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
94 TYPE_VIRTIO_MOUSE);
95}
96
97static void virtio_tablet_initfn(Object *obj)
98{
99 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
100
101 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
102 TYPE_VIRTIO_TABLET);
103}
104
105static 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,
110 .abstract = true,
111};
112
113static 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),
117 .abstract = true,
118};
119
120static 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,
126};
127
128static 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,
134};
135
136static 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,
141};
142
143static void virtio_pci_input_register(void)
144{
145 /* Base types: */
146 type_register_static(&virtio_input_pci_info);
147 type_register_static(&virtio_input_hid_pci_info);
148
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);
153}
154
155type_init(virtio_pci_input_register)