/*1* kbdif.h -- Xen virtual keyboard/mouse2*3* Permission is hereby granted, free of charge, to any person obtaining a copy4* of this software and associated documentation files (the "Software"), to5* deal in the Software without restriction, including without limitation the6* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or7* sell copies of the Software, and to permit persons to whom the Software is8* furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19* DEALINGS IN THE SOFTWARE.20*21* Copyright (C) 2005 Anthony Liguori <[email protected]>22* Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <[email protected]>23*/2425#ifndef __XEN_PUBLIC_IO_KBDIF_H__26#define __XEN_PUBLIC_IO_KBDIF_H__2728/*29*****************************************************************************30* Feature and Parameter Negotiation31*****************************************************************************32*33* The two halves of a para-virtual driver utilize nodes within34* XenStore to communicate capabilities and to negotiate operating parameters.35* This section enumerates these nodes which reside in the respective front and36* backend portions of XenStore, following XenBus convention.37*38* All data in XenStore is stored as strings. Nodes specifying numeric39* values are encoded in decimal. Integer value ranges listed below are40* expressed as fixed sized integer types capable of storing the conversion41* of a properly formated node string, without loss of information.42*43*****************************************************************************44* Backend XenBus Nodes45*****************************************************************************46*47*---------------------------- Features supported ----------------------------48*49* Capable backend advertises supported features by publishing50* corresponding entries in XenStore and puts 1 as the value of the entry.51* If a feature is not supported then 0 must be set or feature entry omitted.52*53* feature-disable-keyboard54* Values: <uint>55*56* If there is no need to expose a virtual keyboard device by the57* frontend then this must be set to 1.58*59* feature-disable-pointer60* Values: <uint>61*62* If there is no need to expose a virtual pointer device by the63* frontend then this must be set to 1.64*65* feature-abs-pointer66* Values: <uint>67*68* Backends, which support reporting of absolute coordinates for pointer69* device should set this to 1.70*71* feature-multi-touch72* Values: <uint>73*74* Backends, which support reporting of multi-touch events75* should set this to 1.76*77* feature-raw-pointer78* Values: <uint>79*80* Backends, which support reporting raw (unscaled) absolute coordinates81* for pointer devices should set this to 1. Raw (unscaled) values have82* a range of [0, 0x7fff].83*84*----------------------- Device Instance Parameters ------------------------85*86* unique-id87* Values: <string>88*89* After device instance initialization it is assigned a unique ID,90* so every instance of the frontend can be identified by the backend91* by this ID. This can be UUID or such.92*93*------------------------- Pointer Device Parameters ------------------------94*95* width96* Values: <uint>97*98* Maximum X coordinate (width) to be used by the frontend99* while reporting input events, pixels, [0; UINT32_MAX].100*101* height102* Values: <uint>103*104* Maximum Y coordinate (height) to be used by the frontend105* while reporting input events, pixels, [0; UINT32_MAX].106*107*----------------------- Multi-touch Device Parameters ----------------------108*109* multi-touch-num-contacts110* Values: <uint>111*112* Number of simultaneous touches reported.113*114* multi-touch-width115* Values: <uint>116*117* Width of the touch area to be used by the frontend118* while reporting input events, pixels, [0; UINT32_MAX].119*120* multi-touch-height121* Values: <uint>122*123* Height of the touch area to be used by the frontend124* while reporting input events, pixels, [0; UINT32_MAX].125*126*****************************************************************************127* Frontend XenBus Nodes128*****************************************************************************129*130*------------------------------ Feature request -----------------------------131*132* Capable frontend requests features from backend via setting corresponding133* entries to 1 in XenStore. Requests for features not advertised as supported134* by the backend have no effect.135*136* request-abs-pointer137* Values: <uint>138*139* Request backend to report absolute pointer coordinates140* (XENKBD_TYPE_POS) instead of relative ones (XENKBD_TYPE_MOTION).141*142* request-multi-touch143* Values: <uint>144*145* Request backend to report multi-touch events.146*147* request-raw-pointer148* Values: <uint>149*150* Request backend to report raw unscaled absolute pointer coordinates.151* This option is only valid if request-abs-pointer is also set.152* Raw unscaled coordinates have the range [0, 0x7fff]153*154*----------------------- Request Transport Parameters -----------------------155*156* event-channel157* Values: <uint>158*159* The identifier of the Xen event channel used to signal activity160* in the ring buffer.161*162* page-gref163* Values: <uint>164*165* The Xen grant reference granting permission for the backend to map166* a sole page in a single page sized event ring buffer.167*168* page-ref169* Values: <uint>170*171* OBSOLETE, not recommended for use.172* PFN of the shared page.173*/174175/*176* EVENT CODES.177*/178179#define XENKBD_TYPE_MOTION 1180#define XENKBD_TYPE_RESERVED 2181#define XENKBD_TYPE_KEY 3182#define XENKBD_TYPE_POS 4183#define XENKBD_TYPE_MTOUCH 5184185/* Multi-touch event sub-codes */186187#define XENKBD_MT_EV_DOWN 0188#define XENKBD_MT_EV_UP 1189#define XENKBD_MT_EV_MOTION 2190#define XENKBD_MT_EV_SYN 3191#define XENKBD_MT_EV_SHAPE 4192#define XENKBD_MT_EV_ORIENT 5193194/*195* CONSTANTS, XENSTORE FIELD AND PATH NAME STRINGS, HELPERS.196*/197198#define XENKBD_DRIVER_NAME "vkbd"199200#define XENKBD_FIELD_FEAT_DSBL_KEYBRD "feature-disable-keyboard"201#define XENKBD_FIELD_FEAT_DSBL_POINTER "feature-disable-pointer"202#define XENKBD_FIELD_FEAT_ABS_POINTER "feature-abs-pointer"203#define XENKBD_FIELD_FEAT_RAW_POINTER "feature-raw-pointer"204#define XENKBD_FIELD_FEAT_MTOUCH "feature-multi-touch"205#define XENKBD_FIELD_REQ_ABS_POINTER "request-abs-pointer"206#define XENKBD_FIELD_REQ_RAW_POINTER "request-raw-pointer"207#define XENKBD_FIELD_REQ_MTOUCH "request-multi-touch"208#define XENKBD_FIELD_RING_GREF "page-gref"209#define XENKBD_FIELD_EVT_CHANNEL "event-channel"210#define XENKBD_FIELD_WIDTH "width"211#define XENKBD_FIELD_HEIGHT "height"212#define XENKBD_FIELD_MT_WIDTH "multi-touch-width"213#define XENKBD_FIELD_MT_HEIGHT "multi-touch-height"214#define XENKBD_FIELD_MT_NUM_CONTACTS "multi-touch-num-contacts"215#define XENKBD_FIELD_UNIQUE_ID "unique-id"216217/* OBSOLETE, not recommended for use */218#define XENKBD_FIELD_RING_REF "page-ref"219220/*221*****************************************************************************222* Description of the protocol between frontend and backend driver.223*****************************************************************************224*225* The two halves of a Para-virtual driver communicate with226* each other using a shared page and an event channel.227* Shared page contains a ring with event structures.228*229* All reserved fields in the structures below must be 0.230*231*****************************************************************************232* Backend to frontend events233*****************************************************************************234*235* Frontends should ignore unknown in events.236* All event packets have the same length (40 octets)237* All event packets have common header:238*239* 0 octet240* +-----------------+241* | type |242* +-----------------+243* type - uint8_t, event code, XENKBD_TYPE_???244*245*246* Pointer relative movement event247* 0 1 2 3 octet248* +----------------+----------------+----------------+----------------+249* | _TYPE_MOTION | reserved | 4250* +----------------+----------------+----------------+----------------+251* | rel_x | 8252* +----------------+----------------+----------------+----------------+253* | rel_y | 12254* +----------------+----------------+----------------+----------------+255* | rel_z | 16256* +----------------+----------------+----------------+----------------+257* | reserved | 20258* +----------------+----------------+----------------+----------------+259* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|260* +----------------+----------------+----------------+----------------+261* | reserved | 40262* +----------------+----------------+----------------+----------------+263*264* rel_x - int32_t, relative X motion265* rel_y - int32_t, relative Y motion266* rel_z - int32_t, relative Z motion (wheel)267*/268269struct xenkbd_motion270{271uint8_t type;272int32_t rel_x;273int32_t rel_y;274int32_t rel_z;275};276277/*278* Key event (includes pointer buttons)279* 0 1 2 3 octet280* +----------------+----------------+----------------+----------------+281* | _TYPE_KEY | pressed | reserved | 4282* +----------------+----------------+----------------+----------------+283* | keycode | 8284* +----------------+----------------+----------------+----------------+285* | reserved | 12286* +----------------+----------------+----------------+----------------+287* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|288* +----------------+----------------+----------------+----------------+289* | reserved | 40290* +----------------+----------------+----------------+----------------+291*292* pressed - uint8_t, 1 if pressed; 0 otherwise293* keycode - uint32_t, KEY_* from linux/input.h294*/295296struct xenkbd_key297{298uint8_t type;299uint8_t pressed;300uint32_t keycode;301};302303/*304* Pointer absolute position event305* 0 1 2 3 octet306* +----------------+----------------+----------------+----------------+307* | _TYPE_POS | reserved | 4308* +----------------+----------------+----------------+----------------+309* | abs_x | 8310* +----------------+----------------+----------------+----------------+311* | abs_y | 12312* +----------------+----------------+----------------+----------------+313* | rel_z | 16314* +----------------+----------------+----------------+----------------+315* | reserved | 20316* +----------------+----------------+----------------+----------------+317* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|318* +----------------+----------------+----------------+----------------+319* | reserved | 40320* +----------------+----------------+----------------+----------------+321*322* abs_x - int32_t, absolute X position (in FB pixels)323* abs_y - int32_t, absolute Y position (in FB pixels)324* rel_z - int32_t, relative Z motion (wheel)325*/326327struct xenkbd_position328{329uint8_t type;330int32_t abs_x;331int32_t abs_y;332int32_t rel_z;333};334335/*336* Multi-touch event and its sub-types337*338* All multi-touch event packets have common header:339*340* 0 1 2 3 octet341* +----------------+----------------+----------------+----------------+342* | _TYPE_MTOUCH | event_type | contact_id | reserved | 4343* +----------------+----------------+----------------+----------------+344* | reserved | 8345* +----------------+----------------+----------------+----------------+346*347* event_type - unt8_t, multi-touch event sub-type, XENKBD_MT_EV_???348* contact_id - unt8_t, ID of the contact349*350* Touch interactions can consist of one or more contacts.351* For each contact, a series of events is generated, starting352* with a down event, followed by zero or more motion events,353* and ending with an up event. Events relating to the same354* contact point can be identified by the ID of the sequence: contact ID.355* Contact ID may be reused after XENKBD_MT_EV_UP event and356* is in the [0; XENKBD_FIELD_NUM_CONTACTS - 1] range.357*358* For further information please refer to documentation on Wayland [1],359* Linux [2] and Windows [3] multi-touch support.360*361* [1] https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml362* [2] https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt363* [3] https://msdn.microsoft.com/en-us/library/jj151564(v=vs.85).aspx364*365*366* Multi-touch down event - sent when a new touch is made: touch is assigned367* a unique contact ID, sent with this and consequent events related368* to this touch.369* 0 1 2 3 octet370* +----------------+----------------+----------------+----------------+371* | _TYPE_MTOUCH | _MT_EV_DOWN | contact_id | reserved | 4372* +----------------+----------------+----------------+----------------+373* | reserved | 8374* +----------------+----------------+----------------+----------------+375* | abs_x | 12376* +----------------+----------------+----------------+----------------+377* | abs_y | 16378* +----------------+----------------+----------------+----------------+379* | reserved | 20380* +----------------+----------------+----------------+----------------+381* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|382* +----------------+----------------+----------------+----------------+383* | reserved | 40384* +----------------+----------------+----------------+----------------+385*386* abs_x - int32_t, absolute X position, in pixels387* abs_y - int32_t, absolute Y position, in pixels388*389* Multi-touch contact release event390* 0 1 2 3 octet391* +----------------+----------------+----------------+----------------+392* | _TYPE_MTOUCH | _MT_EV_UP | contact_id | reserved | 4393* +----------------+----------------+----------------+----------------+394* | reserved | 8395* +----------------+----------------+----------------+----------------+396* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|397* +----------------+----------------+----------------+----------------+398* | reserved | 40399* +----------------+----------------+----------------+----------------+400*401* Multi-touch motion event402* 0 1 2 3 octet403* +----------------+----------------+----------------+----------------+404* | _TYPE_MTOUCH | _MT_EV_MOTION | contact_id | reserved | 4405* +----------------+----------------+----------------+----------------+406* | reserved | 8407* +----------------+----------------+----------------+----------------+408* | abs_x | 12409* +----------------+----------------+----------------+----------------+410* | abs_y | 16411* +----------------+----------------+----------------+----------------+412* | reserved | 20413* +----------------+----------------+----------------+----------------+414* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|415* +----------------+----------------+----------------+----------------+416* | reserved | 40417* +----------------+----------------+----------------+----------------+418*419* abs_x - int32_t, absolute X position, in pixels,420* abs_y - int32_t, absolute Y position, in pixels,421*422* Multi-touch input synchronization event - shows end of a set of events423* which logically belong together.424* 0 1 2 3 octet425* +----------------+----------------+----------------+----------------+426* | _TYPE_MTOUCH | _MT_EV_SYN | contact_id | reserved | 4427* +----------------+----------------+----------------+----------------+428* | reserved | 8429* +----------------+----------------+----------------+----------------+430* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|431* +----------------+----------------+----------------+----------------+432* | reserved | 40433* +----------------+----------------+----------------+----------------+434*435* Multi-touch shape event - touch point's shape has changed its shape.436* Shape is approximated by an ellipse through the major and minor axis437* lengths: major is the longer diameter of the ellipse and minor is the438* shorter one. Center of the ellipse is reported via439* XENKBD_MT_EV_DOWN/XENKBD_MT_EV_MOTION events.440* 0 1 2 3 octet441* +----------------+----------------+----------------+----------------+442* | _TYPE_MTOUCH | _MT_EV_SHAPE | contact_id | reserved | 4443* +----------------+----------------+----------------+----------------+444* | reserved | 8445* +----------------+----------------+----------------+----------------+446* | major | 12447* +----------------+----------------+----------------+----------------+448* | minor | 16449* +----------------+----------------+----------------+----------------+450* | reserved | 20451* +----------------+----------------+----------------+----------------+452* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|453* +----------------+----------------+----------------+----------------+454* | reserved | 40455* +----------------+----------------+----------------+----------------+456*457* major - unt32_t, length of the major axis, pixels458* minor - unt32_t, length of the minor axis, pixels459*460* Multi-touch orientation event - touch point's shape has changed461* its orientation: calculated as a clockwise angle between the major axis462* of the ellipse and positive Y axis in degrees, [-180; +180].463* 0 1 2 3 octet464* +----------------+----------------+----------------+----------------+465* | _TYPE_MTOUCH | _MT_EV_ORIENT | contact_id | reserved | 4466* +----------------+----------------+----------------+----------------+467* | reserved | 8468* +----------------+----------------+----------------+----------------+469* | orientation | reserved | 12470* +----------------+----------------+----------------+----------------+471* | reserved | 16472* +----------------+----------------+----------------+----------------+473* |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|474* +----------------+----------------+----------------+----------------+475* | reserved | 40476* +----------------+----------------+----------------+----------------+477*478* orientation - int16_t, clockwise angle of the major axis479*/480481struct xenkbd_mtouch {482uint8_t type; /* XENKBD_TYPE_MTOUCH */483uint8_t event_type; /* XENKBD_MT_EV_??? */484uint8_t contact_id;485uint8_t reserved[5]; /* reserved for the future use */486union {487struct {488int32_t abs_x; /* absolute X position, pixels */489int32_t abs_y; /* absolute Y position, pixels */490} pos;491struct {492uint32_t major; /* length of the major axis, pixels */493uint32_t minor; /* length of the minor axis, pixels */494} shape;495int16_t orientation; /* clockwise angle of the major axis */496} u;497};498499#define XENKBD_IN_EVENT_SIZE 40500501union xenkbd_in_event502{503uint8_t type;504struct xenkbd_motion motion;505struct xenkbd_key key;506struct xenkbd_position pos;507struct xenkbd_mtouch mtouch;508char pad[XENKBD_IN_EVENT_SIZE];509};510511/*512*****************************************************************************513* Frontend to backend events514*****************************************************************************515*516* Out events may be sent only when requested by backend, and receipt517* of an unknown out event is an error.518* No out events currently defined.519520* All event packets have the same length (40 octets)521* All event packets have common header:522* 0 octet523* +-----------------+524* | type |525* +-----------------+526* type - uint8_t, event code527*/528529#define XENKBD_OUT_EVENT_SIZE 40530531union xenkbd_out_event532{533uint8_t type;534char pad[XENKBD_OUT_EVENT_SIZE];535};536537/*538*****************************************************************************539* Shared page540*****************************************************************************541*/542543#define XENKBD_IN_RING_SIZE 2048544#define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE)545#define XENKBD_IN_RING_OFFS 1024546#define XENKBD_IN_RING(page) \547((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS))548#define XENKBD_IN_RING_REF(page, idx) \549(XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN])550551#define XENKBD_OUT_RING_SIZE 1024552#define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE)553#define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE)554#define XENKBD_OUT_RING(page) \555((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS))556#define XENKBD_OUT_RING_REF(page, idx) \557(XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN])558559struct xenkbd_page560{561uint32_t in_cons, in_prod;562uint32_t out_cons, out_prod;563};564565#endif /* __XEN_PUBLIC_IO_KBDIF_H__ */566567/*568* Local variables:569* mode: C570* c-file-style: "BSD"571* c-basic-offset: 4572* tab-width: 4573* indent-tabs-mode: nil574* End:575*/576577578