diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2025-12-04 15:44:48 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2025-12-04 15:44:48 -0800 |
| commit | fde4ce068d1bccacf1e2d6a28697a3847f28e0a6 (patch) | |
| tree | 44d49678a5013e46a8b358402fb3a65bee178840 /drivers/hid/bpf/progs/Logitech__SpaceNavigator.bpf.c | |
| parent | d1b46f53a51e328202ae049f44b86336d124aeac (diff) | |
| parent | 8af1d3fe5f186bff53057c6856046b0752fe71e8 (diff) | |
Merge tag 'hid-for-linus-2025120201' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID updates from Jiri Kosina:
- Proper mapping of HID_GD_Z to ABS_DISTANCE for stylus/pen types of
devices (Ping Cheng)
- Power management/hibernation improvements in intel-ish (Zhang Lixu)
- Improved support for several Logitech devices, e.g. G Pro X
Superlight 2, new iteration of Lighspeed receiver, G13, G510 (Nathan
Rossi, Mavroudis Chatzilazaridis, Leo L Schwab, Hans de Goede)
- Support for UcLogic XP-PEN Artist 24 Pro (Joshua Goins)
- WinWing Orion2 throttle support improvement (Ivan Gorinov)
- other assorted small fixes and device ID additions
* tag 'hid-for-linus-2025120201' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (37 commits)
drivers: hid: renegotiate resolution multipliers with device after reset
HID: evision: Fix Report Descriptor for Evision Wireless Receiver 320f:226f
HID: logitech-dj: Fix probe failure when used with KVM
HID: logitech-dj: Remove duplicate error logging
HID: logitech-dj: Add support for G Pro X Superlight 2 receiver
selftests/hid-tablet: add ABS_DISTANCE test for stylus/pen
HID: input: map HID_GD_Z to ABS_DISTANCE for stylus/pen
HID: bpf: fix typo in HID usage table
HID: bpf: add the Huion Kamvas 27 Pro
HID: bpf: add heuristics to the Huion Inspiroy 2S eraser button
HID: bpf: Add support for XP-Pen Deco02
HID: bpf: Add support for the XP-Pen Deco 01 V3
HID: bpf: Add support for the Waltop Batteryless Tablet
HID: bpf: Add fixup for Logitech SpaceNavigator variants
HID: bpf: support for Huion Kamvas 16 Gen 3
HID: bpf: add support for Huion Kamvas 13 (Gen 3) (model GS1333)
HID: bpf: Add support for the Inspiroy 2M
Documentation: hid-alps: Format DataByte* subsection headings
Documentation: hid-alps: Fix packet format section headings
HID: nintendo: add WQ_PERCPU to alloc_workqueue users
...
Diffstat (limited to 'drivers/hid/bpf/progs/Logitech__SpaceNavigator.bpf.c')
| -rw-r--r-- | drivers/hid/bpf/progs/Logitech__SpaceNavigator.bpf.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/drivers/hid/bpf/progs/Logitech__SpaceNavigator.bpf.c b/drivers/hid/bpf/progs/Logitech__SpaceNavigator.bpf.c new file mode 100644 index 000000000000..b17719d6d9c7 --- /dev/null +++ b/drivers/hid/bpf/progs/Logitech__SpaceNavigator.bpf.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2025 Curran Muhlberger + */ + +#include "vmlinux.h" +#include "hid_bpf.h" +#include "hid_bpf_helpers.h" +#include <bpf/bpf_tracing.h> + +#define VID_LOGITECH 0x046D +#define PID_SPACENAVIGATOR 0xC626 + +HID_BPF_CONFIG( + HID_DEVICE(BUS_USB, HID_GROUP_ANY, VID_LOGITECH, PID_SPACENAVIGATOR) +); + +/* + * The 3Dconnexion SpaceNavigator 3D Mouse is a multi-axis controller with 6 + * axes (grouped as X,Y,Z and Rx,Ry,Rz). Axis data is absolute, but the report + * descriptor erroneously declares it to be relative. We fix the report + * descriptor to mark both axis collections as absolute. + * + * The kernel attempted to fix this in commit 24985cf68612 (HID: support + * Logitech/3DConnexion SpaceTraveler and SpaceNavigator), but the descriptor + * data offsets are incorrect for at least some SpaceNavigator units. + */ + +SEC(HID_BPF_RDESC_FIXUP) +int BPF_PROG(hid_fix_rdesc, struct hid_bpf_ctx *hctx) +{ + __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */); + + if (!data) + return 0; /* EPERM check */ + + /* Offset of Input item in X,Y,Z and Rx,Ry,Rz collections for all known + * firmware variants. + * - 2009 model: X,Y,Z @ 32-33, Rx,Ry,Rz @ 49-50 (fixup originally + * applied in kernel) + * - 2016 model (size==228): X,Y,Z @ 36-37, Rx,Ry,Rz @ 53-54 + * + * The descriptor size of the 2009 model is not known, and there is evidence + * for at least two other variants (with sizes 202 & 217) besides the 2016 + * model, so we try all known offsets regardless of descriptor size. + */ + const u8 offsets[] = {32, 36, 49, 53}; + + for (size_t idx = 0; idx < ARRAY_SIZE(offsets); idx++) { + u8 offset = offsets[idx]; + + /* if Input (Data,Var,Rel) , make it Input (Data,Var,Abs) */ + if (data[offset] == 0x81 && data[offset + 1] == 0x06) + data[offset + 1] = 0x02; + } + + return 0; +} + +HID_BPF_OPS(logitech_spacenavigator) = { + .hid_rdesc_fixup = (void *)hid_fix_rdesc, +}; + +SEC("syscall") +int probe(struct hid_bpf_probe_args *ctx) +{ + /* Ensure report descriptor size matches one of the known variants. */ + if (ctx->rdesc_size != 202 && + ctx->rdesc_size != 217 && + ctx->rdesc_size != 228) { + ctx->retval = -EINVAL; + return 0; + } + + /* Check whether the kernel has already applied the fix. */ + if ((ctx->rdesc[32] == 0x81 && ctx->rdesc[33] == 0x02 && + ctx->rdesc[49] == 0x81 && ctx->rdesc[50] == 0x02) || + (ctx->rdesc[36] == 0x81 && ctx->rdesc[37] == 0x02 && + ctx->rdesc[53] == 0x81 && ctx->rdesc[54] == 0x02)) + ctx->retval = -EINVAL; + else + ctx->retval = 0; + + return 0; +} + +char _license[] SEC("license") = "GPL"; |