Skip to content

rust: input: add input/serio abstractions and port Gravis Stinger driver

Vecheslav Filatov linux-input lkml rust-for-linux 11 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v11 Latest2 patches 0 repliesNew
  2. v102 patches 0 repliesSuperseded
  3. v92 patches 0 repliesSuperseded
Earlier versions · 8
VersionPostedPatchesRepliesStatus
v82 patches0 repliesSuperseded
v72 patches0 repliesSuperseded
v62 patches0 repliesSuperseded
v52 patches1 replySuperseded
v42 patches0 repliesSuperseded
v32 patches0 repliesSuperseded
v22 patches0 repliesSuperseded
v13 patches0 repliesSuperseded

Changes in v11 from the cover letter

- serio: changed Driver::init() parameter from &Device<device::Bound> to &Device (i.e. &Device<device::Normal>) and Registration::
connect_callback() cast to Device, because serio connect callbacks run outside driver core really_probe() probe context without devres release guarantees on connection failure.
- joystick/stinger_rust: updated StingerDriver::init() signature to accept &serio::Device and removed now-unused device import.

Patches in v11 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rust: input: add input device abstractionsrust/bindings/bindings_helper.h rust/helpers/helpers.c rust/helpers/input.c +2 more+279 -00 replies
2/2rust: serio: add serio bus abstractions and port Gravis Stinger driverdrivers/input/joystick/Kconfig drivers/input/joystick/Makefile drivers/input/joystick/stinger_rust.rs +5 more+570 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v11 yet.

Read the v11 thread

Cover letter [PATCH v11 0/2] rust: input: add input/serio abstractions and port Gravis Stinger driver

This patch series introduces safe Rust abstractions for Linux input devices (struct input_dev) and the serio (Serial I/O) bus subsystem, along with a port of the legacy Gravis Stinger serial gamepad driver to safe Rust.

Changes in v11:
- serio: changed Driver::init() parameter from &Device<device::Bound> to &Device (i.e. &Device<device::Normal>) and Registration::
connect_callback() cast to Device, because serio connect callbacks run outside driver core really_probe() probe context without devres release guarantees on connection failure.
- joystick/stinger_rust: updated StingerDriver::init() signature to accept &serio::Device and removed now-unused device import.

Changes in v10:
- serio: removed wrapper module and aliases, directly mapping Registration::interrupt_callback() to canonical constants bindings::irqreturn::IRQ_NONE and bindings::irqreturn::IRQ_HANDLED.

Changes in v9:
- serio: updated Registration::interrupt_callback() to map IRQ return codes using module-level constants.

Changes in v8:
- serio: simplified IRQ return constants to module-level definitions with direct crate::bindings import without extra wrapper modules.

Changes in v7:
- serio: scoped the lifetime of borrowed mut data inside connect_callback() to drop before calling serio_continue_rx(), preventing aliasing violations with incoming interrupts.
- joystick: added RUSTFLAGS_stinger_rust.o := --crate-name stinger in Makefile to ensure built-in modpost device table aliases match the canonical module name "stinger".

Changes in v6:
- Developer identity: updated author and Signed-off-by to developer's real name (Vecheslav Filatov) across all commits in compliance with the Developer Certificate of Origin (DCO).

Changes in v5:
- serio: decoupled child device allocation and publication in Driver lifecycle (init -> start -> attach). Child input devices are allocated and configured before opening the port, but only registered via Driver::start() after serio_open() succeeds. This prevents premature registration and spurious uevents on probe failures.
- serio: added C wrappers rust_helper_serio_pause_rx() and rust_helper_serio_continue_rx() to safely attach child devices in Driver::attach() under hardware RX pause, eliminating races with concurrent interrupts without sleeping.
- serio: removed redundant Device::as_device() method and made Device::as_raw() crate-private (pub(crate)), relying on the standard AsRef<device::Device> implementation.

Changes in v4:
- Makefile: restored analog.o and db9.o in joystick Makefile that were inadvertently removed during previous revisions.
- serio: eliminated concurrent borrow_mut() and aliasing data races between connect_callback() and interrupt_callback() by initializing and registering the input device prior to serio_open().
- serio: mapped interrupt return codes without missing constants.
- serio & stinger: formatted all module imports in strict vertical style with trailing // comments.
- serio: annotated Registration::drop() and Driver::disconnect() with

    #[inline].

Changes in v3:
- input: added AllocatedDevice::set_phys_from_parent() to dynamically format the physical device path ("%s/input0") in an owned kernel heap buffer.
- input: managed parent device reference counts in set_parent(), drop(), and register() using get_device()/put_device() to avoid dangling pointers and reference leaks.
- input: eliminated manual cleanup duplication in register() by checking to_result() before mem::forget(self).
- input: implemented Send and Sync for AllocatedDevice, added #[inline] on small methods, and formatted imports vertically.
- serio: integrated serio::Device with kernel device abstractions via AsBusDevice, impl_device_context_deref!, and AsRef<device::Device>.
- stinger: restored userspace-visible device name ("Gravis Stinger") and dynamic phys path, preserving udev and EVIOCGNAME compatibility.
- stinger: maintained module name "stinger.ko" using Kbuild object aliasing under CONFIG_JOYSTICK_STINGER_RUST.

Changes in v2:
- Combined serio subsystem abstractions and Gravis Stinger driver port into a single patch (2/2).
- Retained original C driver (stinger.c) under CONFIG_JOYSTICK_STINGER and introduced CONFIG_JOYSTICK_STINGER_RUST to avoid regressions on architectures and configurations without Rust support.
- Ensured IS_REACHABLE() guards for C helpers and #[cfg(CONFIG_* = "y")] for rust/kernel modules to prevent unresolved symbols.

Vecheslav Filatov (2):
rust: input: add input device abstractions
rust: serio: add serio bus abstractions and port Gravis Stinger driver

 drivers/input/joystick/Kconfig         |  14 ++
 drivers/input/joystick/Makefile        |   4 +
 drivers/input/joystick/stinger_rust.rs | 190 ++++++++++++++
 rust/bindings/bindings_helper.h        |   2 +
 rust/helpers/helpers.c                 |   2 +
 rust/helpers/input.c                   |  22 ++
 rust/helpers/serio.c                   |  27 ++
 rust/kernel/input.rs                   | 253 +++++++++++++++++++
 rust/kernel/lib.rs                     |   4 +
 rust/kernel/serio.rs                   | 331 +++++++++++++++++++++++++
 10 files changed, 849 insertions(+)
 create mode 100644 drivers/input/joystick/stinger_rust.rs
 create mode 100644 rust/helpers/input.c
 create mode 100644 rust/helpers/serio.c
 create mode 100644 rust/kernel/input.rs
 create mode 100644 rust/kernel/serio.rs
Signature · 1 line
2.56.0