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 | |
| 11 | #include "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 | |
| 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 Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 32 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHIDPCI, VIRTIO_INPUT_HID_PCI) |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 33 | |
| 34 | struct VirtIOInputHIDPCI { |
| 35 | VirtIOPCIProxy parent_obj; |
| 36 | VirtIOInputHID vdev; |
| 37 | }; |
| 38 | |
| 39 | static Property virtio_input_pci_properties[] = { |
| 40 | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), |
| 41 | DEFINE_PROP_END_OF_LIST(), |
| 42 | }; |
| 43 | |
| 44 | static 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 Gilbert | dd56040 | 2019-07-29 17:29:03 +0100 | [diff] [blame] | 49 | virtio_pci_force_virtio_1(vpci_dev); |
Markus Armbruster | 99ba777 | 2020-06-10 07:32:00 +0200 | [diff] [blame] | 50 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static 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é Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 59 | device_class_set_props(dc, virtio_input_pci_properties); |
Juan Quintela | 9436b8c | 2019-01-03 15:10:00 +0100 | [diff] [blame] | 60 | 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 | |
| 66 | static 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 | |
| 73 | static 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 | |
| 81 | static 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 | |
| 89 | static 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 | |
| 97 | static 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 | |
| 105 | static 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 | |
| 113 | static 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 | |
| 120 | static 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 | |
| 128 | static 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 | |
| 136 | static 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 | |
| 143 | static 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 | |
| 155 | type_init(virtio_pci_input_register) |