/* SPDX-License-Identifier: MIT */1/*2* kbdif.h -- Xen virtual keyboard/mouse3*4* Copyright (C) 2005 Anthony Liguori <[email protected]>5* Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <[email protected]>6*/78#ifndef __XEN_PUBLIC_IO_KBDIF_H__9#define __XEN_PUBLIC_IO_KBDIF_H__1011/*12*****************************************************************************13* Feature and Parameter Negotiation14*****************************************************************************15*16* The two halves of a para-virtual driver utilize nodes within17* XenStore to communicate capabilities and to negotiate operating parameters.18* This section enumerates these nodes which reside in the respective front and19* backend portions of XenStore, following XenBus convention.20*21* All data in XenStore is stored as strings. Nodes specifying numeric22* values are encoded in decimal. Integer value ranges listed below are23* expressed as fixed sized integer types capable of storing the conversion24* of a properly formated node string, without loss of information.25*26*****************************************************************************27* Backend XenBus Nodes28*****************************************************************************29*30*---------------------------- Features supported ----------------------------31*32* Capable backend advertises supported features by publishing33* corresponding entries in XenStore and puts 1 as the value of the entry.34* If a feature is not supported then 0 must be set or feature entry omitted.35*36* feature-disable-keyboard37* Values: <uint>38*39* If there is no need to expose a virtual keyboard device by the40* frontend then this must be set to 1.41*42* feature-disable-pointer43* Values: <uint>44*45* If there is no need to expose a virtual pointer device by the46* frontend then this must be set to 1.47*48* feature-abs-pointer49* Values: <uint>50*51* Backends, which support reporting of absolute coordinates for pointer52* device should set this to 1.53*54* feature-multi-touch55* Values: <uint>56*57* Backends, which support reporting of multi-touch events58* should set this to 1.59*60* feature-raw-pointer61* Values: <uint>62*63* Backends, which support reporting raw (unscaled) absolute coordinates64* for pointer devices should set this to 1. Raw (unscaled) values have65* a range of [0, 0x7fff].66*67*----------------------- Device Instance Parameters ------------------------68*69* unique-id70* Values: <string>71*72* After device instance initialization it is assigned a unique ID,73* so every instance of the frontend can be identified by the backend74* by this ID. This can be UUID or such.75*76*------------------------- Pointer Device Parameters ------------------------77*78* width79* Values: <uint>80*81* Maximum X coordinate (width) to be used by the frontend82* while reporting input events, pixels, [0; UINT32_MAX].83*84* height85* Values: <uint>86*87* Maximum Y coordinate (height) to be used by the frontend88* while reporting input events, pixels, [0; UINT32_MAX].89*90*----------------------- Multi-touch Device Parameters ----------------------91*92* multi-touch-num-contacts93* Values: <uint>94*95* Number of simultaneous touches reported.96*97* multi-touch-width98* Values: <uint>99*100* Width of the touch area to be used by the frontend101* while reporting input events, pixels, [0; UINT32_MAX].102*103* multi-touch-height104* Values: <uint>105*106* Height of the touch area to be used by the frontend107* while reporting input events, pixels, [0; UINT32_MAX].108*109*****************************************************************************110* Frontend XenBus Nodes111*****************************************************************************112*113*------------------------------ Feature request -----------------------------114*115* Capable frontend requests features from backend via setting corresponding116* entries to 1 in XenStore. Requests for features not advertised as supported117* by the backend have no effect.118*119* request-abs-pointer120* Values: <uint>121*122* Request backend to report absolute pointer coordinates123* (XENKBD_TYPE_POS) instead of relative ones (XENKBD_TYPE_MOTION).124*125* request-multi-touch126* Values: <uint>127*128* Request backend to report multi-touch events.129*130* request-raw-pointer131* Values: <uint>132*133* Request backend to report raw unscaled absolute pointer coordinates.134* This option is only valid if request-abs-pointer is also set.135* Raw unscaled coordinates have the range [0, 0x7fff]136*137*----------------------- Request Transport Parameters -----------------------138*139* event-channel140* Values: <uint>141*142* The identifier of the Xen event channel used to signal activity143* in the ring buffer.144*145* page-gref146* Values: <uint>147*148* The Xen grant reference granting permission for the backend to map149* a sole page in a single page sized event ring buffer.150*151* page-ref152* Values: <uint>153*154* OBSOLETE, not recommended for use.155* PFN of the shared page.156*/157158/*159* EVENT CODES.160*/161162#define XENKBD_TYPE_MOTION 1163#define XENKBD_TYPE_RESERVED 2164#define XENKBD_TYPE_KEY 3165#define XENKBD_TYPE_POS 4166#define XENKBD_TYPE_MTOUCH 5167168/* Multi-touch event sub-codes */169170#define XENKBD_MT_EV_DOWN 0171#define XENKBD_MT_EV_UP 1172#define XENKBD_MT_EV_MOTION 2173#define XENKBD_MT_EV_SYN 3174#define XENKBD_MT_EV_SHAPE 4175#define XENKBD_MT_EV_ORIENT 5176177/*178* CONSTANTS, XENSTORE FIELD AND PATH NAME STRINGS, HELPERS.179*/180181#define XENKBD_DRIVER_NAME "vkbd"182183#define XENKBD_FIELD_FEAT_DSBL_KEYBRD "feature-disable-keyboard"184#define XENKBD_FIELD_FEAT_DSBL_POINTER "feature-disable-pointer"185#define XENKBD_FIELD_FEAT_ABS_POINTER "feature-abs-pointer"186#define XENKBD_FIELD_FEAT_RAW_POINTER "feature-raw-pointer"187#define XENKBD_FIELD_FEAT_MTOUCH "feature-multi-touch"188#define XENKBD_FIELD_REQ_ABS_POINTER "request-abs-pointer"189#define XENKBD_FIELD_REQ_RAW_POINTER "request-raw-pointer"190#define XENKBD_FIELD_REQ_MTOUCH "request-multi-touch"191#define XENKBD_FIELD_RING_GREF "page-gref"192#define XENKBD_FIELD_EVT_CHANNEL "event-channel"193#define XENKBD_FIELD_WIDTH "width"194#define XENKBD_FIELD_HEIGHT "height"195#define XENKBD_FIELD_MT_WIDTH "multi-touch-width"196#define XENKBD_FIELD_MT_HEIGHT "multi-touch-height"197#define XENKBD_FIELD_MT_NUM_CONTACTS "multi-touch-num-contacts"198#define XENKBD_FIELD_UNIQUE_ID "unique-id"199200/* OBSOLETE, not recommended for use */201#define XENKBD_FIELD_RING_REF "page-ref"202203/*204*****************************************************************************205* Description of the protocol between frontend and backend driver.206*****************************************************************************207*208* The two halves of a Para-virtual driver communicate with209* each other using a shared page and an event channel.210* Shared page contains a ring with event structures.211*212* All reserved fields in the structures below must be 0.213*214*****************************************************************************215* Backend to frontend events216*****************************************************************************217*218* Frontends should ignore unknown in events.219* All event packets have the same length (40 octets)220* All event packets have common header:221*222* 0 octet223* +-----------------+224* | type |225* +-----------------+226* type - uint8_t, event code, XENKBD_TYPE_???227*228*229* Pointer relative movement event230* 0 1 2 3 octet231* +----------------+----------------+----------------+----------------+232* | _TYPE_MOTION | reserved | 4233* +----------------+----------------+----------------+----------------+234* | rel_x | 8235* +----------------+----------------+----------------+----------------+236* | rel_y | 12237* +----------------+----------------+----------------+----------------+238* | rel_z | 16239* +----------------+----------------+----------------+----------------+240* | reserved | 20241* +----------------+----------------+----------------+----------------+242* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|243* +----------------+----------------+----------------+----------------+244* | reserved | 40245* +----------------+----------------+----------------+----------------+246*247* rel_x - int32_t, relative X motion248* rel_y - int32_t, relative Y motion249* rel_z - int32_t, relative Z motion (wheel)250*/251252struct xenkbd_motion {253uint8_t type;254int32_t rel_x;255int32_t rel_y;256int32_t rel_z;257};258259/*260* Key event (includes pointer buttons)261* 0 1 2 3 octet262* +----------------+----------------+----------------+----------------+263* | _TYPE_KEY | pressed | reserved | 4264* +----------------+----------------+----------------+----------------+265* | keycode | 8266* +----------------+----------------+----------------+----------------+267* | reserved | 12268* +----------------+----------------+----------------+----------------+269* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|270* +----------------+----------------+----------------+----------------+271* | reserved | 40272* +----------------+----------------+----------------+----------------+273*274* pressed - uint8_t, 1 if pressed; 0 otherwise275* keycode - uint32_t, KEY_* from linux/input.h276*/277278struct xenkbd_key {279uint8_t type;280uint8_t pressed;281uint32_t keycode;282};283284/*285* Pointer absolute position event286* 0 1 2 3 octet287* +----------------+----------------+----------------+----------------+288* | _TYPE_POS | reserved | 4289* +----------------+----------------+----------------+----------------+290* | abs_x | 8291* +----------------+----------------+----------------+----------------+292* | abs_y | 12293* +----------------+----------------+----------------+----------------+294* | rel_z | 16295* +----------------+----------------+----------------+----------------+296* | reserved | 20297* +----------------+----------------+----------------+----------------+298* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|299* +----------------+----------------+----------------+----------------+300* | reserved | 40301* +----------------+----------------+----------------+----------------+302*303* abs_x - int32_t, absolute X position (in FB pixels)304* abs_y - int32_t, absolute Y position (in FB pixels)305* rel_z - int32_t, relative Z motion (wheel)306*/307308struct xenkbd_position {309uint8_t type;310int32_t abs_x;311int32_t abs_y;312int32_t rel_z;313};314315/*316* Multi-touch event and its sub-types317*318* All multi-touch event packets have common header:319*320* 0 1 2 3 octet321* +----------------+----------------+----------------+----------------+322* | _TYPE_MTOUCH | event_type | contact_id | reserved | 4323* +----------------+----------------+----------------+----------------+324* | reserved | 8325* +----------------+----------------+----------------+----------------+326*327* event_type - unt8_t, multi-touch event sub-type, XENKBD_MT_EV_???328* contact_id - unt8_t, ID of the contact329*330* Touch interactions can consist of one or more contacts.331* For each contact, a series of events is generated, starting332* with a down event, followed by zero or more motion events,333* and ending with an up event. Events relating to the same334* contact point can be identified by the ID of the sequence: contact ID.335* Contact ID may be reused after XENKBD_MT_EV_UP event and336* is in the [0; XENKBD_FIELD_NUM_CONTACTS - 1] range.337*338* For further information please refer to documentation on Wayland [1],339* Linux [2] and Windows [3] multi-touch support.340*341* [1] https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml342* [2] https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.rst343* [3] https://msdn.microsoft.com/en-us/library/jj151564(v=vs.85).aspx344*345*346* Multi-touch down event - sent when a new touch is made: touch is assigned347* a unique contact ID, sent with this and consequent events related348* to this touch.349* 0 1 2 3 octet350* +----------------+----------------+----------------+----------------+351* | _TYPE_MTOUCH | _MT_EV_DOWN | contact_id | reserved | 4352* +----------------+----------------+----------------+----------------+353* | reserved | 8354* +----------------+----------------+----------------+----------------+355* | abs_x | 12356* +----------------+----------------+----------------+----------------+357* | abs_y | 16358* +----------------+----------------+----------------+----------------+359* | reserved | 20360* +----------------+----------------+----------------+----------------+361* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|362* +----------------+----------------+----------------+----------------+363* | reserved | 40364* +----------------+----------------+----------------+----------------+365*366* abs_x - int32_t, absolute X position, in pixels367* abs_y - int32_t, absolute Y position, in pixels368*369* Multi-touch contact release event370* 0 1 2 3 octet371* +----------------+----------------+----------------+----------------+372* | _TYPE_MTOUCH | _MT_EV_UP | contact_id | reserved | 4373* +----------------+----------------+----------------+----------------+374* | reserved | 8375* +----------------+----------------+----------------+----------------+376* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|377* +----------------+----------------+----------------+----------------+378* | reserved | 40379* +----------------+----------------+----------------+----------------+380*381* Multi-touch motion event382* 0 1 2 3 octet383* +----------------+----------------+----------------+----------------+384* | _TYPE_MTOUCH | _MT_EV_MOTION | contact_id | reserved | 4385* +----------------+----------------+----------------+----------------+386* | reserved | 8387* +----------------+----------------+----------------+----------------+388* | abs_x | 12389* +----------------+----------------+----------------+----------------+390* | abs_y | 16391* +----------------+----------------+----------------+----------------+392* | reserved | 20393* +----------------+----------------+----------------+----------------+394* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|395* +----------------+----------------+----------------+----------------+396* | reserved | 40397* +----------------+----------------+----------------+----------------+398*399* abs_x - int32_t, absolute X position, in pixels,400* abs_y - int32_t, absolute Y position, in pixels,401*402* Multi-touch input synchronization event - shows end of a set of events403* which logically belong together.404* 0 1 2 3 octet405* +----------------+----------------+----------------+----------------+406* | _TYPE_MTOUCH | _MT_EV_SYN | contact_id | reserved | 4407* +----------------+----------------+----------------+----------------+408* | reserved | 8409* +----------------+----------------+----------------+----------------+410* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|411* +----------------+----------------+----------------+----------------+412* | reserved | 40413* +----------------+----------------+----------------+----------------+414*415* Multi-touch shape event - touch point's shape has changed its shape.416* Shape is approximated by an ellipse through the major and minor axis417* lengths: major is the longer diameter of the ellipse and minor is the418* shorter one. Center of the ellipse is reported via419* XENKBD_MT_EV_DOWN/XENKBD_MT_EV_MOTION events.420* 0 1 2 3 octet421* +----------------+----------------+----------------+----------------+422* | _TYPE_MTOUCH | _MT_EV_SHAPE | contact_id | reserved | 4423* +----------------+----------------+----------------+----------------+424* | reserved | 8425* +----------------+----------------+----------------+----------------+426* | major | 12427* +----------------+----------------+----------------+----------------+428* | minor | 16429* +----------------+----------------+----------------+----------------+430* | reserved | 20431* +----------------+----------------+----------------+----------------+432* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|433* +----------------+----------------+----------------+----------------+434* | reserved | 40435* +----------------+----------------+----------------+----------------+436*437* major - unt32_t, length of the major axis, pixels438* minor - unt32_t, length of the minor axis, pixels439*440* Multi-touch orientation event - touch point's shape has changed441* its orientation: calculated as a clockwise angle between the major axis442* of the ellipse and positive Y axis in degrees, [-180; +180].443* 0 1 2 3 octet444* +----------------+----------------+----------------+----------------+445* | _TYPE_MTOUCH | _MT_EV_ORIENT | contact_id | reserved | 4446* +----------------+----------------+----------------+----------------+447* | reserved | 8448* +----------------+----------------+----------------+----------------+449* | orientation | reserved | 12450* +----------------+----------------+----------------+----------------+451* | reserved | 16452* +----------------+----------------+----------------+----------------+453* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|454* +----------------+----------------+----------------+----------------+455* | reserved | 40456* +----------------+----------------+----------------+----------------+457*458* orientation - int16_t, clockwise angle of the major axis459*/460461struct xenkbd_mtouch {462uint8_t type; /* XENKBD_TYPE_MTOUCH */463uint8_t event_type; /* XENKBD_MT_EV_??? */464uint8_t contact_id;465uint8_t reserved[5]; /* reserved for the future use */466union {467struct {468int32_t abs_x; /* absolute X position, pixels */469int32_t abs_y; /* absolute Y position, pixels */470} pos;471struct {472uint32_t major; /* length of the major axis, pixels */473uint32_t minor; /* length of the minor axis, pixels */474} shape;475int16_t orientation; /* clockwise angle of the major axis */476} u;477};478479#define XENKBD_IN_EVENT_SIZE 40480481union xenkbd_in_event {482uint8_t type;483struct xenkbd_motion motion;484struct xenkbd_key key;485struct xenkbd_position pos;486struct xenkbd_mtouch mtouch;487char pad[XENKBD_IN_EVENT_SIZE];488};489490/*491*****************************************************************************492* Frontend to backend events493*****************************************************************************494*495* Out events may be sent only when requested by backend, and receipt496* of an unknown out event is an error.497* No out events currently defined.498499* All event packets have the same length (40 octets)500* All event packets have common header:501* 0 octet502* +-----------------+503* | type |504* +-----------------+505* type - uint8_t, event code506*/507508#define XENKBD_OUT_EVENT_SIZE 40509510union xenkbd_out_event {511uint8_t type;512char pad[XENKBD_OUT_EVENT_SIZE];513};514515/*516*****************************************************************************517* Shared page518*****************************************************************************519*/520521#define XENKBD_IN_RING_SIZE 2048522#define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE)523#define XENKBD_IN_RING_OFFS 1024524#define XENKBD_IN_RING(page) \525((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS))526#define XENKBD_IN_RING_REF(page, idx) \527(XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN])528529#define XENKBD_OUT_RING_SIZE 1024530#define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE)531#define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE)532#define XENKBD_OUT_RING(page) \533((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS))534#define XENKBD_OUT_RING_REF(page, idx) \535(XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN])536537struct xenkbd_page {538uint32_t in_cons, in_prod;539uint32_t out_cons, out_prod;540};541542#endif /* __XEN_PUBLIC_IO_KBDIF_H__ */543544545