Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 1 | /* |
| 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ée | e1b1f53 | 2022-03-21 15:30:25 +0000 | [diff] [blame] | 11 | #include "hw/virtio/virtio-pci.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 12 | #include "hw/qdev-properties.h" |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 13 | #include "hw/virtio/virtio-input.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 14 | #include "qemu/module.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 15 | #include "qom/object.h" |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 16 | |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * virtio-input-pci: This extends VirtioPCIProxy. |
| 20 | */ |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 21 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputPCI, VIRTIO_INPUT_PCI) |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 22 | |
| 23 | struct VirtIOInputPCI { |
| 24 | VirtIOPCIProxy parent_obj; |
| 25 | VirtIOInput vdev; |
| 26 | }; |
| 27 | |
Sergio Lopez | 4b2321c | 2023-05-26 13:29:23 +0200 | [diff] [blame] | 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" |
| 32 | #define TYPE_VIRTIO_MULTITOUCH_PCI "virtio-multitouch-pci" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 33 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHIDPCI, VIRTIO_INPUT_HID_PCI) |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 34 | |
| 35 | struct VirtIOInputHIDPCI { |
| 36 | VirtIOPCIProxy parent_obj; |
| 37 | VirtIOInputHID vdev; |
| 38 | }; |
| 39 | |
| 40 | static Property virtio_input_pci_properties[] = { |
| 41 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), |
| 42 | DEFINE_PROP_END_OF_LIST(), |
| 43 | }; |
| 44 | |
| 45 | static 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 Gilbert | dd56040 | 2019-07-29 17:29:03 +0100 | [diff] [blame] | 50 | virtio_pci_force_virtio_1(vpci_dev); |
Markus Armbruster | 99ba777 | 2020-06-10 07:32:00 +0200 | [diff] [blame] | 51 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static 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é Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 60 | device_class_set_props(dc, virtio_input_pci_properties); |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 61 | 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 | |
| 67 | static 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 | |
| 74 | static 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 | |
| 82 | static 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 | |
| 90 | static 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 | |
| 98 | static 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 Lopez | 4b2321c | 2023-05-26 13:29:23 +0200 | [diff] [blame] | 106 | static 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 Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 114 | static 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 | |
| 122 | static 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 | |
| 129 | static 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 | |
| 137 | static 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 | |
| 145 | static 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 Lopez | 4b2321c | 2023-05-26 13:29:23 +0200 | [diff] [blame] | 152 | static 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 Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 159 | static 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 Lopez | 4b2321c | 2023-05-26 13:29:23 +0200 | [diff] [blame] | 169 | virtio_pci_types_register(&virtio_multitouch_pci_info); |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | type_init(virtio_pci_input_register) |