Re: [PATCH RFC 02/18] rust: drm: Add Device and Driver abstractions

From: Asahi Lina
Date: Thu Mar 09 2023 - 01:11:10 EST


On 08/03/2023 03.19, Björn Roy Baron wrote:
> ------- Original Message -------
> On Tuesday, March 7th, 2023 at 15:25, Asahi Lina <lina@xxxxxxxxxxxxx> wrote:
>
>> Add the initial abstractions for DRM drivers and devices. These go
>> together in one commit since they are fairly tightly coupled types.
>>
>> A few things have been stubbed out, to be implemented as further bits of
>> the DRM subsystem are introduced.
>>
>> Signed-off-by: Asahi Lina lina@xxxxxxxxxxxxx
>>
>> ---
[...]

>> +/// Information data for a DRM Driver.
>> +pub struct DriverInfo {
>> + /// Driver major version.
>> + pub major: i32,
>> + /// Driver minor version.
>> + pub minor: i32,
>> + /// Driver patchlevel version.
>> + pub patchlevel: i32,
>> + /// Driver name.
>> + pub name: &'static CStr,
>> + /// Driver description.
>> + pub desc: &'static CStr,
>> + /// Driver date.
>> + pub date: &'static CStr,
>> +}
>> +
>
> Could you please add an Invariants section to the doc comments indicating what requirements these function pointers must satisfy?

I can try (as much as I can divine from the C side anyway...). I guess
you want interface docs for each callback, so like what it must do and
what invariants each one must uphold?

Note that this is a kernel crate-only struct (the fields are not public)
so users can't create their own AllocOps variants anyway (plus AllocImpl
is sealed, on top of that), but I guess it makes sense to document for
internal kernel crate purposes. At some point it might make sense to
allow drivers to override these with proper Rust callbacks (and then the
wrappers need to ensure safety), but right now that's not implemented.

>> +/// Internal memory management operation set, normally created by memory managers (e.g. GEM).
>> +///
>> +/// See `kernel::drm::gem` and `kernel::drm::gem::shmem`.
>> +pub struct AllocOps {
>> + pub(crate) gem_create_object: Option<
>> + unsafe extern "C" fn(
>> + dev: *mut bindings::drm_device,
>> + size: usize,
>> + ) -> *mut bindings::drm_gem_object,
>> + >,
>> + pub(crate) prime_handle_to_fd: Option<
>> + unsafe extern "C" fn(
>> + dev: *mut bindings::drm_device,
>> + file_priv: *mut bindings::drm_file,
>> + handle: u32,
>> + flags: u32,
>> + prime_fd: *mut core::ffi::c_int,
>> + ) -> core::ffi::c_int,
>> + >,
>> + pub(crate) prime_fd_to_handle: Option<
>> + unsafe extern "C" fn(
>> + dev: *mut bindings::drm_device,
>> + file_priv: *mut bindings::drm_file,
>> + prime_fd: core::ffi::c_int,
>> + handle: *mut u32,
>> + ) -> core::ffi::c_int,
>> + >,
>> + pub(crate) gem_prime_import: Option<
>> + unsafe extern "C" fn(
>> + dev: *mut bindings::drm_device,
>> + dma_buf: *mut bindings::dma_buf,
>> + ) -> *mut bindings::drm_gem_object,
>> + >,
>> + pub(crate) gem_prime_import_sg_table: Option<
>> + unsafe extern "C" fn(
>> + dev: *mut bindings::drm_device,
>> + attach: *mut bindings::dma_buf_attachment,
>> + sgt: *mut bindings::sg_table,
>> + ) -> *mut bindings::drm_gem_object,
>> + >,
>> + pub(crate) gem_prime_mmap: Option<
>> + unsafe extern "C" fn(
>> + obj: *mut bindings::drm_gem_object,
>> + vma: *mut bindings::vm_area_struct,
>> + ) -> core::ffi::c_int,
>> + >,
>> + pub(crate) dumb_create: Option<
>> + unsafe extern "C" fn(
>> + file_priv: *mut bindings::drm_file,
>> + dev: *mut bindings::drm_device,
>> + args: *mut bindings::drm_mode_create_dumb,
>> + ) -> core::ffi::c_int,
>> + >,
>> + pub(crate) dumb_map_offset: Option<
>> + unsafe extern "C" fn(
>> + file_priv: *mut bindings::drm_file,
>> + dev: *mut bindings::drm_device,
>> + handle: u32,
>> + offset: *mut u64,
>> + ) -> core::ffi::c_int,
>> + >,
>> + pub(crate) dumb_destroy: Option<
>> + unsafe extern "C" fn(
>> + file_priv: *mut bindings::drm_file,
>> + dev: *mut bindings::drm_device,
>> + handle: u32,
>> + ) -> core::ffi::c_int,
>> + >,
>> +}
>> +

~~ Lina