Lines Matching +full:haptic +full:- +full:driver
1 .. SPDX-License-Identifier: GPL-2.0
4 HID-BPF
8 custom tweaks, traditionally done with a kernel driver fix. Using the eBPF
17 When (and why) to use HID-BPF
20 There are several use cases when using HID-BPF is better
21 than standard kernel driver fix:
24 -----------------------
30 With HID-BPF, we can apply this filtering in the kernel directly so userspace
38 HID-BPF allows the userspace program to load the program itself, ensuring we
42 ---------------------------------
57 ------------------------------------------------
68 ------------------------------------------------------------------
76 example, the Microsoft Surface Dial is a pushbutton with haptic feedback that
80 events into wheel events. Also, the userspace program can set/unset the haptic
82 screen we likely need to have a haptic click every 15 degrees. But when
87 --------
99 -------
107 1. if the driver doesn't export a hidraw node, we can't trace anything
108 (eBPF will be a "god-mode" there, so this may raise some eyebrows)
113 High-level view of HID-BPF
116 The main idea behind HID-BPF is that it works at an array of bytes level.
124 A corollary of this is that HID-BPF doesn't know about the other subsystems
132 In-tree HID-BPF programs and ``udev-hid-bpf``
141 `udev-hid-bpf <https://libevdev.pages.freedesktop.org/udev-hid-bpf/index.html>`_.
146 those HID-BPF fixes. ``udev-hid-bpf`` also has capabilities of handling multiple
152 HID-BPF is built "on top" of BPF, meaning that we use bpf struct_ops method to
155 HID-BPF has the following attachment types available:
167 This time, we can do any operations allowed by HID-BPF, and talking to the device is
171 BPF program of this type. This is called on ``probe`` from the driver and allows to
182 Available ``struct_ops`` for HID-BPF:
183 -------------------------------------
185 .. kernel-doc:: include/linux/hid_bpf.h
190 -----------------------------------------------
192 .. kernel-doc:: include/linux/hid_bpf.h
195 Available API that can be used in all HID-BPF struct_ops programs:
196 ------------------------------------------------------------------
198 .. kernel-doc:: drivers/hid/bpf/hid_bpf_dispatch.c
201 Available API that can be used in syscall HID-BPF programs or in sleepable HID-BPF struct_ops progr…
202 ---------------------------------------------------------------------------------------------------…
204 .. kernel-doc:: drivers/hid/bpf/hid_bpf_dispatch.c
207 General overview of a HID-BPF program
211 ------------------------------------------
235 2. if the report length is variable, but we know the value of ``X`` is always a 16-bit
245 Effect of a HID-BPF program
246 ---------------------------
248 For all HID-BPF attachment types except for :c:func:`hid_rdesc_fixup`, several eBPF
249 programs can be attached to the same device. If a HID-BPF struct_ops has a
251 kernel will return `-EINVAL` when attaching the struct_ops.
301 The eBPF program can modify the data buffer at-will and the kernel uses the
311 There is no ``detach`` facility in HID-BPF. Detaching a program happens when
312 all the user space file descriptors pointing at a HID-BPF struct_ops link are closed.
333 (where it is interesting to get the non-hidraw traces).
349 *Foreword: for most parts, this could be implemented as a kernel driver*
351 Let's imagine we have a new tablet device that has some haptic capabilities
358 haptic feature of the device itself.
361 ----------------
379 /* HID-BPF kfunc API definitions */
427 hid_skel->struct_ops.haptic_tablet->hid_id = hid_id;
432 link_fd = bpf_map__attach_struct_ops(hid_skel->maps.haptic_tablet);
434 fprintf(stderr, "can not attach HID-BPF program: %m\n");
435 return -1;
452 ----------------------
454 To be able to change the haptic feedback from the tablet, the userspace program
460 /* some more HID-BPF kfunc API definitions */
482 ctx = hid_bpf_allocate_context(args->hid);
487 args->data,
502 int ret = -1;
514 prog_fd = bpf_program__fd(hid_skel->progs.set_haptic);
520 Now our userspace program is aware of the haptic state and can control it. The
526 interface with the kernel at-will, because the userspace application is