2 * kbdif.h -- Xen virtual keyboard/mouse
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
22 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
23 * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
26 #ifndef __XEN_PUBLIC_IO_KBDIF_H__
27 #define __XEN_PUBLIC_IO_KBDIF_H__
30 *****************************************************************************
31 * Feature and Parameter Negotiation
32 *****************************************************************************
34 * The two halves of a para-virtual driver utilize nodes within
35 * XenStore to communicate capabilities and to negotiate operating parameters.
36 * This section enumerates these nodes which reside in the respective front and
37 * backend portions of XenStore, following XenBus convention.
39 * All data in XenStore is stored as strings. Nodes specifying numeric
40 * values are encoded in decimal. Integer value ranges listed below are
41 * expressed as fixed sized integer types capable of storing the conversion
42 * of a properly formated node string, without loss of information.
44 *****************************************************************************
45 * Backend XenBus Nodes
46 *****************************************************************************
48 *---------------------------- Features supported ----------------------------
50 * Capable backend advertises supported features by publishing
51 * corresponding entries in XenStore and puts 1 as the value of the entry.
52 * If a feature is not supported then 0 must be set or feature entry omitted.
54 * feature-disable-keyboard
57 * If there is no need to expose a virtual keyboard device by the
58 * frontend then this must be set to 1.
60 * feature-disable-pointer
63 * If there is no need to expose a virtual pointer device by the
64 * frontend then this must be set to 1.
69 * Backends, which support reporting of absolute coordinates for pointer
70 * device should set this to 1.
75 * Backends, which support reporting of multi-touch events
76 * should set this to 1.
81 * Backends, which support reporting raw (unscaled) absolute coordinates
82 * for pointer devices should set this to 1. Raw (unscaled) values have
83 * a range of [0, 0x7fff].
85 *----------------------- Device Instance Parameters ------------------------
90 * After device instance initialization it is assigned a unique ID,
91 * so every instance of the frontend can be identified by the backend
92 * by this ID. This can be UUID or such.
94 *------------------------- Pointer Device Parameters ------------------------
99 * Maximum X coordinate (width) to be used by the frontend
100 * while reporting input events, pixels, [0; UINT32_MAX].
105 * Maximum Y coordinate (height) to be used by the frontend
106 * while reporting input events, pixels, [0; UINT32_MAX].
108 *----------------------- Multi-touch Device Parameters ----------------------
110 * multi-touch-num-contacts
113 * Number of simultaneous touches reported.
118 * Width of the touch area to be used by the frontend
119 * while reporting input events, pixels, [0; UINT32_MAX].
124 * Height of the touch area to be used by the frontend
125 * while reporting input events, pixels, [0; UINT32_MAX].
127 *****************************************************************************
128 * Frontend XenBus Nodes
129 *****************************************************************************
131 *------------------------------ Feature request -----------------------------
133 * Capable frontend requests features from backend via setting corresponding
134 * entries to 1 in XenStore. Requests for features not advertised as supported
135 * by the backend have no effect.
137 * request-abs-pointer
140 * Request backend to report absolute pointer coordinates
141 * (XENKBD_TYPE_POS) instead of relative ones (XENKBD_TYPE_MOTION).
143 * request-multi-touch
146 * Request backend to report multi-touch events.
148 * request-raw-pointer
151 * Request backend to report raw unscaled absolute pointer coordinates.
152 * This option is only valid if request-abs-pointer is also set.
153 * Raw unscaled coordinates have the range [0, 0x7fff]
155 *----------------------- Request Transport Parameters -----------------------
160 * The identifier of the Xen event channel used to signal activity
161 * in the ring buffer.
166 * The Xen grant reference granting permission for the backend to map
167 * a sole page in a single page sized event ring buffer.
172 * OBSOLETE, not recommended for use.
173 * PFN of the shared page.
180 #define XENKBD_TYPE_MOTION 1
181 #define XENKBD_TYPE_RESERVED 2
182 #define XENKBD_TYPE_KEY 3
183 #define XENKBD_TYPE_POS 4
184 #define XENKBD_TYPE_MTOUCH 5
186 /* Multi-touch event sub-codes */
188 #define XENKBD_MT_EV_DOWN 0
189 #define XENKBD_MT_EV_UP 1
190 #define XENKBD_MT_EV_MOTION 2
191 #define XENKBD_MT_EV_SYN 3
192 #define XENKBD_MT_EV_SHAPE 4
193 #define XENKBD_MT_EV_ORIENT 5
196 * CONSTANTS, XENSTORE FIELD AND PATH NAME STRINGS, HELPERS.
199 #define XENKBD_DRIVER_NAME "vkbd"
201 #define XENKBD_FIELD_FEAT_DSBL_KEYBRD "feature-disable-keyboard"
202 #define XENKBD_FIELD_FEAT_DSBL_POINTER "feature-disable-pointer"
203 #define XENKBD_FIELD_FEAT_ABS_POINTER "feature-abs-pointer"
204 #define XENKBD_FIELD_FEAT_RAW_POINTER "feature-raw-pointer"
205 #define XENKBD_FIELD_FEAT_MTOUCH "feature-multi-touch"
206 #define XENKBD_FIELD_REQ_ABS_POINTER "request-abs-pointer"
207 #define XENKBD_FIELD_REQ_RAW_POINTER "request-raw-pointer"
208 #define XENKBD_FIELD_REQ_MTOUCH "request-multi-touch"
209 #define XENKBD_FIELD_RING_GREF "page-gref"
210 #define XENKBD_FIELD_EVT_CHANNEL "event-channel"
211 #define XENKBD_FIELD_WIDTH "width"
212 #define XENKBD_FIELD_HEIGHT "height"
213 #define XENKBD_FIELD_MT_WIDTH "multi-touch-width"
214 #define XENKBD_FIELD_MT_HEIGHT "multi-touch-height"
215 #define XENKBD_FIELD_MT_NUM_CONTACTS "multi-touch-num-contacts"
216 #define XENKBD_FIELD_UNIQUE_ID "unique-id"
218 /* OBSOLETE, not recommended for use */
219 #define XENKBD_FIELD_RING_REF "page-ref"
222 *****************************************************************************
223 * Description of the protocol between frontend and backend driver.
224 *****************************************************************************
226 * The two halves of a Para-virtual driver communicate with
227 * each other using a shared page and an event channel.
228 * Shared page contains a ring with event structures.
230 * All reserved fields in the structures below must be 0.
232 *****************************************************************************
233 * Backend to frontend events
234 *****************************************************************************
236 * Frontends should ignore unknown in events.
237 * All event packets have the same length (40 octets)
238 * All event packets have common header:
241 * +-----------------+
243 * +-----------------+
244 * type - uint8_t, event code, XENKBD_TYPE_???
247 * Pointer relative movement event
249 * +----------------+----------------+----------------+----------------+
250 * | _TYPE_MOTION | reserved | 4
251 * +----------------+----------------+----------------+----------------+
253 * +----------------+----------------+----------------+----------------+
255 * +----------------+----------------+----------------+----------------+
257 * +----------------+----------------+----------------+----------------+
259 * +----------------+----------------+----------------+----------------+
260 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
261 * +----------------+----------------+----------------+----------------+
263 * +----------------+----------------+----------------+----------------+
265 * rel_x - int32_t, relative X motion
266 * rel_y - int32_t, relative Y motion
267 * rel_z - int32_t, relative Z motion (wheel)
270 struct xenkbd_motion
{
278 * Key event (includes pointer buttons)
280 * +----------------+----------------+----------------+----------------+
281 * | _TYPE_KEY | pressed | reserved | 4
282 * +----------------+----------------+----------------+----------------+
284 * +----------------+----------------+----------------+----------------+
286 * +----------------+----------------+----------------+----------------+
287 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
288 * +----------------+----------------+----------------+----------------+
290 * +----------------+----------------+----------------+----------------+
292 * pressed - uint8_t, 1 if pressed; 0 otherwise
293 * keycode - uint32_t, KEY_* from linux/input.h
303 * Pointer absolute position event
305 * +----------------+----------------+----------------+----------------+
306 * | _TYPE_POS | reserved | 4
307 * +----------------+----------------+----------------+----------------+
309 * +----------------+----------------+----------------+----------------+
311 * +----------------+----------------+----------------+----------------+
313 * +----------------+----------------+----------------+----------------+
315 * +----------------+----------------+----------------+----------------+
316 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
317 * +----------------+----------------+----------------+----------------+
319 * +----------------+----------------+----------------+----------------+
321 * abs_x - int32_t, absolute X position (in FB pixels)
322 * abs_y - int32_t, absolute Y position (in FB pixels)
323 * rel_z - int32_t, relative Z motion (wheel)
326 struct xenkbd_position
{
334 * Multi-touch event and its sub-types
336 * All multi-touch event packets have common header:
339 * +----------------+----------------+----------------+----------------+
340 * | _TYPE_MTOUCH | event_type | contact_id | reserved | 4
341 * +----------------+----------------+----------------+----------------+
343 * +----------------+----------------+----------------+----------------+
345 * event_type - unt8_t, multi-touch event sub-type, XENKBD_MT_EV_???
346 * contact_id - unt8_t, ID of the contact
348 * Touch interactions can consist of one or more contacts.
349 * For each contact, a series of events is generated, starting
350 * with a down event, followed by zero or more motion events,
351 * and ending with an up event. Events relating to the same
352 * contact point can be identified by the ID of the sequence: contact ID.
353 * Contact ID may be reused after XENKBD_MT_EV_UP event and
354 * is in the [0; XENKBD_FIELD_NUM_CONTACTS - 1] range.
356 * For further information please refer to documentation on Wayland [1],
357 * Linux [2] and Windows [3] multi-touch support.
359 * [1] https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml
360 * [2] https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.rst
361 * [3] https://msdn.microsoft.com/en-us/library/jj151564(v=vs.85).aspx
364 * Multi-touch down event - sent when a new touch is made: touch is assigned
365 * a unique contact ID, sent with this and consequent events related
368 * +----------------+----------------+----------------+----------------+
369 * | _TYPE_MTOUCH | _MT_EV_DOWN | contact_id | reserved | 4
370 * +----------------+----------------+----------------+----------------+
372 * +----------------+----------------+----------------+----------------+
374 * +----------------+----------------+----------------+----------------+
376 * +----------------+----------------+----------------+----------------+
378 * +----------------+----------------+----------------+----------------+
379 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
380 * +----------------+----------------+----------------+----------------+
382 * +----------------+----------------+----------------+----------------+
384 * abs_x - int32_t, absolute X position, in pixels
385 * abs_y - int32_t, absolute Y position, in pixels
387 * Multi-touch contact release event
389 * +----------------+----------------+----------------+----------------+
390 * | _TYPE_MTOUCH | _MT_EV_UP | contact_id | reserved | 4
391 * +----------------+----------------+----------------+----------------+
393 * +----------------+----------------+----------------+----------------+
394 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
395 * +----------------+----------------+----------------+----------------+
397 * +----------------+----------------+----------------+----------------+
399 * Multi-touch motion event
401 * +----------------+----------------+----------------+----------------+
402 * | _TYPE_MTOUCH | _MT_EV_MOTION | contact_id | reserved | 4
403 * +----------------+----------------+----------------+----------------+
405 * +----------------+----------------+----------------+----------------+
407 * +----------------+----------------+----------------+----------------+
409 * +----------------+----------------+----------------+----------------+
411 * +----------------+----------------+----------------+----------------+
412 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
413 * +----------------+----------------+----------------+----------------+
415 * +----------------+----------------+----------------+----------------+
417 * abs_x - int32_t, absolute X position, in pixels,
418 * abs_y - int32_t, absolute Y position, in pixels,
420 * Multi-touch input synchronization event - shows end of a set of events
421 * which logically belong together.
423 * +----------------+----------------+----------------+----------------+
424 * | _TYPE_MTOUCH | _MT_EV_SYN | contact_id | reserved | 4
425 * +----------------+----------------+----------------+----------------+
427 * +----------------+----------------+----------------+----------------+
428 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
429 * +----------------+----------------+----------------+----------------+
431 * +----------------+----------------+----------------+----------------+
433 * Multi-touch shape event - touch point's shape has changed its shape.
434 * Shape is approximated by an ellipse through the major and minor axis
435 * lengths: major is the longer diameter of the ellipse and minor is the
436 * shorter one. Center of the ellipse is reported via
437 * XENKBD_MT_EV_DOWN/XENKBD_MT_EV_MOTION events.
439 * +----------------+----------------+----------------+----------------+
440 * | _TYPE_MTOUCH | _MT_EV_SHAPE | contact_id | reserved | 4
441 * +----------------+----------------+----------------+----------------+
443 * +----------------+----------------+----------------+----------------+
445 * +----------------+----------------+----------------+----------------+
447 * +----------------+----------------+----------------+----------------+
449 * +----------------+----------------+----------------+----------------+
450 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
451 * +----------------+----------------+----------------+----------------+
453 * +----------------+----------------+----------------+----------------+
455 * major - unt32_t, length of the major axis, pixels
456 * minor - unt32_t, length of the minor axis, pixels
458 * Multi-touch orientation event - touch point's shape has changed
459 * its orientation: calculated as a clockwise angle between the major axis
460 * of the ellipse and positive Y axis in degrees, [-180; +180].
462 * +----------------+----------------+----------------+----------------+
463 * | _TYPE_MTOUCH | _MT_EV_ORIENT | contact_id | reserved | 4
464 * +----------------+----------------+----------------+----------------+
466 * +----------------+----------------+----------------+----------------+
467 * | orientation | reserved | 12
468 * +----------------+----------------+----------------+----------------+
470 * +----------------+----------------+----------------+----------------+
471 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
472 * +----------------+----------------+----------------+----------------+
474 * +----------------+----------------+----------------+----------------+
476 * orientation - int16_t, clockwise angle of the major axis
479 struct xenkbd_mtouch
{
480 uint8_t type
; /* XENKBD_TYPE_MTOUCH */
481 uint8_t event_type
; /* XENKBD_MT_EV_??? */
483 uint8_t reserved
[5]; /* reserved for the future use */
486 int32_t abs_x
; /* absolute X position, pixels */
487 int32_t abs_y
; /* absolute Y position, pixels */
490 uint32_t major
; /* length of the major axis, pixels */
491 uint32_t minor
; /* length of the minor axis, pixels */
493 int16_t orientation
; /* clockwise angle of the major axis */
497 #define XENKBD_IN_EVENT_SIZE 40
499 union xenkbd_in_event
{
501 struct xenkbd_motion motion
;
502 struct xenkbd_key key
;
503 struct xenkbd_position pos
;
504 struct xenkbd_mtouch mtouch
;
505 char pad
[XENKBD_IN_EVENT_SIZE
];
509 *****************************************************************************
510 * Frontend to backend events
511 *****************************************************************************
513 * Out events may be sent only when requested by backend, and receipt
514 * of an unknown out event is an error.
515 * No out events currently defined.
517 * All event packets have the same length (40 octets)
518 * All event packets have common header:
520 * +-----------------+
522 * +-----------------+
523 * type - uint8_t, event code
526 #define XENKBD_OUT_EVENT_SIZE 40
528 union xenkbd_out_event
{
530 char pad
[XENKBD_OUT_EVENT_SIZE
];
534 *****************************************************************************
536 *****************************************************************************
539 #define XENKBD_IN_RING_SIZE 2048
540 #define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE)
541 #define XENKBD_IN_RING_OFFS 1024
542 #define XENKBD_IN_RING(page) \
543 ((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS))
544 #define XENKBD_IN_RING_REF(page, idx) \
545 (XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN])
547 #define XENKBD_OUT_RING_SIZE 1024
548 #define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE)
549 #define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE)
550 #define XENKBD_OUT_RING(page) \
551 ((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS))
552 #define XENKBD_OUT_RING_REF(page, idx) \
553 (XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN])
556 uint32_t in_cons
, in_prod
;
557 uint32_t out_cons
, out_prod
;
560 #endif /* __XEN_PUBLIC_IO_KBDIF_H__ */