[PATCH 0/5] rust: drm: add panel bindings

From: Albert Esteve

Date: Mon Aug 17 2026 - 07:41:18 EST


This series adds Rust abstractions for the DRM panel subsystem,
covering both the consumer and producer sides of the API.
This helps closing the gap so that future panel drivers
can be written directly in Rust.

Background
----------
The DRM panel C API has been progressively hardened over the past
year (see [1], [2], and [3]). All panel drivers were fully migrated
to kref-based allocation via devm_drm_panel_alloc(). Panel lookup
functions (i.e., of_drm_find_panel() and find_panel_by_fwnode())
were also updated to acquire a reference before returning.

Note this series depends on [3] being merged in the base
tree. Currently it has been only applied to drm-misc-next.
The other series mentioned above are already part of the
base for the current version of this series.

As a personal note, part of my motivation for creating this series
was learning more about Rust in the kernel. I would appreciate
feedback on Rust-specific idioms or kernel conventions used here
that I may have missed.

What this series does
---------------------
Patch 1 adds of::Node, a Rust wrapper for struct device_node
implementing AlwaysRefCounted. C helpers are added so that of_node_get()
and of_node_put() are reachable from Rust independently of CONFIG_OF_DYNAMIC.

Patch 2 adds drm::Connector, a minimal Rust wrapper for
struct drm_connector. Its sole purpose is to provide a typed reference
for the get_modes() callback argument; no ownership or refcounting is
exposed at this stage.

Patch 3 adds the consumer side of the panel abstraction:
- Panel wraps struct drm_panel and implements AlwaysRefCounted via
drm_panel_get/put. Consumer lifecycle methods are exposed as safe wrappers.
- PanelOrientation wraps enum drm_panel_orientation and provides
from_of_node() to read the "rotation" device tree property.
- Registration manages the panel's presence in the global registry
via drm_panel_add/remove, decoupling registry lifetime from
reference count lifetime.

Patch 4 adds the producer side:
- PanelFuncs is a #[vtable] trait that panel drivers implement to
provide their callbacks. All but get_modes are optional.
- Panel::new wraps __devm_drm_panel_alloc, returning an ARef<Panel>.
Registration with the global registry is kept separate via
Registration::register, following the pattern of drm::Device::new.
- ConnectorType mirrors the DRM_MODE_CONNECTOR_* defines from
include/uapi/drm/drm_mode.h, required by Panel::new to specify the
panel's connector type.

Patch 5 adds gated tests, covering data type conversions and layout
invariants.

[1] https://lore.kernel.org/all/20250331-b4-panel-refcounting-v4-0-dad50c60c6c9@xxxxxxxxxx/
[2] https://lore.kernel.org/all/20260508-drm_panel_init_rm-v2-0-0bd4ac429971@xxxxxxxxxx/
[3] https://lore.kernel.org/all/20260717-drm_refcount_wiring-v3-0-023900c32e01@xxxxxxxxxx/

Signed-off-by: Albert Esteve <aesteve@xxxxxxxxxx>
---
Albert Esteve (5):
rust: of: add Node type
rust: drm: add connector abstraction
rust: drm: add panel consumer abstractions
rust: drm: add panel producer abstractions
rust: drm: add KUnit tests for panel

rust/bindings/bindings_helper.h | 2 +
rust/helpers/drm.c | 15 +
rust/helpers/of.c | 10 +
rust/kernel/Kconfig.test | 10 +
rust/kernel/drm/connector.rs | 33 ++
rust/kernel/drm/mod.rs | 2 +
rust/kernel/drm/panel.rs | 684 ++++++++++++++++++++++++++++++++++++++++
rust/kernel/of.rs | 43 +++
8 files changed, 799 insertions(+)
---
base-commit: c21bb4193868a8de71fc4693fa741e195fdf5d86
change-id: 20260814-drm_panel_bindings-91a3aae5d09c

Best regards,
--
Albert Esteve <aesteve@xxxxxxxxxx>