1 /* 2 * kbdif.h -- Xen virtual keyboard/mouse 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com> 23 * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com> 24 */ 25 26 #ifndef __XEN_PUBLIC_IO_KBDIF_H__ 27 #define __XEN_PUBLIC_IO_KBDIF_H__ 28 29 /* 30 ***************************************************************************** 31 * Feature and Parameter Negotiation 32 ***************************************************************************** 33 * 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. 38 * 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. 43 * 44 ***************************************************************************** 45 * Backend XenBus Nodes 46 ***************************************************************************** 47 * 48 *---------------------------- Features supported ---------------------------- 49 * 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. 53 * 54 * feature-abs-pointer 55 * Values: <uint> 56 * 57 * Backends, which support reporting of absolute coordinates for pointer 58 * device should set this to 1. 59 * 60 * feature-multi-touch 61 * Values: <uint> 62 * 63 * Backends, which support reporting of multi-touch events 64 * should set this to 1. 65 * 66 * feature-raw-pointer 67 * Values: <uint> 68 * 69 * Backends, which support reporting raw (unscaled) absolute coordinates 70 * for pointer devices should set this to 1. Raw (unscaled) values have 71 * a range of [0, 0x7fff]. 72 * 73 *------------------------- Pointer Device Parameters ------------------------ 74 * 75 * width 76 * Values: <uint> 77 * 78 * Maximum X coordinate (width) to be used by the frontend 79 * while reporting input events, pixels, [0; UINT32_MAX]. 80 * 81 * height 82 * Values: <uint> 83 * 84 * Maximum Y coordinate (height) to be used by the frontend 85 * while reporting input events, pixels, [0; UINT32_MAX]. 86 * 87 ***************************************************************************** 88 * Frontend XenBus Nodes 89 ***************************************************************************** 90 * 91 *------------------------------ Feature request ----------------------------- 92 * 93 * Capable frontend requests features from backend via setting corresponding 94 * entries to 1 in XenStore. Requests for features not advertised as supported 95 * by the backend have no effect. 96 * 97 * request-abs-pointer 98 * Values: <uint> 99 * 100 * Request backend to report absolute pointer coordinates 101 * (XENKBD_TYPE_POS) instead of relative ones (XENKBD_TYPE_MOTION). 102 * 103 * request-multi-touch 104 * Values: <uint> 105 * 106 * Request backend to report multi-touch events. 107 * 108 * request-raw-pointer 109 * Values: <uint> 110 * 111 * Request backend to report raw unscaled absolute pointer coordinates. 112 * This option is only valid if request-abs-pointer is also set. 113 * Raw unscaled coordinates have the range [0, 0x7fff] 114 * 115 *----------------------- Request Transport Parameters ----------------------- 116 * 117 * event-channel 118 * Values: <uint> 119 * 120 * The identifier of the Xen event channel used to signal activity 121 * in the ring buffer. 122 * 123 * page-gref 124 * Values: <uint> 125 * 126 * The Xen grant reference granting permission for the backend to map 127 * a sole page in a single page sized event ring buffer. 128 * 129 * page-ref 130 * Values: <uint> 131 * 132 * OBSOLETE, not recommended for use. 133 * PFN of the shared page. 134 * 135 *----------------------- Multi-touch Device Parameters ----------------------- 136 * 137 * multi-touch-num-contacts 138 * Values: <uint> 139 * 140 * Number of simultaneous touches reported. 141 * 142 * multi-touch-width 143 * Values: <uint> 144 * 145 * Width of the touch area to be used by the frontend 146 * while reporting input events, pixels, [0; UINT32_MAX]. 147 * 148 * multi-touch-height 149 * Values: <uint> 150 * 151 * Height of the touch area to be used by the frontend 152 * while reporting input events, pixels, [0; UINT32_MAX]. 153 */ 154 155 /* 156 * EVENT CODES. 157 */ 158 159 #define XENKBD_TYPE_MOTION 1 160 #define XENKBD_TYPE_RESERVED 2 161 #define XENKBD_TYPE_KEY 3 162 #define XENKBD_TYPE_POS 4 163 #define XENKBD_TYPE_MTOUCH 5 164 165 /* Multi-touch event sub-codes */ 166 167 #define XENKBD_MT_EV_DOWN 0 168 #define XENKBD_MT_EV_UP 1 169 #define XENKBD_MT_EV_MOTION 2 170 #define XENKBD_MT_EV_SYN 3 171 #define XENKBD_MT_EV_SHAPE 4 172 #define XENKBD_MT_EV_ORIENT 5 173 174 /* 175 * CONSTANTS, XENSTORE FIELD AND PATH NAME STRINGS, HELPERS. 176 */ 177 178 #define XENKBD_DRIVER_NAME "vkbd" 179 180 #define XENKBD_FIELD_FEAT_ABS_POINTER "feature-abs-pointer" 181 #define XENKBD_FIELD_FEAT_MTOUCH "feature-multi-touch" 182 #define XENKBD_FIELD_REQ_ABS_POINTER "request-abs-pointer" 183 #define XENKBD_FIELD_REQ_MTOUCH "request-multi-touch" 184 #define XENKBD_FIELD_RING_GREF "page-gref" 185 #define XENKBD_FIELD_EVT_CHANNEL "event-channel" 186 #define XENKBD_FIELD_WIDTH "width" 187 #define XENKBD_FIELD_HEIGHT "height" 188 #define XENKBD_FIELD_MT_WIDTH "multi-touch-width" 189 #define XENKBD_FIELD_MT_HEIGHT "multi-touch-height" 190 #define XENKBD_FIELD_MT_NUM_CONTACTS "multi-touch-num-contacts" 191 192 /* OBSOLETE, not recommended for use */ 193 #define XENKBD_FIELD_RING_REF "page-ref" 194 195 /* 196 ***************************************************************************** 197 * Description of the protocol between frontend and backend driver. 198 ***************************************************************************** 199 * 200 * The two halves of a Para-virtual driver communicate with 201 * each other using a shared page and an event channel. 202 * Shared page contains a ring with event structures. 203 * 204 * All reserved fields in the structures below must be 0. 205 * 206 ***************************************************************************** 207 * Backend to frontend events 208 ***************************************************************************** 209 * 210 * Frontends should ignore unknown in events. 211 * All event packets have the same length (40 octets) 212 * All event packets have common header: 213 * 214 * 0 octet 215 * +-----------------+ 216 * | type | 217 * +-----------------+ 218 * type - uint8_t, event code, XENKBD_TYPE_??? 219 * 220 * 221 * Pointer relative movement event 222 * 0 1 2 3 octet 223 * +----------------+----------------+----------------+----------------+ 224 * | _TYPE_MOTION | reserved | 4 225 * +----------------+----------------+----------------+----------------+ 226 * | rel_x | 8 227 * +----------------+----------------+----------------+----------------+ 228 * | rel_y | 12 229 * +----------------+----------------+----------------+----------------+ 230 * | rel_z | 16 231 * +----------------+----------------+----------------+----------------+ 232 * | reserved | 20 233 * +----------------+----------------+----------------+----------------+ 234 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 235 * +----------------+----------------+----------------+----------------+ 236 * | reserved | 40 237 * +----------------+----------------+----------------+----------------+ 238 * 239 * rel_x - int32_t, relative X motion 240 * rel_y - int32_t, relative Y motion 241 * rel_z - int32_t, relative Z motion (wheel) 242 */ 243 244 struct xenkbd_motion 245 { 246 uint8_t type; 247 int32_t rel_x; 248 int32_t rel_y; 249 int32_t rel_z; 250 }; 251 252 /* 253 * Key event (includes pointer buttons) 254 * 0 1 2 3 octet 255 * +----------------+----------------+----------------+----------------+ 256 * | _TYPE_KEY | pressed | reserved | 4 257 * +----------------+----------------+----------------+----------------+ 258 * | keycode | 8 259 * +----------------+----------------+----------------+----------------+ 260 * | reserved | 12 261 * +----------------+----------------+----------------+----------------+ 262 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 263 * +----------------+----------------+----------------+----------------+ 264 * | reserved | 40 265 * +----------------+----------------+----------------+----------------+ 266 * 267 * pressed - uint8_t, 1 if pressed; 0 otherwise 268 * keycode - uint32_t, KEY_* from linux/input.h 269 */ 270 271 struct xenkbd_key 272 { 273 uint8_t type; 274 uint8_t pressed; 275 uint32_t keycode; 276 }; 277 278 /* 279 * Pointer absolute position event 280 * 0 1 2 3 octet 281 * +----------------+----------------+----------------+----------------+ 282 * | _TYPE_POS | reserved | 4 283 * +----------------+----------------+----------------+----------------+ 284 * | abs_x | 8 285 * +----------------+----------------+----------------+----------------+ 286 * | abs_y | 12 287 * +----------------+----------------+----------------+----------------+ 288 * | rel_z | 16 289 * +----------------+----------------+----------------+----------------+ 290 * | reserved | 20 291 * +----------------+----------------+----------------+----------------+ 292 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 293 * +----------------+----------------+----------------+----------------+ 294 * | reserved | 40 295 * +----------------+----------------+----------------+----------------+ 296 * 297 * abs_x - int32_t, absolute X position (in FB pixels) 298 * abs_y - int32_t, absolute Y position (in FB pixels) 299 * rel_z - int32_t, relative Z motion (wheel) 300 */ 301 302 struct xenkbd_position 303 { 304 uint8_t type; 305 int32_t abs_x; 306 int32_t abs_y; 307 int32_t rel_z; 308 }; 309 310 /* 311 * Multi-touch event and its sub-types 312 * 313 * All multi-touch event packets have common header: 314 * 315 * 0 1 2 3 octet 316 * +----------------+----------------+----------------+----------------+ 317 * | _TYPE_MTOUCH | event_type | contact_id | reserved | 4 318 * +----------------+----------------+----------------+----------------+ 319 * | reserved | 8 320 * +----------------+----------------+----------------+----------------+ 321 * 322 * event_type - unt8_t, multi-touch event sub-type, XENKBD_MT_EV_??? 323 * contact_id - unt8_t, ID of the contact 324 * 325 * Touch interactions can consist of one or more contacts. 326 * For each contact, a series of events is generated, starting 327 * with a down event, followed by zero or more motion events, 328 * and ending with an up event. Events relating to the same 329 * contact point can be identified by the ID of the sequence: contact ID. 330 * Contact ID may be reused after XENKBD_MT_EV_UP event and 331 * is in the [0; XENKBD_FIELD_NUM_CONTACTS - 1] range. 332 * 333 * For further information please refer to documentation on Wayland [1], 334 * Linux [2] and Windows [3] multi-touch support. 335 * 336 * [1] https://cgit.freedesktop.org/wayland/wayland/tree/protocol/wayland.xml 337 * [2] https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt 338 * [3] https://msdn.microsoft.com/en-us/library/jj151564(v=vs.85).aspx 339 * 340 * 341 * Multi-touch down event - sent when a new touch is made: touch is assigned 342 * a unique contact ID, sent with this and consequent events related 343 * to this touch. 344 * 0 1 2 3 octet 345 * +----------------+----------------+----------------+----------------+ 346 * | _TYPE_MTOUCH | _MT_EV_DOWN | contact_id | reserved | 4 347 * +----------------+----------------+----------------+----------------+ 348 * | reserved | 8 349 * +----------------+----------------+----------------+----------------+ 350 * | abs_x | 12 351 * +----------------+----------------+----------------+----------------+ 352 * | abs_y | 16 353 * +----------------+----------------+----------------+----------------+ 354 * | reserved | 20 355 * +----------------+----------------+----------------+----------------+ 356 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 357 * +----------------+----------------+----------------+----------------+ 358 * | reserved | 40 359 * +----------------+----------------+----------------+----------------+ 360 * 361 * abs_x - int32_t, absolute X position, in pixels 362 * abs_y - int32_t, absolute Y position, in pixels 363 * 364 * Multi-touch contact release event 365 * 0 1 2 3 octet 366 * +----------------+----------------+----------------+----------------+ 367 * | _TYPE_MTOUCH | _MT_EV_UP | contact_id | reserved | 4 368 * +----------------+----------------+----------------+----------------+ 369 * | reserved | 8 370 * +----------------+----------------+----------------+----------------+ 371 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 372 * +----------------+----------------+----------------+----------------+ 373 * | reserved | 40 374 * +----------------+----------------+----------------+----------------+ 375 * 376 * Multi-touch motion event 377 * 0 1 2 3 octet 378 * +----------------+----------------+----------------+----------------+ 379 * | _TYPE_MTOUCH | _MT_EV_MOTION | contact_id | reserved | 4 380 * +----------------+----------------+----------------+----------------+ 381 * | reserved | 8 382 * +----------------+----------------+----------------+----------------+ 383 * | abs_x | 12 384 * +----------------+----------------+----------------+----------------+ 385 * | abs_y | 16 386 * +----------------+----------------+----------------+----------------+ 387 * | reserved | 20 388 * +----------------+----------------+----------------+----------------+ 389 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 390 * +----------------+----------------+----------------+----------------+ 391 * | reserved | 40 392 * +----------------+----------------+----------------+----------------+ 393 * 394 * abs_x - int32_t, absolute X position, in pixels, 395 * abs_y - int32_t, absolute Y position, in pixels, 396 * 397 * Multi-touch input synchronization event - shows end of a set of events 398 * which logically belong together. 399 * 0 1 2 3 octet 400 * +----------------+----------------+----------------+----------------+ 401 * | _TYPE_MTOUCH | _MT_EV_SYN | contact_id | reserved | 4 402 * +----------------+----------------+----------------+----------------+ 403 * | reserved | 8 404 * +----------------+----------------+----------------+----------------+ 405 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 406 * +----------------+----------------+----------------+----------------+ 407 * | reserved | 40 408 * +----------------+----------------+----------------+----------------+ 409 * 410 * Multi-touch shape event - touch point's shape has changed its shape. 411 * Shape is approximated by an ellipse through the major and minor axis 412 * lengths: major is the longer diameter of the ellipse and minor is the 413 * shorter one. Center of the ellipse is reported via 414 * XENKBD_MT_EV_DOWN/XENKBD_MT_EV_MOTION events. 415 * 0 1 2 3 octet 416 * +----------------+----------------+----------------+----------------+ 417 * | _TYPE_MTOUCH | _MT_EV_SHAPE | contact_id | reserved | 4 418 * +----------------+----------------+----------------+----------------+ 419 * | reserved | 8 420 * +----------------+----------------+----------------+----------------+ 421 * | major | 12 422 * +----------------+----------------+----------------+----------------+ 423 * | minor | 16 424 * +----------------+----------------+----------------+----------------+ 425 * | reserved | 20 426 * +----------------+----------------+----------------+----------------+ 427 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 428 * +----------------+----------------+----------------+----------------+ 429 * | reserved | 40 430 * +----------------+----------------+----------------+----------------+ 431 * 432 * major - unt32_t, length of the major axis, pixels 433 * minor - unt32_t, length of the minor axis, pixels 434 * 435 * Multi-touch orientation event - touch point's shape has changed 436 * its orientation: calculated as a clockwise angle between the major axis 437 * of the ellipse and positive Y axis in degrees, [-180; +180]. 438 * 0 1 2 3 octet 439 * +----------------+----------------+----------------+----------------+ 440 * | _TYPE_MTOUCH | _MT_EV_ORIENT | contact_id | reserved | 4 441 * +----------------+----------------+----------------+----------------+ 442 * | reserved | 8 443 * +----------------+----------------+----------------+----------------+ 444 * | orientation | reserved | 12 445 * +----------------+----------------+----------------+----------------+ 446 * | reserved | 16 447 * +----------------+----------------+----------------+----------------+ 448 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/| 449 * +----------------+----------------+----------------+----------------+ 450 * | reserved | 40 451 * +----------------+----------------+----------------+----------------+ 452 * 453 * orientation - int16_t, clockwise angle of the major axis 454 */ 455 456 struct xenkbd_mtouch { 457 uint8_t type; /* XENKBD_TYPE_MTOUCH */ 458 uint8_t event_type; /* XENKBD_MT_EV_??? */ 459 uint8_t contact_id; 460 uint8_t reserved[5]; /* reserved for the future use */ 461 union { 462 struct { 463 int32_t abs_x; /* absolute X position, pixels */ 464 int32_t abs_y; /* absolute Y position, pixels */ 465 } pos; 466 struct { 467 uint32_t major; /* length of the major axis, pixels */ 468 uint32_t minor; /* length of the minor axis, pixels */ 469 } shape; 470 int16_t orientation; /* clockwise angle of the major axis */ 471 } u; 472 }; 473 474 #define XENKBD_IN_EVENT_SIZE 40 475 476 union xenkbd_in_event 477 { 478 uint8_t type; 479 struct xenkbd_motion motion; 480 struct xenkbd_key key; 481 struct xenkbd_position pos; 482 struct xenkbd_mtouch mtouch; 483 char pad[XENKBD_IN_EVENT_SIZE]; 484 }; 485 486 /* 487 ***************************************************************************** 488 * Frontend to backend events 489 ***************************************************************************** 490 * 491 * Out events may be sent only when requested by backend, and receipt 492 * of an unknown out event is an error. 493 * No out events currently defined. 494 495 * All event packets have the same length (40 octets) 496 * All event packets have common header: 497 * 0 octet 498 * +-----------------+ 499 * | type | 500 * +-----------------+ 501 * type - uint8_t, event code 502 */ 503 504 #define XENKBD_OUT_EVENT_SIZE 40 505 506 union xenkbd_out_event 507 { 508 uint8_t type; 509 char pad[XENKBD_OUT_EVENT_SIZE]; 510 }; 511 512 /* 513 ***************************************************************************** 514 * Shared page 515 ***************************************************************************** 516 */ 517 518 #define XENKBD_IN_RING_SIZE 2048 519 #define XENKBD_IN_RING_LEN (XENKBD_IN_RING_SIZE / XENKBD_IN_EVENT_SIZE) 520 #define XENKBD_IN_RING_OFFS 1024 521 #define XENKBD_IN_RING(page) \ 522 ((union xenkbd_in_event *)((char *)(page) + XENKBD_IN_RING_OFFS)) 523 #define XENKBD_IN_RING_REF(page, idx) \ 524 (XENKBD_IN_RING((page))[(idx) % XENKBD_IN_RING_LEN]) 525 526 #define XENKBD_OUT_RING_SIZE 1024 527 #define XENKBD_OUT_RING_LEN (XENKBD_OUT_RING_SIZE / XENKBD_OUT_EVENT_SIZE) 528 #define XENKBD_OUT_RING_OFFS (XENKBD_IN_RING_OFFS + XENKBD_IN_RING_SIZE) 529 #define XENKBD_OUT_RING(page) \ 530 ((union xenkbd_out_event *)((char *)(page) + XENKBD_OUT_RING_OFFS)) 531 #define XENKBD_OUT_RING_REF(page, idx) \ 532 (XENKBD_OUT_RING((page))[(idx) % XENKBD_OUT_RING_LEN]) 533 534 struct xenkbd_page 535 { 536 uint32_t in_cons, in_prod; 537 uint32_t out_cons, out_prod; 538 }; 539 540 #endif /* __XEN_PUBLIC_IO_KBDIF_H__ */ 541 542 /* 543 * Local variables: 544 * mode: C 545 * c-file-style: "BSD" 546 * c-basic-offset: 4 547 * tab-width: 4 548 * indent-tabs-mode: nil 549 * End: 550 */ 551