Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: drm: add driver abstractions

Implement the DRM driver abstractions.

The `Driver` trait provides the interface to the actual driver to fill
in the driver specific data, such as the `DriverInfo`, driver features
and IOCTLs.

Reviewed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Asahi Lina <lina@asahilina.net>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20250410235546.43736-4-dakr@kernel.org
[ MISC changes
* remove unnecessary DRM features; make remaining ones crate private
* add #[expect(unused)] to avoid warnings
* add sealed trait
* remove shmem::Object references
* original source archive: https://archive.is/Pl9ys

- Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Asahi Lina and committed by
Danilo Krummrich
07c90160 9a695706

+122
+1
rust/bindings/bindings_helper.h
··· 6 6 * Sorted alphabetically. 7 7 */ 8 8 9 + #include <drm/drm_drv.h> 9 10 #include <drm/drm_ioctl.h> 10 11 #include <kunit/test.h> 11 12 #include <linux/auxiliary_bus.h>
+113
rust/kernel/drm/driver.rs
··· 1 + // SPDX-License-Identifier: GPL-2.0 OR MIT 2 + 3 + //! DRM driver core. 4 + //! 5 + //! C header: [`include/linux/drm/drm_drv.h`](srctree/include/linux/drm/drm_drv.h) 6 + 7 + use crate::{bindings, drm, str::CStr}; 8 + use macros::vtable; 9 + 10 + /// Driver use the GEM memory manager. This should be set for all modern drivers. 11 + #[expect(unused)] 12 + pub(crate) const FEAT_GEM: u32 = bindings::drm_driver_feature_DRIVER_GEM; 13 + 14 + /// Information data for a DRM Driver. 15 + pub struct DriverInfo { 16 + /// Driver major version. 17 + pub major: i32, 18 + /// Driver minor version. 19 + pub minor: i32, 20 + /// Driver patchlevel version. 21 + pub patchlevel: i32, 22 + /// Driver name. 23 + pub name: &'static CStr, 24 + /// Driver description. 25 + pub desc: &'static CStr, 26 + } 27 + 28 + /// Internal memory management operation set, normally created by memory managers (e.g. GEM). 29 + pub struct AllocOps { 30 + #[expect(unused)] 31 + pub(crate) gem_create_object: Option< 32 + unsafe extern "C" fn( 33 + dev: *mut bindings::drm_device, 34 + size: usize, 35 + ) -> *mut bindings::drm_gem_object, 36 + >, 37 + #[expect(unused)] 38 + pub(crate) prime_handle_to_fd: Option< 39 + unsafe extern "C" fn( 40 + dev: *mut bindings::drm_device, 41 + file_priv: *mut bindings::drm_file, 42 + handle: u32, 43 + flags: u32, 44 + prime_fd: *mut core::ffi::c_int, 45 + ) -> core::ffi::c_int, 46 + >, 47 + #[expect(unused)] 48 + pub(crate) prime_fd_to_handle: Option< 49 + unsafe extern "C" fn( 50 + dev: *mut bindings::drm_device, 51 + file_priv: *mut bindings::drm_file, 52 + prime_fd: core::ffi::c_int, 53 + handle: *mut u32, 54 + ) -> core::ffi::c_int, 55 + >, 56 + #[expect(unused)] 57 + pub(crate) gem_prime_import: Option< 58 + unsafe extern "C" fn( 59 + dev: *mut bindings::drm_device, 60 + dma_buf: *mut bindings::dma_buf, 61 + ) -> *mut bindings::drm_gem_object, 62 + >, 63 + #[expect(unused)] 64 + pub(crate) gem_prime_import_sg_table: Option< 65 + unsafe extern "C" fn( 66 + dev: *mut bindings::drm_device, 67 + attach: *mut bindings::dma_buf_attachment, 68 + sgt: *mut bindings::sg_table, 69 + ) -> *mut bindings::drm_gem_object, 70 + >, 71 + #[expect(unused)] 72 + pub(crate) dumb_create: Option< 73 + unsafe extern "C" fn( 74 + file_priv: *mut bindings::drm_file, 75 + dev: *mut bindings::drm_device, 76 + args: *mut bindings::drm_mode_create_dumb, 77 + ) -> core::ffi::c_int, 78 + >, 79 + #[expect(unused)] 80 + pub(crate) dumb_map_offset: Option< 81 + unsafe extern "C" fn( 82 + file_priv: *mut bindings::drm_file, 83 + dev: *mut bindings::drm_device, 84 + handle: u32, 85 + offset: *mut u64, 86 + ) -> core::ffi::c_int, 87 + >, 88 + } 89 + 90 + /// Trait for memory manager implementations. Implemented internally. 91 + pub trait AllocImpl: super::private::Sealed { 92 + /// The C callback operations for this memory manager. 93 + const ALLOC_OPS: AllocOps; 94 + } 95 + 96 + /// The DRM `Driver` trait. 97 + /// 98 + /// This trait must be implemented by drivers in order to create a `struct drm_device` and `struct 99 + /// drm_driver` to be registered in the DRM subsystem. 100 + #[vtable] 101 + pub trait Driver { 102 + /// Context data associated with the DRM driver 103 + type Data: Sync + Send; 104 + 105 + /// The type used to manage memory for this driver. 106 + type Object: AllocImpl; 107 + 108 + /// Driver metadata 109 + const INFO: DriverInfo; 110 + 111 + /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`. 112 + const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor]; 113 + }
+8
rust/kernel/drm/mod.rs
··· 2 2 3 3 //! DRM subsystem abstractions. 4 4 5 + pub mod driver; 5 6 pub mod ioctl; 7 + 8 + pub use self::driver::Driver; 9 + pub use self::driver::DriverInfo; 10 + 11 + pub(crate) mod private { 12 + pub trait Sealed {} 13 + }