rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/9] Rust version of the VGEM driver
@ 2023-03-17 12:12 Maíra Canal
  2023-03-17 12:12 ` [RFC PATCH 1/9] rust: dma_resv: add DMA Reservation abstraction Maíra Canal
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Maíra Canal @ 2023-03-17 12:12 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Miguel Ojeda, Alex Gaynor,
	Wedson Almeida Filho, Boqun Feng, Gary Guo, Asahi Lina,
	Faith Ekstrand
  Cc: rust-for-linux, dri-devel, Melissa Wen, Maíra Canal

This is my first take on using the DRM Rust abstractions [1] to convert a DRM
driver, written originally in C, to Rust. This patchset consists of a conversion
of the vgem driver to a DRM Rust driver. This new driver has the exactly same
functionalities of the original C driver, but takes advantages of all the Rust
features.

These patches are based primarily on the Rust DRM abstractions [1], sent as a
RFC to the mailing list last week. Also, it depends on some Device abstractions
[2] and on the Timer abstraction [3] developed by Boqun Feng.

This patchset introduces some changes to the DRM abstractions proposed in [1]
and also introduces a new abstraction to DMA reservation. Finally, introduces a
fully functional vgem driver written in Rust.

* Patch #1: Introduces a safe abstraction to the DMA Reservation.
* Patch #2 - #5: Introduces some increments to the DRM abstractions, adding
  methods and exposing attributes.
* Patch #6: Makes an adaptation to the UAPI, in order to be interpreted by bindgen.
* Patch #7 - #8: Introduces the vgem driver.
* Patch #9: Makes it possible to use the kernel::declare_drm_ioctls! macro.

The driver was tested with IGT, using the tests `vgem_basic`, `vgem_slow` and
`dmabuf_sync_file`. Also, I incremented some invalid tests to `vgem_basic` [4]
to assure the proper error handling of the driver.

A branch with all the dependencies and ready for compilation is available at
[5].

Note that patch #8 is necessary to deal with the current
kernel::declare_drm_ioctls! macro. Currently, the macro
kernel::declare_drm_ioctls! considers that the IOCTLs are in the right order and
there are no gaps, which is not true for vgem. The vgem IOCTLs starts at 0x01,
so there is a gap for IOCTL 0x00. To bypass this problem I'm currently using a
dummy IOCTL as IOCTL 0x00, but this solution should be temporary. I would love
to hear suggestions on how to address this problem.

Any suggestions and SAFETY reviews are welcomed!

[1] https://lore.kernel.org/dri-devel/20230307-rust-drm-v1-0-917ff5bc80a8@asahilina.net/T/
[2] https://github.com/Rust-for-Linux/linux/pull/982
[3] https://github.com/fbq/linux-rust/commit/c31a2a3ce7420b43bda2c6f1b43227baf0d13661
[4] https://patchwork.freedesktop.org/series/114912/
[5] https://github.com/mairacanal/linux/tree/vgem/wip-dma

Best Regards,
- Maíra Canal

Maíra Canal (9):
  rust: dma_resv: add DMA Reservation abstraction
  rust: drm: gem: add method to return DmaResv from GEMObject
  rust: dma_fence: add method to return an indication if the fence is signaled
  rust: dma_fence: expose the fence's seqno publically
  rust: drm: gem: shmem: set map_wc on gem_create_object callback
  drm/vgem: move IOCTLs numbers to enum
  drm/rustgem: implement a Rust version of VGEM
  drm/rustgem: implement timeout to prevent hangs
  drm/rustgem: create dummy IOCTL with number 0x00

 drivers/gpu/drm/Kconfig          |  11 +++
 drivers/gpu/drm/Makefile         |   1 +
 drivers/gpu/drm/rustgem/Makefile |   3 +
 drivers/gpu/drm/rustgem/fence.rs |  83 ++++++++++++++++++
 drivers/gpu/drm/rustgem/file.rs  | 143 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/rustgem/gem.rs   |  31 +++++++
 drivers/gpu/drm/rustgem/vgem.rs  | 105 +++++++++++++++++++++++
 include/uapi/drm/vgem_drm.h      |  11 ++-
 rust/bindings/bindings_helper.h  |   2 +
 rust/helpers.c                   |  25 ++++++
 rust/kernel/dma_fence.rs         |  12 +++
 rust/kernel/dma_resv.rs          |  75 ++++++++++++++++
 rust/kernel/drm/gem/mod.rs       |   7 ++
 rust/kernel/drm/gem/shmem.rs     |   5 ++
 rust/kernel/lib.rs               |   1 +
 15 files changed, 513 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/rustgem/Makefile
 create mode 100644 drivers/gpu/drm/rustgem/fence.rs
 create mode 100644 drivers/gpu/drm/rustgem/file.rs
 create mode 100644 drivers/gpu/drm/rustgem/gem.rs
 create mode 100644 drivers/gpu/drm/rustgem/vgem.rs
 create mode 100644 rust/kernel/dma_resv.rs

-- 
2.39.2


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

end of thread, other threads:[~2023-04-13  9:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 12:12 [RFC PATCH 0/9] Rust version of the VGEM driver Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 1/9] rust: dma_resv: add DMA Reservation abstraction Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 2/9] rust: drm: gem: add method to return DmaResv from GEMObject Maíra Canal
2023-03-22 19:45   ` Björn Roy Baron
2023-03-22 19:57     ` Björn Roy Baron
2023-03-17 12:12 ` [RFC PATCH 3/9] rust: dma_fence: add method to return an indication if the fence is signaled Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 4/9] rust: dma_fence: expose the fence's seqno publically Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 5/9] rust: drm: gem: shmem: set map_wc on gem_create_object callback Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 6/9] drm/vgem: move IOCTLs numbers to enum Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 7/9] drm/rustgem: implement a Rust version of VGEM Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 8/9] drm/rustgem: implement timeout to prevent hangs Maíra Canal
2023-03-17 12:12 ` [RFC PATCH 9/9] drm/rustgem: create dummy IOCTL with number 0x00 Maíra Canal
2023-04-13  9:08   ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).