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