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