drm: drv: implement __drm_dev_alloc()
authorDanilo Krummrich <dakr@kernel.org>
Thu, 10 Apr 2025 23:55:20 +0000 (01:55 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Thu, 24 Apr 2025 11:50:03 +0000 (13:50 +0200)
commit57493a145552fe8a9a926f25b14c324c441ca358
treeafcadde0eeae7d1160b8558ed5371c021b0339cb
parent0c848b3adb45acc1722f94333e2a97bf1720e431
drm: drv: implement __drm_dev_alloc()

In the Rust DRM device abstraction we need to allocate a struct
drm_device.

Currently, there are two options, the deprecated drm_dev_alloc() (which
does not support subclassing) and devm_drm_dev_alloc(). The latter
supports subclassing, but also manages the initial reference through
devres for the parent device.

In Rust we want to conform with the subclassing pattern, but do not want
to get the initial reference managed for us, since Rust has its own,
idiomatic ways to properly deal with it.

There are two options to achieve this.

  1) Allocate the memory ourselves with a KBox.
  2) Implement __drm_dev_alloc(), which supports subclassing, but is
     unmanged.

While (1) would be possible, it would be cumbersome, since it would
require exporting drm_dev_init() and drmm_add_final_kfree().

Hence, go with option (2) and implement __drm_dev_alloc().

Reviewed-by: Maxime Ripard <mripard@kernel.org>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20250410235546.43736-2-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/gpu/drm/drm_drv.c
include/drm/drm_drv.h