1178f6ab7SMaximilian Luz.. SPDX-License-Identifier: GPL-2.0+ 2178f6ab7SMaximilian Luz 3178f6ab7SMaximilian Luz.. |ssam_cdev_request| replace:: :c:type:`struct ssam_cdev_request <ssam_cdev_request>` 4178f6ab7SMaximilian Luz.. |ssam_cdev_request_flags| replace:: :c:type:`enum ssam_cdev_request_flags <ssam_cdev_request_flags>` 5*8ae20054SMaximilian Luz.. |ssam_cdev_event| replace:: :c:type:`struct ssam_cdev_event <ssam_cdev_event>` 6178f6ab7SMaximilian Luz 7178f6ab7SMaximilian Luz============================== 8178f6ab7SMaximilian LuzUser-Space EC Interface (cdev) 9178f6ab7SMaximilian Luz============================== 10178f6ab7SMaximilian Luz 11178f6ab7SMaximilian LuzThe ``surface_aggregator_cdev`` module provides a misc-device for the SSAM 12178f6ab7SMaximilian Luzcontroller to allow for a (more or less) direct connection from user-space to 13178f6ab7SMaximilian Luzthe SAM EC. It is intended to be used for development and debugging, and 14178f6ab7SMaximilian Luztherefore should not be used or relied upon in any other way. Note that this 15178f6ab7SMaximilian Luzmodule is not loaded automatically, but instead must be loaded manually. 16178f6ab7SMaximilian Luz 17178f6ab7SMaximilian LuzThe provided interface is accessible through the ``/dev/surface/aggregator`` 18178f6ab7SMaximilian Luzdevice-file. All functionality of this interface is provided via IOCTLs. 19178f6ab7SMaximilian LuzThese IOCTLs and their respective input/output parameter structs are defined in 20178f6ab7SMaximilian Luz``include/uapi/linux/surface_aggregator/cdev.h``. 21178f6ab7SMaximilian Luz 22178f6ab7SMaximilian LuzA small python library and scripts for accessing this interface can be found 23178f6ab7SMaximilian Luzat https://github.com/linux-surface/surface-aggregator-module/tree/master/scripts/ssam. 24178f6ab7SMaximilian Luz 25*8ae20054SMaximilian Luz.. contents:: 26*8ae20054SMaximilian Luz 27*8ae20054SMaximilian Luz 28*8ae20054SMaximilian LuzReceiving Events 29*8ae20054SMaximilian Luz================ 30*8ae20054SMaximilian Luz 31*8ae20054SMaximilian LuzEvents can be received by reading from the device-file. The are represented by 32*8ae20054SMaximilian Luzthe |ssam_cdev_event| datatype. 33*8ae20054SMaximilian Luz 34*8ae20054SMaximilian LuzBefore events are available to be read, however, the desired notifiers must be 35*8ae20054SMaximilian Luzregistered via the ``SSAM_CDEV_NOTIF_REGISTER`` IOCTL. Notifiers are, in 36*8ae20054SMaximilian Luzessence, callbacks, called when the EC sends an event. They are, in this 37*8ae20054SMaximilian Luzinterface, associated with a specific target category and device-file-instance. 38*8ae20054SMaximilian LuzThey forward any event of this category to the buffer of the corresponding 39*8ae20054SMaximilian Luzinstance, from which it can then be read. 40*8ae20054SMaximilian Luz 41*8ae20054SMaximilian LuzNotifiers themselves do not enable events on the EC. Thus, it may additionally 42*8ae20054SMaximilian Luzbe necessary to enable events via the ``SSAM_CDEV_EVENT_ENABLE`` IOCTL. While 43*8ae20054SMaximilian Luznotifiers work per-client (i.e. per-device-file-instance), events are enabled 44*8ae20054SMaximilian Luzglobally, for the EC and all of its clients (regardless of userspace or 45*8ae20054SMaximilian Luznon-userspace). The ``SSAM_CDEV_EVENT_ENABLE`` and ``SSAM_CDEV_EVENT_DISABLE`` 46*8ae20054SMaximilian LuzIOCTLs take care of reference counting the events, such that an event is 47*8ae20054SMaximilian Luzenabled as long as there is a client that has requested it. 48*8ae20054SMaximilian Luz 49*8ae20054SMaximilian LuzNote that enabled events are not automatically disabled once the client 50*8ae20054SMaximilian Luzinstance is closed. Therefore any client process (or group of processes) should 51*8ae20054SMaximilian Luzbalance their event enable calls with the corresponding event disable calls. It 52*8ae20054SMaximilian Luzis, however, perfectly valid to enable and disable events on different client 53*8ae20054SMaximilian Luzinstances. For example, it is valid to set up notifiers and read events on 54*8ae20054SMaximilian Luzclient instance ``A``, enable those events on instance ``B`` (note that these 55*8ae20054SMaximilian Luzwill also be received by A since events are enabled/disabled globally), and 56*8ae20054SMaximilian Luzafter no more events are desired, disable the previously enabled events via 57*8ae20054SMaximilian Luzinstance ``C``. 58*8ae20054SMaximilian Luz 59178f6ab7SMaximilian Luz 60178f6ab7SMaximilian LuzController IOCTLs 61178f6ab7SMaximilian Luz================= 62178f6ab7SMaximilian Luz 63178f6ab7SMaximilian LuzThe following IOCTLs are provided: 64178f6ab7SMaximilian Luz 65178f6ab7SMaximilian Luz.. flat-table:: Controller IOCTLs 66178f6ab7SMaximilian Luz :widths: 1 1 1 1 4 67178f6ab7SMaximilian Luz :header-rows: 1 68178f6ab7SMaximilian Luz 69178f6ab7SMaximilian Luz * - Type 70178f6ab7SMaximilian Luz - Number 71178f6ab7SMaximilian Luz - Direction 72178f6ab7SMaximilian Luz - Name 73178f6ab7SMaximilian Luz - Description 74178f6ab7SMaximilian Luz 75178f6ab7SMaximilian Luz * - ``0xA5`` 76178f6ab7SMaximilian Luz - ``1`` 77178f6ab7SMaximilian Luz - ``WR`` 78178f6ab7SMaximilian Luz - ``REQUEST`` 79178f6ab7SMaximilian Luz - Perform synchronous SAM request. 80178f6ab7SMaximilian Luz 81*8ae20054SMaximilian Luz * - ``0xA5`` 82*8ae20054SMaximilian Luz - ``2`` 83*8ae20054SMaximilian Luz - ``W`` 84*8ae20054SMaximilian Luz - ``NOTIF_REGISTER`` 85*8ae20054SMaximilian Luz - Register event notifier. 86178f6ab7SMaximilian Luz 87*8ae20054SMaximilian Luz * - ``0xA5`` 88*8ae20054SMaximilian Luz - ``3`` 89*8ae20054SMaximilian Luz - ``W`` 90*8ae20054SMaximilian Luz - ``NOTIF_UNREGISTER`` 91*8ae20054SMaximilian Luz - Unregister event notifier. 92*8ae20054SMaximilian Luz 93*8ae20054SMaximilian Luz * - ``0xA5`` 94*8ae20054SMaximilian Luz - ``4`` 95*8ae20054SMaximilian Luz - ``W`` 96*8ae20054SMaximilian Luz - ``EVENT_ENABLE`` 97*8ae20054SMaximilian Luz - Enable event source. 98*8ae20054SMaximilian Luz 99*8ae20054SMaximilian Luz * - ``0xA5`` 100*8ae20054SMaximilian Luz - ``5`` 101*8ae20054SMaximilian Luz - ``W`` 102*8ae20054SMaximilian Luz - ``EVENT_DISABLE`` 103*8ae20054SMaximilian Luz - Disable event source. 104*8ae20054SMaximilian Luz 105*8ae20054SMaximilian Luz 106*8ae20054SMaximilian Luz``SSAM_CDEV_REQUEST`` 107*8ae20054SMaximilian Luz--------------------- 108178f6ab7SMaximilian Luz 109178f6ab7SMaximilian LuzDefined as ``_IOWR(0xA5, 1, struct ssam_cdev_request)``. 110178f6ab7SMaximilian Luz 111178f6ab7SMaximilian LuzExecutes a synchronous SAM request. The request specification is passed in 112178f6ab7SMaximilian Luzas argument of type |ssam_cdev_request|, which is then written to/modified 113178f6ab7SMaximilian Luzby the IOCTL to return status and result of the request. 114178f6ab7SMaximilian Luz 115178f6ab7SMaximilian LuzRequest payload data must be allocated separately and is passed in via the 116178f6ab7SMaximilian Luz``payload.data`` and ``payload.length`` members. If a response is required, 117178f6ab7SMaximilian Luzthe response buffer must be allocated by the caller and passed in via the 118178f6ab7SMaximilian Luz``response.data`` member. The ``response.length`` member must be set to the 119178f6ab7SMaximilian Luzcapacity of this buffer, or if no response is required, zero. Upon 120178f6ab7SMaximilian Luzcompletion of the request, the call will write the response to the response 121178f6ab7SMaximilian Luzbuffer (if its capacity allows it) and overwrite the length field with the 122178f6ab7SMaximilian Luzactual size of the response, in bytes. 123178f6ab7SMaximilian Luz 124178f6ab7SMaximilian LuzAdditionally, if the request has a response, this must be indicated via the 125178f6ab7SMaximilian Luzrequest flags, as is done with in-kernel requests. Request flags can be set 126178f6ab7SMaximilian Luzvia the ``flags`` member and the values correspond to the values found in 127178f6ab7SMaximilian Luz|ssam_cdev_request_flags|. 128178f6ab7SMaximilian Luz 129178f6ab7SMaximilian LuzFinally, the status of the request itself is returned in the ``status`` 130178f6ab7SMaximilian Luzmember (a negative errno value indicating failure). Note that failure 131178f6ab7SMaximilian Luzindication of the IOCTL is separated from failure indication of the request: 132178f6ab7SMaximilian LuzThe IOCTL returns a negative status code if anything failed during setup of 133178f6ab7SMaximilian Luzthe request (``-EFAULT``) or if the provided argument or any of its fields 134178f6ab7SMaximilian Luzare invalid (``-EINVAL``). In this case, the status value of the request 135178f6ab7SMaximilian Luzargument may be set, providing more detail on what went wrong (e.g. 136178f6ab7SMaximilian Luz``-ENOMEM`` for out-of-memory), but this value may also be zero. The IOCTL 137178f6ab7SMaximilian Luzwill return with a zero status code in case the request has been set up, 138178f6ab7SMaximilian Luzsubmitted, and completed (i.e. handed back to user-space) successfully from 139178f6ab7SMaximilian Luzinside the IOCTL, but the request ``status`` member may still be negative in 140178f6ab7SMaximilian Luzcase the actual execution of the request failed after it has been submitted. 141178f6ab7SMaximilian Luz 142*8ae20054SMaximilian LuzA full definition of the argument struct is provided below. 143*8ae20054SMaximilian Luz 144*8ae20054SMaximilian Luz``SSAM_CDEV_NOTIF_REGISTER`` 145*8ae20054SMaximilian Luz---------------------------- 146*8ae20054SMaximilian Luz 147*8ae20054SMaximilian LuzDefined as ``_IOW(0xA5, 2, struct ssam_cdev_notifier_desc)``. 148*8ae20054SMaximilian Luz 149*8ae20054SMaximilian LuzRegister a notifier for the event target category specified in the given 150*8ae20054SMaximilian Luznotifier description with the specified priority. Notifiers registration is 151*8ae20054SMaximilian Luzrequired to receive events, but does not enable events themselves. After a 152*8ae20054SMaximilian Luznotifier for a specific target category has been registered, all events of that 153*8ae20054SMaximilian Luzcategory will be forwarded to the userspace client and can then be read from 154*8ae20054SMaximilian Luzthe device file instance. Note that events may have to be enabled, e.g. via the 155*8ae20054SMaximilian Luz``SSAM_CDEV_EVENT_ENABLE`` IOCTL, before the EC will send them. 156*8ae20054SMaximilian Luz 157*8ae20054SMaximilian LuzOnly one notifier can be registered per target category and client instance. If 158*8ae20054SMaximilian Luza notifier has already been registered, this IOCTL will fail with ``-EEXIST``. 159*8ae20054SMaximilian Luz 160*8ae20054SMaximilian LuzNotifiers will automatically be removed when the device file instance is 161*8ae20054SMaximilian Luzclosed. 162*8ae20054SMaximilian Luz 163*8ae20054SMaximilian Luz``SSAM_CDEV_NOTIF_UNREGISTER`` 164*8ae20054SMaximilian Luz------------------------------ 165*8ae20054SMaximilian Luz 166*8ae20054SMaximilian LuzDefined as ``_IOW(0xA5, 3, struct ssam_cdev_notifier_desc)``. 167*8ae20054SMaximilian Luz 168*8ae20054SMaximilian LuzUnregisters the notifier associated with the specified target category. The 169*8ae20054SMaximilian Luzpriority field will be ignored by this IOCTL. If no notifier has been 170*8ae20054SMaximilian Luzregistered for this client instance and the given category, this IOCTL will 171*8ae20054SMaximilian Luzfail with ``-ENOENT``. 172*8ae20054SMaximilian Luz 173*8ae20054SMaximilian Luz``SSAM_CDEV_EVENT_ENABLE`` 174*8ae20054SMaximilian Luz-------------------------- 175*8ae20054SMaximilian Luz 176*8ae20054SMaximilian LuzDefined as ``_IOW(0xA5, 4, struct ssam_cdev_event_desc)``. 177*8ae20054SMaximilian Luz 178*8ae20054SMaximilian LuzEnable the event associated with the given event descriptor. 179*8ae20054SMaximilian Luz 180*8ae20054SMaximilian LuzNote that this call will not register a notifier itself, it will only enable 181*8ae20054SMaximilian Luzevents on the controller. If you want to receive events by reading from the 182*8ae20054SMaximilian Luzdevice file, you will need to register the corresponding notifier(s) on that 183*8ae20054SMaximilian Luzinstance. 184*8ae20054SMaximilian Luz 185*8ae20054SMaximilian LuzEvents are not automatically disabled when the device file is closed. This must 186*8ae20054SMaximilian Luzbe done manually, via a call to the ``SSAM_CDEV_EVENT_DISABLE`` IOCTL. 187*8ae20054SMaximilian Luz 188*8ae20054SMaximilian Luz``SSAM_CDEV_EVENT_DISABLE`` 189*8ae20054SMaximilian Luz--------------------------- 190*8ae20054SMaximilian Luz 191*8ae20054SMaximilian LuzDefined as ``_IOW(0xA5, 5, struct ssam_cdev_event_desc)``. 192*8ae20054SMaximilian Luz 193*8ae20054SMaximilian LuzDisable the event associated with the given event descriptor. 194*8ae20054SMaximilian Luz 195*8ae20054SMaximilian LuzNote that this will not unregister any notifiers. Events may still be received 196*8ae20054SMaximilian Luzand forwarded to user-space after this call. The only safe way of stopping 197*8ae20054SMaximilian Luzevents from being received is unregistering all previously registered 198*8ae20054SMaximilian Luznotifiers. 199*8ae20054SMaximilian Luz 200*8ae20054SMaximilian Luz 201*8ae20054SMaximilian LuzStructures and Enums 202*8ae20054SMaximilian Luz==================== 203178f6ab7SMaximilian Luz 204178f6ab7SMaximilian Luz.. kernel-doc:: include/uapi/linux/surface_aggregator/cdev.h 205