kbdif.h 22 KB

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