brintos

brintos / linux-shallow public Read only

0
0
Text · 7.9 KiB · 0134a84 Raw
205 lines · plain
1.. SPDX-License-Identifier: GPL-2.0+2 3.. |ssam_cdev_request| replace:: :c:type:`struct ssam_cdev_request <ssam_cdev_request>`4.. |ssam_cdev_request_flags| replace:: :c:type:`enum ssam_cdev_request_flags <ssam_cdev_request_flags>`5.. |ssam_cdev_event| replace:: :c:type:`struct ssam_cdev_event <ssam_cdev_event>`6 7==============================8User-Space EC Interface (cdev)9==============================10 11The ``surface_aggregator_cdev`` module provides a misc-device for the SSAM12controller to allow for a (more or less) direct connection from user-space to13the SAM EC. It is intended to be used for development and debugging, and14therefore should not be used or relied upon in any other way. Note that this15module is not loaded automatically, but instead must be loaded manually.16 17The provided interface is accessible through the ``/dev/surface/aggregator``18device-file. All functionality of this interface is provided via IOCTLs.19These IOCTLs and their respective input/output parameter structs are defined in20``include/uapi/linux/surface_aggregator/cdev.h``.21 22A small python library and scripts for accessing this interface can be found23at https://github.com/linux-surface/surface-aggregator-module/tree/master/scripts/ssam.24 25.. contents::26 27 28Receiving Events29================30 31Events can be received by reading from the device-file. The are represented by32the |ssam_cdev_event| datatype.33 34Before events are available to be read, however, the desired notifiers must be35registered via the ``SSAM_CDEV_NOTIF_REGISTER`` IOCTL. Notifiers are, in36essence, callbacks, called when the EC sends an event. They are, in this37interface, associated with a specific target category and device-file-instance.38They forward any event of this category to the buffer of the corresponding39instance, from which it can then be read.40 41Notifiers themselves do not enable events on the EC. Thus, it may additionally42be necessary to enable events via the ``SSAM_CDEV_EVENT_ENABLE`` IOCTL. While43notifiers work per-client (i.e. per-device-file-instance), events are enabled44globally, for the EC and all of its clients (regardless of userspace or45non-userspace). The ``SSAM_CDEV_EVENT_ENABLE`` and ``SSAM_CDEV_EVENT_DISABLE``46IOCTLs take care of reference counting the events, such that an event is47enabled as long as there is a client that has requested it.48 49Note that enabled events are not automatically disabled once the client50instance is closed. Therefore any client process (or group of processes) should51balance their event enable calls with the corresponding event disable calls. It52is, however, perfectly valid to enable and disable events on different client53instances. For example, it is valid to set up notifiers and read events on54client instance ``A``, enable those events on instance ``B`` (note that these55will also be received by A since events are enabled/disabled globally), and56after no more events are desired, disable the previously enabled events via57instance ``C``.58 59 60Controller IOCTLs61=================62 63The following IOCTLs are provided:64 65.. flat-table:: Controller IOCTLs66   :widths: 1 1 1 1 467   :header-rows: 168 69   * - Type70     - Number71     - Direction72     - Name73     - Description74 75   * - ``0xA5``76     - ``1``77     - ``WR``78     - ``REQUEST``79     - Perform synchronous SAM request.80 81   * - ``0xA5``82     - ``2``83     - ``W``84     - ``NOTIF_REGISTER``85     - Register event notifier.86 87   * - ``0xA5``88     - ``3``89     - ``W``90     - ``NOTIF_UNREGISTER``91     - Unregister event notifier.92 93   * - ``0xA5``94     - ``4``95     - ``W``96     - ``EVENT_ENABLE``97     - Enable event source.98 99   * - ``0xA5``100     - ``5``101     - ``W``102     - ``EVENT_DISABLE``103     - Disable event source.104 105 106``SSAM_CDEV_REQUEST``107---------------------108 109Defined as ``_IOWR(0xA5, 1, struct ssam_cdev_request)``.110 111Executes a synchronous SAM request. The request specification is passed in112as argument of type |ssam_cdev_request|, which is then written to/modified113by the IOCTL to return status and result of the request.114 115Request payload data must be allocated separately and is passed in via the116``payload.data`` and ``payload.length`` members. If a response is required,117the response buffer must be allocated by the caller and passed in via the118``response.data`` member. The ``response.length`` member must be set to the119capacity of this buffer, or if no response is required, zero. Upon120completion of the request, the call will write the response to the response121buffer (if its capacity allows it) and overwrite the length field with the122actual size of the response, in bytes.123 124Additionally, if the request has a response, this must be indicated via the125request flags, as is done with in-kernel requests. Request flags can be set126via the ``flags`` member and the values correspond to the values found in127|ssam_cdev_request_flags|.128 129Finally, the status of the request itself is returned in the ``status``130member (a negative errno value indicating failure). Note that failure131indication of the IOCTL is separated from failure indication of the request:132The IOCTL returns a negative status code if anything failed during setup of133the request (``-EFAULT``) or if the provided argument or any of its fields134are invalid (``-EINVAL``). In this case, the status value of the request135argument may be set, providing more detail on what went wrong (e.g.136``-ENOMEM`` for out-of-memory), but this value may also be zero. The IOCTL137will return with a zero status code in case the request has been set up,138submitted, and completed (i.e. handed back to user-space) successfully from139inside the IOCTL, but the request ``status`` member may still be negative in140case the actual execution of the request failed after it has been submitted.141 142A full definition of the argument struct is provided below.143 144``SSAM_CDEV_NOTIF_REGISTER``145----------------------------146 147Defined as ``_IOW(0xA5, 2, struct ssam_cdev_notifier_desc)``.148 149Register a notifier for the event target category specified in the given150notifier description with the specified priority. Notifiers registration is151required to receive events, but does not enable events themselves. After a152notifier for a specific target category has been registered, all events of that153category will be forwarded to the userspace client and can then be read from154the device file instance. Note that events may have to be enabled, e.g. via the155``SSAM_CDEV_EVENT_ENABLE`` IOCTL, before the EC will send them.156 157Only one notifier can be registered per target category and client instance. If158a notifier has already been registered, this IOCTL will fail with ``-EEXIST``.159 160Notifiers will automatically be removed when the device file instance is161closed.162 163``SSAM_CDEV_NOTIF_UNREGISTER``164------------------------------165 166Defined as ``_IOW(0xA5, 3, struct ssam_cdev_notifier_desc)``.167 168Unregisters the notifier associated with the specified target category. The169priority field will be ignored by this IOCTL. If no notifier has been170registered for this client instance and the given category, this IOCTL will171fail with ``-ENOENT``.172 173``SSAM_CDEV_EVENT_ENABLE``174--------------------------175 176Defined as ``_IOW(0xA5, 4, struct ssam_cdev_event_desc)``.177 178Enable the event associated with the given event descriptor.179 180Note that this call will not register a notifier itself, it will only enable181events on the controller. If you want to receive events by reading from the182device file, you will need to register the corresponding notifier(s) on that183instance.184 185Events are not automatically disabled when the device file is closed. This must186be done manually, via a call to the ``SSAM_CDEV_EVENT_DISABLE`` IOCTL.187 188``SSAM_CDEV_EVENT_DISABLE``189---------------------------190 191Defined as ``_IOW(0xA5, 5, struct ssam_cdev_event_desc)``.192 193Disable the event associated with the given event descriptor.194 195Note that this will not unregister any notifiers. Events may still be received196and forwarded to user-space after this call. The only safe way of stopping197events from being received is unregistering all previously registered198notifiers.199 200 201Structures and Enums202====================203 204.. kernel-doc:: include/uapi/linux/surface_aggregator/cdev.h205