logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

dtx.h (5438B)


  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * Surface DTX (clipboard detachment system driver) user-space interface.
  4. *
  5. * Definitions, structs, and IOCTLs for the /dev/surface/dtx misc device. This
  6. * device allows user-space to control the clipboard detachment process on
  7. * Surface Book series devices.
  8. *
  9. * Copyright (C) 2020-2021 Maximilian Luz <luzmaximilian@gmail.com>
  10. */
  11. #ifndef _LINUX_SURFACE_AGGREGATOR_DTX_H
  12. #define _LINUX_SURFACE_AGGREGATOR_DTX_H
  13. #include <linux/ioctl.h>
  14. #include <linux/types.h>
  15. /* Status/error categories */
  16. #define SDTX_CATEGORY_STATUS 0x0000
  17. #define SDTX_CATEGORY_RUNTIME_ERROR 0x1000
  18. #define SDTX_CATEGORY_HARDWARE_ERROR 0x2000
  19. #define SDTX_CATEGORY_UNKNOWN 0xf000
  20. #define SDTX_CATEGORY_MASK 0xf000
  21. #define SDTX_CATEGORY(value) ((value) & SDTX_CATEGORY_MASK)
  22. #define SDTX_STATUS(code) ((code) | SDTX_CATEGORY_STATUS)
  23. #define SDTX_ERR_RT(code) ((code) | SDTX_CATEGORY_RUNTIME_ERROR)
  24. #define SDTX_ERR_HW(code) ((code) | SDTX_CATEGORY_HARDWARE_ERROR)
  25. #define SDTX_UNKNOWN(code) ((code) | SDTX_CATEGORY_UNKNOWN)
  26. #define SDTX_SUCCESS(value) (SDTX_CATEGORY(value) == SDTX_CATEGORY_STATUS)
  27. /* Latch status values */
  28. #define SDTX_LATCH_CLOSED SDTX_STATUS(0x00)
  29. #define SDTX_LATCH_OPENED SDTX_STATUS(0x01)
  30. /* Base state values */
  31. #define SDTX_BASE_DETACHED SDTX_STATUS(0x00)
  32. #define SDTX_BASE_ATTACHED SDTX_STATUS(0x01)
  33. /* Runtime errors (non-critical) */
  34. #define SDTX_DETACH_NOT_FEASIBLE SDTX_ERR_RT(0x01)
  35. #define SDTX_DETACH_TIMEDOUT SDTX_ERR_RT(0x02)
  36. /* Hardware errors (critical) */
  37. #define SDTX_ERR_FAILED_TO_OPEN SDTX_ERR_HW(0x01)
  38. #define SDTX_ERR_FAILED_TO_REMAIN_OPEN SDTX_ERR_HW(0x02)
  39. #define SDTX_ERR_FAILED_TO_CLOSE SDTX_ERR_HW(0x03)
  40. /* Base types */
  41. #define SDTX_DEVICE_TYPE_HID 0x0100
  42. #define SDTX_DEVICE_TYPE_SSH 0x0200
  43. #define SDTX_DEVICE_TYPE_MASK 0x0f00
  44. #define SDTX_DEVICE_TYPE(value) ((value) & SDTX_DEVICE_TYPE_MASK)
  45. #define SDTX_BASE_TYPE_HID(id) ((id) | SDTX_DEVICE_TYPE_HID)
  46. #define SDTX_BASE_TYPE_SSH(id) ((id) | SDTX_DEVICE_TYPE_SSH)
  47. /**
  48. * enum sdtx_device_mode - Mode describing how (and if) the clipboard is
  49. * attached to the base of the device.
  50. * @SDTX_DEVICE_MODE_TABLET: The clipboard is detached from the base and the
  51. * device operates as tablet.
  52. * @SDTX_DEVICE_MODE_LAPTOP: The clipboard is attached normally to the base
  53. * and the device operates as laptop.
  54. * @SDTX_DEVICE_MODE_STUDIO: The clipboard is attached to the base in reverse.
  55. * The device operates as tablet with keyboard and
  56. * touchpad deactivated, however, the base battery
  57. * and, if present in the specific device model, dGPU
  58. * are available to the system.
  59. */
  60. enum sdtx_device_mode {
  61. SDTX_DEVICE_MODE_TABLET = 0x00,
  62. SDTX_DEVICE_MODE_LAPTOP = 0x01,
  63. SDTX_DEVICE_MODE_STUDIO = 0x02,
  64. };
  65. /**
  66. * struct sdtx_event - Event provided by reading from the DTX device file.
  67. * @length: Length of the event payload, in bytes.
  68. * @code: Event code, detailing what type of event this is.
  69. * @data: Payload of the event, containing @length bytes.
  70. *
  71. * See &enum sdtx_event_code for currently valid event codes.
  72. */
  73. struct sdtx_event {
  74. __u16 length;
  75. __u16 code;
  76. __u8 data[];
  77. } __attribute__((__packed__));
  78. /**
  79. * enum sdtx_event_code - Code describing the type of an event.
  80. * @SDTX_EVENT_REQUEST: Detachment request event type.
  81. * @SDTX_EVENT_CANCEL: Cancel detachment process event type.
  82. * @SDTX_EVENT_BASE_CONNECTION: Base/clipboard connection change event type.
  83. * @SDTX_EVENT_LATCH_STATUS: Latch status change event type.
  84. * @SDTX_EVENT_DEVICE_MODE: Device mode change event type.
  85. *
  86. * Used in &struct sdtx_event to describe the type of the event. Further event
  87. * codes are reserved for future use. Any event parser should be able to
  88. * gracefully handle unknown events, i.e. by simply skipping them.
  89. *
  90. * Consult the DTX user-space interface documentation for details regarding
  91. * the individual event types.
  92. */
  93. enum sdtx_event_code {
  94. SDTX_EVENT_REQUEST = 1,
  95. SDTX_EVENT_CANCEL = 2,
  96. SDTX_EVENT_BASE_CONNECTION = 3,
  97. SDTX_EVENT_LATCH_STATUS = 4,
  98. SDTX_EVENT_DEVICE_MODE = 5,
  99. };
  100. /**
  101. * struct sdtx_base_info - Describes if and what type of base is connected.
  102. * @state: The state of the connection. Valid values are %SDTX_BASE_DETACHED,
  103. * %SDTX_BASE_ATTACHED, and %SDTX_DETACH_NOT_FEASIBLE (in case a base
  104. * is attached but low clipboard battery prevents detachment). Other
  105. * values are currently reserved.
  106. * @base_id: The type of base connected. Zero if no base is connected.
  107. */
  108. struct sdtx_base_info {
  109. __u16 state;
  110. __u16 base_id;
  111. } __attribute__((__packed__));
  112. /* IOCTLs */
  113. #define SDTX_IOCTL_EVENTS_ENABLE _IO(0xa5, 0x21)
  114. #define SDTX_IOCTL_EVENTS_DISABLE _IO(0xa5, 0x22)
  115. #define SDTX_IOCTL_LATCH_LOCK _IO(0xa5, 0x23)
  116. #define SDTX_IOCTL_LATCH_UNLOCK _IO(0xa5, 0x24)
  117. #define SDTX_IOCTL_LATCH_REQUEST _IO(0xa5, 0x25)
  118. #define SDTX_IOCTL_LATCH_CONFIRM _IO(0xa5, 0x26)
  119. #define SDTX_IOCTL_LATCH_HEARTBEAT _IO(0xa5, 0x27)
  120. #define SDTX_IOCTL_LATCH_CANCEL _IO(0xa5, 0x28)
  121. #define SDTX_IOCTL_GET_BASE_INFO _IOR(0xa5, 0x29, struct sdtx_base_info)
  122. #define SDTX_IOCTL_GET_DEVICE_MODE _IOR(0xa5, 0x2a, __u16)
  123. #define SDTX_IOCTL_GET_LATCH_STATUS _IOR(0xa5, 0x2b, __u16)
  124. #endif /* _LINUX_SURFACE_AGGREGATOR_DTX_H */