| 1 | #ifndef QEMU_VIRTIO_INPUT_H |
| 2 | #define QEMU_VIRTIO_INPUT_H |
| 3 | |
| 4 | #include "hw/virtio/vhost-user.h" |
| 5 | #include "hw/virtio/vhost-user-base.h" |
| 6 | #include "ui/input.h" |
| 7 | #include "system/vhost-user-backend.h" |
| 8 | |
| 9 | /* ----------------------------------------------------------------- */ |
| 10 | /* virtio input protocol */ |
| 11 | |
| 12 | #include "standard-headers/linux/virtio_ids.h" |
| 13 | #include "standard-headers/linux/virtio_input.h" |
| 14 | #include "qom/object.h" |
| 15 | |
| 16 | typedef struct virtio_input_absinfo virtio_input_absinfo; |
| 17 | typedef struct virtio_input_config virtio_input_config; |
| 18 | typedef struct virtio_input_event virtio_input_event; |
| 19 | |
| 20 | /* ----------------------------------------------------------------- */ |
| 21 | /* qemu internals */ |
| 22 | |
| 23 | #define TYPE_VIRTIO_INPUT "virtio-input-device" |
| 24 | OBJECT_DECLARE_TYPE(VirtIOInput, VirtIOInputClass, |
| 25 | VIRTIO_INPUT) |
| 26 | #define VIRTIO_INPUT_GET_PARENT_CLASS(obj) \ |
| 27 | OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT) |
| 28 | |
| 29 | #define TYPE_VIRTIO_INPUT_HID "virtio-input-hid-device" |
| 30 | #define TYPE_VIRTIO_KEYBOARD "virtio-keyboard-device" |
| 31 | #define TYPE_VIRTIO_MOUSE "virtio-mouse-device" |
| 32 | #define TYPE_VIRTIO_TABLET "virtio-tablet-device" |
| 33 | #define TYPE_VIRTIO_MULTITOUCH "virtio-multitouch-device" |
| 34 | |
| 35 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHID, VIRTIO_INPUT_HID) |
| 36 | #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \ |
| 37 | OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HID) |
| 38 | |
| 39 | #define TYPE_VIRTIO_INPUT_HOST "virtio-input-host-device" |
| 40 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHost, VIRTIO_INPUT_HOST) |
| 41 | #define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \ |
| 42 | OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST) |
| 43 | |
| 44 | #define TYPE_VHOST_USER_INPUT "vhost-user-input" |
| 45 | OBJECT_DECLARE_SIMPLE_TYPE(VHostUserInput, VHOST_USER_INPUT) |
| 46 | #define VHOST_USER_INPUT_GET_PARENT_CLASS(obj) \ |
| 47 | OBJECT_GET_PARENT_CLASS(obj, TYPE_VHOST_USER_INPUT) |
| 48 | |
| 49 | typedef struct VirtIOInputConfig VirtIOInputConfig; |
| 50 | |
| 51 | struct VirtIOInputConfig { |
| 52 | virtio_input_config config; |
| 53 | QTAILQ_ENTRY(VirtIOInputConfig) node; |
| 54 | }; |
| 55 | |
| 56 | struct VirtIOInput { |
| 57 | VirtIODevice parent_obj; |
| 58 | uint8_t cfg_select; |
| 59 | uint8_t cfg_subsel; |
| 60 | uint32_t cfg_size; |
| 61 | QTAILQ_HEAD(, VirtIOInputConfig) cfg_list; |
| 62 | VirtQueue *evt, *sts; |
| 63 | char *serial; |
| 64 | |
| 65 | struct { |
| 66 | virtio_input_event event; |
| 67 | VirtQueueElement *elem; |
| 68 | } *queue; |
| 69 | uint32_t qindex, qsize; |
| 70 | |
| 71 | bool active; |
| 72 | }; |
| 73 | |
| 74 | struct VirtIOInputClass { |
| 75 | /*< private >*/ |
| 76 | VirtioDeviceClass parent; |
| 77 | /*< public >*/ |
| 78 | |
| 79 | DeviceRealize realize; |
| 80 | DeviceUnrealize unrealize; |
| 81 | void (*change_active)(VirtIOInput *vinput); |
| 82 | void (*handle_status)(VirtIOInput *vinput, virtio_input_event *event); |
| 83 | }; |
| 84 | |
| 85 | struct VirtIOInputHID { |
| 86 | VirtIOInput parent_obj; |
| 87 | char *display; |
| 88 | uint32_t head; |
| 89 | const QemuInputHandler *handler; |
| 90 | QemuInputHandlerState *hs; |
| 91 | int ledstate; |
| 92 | }; |
| 93 | |
| 94 | struct VirtIOInputHost { |
| 95 | VirtIOInput parent_obj; |
| 96 | char *evdev; |
| 97 | int fd; |
| 98 | }; |
| 99 | |
| 100 | struct VHostUserInput { |
| 101 | VHostUserBase parent_obj; |
| 102 | }; |
| 103 | |
| 104 | void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event); |
| 105 | void virtio_input_init_config(VirtIOInput *vinput, |
| 106 | virtio_input_config *config); |
| 107 | virtio_input_config *virtio_input_find_config(VirtIOInput *vinput, |
| 108 | uint8_t select, |
| 109 | uint8_t subsel); |
| 110 | void virtio_input_add_config(VirtIOInput *vinput, |
| 111 | virtio_input_config *config); |
| 112 | void virtio_input_idstr_config(VirtIOInput *vinput, |
| 113 | uint8_t select, const char *string); |
| 114 | |
| 115 | #endif /* QEMU_VIRTIO_INPUT_H */ |