From b56fdbe3ade195f3f270ffc1e119ca72f74f090a Mon Sep 17 00:00:00 2001 From: Lyude Paul <lyude@redhat.com> Date: Wed, 12 Feb 2025 19:21:09 -0500 Subject: [PATCH] squash! rust: drm/kms: Add bindings for drm_encoder * Turn all of the encoder type IDs into an enum using a new macro --- rust/kernel/drm/kms/encoder.rs | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/rust/kernel/drm/kms/encoder.rs b/rust/kernel/drm/kms/encoder.rs index 2cbbffdb2b3b0..65a38ff508d5d 100644 --- a/rust/kernel/drm/kms/encoder.rs +++ b/rust/kernel/drm/kms/encoder.rs @@ -19,19 +19,36 @@ use core::{ }; use super::{ModeObject, ModeObjectVtable, StaticModeObject, KmsDriver, UnregisteredKmsDevice}; use bindings; +use macros::paste; + +/// A macro for generating our type ID enumerator. +macro_rules! declare_encoder_types { + ($( $oldname:ident as $newname:ident ),+) => { + #[repr(i32)] + #[non_exhaustive] + #[derive(Copy, Clone, PartialEq, Eq)] + /// An enumerator for all possible [`Encoder`] type IDs. + pub enum Type { + // Note: bindgen defaults the macro values to u32 and not i32, but DRM takes them as an + // i32 - so just do the conversion here + $( + #[doc = concat!("The encoder type ID for a ", stringify!($newname), " encoder.")] + $newname = paste!(crate::bindings::[<DRM_MODE_ENCODER_ $oldname>]) as i32 + ),+ + } + }; +} -// TODO: We should alias all of these types with shorter names -pub use bindings::{ - DRM_MODE_ENCODER_NONE, - DRM_MODE_ENCODER_DAC, - DRM_MODE_ENCODER_TMDS, - DRM_MODE_ENCODER_LVDS, - DRM_MODE_ENCODER_TVDAC, - DRM_MODE_ENCODER_VIRTUAL, - DRM_MODE_ENCODER_DSI, - DRM_MODE_ENCODER_DPMST, - DRM_MODE_ENCODER_DPI, -}; +declare_encoder_types! { + NONE as None, + DAC as Dac, + TMDS as Tmds, + LVDS as Lvds, + VIRTUAL as Virtual, + DSI as Dsi, + DPMST as DpMst, + DPI as Dpi +} /// The main trait for implementing the [`struct drm_encoder`] API for [`Encoder`]. /// @@ -259,7 +276,7 @@ impl<T: DriverEncoder> UnregisteredEncoder<T> { /// [`KmsDriver::create_objects`]: kernel::drm::kms::KmsDriver::create_objects pub fn new<'a, 'b: 'a>( dev: &'a UnregisteredKmsDevice<'a, T::Driver>, - type_: u32, + type_: Type, possible_crtcs: u32, possible_clones: u32, name: Option<&CStr>, -- GitLab