Skip to content

Initial Rust V4L2 support

Daniel Almeida linux-media lkml rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 46 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6rust: media: add the media modulerust/kernel/lib.rs rust/kernel/media/mod.rs rust/kernel/media/v4l2/mod.rs+10 -00 replies
2/6rust: media: add initial videodev2.h abstractionsrust/bindings/bindings_helper.h rust/kernel/media/v4l2/capabilities.rs rust/kernel/media/v4l2/enums.rs +5 more+762 -00 replies
3/6rust: sync: introduce FfiMutexrust/kernel/sync.rs rust/kernel/sync/ffi_mutex.rs+71 -00 replies
4/6rust: media: videobuf2: add a videobuf2 abstractionrust/bindings/bindings_helper.h rust/kernel/media/mod.rs rust/kernel/media/videobuf2/core.rs +1 more+561 -00 replies
5/6rust: media: add {video|v4l2}_device_register supportrust/bindings/bindings_helper.h rust/kernel/media/v4l2/dev.rs rust/kernel/media/v4l2/device.rs +2 more+1099 -00 replies
6/6rust: media: add v4l2 rust samplesamples/rust/Kconfig samples/rust/Makefile samples/rust/rust_v4l2.rs+415 -00 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 0/6] Initial Rust V4L2 support

Hi all, this is my first attempt at adding Rust support to the media subsystem.

It adds just enough support to write a clone of the virtio-camera prototype written by my colleague, Dmitry Osipenko, available at [0].

Basically, there's support for video_device_register, v4l2_device_register and for some ioctls in v4l2_ioctl_ops. There is also some initial vb2 support, alongside some wrappers for some types found in videodev2.h.

I wrote a sample Rust driver just to prove that this probes, and that you get a message on dmesg whenever an ioctl is called.

As there is no actual implementation for any of the ioctls, this module can misbehave with some programs. I can work around this in a future submission.

Note that this is based on the rust branch, as opposed to rust-next. The reasoning is simple: I expect this series to just kickstart some discussion around the subject. Actual upstreaming can come up much later, at which point I can rebase on the rust branch.

Lastly, the origins of this series trace back to a v4l2 virtIO driver I was writing in Rust. As the project was eventually shelved for other reasons, I picked both the virtIO and the v4l2 bindings into their own patches which I am now in the process of submitting. This is to say that I tested this code with said driver and CrosVM in the past, and it worked ok.

Please let me know your thoughts.

[0]: https://gitlab.collabora.com/dmitry.osipenko/linux-kernel-rd/-/commit/055a2c322e931a8b388f864f1db81bbdfd525602

Daniel Almeida (6):
rust: media: add the media module
rust: media: add initial videodev2.h abstractions
rust: sync: introduce FfiMutex
rust: media: videobuf2: add a videobuf2 abstraction
rust: media: add {video|v4l2}_device_register support
rust: media: add v4l2 rust sample

 rust/bindings/bindings_helper.h        |   8 +
 rust/kernel/lib.rs                     |   2 +
 rust/kernel/media/mod.rs               |   6 +
 rust/kernel/media/v4l2/capabilities.rs |  80 ++++
 rust/kernel/media/v4l2/dev.rs          | 369 +++++++++++++++
 rust/kernel/media/v4l2/device.rs       | 115 +++++
 rust/kernel/media/v4l2/enums.rs        | 135 ++++++
 rust/kernel/media/v4l2/format.rs       | 178 ++++++++
 rust/kernel/media/v4l2/framesize.rs    | 176 +++++++
 rust/kernel/media/v4l2/inputs.rs       | 104 +++++
 rust/kernel/media/v4l2/ioctls.rs       | 608 +++++++++++++++++++++++++
 rust/kernel/media/v4l2/mmap.rs         |  81 ++++
 rust/kernel/media/v4l2/mod.rs          |  13 +
 rust/kernel/media/videobuf2/core.rs    | 552 ++++++++++++++++++++++
 rust/kernel/media/videobuf2/mod.rs     |   5 +
 rust/kernel/sync.rs                    |   1 +
 rust/kernel/sync/ffi_mutex.rs          |  70 +++
 samples/rust/Kconfig                   |  11 +
 samples/rust/Makefile                  |   1 +
 samples/rust/rust_v4l2.rs              | 403 ++++++++++++++++
 20 files changed, 2918 insertions(+)
 create mode 100644 rust/kernel/media/mod.rs
 create mode 100644 rust/kernel/media/v4l2/capabilities.rs
 create mode 100644 rust/kernel/media/v4l2/dev.rs
 create mode 100644 rust/kernel/media/v4l2/device.rs
 create mode 100644 rust/kernel/media/v4l2/enums.rs
 create mode 100644 rust/kernel/media/v4l2/format.rs
 create mode 100644 rust/kernel/media/v4l2/framesize.rs
 create mode 100644 rust/kernel/media/v4l2/inputs.rs
 create mode 100644 rust/kernel/media/v4l2/ioctls.rs
 create mode 100644 rust/kernel/media/v4l2/mmap.rs
 create mode 100644 rust/kernel/media/v4l2/mod.rs
 create mode 100644 rust/kernel/media/videobuf2/core.rs
 create mode 100644 rust/kernel/media/videobuf2/mod.rs
 create mode 100644 rust/kernel/sync/ffi_mutex.rs
 create mode 100644 samples/rust/rust_v4l2.rs
Signature · 1 line
2.40.0