kbdif.h 23 KB

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