Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /*
0003  * kbdif.h -- Xen virtual keyboard/mouse
0004  *
0005  * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
0006  * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
0007  */
0008 
0009 #ifndef __XEN_PUBLIC_IO_KBDIF_H__
0010 #define __XEN_PUBLIC_IO_KBDIF_H__
0011 
0012 /*
0013  *****************************************************************************
0014  *                     Feature and Parameter Negotiation
0015  *****************************************************************************
0016  *
0017  * The two halves of a para-virtual driver utilize nodes within
0018  * XenStore to communicate capabilities and to negotiate operating parameters.
0019  * This section enumerates these nodes which reside in the respective front and
0020  * backend portions of XenStore, following XenBus convention.
0021  *
0022  * All data in XenStore is stored as strings.  Nodes specifying numeric
0023  * values are encoded in decimal. Integer value ranges listed below are
0024  * expressed as fixed sized integer types capable of storing the conversion
0025  * of a properly formated node string, without loss of information.
0026  *
0027  *****************************************************************************
0028  *                            Backend XenBus Nodes
0029  *****************************************************************************
0030  *
0031  *---------------------------- Features supported ----------------------------
0032  *
0033  * Capable backend advertises supported features by publishing
0034  * corresponding entries in XenStore and puts 1 as the value of the entry.
0035  * If a feature is not supported then 0 must be set or feature entry omitted.
0036  *
0037  * feature-disable-keyboard
0038  *      Values:         <uint>
0039  *
0040  *      If there is no need to expose a virtual keyboard device by the
0041  *      frontend then this must be set to 1.
0042  *
0043  * feature-disable-pointer
0044  *      Values:         <uint>
0045  *
0046  *      If there is no need to expose a virtual pointer device by the
0047  *      frontend then this must be set to 1.
0048  *
0049  * feature-abs-pointer
0050  *      Values:         <uint>
0051  *
0052  *      Backends, which support reporting of absolute coordinates for pointer
0053  *      device should set this to 1.
0054  *
0055  * feature-multi-touch
0056  *      Values:         <uint>
0057  *
0058  *      Backends, which support reporting of multi-touch events
0059  *      should set this to 1.
0060  *
0061  * feature-raw-pointer
0062  *      Values:        <uint>
0063  *
0064  *      Backends, which support reporting raw (unscaled) absolute coordinates
0065  *      for pointer devices should set this to 1. Raw (unscaled) values have
0066  *      a range of [0, 0x7fff].
0067  *
0068  *-----------------------  Device Instance Parameters ------------------------
0069  *
0070  * unique-id
0071  *      Values:         <string>
0072  *
0073  *      After device instance initialization it is assigned a unique ID,
0074  *      so every instance of the frontend can be identified by the backend
0075  *      by this ID. This can be UUID or such.
0076  *
0077  *------------------------- Pointer Device Parameters ------------------------
0078  *
0079  * width
0080  *      Values:         <uint>
0081  *
0082  *      Maximum X coordinate (width) to be used by the frontend
0083  *      while reporting input events, pixels, [0; UINT32_MAX].
0084  *
0085  * height
0086  *      Values:         <uint>
0087  *
0088  *      Maximum Y coordinate (height) to be used by the frontend
0089  *      while reporting input events, pixels, [0; UINT32_MAX].
0090  *
0091  *----------------------- Multi-touch Device Parameters ----------------------
0092  *
0093  * multi-touch-num-contacts
0094  *      Values:         <uint>
0095  *
0096  *      Number of simultaneous touches reported.
0097  *
0098  * multi-touch-width
0099  *      Values:         <uint>
0100  *
0101  *      Width of the touch area to be used by the frontend
0102  *      while reporting input events, pixels, [0; UINT32_MAX].
0103  *
0104  * multi-touch-height
0105  *      Values:         <uint>
0106  *
0107  *      Height of the touch area to be used by the frontend
0108  *      while reporting input events, pixels, [0; UINT32_MAX].
0109  *
0110  *****************************************************************************
0111  *                            Frontend XenBus Nodes
0112  *****************************************************************************
0113  *
0114  *------------------------------ Feature request -----------------------------
0115  *
0116  * Capable frontend requests features from backend via setting corresponding
0117  * entries to 1 in XenStore. Requests for features not advertised as supported
0118  * by the backend have no effect.
0119  *
0120  * request-abs-pointer
0121  *      Values:         <uint>
0122  *
0123  *      Request backend to report absolute pointer coordinates
0124  *      (XENKBD_TYPE_POS) instead of relative ones (XENKBD_TYPE_MOTION).
0125  *
0126  * request-multi-touch
0127  *      Values:         <uint>
0128  *
0129  *      Request backend to report multi-touch events.
0130  *
0131  * request-raw-pointer
0132  *      Values:         <uint>
0133  *
0134  *      Request backend to report raw unscaled absolute pointer coordinates.
0135  *      This option is only valid if request-abs-pointer is also set.
0136  *      Raw unscaled coordinates have the range [0, 0x7fff]
0137  *
0138  *----------------------- Request Transport Parameters -----------------------
0139  *
0140  * event-channel
0141  *      Values:         <uint>
0142  *
0143  *      The identifier of the Xen event channel used to signal activity
0144  *      in the ring buffer.
0145  *
0146  * page-gref
0147  *      Values:         <uint>
0148  *
0149  *      The Xen grant reference granting permission for the backend to map
0150  *      a sole page in a single page sized event ring buffer.
0151  *
0152  * page-ref
0153  *      Values:         <uint>
0154  *
0155  *      OBSOLETE, not recommended for use.
0156  *      PFN of the shared page.
0157  */
0158 
0159 /*
0160  * EVENT CODES.
0161  */
0162 
0163 #define XENKBD_TYPE_MOTION      1
0164 #define XENKBD_TYPE_RESERVED        2
0165 #define XENKBD_TYPE_KEY         3
0166 #define XENKBD_TYPE_POS         4
0167 #define XENKBD_TYPE_MTOUCH      5
0168 
0169 /* Multi-touch event sub-codes */
0170 
0171 #define XENKBD_MT_EV_DOWN       0
0172 #define XENKBD_MT_EV_UP         1
0173 #define XENKBD_MT_EV_MOTION     2
0174 #define XENKBD_MT_EV_SYN        3
0175 #define XENKBD_MT_EV_SHAPE      4
0176 #define XENKBD_MT_EV_ORIENT     5
0177 
0178 /*
0179  * CONSTANTS, XENSTORE FIELD AND PATH NAME STRINGS, HELPERS.
0180  */
0181 
0182 #define XENKBD_DRIVER_NAME      "vkbd"
0183 
0184 #define XENKBD_FIELD_FEAT_DSBL_KEYBRD   "feature-disable-keyboard"
0185 #define XENKBD_FIELD_FEAT_DSBL_POINTER  "feature-disable-pointer"
0186 #define XENKBD_FIELD_FEAT_ABS_POINTER   "feature-abs-pointer"
0187 #define XENKBD_FIELD_FEAT_RAW_POINTER   "feature-raw-pointer"
0188 #define XENKBD_FIELD_FEAT_MTOUCH    "feature-multi-touch"
0189 #define XENKBD_FIELD_REQ_ABS_POINTER    "request-abs-pointer"
0190 #define XENKBD_FIELD_REQ_RAW_POINTER    "request-raw-pointer"
0191 #define XENKBD_FIELD_REQ_MTOUCH     "request-multi-touch"
0192 #define XENKBD_FIELD_RING_GREF      "page-gref"
0193 #define XENKBD_FIELD_EVT_CHANNEL    "event-channel"
0194 #define XENKBD_FIELD_WIDTH      "width"
0195 #define XENKBD_FIELD_HEIGHT     "height"
0196 #define XENKBD_FIELD_MT_WIDTH       "multi-touch-width"
0197 #define XENKBD_FIELD_MT_HEIGHT      "multi-touch-height"
0198 #define XENKBD_FIELD_MT_NUM_CONTACTS    "multi-touch-num-contacts"
0199 #define XENKBD_FIELD_UNIQUE_ID      "unique-id"
0200 
0201 /* OBSOLETE, not recommended for use */
0202 #define XENKBD_FIELD_RING_REF       "page-ref"
0203 
0204 /*
0205  *****************************************************************************
0206  * Description of the protocol between frontend and backend driver.
0207  *****************************************************************************
0208  *
0209  * The two halves of a Para-virtual driver communicate with
0210  * each other using a shared page and an event channel.
0211  * Shared page contains a ring with event structures.
0212  *
0213  * All reserved fields in the structures below must be 0.
0214  *
0215  *****************************************************************************
0216  *                           Backend to frontend events
0217  *****************************************************************************
0218  *
0219  * Frontends should ignore unknown in events.
0220  * All event packets have the same length (40 octets)
0221  * All event packets have common header:
0222  *
0223  *          0         octet
0224  * +-----------------+
0225  * |       type      |
0226  * +-----------------+
0227  * type - uint8_t, event code, XENKBD_TYPE_???
0228  *
0229  *
0230  * Pointer relative movement event
0231  *         0                1                 2               3        octet
0232  * +----------------+----------------+----------------+----------------+
0233  * |  _TYPE_MOTION  |                     reserved                     | 4
0234  * +----------------+----------------+----------------+----------------+
0235  * |                               rel_x                               | 8
0236  * +----------------+----------------+----------------+----------------+
0237  * |                               rel_y                               | 12
0238  * +----------------+----------------+----------------+----------------+
0239  * |                               rel_z                               | 16
0240  * +----------------+----------------+----------------+----------------+
0241  * |                             reserved                              | 20
0242  * +----------------+----------------+----------------+----------------+
0243  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0244  * +----------------+----------------+----------------+----------------+
0245  * |                             reserved                              | 40
0246  * +----------------+----------------+----------------+----------------+
0247  *
0248  * rel_x - int32_t, relative X motion
0249  * rel_y - int32_t, relative Y motion
0250  * rel_z - int32_t, relative Z motion (wheel)
0251  */
0252 
0253 struct xenkbd_motion {
0254     uint8_t type;
0255     int32_t rel_x;
0256     int32_t rel_y;
0257     int32_t rel_z;
0258 };
0259 
0260 /*
0261  * Key event (includes pointer buttons)
0262  *         0                1                 2               3        octet
0263  * +----------------+----------------+----------------+----------------+
0264  * |  _TYPE_KEY     |     pressed    |            reserved             | 4
0265  * +----------------+----------------+----------------+----------------+
0266  * |                              keycode                              | 8
0267  * +----------------+----------------+----------------+----------------+
0268  * |                             reserved                              | 12
0269  * +----------------+----------------+----------------+----------------+
0270  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0271  * +----------------+----------------+----------------+----------------+
0272  * |                             reserved                              | 40
0273  * +----------------+----------------+----------------+----------------+
0274  *
0275  * pressed - uint8_t, 1 if pressed; 0 otherwise
0276  * keycode - uint32_t, KEY_* from linux/input.h
0277  */
0278 
0279 struct xenkbd_key {
0280     uint8_t type;
0281     uint8_t pressed;
0282     uint32_t keycode;
0283 };
0284 
0285 /*
0286  * Pointer absolute position event
0287  *         0                1                 2               3        octet
0288  * +----------------+----------------+----------------+----------------+
0289  * |  _TYPE_POS     |                     reserved                     | 4
0290  * +----------------+----------------+----------------+----------------+
0291  * |                               abs_x                               | 8
0292  * +----------------+----------------+----------------+----------------+
0293  * |                               abs_y                               | 12
0294  * +----------------+----------------+----------------+----------------+
0295  * |                               rel_z                               | 16
0296  * +----------------+----------------+----------------+----------------+
0297  * |                             reserved                              | 20
0298  * +----------------+----------------+----------------+----------------+
0299  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0300  * +----------------+----------------+----------------+----------------+
0301  * |                             reserved                              | 40
0302  * +----------------+----------------+----------------+----------------+
0303  *
0304  * abs_x - int32_t, absolute X position (in FB pixels)
0305  * abs_y - int32_t, absolute Y position (in FB pixels)
0306  * rel_z - int32_t, relative Z motion (wheel)
0307  */
0308 
0309 struct xenkbd_position {
0310     uint8_t type;
0311     int32_t abs_x;
0312     int32_t abs_y;
0313     int32_t rel_z;
0314 };
0315 
0316 /*
0317  * Multi-touch event and its sub-types
0318  *
0319  * All multi-touch event packets have common header:
0320  *
0321  *         0                1                 2               3        octet
0322  * +----------------+----------------+----------------+----------------+
0323  * |  _TYPE_MTOUCH  |   event_type   |   contact_id   |    reserved    | 4
0324  * +----------------+----------------+----------------+----------------+
0325  * |                             reserved                              | 8
0326  * +----------------+----------------+----------------+----------------+
0327  *
0328  * event_type - unt8_t, multi-touch event sub-type, XENKBD_MT_EV_???
0329  * contact_id - unt8_t, ID of the contact
0330  *
0331  * Touch interactions can consist of one or more contacts.
0332  * For each contact, a series of events is generated, starting
0333  * with a down event, followed by zero or more motion events,
0334  * and ending with an up event. Events relating to the same
0335  * contact point can be identified by the ID of the sequence: contact ID.
0336  * Contact ID may be reused after XENKBD_MT_EV_UP event and
0337  * is in the [0; XENKBD_FIELD_NUM_CONTACTS - 1] range.
0338  *
0339  * For further information please refer to documentation on Wayland [1],
0340  * Linux [2] and Windows [3] multi-touch support.
0341  *
0342  * [1] https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml
0343  * [2] https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.rst
0344  * [3] https://msdn.microsoft.com/en-us/library/jj151564(v=vs.85).aspx
0345  *
0346  *
0347  * Multi-touch down event - sent when a new touch is made: touch is assigned
0348  * a unique contact ID, sent with this and consequent events related
0349  * to this touch.
0350  *         0                1                 2               3        octet
0351  * +----------------+----------------+----------------+----------------+
0352  * |  _TYPE_MTOUCH  |   _MT_EV_DOWN  |   contact_id   |    reserved    | 4
0353  * +----------------+----------------+----------------+----------------+
0354  * |                             reserved                              | 8
0355  * +----------------+----------------+----------------+----------------+
0356  * |                               abs_x                               | 12
0357  * +----------------+----------------+----------------+----------------+
0358  * |                               abs_y                               | 16
0359  * +----------------+----------------+----------------+----------------+
0360  * |                             reserved                              | 20
0361  * +----------------+----------------+----------------+----------------+
0362  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0363  * +----------------+----------------+----------------+----------------+
0364  * |                             reserved                              | 40
0365  * +----------------+----------------+----------------+----------------+
0366  *
0367  * abs_x - int32_t, absolute X position, in pixels
0368  * abs_y - int32_t, absolute Y position, in pixels
0369  *
0370  * Multi-touch contact release event
0371  *         0                1                 2               3        octet
0372  * +----------------+----------------+----------------+----------------+
0373  * |  _TYPE_MTOUCH  |  _MT_EV_UP     |   contact_id   |    reserved    | 4
0374  * +----------------+----------------+----------------+----------------+
0375  * |                             reserved                              | 8
0376  * +----------------+----------------+----------------+----------------+
0377  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0378  * +----------------+----------------+----------------+----------------+
0379  * |                             reserved                              | 40
0380  * +----------------+----------------+----------------+----------------+
0381  *
0382  * Multi-touch motion event
0383  *         0                1                 2               3        octet
0384  * +----------------+----------------+----------------+----------------+
0385  * |  _TYPE_MTOUCH  |  _MT_EV_MOTION |   contact_id   |    reserved    | 4
0386  * +----------------+----------------+----------------+----------------+
0387  * |                             reserved                              | 8
0388  * +----------------+----------------+----------------+----------------+
0389  * |                               abs_x                               | 12
0390  * +----------------+----------------+----------------+----------------+
0391  * |                               abs_y                               | 16
0392  * +----------------+----------------+----------------+----------------+
0393  * |                             reserved                              | 20
0394  * +----------------+----------------+----------------+----------------+
0395  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0396  * +----------------+----------------+----------------+----------------+
0397  * |                             reserved                              | 40
0398  * +----------------+----------------+----------------+----------------+
0399  *
0400  * abs_x - int32_t, absolute X position, in pixels,
0401  * abs_y - int32_t, absolute Y position, in pixels,
0402  *
0403  * Multi-touch input synchronization event - shows end of a set of events
0404  * which logically belong together.
0405  *         0                1                 2               3        octet
0406  * +----------------+----------------+----------------+----------------+
0407  * |  _TYPE_MTOUCH  |  _MT_EV_SYN    |   contact_id   |    reserved    | 4
0408  * +----------------+----------------+----------------+----------------+
0409  * |                             reserved                              | 8
0410  * +----------------+----------------+----------------+----------------+
0411  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0412  * +----------------+----------------+----------------+----------------+
0413  * |                             reserved                              | 40
0414  * +----------------+----------------+----------------+----------------+
0415  *
0416  * Multi-touch shape event - touch point's shape has changed its shape.
0417  * Shape is approximated by an ellipse through the major and minor axis
0418  * lengths: major is the longer diameter of the ellipse and minor is the
0419  * shorter one. Center of the ellipse is reported via
0420  * XENKBD_MT_EV_DOWN/XENKBD_MT_EV_MOTION events.
0421  *         0                1                 2               3        octet
0422  * +----------------+----------------+----------------+----------------+
0423  * |  _TYPE_MTOUCH  |  _MT_EV_SHAPE  |   contact_id   |    reserved    | 4
0424  * +----------------+----------------+----------------+----------------+
0425  * |                             reserved                              | 8
0426  * +----------------+----------------+----------------+----------------+
0427  * |                               major                               | 12
0428  * +----------------+----------------+----------------+----------------+
0429  * |                               minor                               | 16
0430  * +----------------+----------------+----------------+----------------+
0431  * |                             reserved                              | 20
0432  * +----------------+----------------+----------------+----------------+
0433  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0434  * +----------------+----------------+----------------+----------------+
0435  * |                             reserved                              | 40
0436  * +----------------+----------------+----------------+----------------+
0437  *
0438  * major - unt32_t, length of the major axis, pixels
0439  * minor - unt32_t, length of the minor axis, pixels
0440  *
0441  * Multi-touch orientation event - touch point's shape has changed
0442  * its orientation: calculated as a clockwise angle between the major axis
0443  * of the ellipse and positive Y axis in degrees, [-180; +180].
0444  *         0                1                 2               3        octet
0445  * +----------------+----------------+----------------+----------------+
0446  * |  _TYPE_MTOUCH  |  _MT_EV_ORIENT |   contact_id   |    reserved    | 4
0447  * +----------------+----------------+----------------+----------------+
0448  * |                             reserved                              | 8
0449  * +----------------+----------------+----------------+----------------+
0450  * |           orientation           |            reserved             | 12
0451  * +----------------+----------------+----------------+----------------+
0452  * |                             reserved                              | 16
0453  * +----------------+----------------+----------------+----------------+
0454  * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
0455  * +----------------+----------------+----------------+----------------+
0456  * |                             reserved                              | 40
0457  * +----------------+----------------+----------------+----------------+
0458  *
0459  * orientation - int16_t, clockwise angle of the major axis
0460  */
0461 
0462 struct xenkbd_mtouch {
0463     uint8_t type;           /* XENKBD_TYPE_MTOUCH */
0464     uint8_t event_type;     /* XENKBD_MT_EV_??? */
0465     uint8_t contact_id;
0466     uint8_t reserved[5];        /* reserved for the future use */
0467     union {
0468         struct {
0469             int32_t abs_x;  /* absolute X position, pixels */
0470             int32_t abs_y;  /* absolute Y position, pixels */
0471         } pos;
0472         struct {
0473             uint32_t major; /* length of the major axis, pixels */
0474             uint32_t minor; /* length of the minor axis, pixels */
0475         } shape;
0476         int16_t orientation;    /* clockwise angle of the major axis */
0477     } u;
0478 };
0479 
0480 #define XENKBD_IN_EVENT_SIZE 40
0481 
0482 union xenkbd_in_event {
0483     uint8_t type;
0484     struct xenkbd_motion motion;
0485     struct xenkbd_key key;
0486     struct xenkbd_position pos;
0487     struct xenkbd_mtouch mtouch;
0488     char pad[XENKBD_IN_EVENT_SIZE];
0489 };
0490 
0491 /*
0492  *****************************************************************************
0493  *                            Frontend to backend events
0494  *****************************************************************************
0495  *
0496  * Out events may be sent only when requested by backend, and receipt
0497  * of an unknown out event is an error.
0498  * No out events currently defined.
0499 
0500  * All event packets have the same length (40 octets)
0501  * All event packets have common header:
0502  *          0         octet
0503  * +-----------------+
0504  * |       type      |
0505  * +-----------------+
0506  * type - uint8_t, event code
0507  */
0508 
0509 #define XENKBD_OUT_EVENT_SIZE 40
0510 
0511 union xenkbd_out_event {
0512     uint8_t type;
0513     char pad[XENKBD_OUT_EVENT_SIZE];
0514 };
0515 
0516 /*
0517  *****************************************************************************
0518  *                            Shared page
0519  *****************************************************************************
0520  */
0521 
0522 #define XENKBD_IN_RING_SIZE 2048
0523 #define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE)
0524 #define XENKBD_IN_RING_OFFS 1024
0525 #define XENKBD_IN_RING(page) \
0526     ((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS))
0527 #define XENKBD_IN_RING_REF(page, idx) \
0528     (XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN])
0529 
0530 #define XENKBD_OUT_RING_SIZE 1024
0531 #define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE)
0532 #define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE)
0533 #define XENKBD_OUT_RING(page) \
0534     ((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS))
0535 #define XENKBD_OUT_RING_REF(page, idx) \
0536     (XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN])
0537 
0538 struct xenkbd_page {
0539     uint32_t in_cons, in_prod;
0540     uint32_t out_cons, out_prod;
0541 };
0542 
0543 #endif /* __XEN_PUBLIC_IO_KBDIF_H__ */