xref: /qemu/include/hw/virtio/virtio-input.h (revision e3a6e0da)
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 OBJECT_DECLARE_TYPE(VirtIOInput, VirtIOInputClass,
23                     virtio_input, VIRTIO_INPUT)
24 #define VIRTIO_INPUT_GET_PARENT_CLASS(obj) \
25         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT)
26 
27 #define TYPE_VIRTIO_INPUT_HID "virtio-input-hid-device"
28 #define TYPE_VIRTIO_KEYBOARD  "virtio-keyboard-device"
29 #define TYPE_VIRTIO_MOUSE     "virtio-mouse-device"
30 #define TYPE_VIRTIO_TABLET    "virtio-tablet-device"
31 
32 typedef struct VirtIOInputHID VirtIOInputHID;
33 DECLARE_INSTANCE_CHECKER(VirtIOInputHID, VIRTIO_INPUT_HID,
34                          TYPE_VIRTIO_INPUT_HID)
35 #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \
36         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HID)
37 
38 #define TYPE_VIRTIO_INPUT_HOST   "virtio-input-host-device"
39 typedef struct VirtIOInputHost VirtIOInputHost;
40 DECLARE_INSTANCE_CHECKER(VirtIOInputHost, VIRTIO_INPUT_HOST,
41                          TYPE_VIRTIO_INPUT_HOST)
42 #define VIRTIO_INPUT_HOST_GET_PARENT_CLASS(obj) \
43         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HOST)
44 
45 #define TYPE_VHOST_USER_INPUT   "vhost-user-input"
46 typedef struct VHostUserInput VHostUserInput;
47 DECLARE_INSTANCE_CHECKER(VHostUserInput, VHOST_USER_INPUT,
48                          TYPE_VHOST_USER_INPUT)
49 #define VHOST_USER_INPUT_GET_PARENT_CLASS(obj)             \
50     OBJECT_GET_PARENT_CLASS(obj, TYPE_VHOST_USER_INPUT)
51 
52 typedef struct VirtIOInputConfig VirtIOInputConfig;
53 
54 struct VirtIOInputConfig {
55     virtio_input_config               config;
56     QTAILQ_ENTRY(VirtIOInputConfig)   node;
57 };
58 
59 struct VirtIOInput {
60     VirtIODevice                      parent_obj;
61     uint8_t                           cfg_select;
62     uint8_t                           cfg_subsel;
63     uint32_t                          cfg_size;
64     QTAILQ_HEAD(, VirtIOInputConfig)  cfg_list;
65     VirtQueue                         *evt, *sts;
66     char                              *serial;
67 
68     struct {
69         virtio_input_event event;
70         VirtQueueElement *elem;
71     }                                 *queue;
72     uint32_t                          qindex, qsize;
73 
74     bool                              active;
75 };
76 
77 struct VirtIOInputClass {
78     /*< private >*/
79     VirtioDeviceClass parent;
80     /*< public >*/
81 
82     DeviceRealize realize;
83     DeviceUnrealize unrealize;
84     void (*change_active)(VirtIOInput *vinput);
85     void (*handle_status)(VirtIOInput *vinput, virtio_input_event *event);
86 };
87 
88 struct VirtIOInputHID {
89     VirtIOInput                       parent_obj;
90     char                              *display;
91     uint32_t                          head;
92     QemuInputHandler                  *handler;
93     QemuInputHandlerState             *hs;
94     int                               ledstate;
95     bool                              wheel_axis;
96 };
97 
98 struct VirtIOInputHost {
99     VirtIOInput                       parent_obj;
100     char                              *evdev;
101     int                               fd;
102 };
103 
104 struct VHostUserInput {
105     VirtIOInput                       parent_obj;
106 
107     VhostUserBackend                  *vhost;
108 };
109 
110 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event);
111 void virtio_input_init_config(VirtIOInput *vinput,
112                               virtio_input_config *config);
113 virtio_input_config *virtio_input_find_config(VirtIOInput *vinput,
114                                               uint8_t select,
115                                               uint8_t subsel);
116 void virtio_input_add_config(VirtIOInput *vinput,
117                              virtio_input_config *config);
118 void virtio_input_idstr_config(VirtIOInput *vinput,
119                                uint8_t select, const char *string);
120 
121 #endif /* QEMU_VIRTIO_INPUT_H */
122