162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0+ 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci.. |__u16| replace:: :c:type:`__u16 <__u16>` 462306a36Sopenharmony_ci.. |sdtx_event| replace:: :c:type:`struct sdtx_event <sdtx_event>` 562306a36Sopenharmony_ci.. |sdtx_event_code| replace:: :c:type:`enum sdtx_event_code <sdtx_event_code>` 662306a36Sopenharmony_ci.. |sdtx_base_info| replace:: :c:type:`struct sdtx_base_info <sdtx_base_info>` 762306a36Sopenharmony_ci.. |sdtx_device_mode| replace:: :c:type:`struct sdtx_device_mode <sdtx_device_mode>` 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci====================================================== 1062306a36Sopenharmony_ciUser-Space DTX (Clipboard Detachment System) Interface 1162306a36Sopenharmony_ci====================================================== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciThe ``surface_dtx`` driver is responsible for proper clipboard detachment 1462306a36Sopenharmony_ciand re-attachment handling. To this end, it provides the ``/dev/surface/dtx`` 1562306a36Sopenharmony_cidevice file, through which it can interface with a user-space daemon. This 1662306a36Sopenharmony_cidaemon is then ultimately responsible for determining and taking necessary 1762306a36Sopenharmony_ciactions, such as unmounting devices attached to the base, 1862306a36Sopenharmony_ciunloading/reloading the graphics-driver, user-notifications, etc. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciThere are two basic communication principles used in this driver: Commands 2162306a36Sopenharmony_ci(in other parts of the documentation also referred to as requests) and 2262306a36Sopenharmony_cievents. Commands are sent to the EC and may have a different implications in 2362306a36Sopenharmony_cidifferent contexts. Events are sent by the EC upon some internal state 2462306a36Sopenharmony_cichange. Commands are always driver-initiated, whereas events are always 2562306a36Sopenharmony_ciinitiated by the EC. 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci.. contents:: 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciNomenclature 3062306a36Sopenharmony_ci============ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci* **Clipboard:** 3362306a36Sopenharmony_ci The detachable upper part of the Surface Book, housing the screen and CPU. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci* **Base:** 3662306a36Sopenharmony_ci The lower part of the Surface Book from which the clipboard can be 3762306a36Sopenharmony_ci detached, optionally (model dependent) housing the discrete GPU (dGPU). 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci* **Latch:** 4062306a36Sopenharmony_ci The mechanism keeping the clipboard attached to the base in normal 4162306a36Sopenharmony_ci operation and allowing it to be detached when requested. 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci* **Silently ignored commands:** 4462306a36Sopenharmony_ci The command is accepted by the EC as a valid command and acknowledged 4562306a36Sopenharmony_ci (following the standard communication protocol), but the EC does not act 4662306a36Sopenharmony_ci upon it, i.e. ignores it.e upper part of the 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciDetachment Process 5062306a36Sopenharmony_ci================== 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciWarning: This part of the documentation is based on reverse engineering and 5362306a36Sopenharmony_citesting and thus may contain errors or be incomplete. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciLatch States 5662306a36Sopenharmony_ci------------ 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciThe latch mechanism has two major states: *open* and *closed*. In the 5962306a36Sopenharmony_ci*closed* state (default), the clipboard is secured to the base, whereas in 6062306a36Sopenharmony_cithe *open* state, the clipboard can be removed by a user. 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ciThe latch can additionally be locked and, correspondingly, unlocked, which 6362306a36Sopenharmony_cican influence the detachment procedure. Specifically, this locking mechanism 6462306a36Sopenharmony_ciis intended to prevent the dGPU, positioned in the base of the device, from 6562306a36Sopenharmony_cibeing hot-unplugged while in use. More details can be found in the 6662306a36Sopenharmony_cidocumentation for the detachment procedure below. By default, the latch is 6762306a36Sopenharmony_ciunlocked. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciDetachment Procedure 7062306a36Sopenharmony_ci-------------------- 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ciNote that the detachment process is governed fully by the EC. The 7362306a36Sopenharmony_ci``surface_dtx`` driver only relays events from the EC to user-space and 7462306a36Sopenharmony_cicommands from user-space to the EC, i.e. it does not influence this process. 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciThe detachment process is started with the user pressing the *detach* button 7762306a36Sopenharmony_cion the base of the device or executing the ``SDTX_IOCTL_LATCH_REQUEST`` IOCTL. 7862306a36Sopenharmony_ciFollowing that: 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci1. The EC turns on the indicator led on the detach-button, sends a 8162306a36Sopenharmony_ci *detach-request* event (``SDTX_EVENT_REQUEST``), and awaits further 8262306a36Sopenharmony_ci instructions/commands. In case the latch is unlocked, the led will flash 8362306a36Sopenharmony_ci green. If the latch has been locked, the led will be solid red 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci2. The event is, via the ``surface_dtx`` driver, relayed to user-space, where 8662306a36Sopenharmony_ci an appropriate user-space daemon can handle it and send instructions back 8762306a36Sopenharmony_ci to the EC via IOCTLs provided by this driver. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci3. The EC waits for instructions from user-space and acts according to them. 9062306a36Sopenharmony_ci If the EC does not receive any instructions in a given period, it will 9162306a36Sopenharmony_ci time out and continue as follows: 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci - If the latch is unlocked, the EC will open the latch and the clipboard 9462306a36Sopenharmony_ci can be detached from the base. This is the exact behavior as without 9562306a36Sopenharmony_ci this driver or any user-space daemon. See the ``SDTX_IOCTL_LATCH_CONFIRM`` 9662306a36Sopenharmony_ci description below for more details on the follow-up behavior of the EC. 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci - If the latch is locked, the EC will *not* open the latch, meaning the 9962306a36Sopenharmony_ci clipboard cannot be detached from the base. Furthermore, the EC sends 10062306a36Sopenharmony_ci an cancel event (``SDTX_EVENT_CANCEL``) detailing this with the cancel 10162306a36Sopenharmony_ci reason ``SDTX_DETACH_TIMEDOUT`` (see :ref:`events` for details). 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ciValid responses by a user-space daemon to a detachment request event are: 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci- Execute ``SDTX_IOCTL_LATCH_REQUEST``. This will immediately abort the 10662306a36Sopenharmony_ci detachment process. Furthermore, the EC will send a detach-request event, 10762306a36Sopenharmony_ci similar to the user pressing the detach-button to cancel said process (see 10862306a36Sopenharmony_ci below). 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci- Execute ``SDTX_IOCTL_LATCH_CONFIRM``. This will cause the EC to open the 11162306a36Sopenharmony_ci latch, after which the user can separate clipboard and base. 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci As this changes the latch state, a *latch-status* event 11462306a36Sopenharmony_ci (``SDTX_EVENT_LATCH_STATUS``) will be sent once the latch has been opened 11562306a36Sopenharmony_ci successfully. If the EC fails to open the latch, e.g. due to hardware 11662306a36Sopenharmony_ci error or low battery, a latch-cancel event (``SDTX_EVENT_CANCEL``) will be 11762306a36Sopenharmony_ci sent with the cancel reason indicating the specific failure. 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci If the latch is currently locked, the latch will automatically be 12062306a36Sopenharmony_ci unlocked before it is opened. 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci- Execute ``SDTX_IOCTL_LATCH_HEARTBEAT``. This will reset the internal timeout. 12362306a36Sopenharmony_ci No other actions will be performed, i.e. the detachment process will neither 12462306a36Sopenharmony_ci be completed nor canceled, and the EC will still be waiting for further 12562306a36Sopenharmony_ci responses. 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci- Execute ``SDTX_IOCTL_LATCH_CANCEL``. This will abort the detachment process, 12862306a36Sopenharmony_ci similar to ``SDTX_IOCTL_LATCH_REQUEST``, described above, or the button 12962306a36Sopenharmony_ci press, described below. A *generic request* event (``SDTX_EVENT_REQUEST``) 13062306a36Sopenharmony_ci is send in response to this. In contrast to those, however, this command 13162306a36Sopenharmony_ci does not trigger a new detachment process if none is currently in 13262306a36Sopenharmony_ci progress. 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci- Do nothing. The detachment process eventually times out as described in 13562306a36Sopenharmony_ci point 3. 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ciSee :ref:`ioctls` for more details on these responses. 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciIt is important to note that, if the user presses the detach button at any 14062306a36Sopenharmony_cipoint when a detachment operation is in progress (i.e. after the EC has sent 14162306a36Sopenharmony_cithe initial *detach-request* event (``SDTX_EVENT_REQUEST``) and before it 14262306a36Sopenharmony_cireceived the corresponding response concluding the process), the detachment 14362306a36Sopenharmony_ciprocess is canceled on the EC-level and an identical event is being sent. 14462306a36Sopenharmony_ciThus a *detach-request* event, by itself, does not signal the start of the 14562306a36Sopenharmony_cidetachment process. 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ciThe detachment process may further be canceled by the EC due to hardware 14862306a36Sopenharmony_cifailures or a low clipboard battery. This is done via a cancel event 14962306a36Sopenharmony_ci(``SDTX_EVENT_CANCEL``) with the corresponding cancel reason. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ciUser-Space Interface Documentation 15362306a36Sopenharmony_ci================================== 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ciError Codes and Status Values 15662306a36Sopenharmony_ci----------------------------- 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ciError and status codes are divided into different categories, which can be 15962306a36Sopenharmony_ciused to determine if the status code is an error, and, if it is, the 16062306a36Sopenharmony_ciseverity and type of that error. The current categories are: 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci.. flat-table:: Overview of Status/Error Categories. 16362306a36Sopenharmony_ci :widths: 2 1 3 16462306a36Sopenharmony_ci :header-rows: 1 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci * - Name 16762306a36Sopenharmony_ci - Value 16862306a36Sopenharmony_ci - Short Description 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci * - ``STATUS`` 17162306a36Sopenharmony_ci - ``0x0000`` 17262306a36Sopenharmony_ci - Non-error status codes. 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci * - ``RUNTIME_ERROR`` 17562306a36Sopenharmony_ci - ``0x1000`` 17662306a36Sopenharmony_ci - Non-critical runtime errors. 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci * - ``HARDWARE_ERROR`` 17962306a36Sopenharmony_ci - ``0x2000`` 18062306a36Sopenharmony_ci - Critical hardware failures. 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci * - ``UNKNOWN`` 18362306a36Sopenharmony_ci - ``0xF000`` 18462306a36Sopenharmony_ci - Unknown error codes. 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ciOther categories are reserved for future use. The ``SDTX_CATEGORY()`` macro 18762306a36Sopenharmony_cican be used to determine the category of any status value. The 18862306a36Sopenharmony_ci``SDTX_SUCCESS()`` macro can be used to check if the status value is a 18962306a36Sopenharmony_cisuccess value (``SDTX_CATEGORY_STATUS``) or if it indicates a failure. 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ciUnknown status or error codes sent by the EC are assigned to the ``UNKNOWN`` 19262306a36Sopenharmony_cicategory by the driver and may be implemented via their own code in the 19362306a36Sopenharmony_cifuture. 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ciCurrently used error codes are: 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci.. flat-table:: Overview of Error Codes. 19862306a36Sopenharmony_ci :widths: 2 1 1 3 19962306a36Sopenharmony_ci :header-rows: 1 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci * - Name 20262306a36Sopenharmony_ci - Category 20362306a36Sopenharmony_ci - Value 20462306a36Sopenharmony_ci - Short Description 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci * - ``SDTX_DETACH_NOT_FEASIBLE`` 20762306a36Sopenharmony_ci - ``RUNTIME`` 20862306a36Sopenharmony_ci - ``0x1001`` 20962306a36Sopenharmony_ci - Detachment not feasible due to low clipboard battery. 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci * - ``SDTX_DETACH_TIMEDOUT`` 21262306a36Sopenharmony_ci - ``RUNTIME`` 21362306a36Sopenharmony_ci - ``0x1002`` 21462306a36Sopenharmony_ci - Detachment process timed out while the latch was locked. 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci * - ``SDTX_ERR_FAILED_TO_OPEN`` 21762306a36Sopenharmony_ci - ``HARDWARE`` 21862306a36Sopenharmony_ci - ``0x2001`` 21962306a36Sopenharmony_ci - Failed to open latch. 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci * - ``SDTX_ERR_FAILED_TO_REMAIN_OPEN`` 22262306a36Sopenharmony_ci - ``HARDWARE`` 22362306a36Sopenharmony_ci - ``0x2002`` 22462306a36Sopenharmony_ci - Failed to keep latch open. 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci * - ``SDTX_ERR_FAILED_TO_CLOSE`` 22762306a36Sopenharmony_ci - ``HARDWARE`` 22862306a36Sopenharmony_ci - ``0x2003`` 22962306a36Sopenharmony_ci - Failed to close latch. 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ciOther error codes are reserved for future use. Non-error status codes may 23262306a36Sopenharmony_cioverlap and are generally only unique within their use-case: 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci.. flat-table:: Latch Status Codes. 23562306a36Sopenharmony_ci :widths: 2 1 1 3 23662306a36Sopenharmony_ci :header-rows: 1 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci * - Name 23962306a36Sopenharmony_ci - Category 24062306a36Sopenharmony_ci - Value 24162306a36Sopenharmony_ci - Short Description 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci * - ``SDTX_LATCH_CLOSED`` 24462306a36Sopenharmony_ci - ``STATUS`` 24562306a36Sopenharmony_ci - ``0x0000`` 24662306a36Sopenharmony_ci - Latch is closed/has been closed. 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci * - ``SDTX_LATCH_OPENED`` 24962306a36Sopenharmony_ci - ``STATUS`` 25062306a36Sopenharmony_ci - ``0x0001`` 25162306a36Sopenharmony_ci - Latch is open/has been opened. 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci.. flat-table:: Base State Codes. 25462306a36Sopenharmony_ci :widths: 2 1 1 3 25562306a36Sopenharmony_ci :header-rows: 1 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci * - Name 25862306a36Sopenharmony_ci - Category 25962306a36Sopenharmony_ci - Value 26062306a36Sopenharmony_ci - Short Description 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci * - ``SDTX_BASE_DETACHED`` 26362306a36Sopenharmony_ci - ``STATUS`` 26462306a36Sopenharmony_ci - ``0x0000`` 26562306a36Sopenharmony_ci - Base has been detached/is not present. 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci * - ``SDTX_BASE_ATTACHED`` 26862306a36Sopenharmony_ci - ``STATUS`` 26962306a36Sopenharmony_ci - ``0x0001`` 27062306a36Sopenharmony_ci - Base has been attached/is present. 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ciAgain, other codes are reserved for future use. 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci.. _events: 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ciEvents 27762306a36Sopenharmony_ci------ 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ciEvents can be received by reading from the device file. They are disabled by 28062306a36Sopenharmony_cidefault and have to be enabled by executing ``SDTX_IOCTL_EVENTS_ENABLE`` 28162306a36Sopenharmony_cifirst. All events follow the layout prescribed by |sdtx_event|. Specific 28262306a36Sopenharmony_cievent types can be identified by their event code, described in 28362306a36Sopenharmony_ci|sdtx_event_code|. Note that other event codes are reserved for future use, 28462306a36Sopenharmony_cithus an event parser must be able to handle any unknown/unsupported event 28562306a36Sopenharmony_citypes gracefully, by relying on the payload length given in the event header. 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ciCurrently provided event types are: 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ci.. flat-table:: Overview of DTX events. 29062306a36Sopenharmony_ci :widths: 2 1 1 3 29162306a36Sopenharmony_ci :header-rows: 1 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ci * - Name 29462306a36Sopenharmony_ci - Code 29562306a36Sopenharmony_ci - Payload 29662306a36Sopenharmony_ci - Short Description 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci * - ``SDTX_EVENT_REQUEST`` 29962306a36Sopenharmony_ci - ``1`` 30062306a36Sopenharmony_ci - ``0`` bytes 30162306a36Sopenharmony_ci - Detachment process initiated/aborted. 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ci * - ``SDTX_EVENT_CANCEL`` 30462306a36Sopenharmony_ci - ``2`` 30562306a36Sopenharmony_ci - ``2`` bytes 30662306a36Sopenharmony_ci - EC canceled detachment process. 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci * - ``SDTX_EVENT_BASE_CONNECTION`` 30962306a36Sopenharmony_ci - ``3`` 31062306a36Sopenharmony_ci - ``4`` bytes 31162306a36Sopenharmony_ci - Base connection state changed. 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci * - ``SDTX_EVENT_LATCH_STATUS`` 31462306a36Sopenharmony_ci - ``4`` 31562306a36Sopenharmony_ci - ``2`` bytes 31662306a36Sopenharmony_ci - Latch status changed. 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci * - ``SDTX_EVENT_DEVICE_MODE`` 31962306a36Sopenharmony_ci - ``5`` 32062306a36Sopenharmony_ci - ``2`` bytes 32162306a36Sopenharmony_ci - Device mode changed. 32262306a36Sopenharmony_ci 32362306a36Sopenharmony_ciIndividual events in more detail: 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci``SDTX_EVENT_REQUEST`` 32662306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^ 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ciSent when a detachment process is started or, if in progress, aborted by the 32962306a36Sopenharmony_ciuser, either via a detach button press or a detach request 33062306a36Sopenharmony_ci(``SDTX_IOCTL_LATCH_REQUEST``) being sent from user-space. 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ciDoes not have any payload. 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci``SDTX_EVENT_CANCEL`` 33562306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^ 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ciSent when a detachment process is canceled by the EC due to unfulfilled 33862306a36Sopenharmony_cipreconditions (e.g. clipboard battery too low to detach) or hardware 33962306a36Sopenharmony_cifailure. The reason for cancellation is given in the event payload detailed 34062306a36Sopenharmony_cibelow and can be one of 34162306a36Sopenharmony_ci 34262306a36Sopenharmony_ci* ``SDTX_DETACH_TIMEDOUT``: Detachment timed out while the latch was locked. 34362306a36Sopenharmony_ci The latch has neither been opened nor unlocked. 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci* ``SDTX_DETACH_NOT_FEASIBLE``: Detachment not feasible due to low clipboard 34662306a36Sopenharmony_ci battery. 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_OPEN``: Could not open the latch (hardware failure). 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_REMAIN_OPEN``: Could not keep the latch open (hardware 35162306a36Sopenharmony_ci failure). 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_CLOSE``: Could not close the latch (hardware failure). 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ciOther error codes in this context are reserved for future use. 35662306a36Sopenharmony_ci 35762306a36Sopenharmony_ciThese codes can be classified via the ``SDTX_CATEGORY()`` macro to discern 35862306a36Sopenharmony_cibetween critical hardware errors (``SDTX_CATEGORY_HARDWARE_ERROR``) or 35962306a36Sopenharmony_ciruntime errors (``SDTX_CATEGORY_RUNTIME_ERROR``), the latter of which may 36062306a36Sopenharmony_cihappen during normal operation if certain preconditions for detachment are 36162306a36Sopenharmony_cinot given. 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci.. flat-table:: Detachment Cancel Event Payload 36462306a36Sopenharmony_ci :widths: 1 1 4 36562306a36Sopenharmony_ci :header-rows: 1 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci * - Field 36862306a36Sopenharmony_ci - Type 36962306a36Sopenharmony_ci - Description 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci * - ``reason`` 37262306a36Sopenharmony_ci - |__u16| 37362306a36Sopenharmony_ci - Reason for cancellation. 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_ci``SDTX_EVENT_BASE_CONNECTION`` 37662306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ciSent when the base connection state has changed, i.e. when the base has been 37962306a36Sopenharmony_ciattached, detached, or detachment has become infeasible due to low clipboard 38062306a36Sopenharmony_cibattery. The new state and, if a base is connected, ID of the base is 38162306a36Sopenharmony_ciprovided as payload of type |sdtx_base_info| with its layout presented 38262306a36Sopenharmony_cibelow: 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci.. flat-table:: Base-Connection-Change Event Payload 38562306a36Sopenharmony_ci :widths: 1 1 4 38662306a36Sopenharmony_ci :header-rows: 1 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci * - Field 38962306a36Sopenharmony_ci - Type 39062306a36Sopenharmony_ci - Description 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci * - ``state`` 39362306a36Sopenharmony_ci - |__u16| 39462306a36Sopenharmony_ci - Base connection state. 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci * - ``base_id`` 39762306a36Sopenharmony_ci - |__u16| 39862306a36Sopenharmony_ci - Type of base connected (zero if none). 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ciPossible values for ``state`` are: 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci* ``SDTX_BASE_DETACHED``, 40362306a36Sopenharmony_ci* ``SDTX_BASE_ATTACHED``, and 40462306a36Sopenharmony_ci* ``SDTX_DETACH_NOT_FEASIBLE``. 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_ciOther values are reserved for future use. 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci``SDTX_EVENT_LATCH_STATUS`` 40962306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^ 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ciSent when the latch status has changed, i.e. when the latch has been opened, 41262306a36Sopenharmony_ciclosed, or an error occurred. The current status is provided as payload: 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci.. flat-table:: Latch-Status-Change Event Payload 41562306a36Sopenharmony_ci :widths: 1 1 4 41662306a36Sopenharmony_ci :header-rows: 1 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci * - Field 41962306a36Sopenharmony_ci - Type 42062306a36Sopenharmony_ci - Description 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_ci * - ``status`` 42362306a36Sopenharmony_ci - |__u16| 42462306a36Sopenharmony_ci - Latch status. 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ciPossible values for ``status`` are: 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci* ``SDTX_LATCH_CLOSED``, 42962306a36Sopenharmony_ci* ``SDTX_LATCH_OPENED``, 43062306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_OPEN``, 43162306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_REMAIN_OPEN``, and 43262306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_CLOSE``. 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ciOther values are reserved for future use. 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_ci``SDTX_EVENT_DEVICE_MODE`` 43762306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^ 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ciSent when the device mode has changed. The new device mode is provided as 44062306a36Sopenharmony_cipayload: 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ci.. flat-table:: Device-Mode-Change Event Payload 44362306a36Sopenharmony_ci :widths: 1 1 4 44462306a36Sopenharmony_ci :header-rows: 1 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci * - Field 44762306a36Sopenharmony_ci - Type 44862306a36Sopenharmony_ci - Description 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci * - ``mode`` 45162306a36Sopenharmony_ci - |__u16| 45262306a36Sopenharmony_ci - Device operation mode. 45362306a36Sopenharmony_ci 45462306a36Sopenharmony_ciPossible values for ``mode`` are: 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci* ``SDTX_DEVICE_MODE_TABLET``, 45762306a36Sopenharmony_ci* ``SDTX_DEVICE_MODE_LAPTOP``, and 45862306a36Sopenharmony_ci* ``SDTX_DEVICE_MODE_STUDIO``. 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_ciOther values are reserved for future use. 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci.. _ioctls: 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ciIOCTLs 46562306a36Sopenharmony_ci------ 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ciThe following IOCTLs are provided: 46862306a36Sopenharmony_ci 46962306a36Sopenharmony_ci.. flat-table:: Overview of DTX IOCTLs 47062306a36Sopenharmony_ci :widths: 1 1 1 1 4 47162306a36Sopenharmony_ci :header-rows: 1 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ci * - Type 47462306a36Sopenharmony_ci - Number 47562306a36Sopenharmony_ci - Direction 47662306a36Sopenharmony_ci - Name 47762306a36Sopenharmony_ci - Description 47862306a36Sopenharmony_ci 47962306a36Sopenharmony_ci * - ``0xA5`` 48062306a36Sopenharmony_ci - ``0x21`` 48162306a36Sopenharmony_ci - ``-`` 48262306a36Sopenharmony_ci - ``EVENTS_ENABLE`` 48362306a36Sopenharmony_ci - Enable events for the current file descriptor. 48462306a36Sopenharmony_ci 48562306a36Sopenharmony_ci * - ``0xA5`` 48662306a36Sopenharmony_ci - ``0x22`` 48762306a36Sopenharmony_ci - ``-`` 48862306a36Sopenharmony_ci - ``EVENTS_DISABLE`` 48962306a36Sopenharmony_ci - Disable events for the current file descriptor. 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ci * - ``0xA5`` 49262306a36Sopenharmony_ci - ``0x23`` 49362306a36Sopenharmony_ci - ``-`` 49462306a36Sopenharmony_ci - ``LATCH_LOCK`` 49562306a36Sopenharmony_ci - Lock the latch. 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci * - ``0xA5`` 49862306a36Sopenharmony_ci - ``0x24`` 49962306a36Sopenharmony_ci - ``-`` 50062306a36Sopenharmony_ci - ``LATCH_UNLOCK`` 50162306a36Sopenharmony_ci - Unlock the latch. 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci * - ``0xA5`` 50462306a36Sopenharmony_ci - ``0x25`` 50562306a36Sopenharmony_ci - ``-`` 50662306a36Sopenharmony_ci - ``LATCH_REQUEST`` 50762306a36Sopenharmony_ci - Request clipboard detachment. 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci * - ``0xA5`` 51062306a36Sopenharmony_ci - ``0x26`` 51162306a36Sopenharmony_ci - ``-`` 51262306a36Sopenharmony_ci - ``LATCH_CONFIRM`` 51362306a36Sopenharmony_ci - Confirm clipboard detachment request. 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci * - ``0xA5`` 51662306a36Sopenharmony_ci - ``0x27`` 51762306a36Sopenharmony_ci - ``-`` 51862306a36Sopenharmony_ci - ``LATCH_HEARTBEAT`` 51962306a36Sopenharmony_ci - Send heartbeat signal to EC. 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_ci * - ``0xA5`` 52262306a36Sopenharmony_ci - ``0x28`` 52362306a36Sopenharmony_ci - ``-`` 52462306a36Sopenharmony_ci - ``LATCH_CANCEL`` 52562306a36Sopenharmony_ci - Cancel detachment process. 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci * - ``0xA5`` 52862306a36Sopenharmony_ci - ``0x29`` 52962306a36Sopenharmony_ci - ``R`` 53062306a36Sopenharmony_ci - ``GET_BASE_INFO`` 53162306a36Sopenharmony_ci - Get current base/connection information. 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci * - ``0xA5`` 53462306a36Sopenharmony_ci - ``0x2A`` 53562306a36Sopenharmony_ci - ``R`` 53662306a36Sopenharmony_ci - ``GET_DEVICE_MODE`` 53762306a36Sopenharmony_ci - Get current device operation mode. 53862306a36Sopenharmony_ci 53962306a36Sopenharmony_ci * - ``0xA5`` 54062306a36Sopenharmony_ci - ``0x2B`` 54162306a36Sopenharmony_ci - ``R`` 54262306a36Sopenharmony_ci - ``GET_LATCH_STATUS`` 54362306a36Sopenharmony_ci - Get current device latch status. 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci``SDTX_IOCTL_EVENTS_ENABLE`` 54662306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x22)``. 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ciEnable events for the current file descriptor. Events can be obtained by 55162306a36Sopenharmony_cireading from the device, if enabled. Events are disabled by default. 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_ci``SDTX_IOCTL_EVENTS_DISABLE`` 55462306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x22)``. 55762306a36Sopenharmony_ci 55862306a36Sopenharmony_ciDisable events for the current file descriptor. Events can be obtained by 55962306a36Sopenharmony_cireading from the device, if enabled. Events are disabled by default. 56062306a36Sopenharmony_ci 56162306a36Sopenharmony_ci``SDTX_IOCTL_LATCH_LOCK`` 56262306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^ 56362306a36Sopenharmony_ci 56462306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x23)``. 56562306a36Sopenharmony_ci 56662306a36Sopenharmony_ciLocks the latch, causing the detachment procedure to abort without opening 56762306a36Sopenharmony_cithe latch on timeout. The latch is unlocked by default. This command will be 56862306a36Sopenharmony_cisilently ignored if the latch is already locked. 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_ci``SDTX_IOCTL_LATCH_UNLOCK`` 57162306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^ 57262306a36Sopenharmony_ci 57362306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x24)``. 57462306a36Sopenharmony_ci 57562306a36Sopenharmony_ciUnlocks the latch, causing the detachment procedure to open the latch on 57662306a36Sopenharmony_citimeout. The latch is unlocked by default. This command will not open the 57762306a36Sopenharmony_cilatch when sent during an ongoing detachment process. It will be silently 57862306a36Sopenharmony_ciignored if the latch is already unlocked. 57962306a36Sopenharmony_ci 58062306a36Sopenharmony_ci``SDTX_IOCTL_LATCH_REQUEST`` 58162306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 58262306a36Sopenharmony_ci 58362306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x25)``. 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ciGeneric latch request. Behavior depends on the context: If no 58662306a36Sopenharmony_cidetachment-process is active, detachment is requested. Otherwise the 58762306a36Sopenharmony_cicurrently active detachment-process will be aborted. 58862306a36Sopenharmony_ci 58962306a36Sopenharmony_ciIf a detachment process is canceled by this operation, a generic detachment 59062306a36Sopenharmony_cirequest event (``SDTX_EVENT_REQUEST``) will be sent. 59162306a36Sopenharmony_ci 59262306a36Sopenharmony_ciThis essentially behaves the same as a detachment button press. 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci``SDTX_IOCTL_LATCH_CONFIRM`` 59562306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x26)``. 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ciAcknowledges and confirms a latch request. If sent during an ongoing 60062306a36Sopenharmony_cidetachment process, this command causes the latch to be opened immediately. 60162306a36Sopenharmony_ciThe latch will also be opened if it has been locked. In this case, the latch 60262306a36Sopenharmony_cilock is reset to the unlocked state. 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ciThis command will be silently ignored if there is currently no detachment 60562306a36Sopenharmony_ciprocedure in progress. 60662306a36Sopenharmony_ci 60762306a36Sopenharmony_ci``SDTX_IOCTL_LATCH_HEARTBEAT`` 60862306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x27)``. 61162306a36Sopenharmony_ci 61262306a36Sopenharmony_ciSends a heartbeat, essentially resetting the detachment timeout. This 61362306a36Sopenharmony_cicommand can be used to keep the detachment process alive while work required 61462306a36Sopenharmony_cifor the detachment to succeed is still in progress. 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_ciThis command will be silently ignored if there is currently no detachment 61762306a36Sopenharmony_ciprocedure in progress. 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci``SDTX_IOCTL_LATCH_CANCEL`` 62062306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^ 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_ciDefined as ``_IO(0xA5, 0x28)``. 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_ciCancels detachment in progress (if any). If a detachment process is canceled 62562306a36Sopenharmony_ciby this operation, a generic detachment request event 62662306a36Sopenharmony_ci(``SDTX_EVENT_REQUEST``) will be sent. 62762306a36Sopenharmony_ci 62862306a36Sopenharmony_ciThis command will be silently ignored if there is currently no detachment 62962306a36Sopenharmony_ciprocedure in progress. 63062306a36Sopenharmony_ci 63162306a36Sopenharmony_ci``SDTX_IOCTL_GET_BASE_INFO`` 63262306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ciDefined as ``_IOR(0xA5, 0x29, struct sdtx_base_info)``. 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_ciGet the current base connection state (i.e. attached/detached) and the type 63762306a36Sopenharmony_ciof the base connected to the clipboard. This is command essentially provides 63862306a36Sopenharmony_cia way to query the information provided by the base connection change event 63962306a36Sopenharmony_ci(``SDTX_EVENT_BASE_CONNECTION``). 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_ciPossible values for ``struct sdtx_base_info.state`` are: 64262306a36Sopenharmony_ci 64362306a36Sopenharmony_ci* ``SDTX_BASE_DETACHED``, 64462306a36Sopenharmony_ci* ``SDTX_BASE_ATTACHED``, and 64562306a36Sopenharmony_ci* ``SDTX_DETACH_NOT_FEASIBLE``. 64662306a36Sopenharmony_ci 64762306a36Sopenharmony_ciOther values are reserved for future use. 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_ci``SDTX_IOCTL_GET_DEVICE_MODE`` 65062306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 65162306a36Sopenharmony_ci 65262306a36Sopenharmony_ciDefined as ``_IOR(0xA5, 0x2A, __u16)``. 65362306a36Sopenharmony_ci 65462306a36Sopenharmony_ciReturns the device operation mode, indicating if and how the base is 65562306a36Sopenharmony_ciattached to the clipboard. This is command essentially provides a way to 65662306a36Sopenharmony_ciquery the information provided by the device mode change event 65762306a36Sopenharmony_ci(``SDTX_EVENT_DEVICE_MODE``). 65862306a36Sopenharmony_ci 65962306a36Sopenharmony_ciReturned values are: 66062306a36Sopenharmony_ci 66162306a36Sopenharmony_ci* ``SDTX_DEVICE_MODE_LAPTOP`` 66262306a36Sopenharmony_ci* ``SDTX_DEVICE_MODE_TABLET`` 66362306a36Sopenharmony_ci* ``SDTX_DEVICE_MODE_STUDIO`` 66462306a36Sopenharmony_ci 66562306a36Sopenharmony_ciSee |sdtx_device_mode| for details. Other values are reserved for future 66662306a36Sopenharmony_ciuse. 66762306a36Sopenharmony_ci 66862306a36Sopenharmony_ci 66962306a36Sopenharmony_ci``SDTX_IOCTL_GET_LATCH_STATUS`` 67062306a36Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 67162306a36Sopenharmony_ci 67262306a36Sopenharmony_ciDefined as ``_IOR(0xA5, 0x2B, __u16)``. 67362306a36Sopenharmony_ci 67462306a36Sopenharmony_ciGet the current latch status or (presumably) the last error encountered when 67562306a36Sopenharmony_citrying to open/close the latch. This is command essentially provides a way 67662306a36Sopenharmony_cito query the information provided by the latch status change event 67762306a36Sopenharmony_ci(``SDTX_EVENT_LATCH_STATUS``). 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ciReturned values are: 68062306a36Sopenharmony_ci 68162306a36Sopenharmony_ci* ``SDTX_LATCH_CLOSED``, 68262306a36Sopenharmony_ci* ``SDTX_LATCH_OPENED``, 68362306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_OPEN``, 68462306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_REMAIN_OPEN``, and 68562306a36Sopenharmony_ci* ``SDTX_ERR_FAILED_TO_CLOSE``. 68662306a36Sopenharmony_ci 68762306a36Sopenharmony_ciOther values are reserved for future use. 68862306a36Sopenharmony_ci 68962306a36Sopenharmony_ciA Note on Base IDs 69062306a36Sopenharmony_ci------------------ 69162306a36Sopenharmony_ci 69262306a36Sopenharmony_ciBase types/IDs provided via ``SDTX_EVENT_BASE_CONNECTION`` or 69362306a36Sopenharmony_ci``SDTX_IOCTL_GET_BASE_INFO`` are directly forwarded from the EC in the lower 69462306a36Sopenharmony_cibyte of the combined |__u16| value, with the driver storing the EC type from 69562306a36Sopenharmony_ciwhich this ID comes in the high byte (without this, base IDs over different 69662306a36Sopenharmony_citypes of ECs may be overlapping). 69762306a36Sopenharmony_ci 69862306a36Sopenharmony_ciThe ``SDTX_DEVICE_TYPE()`` macro can be used to determine the EC device 69962306a36Sopenharmony_citype. This can be one of 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci* ``SDTX_DEVICE_TYPE_HID``, for Surface Aggregator Module over HID, and 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ci* ``SDTX_DEVICE_TYPE_SSH``, for Surface Aggregator Module over Surface Serial 70462306a36Sopenharmony_ci Hub. 70562306a36Sopenharmony_ci 70662306a36Sopenharmony_ciNote that currently only the ``SSH`` type EC is supported, however ``HID`` 70762306a36Sopenharmony_citype is reserved for future use. 70862306a36Sopenharmony_ci 70962306a36Sopenharmony_ciStructures and Enums 71062306a36Sopenharmony_ci-------------------- 71162306a36Sopenharmony_ci 71262306a36Sopenharmony_ci.. kernel-doc:: include/uapi/linux/surface_aggregator/dtx.h 71362306a36Sopenharmony_ci 71462306a36Sopenharmony_ciAPI Users 71562306a36Sopenharmony_ci========= 71662306a36Sopenharmony_ci 71762306a36Sopenharmony_ciA user-space daemon utilizing this API can be found at 71862306a36Sopenharmony_cihttps://github.com/linux-surface/surface-dtx-daemon. 719