1 /* SPDX-License-Identifier: MIT */
3 * kbdif.h -- Xen virtual keyboard/mouse
5 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
6 * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
9 #ifndef __XEN_PUBLIC_IO_KBDIF_H__
10 #define __XEN_PUBLIC_IO_KBDIF_H__
13 *****************************************************************************
14 * Feature and Parameter Negotiation
15 *****************************************************************************
17 * The two halves of a para-virtual driver utilize nodes within
18 * XenStore to communicate capabilities and to negotiate operating parameters.
19 * This section enumerates these nodes which reside in the respective front and
20 * backend portions of XenStore, following XenBus convention.
22 * All data in XenStore is stored as strings. Nodes specifying numeric
23 * values are encoded in decimal. Integer value ranges listed below are
24 * expressed as fixed sized integer types capable of storing the conversion
25 * of a properly formated node string, without loss of information.
27 *****************************************************************************
28 * Backend XenBus Nodes
29 *****************************************************************************
31 *---------------------------- Features supported ----------------------------
33 * Capable backend advertises supported features by publishing
34 * corresponding entries in XenStore and puts 1 as the value of the entry.
35 * If a feature is not supported then 0 must be set or feature entry omitted.
37 * feature-disable-keyboard
40 * If there is no need to expose a virtual keyboard device by the
41 * frontend then this must be set to 1.
43 * feature-disable-pointer
46 * If there is no need to expose a virtual pointer device by the
47 * frontend then this must be set to 1.
52 * Backends, which support reporting of absolute coordinates for pointer
53 * device should set this to 1.
58 * Backends, which support reporting of multi-touch events
59 * should set this to 1.
64 * Backends, which support reporting raw (unscaled) absolute coordinates
65 * for pointer devices should set this to 1. Raw (unscaled) values have
66 * a range of [0, 0x7fff].
68 *----------------------- Device Instance Parameters ------------------------
73 * After device instance initialization it is assigned a unique ID,
74 * so every instance of the frontend can be identified by the backend
75 * by this ID. This can be UUID or such.
77 *------------------------- Pointer Device Parameters ------------------------
82 * Maximum X coordinate (width) to be used by the frontend
83 * while reporting input events, pixels, [0; UINT32_MAX].
88 * Maximum Y coordinate (height) to be used by the frontend
89 * while reporting input events, pixels, [0; UINT32_MAX].
91 *----------------------- Multi-touch Device Parameters ----------------------
93 * multi-touch-num-contacts
96 * Number of simultaneous touches reported.
101 * Width of the touch area to be used by the frontend
102 * while reporting input events, pixels, [0; UINT32_MAX].
107 * Height of the touch area to be used by the frontend
108 * while reporting input events, pixels, [0; UINT32_MAX].
110 *****************************************************************************
111 * Frontend XenBus Nodes
112 *****************************************************************************
114 *------------------------------ Feature request -----------------------------
116 * Capable frontend requests features from backend via setting corresponding
117 * entries to 1 in XenStore. Requests for features not advertised as supported
118 * by the backend have no effect.
120 * request-abs-pointer
123 * Request backend to report absolute pointer coordinates
124 * (XENKBD_TYPE_POS) instead of relative ones (XENKBD_TYPE_MOTION).
126 * request-multi-touch
129 * Request backend to report multi-touch events.
131 * request-raw-pointer
134 * Request backend to report raw unscaled absolute pointer coordinates.
135 * This option is only valid if request-abs-pointer is also set.
136 * Raw unscaled coordinates have the range [0, 0x7fff]
138 *----------------------- Request Transport Parameters -----------------------
143 * The identifier of the Xen event channel used to signal activity
144 * in the ring buffer.
149 * The Xen grant reference granting permission for the backend to map
150 * a sole page in a single page sized event ring buffer.
155 * OBSOLETE, not recommended for use.
156 * PFN of the shared page.
163 #define XENKBD_TYPE_MOTION 1
164 #define XENKBD_TYPE_RESERVED 2
165 #define XENKBD_TYPE_KEY 3
166 #define XENKBD_TYPE_POS 4
167 #define XENKBD_TYPE_MTOUCH 5
169 /* Multi-touch event sub-codes */
171 #define XENKBD_MT_EV_DOWN 0
172 #define XENKBD_MT_EV_UP 1
173 #define XENKBD_MT_EV_MOTION 2
174 #define XENKBD_MT_EV_SYN 3
175 #define XENKBD_MT_EV_SHAPE 4
176 #define XENKBD_MT_EV_ORIENT 5
179 * CONSTANTS, XENSTORE FIELD AND PATH NAME STRINGS, HELPERS.
182 #define XENKBD_DRIVER_NAME "vkbd"
184 #define XENKBD_FIELD_FEAT_DSBL_KEYBRD "feature-disable-keyboard"
185 #define XENKBD_FIELD_FEAT_DSBL_POINTER "feature-disable-pointer"
186 #define XENKBD_FIELD_FEAT_ABS_POINTER "feature-abs-pointer"
187 #define XENKBD_FIELD_FEAT_RAW_POINTER "feature-raw-pointer"
188 #define XENKBD_FIELD_FEAT_MTOUCH "feature-multi-touch"
189 #define XENKBD_FIELD_REQ_ABS_POINTER "request-abs-pointer"
190 #define XENKBD_FIELD_REQ_RAW_POINTER "request-raw-pointer"
191 #define XENKBD_FIELD_REQ_MTOUCH "request-multi-touch"
192 #define XENKBD_FIELD_RING_GREF "page-gref"
193 #define XENKBD_FIELD_EVT_CHANNEL "event-channel"
194 #define XENKBD_FIELD_WIDTH "width"
195 #define XENKBD_FIELD_HEIGHT "height"
196 #define XENKBD_FIELD_MT_WIDTH "multi-touch-width"
197 #define XENKBD_FIELD_MT_HEIGHT "multi-touch-height"
198 #define XENKBD_FIELD_MT_NUM_CONTACTS "multi-touch-num-contacts"
199 #define XENKBD_FIELD_UNIQUE_ID "unique-id"
201 /* OBSOLETE, not recommended for use */
202 #define XENKBD_FIELD_RING_REF "page-ref"
205 *****************************************************************************
206 * Description of the protocol between frontend and backend driver.
207 *****************************************************************************
209 * The two halves of a Para-virtual driver communicate with
210 * each other using a shared page and an event channel.
211 * Shared page contains a ring with event structures.
213 * All reserved fields in the structures below must be 0.
215 *****************************************************************************
216 * Backend to frontend events
217 *****************************************************************************
219 * Frontends should ignore unknown in events.
220 * All event packets have the same length (40 octets)
221 * All event packets have common header:
224 * +-----------------+
226 * +-----------------+
227 * type - uint8_t, event code, XENKBD_TYPE_???
230 * Pointer relative movement event
232 * +----------------+----------------+----------------+----------------+
233 * | _TYPE_MOTION | reserved | 4
234 * +----------------+----------------+----------------+----------------+
236 * +----------------+----------------+----------------+----------------+
238 * +----------------+----------------+----------------+----------------+
240 * +----------------+----------------+----------------+----------------+
242 * +----------------+----------------+----------------+----------------+
243 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
244 * +----------------+----------------+----------------+----------------+
246 * +----------------+----------------+----------------+----------------+
248 * rel_x - int32_t, relative X motion
249 * rel_y - int32_t, relative Y motion
250 * rel_z - int32_t, relative Z motion (wheel)
262 * Key event (includes pointer buttons)
264 * +----------------+----------------+----------------+----------------+
265 * | _TYPE_KEY | pressed | reserved | 4
266 * +----------------+----------------+----------------+----------------+
268 * +----------------+----------------+----------------+----------------+
270 * +----------------+----------------+----------------+----------------+
271 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
272 * +----------------+----------------+----------------+----------------+
274 * +----------------+----------------+----------------+----------------+
276 * pressed - uint8_t, 1 if pressed; 0 otherwise
277 * keycode - uint32_t, KEY_* from linux/input.h
288 * Pointer absolute position event
290 * +----------------+----------------+----------------+----------------+
291 * | _TYPE_POS | reserved | 4
292 * +----------------+----------------+----------------+----------------+
294 * +----------------+----------------+----------------+----------------+
296 * +----------------+----------------+----------------+----------------+
298 * +----------------+----------------+----------------+----------------+
300 * +----------------+----------------+----------------+----------------+
301 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
302 * +----------------+----------------+----------------+----------------+
304 * +----------------+----------------+----------------+----------------+
306 * abs_x - int32_t, absolute X position (in FB pixels)
307 * abs_y - int32_t, absolute Y position (in FB pixels)
308 * rel_z - int32_t, relative Z motion (wheel)
311 struct xenkbd_position
320 * Multi-touch event and its sub-types
322 * All multi-touch event packets have common header:
325 * +----------------+----------------+----------------+----------------+
326 * | _TYPE_MTOUCH | event_type | contact_id | reserved | 4
327 * +----------------+----------------+----------------+----------------+
329 * +----------------+----------------+----------------+----------------+
331 * event_type - unt8_t, multi-touch event sub-type, XENKBD_MT_EV_???
332 * contact_id - unt8_t, ID of the contact
334 * Touch interactions can consist of one or more contacts.
335 * For each contact, a series of events is generated, starting
336 * with a down event, followed by zero or more motion events,
337 * and ending with an up event. Events relating to the same
338 * contact point can be identified by the ID of the sequence: contact ID.
339 * Contact ID may be reused after XENKBD_MT_EV_UP event and
340 * is in the [0; XENKBD_FIELD_NUM_CONTACTS - 1] range.
342 * For further information please refer to documentation on Wayland [1],
343 * Linux [2] and Windows [3] multi-touch support.
345 * [1] https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml
346 * [2] https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt
347 * [3] https://msdn.microsoft.com/en-us/library/jj151564(v=vs.85).aspx
350 * Multi-touch down event - sent when a new touch is made: touch is assigned
351 * a unique contact ID, sent with this and consequent events related
354 * +----------------+----------------+----------------+----------------+
355 * | _TYPE_MTOUCH | _MT_EV_DOWN | contact_id | reserved | 4
356 * +----------------+----------------+----------------+----------------+
358 * +----------------+----------------+----------------+----------------+
360 * +----------------+----------------+----------------+----------------+
362 * +----------------+----------------+----------------+----------------+
364 * +----------------+----------------+----------------+----------------+
365 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
366 * +----------------+----------------+----------------+----------------+
368 * +----------------+----------------+----------------+----------------+
370 * abs_x - int32_t, absolute X position, in pixels
371 * abs_y - int32_t, absolute Y position, in pixels
373 * Multi-touch contact release event
375 * +----------------+----------------+----------------+----------------+
376 * | _TYPE_MTOUCH | _MT_EV_UP | contact_id | reserved | 4
377 * +----------------+----------------+----------------+----------------+
379 * +----------------+----------------+----------------+----------------+
380 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
381 * +----------------+----------------+----------------+----------------+
383 * +----------------+----------------+----------------+----------------+
385 * Multi-touch motion event
387 * +----------------+----------------+----------------+----------------+
388 * | _TYPE_MTOUCH | _MT_EV_MOTION | contact_id | reserved | 4
389 * +----------------+----------------+----------------+----------------+
391 * +----------------+----------------+----------------+----------------+
393 * +----------------+----------------+----------------+----------------+
395 * +----------------+----------------+----------------+----------------+
397 * +----------------+----------------+----------------+----------------+
398 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
399 * +----------------+----------------+----------------+----------------+
401 * +----------------+----------------+----------------+----------------+
403 * abs_x - int32_t, absolute X position, in pixels,
404 * abs_y - int32_t, absolute Y position, in pixels,
406 * Multi-touch input synchronization event - shows end of a set of events
407 * which logically belong together.
409 * +----------------+----------------+----------------+----------------+
410 * | _TYPE_MTOUCH | _MT_EV_SYN | contact_id | reserved | 4
411 * +----------------+----------------+----------------+----------------+
413 * +----------------+----------------+----------------+----------------+
414 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
415 * +----------------+----------------+----------------+----------------+
417 * +----------------+----------------+----------------+----------------+
419 * Multi-touch shape event - touch point's shape has changed its shape.
420 * Shape is approximated by an ellipse through the major and minor axis
421 * lengths: major is the longer diameter of the ellipse and minor is the
422 * shorter one. Center of the ellipse is reported via
423 * XENKBD_MT_EV_DOWN/XENKBD_MT_EV_MOTION events.
425 * +----------------+----------------+----------------+----------------+
426 * | _TYPE_MTOUCH | _MT_EV_SHAPE | contact_id | reserved | 4
427 * +----------------+----------------+----------------+----------------+
429 * +----------------+----------------+----------------+----------------+
431 * +----------------+----------------+----------------+----------------+
433 * +----------------+----------------+----------------+----------------+
435 * +----------------+----------------+----------------+----------------+
436 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
437 * +----------------+----------------+----------------+----------------+
439 * +----------------+----------------+----------------+----------------+
441 * major - unt32_t, length of the major axis, pixels
442 * minor - unt32_t, length of the minor axis, pixels
444 * Multi-touch orientation event - touch point's shape has changed
445 * its orientation: calculated as a clockwise angle between the major axis
446 * of the ellipse and positive Y axis in degrees, [-180; +180].
448 * +----------------+----------------+----------------+----------------+
449 * | _TYPE_MTOUCH | _MT_EV_ORIENT | contact_id | reserved | 4
450 * +----------------+----------------+----------------+----------------+
452 * +----------------+----------------+----------------+----------------+
453 * | orientation | reserved | 12
454 * +----------------+----------------+----------------+----------------+
456 * +----------------+----------------+----------------+----------------+
457 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
458 * +----------------+----------------+----------------+----------------+
460 * +----------------+----------------+----------------+----------------+
462 * orientation - int16_t, clockwise angle of the major axis
465 struct xenkbd_mtouch
{
466 uint8_t type
; /* XENKBD_TYPE_MTOUCH */
467 uint8_t event_type
; /* XENKBD_MT_EV_??? */
469 uint8_t reserved
[5]; /* reserved for the future use */
472 int32_t abs_x
; /* absolute X position, pixels */
473 int32_t abs_y
; /* absolute Y position, pixels */
476 uint32_t major
; /* length of the major axis, pixels */
477 uint32_t minor
; /* length of the minor axis, pixels */
479 int16_t orientation
; /* clockwise angle of the major axis */
483 #define XENKBD_IN_EVENT_SIZE 40
485 union xenkbd_in_event
488 struct xenkbd_motion motion
;
489 struct xenkbd_key key
;
490 struct xenkbd_position pos
;
491 struct xenkbd_mtouch mtouch
;
492 char pad
[XENKBD_IN_EVENT_SIZE
];
496 *****************************************************************************
497 * Frontend to backend events
498 *****************************************************************************
500 * Out events may be sent only when requested by backend, and receipt
501 * of an unknown out event is an error.
502 * No out events currently defined.
504 * All event packets have the same length (40 octets)
505 * All event packets have common header:
507 * +-----------------+
509 * +-----------------+
510 * type - uint8_t, event code
513 #define XENKBD_OUT_EVENT_SIZE 40
515 union xenkbd_out_event
518 char pad
[XENKBD_OUT_EVENT_SIZE
];
522 *****************************************************************************
524 *****************************************************************************
527 #define XENKBD_IN_RING_SIZE 2048
528 #define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE)
529 #define XENKBD_IN_RING_OFFS 1024
530 #define XENKBD_IN_RING(page) \
531 ((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS))
532 #define XENKBD_IN_RING_REF(page, idx) \
533 (XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN])
535 #define XENKBD_OUT_RING_SIZE 1024
536 #define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE)
537 #define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE)
538 #define XENKBD_OUT_RING(page) \
539 ((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS))
540 #define XENKBD_OUT_RING_REF(page, idx) \
541 (XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN])
545 uint32_t in_cons
, in_prod
;
546 uint32_t out_cons
, out_prod
;
549 #endif /* __XEN_PUBLIC_IO_KBDIF_H__ */
554 * c-file-style: "BSD"
557 * indent-tabs-mode: nil