The Rust DRM abstractions currently cover GEM and the device/driver
registration boilerplate, but expose nothing of the KMS (mode-setting)
API, so a Rust driver cannot bring up a display pipeline without
dropping to C. Add the minimum needed to drive an atomic mode-setting
pipeline built on the drm_simple_display_pipe helper (one CRTC + a
primary plane + encoder), the same path simpledrm/gud/udl use.

Two pieces:

 - bindings_helper.h: pull in the KMS headers (drm_atomic_helper,
   drm_connector, drm_gem_atomic_helper, drm_gem_framebuffer_helper,
   drm_managed, drm_modes, drm_modeset_helper_vtables,
   drm_probe_helper, drm_simple_kms_helper) so bindgen emits the
   drm_simple_display_pipe, drm_connector, drm_display_mode and helper
   bindings a KMS driver calls (drm_simple_display_pipe_init,
   drm_connector_init, drm_helper_probe_single_connector_modes,
   drm_gem_fb_create, drm_cvt_mode and the drm_atomic_helper_* family).

 - drm::driver: add FEAT_MODESET / FEAT_ATOMIC and the matching
   Driver::FEAT_MODESET / Driver::FEAT_ATOMIC associated consts, folded
   into compute_features() exactly like the existing FEAT_RENDER. They
   default to false, so GEM-only drivers are unaffected.

No safe CRTC/plane/connector wrappers are added here; this is the raw
binding surface a driver needs to call the C helpers itself, and is
meant to be superseded by the in-progress safe KMS layer. The raw
drm_device pointer those helpers need is exposed by a separate follow-up
patch ("expose drm::Device::as_raw()") so the escape hatch can be
reviewed on its own.

Signed-off-by: Mike Lothian <[email protected]>
Assisted-by: Claude:claude-opus-4-8 [Claude-Code]
---
 rust/bindings/bindings_helper.h |  9 +++++++++
 rust/kernel/drm/device.rs       |  8 ++++++++
 rust/kernel/drm/driver.rs       | 17 +++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 14671e1825bb..877f82b927a0 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -32,13 +32,22 @@
 
 #include <linux/acpi.h>
 #include <linux/gpu_buddy.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_connector.h>
 #include <drm/drm_device.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
 #include <drm/drm_gem.h>
+#include <drm/drm_gem_atomic_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_gpuvm.h>
 #include <drm/drm_ioctl.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_simple_kms_helper.h>
 #include <kunit/test.h>
 #include <linux/auxiliary_bus.h>
 #include <linux/bitmap.h>
diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index 477cf771fb10..1d3319b713e2 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -165,6 +165,14 @@ const fn compute_features() -> u32 {
             features |= drm::driver::FEAT_RENDER;
         }
 
+        if T::FEAT_MODESET {
+            features |= drm::driver::FEAT_MODESET;
+        }
+
+        if T::FEAT_ATOMIC {
+            features |= drm::driver::FEAT_ATOMIC;
+        }
+
         features
     }
 
diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
index 25f7e233884d..6a79594510fd 100644
--- a/rust/kernel/drm/driver.rs
+++ b/rust/kernel/drm/driver.rs
@@ -22,6 +22,10 @@
 pub(crate) const FEAT_GEM: u32 = bindings::drm_driver_feature_DRIVER_GEM;
 /// Driver supports render nodes, i.e.: /dev/dri/renderDXX devices.
 pub(crate) const FEAT_RENDER: u32 = bindings::drm_driver_feature_DRIVER_RENDER;
+/// Driver supports mode setting (KMS).
+pub(crate) const FEAT_MODESET: u32 = 
bindings::drm_driver_feature_DRIVER_MODESET;
+/// Driver supports atomic mode setting.
+pub(crate) const FEAT_ATOMIC: u32 = bindings::drm_driver_feature_DRIVER_ATOMIC;
 
 /// Information data for a DRM Driver.
 pub struct DriverInfo {
@@ -131,6 +135,19 @@ pub trait Driver {
     /// usable from the render node (i.e. marked DRM_RENDER_ALLOW), whereas
     /// userspace processes using the master node can invoke any ioctl.
     const FEAT_RENDER: bool = false;
+
+    /// Sets the `DRIVER_MODESET` feature for this driver.
+    ///
+    /// When enabled, the driver advertises kernel mode-setting (KMS): it owns 
a
+    /// `drm_mode_config` and drives CRTCs, planes, encoders and connectors. 
Leave
+    /// `false` for a render-only (GEM) driver.
+    const FEAT_MODESET: bool = false;
+
+    /// Sets the `DRIVER_ATOMIC` feature for this driver.
+    ///
+    /// When enabled, the driver advertises the atomic mode-setting uAPI. It 
only
+    /// has an effect together with [`Driver::FEAT_MODESET`].
+    const FEAT_ATOMIC: bool = false;
 }
 
 /// The registration type of a `drm::Device`.
-- 
2.54.0

Reply via email to