Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rust: input: add input/serio abstractions and port Gravis Stinger driver
@ 2026-11-06 20:14 clicedvly768
  2026-11-06 20:14 ` [PATCH v2 1/2] rust: input: add input device abstractions clicedvly768
  2026-11-06 20:14 ` [PATCH v2 2/2] rust: serio: add serio bus abstractions and port Gravis Stinger driver clicedvly768
  0 siblings, 2 replies; 5+ messages in thread
From: clicedvly768 @ 2026-11-06 20:14 UTC (permalink / raw)
  To: ojeda, dmitry.torokhov; +Cc: rust-for-linux, linux-input, clicedvly768

This series introduces safe Rust abstractions for the Linux input and
serio (Serial I/O) subsystems and demonstrates their real-world usage
by porting the legacy Gravis Stinger serial gamepad driver to safe Rust.

Following community review, the serio bus abstractions and the Stinger
driver port have been consolidated into the second patch, while keeping
the input device abstractions in the first patch.

Motivation and Design:
- In the Rust for Linux (RfL) philosophy, device drivers should not rely
  on raw FFI and unsafe blocks. Instead, the kernel crate provides safe,
  idiomatic Rust abstractions.
- The Gravis Stinger gamepad is an ideal candidate for demonstrating safe
  Rust driver development in the input subsystem: it uses a well-defined
  4-byte serial protocol at 9600 baud, 10 buttons, and 2 analog axes.
- The ported driver (`drivers/input/joystick/stinger_rust.rs`) contains
  ZERO unsafe blocks, using RAII types (`AllocatedDevice`,
  `RegisteredDevice`, `serio::Registration`) for memory safety and
  device lifetime management.
- Non-regression: `CONFIG_JOYSTICK_STINGER_RUST` is offered alongside
  the original C driver (`stinger.c`), ensuring architectures without
  Rust (e.g. powerpc defconfigs) suffer no hardware support regressions.

Testing:
- Built with Clang/LLVM and rustc 1.85.
- Passes all strict kernel Rust checks: `make LLVM=1 rustfmtcheck`,
  `make LLVM=1 rustdoc`, and `make LLVM=1 CLIPPY=1` with zero warnings.
- Tested both built-in (`CONFIG_JOYSTICK_STINGER=y`) and loadable module
  (`CONFIG_JOYSTICK_STINGER=m`) configurations.
- Tested end-to-end in a custom QEMU virtual test environment with serial
  port loopback (`serport` line discipline `N_MOUSE` and `SERIO_STINGER`).
- Verified event reporting (`EV_KEY`, `EV_ABS`, `EV_SYN`) via `evtest`
  and an automated test suite across all 10 buttons and
  both axes (-64..64).

Changes in v2:
- Consolidated serio abstractions and Stinger driver port into patch 2/2.
- Gated built-in Rust modules and helpers with `#[cfg(CONFIG_* = "y")]`
  and `#if IS_REACHABLE(CONFIG_*)` to prevent vmlinux link failures
  when CONFIG_INPUT or CONFIG_SERIO is compiled as a module or disabled.
- Retained original `stinger.c` and introduced `JOYSTICK_STINGER_RUST`
  to avoid hardware support regressions on architectures without RUST.
- Replaced raw slice `&'static [DeviceId]` with
  `kernel::device_id::RawDeviceId` and `kernel::device_id::IdTable`
  via `kernel::serio_device_table!`, guaranteeing compile-time
  zero-sentinel termination and exporting modpost device aliases.
- Fixed module owner tracking: removed `helpers.o` registration wrappers;
  `Registration::new` now takes `&'static ThisModule` and calls
  `bindings::__serio_register_driver` with the driver's own module pointer.
- Stored `Opaque<bindings::serio_driver>` in `Pin<KBox<...>>` to avoid
  aliasing violations on C-owned memory.
- Fixed return error code sign in `connect_callback` (`to_errno()` is
  already negative).
- Reordered port opening: `serio_open` is called before publishing the
  input device to userspace.
- Reused `kernel::irq::IrqReturn` instead of duplicating a custom enum.
- Integrated `serio::Device` with generic device infrastructure:
  implemented `AsRef<device::Device>` and `Deref<Target = device::Device>`,
  and added `AllocatedDevice::set_parent()` in `input.rs` to maintain
  the sysfs device hierarchy (`&serio->dev`).
- Switched `AllocatedDevice::set_phys()` to `&'static CStr`.
- Added bounds check `axis < ABS_CNT` in `set_abs_params()`.
- Added `#[inline]` on small helper methods and used vertical imports.

clicedvly768 (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 | 178 +++++++++++++++++
 rust/bindings/bindings_helper.h        |   2 +
 rust/helpers/helpers.c                 |   2 +
 rust/helpers/input.c                   |  22 +++
 rust/helpers/serio.c                   |  17 ++
 rust/kernel/input.rs                   | 214 +++++++++++++++++++++
 rust/kernel/lib.rs                     |   4 +
 rust/kernel/serio.rs                   | 256 +++++++++++++++++++++++++
 10 files changed, 713 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

-- 
2.56.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-06 20:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 20:14 [PATCH v2 0/2] rust: input: add input/serio abstractions and port Gravis Stinger driver clicedvly768
2026-11-06 20:14 ` [PATCH v2 1/2] rust: input: add input device abstractions clicedvly768
2026-11-06 20:27   ` sashiko-bot
2026-11-06 20:14 ` [PATCH v2 2/2] rust: serio: add serio bus abstractions and port Gravis Stinger driver clicedvly768
2026-11-06 20:33   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox